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) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Thomas Browning -/ import Mathlib.Algebra.Group.ConjFinite import Mathlib.Data.Fintype.BigOperators import Mathlib.Dynamics.PeriodicPts import Mathlib.GroupTheory.Commutator import Mathlib.GroupTheory.Coset import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.GroupTheory.GroupAction.Hom #align_import group_theory.group_action.quotient from "leanprover-community/mathlib"@"4be589053caf347b899a494da75410deb55fb3ef" /-! # Properties of group actions involving quotient groups This file proves properties of group actions which use the quotient group construction, notably * the orbit-stabilizer theorem `card_orbit_mul_card_stabilizer_eq_card_group` * the class formula `card_eq_sum_card_group_div_card_stabilizer'` * Burnside's lemma `sum_card_fixedBy_eq_card_orbits_mul_card_group` -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} open Function namespace MulAction variable [Group α] section QuotientAction open Subgroup MulOpposite QuotientGroup variable (β) [Monoid β] [MulAction β α] (H : Subgroup α) /-- A typeclass for when a `MulAction β α` descends to the quotient `α ⧸ H`. -/ class QuotientAction : Prop where /-- The action fulfils a normality condition on products that lie in `H`. This ensures that the action descends to an action on the quotient `α ⧸ H`. -/ inv_mul_mem : ∀ (b : β) {a a' : α}, a⁻¹ * a' ∈ H → (b • a)⁻¹ * b • a' ∈ H #align mul_action.quotient_action MulAction.QuotientAction /-- A typeclass for when an `AddAction β α` descends to the quotient `α ⧸ H`. -/ class _root_.AddAction.QuotientAction {α : Type u} (β : Type v) [AddGroup α] [AddMonoid β] [AddAction β α] (H : AddSubgroup α) : Prop where /-- The action fulfils a normality condition on summands that lie in `H`. This ensures that the action descends to an action on the quotient `α ⧸ H`. -/ inv_mul_mem : ∀ (b : β) {a a' : α}, -a + a' ∈ H → -(b +ᵥ a) + (b +ᵥ a') ∈ H #align add_action.quotient_action AddAction.QuotientAction attribute [to_additive] MulAction.QuotientAction @[to_additive] instance left_quotientAction : QuotientAction α H := ⟨fun _ _ _ _ => by rwa [smul_eq_mul, smul_eq_mul, mul_inv_rev, mul_assoc, inv_mul_cancel_left]⟩ #align mul_action.left_quotient_action MulAction.left_quotientAction #align add_action.left_quotient_action AddAction.left_quotientAction @[to_additive] instance right_quotientAction : QuotientAction (normalizer H).op H := ⟨fun b c _ _ => by rwa [smul_def, smul_def, smul_eq_mul_unop, smul_eq_mul_unop, mul_inv_rev, ← mul_assoc, mem_normalizer_iff'.mp b.prop, mul_assoc, mul_inv_cancel_left]⟩ #align mul_action.right_quotient_action MulAction.right_quotientAction #align add_action.right_quotient_action AddAction.right_quotientAction @[to_additive] instance right_quotientAction' [hH : H.Normal] : QuotientAction αᵐᵒᵖ H := ⟨fun _ _ _ _ => by rwa [smul_eq_mul_unop, smul_eq_mul_unop, mul_inv_rev, mul_assoc, hH.mem_comm_iff, mul_assoc, mul_inv_cancel_right]⟩ #align mul_action.right_quotient_action' MulAction.right_quotientAction' #align add_action.right_quotient_action' AddAction.right_quotientAction' @[to_additive] instance quotient [QuotientAction β H] : MulAction β (α ⧸ H) where smul b := Quotient.map' (b • ·) fun _ _ h => leftRel_apply.mpr <| QuotientAction.inv_mul_mem b <| leftRel_apply.mp h one_smul q := Quotient.inductionOn' q fun a => congr_arg Quotient.mk'' (one_smul β a) mul_smul b b' q := Quotient.inductionOn' q fun a => congr_arg Quotient.mk'' (mul_smul b b' a) #align mul_action.quotient MulAction.quotient #align add_action.quotient AddAction.quotient variable {β} @[to_additive (attr := simp)] theorem Quotient.smul_mk [QuotientAction β H] (b : β) (a : α) : (b • QuotientGroup.mk a : α ⧸ H) = QuotientGroup.mk (b • a) := rfl #align mul_action.quotient.smul_mk MulAction.Quotient.smul_mk #align add_action.quotient.vadd_mk AddAction.Quotient.vadd_mk @[to_additive (attr := simp)] theorem Quotient.smul_coe [QuotientAction β H] (b : β) (a : α) : b • (a : α ⧸ H) = (↑(b • a) : α ⧸ H) := rfl #align mul_action.quotient.smul_coe MulAction.Quotient.smul_coe #align add_action.quotient.vadd_coe AddAction.Quotient.vadd_coe @[to_additive (attr := simp)] theorem Quotient.mk_smul_out' [QuotientAction β H] (b : β) (q : α ⧸ H) : QuotientGroup.mk (b • q.out') = b • q := by rw [← Quotient.smul_mk, QuotientGroup.out_eq'] #align mul_action.quotient.mk_smul_out' MulAction.Quotient.mk_smul_out' #align add_action.quotient.mk_vadd_out' AddAction.Quotient.mk_vadd_out' -- Porting note: removed simp attribute, simp can prove this @[to_additive] theorem Quotient.coe_smul_out' [QuotientAction β H] (b : β) (q : α ⧸ H) : ↑(b • q.out') = b • q := Quotient.mk_smul_out' H b q #align mul_action.quotient.coe_smul_out' MulAction.Quotient.coe_smul_out' #align add_action.quotient.coe_vadd_out' AddAction.Quotient.coe_vadd_out' theorem _root_.QuotientGroup.out'_conj_pow_minimalPeriod_mem (a : α) (q : α ⧸ H) : q.out'⁻¹ * a ^ Function.minimalPeriod (a • ·) q * q.out' ∈ H := by rw [mul_assoc, ← QuotientGroup.eq', QuotientGroup.out_eq', ← smul_eq_mul, Quotient.mk_smul_out', eq_comm, pow_smul_eq_iff_minimalPeriod_dvd] #align quotient_group.out'_conj_pow_minimal_period_mem QuotientGroup.out'_conj_pow_minimalPeriod_mem end QuotientAction open QuotientGroup /-- The canonical map to the left cosets. -/ def _root_.MulActionHom.toQuotient (H : Subgroup α) : α →[α] α ⧸ H where toFun := (↑); map_smul' := Quotient.smul_coe H #align mul_action_hom.to_quotient MulActionHom.toQuotient @[simp] theorem _root_.MulActionHom.toQuotient_apply (H : Subgroup α) (g : α) : MulActionHom.toQuotient H g = g := rfl #align mul_action_hom.to_quotient_apply MulActionHom.toQuotient_apply @[to_additive] instance mulLeftCosetsCompSubtypeVal (H I : Subgroup α) : MulAction I (α ⧸ H) := MulAction.compHom (α ⧸ H) (Subgroup.subtype I) #align mul_action.mul_left_cosets_comp_subtype_val MulAction.mulLeftCosetsCompSubtypeVal #align add_action.add_left_cosets_comp_subtype_val AddAction.addLeftCosetsCompSubtypeVal -- Porting note: Needed to insert [Group α] here variable (α) [Group α] [MulAction α β] (x : β) /-- The canonical map from the quotient of the stabilizer to the set. -/ @[to_additive "The canonical map from the quotient of the stabilizer to the set. "] def ofQuotientStabilizer (g : α ⧸ MulAction.stabilizer α x) : β := Quotient.liftOn' g (· • x) fun g1 g2 H => calc g1 • x = g1 • (g1⁻¹ * g2) • x := congr_arg _ (leftRel_apply.mp H).symm _ = g2 • x := by rw [smul_smul, mul_inv_cancel_left] #align mul_action.of_quotient_stabilizer MulAction.ofQuotientStabilizer #align add_action.of_quotient_stabilizer AddAction.ofQuotientStabilizer @[to_additive (attr := simp)] theorem ofQuotientStabilizer_mk (g : α) : ofQuotientStabilizer α x (QuotientGroup.mk g) = g • x := rfl #align mul_action.of_quotient_stabilizer_mk MulAction.ofQuotientStabilizer_mk #align add_action.of_quotient_stabilizer_mk AddAction.ofQuotientStabilizer_mk @[to_additive] theorem ofQuotientStabilizer_mem_orbit (g) : ofQuotientStabilizer α x g ∈ orbit α x := Quotient.inductionOn' g fun g => ⟨g, rfl⟩ #align mul_action.of_quotient_stabilizer_mem_orbit MulAction.ofQuotientStabilizer_mem_orbit #align add_action.of_quotient_stabilizer_mem_orbit AddAction.ofQuotientStabilizer_mem_orbit @[to_additive] theorem ofQuotientStabilizer_smul (g : α) (g' : α ⧸ MulAction.stabilizer α x) : ofQuotientStabilizer α x (g • g') = g • ofQuotientStabilizer α x g' := Quotient.inductionOn' g' fun _ => mul_smul _ _ _ #align mul_action.of_quotient_stabilizer_smul MulAction.ofQuotientStabilizer_smul #align add_action.of_quotient_stabilizer_vadd AddAction.ofQuotientStabilizer_vadd @[to_additive] theorem injective_ofQuotientStabilizer : Function.Injective (ofQuotientStabilizer α x) := fun y₁ y₂ => Quotient.inductionOn₂' y₁ y₂ fun g₁ g₂ (H : g₁ • x = g₂ • x) => Quotient.sound' <| by rw [leftRel_apply] show (g₁⁻¹ * g₂) • x = x rw [mul_smul, ← H, inv_smul_smul] #align mul_action.injective_of_quotient_stabilizer MulAction.injective_ofQuotientStabilizer #align add_action.injective_of_quotient_stabilizer AddAction.injective_ofQuotientStabilizer /-- **Orbit-stabilizer theorem**. -/ @[to_additive "Orbit-stabilizer theorem."] noncomputable def orbitEquivQuotientStabilizer (b : β) : orbit α b ≃ α ⧸ stabilizer α b := Equiv.symm <| Equiv.ofBijective (fun g => ⟨ofQuotientStabilizer α b g, ofQuotientStabilizer_mem_orbit α b g⟩) ⟨fun x y hxy => injective_ofQuotientStabilizer α b (by convert congr_arg Subtype.val hxy), fun ⟨b, ⟨g, hgb⟩⟩ => ⟨g, Subtype.eq hgb⟩⟩ #align mul_action.orbit_equiv_quotient_stabilizer MulAction.orbitEquivQuotientStabilizer #align add_action.orbit_equiv_quotient_stabilizer AddAction.orbitEquivQuotientStabilizer /-- Orbit-stabilizer theorem. -/ @[to_additive "Orbit-stabilizer theorem."] noncomputable def orbitProdStabilizerEquivGroup (b : β) : orbit α b × stabilizer α b ≃ α := (Equiv.prodCongr (orbitEquivQuotientStabilizer α _) (Equiv.refl _)).trans Subgroup.groupEquivQuotientProdSubgroup.symm #align mul_action.orbit_prod_stabilizer_equiv_group MulAction.orbitProdStabilizerEquivGroup #align add_action.orbit_sum_stabilizer_equiv_add_group AddAction.orbitSumStabilizerEquivAddGroup /-- Orbit-stabilizer theorem. -/ @[to_additive "Orbit-stabilizer theorem."] theorem card_orbit_mul_card_stabilizer_eq_card_group (b : β) [Fintype α] [Fintype <| orbit α b] [Fintype <| stabilizer α b] : Fintype.card (orbit α b) * Fintype.card (stabilizer α b) = Fintype.card α := by rw [← Fintype.card_prod, Fintype.card_congr (orbitProdStabilizerEquivGroup α b)] #align mul_action.card_orbit_mul_card_stabilizer_eq_card_group MulAction.card_orbit_mul_card_stabilizer_eq_card_group #align add_action.card_orbit_add_card_stabilizer_eq_card_add_group AddAction.card_orbit_add_card_stabilizer_eq_card_addGroup @[to_additive (attr := simp)] theorem orbitEquivQuotientStabilizer_symm_apply (b : β) (a : α) : ((orbitEquivQuotientStabilizer α b).symm a : β) = a • b := rfl #align mul_action.orbit_equiv_quotient_stabilizer_symm_apply MulAction.orbitEquivQuotientStabilizer_symm_apply #align add_action.orbit_equiv_quotient_stabilizer_symm_apply AddAction.orbitEquivQuotientStabilizer_symm_apply @[to_additive (attr := simp)]
Mathlib/GroupTheory/GroupAction/Quotient.lean
225
228
theorem stabilizer_quotient {G} [Group G] (H : Subgroup G) : MulAction.stabilizer G ((1 : G) : G ⧸ H) = H := by
ext simp [QuotientGroup.eq]
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Subalgebra import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.Artinian #align_import algebra.lie.submodule from "leanprover-community/mathlib"@"9822b65bfc4ac74537d77ae318d27df1df662471" /-! # Lie submodules of a Lie algebra In this file we define Lie submodules and Lie ideals, we construct the lattice structure on Lie submodules and we use it to define various important operations, notably the Lie span of a subset of a Lie module. ## Main definitions * `LieSubmodule` * `LieSubmodule.wellFounded_of_noetherian` * `LieSubmodule.lieSpan` * `LieSubmodule.map` * `LieSubmodule.comap` * `LieIdeal` * `LieIdeal.map` * `LieIdeal.comap` ## Tags lie algebra, lie submodule, lie ideal, lattice structure -/ universe u v w w₁ w₂ section LieSubmodule variable (R : Type u) (L : Type v) (M : Type w) variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] [LieModule R L M] /-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket. This is a sufficient condition for the subset itself to form a Lie module. -/ structure LieSubmodule extends Submodule R M where lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier #align lie_submodule LieSubmodule attribute [nolint docBlame] LieSubmodule.toSubmodule attribute [coe] LieSubmodule.toSubmodule namespace LieSubmodule variable {R L M} variable (N N' : LieSubmodule R L M) instance : SetLike (LieSubmodule R L M) M where coe s := s.carrier coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h instance : AddSubgroupClass (LieSubmodule R L M) M where add_mem {N} _ _ := N.add_mem' zero_mem N := N.zero_mem' neg_mem {N} x hx := show -x ∈ N.toSubmodule from neg_mem hx instance instSMulMemClass : SMulMemClass (LieSubmodule R L M) R M where smul_mem {s} c _ h := s.smul_mem' c h /-- The zero module is a Lie submodule of any Lie module. -/ instance : Zero (LieSubmodule R L M) := ⟨{ (0 : Submodule R M) with lie_mem := fun {x m} h ↦ by rw [(Submodule.mem_bot R).1 h]; apply lie_zero }⟩ instance : Inhabited (LieSubmodule R L M) := ⟨0⟩ instance coeSubmodule : CoeOut (LieSubmodule R L M) (Submodule R M) := ⟨toSubmodule⟩ #align lie_submodule.coe_submodule LieSubmodule.coeSubmodule -- Syntactic tautology #noalign lie_submodule.to_submodule_eq_coe @[norm_cast] theorem coe_toSubmodule : ((N : Submodule R M) : Set M) = N := rfl #align lie_submodule.coe_to_submodule LieSubmodule.coe_toSubmodule -- Porting note (#10618): `simp` can prove this after `mem_coeSubmodule` is added to the simp set, -- but `dsimp` can't. @[simp, nolint simpNF] theorem mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : Set M) := Iff.rfl #align lie_submodule.mem_carrier LieSubmodule.mem_carrier theorem mem_mk_iff (S : Set M) (h₁ h₂ h₃ h₄) {x : M} : x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) ↔ x ∈ S := Iff.rfl #align lie_submodule.mem_mk_iff LieSubmodule.mem_mk_iff @[simp] theorem mem_mk_iff' (p : Submodule R M) (h) {x : M} : x ∈ (⟨p, h⟩ : LieSubmodule R L M) ↔ x ∈ p := Iff.rfl @[simp] theorem mem_coeSubmodule {x : M} : x ∈ (N : Submodule R M) ↔ x ∈ N := Iff.rfl #align lie_submodule.mem_coe_submodule LieSubmodule.mem_coeSubmodule theorem mem_coe {x : M} : x ∈ (N : Set M) ↔ x ∈ N := Iff.rfl #align lie_submodule.mem_coe LieSubmodule.mem_coe @[simp] protected theorem zero_mem : (0 : M) ∈ N := zero_mem N #align lie_submodule.zero_mem LieSubmodule.zero_mem -- Porting note (#10618): @[simp] can prove this theorem mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 := Subtype.ext_iff_val #align lie_submodule.mk_eq_zero LieSubmodule.mk_eq_zero @[simp] theorem coe_toSet_mk (S : Set M) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) : Set M) = S := rfl #align lie_submodule.coe_to_set_mk LieSubmodule.coe_toSet_mk
Mathlib/Algebra/Lie/Submodule.lean
132
133
theorem coe_toSubmodule_mk (p : Submodule R M) (h) : (({ p with lie_mem := h } : LieSubmodule R L M) : Submodule R M) = p := by
cases p; rfl
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Ralf Stephan, Neil Strickland, Ruben Van de Velde -/ import Mathlib.Data.PNat.Defs import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Set.Basic import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Order.Positive.Ring import Mathlib.Order.Hom.Basic #align_import data.pnat.basic from "leanprover-community/mathlib"@"172bf2812857f5e56938cc148b7a539f52f84ca9" /-! # The positive natural numbers This file develops the type `ℕ+` or `PNat`, the subtype of natural numbers that are positive. It is defined in `Data.PNat.Defs`, but most of the development is deferred to here so that `Data.PNat.Defs` can have very few imports. -/ deriving instance AddLeftCancelSemigroup, AddRightCancelSemigroup, AddCommSemigroup, LinearOrderedCancelCommMonoid, Add, Mul, Distrib for PNat namespace PNat -- Porting note: this instance is no longer automatically inferred in Lean 4. instance instWellFoundedLT : WellFoundedLT ℕ+ := WellFoundedRelation.isWellFounded instance instIsWellOrder : IsWellOrder ℕ+ (· < ·) where @[simp] theorem one_add_natPred (n : ℕ+) : 1 + n.natPred = n := by rw [natPred, add_tsub_cancel_iff_le.mpr <| show 1 ≤ (n : ℕ) from n.2] #align pnat.one_add_nat_pred PNat.one_add_natPred @[simp] theorem natPred_add_one (n : ℕ+) : n.natPred + 1 = n := (add_comm _ _).trans n.one_add_natPred #align pnat.nat_pred_add_one PNat.natPred_add_one @[mono] theorem natPred_strictMono : StrictMono natPred := fun m _ h => Nat.pred_lt_pred m.2.ne' h #align pnat.nat_pred_strict_mono PNat.natPred_strictMono @[mono] theorem natPred_monotone : Monotone natPred := natPred_strictMono.monotone #align pnat.nat_pred_monotone PNat.natPred_monotone theorem natPred_injective : Function.Injective natPred := natPred_strictMono.injective #align pnat.nat_pred_injective PNat.natPred_injective @[simp] theorem natPred_lt_natPred {m n : ℕ+} : m.natPred < n.natPred ↔ m < n := natPred_strictMono.lt_iff_lt #align pnat.nat_pred_lt_nat_pred PNat.natPred_lt_natPred @[simp] theorem natPred_le_natPred {m n : ℕ+} : m.natPred ≤ n.natPred ↔ m ≤ n := natPred_strictMono.le_iff_le #align pnat.nat_pred_le_nat_pred PNat.natPred_le_natPred @[simp] theorem natPred_inj {m n : ℕ+} : m.natPred = n.natPred ↔ m = n := natPred_injective.eq_iff #align pnat.nat_pred_inj PNat.natPred_inj @[simp, norm_cast] lemma val_ofNat (n : ℕ) [NeZero n] : ((no_index (OfNat.ofNat n) : ℕ+) : ℕ) = OfNat.ofNat n := rfl @[simp] lemma mk_ofNat (n : ℕ) (h : 0 < n) : @Eq ℕ+ (⟨no_index (OfNat.ofNat n), h⟩ : ℕ+) (haveI : NeZero n := ⟨h.ne'⟩; OfNat.ofNat n) := rfl end PNat namespace Nat @[mono] theorem succPNat_strictMono : StrictMono succPNat := fun _ _ => Nat.succ_lt_succ #align nat.succ_pnat_strict_mono Nat.succPNat_strictMono @[mono] theorem succPNat_mono : Monotone succPNat := succPNat_strictMono.monotone #align nat.succ_pnat_mono Nat.succPNat_mono @[simp] theorem succPNat_lt_succPNat {m n : ℕ} : m.succPNat < n.succPNat ↔ m < n := succPNat_strictMono.lt_iff_lt #align nat.succ_pnat_lt_succ_pnat Nat.succPNat_lt_succPNat @[simp] theorem succPNat_le_succPNat {m n : ℕ} : m.succPNat ≤ n.succPNat ↔ m ≤ n := succPNat_strictMono.le_iff_le #align nat.succ_pnat_le_succ_pnat Nat.succPNat_le_succPNat theorem succPNat_injective : Function.Injective succPNat := succPNat_strictMono.injective #align nat.succ_pnat_injective Nat.succPNat_injective @[simp] theorem succPNat_inj {n m : ℕ} : succPNat n = succPNat m ↔ n = m := succPNat_injective.eq_iff #align nat.succ_pnat_inj Nat.succPNat_inj end Nat namespace PNat open Nat /-- We now define a long list of structures on `ℕ+` induced by similar structures on `ℕ`. Most of these behave in a completely obvious way, but there are a few things to be said about subtraction, division and powers. -/ @[simp, norm_cast] theorem coe_inj {m n : ℕ+} : (m : ℕ) = n ↔ m = n := SetCoe.ext_iff #align pnat.coe_inj PNat.coe_inj @[simp, norm_cast] theorem add_coe (m n : ℕ+) : ((m + n : ℕ+) : ℕ) = m + n := rfl #align pnat.add_coe PNat.add_coe /-- `coe` promoted to an `AddHom`, that is, a morphism which preserves addition. -/ def coeAddHom : AddHom ℕ+ ℕ where toFun := Coe.coe map_add' := add_coe #align pnat.coe_add_hom PNat.coeAddHom instance covariantClass_add_le : CovariantClass ℕ+ ℕ+ (· + ·) (· ≤ ·) := Positive.covariantClass_add_le instance covariantClass_add_lt : CovariantClass ℕ+ ℕ+ (· + ·) (· < ·) := Positive.covariantClass_add_lt instance contravariantClass_add_le : ContravariantClass ℕ+ ℕ+ (· + ·) (· ≤ ·) := Positive.contravariantClass_add_le instance contravariantClass_add_lt : ContravariantClass ℕ+ ℕ+ (· + ·) (· < ·) := Positive.contravariantClass_add_lt /-- An equivalence between `ℕ+` and `ℕ` given by `PNat.natPred` and `Nat.succPNat`. -/ @[simps (config := .asFn)] def _root_.Equiv.pnatEquivNat : ℕ+ ≃ ℕ where toFun := PNat.natPred invFun := Nat.succPNat left_inv := succPNat_natPred right_inv := Nat.natPred_succPNat #align equiv.pnat_equiv_nat Equiv.pnatEquivNat #align equiv.pnat_equiv_nat_symm_apply Equiv.pnatEquivNat_symm_apply #align equiv.pnat_equiv_nat_apply Equiv.pnatEquivNat_apply /-- The order isomorphism between ℕ and ℕ+ given by `succ`. -/ @[simps! (config := .asFn) apply] def _root_.OrderIso.pnatIsoNat : ℕ+ ≃o ℕ where toEquiv := Equiv.pnatEquivNat map_rel_iff' := natPred_le_natPred #align order_iso.pnat_iso_nat OrderIso.pnatIsoNat #align order_iso.pnat_iso_nat_apply OrderIso.pnatIsoNat_apply @[simp] theorem _root_.OrderIso.pnatIsoNat_symm_apply : OrderIso.pnatIsoNat.symm = Nat.succPNat := rfl #align order_iso.pnat_iso_nat_symm_apply OrderIso.pnatIsoNat_symm_apply theorem lt_add_one_iff : ∀ {a b : ℕ+}, a < b + 1 ↔ a ≤ b := Nat.lt_add_one_iff #align pnat.lt_add_one_iff PNat.lt_add_one_iff theorem add_one_le_iff : ∀ {a b : ℕ+}, a + 1 ≤ b ↔ a < b := Nat.add_one_le_iff #align pnat.add_one_le_iff PNat.add_one_le_iff instance instOrderBot : OrderBot ℕ+ where bot := 1 bot_le a := a.property @[simp] theorem bot_eq_one : (⊥ : ℕ+) = 1 := rfl #align pnat.bot_eq_one PNat.bot_eq_one /-- Strong induction on `ℕ+`, with `n = 1` treated separately. -/ def caseStrongInductionOn {p : ℕ+ → Sort*} (a : ℕ+) (hz : p 1) (hi : ∀ n, (∀ m, m ≤ n → p m) → p (n + 1)) : p a := by apply strongInductionOn a rintro ⟨k, kprop⟩ hk cases' k with k · exact (lt_irrefl 0 kprop).elim cases' k with k · exact hz exact hi ⟨k.succ, Nat.succ_pos _⟩ fun m hm => hk _ (Nat.lt_succ_iff.2 hm) #align pnat.case_strong_induction_on PNat.caseStrongInductionOn /-- An induction principle for `ℕ+`: it takes values in `Sort*`, so it applies also to Types, not only to `Prop`. -/ @[elab_as_elim] def recOn (n : ℕ+) {p : ℕ+ → Sort*} (p1 : p 1) (hp : ∀ n, p n → p (n + 1)) : p n := by rcases n with ⟨n, h⟩ induction' n with n IH · exact absurd h (by decide) · cases' n with n · exact p1 · exact hp _ (IH n.succ_pos) #align pnat.rec_on PNat.recOn @[simp] theorem recOn_one {p} (p1 hp) : @PNat.recOn 1 p p1 hp = p1 := rfl #align pnat.rec_on_one PNat.recOn_one @[simp]
Mathlib/Data/PNat/Basic.lean
220
223
theorem recOn_succ (n : ℕ+) {p : ℕ+ → Sort*} (p1 hp) : @PNat.recOn (n + 1) p p1 hp = hp n (@PNat.recOn n p p1 hp) := by
cases' n with n h cases n <;> [exact absurd h (by decide); rfl]
/- 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.Topology.Algebra.Constructions import Mathlib.Topology.Bases import Mathlib.Topology.UniformSpace.Basic #align_import topology.uniform_space.cauchy from "leanprover-community/mathlib"@"22131150f88a2d125713ffa0f4693e3355b1eb49" /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ universe u v open scoped Classical open Filter TopologicalSpace Set UniformSpace Function open scoped Classical open Uniformity Topology Filter variable {α : Type u} {β : Type v} [uniformSpace : UniformSpace α] /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy sequences, because if `a : ℕ → α` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def Cauchy (f : Filter α) := NeBot f ∧ f ×ˢ f ≤ 𝓤 α #align cauchy Cauchy /-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f` has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/ def IsComplete (s : Set α) := ∀ f, Cauchy f → f ≤ 𝓟 s → ∃ x ∈ s, f ≤ 𝓝 x #align is_complete IsComplete theorem Filter.HasBasis.cauchy_iff {ι} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ i, p i → ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s i := and_congr Iff.rfl <| (f.basis_sets.prod_self.le_basis_iff h).trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] #align filter.has_basis.cauchy_iff Filter.HasBasis.cauchy_iff theorem cauchy_iff' {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s := (𝓤 α).basis_sets.cauchy_iff #align cauchy_iff' cauchy_iff' theorem cauchy_iff {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s := cauchy_iff'.trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] #align cauchy_iff cauchy_iff lemma cauchy_iff_le {l : Filter α} [hl : l.NeBot] : Cauchy l ↔ l ×ˢ l ≤ 𝓤 α := by simp only [Cauchy, hl, true_and] theorem Cauchy.ultrafilter_of {l : Filter α} (h : Cauchy l) : Cauchy (@Ultrafilter.of _ l h.1 : Filter α) := by haveI := h.1 have := Ultrafilter.of_le l exact ⟨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2⟩ #align cauchy.ultrafilter_of Cauchy.ultrafilter_of theorem cauchy_map_iff {l : Filter β} {f : β → α} : Cauchy (l.map f) ↔ NeBot l ∧ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := by rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto] #align cauchy_map_iff cauchy_map_iff theorem cauchy_map_iff' {l : Filter β} [hl : NeBot l] {f : β → α} : Cauchy (l.map f) ↔ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := cauchy_map_iff.trans <| and_iff_right hl #align cauchy_map_iff' cauchy_map_iff' theorem Cauchy.mono {f g : Filter α} [hg : NeBot g] (h_c : Cauchy f) (h_le : g ≤ f) : Cauchy g := ⟨hg, le_trans (Filter.prod_mono h_le h_le) h_c.right⟩ #align cauchy.mono Cauchy.mono theorem Cauchy.mono' {f g : Filter α} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≤ f) : Cauchy g := h_c.mono h_le #align cauchy.mono' Cauchy.mono' theorem cauchy_nhds {a : α} : Cauchy (𝓝 a) := ⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩ #align cauchy_nhds cauchy_nhds theorem cauchy_pure {a : α} : Cauchy (pure a) := cauchy_nhds.mono (pure_le_nhds a) #align cauchy_pure cauchy_pure theorem Filter.Tendsto.cauchy_map {l : Filter β} [NeBot l] {f : β → α} {a : α} (h : Tendsto f l (𝓝 a)) : Cauchy (map f l) := cauchy_nhds.mono h #align filter.tendsto.cauchy_map Filter.Tendsto.cauchy_map lemma Cauchy.mono_uniformSpace {u v : UniformSpace β} {F : Filter β} (huv : u ≤ v) (hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F := ⟨hF.1, hF.2.trans huv⟩ lemma cauchy_inf_uniformSpace {u v : UniformSpace β} {F : Filter β} : Cauchy (uniformSpace := u ⊓ v) F ↔ Cauchy (uniformSpace := u) F ∧ Cauchy (uniformSpace := v) F := by unfold Cauchy rw [inf_uniformity (u := u), le_inf_iff, and_and_left] lemma cauchy_iInf_uniformSpace {ι : Sort*} [Nonempty ι] {u : ι → UniformSpace β} {l : Filter β} : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by unfold Cauchy rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const] lemma cauchy_iInf_uniformSpace' {ι : Sort*} {u : ι → UniformSpace β} {l : Filter β} [l.NeBot] : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff] lemma cauchy_comap_uniformSpace {u : UniformSpace β} {f : α → β} {l : Filter α} : Cauchy (uniformSpace := comap f u) l ↔ Cauchy (map f l) := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap] rfl lemma cauchy_prod_iff [UniformSpace β] {F : Filter (α × β)} : Cauchy F ↔ Cauchy (map Prod.fst F) ∧ Cauchy (map Prod.snd F) := by simp_rw [instUniformSpaceProd, ← cauchy_comap_uniformSpace, ← cauchy_inf_uniformSpace] theorem Cauchy.prod [UniformSpace β] {f : Filter α} {g : Filter β} (hf : Cauchy f) (hg : Cauchy g) : Cauchy (f ×ˢ g) := by have := hf.1; have := hg.1 simpa [cauchy_prod_iff, hf.1] using ⟨hf, hg⟩ #align cauchy.prod Cauchy.prod /-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and `SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s` one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y` with `(x, y) ∈ s`, then `f` converges to `x`. -/ theorem le_nhds_of_cauchy_adhp_aux {f : Filter α} {x : α} (adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s ∧ ∃ y, (x, y) ∈ s ∧ y ∈ t) : f ≤ 𝓝 x := by -- Consider a neighborhood `s` of `x` intro s hs -- Take an entourage twice smaller than `s` rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩ -- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U` rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩ apply mem_of_superset t_mem -- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s` exact fun z hz => hU (prod_mk_mem_compRel hxy (ht <| mk_mem_prod hy hz)) rfl #align le_nhds_of_cauchy_adhp_aux le_nhds_of_cauchy_adhp_aux /-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point for `f`. -/ theorem le_nhds_of_cauchy_adhp {f : Filter α} {x : α} (hf : Cauchy f) (adhs : ClusterPt x f) : f ≤ 𝓝 x := le_nhds_of_cauchy_adhp_aux (fun s hs => by obtain ⟨t, t_mem, ht⟩ : ∃ t ∈ f, t ×ˢ t ⊆ s := (cauchy_iff.1 hf).2 s hs use t, t_mem, ht exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem)) #align le_nhds_of_cauchy_adhp le_nhds_of_cauchy_adhp theorem le_nhds_iff_adhp_of_cauchy {f : Filter α} {x : α} (hf : Cauchy f) : f ≤ 𝓝 x ↔ ClusterPt x f := ⟨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩ #align le_nhds_iff_adhp_of_cauchy le_nhds_iff_adhp_of_cauchy nonrec theorem Cauchy.map [UniformSpace β] {f : Filter α} {m : α → β} (hf : Cauchy f) (hm : UniformContinuous m) : Cauchy (map m f) := ⟨hf.1.map _, calc map m f ×ˢ map m f = map (Prod.map m m) (f ×ˢ f) := Filter.prod_map_map_eq _ ≤ Filter.map (Prod.map m m) (𝓤 α) := map_mono hf.right _ ≤ 𝓤 β := hm⟩ #align cauchy.map Cauchy.map nonrec theorem Cauchy.comap [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) [NeBot (comap m f)] : Cauchy (comap m f) := ⟨‹_›, calc comap m f ×ˢ comap m f = comap (Prod.map m m) (f ×ˢ f) := prod_comap_comap_eq _ ≤ comap (Prod.map m m) (𝓤 β) := comap_mono hf.right _ ≤ 𝓤 α := hm⟩ #align cauchy.comap Cauchy.comap theorem Cauchy.comap' [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : Filter.comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) (_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) := hf.comap hm #align cauchy.comap' Cauchy.comap' /-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/ def CauchySeq [Preorder β] (u : β → α) := Cauchy (atTop.map u) #align cauchy_seq CauchySeq
Mathlib/Topology/UniformSpace/Cauchy.lean
202
204
theorem CauchySeq.tendsto_uniformity [Preorder β] {u : β → α} (h : CauchySeq u) : Tendsto (Prod.map u u) atTop (𝓤 α) := by
simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot -/ import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Algebra.Order.Interval.Set.Monoid import Mathlib.Data.Set.Pointwise.Basic import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax #align_import data.set.pointwise.interval from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # (Pre)images of intervals In this file we prove a bunch of trivial lemmas like “if we add `a` to all points of `[b, c]`, then we get `[a + b, a + c]`”. For the functions `x ↦ x ± a`, `x ↦ a ± x`, and `x ↦ -x` we prove lemmas about preimages and images of all intervals. We also prove a few lemmas about images under `x ↦ a * x`, `x ↦ x * a` and `x ↦ x⁻¹`. -/ open Interval Pointwise variable {α : Type*} namespace Set /-! ### Binary pointwise operations Note that the subset operations below only cover the cases with the largest possible intervals on the LHS: to conclude that `Ioo a b * Ioo c d ⊆ Ioo (a * c) (c * d)`, you can use monotonicity of `*` and `Set.Ico_mul_Ioc_subset`. TODO: repeat these lemmas for the generality of `mul_le_mul` (which assumes nonnegativity), which the unprimed names have been reserved for -/ section ContravariantLE variable [Mul α] [Preorder α] variable [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (Function.swap HMul.hMul) LE.le] @[to_additive Icc_add_Icc_subset] theorem Icc_mul_Icc_subset' (a b c d : α) : Icc a b * Icc c d ⊆ Icc (a * c) (b * d) := by rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_le_mul' hyb hzd⟩ @[to_additive Iic_add_Iic_subset] theorem Iic_mul_Iic_subset' (a b : α) : Iic a * Iic b ⊆ Iic (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb @[to_additive Ici_add_Ici_subset] theorem Ici_mul_Ici_subset' (a b : α) : Ici a * Ici b ⊆ Ici (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb end ContravariantLE section ContravariantLT variable [Mul α] [PartialOrder α] variable [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (Function.swap HMul.hMul) LT.lt] @[to_additive Icc_add_Ico_subset] theorem Icc_mul_Ico_subset' (a b c d : α) : Icc a b * Ico c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Icc_subset] theorem Ico_mul_Icc_subset' (a b c d : α) : Ico a b * Icc c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Ioc_add_Ico_subset] theorem Ioc_mul_Ico_subset' (a b c d : α) : Ioc a b * Ico c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_lt_of_le hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Ioc_subset] theorem Ico_mul_Ioc_subset' (a b c d : α) : Ico a b * Ioc c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_le_of_lt hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Iic_add_Iio_subset] theorem Iic_mul_Iio_subset' (a b : α) : Iic a * Iio b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb @[to_additive Iio_add_Iic_subset] theorem Iio_mul_Iic_subset' (a b : α) : Iio a * Iic b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ioi_add_Ici_subset] theorem Ioi_mul_Ici_subset' (a b : α) : Ioi a * Ici b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ici_add_Ioi_subset] theorem Ici_mul_Ioi_subset' (a b : α) : Ici a * Ioi b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb end ContravariantLT section OrderedAddCommGroup variable [OrderedAddCommGroup α] (a b c : α) /-! ### Preimages under `x ↦ a + x` -/ @[simp] theorem preimage_const_add_Ici : (fun x => a + x) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add'.symm #align set.preimage_const_add_Ici Set.preimage_const_add_Ici @[simp] theorem preimage_const_add_Ioi : (fun x => a + x) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add'.symm #align set.preimage_const_add_Ioi Set.preimage_const_add_Ioi @[simp] theorem preimage_const_add_Iic : (fun x => a + x) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le'.symm #align set.preimage_const_add_Iic Set.preimage_const_add_Iic @[simp] theorem preimage_const_add_Iio : (fun x => a + x) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt'.symm #align set.preimage_const_add_Iio Set.preimage_const_add_Iio @[simp] theorem preimage_const_add_Icc : (fun x => a + x) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_const_add_Icc Set.preimage_const_add_Icc @[simp] theorem preimage_const_add_Ico : (fun x => a + x) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_const_add_Ico Set.preimage_const_add_Ico @[simp] theorem preimage_const_add_Ioc : (fun x => a + x) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_const_add_Ioc Set.preimage_const_add_Ioc @[simp] theorem preimage_const_add_Ioo : (fun x => a + x) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_const_add_Ioo Set.preimage_const_add_Ioo /-! ### Preimages under `x ↦ x + a` -/ @[simp] theorem preimage_add_const_Ici : (fun x => x + a) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add.symm #align set.preimage_add_const_Ici Set.preimage_add_const_Ici @[simp] theorem preimage_add_const_Ioi : (fun x => x + a) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add.symm #align set.preimage_add_const_Ioi Set.preimage_add_const_Ioi @[simp] theorem preimage_add_const_Iic : (fun x => x + a) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le.symm #align set.preimage_add_const_Iic Set.preimage_add_const_Iic @[simp] theorem preimage_add_const_Iio : (fun x => x + a) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt.symm #align set.preimage_add_const_Iio Set.preimage_add_const_Iio @[simp] theorem preimage_add_const_Icc : (fun x => x + a) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_add_const_Icc Set.preimage_add_const_Icc @[simp] theorem preimage_add_const_Ico : (fun x => x + a) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_add_const_Ico Set.preimage_add_const_Ico @[simp] theorem preimage_add_const_Ioc : (fun x => x + a) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_add_const_Ioc Set.preimage_add_const_Ioc @[simp] theorem preimage_add_const_Ioo : (fun x => x + a) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_add_const_Ioo Set.preimage_add_const_Ioo /-! ### Preimages under `x ↦ -x` -/ @[simp] theorem preimage_neg_Ici : -Ici a = Iic (-a) := ext fun _x => le_neg #align set.preimage_neg_Ici Set.preimage_neg_Ici @[simp] theorem preimage_neg_Iic : -Iic a = Ici (-a) := ext fun _x => neg_le #align set.preimage_neg_Iic Set.preimage_neg_Iic @[simp] theorem preimage_neg_Ioi : -Ioi a = Iio (-a) := ext fun _x => lt_neg #align set.preimage_neg_Ioi Set.preimage_neg_Ioi @[simp] theorem preimage_neg_Iio : -Iio a = Ioi (-a) := ext fun _x => neg_lt #align set.preimage_neg_Iio Set.preimage_neg_Iio @[simp] theorem preimage_neg_Icc : -Icc a b = Icc (-b) (-a) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_neg_Icc Set.preimage_neg_Icc @[simp] theorem preimage_neg_Ico : -Ico a b = Ioc (-b) (-a) := by simp [← Ici_inter_Iio, ← Ioi_inter_Iic, inter_comm] #align set.preimage_neg_Ico Set.preimage_neg_Ico @[simp] theorem preimage_neg_Ioc : -Ioc a b = Ico (-b) (-a) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_neg_Ioc Set.preimage_neg_Ioc @[simp] theorem preimage_neg_Ioo : -Ioo a b = Ioo (-b) (-a) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_neg_Ioo Set.preimage_neg_Ioo /-! ### Preimages under `x ↦ x - a` -/ @[simp] theorem preimage_sub_const_Ici : (fun x => x - a) ⁻¹' Ici b = Ici (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ici Set.preimage_sub_const_Ici @[simp] theorem preimage_sub_const_Ioi : (fun x => x - a) ⁻¹' Ioi b = Ioi (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioi Set.preimage_sub_const_Ioi @[simp] theorem preimage_sub_const_Iic : (fun x => x - a) ⁻¹' Iic b = Iic (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iic Set.preimage_sub_const_Iic @[simp] theorem preimage_sub_const_Iio : (fun x => x - a) ⁻¹' Iio b = Iio (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iio Set.preimage_sub_const_Iio @[simp] theorem preimage_sub_const_Icc : (fun x => x - a) ⁻¹' Icc b c = Icc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Icc Set.preimage_sub_const_Icc @[simp] theorem preimage_sub_const_Ico : (fun x => x - a) ⁻¹' Ico b c = Ico (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ico Set.preimage_sub_const_Ico @[simp] theorem preimage_sub_const_Ioc : (fun x => x - a) ⁻¹' Ioc b c = Ioc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioc Set.preimage_sub_const_Ioc @[simp] theorem preimage_sub_const_Ioo : (fun x => x - a) ⁻¹' Ioo b c = Ioo (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioo Set.preimage_sub_const_Ioo /-! ### Preimages under `x ↦ a - x` -/ @[simp] theorem preimage_const_sub_Ici : (fun x => a - x) ⁻¹' Ici b = Iic (a - b) := ext fun _x => le_sub_comm #align set.preimage_const_sub_Ici Set.preimage_const_sub_Ici @[simp] theorem preimage_const_sub_Iic : (fun x => a - x) ⁻¹' Iic b = Ici (a - b) := ext fun _x => sub_le_comm #align set.preimage_const_sub_Iic Set.preimage_const_sub_Iic @[simp] theorem preimage_const_sub_Ioi : (fun x => a - x) ⁻¹' Ioi b = Iio (a - b) := ext fun _x => lt_sub_comm #align set.preimage_const_sub_Ioi Set.preimage_const_sub_Ioi @[simp] theorem preimage_const_sub_Iio : (fun x => a - x) ⁻¹' Iio b = Ioi (a - b) := ext fun _x => sub_lt_comm #align set.preimage_const_sub_Iio Set.preimage_const_sub_Iio @[simp] theorem preimage_const_sub_Icc : (fun x => a - x) ⁻¹' Icc b c = Icc (a - c) (a - b) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_const_sub_Icc Set.preimage_const_sub_Icc @[simp] theorem preimage_const_sub_Ico : (fun x => a - x) ⁻¹' Ico b c = Ioc (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ico Set.preimage_const_sub_Ico @[simp] theorem preimage_const_sub_Ioc : (fun x => a - x) ⁻¹' Ioc b c = Ico (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioc Set.preimage_const_sub_Ioc @[simp] theorem preimage_const_sub_Ioo : (fun x => a - x) ⁻¹' Ioo b c = Ioo (a - c) (a - b) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioo Set.preimage_const_sub_Ioo /-! ### Images under `x ↦ a + x` -/ -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iic : (fun x => a + x) '' Iic b = Iic (a + b) := by simp [add_comm] #align set.image_const_add_Iic Set.image_const_add_Iic -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iio : (fun x => a + x) '' Iio b = Iio (a + b) := by simp [add_comm] #align set.image_const_add_Iio Set.image_const_add_Iio /-! ### Images under `x ↦ x + a` -/ -- @[simp] -- Porting note (#10618): simp can prove this
Mathlib/Data/Set/Pointwise/Interval.lean
363
363
theorem image_add_const_Iic : (fun x => x + a) '' Iic b = Iic (b + a) := by
simp
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.ModelTheory.Substructures #align_import model_theory.finitely_generated from "leanprover-community/mathlib"@"0602c59878ff3d5f71dea69c2d32ccf2e93e5398" /-! # Finitely Generated First-Order Structures This file defines what it means for a first-order (sub)structure to be finitely or countably generated, similarly to other finitely-generated objects in the algebra library. ## Main Definitions * `FirstOrder.Language.Substructure.FG` indicates that a substructure is finitely generated. * `FirstOrder.Language.Structure.FG` indicates that a structure is finitely generated. * `FirstOrder.Language.Substructure.CG` indicates that a substructure is countably generated. * `FirstOrder.Language.Structure.CG` indicates that a structure is countably generated. ## TODO Develop a more unified definition of finite generation using the theory of closure operators, or use this definition of finite generation to define the others. -/ open FirstOrder Set namespace FirstOrder namespace Language open Structure variable {L : Language} {M : Type*} [L.Structure M] namespace Substructure /-- A substructure of `M` is finitely generated if it is the closure of a finite subset of `M`. -/ def FG (N : L.Substructure M) : Prop := ∃ S : Finset M, closure L S = N #align first_order.language.substructure.fg FirstOrder.Language.Substructure.FG theorem fg_def {N : L.Substructure M} : N.FG ↔ ∃ S : Set M, S.Finite ∧ closure L S = N := ⟨fun ⟨t, h⟩ => ⟨_, Finset.finite_toSet t, h⟩, by rintro ⟨t', h, rfl⟩ rcases Finite.exists_finset_coe h with ⟨t, rfl⟩ exact ⟨t, rfl⟩⟩ #align first_order.language.substructure.fg_def FirstOrder.Language.Substructure.fg_def theorem fg_iff_exists_fin_generating_family {N : L.Substructure M} : N.FG ↔ ∃ (n : ℕ) (s : Fin n → M), closure L (range s) = N := by rw [fg_def] constructor · rintro ⟨S, Sfin, hS⟩ obtain ⟨n, f, rfl⟩ := Sfin.fin_embedding exact ⟨n, f, hS⟩ · rintro ⟨n, s, hs⟩ exact ⟨range s, finite_range s, hs⟩ #align first_order.language.substructure.fg_iff_exists_fin_generating_family FirstOrder.Language.Substructure.fg_iff_exists_fin_generating_family theorem fg_bot : (⊥ : L.Substructure M).FG := ⟨∅, by rw [Finset.coe_empty, closure_empty]⟩ #align first_order.language.substructure.fg_bot FirstOrder.Language.Substructure.fg_bot theorem fg_closure {s : Set M} (hs : s.Finite) : FG (closure L s) := ⟨hs.toFinset, by rw [hs.coe_toFinset]⟩ #align first_order.language.substructure.fg_closure FirstOrder.Language.Substructure.fg_closure theorem fg_closure_singleton (x : M) : FG (closure L ({x} : Set M)) := fg_closure (finite_singleton x) #align first_order.language.substructure.fg_closure_singleton FirstOrder.Language.Substructure.fg_closure_singleton theorem FG.sup {N₁ N₂ : L.Substructure M} (hN₁ : N₁.FG) (hN₂ : N₂.FG) : (N₁ ⊔ N₂).FG := let ⟨t₁, ht₁⟩ := fg_def.1 hN₁ let ⟨t₂, ht₂⟩ := fg_def.1 hN₂ fg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [closure_union, ht₁.2, ht₂.2]⟩ #align first_order.language.substructure.fg.sup FirstOrder.Language.Substructure.FG.sup theorem FG.map {N : Type*} [L.Structure N] (f : M →[L] N) {s : L.Substructure M} (hs : s.FG) : (s.map f).FG := let ⟨t, ht⟩ := fg_def.1 hs fg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩ #align first_order.language.substructure.fg.map FirstOrder.Language.Substructure.FG.map theorem FG.of_map_embedding {N : Type*} [L.Structure N] (f : M ↪[L] N) {s : L.Substructure M} (hs : (s.map f.toHom).FG) : s.FG := by rcases hs with ⟨t, h⟩ rw [fg_def] refine ⟨f ⁻¹' t, t.finite_toSet.preimage f.injective.injOn, ?_⟩ have hf : Function.Injective f.toHom := f.injective refine map_injective_of_injective hf ?_ rw [← h, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset] intro x hx have h' := subset_closure (L := L) hx rw [h] at h' exact Hom.map_le_range h' #align first_order.language.substructure.fg.of_map_embedding FirstOrder.Language.Substructure.FG.of_map_embedding /-- A substructure of `M` is countably generated if it is the closure of a countable subset of `M`. -/ def CG (N : L.Substructure M) : Prop := ∃ S : Set M, S.Countable ∧ closure L S = N #align first_order.language.substructure.cg FirstOrder.Language.Substructure.CG theorem cg_def {N : L.Substructure M} : N.CG ↔ ∃ S : Set M, S.Countable ∧ closure L S = N := Iff.refl _ #align first_order.language.substructure.cg_def FirstOrder.Language.Substructure.cg_def
Mathlib/ModelTheory/FinitelyGenerated.lean
111
113
theorem FG.cg {N : L.Substructure M} (h : N.FG) : N.CG := by
obtain ⟨s, hf, rfl⟩ := fg_def.1 h exact ⟨s, hf.countable, rfl⟩
/- Copyright (c) 2020 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Data.Real.Sqrt import Mathlib.Analysis.NormedSpace.Star.Basic import Mathlib.Analysis.NormedSpace.ContinuousLinearMap import Mathlib.Analysis.NormedSpace.Basic #align_import data.is_R_or_C.basic from "leanprover-community/mathlib"@"baa88307f3e699fa7054ef04ec79fa4f056169cb" /-! # `RCLike`: a typeclass for ℝ or ℂ This file defines the typeclass `RCLike` intended to have only two instances: ℝ and ℂ. It is meant for definitions and theorems which hold for both the real and the complex case, and in particular when the real case follows directly from the complex case by setting `re` to `id`, `im` to zero and so on. Its API follows closely that of ℂ. Applications include defining inner products and Hilbert spaces for both the real and complex case. One typically produces the definitions and proof for an arbitrary field of this typeclass, which basically amounts to doing the complex case, and the two cases then fall out immediately from the two instances of the class. The instance for `ℝ` is registered in this file. The instance for `ℂ` is declared in `Mathlib/Analysis/Complex/Basic.lean`. ## Implementation notes The coercion from reals into an `RCLike` field is done by registering `RCLike.ofReal` as a `CoeTC`. For this to work, we must proceed carefully to avoid problems involving circular coercions in the case `K=ℝ`; in particular, we cannot use the plain `Coe` and must set priorities carefully. This problem was already solved for `ℕ`, and we copy the solution detailed in `Mathlib/Data/Nat/Cast/Defs.lean`. See also Note [coercion into rings] for more details. In addition, several lemmas need to be set at priority 900 to make sure that they do not override their counterparts in `Mathlib/Analysis/Complex/Basic.lean` (which causes linter errors). A few lemmas requiring heavier imports are in `Mathlib/Data/RCLike/Lemmas.lean`. -/ section local notation "𝓚" => algebraMap ℝ _ open ComplexConjugate /-- This typeclass captures properties shared by ℝ and ℂ, with an API that closely matches that of ℂ. -/ class RCLike (K : semiOutParam Type*) extends DenselyNormedField K, StarRing K, NormedAlgebra ℝ K, CompleteSpace K where re : K →+ ℝ im : K →+ ℝ /-- Imaginary unit in `K`. Meant to be set to `0` for `K = ℝ`. -/ I : K I_re_ax : re I = 0 I_mul_I_ax : I = 0 ∨ I * I = -1 re_add_im_ax : ∀ z : K, 𝓚 (re z) + 𝓚 (im z) * I = z ofReal_re_ax : ∀ r : ℝ, re (𝓚 r) = r ofReal_im_ax : ∀ r : ℝ, im (𝓚 r) = 0 mul_re_ax : ∀ z w : K, re (z * w) = re z * re w - im z * im w mul_im_ax : ∀ z w : K, im (z * w) = re z * im w + im z * re w conj_re_ax : ∀ z : K, re (conj z) = re z conj_im_ax : ∀ z : K, im (conj z) = -im z conj_I_ax : conj I = -I norm_sq_eq_def_ax : ∀ z : K, ‖z‖ ^ 2 = re z * re z + im z * im z mul_im_I_ax : ∀ z : K, im z * im I = im z /-- only an instance in the `ComplexOrder` locale -/ [toPartialOrder : PartialOrder K] le_iff_re_im {z w : K} : z ≤ w ↔ re z ≤ re w ∧ im z = im w -- note we cannot put this in the `extends` clause [toDecidableEq : DecidableEq K] #align is_R_or_C RCLike scoped[ComplexOrder] attribute [instance 100] RCLike.toPartialOrder attribute [instance 100] RCLike.toDecidableEq end variable {K E : Type*} [RCLike K] namespace RCLike open ComplexConjugate /-- Coercion from `ℝ` to an `RCLike` field. -/ @[coe] abbrev ofReal : ℝ → K := Algebra.cast /- The priority must be set at 900 to ensure that coercions are tried in the right order. See Note [coercion into rings], or `Mathlib/Data/Nat/Cast/Basic.lean` for more details. -/ noncomputable instance (priority := 900) algebraMapCoe : CoeTC ℝ K := ⟨ofReal⟩ #align is_R_or_C.algebra_map_coe RCLike.algebraMapCoe theorem ofReal_alg (x : ℝ) : (x : K) = x • (1 : K) := Algebra.algebraMap_eq_smul_one x #align is_R_or_C.of_real_alg RCLike.ofReal_alg theorem real_smul_eq_coe_mul (r : ℝ) (z : K) : r • z = (r : K) * z := Algebra.smul_def r z #align is_R_or_C.real_smul_eq_coe_mul RCLike.real_smul_eq_coe_mul theorem real_smul_eq_coe_smul [AddCommGroup E] [Module K E] [Module ℝ E] [IsScalarTower ℝ K E] (r : ℝ) (x : E) : r • x = (r : K) • x := by rw [RCLike.ofReal_alg, smul_one_smul] #align is_R_or_C.real_smul_eq_coe_smul RCLike.real_smul_eq_coe_smul theorem algebraMap_eq_ofReal : ⇑(algebraMap ℝ K) = ofReal := rfl #align is_R_or_C.algebra_map_eq_of_real RCLike.algebraMap_eq_ofReal @[simp, rclike_simps] theorem re_add_im (z : K) : (re z : K) + im z * I = z := RCLike.re_add_im_ax z #align is_R_or_C.re_add_im RCLike.re_add_im @[simp, norm_cast, rclike_simps] theorem ofReal_re : ∀ r : ℝ, re (r : K) = r := RCLike.ofReal_re_ax #align is_R_or_C.of_real_re RCLike.ofReal_re @[simp, norm_cast, rclike_simps] theorem ofReal_im : ∀ r : ℝ, im (r : K) = 0 := RCLike.ofReal_im_ax #align is_R_or_C.of_real_im RCLike.ofReal_im @[simp, rclike_simps] theorem mul_re : ∀ z w : K, re (z * w) = re z * re w - im z * im w := RCLike.mul_re_ax #align is_R_or_C.mul_re RCLike.mul_re @[simp, rclike_simps] theorem mul_im : ∀ z w : K, im (z * w) = re z * im w + im z * re w := RCLike.mul_im_ax #align is_R_or_C.mul_im RCLike.mul_im theorem ext_iff {z w : K} : z = w ↔ re z = re w ∧ im z = im w := ⟨fun h => h ▸ ⟨rfl, rfl⟩, fun ⟨h₁, h₂⟩ => re_add_im z ▸ re_add_im w ▸ h₁ ▸ h₂ ▸ rfl⟩ #align is_R_or_C.ext_iff RCLike.ext_iff theorem ext {z w : K} (hre : re z = re w) (him : im z = im w) : z = w := ext_iff.2 ⟨hre, him⟩ #align is_R_or_C.ext RCLike.ext @[norm_cast] theorem ofReal_zero : ((0 : ℝ) : K) = 0 := algebraMap.coe_zero #align is_R_or_C.of_real_zero RCLike.ofReal_zero @[rclike_simps] theorem zero_re' : re (0 : K) = (0 : ℝ) := map_zero re #align is_R_or_C.zero_re' RCLike.zero_re' @[norm_cast] theorem ofReal_one : ((1 : ℝ) : K) = 1 := map_one (algebraMap ℝ K) #align is_R_or_C.of_real_one RCLike.ofReal_one @[simp, rclike_simps] theorem one_re : re (1 : K) = 1 := by rw [← ofReal_one, ofReal_re] #align is_R_or_C.one_re RCLike.one_re @[simp, rclike_simps] theorem one_im : im (1 : K) = 0 := by rw [← ofReal_one, ofReal_im] #align is_R_or_C.one_im RCLike.one_im theorem ofReal_injective : Function.Injective ((↑) : ℝ → K) := (algebraMap ℝ K).injective #align is_R_or_C.of_real_injective RCLike.ofReal_injective @[norm_cast] theorem ofReal_inj {z w : ℝ} : (z : K) = (w : K) ↔ z = w := algebraMap.coe_inj #align is_R_or_C.of_real_inj RCLike.ofReal_inj -- replaced by `RCLike.ofNat_re` #noalign is_R_or_C.bit0_re #noalign is_R_or_C.bit1_re -- replaced by `RCLike.ofNat_im` #noalign is_R_or_C.bit0_im #noalign is_R_or_C.bit1_im theorem ofReal_eq_zero {x : ℝ} : (x : K) = 0 ↔ x = 0 := algebraMap.lift_map_eq_zero_iff x #align is_R_or_C.of_real_eq_zero RCLike.ofReal_eq_zero theorem ofReal_ne_zero {x : ℝ} : (x : K) ≠ 0 ↔ x ≠ 0 := ofReal_eq_zero.not #align is_R_or_C.of_real_ne_zero RCLike.ofReal_ne_zero @[simp, rclike_simps, norm_cast] theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : K) = r + s := algebraMap.coe_add _ _ #align is_R_or_C.of_real_add RCLike.ofReal_add -- replaced by `RCLike.ofReal_ofNat` #noalign is_R_or_C.of_real_bit0 #noalign is_R_or_C.of_real_bit1 @[simp, norm_cast, rclike_simps] theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : K) = -r := algebraMap.coe_neg r #align is_R_or_C.of_real_neg RCLike.ofReal_neg @[simp, norm_cast, rclike_simps] theorem ofReal_sub (r s : ℝ) : ((r - s : ℝ) : K) = r - s := map_sub (algebraMap ℝ K) r s #align is_R_or_C.of_real_sub RCLike.ofReal_sub @[simp, rclike_simps, norm_cast] theorem ofReal_sum {α : Type*} (s : Finset α) (f : α → ℝ) : ((∑ i ∈ s, f i : ℝ) : K) = ∑ i ∈ s, (f i : K) := map_sum (algebraMap ℝ K) _ _ #align is_R_or_C.of_real_sum RCLike.ofReal_sum @[simp, rclike_simps, norm_cast] theorem ofReal_finsupp_sum {α M : Type*} [Zero M] (f : α →₀ M) (g : α → M → ℝ) : ((f.sum fun a b => g a b : ℝ) : K) = f.sum fun a b => (g a b : K) := map_finsupp_sum (algebraMap ℝ K) f g #align is_R_or_C.of_real_finsupp_sum RCLike.ofReal_finsupp_sum @[simp, norm_cast, rclike_simps] theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : K) = r * s := algebraMap.coe_mul _ _ #align is_R_or_C.of_real_mul RCLike.ofReal_mul @[simp, norm_cast, rclike_simps] theorem ofReal_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : K) = (r : K) ^ n := map_pow (algebraMap ℝ K) r n #align is_R_or_C.of_real_pow RCLike.ofReal_pow @[simp, rclike_simps, norm_cast] theorem ofReal_prod {α : Type*} (s : Finset α) (f : α → ℝ) : ((∏ i ∈ s, f i : ℝ) : K) = ∏ i ∈ s, (f i : K) := map_prod (algebraMap ℝ K) _ _ #align is_R_or_C.of_real_prod RCLike.ofReal_prod @[simp, rclike_simps, norm_cast] theorem ofReal_finsupp_prod {α M : Type*} [Zero M] (f : α →₀ M) (g : α → M → ℝ) : ((f.prod fun a b => g a b : ℝ) : K) = f.prod fun a b => (g a b : K) := map_finsupp_prod _ f g #align is_R_or_C.of_real_finsupp_prod RCLike.ofReal_finsupp_prod @[simp, norm_cast, rclike_simps] theorem real_smul_ofReal (r x : ℝ) : r • (x : K) = (r : K) * (x : K) := real_smul_eq_coe_mul _ _ #align is_R_or_C.real_smul_of_real RCLike.real_smul_ofReal @[rclike_simps] theorem re_ofReal_mul (r : ℝ) (z : K) : re (↑r * z) = r * re z := by simp only [mul_re, ofReal_im, zero_mul, ofReal_re, sub_zero] #align is_R_or_C.of_real_mul_re RCLike.re_ofReal_mul @[rclike_simps] theorem im_ofReal_mul (r : ℝ) (z : K) : im (↑r * z) = r * im z := by simp only [add_zero, ofReal_im, zero_mul, ofReal_re, mul_im] #align is_R_or_C.of_real_mul_im RCLike.im_ofReal_mul @[rclike_simps] theorem smul_re (r : ℝ) (z : K) : re (r • z) = r * re z := by rw [real_smul_eq_coe_mul, re_ofReal_mul] #align is_R_or_C.smul_re RCLike.smul_re @[rclike_simps] theorem smul_im (r : ℝ) (z : K) : im (r • z) = r * im z := by rw [real_smul_eq_coe_mul, im_ofReal_mul] #align is_R_or_C.smul_im RCLike.smul_im @[simp, norm_cast, rclike_simps] theorem norm_ofReal (r : ℝ) : ‖(r : K)‖ = |r| := norm_algebraMap' K r #align is_R_or_C.norm_of_real RCLike.norm_ofReal /-! ### Characteristic zero -/ -- see Note [lower instance priority] /-- ℝ and ℂ are both of characteristic zero. -/ instance (priority := 100) charZero_rclike : CharZero K := (RingHom.charZero_iff (algebraMap ℝ K).injective).1 inferInstance set_option linter.uppercaseLean3 false in #align is_R_or_C.char_zero_R_or_C RCLike.charZero_rclike /-! ### The imaginary unit, `I` -/ /-- The imaginary unit. -/ @[simp, rclike_simps] theorem I_re : re (I : K) = 0 := I_re_ax set_option linter.uppercaseLean3 false in #align is_R_or_C.I_re RCLike.I_re @[simp, rclike_simps] theorem I_im (z : K) : im z * im (I : K) = im z := mul_im_I_ax z set_option linter.uppercaseLean3 false in #align is_R_or_C.I_im RCLike.I_im @[simp, rclike_simps] theorem I_im' (z : K) : im (I : K) * im z = im z := by rw [mul_comm, I_im] set_option linter.uppercaseLean3 false in #align is_R_or_C.I_im' RCLike.I_im' @[rclike_simps] -- porting note (#10618): was `simp` theorem I_mul_re (z : K) : re (I * z) = -im z := by simp only [I_re, zero_sub, I_im', zero_mul, mul_re] set_option linter.uppercaseLean3 false in #align is_R_or_C.I_mul_re RCLike.I_mul_re theorem I_mul_I : (I : K) = 0 ∨ (I : K) * I = -1 := I_mul_I_ax set_option linter.uppercaseLean3 false in #align is_R_or_C.I_mul_I RCLike.I_mul_I variable (𝕜) in lemma I_eq_zero_or_im_I_eq_one : (I : K) = 0 ∨ im (I : K) = 1 := I_mul_I (K := K) |>.imp_right fun h ↦ by simpa [h] using (I_mul_re (I : K)).symm @[simp, rclike_simps] theorem conj_re (z : K) : re (conj z) = re z := RCLike.conj_re_ax z #align is_R_or_C.conj_re RCLike.conj_re @[simp, rclike_simps] theorem conj_im (z : K) : im (conj z) = -im z := RCLike.conj_im_ax z #align is_R_or_C.conj_im RCLike.conj_im @[simp, rclike_simps] theorem conj_I : conj (I : K) = -I := RCLike.conj_I_ax set_option linter.uppercaseLean3 false in #align is_R_or_C.conj_I RCLike.conj_I @[simp, rclike_simps] theorem conj_ofReal (r : ℝ) : conj (r : K) = (r : K) := by rw [ext_iff] simp only [ofReal_im, conj_im, eq_self_iff_true, conj_re, and_self_iff, neg_zero] #align is_R_or_C.conj_of_real RCLike.conj_ofReal -- replaced by `RCLike.conj_ofNat` #noalign is_R_or_C.conj_bit0 #noalign is_R_or_C.conj_bit1 theorem conj_nat_cast (n : ℕ) : conj (n : K) = n := map_natCast _ _ -- See note [no_index around OfNat.ofNat] theorem conj_ofNat (n : ℕ) [n.AtLeastTwo] : conj (no_index (OfNat.ofNat n : K)) = OfNat.ofNat n := map_ofNat _ _ @[rclike_simps] -- Porting note (#10618): was a `simp` but `simp` can prove it theorem conj_neg_I : conj (-I) = (I : K) := by rw [map_neg, conj_I, neg_neg] set_option linter.uppercaseLean3 false in #align is_R_or_C.conj_neg_I RCLike.conj_neg_I theorem conj_eq_re_sub_im (z : K) : conj z = re z - im z * I := (congr_arg conj (re_add_im z).symm).trans <| by rw [map_add, map_mul, conj_I, conj_ofReal, conj_ofReal, mul_neg, sub_eq_add_neg] #align is_R_or_C.conj_eq_re_sub_im RCLike.conj_eq_re_sub_im theorem sub_conj (z : K) : z - conj z = 2 * im z * I := calc z - conj z = re z + im z * I - (re z - im z * I) := by rw [re_add_im, ← conj_eq_re_sub_im] _ = 2 * im z * I := by rw [add_sub_sub_cancel, ← two_mul, mul_assoc] #align is_R_or_C.sub_conj RCLike.sub_conj @[rclike_simps] theorem conj_smul (r : ℝ) (z : K) : conj (r • z) = r • conj z := by rw [conj_eq_re_sub_im, conj_eq_re_sub_im, smul_re, smul_im, ofReal_mul, ofReal_mul, real_smul_eq_coe_mul r (_ - _), mul_sub, mul_assoc] #align is_R_or_C.conj_smul RCLike.conj_smul theorem add_conj (z : K) : z + conj z = 2 * re z := calc z + conj z = re z + im z * I + (re z - im z * I) := by rw [re_add_im, conj_eq_re_sub_im] _ = 2 * re z := by rw [add_add_sub_cancel, two_mul] #align is_R_or_C.add_conj RCLike.add_conj theorem re_eq_add_conj (z : K) : ↑(re z) = (z + conj z) / 2 := by rw [add_conj, mul_div_cancel_left₀ (re z : K) two_ne_zero] #align is_R_or_C.re_eq_add_conj RCLike.re_eq_add_conj theorem im_eq_conj_sub (z : K) : ↑(im z) = I * (conj z - z) / 2 := by rw [← neg_inj, ← ofReal_neg, ← I_mul_re, re_eq_add_conj, map_mul, conj_I, ← neg_div, ← mul_neg, neg_sub, mul_sub, neg_mul, sub_eq_add_neg] #align is_R_or_C.im_eq_conj_sub RCLike.im_eq_conj_sub open List in /-- There are several equivalent ways to say that a number `z` is in fact a real number. -/ theorem is_real_TFAE (z : K) : TFAE [conj z = z, ∃ r : ℝ, (r : K) = z, ↑(re z) = z, im z = 0] := by tfae_have 1 → 4 · intro h rw [← @ofReal_inj K, im_eq_conj_sub, h, sub_self, mul_zero, zero_div, ofReal_zero] tfae_have 4 → 3 · intro h conv_rhs => rw [← re_add_im z, h, ofReal_zero, zero_mul, add_zero] tfae_have 3 → 2 · exact fun h => ⟨_, h⟩ tfae_have 2 → 1 · exact fun ⟨r, hr⟩ => hr ▸ conj_ofReal _ tfae_finish #align is_R_or_C.is_real_tfae RCLike.is_real_TFAE theorem conj_eq_iff_real {z : K} : conj z = z ↔ ∃ r : ℝ, z = (r : K) := ((is_real_TFAE z).out 0 1).trans <| by simp only [eq_comm] #align is_R_or_C.conj_eq_iff_real RCLike.conj_eq_iff_real theorem conj_eq_iff_re {z : K} : conj z = z ↔ (re z : K) = z := (is_real_TFAE z).out 0 2 #align is_R_or_C.conj_eq_iff_re RCLike.conj_eq_iff_re theorem conj_eq_iff_im {z : K} : conj z = z ↔ im z = 0 := (is_real_TFAE z).out 0 3 #align is_R_or_C.conj_eq_iff_im RCLike.conj_eq_iff_im @[simp] theorem star_def : (Star.star : K → K) = conj := rfl #align is_R_or_C.star_def RCLike.star_def variable (K) /-- Conjugation as a ring equivalence. This is used to convert the inner product into a sesquilinear product. -/ abbrev conjToRingEquiv : K ≃+* Kᵐᵒᵖ := starRingEquiv #align is_R_or_C.conj_to_ring_equiv RCLike.conjToRingEquiv variable {K} {z : K} /-- The norm squared function. -/ def normSq : K →*₀ ℝ where toFun z := re z * re z + im z * im z map_zero' := by simp only [add_zero, mul_zero, map_zero] map_one' := by simp only [one_im, add_zero, mul_one, one_re, mul_zero] map_mul' z w := by simp only [mul_im, mul_re] ring #align is_R_or_C.norm_sq RCLike.normSq theorem normSq_apply (z : K) : normSq z = re z * re z + im z * im z := rfl #align is_R_or_C.norm_sq_apply RCLike.normSq_apply theorem norm_sq_eq_def {z : K} : ‖z‖ ^ 2 = re z * re z + im z * im z := norm_sq_eq_def_ax z #align is_R_or_C.norm_sq_eq_def RCLike.norm_sq_eq_def theorem normSq_eq_def' (z : K) : normSq z = ‖z‖ ^ 2 := norm_sq_eq_def.symm #align is_R_or_C.norm_sq_eq_def' RCLike.normSq_eq_def' @[rclike_simps] theorem normSq_zero : normSq (0 : K) = 0 := normSq.map_zero #align is_R_or_C.norm_sq_zero RCLike.normSq_zero @[rclike_simps] theorem normSq_one : normSq (1 : K) = 1 := normSq.map_one #align is_R_or_C.norm_sq_one RCLike.normSq_one theorem normSq_nonneg (z : K) : 0 ≤ normSq z := add_nonneg (mul_self_nonneg _) (mul_self_nonneg _) #align is_R_or_C.norm_sq_nonneg RCLike.normSq_nonneg @[rclike_simps] -- porting note (#10618): was `simp` theorem normSq_eq_zero {z : K} : normSq z = 0 ↔ z = 0 := map_eq_zero _ #align is_R_or_C.norm_sq_eq_zero RCLike.normSq_eq_zero @[simp, rclike_simps] theorem normSq_pos {z : K} : 0 < normSq z ↔ z ≠ 0 := by rw [lt_iff_le_and_ne, Ne, eq_comm]; simp [normSq_nonneg] #align is_R_or_C.norm_sq_pos RCLike.normSq_pos @[simp, rclike_simps] theorem normSq_neg (z : K) : normSq (-z) = normSq z := by simp only [normSq_eq_def', norm_neg] #align is_R_or_C.norm_sq_neg RCLike.normSq_neg @[simp, rclike_simps] theorem normSq_conj (z : K) : normSq (conj z) = normSq z := by simp only [normSq_apply, neg_mul, mul_neg, neg_neg, rclike_simps] #align is_R_or_C.norm_sq_conj RCLike.normSq_conj @[rclike_simps] -- porting note (#10618): was `simp` theorem normSq_mul (z w : K) : normSq (z * w) = normSq z * normSq w := map_mul _ z w #align is_R_or_C.norm_sq_mul RCLike.normSq_mul theorem normSq_add (z w : K) : normSq (z + w) = normSq z + normSq w + 2 * re (z * conj w) := by simp only [normSq_apply, map_add, rclike_simps] ring #align is_R_or_C.norm_sq_add RCLike.normSq_add theorem re_sq_le_normSq (z : K) : re z * re z ≤ normSq z := le_add_of_nonneg_right (mul_self_nonneg _) #align is_R_or_C.re_sq_le_norm_sq RCLike.re_sq_le_normSq theorem im_sq_le_normSq (z : K) : im z * im z ≤ normSq z := le_add_of_nonneg_left (mul_self_nonneg _) #align is_R_or_C.im_sq_le_norm_sq RCLike.im_sq_le_normSq theorem mul_conj (z : K) : z * conj z = ‖z‖ ^ 2 := by apply ext <;> simp [← ofReal_pow, norm_sq_eq_def, mul_comm] #align is_R_or_C.mul_conj RCLike.mul_conj theorem conj_mul (z : K) : conj z * z = ‖z‖ ^ 2 := by rw [mul_comm, mul_conj] #align is_R_or_C.conj_mul RCLike.conj_mul lemma inv_eq_conj (hz : ‖z‖ = 1) : z⁻¹ = conj z := inv_eq_of_mul_eq_one_left $ by simp_rw [conj_mul, hz, algebraMap.coe_one, one_pow] theorem normSq_sub (z w : K) : normSq (z - w) = normSq z + normSq w - 2 * re (z * conj w) := by simp only [normSq_add, sub_eq_add_neg, map_neg, mul_neg, normSq_neg, map_neg] #align is_R_or_C.norm_sq_sub RCLike.normSq_sub theorem sqrt_normSq_eq_norm {z : K} : √(normSq z) = ‖z‖ := by rw [normSq_eq_def', Real.sqrt_sq (norm_nonneg _)] #align is_R_or_C.sqrt_norm_sq_eq_norm RCLike.sqrt_normSq_eq_norm /-! ### Inversion -/ @[simp, norm_cast, rclike_simps] theorem ofReal_inv (r : ℝ) : ((r⁻¹ : ℝ) : K) = (r : K)⁻¹ := map_inv₀ _ r #align is_R_or_C.of_real_inv RCLike.ofReal_inv theorem inv_def (z : K) : z⁻¹ = conj z * ((‖z‖ ^ 2)⁻¹ : ℝ) := by rcases eq_or_ne z 0 with (rfl | h₀) · simp · apply inv_eq_of_mul_eq_one_right rw [← mul_assoc, mul_conj, ofReal_inv, ofReal_pow, mul_inv_cancel] simpa #align is_R_or_C.inv_def RCLike.inv_def @[simp, rclike_simps] theorem inv_re (z : K) : re z⁻¹ = re z / normSq z := by rw [inv_def, normSq_eq_def', mul_comm, re_ofReal_mul, conj_re, div_eq_inv_mul] #align is_R_or_C.inv_re RCLike.inv_re @[simp, rclike_simps] theorem inv_im (z : K) : im z⁻¹ = -im z / normSq z := by rw [inv_def, normSq_eq_def', mul_comm, im_ofReal_mul, conj_im, div_eq_inv_mul] #align is_R_or_C.inv_im RCLike.inv_im
Mathlib/Analysis/RCLike/Basic.lean
550
552
theorem div_re (z w : K) : re (z / w) = re z * re w / normSq w + im z * im w / normSq w := by
simp only [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, neg_mul, mul_neg, neg_neg, map_neg, rclike_simps]
/- Copyright (c) 2017 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Mario Carneiro -/ import Mathlib.Data.Complex.Basic import Mathlib.Data.Real.Sqrt #align_import data.complex.basic from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004" /-! # Absolute values of complex numbers -/ open Set ComplexConjugate namespace Complex /-! ### Absolute value -/ namespace AbsTheory -- We develop enough theory to bundle `abs` into an `AbsoluteValue` before making things public; -- this is so there's not two versions of it hanging around. local notation "abs" z => Real.sqrt (normSq z) private theorem mul_self_abs (z : ℂ) : ((abs z) * abs z) = normSq z := Real.mul_self_sqrt (normSq_nonneg _) private theorem abs_nonneg' (z : ℂ) : 0 ≤ abs z := Real.sqrt_nonneg _ theorem abs_conj (z : ℂ) : (abs conj z) = abs z := by simp #align complex.abs_theory.abs_conj Complex.AbsTheory.abs_conj private theorem abs_re_le_abs (z : ℂ) : |z.re| ≤ abs z := by rw [mul_self_le_mul_self_iff (abs_nonneg z.re) (abs_nonneg' _), abs_mul_abs_self, mul_self_abs] apply re_sq_le_normSq private theorem re_le_abs (z : ℂ) : z.re ≤ abs z := (abs_le.1 (abs_re_le_abs _)).2 private theorem abs_mul (z w : ℂ) : (abs z * w) = (abs z) * abs w := by rw [normSq_mul, Real.sqrt_mul (normSq_nonneg _)] private theorem abs_add (z w : ℂ) : (abs z + w) ≤ (abs z) + abs w := (mul_self_le_mul_self_iff (abs_nonneg' (z + w)) (add_nonneg (abs_nonneg' z) (abs_nonneg' w))).2 <| by rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs, add_right_comm, normSq_add, add_le_add_iff_left, mul_assoc, mul_le_mul_left (zero_lt_two' ℝ), ← Real.sqrt_mul <| normSq_nonneg z, ← normSq_conj w, ← map_mul] exact re_le_abs (z * conj w) /-- The complex absolute value function, defined as the square root of the norm squared. -/ noncomputable def _root_.Complex.abs : AbsoluteValue ℂ ℝ where toFun x := abs x map_mul' := abs_mul nonneg' := abs_nonneg' eq_zero' _ := (Real.sqrt_eq_zero <| normSq_nonneg _).trans normSq_eq_zero add_le' := abs_add #align complex.abs Complex.abs end AbsTheory theorem abs_def : (Complex.abs : ℂ → ℝ) = fun z => (normSq z).sqrt := rfl #align complex.abs_def Complex.abs_def theorem abs_apply {z : ℂ} : Complex.abs z = (normSq z).sqrt := rfl #align complex.abs_apply Complex.abs_apply @[simp, norm_cast] theorem abs_ofReal (r : ℝ) : Complex.abs r = |r| := by simp [Complex.abs, normSq_ofReal, Real.sqrt_mul_self_eq_abs] #align complex.abs_of_real Complex.abs_ofReal nonrec theorem abs_of_nonneg {r : ℝ} (h : 0 ≤ r) : Complex.abs r = r := (Complex.abs_ofReal _).trans (abs_of_nonneg h) #align complex.abs_of_nonneg Complex.abs_of_nonneg -- Porting note: removed `norm_cast` attribute because the RHS can't start with `↑` @[simp] theorem abs_natCast (n : ℕ) : Complex.abs n = n := Complex.abs_of_nonneg (Nat.cast_nonneg n) #align complex.abs_of_nat Complex.abs_natCast #align complex.abs_cast_nat Complex.abs_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem abs_ofNat (n : ℕ) [n.AtLeastTwo] : Complex.abs (no_index (OfNat.ofNat n : ℂ)) = OfNat.ofNat n := abs_natCast n theorem mul_self_abs (z : ℂ) : Complex.abs z * Complex.abs z = normSq z := Real.mul_self_sqrt (normSq_nonneg _) #align complex.mul_self_abs Complex.mul_self_abs theorem sq_abs (z : ℂ) : Complex.abs z ^ 2 = normSq z := Real.sq_sqrt (normSq_nonneg _) #align complex.sq_abs Complex.sq_abs @[simp] theorem sq_abs_sub_sq_re (z : ℂ) : Complex.abs z ^ 2 - z.re ^ 2 = z.im ^ 2 := by rw [sq_abs, normSq_apply, ← sq, ← sq, add_sub_cancel_left] #align complex.sq_abs_sub_sq_re Complex.sq_abs_sub_sq_re @[simp] theorem sq_abs_sub_sq_im (z : ℂ) : Complex.abs z ^ 2 - z.im ^ 2 = z.re ^ 2 := by rw [← sq_abs_sub_sq_re, sub_sub_cancel] #align complex.sq_abs_sub_sq_im Complex.sq_abs_sub_sq_im lemma abs_add_mul_I (x y : ℝ) : abs (x + y * I) = (x ^ 2 + y ^ 2).sqrt := by rw [← normSq_add_mul_I]; rfl lemma abs_eq_sqrt_sq_add_sq (z : ℂ) : abs z = (z.re ^ 2 + z.im ^ 2).sqrt := by rw [abs_apply, normSq_apply, sq, sq] @[simp] theorem abs_I : Complex.abs I = 1 := by simp [Complex.abs] set_option linter.uppercaseLean3 false in #align complex.abs_I Complex.abs_I theorem abs_two : Complex.abs 2 = 2 := abs_ofNat 2 #align complex.abs_two Complex.abs_two @[simp] theorem range_abs : range Complex.abs = Ici 0 := Subset.antisymm (by simp only [range_subset_iff, Ici, mem_setOf_eq, apply_nonneg, forall_const]) (fun x hx => ⟨x, Complex.abs_of_nonneg hx⟩) #align complex.range_abs Complex.range_abs @[simp] theorem abs_conj (z : ℂ) : Complex.abs (conj z) = Complex.abs z := AbsTheory.abs_conj z #align complex.abs_conj Complex.abs_conj -- Porting note (#10618): @[simp] can prove it now theorem abs_prod {ι : Type*} (s : Finset ι) (f : ι → ℂ) : Complex.abs (s.prod f) = s.prod fun I => Complex.abs (f I) := map_prod Complex.abs _ _ #align complex.abs_prod Complex.abs_prod -- @[simp] /- Porting note (#11119): `simp` attribute removed as linter reports this can be proved by `simp only [@map_pow]` -/ theorem abs_pow (z : ℂ) (n : ℕ) : Complex.abs (z ^ n) = Complex.abs z ^ n := map_pow Complex.abs z n #align complex.abs_pow Complex.abs_pow -- @[simp] /- Porting note (#11119): `simp` attribute removed as linter reports this can be proved by `simp only [@map_zpow₀]` -/ theorem abs_zpow (z : ℂ) (n : ℤ) : Complex.abs (z ^ n) = Complex.abs z ^ n := map_zpow₀ Complex.abs z n #align complex.abs_zpow Complex.abs_zpow theorem abs_re_le_abs (z : ℂ) : |z.re| ≤ Complex.abs z := Real.abs_le_sqrt <| by rw [normSq_apply, ← sq] exact le_add_of_nonneg_right (mul_self_nonneg _) #align complex.abs_re_le_abs Complex.abs_re_le_abs theorem abs_im_le_abs (z : ℂ) : |z.im| ≤ Complex.abs z := Real.abs_le_sqrt <| by rw [normSq_apply, ← sq, ← sq] exact le_add_of_nonneg_left (sq_nonneg _) #align complex.abs_im_le_abs Complex.abs_im_le_abs theorem re_le_abs (z : ℂ) : z.re ≤ Complex.abs z := (abs_le.1 (abs_re_le_abs _)).2 #align complex.re_le_abs Complex.re_le_abs theorem im_le_abs (z : ℂ) : z.im ≤ Complex.abs z := (abs_le.1 (abs_im_le_abs _)).2 #align complex.im_le_abs Complex.im_le_abs @[simp] theorem abs_re_lt_abs {z : ℂ} : |z.re| < Complex.abs z ↔ z.im ≠ 0 := by rw [Complex.abs, AbsoluteValue.coe_mk, MulHom.coe_mk, Real.lt_sqrt (abs_nonneg _), normSq_apply, _root_.sq_abs, ← sq, lt_add_iff_pos_right, mul_self_pos] #align complex.abs_re_lt_abs Complex.abs_re_lt_abs @[simp] theorem abs_im_lt_abs {z : ℂ} : |z.im| < Complex.abs z ↔ z.re ≠ 0 := by simpa using @abs_re_lt_abs (z * I) #align complex.abs_im_lt_abs Complex.abs_im_lt_abs @[simp] lemma abs_re_eq_abs {z : ℂ} : |z.re| = abs z ↔ z.im = 0 := not_iff_not.1 <| (abs_re_le_abs z).lt_iff_ne.symm.trans abs_re_lt_abs @[simp] lemma abs_im_eq_abs {z : ℂ} : |z.im| = abs z ↔ z.re = 0 := not_iff_not.1 <| (abs_im_le_abs z).lt_iff_ne.symm.trans abs_im_lt_abs @[simp] theorem abs_abs (z : ℂ) : |Complex.abs z| = Complex.abs z := _root_.abs_of_nonneg (AbsoluteValue.nonneg _ z) #align complex.abs_abs Complex.abs_abs -- Porting note: probably should be golfed theorem abs_le_abs_re_add_abs_im (z : ℂ) : Complex.abs z ≤ |z.re| + |z.im| := by simpa [re_add_im] using Complex.abs.add_le z.re (z.im * I) #align complex.abs_le_abs_re_add_abs_im Complex.abs_le_abs_re_add_abs_im -- Porting note: added so `two_pos` in the next proof works -- TODO: move somewhere else instance : NeZero (1 : ℝ) := ⟨by apply one_ne_zero⟩ theorem abs_le_sqrt_two_mul_max (z : ℂ) : Complex.abs z ≤ Real.sqrt 2 * max |z.re| |z.im| := by cases' z with x y simp only [abs_apply, normSq_mk, ← sq] by_cases hle : |x| ≤ |y| · calc Real.sqrt (x ^ 2 + y ^ 2) ≤ Real.sqrt (y ^ 2 + y ^ 2) := Real.sqrt_le_sqrt (add_le_add_right (sq_le_sq.2 hle) _) _ = Real.sqrt 2 * max |x| |y| := by rw [max_eq_right hle, ← two_mul, Real.sqrt_mul two_pos.le, Real.sqrt_sq_eq_abs] · have hle' := le_of_not_le hle rw [add_comm] calc Real.sqrt (y ^ 2 + x ^ 2) ≤ Real.sqrt (x ^ 2 + x ^ 2) := Real.sqrt_le_sqrt (add_le_add_right (sq_le_sq.2 hle') _) _ = Real.sqrt 2 * max |x| |y| := by rw [max_eq_left hle', ← two_mul, Real.sqrt_mul two_pos.le, Real.sqrt_sq_eq_abs] #align complex.abs_le_sqrt_two_mul_max Complex.abs_le_sqrt_two_mul_max theorem abs_re_div_abs_le_one (z : ℂ) : |z.re / Complex.abs z| ≤ 1 := if hz : z = 0 then by simp [hz, zero_le_one] else by simp_rw [_root_.abs_div, abs_abs, div_le_iff (AbsoluteValue.pos Complex.abs hz), one_mul, abs_re_le_abs] #align complex.abs_re_div_abs_le_one Complex.abs_re_div_abs_le_one theorem abs_im_div_abs_le_one (z : ℂ) : |z.im / Complex.abs z| ≤ 1 := if hz : z = 0 then by simp [hz, zero_le_one] else by simp_rw [_root_.abs_div, abs_abs, div_le_iff (AbsoluteValue.pos Complex.abs hz), one_mul, abs_im_le_abs] #align complex.abs_im_div_abs_le_one Complex.abs_im_div_abs_le_one @[simp, norm_cast] lemma abs_intCast (n : ℤ) : abs n = |↑n| := by rw [← ofReal_intCast, abs_ofReal] #align complex.int_cast_abs Complex.abs_intCast @[deprecated (since := "2024-02-14")] lemma int_cast_abs (n : ℤ) : |↑n| = Complex.abs n := (abs_intCast _).symm theorem normSq_eq_abs (x : ℂ) : normSq x = (Complex.abs x) ^ 2 := by simp [abs, sq, abs_def, Real.mul_self_sqrt (normSq_nonneg _)] #align complex.norm_sq_eq_abs Complex.normSq_eq_abs @[simp] theorem range_normSq : range normSq = Ici 0 := Subset.antisymm (range_subset_iff.2 normSq_nonneg) fun x hx => ⟨Real.sqrt x, by rw [normSq_ofReal, Real.mul_self_sqrt hx]⟩ #align complex.range_norm_sq Complex.range_normSq /-! ### Cauchy sequences -/ local notation "abs'" => _root_.abs theorem isCauSeq_re (f : CauSeq ℂ Complex.abs) : IsCauSeq abs' fun n => (f n).re := fun ε ε0 => (f.cauchy ε0).imp fun i H j ij => lt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij) #align complex.is_cau_seq_re Complex.isCauSeq_re theorem isCauSeq_im (f : CauSeq ℂ Complex.abs) : IsCauSeq abs' fun n => (f n).im := fun ε ε0 => (f.cauchy ε0).imp fun i H j ij ↦ by simpa only [← ofReal_sub, abs_ofReal, sub_re] using (abs_im_le_abs _).trans_lt $ H _ ij #align complex.is_cau_seq_im Complex.isCauSeq_im /-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/ noncomputable def cauSeqRe (f : CauSeq ℂ Complex.abs) : CauSeq ℝ abs' := ⟨_, isCauSeq_re f⟩ #align complex.cau_seq_re Complex.cauSeqRe /-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/ noncomputable def cauSeqIm (f : CauSeq ℂ Complex.abs) : CauSeq ℝ abs' := ⟨_, isCauSeq_im f⟩ #align complex.cau_seq_im Complex.cauSeqIm theorem isCauSeq_abs {f : ℕ → ℂ} (hf : IsCauSeq Complex.abs f) : IsCauSeq abs' (Complex.abs ∘ f) := fun ε ε0 => let ⟨i, hi⟩ := hf ε ε0 ⟨i, fun j hj => lt_of_le_of_lt (Complex.abs.abs_abv_sub_le_abv_sub _ _) (hi j hj)⟩ #align complex.is_cau_seq_abs Complex.isCauSeq_abs /-- The limit of a Cauchy sequence of complex numbers. -/ noncomputable def limAux (f : CauSeq ℂ Complex.abs) : ℂ := ⟨CauSeq.lim (cauSeqRe f), CauSeq.lim (cauSeqIm f)⟩ #align complex.lim_aux Complex.limAux theorem equiv_limAux (f : CauSeq ℂ Complex.abs) : f ≈ CauSeq.const Complex.abs (limAux f) := fun ε ε0 => (exists_forall_ge_and (CauSeq.equiv_lim ⟨_, isCauSeq_re f⟩ _ (half_pos ε0)) (CauSeq.equiv_lim ⟨_, isCauSeq_im f⟩ _ (half_pos ε0))).imp fun i H j ij => by cases' H _ ij with H₁ H₂ apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _) dsimp [limAux] at * have := add_lt_add H₁ H₂ rwa [add_halves] at this #align complex.equiv_lim_aux Complex.equiv_limAux instance instIsComplete : CauSeq.IsComplete ℂ Complex.abs := ⟨fun f => ⟨limAux f, equiv_limAux f⟩⟩ open CauSeq theorem lim_eq_lim_im_add_lim_re (f : CauSeq ℂ Complex.abs) : lim f = ↑(lim (cauSeqRe f)) + ↑(lim (cauSeqIm f)) * I := lim_eq_of_equiv_const <| calc f ≈ _ := equiv_limAux f _ = CauSeq.const Complex.abs (↑(lim (cauSeqRe f)) + ↑(lim (cauSeqIm f)) * I) := CauSeq.ext fun _ => Complex.ext (by simp [limAux, cauSeqRe, ofReal']) (by simp [limAux, cauSeqIm, ofReal']) #align complex.lim_eq_lim_im_add_lim_re Complex.lim_eq_lim_im_add_lim_re theorem lim_re (f : CauSeq ℂ Complex.abs) : lim (cauSeqRe f) = (lim f).re := by rw [lim_eq_lim_im_add_lim_re]; simp [ofReal'] #align complex.lim_re Complex.lim_re
Mathlib/Data/Complex/Abs.lean
327
328
theorem lim_im (f : CauSeq ℂ Complex.abs) : lim (cauSeqIm f) = (lim f).im := by
rw [lim_eq_lim_im_add_lim_re]; simp [ofReal']
/- 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.EqLocus import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Algebra.Ring.Idempotents import Mathlib.Data.Set.Pointwise.SMul import Mathlib.LinearAlgebra.Basic import Mathlib.Order.CompactlyGenerated.Basic import Mathlib.Order.OmegaCompletePartialOrder #align_import linear_algebra.span from "leanprover-community/mathlib"@"10878f6bf1dab863445907ab23fbfcefcb5845d0" /-! # The span of a set of vectors, as a submodule * `Submodule.span s` is defined to be the smallest submodule containing the set `s`. ## Notations * We introduce the notation `R ∙ v` for the span of a singleton, `Submodule.span R {v}`. This is `\span`, not the same as the scalar multiplication `•`/`\bub`. -/ variable {R R₂ K M M₂ V S : Type*} namespace Submodule open Function Set open Pointwise section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] variable {x : M} (p p' : Submodule R M) variable [Semiring R₂] {σ₁₂ : R →+* R₂} variable [AddCommMonoid M₂] [Module R₂ M₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] section variable (R) /-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/ def span (s : Set M) : Submodule R M := sInf { p | s ⊆ p } #align submodule.span Submodule.span variable {R} -- Porting note: renamed field to `principal'` and added `principal` to fix explicit argument /-- An `R`-submodule of `M` is principal if it is generated by one element. -/ @[mk_iff] class IsPrincipal (S : Submodule R M) : Prop where principal' : ∃ a, S = span R {a} #align submodule.is_principal Submodule.IsPrincipal theorem IsPrincipal.principal (S : Submodule R M) [S.IsPrincipal] : ∃ a, S = span R {a} := Submodule.IsPrincipal.principal' #align submodule.is_principal.principal Submodule.IsPrincipal.principal end variable {s t : Set M} theorem mem_span : x ∈ span R s ↔ ∀ p : Submodule R M, s ⊆ p → x ∈ p := mem_iInter₂ #align submodule.mem_span Submodule.mem_span @[aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_span : s ⊆ span R s := fun _ h => mem_span.2 fun _ hp => hp h #align submodule.subset_span Submodule.subset_span theorem span_le {p} : span R s ≤ p ↔ s ⊆ p := ⟨Subset.trans subset_span, fun ss _ h => mem_span.1 h _ ss⟩ #align submodule.span_le Submodule.span_le theorem span_mono (h : s ⊆ t) : span R s ≤ span R t := span_le.2 <| Subset.trans h subset_span #align submodule.span_mono Submodule.span_mono theorem span_monotone : Monotone (span R : Set M → Submodule R M) := fun _ _ => span_mono #align submodule.span_monotone Submodule.span_monotone theorem span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p := le_antisymm (span_le.2 h₁) h₂ #align submodule.span_eq_of_le Submodule.span_eq_of_le theorem span_eq : span R (p : Set M) = p := span_eq_of_le _ (Subset.refl _) subset_span #align submodule.span_eq Submodule.span_eq theorem span_eq_span (hs : s ⊆ span R t) (ht : t ⊆ span R s) : span R s = span R t := le_antisymm (span_le.2 hs) (span_le.2 ht) #align submodule.span_eq_span Submodule.span_eq_span /-- A version of `Submodule.span_eq` for subobjects closed under addition and scalar multiplication and containing zero. In general, this should not be used directly, but can be used to quickly generate proofs for specific types of subobjects. -/ lemma coe_span_eq_self [SetLike S M] [AddSubmonoidClass S M] [SMulMemClass S R M] (s : S) : (span R (s : Set M) : Set M) = s := by refine le_antisymm ?_ subset_span let s' : Submodule R M := { carrier := s add_mem' := add_mem zero_mem' := zero_mem _ smul_mem' := SMulMemClass.smul_mem } exact span_le (p := s') |>.mpr le_rfl /-- A version of `Submodule.span_eq` for when the span is by a smaller ring. -/ @[simp] theorem span_coe_eq_restrictScalars [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : span S (p : Set M) = p.restrictScalars S := span_eq (p.restrictScalars S) #align submodule.span_coe_eq_restrict_scalars Submodule.span_coe_eq_restrictScalars /-- A version of `Submodule.map_span_le` that does not require the `RingHomSurjective` assumption. -/ theorem image_span_subset (f : F) (s : Set M) (N : Submodule R₂ M₂) : f '' span R s ⊆ N ↔ ∀ m ∈ s, f m ∈ N := image_subset_iff.trans <| span_le (p := N.comap f) theorem image_span_subset_span (f : F) (s : Set M) : f '' span R s ⊆ span R₂ (f '' s) := (image_span_subset f s _).2 fun x hx ↦ subset_span ⟨x, hx, rfl⟩ theorem map_span [RingHomSurjective σ₁₂] (f : F) (s : Set M) : (span R s).map f = span R₂ (f '' s) := Eq.symm <| span_eq_of_le _ (Set.image_subset f subset_span) (image_span_subset_span f s) #align submodule.map_span Submodule.map_span alias _root_.LinearMap.map_span := Submodule.map_span #align linear_map.map_span LinearMap.map_span theorem map_span_le [RingHomSurjective σ₁₂] (f : F) (s : Set M) (N : Submodule R₂ M₂) : map f (span R s) ≤ N ↔ ∀ m ∈ s, f m ∈ N := image_span_subset f s N #align submodule.map_span_le Submodule.map_span_le alias _root_.LinearMap.map_span_le := Submodule.map_span_le #align linear_map.map_span_le LinearMap.map_span_le @[simp] theorem span_insert_zero : span R (insert (0 : M) s) = span R s := by refine le_antisymm ?_ (Submodule.span_mono (Set.subset_insert 0 s)) rw [span_le, Set.insert_subset_iff] exact ⟨by simp only [SetLike.mem_coe, Submodule.zero_mem], Submodule.subset_span⟩ #align submodule.span_insert_zero Submodule.span_insert_zero -- See also `span_preimage_eq` below. theorem span_preimage_le (f : F) (s : Set M₂) : span R (f ⁻¹' s) ≤ (span R₂ s).comap f := by rw [span_le, comap_coe] exact preimage_mono subset_span #align submodule.span_preimage_le Submodule.span_preimage_le alias _root_.LinearMap.span_preimage_le := Submodule.span_preimage_le #align linear_map.span_preimage_le LinearMap.span_preimage_le theorem closure_subset_span {s : Set M} : (AddSubmonoid.closure s : Set M) ⊆ span R s := (@AddSubmonoid.closure_le _ _ _ (span R s).toAddSubmonoid).mpr subset_span #align submodule.closure_subset_span Submodule.closure_subset_span theorem closure_le_toAddSubmonoid_span {s : Set M} : AddSubmonoid.closure s ≤ (span R s).toAddSubmonoid := closure_subset_span #align submodule.closure_le_to_add_submonoid_span Submodule.closure_le_toAddSubmonoid_span @[simp] theorem span_closure {s : Set M} : span R (AddSubmonoid.closure s : Set M) = span R s := le_antisymm (span_le.mpr closure_subset_span) (span_mono AddSubmonoid.subset_closure) #align submodule.span_closure Submodule.span_closure /-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is preserved under addition and scalar multiplication, then `p` holds for all elements of the span of `s`. -/ @[elab_as_elim] theorem span_induction {p : M → Prop} (h : x ∈ span R s) (mem : ∀ x ∈ s, p x) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (smul : ∀ (a : R) (x), p x → p (a • x)) : p x := ((@span_le (p := ⟨⟨⟨p, by intros x y; exact add x y⟩, zero⟩, smul⟩)) s).2 mem h #align submodule.span_induction Submodule.span_induction /-- An induction principle for span membership. This is a version of `Submodule.span_induction` for binary predicates. -/ theorem span_induction₂ {p : M → M → Prop} {a b : M} (ha : a ∈ Submodule.span R s) (hb : b ∈ Submodule.span R s) (mem_mem : ∀ x ∈ s, ∀ y ∈ s, p x y) (zero_left : ∀ y, p 0 y) (zero_right : ∀ x, p x 0) (add_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (add_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (smul_left : ∀ (r : R) x y, p x y → p (r • x) y) (smul_right : ∀ (r : R) x y, p x y → p x (r • y)) : p a b := Submodule.span_induction ha (fun x hx => Submodule.span_induction hb (mem_mem x hx) (zero_right x) (add_right x) fun r => smul_right r x) (zero_left b) (fun x₁ x₂ => add_left x₁ x₂ b) fun r x => smul_left r x b /-- A dependent version of `Submodule.span_induction`. -/ @[elab_as_elim] theorem span_induction' {p : ∀ x, x ∈ span R s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_span h)) (zero : p 0 (Submodule.zero_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) (smul : ∀ (a : R) (x hx), p x hx → p (a • x) (Submodule.smul_mem _ _ ‹_›)) {x} (hx : x ∈ span R s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) => hc refine span_induction hx (fun m hm => ⟨subset_span hm, mem m hm⟩) ⟨zero_mem _, zero⟩ (fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) fun r x hx => Exists.elim hx fun hx' hx => ⟨smul_mem _ _ hx', smul r _ _ hx⟩ #align submodule.span_induction' Submodule.span_induction' open AddSubmonoid in theorem span_eq_closure {s : Set M} : (span R s).toAddSubmonoid = closure (@univ R • s) := by refine le_antisymm (fun x hx ↦ span_induction hx (fun x hx ↦ subset_closure ⟨1, trivial, x, hx, one_smul R x⟩) (zero_mem _) (fun _ _ ↦ add_mem) fun r m hm ↦ closure_induction hm ?_ ?_ fun _ _ h h' ↦ ?_) (closure_le.2 ?_) · rintro _ ⟨r, -, m, hm, rfl⟩; exact smul_mem _ _ (subset_span hm) · rintro _ ⟨r', -, m, hm, rfl⟩; exact subset_closure ⟨r * r', trivial, m, hm, mul_smul r r' m⟩ · rw [smul_zero]; apply zero_mem · rw [smul_add]; exact add_mem h h' /-- A variant of `span_induction` that combines `∀ x ∈ s, p x` and `∀ r x, p x → p (r • x)` into a single condition `∀ r, ∀ x ∈ s, p (r • x)`, which can be easier to verify. -/ @[elab_as_elim] theorem closure_induction {p : M → Prop} (h : x ∈ span R s) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (smul_mem : ∀ r : R, ∀ x ∈ s, p (r • x)) : p x := by rw [← mem_toAddSubmonoid, span_eq_closure] at h refine AddSubmonoid.closure_induction h ?_ zero add rintro _ ⟨r, -, m, hm, rfl⟩ exact smul_mem r m hm /-- A dependent version of `Submodule.closure_induction`. -/ @[elab_as_elim] theorem closure_induction' {p : ∀ x, x ∈ span R s → Prop} (zero : p 0 (Submodule.zero_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) (smul_mem : ∀ (r x) (h : x ∈ s), p (r • x) (Submodule.smul_mem _ _ <| subset_span h)) {x} (hx : x ∈ span R s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) ↦ hc refine closure_induction hx ⟨zero_mem _, zero⟩ (fun x y hx hy ↦ Exists.elim hx fun hx' hx ↦ Exists.elim hy fun hy' hy ↦ ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) fun r x hx ↦ ⟨Submodule.smul_mem _ _ (subset_span hx), smul_mem r x hx⟩ @[simp] theorem span_span_coe_preimage : span R (((↑) : span R s → M) ⁻¹' s) = ⊤ := eq_top_iff.2 fun x ↦ Subtype.recOn x fun x hx _ ↦ by refine span_induction' (p := fun x hx ↦ (⟨x, hx⟩ : span R s) ∈ span R (Subtype.val ⁻¹' s)) (fun x' hx' ↦ subset_span hx') ?_ (fun x _ y _ ↦ ?_) (fun r x _ ↦ ?_) hx · exact zero_mem _ · exact add_mem · exact smul_mem _ _ #align submodule.span_span_coe_preimage Submodule.span_span_coe_preimage @[simp] lemma span_setOf_mem_eq_top : span R {x : span R s | (x : M) ∈ s} = ⊤ := span_span_coe_preimage theorem span_nat_eq_addSubmonoid_closure (s : Set M) : (span ℕ s).toAddSubmonoid = AddSubmonoid.closure s := by refine Eq.symm (AddSubmonoid.closure_eq_of_le subset_span ?_) apply (OrderIso.to_galoisConnection (AddSubmonoid.toNatSubmodule (M := M)).symm).l_le (a := span ℕ s) (b := AddSubmonoid.closure s) rw [span_le] exact AddSubmonoid.subset_closure #align submodule.span_nat_eq_add_submonoid_closure Submodule.span_nat_eq_addSubmonoid_closure @[simp] theorem span_nat_eq (s : AddSubmonoid M) : (span ℕ (s : Set M)).toAddSubmonoid = s := by rw [span_nat_eq_addSubmonoid_closure, s.closure_eq] #align submodule.span_nat_eq Submodule.span_nat_eq theorem span_int_eq_addSubgroup_closure {M : Type*} [AddCommGroup M] (s : Set M) : (span ℤ s).toAddSubgroup = AddSubgroup.closure s := Eq.symm <| AddSubgroup.closure_eq_of_le _ subset_span fun x hx => span_induction hx (fun x hx => AddSubgroup.subset_closure hx) (AddSubgroup.zero_mem _) (fun _ _ => AddSubgroup.add_mem _) fun _ _ _ => AddSubgroup.zsmul_mem _ ‹_› _ #align submodule.span_int_eq_add_subgroup_closure Submodule.span_int_eq_addSubgroup_closure @[simp] theorem span_int_eq {M : Type*} [AddCommGroup M] (s : AddSubgroup M) : (span ℤ (s : Set M)).toAddSubgroup = s := by rw [span_int_eq_addSubgroup_closure, s.closure_eq] #align submodule.span_int_eq Submodule.span_int_eq section variable (R M) /-- `span` forms a Galois insertion with the coercion from submodule to set. -/ protected def gi : GaloisInsertion (@span R M _ _ _) (↑) where choice s _ := span R s gc _ _ := span_le le_l_u _ := subset_span choice_eq _ _ := rfl #align submodule.gi Submodule.gi end @[simp] theorem span_empty : span R (∅ : Set M) = ⊥ := (Submodule.gi R M).gc.l_bot #align submodule.span_empty Submodule.span_empty @[simp] theorem span_univ : span R (univ : Set M) = ⊤ := eq_top_iff.2 <| SetLike.le_def.2 <| subset_span #align submodule.span_univ Submodule.span_univ theorem span_union (s t : Set M) : span R (s ∪ t) = span R s ⊔ span R t := (Submodule.gi R M).gc.l_sup #align submodule.span_union Submodule.span_union theorem span_iUnion {ι} (s : ι → Set M) : span R (⋃ i, s i) = ⨆ i, span R (s i) := (Submodule.gi R M).gc.l_iSup #align submodule.span_Union Submodule.span_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem span_iUnion₂ {ι} {κ : ι → Sort*} (s : ∀ i, κ i → Set M) : span R (⋃ (i) (j), s i j) = ⨆ (i) (j), span R (s i j) := (Submodule.gi R M).gc.l_iSup₂ #align submodule.span_Union₂ Submodule.span_iUnion₂ theorem span_attach_biUnion [DecidableEq M] {α : Type*} (s : Finset α) (f : s → Finset M) : span R (s.attach.biUnion f : Set M) = ⨆ x, span R (f x) := by simp [span_iUnion] #align submodule.span_attach_bUnion Submodule.span_attach_biUnion theorem sup_span : p ⊔ span R s = span R (p ∪ s) := by rw [Submodule.span_union, p.span_eq] #align submodule.sup_span Submodule.sup_span theorem span_sup : span R s ⊔ p = span R (s ∪ p) := by rw [Submodule.span_union, p.span_eq] #align submodule.span_sup Submodule.span_sup notation:1000 /- Note that the character `∙` U+2219 used below is different from the scalar multiplication character `•` U+2022. -/ R " ∙ " x => span R (singleton x) theorem span_eq_iSup_of_singleton_spans (s : Set M) : span R s = ⨆ x ∈ s, R ∙ x := by simp only [← span_iUnion, Set.biUnion_of_singleton s] #align submodule.span_eq_supr_of_singleton_spans Submodule.span_eq_iSup_of_singleton_spans theorem span_range_eq_iSup {ι : Sort*} {v : ι → M} : span R (range v) = ⨆ i, R ∙ v i := by rw [span_eq_iSup_of_singleton_spans, iSup_range] #align submodule.span_range_eq_supr Submodule.span_range_eq_iSup theorem span_smul_le (s : Set M) (r : R) : span R (r • s) ≤ span R s := by rw [span_le] rintro _ ⟨x, hx, rfl⟩ exact smul_mem (span R s) r (subset_span hx) #align submodule.span_smul_le Submodule.span_smul_le theorem subset_span_trans {U V W : Set M} (hUV : U ⊆ Submodule.span R V) (hVW : V ⊆ Submodule.span R W) : U ⊆ Submodule.span R W := (Submodule.gi R M).gc.le_u_l_trans hUV hVW #align submodule.subset_span_trans Submodule.subset_span_trans /-- See `Submodule.span_smul_eq` (in `RingTheory.Ideal.Operations`) for `span R (r • s) = r • span R s` that holds for arbitrary `r` in a `CommSemiring`. -/ theorem span_smul_eq_of_isUnit (s : Set M) (r : R) (hr : IsUnit r) : span R (r • s) = span R s := by apply le_antisymm · apply span_smul_le · convert span_smul_le (r • s) ((hr.unit⁻¹ : _) : R) rw [smul_smul] erw [hr.unit.inv_val] rw [one_smul] #align submodule.span_smul_eq_of_is_unit Submodule.span_smul_eq_of_isUnit @[simp] theorem coe_iSup_of_directed {ι} [Nonempty ι] (S : ι → Submodule R M) (H : Directed (· ≤ ·) S) : ((iSup S: Submodule R M) : Set M) = ⋃ i, S i := let s : Submodule R M := { __ := AddSubmonoid.copy _ _ (AddSubmonoid.coe_iSup_of_directed H).symm smul_mem' := fun r _ hx ↦ have ⟨i, hi⟩ := Set.mem_iUnion.mp hx Set.mem_iUnion.mpr ⟨i, (S i).smul_mem' r hi⟩ } have : iSup S = s := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (S i : Set M)) i) (Set.iUnion_subset fun _ ↦ le_iSup S _) this.symm ▸ rfl #align submodule.coe_supr_of_directed Submodule.coe_iSup_of_directed @[simp] theorem mem_iSup_of_directed {ι} [Nonempty ι] (S : ι → Submodule R M) (H : Directed (· ≤ ·) S) {x} : x ∈ iSup S ↔ ∃ i, x ∈ S i := by rw [← SetLike.mem_coe, coe_iSup_of_directed S H, mem_iUnion] rfl #align submodule.mem_supr_of_directed Submodule.mem_iSup_of_directed theorem mem_sSup_of_directed {s : Set (Submodule R M)} {z} (hs : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s) : z ∈ sSup s ↔ ∃ y ∈ s, z ∈ y := by have : Nonempty s := hs.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed _ hdir.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] #align submodule.mem_Sup_of_directed Submodule.mem_sSup_of_directed @[norm_cast, simp] theorem coe_iSup_of_chain (a : ℕ →o Submodule R M) : (↑(⨆ k, a k) : Set M) = ⋃ k, (a k : Set M) := coe_iSup_of_directed a a.monotone.directed_le #align submodule.coe_supr_of_chain Submodule.coe_iSup_of_chain /-- We can regard `coe_iSup_of_chain` as the statement that `(↑) : (Submodule R M) → Set M` is Scott continuous for the ω-complete partial order induced by the complete lattice structures. -/ theorem coe_scott_continuous : OmegaCompletePartialOrder.Continuous' ((↑) : Submodule R M → Set M) := ⟨SetLike.coe_mono, coe_iSup_of_chain⟩ #align submodule.coe_scott_continuous Submodule.coe_scott_continuous @[simp] theorem mem_iSup_of_chain (a : ℕ →o Submodule R M) (m : M) : (m ∈ ⨆ k, a k) ↔ ∃ k, m ∈ a k := mem_iSup_of_directed a a.monotone.directed_le #align submodule.mem_supr_of_chain Submodule.mem_iSup_of_chain section variable {p p'} theorem mem_sup : x ∈ p ⊔ p' ↔ ∃ y ∈ p, ∃ z ∈ p', y + z = x := ⟨fun h => by rw [← span_eq p, ← span_eq p', ← span_union] at h refine span_induction h ?_ ?_ ?_ ?_ · rintro y (h | h) · exact ⟨y, h, 0, by simp, by simp⟩ · exact ⟨0, by simp, y, h, by simp⟩ · exact ⟨0, by simp, 0, by simp⟩ · rintro _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩ exact ⟨_, add_mem hy₁ hy₂, _, add_mem hz₁ hz₂, by rw [add_assoc, add_assoc, ← add_assoc y₂, ← add_assoc z₁, add_comm y₂]⟩ · rintro a _ ⟨y, hy, z, hz, rfl⟩ exact ⟨_, smul_mem _ a hy, _, smul_mem _ a hz, by simp [smul_add]⟩, by rintro ⟨y, hy, z, hz, rfl⟩ exact add_mem ((le_sup_left : p ≤ p ⊔ p') hy) ((le_sup_right : p' ≤ p ⊔ p') hz)⟩ #align submodule.mem_sup Submodule.mem_sup theorem mem_sup' : x ∈ p ⊔ p' ↔ ∃ (y : p) (z : p'), (y : M) + z = x := mem_sup.trans <| by simp only [Subtype.exists, exists_prop] #align submodule.mem_sup' Submodule.mem_sup' lemma exists_add_eq_of_codisjoint (h : Codisjoint p p') (x : M) : ∃ y ∈ p, ∃ z ∈ p', y + z = x := by suffices x ∈ p ⊔ p' by exact Submodule.mem_sup.mp this simpa only [h.eq_top] using Submodule.mem_top variable (p p') theorem coe_sup : ↑(p ⊔ p') = (p + p' : Set M) := by ext rw [SetLike.mem_coe, mem_sup, Set.mem_add] simp #align submodule.coe_sup Submodule.coe_sup theorem sup_toAddSubmonoid : (p ⊔ p').toAddSubmonoid = p.toAddSubmonoid ⊔ p'.toAddSubmonoid := by ext x rw [mem_toAddSubmonoid, mem_sup, AddSubmonoid.mem_sup] rfl #align submodule.sup_to_add_submonoid Submodule.sup_toAddSubmonoid theorem sup_toAddSubgroup {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] (p p' : Submodule R M) : (p ⊔ p').toAddSubgroup = p.toAddSubgroup ⊔ p'.toAddSubgroup := by ext x rw [mem_toAddSubgroup, mem_sup, AddSubgroup.mem_sup] rfl #align submodule.sup_to_add_subgroup Submodule.sup_toAddSubgroup end theorem mem_span_singleton_self (x : M) : x ∈ R ∙ x := subset_span rfl #align submodule.mem_span_singleton_self Submodule.mem_span_singleton_self theorem nontrivial_span_singleton {x : M} (h : x ≠ 0) : Nontrivial (R ∙ x) := ⟨by use 0, ⟨x, Submodule.mem_span_singleton_self x⟩ intro H rw [eq_comm, Submodule.mk_eq_zero] at H exact h H⟩ #align submodule.nontrivial_span_singleton Submodule.nontrivial_span_singleton theorem mem_span_singleton {y : M} : (x ∈ R ∙ y) ↔ ∃ a : R, a • y = x := ⟨fun h => by refine span_induction h ?_ ?_ ?_ ?_ · rintro y (rfl | ⟨⟨_⟩⟩) exact ⟨1, by simp⟩ · exact ⟨0, by simp⟩ · rintro _ _ ⟨a, rfl⟩ ⟨b, rfl⟩ exact ⟨a + b, by simp [add_smul]⟩ · rintro a _ ⟨b, rfl⟩ exact ⟨a * b, by simp [smul_smul]⟩, by rintro ⟨a, y, rfl⟩; exact smul_mem _ _ (subset_span <| by simp)⟩ #align submodule.mem_span_singleton Submodule.mem_span_singleton theorem le_span_singleton_iff {s : Submodule R M} {v₀ : M} : (s ≤ R ∙ v₀) ↔ ∀ v ∈ s, ∃ r : R, r • v₀ = v := by simp_rw [SetLike.le_def, mem_span_singleton] #align submodule.le_span_singleton_iff Submodule.le_span_singleton_iff variable (R)
Mathlib/LinearAlgebra/Span.lean
504
506
theorem span_singleton_eq_top_iff (x : M) : (R ∙ x) = ⊤ ↔ ∀ v, ∃ r : R, r • x = v := by
rw [eq_top_iff, le_span_singleton_iff] tauto
/- Copyright (c) 2022 Wrenna Robson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wrenna Robson -/ import Mathlib.Topology.MetricSpace.Basic #align_import topology.metric_space.infsep from "leanprover-community/mathlib"@"5316314b553dcf8c6716541851517c1a9715e22b" /-! # Infimum separation This file defines the extended infimum separation of a set. This is approximately dual to the diameter of a set, but where the extended diameter of a set is the supremum of the extended distance between elements of the set, the extended infimum separation is the infimum of the (extended) distance between *distinct* elements in the set. We also define the infimum separation as the cast of the extended infimum separation to the reals. This is the infimum of the distance between distinct elements of the set when in a pseudometric space. All lemmas and definitions are in the `Set` namespace to give access to dot notation. ## Main definitions * `Set.einfsep`: Extended infimum separation of a set. * `Set.infsep`: Infimum separation of a set (when in a pseudometric space). !-/ variable {α β : Type*} namespace Set section Einfsep open ENNReal open Function /-- The "extended infimum separation" of a set with an edist function. -/ noncomputable def einfsep [EDist α] (s : Set α) : ℝ≥0∞ := ⨅ (x ∈ s) (y ∈ s) (_ : x ≠ y), edist x y #align set.einfsep Set.einfsep section EDist variable [EDist α] {x y : α} {s t : Set α} theorem le_einfsep_iff {d} : d ≤ s.einfsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y := by simp_rw [einfsep, le_iInf_iff] #align set.le_einfsep_iff Set.le_einfsep_iff theorem einfsep_zero : s.einfsep = 0 ↔ ∀ C > 0, ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < C := by simp_rw [einfsep, ← _root_.bot_eq_zero, iInf_eq_bot, iInf_lt_iff, exists_prop] #align set.einfsep_zero Set.einfsep_zero theorem einfsep_pos : 0 < s.einfsep ↔ ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by rw [pos_iff_ne_zero, Ne, einfsep_zero] simp only [not_forall, not_exists, not_lt, exists_prop, not_and] #align set.einfsep_pos Set.einfsep_pos theorem einfsep_top : s.einfsep = ∞ ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → edist x y = ∞ := by simp_rw [einfsep, iInf_eq_top] #align set.einfsep_top Set.einfsep_top theorem einfsep_lt_top : s.einfsep < ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < ∞ := by simp_rw [einfsep, iInf_lt_iff, exists_prop] #align set.einfsep_lt_top Set.einfsep_lt_top theorem einfsep_ne_top : s.einfsep ≠ ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y ≠ ∞ := by simp_rw [← lt_top_iff_ne_top, einfsep_lt_top] #align set.einfsep_ne_top Set.einfsep_ne_top theorem einfsep_lt_iff {d} : s.einfsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < d := by simp_rw [einfsep, iInf_lt_iff, exists_prop] #align set.einfsep_lt_iff Set.einfsep_lt_iff theorem nontrivial_of_einfsep_lt_top (hs : s.einfsep < ∞) : s.Nontrivial := by rcases einfsep_lt_top.1 hs with ⟨_, hx, _, hy, hxy, _⟩ exact ⟨_, hx, _, hy, hxy⟩ #align set.nontrivial_of_einfsep_lt_top Set.nontrivial_of_einfsep_lt_top theorem nontrivial_of_einfsep_ne_top (hs : s.einfsep ≠ ∞) : s.Nontrivial := nontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs) #align set.nontrivial_of_einfsep_ne_top Set.nontrivial_of_einfsep_ne_top theorem Subsingleton.einfsep (hs : s.Subsingleton) : s.einfsep = ∞ := by rw [einfsep_top] exact fun _ hx _ hy hxy => (hxy <| hs hx hy).elim #align set.subsingleton.einfsep Set.Subsingleton.einfsep theorem le_einfsep_image_iff {d} {f : β → α} {s : Set β} : d ≤ einfsep (f '' s) ↔ ∀ x ∈ s, ∀ y ∈ s, f x ≠ f y → d ≤ edist (f x) (f y) := by simp_rw [le_einfsep_iff, forall_mem_image] #align set.le_einfsep_image_iff Set.le_einfsep_image_iff theorem le_edist_of_le_einfsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hd : d ≤ s.einfsep) : d ≤ edist x y := le_einfsep_iff.1 hd x hx y hy hxy #align set.le_edist_of_le_einfsep Set.le_edist_of_le_einfsep theorem einfsep_le_edist_of_mem {x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) : s.einfsep ≤ edist x y := le_edist_of_le_einfsep hx hy hxy le_rfl #align set.einfsep_le_edist_of_mem Set.einfsep_le_edist_of_mem theorem einfsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) (hxy' : edist x y ≤ d) : s.einfsep ≤ d := le_trans (einfsep_le_edist_of_mem hx hy hxy) hxy' #align set.einfsep_le_of_mem_of_edist_le Set.einfsep_le_of_mem_of_edist_le theorem le_einfsep {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y) : d ≤ s.einfsep := le_einfsep_iff.2 h #align set.le_einfsep Set.le_einfsep @[simp] theorem einfsep_empty : (∅ : Set α).einfsep = ∞ := subsingleton_empty.einfsep #align set.einfsep_empty Set.einfsep_empty @[simp] theorem einfsep_singleton : ({x} : Set α).einfsep = ∞ := subsingleton_singleton.einfsep #align set.einfsep_singleton Set.einfsep_singleton theorem einfsep_iUnion_mem_option {ι : Type*} (o : Option ι) (s : ι → Set α) : (⋃ i ∈ o, s i).einfsep = ⨅ i ∈ o, (s i).einfsep := by cases o <;> simp #align set.einfsep_Union_mem_option Set.einfsep_iUnion_mem_option theorem einfsep_anti (hst : s ⊆ t) : t.einfsep ≤ s.einfsep := le_einfsep fun _x hx _y hy => einfsep_le_edist_of_mem (hst hx) (hst hy) #align set.einfsep_anti Set.einfsep_anti theorem einfsep_insert_le : (insert x s).einfsep ≤ ⨅ (y ∈ s) (_ : x ≠ y), edist x y := by simp_rw [le_iInf_iff] exact fun _ hy hxy => einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ hy) hxy #align set.einfsep_insert_le Set.einfsep_insert_le theorem le_einfsep_pair : edist x y ⊓ edist y x ≤ ({x, y} : Set α).einfsep := by simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff, mem_singleton_iff] rintro a (rfl | rfl) b (rfl | rfl) hab <;> (try simp only [le_refl, true_or, or_true]) <;> contradiction #align set.le_einfsep_pair Set.le_einfsep_pair theorem einfsep_pair_le_left (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist x y := einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hxy #align set.einfsep_pair_le_left Set.einfsep_pair_le_left theorem einfsep_pair_le_right (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist y x := by rw [pair_comm]; exact einfsep_pair_le_left hxy.symm #align set.einfsep_pair_le_right Set.einfsep_pair_le_right theorem einfsep_pair_eq_inf (hxy : x ≠ y) : ({x, y} : Set α).einfsep = edist x y ⊓ edist y x := le_antisymm (le_inf (einfsep_pair_le_left hxy) (einfsep_pair_le_right hxy)) le_einfsep_pair #align set.einfsep_pair_eq_inf Set.einfsep_pair_eq_inf
Mathlib/Topology/MetricSpace/Infsep.lean
163
166
theorem einfsep_eq_iInf : s.einfsep = ⨅ d : s.offDiag, (uncurry edist) (d : α × α) := by
refine eq_of_forall_le_iff fun _ => ?_ simp_rw [le_einfsep_iff, le_iInf_iff, imp_forall_iff, SetCoe.forall, mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp]
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.Discriminant import Mathlib.RingTheory.Polynomial.Eisenstein.IsIntegral import Mathlib.RingTheory.Ideal.Norm #align_import number_theory.cyclotomic.rat from "leanprover-community/mathlib"@"b353176c24d96c23f0ce1cc63efc3f55019702d9" /-! # Ring of integers of `p ^ n`-th cyclotomic fields We gather results about cyclotomic extensions of `ℚ`. In particular, we compute the ring of integers of a `p ^ n`-th cyclotomic extension of `ℚ`. ## Main results * `IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime_pow`: if `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the integral closure of `ℤ` in `K`. * `IsCyclotomicExtension.Rat.cyclotomicRing_isIntegralClosure_of_prime_pow`: the integral closure of `ℤ` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) ℤ ℚ`. * `IsCyclotomicExtension.Rat.absdiscr_prime_pow` and related results: the absolute discriminant of cyclotomic fields. -/ universe u open Algebra IsCyclotomicExtension Polynomial NumberField open scoped Cyclotomic Nat variable {p : ℕ+} {k : ℕ} {K : Type u} [Field K] [CharZero K] {ζ : K} [hp : Fact (p : ℕ).Prime] namespace IsCyclotomicExtension.Rat /-- The discriminant of the power basis given by `ζ - 1`. -/ theorem discr_prime_pow_ne_two' [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hk : p ^ (k + 1) ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ (k + 1) : ℕ).totient / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) := by rw [← discr_prime_pow_ne_two hζ (cyclotomic.irreducible_rat (p ^ (k + 1)).pos) hk] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm #align is_cyclotomic_extension.rat.discr_prime_pow_ne_two' IsCyclotomicExtension.Rat.discr_prime_pow_ne_two' theorem discr_odd_prime' [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) (hodd : p ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) := by rw [← discr_odd_prime hζ (cyclotomic.irreducible_rat hp.out.pos) hodd] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm #align is_cyclotomic_extension.rat.discr_odd_prime' IsCyclotomicExtension.Rat.discr_odd_prime' /-- The discriminant of the power basis given by `ζ - 1`. Beware that in the cases `p ^ k = 1` and `p ^ k = 2` the formula uses `1 / 2 = 0` and `0 - 1 = 0`. It is useful only to have a uniform result. See also `IsCyclotomicExtension.Rat.discr_prime_pow_eq_unit_mul_pow'`. -/
Mathlib/NumberTheory/Cyclotomic/Rat.lean
55
59
theorem discr_prime_pow' [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ k : ℕ).totient / 2) * p ^ ((p : ℕ) ^ (k - 1) * ((p - 1) * k - 1)) := by
rw [← discr_prime_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos)] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm
/- 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, Jeremy Avigad -/ import Mathlib.Order.Filter.Lift import Mathlib.Topology.Defs.Filter #align_import topology.basic from "leanprover-community/mathlib"@"e354e865255654389cc46e6032160238df2e0f40" /-! # Basic theory of topological spaces. The main definition is the type class `TopologicalSpace X` which endows a type `X` with a topology. Then `Set X` gets predicates `IsOpen`, `IsClosed` and functions `interior`, `closure` and `frontier`. Each point `x` of `X` gets a neighborhood filter `𝓝 x`. A filter `F` on `X` has `x` as a cluster point if `ClusterPt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : α → X` clusters at `x` along `F : Filter α` if `MapClusterPt x F f : ClusterPt x (map f F)`. In particular the notion of cluster point of a sequence `u` is `MapClusterPt x atTop u`. For topological spaces `X` and `Y`, a function `f : X → Y` and a point `x : X`, `ContinuousAt f x` means `f` is continuous at `x`, and global continuity is `Continuous f`. There is also a version of continuity `PContinuous` for partially defined functions. ## Notation The following notation is introduced elsewhere and it heavily used in this file. * `𝓝 x`: the filter `nhds x` of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`; * `𝓝[≠] x`: the filter `nhdsWithin x {x}ᶜ` of punctured neighborhoods of `x`. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space, interior, closure, frontier, neighborhood, continuity, continuous function -/ noncomputable section open Set Filter universe u v w x /-! ### Topological spaces -/ /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T) (union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where IsOpen X := Xᶜ ∈ T isOpen_univ := by simp [empty_mem] isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht isOpen_sUnion s hs := by simp only [Set.compl_sUnion] exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy #align topological_space.of_closed TopologicalSpace.ofClosed section TopologicalSpace variable {X : Type u} {Y : Type v} {ι : Sort w} {α β : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} open Topology lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl #align is_open_mk isOpen_mk @[ext] protected theorem TopologicalSpace.ext : ∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align topological_space_eq TopologicalSpace.ext section variable [TopologicalSpace X] end protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} : t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s := ⟨fun h s => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ #align topological_space_eq_iff TopologicalSpace.ext_iff theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s := rfl #align is_open_fold isOpen_fold variable [TopologicalSpace X] theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) := isOpen_sUnion (forall_mem_range.2 h) #align is_open_Union isOpen_iUnion theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋃ i ∈ s, f i) := isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi #align is_open_bUnion isOpen_biUnion theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) #align is_open.union IsOpen.union lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) : IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩ rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter] exact isOpen_iUnion fun i ↦ h i @[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim #align is_open_empty isOpen_empty theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) : (∀ t ∈ s, IsOpen t) → IsOpen (⋂₀ s) := Finite.induction_on hs (fun _ => by rw [sInter_empty]; exact isOpen_univ) fun _ _ ih h => by simp only [sInter_insert, forall_mem_insert] at h ⊢ exact h.1.inter (ih h.2) #align is_open_sInter Set.Finite.isOpen_sInter theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h) #align is_open_bInter Set.Finite.isOpen_biInter theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) : IsOpen (⋂ i, s i) := (finite_range _).isOpen_sInter (forall_mem_range.2 h) #align is_open_Inter isOpen_iInter_of_finite theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := s.finite_toSet.isOpen_biInter h #align is_open_bInter_finset isOpen_biInter_finset @[simp] -- Porting note: added `simp` theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*] #align is_open_const isOpen_const theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } := IsOpen.inter #align is_open.and IsOpen.and @[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s := ⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩ #align is_open_compl_iff isOpen_compl_iff theorem TopologicalSpace.ext_iff_isClosed {t₁ t₂ : TopologicalSpace X} : t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by rw [TopologicalSpace.ext_iff, compl_surjective.forall] simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂] alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed -- Porting note (#10756): new lemma theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩ @[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const #align is_closed_empty isClosed_empty @[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const #align is_closed_univ isClosed_univ theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter #align is_closed.union IsClosed.union theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion #align is_closed_sInter isClosed_sInter theorem isClosed_iInter {f : ι → Set X} (h : ∀ i, IsClosed (f i)) : IsClosed (⋂ i, f i) := isClosed_sInter <| forall_mem_range.2 h #align is_closed_Inter isClosed_iInter theorem isClosed_biInter {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋂ i ∈ s, f i) := isClosed_iInter fun i => isClosed_iInter <| h i #align is_closed_bInter isClosed_biInter @[simp] theorem isClosed_compl_iff {s : Set X} : IsClosed sᶜ ↔ IsOpen s := by rw [← isOpen_compl_iff, compl_compl] #align is_closed_compl_iff isClosed_compl_iff alias ⟨_, IsOpen.isClosed_compl⟩ := isClosed_compl_iff #align is_open.is_closed_compl IsOpen.isClosed_compl theorem IsOpen.sdiff (h₁ : IsOpen s) (h₂ : IsClosed t) : IsOpen (s \ t) := IsOpen.inter h₁ h₂.isOpen_compl #align is_open.sdiff IsOpen.sdiff theorem IsClosed.inter (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ∩ s₂) := by rw [← isOpen_compl_iff] at * rw [compl_inter] exact IsOpen.union h₁ h₂ #align is_closed.inter IsClosed.inter theorem IsClosed.sdiff (h₁ : IsClosed s) (h₂ : IsOpen t) : IsClosed (s \ t) := IsClosed.inter h₁ (isClosed_compl_iff.mpr h₂) #align is_closed.sdiff IsClosed.sdiff theorem Set.Finite.isClosed_biUnion {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact hs.isOpen_biInter h #align is_closed_bUnion Set.Finite.isClosed_biUnion lemma isClosed_biUnion_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := s.finite_toSet.isClosed_biUnion h theorem isClosed_iUnion_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsClosed (s i)) : IsClosed (⋃ i, s i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact isOpen_iInter_of_finite h #align is_closed_Union isClosed_iUnion_of_finite theorem isClosed_imp {p q : X → Prop} (hp : IsOpen { x | p x }) (hq : IsClosed { x | q x }) : IsClosed { x | p x → q x } := by simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq #align is_closed_imp isClosed_imp theorem IsClosed.not : IsClosed { a | p a } → IsOpen { a | ¬p a } := isOpen_compl_iff.mpr #align is_closed.not IsClosed.not /-! ### Interior of a set -/ theorem mem_interior : x ∈ interior s ↔ ∃ t ⊆ s, IsOpen t ∧ x ∈ t := by simp only [interior, mem_sUnion, mem_setOf_eq, and_assoc, and_left_comm] #align mem_interior mem_interiorₓ @[simp] theorem isOpen_interior : IsOpen (interior s) := isOpen_sUnion fun _ => And.left #align is_open_interior isOpen_interior theorem interior_subset : interior s ⊆ s := sUnion_subset fun _ => And.right #align interior_subset interior_subset theorem interior_maximal (h₁ : t ⊆ s) (h₂ : IsOpen t) : t ⊆ interior s := subset_sUnion_of_mem ⟨h₂, h₁⟩ #align interior_maximal interior_maximal theorem IsOpen.interior_eq (h : IsOpen s) : interior s = s := interior_subset.antisymm (interior_maximal (Subset.refl s) h) #align is_open.interior_eq IsOpen.interior_eq theorem interior_eq_iff_isOpen : interior s = s ↔ IsOpen s := ⟨fun h => h ▸ isOpen_interior, IsOpen.interior_eq⟩ #align interior_eq_iff_is_open interior_eq_iff_isOpen theorem subset_interior_iff_isOpen : s ⊆ interior s ↔ IsOpen s := by simp only [interior_eq_iff_isOpen.symm, Subset.antisymm_iff, interior_subset, true_and] #align subset_interior_iff_is_open subset_interior_iff_isOpen theorem IsOpen.subset_interior_iff (h₁ : IsOpen s) : s ⊆ interior t ↔ s ⊆ t := ⟨fun h => Subset.trans h interior_subset, fun h₂ => interior_maximal h₂ h₁⟩ #align is_open.subset_interior_iff IsOpen.subset_interior_iff theorem subset_interior_iff : t ⊆ interior s ↔ ∃ U, IsOpen U ∧ t ⊆ U ∧ U ⊆ s := ⟨fun h => ⟨interior s, isOpen_interior, h, interior_subset⟩, fun ⟨_U, hU, htU, hUs⟩ => htU.trans (interior_maximal hUs hU)⟩ #align subset_interior_iff subset_interior_iff lemma interior_subset_iff : interior s ⊆ t ↔ ∀ U, IsOpen U → U ⊆ s → U ⊆ t := by simp [interior] @[mono, gcongr] theorem interior_mono (h : s ⊆ t) : interior s ⊆ interior t := interior_maximal (Subset.trans interior_subset h) isOpen_interior #align interior_mono interior_mono @[simp] theorem interior_empty : interior (∅ : Set X) = ∅ := isOpen_empty.interior_eq #align interior_empty interior_empty @[simp] theorem interior_univ : interior (univ : Set X) = univ := isOpen_univ.interior_eq #align interior_univ interior_univ @[simp] theorem interior_eq_univ : interior s = univ ↔ s = univ := ⟨fun h => univ_subset_iff.mp <| h.symm.trans_le interior_subset, fun h => h.symm ▸ interior_univ⟩ #align interior_eq_univ interior_eq_univ @[simp] theorem interior_interior : interior (interior s) = interior s := isOpen_interior.interior_eq #align interior_interior interior_interior @[simp] theorem interior_inter : interior (s ∩ t) = interior s ∩ interior t := (Monotone.map_inf_le (fun _ _ ↦ interior_mono) s t).antisymm <| interior_maximal (inter_subset_inter interior_subset interior_subset) <| isOpen_interior.inter isOpen_interior #align interior_inter interior_inter theorem Set.Finite.interior_biInter {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := hs.induction_on (by simp) <| by intros; simp [*] theorem Set.Finite.interior_sInter {S : Set (Set X)} (hS : S.Finite) : interior (⋂₀ S) = ⋂ s ∈ S, interior s := by rw [sInter_eq_biInter, hS.interior_biInter] @[simp] theorem Finset.interior_iInter {ι : Type*} (s : Finset ι) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := s.finite_toSet.interior_biInter f #align finset.interior_Inter Finset.interior_iInter @[simp] theorem interior_iInter_of_finite [Finite ι] (f : ι → Set X) : interior (⋂ i, f i) = ⋂ i, interior (f i) := by rw [← sInter_range, (finite_range f).interior_sInter, biInter_range] #align interior_Inter interior_iInter_of_finite theorem interior_union_isClosed_of_interior_empty (h₁ : IsClosed s) (h₂ : interior t = ∅) : interior (s ∪ t) = interior s := have : interior (s ∪ t) ⊆ s := fun x ⟨u, ⟨(hu₁ : IsOpen u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩ => by_contradiction fun hx₂ : x ∉ s => have : u \ s ⊆ t := fun x ⟨h₁, h₂⟩ => Or.resolve_left (hu₂ h₁) h₂ have : u \ s ⊆ interior t := by rwa [(IsOpen.sdiff hu₁ h₁).subset_interior_iff] have : u \ s ⊆ ∅ := by rwa [h₂] at this this ⟨hx₁, hx₂⟩ Subset.antisymm (interior_maximal this isOpen_interior) (interior_mono subset_union_left) #align interior_union_is_closed_of_interior_empty interior_union_isClosed_of_interior_empty theorem isOpen_iff_forall_mem_open : IsOpen s ↔ ∀ x ∈ s, ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t := by rw [← subset_interior_iff_isOpen] simp only [subset_def, mem_interior] #align is_open_iff_forall_mem_open isOpen_iff_forall_mem_open theorem interior_iInter_subset (s : ι → Set X) : interior (⋂ i, s i) ⊆ ⋂ i, interior (s i) := subset_iInter fun _ => interior_mono <| iInter_subset _ _ #align interior_Inter_subset interior_iInter_subset theorem interior_iInter₂_subset (p : ι → Sort*) (s : ∀ i, p i → Set X) : interior (⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), interior (s i j) := (interior_iInter_subset _).trans <| iInter_mono fun _ => interior_iInter_subset _ #align interior_Inter₂_subset interior_iInter₂_subset theorem interior_sInter_subset (S : Set (Set X)) : interior (⋂₀ S) ⊆ ⋂ s ∈ S, interior s := calc interior (⋂₀ S) = interior (⋂ s ∈ S, s) := by rw [sInter_eq_biInter] _ ⊆ ⋂ s ∈ S, interior s := interior_iInter₂_subset _ _ #align interior_sInter_subset interior_sInter_subset theorem Filter.HasBasis.lift'_interior {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) : (l.lift' interior).HasBasis p fun i => interior (s i) := h.lift' fun _ _ ↦ interior_mono theorem Filter.lift'_interior_le (l : Filter X) : l.lift' interior ≤ l := fun _s hs ↦ mem_of_superset (mem_lift' hs) interior_subset theorem Filter.HasBasis.lift'_interior_eq_self {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) (ho : ∀ i, p i → IsOpen (s i)) : l.lift' interior = l := le_antisymm l.lift'_interior_le <| h.lift'_interior.ge_iff.2 fun i hi ↦ by simpa only [(ho i hi).interior_eq] using h.mem_of_mem hi /-! ### Closure of a set -/ @[simp] theorem isClosed_closure : IsClosed (closure s) := isClosed_sInter fun _ => And.left #align is_closed_closure isClosed_closure theorem subset_closure : s ⊆ closure s := subset_sInter fun _ => And.right #align subset_closure subset_closure theorem not_mem_of_not_mem_closure {P : X} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) #align not_mem_of_not_mem_closure not_mem_of_not_mem_closure theorem closure_minimal (h₁ : s ⊆ t) (h₂ : IsClosed t) : closure s ⊆ t := sInter_subset_of_mem ⟨h₂, h₁⟩ #align closure_minimal closure_minimal theorem Disjoint.closure_left (hd : Disjoint s t) (ht : IsOpen t) : Disjoint (closure s) t := disjoint_compl_left.mono_left <| closure_minimal hd.subset_compl_right ht.isClosed_compl #align disjoint.closure_left Disjoint.closure_left theorem Disjoint.closure_right (hd : Disjoint s t) (hs : IsOpen s) : Disjoint s (closure t) := (hd.symm.closure_left hs).symm #align disjoint.closure_right Disjoint.closure_right theorem IsClosed.closure_eq (h : IsClosed s) : closure s = s := Subset.antisymm (closure_minimal (Subset.refl s) h) subset_closure #align is_closed.closure_eq IsClosed.closure_eq theorem IsClosed.closure_subset (hs : IsClosed s) : closure s ⊆ s := closure_minimal (Subset.refl _) hs #align is_closed.closure_subset IsClosed.closure_subset theorem IsClosed.closure_subset_iff (h₁ : IsClosed t) : closure s ⊆ t ↔ s ⊆ t := ⟨Subset.trans subset_closure, fun h => closure_minimal h h₁⟩ #align is_closed.closure_subset_iff IsClosed.closure_subset_iff theorem IsClosed.mem_iff_closure_subset (hs : IsClosed s) : x ∈ s ↔ closure ({x} : Set X) ⊆ s := (hs.closure_subset_iff.trans Set.singleton_subset_iff).symm #align is_closed.mem_iff_closure_subset IsClosed.mem_iff_closure_subset @[mono, gcongr] theorem closure_mono (h : s ⊆ t) : closure s ⊆ closure t := closure_minimal (Subset.trans h subset_closure) isClosed_closure #align closure_mono closure_mono theorem monotone_closure (X : Type*) [TopologicalSpace X] : Monotone (@closure X _) := fun _ _ => closure_mono #align monotone_closure monotone_closure theorem diff_subset_closure_iff : s \ t ⊆ closure t ↔ s ⊆ closure t := by rw [diff_subset_iff, union_eq_self_of_subset_left subset_closure] #align diff_subset_closure_iff diff_subset_closure_iff theorem closure_inter_subset_inter_closure (s t : Set X) : closure (s ∩ t) ⊆ closure s ∩ closure t := (monotone_closure X).map_inf_le s t #align closure_inter_subset_inter_closure closure_inter_subset_inter_closure theorem isClosed_of_closure_subset (h : closure s ⊆ s) : IsClosed s := by rw [subset_closure.antisymm h]; exact isClosed_closure #align is_closed_of_closure_subset isClosed_of_closure_subset theorem closure_eq_iff_isClosed : closure s = s ↔ IsClosed s := ⟨fun h => h ▸ isClosed_closure, IsClosed.closure_eq⟩ #align closure_eq_iff_is_closed closure_eq_iff_isClosed theorem closure_subset_iff_isClosed : closure s ⊆ s ↔ IsClosed s := ⟨isClosed_of_closure_subset, IsClosed.closure_subset⟩ #align closure_subset_iff_is_closed closure_subset_iff_isClosed @[simp] theorem closure_empty : closure (∅ : Set X) = ∅ := isClosed_empty.closure_eq #align closure_empty closure_empty @[simp] theorem closure_empty_iff (s : Set X) : closure s = ∅ ↔ s = ∅ := ⟨subset_eq_empty subset_closure, fun h => h.symm ▸ closure_empty⟩ #align closure_empty_iff closure_empty_iff @[simp] theorem closure_nonempty_iff : (closure s).Nonempty ↔ s.Nonempty := by simp only [nonempty_iff_ne_empty, Ne, closure_empty_iff] #align closure_nonempty_iff closure_nonempty_iff alias ⟨Set.Nonempty.of_closure, Set.Nonempty.closure⟩ := closure_nonempty_iff #align set.nonempty.of_closure Set.Nonempty.of_closure #align set.nonempty.closure Set.Nonempty.closure @[simp] theorem closure_univ : closure (univ : Set X) = univ := isClosed_univ.closure_eq #align closure_univ closure_univ @[simp] theorem closure_closure : closure (closure s) = closure s := isClosed_closure.closure_eq #align closure_closure closure_closure
Mathlib/Topology/Basic.lean
492
494
theorem closure_eq_compl_interior_compl : closure s = (interior sᶜ)ᶜ := by
rw [interior, closure, compl_sUnion, compl_image_set_of] simp only [compl_subset_compl, isOpen_compl_iff]
/- 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.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Monoidal.Functor #align_import category_theory.monoidal.preadditive from "leanprover-community/mathlib"@"986c4d5761f938b2e1c43c01f001b6d9d88c2055" /-! # Preadditive monoidal categories A monoidal category is `MonoidalPreadditive` if it is preadditive and tensor product of morphisms is linear in both factors. -/ noncomputable section open scoped Classical namespace CategoryTheory open CategoryTheory.Limits open CategoryTheory.MonoidalCategory variable (C : Type*) [Category C] [Preadditive C] [MonoidalCategory C] /-- A category is `MonoidalPreadditive` if tensoring is additive in both factors. Note we don't `extend Preadditive C` here, as `Abelian C` already extends it, and we'll need to have both typeclasses sometimes. -/ class MonoidalPreadditive : Prop where whiskerLeft_zero : ∀ {X Y Z : C}, X ◁ (0 : Y ⟶ Z) = 0 := by aesop_cat zero_whiskerRight : ∀ {X Y Z : C}, (0 : Y ⟶ Z) ▷ X = 0 := by aesop_cat whiskerLeft_add : ∀ {X Y Z : C} (f g : Y ⟶ Z), X ◁ (f + g) = X ◁ f + X ◁ g := by aesop_cat add_whiskerRight : ∀ {X Y Z : C} (f g : Y ⟶ Z), (f + g) ▷ X = f ▷ X + g ▷ X := by aesop_cat #align category_theory.monoidal_preadditive CategoryTheory.MonoidalPreadditive attribute [simp] MonoidalPreadditive.whiskerLeft_zero MonoidalPreadditive.zero_whiskerRight attribute [simp] MonoidalPreadditive.whiskerLeft_add MonoidalPreadditive.add_whiskerRight variable {C} variable [MonoidalPreadditive C] namespace MonoidalPreadditive -- The priority setting will not be needed when we replace `𝟙 X ⊗ f` by `X ◁ f`. @[simp (low)] theorem tensor_zero {W X Y Z : C} (f : W ⟶ X) : f ⊗ (0 : Y ⟶ Z) = 0 := by simp [tensorHom_def] -- The priority setting will not be needed when we replace `f ⊗ 𝟙 X` by `f ▷ X`. @[simp (low)] theorem zero_tensor {W X Y Z : C} (f : Y ⟶ Z) : (0 : W ⟶ X) ⊗ f = 0 := by simp [tensorHom_def] theorem tensor_add {W X Y Z : C} (f : W ⟶ X) (g h : Y ⟶ Z) : f ⊗ (g + h) = f ⊗ g + f ⊗ h := by simp [tensorHom_def] theorem add_tensor {W X Y Z : C} (f g : W ⟶ X) (h : Y ⟶ Z) : (f + g) ⊗ h = f ⊗ h + g ⊗ h := by simp [tensorHom_def] end MonoidalPreadditive instance tensorLeft_additive (X : C) : (tensorLeft X).Additive where #align category_theory.tensor_left_additive CategoryTheory.tensorLeft_additive instance tensorRight_additive (X : C) : (tensorRight X).Additive where #align category_theory.tensor_right_additive CategoryTheory.tensorRight_additive instance tensoringLeft_additive (X : C) : ((tensoringLeft C).obj X).Additive where #align category_theory.tensoring_left_additive CategoryTheory.tensoringLeft_additive instance tensoringRight_additive (X : C) : ((tensoringRight C).obj X).Additive where #align category_theory.tensoring_right_additive CategoryTheory.tensoringRight_additive /-- A faithful additive monoidal functor to a monoidal preadditive category ensures that the domain is monoidal preadditive. -/ theorem monoidalPreadditive_of_faithful {D} [Category D] [Preadditive D] [MonoidalCategory D] (F : MonoidalFunctor D C) [F.Faithful] [F.Additive] : MonoidalPreadditive D := { whiskerLeft_zero := by intros apply F.toFunctor.map_injective simp [F.map_whiskerLeft] zero_whiskerRight := by intros apply F.toFunctor.map_injective simp [F.map_whiskerRight] whiskerLeft_add := by intros apply F.toFunctor.map_injective simp only [F.map_whiskerLeft, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp, MonoidalPreadditive.whiskerLeft_add] add_whiskerRight := by intros apply F.toFunctor.map_injective simp only [F.map_whiskerRight, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp, MonoidalPreadditive.add_whiskerRight] } #align category_theory.monoidal_preadditive_of_faithful CategoryTheory.monoidalPreadditive_of_faithful theorem whiskerLeft_sum (P : C) {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) : P ◁ ∑ j ∈ s, g j = ∑ j ∈ s, P ◁ g j := map_sum ((tensoringLeft C).obj P).mapAddHom g s theorem sum_whiskerRight {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) (P : C) : (∑ j ∈ s, g j) ▷ P = ∑ j ∈ s, g j ▷ P := map_sum ((tensoringRight C).obj P).mapAddHom g s theorem tensor_sum {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) : (f ⊗ ∑ j ∈ s, g j) = ∑ j ∈ s, f ⊗ g j := by simp only [tensorHom_def, whiskerLeft_sum, Preadditive.comp_sum] #align category_theory.tensor_sum CategoryTheory.tensor_sum theorem sum_tensor {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) : (∑ j ∈ s, g j) ⊗ f = ∑ j ∈ s, g j ⊗ f := by simp only [tensorHom_def, sum_whiskerRight, Preadditive.sum_comp] #align category_theory.sum_tensor CategoryTheory.sum_tensor -- In a closed monoidal category, this would hold because -- `tensorLeft X` is a left adjoint and hence preserves all colimits. -- In any case it is true in any preadditive category. instance (X : C) : PreservesFiniteBiproducts (tensorLeft X) where preserves {J} := { preserves := fun {f} => { preserves := fun {b} i => isBilimitOfTotal _ (by dsimp simp_rw [← id_tensorHom] simp only [← tensor_comp, Category.comp_id, ← tensor_sum, ← tensor_id, IsBilimit.total i]) } } instance (X : C) : PreservesFiniteBiproducts (tensorRight X) where preserves {J} := { preserves := fun {f} => { preserves := fun {b} i => isBilimitOfTotal _ (by dsimp simp_rw [← tensorHom_id] simp only [← tensor_comp, Category.comp_id, ← sum_tensor, ← tensor_id, IsBilimit.total i]) } } variable [HasFiniteBiproducts C] /-- The isomorphism showing how tensor product on the left distributes over direct sums. -/ def leftDistributor {J : Type} [Fintype J] (X : C) (f : J → C) : X ⊗ ⨁ f ≅ ⨁ fun j => X ⊗ f j := (tensorLeft X).mapBiproduct f #align category_theory.left_distributor CategoryTheory.leftDistributor theorem leftDistributor_hom {J : Type} [Fintype J] (X : C) (f : J → C) : (leftDistributor X f).hom = ∑ j : J, (X ◁ biproduct.π f j) ≫ biproduct.ι (fun j => X ⊗ f j) j := by ext dsimp [leftDistributor, Functor.mapBiproduct, Functor.mapBicone] erw [biproduct.lift_π] simp only [Preadditive.sum_comp, Category.assoc, biproduct.ι_π, comp_dite, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, ite_true, eqToHom_refl, Category.comp_id] #align category_theory.left_distributor_hom CategoryTheory.leftDistributor_hom theorem leftDistributor_inv {J : Type} [Fintype J] (X : C) (f : J → C) : (leftDistributor X f).inv = ∑ j : J, biproduct.π _ j ≫ (X ◁ biproduct.ι f j) := by ext dsimp [leftDistributor, Functor.mapBiproduct, Functor.mapBicone] simp only [Preadditive.comp_sum, biproduct.ι_π_assoc, dite_comp, zero_comp, Finset.sum_dite_eq, Finset.mem_univ, ite_true, eqToHom_refl, Category.id_comp, biproduct.ι_desc] #align category_theory.left_distributor_inv CategoryTheory.leftDistributor_inv @[reassoc (attr := simp)] theorem leftDistributor_hom_comp_biproduct_π {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : (leftDistributor X f).hom ≫ biproduct.π _ j = X ◁ biproduct.π _ j := by simp [leftDistributor_hom, Preadditive.sum_comp, biproduct.ι_π, comp_dite] @[reassoc (attr := simp)] theorem biproduct_ι_comp_leftDistributor_hom {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : (X ◁ biproduct.ι _ j) ≫ (leftDistributor X f).hom = biproduct.ι (fun j => X ⊗ f j) j := by simp [leftDistributor_hom, Preadditive.comp_sum, ← MonoidalCategory.whiskerLeft_comp_assoc, biproduct.ι_π, whiskerLeft_dite, dite_comp] @[reassoc (attr := simp)] theorem leftDistributor_inv_comp_biproduct_π {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : (leftDistributor X f).inv ≫ (X ◁ biproduct.π _ j) = biproduct.π _ j := by simp [leftDistributor_inv, Preadditive.sum_comp, ← MonoidalCategory.whiskerLeft_comp, biproduct.ι_π, whiskerLeft_dite, comp_dite] @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Monoidal/Preadditive.lean
188
190
theorem biproduct_ι_comp_leftDistributor_inv {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : biproduct.ι _ j ≫ (leftDistributor X f).inv = X ◁ biproduct.ι _ j := by
simp [leftDistributor_inv, Preadditive.comp_sum, ← id_tensor_comp, biproduct.ι_π_assoc, dite_comp]
/- 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)
Mathlib/MeasureTheory/OuterMeasure/Basic.lean
63
69
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
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.Algebra.Category.GroupCat.EquivalenceGroupAddGroup import Mathlib.GroupTheory.QuotientGroup #align_import algebra.category.Group.epi_mono from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Monomorphisms and epimorphisms in `Group` In this file, we prove monomorphisms in the category of groups are injective homomorphisms and epimorphisms are surjective homomorphisms. -/ noncomputable section open scoped Pointwise universe u v namespace MonoidHom open QuotientGroup variable {A : Type u} {B : Type v} section variable [Group A] [Group B] @[to_additive]
Mathlib/Algebra/Category/GroupCat/EpiMono.lean
35
36
theorem ker_eq_bot_of_cancel {f : A →* B} (h : ∀ u v : f.ker →* A, f.comp u = f.comp v → u = v) : f.ker = ⊥ := by
simpa using _root_.congr_arg range (h f.ker.subtype 1 (by aesop_cat))
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Topology.Bases import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Compactness.SigmaCompact /-! # Lindelöf sets and Lindelöf spaces ## Main definitions We define the following properties for sets in a topological space: * `IsLindelof s`: Two definitions are possible here. The more standard definition is that every open cover that contains `s` contains a countable subcover. We choose for the equivalent definition where we require that every nontrivial filter on `s` with the countable intersection property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`. * `LindelofSpace X`: `X` is Lindelöf if it is Lindelöf as a set. * `NonLindelofSpace`: a space that is not a Lindëlof space, e.g. the Long Line. ## Main results * `isLindelof_iff_countable_subcover`: A set is Lindelöf iff every open cover has a countable subcover. ## Implementation details * This API is mainly based on the API for IsCompact and follows notation and style as much as possible. -/ open Set Filter Topology TopologicalSpace universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Lindelof /-- A set `s` is Lindelöf if every nontrivial filter `f` with the countable intersection property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by `isLindelof_iff_countable_subcover`. -/ def IsLindelof (s : Set X) := ∀ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x f /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢ exact hs inf_le_right /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx ↦ ?_ rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left] exact hf x hx /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a Lindelöf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X → Prop} (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, p s) → p (⋃₀ S)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a Lindelöf set and a closed set is a Lindelöf set. -/ theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by intro f hnf _ hstf rw [← inf_principal, le_inf_iff] at hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs hstf.1 have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2 exact ⟨x, ⟨hsx, hxt⟩, hx⟩ /-- The intersection of a closed set and a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.inter_left (ht : IsLindelof t) (hs : IsClosed s) : IsLindelof (s ∩ t) := inter_comm t s ▸ ht.inter_right hs /-- The set difference of a Lindelöf set and an open set is a Lindelöf set. -/ theorem IsLindelof.diff (hs : IsLindelof s) (ht : IsOpen t) : IsLindelof (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) /-- A closed subset of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.of_isClosed_subset (hs : IsLindelof s) (ht : IsClosed t) (h : t ⊆ s) : IsLindelof t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht /-- A continuous image of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.image_of_continuousOn {f : X → Y} (hs : IsLindelof s) (hf : ContinuousOn f s) : IsLindelof (f '' s) := by intro l lne _ ls have : NeBot (l.comap f ⊓ 𝓟 s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this _ inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot /-- A continuous image of a Lindelöf set is a Lindelöf set within the codomain. -/ theorem IsLindelof.image {f : X → Y} (hs : IsLindelof s) (hf : Continuous f) : IsLindelof (f '' s) := hs.image_of_continuousOn hf.continuousOn /-- A filter with the countable intersection property that is finer than the principal filter on a Lindelöf set `s` contains any open set that contains all clusterpoints of `s`. -/ theorem IsLindelof.adherence_nhdset {f : Filter X} [CountableInterFilter f] (hs : IsLindelof s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := (eq_or_neBot _).casesOn mem_of_eq_bot fun _ ↦ let ⟨x, hx, hfx⟩ := @hs (f ⊓ 𝓟 tᶜ) _ _ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (ht₁.mem_nhds this) have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne absurd A this /-- For every open cover of a Lindelöf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover {ι : Type v} (hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i) := by have hmono : ∀ ⦃s t : Set X⦄, s ⊆ t → (∃ r : Set ι, r.Countable ∧ t ⊆ ⋃ i ∈ r, U i) → (∃ r : Set ι, r.Countable ∧ s ⊆ ⋃ i ∈ r, U i) := by intro _ _ hst ⟨r, ⟨hrcountable, hsub⟩⟩ exact ⟨r, hrcountable, Subset.trans hst hsub⟩ have hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i)) → ∃ r : Set ι, r.Countable ∧ (⋃₀ S ⊆ ⋃ i ∈ r, U i) := by intro S hS hsr choose! r hr using hsr refine ⟨⋃ s ∈ S, r s, hS.biUnion_iff.mpr (fun s hs ↦ (hr s hs).1), ?_⟩ refine sUnion_subset ?h.right.h simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] exact fun i is x hx ↦ mem_biUnion is ((hr i is).2 hx) have h_nhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∃ r : Set ι, r.Countable ∧ (t ⊆ ⋃ i ∈ r, U i) := by intro x hx let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) refine ⟨U i, mem_nhdsWithin_of_mem_nhds ((hUo i).mem_nhds hi), {i}, by simp, ?_⟩ simp only [mem_singleton_iff, iUnion_iUnion_eq_left] exact Subset.refl _ exact hs.induction_on hmono hcountable_union h_nhds theorem IsLindelof.elim_nhds_subcover' (hs : IsLindelof s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Set s, t.Countable ∧ s ⊆ ⋃ x ∈ t, U (x : s) x.2 := by have := hs.elim_countable_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ rcases this with ⟨r, ⟨hr, hs⟩⟩ use r, hr apply Subset.trans hs apply iUnion₂_subset intro i hi apply Subset.trans interior_subset exact subset_iUnion_of_subset i (subset_iUnion_of_subset hi (Subset.refl _)) theorem IsLindelof.elim_nhds_subcover (hs : IsLindelof s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Set X, t.Countable ∧ (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by let ⟨t, ⟨htc, htsub⟩⟩ := hs.elim_nhds_subcover' (fun x _ ↦ U x) hU refine ⟨↑t, Countable.image htc Subtype.val, ?_⟩ constructor · intro _ simp only [mem_image, Subtype.exists, exists_and_right, exists_eq_right, forall_exists_index] tauto · have : ⋃ x ∈ t, U ↑x = ⋃ x ∈ Subtype.val '' t, U x := biUnion_image.symm rwa [← this] /-- The neighborhood filter of a Lindelöf set is disjoint with a filter `l` with the countable intersection property if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/
Mathlib/Topology/Compactness/Lindelof.lean
182
192
theorem IsLindelof.disjoint_nhdsSet_left {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by
refine ⟨fun h x hx ↦ h.mono_left <| nhds_le_nhdsSet hx, fun H ↦ ?_⟩ choose! U hxU hUl using fun x hx ↦ (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx ↦ (hUo x hx).mem_nhds (hxU x hx) with ⟨t, htc, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 ⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx ↦ hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnion₂] exact (countable_bInter_mem htc).mpr (fun i hi ↦ hUl _ (hts _ hi))
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.Topology.Algebra.Module.WeakDual import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction import Mathlib.MeasureTheory.Measure.HasOuterApproxClosed #align_import measure_theory.measure.finite_measure from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Finite measures This file defines the type of finite measures on a given measurable space. When the underlying space has a topology and the measurable space structure (sigma algebra) is finer than the Borel sigma algebra, then the type of finite measures is equipped with the topology of weak convergence of measures. The topology of weak convergence is the coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued function `f`, the integration of `f` against the measure is continuous. ## Main definitions The main definitions are * `MeasureTheory.FiniteMeasure Ω`: The type of finite measures on `Ω` with the topology of weak convergence of measures. * `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))`: Interpret a finite measure as a continuous linear functional on the space of bounded continuous nonnegative functions on `Ω`. This is used for the definition of the topology of weak convergence. * `MeasureTheory.FiniteMeasure.map`: The push-forward `f* μ` of a finite measure `μ` on `Ω` along a measurable function `f : Ω → Ω'`. * `MeasureTheory.FiniteMeasure.mapCLM`: The push-forward along a given continuous `f : Ω → Ω'` as a continuous linear map `f* : FiniteMeasure Ω →L[ℝ≥0] FiniteMeasure Ω'`. ## Main results * Finite measures `μ` on `Ω` give rise to continuous linear functionals on the space of bounded continuous nonnegative functions on `Ω` via integration: `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))` * `MeasureTheory.FiniteMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of finite measures is characterized by the convergence of integrals of all bounded continuous functions. This shows that the chosen definition of topology coincides with the common textbook definition of weak convergence of measures. A similar characterization by the convergence of integrals (in the `MeasureTheory.lintegral` sense) of all bounded continuous nonnegative functions is `MeasureTheory.FiniteMeasure.tendsto_iff_forall_lintegral_tendsto`. * `MeasureTheory.FiniteMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the push-forward of finite measures `f* : FiniteMeasure Ω → FiniteMeasure Ω'` is continuous. * `MeasureTheory.FiniteMeasure.t2Space`: The topology of weak convergence of finite Borel measures is Hausdorff on spaces where indicators of closed sets have continuous decreasing approximating sequences (in particular on any pseudo-metrizable spaces). ## Implementation notes The topology of weak convergence of finite Borel measures is defined using a mapping from `MeasureTheory.FiniteMeasure Ω` to `WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)`, inheriting the topology from the latter. The implementation of `MeasureTheory.FiniteMeasure Ω` and is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`. Another alternative would have been to use a bijection with `MeasureTheory.VectorMeasure Ω ℝ≥0` as an intermediate step. Some considerations: * Potential advantages of using the `NNReal`-valued vector measure alternative: * The coercion to function would avoid need to compose with `ENNReal.toNNReal`, the `NNReal`-valued API could be more directly available. * Potential drawbacks of the vector measure alternative: * The coercion to function would lose monotonicity, as non-measurable sets would be defined to have measure 0. * No integration theory directly. E.g., the topology definition requires `MeasureTheory.lintegral` w.r.t. a coercion to `MeasureTheory.Measure Ω` in any case. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags weak convergence of measures, finite measure -/ noncomputable section open MeasureTheory open Set open Filter open BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory namespace FiniteMeasure section FiniteMeasure /-! ### Finite measures In this section we define the `Type` of `MeasureTheory.FiniteMeasure Ω`, when `Ω` is a measurable space. Finite measures on `Ω` are a module over `ℝ≥0`. If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.FiniteMeasure Ω` is equipped with the topology of weak convergence of measures. This is implemented by defining a pairing of finite measures `μ` on `Ω` with continuous bounded nonnegative functions `f : Ω →ᵇ ℝ≥0` via integration, and using the associated weak topology (essentially the weak-star topology on the dual of `Ω →ᵇ ℝ≥0`). -/ variable {Ω : Type*} [MeasurableSpace Ω] /-- Finite measures are defined as the subtype of measures that have the property of being finite measures (i.e., their total mass is finite). -/ def _root_.MeasureTheory.FiniteMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ := { μ : Measure Ω // IsFiniteMeasure μ } #align measure_theory.finite_measure MeasureTheory.FiniteMeasure -- Porting note: as with other subtype synonyms (e.g., `ℝ≥0`, we need a new function for the -- coercion instead of relying on `Subtype.val`. /-- Coercion from `MeasureTheory.FiniteMeasure Ω` to `MeasureTheory.Measure Ω`. -/ @[coe] def toMeasure : FiniteMeasure Ω → Measure Ω := Subtype.val /-- A finite measure can be interpreted as a measure. -/ instance instCoe : Coe (FiniteMeasure Ω) (MeasureTheory.Measure Ω) where coe := toMeasure instance isFiniteMeasure (μ : FiniteMeasure Ω) : IsFiniteMeasure (μ : Measure Ω) := μ.prop #align measure_theory.finite_measure.is_finite_measure MeasureTheory.FiniteMeasure.isFiniteMeasure @[simp] theorem val_eq_toMeasure (ν : FiniteMeasure Ω) : ν.val = (ν : Measure Ω) := rfl #align measure_theory.finite_measure.val_eq_to_measure MeasureTheory.FiniteMeasure.val_eq_toMeasure theorem toMeasure_injective : Function.Injective ((↑) : FiniteMeasure Ω → Measure Ω) := Subtype.coe_injective #align measure_theory.finite_measure.coe_injective MeasureTheory.FiniteMeasure.toMeasure_injective instance instFunLike : FunLike (FiniteMeasure Ω) (Set Ω) ℝ≥0 where coe μ s := ((μ : Measure Ω) s).toNNReal coe_injective' μ ν h := toMeasure_injective $ Measure.ext fun s _ ↦ by simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s lemma coeFn_def (μ : FiniteMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl #align measure_theory.finite_measure.coe_fn_eq_to_nnreal_coe_fn_to_measure MeasureTheory.FiniteMeasure.coeFn_def lemma coeFn_mk (μ : Measure Ω) (hμ) : DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl @[simp, norm_cast] lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) : DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl @[simp] theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : FiniteMeasure Ω) (s : Set Ω) : (ν s : ℝ≥0∞) = (ν : Measure Ω) s := ENNReal.coe_toNNReal (measure_lt_top (↑ν) s).ne #align measure_theory.finite_measure.ennreal_coe_fn_eq_coe_fn_to_measure MeasureTheory.FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure theorem apply_mono (μ : FiniteMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by change ((μ : Measure Ω) s₁).toNNReal ≤ ((μ : Measure Ω) s₂).toNNReal have key : (μ : Measure Ω) s₁ ≤ (μ : Measure Ω) s₂ := (μ : Measure Ω).mono h apply (ENNReal.toNNReal_le_toNNReal (measure_ne_top _ s₁) (measure_ne_top _ s₂)).mpr key #align measure_theory.finite_measure.apply_mono MeasureTheory.FiniteMeasure.apply_mono /-- The (total) mass of a finite measure `μ` is `μ univ`, i.e., the cast to `NNReal` of `(μ : measure Ω) univ`. -/ def mass (μ : FiniteMeasure Ω) : ℝ≥0 := μ univ #align measure_theory.finite_measure.mass MeasureTheory.FiniteMeasure.mass @[simp] theorem apply_le_mass (μ : FiniteMeasure Ω) (s : Set Ω) : μ s ≤ μ.mass := by simpa using apply_mono μ (subset_univ s) @[simp] theorem ennreal_mass {μ : FiniteMeasure Ω} : (μ.mass : ℝ≥0∞) = (μ : Measure Ω) univ := ennreal_coeFn_eq_coeFn_toMeasure μ Set.univ #align measure_theory.finite_measure.ennreal_mass MeasureTheory.FiniteMeasure.ennreal_mass instance instZero : Zero (FiniteMeasure Ω) where zero := ⟨0, MeasureTheory.isFiniteMeasureZero⟩ #align measure_theory.finite_measure.has_zero MeasureTheory.FiniteMeasure.instZero @[simp, norm_cast] lemma coeFn_zero : ⇑(0 : FiniteMeasure Ω) = 0 := rfl #align measure_theory.finite_measure.coe_fn_zero MeasureTheory.FiniteMeasure.coeFn_zero @[simp] theorem zero_mass : (0 : FiniteMeasure Ω).mass = 0 := rfl #align measure_theory.finite_measure.zero.mass MeasureTheory.FiniteMeasure.zero_mass @[simp] theorem mass_zero_iff (μ : FiniteMeasure Ω) : μ.mass = 0 ↔ μ = 0 := by refine ⟨fun μ_mass => ?_, fun hμ => by simp only [hμ, zero_mass]⟩ apply toMeasure_injective apply Measure.measure_univ_eq_zero.mp rwa [← ennreal_mass, ENNReal.coe_eq_zero] #align measure_theory.finite_measure.mass_zero_iff MeasureTheory.FiniteMeasure.mass_zero_iff theorem mass_nonzero_iff (μ : FiniteMeasure Ω) : μ.mass ≠ 0 ↔ μ ≠ 0 := by rw [not_iff_not] exact FiniteMeasure.mass_zero_iff μ #align measure_theory.finite_measure.mass_nonzero_iff MeasureTheory.FiniteMeasure.mass_nonzero_iff @[ext] theorem eq_of_forall_toMeasure_apply_eq (μ ν : FiniteMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by apply Subtype.ext ext1 s s_mble exact h s s_mble #align measure_theory.finite_measure.eq_of_forall_measure_apply_eq MeasureTheory.FiniteMeasure.eq_of_forall_toMeasure_apply_eq theorem eq_of_forall_apply_eq (μ ν : FiniteMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by ext1 s s_mble simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble) #align measure_theory.finite_measure.eq_of_forall_apply_eq MeasureTheory.FiniteMeasure.eq_of_forall_apply_eq instance instInhabited : Inhabited (FiniteMeasure Ω) := ⟨0⟩ instance instAdd : Add (FiniteMeasure Ω) where add μ ν := ⟨μ + ν, MeasureTheory.isFiniteMeasureAdd⟩ variable {R : Type*} [SMul R ℝ≥0] [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0 ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] instance instSMul : SMul R (FiniteMeasure Ω) where smul (c : R) μ := ⟨c • (μ : Measure Ω), MeasureTheory.isFiniteMeasureSMulOfNNRealTower⟩ @[simp, norm_cast] theorem toMeasure_zero : ((↑) : FiniteMeasure Ω → Measure Ω) 0 = 0 := rfl #align measure_theory.finite_measure.coe_zero MeasureTheory.FiniteMeasure.toMeasure_zero -- Porting note: with `simp` here the `coeFn` lemmas below fall prey to `simpNF`: the LHS simplifies @[norm_cast] theorem toMeasure_add (μ ν : FiniteMeasure Ω) : ↑(μ + ν) = (↑μ + ↑ν : Measure Ω) := rfl #align measure_theory.finite_measure.coe_add MeasureTheory.FiniteMeasure.toMeasure_add @[simp, norm_cast] theorem toMeasure_smul (c : R) (μ : FiniteMeasure Ω) : ↑(c • μ) = c • (μ : Measure Ω) := rfl #align measure_theory.finite_measure.coe_smul MeasureTheory.FiniteMeasure.toMeasure_smul @[simp, norm_cast] theorem coeFn_add (μ ν : FiniteMeasure Ω) : (⇑(μ + ν) : Set Ω → ℝ≥0) = (⇑μ + ⇑ν : Set Ω → ℝ≥0) := by funext simp only [Pi.add_apply, ← ENNReal.coe_inj, ne_eq, ennreal_coeFn_eq_coeFn_toMeasure, ENNReal.coe_add] norm_cast #align measure_theory.finite_measure.coe_fn_add MeasureTheory.FiniteMeasure.coeFn_add @[simp, norm_cast] theorem coeFn_smul [IsScalarTower R ℝ≥0 ℝ≥0] (c : R) (μ : FiniteMeasure Ω) : (⇑(c • μ) : Set Ω → ℝ≥0) = c • (⇑μ : Set Ω → ℝ≥0) := by funext; simp [← ENNReal.coe_inj, ENNReal.coe_smul] #align measure_theory.finite_measure.coe_fn_smul MeasureTheory.FiniteMeasure.coeFn_smul instance instAddCommMonoid : AddCommMonoid (FiniteMeasure Ω) := toMeasure_injective.addCommMonoid (↑) toMeasure_zero toMeasure_add fun _ _ => toMeasure_smul _ _ /-- Coercion is an `AddMonoidHom`. -/ @[simps] def toMeasureAddMonoidHom : FiniteMeasure Ω →+ Measure Ω where toFun := (↑) map_zero' := toMeasure_zero map_add' := toMeasure_add #align measure_theory.finite_measure.coe_add_monoid_hom MeasureTheory.FiniteMeasure.toMeasureAddMonoidHom instance {Ω : Type*} [MeasurableSpace Ω] : Module ℝ≥0 (FiniteMeasure Ω) := Function.Injective.module _ toMeasureAddMonoidHom toMeasure_injective toMeasure_smul @[simp] theorem smul_apply [IsScalarTower R ℝ≥0 ℝ≥0] (c : R) (μ : FiniteMeasure Ω) (s : Set Ω) : (c • μ) s = c • μ s := by rw [coeFn_smul, Pi.smul_apply] #align measure_theory.finite_measure.coe_fn_smul_apply MeasureTheory.FiniteMeasure.smul_apply /-- Restrict a finite measure μ to a set A. -/ def restrict (μ : FiniteMeasure Ω) (A : Set Ω) : FiniteMeasure Ω where val := (μ : Measure Ω).restrict A property := MeasureTheory.isFiniteMeasureRestrict (μ : Measure Ω) A #align measure_theory.finite_measure.restrict MeasureTheory.FiniteMeasure.restrict theorem restrict_measure_eq (μ : FiniteMeasure Ω) (A : Set Ω) : (μ.restrict A : Measure Ω) = (μ : Measure Ω).restrict A := rfl #align measure_theory.finite_measure.restrict_measure_eq MeasureTheory.FiniteMeasure.restrict_measure_eq theorem restrict_apply_measure (μ : FiniteMeasure Ω) (A : Set Ω) {s : Set Ω} (s_mble : MeasurableSet s) : (μ.restrict A : Measure Ω) s = (μ : Measure Ω) (s ∩ A) := Measure.restrict_apply s_mble #align measure_theory.finite_measure.restrict_apply_measure MeasureTheory.FiniteMeasure.restrict_apply_measure theorem restrict_apply (μ : FiniteMeasure Ω) (A : Set Ω) {s : Set Ω} (s_mble : MeasurableSet s) : (μ.restrict A) s = μ (s ∩ A) := by apply congr_arg ENNReal.toNNReal exact Measure.restrict_apply s_mble #align measure_theory.finite_measure.restrict_apply MeasureTheory.FiniteMeasure.restrict_apply theorem restrict_mass (μ : FiniteMeasure Ω) (A : Set Ω) : (μ.restrict A).mass = μ A := by simp only [mass, restrict_apply μ A MeasurableSet.univ, univ_inter] #align measure_theory.finite_measure.restrict_mass MeasureTheory.FiniteMeasure.restrict_mass theorem restrict_eq_zero_iff (μ : FiniteMeasure Ω) (A : Set Ω) : μ.restrict A = 0 ↔ μ A = 0 := by rw [← mass_zero_iff, restrict_mass] #align measure_theory.finite_measure.restrict_eq_zero_iff MeasureTheory.FiniteMeasure.restrict_eq_zero_iff theorem restrict_nonzero_iff (μ : FiniteMeasure Ω) (A : Set Ω) : μ.restrict A ≠ 0 ↔ μ A ≠ 0 := by rw [← mass_nonzero_iff, restrict_mass] #align measure_theory.finite_measure.restrict_nonzero_iff MeasureTheory.FiniteMeasure.restrict_nonzero_iff variable [TopologicalSpace Ω] /-- Two finite Borel measures are equal if the integrals of all bounded continuous functions with respect to both agree. -/ theorem ext_of_forall_lintegral_eq [HasOuterApproxClosed Ω] [BorelSpace Ω] {μ ν : FiniteMeasure Ω} (h : ∀ (f : Ω →ᵇ ℝ≥0), ∫⁻ x, f x ∂μ = ∫⁻ x, f x ∂ν) : μ = ν := by apply Subtype.ext change (μ : Measure Ω) = (ν : Measure Ω) exact ext_of_forall_lintegral_eq_of_IsFiniteMeasure h /-- The pairing of a finite (Borel) measure `μ` with a nonnegative bounded continuous function is obtained by (Lebesgue) integrating the (test) function against the measure. This is `MeasureTheory.FiniteMeasure.testAgainstNN`. -/ def testAgainstNN (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) : ℝ≥0 := (∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal #align measure_theory.finite_measure.test_against_nn MeasureTheory.FiniteMeasure.testAgainstNN @[simp] theorem testAgainstNN_coe_eq {μ : FiniteMeasure Ω} {f : Ω →ᵇ ℝ≥0} : (μ.testAgainstNN f : ℝ≥0∞) = ∫⁻ ω, f ω ∂(μ : Measure Ω) := ENNReal.coe_toNNReal (f.lintegral_lt_top_of_nnreal _).ne #align measure_theory.finite_measure.test_against_nn_coe_eq MeasureTheory.FiniteMeasure.testAgainstNN_coe_eq theorem testAgainstNN_const (μ : FiniteMeasure Ω) (c : ℝ≥0) : μ.testAgainstNN (BoundedContinuousFunction.const Ω c) = c * μ.mass := by simp [← ENNReal.coe_inj] #align measure_theory.finite_measure.test_against_nn_const MeasureTheory.FiniteMeasure.testAgainstNN_const theorem testAgainstNN_mono (μ : FiniteMeasure Ω) {f g : Ω →ᵇ ℝ≥0} (f_le_g : (f : Ω → ℝ≥0) ≤ g) : μ.testAgainstNN f ≤ μ.testAgainstNN g := by simp only [← ENNReal.coe_le_coe, testAgainstNN_coe_eq] gcongr apply f_le_g #align measure_theory.finite_measure.test_against_nn_mono MeasureTheory.FiniteMeasure.testAgainstNN_mono @[simp] theorem testAgainstNN_zero (μ : FiniteMeasure Ω) : μ.testAgainstNN 0 = 0 := by simpa only [zero_mul] using μ.testAgainstNN_const 0 #align measure_theory.finite_measure.test_against_nn_zero MeasureTheory.FiniteMeasure.testAgainstNN_zero @[simp] theorem testAgainstNN_one (μ : FiniteMeasure Ω) : μ.testAgainstNN 1 = μ.mass := by simp only [testAgainstNN, coe_one, Pi.one_apply, ENNReal.coe_one, lintegral_one] rfl #align measure_theory.finite_measure.test_against_nn_one MeasureTheory.FiniteMeasure.testAgainstNN_one @[simp] theorem zero_testAgainstNN_apply (f : Ω →ᵇ ℝ≥0) : (0 : FiniteMeasure Ω).testAgainstNN f = 0 := by simp only [testAgainstNN, toMeasure_zero, lintegral_zero_measure, ENNReal.zero_toNNReal] #align measure_theory.finite_measure.zero.test_against_nn_apply MeasureTheory.FiniteMeasure.zero_testAgainstNN_apply theorem zero_testAgainstNN : (0 : FiniteMeasure Ω).testAgainstNN = 0 := by funext; simp only [zero_testAgainstNN_apply, Pi.zero_apply] #align measure_theory.finite_measure.zero.test_against_nn MeasureTheory.FiniteMeasure.zero_testAgainstNN @[simp] theorem smul_testAgainstNN_apply (c : ℝ≥0) (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) : (c • μ).testAgainstNN f = c • μ.testAgainstNN f := by simp only [testAgainstNN, toMeasure_smul, smul_eq_mul, ← ENNReal.smul_toNNReal, ENNReal.smul_def, lintegral_smul_measure] #align measure_theory.finite_measure.smul_test_against_nn_apply MeasureTheory.FiniteMeasure.smul_testAgainstNN_apply section weak_convergence variable [OpensMeasurableSpace Ω] theorem testAgainstNN_add (μ : FiniteMeasure Ω) (f₁ f₂ : Ω →ᵇ ℝ≥0) : μ.testAgainstNN (f₁ + f₂) = μ.testAgainstNN f₁ + μ.testAgainstNN f₂ := by simp only [← ENNReal.coe_inj, BoundedContinuousFunction.coe_add, ENNReal.coe_add, Pi.add_apply, testAgainstNN_coe_eq] exact lintegral_add_left (BoundedContinuousFunction.measurable_coe_ennreal_comp _) _ #align measure_theory.finite_measure.test_against_nn_add MeasureTheory.FiniteMeasure.testAgainstNN_add
Mathlib/MeasureTheory/Measure/FiniteMeasure.lean
396
404
theorem testAgainstNN_smul [IsScalarTower R ℝ≥0 ℝ≥0] [PseudoMetricSpace R] [Zero R] [BoundedSMul R ℝ≥0] (μ : FiniteMeasure Ω) (c : R) (f : Ω →ᵇ ℝ≥0) : μ.testAgainstNN (c • f) = c • μ.testAgainstNN f := by
simp only [← ENNReal.coe_inj, BoundedContinuousFunction.coe_smul, testAgainstNN_coe_eq, ENNReal.coe_smul] simp_rw [← smul_one_smul ℝ≥0∞ c (f _ : ℝ≥0∞), ← smul_one_smul ℝ≥0∞ c (lintegral _ _ : ℝ≥0∞), smul_eq_mul] exact @lintegral_const_mul _ _ (μ : Measure Ω) (c • (1 : ℝ≥0∞)) _ f.measurable_coe_ennreal_comp
/- 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.Algebra.BigOperators.GroupWithZero.Finset import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.Data.Finset.Preimage import Mathlib.Data.Set.Finite import Mathlib.GroupTheory.GroupAction.BigOperators #align_import data.dfinsupp.basic from "leanprover-community/mathlib"@"6623e6af705e97002a9054c1c05a980180276fc1" /-! # Dependent functions with finite support For a non-dependent version see `data/finsupp.lean`. ## Notation This file introduces the notation `Π₀ a, β a` as notation for `DFinsupp β`, mirroring the `α →₀ β` notation used for `Finsupp`. This works for nested binders too, with `Π₀ a b, γ a b` as notation for `DFinsupp (fun a ↦ DFinsupp (γ a))`. ## Implementation notes The support is internally represented (in the primed `DFinsupp.support'`) as a `Multiset` that represents a superset of the true support of the function, quotiented by the always-true relation so that this does not impact equality. This approach has computational benefits over storing a `Finset`; it allows us to add together two finitely-supported functions without having to evaluate the resulting function to recompute its support (which would required decidability of `b = 0` for `b : β i`). The true support of the function can still be recovered with `DFinsupp.support`; but these decidability obligations are now postponed to when the support is actually needed. As a consequence, there are two ways to sum a `DFinsupp`: with `DFinsupp.sum` which works over an arbitrary function but requires recomputation of the support and therefore a `Decidable` argument; and with `DFinsupp.sumAddHom` which requires an additive morphism, using its properties to show that summing over a superset of the support is sufficient. `Finsupp` takes an altogether different approach here; it uses `Classical.Decidable` and declares the `Add` instance as noncomputable. This design difference is independent of the fact that `DFinsupp` is dependently-typed and `Finsupp` is not; in future, we may want to align these two definitions, or introduce two more definitions for the other combinations of decisions. -/ universe u u₁ u₂ v v₁ v₂ v₃ w x y l variable {ι : Type u} {γ : Type w} {β : ι → Type v} {β₁ : ι → Type v₁} {β₂ : ι → Type v₂} variable (β) /-- A dependent function `Π i, β i` with finite support, with notation `Π₀ i, β i`. Note that `DFinsupp.support` is the preferred API for accessing the support of the function, `DFinsupp.support'` is an implementation detail that aids computability; see the implementation notes in this file for more information. -/ structure DFinsupp [∀ i, Zero (β i)] : Type max u v where mk' :: /-- The underlying function of a dependent function with finite support (aka `DFinsupp`). -/ toFun : ∀ i, β i /-- The support of a dependent function with finite support (aka `DFinsupp`). -/ support' : Trunc { s : Multiset ι // ∀ i, i ∈ s ∨ toFun i = 0 } #align dfinsupp DFinsupp variable {β} /-- `Π₀ i, β i` denotes the type of dependent functions with finite support `DFinsupp β`. -/ notation3 "Π₀ "(...)", "r:(scoped f => DFinsupp f) => r namespace DFinsupp section Basic variable [∀ i, Zero (β i)] [∀ i, Zero (β₁ i)] [∀ i, Zero (β₂ i)] instance instDFunLike : DFunLike (Π₀ i, β i) ι β := ⟨fun f => f.toFun, fun ⟨f₁, s₁⟩ ⟨f₂, s₁⟩ ↦ fun (h : f₁ = f₂) ↦ by subst h congr apply Subsingleton.elim ⟩ #align dfinsupp.fun_like DFinsupp.instDFunLike /-- Helper instance for when there are too many metavariables to apply `DFunLike.coeFunForall` directly. -/ instance : CoeFun (Π₀ i, β i) fun _ => ∀ i, β i := inferInstance @[simp] theorem toFun_eq_coe (f : Π₀ i, β i) : f.toFun = f := rfl #align dfinsupp.to_fun_eq_coe DFinsupp.toFun_eq_coe @[ext] theorem ext {f g : Π₀ i, β i} (h : ∀ i, f i = g i) : f = g := DFunLike.ext _ _ h #align dfinsupp.ext DFinsupp.ext #align dfinsupp.ext_iff DFunLike.ext_iff #align dfinsupp.coe_fn_injective DFunLike.coe_injective lemma ne_iff {f g : Π₀ i, β i} : f ≠ g ↔ ∃ i, f i ≠ g i := DFunLike.ne_iff instance : Zero (Π₀ i, β i) := ⟨⟨0, Trunc.mk <| ⟨∅, fun _ => Or.inr rfl⟩⟩⟩ instance : Inhabited (Π₀ i, β i) := ⟨0⟩ @[simp, norm_cast] lemma coe_mk' (f : ∀ i, β i) (s) : ⇑(⟨f, s⟩ : Π₀ i, β i) = f := rfl #align dfinsupp.coe_mk' DFinsupp.coe_mk' @[simp, norm_cast] lemma coe_zero : ⇑(0 : Π₀ i, β i) = 0 := rfl #align dfinsupp.coe_zero DFinsupp.coe_zero theorem zero_apply (i : ι) : (0 : Π₀ i, β i) i = 0 := rfl #align dfinsupp.zero_apply DFinsupp.zero_apply /-- The composition of `f : β₁ → β₂` and `g : Π₀ i, β₁ i` is `mapRange f hf g : Π₀ i, β₂ i`, well defined when `f 0 = 0`. This preserves the structure on `f`, and exists in various bundled forms for when `f` is itself bundled: * `DFinsupp.mapRange.addMonoidHom` * `DFinsupp.mapRange.addEquiv` * `dfinsupp.mapRange.linearMap` * `dfinsupp.mapRange.linearEquiv` -/ def mapRange (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (x : Π₀ i, β₁ i) : Π₀ i, β₂ i := ⟨fun i => f i (x i), x.support'.map fun s => ⟨s.1, fun i => (s.2 i).imp_right fun h : x i = 0 => by rw [← hf i, ← h]⟩⟩ #align dfinsupp.map_range DFinsupp.mapRange @[simp] theorem mapRange_apply (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (g : Π₀ i, β₁ i) (i : ι) : mapRange f hf g i = f i (g i) := rfl #align dfinsupp.map_range_apply DFinsupp.mapRange_apply @[simp] theorem mapRange_id (h : ∀ i, id (0 : β₁ i) = 0 := fun i => rfl) (g : Π₀ i : ι, β₁ i) : mapRange (fun i => (id : β₁ i → β₁ i)) h g = g := by ext rfl #align dfinsupp.map_range_id DFinsupp.mapRange_id theorem mapRange_comp (f : ∀ i, β₁ i → β₂ i) (f₂ : ∀ i, β i → β₁ i) (hf : ∀ i, f i 0 = 0) (hf₂ : ∀ i, f₂ i 0 = 0) (h : ∀ i, (f i ∘ f₂ i) 0 = 0) (g : Π₀ i : ι, β i) : mapRange (fun i => f i ∘ f₂ i) h g = mapRange f hf (mapRange f₂ hf₂ g) := by ext simp only [mapRange_apply]; rfl #align dfinsupp.map_range_comp DFinsupp.mapRange_comp @[simp] theorem mapRange_zero (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) : mapRange f hf (0 : Π₀ i, β₁ i) = 0 := by ext simp only [mapRange_apply, coe_zero, Pi.zero_apply, hf] #align dfinsupp.map_range_zero DFinsupp.mapRange_zero /-- Let `f i` be a binary operation `β₁ i → β₂ i → β i` such that `f i 0 0 = 0`. Then `zipWith f hf` is a binary operation `Π₀ i, β₁ i → Π₀ i, β₂ i → Π₀ i, β i`. -/ def zipWith (f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) (x : Π₀ i, β₁ i) (y : Π₀ i, β₂ i) : Π₀ i, β i := ⟨fun i => f i (x i) (y i), by refine x.support'.bind fun xs => ?_ refine y.support'.map fun ys => ?_ refine ⟨xs + ys, fun i => ?_⟩ obtain h1 | (h1 : x i = 0) := xs.prop i · left rw [Multiset.mem_add] left exact h1 obtain h2 | (h2 : y i = 0) := ys.prop i · left rw [Multiset.mem_add] right exact h2 right; rw [← hf, ← h1, ← h2]⟩ #align dfinsupp.zip_with DFinsupp.zipWith @[simp] theorem zipWith_apply (f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) (g₁ : Π₀ i, β₁ i) (g₂ : Π₀ i, β₂ i) (i : ι) : zipWith f hf g₁ g₂ i = f i (g₁ i) (g₂ i) := rfl #align dfinsupp.zip_with_apply DFinsupp.zipWith_apply section Piecewise variable (x y : Π₀ i, β i) (s : Set ι) [∀ i, Decidable (i ∈ s)] /-- `x.piecewise y s` is the finitely supported function equal to `x` on the set `s`, and to `y` on its complement. -/ def piecewise : Π₀ i, β i := zipWith (fun i x y => if i ∈ s then x else y) (fun _ => ite_self 0) x y #align dfinsupp.piecewise DFinsupp.piecewise theorem piecewise_apply (i : ι) : x.piecewise y s i = if i ∈ s then x i else y i := zipWith_apply _ _ x y i #align dfinsupp.piecewise_apply DFinsupp.piecewise_apply @[simp, norm_cast] theorem coe_piecewise : ⇑(x.piecewise y s) = s.piecewise x y := by ext apply piecewise_apply #align dfinsupp.coe_piecewise DFinsupp.coe_piecewise end Piecewise end Basic section Algebra instance [∀ i, AddZeroClass (β i)] : Add (Π₀ i, β i) := ⟨zipWith (fun _ => (· + ·)) fun _ => add_zero 0⟩ theorem add_apply [∀ i, AddZeroClass (β i)] (g₁ g₂ : Π₀ i, β i) (i : ι) : (g₁ + g₂) i = g₁ i + g₂ i := rfl #align dfinsupp.add_apply DFinsupp.add_apply @[simp, norm_cast] theorem coe_add [∀ i, AddZeroClass (β i)] (g₁ g₂ : Π₀ i, β i) : ⇑(g₁ + g₂) = g₁ + g₂ := rfl #align dfinsupp.coe_add DFinsupp.coe_add instance addZeroClass [∀ i, AddZeroClass (β i)] : AddZeroClass (Π₀ i, β i) := DFunLike.coe_injective.addZeroClass _ coe_zero coe_add instance instIsLeftCancelAdd [∀ i, AddZeroClass (β i)] [∀ i, IsLeftCancelAdd (β i)] : IsLeftCancelAdd (Π₀ i, β i) where add_left_cancel _ _ _ h := ext fun x => add_left_cancel <| DFunLike.congr_fun h x instance instIsRightCancelAdd [∀ i, AddZeroClass (β i)] [∀ i, IsRightCancelAdd (β i)] : IsRightCancelAdd (Π₀ i, β i) where add_right_cancel _ _ _ h := ext fun x => add_right_cancel <| DFunLike.congr_fun h x instance instIsCancelAdd [∀ i, AddZeroClass (β i)] [∀ i, IsCancelAdd (β i)] : IsCancelAdd (Π₀ i, β i) where /-- Note the general `SMul` instance doesn't apply as `ℕ` is not distributive unless `β i`'s addition is commutative. -/ instance hasNatScalar [∀ i, AddMonoid (β i)] : SMul ℕ (Π₀ i, β i) := ⟨fun c v => v.mapRange (fun _ => (c • ·)) fun _ => nsmul_zero _⟩ #align dfinsupp.has_nat_scalar DFinsupp.hasNatScalar theorem nsmul_apply [∀ i, AddMonoid (β i)] (b : ℕ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i := rfl #align dfinsupp.nsmul_apply DFinsupp.nsmul_apply @[simp, norm_cast] theorem coe_nsmul [∀ i, AddMonoid (β i)] (b : ℕ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v := rfl #align dfinsupp.coe_nsmul DFinsupp.coe_nsmul instance [∀ i, AddMonoid (β i)] : AddMonoid (Π₀ i, β i) := DFunLike.coe_injective.addMonoid _ coe_zero coe_add fun _ _ => coe_nsmul _ _ /-- Coercion from a `DFinsupp` to a pi type is an `AddMonoidHom`. -/ def coeFnAddMonoidHom [∀ i, AddZeroClass (β i)] : (Π₀ i, β i) →+ ∀ i, β i where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add #align dfinsupp.coe_fn_add_monoid_hom DFinsupp.coeFnAddMonoidHom /-- Evaluation at a point is an `AddMonoidHom`. This is the finitely-supported version of `Pi.evalAddMonoidHom`. -/ def evalAddMonoidHom [∀ i, AddZeroClass (β i)] (i : ι) : (Π₀ i, β i) →+ β i := (Pi.evalAddMonoidHom β i).comp coeFnAddMonoidHom #align dfinsupp.eval_add_monoid_hom DFinsupp.evalAddMonoidHom instance addCommMonoid [∀ i, AddCommMonoid (β i)] : AddCommMonoid (Π₀ i, β i) := DFunLike.coe_injective.addCommMonoid _ coe_zero coe_add fun _ _ => coe_nsmul _ _ @[simp, norm_cast] theorem coe_finset_sum {α} [∀ i, AddCommMonoid (β i)] (s : Finset α) (g : α → Π₀ i, β i) : ⇑(∑ a ∈ s, g a) = ∑ a ∈ s, ⇑(g a) := map_sum coeFnAddMonoidHom g s #align dfinsupp.coe_finset_sum DFinsupp.coe_finset_sum @[simp] theorem finset_sum_apply {α} [∀ i, AddCommMonoid (β i)] (s : Finset α) (g : α → Π₀ i, β i) (i : ι) : (∑ a ∈ s, g a) i = ∑ a ∈ s, g a i := map_sum (evalAddMonoidHom i) g s #align dfinsupp.finset_sum_apply DFinsupp.finset_sum_apply instance [∀ i, AddGroup (β i)] : Neg (Π₀ i, β i) := ⟨fun f => f.mapRange (fun _ => Neg.neg) fun _ => neg_zero⟩ theorem neg_apply [∀ i, AddGroup (β i)] (g : Π₀ i, β i) (i : ι) : (-g) i = -g i := rfl #align dfinsupp.neg_apply DFinsupp.neg_apply @[simp, norm_cast] lemma coe_neg [∀ i, AddGroup (β i)] (g : Π₀ i, β i) : ⇑(-g) = -g := rfl #align dfinsupp.coe_neg DFinsupp.coe_neg instance [∀ i, AddGroup (β i)] : Sub (Π₀ i, β i) := ⟨zipWith (fun _ => Sub.sub) fun _ => sub_zero 0⟩ theorem sub_apply [∀ i, AddGroup (β i)] (g₁ g₂ : Π₀ i, β i) (i : ι) : (g₁ - g₂) i = g₁ i - g₂ i := rfl #align dfinsupp.sub_apply DFinsupp.sub_apply @[simp, norm_cast] theorem coe_sub [∀ i, AddGroup (β i)] (g₁ g₂ : Π₀ i, β i) : ⇑(g₁ - g₂) = g₁ - g₂ := rfl #align dfinsupp.coe_sub DFinsupp.coe_sub /-- Note the general `SMul` instance doesn't apply as `ℤ` is not distributive unless `β i`'s addition is commutative. -/ instance hasIntScalar [∀ i, AddGroup (β i)] : SMul ℤ (Π₀ i, β i) := ⟨fun c v => v.mapRange (fun _ => (c • ·)) fun _ => zsmul_zero _⟩ #align dfinsupp.has_int_scalar DFinsupp.hasIntScalar theorem zsmul_apply [∀ i, AddGroup (β i)] (b : ℤ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i := rfl #align dfinsupp.zsmul_apply DFinsupp.zsmul_apply @[simp, norm_cast] theorem coe_zsmul [∀ i, AddGroup (β i)] (b : ℤ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v := rfl #align dfinsupp.coe_zsmul DFinsupp.coe_zsmul instance [∀ i, AddGroup (β i)] : AddGroup (Π₀ i, β i) := DFunLike.coe_injective.addGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_nsmul _ _) fun _ _ => coe_zsmul _ _ instance addCommGroup [∀ i, AddCommGroup (β i)] : AddCommGroup (Π₀ i, β i) := DFunLike.coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_nsmul _ _) fun _ _ => coe_zsmul _ _ /-- Dependent functions with finite support inherit a semiring action from an action on each coordinate. -/ instance [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] : SMul γ (Π₀ i, β i) := ⟨fun c v => v.mapRange (fun _ => (c • ·)) fun _ => smul_zero _⟩ theorem smul_apply [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] (b : γ) (v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i := rfl #align dfinsupp.smul_apply DFinsupp.smul_apply @[simp, norm_cast] theorem coe_smul [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] (b : γ) (v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v := rfl #align dfinsupp.coe_smul DFinsupp.coe_smul instance smulCommClass {δ : Type*} [Monoid γ] [Monoid δ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] [∀ i, DistribMulAction δ (β i)] [∀ i, SMulCommClass γ δ (β i)] : SMulCommClass γ δ (Π₀ i, β i) where smul_comm r s m := ext fun i => by simp only [smul_apply, smul_comm r s (m i)] instance isScalarTower {δ : Type*} [Monoid γ] [Monoid δ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] [∀ i, DistribMulAction δ (β i)] [SMul γ δ] [∀ i, IsScalarTower γ δ (β i)] : IsScalarTower γ δ (Π₀ i, β i) where smul_assoc r s m := ext fun i => by simp only [smul_apply, smul_assoc r s (m i)] instance isCentralScalar [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] [∀ i, DistribMulAction γᵐᵒᵖ (β i)] [∀ i, IsCentralScalar γ (β i)] : IsCentralScalar γ (Π₀ i, β i) where op_smul_eq_smul r m := ext fun i => by simp only [smul_apply, op_smul_eq_smul r (m i)] /-- Dependent functions with finite support inherit a `DistribMulAction` structure from such a structure on each coordinate. -/ instance distribMulAction [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] : DistribMulAction γ (Π₀ i, β i) := Function.Injective.distribMulAction coeFnAddMonoidHom DFunLike.coe_injective coe_smul /-- Dependent functions with finite support inherit a module structure from such a structure on each coordinate. -/ instance module [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] : Module γ (Π₀ i, β i) := { inferInstanceAs (DistribMulAction γ (Π₀ i, β i)) with zero_smul := fun c => ext fun i => by simp only [smul_apply, zero_smul, zero_apply] add_smul := fun c x y => ext fun i => by simp only [add_apply, smul_apply, add_smul] } #align dfinsupp.module DFinsupp.module end Algebra section FilterAndSubtypeDomain /-- `Filter p f` is the function which is `f i` if `p i` is true and 0 otherwise. -/ def filter [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (x : Π₀ i, β i) : Π₀ i, β i := ⟨fun i => if p i then x i else 0, x.support'.map fun xs => ⟨xs.1, fun i => (xs.prop i).imp_right fun H : x i = 0 => by simp only [H, ite_self]⟩⟩ #align dfinsupp.filter DFinsupp.filter @[simp] theorem filter_apply [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (i : ι) (f : Π₀ i, β i) : f.filter p i = if p i then f i else 0 := rfl #align dfinsupp.filter_apply DFinsupp.filter_apply theorem filter_apply_pos [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] (f : Π₀ i, β i) {i : ι} (h : p i) : f.filter p i = f i := by simp only [filter_apply, if_pos h] #align dfinsupp.filter_apply_pos DFinsupp.filter_apply_pos theorem filter_apply_neg [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] (f : Π₀ i, β i) {i : ι} (h : ¬p i) : f.filter p i = 0 := by simp only [filter_apply, if_neg h] #align dfinsupp.filter_apply_neg DFinsupp.filter_apply_neg theorem filter_pos_add_filter_neg [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (p : ι → Prop) [DecidablePred p] : (f.filter p + f.filter fun i => ¬p i) = f := ext fun i => by simp only [add_apply, filter_apply]; split_ifs <;> simp only [add_zero, zero_add] #align dfinsupp.filter_pos_add_filter_neg DFinsupp.filter_pos_add_filter_neg @[simp] theorem filter_zero [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] : (0 : Π₀ i, β i).filter p = 0 := by ext simp #align dfinsupp.filter_zero DFinsupp.filter_zero @[simp] theorem filter_add [∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] (f g : Π₀ i, β i) : (f + g).filter p = f.filter p + g.filter p := by ext simp [ite_add_zero] #align dfinsupp.filter_add DFinsupp.filter_add @[simp] theorem filter_smul [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] (p : ι → Prop) [DecidablePred p] (r : γ) (f : Π₀ i, β i) : (r • f).filter p = r • f.filter p := by ext simp [smul_apply, smul_ite] #align dfinsupp.filter_smul DFinsupp.filter_smul variable (γ β) /-- `DFinsupp.filter` as an `AddMonoidHom`. -/ @[simps] def filterAddMonoidHom [∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i, β i) →+ Π₀ i, β i where toFun := filter p map_zero' := filter_zero p map_add' := filter_add p #align dfinsupp.filter_add_monoid_hom DFinsupp.filterAddMonoidHom #align dfinsupp.filter_add_monoid_hom_apply DFinsupp.filterAddMonoidHom_apply /-- `DFinsupp.filter` as a `LinearMap`. -/ @[simps] def filterLinearMap [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i, β i) →ₗ[γ] Π₀ i, β i where toFun := filter p map_add' := filter_add p map_smul' := filter_smul p #align dfinsupp.filter_linear_map DFinsupp.filterLinearMap #align dfinsupp.filter_linear_map_apply DFinsupp.filterLinearMap_apply variable {γ β} @[simp] theorem filter_neg [∀ i, AddGroup (β i)] (p : ι → Prop) [DecidablePred p] (f : Π₀ i, β i) : (-f).filter p = -f.filter p := (filterAddMonoidHom β p).map_neg f #align dfinsupp.filter_neg DFinsupp.filter_neg @[simp] theorem filter_sub [∀ i, AddGroup (β i)] (p : ι → Prop) [DecidablePred p] (f g : Π₀ i, β i) : (f - g).filter p = f.filter p - g.filter p := (filterAddMonoidHom β p).map_sub f g #align dfinsupp.filter_sub DFinsupp.filter_sub /-- `subtypeDomain p f` is the restriction of the finitely supported function `f` to the subtype `p`. -/ def subtypeDomain [∀ i, Zero (β i)] (p : ι → Prop) [DecidablePred p] (x : Π₀ i, β i) : Π₀ i : Subtype p, β i := ⟨fun i => x (i : ι), x.support'.map fun xs => ⟨(Multiset.filter p xs.1).attach.map fun j => ⟨j.1, (Multiset.mem_filter.1 j.2).2⟩, fun i => (xs.prop i).imp_left fun H => Multiset.mem_map.2 ⟨⟨i, Multiset.mem_filter.2 ⟨H, i.2⟩⟩, Multiset.mem_attach _ _, Subtype.eta _ _⟩⟩⟩ #align dfinsupp.subtype_domain DFinsupp.subtypeDomain @[simp] theorem subtypeDomain_zero [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] : subtypeDomain p (0 : Π₀ i, β i) = 0 := rfl #align dfinsupp.subtype_domain_zero DFinsupp.subtypeDomain_zero @[simp] theorem subtypeDomain_apply [∀ i, Zero (β i)] {p : ι → Prop} [DecidablePred p] {i : Subtype p} {v : Π₀ i, β i} : (subtypeDomain p v) i = v i := rfl #align dfinsupp.subtype_domain_apply DFinsupp.subtypeDomain_apply @[simp] theorem subtypeDomain_add [∀ i, AddZeroClass (β i)] {p : ι → Prop} [DecidablePred p] (v v' : Π₀ i, β i) : (v + v').subtypeDomain p = v.subtypeDomain p + v'.subtypeDomain p := DFunLike.coe_injective rfl #align dfinsupp.subtype_domain_add DFinsupp.subtypeDomain_add @[simp] theorem subtypeDomain_smul [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] {p : ι → Prop} [DecidablePred p] (r : γ) (f : Π₀ i, β i) : (r • f).subtypeDomain p = r • f.subtypeDomain p := DFunLike.coe_injective rfl #align dfinsupp.subtype_domain_smul DFinsupp.subtypeDomain_smul variable (γ β) /-- `subtypeDomain` but as an `AddMonoidHom`. -/ @[simps] def subtypeDomainAddMonoidHom [∀ i, AddZeroClass (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i : ι, β i) →+ Π₀ i : Subtype p, β i where toFun := subtypeDomain p map_zero' := subtypeDomain_zero map_add' := subtypeDomain_add #align dfinsupp.subtype_domain_add_monoid_hom DFinsupp.subtypeDomainAddMonoidHom #align dfinsupp.subtype_domain_add_monoid_hom_apply DFinsupp.subtypeDomainAddMonoidHom_apply /-- `DFinsupp.subtypeDomain` as a `LinearMap`. -/ @[simps] def subtypeDomainLinearMap [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] (p : ι → Prop) [DecidablePred p] : (Π₀ i, β i) →ₗ[γ] Π₀ i : Subtype p, β i where toFun := subtypeDomain p map_add' := subtypeDomain_add map_smul' := subtypeDomain_smul #align dfinsupp.subtype_domain_linear_map DFinsupp.subtypeDomainLinearMap #align dfinsupp.subtype_domain_linear_map_apply DFinsupp.subtypeDomainLinearMap_apply variable {γ β} @[simp] theorem subtypeDomain_neg [∀ i, AddGroup (β i)] {p : ι → Prop} [DecidablePred p] {v : Π₀ i, β i} : (-v).subtypeDomain p = -v.subtypeDomain p := DFunLike.coe_injective rfl #align dfinsupp.subtype_domain_neg DFinsupp.subtypeDomain_neg @[simp] theorem subtypeDomain_sub [∀ i, AddGroup (β i)] {p : ι → Prop} [DecidablePred p] {v v' : Π₀ i, β i} : (v - v').subtypeDomain p = v.subtypeDomain p - v'.subtypeDomain p := DFunLike.coe_injective rfl #align dfinsupp.subtype_domain_sub DFinsupp.subtypeDomain_sub end FilterAndSubtypeDomain variable [DecidableEq ι] section Basic variable [∀ i, Zero (β i)] theorem finite_support (f : Π₀ i, β i) : Set.Finite { i | f i ≠ 0 } := Trunc.induction_on f.support' fun xs ↦ xs.1.finite_toSet.subset fun i H ↦ ((xs.prop i).resolve_right H) #align dfinsupp.finite_support DFinsupp.finite_support /-- Create an element of `Π₀ i, β i` from a finset `s` and a function `x` defined on this `Finset`. -/ def mk (s : Finset ι) (x : ∀ i : (↑s : Set ι), β (i : ι)) : Π₀ i, β i := ⟨fun i => if H : i ∈ s then x ⟨i, H⟩ else 0, Trunc.mk ⟨s.1, fun i => if H : i ∈ s then Or.inl H else Or.inr <| dif_neg H⟩⟩ #align dfinsupp.mk DFinsupp.mk variable {s : Finset ι} {x : ∀ i : (↑s : Set ι), β i} {i : ι} @[simp] theorem mk_apply : (mk s x : ∀ i, β i) i = if H : i ∈ s then x ⟨i, H⟩ else 0 := rfl #align dfinsupp.mk_apply DFinsupp.mk_apply theorem mk_of_mem (hi : i ∈ s) : (mk s x : ∀ i, β i) i = x ⟨i, hi⟩ := dif_pos hi #align dfinsupp.mk_of_mem DFinsupp.mk_of_mem theorem mk_of_not_mem (hi : i ∉ s) : (mk s x : ∀ i, β i) i = 0 := dif_neg hi #align dfinsupp.mk_of_not_mem DFinsupp.mk_of_not_mem theorem mk_injective (s : Finset ι) : Function.Injective (@mk ι β _ _ s) := by intro x y H ext i have h1 : (mk s x : ∀ i, β i) i = (mk s y : ∀ i, β i) i := by rw [H] obtain ⟨i, hi : i ∈ s⟩ := i dsimp only [mk_apply, Subtype.coe_mk] at h1 simpa only [dif_pos hi] using h1 #align dfinsupp.mk_injective DFinsupp.mk_injective instance unique [∀ i, Subsingleton (β i)] : Unique (Π₀ i, β i) := DFunLike.coe_injective.unique #align dfinsupp.unique DFinsupp.unique instance uniqueOfIsEmpty [IsEmpty ι] : Unique (Π₀ i, β i) := DFunLike.coe_injective.unique #align dfinsupp.unique_of_is_empty DFinsupp.uniqueOfIsEmpty /-- Given `Fintype ι`, `equivFunOnFintype` is the `Equiv` between `Π₀ i, β i` and `Π i, β i`. (All dependent functions on a finite type are finitely supported.) -/ @[simps apply] def equivFunOnFintype [Fintype ι] : (Π₀ i, β i) ≃ ∀ i, β i where toFun := (⇑) invFun f := ⟨f, Trunc.mk ⟨Finset.univ.1, fun _ => Or.inl <| Finset.mem_univ_val _⟩⟩ left_inv _ := DFunLike.coe_injective rfl right_inv _ := rfl #align dfinsupp.equiv_fun_on_fintype DFinsupp.equivFunOnFintype #align dfinsupp.equiv_fun_on_fintype_apply DFinsupp.equivFunOnFintype_apply @[simp] theorem equivFunOnFintype_symm_coe [Fintype ι] (f : Π₀ i, β i) : equivFunOnFintype.symm f = f := Equiv.symm_apply_apply _ _ #align dfinsupp.equiv_fun_on_fintype_symm_coe DFinsupp.equivFunOnFintype_symm_coe /-- The function `single i b : Π₀ i, β i` sends `i` to `b` and all other points to `0`. -/ def single (i : ι) (b : β i) : Π₀ i, β i := ⟨Pi.single i b, Trunc.mk ⟨{i}, fun j => (Decidable.eq_or_ne j i).imp (by simp) fun h => Pi.single_eq_of_ne h _⟩⟩ #align dfinsupp.single DFinsupp.single theorem single_eq_pi_single {i b} : ⇑(single i b : Π₀ i, β i) = Pi.single i b := rfl #align dfinsupp.single_eq_pi_single DFinsupp.single_eq_pi_single @[simp] theorem single_apply {i i' b} : (single i b : Π₀ i, β i) i' = if h : i = i' then Eq.recOn h b else 0 := by rw [single_eq_pi_single, Pi.single, Function.update] simp [@eq_comm _ i i'] #align dfinsupp.single_apply DFinsupp.single_apply @[simp] theorem single_zero (i) : (single i 0 : Π₀ i, β i) = 0 := DFunLike.coe_injective <| Pi.single_zero _ #align dfinsupp.single_zero DFinsupp.single_zero -- @[simp] -- Porting note (#10618): simp can prove this theorem single_eq_same {i b} : (single i b : Π₀ i, β i) i = b := by simp only [single_apply, dite_eq_ite, ite_true] #align dfinsupp.single_eq_same DFinsupp.single_eq_same theorem single_eq_of_ne {i i' b} (h : i ≠ i') : (single i b : Π₀ i, β i) i' = 0 := by simp only [single_apply, dif_neg h] #align dfinsupp.single_eq_of_ne DFinsupp.single_eq_of_ne theorem single_injective {i} : Function.Injective (single i : β i → Π₀ i, β i) := fun _ _ H => Pi.single_injective β i <| DFunLike.coe_injective.eq_iff.mpr H #align dfinsupp.single_injective DFinsupp.single_injective /-- Like `Finsupp.single_eq_single_iff`, but with a `HEq` due to dependent types -/ theorem single_eq_single_iff (i j : ι) (xi : β i) (xj : β j) : DFinsupp.single i xi = DFinsupp.single j xj ↔ i = j ∧ HEq xi xj ∨ xi = 0 ∧ xj = 0 := by constructor · intro h by_cases hij : i = j · subst hij exact Or.inl ⟨rfl, heq_of_eq (DFinsupp.single_injective h)⟩ · have h_coe : ⇑(DFinsupp.single i xi) = DFinsupp.single j xj := congr_arg (⇑) h have hci := congr_fun h_coe i have hcj := congr_fun h_coe j rw [DFinsupp.single_eq_same] at hci hcj rw [DFinsupp.single_eq_of_ne (Ne.symm hij)] at hci rw [DFinsupp.single_eq_of_ne hij] at hcj exact Or.inr ⟨hci, hcj.symm⟩ · rintro (⟨rfl, hxi⟩ | ⟨hi, hj⟩) · rw [eq_of_heq hxi] · rw [hi, hj, DFinsupp.single_zero, DFinsupp.single_zero] #align dfinsupp.single_eq_single_iff DFinsupp.single_eq_single_iff /-- `DFinsupp.single a b` is injective in `a`. For the statement that it is injective in `b`, see `DFinsupp.single_injective` -/ theorem single_left_injective {b : ∀ i : ι, β i} (h : ∀ i, b i ≠ 0) : Function.Injective (fun i => single i (b i) : ι → Π₀ i, β i) := fun _ _ H => (((single_eq_single_iff _ _ _ _).mp H).resolve_right fun hb => h _ hb.1).left #align dfinsupp.single_left_injective DFinsupp.single_left_injective @[simp] theorem single_eq_zero {i : ι} {xi : β i} : single i xi = 0 ↔ xi = 0 := by rw [← single_zero i, single_eq_single_iff] simp #align dfinsupp.single_eq_zero DFinsupp.single_eq_zero theorem filter_single (p : ι → Prop) [DecidablePred p] (i : ι) (x : β i) : (single i x).filter p = if p i then single i x else 0 := by ext j have := apply_ite (fun x : Π₀ i, β i => x j) (p i) (single i x) 0 dsimp at this rw [filter_apply, this] obtain rfl | hij := Decidable.eq_or_ne i j · rfl · rw [single_eq_of_ne hij, ite_self, ite_self] #align dfinsupp.filter_single DFinsupp.filter_single @[simp] theorem filter_single_pos {p : ι → Prop} [DecidablePred p] (i : ι) (x : β i) (h : p i) : (single i x).filter p = single i x := by rw [filter_single, if_pos h] #align dfinsupp.filter_single_pos DFinsupp.filter_single_pos @[simp] theorem filter_single_neg {p : ι → Prop} [DecidablePred p] (i : ι) (x : β i) (h : ¬p i) : (single i x).filter p = 0 := by rw [filter_single, if_neg h] #align dfinsupp.filter_single_neg DFinsupp.filter_single_neg /-- Equality of sigma types is sufficient (but not necessary) to show equality of `DFinsupp`s. -/ theorem single_eq_of_sigma_eq {i j} {xi : β i} {xj : β j} (h : (⟨i, xi⟩ : Sigma β) = ⟨j, xj⟩) : DFinsupp.single i xi = DFinsupp.single j xj := by cases h rfl #align dfinsupp.single_eq_of_sigma_eq DFinsupp.single_eq_of_sigma_eq @[simp] theorem equivFunOnFintype_single [Fintype ι] (i : ι) (m : β i) : (@DFinsupp.equivFunOnFintype ι β _ _) (DFinsupp.single i m) = Pi.single i m := by ext x dsimp [Pi.single, Function.update] simp [DFinsupp.single_eq_pi_single, @eq_comm _ i] #align dfinsupp.equiv_fun_on_fintype_single DFinsupp.equivFunOnFintype_single @[simp] theorem equivFunOnFintype_symm_single [Fintype ι] (i : ι) (m : β i) : (@DFinsupp.equivFunOnFintype ι β _ _).symm (Pi.single i m) = DFinsupp.single i m := by ext i' simp only [← single_eq_pi_single, equivFunOnFintype_symm_coe] #align dfinsupp.equiv_fun_on_fintype_symm_single DFinsupp.equivFunOnFintype_symm_single section SingleAndZipWith variable [∀ i, Zero (β₁ i)] [∀ i, Zero (β₂ i)] @[simp] theorem zipWith_single_single (f : ∀ i, β₁ i → β₂ i → β i) (hf : ∀ i, f i 0 0 = 0) {i} (b₁ : β₁ i) (b₂ : β₂ i) : zipWith f hf (single i b₁) (single i b₂) = single i (f i b₁ b₂) := by ext j rw [zipWith_apply] obtain rfl | hij := Decidable.eq_or_ne i j · rw [single_eq_same, single_eq_same, single_eq_same] · rw [single_eq_of_ne hij, single_eq_of_ne hij, single_eq_of_ne hij, hf] end SingleAndZipWith /-- Redefine `f i` to be `0`. -/ def erase (i : ι) (x : Π₀ i, β i) : Π₀ i, β i := ⟨fun j ↦ if j = i then 0 else x.1 j, x.support'.map fun xs ↦ ⟨xs.1, fun j ↦ (xs.prop j).imp_right (by simp only [·, ite_self])⟩⟩ #align dfinsupp.erase DFinsupp.erase @[simp] theorem erase_apply {i j : ι} {f : Π₀ i, β i} : (f.erase i) j = if j = i then 0 else f j := rfl #align dfinsupp.erase_apply DFinsupp.erase_apply -- @[simp] -- Porting note (#10618): simp can prove this theorem erase_same {i : ι} {f : Π₀ i, β i} : (f.erase i) i = 0 := by simp #align dfinsupp.erase_same DFinsupp.erase_same theorem erase_ne {i i' : ι} {f : Π₀ i, β i} (h : i' ≠ i) : (f.erase i) i' = f i' := by simp [h] #align dfinsupp.erase_ne DFinsupp.erase_ne theorem piecewise_single_erase (x : Π₀ i, β i) (i : ι) [∀ i' : ι, Decidable <| (i' ∈ ({i} : Set ι))] : -- Porting note: added Decidable hypothesis (single i (x i)).piecewise (x.erase i) {i} = x := by ext j; rw [piecewise_apply]; split_ifs with h · rw [(id h : j = i), single_eq_same] · exact erase_ne h #align dfinsupp.piecewise_single_erase DFinsupp.piecewise_single_erase theorem erase_eq_sub_single {β : ι → Type*} [∀ i, AddGroup (β i)] (f : Π₀ i, β i) (i : ι) : f.erase i = f - single i (f i) := by ext j rcases eq_or_ne i j with (rfl | h) · simp · simp [erase_ne h.symm, single_eq_of_ne h, @eq_comm _ j, h] #align dfinsupp.erase_eq_sub_single DFinsupp.erase_eq_sub_single @[simp] theorem erase_zero (i : ι) : erase i (0 : Π₀ i, β i) = 0 := ext fun _ => ite_self _ #align dfinsupp.erase_zero DFinsupp.erase_zero @[simp] theorem filter_ne_eq_erase (f : Π₀ i, β i) (i : ι) : f.filter (· ≠ i) = f.erase i := by ext1 j simp only [DFinsupp.filter_apply, DFinsupp.erase_apply, ite_not] #align dfinsupp.filter_ne_eq_erase DFinsupp.filter_ne_eq_erase @[simp] theorem filter_ne_eq_erase' (f : Π₀ i, β i) (i : ι) : f.filter (i ≠ ·) = f.erase i := by rw [← filter_ne_eq_erase f i] congr with j exact ne_comm #align dfinsupp.filter_ne_eq_erase' DFinsupp.filter_ne_eq_erase' theorem erase_single (j : ι) (i : ι) (x : β i) : (single i x).erase j = if i = j then 0 else single i x := by rw [← filter_ne_eq_erase, filter_single, ite_not] #align dfinsupp.erase_single DFinsupp.erase_single @[simp] theorem erase_single_same (i : ι) (x : β i) : (single i x).erase i = 0 := by rw [erase_single, if_pos rfl] #align dfinsupp.erase_single_same DFinsupp.erase_single_same @[simp] theorem erase_single_ne {i j : ι} (x : β i) (h : i ≠ j) : (single i x).erase j = single i x := by rw [erase_single, if_neg h] #align dfinsupp.erase_single_ne DFinsupp.erase_single_ne section Update variable (f : Π₀ i, β i) (i) (b : β i) /-- Replace the value of a `Π₀ i, β i` at a given point `i : ι` by a given value `b : β i`. If `b = 0`, this amounts to removing `i` from the support. Otherwise, `i` is added to it. This is the (dependent) finitely-supported version of `Function.update`. -/ def update : Π₀ i, β i := ⟨Function.update f i b, f.support'.map fun s => ⟨i ::ₘ s.1, fun j => by rcases eq_or_ne i j with (rfl | hi) · simp · obtain hj | (hj : f j = 0) := s.prop j · exact Or.inl (Multiset.mem_cons_of_mem hj) · exact Or.inr ((Function.update_noteq hi.symm b _).trans hj)⟩⟩ #align dfinsupp.update DFinsupp.update variable (j : ι) @[simp, norm_cast] lemma coe_update : (f.update i b : ∀ i : ι, β i) = Function.update f i b := rfl #align dfinsupp.coe_update DFinsupp.coe_update @[simp] theorem update_self : f.update i (f i) = f := by ext simp #align dfinsupp.update_self DFinsupp.update_self @[simp] theorem update_eq_erase : f.update i 0 = f.erase i := by ext j rcases eq_or_ne i j with (rfl | hi) · simp · simp [hi.symm] #align dfinsupp.update_eq_erase DFinsupp.update_eq_erase theorem update_eq_single_add_erase {β : ι → Type*} [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (i : ι) (b : β i) : f.update i b = single i b + f.erase i := by ext j rcases eq_or_ne i j with (rfl | h) · simp · simp [Function.update_noteq h.symm, h, erase_ne, h.symm] #align dfinsupp.update_eq_single_add_erase DFinsupp.update_eq_single_add_erase theorem update_eq_erase_add_single {β : ι → Type*} [∀ i, AddZeroClass (β i)] (f : Π₀ i, β i) (i : ι) (b : β i) : f.update i b = f.erase i + single i b := by ext j rcases eq_or_ne i j with (rfl | h) · simp · simp [Function.update_noteq h.symm, h, erase_ne, h.symm] #align dfinsupp.update_eq_erase_add_single DFinsupp.update_eq_erase_add_single theorem update_eq_sub_add_single {β : ι → Type*} [∀ i, AddGroup (β i)] (f : Π₀ i, β i) (i : ι) (b : β i) : f.update i b = f - single i (f i) + single i b := by rw [update_eq_erase_add_single f i b, erase_eq_sub_single f i] #align dfinsupp.update_eq_sub_add_single DFinsupp.update_eq_sub_add_single end Update end Basic section AddMonoid variable [∀ i, AddZeroClass (β i)] @[simp] theorem single_add (i : ι) (b₁ b₂ : β i) : single i (b₁ + b₂) = single i b₁ + single i b₂ := (zipWith_single_single (fun _ => (· + ·)) _ b₁ b₂).symm #align dfinsupp.single_add DFinsupp.single_add @[simp] theorem erase_add (i : ι) (f₁ f₂ : Π₀ i, β i) : erase i (f₁ + f₂) = erase i f₁ + erase i f₂ := ext fun _ => by simp [ite_zero_add] #align dfinsupp.erase_add DFinsupp.erase_add variable (β) /-- `DFinsupp.single` as an `AddMonoidHom`. -/ @[simps] def singleAddHom (i : ι) : β i →+ Π₀ i, β i where toFun := single i map_zero' := single_zero i map_add' := single_add i #align dfinsupp.single_add_hom DFinsupp.singleAddHom #align dfinsupp.single_add_hom_apply DFinsupp.singleAddHom_apply /-- `DFinsupp.erase` as an `AddMonoidHom`. -/ @[simps] def eraseAddHom (i : ι) : (Π₀ i, β i) →+ Π₀ i, β i where toFun := erase i map_zero' := erase_zero i map_add' := erase_add i #align dfinsupp.erase_add_hom DFinsupp.eraseAddHom #align dfinsupp.erase_add_hom_apply DFinsupp.eraseAddHom_apply variable {β} @[simp] theorem single_neg {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (x : β i) : single i (-x) = -single i x := (singleAddHom β i).map_neg x #align dfinsupp.single_neg DFinsupp.single_neg @[simp] theorem single_sub {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (x y : β i) : single i (x - y) = single i x - single i y := (singleAddHom β i).map_sub x y #align dfinsupp.single_sub DFinsupp.single_sub @[simp] theorem erase_neg {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (f : Π₀ i, β i) : (-f).erase i = -f.erase i := (eraseAddHom β i).map_neg f #align dfinsupp.erase_neg DFinsupp.erase_neg @[simp] theorem erase_sub {β : ι → Type v} [∀ i, AddGroup (β i)] (i : ι) (f g : Π₀ i, β i) : (f - g).erase i = f.erase i - g.erase i := (eraseAddHom β i).map_sub f g #align dfinsupp.erase_sub DFinsupp.erase_sub theorem single_add_erase (i : ι) (f : Π₀ i, β i) : single i (f i) + f.erase i = f := ext fun i' => if h : i = i' then by subst h; simp only [add_apply, single_apply, erase_apply, add_zero, dite_eq_ite, if_true] else by simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (Ne.symm h), zero_add] #align dfinsupp.single_add_erase DFinsupp.single_add_erase theorem erase_add_single (i : ι) (f : Π₀ i, β i) : f.erase i + single i (f i) = f := ext fun i' => if h : i = i' then by subst h; simp only [add_apply, single_apply, erase_apply, zero_add, dite_eq_ite, if_true] else by simp only [add_apply, single_apply, erase_apply, dif_neg h, if_neg (Ne.symm h), add_zero] #align dfinsupp.erase_add_single DFinsupp.erase_add_single protected theorem induction {p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i) (h0 : p 0) (ha : ∀ (i b) (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (single i b + f)) : p f := by cases' f with f s induction' s using Trunc.induction_on with s cases' s with s H induction' s using Multiset.induction_on with i s ih generalizing f · have : f = 0 := funext fun i => (H i).resolve_left (Multiset.not_mem_zero _) subst this exact h0 have H2 : p (erase i ⟨f, Trunc.mk ⟨i ::ₘ s, H⟩⟩) := by dsimp only [erase, Trunc.map, Trunc.bind, Trunc.liftOn, Trunc.lift_mk, Function.comp, Subtype.coe_mk] have H2 : ∀ j, j ∈ s ∨ ite (j = i) 0 (f j) = 0 := by intro j cases' H j with H2 H2 · cases' Multiset.mem_cons.1 H2 with H3 H3 · right; exact if_pos H3 · left; exact H3 right split_ifs <;> [rfl; exact H2] have H3 : ∀ aux, (⟨fun j : ι => ite (j = i) 0 (f j), Trunc.mk ⟨i ::ₘ s, aux⟩⟩ : Π₀ i, β i) = ⟨fun j : ι => ite (j = i) 0 (f j), Trunc.mk ⟨s, H2⟩⟩ := fun _ ↦ ext fun _ => rfl rw [H3] apply ih have H3 : single i _ + _ = (⟨f, Trunc.mk ⟨i ::ₘ s, H⟩⟩ : Π₀ i, β i) := single_add_erase _ _ rw [← H3] change p (single i (f i) + _) cases' Classical.em (f i = 0) with h h · rw [h, single_zero, zero_add] exact H2 refine ha _ _ _ ?_ h H2 rw [erase_same] #align dfinsupp.induction DFinsupp.induction theorem induction₂ {p : (Π₀ i, β i) → Prop} (f : Π₀ i, β i) (h0 : p 0) (ha : ∀ (i b) (f : Π₀ i, β i), f i = 0 → b ≠ 0 → p f → p (f + single i b)) : p f := DFinsupp.induction f h0 fun i b f h1 h2 h3 => have h4 : f + single i b = single i b + f := by ext j; by_cases H : i = j · subst H simp [h1] · simp [H] Eq.recOn h4 <| ha i b f h1 h2 h3 #align dfinsupp.induction₂ DFinsupp.induction₂ @[simp] theorem add_closure_iUnion_range_single : AddSubmonoid.closure (⋃ i : ι, Set.range (single i : β i → Π₀ i, β i)) = ⊤ := top_unique fun x _ => by apply DFinsupp.induction x · exact AddSubmonoid.zero_mem _ exact fun a b f _ _ hf => AddSubmonoid.add_mem _ (AddSubmonoid.subset_closure <| Set.mem_iUnion.2 ⟨a, Set.mem_range_self _⟩) hf #align dfinsupp.add_closure_Union_range_single DFinsupp.add_closure_iUnion_range_single /-- If two additive homomorphisms from `Π₀ i, β i` are equal on each `single a b`, then they are equal. -/ theorem addHom_ext {γ : Type w} [AddZeroClass γ] ⦃f g : (Π₀ i, β i) →+ γ⦄ (H : ∀ (i : ι) (y : β i), f (single i y) = g (single i y)) : f = g := by refine AddMonoidHom.eq_of_eqOn_denseM add_closure_iUnion_range_single fun f hf => ?_ simp only [Set.mem_iUnion, Set.mem_range] at hf rcases hf with ⟨x, y, rfl⟩ apply H #align dfinsupp.add_hom_ext DFinsupp.addHom_ext /-- If two additive homomorphisms from `Π₀ i, β i` are equal on each `single a b`, then they are equal. See note [partially-applied ext lemmas]. -/ @[ext] theorem addHom_ext' {γ : Type w} [AddZeroClass γ] ⦃f g : (Π₀ i, β i) →+ γ⦄ (H : ∀ x, f.comp (singleAddHom β x) = g.comp (singleAddHom β x)) : f = g := addHom_ext fun x => DFunLike.congr_fun (H x) #align dfinsupp.add_hom_ext' DFinsupp.addHom_ext' end AddMonoid @[simp] theorem mk_add [∀ i, AddZeroClass (β i)] {s : Finset ι} {x y : ∀ i : (↑s : Set ι), β i} : mk s (x + y) = mk s x + mk s y := ext fun i => by simp only [add_apply, mk_apply]; split_ifs <;> [rfl; rw [zero_add]] #align dfinsupp.mk_add DFinsupp.mk_add @[simp] theorem mk_zero [∀ i, Zero (β i)] {s : Finset ι} : mk s (0 : ∀ i : (↑s : Set ι), β i.1) = 0 := ext fun i => by simp only [mk_apply]; split_ifs <;> rfl #align dfinsupp.mk_zero DFinsupp.mk_zero @[simp] theorem mk_neg [∀ i, AddGroup (β i)] {s : Finset ι} {x : ∀ i : (↑s : Set ι), β i.1} : mk s (-x) = -mk s x := ext fun i => by simp only [neg_apply, mk_apply]; split_ifs <;> [rfl; rw [neg_zero]] #align dfinsupp.mk_neg DFinsupp.mk_neg @[simp] theorem mk_sub [∀ i, AddGroup (β i)] {s : Finset ι} {x y : ∀ i : (↑s : Set ι), β i.1} : mk s (x - y) = mk s x - mk s y := ext fun i => by simp only [sub_apply, mk_apply]; split_ifs <;> [rfl; rw [sub_zero]] #align dfinsupp.mk_sub DFinsupp.mk_sub /-- If `s` is a subset of `ι` then `mk_addGroupHom s` is the canonical additive group homomorphism from $\prod_{i\in s}\beta_i$ to $\prod_{\mathtt{i : \iota}}\beta_i.$-/ def mkAddGroupHom [∀ i, AddGroup (β i)] (s : Finset ι) : (∀ i : (s : Set ι), β ↑i) →+ Π₀ i : ι, β i where toFun := mk s map_zero' := mk_zero map_add' _ _ := mk_add #align dfinsupp.mk_add_group_hom DFinsupp.mkAddGroupHom section variable [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] @[simp] theorem mk_smul {s : Finset ι} (c : γ) (x : ∀ i : (↑s : Set ι), β (i : ι)) : mk s (c • x) = c • mk s x := ext fun i => by simp only [smul_apply, mk_apply]; split_ifs <;> [rfl; rw [smul_zero]] #align dfinsupp.mk_smul DFinsupp.mk_smul @[simp] theorem single_smul {i : ι} (c : γ) (x : β i) : single i (c • x) = c • single i x := ext fun i => by simp only [smul_apply, single_apply] split_ifs with h · cases h; rfl · rw [smul_zero] #align dfinsupp.single_smul DFinsupp.single_smul end section SupportBasic variable [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] /-- Set `{i | f x ≠ 0}` as a `Finset`. -/ def support (f : Π₀ i, β i) : Finset ι := (f.support'.lift fun xs => (Multiset.toFinset xs.1).filter fun i => f i ≠ 0) <| by rintro ⟨sx, hx⟩ ⟨sy, hy⟩ dsimp only [Subtype.coe_mk, toFun_eq_coe] at * ext i; constructor · intro H rcases Finset.mem_filter.1 H with ⟨_, h⟩ exact Finset.mem_filter.2 ⟨Multiset.mem_toFinset.2 <| (hy i).resolve_right h, h⟩ · intro H rcases Finset.mem_filter.1 H with ⟨_, h⟩ exact Finset.mem_filter.2 ⟨Multiset.mem_toFinset.2 <| (hx i).resolve_right h, h⟩ #align dfinsupp.support DFinsupp.support @[simp] theorem support_mk_subset {s : Finset ι} {x : ∀ i : (↑s : Set ι), β i.1} : (mk s x).support ⊆ s := fun _ H => Multiset.mem_toFinset.1 (Finset.mem_filter.1 H).1 #align dfinsupp.support_mk_subset DFinsupp.support_mk_subset @[simp] theorem support_mk'_subset {f : ∀ i, β i} {s : Multiset ι} {h} : (mk' f <| Trunc.mk ⟨s, h⟩).support ⊆ s.toFinset := fun i H => Multiset.mem_toFinset.1 <| by simpa using (Finset.mem_filter.1 H).1 #align dfinsupp.support_mk'_subset DFinsupp.support_mk'_subset @[simp] theorem mem_support_toFun (f : Π₀ i, β i) (i) : i ∈ f.support ↔ f i ≠ 0 := by cases' f with f s induction' s using Trunc.induction_on with s dsimp only [support, Trunc.lift_mk] rw [Finset.mem_filter, Multiset.mem_toFinset, coe_mk'] exact and_iff_right_of_imp (s.prop i).resolve_right #align dfinsupp.mem_support_to_fun DFinsupp.mem_support_toFun theorem eq_mk_support (f : Π₀ i, β i) : f = mk f.support fun i => f i := by aesop #align dfinsupp.eq_mk_support DFinsupp.eq_mk_support /-- Equivalence between dependent functions with finite support `s : Finset ι` and functions `∀ i, {x : β i // x ≠ 0}`. -/ @[simps] def subtypeSupportEqEquiv (s : Finset ι) : {f : Π₀ i, β i // f.support = s} ≃ ∀ i : s, {x : β i // x ≠ 0} where toFun | ⟨f, hf⟩ => fun ⟨i, hi⟩ ↦ ⟨f i, (f.mem_support_toFun i).1 <| hf.symm ▸ hi⟩ invFun f := ⟨mk s fun i ↦ (f i).1, Finset.ext fun i ↦ by -- TODO: `simp` fails to use `(f _).2` inside `∃ _, _` calc i ∈ support (mk s fun i ↦ (f i).1) ↔ ∃ h : i ∈ s, (f ⟨i, h⟩).1 ≠ 0 := by simp _ ↔ ∃ _ : i ∈ s, True := exists_congr fun h ↦ (iff_true _).mpr (f _).2 _ ↔ i ∈ s := by simp⟩ left_inv := by rintro ⟨f, rfl⟩ ext i simpa using Eq.symm right_inv f := by ext1 simp [Subtype.eta]; rfl /-- Equivalence between all dependent finitely supported functions `f : Π₀ i, β i` and type of pairs `⟨s : Finset ι, f : ∀ i : s, {x : β i // x ≠ 0}⟩`. -/ @[simps! apply_fst apply_snd_coe] def sigmaFinsetFunEquiv : (Π₀ i, β i) ≃ Σ s : Finset ι, ∀ i : s, {x : β i // x ≠ 0} := (Equiv.sigmaFiberEquiv DFinsupp.support).symm.trans (.sigmaCongrRight subtypeSupportEqEquiv) @[simp] theorem support_zero : (0 : Π₀ i, β i).support = ∅ := rfl #align dfinsupp.support_zero DFinsupp.support_zero theorem mem_support_iff {f : Π₀ i, β i} {i : ι} : i ∈ f.support ↔ f i ≠ 0 := f.mem_support_toFun _ #align dfinsupp.mem_support_iff DFinsupp.mem_support_iff theorem not_mem_support_iff {f : Π₀ i, β i} {i : ι} : i ∉ f.support ↔ f i = 0 := not_iff_comm.1 mem_support_iff.symm #align dfinsupp.not_mem_support_iff DFinsupp.not_mem_support_iff @[simp] theorem support_eq_empty {f : Π₀ i, β i} : f.support = ∅ ↔ f = 0 := ⟨fun H => ext <| by simpa [Finset.ext_iff] using H, by simp (config := { contextual := true })⟩ #align dfinsupp.support_eq_empty DFinsupp.support_eq_empty instance decidableZero : DecidablePred (Eq (0 : Π₀ i, β i)) := fun _ => decidable_of_iff _ <| support_eq_empty.trans eq_comm #align dfinsupp.decidable_zero DFinsupp.decidableZero theorem support_subset_iff {s : Set ι} {f : Π₀ i, β i} : ↑f.support ⊆ s ↔ ∀ i ∉ s, f i = 0 := by simp [Set.subset_def]; exact forall_congr' fun i => not_imp_comm #align dfinsupp.support_subset_iff DFinsupp.support_subset_iff theorem support_single_ne_zero {i : ι} {b : β i} (hb : b ≠ 0) : (single i b).support = {i} := by ext j; by_cases h : i = j · subst h simp [hb] simp [Ne.symm h, h] #align dfinsupp.support_single_ne_zero DFinsupp.support_single_ne_zero theorem support_single_subset {i : ι} {b : β i} : (single i b).support ⊆ {i} := support_mk'_subset #align dfinsupp.support_single_subset DFinsupp.support_single_subset section MapRangeAndZipWith variable [∀ i, Zero (β₁ i)] [∀ i, Zero (β₂ i)] theorem mapRange_def [∀ (i) (x : β₁ i), Decidable (x ≠ 0)] {f : ∀ i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} : mapRange f hf g = mk g.support fun i => f i.1 (g i.1) := by ext i by_cases h : g i ≠ 0 <;> simp at h <;> simp [h, hf] #align dfinsupp.map_range_def DFinsupp.mapRange_def @[simp] theorem mapRange_single {f : ∀ i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {i : ι} {b : β₁ i} : mapRange f hf (single i b) = single i (f i b) := DFinsupp.ext fun i' => by by_cases h : i = i' · subst i' simp · simp [h, hf] #align dfinsupp.map_range_single DFinsupp.mapRange_single variable [∀ (i) (x : β₁ i), Decidable (x ≠ 0)] [∀ (i) (x : β₂ i), Decidable (x ≠ 0)] theorem support_mapRange {f : ∀ i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} : (mapRange f hf g).support ⊆ g.support := by simp [mapRange_def] #align dfinsupp.support_map_range DFinsupp.support_mapRange theorem zipWith_def {ι : Type u} {β : ι → Type v} {β₁ : ι → Type v₁} {β₂ : ι → Type v₂} [dec : DecidableEq ι] [∀ i : ι, Zero (β i)] [∀ i : ι, Zero (β₁ i)] [∀ i : ι, Zero (β₂ i)] [∀ (i : ι) (x : β₁ i), Decidable (x ≠ 0)] [∀ (i : ι) (x : β₂ i), Decidable (x ≠ 0)] {f : ∀ i, β₁ i → β₂ i → β i} {hf : ∀ i, f i 0 0 = 0} {g₁ : Π₀ i, β₁ i} {g₂ : Π₀ i, β₂ i} : zipWith f hf g₁ g₂ = mk (g₁.support ∪ g₂.support) fun i => f i.1 (g₁ i.1) (g₂ i.1) := by ext i by_cases h1 : g₁ i ≠ 0 <;> by_cases h2 : g₂ i ≠ 0 <;> simp only [not_not, Ne] at h1 h2 <;> simp [h1, h2, hf] #align dfinsupp.zip_with_def DFinsupp.zipWith_def theorem support_zipWith {f : ∀ i, β₁ i → β₂ i → β i} {hf : ∀ i, f i 0 0 = 0} {g₁ : Π₀ i, β₁ i} {g₂ : Π₀ i, β₂ i} : (zipWith f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support := by simp [zipWith_def] #align dfinsupp.support_zip_with DFinsupp.support_zipWith end MapRangeAndZipWith theorem erase_def (i : ι) (f : Π₀ i, β i) : f.erase i = mk (f.support.erase i) fun j => f j.1 := by ext j by_cases h1 : j = i <;> by_cases h2 : f j ≠ 0 <;> simp at h2 <;> simp [h1, h2] #align dfinsupp.erase_def DFinsupp.erase_def @[simp] theorem support_erase (i : ι) (f : Π₀ i, β i) : (f.erase i).support = f.support.erase i := by ext j by_cases h1 : j = i · simp only [h1, mem_support_toFun, erase_apply, ite_true, ne_eq, not_true, not_not, Finset.mem_erase, false_and] by_cases h2 : f j ≠ 0 <;> simp at h2 <;> simp [h1, h2] #align dfinsupp.support_erase DFinsupp.support_erase theorem support_update_ne_zero (f : Π₀ i, β i) (i : ι) {b : β i} (h : b ≠ 0) : support (f.update i b) = insert i f.support := by ext j rcases eq_or_ne i j with (rfl | hi) · simp [h] · simp [hi.symm] #align dfinsupp.support_update_ne_zero DFinsupp.support_update_ne_zero theorem support_update (f : Π₀ i, β i) (i : ι) (b : β i) [Decidable (b = 0)] : support (f.update i b) = if b = 0 then support (f.erase i) else insert i f.support := by ext j split_ifs with hb · subst hb simp [update_eq_erase, support_erase] · rw [support_update_ne_zero f _ hb] #align dfinsupp.support_update DFinsupp.support_update section FilterAndSubtypeDomain variable {p : ι → Prop} [DecidablePred p] theorem filter_def (f : Π₀ i, β i) : f.filter p = mk (f.support.filter p) fun i => f i.1 := by ext i; by_cases h1 : p i <;> by_cases h2 : f i ≠ 0 <;> simp at h2 <;> simp [h1, h2] #align dfinsupp.filter_def DFinsupp.filter_def @[simp] theorem support_filter (f : Π₀ i, β i) : (f.filter p).support = f.support.filter p := by ext i; by_cases h : p i <;> simp [h] #align dfinsupp.support_filter DFinsupp.support_filter theorem subtypeDomain_def (f : Π₀ i, β i) : f.subtypeDomain p = mk (f.support.subtype p) fun i => f i := by ext i; by_cases h2 : f i ≠ 0 <;> try simp at h2; dsimp; simp [h2] #align dfinsupp.subtype_domain_def DFinsupp.subtypeDomain_def @[simp, nolint simpNF] -- Porting note: simpNF claims that LHS does not simplify, but it does theorem support_subtypeDomain {f : Π₀ i, β i} : (subtypeDomain p f).support = f.support.subtype p := by ext i simp #align dfinsupp.support_subtype_domain DFinsupp.support_subtypeDomain end FilterAndSubtypeDomain end SupportBasic theorem support_add [∀ i, AddZeroClass (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] {g₁ g₂ : Π₀ i, β i} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support := support_zipWith #align dfinsupp.support_add DFinsupp.support_add @[simp] theorem support_neg [∀ i, AddGroup (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] {f : Π₀ i, β i} : support (-f) = support f := by ext i; simp #align dfinsupp.support_neg DFinsupp.support_neg theorem support_smul {γ : Type w} [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] (b : γ) (v : Π₀ i, β i) : (b • v).support ⊆ v.support := support_mapRange #align dfinsupp.support_smul DFinsupp.support_smul instance [∀ i, Zero (β i)] [∀ i, DecidableEq (β i)] : DecidableEq (Π₀ i, β i) := fun f g => decidable_of_iff (f.support = g.support ∧ ∀ i ∈ f.support, f i = g i) ⟨fun ⟨h₁, h₂⟩ => ext fun i => if h : i ∈ f.support then h₂ i h else by have hf : f i = 0 := by rwa [mem_support_iff, not_not] at h have hg : g i = 0 := by rwa [h₁, mem_support_iff, not_not] at h rw [hf, hg], by rintro rfl; simp⟩ section Equiv open Finset variable {κ : Type*} /-- Reindexing (and possibly removing) terms of a dfinsupp. -/ noncomputable def comapDomain [∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) (f : Π₀ i, β i) : Π₀ k, β (h k) where toFun x := f (h x) support' := f.support'.map fun s => ⟨((Multiset.toFinset s.1).preimage h hh.injOn).val, fun x => (s.prop (h x)).imp_left fun hx => mem_preimage.mpr <| Multiset.mem_toFinset.mpr hx⟩ #align dfinsupp.comap_domain DFinsupp.comapDomain @[simp] theorem comapDomain_apply [∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) (f : Π₀ i, β i) (k : κ) : comapDomain h hh f k = f (h k) := rfl #align dfinsupp.comap_domain_apply DFinsupp.comapDomain_apply @[simp] theorem comapDomain_zero [∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) : comapDomain h hh (0 : Π₀ i, β i) = 0 := by ext rw [zero_apply, comapDomain_apply, zero_apply] #align dfinsupp.comap_domain_zero DFinsupp.comapDomain_zero @[simp] theorem comapDomain_add [∀ i, AddZeroClass (β i)] (h : κ → ι) (hh : Function.Injective h) (f g : Π₀ i, β i) : comapDomain h hh (f + g) = comapDomain h hh f + comapDomain h hh g := by ext rw [add_apply, comapDomain_apply, comapDomain_apply, comapDomain_apply, add_apply] #align dfinsupp.comap_domain_add DFinsupp.comapDomain_add @[simp] theorem comapDomain_smul [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] (h : κ → ι) (hh : Function.Injective h) (r : γ) (f : Π₀ i, β i) : comapDomain h hh (r • f) = r • comapDomain h hh f := by ext rw [smul_apply, comapDomain_apply, smul_apply, comapDomain_apply] #align dfinsupp.comap_domain_smul DFinsupp.comapDomain_smul @[simp] theorem comapDomain_single [DecidableEq κ] [∀ i, Zero (β i)] (h : κ → ι) (hh : Function.Injective h) (k : κ) (x : β (h k)) : comapDomain h hh (single (h k) x) = single k x := by ext i rw [comapDomain_apply] obtain rfl | hik := Decidable.eq_or_ne i k · rw [single_eq_same, single_eq_same] · rw [single_eq_of_ne hik.symm, single_eq_of_ne (hh.ne hik.symm)] #align dfinsupp.comap_domain_single DFinsupp.comapDomain_single /-- A computable version of comap_domain when an explicit left inverse is provided. -/ def comapDomain' [∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (f : Π₀ i, β i) : Π₀ k, β (h k) where toFun x := f (h x) support' := f.support'.map fun s => ⟨Multiset.map h' s.1, fun x => (s.prop (h x)).imp_left fun hx => Multiset.mem_map.mpr ⟨_, hx, hh' _⟩⟩ #align dfinsupp.comap_domain' DFinsupp.comapDomain' @[simp] theorem comapDomain'_apply [∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (f : Π₀ i, β i) (k : κ) : comapDomain' h hh' f k = f (h k) := rfl #align dfinsupp.comap_domain'_apply DFinsupp.comapDomain'_apply @[simp] theorem comapDomain'_zero [∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) : comapDomain' h hh' (0 : Π₀ i, β i) = 0 := by ext rw [zero_apply, comapDomain'_apply, zero_apply] #align dfinsupp.comap_domain'_zero DFinsupp.comapDomain'_zero @[simp] theorem comapDomain'_add [∀ i, AddZeroClass (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (f g : Π₀ i, β i) : comapDomain' h hh' (f + g) = comapDomain' h hh' f + comapDomain' h hh' g := by ext rw [add_apply, comapDomain'_apply, comapDomain'_apply, comapDomain'_apply, add_apply] #align dfinsupp.comap_domain'_add DFinsupp.comapDomain'_add @[simp] theorem comapDomain'_smul [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (r : γ) (f : Π₀ i, β i) : comapDomain' h hh' (r • f) = r • comapDomain' h hh' f := by ext rw [smul_apply, comapDomain'_apply, smul_apply, comapDomain'_apply] #align dfinsupp.comap_domain'_smul DFinsupp.comapDomain'_smul @[simp] theorem comapDomain'_single [DecidableEq ι] [DecidableEq κ] [∀ i, Zero (β i)] (h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (k : κ) (x : β (h k)) : comapDomain' h hh' (single (h k) x) = single k x := by ext i rw [comapDomain'_apply] obtain rfl | hik := Decidable.eq_or_ne i k · rw [single_eq_same, single_eq_same] · rw [single_eq_of_ne hik.symm, single_eq_of_ne (hh'.injective.ne hik.symm)] #align dfinsupp.comap_domain'_single DFinsupp.comapDomain'_single /-- Reindexing terms of a dfinsupp. This is the dfinsupp version of `Equiv.piCongrLeft'`. -/ @[simps apply] def equivCongrLeft [∀ i, Zero (β i)] (h : ι ≃ κ) : (Π₀ i, β i) ≃ Π₀ k, β (h.symm k) where toFun := comapDomain' h.symm h.right_inv invFun f := mapRange (fun i => Equiv.cast <| congr_arg β <| h.symm_apply_apply i) (fun i => (Equiv.cast_eq_iff_heq _).mpr <| by rw [Equiv.symm_apply_apply]) (@comapDomain' _ _ _ _ h _ h.left_inv f) left_inv f := by ext i rw [mapRange_apply, comapDomain'_apply, comapDomain'_apply, Equiv.cast_eq_iff_heq, h.symm_apply_apply] right_inv f := by ext k rw [comapDomain'_apply, mapRange_apply, comapDomain'_apply, Equiv.cast_eq_iff_heq, h.apply_symm_apply] #align dfinsupp.equiv_congr_left DFinsupp.equivCongrLeft #align dfinsupp.equiv_congr_left_apply DFinsupp.equivCongrLeft_apply section SigmaCurry variable {α : ι → Type*} {δ : ∀ i, α i → Type v} -- lean can't find these instances -- Porting note: but Lean 4 can!!! instance hasAdd₂ [∀ i j, AddZeroClass (δ i j)] : Add (Π₀ (i : ι) (j : α i), δ i j) := inferInstance -- @DFinsupp.hasAdd ι (fun i => Π₀ j, δ i j) _ #align dfinsupp.has_add₂ DFinsupp.hasAdd₂ instance addZeroClass₂ [∀ i j, AddZeroClass (δ i j)] : AddZeroClass (Π₀ (i : ι) (j : α i), δ i j) := inferInstance -- @DFinsupp.addZeroClass ι (fun i => Π₀ j, δ i j) _ #align dfinsupp.add_zero_class₂ DFinsupp.addZeroClass₂ instance addMonoid₂ [∀ i j, AddMonoid (δ i j)] : AddMonoid (Π₀ (i : ι) (j : α i), δ i j) := inferInstance -- @DFinsupp.addMonoid ι (fun i => Π₀ j, δ i j) _ #align dfinsupp.add_monoid₂ DFinsupp.addMonoid₂ instance distribMulAction₂ [Monoid γ] [∀ i j, AddMonoid (δ i j)] [∀ i j, DistribMulAction γ (δ i j)] : DistribMulAction γ (Π₀ (i : ι) (j : α i), δ i j) := @DFinsupp.distribMulAction ι _ (fun i => Π₀ j, δ i j) _ _ _ #align dfinsupp.distrib_mul_action₂ DFinsupp.distribMulAction₂ /-- The natural map between `Π₀ (i : Σ i, α i), δ i.1 i.2` and `Π₀ i (j : α i), δ i j`. -/ def sigmaCurry [∀ i j, Zero (δ i j)] (f : Π₀ (i : Σ _, _), δ i.1 i.2) : Π₀ (i) (j), δ i j where toFun := fun i ↦ { toFun := fun j ↦ f ⟨i, j⟩, support' := f.support'.map (fun ⟨m, hm⟩ ↦ ⟨m.filterMap (fun ⟨i', j'⟩ ↦ if h : i' = i then some <| h.rec j' else none), fun j ↦ (hm ⟨i, j⟩).imp_left (fun h ↦ (m.mem_filterMap _).mpr ⟨⟨i, j⟩, h, dif_pos rfl⟩)⟩) } support' := f.support'.map (fun ⟨m, hm⟩ ↦ ⟨m.map Sigma.fst, fun i ↦ Decidable.or_iff_not_imp_left.mpr (fun h ↦ DFinsupp.ext (fun j ↦ (hm ⟨i, j⟩).resolve_left (fun H ↦ (Multiset.mem_map.not.mp h) ⟨⟨i, j⟩, H, rfl⟩)))⟩) @[simp] theorem sigmaCurry_apply [∀ i j, Zero (δ i j)] (f : Π₀ (i : Σ _, _), δ i.1 i.2) (i : ι) (j : α i) : sigmaCurry f i j = f ⟨i, j⟩ := rfl #align dfinsupp.sigma_curry_apply DFinsupp.sigmaCurry_apply @[simp] theorem sigmaCurry_zero [∀ i j, Zero (δ i j)] : sigmaCurry (0 : Π₀ (i : Σ _, _), δ i.1 i.2) = 0 := rfl #align dfinsupp.sigma_curry_zero DFinsupp.sigmaCurry_zero @[simp] theorem sigmaCurry_add [∀ i j, AddZeroClass (δ i j)] (f g : Π₀ (i : Σ _, _), δ i.1 i.2) : sigmaCurry (f + g) = sigmaCurry f + sigmaCurry g := by ext (i j) rfl #align dfinsupp.sigma_curry_add DFinsupp.sigmaCurry_add @[simp] theorem sigmaCurry_smul [Monoid γ] [∀ i j, AddMonoid (δ i j)] [∀ i j, DistribMulAction γ (δ i j)] (r : γ) (f : Π₀ (i : Σ _, _), δ i.1 i.2) : sigmaCurry (r • f) = r • sigmaCurry f := by ext (i j) rfl #align dfinsupp.sigma_curry_smul DFinsupp.sigmaCurry_smul @[simp] theorem sigmaCurry_single [∀ i, DecidableEq (α i)] [∀ i j, Zero (δ i j)] (ij : Σ i, α i) (x : δ ij.1 ij.2) : sigmaCurry (single ij x) = single ij.1 (single ij.2 x : Π₀ j, δ ij.1 j) := by obtain ⟨i, j⟩ := ij ext i' j' dsimp only rw [sigmaCurry_apply] obtain rfl | hi := eq_or_ne i i' · rw [single_eq_same] obtain rfl | hj := eq_or_ne j j' · rw [single_eq_same, single_eq_same] · rw [single_eq_of_ne, single_eq_of_ne hj] simpa using hj · rw [single_eq_of_ne, single_eq_of_ne hi, zero_apply] simp [hi] #align dfinsupp.sigma_curry_single DFinsupp.sigmaCurry_single /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- The natural map between `Π₀ i (j : α i), δ i j` and `Π₀ (i : Σ i, α i), δ i.1 i.2`, inverse of `curry`. -/ def sigmaUncurry [∀ i j, Zero (δ i j)] [∀ i, DecidableEq (α i)] [∀ i j (x : δ i j), Decidable (x ≠ 0)] (f : Π₀ (i) (j), δ i j) : Π₀ i : Σi, _, δ i.1 i.2 where toFun i := f i.1 i.2 support' := f.support'.map fun s => ⟨Multiset.bind s.1 fun i => ((f i).support.map ⟨Sigma.mk i, sigma_mk_injective⟩).val, fun i => by simp_rw [Multiset.mem_bind, map_val, Multiset.mem_map, Function.Embedding.coeFn_mk, ← Finset.mem_def, mem_support_toFun] obtain hi | (hi : f i.1 = 0) := s.prop i.1 · by_cases hi' : f i.1 i.2 = 0 · exact Or.inr hi' · exact Or.inl ⟨_, hi, i.2, hi', Sigma.eta _⟩ · right rw [hi, zero_apply]⟩ #align dfinsupp.sigma_uncurry DFinsupp.sigmaUncurry /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[simp] theorem sigmaUncurry_apply [∀ i j, Zero (δ i j)] [∀ i, DecidableEq (α i)] [∀ i j (x : δ i j), Decidable (x ≠ 0)] (f : Π₀ (i) (j), δ i j) (i : ι) (j : α i) : sigmaUncurry f ⟨i, j⟩ = f i j := rfl #align dfinsupp.sigma_uncurry_apply DFinsupp.sigmaUncurry_apply /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[simp] theorem sigmaUncurry_zero [∀ i j, Zero (δ i j)] [∀ i, DecidableEq (α i)] [∀ i j (x : δ i j), Decidable (x ≠ 0)] : sigmaUncurry (0 : Π₀ (i) (j), δ i j) = 0 := rfl #align dfinsupp.sigma_uncurry_zero DFinsupp.sigmaUncurry_zero /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[simp] theorem sigmaUncurry_add [∀ i j, AddZeroClass (δ i j)] [∀ i, DecidableEq (α i)] [∀ i j (x : δ i j), Decidable (x ≠ 0)] (f g : Π₀ (i) (j), δ i j) : sigmaUncurry (f + g) = sigmaUncurry f + sigmaUncurry g := DFunLike.coe_injective rfl #align dfinsupp.sigma_uncurry_add DFinsupp.sigmaUncurry_add /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ @[simp] theorem sigmaUncurry_smul [Monoid γ] [∀ i j, AddMonoid (δ i j)] [∀ i, DecidableEq (α i)] [∀ i j (x : δ i j), Decidable (x ≠ 0)] [∀ i j, DistribMulAction γ (δ i j)] (r : γ) (f : Π₀ (i) (j), δ i j) : sigmaUncurry (r • f) = r • sigmaUncurry f := DFunLike.coe_injective rfl #align dfinsupp.sigma_uncurry_smul DFinsupp.sigmaUncurry_smul @[simp] theorem sigmaUncurry_single [∀ i j, Zero (δ i j)] [∀ i, DecidableEq (α i)] [∀ i j (x : δ i j), Decidable (x ≠ 0)] (i) (j : α i) (x : δ i j) : sigmaUncurry (single i (single j x : Π₀ j : α i, δ i j)) = single ⟨i, j⟩ (by exact x) := by ext ⟨i', j'⟩ dsimp only rw [sigmaUncurry_apply] obtain rfl | hi := eq_or_ne i i' · rw [single_eq_same] obtain rfl | hj := eq_or_ne j j' · rw [single_eq_same, single_eq_same] · rw [single_eq_of_ne hj, single_eq_of_ne] simpa using hj · rw [single_eq_of_ne hi, single_eq_of_ne, zero_apply] simp [hi] #align dfinsupp.sigma_uncurry_single DFinsupp.sigmaUncurry_single /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- The natural bijection between `Π₀ (i : Σ i, α i), δ i.1 i.2` and `Π₀ i (j : α i), δ i j`. This is the dfinsupp version of `Equiv.piCurry`. -/ def sigmaCurryEquiv [∀ i j, Zero (δ i j)] [∀ i, DecidableEq (α i)] [∀ i j (x : δ i j), Decidable (x ≠ 0)] : (Π₀ i : Σi, _, δ i.1 i.2) ≃ Π₀ (i) (j), δ i j where toFun := sigmaCurry invFun := sigmaUncurry left_inv f := by ext ⟨i, j⟩ rw [sigmaUncurry_apply, sigmaCurry_apply] right_inv f := by ext i j rw [sigmaCurry_apply, sigmaUncurry_apply] #align dfinsupp.sigma_curry_equiv DFinsupp.sigmaCurryEquiv end SigmaCurry variable {α : Option ι → Type v} /-- Adds a term to a dfinsupp, making a dfinsupp indexed by an `Option`. This is the dfinsupp version of `Option.rec`. -/ def extendWith [∀ i, Zero (α i)] (a : α none) (f : Π₀ i, α (some i)) : Π₀ i, α i where toFun := fun i ↦ match i with | none => a | some _ => f _ support' := f.support'.map fun s => ⟨none ::ₘ Multiset.map some s.1, fun i => Option.rec (Or.inl <| Multiset.mem_cons_self _ _) (fun i => (s.prop i).imp_left fun h => Multiset.mem_cons_of_mem <| Multiset.mem_map_of_mem _ h) i⟩ #align dfinsupp.extend_with DFinsupp.extendWith @[simp] theorem extendWith_none [∀ i, Zero (α i)] (f : Π₀ i, α (some i)) (a : α none) : f.extendWith a none = a := rfl #align dfinsupp.extend_with_none DFinsupp.extendWith_none @[simp] theorem extendWith_some [∀ i, Zero (α i)] (f : Π₀ i, α (some i)) (a : α none) (i : ι) : f.extendWith a (some i) = f i := rfl #align dfinsupp.extend_with_some DFinsupp.extendWith_some @[simp] theorem extendWith_single_zero [DecidableEq ι] [∀ i, Zero (α i)] (i : ι) (x : α (some i)) : (single i x).extendWith 0 = single (some i) x := by ext (_ | j) · rw [extendWith_none, single_eq_of_ne (Option.some_ne_none _)] · rw [extendWith_some] obtain rfl | hij := Decidable.eq_or_ne i j · rw [single_eq_same, single_eq_same] · rw [single_eq_of_ne hij, single_eq_of_ne ((Option.some_injective _).ne hij)] #align dfinsupp.extend_with_single_zero DFinsupp.extendWith_single_zero @[simp] theorem extendWith_zero [DecidableEq ι] [∀ i, Zero (α i)] (x : α none) : (0 : Π₀ i, α (some i)).extendWith x = single none x := by ext (_ | j) · rw [extendWith_none, single_eq_same] · rw [extendWith_some, single_eq_of_ne (Option.some_ne_none _).symm, zero_apply] #align dfinsupp.extend_with_zero DFinsupp.extendWith_zero /-- Bijection obtained by separating the term of index `none` of a dfinsupp over `Option ι`. This is the dfinsupp version of `Equiv.piOptionEquivProd`. -/ @[simps] noncomputable def equivProdDFinsupp [∀ i, Zero (α i)] : (Π₀ i, α i) ≃ α none × Π₀ i, α (some i) where toFun f := (f none, comapDomain some (Option.some_injective _) f) invFun f := f.2.extendWith f.1 left_inv f := by ext i; cases' i with i · rw [extendWith_none] · rw [extendWith_some, comapDomain_apply] right_inv x := by dsimp only ext · exact extendWith_none x.snd _ · rw [comapDomain_apply, extendWith_some] #align dfinsupp.equiv_prod_dfinsupp DFinsupp.equivProdDFinsupp #align dfinsupp.equiv_prod_dfinsupp_apply DFinsupp.equivProdDFinsupp_apply #align dfinsupp.equiv_prod_dfinsupp_symm_apply DFinsupp.equivProdDFinsupp_symm_apply theorem equivProdDFinsupp_add [∀ i, AddZeroClass (α i)] (f g : Π₀ i, α i) : equivProdDFinsupp (f + g) = equivProdDFinsupp f + equivProdDFinsupp g := Prod.ext (add_apply _ _ _) (comapDomain_add _ (Option.some_injective _) _ _) #align dfinsupp.equiv_prod_dfinsupp_add DFinsupp.equivProdDFinsupp_add theorem equivProdDFinsupp_smul [Monoid γ] [∀ i, AddMonoid (α i)] [∀ i, DistribMulAction γ (α i)] (r : γ) (f : Π₀ i, α i) : equivProdDFinsupp (r • f) = r • equivProdDFinsupp f := Prod.ext (smul_apply _ _ _) (comapDomain_smul _ (Option.some_injective _) _ _) #align dfinsupp.equiv_prod_dfinsupp_smul DFinsupp.equivProdDFinsupp_smul end Equiv section ProdAndSum /-- `DFinsupp.prod f g` is the product of `g i (f i)` over the support of `f`. -/ @[to_additive "`sum f g` is the sum of `g i (f i)` over the support of `f`."] def prod [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid γ] (f : Π₀ i, β i) (g : ∀ i, β i → γ) : γ := ∏ i ∈ f.support, g i (f i) #align dfinsupp.prod DFinsupp.prod #align dfinsupp.sum DFinsupp.sum @[to_additive (attr := simp)] theorem _root_.map_dfinsupp_prod {R S H : Type*} [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid R] [CommMonoid S] [FunLike H R S] [MonoidHomClass H R S] (h : H) (f : Π₀ i, β i) (g : ∀ i, β i → R) : h (f.prod g) = f.prod fun a b => h (g a b) := map_prod _ _ _ @[to_additive] theorem prod_mapRange_index {β₁ : ι → Type v₁} {β₂ : ι → Type v₂} [∀ i, Zero (β₁ i)] [∀ i, Zero (β₂ i)] [∀ (i) (x : β₁ i), Decidable (x ≠ 0)] [∀ (i) (x : β₂ i), Decidable (x ≠ 0)] [CommMonoid γ] {f : ∀ i, β₁ i → β₂ i} {hf : ∀ i, f i 0 = 0} {g : Π₀ i, β₁ i} {h : ∀ i, β₂ i → γ} (h0 : ∀ i, h i 0 = 1) : (mapRange f hf g).prod h = g.prod fun i b => h i (f i b) := by rw [mapRange_def] refine (Finset.prod_subset support_mk_subset ?_).trans ?_ · intro i h1 h2 simp only [mem_support_toFun, ne_eq] at h1 simp only [Finset.coe_sort_coe, mem_support_toFun, mk_apply, ne_eq, h1, not_false_iff, dite_eq_ite, ite_true, not_not] at h2 simp [h2, h0] · refine Finset.prod_congr rfl ?_ intro i h1 simp only [mem_support_toFun, ne_eq] at h1 simp [h1] #align dfinsupp.prod_map_range_index DFinsupp.prod_mapRange_index #align dfinsupp.sum_map_range_index DFinsupp.sum_mapRange_index @[to_additive] theorem prod_zero_index [∀ i, AddCommMonoid (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid γ] {h : ∀ i, β i → γ} : (0 : Π₀ i, β i).prod h = 1 := rfl #align dfinsupp.prod_zero_index DFinsupp.prod_zero_index #align dfinsupp.sum_zero_index DFinsupp.sum_zero_index @[to_additive] theorem prod_single_index [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid γ] {i : ι} {b : β i} {h : ∀ i, β i → γ} (h_zero : h i 0 = 1) : (single i b).prod h = h i b := by by_cases h : b ≠ 0 · simp [DFinsupp.prod, support_single_ne_zero h] · rw [not_not] at h simp [h, prod_zero_index, h_zero] rfl #align dfinsupp.prod_single_index DFinsupp.prod_single_index #align dfinsupp.sum_single_index DFinsupp.sum_single_index @[to_additive] theorem prod_neg_index [∀ i, AddGroup (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid γ] {g : Π₀ i, β i} {h : ∀ i, β i → γ} (h0 : ∀ i, h i 0 = 1) : (-g).prod h = g.prod fun i b => h i (-b) := prod_mapRange_index h0 #align dfinsupp.prod_neg_index DFinsupp.prod_neg_index #align dfinsupp.sum_neg_index DFinsupp.sum_neg_index @[to_additive] theorem prod_comm {ι₁ ι₂ : Sort _} {β₁ : ι₁ → Type*} {β₂ : ι₂ → Type*} [DecidableEq ι₁] [DecidableEq ι₂] [∀ i, Zero (β₁ i)] [∀ i, Zero (β₂ i)] [∀ (i) (x : β₁ i), Decidable (x ≠ 0)] [∀ (i) (x : β₂ i), Decidable (x ≠ 0)] [CommMonoid γ] (f₁ : Π₀ i, β₁ i) (f₂ : Π₀ i, β₂ i) (h : ∀ i, β₁ i → ∀ i, β₂ i → γ) : (f₁.prod fun i₁ x₁ => f₂.prod fun i₂ x₂ => h i₁ x₁ i₂ x₂) = f₂.prod fun i₂ x₂ => f₁.prod fun i₁ x₁ => h i₁ x₁ i₂ x₂ := Finset.prod_comm #align dfinsupp.prod_comm DFinsupp.prod_comm #align dfinsupp.sum_comm DFinsupp.sum_comm @[simp] theorem sum_apply {ι₁ : Type u₁} [DecidableEq ι₁] {β₁ : ι₁ → Type v₁} [∀ i₁, Zero (β₁ i₁)] [∀ (i) (x : β₁ i), Decidable (x ≠ 0)] [∀ i, AddCommMonoid (β i)] {f : Π₀ i₁, β₁ i₁} {g : ∀ i₁, β₁ i₁ → Π₀ i, β i} {i₂ : ι} : (f.sum g) i₂ = f.sum fun i₁ b => g i₁ b i₂ := map_sum (evalAddMonoidHom i₂) _ f.support #align dfinsupp.sum_apply DFinsupp.sum_apply theorem support_sum {ι₁ : Type u₁} [DecidableEq ι₁] {β₁ : ι₁ → Type v₁} [∀ i₁, Zero (β₁ i₁)] [∀ (i) (x : β₁ i), Decidable (x ≠ 0)] [∀ i, AddCommMonoid (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] {f : Π₀ i₁, β₁ i₁} {g : ∀ i₁, β₁ i₁ → Π₀ i, β i} : (f.sum g).support ⊆ f.support.biUnion fun i => (g i (f i)).support := by have : ∀ i₁ : ι, (f.sum fun (i : ι₁) (b : β₁ i) => (g i b) i₁) ≠ 0 → ∃ i : ι₁, f i ≠ 0 ∧ ¬(g i (f i)) i₁ = 0 := fun i₁ h => let ⟨i, hi, Ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h ⟨i, mem_support_iff.1 hi, Ne⟩ simpa [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply] using this #align dfinsupp.support_sum DFinsupp.support_sum @[to_additive (attr := simp)] theorem prod_one [∀ i, AddCommMonoid (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid γ] {f : Π₀ i, β i} : (f.prod fun _ _ => (1 : γ)) = 1 := Finset.prod_const_one #align dfinsupp.prod_one DFinsupp.prod_one #align dfinsupp.sum_zero DFinsupp.sum_zero @[to_additive (attr := simp)] theorem prod_mul [∀ i, AddCommMonoid (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid γ] {f : Π₀ i, β i} {h₁ h₂ : ∀ i, β i → γ} : (f.prod fun i b => h₁ i b * h₂ i b) = f.prod h₁ * f.prod h₂ := Finset.prod_mul_distrib #align dfinsupp.prod_mul DFinsupp.prod_mul #align dfinsupp.sum_add DFinsupp.sum_add @[to_additive (attr := simp)] theorem prod_inv [∀ i, AddCommMonoid (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommGroup γ] {f : Π₀ i, β i} {h : ∀ i, β i → γ} : (f.prod fun i b => (h i b)⁻¹) = (f.prod h)⁻¹ := (map_prod (invMonoidHom : γ →* γ) _ f.support).symm #align dfinsupp.prod_inv DFinsupp.prod_inv #align dfinsupp.sum_neg DFinsupp.sum_neg @[to_additive] theorem prod_eq_one [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid γ] {f : Π₀ i, β i} {h : ∀ i, β i → γ} (hyp : ∀ i, h i (f i) = 1) : f.prod h = 1 := Finset.prod_eq_one fun i _ => hyp i #align dfinsupp.prod_eq_one DFinsupp.prod_eq_one #align dfinsupp.sum_eq_zero DFinsupp.sum_eq_zero theorem smul_sum {α : Type*} [Monoid α] [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [AddCommMonoid γ] [DistribMulAction α γ] {f : Π₀ i, β i} {h : ∀ i, β i → γ} {c : α} : c • f.sum h = f.sum fun a b => c • h a b := Finset.smul_sum #align dfinsupp.smul_sum DFinsupp.smul_sum @[to_additive] theorem prod_add_index [∀ i, AddCommMonoid (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid γ] {f g : Π₀ i, β i} {h : ∀ i, β i → γ} (h_zero : ∀ i, h i 0 = 1) (h_add : ∀ i b₁ b₂, h i (b₁ + b₂) = h i b₁ * h i b₂) : (f + g).prod h = f.prod h * g.prod h := have f_eq : (∏ i ∈ f.support ∪ g.support, h i (f i)) = f.prod h := (Finset.prod_subset Finset.subset_union_left <| by simp (config := { contextual := true }) [mem_support_iff, h_zero]).symm have g_eq : (∏ i ∈ f.support ∪ g.support, h i (g i)) = g.prod h := (Finset.prod_subset Finset.subset_union_right <| by simp (config := { contextual := true }) [mem_support_iff, h_zero]).symm calc (∏ i ∈ (f + g).support, h i ((f + g) i)) = ∏ i ∈ f.support ∪ g.support, h i ((f + g) i) := Finset.prod_subset support_add <| by simp (config := { contextual := true }) [mem_support_iff, h_zero] _ = (∏ i ∈ f.support ∪ g.support, h i (f i)) * ∏ i ∈ f.support ∪ g.support, h i (g i) := by { simp [h_add, Finset.prod_mul_distrib] } _ = _ := by rw [f_eq, g_eq] #align dfinsupp.prod_add_index DFinsupp.prod_add_index #align dfinsupp.sum_add_index DFinsupp.sum_add_index @[to_additive] theorem _root_.dfinsupp_prod_mem [∀ i, Zero (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [CommMonoid γ] {S : Type*} [SetLike S γ] [SubmonoidClass S γ] (s : S) (f : Π₀ i, β i) (g : ∀ i, β i → γ) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s := prod_mem fun _ hi => h _ <| mem_support_iff.1 hi #align dfinsupp_prod_mem dfinsupp_prod_mem #align dfinsupp_sum_mem dfinsupp_sum_mem @[to_additive (attr := simp)] theorem prod_eq_prod_fintype [Fintype ι] [∀ i, Zero (β i)] [∀ (i : ι) (x : β i), Decidable (x ≠ 0)] -- Porting note: `f` was a typeclass argument [CommMonoid γ] (v : Π₀ i, β i) {f : ∀ i, β i → γ} (hf : ∀ i, f i 0 = 1) : v.prod f = ∏ i, f i (DFinsupp.equivFunOnFintype v i) := by suffices (∏ i ∈ v.support, f i (v i)) = ∏ i, f i (v i) by simp [DFinsupp.prod, this] apply Finset.prod_subset v.support.subset_univ intro i _ hi rw [mem_support_iff, not_not] at hi rw [hi, hf] #align dfinsupp.prod_eq_prod_fintype DFinsupp.prod_eq_prod_fintype #align dfinsupp.sum_eq_sum_fintype DFinsupp.sum_eq_sum_fintype section CommMonoidWithZero variable [Π i, Zero (β i)] [CommMonoidWithZero γ] [Nontrivial γ] [NoZeroDivisors γ] [Π i, DecidableEq (β i)] {f : Π₀ i, β i} {g : Π i, β i → γ} @[simp] lemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff lemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff end CommMonoidWithZero /-- When summing over an `AddMonoidHom`, the decidability assumption is not needed, and the result is also an `AddMonoidHom`. -/ def sumAddHom [∀ i, AddZeroClass (β i)] [AddCommMonoid γ] (φ : ∀ i, β i →+ γ) : (Π₀ i, β i) →+ γ where toFun f := (f.support'.lift fun s => ∑ i ∈ Multiset.toFinset s.1, φ i (f i)) <| by rintro ⟨sx, hx⟩ ⟨sy, hy⟩ dsimp only [Subtype.coe_mk, toFun_eq_coe] at * have H1 : sx.toFinset ∩ sy.toFinset ⊆ sx.toFinset := Finset.inter_subset_left have H2 : sx.toFinset ∩ sy.toFinset ⊆ sy.toFinset := Finset.inter_subset_right refine (Finset.sum_subset H1 ?_).symm.trans ((Finset.sum_congr rfl ?_).trans (Finset.sum_subset H2 ?_)) · intro i H1 H2 rw [Finset.mem_inter] at H2 simp only [Multiset.mem_toFinset] at H1 H2 convert AddMonoidHom.map_zero (φ i) exact (hy i).resolve_left (mt (And.intro H1) H2) · intro i _ rfl · intro i H1 H2 rw [Finset.mem_inter] at H2 simp only [Multiset.mem_toFinset] at H1 H2 convert AddMonoidHom.map_zero (φ i) exact (hx i).resolve_left (mt (fun H3 => And.intro H3 H1) H2) map_add' := by rintro ⟨f, sf, hf⟩ ⟨g, sg, hg⟩ change (∑ i ∈ _, _) = (∑ i ∈ _, _) + ∑ i ∈ _, _ simp only [coe_add, coe_mk', Subtype.coe_mk, Pi.add_apply, map_add, Finset.sum_add_distrib] congr 1 · refine (Finset.sum_subset ?_ ?_).symm · intro i simp only [Multiset.mem_toFinset, Multiset.mem_add] exact Or.inl · intro i _ H2 simp only [Multiset.mem_toFinset, Multiset.mem_add] at H2 rw [(hf i).resolve_left H2, AddMonoidHom.map_zero] · refine (Finset.sum_subset ?_ ?_).symm · intro i simp only [Multiset.mem_toFinset, Multiset.mem_add] exact Or.inr · intro i _ H2 simp only [Multiset.mem_toFinset, Multiset.mem_add] at H2 rw [(hg i).resolve_left H2, AddMonoidHom.map_zero] map_zero' := by simp only [toFun_eq_coe, coe_zero, Pi.zero_apply, map_zero, Finset.sum_const_zero]; rfl #align dfinsupp.sum_add_hom DFinsupp.sumAddHom @[simp] theorem sumAddHom_single [∀ i, AddZeroClass (β i)] [AddCommMonoid γ] (φ : ∀ i, β i →+ γ) (i) (x : β i) : sumAddHom φ (single i x) = φ i x := by dsimp [sumAddHom, single, Trunc.lift_mk] rw [Multiset.toFinset_singleton, Finset.sum_singleton, Pi.single_eq_same] #align dfinsupp.sum_add_hom_single DFinsupp.sumAddHom_single @[simp] theorem sumAddHom_comp_single [∀ i, AddZeroClass (β i)] [AddCommMonoid γ] (f : ∀ i, β i →+ γ) (i : ι) : (sumAddHom f).comp (singleAddHom β i) = f i := AddMonoidHom.ext fun x => sumAddHom_single f i x #align dfinsupp.sum_add_hom_comp_single DFinsupp.sumAddHom_comp_single /-- While we didn't need decidable instances to define it, we do to reduce it to a sum -/ theorem sumAddHom_apply [∀ i, AddZeroClass (β i)] [∀ (i) (x : β i), Decidable (x ≠ 0)] [AddCommMonoid γ] (φ : ∀ i, β i →+ γ) (f : Π₀ i, β i) : sumAddHom φ f = f.sum fun x => φ x := by rcases f with ⟨f, s, hf⟩ change (∑ i ∈ _, _) = ∑ i ∈ Finset.filter _ _, _ rw [Finset.sum_filter, Finset.sum_congr rfl] intro i _ dsimp only [coe_mk', Subtype.coe_mk] at * split_ifs with h · rfl · rw [not_not.mp h, AddMonoidHom.map_zero] #align dfinsupp.sum_add_hom_apply DFinsupp.sumAddHom_apply theorem _root_.dfinsupp_sumAddHom_mem [∀ i, AddZeroClass (β i)] [AddCommMonoid γ] {S : Type*} [SetLike S γ] [AddSubmonoidClass S γ] (s : S) (f : Π₀ i, β i) (g : ∀ i, β i →+ γ) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : DFinsupp.sumAddHom g f ∈ s := by classical rw [DFinsupp.sumAddHom_apply] exact dfinsupp_sum_mem s f (g ·) h #align dfinsupp_sum_add_hom_mem dfinsupp_sumAddHom_mem /-- The supremum of a family of commutative additive submonoids is equal to the range of `DFinsupp.sumAddHom`; that is, every element in the `iSup` can be produced from taking a finite number of non-zero elements of `S i`, coercing them to `γ`, and summing them. -/ theorem _root_.AddSubmonoid.iSup_eq_mrange_dfinsupp_sumAddHom [AddCommMonoid γ] (S : ι → AddSubmonoid γ) : iSup S = AddMonoidHom.mrange (DFinsupp.sumAddHom fun i => (S i).subtype) := by apply le_antisymm · apply iSup_le _ intro i y hy exact ⟨DFinsupp.single i ⟨y, hy⟩, DFinsupp.sumAddHom_single _ _ _⟩ · rintro x ⟨v, rfl⟩ exact dfinsupp_sumAddHom_mem _ v _ fun i _ => (le_iSup S i : S i ≤ _) (v i).prop #align add_submonoid.supr_eq_mrange_dfinsupp_sum_add_hom AddSubmonoid.iSup_eq_mrange_dfinsupp_sumAddHom /-- The bounded supremum of a family of commutative additive submonoids is equal to the range of `DFinsupp.sumAddHom` composed with `DFinsupp.filterAddMonoidHom`; that is, every element in the bounded `iSup` can be produced from taking a finite number of non-zero elements from the `S i` that satisfy `p i`, coercing them to `γ`, and summing them. -/ theorem _root_.AddSubmonoid.bsupr_eq_mrange_dfinsupp_sumAddHom (p : ι → Prop) [DecidablePred p] [AddCommMonoid γ] (S : ι → AddSubmonoid γ) : ⨆ (i) (_ : p i), S i = AddMonoidHom.mrange ((sumAddHom fun i => (S i).subtype).comp (filterAddMonoidHom _ p)) := by apply le_antisymm · refine iSup₂_le fun i hi y hy => ⟨DFinsupp.single i ⟨y, hy⟩, ?_⟩ rw [AddMonoidHom.comp_apply, filterAddMonoidHom_apply, filter_single_pos _ _ hi] exact sumAddHom_single _ _ _ · rintro x ⟨v, rfl⟩ refine dfinsupp_sumAddHom_mem _ _ _ fun i _ => ?_ refine AddSubmonoid.mem_iSup_of_mem i ?_ by_cases hp : p i · simp [hp] · simp [hp] #align add_submonoid.bsupr_eq_mrange_dfinsupp_sum_add_hom AddSubmonoid.bsupr_eq_mrange_dfinsupp_sumAddHom theorem _root_.AddSubmonoid.mem_iSup_iff_exists_dfinsupp [AddCommMonoid γ] (S : ι → AddSubmonoid γ) (x : γ) : x ∈ iSup S ↔ ∃ f : Π₀ i, S i, DFinsupp.sumAddHom (fun i => (S i).subtype) f = x := SetLike.ext_iff.mp (AddSubmonoid.iSup_eq_mrange_dfinsupp_sumAddHom S) x #align add_submonoid.mem_supr_iff_exists_dfinsupp AddSubmonoid.mem_iSup_iff_exists_dfinsupp /-- A variant of `AddSubmonoid.mem_iSup_iff_exists_dfinsupp` with the RHS fully unfolded. -/ theorem _root_.AddSubmonoid.mem_iSup_iff_exists_dfinsupp' [AddCommMonoid γ] (S : ι → AddSubmonoid γ) [∀ (i) (x : S i), Decidable (x ≠ 0)] (x : γ) : x ∈ iSup S ↔ ∃ f : Π₀ i, S i, (f.sum fun i xi => ↑xi) = x := by rw [AddSubmonoid.mem_iSup_iff_exists_dfinsupp] simp_rw [sumAddHom_apply] rfl #align add_submonoid.mem_supr_iff_exists_dfinsupp' AddSubmonoid.mem_iSup_iff_exists_dfinsupp' theorem _root_.AddSubmonoid.mem_bsupr_iff_exists_dfinsupp (p : ι → Prop) [DecidablePred p] [AddCommMonoid γ] (S : ι → AddSubmonoid γ) (x : γ) : (x ∈ ⨆ (i) (_ : p i), S i) ↔ ∃ f : Π₀ i, S i, DFinsupp.sumAddHom (fun i => (S i).subtype) (f.filter p) = x := SetLike.ext_iff.mp (AddSubmonoid.bsupr_eq_mrange_dfinsupp_sumAddHom p S) x #align add_submonoid.mem_bsupr_iff_exists_dfinsupp AddSubmonoid.mem_bsupr_iff_exists_dfinsupp theorem sumAddHom_comm {ι₁ ι₂ : Sort _} {β₁ : ι₁ → Type*} {β₂ : ι₂ → Type*} {γ : Type*} [DecidableEq ι₁] [DecidableEq ι₂] [∀ i, AddZeroClass (β₁ i)] [∀ i, AddZeroClass (β₂ i)] [AddCommMonoid γ] (f₁ : Π₀ i, β₁ i) (f₂ : Π₀ i, β₂ i) (h : ∀ i j, β₁ i →+ β₂ j →+ γ) : sumAddHom (fun i₂ => sumAddHom (fun i₁ => h i₁ i₂) f₁) f₂ = sumAddHom (fun i₁ => sumAddHom (fun i₂ => (h i₁ i₂).flip) f₂) f₁ := by obtain ⟨⟨f₁, s₁, h₁⟩, ⟨f₂, s₂, h₂⟩⟩ := f₁, f₂ simp only [sumAddHom, AddMonoidHom.finset_sum_apply, Quotient.liftOn_mk, AddMonoidHom.coe_mk, AddMonoidHom.flip_apply, Trunc.lift, toFun_eq_coe, ZeroHom.coe_mk, coe_mk'] exact Finset.sum_comm #align dfinsupp.sum_add_hom_comm DFinsupp.sumAddHom_comm /-- The `DFinsupp` version of `Finsupp.liftAddHom`,-/ @[simps apply symm_apply] def liftAddHom [∀ i, AddZeroClass (β i)] [AddCommMonoid γ] : (∀ i, β i →+ γ) ≃+ ((Π₀ i, β i) →+ γ) where toFun := sumAddHom invFun F i := F.comp (singleAddHom β i) left_inv x := by ext; simp right_inv ψ := by ext; simp map_add' F G := by ext; simp #align dfinsupp.lift_add_hom DFinsupp.liftAddHom #align dfinsupp.lift_add_hom_apply DFinsupp.liftAddHom_apply #align dfinsupp.lift_add_hom_symm_apply DFinsupp.liftAddHom_symm_apply -- Porting note: The elaborator is struggling with `liftAddHom`. Passing it `β` explicitly helps. -- This applies to roughly the remainder of the file. /-- The `DFinsupp` version of `Finsupp.liftAddHom_singleAddHom`,-/ @[simp, nolint simpNF] -- Porting note: linter claims that simp can prove this, but it can not theorem liftAddHom_singleAddHom [∀ i, AddCommMonoid (β i)] : liftAddHom (β := β) (singleAddHom β) = AddMonoidHom.id (Π₀ i, β i) := (liftAddHom (β := β)).toEquiv.apply_eq_iff_eq_symm_apply.2 rfl #align dfinsupp.lift_add_hom_single_add_hom DFinsupp.liftAddHom_singleAddHom /-- The `DFinsupp` version of `Finsupp.liftAddHom_apply_single`,-/ theorem liftAddHom_apply_single [∀ i, AddZeroClass (β i)] [AddCommMonoid γ] (f : ∀ i, β i →+ γ) (i : ι) (x : β i) : liftAddHom (β := β) f (single i x) = f i x := by simp #align dfinsupp.lift_add_hom_apply_single DFinsupp.liftAddHom_apply_single /-- The `DFinsupp` version of `Finsupp.liftAddHom_comp_single`,-/
Mathlib/Data/DFinsupp/Basic.lean
2,047
2,048
theorem liftAddHom_comp_single [∀ i, AddZeroClass (β i)] [AddCommMonoid γ] (f : ∀ i, β i →+ γ) (i : ι) : (liftAddHom (β := β) f).comp (singleAddHom β i) = f i := by
simp
/- Copyright (c) 2023 Paul Reichert. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul Reichert, Yaël Dillies -/ import Mathlib.Analysis.NormedSpace.AddTorsorBases #align_import analysis.convex.intrinsic from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Intrinsic frontier and interior This file defines the intrinsic frontier, interior and closure of a set in a normed additive torsor. These are also known as relative frontier, interior, closure. The intrinsic frontier/interior/closure of a set `s` is the frontier/interior/closure of `s` considered as a set in its affine span. The intrinsic interior is in general greater than the topological interior, the intrinsic frontier in general less than the topological frontier, and the intrinsic closure in cases of interest the same as the topological closure. ## Definitions * `intrinsicInterior`: Intrinsic interior * `intrinsicFrontier`: Intrinsic frontier * `intrinsicClosure`: Intrinsic closure ## Results The main results are: * `AffineIsometry.image_intrinsicInterior`/`AffineIsometry.image_intrinsicFrontier`/ `AffineIsometry.image_intrinsicClosure`: Intrinsic interiors/frontiers/closures commute with taking the image under an affine isometry. * `Set.Nonempty.intrinsicInterior`: The intrinsic interior of a nonempty convex set is nonempty. ## References * Chapter 8 of [Barry Simon, *Convexity*][simon2011] * Chapter 1 of [Rolf Schneider, *Convex Bodies: The Brunn-Minkowski theory*][schneider2013]. ## TODO * `IsClosed s → IsExtreme 𝕜 s (intrinsicFrontier 𝕜 s)` * `x ∈ s → y ∈ intrinsicInterior 𝕜 s → openSegment 𝕜 x y ⊆ intrinsicInterior 𝕜 s` -/ open AffineSubspace Set open scoped Pointwise variable {𝕜 V W Q P : Type*} section AddTorsor variable (𝕜) [Ring 𝕜] [AddCommGroup V] [Module 𝕜 V] [TopologicalSpace P] [AddTorsor V P] {s t : Set P} {x : P} /-- The intrinsic interior of a set is its interior considered as a set in its affine span. -/ def intrinsicInterior (s : Set P) : Set P := (↑) '' interior ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) #align intrinsic_interior intrinsicInterior /-- The intrinsic frontier of a set is its frontier considered as a set in its affine span. -/ def intrinsicFrontier (s : Set P) : Set P := (↑) '' frontier ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) #align intrinsic_frontier intrinsicFrontier /-- The intrinsic closure of a set is its closure considered as a set in its affine span. -/ def intrinsicClosure (s : Set P) : Set P := (↑) '' closure ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) #align intrinsic_closure intrinsicClosure variable {𝕜} @[simp] theorem mem_intrinsicInterior : x ∈ intrinsicInterior 𝕜 s ↔ ∃ y, y ∈ interior ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) ∧ ↑y = x := mem_image _ _ _ #align mem_intrinsic_interior mem_intrinsicInterior @[simp] theorem mem_intrinsicFrontier : x ∈ intrinsicFrontier 𝕜 s ↔ ∃ y, y ∈ frontier ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) ∧ ↑y = x := mem_image _ _ _ #align mem_intrinsic_frontier mem_intrinsicFrontier @[simp] theorem mem_intrinsicClosure : x ∈ intrinsicClosure 𝕜 s ↔ ∃ y, y ∈ closure ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) ∧ ↑y = x := mem_image _ _ _ #align mem_intrinsic_closure mem_intrinsicClosure theorem intrinsicInterior_subset : intrinsicInterior 𝕜 s ⊆ s := image_subset_iff.2 interior_subset #align intrinsic_interior_subset intrinsicInterior_subset theorem intrinsicFrontier_subset (hs : IsClosed s) : intrinsicFrontier 𝕜 s ⊆ s := image_subset_iff.2 (hs.preimage continuous_induced_dom).frontier_subset #align intrinsic_frontier_subset intrinsicFrontier_subset theorem intrinsicFrontier_subset_intrinsicClosure : intrinsicFrontier 𝕜 s ⊆ intrinsicClosure 𝕜 s := image_subset _ frontier_subset_closure #align intrinsic_frontier_subset_intrinsic_closure intrinsicFrontier_subset_intrinsicClosure theorem subset_intrinsicClosure : s ⊆ intrinsicClosure 𝕜 s := fun x hx => ⟨⟨x, subset_affineSpan _ _ hx⟩, subset_closure hx, rfl⟩ #align subset_intrinsic_closure subset_intrinsicClosure @[simp] theorem intrinsicInterior_empty : intrinsicInterior 𝕜 (∅ : Set P) = ∅ := by simp [intrinsicInterior] #align intrinsic_interior_empty intrinsicInterior_empty @[simp] theorem intrinsicFrontier_empty : intrinsicFrontier 𝕜 (∅ : Set P) = ∅ := by simp [intrinsicFrontier] #align intrinsic_frontier_empty intrinsicFrontier_empty @[simp] theorem intrinsicClosure_empty : intrinsicClosure 𝕜 (∅ : Set P) = ∅ := by simp [intrinsicClosure] #align intrinsic_closure_empty intrinsicClosure_empty @[simp] theorem intrinsicClosure_nonempty : (intrinsicClosure 𝕜 s).Nonempty ↔ s.Nonempty := ⟨by simp_rw [nonempty_iff_ne_empty]; rintro h rfl; exact h intrinsicClosure_empty, Nonempty.mono subset_intrinsicClosure⟩ #align intrinsic_closure_nonempty intrinsicClosure_nonempty alias ⟨Set.Nonempty.ofIntrinsicClosure, Set.Nonempty.intrinsicClosure⟩ := intrinsicClosure_nonempty #align set.nonempty.of_intrinsic_closure Set.Nonempty.ofIntrinsicClosure #align set.nonempty.intrinsic_closure Set.Nonempty.intrinsicClosure --attribute [protected] Set.Nonempty.intrinsicClosure -- Porting note: removed @[simp] theorem intrinsicInterior_singleton (x : P) : intrinsicInterior 𝕜 ({x} : Set P) = {x} := by simpa only [intrinsicInterior, preimage_coe_affineSpan_singleton, interior_univ, image_univ, Subtype.range_coe] using coe_affineSpan_singleton _ _ _ #align intrinsic_interior_singleton intrinsicInterior_singleton @[simp]
Mathlib/Analysis/Convex/Intrinsic.lean
142
143
theorem intrinsicFrontier_singleton (x : P) : intrinsicFrontier 𝕜 ({x} : Set P) = ∅ := by
rw [intrinsicFrontier, preimage_coe_affineSpan_singleton, frontier_univ, image_empty]
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies -/ import Mathlib.Order.BooleanAlgebra import Mathlib.Logic.Equiv.Basic #align_import order.symm_diff from "leanprover-community/mathlib"@"6eb334bd8f3433d5b08ba156b8ec3e6af47e1904" /-! # Symmetric difference and bi-implication This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras. ## Examples Some examples are * The symmetric difference of two sets is the set of elements that are in either but not both. * The symmetric difference on propositions is `Xor'`. * The symmetric difference on `Bool` is `Bool.xor`. * The equivalence of propositions. Two propositions are equivalent if they imply each other. * The symmetric difference translates to addition when considering a Boolean algebra as a Boolean ring. ## Main declarations * `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)` * `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)` In generalized Boolean algebras, the symmetric difference operator is: * `symmDiff_comm`: commutative, and * `symmDiff_assoc`: associative. ## Notations * `a ∆ b`: `symmDiff a b` * `a ⇔ b`: `bihimp a b` ## References The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A Proof from the Book" by John McCuan: * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> ## Tags boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication, Heyting -/ open Function OrderDual variable {ι α β : Type*} {π : ι → Type*} /-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/ def symmDiff [Sup α] [SDiff α] (a b : α) : α := a \ b ⊔ b \ a #align symm_diff symmDiff /-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of propositions. -/ def bihimp [Inf α] [HImp α] (a b : α) : α := (b ⇨ a) ⊓ (a ⇨ b) #align bihimp bihimp /-- Notation for symmDiff -/ scoped[symmDiff] infixl:100 " ∆ " => symmDiff /-- Notation for bihimp -/ scoped[symmDiff] infixl:100 " ⇔ " => bihimp open scoped symmDiff theorem symmDiff_def [Sup α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a := rfl #align symm_diff_def symmDiff_def theorem bihimp_def [Inf α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) := rfl #align bihimp_def bihimp_def theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q := rfl #align symm_diff_eq_xor symmDiff_eq_Xor' @[simp] theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) := (iff_iff_implies_and_implies _ _).symm.trans Iff.comm #align bihimp_iff_iff bihimp_iff_iff @[simp] theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide #align bool.symm_diff_eq_bxor Bool.symmDiff_eq_xor section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] (a b c d : α) @[simp] theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b := rfl #align to_dual_symm_diff toDual_symmDiff @[simp] theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b := rfl #align of_dual_bihimp ofDual_bihimp theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm] #align symm_diff_comm symmDiff_comm instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) := ⟨symmDiff_comm⟩ #align symm_diff_is_comm symmDiff_isCommutative @[simp] theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self] #align symm_diff_self symmDiff_self @[simp] theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq] #align symm_diff_bot symmDiff_bot @[simp] theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot] #align bot_symm_diff bot_symmDiff @[simp] theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff] #align symm_diff_eq_bot symmDiff_eq_bot theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq] #align symm_diff_of_le symmDiff_of_le theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq] #align symm_diff_of_ge symmDiff_of_ge theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c := sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb #align symm_diff_le symmDiff_le theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by simp_rw [symmDiff, sup_le_iff, sdiff_le_iff] #align symm_diff_le_iff symmDiff_le_iff @[simp] theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b := sup_le_sup sdiff_le sdiff_le #align symm_diff_le_sup symmDiff_le_sup theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff] #align symm_diff_eq_sup_sdiff_inf symmDiff_eq_sup_sdiff_inf theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right] #align disjoint.symm_diff_eq_sup Disjoint.symmDiff_eq_sup theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left] #align symm_diff_sdiff symmDiff_sdiff @[simp] theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by rw [symmDiff_sdiff] simp [symmDiff] #align symm_diff_sdiff_inf symmDiff_sdiff_inf @[simp] theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by rw [symmDiff, sdiff_idem] exact le_antisymm (sup_le_sup sdiff_le sdiff_le) (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup) #align symm_diff_sdiff_eq_sup symmDiff_sdiff_eq_sup @[simp] theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm] #align sdiff_symm_diff_eq_sup sdiff_symmDiff_eq_sup @[simp] theorem symmDiff_sup_inf : a ∆ b ⊔ a ⊓ b = a ⊔ b := by refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_ rw [sup_inf_left, symmDiff] refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right) · rw [sup_right_comm] exact le_sup_of_le_left le_sdiff_sup · rw [sup_assoc] exact le_sup_of_le_right le_sdiff_sup #align symm_diff_sup_inf symmDiff_sup_inf @[simp] theorem inf_sup_symmDiff : a ⊓ b ⊔ a ∆ b = a ⊔ b := by rw [sup_comm, symmDiff_sup_inf] #align inf_sup_symm_diff inf_sup_symmDiff @[simp] theorem symmDiff_symmDiff_inf : a ∆ b ∆ (a ⊓ b) = a ⊔ b := by rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf] #align symm_diff_symm_diff_inf symmDiff_symmDiff_inf @[simp] theorem inf_symmDiff_symmDiff : (a ⊓ b) ∆ (a ∆ b) = a ⊔ b := by rw [symmDiff_comm, symmDiff_symmDiff_inf] #align inf_symm_diff_symm_diff inf_symmDiff_symmDiff theorem symmDiff_triangle : a ∆ c ≤ a ∆ b ⊔ b ∆ c := by refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_ rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff] #align symm_diff_triangle symmDiff_triangle theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot] theorem le_symmDiff_sup_left (a b : α) : b ≤ (a ∆ b) ⊔ a := symmDiff_comm a b ▸ le_symmDiff_sup_right .. end GeneralizedCoheytingAlgebra section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] (a b c d : α) @[simp] theorem toDual_bihimp : toDual (a ⇔ b) = toDual a ∆ toDual b := rfl #align to_dual_bihimp toDual_bihimp @[simp] theorem ofDual_symmDiff (a b : αᵒᵈ) : ofDual (a ∆ b) = ofDual a ⇔ ofDual b := rfl #align of_dual_symm_diff ofDual_symmDiff theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(· ⇔ ·), inf_comm] #align bihimp_comm bihimp_comm instance bihimp_isCommutative : Std.Commutative (α := α) (· ⇔ ·) := ⟨bihimp_comm⟩ #align bihimp_is_comm bihimp_isCommutative @[simp] theorem bihimp_self : a ⇔ a = ⊤ := by rw [bihimp, inf_idem, himp_self] #align bihimp_self bihimp_self @[simp] theorem bihimp_top : a ⇔ ⊤ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq] #align bihimp_top bihimp_top @[simp] theorem top_bihimp : ⊤ ⇔ a = a := by rw [bihimp_comm, bihimp_top] #align top_bihimp top_bihimp @[simp] theorem bihimp_eq_top {a b : α} : a ⇔ b = ⊤ ↔ a = b := @symmDiff_eq_bot αᵒᵈ _ _ _ #align bihimp_eq_top bihimp_eq_top theorem bihimp_of_le {a b : α} (h : a ≤ b) : a ⇔ b = b ⇨ a := by rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq] #align bihimp_of_le bihimp_of_le theorem bihimp_of_ge {a b : α} (h : b ≤ a) : a ⇔ b = a ⇨ b := by rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq] #align bihimp_of_ge bihimp_of_ge theorem le_bihimp {a b c : α} (hb : a ⊓ b ≤ c) (hc : a ⊓ c ≤ b) : a ≤ b ⇔ c := le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb #align le_bihimp le_bihimp theorem le_bihimp_iff {a b c : α} : a ≤ b ⇔ c ↔ a ⊓ b ≤ c ∧ a ⊓ c ≤ b := by simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm] #align le_bihimp_iff le_bihimp_iff @[simp] theorem inf_le_bihimp {a b : α} : a ⊓ b ≤ a ⇔ b := inf_le_inf le_himp le_himp #align inf_le_bihimp inf_le_bihimp theorem bihimp_eq_inf_himp_inf : a ⇔ b = a ⊔ b ⇨ a ⊓ b := by simp [himp_inf_distrib, bihimp] #align bihimp_eq_inf_himp_inf bihimp_eq_inf_himp_inf theorem Codisjoint.bihimp_eq_inf {a b : α} (h : Codisjoint a b) : a ⇔ b = a ⊓ b := by rw [bihimp, h.himp_eq_left, h.himp_eq_right] #align codisjoint.bihimp_eq_inf Codisjoint.bihimp_eq_inf theorem himp_bihimp : a ⇨ b ⇔ c = (a ⊓ c ⇨ b) ⊓ (a ⊓ b ⇨ c) := by rw [bihimp, himp_inf_distrib, himp_himp, himp_himp] #align himp_bihimp himp_bihimp @[simp] theorem sup_himp_bihimp : a ⊔ b ⇨ a ⇔ b = a ⇔ b := by rw [himp_bihimp] simp [bihimp] #align sup_himp_bihimp sup_himp_bihimp @[simp] theorem bihimp_himp_eq_inf : a ⇔ (a ⇨ b) = a ⊓ b := @symmDiff_sdiff_eq_sup αᵒᵈ _ _ _ #align bihimp_himp_eq_inf bihimp_himp_eq_inf @[simp] theorem himp_bihimp_eq_inf : (b ⇨ a) ⇔ b = a ⊓ b := @sdiff_symmDiff_eq_sup αᵒᵈ _ _ _ #align himp_bihimp_eq_inf himp_bihimp_eq_inf @[simp] theorem bihimp_inf_sup : a ⇔ b ⊓ (a ⊔ b) = a ⊓ b := @symmDiff_sup_inf αᵒᵈ _ _ _ #align bihimp_inf_sup bihimp_inf_sup @[simp] theorem sup_inf_bihimp : (a ⊔ b) ⊓ a ⇔ b = a ⊓ b := @inf_sup_symmDiff αᵒᵈ _ _ _ #align sup_inf_bihimp sup_inf_bihimp @[simp] theorem bihimp_bihimp_sup : a ⇔ b ⇔ (a ⊔ b) = a ⊓ b := @symmDiff_symmDiff_inf αᵒᵈ _ _ _ #align bihimp_bihimp_sup bihimp_bihimp_sup @[simp] theorem sup_bihimp_bihimp : (a ⊔ b) ⇔ (a ⇔ b) = a ⊓ b := @inf_symmDiff_symmDiff αᵒᵈ _ _ _ #align sup_bihimp_bihimp sup_bihimp_bihimp theorem bihimp_triangle : a ⇔ b ⊓ b ⇔ c ≤ a ⇔ c := @symmDiff_triangle αᵒᵈ _ _ _ _ #align bihimp_triangle bihimp_triangle end GeneralizedHeytingAlgebra section CoheytingAlgebra variable [CoheytingAlgebra α] (a : α) @[simp] theorem symmDiff_top' : a ∆ ⊤ = ¬a := by simp [symmDiff] #align symm_diff_top' symmDiff_top' @[simp] theorem top_symmDiff' : ⊤ ∆ a = ¬a := by simp [symmDiff] #align top_symm_diff' top_symmDiff' @[simp] theorem hnot_symmDiff_self : (¬a) ∆ a = ⊤ := by rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self] exact Codisjoint.top_le codisjoint_hnot_left #align hnot_symm_diff_self hnot_symmDiff_self @[simp] theorem symmDiff_hnot_self : a ∆ (¬a) = ⊤ := by rw [symmDiff_comm, hnot_symmDiff_self] #align symm_diff_hnot_self symmDiff_hnot_self theorem IsCompl.symmDiff_eq_top {a b : α} (h : IsCompl a b) : a ∆ b = ⊤ := by rw [h.eq_hnot, hnot_symmDiff_self] #align is_compl.symm_diff_eq_top IsCompl.symmDiff_eq_top end CoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra α] (a : α) @[simp] theorem bihimp_bot : a ⇔ ⊥ = aᶜ := by simp [bihimp] #align bihimp_bot bihimp_bot @[simp] theorem bot_bihimp : ⊥ ⇔ a = aᶜ := by simp [bihimp] #align bot_bihimp bot_bihimp @[simp] theorem compl_bihimp_self : aᶜ ⇔ a = ⊥ := @hnot_symmDiff_self αᵒᵈ _ _ #align compl_bihimp_self compl_bihimp_self @[simp] theorem bihimp_hnot_self : a ⇔ aᶜ = ⊥ := @symmDiff_hnot_self αᵒᵈ _ _ #align bihimp_hnot_self bihimp_hnot_self theorem IsCompl.bihimp_eq_bot {a b : α} (h : IsCompl a b) : a ⇔ b = ⊥ := by rw [h.eq_compl, compl_bihimp_self] #align is_compl.bihimp_eq_bot IsCompl.bihimp_eq_bot end HeytingAlgebra section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] (a b c d : α) @[simp] theorem sup_sdiff_symmDiff : (a ⊔ b) \ a ∆ b = a ⊓ b := sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf]) #align sup_sdiff_symm_diff sup_sdiff_symmDiff theorem disjoint_symmDiff_inf : Disjoint (a ∆ b) (a ⊓ b) := by rw [symmDiff_eq_sup_sdiff_inf] exact disjoint_sdiff_self_left #align disjoint_symm_diff_inf disjoint_symmDiff_inf theorem inf_symmDiff_distrib_left : a ⊓ b ∆ c = (a ⊓ b) ∆ (a ⊓ c) := by rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left, symmDiff_eq_sup_sdiff_inf] #align inf_symm_diff_distrib_left inf_symmDiff_distrib_left theorem inf_symmDiff_distrib_right : a ∆ b ⊓ c = (a ⊓ c) ∆ (b ⊓ c) := by simp_rw [inf_comm _ c, inf_symmDiff_distrib_left] #align inf_symm_diff_distrib_right inf_symmDiff_distrib_right theorem sdiff_symmDiff : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ a ⊓ c \ b := by simp only [(· ∆ ·), sdiff_sdiff_sup_sdiff'] #align sdiff_symm_diff sdiff_symmDiff theorem sdiff_symmDiff' : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ (a ⊔ b) := by rw [sdiff_symmDiff, sdiff_sup] #align sdiff_symm_diff' sdiff_symmDiff' @[simp] theorem symmDiff_sdiff_left : a ∆ b \ a = b \ a := by rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq] #align symm_diff_sdiff_left symmDiff_sdiff_left @[simp] theorem symmDiff_sdiff_right : a ∆ b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left] #align symm_diff_sdiff_right symmDiff_sdiff_right @[simp]
Mathlib/Order/SymmDiff.lean
435
435
theorem sdiff_symmDiff_left : a \ a ∆ b = a ⊓ b := by
simp [sdiff_symmDiff]
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov, Hunter Monroe -/ import Mathlib.Combinatorics.SimpleGraph.Init import Mathlib.Data.Rel import Mathlib.Data.Set.Finite import Mathlib.Data.Sym.Sym2 #align_import combinatorics.simple_graph.basic from "leanprover-community/mathlib"@"3365b20c2ffa7c35e47e5209b89ba9abdddf3ffe" /-! # Simple graphs This module defines simple graphs on a vertex type `V` as an irreflexive symmetric relation. ## Main definitions * `SimpleGraph` is a structure for symmetric, irreflexive relations * `SimpleGraph.neighborSet` is the `Set` of vertices adjacent to a given vertex * `SimpleGraph.commonNeighbors` is the intersection of the neighbor sets of two given vertices * `SimpleGraph.incidenceSet` is the `Set` of edges containing a given vertex * `CompleteAtomicBooleanAlgebra` instance: Under the subgraph relation, `SimpleGraph` forms a `CompleteAtomicBooleanAlgebra`. In other words, this is the complete lattice of spanning subgraphs of the complete graph. ## Todo * This is the simplest notion of an unoriented graph. This should eventually fit into a more complete combinatorics hierarchy which includes multigraphs and directed graphs. We begin with simple graphs in order to start learning what the combinatorics hierarchy should look like. -/ -- Porting note: using `aesop` for automation -- Porting note: These attributes are needed to use `aesop` as a replacement for `obviously` attribute [aesop norm unfold (rule_sets := [SimpleGraph])] Symmetric attribute [aesop norm unfold (rule_sets := [SimpleGraph])] Irreflexive -- Porting note: a thin wrapper around `aesop` for graph lemmas, modelled on `aesop_cat` /-- A variant of the `aesop` tactic for use in the graph library. Changes relative to standard `aesop`: - We use the `SimpleGraph` rule set in addition to the default rule sets. - We instruct Aesop's `intro` rule to unfold with `default` transparency. - We instruct Aesop to fail if it can't fully solve the goal. This allows us to use `aesop_graph` for auto-params. -/ macro (name := aesop_graph) "aesop_graph" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { introsTransparency? := some .default, terminal := true }) (rule_sets := [$(Lean.mkIdent `SimpleGraph):ident])) /-- Use `aesop_graph?` to pass along a `Try this` suggestion when using `aesop_graph` -/ macro (name := aesop_graph?) "aesop_graph?" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { introsTransparency? := some .default, terminal := true }) (rule_sets := [$(Lean.mkIdent `SimpleGraph):ident])) /-- A variant of `aesop_graph` which does not fail if it is unable to solve the goal. Use this only for exploration! Nonterminal Aesop is even worse than nonterminal `simp`. -/ macro (name := aesop_graph_nonterminal) "aesop_graph_nonterminal" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { introsTransparency? := some .default, warnOnNonterminal := false }) (rule_sets := [$(Lean.mkIdent `SimpleGraph):ident])) open Finset Function universe u v w /-- A simple graph is an irreflexive symmetric relation `Adj` on a vertex type `V`. The relation describes which pairs of vertices are adjacent. There is exactly one edge for every pair of adjacent vertices; see `SimpleGraph.edgeSet` for the corresponding edge set. -/ @[ext, aesop safe constructors (rule_sets := [SimpleGraph])] structure SimpleGraph (V : Type u) where /-- The adjacency relation of a simple graph. -/ Adj : V → V → Prop symm : Symmetric Adj := by aesop_graph loopless : Irreflexive Adj := by aesop_graph #align simple_graph SimpleGraph -- Porting note: changed `obviously` to `aesop` in the `structure` initialize_simps_projections SimpleGraph (Adj → adj) /-- Constructor for simple graphs using a symmetric irreflexive boolean function. -/ @[simps] def SimpleGraph.mk' {V : Type u} : {adj : V → V → Bool // (∀ x y, adj x y = adj y x) ∧ (∀ x, ¬ adj x x)} ↪ SimpleGraph V where toFun x := ⟨fun v w ↦ x.1 v w, fun v w ↦ by simp [x.2.1], fun v ↦ by simp [x.2.2]⟩ inj' := by rintro ⟨adj, _⟩ ⟨adj', _⟩ simp only [mk.injEq, Subtype.mk.injEq] intro h funext v w simpa [Bool.coe_iff_coe] using congr_fun₂ h v w /-- We can enumerate simple graphs by enumerating all functions `V → V → Bool` and filtering on whether they are symmetric and irreflexive. -/ instance {V : Type u} [Fintype V] [DecidableEq V] : Fintype (SimpleGraph V) where elems := Finset.univ.map SimpleGraph.mk' complete := by classical rintro ⟨Adj, hs, hi⟩ simp only [mem_map, mem_univ, true_and, Subtype.exists, Bool.not_eq_true] refine ⟨fun v w ↦ Adj v w, ⟨?_, ?_⟩, ?_⟩ · simp [hs.iff] · intro v; simp [hi v] · ext simp /-- Construct the simple graph induced by the given relation. It symmetrizes the relation and makes it irreflexive. -/ def SimpleGraph.fromRel {V : Type u} (r : V → V → Prop) : SimpleGraph V where Adj a b := a ≠ b ∧ (r a b ∨ r b a) symm := fun _ _ ⟨hn, hr⟩ => ⟨hn.symm, hr.symm⟩ loopless := fun _ ⟨hn, _⟩ => hn rfl #align simple_graph.from_rel SimpleGraph.fromRel @[simp] theorem SimpleGraph.fromRel_adj {V : Type u} (r : V → V → Prop) (v w : V) : (SimpleGraph.fromRel r).Adj v w ↔ v ≠ w ∧ (r v w ∨ r w v) := Iff.rfl #align simple_graph.from_rel_adj SimpleGraph.fromRel_adj -- Porting note: attributes needed for `completeGraph` attribute [aesop safe (rule_sets := [SimpleGraph])] Ne.symm attribute [aesop safe (rule_sets := [SimpleGraph])] Ne.irrefl /-- The complete graph on a type `V` is the simple graph with all pairs of distinct vertices adjacent. In `Mathlib`, this is usually referred to as `⊤`. -/ def completeGraph (V : Type u) : SimpleGraph V where Adj := Ne #align complete_graph completeGraph /-- The graph with no edges on a given vertex type `V`. `Mathlib` prefers the notation `⊥`. -/ def emptyGraph (V : Type u) : SimpleGraph V where Adj _ _ := False #align empty_graph emptyGraph /-- Two vertices are adjacent in the complete bipartite graph on two vertex types if and only if they are not from the same side. Any bipartite graph may be regarded as a subgraph of one of these. -/ @[simps] def completeBipartiteGraph (V W : Type*) : SimpleGraph (Sum V W) where Adj v w := v.isLeft ∧ w.isRight ∨ v.isRight ∧ w.isLeft symm v w := by cases v <;> cases w <;> simp loopless v := by cases v <;> simp #align complete_bipartite_graph completeBipartiteGraph namespace SimpleGraph variable {ι : Sort*} {V : Type u} (G : SimpleGraph V) {a b c u v w : V} {e : Sym2 V} @[simp] protected theorem irrefl {v : V} : ¬G.Adj v v := G.loopless v #align simple_graph.irrefl SimpleGraph.irrefl theorem adj_comm (u v : V) : G.Adj u v ↔ G.Adj v u := ⟨fun x => G.symm x, fun x => G.symm x⟩ #align simple_graph.adj_comm SimpleGraph.adj_comm @[symm] theorem adj_symm (h : G.Adj u v) : G.Adj v u := G.symm h #align simple_graph.adj_symm SimpleGraph.adj_symm theorem Adj.symm {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Adj v u := G.symm h #align simple_graph.adj.symm SimpleGraph.Adj.symm theorem ne_of_adj (h : G.Adj a b) : a ≠ b := by rintro rfl exact G.irrefl h #align simple_graph.ne_of_adj SimpleGraph.ne_of_adj protected theorem Adj.ne {G : SimpleGraph V} {a b : V} (h : G.Adj a b) : a ≠ b := G.ne_of_adj h #align simple_graph.adj.ne SimpleGraph.Adj.ne protected theorem Adj.ne' {G : SimpleGraph V} {a b : V} (h : G.Adj a b) : b ≠ a := h.ne.symm #align simple_graph.adj.ne' SimpleGraph.Adj.ne' theorem ne_of_adj_of_not_adj {v w x : V} (h : G.Adj v x) (hn : ¬G.Adj w x) : v ≠ w := fun h' => hn (h' ▸ h) #align simple_graph.ne_of_adj_of_not_adj SimpleGraph.ne_of_adj_of_not_adj theorem adj_injective : Injective (Adj : SimpleGraph V → V → V → Prop) := SimpleGraph.ext #align simple_graph.adj_injective SimpleGraph.adj_injective @[simp] theorem adj_inj {G H : SimpleGraph V} : G.Adj = H.Adj ↔ G = H := adj_injective.eq_iff #align simple_graph.adj_inj SimpleGraph.adj_inj section Order /-- The relation that one `SimpleGraph` is a subgraph of another. Note that this should be spelled `≤`. -/ def IsSubgraph (x y : SimpleGraph V) : Prop := ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w #align simple_graph.is_subgraph SimpleGraph.IsSubgraph instance : LE (SimpleGraph V) := ⟨IsSubgraph⟩ @[simp] theorem isSubgraph_eq_le : (IsSubgraph : SimpleGraph V → SimpleGraph V → Prop) = (· ≤ ·) := rfl #align simple_graph.is_subgraph_eq_le SimpleGraph.isSubgraph_eq_le /-- The supremum of two graphs `x ⊔ y` has edges where either `x` or `y` have edges. -/ instance : Sup (SimpleGraph V) where sup x y := { Adj := x.Adj ⊔ y.Adj symm := fun v w h => by rwa [Pi.sup_apply, Pi.sup_apply, x.adj_comm, y.adj_comm] } @[simp] theorem sup_adj (x y : SimpleGraph V) (v w : V) : (x ⊔ y).Adj v w ↔ x.Adj v w ∨ y.Adj v w := Iff.rfl #align simple_graph.sup_adj SimpleGraph.sup_adj /-- The infimum of two graphs `x ⊓ y` has edges where both `x` and `y` have edges. -/ instance : Inf (SimpleGraph V) where inf x y := { Adj := x.Adj ⊓ y.Adj symm := fun v w h => by rwa [Pi.inf_apply, Pi.inf_apply, x.adj_comm, y.adj_comm] } @[simp] theorem inf_adj (x y : SimpleGraph V) (v w : V) : (x ⊓ y).Adj v w ↔ x.Adj v w ∧ y.Adj v w := Iff.rfl #align simple_graph.inf_adj SimpleGraph.inf_adj /-- We define `Gᶜ` to be the `SimpleGraph V` such that no two adjacent vertices in `G` are adjacent in the complement, and every nonadjacent pair of vertices is adjacent (still ensuring that vertices are not adjacent to themselves). -/ instance hasCompl : HasCompl (SimpleGraph V) where compl G := { Adj := fun v w => v ≠ w ∧ ¬G.Adj v w symm := fun v w ⟨hne, _⟩ => ⟨hne.symm, by rwa [adj_comm]⟩ loopless := fun v ⟨hne, _⟩ => (hne rfl).elim } @[simp] theorem compl_adj (G : SimpleGraph V) (v w : V) : Gᶜ.Adj v w ↔ v ≠ w ∧ ¬G.Adj v w := Iff.rfl #align simple_graph.compl_adj SimpleGraph.compl_adj /-- The difference of two graphs `x \ y` has the edges of `x` with the edges of `y` removed. -/ instance sdiff : SDiff (SimpleGraph V) where sdiff x y := { Adj := x.Adj \ y.Adj symm := fun v w h => by change x.Adj w v ∧ ¬y.Adj w v; rwa [x.adj_comm, y.adj_comm] } @[simp] theorem sdiff_adj (x y : SimpleGraph V) (v w : V) : (x \ y).Adj v w ↔ x.Adj v w ∧ ¬y.Adj v w := Iff.rfl #align simple_graph.sdiff_adj SimpleGraph.sdiff_adj instance supSet : SupSet (SimpleGraph V) where sSup s := { Adj := fun a b => ∃ G ∈ s, Adj G a b symm := fun a b => Exists.imp fun _ => And.imp_right Adj.symm loopless := by rintro a ⟨G, _, ha⟩ exact ha.ne rfl } instance infSet : InfSet (SimpleGraph V) where sInf s := { Adj := fun a b => (∀ ⦃G⦄, G ∈ s → Adj G a b) ∧ a ≠ b symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) Ne.symm loopless := fun _ h => h.2 rfl } @[simp] theorem sSup_adj {s : Set (SimpleGraph V)} {a b : V} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b := Iff.rfl #align simple_graph.Sup_adj SimpleGraph.sSup_adj @[simp] theorem sInf_adj {s : Set (SimpleGraph V)} : (sInf s).Adj a b ↔ (∀ G ∈ s, Adj G a b) ∧ a ≠ b := Iff.rfl #align simple_graph.Inf_adj SimpleGraph.sInf_adj @[simp] theorem iSup_adj {f : ι → SimpleGraph V} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by simp [iSup] #align simple_graph.supr_adj SimpleGraph.iSup_adj @[simp] theorem iInf_adj {f : ι → SimpleGraph V} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ a ≠ b := by simp [iInf] #align simple_graph.infi_adj SimpleGraph.iInf_adj theorem sInf_adj_of_nonempty {s : Set (SimpleGraph V)} (hs : s.Nonempty) : (sInf s).Adj a b ↔ ∀ G ∈ s, Adj G a b := sInf_adj.trans <| and_iff_left_of_imp <| by obtain ⟨G, hG⟩ := hs exact fun h => (h _ hG).ne #align simple_graph.Inf_adj_of_nonempty SimpleGraph.sInf_adj_of_nonempty theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → SimpleGraph V} : (⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _), Set.forall_mem_range] #align simple_graph.infi_adj_of_nonempty SimpleGraph.iInf_adj_of_nonempty /-- For graphs `G`, `H`, `G ≤ H` iff `∀ a b, G.Adj a b → H.Adj a b`. -/ instance distribLattice : DistribLattice (SimpleGraph V) := { show DistribLattice (SimpleGraph V) from adj_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl with le := fun G H => ∀ ⦃a b⦄, G.Adj a b → H.Adj a b } instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (SimpleGraph V) := { SimpleGraph.distribLattice with le := (· ≤ ·) sup := (· ⊔ ·) inf := (· ⊓ ·) compl := HasCompl.compl sdiff := (· \ ·) top := completeGraph V bot := emptyGraph V le_top := fun x v w h => x.ne_of_adj h bot_le := fun x v w h => h.elim sdiff_eq := fun x y => by ext v w refine ⟨fun h => ⟨h.1, ⟨?_, h.2⟩⟩, fun h => ⟨h.1, h.2.2⟩⟩ rintro rfl exact x.irrefl h.1 inf_compl_le_bot := fun G v w h => False.elim <| h.2.2 h.1 top_le_sup_compl := fun G v w hvw => by by_cases h : G.Adj v w · exact Or.inl h · exact Or.inr ⟨hvw, h⟩ sSup := sSup le_sSup := fun s G hG a b hab => ⟨G, hG, hab⟩ sSup_le := fun s G hG a b => by rintro ⟨H, hH, hab⟩ exact hG _ hH hab sInf := sInf sInf_le := fun s G hG a b hab => hab.1 hG le_sInf := fun s G hG a b hab => ⟨fun H hH => hG _ hH hab, hab.ne⟩ iInf_iSup_eq := fun f => by ext; simp [Classical.skolem] } @[simp] theorem top_adj (v w : V) : (⊤ : SimpleGraph V).Adj v w ↔ v ≠ w := Iff.rfl #align simple_graph.top_adj SimpleGraph.top_adj @[simp] theorem bot_adj (v w : V) : (⊥ : SimpleGraph V).Adj v w ↔ False := Iff.rfl #align simple_graph.bot_adj SimpleGraph.bot_adj @[simp] theorem completeGraph_eq_top (V : Type u) : completeGraph V = ⊤ := rfl #align simple_graph.complete_graph_eq_top SimpleGraph.completeGraph_eq_top @[simp] theorem emptyGraph_eq_bot (V : Type u) : emptyGraph V = ⊥ := rfl #align simple_graph.empty_graph_eq_bot SimpleGraph.emptyGraph_eq_bot @[simps] instance (V : Type u) : Inhabited (SimpleGraph V) := ⟨⊥⟩ instance [Subsingleton V] : Unique (SimpleGraph V) where default := ⊥ uniq G := by ext a b; have := Subsingleton.elim a b; simp [this] instance [Nontrivial V] : Nontrivial (SimpleGraph V) := ⟨⟨⊥, ⊤, fun h ↦ not_subsingleton V ⟨by simpa only [← adj_inj, Function.funext_iff, bot_adj, top_adj, ne_eq, eq_iff_iff, false_iff, not_not] using h⟩⟩⟩ section Decidable variable (V) (H : SimpleGraph V) [DecidableRel G.Adj] [DecidableRel H.Adj] instance Bot.adjDecidable : DecidableRel (⊥ : SimpleGraph V).Adj := inferInstanceAs <| DecidableRel fun _ _ => False #align simple_graph.bot.adj_decidable SimpleGraph.Bot.adjDecidable instance Sup.adjDecidable : DecidableRel (G ⊔ H).Adj := inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∨ H.Adj v w #align simple_graph.sup.adj_decidable SimpleGraph.Sup.adjDecidable instance Inf.adjDecidable : DecidableRel (G ⊓ H).Adj := inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∧ H.Adj v w #align simple_graph.inf.adj_decidable SimpleGraph.Inf.adjDecidable instance Sdiff.adjDecidable : DecidableRel (G \ H).Adj := inferInstanceAs <| DecidableRel fun v w => G.Adj v w ∧ ¬H.Adj v w #align simple_graph.sdiff.adj_decidable SimpleGraph.Sdiff.adjDecidable variable [DecidableEq V] instance Top.adjDecidable : DecidableRel (⊤ : SimpleGraph V).Adj := inferInstanceAs <| DecidableRel fun v w => v ≠ w #align simple_graph.top.adj_decidable SimpleGraph.Top.adjDecidable instance Compl.adjDecidable : DecidableRel (Gᶜ.Adj) := inferInstanceAs <| DecidableRel fun v w => v ≠ w ∧ ¬G.Adj v w #align simple_graph.compl.adj_decidable SimpleGraph.Compl.adjDecidable end Decidable end Order /-- `G.support` is the set of vertices that form edges in `G`. -/ def support : Set V := Rel.dom G.Adj #align simple_graph.support SimpleGraph.support theorem mem_support {v : V} : v ∈ G.support ↔ ∃ w, G.Adj v w := Iff.rfl #align simple_graph.mem_support SimpleGraph.mem_support theorem support_mono {G G' : SimpleGraph V} (h : G ≤ G') : G.support ⊆ G'.support := Rel.dom_mono h #align simple_graph.support_mono SimpleGraph.support_mono /-- `G.neighborSet v` is the set of vertices adjacent to `v` in `G`. -/ def neighborSet (v : V) : Set V := {w | G.Adj v w} #align simple_graph.neighbor_set SimpleGraph.neighborSet instance neighborSet.memDecidable (v : V) [DecidableRel G.Adj] : DecidablePred (· ∈ G.neighborSet v) := inferInstanceAs <| DecidablePred (Adj G v) #align simple_graph.neighbor_set.mem_decidable SimpleGraph.neighborSet.memDecidable section EdgeSet variable {G₁ G₂ : SimpleGraph V} /-- The edges of G consist of the unordered pairs of vertices related by `G.Adj`. This is the order embedding; for the edge set of a particular graph, see `SimpleGraph.edgeSet`. The way `edgeSet` is defined is such that `mem_edgeSet` is proved by `Iff.rfl`. (That is, `s(v, w) ∈ G.edgeSet` is definitionally equal to `G.Adj v w`.) -/ -- Porting note: We need a separate definition so that dot notation works. def edgeSetEmbedding (V : Type*) : SimpleGraph V ↪o Set (Sym2 V) := OrderEmbedding.ofMapLEIff (fun G => Sym2.fromRel G.symm) fun _ _ => ⟨fun h a b => @h s(a, b), fun h e => Sym2.ind @h e⟩ /-- `G.edgeSet` is the edge set for `G`. This is an abbreviation for `edgeSetEmbedding G` that permits dot notation. -/ abbrev edgeSet (G : SimpleGraph V) : Set (Sym2 V) := edgeSetEmbedding V G #align simple_graph.edge_set SimpleGraph.edgeSetEmbedding @[simp] theorem mem_edgeSet : s(v, w) ∈ G.edgeSet ↔ G.Adj v w := Iff.rfl #align simple_graph.mem_edge_set SimpleGraph.mem_edgeSet theorem not_isDiag_of_mem_edgeSet : e ∈ edgeSet G → ¬e.IsDiag := Sym2.ind (fun _ _ => Adj.ne) e #align simple_graph.not_is_diag_of_mem_edge_set SimpleGraph.not_isDiag_of_mem_edgeSet theorem edgeSet_inj : G₁.edgeSet = G₂.edgeSet ↔ G₁ = G₂ := (edgeSetEmbedding V).eq_iff_eq #align simple_graph.edge_set_inj SimpleGraph.edgeSet_inj @[simp] theorem edgeSet_subset_edgeSet : edgeSet G₁ ⊆ edgeSet G₂ ↔ G₁ ≤ G₂ := (edgeSetEmbedding V).le_iff_le #align simple_graph.edge_set_subset_edge_set SimpleGraph.edgeSet_subset_edgeSet @[simp] theorem edgeSet_ssubset_edgeSet : edgeSet G₁ ⊂ edgeSet G₂ ↔ G₁ < G₂ := (edgeSetEmbedding V).lt_iff_lt #align simple_graph.edge_set_ssubset_edge_set SimpleGraph.edgeSet_ssubset_edgeSet theorem edgeSet_injective : Injective (edgeSet : SimpleGraph V → Set (Sym2 V)) := (edgeSetEmbedding V).injective #align simple_graph.edge_set_injective SimpleGraph.edgeSet_injective alias ⟨_, edgeSet_mono⟩ := edgeSet_subset_edgeSet #align simple_graph.edge_set_mono SimpleGraph.edgeSet_mono alias ⟨_, edgeSet_strict_mono⟩ := edgeSet_ssubset_edgeSet #align simple_graph.edge_set_strict_mono SimpleGraph.edgeSet_strict_mono attribute [mono] edgeSet_mono edgeSet_strict_mono variable (G₁ G₂) @[simp] theorem edgeSet_bot : (⊥ : SimpleGraph V).edgeSet = ∅ := Sym2.fromRel_bot #align simple_graph.edge_set_bot SimpleGraph.edgeSet_bot @[simp] theorem edgeSet_top : (⊤ : SimpleGraph V).edgeSet = {e | ¬e.IsDiag} := Sym2.fromRel_ne @[simp] theorem edgeSet_subset_setOf_not_isDiag : G.edgeSet ⊆ {e | ¬e.IsDiag} := fun _ h => (Sym2.fromRel_irreflexive (sym := G.symm)).mp G.loopless h @[simp] theorem edgeSet_sup : (G₁ ⊔ G₂).edgeSet = G₁.edgeSet ∪ G₂.edgeSet := by ext ⟨x, y⟩ rfl #align simple_graph.edge_set_sup SimpleGraph.edgeSet_sup @[simp] theorem edgeSet_inf : (G₁ ⊓ G₂).edgeSet = G₁.edgeSet ∩ G₂.edgeSet := by ext ⟨x, y⟩ rfl #align simple_graph.edge_set_inf SimpleGraph.edgeSet_inf @[simp] theorem edgeSet_sdiff : (G₁ \ G₂).edgeSet = G₁.edgeSet \ G₂.edgeSet := by ext ⟨x, y⟩ rfl #align simple_graph.edge_set_sdiff SimpleGraph.edgeSet_sdiff variable {G G₁ G₂} @[simp] lemma disjoint_edgeSet : Disjoint G₁.edgeSet G₂.edgeSet ↔ Disjoint G₁ G₂ := by rw [Set.disjoint_iff, disjoint_iff_inf_le, ← edgeSet_inf, ← edgeSet_bot, ← Set.le_iff_subset, OrderEmbedding.le_iff_le] #align simple_graph.disjoint_edge_set SimpleGraph.disjoint_edgeSet @[simp] lemma edgeSet_eq_empty : G.edgeSet = ∅ ↔ G = ⊥ := by rw [← edgeSet_bot, edgeSet_inj] #align simple_graph.edge_set_eq_empty SimpleGraph.edgeSet_eq_empty @[simp] lemma edgeSet_nonempty : G.edgeSet.Nonempty ↔ G ≠ ⊥ := by rw [Set.nonempty_iff_ne_empty, edgeSet_eq_empty.ne] #align simple_graph.edge_set_nonempty SimpleGraph.edgeSet_nonempty /-- This lemma, combined with `edgeSet_sdiff` and `edgeSet_from_edgeSet`, allows proving `(G \ from_edgeSet s).edge_set = G.edgeSet \ s` by `simp`. -/ @[simp] theorem edgeSet_sdiff_sdiff_isDiag (G : SimpleGraph V) (s : Set (Sym2 V)) : G.edgeSet \ (s \ { e | e.IsDiag }) = G.edgeSet \ s := by ext e simp only [Set.mem_diff, Set.mem_setOf_eq, not_and, not_not, and_congr_right_iff] intro h simp only [G.not_isDiag_of_mem_edgeSet h, imp_false] #align simple_graph.edge_set_sdiff_sdiff_is_diag SimpleGraph.edgeSet_sdiff_sdiff_isDiag /-- Two vertices are adjacent iff there is an edge between them. The condition `v ≠ w` ensures they are different endpoints of the edge, which is necessary since when `v = w` the existential `∃ (e ∈ G.edgeSet), v ∈ e ∧ w ∈ e` is satisfied by every edge incident to `v`. -/ theorem adj_iff_exists_edge {v w : V} : G.Adj v w ↔ v ≠ w ∧ ∃ e ∈ G.edgeSet, v ∈ e ∧ w ∈ e := by refine ⟨fun _ => ⟨G.ne_of_adj ‹_›, s(v, w), by simpa⟩, ?_⟩ rintro ⟨hne, e, he, hv⟩ rw [Sym2.mem_and_mem_iff hne] at hv subst e rwa [mem_edgeSet] at he #align simple_graph.adj_iff_exists_edge SimpleGraph.adj_iff_exists_edge theorem adj_iff_exists_edge_coe : G.Adj a b ↔ ∃ e : G.edgeSet, e.val = s(a, b) := by simp only [mem_edgeSet, exists_prop, SetCoe.exists, exists_eq_right, Subtype.coe_mk] #align simple_graph.adj_iff_exists_edge_coe SimpleGraph.adj_iff_exists_edge_coe variable (G G₁ G₂) theorem edge_other_ne {e : Sym2 V} (he : e ∈ G.edgeSet) {v : V} (h : v ∈ e) : Sym2.Mem.other h ≠ v := by erw [← Sym2.other_spec h, Sym2.eq_swap] at he exact G.ne_of_adj he #align simple_graph.edge_other_ne SimpleGraph.edge_other_ne instance decidableMemEdgeSet [DecidableRel G.Adj] : DecidablePred (· ∈ G.edgeSet) := Sym2.fromRel.decidablePred G.symm #align simple_graph.decidable_mem_edge_set SimpleGraph.decidableMemEdgeSet instance fintypeEdgeSet [Fintype (Sym2 V)] [DecidableRel G.Adj] : Fintype G.edgeSet := Subtype.fintype _ #align simple_graph.fintype_edge_set SimpleGraph.fintypeEdgeSet instance fintypeEdgeSetBot : Fintype (⊥ : SimpleGraph V).edgeSet := by rw [edgeSet_bot] infer_instance #align simple_graph.fintype_edge_set_bot SimpleGraph.fintypeEdgeSetBot instance fintypeEdgeSetSup [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] : Fintype (G₁ ⊔ G₂).edgeSet := by rw [edgeSet_sup] infer_instance #align simple_graph.fintype_edge_set_sup SimpleGraph.fintypeEdgeSetSup instance fintypeEdgeSetInf [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] : Fintype (G₁ ⊓ G₂).edgeSet := by rw [edgeSet_inf] exact Set.fintypeInter _ _ #align simple_graph.fintype_edge_set_inf SimpleGraph.fintypeEdgeSetInf instance fintypeEdgeSetSdiff [DecidableEq V] [Fintype G₁.edgeSet] [Fintype G₂.edgeSet] : Fintype (G₁ \ G₂).edgeSet := by rw [edgeSet_sdiff] exact Set.fintypeDiff _ _ #align simple_graph.fintype_edge_set_sdiff SimpleGraph.fintypeEdgeSetSdiff end EdgeSet section FromEdgeSet variable (s : Set (Sym2 V)) /-- `fromEdgeSet` constructs a `SimpleGraph` from a set of edges, without loops. -/ def fromEdgeSet : SimpleGraph V where Adj := Sym2.ToRel s ⊓ Ne symm v w h := ⟨Sym2.toRel_symmetric s h.1, h.2.symm⟩ #align simple_graph.from_edge_set SimpleGraph.fromEdgeSet @[simp] theorem fromEdgeSet_adj : (fromEdgeSet s).Adj v w ↔ s(v, w) ∈ s ∧ v ≠ w := Iff.rfl #align simple_graph.from_edge_set_adj SimpleGraph.fromEdgeSet_adj -- Note: we need to make sure `fromEdgeSet_adj` and this lemma are confluent. -- In particular, both yield `s(u, v) ∈ (fromEdgeSet s).edgeSet` ==> `s(v, w) ∈ s ∧ v ≠ w`. @[simp] theorem edgeSet_fromEdgeSet : (fromEdgeSet s).edgeSet = s \ { e | e.IsDiag } := by ext e exact Sym2.ind (by simp) e #align simple_graph.edge_set_from_edge_set SimpleGraph.edgeSet_fromEdgeSet @[simp] theorem fromEdgeSet_edgeSet : fromEdgeSet G.edgeSet = G := by ext v w exact ⟨fun h => h.1, fun h => ⟨h, G.ne_of_adj h⟩⟩ #align simple_graph.from_edge_set_edge_set SimpleGraph.fromEdgeSet_edgeSet @[simp] theorem fromEdgeSet_empty : fromEdgeSet (∅ : Set (Sym2 V)) = ⊥ := by ext v w simp only [fromEdgeSet_adj, Set.mem_empty_iff_false, false_and_iff, bot_adj] #align simple_graph.from_edge_set_empty SimpleGraph.fromEdgeSet_empty @[simp] theorem fromEdgeSet_univ : fromEdgeSet (Set.univ : Set (Sym2 V)) = ⊤ := by ext v w simp only [fromEdgeSet_adj, Set.mem_univ, true_and_iff, top_adj] #align simple_graph.from_edge_set_univ SimpleGraph.fromEdgeSet_univ @[simp] theorem fromEdgeSet_inter (s t : Set (Sym2 V)) : fromEdgeSet (s ∩ t) = fromEdgeSet s ⊓ fromEdgeSet t := by ext v w simp only [fromEdgeSet_adj, Set.mem_inter_iff, Ne, inf_adj] tauto #align simple_graph.from_edge_set_inf SimpleGraph.fromEdgeSet_inter @[simp] theorem fromEdgeSet_union (s t : Set (Sym2 V)) : fromEdgeSet (s ∪ t) = fromEdgeSet s ⊔ fromEdgeSet t := by ext v w simp [Set.mem_union, or_and_right] #align simple_graph.from_edge_set_sup SimpleGraph.fromEdgeSet_union @[simp] theorem fromEdgeSet_sdiff (s t : Set (Sym2 V)) : fromEdgeSet (s \ t) = fromEdgeSet s \ fromEdgeSet t := by ext v w constructor <;> simp (config := { contextual := true }) #align simple_graph.from_edge_set_sdiff SimpleGraph.fromEdgeSet_sdiff @[mono] theorem fromEdgeSet_mono {s t : Set (Sym2 V)} (h : s ⊆ t) : fromEdgeSet s ≤ fromEdgeSet t := by rintro v w simp (config := { contextual := true }) only [fromEdgeSet_adj, Ne, not_false_iff, and_true_iff, and_imp] exact fun vws _ => h vws #align simple_graph.from_edge_set_mono SimpleGraph.fromEdgeSet_mono @[simp] lemma disjoint_fromEdgeSet : Disjoint G (fromEdgeSet s) ↔ Disjoint G.edgeSet s := by conv_rhs => rw [← Set.diff_union_inter s {e : Sym2 V | e.IsDiag}] rw [← disjoint_edgeSet, edgeSet_fromEdgeSet, Set.disjoint_union_right, and_iff_left] exact Set.disjoint_left.2 fun e he he' ↦ not_isDiag_of_mem_edgeSet _ he he'.2 #align simple_graph.disjoint_from_edge_set SimpleGraph.disjoint_fromEdgeSet @[simp] lemma fromEdgeSet_disjoint : Disjoint (fromEdgeSet s) G ↔ Disjoint s G.edgeSet := by rw [disjoint_comm, disjoint_fromEdgeSet, disjoint_comm] #align simple_graph.from_edge_set_disjoint SimpleGraph.fromEdgeSet_disjoint instance [DecidableEq V] [Fintype s] : Fintype (fromEdgeSet s).edgeSet := by rw [edgeSet_fromEdgeSet s] infer_instance end FromEdgeSet /-! ### Incidence set -/ /-- Set of edges incident to a given vertex, aka incidence set. -/ def incidenceSet (v : V) : Set (Sym2 V) := { e ∈ G.edgeSet | v ∈ e } #align simple_graph.incidence_set SimpleGraph.incidenceSet theorem incidenceSet_subset (v : V) : G.incidenceSet v ⊆ G.edgeSet := fun _ h => h.1 #align simple_graph.incidence_set_subset SimpleGraph.incidenceSet_subset theorem mk'_mem_incidenceSet_iff : s(b, c) ∈ G.incidenceSet a ↔ G.Adj b c ∧ (a = b ∨ a = c) := and_congr_right' Sym2.mem_iff #align simple_graph.mk_mem_incidence_set_iff SimpleGraph.mk'_mem_incidenceSet_iff theorem mk'_mem_incidenceSet_left_iff : s(a, b) ∈ G.incidenceSet a ↔ G.Adj a b := and_iff_left <| Sym2.mem_mk_left _ _ #align simple_graph.mk_mem_incidence_set_left_iff SimpleGraph.mk'_mem_incidenceSet_left_iff theorem mk'_mem_incidenceSet_right_iff : s(a, b) ∈ G.incidenceSet b ↔ G.Adj a b := and_iff_left <| Sym2.mem_mk_right _ _ #align simple_graph.mk_mem_incidence_set_right_iff SimpleGraph.mk'_mem_incidenceSet_right_iff theorem edge_mem_incidenceSet_iff {e : G.edgeSet} : ↑e ∈ G.incidenceSet a ↔ a ∈ (e : Sym2 V) := and_iff_right e.2 #align simple_graph.edge_mem_incidence_set_iff SimpleGraph.edge_mem_incidenceSet_iff theorem incidenceSet_inter_incidenceSet_subset (h : a ≠ b) : G.incidenceSet a ∩ G.incidenceSet b ⊆ {s(a, b)} := fun _e he => (Sym2.mem_and_mem_iff h).1 ⟨he.1.2, he.2.2⟩ #align simple_graph.incidence_set_inter_incidence_set_subset SimpleGraph.incidenceSet_inter_incidenceSet_subset theorem incidenceSet_inter_incidenceSet_of_adj (h : G.Adj a b) : G.incidenceSet a ∩ G.incidenceSet b = {s(a, b)} := by refine (G.incidenceSet_inter_incidenceSet_subset <| h.ne).antisymm ?_ rintro _ (rfl : _ = s(a, b)) exact ⟨G.mk'_mem_incidenceSet_left_iff.2 h, G.mk'_mem_incidenceSet_right_iff.2 h⟩ #align simple_graph.incidence_set_inter_incidence_set_of_adj SimpleGraph.incidenceSet_inter_incidenceSet_of_adj theorem adj_of_mem_incidenceSet (h : a ≠ b) (ha : e ∈ G.incidenceSet a) (hb : e ∈ G.incidenceSet b) : G.Adj a b := by rwa [← mk'_mem_incidenceSet_left_iff, ← Set.mem_singleton_iff.1 <| G.incidenceSet_inter_incidenceSet_subset h ⟨ha, hb⟩] #align simple_graph.adj_of_mem_incidence_set SimpleGraph.adj_of_mem_incidenceSet theorem incidenceSet_inter_incidenceSet_of_not_adj (h : ¬G.Adj a b) (hn : a ≠ b) : G.incidenceSet a ∩ G.incidenceSet b = ∅ := by simp_rw [Set.eq_empty_iff_forall_not_mem, Set.mem_inter_iff, not_and] intro u ha hb exact h (G.adj_of_mem_incidenceSet hn ha hb) #align simple_graph.incidence_set_inter_incidence_set_of_not_adj SimpleGraph.incidenceSet_inter_incidenceSet_of_not_adj instance decidableMemIncidenceSet [DecidableEq V] [DecidableRel G.Adj] (v : V) : DecidablePred (· ∈ G.incidenceSet v) := inferInstanceAs <| DecidablePred fun e => e ∈ G.edgeSet ∧ v ∈ e #align simple_graph.decidable_mem_incidence_set SimpleGraph.decidableMemIncidenceSet @[simp] theorem mem_neighborSet (v w : V) : w ∈ G.neighborSet v ↔ G.Adj v w := Iff.rfl #align simple_graph.mem_neighbor_set SimpleGraph.mem_neighborSet lemma not_mem_neighborSet_self : a ∉ G.neighborSet a := by simp #align simple_graph.not_mem_neighbor_set_self SimpleGraph.not_mem_neighborSet_self @[simp] theorem mem_incidenceSet (v w : V) : s(v, w) ∈ G.incidenceSet v ↔ G.Adj v w := by simp [incidenceSet] #align simple_graph.mem_incidence_set SimpleGraph.mem_incidenceSet theorem mem_incidence_iff_neighbor {v w : V} : s(v, w) ∈ G.incidenceSet v ↔ w ∈ G.neighborSet v := by simp only [mem_incidenceSet, mem_neighborSet] #align simple_graph.mem_incidence_iff_neighbor SimpleGraph.mem_incidence_iff_neighbor theorem adj_incidenceSet_inter {v : V} {e : Sym2 V} (he : e ∈ G.edgeSet) (h : v ∈ e) : G.incidenceSet v ∩ G.incidenceSet (Sym2.Mem.other h) = {e} := by ext e' simp only [incidenceSet, Set.mem_sep_iff, Set.mem_inter_iff, Set.mem_singleton_iff] refine ⟨fun h' => ?_, ?_⟩ · rw [← Sym2.other_spec h] exact (Sym2.mem_and_mem_iff (edge_other_ne G he h).symm).mp ⟨h'.1.2, h'.2.2⟩ · rintro rfl exact ⟨⟨he, h⟩, he, Sym2.other_mem _⟩ #align simple_graph.adj_incidence_set_inter SimpleGraph.adj_incidenceSet_inter
Mathlib/Combinatorics/SimpleGraph/Basic.lean
793
798
theorem compl_neighborSet_disjoint (G : SimpleGraph V) (v : V) : Disjoint (G.neighborSet v) (Gᶜ.neighborSet v) := by
rw [Set.disjoint_iff] rintro w ⟨h, h'⟩ rw [mem_neighborSet, compl_adj] at h' exact h'.2 h
/- 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 -/ import Mathlib.AlgebraicGeometry.PrimeSpectrum.Basic import Mathlib.Algebra.Category.Ring.Colimits import Mathlib.Algebra.Category.Ring.Limits import Mathlib.Topology.Sheaves.LocalPredicate import Mathlib.RingTheory.Localization.AtPrime import Mathlib.Algebra.Ring.Subring.Basic #align_import algebraic_geometry.structure_sheaf from "leanprover-community/mathlib"@"5dc6092d09e5e489106865241986f7f2ad28d4c8" /-! # The structure sheaf on `PrimeSpectrum R`. We define the structure sheaf on `TopCat.of (PrimeSpectrum R)`, for a commutative ring `R` and prove basic properties about it. We define this as a subsheaf of the sheaf of dependent functions into the localizations, cut out by the condition that the function must be locally equal to a ratio of elements of `R`. Because the condition "is equal to a fraction" passes to smaller open subsets, the subset of functions satisfying this condition is automatically a subpresheaf. Because the condition "is locally equal to a fraction" is local, it is also a subsheaf. (It may be helpful to refer back to `Mathlib/Topology/Sheaves/SheafOfFunctions.lean`, where we show that dependent functions into any type family form a sheaf, and also `Mathlib/Topology/Sheaves/LocalPredicate.lean`, where we characterise the predicates which pick out sub-presheaves and sub-sheaves of these sheaves.) We also set up the ring structure, obtaining `structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R)`. We then construct two basic isomorphisms, relating the structure sheaf to the underlying ring `R`. First, `StructureSheaf.stalkIso` gives an isomorphism between the stalk of the structure sheaf at a point `p` and the localization of `R` at the prime ideal `p`. Second, `StructureSheaf.basicOpenIso` gives an isomorphism between the structure sheaf on `basicOpen f` and the localization of `R` at the submonoid of powers of `f`. ## References * [Robin Hartshorne, *Algebraic Geometry*][Har77] -/ universe u noncomputable section variable (R : Type u) [CommRing R] open TopCat open TopologicalSpace open CategoryTheory open Opposite namespace AlgebraicGeometry /-- The prime spectrum, just as a topological space. -/ def PrimeSpectrum.Top : TopCat := TopCat.of (PrimeSpectrum R) set_option linter.uppercaseLean3 false in #align algebraic_geometry.prime_spectrum.Top AlgebraicGeometry.PrimeSpectrum.Top namespace StructureSheaf /-- The type family over `PrimeSpectrum R` consisting of the localization over each point. -/ def Localizations (P : PrimeSpectrum.Top R) : Type u := Localization.AtPrime P.asIdeal #align algebraic_geometry.structure_sheaf.localizations AlgebraicGeometry.StructureSheaf.Localizations -- Porting note: can't derive `CommRingCat` instance commRingLocalizations (P : PrimeSpectrum.Top R) : CommRing <| Localizations R P := inferInstanceAs <| CommRing <| Localization.AtPrime P.asIdeal -- Porting note: can't derive `LocalRing` instance localRingLocalizations (P : PrimeSpectrum.Top R) : LocalRing <| Localizations R P := inferInstanceAs <| LocalRing <| Localization.AtPrime P.asIdeal instance (P : PrimeSpectrum.Top R) : Inhabited (Localizations R P) := ⟨1⟩ instance (U : Opens (PrimeSpectrum.Top R)) (x : U) : Algebra R (Localizations R x) := inferInstanceAs <| Algebra R (Localization.AtPrime x.1.asIdeal) instance (U : Opens (PrimeSpectrum.Top R)) (x : U) : IsLocalization.AtPrime (Localizations R x) (x : PrimeSpectrum.Top R).asIdeal := Localization.isLocalization variable {R} /-- The predicate saying that a dependent function on an open `U` is realised as a fixed fraction `r / s` in each of the stalks (which are localizations at various prime ideals). -/ def IsFraction {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) : Prop := ∃ r s : R, ∀ x : U, ¬s ∈ x.1.asIdeal ∧ f x * algebraMap _ _ s = algebraMap _ _ r #align algebraic_geometry.structure_sheaf.is_fraction AlgebraicGeometry.StructureSheaf.IsFraction theorem IsFraction.eq_mk' {U : Opens (PrimeSpectrum.Top R)} {f : ∀ x : U, Localizations R x} (hf : IsFraction f) : ∃ r s : R, ∀ x : U, ∃ hs : s ∉ x.1.asIdeal, f x = IsLocalization.mk' (Localization.AtPrime _) r (⟨s, hs⟩ : (x : PrimeSpectrum.Top R).asIdeal.primeCompl) := by rcases hf with ⟨r, s, h⟩ refine ⟨r, s, fun x => ⟨(h x).1, (IsLocalization.mk'_eq_iff_eq_mul.mpr ?_).symm⟩⟩ exact (h x).2.symm #align algebraic_geometry.structure_sheaf.is_fraction.eq_mk' AlgebraicGeometry.StructureSheaf.IsFraction.eq_mk' variable (R) /-- The predicate `IsFraction` is "prelocal", in the sense that if it holds on `U` it holds on any open subset `V` of `U`. -/ def isFractionPrelocal : PrelocalPredicate (Localizations R) where pred {U} f := IsFraction f res := by rintro V U i f ⟨r, s, w⟩; exact ⟨r, s, fun x => w (i x)⟩ #align algebraic_geometry.structure_sheaf.is_fraction_prelocal AlgebraicGeometry.StructureSheaf.isFractionPrelocal /-- We will define the structure sheaf as the subsheaf of all dependent functions in `Π x : U, Localizations R x` consisting of those functions which can locally be expressed as a ratio of (the images in the localization of) elements of `R`. Quoting Hartshorne: For an open set $U ⊆ Spec A$, we define $𝒪(U)$ to be the set of functions $s : U → ⨆_{𝔭 ∈ U} A_𝔭$, such that $s(𝔭) ∈ A_𝔭$ for each $𝔭$, and such that $s$ is locally a quotient of elements of $A$: to be precise, we require that for each $𝔭 ∈ U$, there is a neighborhood $V$ of $𝔭$, contained in $U$, and elements $a, f ∈ A$, such that for each $𝔮 ∈ V, f ∉ 𝔮$, and $s(𝔮) = a/f$ in $A_𝔮$. Now Hartshorne had the disadvantage of not knowing about dependent functions, so we replace his circumlocution about functions into a disjoint union with `Π x : U, Localizations x`. -/ def isLocallyFraction : LocalPredicate (Localizations R) := (isFractionPrelocal R).sheafify #align algebraic_geometry.structure_sheaf.is_locally_fraction AlgebraicGeometry.StructureSheaf.isLocallyFraction @[simp] theorem isLocallyFraction_pred {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) : (isLocallyFraction R).pred f = ∀ x : U, ∃ (V : _) (_ : x.1 ∈ V) (i : V ⟶ U), ∃ r s : R, ∀ y : V, ¬s ∈ y.1.asIdeal ∧ f (i y : U) * algebraMap _ _ s = algebraMap _ _ r := rfl #align algebraic_geometry.structure_sheaf.is_locally_fraction_pred AlgebraicGeometry.StructureSheaf.isLocallyFraction_pred /-- The functions satisfying `isLocallyFraction` form a subring. -/ def sectionsSubring (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) : Subring (∀ x : U.unop, Localizations R x) where carrier := { f | (isLocallyFraction R).pred f } zero_mem' := by refine fun x => ⟨unop U, x.2, 𝟙 _, 0, 1, fun y => ⟨?_, ?_⟩⟩ · rw [← Ideal.ne_top_iff_one]; exact y.1.IsPrime.1 · simp one_mem' := by refine fun x => ⟨unop U, x.2, 𝟙 _, 1, 1, fun y => ⟨?_, ?_⟩⟩ · rw [← Ideal.ne_top_iff_one]; exact y.1.IsPrime.1 · simp add_mem' := by intro a b ha hb x rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩ rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩ refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * sb + rb * sa, sa * sb, ?_⟩ intro y rcases wa (Opens.infLELeft _ _ y) with ⟨nma, wa⟩ rcases wb (Opens.infLERight _ _ y) with ⟨nmb, wb⟩ fconstructor · intro H; cases y.1.IsPrime.mem_or_mem H <;> contradiction · simp only [add_mul, RingHom.map_add, Pi.add_apply, RingHom.map_mul] erw [← wa, ← wb] simp only [mul_assoc] congr 2 rw [mul_comm] neg_mem' := by intro a ha x rcases ha x with ⟨V, m, i, r, s, w⟩ refine ⟨V, m, i, -r, s, ?_⟩ intro y rcases w y with ⟨nm, w⟩ fconstructor · exact nm · simp only [RingHom.map_neg, Pi.neg_apply] erw [← w] simp only [neg_mul] mul_mem' := by intro a b ha hb x rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩ rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩ refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * rb, sa * sb, ?_⟩ intro y rcases wa (Opens.infLELeft _ _ y) with ⟨nma, wa⟩ rcases wb (Opens.infLERight _ _ y) with ⟨nmb, wb⟩ fconstructor · intro H; cases y.1.IsPrime.mem_or_mem H <;> contradiction · simp only [Pi.mul_apply, RingHom.map_mul] erw [← wa, ← wb] simp only [mul_left_comm, mul_assoc, mul_comm] #align algebraic_geometry.structure_sheaf.sections_subring AlgebraicGeometry.StructureSheaf.sectionsSubring end StructureSheaf open StructureSheaf /-- The structure sheaf (valued in `Type`, not yet `CommRingCat`) is the subsheaf consisting of functions satisfying `isLocallyFraction`. -/ def structureSheafInType : Sheaf (Type u) (PrimeSpectrum.Top R) := subsheafToTypes (isLocallyFraction R) #align algebraic_geometry.structure_sheaf_in_Type AlgebraicGeometry.structureSheafInType instance commRingStructureSheafInTypeObj (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) : CommRing ((structureSheafInType R).1.obj U) := (sectionsSubring R U).toCommRing #align algebraic_geometry.comm_ring_structure_sheaf_in_Type_obj AlgebraicGeometry.commRingStructureSheafInTypeObj open PrimeSpectrum /-- The structure presheaf, valued in `CommRingCat`, constructed by dressing up the `Type` valued structure presheaf. -/ @[simps] def structurePresheafInCommRing : Presheaf CommRingCat (PrimeSpectrum.Top R) where obj U := CommRingCat.of ((structureSheafInType R).1.obj U) map {U V} i := { toFun := (structureSheafInType R).1.map i map_zero' := rfl map_add' := fun x y => rfl map_one' := rfl map_mul' := fun x y => rfl } set_option linter.uppercaseLean3 false in #align algebraic_geometry.structure_presheaf_in_CommRing AlgebraicGeometry.structurePresheafInCommRing -- These lemmas have always been bad (#7657), but leanprover/lean4#2644 made `simp` start noticing attribute [nolint simpNF] AlgebraicGeometry.structurePresheafInCommRing_map_apply /-- Some glue, verifying that the structure presheaf valued in `CommRingCat` agrees with the `Type` valued structure presheaf. -/ def structurePresheafCompForget : structurePresheafInCommRing R ⋙ forget CommRingCat ≅ (structureSheafInType R).1 := NatIso.ofComponents fun U => Iso.refl _ set_option linter.uppercaseLean3 false in #align algebraic_geometry.structure_presheaf_comp_forget AlgebraicGeometry.structurePresheafCompForget open TopCat.Presheaf /-- The structure sheaf on $Spec R$, valued in `CommRingCat`. This is provided as a bundled `SheafedSpace` as `Spec.SheafedSpace R` later. -/ def Spec.structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R) := ⟨structurePresheafInCommRing R, (-- We check the sheaf condition under `forget CommRingCat`. isSheaf_iff_isSheaf_comp _ _).mpr (isSheaf_of_iso (structurePresheafCompForget R).symm (structureSheafInType R).cond)⟩ set_option linter.uppercaseLean3 false in #align algebraic_geometry.Spec.structure_sheaf AlgebraicGeometry.Spec.structureSheaf open Spec (structureSheaf) namespace StructureSheaf @[simp] theorem res_apply (U V : Opens (PrimeSpectrum.Top R)) (i : V ⟶ U) (s : (structureSheaf R).1.obj (op U)) (x : V) : ((structureSheaf R).1.map i.op s).1 x = (s.1 (i x) : _) := rfl #align algebraic_geometry.structure_sheaf.res_apply AlgebraicGeometry.StructureSheaf.res_apply /- Notation in this comment X = Spec R OX = structure sheaf In the following we construct an isomorphism between OX_p and R_p given any point p corresponding to a prime ideal in R. We do this via 8 steps: 1. def const (f g : R) (V) (hv : V ≤ D_g) : OX(V) [for api] 2. def toOpen (U) : R ⟶ OX(U) 3. [2] def toStalk (p : Spec R) : R ⟶ OX_p 4. [2] def toBasicOpen (f : R) : R_f ⟶ OX(D_f) 5. [3] def localizationToStalk (p : Spec R) : R_p ⟶ OX_p 6. def openToLocalization (U) (p) (hp : p ∈ U) : OX(U) ⟶ R_p 7. [6] def stalkToFiberRingHom (p : Spec R) : OX_p ⟶ R_p 8. [5,7] def stalkIso (p : Spec R) : OX_p ≅ R_p In the square brackets we list the dependencies of a construction on the previous steps. -/ /-- The section of `structureSheaf R` on an open `U` sending each `x ∈ U` to the element `f/g` in the localization of `R` at `x`. -/ def const (f g : R) (U : Opens (PrimeSpectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) : (structureSheaf R).1.obj (op U) := ⟨fun x => IsLocalization.mk' _ f ⟨g, hu x x.2⟩, fun x => ⟨U, x.2, 𝟙 _, f, g, fun y => ⟨hu y y.2, IsLocalization.mk'_spec _ _ _⟩⟩⟩ #align algebraic_geometry.structure_sheaf.const AlgebraicGeometry.StructureSheaf.const @[simp] theorem const_apply (f g : R) (U : Opens (PrimeSpectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U) : (const R f g U hu).1 x = IsLocalization.mk' _ f ⟨g, hu x x.2⟩ := rfl #align algebraic_geometry.structure_sheaf.const_apply AlgebraicGeometry.StructureSheaf.const_apply theorem const_apply' (f g : R) (U : Opens (PrimeSpectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U) (hx : g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) : (const R f g U hu).1 x = IsLocalization.mk' _ f ⟨g, hx⟩ := rfl #align algebraic_geometry.structure_sheaf.const_apply' AlgebraicGeometry.StructureSheaf.const_apply' theorem exists_const (U) (s : (structureSheaf R).1.obj (op U)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) : ∃ (V : Opens (PrimeSpectrum.Top R)) (_ : x ∈ V) (i : V ⟶ U) (f g : R) (hg : _), const R f g V hg = (structureSheaf R).1.map i.op s := let ⟨V, hxV, iVU, f, g, hfg⟩ := s.2 ⟨x, hx⟩ ⟨V, hxV, iVU, f, g, fun y hyV => (hfg ⟨y, hyV⟩).1, Subtype.eq <| funext fun y => IsLocalization.mk'_eq_iff_eq_mul.2 <| Eq.symm <| (hfg y).2⟩ #align algebraic_geometry.structure_sheaf.exists_const AlgebraicGeometry.StructureSheaf.exists_const @[simp] theorem res_const (f g : R) (U hu V hv i) : (structureSheaf R).1.map i (const R f g U hu) = const R f g V hv := rfl #align algebraic_geometry.structure_sheaf.res_const AlgebraicGeometry.StructureSheaf.res_const theorem res_const' (f g : R) (V hv) : (structureSheaf R).1.map (homOfLE hv).op (const R f g (PrimeSpectrum.basicOpen g) fun _ => id) = const R f g V hv := rfl #align algebraic_geometry.structure_sheaf.res_const' AlgebraicGeometry.StructureSheaf.res_const' theorem const_zero (f : R) (U hu) : const R 0 f U hu = 0 := Subtype.eq <| funext fun x => IsLocalization.mk'_eq_iff_eq_mul.2 <| by rw [RingHom.map_zero] exact (mul_eq_zero_of_left rfl ((algebraMap R (Localizations R x)) _)).symm #align algebraic_geometry.structure_sheaf.const_zero AlgebraicGeometry.StructureSheaf.const_zero theorem const_self (f : R) (U hu) : const R f f U hu = 1 := Subtype.eq <| funext fun _ => IsLocalization.mk'_self _ _ #align algebraic_geometry.structure_sheaf.const_self AlgebraicGeometry.StructureSheaf.const_self theorem const_one (U) : (const R 1 1 U fun _ _ => Submonoid.one_mem _) = 1 := const_self R 1 U _ #align algebraic_geometry.structure_sheaf.const_one AlgebraicGeometry.StructureSheaf.const_one theorem const_add (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) : const R f₁ g₁ U hu₁ + const R f₂ g₂ U hu₂ = const R (f₁ * g₂ + f₂ * g₁) (g₁ * g₂) U fun x hx => Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) := Subtype.eq <| funext fun x => Eq.symm <| IsLocalization.mk'_add _ _ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩ #align algebraic_geometry.structure_sheaf.const_add AlgebraicGeometry.StructureSheaf.const_add theorem const_mul (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) : const R f₁ g₁ U hu₁ * const R f₂ g₂ U hu₂ = const R (f₁ * f₂) (g₁ * g₂) U fun x hx => Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) := Subtype.eq <| funext fun x => Eq.symm <| IsLocalization.mk'_mul _ f₁ f₂ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩ #align algebraic_geometry.structure_sheaf.const_mul AlgebraicGeometry.StructureSheaf.const_mul theorem const_ext {f₁ f₂ g₁ g₂ : R} {U hu₁ hu₂} (h : f₁ * g₂ = f₂ * g₁) : const R f₁ g₁ U hu₁ = const R f₂ g₂ U hu₂ := Subtype.eq <| funext fun x => IsLocalization.mk'_eq_of_eq (by rw [mul_comm, Subtype.coe_mk, ← h, mul_comm, Subtype.coe_mk]) #align algebraic_geometry.structure_sheaf.const_ext AlgebraicGeometry.StructureSheaf.const_ext theorem const_congr {f₁ f₂ g₁ g₂ : R} {U hu} (hf : f₁ = f₂) (hg : g₁ = g₂) : const R f₁ g₁ U hu = const R f₂ g₂ U (hg ▸ hu) := by substs hf hg; rfl #align algebraic_geometry.structure_sheaf.const_congr AlgebraicGeometry.StructureSheaf.const_congr theorem const_mul_rev (f g : R) (U hu₁ hu₂) : const R f g U hu₁ * const R g f U hu₂ = 1 := by rw [const_mul, const_congr R rfl (mul_comm g f), const_self] #align algebraic_geometry.structure_sheaf.const_mul_rev AlgebraicGeometry.StructureSheaf.const_mul_rev theorem const_mul_cancel (f g₁ g₂ : R) (U hu₁ hu₂) : const R f g₁ U hu₁ * const R g₁ g₂ U hu₂ = const R f g₂ U hu₂ := by rw [const_mul, const_ext]; rw [mul_assoc] #align algebraic_geometry.structure_sheaf.const_mul_cancel AlgebraicGeometry.StructureSheaf.const_mul_cancel theorem const_mul_cancel' (f g₁ g₂ : R) (U hu₁ hu₂) : const R g₁ g₂ U hu₂ * const R f g₁ U hu₁ = const R f g₂ U hu₂ := by rw [mul_comm, const_mul_cancel] #align algebraic_geometry.structure_sheaf.const_mul_cancel' AlgebraicGeometry.StructureSheaf.const_mul_cancel' /-- The canonical ring homomorphism interpreting an element of `R` as a section of the structure sheaf. -/ def toOpen (U : Opens (PrimeSpectrum.Top R)) : CommRingCat.of R ⟶ (structureSheaf R).1.obj (op U) where toFun f := ⟨fun x => algebraMap R _ f, fun x => ⟨U, x.2, 𝟙 _, f, 1, fun y => ⟨(Ideal.ne_top_iff_one _).1 y.1.2.1, by rw [RingHom.map_one, mul_one]⟩⟩⟩ map_one' := Subtype.eq <| funext fun x => RingHom.map_one _ map_mul' f g := Subtype.eq <| funext fun x => RingHom.map_mul _ _ _ map_zero' := Subtype.eq <| funext fun x => RingHom.map_zero _ map_add' f g := Subtype.eq <| funext fun x => RingHom.map_add _ _ _ #align algebraic_geometry.structure_sheaf.to_open AlgebraicGeometry.StructureSheaf.toOpen @[simp] theorem toOpen_res (U V : Opens (PrimeSpectrum.Top R)) (i : V ⟶ U) : toOpen R U ≫ (structureSheaf R).1.map i.op = toOpen R V := rfl #align algebraic_geometry.structure_sheaf.to_open_res AlgebraicGeometry.StructureSheaf.toOpen_res @[simp] theorem toOpen_apply (U : Opens (PrimeSpectrum.Top R)) (f : R) (x : U) : (toOpen R U f).1 x = algebraMap _ _ f := rfl #align algebraic_geometry.structure_sheaf.to_open_apply AlgebraicGeometry.StructureSheaf.toOpen_apply theorem toOpen_eq_const (U : Opens (PrimeSpectrum.Top R)) (f : R) : toOpen R U f = const R f 1 U fun x _ => (Ideal.ne_top_iff_one _).1 x.2.1 := Subtype.eq <| funext fun _ => Eq.symm <| IsLocalization.mk'_one _ f #align algebraic_geometry.structure_sheaf.to_open_eq_const AlgebraicGeometry.StructureSheaf.toOpen_eq_const /-- The canonical ring homomorphism interpreting an element of `R` as an element of the stalk of `structureSheaf R` at `x`. -/ def toStalk (x : PrimeSpectrum.Top R) : CommRingCat.of R ⟶ (structureSheaf R).presheaf.stalk x := (toOpen R ⊤ ≫ (structureSheaf R).presheaf.germ ⟨x, by trivial⟩) #align algebraic_geometry.structure_sheaf.to_stalk AlgebraicGeometry.StructureSheaf.toStalk @[simp] theorem toOpen_germ (U : Opens (PrimeSpectrum.Top R)) (x : U) : toOpen R U ≫ (structureSheaf R).presheaf.germ x = toStalk R x := by rw [← toOpen_res R ⊤ U (homOfLE le_top : U ⟶ ⊤), Category.assoc, Presheaf.germ_res]; rfl #align algebraic_geometry.structure_sheaf.to_open_germ AlgebraicGeometry.StructureSheaf.toOpen_germ @[simp] theorem germ_toOpen (U : Opens (PrimeSpectrum.Top R)) (x : U) (f : R) : (structureSheaf R).presheaf.germ x (toOpen R U f) = toStalk R x f := by rw [← toOpen_germ]; rfl #align algebraic_geometry.structure_sheaf.germ_to_open AlgebraicGeometry.StructureSheaf.germ_toOpen theorem germ_to_top (x : PrimeSpectrum.Top R) (f : R) : (structureSheaf R).presheaf.germ (⟨x, trivial⟩ : (⊤ : Opens (PrimeSpectrum.Top R))) (toOpen R ⊤ f) = toStalk R x f := rfl #align algebraic_geometry.structure_sheaf.germ_to_top AlgebraicGeometry.StructureSheaf.germ_to_top theorem isUnit_to_basicOpen_self (f : R) : IsUnit (toOpen R (PrimeSpectrum.basicOpen f) f) := isUnit_of_mul_eq_one _ (const R 1 f (PrimeSpectrum.basicOpen f) fun _ => id) <| by rw [toOpen_eq_const, const_mul_rev] #align algebraic_geometry.structure_sheaf.is_unit_to_basic_open_self AlgebraicGeometry.StructureSheaf.isUnit_to_basicOpen_self theorem isUnit_toStalk (x : PrimeSpectrum.Top R) (f : x.asIdeal.primeCompl) : IsUnit (toStalk R x (f : R)) := by erw [← germ_toOpen R (PrimeSpectrum.basicOpen (f : R)) ⟨x, f.2⟩ (f : R)] exact RingHom.isUnit_map _ (isUnit_to_basicOpen_self R f) #align algebraic_geometry.structure_sheaf.is_unit_to_stalk AlgebraicGeometry.StructureSheaf.isUnit_toStalk /-- The canonical ring homomorphism from the localization of `R` at `p` to the stalk of the structure sheaf at the point `p`. -/ def localizationToStalk (x : PrimeSpectrum.Top R) : CommRingCat.of (Localization.AtPrime x.asIdeal) ⟶ (structureSheaf R).presheaf.stalk x := show Localization.AtPrime x.asIdeal →+* _ from IsLocalization.lift (isUnit_toStalk R x) #align algebraic_geometry.structure_sheaf.localization_to_stalk AlgebraicGeometry.StructureSheaf.localizationToStalk @[simp] theorem localizationToStalk_of (x : PrimeSpectrum.Top R) (f : R) : localizationToStalk R x (algebraMap _ (Localization _) f) = toStalk R x f := IsLocalization.lift_eq (S := Localization x.asIdeal.primeCompl) _ f #align algebraic_geometry.structure_sheaf.localization_to_stalk_of AlgebraicGeometry.StructureSheaf.localizationToStalk_of @[simp] theorem localizationToStalk_mk' (x : PrimeSpectrum.Top R) (f : R) (s : x.asIdeal.primeCompl) : localizationToStalk R x (IsLocalization.mk' (Localization.AtPrime x.asIdeal) f s) = (structureSheaf R).presheaf.germ (⟨x, s.2⟩ : PrimeSpectrum.basicOpen (s : R)) (const R f s (PrimeSpectrum.basicOpen s) fun _ => id) := (IsLocalization.lift_mk'_spec (S := Localization.AtPrime x.asIdeal) _ _ _ _).2 <| by erw [← germ_toOpen R (PrimeSpectrum.basicOpen s) ⟨x, s.2⟩, ← germ_toOpen R (PrimeSpectrum.basicOpen s) ⟨x, s.2⟩, ← RingHom.map_mul, toOpen_eq_const, toOpen_eq_const, const_mul_cancel'] #align algebraic_geometry.structure_sheaf.localization_to_stalk_mk' AlgebraicGeometry.StructureSheaf.localizationToStalk_mk' /-- The ring homomorphism that takes a section of the structure sheaf of `R` on the open set `U`, implemented as a subtype of dependent functions to localizations at prime ideals, and evaluates the section on the point corresponding to a given prime ideal. -/ def openToLocalization (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) : (structureSheaf R).1.obj (op U) ⟶ CommRingCat.of (Localization.AtPrime x.asIdeal) where toFun s := (s.1 ⟨x, hx⟩ : _) map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl #align algebraic_geometry.structure_sheaf.open_to_localization AlgebraicGeometry.StructureSheaf.openToLocalization @[simp] theorem coe_openToLocalization (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) : (openToLocalization R U x hx : (structureSheaf R).1.obj (op U) → Localization.AtPrime x.asIdeal) = fun s => (s.1 ⟨x, hx⟩ : _) := rfl #align algebraic_geometry.structure_sheaf.coe_open_to_localization AlgebraicGeometry.StructureSheaf.coe_openToLocalization theorem openToLocalization_apply (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) (s : (structureSheaf R).1.obj (op U)) : openToLocalization R U x hx s = (s.1 ⟨x, hx⟩ : _) := rfl #align algebraic_geometry.structure_sheaf.open_to_localization_apply AlgebraicGeometry.StructureSheaf.openToLocalization_apply /-- The ring homomorphism from the stalk of the structure sheaf of `R` at a point corresponding to a prime ideal `p` to the localization of `R` at `p`, formed by gluing the `openToLocalization` maps. -/ def stalkToFiberRingHom (x : PrimeSpectrum.Top R) : (structureSheaf R).presheaf.stalk x ⟶ CommRingCat.of (Localization.AtPrime x.asIdeal) := Limits.colimit.desc ((OpenNhds.inclusion x).op ⋙ (structureSheaf R).1) { pt := _ ι := { app := fun U => openToLocalization R ((OpenNhds.inclusion _).obj (unop U)) x (unop U).2 } } #align algebraic_geometry.structure_sheaf.stalk_to_fiber_ring_hom AlgebraicGeometry.StructureSheaf.stalkToFiberRingHom @[simp] theorem germ_comp_stalkToFiberRingHom (U : Opens (PrimeSpectrum.Top R)) (x : U) : (structureSheaf R).presheaf.germ x ≫ stalkToFiberRingHom R x = openToLocalization R U x x.2 := Limits.colimit.ι_desc _ _ #align algebraic_geometry.structure_sheaf.germ_comp_stalk_to_fiber_ring_hom AlgebraicGeometry.StructureSheaf.germ_comp_stalkToFiberRingHom @[simp] theorem stalkToFiberRingHom_germ' (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) (s : (structureSheaf R).1.obj (op U)) : stalkToFiberRingHom R x ((structureSheaf R).presheaf.germ ⟨x, hx⟩ s) = (s.1 ⟨x, hx⟩ : _) := RingHom.ext_iff.1 (germ_comp_stalkToFiberRingHom R U ⟨x, hx⟩ : _) s #align algebraic_geometry.structure_sheaf.stalk_to_fiber_ring_hom_germ' AlgebraicGeometry.StructureSheaf.stalkToFiberRingHom_germ' @[simp]
Mathlib/AlgebraicGeometry/StructureSheaf.lean
553
556
theorem stalkToFiberRingHom_germ (U : Opens (PrimeSpectrum.Top R)) (x : U) (s : (structureSheaf R).1.obj (op U)) : stalkToFiberRingHom R x ((structureSheaf R).presheaf.germ x s) = s.1 x := by
cases x; exact stalkToFiberRingHom_germ' R U _ _ _
/- Copyright (c) 2023 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.Mul import Mathlib.Analysis.Calculus.Deriv.Comp #align_import analysis.calculus.deriv.inv from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Derivatives of `x ↦ x⁻¹` and `f x / g x` In this file we prove `(x⁻¹)' = -1 / x ^ 2`, `((f x)⁻¹)' = -f' x / (f x) ^ 2`, and `(f x / g x)' = (f' x * g x - f x * g' x) / (g x) ^ 2` for different notions of derivative. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative -/ universe u v w open scoped Classical open Topology Filter ENNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L : Filter 𝕜} section Inverse /-! ### Derivative of `x ↦ x⁻¹` -/ theorem hasStrictDerivAt_inv (hx : x ≠ 0) : HasStrictDerivAt Inv.inv (-(x ^ 2)⁻¹) x := by suffices (fun p : 𝕜 × 𝕜 => (p.1 - p.2) * ((x * x)⁻¹ - (p.1 * p.2)⁻¹)) =o[𝓝 (x, x)] fun p => (p.1 - p.2) * 1 by refine this.congr' ?_ (eventually_of_forall fun _ => mul_one _) refine Eventually.mono ((isOpen_ne.prod isOpen_ne).mem_nhds ⟨hx, hx⟩) ?_ rintro ⟨y, z⟩ ⟨hy, hz⟩ simp only [mem_setOf_eq] at hy hz -- hy : y ≠ 0, hz : z ≠ 0 field_simp [hx, hy, hz] ring refine (isBigO_refl (fun p : 𝕜 × 𝕜 => p.1 - p.2) _).mul_isLittleO ((isLittleO_one_iff 𝕜).2 ?_) rw [← sub_self (x * x)⁻¹] exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv₀ <| mul_ne_zero hx hx) #align has_strict_deriv_at_inv hasStrictDerivAt_inv theorem hasDerivAt_inv (x_ne_zero : x ≠ 0) : HasDerivAt (fun y => y⁻¹) (-(x ^ 2)⁻¹) x := (hasStrictDerivAt_inv x_ne_zero).hasDerivAt #align has_deriv_at_inv hasDerivAt_inv theorem hasDerivWithinAt_inv (x_ne_zero : x ≠ 0) (s : Set 𝕜) : HasDerivWithinAt (fun x => x⁻¹) (-(x ^ 2)⁻¹) s x := (hasDerivAt_inv x_ne_zero).hasDerivWithinAt #align has_deriv_within_at_inv hasDerivWithinAt_inv theorem differentiableAt_inv : DifferentiableAt 𝕜 (fun x => x⁻¹) x ↔ x ≠ 0 := ⟨fun H => NormedField.continuousAt_inv.1 H.continuousAt, fun H => (hasDerivAt_inv H).differentiableAt⟩ #align differentiable_at_inv differentiableAt_inv theorem differentiableWithinAt_inv (x_ne_zero : x ≠ 0) : DifferentiableWithinAt 𝕜 (fun x => x⁻¹) s x := (differentiableAt_inv.2 x_ne_zero).differentiableWithinAt #align differentiable_within_at_inv differentiableWithinAt_inv theorem differentiableOn_inv : DifferentiableOn 𝕜 (fun x : 𝕜 => x⁻¹) { x | x ≠ 0 } := fun _x hx => differentiableWithinAt_inv hx #align differentiable_on_inv differentiableOn_inv theorem deriv_inv : deriv (fun x => x⁻¹) x = -(x ^ 2)⁻¹ := by rcases eq_or_ne x 0 with (rfl | hne) · simp [deriv_zero_of_not_differentiableAt (mt differentiableAt_inv.1 (not_not.2 rfl))] · exact (hasDerivAt_inv hne).deriv #align deriv_inv deriv_inv @[simp] theorem deriv_inv' : (deriv fun x : 𝕜 => x⁻¹) = fun x => -(x ^ 2)⁻¹ := funext fun _ => deriv_inv #align deriv_inv' deriv_inv' theorem derivWithin_inv (x_ne_zero : x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => x⁻¹) s x = -(x ^ 2)⁻¹ := by rw [DifferentiableAt.derivWithin (differentiableAt_inv.2 x_ne_zero) hxs] exact deriv_inv #align deriv_within_inv derivWithin_inv theorem hasFDerivAt_inv (x_ne_zero : x ≠ 0) : HasFDerivAt (fun x => x⁻¹) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) : 𝕜 →L[𝕜] 𝕜) x := hasDerivAt_inv x_ne_zero #align has_fderiv_at_inv hasFDerivAt_inv theorem hasFDerivWithinAt_inv (x_ne_zero : x ≠ 0) : HasFDerivWithinAt (fun x => x⁻¹) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) : 𝕜 →L[𝕜] 𝕜) s x := (hasFDerivAt_inv x_ne_zero).hasFDerivWithinAt #align has_fderiv_within_at_inv hasFDerivWithinAt_inv
Mathlib/Analysis/Calculus/Deriv/Inv.lean
114
115
theorem fderiv_inv : fderiv 𝕜 (fun x => x⁻¹) x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) := by
rw [← deriv_fderiv, deriv_inv]
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Reverse import Mathlib.Algebra.Polynomial.Inductions import Mathlib.RingTheory.Localization.Basic #align_import data.polynomial.laurent from "leanprover-community/mathlib"@"831c494092374cfe9f50591ed0ac81a25efc5b86" /-! # Laurent polynomials We introduce Laurent polynomials over a semiring `R`. Mathematically, they are expressions of the form $$ \sum_{i \in \mathbb{Z}} a_i T ^ i $$ where the sum extends over a finite subset of `ℤ`. Thus, negative exponents are allowed. The coefficients come from the semiring `R` and the variable `T` commutes with everything. Since we are going to convert back and forth between polynomials and Laurent polynomials, we decided to maintain some distinction by using the symbol `T`, rather than `X`, as the variable for Laurent polynomials. ## Notation The symbol `R[T;T⁻¹]` stands for `LaurentPolynomial R`. We also define * `C : R →+* R[T;T⁻¹]` the inclusion of constant polynomials, analogous to the one for `R[X]`; * `T : ℤ → R[T;T⁻¹]` the sequence of powers of the variable `T`. ## Implementation notes We define Laurent polynomials as `AddMonoidAlgebra R ℤ`. Thus, they are essentially `Finsupp`s `ℤ →₀ R`. This choice differs from the current irreducible design of `Polynomial`, that instead shields away the implementation via `Finsupp`s. It is closer to the original definition of polynomials. As a consequence, `LaurentPolynomial` plays well with polynomials, but there is a little roughness in establishing the API, since the `Finsupp` implementation of `R[X]` is well-shielded. Unlike the case of polynomials, I felt that the exponent notation was not too easy to use, as only natural exponents would be allowed. Moreover, in the end, it seems likely that we should aim to perform computations on exponents in `ℤ` anyway and separating this via the symbol `T` seems convenient. I made a *heavy* use of `simp` lemmas, aiming to bring Laurent polynomials to the form `C a * T n`. Any comments or suggestions for improvements is greatly appreciated! ## Future work Lots is missing! -- (Riccardo) add inclusion into Laurent series. -- (Riccardo) giving a morphism (as `R`-alg, so in the commutative case) from `R[T,T⁻¹]` to `S` is the same as choosing a unit of `S`. -- A "better" definition of `trunc` would be as an `R`-linear map. This works: -- ``` -- def trunc : R[T;T⁻¹] →[R] R[X] := -- refine (?_ : R[ℕ] →[R] R[X]).comp ?_ -- · exact ⟨(toFinsuppIso R).symm, by simp⟩ -- · refine ⟨fun r ↦ comapDomain _ r -- (Set.injOn_of_injective (fun _ _ ↦ Int.ofNat.inj) _), ?_⟩ -- exact fun r f ↦ comapDomain_smul .. -- ``` -- but it would make sense to bundle the maps better, for a smoother user experience. -- I (DT) did not have the strength to embark on this (possibly short!) journey, after getting to -- this stage of the Laurent process! -- This would likely involve adding a `comapDomain` analogue of -- `AddMonoidAlgebra.mapDomainAlgHom` and an `R`-linear version of -- `Polynomial.toFinsuppIso`. -- Add `degree, int_degree, int_trailing_degree, leading_coeff, trailing_coeff,...`. -/ open Polynomial Function AddMonoidAlgebra Finsupp noncomputable section variable {R : Type*} /-- The semiring of Laurent polynomials with coefficients in the semiring `R`. We denote it by `R[T;T⁻¹]`. The ring homomorphism `C : R →+* R[T;T⁻¹]` includes `R` as the constant polynomials. -/ abbrev LaurentPolynomial (R : Type*) [Semiring R] := AddMonoidAlgebra R ℤ #align laurent_polynomial LaurentPolynomial @[nolint docBlame] scoped[LaurentPolynomial] notation:9000 R "[T;T⁻¹]" => LaurentPolynomial R open LaurentPolynomial -- Porting note: `ext` no longer applies `Finsupp.ext` automatically @[ext] theorem LaurentPolynomial.ext [Semiring R] {p q : R[T;T⁻¹]} (h : ∀ a, p a = q a) : p = q := Finsupp.ext h /-- The ring homomorphism, taking a polynomial with coefficients in `R` to a Laurent polynomial with coefficients in `R`. -/ def Polynomial.toLaurent [Semiring R] : R[X] →+* R[T;T⁻¹] := (mapDomainRingHom R Int.ofNatHom).comp (toFinsuppIso R) #align polynomial.to_laurent Polynomial.toLaurent /-- This is not a simp lemma, as it is usually preferable to use the lemmas about `C` and `X` instead. -/ theorem Polynomial.toLaurent_apply [Semiring R] (p : R[X]) : toLaurent p = p.toFinsupp.mapDomain (↑) := rfl #align polynomial.to_laurent_apply Polynomial.toLaurent_apply /-- The `R`-algebra map, taking a polynomial with coefficients in `R` to a Laurent polynomial with coefficients in `R`. -/ def Polynomial.toLaurentAlg [CommSemiring R] : R[X] →ₐ[R] R[T;T⁻¹] := (mapDomainAlgHom R R Int.ofNatHom).comp (toFinsuppIsoAlg R).toAlgHom #align polynomial.to_laurent_alg Polynomial.toLaurentAlg @[simp] lemma Polynomial.coe_toLaurentAlg [CommSemiring R] : (toLaurentAlg : R[X] → R[T;T⁻¹]) = toLaurent := rfl theorem Polynomial.toLaurentAlg_apply [CommSemiring R] (f : R[X]) : toLaurentAlg f = toLaurent f := rfl #align polynomial.to_laurent_alg_apply Polynomial.toLaurentAlg_apply namespace LaurentPolynomial section Semiring variable [Semiring R] theorem single_zero_one_eq_one : (Finsupp.single 0 1 : R[T;T⁻¹]) = (1 : R[T;T⁻¹]) := rfl #align laurent_polynomial.single_zero_one_eq_one LaurentPolynomial.single_zero_one_eq_one /-! ### The functions `C` and `T`. -/ /-- The ring homomorphism `C`, including `R` into the ring of Laurent polynomials over `R` as the constant Laurent polynomials. -/ def C : R →+* R[T;T⁻¹] := singleZeroRingHom set_option linter.uppercaseLean3 false in #align laurent_polynomial.C LaurentPolynomial.C theorem algebraMap_apply {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (r : R) : algebraMap R (LaurentPolynomial A) r = C (algebraMap R A r) := rfl #align laurent_polynomial.algebra_map_apply LaurentPolynomial.algebraMap_apply /-- When we have `[CommSemiring R]`, the function `C` is the same as `algebraMap R R[T;T⁻¹]`. (But note that `C` is defined when `R` is not necessarily commutative, in which case `algebraMap` is not available.) -/ theorem C_eq_algebraMap {R : Type*} [CommSemiring R] (r : R) : C r = algebraMap R R[T;T⁻¹] r := rfl set_option linter.uppercaseLean3 false in #align laurent_polynomial.C_eq_algebra_map LaurentPolynomial.C_eq_algebraMap theorem single_eq_C (r : R) : Finsupp.single 0 r = C r := rfl set_option linter.uppercaseLean3 false in #align laurent_polynomial.single_eq_C LaurentPolynomial.single_eq_C @[simp] lemma C_apply (t : R) (n : ℤ) : C t n = if n = 0 then t else 0 := by rw [← single_eq_C, Finsupp.single_apply]; aesop /-- The function `n ↦ T ^ n`, implemented as a sequence `ℤ → R[T;T⁻¹]`. Using directly `T ^ n` does not work, since we want the exponents to be of Type `ℤ` and there is no `ℤ`-power defined on `R[T;T⁻¹]`. Using that `T` is a unit introduces extra coercions. For these reasons, the definition of `T` is as a sequence. -/ def T (n : ℤ) : R[T;T⁻¹] := Finsupp.single n 1 set_option linter.uppercaseLean3 false in #align laurent_polynomial.T LaurentPolynomial.T @[simp] lemma T_apply (m n : ℤ) : (T n : R[T;T⁻¹]) m = if n = m then 1 else 0 := Finsupp.single_apply @[simp] theorem T_zero : (T 0 : R[T;T⁻¹]) = 1 := rfl set_option linter.uppercaseLean3 false in #align laurent_polynomial.T_zero LaurentPolynomial.T_zero theorem T_add (m n : ℤ) : (T (m + n) : R[T;T⁻¹]) = T m * T n := by -- Porting note: was `convert single_mul_single.symm` simp [T, single_mul_single] set_option linter.uppercaseLean3 false in #align laurent_polynomial.T_add LaurentPolynomial.T_add theorem T_sub (m n : ℤ) : (T (m - n) : R[T;T⁻¹]) = T m * T (-n) := by rw [← T_add, sub_eq_add_neg] set_option linter.uppercaseLean3 false in #align laurent_polynomial.T_sub LaurentPolynomial.T_sub @[simp] theorem T_pow (m : ℤ) (n : ℕ) : (T m ^ n : R[T;T⁻¹]) = T (n * m) := by rw [T, T, single_pow n, one_pow, nsmul_eq_mul] set_option linter.uppercaseLean3 false in #align laurent_polynomial.T_pow LaurentPolynomial.T_pow /-- The `simp` version of `mul_assoc`, in the presence of `T`'s. -/ @[simp] theorem mul_T_assoc (f : R[T;T⁻¹]) (m n : ℤ) : f * T m * T n = f * T (m + n) := by simp [← T_add, mul_assoc] set_option linter.uppercaseLean3 false in #align laurent_polynomial.mul_T_assoc LaurentPolynomial.mul_T_assoc @[simp] theorem single_eq_C_mul_T (r : R) (n : ℤ) : (Finsupp.single n r : R[T;T⁻¹]) = (C r * T n : R[T;T⁻¹]) := by -- Porting note: was `convert single_mul_single.symm` simp [C, T, single_mul_single] set_option linter.uppercaseLean3 false in #align laurent_polynomial.single_eq_C_mul_T LaurentPolynomial.single_eq_C_mul_T -- This lemma locks in the right changes and is what Lean proved directly. -- The actual `simp`-normal form of a Laurent monomial is `C a * T n`, whenever it can be reached. @[simp] theorem _root_.Polynomial.toLaurent_C_mul_T (n : ℕ) (r : R) : (toLaurent (Polynomial.monomial n r) : R[T;T⁻¹]) = C r * T n := show Finsupp.mapDomain (↑) (monomial n r).toFinsupp = (C r * T n : R[T;T⁻¹]) by rw [toFinsupp_monomial, Finsupp.mapDomain_single, single_eq_C_mul_T] set_option linter.uppercaseLean3 false in #align polynomial.to_laurent_C_mul_T Polynomial.toLaurent_C_mul_T @[simp] theorem _root_.Polynomial.toLaurent_C (r : R) : toLaurent (Polynomial.C r) = C r := by convert Polynomial.toLaurent_C_mul_T 0 r simp only [Int.ofNat_zero, T_zero, mul_one] set_option linter.uppercaseLean3 false in #align polynomial.to_laurent_C Polynomial.toLaurent_C @[simp] theorem _root_.Polynomial.toLaurent_comp_C : toLaurent (R := R) ∘ Polynomial.C = C := funext Polynomial.toLaurent_C @[simp] theorem _root_.Polynomial.toLaurent_X : (toLaurent Polynomial.X : R[T;T⁻¹]) = T 1 := by have : (Polynomial.X : R[X]) = monomial 1 1 := by simp [← C_mul_X_pow_eq_monomial] simp [this, Polynomial.toLaurent_C_mul_T] set_option linter.uppercaseLean3 false in #align polynomial.to_laurent_X Polynomial.toLaurent_X -- @[simp] -- Porting note (#10618): simp can prove this theorem _root_.Polynomial.toLaurent_one : (Polynomial.toLaurent : R[X] → R[T;T⁻¹]) 1 = 1 := map_one Polynomial.toLaurent #align polynomial.to_laurent_one Polynomial.toLaurent_one -- @[simp] -- Porting note (#10618): simp can prove this theorem _root_.Polynomial.toLaurent_C_mul_eq (r : R) (f : R[X]) : toLaurent (Polynomial.C r * f) = C r * toLaurent f := by simp only [_root_.map_mul, Polynomial.toLaurent_C] set_option linter.uppercaseLean3 false in #align polynomial.to_laurent_C_mul_eq Polynomial.toLaurent_C_mul_eq -- @[simp] -- Porting note (#10618): simp can prove this theorem _root_.Polynomial.toLaurent_X_pow (n : ℕ) : toLaurent (X ^ n : R[X]) = T n := by simp only [map_pow, Polynomial.toLaurent_X, T_pow, mul_one] set_option linter.uppercaseLean3 false in #align polynomial.to_laurent_X_pow Polynomial.toLaurent_X_pow -- @[simp] -- Porting note (#10618): simp can prove this theorem _root_.Polynomial.toLaurent_C_mul_X_pow (n : ℕ) (r : R) : toLaurent (Polynomial.C r * X ^ n) = C r * T n := by simp only [_root_.map_mul, Polynomial.toLaurent_C, Polynomial.toLaurent_X_pow] set_option linter.uppercaseLean3 false in #align polynomial.to_laurent_C_mul_X_pow Polynomial.toLaurent_C_mul_X_pow instance invertibleT (n : ℤ) : Invertible (T n : R[T;T⁻¹]) where invOf := T (-n) invOf_mul_self := by rw [← T_add, add_left_neg, T_zero] mul_invOf_self := by rw [← T_add, add_right_neg, T_zero] set_option linter.uppercaseLean3 false in #align laurent_polynomial.invertible_T LaurentPolynomial.invertibleT @[simp] theorem invOf_T (n : ℤ) : ⅟ (T n : R[T;T⁻¹]) = T (-n) := rfl set_option linter.uppercaseLean3 false in #align laurent_polynomial.inv_of_T LaurentPolynomial.invOf_T theorem isUnit_T (n : ℤ) : IsUnit (T n : R[T;T⁻¹]) := isUnit_of_invertible _ set_option linter.uppercaseLean3 false in #align laurent_polynomial.is_unit_T LaurentPolynomial.isUnit_T @[elab_as_elim] protected theorem induction_on {M : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹]) (h_C : ∀ a, M (C a)) (h_add : ∀ {p q}, M p → M q → M (p + q)) (h_C_mul_T : ∀ (n : ℕ) (a : R), M (C a * T n) → M (C a * T (n + 1))) (h_C_mul_T_Z : ∀ (n : ℕ) (a : R), M (C a * T (-n)) → M (C a * T (-n - 1))) : M p := by have A : ∀ {n : ℤ} {a : R}, M (C a * T n) := by intro n a refine Int.induction_on n ?_ ?_ ?_ · simpa only [T_zero, mul_one] using h_C a · exact fun m => h_C_mul_T m a · exact fun m => h_C_mul_T_Z m a have B : ∀ s : Finset ℤ, M (s.sum fun n : ℤ => C (p.toFun n) * T n) := by apply Finset.induction · convert h_C 0 simp only [Finset.sum_empty, _root_.map_zero] · intro n s ns ih rw [Finset.sum_insert ns] exact h_add A ih convert B p.support ext a simp_rw [← single_eq_C_mul_T] -- Porting note: did not make progress in `simp_rw` rw [Finset.sum_apply'] simp_rw [Finsupp.single_apply, Finset.sum_ite_eq'] split_ifs with h · rfl · exact Finsupp.not_mem_support_iff.mp h #align laurent_polynomial.induction_on LaurentPolynomial.induction_on /-- To prove something about Laurent polynomials, it suffices to show that * the condition is closed under taking sums, and * it holds for monomials. -/ @[elab_as_elim] protected theorem induction_on' {M : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹]) (h_add : ∀ p q, M p → M q → M (p + q)) (h_C_mul_T : ∀ (n : ℤ) (a : R), M (C a * T n)) : M p := by refine p.induction_on (fun a => ?_) (fun {p q} => h_add p q) ?_ ?_ <;> try exact fun n f _ => h_C_mul_T _ f convert h_C_mul_T 0 a exact (mul_one _).symm #align laurent_polynomial.induction_on' LaurentPolynomial.induction_on' theorem commute_T (n : ℤ) (f : R[T;T⁻¹]) : Commute (T n) f := f.induction_on' (fun p q Tp Tq => Commute.add_right Tp Tq) fun m a => show T n * _ = _ by rw [T, T, ← single_eq_C, single_mul_single, single_mul_single, single_mul_single] simp [add_comm] set_option linter.uppercaseLean3 false in #align laurent_polynomial.commute_T LaurentPolynomial.commute_T @[simp] theorem T_mul (n : ℤ) (f : R[T;T⁻¹]) : T n * f = f * T n := (commute_T n f).eq set_option linter.uppercaseLean3 false in #align laurent_polynomial.T_mul LaurentPolynomial.T_mul /-- `trunc : R[T;T⁻¹] →+ R[X]` maps a Laurent polynomial `f` to the polynomial whose terms of nonnegative degree coincide with the ones of `f`. The terms of negative degree of `f` "vanish". `trunc` is a left-inverse to `Polynomial.toLaurent`. -/ def trunc : R[T;T⁻¹] →+ R[X] := (toFinsuppIso R).symm.toAddMonoidHom.comp <| comapDomain.addMonoidHom fun _ _ => Int.ofNat.inj #align laurent_polynomial.trunc LaurentPolynomial.trunc @[simp] theorem trunc_C_mul_T (n : ℤ) (r : R) : trunc (C r * T n) = ite (0 ≤ n) (monomial n.toNat r) 0 := by apply (toFinsuppIso R).injective rw [← single_eq_C_mul_T, trunc, AddMonoidHom.coe_comp, Function.comp_apply] -- Porting note (#10691): was `rw` erw [comapDomain.addMonoidHom_apply Int.ofNat_injective] rw [toFinsuppIso_apply] -- Porting note: rewrote proof below relative to mathlib3. by_cases n0 : 0 ≤ n · lift n to ℕ using n0 erw [comapDomain_single] simp only [Nat.cast_nonneg, Int.toNat_ofNat, ite_true, toFinsupp_monomial] · lift -n to ℕ using (neg_pos.mpr (not_le.mp n0)).le with m rw [toFinsupp_inj, if_neg n0] ext a have := ((not_le.mp n0).trans_le (Int.ofNat_zero_le a)).ne simp only [coeff_ofFinsupp, comapDomain_apply, Int.ofNat_eq_coe, coeff_zero, single_eq_of_ne this] set_option linter.uppercaseLean3 false in #align laurent_polynomial.trunc_C_mul_T LaurentPolynomial.trunc_C_mul_T @[simp] theorem leftInverse_trunc_toLaurent : Function.LeftInverse (trunc : R[T;T⁻¹] → R[X]) Polynomial.toLaurent := by refine fun f => f.induction_on' ?_ ?_ · intro f g hf hg simp only [hf, hg, _root_.map_add] · intro n r simp only [Polynomial.toLaurent_C_mul_T, trunc_C_mul_T, Int.natCast_nonneg, Int.toNat_natCast, if_true] #align laurent_polynomial.left_inverse_trunc_to_laurent LaurentPolynomial.leftInverse_trunc_toLaurent @[simp] theorem _root_.Polynomial.trunc_toLaurent (f : R[X]) : trunc (toLaurent f) = f := leftInverse_trunc_toLaurent _ #align polynomial.trunc_to_laurent Polynomial.trunc_toLaurent theorem _root_.Polynomial.toLaurent_injective : Function.Injective (Polynomial.toLaurent : R[X] → R[T;T⁻¹]) := leftInverse_trunc_toLaurent.injective #align polynomial.to_laurent_injective Polynomial.toLaurent_injective @[simp] theorem _root_.Polynomial.toLaurent_inj (f g : R[X]) : toLaurent f = toLaurent g ↔ f = g := ⟨fun h => Polynomial.toLaurent_injective h, congr_arg _⟩ #align polynomial.to_laurent_inj Polynomial.toLaurent_inj theorem _root_.Polynomial.toLaurent_ne_zero {f : R[X]} : f ≠ 0 ↔ toLaurent f ≠ 0 := (map_ne_zero_iff _ Polynomial.toLaurent_injective).symm #align polynomial.to_laurent_ne_zero Polynomial.toLaurent_ne_zero theorem exists_T_pow (f : R[T;T⁻¹]) : ∃ (n : ℕ) (f' : R[X]), toLaurent f' = f * T n := by refine f.induction_on' ?_ fun n a => ?_ <;> clear f · rintro f g ⟨m, fn, hf⟩ ⟨n, gn, hg⟩ refine ⟨m + n, fn * X ^ n + gn * X ^ m, ?_⟩ simp only [hf, hg, add_mul, add_comm (n : ℤ), map_add, map_mul, Polynomial.toLaurent_X_pow, mul_T_assoc, Int.ofNat_add] · cases' n with n n · exact ⟨0, Polynomial.C a * X ^ n, by simp⟩ · refine ⟨n + 1, Polynomial.C a, ?_⟩ simp only [Int.negSucc_eq, Polynomial.toLaurent_C, Int.ofNat_succ, mul_T_assoc, add_left_neg, T_zero, mul_one] set_option linter.uppercaseLean3 false in #align laurent_polynomial.exists_T_pow LaurentPolynomial.exists_T_pow /-- This is a version of `exists_T_pow` stated as an induction principle. -/ @[elab_as_elim] theorem induction_on_mul_T {Q : R[T;T⁻¹] → Prop} (f : R[T;T⁻¹]) (Qf : ∀ {f : R[X]} {n : ℕ}, Q (toLaurent f * T (-n))) : Q f := by rcases f.exists_T_pow with ⟨n, f', hf⟩ rw [← mul_one f, ← T_zero, ← Nat.cast_zero, ← Nat.sub_self n, Nat.cast_sub rfl.le, T_sub, ← mul_assoc, ← hf] exact Qf set_option linter.uppercaseLean3 false in #align laurent_polynomial.induction_on_mul_T LaurentPolynomial.induction_on_mul_T /-- Suppose that `Q` is a statement about Laurent polynomials such that * `Q` is true on *ordinary* polynomials; * `Q (f * T)` implies `Q f`; it follow that `Q` is true on all Laurent polynomials. -/ theorem reduce_to_polynomial_of_mul_T (f : R[T;T⁻¹]) {Q : R[T;T⁻¹] → Prop} (Qf : ∀ f : R[X], Q (toLaurent f)) (QT : ∀ f, Q (f * T 1) → Q f) : Q f := by induction' f using LaurentPolynomial.induction_on_mul_T with f n induction' n with n hn · simpa only [Nat.zero_eq, Nat.cast_zero, neg_zero, T_zero, mul_one] using Qf _ · convert QT _ _ simpa using hn set_option linter.uppercaseLean3 false in #align laurent_polynomial.reduce_to_polynomial_of_mul_T LaurentPolynomial.reduce_to_polynomial_of_mul_T section Support theorem support_C_mul_T (a : R) (n : ℤ) : Finsupp.support (C a * T n) ⊆ {n} := by -- Porting note: was -- simpa only [← single_eq_C_mul_T] using support_single_subset rw [← single_eq_C_mul_T] exact support_single_subset set_option linter.uppercaseLean3 false in #align laurent_polynomial.support_C_mul_T LaurentPolynomial.support_C_mul_T theorem support_C_mul_T_of_ne_zero {a : R} (a0 : a ≠ 0) (n : ℤ) : Finsupp.support (C a * T n) = {n} := by rw [← single_eq_C_mul_T] exact support_single_ne_zero _ a0 set_option linter.uppercaseLean3 false in #align laurent_polynomial.support_C_mul_T_of_ne_zero LaurentPolynomial.support_C_mul_T_of_ne_zero /-- The support of a polynomial `f` is a finset in `ℕ`. The lemma `toLaurent_support f` shows that the support of `f.toLaurent` is the same finset, but viewed in `ℤ` under the natural inclusion `ℕ ↪ ℤ`. -/
Mathlib/Algebra/Polynomial/Laurent.lean
461
478
theorem toLaurent_support (f : R[X]) : f.toLaurent.support = f.support.map Nat.castEmbedding := by
generalize hd : f.support = s revert f refine Finset.induction_on s ?_ ?_ <;> clear s · simp (config := { contextual := true }) only [Polynomial.support_eq_empty, map_zero, Finsupp.support_zero, eq_self_iff_true, imp_true_iff, Finset.map_empty, Finsupp.support_eq_empty] · intro a s as hf f fs have : (erase a f).toLaurent.support = s.map Nat.castEmbedding := by refine hf (f.erase a) ?_ simp only [fs, Finset.erase_eq_of_not_mem as, Polynomial.support_erase, Finset.erase_insert_eq_erase] rw [← monomial_add_erase f a, Finset.map_insert, ← this, map_add, Polynomial.toLaurent_C_mul_T, support_add_eq, Finset.insert_eq] · congr exact support_C_mul_T_of_ne_zero (Polynomial.mem_support_iff.mp (by simp [fs])) _ · rw [this] exact Disjoint.mono_left (support_C_mul_T _ _) (by simpa)
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jannis Limperg, Mario Carneiro -/ import Batteries.Classes.Order import Batteries.Control.ForInStep.Basic namespace Batteries namespace BinomialHeap namespace Imp /-- A `HeapNode` is one of the internal nodes of the binomial heap. It is always a perfect binary tree, with the depth of the tree stored in the `Heap`. However the interpretation of the two pointers is different: we view the `child` as going to the first child of this node, and `sibling` goes to the next sibling of this tree. So it actually encodes a forest where each node has children `node.child`, `node.child.sibling`, `node.child.sibling.sibling`, etc. Each edge in this forest denotes a `le a b` relation that has been checked, so the root is smaller than everything else under it. -/ inductive HeapNode (α : Type u) where /-- An empty forest, which has depth `0`. -/ | nil : HeapNode α /-- A forest of rank `r + 1` consists of a root `a`, a forest `child` of rank `r` elements greater than `a`, and another forest `sibling` of rank `r`. -/ | node (a : α) (child sibling : HeapNode α) : HeapNode α deriving Repr /-- The "real size" of the node, counting up how many values of type `α` are stored. This is `O(n)` and is intended mainly for specification purposes. For a well formed `HeapNode` the size is always `2^n - 1` where `n` is the depth. -/ @[simp] def HeapNode.realSize : HeapNode α → Nat | .nil => 0 | .node _ c s => c.realSize + 1 + s.realSize /-- A node containing a single element `a`. -/ def HeapNode.singleton (a : α) : HeapNode α := .node a .nil .nil /-- `O(log n)`. The rank, or the number of trees in the forest. It is also the depth of the forest. -/ def HeapNode.rank : HeapNode α → Nat | .nil => 0 | .node _ _ s => s.rank + 1 /-- Tail-recursive version of `HeapNode.rank`. -/ @[inline] private def HeapNode.rankTR (s : HeapNode α) : Nat := go s 0 where /-- Computes `s.rank + r` -/ go : HeapNode α → Nat → Nat | .nil, r => r | .node _ _ s, r => go s (r + 1) @[csimp] private theorem HeapNode.rankTR_eq : @rankTR = @rank := by funext α s; exact go s 0 where go {α} : ∀ s n, @rankTR.go α s n = rank s + n | .nil, _ => (Nat.zero_add ..).symm | .node .., _ => by simp_arith only [rankTR.go, go, rank] /-- A `Heap` is the top level structure in a binomial heap. It consists of a forest of `HeapNode`s with strictly increasing ranks. -/ inductive Heap (α : Type u) where /-- An empty heap. -/ | nil : Heap α /-- A cons node contains a tree of root `val`, children `node` and rank `rank`, and then `next` which is the rest of the forest. -/ | cons (rank : Nat) (val : α) (node : HeapNode α) (next : Heap α) : Heap α deriving Repr /-- `O(n)`. The "real size" of the heap, counting up how many values of type `α` are stored. This is intended mainly for specification purposes. Prefer `Heap.size`, which is the same for well formed heaps. -/ @[simp] def Heap.realSize : Heap α → Nat | .nil => 0 | .cons _ _ c s => c.realSize + 1 + s.realSize /-- `O(log n)`. The number of elements in the heap. -/ def Heap.size : Heap α → Nat | .nil => 0 | .cons r _ _ s => 1 <<< r + s.size /-- `O(1)`. Is the heap empty? -/ @[inline] def Heap.isEmpty : Heap α → Bool | .nil => true | _ => false /-- `O(1)`. The heap containing a single value `a`. -/ @[inline] def Heap.singleton (a : α) : Heap α := .cons 0 a .nil .nil /-- `O(1)`. Auxiliary for `Heap.merge`: Is the minimum rank in `Heap` strictly larger than `n`? -/ def Heap.rankGT : Heap α → Nat → Prop | .nil, _ => True | .cons r .., n => n < r instance : Decidable (Heap.rankGT s n) := match s with | .nil => inferInstanceAs (Decidable True) | .cons .. => inferInstanceAs (Decidable (_ < _)) /-- `O(log n)`. The number of trees in the forest. -/ @[simp] def Heap.length : Heap α → Nat | .nil => 0 | .cons _ _ _ r => r.length + 1 /-- `O(1)`. Auxiliary for `Heap.merge`: combines two heap nodes of the same rank into one with the next larger rank. -/ @[inline] def combine (le : α → α → Bool) (a₁ a₂ : α) (n₁ n₂ : HeapNode α) : α × HeapNode α := if le a₁ a₂ then (a₁, .node a₂ n₂ n₁) else (a₂, .node a₁ n₁ n₂) /-- Merge two forests of binomial trees. The forests are assumed to be ordered by rank and `merge` maintains this invariant. -/ @[specialize] def Heap.merge (le : α → α → Bool) : Heap α → Heap α → Heap α | .nil, h => h | h, .nil => h | s₁@(.cons r₁ a₁ n₁ t₁), s₂@(.cons r₂ a₂ n₂ t₂) => if r₁ < r₂ then .cons r₁ a₁ n₁ (merge le t₁ s₂) else if r₂ < r₁ then .cons r₂ a₂ n₂ (merge le s₁ t₂) else let (a, n) := combine le a₁ a₂ n₁ n₂ let r := r₁ + 1 if t₁.rankGT r then if t₂.rankGT r then .cons r a n (merge le t₁ t₂) else merge le (.cons r a n t₁) t₂ else if t₂.rankGT r then merge le t₁ (.cons r a n t₂) else .cons r a n (merge le t₁ t₂) termination_by s₁ s₂ => s₁.length + s₂.length /-- `O(log n)`. Convert a `HeapNode` to a `Heap` by reversing the order of the nodes along the `sibling` spine. -/ def HeapNode.toHeap (s : HeapNode α) : Heap α := go s s.rank .nil where /-- Computes `s.toHeap ++ res` tail-recursively, assuming `n = s.rank`. -/ go : HeapNode α → Nat → Heap α → Heap α | .nil, _, res => res | .node a c s, n, res => go s (n - 1) (.cons (n - 1) a c res) /-- `O(log n)`. Get the smallest element in the heap, including the passed in value `a`. -/ @[specialize] def Heap.headD (le : α → α → Bool) (a : α) : Heap α → α | .nil => a | .cons _ b _ hs => headD le (if le a b then a else b) hs /-- `O(log n)`. Get the smallest element in the heap, if it has an element. -/ @[inline] def Heap.head? (le : α → α → Bool) : Heap α → Option α | .nil => none | .cons _ h _ hs => some <| headD le h hs /-- The return type of `FindMin`, which encodes various quantities needed to reconstruct the tree in `deleteMin`. -/ structure FindMin (α) where /-- The list of elements prior to the minimum element, encoded as a "difference list". -/ before : Heap α → Heap α := id /-- The minimum element. -/ val : α /-- The children of the minimum element. -/ node : HeapNode α /-- The forest after the minimum element. -/ next : Heap α /-- `O(log n)`. Find the minimum element, and return a data structure `FindMin` with information needed to reconstruct the rest of the binomial heap. -/ @[specialize] def Heap.findMin (le : α → α → Bool) (k : Heap α → Heap α) : Heap α → FindMin α → FindMin α | .nil, res => res | .cons r a c s, res => -- It is important that we check `le res.val a` here, not the other way -- around. This ensures that head? and findMin find the same element even -- when we have `le res.val a` and `le a res.val` (i.e. le is not antisymmetric). findMin le (k ∘ .cons r a c) s <| if le res.val a then res else ⟨k, a, c, s⟩ /-- `O(log n)`. Find and remove the the minimum element from the binomial heap. -/ def Heap.deleteMin (le : α → α → Bool) : Heap α → Option (α × Heap α) | .nil => none | .cons r a c s => let { before, val, node, next } := findMin le (.cons r a c) s ⟨id, a, c, s⟩ some (val, node.toHeap.merge le (before next)) /-- `O(log n)`. Get the tail of the binomial heap after removing the minimum element. -/ @[inline] def Heap.tail? (le : α → α → Bool) (h : Heap α) : Option (Heap α) := deleteMin le h |>.map (·.snd) /-- `O(log n)`. Remove the minimum element of the heap. -/ @[inline] def Heap.tail (le : α → α → Bool) (h : Heap α) : Heap α := tail? le h |>.getD .nil theorem Heap.realSize_merge (le) (s₁ s₂ : Heap α) : (s₁.merge le s₂).realSize = s₁.realSize + s₂.realSize := by unfold merge; split · simp · simp · next r₁ a₁ n₁ t₁ r₂ a₂ n₂ t₂ => have IH₁ r a n := realSize_merge le t₁ (cons r a n t₂) have IH₂ r a n := realSize_merge le (cons r a n t₁) t₂ have IH₃ := realSize_merge le t₁ t₂ split; · simp [IH₁, Nat.add_assoc] split; · simp [IH₂, Nat.add_assoc, Nat.add_left_comm] split; simp only; rename_i a n eq have : n.realSize = n₁.realSize + 1 + n₂.realSize := by rw [combine] at eq; split at eq <;> cases eq <;> simp [Nat.add_assoc, Nat.add_left_comm, Nat.add_comm] split <;> split <;> simp [IH₁, IH₂, IH₃, this, Nat.add_assoc, Nat.add_left_comm] termination_by s₁.length + s₂.length private def FindMin.HasSize (res : FindMin α) (n : Nat) : Prop := ∃ m, (∀ s, (res.before s).realSize = m + s.realSize) ∧ n = m + res.node.realSize + res.next.realSize + 1 private theorem Heap.realSize_findMin {s : Heap α} (m) (hk : ∀ s, (k s).realSize = m + s.realSize) (eq : n = m + s.realSize) (hres : res.HasSize n) : (s.findMin le k res).HasSize n := match s with | .nil => hres | .cons r a c s => by simp [findMin] refine realSize_findMin (m + c.realSize + 1) (by simp [hk, Nat.add_assoc]) (by simp [eq, Nat.add_assoc]) ?_ split · exact hres · exact ⟨m, hk, by simp [eq, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm]⟩ theorem HeapNode.realSize_toHeap (s : HeapNode α) : s.toHeap.realSize = s.realSize := go s where go {n res} : ∀ s : HeapNode α, (toHeap.go s n res).realSize = s.realSize + res.realSize | .nil => (Nat.zero_add _).symm | .node a c s => by simp [toHeap.go, go, Nat.add_assoc, Nat.add_left_comm]
.lake/packages/batteries/Batteries/Data/BinomialHeap/Basic.lean
247
257
theorem Heap.realSize_deleteMin {s : Heap α} (eq : s.deleteMin le = some (a, s')) : s.realSize = s'.realSize + 1 := by
cases s with cases eq | cons r a c s => ?_ have : (s.findMin le (cons r a c) ⟨id, a, c, s⟩).HasSize (c.realSize + s.realSize + 1) := Heap.realSize_findMin (c.realSize + 1) (by simp) (Nat.add_right_comm ..) ⟨0, by simp⟩ revert this match s.findMin le (cons r a c) ⟨id, a, c, s⟩ with | { before, val, node, next } => intro ⟨m, ih₁, ih₂⟩; dsimp only at ih₁ ih₂ rw [realSize, Nat.add_right_comm, ih₂] simp only [realSize_merge, HeapNode.realSize_toHeap, ih₁, Nat.add_assoc, Nat.add_left_comm]
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Balanced import Mathlib.CategoryTheory.Limits.EssentiallySmall import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms import Mathlib.CategoryTheory.Subobject.Lattice import Mathlib.CategoryTheory.Subobject.WellPowered import Mathlib.Data.Set.Opposite import Mathlib.Data.Set.Subsingleton #align_import category_theory.generator from "leanprover-community/mathlib"@"f187f1074fa1857c94589cc653c786cadc4c35ff" /-! # Separating and detecting sets There are several non-equivalent notions of a generator of a category. Here, we consider two of them: * We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`. * We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms, i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism. There are, of course, also the dual notions of coseparating and codetecting sets. ## Main results We * define predicates `IsSeparating`, `IsCoseparating`, `IsDetecting` and `IsCodetecting` on sets of objects; * show that separating and coseparating are dual notions; * show that detecting and codetecting are dual notions; * show that if `C` has equalizers, then detecting implies separating; * show that if `C` has coequalizers, then codetecting implies separating; * show that if `C` is balanced, then separating implies detecting and coseparating implies codetecting; * show that `∅` is separating if and only if `∅` is coseparating if and only if `C` is thin; * show that `∅` is detecting if and only if `∅` is codetecting if and only if `C` is a groupoid; * define predicates `IsSeparator`, `IsCoseparator`, `IsDetector` and `IsCodetector` as the singleton counterparts to the definitions for sets above and restate the above results in this situation; * show that `G` is a separator if and only if `coyoneda.obj (op G)` is faithful (and the dual); * show that `G` is a detector if and only if `coyoneda.obj (op G)` reflects isomorphisms (and the dual). ## Future work * We currently don't have any examples yet. * We will want typeclasses `HasSeparator C` and similar. -/ universe w v₁ v₂ u₁ u₂ open CategoryTheory.Limits Opposite namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] /-- We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`. -/ def IsSeparating (𝒢 : Set C) : Prop := ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : G ⟶ X), h ≫ f = h ≫ g) → f = g #align category_theory.is_separating CategoryTheory.IsSeparating /-- We say that `𝒢` is a coseparating set if the functors `C(-, G)` for `G ∈ 𝒢` are collectively faithful, i.e., if `f ≫ h = g ≫ h` for all `h` with codomain in `𝒢` implies `f = g`. -/ def IsCoseparating (𝒢 : Set C) : Prop := ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : Y ⟶ G), f ≫ h = g ≫ h) → f = g #align category_theory.is_coseparating CategoryTheory.IsCoseparating /-- We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms, i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism. -/ def IsDetecting (𝒢 : Set C) : Prop := ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : G ⟶ Y), ∃! h' : G ⟶ X, h' ≫ f = h) → IsIso f #align category_theory.is_detecting CategoryTheory.IsDetecting /-- We say that `𝒢` is a codetecting set if the functors `C(-, G)` collectively reflect isomorphisms, i.e., if any `h` with codomain in `G` uniquely factors through `f`, then `f` is an isomorphism. -/ def IsCodetecting (𝒢 : Set C) : Prop := ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : X ⟶ G), ∃! h' : Y ⟶ G, f ≫ h' = h) → IsIso f #align category_theory.is_codetecting CategoryTheory.IsCodetecting section Dual theorem isSeparating_op_iff (𝒢 : Set C) : IsSeparating 𝒢.op ↔ IsCoseparating 𝒢 := by refine ⟨fun h𝒢 X Y f g hfg => ?_, fun h𝒢 X Y f g hfg => ?_⟩ · refine Quiver.Hom.op_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.unop_inj ?_) simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ (Set.mem_op.1 hG) _ · refine Quiver.Hom.unop_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.op_inj ?_) simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ (Set.op_mem_op.2 hG) _ #align category_theory.is_separating_op_iff CategoryTheory.isSeparating_op_iff theorem isCoseparating_op_iff (𝒢 : Set C) : IsCoseparating 𝒢.op ↔ IsSeparating 𝒢 := by refine ⟨fun h𝒢 X Y f g hfg => ?_, fun h𝒢 X Y f g hfg => ?_⟩ · refine Quiver.Hom.op_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.unop_inj ?_) simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ (Set.mem_op.1 hG) _ · refine Quiver.Hom.unop_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.op_inj ?_) simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ (Set.op_mem_op.2 hG) _ #align category_theory.is_coseparating_op_iff CategoryTheory.isCoseparating_op_iff theorem isCoseparating_unop_iff (𝒢 : Set Cᵒᵖ) : IsCoseparating 𝒢.unop ↔ IsSeparating 𝒢 := by rw [← isSeparating_op_iff, Set.unop_op] #align category_theory.is_coseparating_unop_iff CategoryTheory.isCoseparating_unop_iff theorem isSeparating_unop_iff (𝒢 : Set Cᵒᵖ) : IsSeparating 𝒢.unop ↔ IsCoseparating 𝒢 := by rw [← isCoseparating_op_iff, Set.unop_op] #align category_theory.is_separating_unop_iff CategoryTheory.isSeparating_unop_iff theorem isDetecting_op_iff (𝒢 : Set C) : IsDetecting 𝒢.op ↔ IsCodetecting 𝒢 := by refine ⟨fun h𝒢 X Y f hf => ?_, fun h𝒢 X Y f hf => ?_⟩ · refine (isIso_op_iff _).1 (h𝒢 _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (unop G) (Set.mem_op.1 hG) h.unop exact ⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩ · refine (isIso_unop_iff _).1 (h𝒢 _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (op G) (Set.op_mem_op.2 hG) h.op refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩ exact Quiver.Hom.unop_inj (by simpa only using hy) #align category_theory.is_detecting_op_iff CategoryTheory.isDetecting_op_iff theorem isCodetecting_op_iff (𝒢 : Set C) : IsCodetecting 𝒢.op ↔ IsDetecting 𝒢 := by refine ⟨fun h𝒢 X Y f hf => ?_, fun h𝒢 X Y f hf => ?_⟩ · refine (isIso_op_iff _).1 (h𝒢 _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (unop G) (Set.mem_op.1 hG) h.unop exact ⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩ · refine (isIso_unop_iff _).1 (h𝒢 _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (op G) (Set.op_mem_op.2 hG) h.op refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩ exact Quiver.Hom.unop_inj (by simpa only using hy) #align category_theory.is_codetecting_op_iff CategoryTheory.isCodetecting_op_iff theorem isDetecting_unop_iff (𝒢 : Set Cᵒᵖ) : IsDetecting 𝒢.unop ↔ IsCodetecting 𝒢 := by rw [← isCodetecting_op_iff, Set.unop_op] #align category_theory.is_detecting_unop_iff CategoryTheory.isDetecting_unop_iff theorem isCodetecting_unop_iff {𝒢 : Set Cᵒᵖ} : IsCodetecting 𝒢.unop ↔ IsDetecting 𝒢 := by rw [← isDetecting_op_iff, Set.unop_op] #align category_theory.is_codetecting_unop_iff CategoryTheory.isCodetecting_unop_iff end Dual theorem IsDetecting.isSeparating [HasEqualizers C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) : IsSeparating 𝒢 := fun _ _ f g hfg => have : IsIso (equalizer.ι f g) := h𝒢 _ fun _ hG _ => equalizer.existsUnique _ (hfg _ hG _) eq_of_epi_equalizer #align category_theory.is_detecting.is_separating CategoryTheory.IsDetecting.isSeparating section theorem IsCodetecting.isCoseparating [HasCoequalizers C] {𝒢 : Set C} : IsCodetecting 𝒢 → IsCoseparating 𝒢 := by simpa only [← isSeparating_op_iff, ← isDetecting_op_iff] using IsDetecting.isSeparating #align category_theory.is_codetecting.is_coseparating CategoryTheory.IsCodetecting.isCoseparating end theorem IsSeparating.isDetecting [Balanced C] {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) : IsDetecting 𝒢 := by intro X Y f hf refine (isIso_iff_mono_and_epi _).2 ⟨⟨fun g h hgh => h𝒢 _ _ fun G hG i => ?_⟩, ⟨fun g h hgh => ?_⟩⟩ · obtain ⟨t, -, ht⟩ := hf G hG (i ≫ g ≫ f) rw [ht (i ≫ g) (Category.assoc _ _ _), ht (i ≫ h) (hgh.symm ▸ Category.assoc _ _ _)] · refine h𝒢 _ _ fun G hG i => ?_ obtain ⟨t, rfl, -⟩ := hf G hG i rw [Category.assoc, hgh, Category.assoc] #align category_theory.is_separating.is_detecting CategoryTheory.IsSeparating.isDetecting section attribute [local instance] balanced_opposite theorem IsCoseparating.isCodetecting [Balanced C] {𝒢 : Set C} : IsCoseparating 𝒢 → IsCodetecting 𝒢 := by simpa only [← isDetecting_op_iff, ← isSeparating_op_iff] using IsSeparating.isDetecting #align category_theory.is_coseparating.is_codetecting CategoryTheory.IsCoseparating.isCodetecting end theorem isDetecting_iff_isSeparating [HasEqualizers C] [Balanced C] (𝒢 : Set C) : IsDetecting 𝒢 ↔ IsSeparating 𝒢 := ⟨IsDetecting.isSeparating, IsSeparating.isDetecting⟩ #align category_theory.is_detecting_iff_is_separating CategoryTheory.isDetecting_iff_isSeparating theorem isCodetecting_iff_isCoseparating [HasCoequalizers C] [Balanced C] {𝒢 : Set C} : IsCodetecting 𝒢 ↔ IsCoseparating 𝒢 := ⟨IsCodetecting.isCoseparating, IsCoseparating.isCodetecting⟩ #align category_theory.is_codetecting_iff_is_coseparating CategoryTheory.isCodetecting_iff_isCoseparating section Mono theorem IsSeparating.mono {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) : IsSeparating ℋ := fun _ _ _ _ hfg => h𝒢 _ _ fun _ hG _ => hfg _ (h𝒢ℋ hG) _ #align category_theory.is_separating.mono CategoryTheory.IsSeparating.mono theorem IsCoseparating.mono {𝒢 : Set C} (h𝒢 : IsCoseparating 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) : IsCoseparating ℋ := fun _ _ _ _ hfg => h𝒢 _ _ fun _ hG _ => hfg _ (h𝒢ℋ hG) _ #align category_theory.is_coseparating.mono CategoryTheory.IsCoseparating.mono theorem IsDetecting.mono {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) : IsDetecting ℋ := fun _ _ _ hf => h𝒢 _ fun _ hG _ => hf _ (h𝒢ℋ hG) _ #align category_theory.is_detecting.mono CategoryTheory.IsDetecting.mono theorem IsCodetecting.mono {𝒢 : Set C} (h𝒢 : IsCodetecting 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) : IsCodetecting ℋ := fun _ _ _ hf => h𝒢 _ fun _ hG _ => hf _ (h𝒢ℋ hG) _ #align category_theory.is_codetecting.mono CategoryTheory.IsCodetecting.mono end Mono section Empty theorem thin_of_isSeparating_empty (h : IsSeparating (∅ : Set C)) : Quiver.IsThin C := fun _ _ => ⟨fun _ _ => h _ _ fun _ => False.elim⟩ #align category_theory.thin_of_is_separating_empty CategoryTheory.thin_of_isSeparating_empty theorem isSeparating_empty_of_thin [Quiver.IsThin C] : IsSeparating (∅ : Set C) := fun _ _ _ _ _ => Subsingleton.elim _ _ #align category_theory.is_separating_empty_of_thin CategoryTheory.isSeparating_empty_of_thin theorem thin_of_isCoseparating_empty (h : IsCoseparating (∅ : Set C)) : Quiver.IsThin C := fun _ _ => ⟨fun _ _ => h _ _ fun _ => False.elim⟩ #align category_theory.thin_of_is_coseparating_empty CategoryTheory.thin_of_isCoseparating_empty theorem isCoseparating_empty_of_thin [Quiver.IsThin C] : IsCoseparating (∅ : Set C) := fun _ _ _ _ _ => Subsingleton.elim _ _ #align category_theory.is_coseparating_empty_of_thin CategoryTheory.isCoseparating_empty_of_thin theorem groupoid_of_isDetecting_empty (h : IsDetecting (∅ : Set C)) {X Y : C} (f : X ⟶ Y) : IsIso f := h _ fun _ => False.elim #align category_theory.groupoid_of_is_detecting_empty CategoryTheory.groupoid_of_isDetecting_empty theorem isDetecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), IsIso f] : IsDetecting (∅ : Set C) := fun _ _ _ _ => inferInstance #align category_theory.is_detecting_empty_of_groupoid CategoryTheory.isDetecting_empty_of_groupoid theorem groupoid_of_isCodetecting_empty (h : IsCodetecting (∅ : Set C)) {X Y : C} (f : X ⟶ Y) : IsIso f := h _ fun _ => False.elim #align category_theory.groupoid_of_is_codetecting_empty CategoryTheory.groupoid_of_isCodetecting_empty theorem isCodetecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), IsIso f] : IsCodetecting (∅ : Set C) := fun _ _ _ _ => inferInstance #align category_theory.is_codetecting_empty_of_groupoid CategoryTheory.isCodetecting_empty_of_groupoid end Empty theorem isSeparating_iff_epi (𝒢 : Set C) [∀ A : C, HasCoproduct fun f : ΣG : 𝒢, (G : C) ⟶ A => (f.1 : C)] : IsSeparating 𝒢 ↔ ∀ A : C, Epi (Sigma.desc (@Sigma.snd 𝒢 fun G => (G : C) ⟶ A)) := by refine ⟨fun h A => ⟨fun u v huv => h _ _ fun G hG f => ?_⟩, fun h X Y f g hh => ?_⟩ · simpa using Sigma.ι (fun f : ΣG : 𝒢, (G : C) ⟶ A => (f.1 : C)) ⟨⟨G, hG⟩, f⟩ ≫= huv · haveI := h X refine (cancel_epi (Sigma.desc (@Sigma.snd 𝒢 fun G => (G : C) ⟶ X))).1 (colimit.hom_ext fun j => ?_) simpa using hh j.as.1.1 j.as.1.2 j.as.2 #align category_theory.is_separating_iff_epi CategoryTheory.isSeparating_iff_epi theorem isCoseparating_iff_mono (𝒢 : Set C) [∀ A : C, HasProduct fun f : ΣG : 𝒢, A ⟶ (G : C) => (f.1 : C)] : IsCoseparating 𝒢 ↔ ∀ A : C, Mono (Pi.lift (@Sigma.snd 𝒢 fun G => A ⟶ (G : C))) := by refine ⟨fun h A => ⟨fun u v huv => h _ _ fun G hG f => ?_⟩, fun h X Y f g hh => ?_⟩ · simpa using huv =≫ Pi.π (fun f : ΣG : 𝒢, A ⟶ (G : C) => (f.1 : C)) ⟨⟨G, hG⟩, f⟩ · haveI := h Y refine (cancel_mono (Pi.lift (@Sigma.snd 𝒢 fun G => Y ⟶ (G : C)))).1 (limit.hom_ext fun j => ?_) simpa using hh j.as.1.1 j.as.1.2 j.as.2 #align category_theory.is_coseparating_iff_mono CategoryTheory.isCoseparating_iff_mono /-- An ingredient of the proof of the Special Adjoint Functor Theorem: a complete well-powered category with a small coseparating set has an initial object. In fact, it follows from the Special Adjoint Functor Theorem that `C` is already cocomplete, see `hasColimits_of_hasLimits_of_isCoseparating`. -/ theorem hasInitial_of_isCoseparating [WellPowered C] [HasLimits C] {𝒢 : Set C} [Small.{v₁} 𝒢] (h𝒢 : IsCoseparating 𝒢) : HasInitial C := by haveI : HasProductsOfShape 𝒢 C := hasProductsOfShape_of_small C 𝒢 haveI := fun A => hasProductsOfShape_of_small.{v₁} C (ΣG : 𝒢, A ⟶ (G : C)) letI := completeLatticeOfCompleteSemilatticeInf (Subobject (piObj (Subtype.val : 𝒢 → C))) suffices ∀ A : C, Unique (((⊥ : Subobject (piObj (Subtype.val : 𝒢 → C))) : C) ⟶ A) by exact hasInitial_of_unique ((⊥ : Subobject (piObj (Subtype.val : 𝒢 → C))) : C) refine fun A => ⟨⟨?_⟩, fun f => ?_⟩ · let s := Pi.lift fun f : ΣG : 𝒢, A ⟶ (G : C) => id (Pi.π (Subtype.val : 𝒢 → C)) f.1 let t := Pi.lift (@Sigma.snd 𝒢 fun G => A ⟶ (G : C)) haveI : Mono t := (isCoseparating_iff_mono 𝒢).1 h𝒢 A exact Subobject.ofLEMk _ (pullback.fst : pullback s t ⟶ _) bot_le ≫ pullback.snd · suffices ∀ (g : Subobject.underlying.obj ⊥ ⟶ A), f = g by apply this intro g suffices IsSplitEpi (equalizer.ι f g) by exact eq_of_epi_equalizer exact IsSplitEpi.mk' ⟨Subobject.ofLEMk _ (equalizer.ι f g ≫ Subobject.arrow _) bot_le, by ext simp⟩ #align category_theory.has_initial_of_is_coseparating CategoryTheory.hasInitial_of_isCoseparating /-- An ingredient of the proof of the Special Adjoint Functor Theorem: a cocomplete well-copowered category with a small separating set has a terminal object. In fact, it follows from the Special Adjoint Functor Theorem that `C` is already complete, see `hasLimits_of_hasColimits_of_isSeparating`. -/ theorem hasTerminal_of_isSeparating [WellPowered Cᵒᵖ] [HasColimits C] {𝒢 : Set C} [Small.{v₁} 𝒢] (h𝒢 : IsSeparating 𝒢) : HasTerminal C := by haveI : Small.{v₁} 𝒢.op := small_of_injective (Set.opEquiv_self 𝒢).injective haveI : HasInitial Cᵒᵖ := hasInitial_of_isCoseparating ((isCoseparating_op_iff _).2 h𝒢) exact hasTerminal_of_hasInitial_op #align category_theory.has_terminal_of_is_separating CategoryTheory.hasTerminal_of_isSeparating section WellPowered namespace Subobject theorem eq_of_le_of_isDetecting {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {X : C} (P Q : Subobject X) (h₁ : P ≤ Q) (h₂ : ∀ G ∈ 𝒢, ∀ {f : G ⟶ X}, Q.Factors f → P.Factors f) : P = Q := by suffices IsIso (ofLE _ _ h₁) by exact le_antisymm h₁ (le_of_comm (inv (ofLE _ _ h₁)) (by simp)) refine h𝒢 _ fun G hG f => ?_ have : P.Factors (f ≫ Q.arrow) := h₂ _ hG ((factors_iff _ _).2 ⟨_, rfl⟩) refine ⟨factorThru _ _ this, ?_, fun g (hg : g ≫ _ = f) => ?_⟩ · simp only [← cancel_mono Q.arrow, Category.assoc, ofLE_arrow, factorThru_arrow] · simp only [← cancel_mono (Subobject.ofLE _ _ h₁), ← cancel_mono Q.arrow, hg, Category.assoc, ofLE_arrow, factorThru_arrow] #align category_theory.subobject.eq_of_le_of_is_detecting CategoryTheory.Subobject.eq_of_le_of_isDetecting theorem inf_eq_of_isDetecting [HasPullbacks C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {X : C} (P Q : Subobject X) (h : ∀ G ∈ 𝒢, ∀ {f : G ⟶ X}, P.Factors f → Q.Factors f) : P ⊓ Q = P := eq_of_le_of_isDetecting h𝒢 _ _ _root_.inf_le_left fun _ hG _ hf => (inf_factors _).2 ⟨hf, h _ hG hf⟩ #align category_theory.subobject.inf_eq_of_is_detecting CategoryTheory.Subobject.inf_eq_of_isDetecting theorem eq_of_isDetecting [HasPullbacks C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {X : C} (P Q : Subobject X) (h : ∀ G ∈ 𝒢, ∀ {f : G ⟶ X}, P.Factors f ↔ Q.Factors f) : P = Q := calc P = P ⊓ Q := Eq.symm <| inf_eq_of_isDetecting h𝒢 _ _ fun G hG _ hf => (h G hG).1 hf _ = Q ⊓ P := inf_comm .. _ = Q := inf_eq_of_isDetecting h𝒢 _ _ fun G hG _ hf => (h G hG).2 hf #align category_theory.subobject.eq_of_is_detecting CategoryTheory.Subobject.eq_of_isDetecting end Subobject /-- A category with pullbacks and a small detecting set is well-powered. -/ theorem wellPowered_of_isDetecting [HasPullbacks C] {𝒢 : Set C} [Small.{v₁} 𝒢] (h𝒢 : IsDetecting 𝒢) : WellPowered C := ⟨fun X => @small_of_injective _ _ _ (fun P : Subobject X => { f : ΣG : 𝒢, G.1 ⟶ X | P.Factors f.2 }) fun P Q h => Subobject.eq_of_isDetecting h𝒢 _ _ (by simpa [Set.ext_iff] using h)⟩ #align category_theory.well_powered_of_is_detecting CategoryTheory.wellPowered_of_isDetecting end WellPowered namespace StructuredArrow variable (S : D) (T : C ⥤ D) theorem isCoseparating_proj_preimage {𝒢 : Set C} (h𝒢 : IsCoseparating 𝒢) : IsCoseparating ((proj S T).obj ⁻¹' 𝒢) := by refine fun X Y f g hfg => ext _ _ (h𝒢 _ _ fun G hG h => ?_) exact congr_arg CommaMorphism.right (hfg (mk (Y.hom ≫ T.map h)) hG (homMk h rfl)) #align category_theory.structured_arrow.is_coseparating_proj_preimage CategoryTheory.StructuredArrow.isCoseparating_proj_preimage end StructuredArrow namespace CostructuredArrow variable (S : C ⥤ D) (T : D) theorem isSeparating_proj_preimage {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) : IsSeparating ((proj S T).obj ⁻¹' 𝒢) := by refine fun X Y f g hfg => ext _ _ (h𝒢 _ _ fun G hG h => ?_) exact congr_arg CommaMorphism.left (hfg (mk (S.map h ≫ X.hom)) hG (homMk h rfl)) #align category_theory.costructured_arrow.is_separating_proj_preimage CategoryTheory.CostructuredArrow.isSeparating_proj_preimage end CostructuredArrow /-- We say that `G` is a separator if the functor `C(G, -)` is faithful. -/ def IsSeparator (G : C) : Prop := IsSeparating ({G} : Set C) #align category_theory.is_separator CategoryTheory.IsSeparator /-- We say that `G` is a coseparator if the functor `C(-, G)` is faithful. -/ def IsCoseparator (G : C) : Prop := IsCoseparating ({G} : Set C) #align category_theory.is_coseparator CategoryTheory.IsCoseparator /-- We say that `G` is a detector if the functor `C(G, -)` reflects isomorphisms. -/ def IsDetector (G : C) : Prop := IsDetecting ({G} : Set C) #align category_theory.is_detector CategoryTheory.IsDetector /-- We say that `G` is a codetector if the functor `C(-, G)` reflects isomorphisms. -/ def IsCodetector (G : C) : Prop := IsCodetecting ({G} : Set C) #align category_theory.is_codetector CategoryTheory.IsCodetector section Dual theorem isSeparator_op_iff (G : C) : IsSeparator (op G) ↔ IsCoseparator G := by rw [IsSeparator, IsCoseparator, ← isSeparating_op_iff, Set.singleton_op] #align category_theory.is_separator_op_iff CategoryTheory.isSeparator_op_iff theorem isCoseparator_op_iff (G : C) : IsCoseparator (op G) ↔ IsSeparator G := by rw [IsSeparator, IsCoseparator, ← isCoseparating_op_iff, Set.singleton_op] #align category_theory.is_coseparator_op_iff CategoryTheory.isCoseparator_op_iff theorem isCoseparator_unop_iff (G : Cᵒᵖ) : IsCoseparator (unop G) ↔ IsSeparator G := by rw [IsSeparator, IsCoseparator, ← isCoseparating_unop_iff, Set.singleton_unop] #align category_theory.is_coseparator_unop_iff CategoryTheory.isCoseparator_unop_iff theorem isSeparator_unop_iff (G : Cᵒᵖ) : IsSeparator (unop G) ↔ IsCoseparator G := by rw [IsSeparator, IsCoseparator, ← isSeparating_unop_iff, Set.singleton_unop] #align category_theory.is_separator_unop_iff CategoryTheory.isSeparator_unop_iff theorem isDetector_op_iff (G : C) : IsDetector (op G) ↔ IsCodetector G := by rw [IsDetector, IsCodetector, ← isDetecting_op_iff, Set.singleton_op] #align category_theory.is_detector_op_iff CategoryTheory.isDetector_op_iff theorem isCodetector_op_iff (G : C) : IsCodetector (op G) ↔ IsDetector G := by rw [IsDetector, IsCodetector, ← isCodetecting_op_iff, Set.singleton_op] #align category_theory.is_codetector_op_iff CategoryTheory.isCodetector_op_iff theorem isCodetector_unop_iff (G : Cᵒᵖ) : IsCodetector (unop G) ↔ IsDetector G := by rw [IsDetector, IsCodetector, ← isCodetecting_unop_iff, Set.singleton_unop] #align category_theory.is_codetector_unop_iff CategoryTheory.isCodetector_unop_iff theorem isDetector_unop_iff (G : Cᵒᵖ) : IsDetector (unop G) ↔ IsCodetector G := by rw [IsDetector, IsCodetector, ← isDetecting_unop_iff, Set.singleton_unop] #align category_theory.is_detector_unop_iff CategoryTheory.isDetector_unop_iff end Dual theorem IsDetector.isSeparator [HasEqualizers C] {G : C} : IsDetector G → IsSeparator G := IsDetecting.isSeparating #align category_theory.is_detector.is_separator CategoryTheory.IsDetector.isSeparator theorem IsCodetector.isCoseparator [HasCoequalizers C] {G : C} : IsCodetector G → IsCoseparator G := IsCodetecting.isCoseparating #align category_theory.is_codetector.is_coseparator CategoryTheory.IsCodetector.isCoseparator theorem IsSeparator.isDetector [Balanced C] {G : C} : IsSeparator G → IsDetector G := IsSeparating.isDetecting #align category_theory.is_separator.is_detector CategoryTheory.IsSeparator.isDetector theorem IsCospearator.isCodetector [Balanced C] {G : C} : IsCoseparator G → IsCodetector G := IsCoseparating.isCodetecting #align category_theory.is_cospearator.is_codetector CategoryTheory.IsCospearator.isCodetector theorem isSeparator_def (G : C) : IsSeparator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g := ⟨fun hG X Y f g hfg => hG _ _ fun H hH h => by obtain rfl := Set.mem_singleton_iff.1 hH exact hfg h, fun hG X Y f g hfg => hG _ _ fun h => hfg _ (Set.mem_singleton _) _⟩ #align category_theory.is_separator_def CategoryTheory.isSeparator_def theorem IsSeparator.def {G : C} : IsSeparator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g := (isSeparator_def _).1 #align category_theory.is_separator.def CategoryTheory.IsSeparator.def theorem isCoseparator_def (G : C) : IsCoseparator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g := ⟨fun hG X Y f g hfg => hG _ _ fun H hH h => by obtain rfl := Set.mem_singleton_iff.1 hH exact hfg h, fun hG X Y f g hfg => hG _ _ fun h => hfg _ (Set.mem_singleton _) _⟩ #align category_theory.is_coseparator_def CategoryTheory.isCoseparator_def theorem IsCoseparator.def {G : C} : IsCoseparator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g := (isCoseparator_def _).1 #align category_theory.is_coseparator.def CategoryTheory.IsCoseparator.def theorem isDetector_def (G : C) : IsDetector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → IsIso f := ⟨fun hG X Y f hf => hG _ fun H hH h => by obtain rfl := Set.mem_singleton_iff.1 hH exact hf h, fun hG X Y f hf => hG _ fun h => hf _ (Set.mem_singleton _) _⟩ #align category_theory.is_detector_def CategoryTheory.isDetector_def theorem IsDetector.def {G : C} : IsDetector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → IsIso f := (isDetector_def _).1 #align category_theory.is_detector.def CategoryTheory.IsDetector.def theorem isCodetector_def (G : C) : IsCodetector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → IsIso f := ⟨fun hG X Y f hf => hG _ fun H hH h => by obtain rfl := Set.mem_singleton_iff.1 hH exact hf h, fun hG X Y f hf => hG _ fun h => hf _ (Set.mem_singleton _) _⟩ #align category_theory.is_codetector_def CategoryTheory.isCodetector_def theorem IsCodetector.def {G : C} : IsCodetector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → IsIso f := (isCodetector_def _).1 #align category_theory.is_codetector.def CategoryTheory.IsCodetector.def theorem isSeparator_iff_faithful_coyoneda_obj (G : C) : IsSeparator G ↔ (coyoneda.obj (op G)).Faithful := ⟨fun hG => ⟨fun hfg => hG.def _ _ (congr_fun hfg)⟩, fun _ => (isSeparator_def _).2 fun _ _ _ _ hfg => (coyoneda.obj (op G)).map_injective (funext hfg)⟩ #align category_theory.is_separator_iff_faithful_coyoneda_obj CategoryTheory.isSeparator_iff_faithful_coyoneda_obj theorem isCoseparator_iff_faithful_yoneda_obj (G : C) : IsCoseparator G ↔ (yoneda.obj G).Faithful := ⟨fun hG => ⟨fun hfg => Quiver.Hom.unop_inj (hG.def _ _ (congr_fun hfg))⟩, fun _ => (isCoseparator_def _).2 fun _ _ _ _ hfg => Quiver.Hom.op_inj <| (yoneda.obj G).map_injective (funext hfg)⟩ #align category_theory.is_coseparator_iff_faithful_yoneda_obj CategoryTheory.isCoseparator_iff_faithful_yoneda_obj theorem isSeparator_iff_epi (G : C) [∀ A : C, HasCoproduct fun _ : G ⟶ A => G] : IsSeparator G ↔ ∀ A : C, Epi (Sigma.desc fun f : G ⟶ A => f) := by rw [isSeparator_def] refine ⟨fun h A => ⟨fun u v huv => h _ _ fun i => ?_⟩, fun h X Y f g hh => ?_⟩ · simpa using Sigma.ι _ i ≫= huv · haveI := h X refine (cancel_epi (Sigma.desc fun f : G ⟶ X => f)).1 (colimit.hom_ext fun j => ?_) simpa using hh j.as #align category_theory.is_separator_iff_epi CategoryTheory.isSeparator_iff_epi theorem isCoseparator_iff_mono (G : C) [∀ A : C, HasProduct fun _ : A ⟶ G => G] : IsCoseparator G ↔ ∀ A : C, Mono (Pi.lift fun f : A ⟶ G => f) := by rw [isCoseparator_def] refine ⟨fun h A => ⟨fun u v huv => h _ _ fun i => ?_⟩, fun h X Y f g hh => ?_⟩ · simpa using huv =≫ Pi.π _ i · haveI := h Y refine (cancel_mono (Pi.lift fun f : Y ⟶ G => f)).1 (limit.hom_ext fun j => ?_) simpa using hh j.as #align category_theory.is_coseparator_iff_mono CategoryTheory.isCoseparator_iff_mono section ZeroMorphisms variable [HasZeroMorphisms C] theorem isSeparator_coprod (G H : C) [HasBinaryCoproduct G H] : IsSeparator (G ⨿ H) ↔ IsSeparating ({G, H} : Set C) := by refine ⟨fun h X Y u v huv => ?_, fun h => (isSeparator_def _).2 fun X Y u v huv => h _ _ fun Z hZ g => ?_⟩ · refine h.def _ _ fun g => coprod.hom_ext ?_ ?_ · simpa using huv G (by simp) (coprod.inl ≫ g) · simpa using huv H (by simp) (coprod.inr ≫ g) · simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hZ rcases hZ with (rfl | rfl) · simpa using coprod.inl ≫= huv (coprod.desc g 0) · simpa using coprod.inr ≫= huv (coprod.desc 0 g) #align category_theory.is_separator_coprod CategoryTheory.isSeparator_coprod theorem isSeparator_coprod_of_isSeparator_left (G H : C) [HasBinaryCoproduct G H] (hG : IsSeparator G) : IsSeparator (G ⨿ H) := (isSeparator_coprod _ _).2 <| IsSeparating.mono hG <| by simp #align category_theory.is_separator_coprod_of_is_separator_left CategoryTheory.isSeparator_coprod_of_isSeparator_left theorem isSeparator_coprod_of_isSeparator_right (G H : C) [HasBinaryCoproduct G H] (hH : IsSeparator H) : IsSeparator (G ⨿ H) := (isSeparator_coprod _ _).2 <| IsSeparating.mono hH <| by simp #align category_theory.is_separator_coprod_of_is_separator_right CategoryTheory.isSeparator_coprod_of_isSeparator_right
Mathlib/CategoryTheory/Generator.lean
570
578
theorem isSeparator_sigma {β : Type w} (f : β → C) [HasCoproduct f] : IsSeparator (∐ f) ↔ IsSeparating (Set.range f) := by
refine ⟨fun h X Y u v huv => ?_, fun h => (isSeparator_def _).2 fun X Y u v huv => h _ _ fun Z hZ g => ?_⟩ · refine h.def _ _ fun g => colimit.hom_ext fun b => ?_ simpa using huv (f b.as) (by simp) (colimit.ι (Discrete.functor f) _ ≫ g) · obtain ⟨b, rfl⟩ := Set.mem_range.1 hZ classical simpa using Sigma.ι f b ≫= huv (Sigma.desc (Pi.single b g))
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.Pi.Basic import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.IsomorphismClasses import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects #align_import category_theory.limits.shapes.zero_morphisms from "leanprover-community/mathlib"@"f7707875544ef1f81b32cb68c79e0e24e45a0e76" /-! # Zero morphisms and zero objects A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. (Notice this is extra structure, not merely a property.) A category "has a zero object" if it has an object which is both initial and terminal. Having a zero object provides zero morphisms, as the unique morphisms factoring through the zero object. ## References * https://en.wikipedia.org/wiki/Zero_morphism * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v u universe v' u' open CategoryTheory open CategoryTheory.Category open scoped Classical namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] variable (D : Type u') [Category.{v'} D] /-- A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. -/ class HasZeroMorphisms where /-- Every morphism space has zero -/ [zero : ∀ X Y : C, Zero (X ⟶ Y)] /-- `f` composed with `0` is `0` -/ comp_zero : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := by aesop_cat /-- `0` composed with `f` is `0` -/ zero_comp : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := by aesop_cat #align category_theory.limits.has_zero_morphisms CategoryTheory.Limits.HasZeroMorphisms #align category_theory.limits.has_zero_morphisms.comp_zero' CategoryTheory.Limits.HasZeroMorphisms.comp_zero #align category_theory.limits.has_zero_morphisms.zero_comp' CategoryTheory.Limits.HasZeroMorphisms.zero_comp attribute [instance] HasZeroMorphisms.zero variable {C} @[simp] theorem comp_zero [HasZeroMorphisms C] {X Y : C} {f : X ⟶ Y} {Z : C} : f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := HasZeroMorphisms.comp_zero f Z #align category_theory.limits.comp_zero CategoryTheory.Limits.comp_zero @[simp] theorem zero_comp [HasZeroMorphisms C] {X : C} {Y Z : C} {f : Y ⟶ Z} : (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := HasZeroMorphisms.zero_comp X f #align category_theory.limits.zero_comp CategoryTheory.Limits.zero_comp instance hasZeroMorphismsPEmpty : HasZeroMorphisms (Discrete PEmpty) where zero := by aesop_cat #align category_theory.limits.has_zero_morphisms_pempty CategoryTheory.Limits.hasZeroMorphismsPEmpty instance hasZeroMorphismsPUnit : HasZeroMorphisms (Discrete PUnit) where zero X Y := by repeat (constructor) #align category_theory.limits.has_zero_morphisms_punit CategoryTheory.Limits.hasZeroMorphismsPUnit namespace HasZeroMorphisms /-- This lemma will be immediately superseded by `ext`, below. -/ private theorem ext_aux (I J : HasZeroMorphisms C) (w : ∀ X Y : C, (I.zero X Y).zero = (J.zero X Y).zero) : I = J := by have : I.zero = J.zero := by funext X Y specialize w X Y apply congrArg Zero.mk w cases I; cases J congr · apply proof_irrel_heq · apply proof_irrel_heq -- Porting note: private def; no align /-- If you're tempted to use this lemma "in the wild", you should probably carefully consider whether you've made a mistake in allowing two instances of `HasZeroMorphisms` to exist at all. See, particularly, the note on `zeroMorphismsOfZeroObject` below. -/ theorem ext (I J : HasZeroMorphisms C) : I = J := by apply ext_aux intro X Y have : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (I.zero X Y).zero := by apply I.zero_comp X (J.zero Y Y).zero have that : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (J.zero X Y).zero := by apply J.comp_zero (I.zero X Y).zero Y rw [← this, ← that] #align category_theory.limits.has_zero_morphisms.ext CategoryTheory.Limits.HasZeroMorphisms.ext instance : Subsingleton (HasZeroMorphisms C) := ⟨ext⟩ end HasZeroMorphisms open Opposite HasZeroMorphisms instance hasZeroMorphismsOpposite [HasZeroMorphisms C] : HasZeroMorphisms Cᵒᵖ where zero X Y := ⟨(0 : unop Y ⟶ unop X).op⟩ comp_zero f Z := congr_arg Quiver.Hom.op (HasZeroMorphisms.zero_comp (unop Z) f.unop) zero_comp X {Y Z} (f : Y ⟶ Z) := congrArg Quiver.Hom.op (HasZeroMorphisms.comp_zero f.unop (unop X)) #align category_theory.limits.has_zero_morphisms_opposite CategoryTheory.Limits.hasZeroMorphismsOpposite section variable [HasZeroMorphisms C] @[simp] lemma op_zero (X Y : C) : (0 : X ⟶ Y).op = 0 := rfl #align category_theory.op_zero CategoryTheory.Limits.op_zero @[simp] lemma unop_zero (X Y : Cᵒᵖ) : (0 : X ⟶ Y).unop = 0 := rfl #align category_theory.unop_zero CategoryTheory.Limits.unop_zero theorem zero_of_comp_mono {X Y Z : C} {f : X ⟶ Y} (g : Y ⟶ Z) [Mono g] (h : f ≫ g = 0) : f = 0 := by rw [← zero_comp, cancel_mono] at h exact h #align category_theory.limits.zero_of_comp_mono CategoryTheory.Limits.zero_of_comp_mono theorem zero_of_epi_comp {X Y Z : C} (f : X ⟶ Y) {g : Y ⟶ Z} [Epi f] (h : f ≫ g = 0) : g = 0 := by rw [← comp_zero, cancel_epi] at h exact h #align category_theory.limits.zero_of_epi_comp CategoryTheory.Limits.zero_of_epi_comp theorem eq_zero_of_image_eq_zero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : image.ι f = 0) : f = 0 := by rw [← image.fac f, w, HasZeroMorphisms.comp_zero] #align category_theory.limits.eq_zero_of_image_eq_zero CategoryTheory.Limits.eq_zero_of_image_eq_zero theorem nonzero_image_of_nonzero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : f ≠ 0) : image.ι f ≠ 0 := fun h => w (eq_zero_of_image_eq_zero h) #align category_theory.limits.nonzero_image_of_nonzero CategoryTheory.Limits.nonzero_image_of_nonzero end section variable [HasZeroMorphisms D] instance : HasZeroMorphisms (C ⥤ D) where zero F G := ⟨{ app := fun X => 0 }⟩ comp_zero := fun η H => by ext X; dsimp; apply comp_zero zero_comp := fun F {G H} η => by ext X; dsimp; apply zero_comp @[simp] theorem zero_app (F G : C ⥤ D) (j : C) : (0 : F ⟶ G).app j = 0 := rfl #align category_theory.limits.zero_app CategoryTheory.Limits.zero_app end namespace IsZero variable [HasZeroMorphisms C] theorem eq_zero_of_src {X Y : C} (o : IsZero X) (f : X ⟶ Y) : f = 0 := o.eq_of_src _ _ #align category_theory.limits.is_zero.eq_zero_of_src CategoryTheory.Limits.IsZero.eq_zero_of_src theorem eq_zero_of_tgt {X Y : C} (o : IsZero Y) (f : X ⟶ Y) : f = 0 := o.eq_of_tgt _ _ #align category_theory.limits.is_zero.eq_zero_of_tgt CategoryTheory.Limits.IsZero.eq_zero_of_tgt theorem iff_id_eq_zero (X : C) : IsZero X ↔ 𝟙 X = 0 := ⟨fun h => h.eq_of_src _ _, fun h => ⟨fun Y => ⟨⟨⟨0⟩, fun f => by rw [← id_comp f, ← id_comp (0: X ⟶ Y), h, zero_comp, zero_comp]; simp only⟩⟩, fun Y => ⟨⟨⟨0⟩, fun f => by rw [← comp_id f, ← comp_id (0 : Y ⟶ X), h, comp_zero, comp_zero]; simp only ⟩⟩⟩⟩ #align category_theory.limits.is_zero.iff_id_eq_zero CategoryTheory.Limits.IsZero.iff_id_eq_zero theorem of_mono_zero (X Y : C) [Mono (0 : X ⟶ Y)] : IsZero X := (iff_id_eq_zero X).mpr ((cancel_mono (0 : X ⟶ Y)).1 (by simp)) #align category_theory.limits.is_zero.of_mono_zero CategoryTheory.Limits.IsZero.of_mono_zero theorem of_epi_zero (X Y : C) [Epi (0 : X ⟶ Y)] : IsZero Y := (iff_id_eq_zero Y).mpr ((cancel_epi (0 : X ⟶ Y)).1 (by simp)) #align category_theory.limits.is_zero.of_epi_zero CategoryTheory.Limits.IsZero.of_epi_zero theorem of_mono_eq_zero {X Y : C} (f : X ⟶ Y) [Mono f] (h : f = 0) : IsZero X := by subst h apply of_mono_zero X Y #align category_theory.limits.is_zero.of_mono_eq_zero CategoryTheory.Limits.IsZero.of_mono_eq_zero theorem of_epi_eq_zero {X Y : C} (f : X ⟶ Y) [Epi f] (h : f = 0) : IsZero Y := by subst h apply of_epi_zero X Y #align category_theory.limits.is_zero.of_epi_eq_zero CategoryTheory.Limits.IsZero.of_epi_eq_zero theorem iff_isSplitMono_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitMono f] : IsZero X ↔ f = 0 := by rw [iff_id_eq_zero] constructor · intro h rw [← Category.id_comp f, h, zero_comp] · intro h rw [← IsSplitMono.id f] simp only [h, zero_comp] #align category_theory.limits.is_zero.iff_is_split_mono_eq_zero CategoryTheory.Limits.IsZero.iff_isSplitMono_eq_zero theorem iff_isSplitEpi_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsZero Y ↔ f = 0 := by rw [iff_id_eq_zero] constructor · intro h rw [← Category.comp_id f, h, comp_zero] · intro h rw [← IsSplitEpi.id f] simp [h] #align category_theory.limits.is_zero.iff_is_split_epi_eq_zero CategoryTheory.Limits.IsZero.iff_isSplitEpi_eq_zero theorem of_mono {X Y : C} (f : X ⟶ Y) [Mono f] (i : IsZero Y) : IsZero X := by have hf := i.eq_zero_of_tgt f subst hf exact IsZero.of_mono_zero X Y #align category_theory.limits.is_zero.of_mono CategoryTheory.Limits.IsZero.of_mono theorem of_epi {X Y : C} (f : X ⟶ Y) [Epi f] (i : IsZero X) : IsZero Y := by have hf := i.eq_zero_of_src f subst hf exact IsZero.of_epi_zero X Y #align category_theory.limits.is_zero.of_epi CategoryTheory.Limits.IsZero.of_epi end IsZero /-- A category with a zero object has zero morphisms. It is rarely a good idea to use this. Many categories that have a zero object have zero morphisms for some other reason, for example from additivity. Library code that uses `zeroMorphismsOfZeroObject` will then be incompatible with these categories because the `HasZeroMorphisms` instances will not be definitionally equal. For this reason library code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already asks for an instance of `HasZeroObjects`. -/ def IsZero.hasZeroMorphisms {O : C} (hO : IsZero O) : HasZeroMorphisms C where zero X Y := { zero := hO.from_ X ≫ hO.to_ Y } zero_comp X {Y Z} f := by change (hO.from_ X ≫ hO.to_ Y) ≫ f = hO.from_ X ≫ hO.to_ Z rw [Category.assoc] congr apply hO.eq_of_src comp_zero {X Y} f Z := by change f ≫ (hO.from_ Y ≫ hO.to_ Z) = hO.from_ X ≫ hO.to_ Z rw [← Category.assoc] congr apply hO.eq_of_tgt #align category_theory.limits.is_zero.has_zero_morphisms CategoryTheory.Limits.IsZero.hasZeroMorphisms namespace HasZeroObject variable [HasZeroObject C] open ZeroObject /-- A category with a zero object has zero morphisms. It is rarely a good idea to use this. Many categories that have a zero object have zero morphisms for some other reason, for example from additivity. Library code that uses `zeroMorphismsOfZeroObject` will then be incompatible with these categories because the `has_zero_morphisms` instances will not be definitionally equal. For this reason library code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already asks for an instance of `HasZeroObjects`. -/ def zeroMorphismsOfZeroObject : HasZeroMorphisms C where zero X Y := { zero := (default : X ⟶ 0) ≫ default } zero_comp X {Y Z} f := by change ((default : X ⟶ 0) ≫ default) ≫ f = (default : X ⟶ 0) ≫ default rw [Category.assoc] congr simp only [eq_iff_true_of_subsingleton] comp_zero {X Y} f Z := by change f ≫ (default : Y ⟶ 0) ≫ default = (default : X ⟶ 0) ≫ default rw [← Category.assoc] congr simp only [eq_iff_true_of_subsingleton] #align category_theory.limits.has_zero_object.zero_morphisms_of_zero_object CategoryTheory.Limits.HasZeroObject.zeroMorphismsOfZeroObject section HasZeroMorphisms variable [HasZeroMorphisms C] @[simp] theorem zeroIsoIsInitial_hom {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).hom = 0 := by ext #align category_theory.limits.has_zero_object.zero_iso_is_initial_hom CategoryTheory.Limits.HasZeroObject.zeroIsoIsInitial_hom @[simp] theorem zeroIsoIsInitial_inv {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).inv = 0 := by ext #align category_theory.limits.has_zero_object.zero_iso_is_initial_inv CategoryTheory.Limits.HasZeroObject.zeroIsoIsInitial_inv @[simp] theorem zeroIsoIsTerminal_hom {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).hom = 0 := by ext #align category_theory.limits.has_zero_object.zero_iso_is_terminal_hom CategoryTheory.Limits.HasZeroObject.zeroIsoIsTerminal_hom @[simp] theorem zeroIsoIsTerminal_inv {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).inv = 0 := by ext #align category_theory.limits.has_zero_object.zero_iso_is_terminal_inv CategoryTheory.Limits.HasZeroObject.zeroIsoIsTerminal_inv @[simp]
Mathlib/CategoryTheory/Limits/Shapes/ZeroMorphisms.lean
320
320
theorem zeroIsoInitial_hom [HasInitial C] : zeroIsoInitial.hom = (0 : 0 ⟶ ⊥_ C) := by
ext
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Yaël Dillies -/ import Mathlib.Algebra.CharZero.Defs import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Algebra.Group.Units import Mathlib.Algebra.GroupWithZero.NeZero import Mathlib.Algebra.Order.Group.Defs import Mathlib.Algebra.Order.GroupWithZero.Unbundled import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Order.Monoid.NatCast import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax import Mathlib.Algebra.Ring.Defs import Mathlib.Tactic.Tauto #align_import algebra.order.ring.char_zero from "leanprover-community/mathlib"@"655994e298904d7e5bbd1e18c95defd7b543eb94" #align_import algebra.order.ring.defs from "leanprover-community/mathlib"@"44e29dbcff83ba7114a464d592b8c3743987c1e5" /-! # Ordered rings and semirings This file develops the basics of ordered (semi)rings. Each typeclass here comprises * an algebraic class (`Semiring`, `CommSemiring`, `Ring`, `CommRing`) * an order class (`PartialOrder`, `LinearOrder`) * assumptions on how both interact ((strict) monotonicity, canonicity) For short, * "`+` respects `≤`" means "monotonicity of addition" * "`+` respects `<`" means "strict monotonicity of addition" * "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number". * "`*` respects `<`" means "strict monotonicity of multiplication by a positive number". ## Typeclasses * `OrderedSemiring`: Semiring with a partial order such that `+` and `*` respect `≤`. * `StrictOrderedSemiring`: Nontrivial semiring with a partial order such that `+` and `*` respects `<`. * `OrderedCommSemiring`: Commutative semiring with a partial order such that `+` and `*` respect `≤`. * `StrictOrderedCommSemiring`: Nontrivial commutative semiring with a partial order such that `+` and `*` respect `<`. * `OrderedRing`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`. * `OrderedCommRing`: Commutative ring with a partial order such that `+` respects `≤` and `*` respects `<`. * `LinearOrderedSemiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and `*` respects `<`. * `LinearOrderedCommSemiring`: Nontrivial commutative semiring with a linear order such that `+` respects `≤` and `*` respects `<`. * `LinearOrderedRing`: Nontrivial ring with a linear order such that `+` respects `≤` and `*` respects `<`. * `LinearOrderedCommRing`: Nontrivial commutative ring with a linear order such that `+` respects `≤` and `*` respects `<`. * `CanonicallyOrderedCommSemiring`: Commutative semiring with a partial order such that `+` respects `≤`, `*` respects `<`, and `a ≤ b ↔ ∃ c, b = a + c`. ## Hierarchy The hardest part of proving order lemmas might be to figure out the correct generality and its corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its immediate predecessors and what conditions are added to each of them. * `OrderedSemiring` - `OrderedAddCommMonoid` & multiplication & `*` respects `≤` - `Semiring` & partial order structure & `+` respects `≤` & `*` respects `≤` * `StrictOrderedSemiring` - `OrderedCancelAddCommMonoid` & multiplication & `*` respects `<` & nontriviality - `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality * `OrderedCommSemiring` - `OrderedSemiring` & commutativity of multiplication - `CommSemiring` & partial order structure & `+` respects `≤` & `*` respects `<` * `StrictOrderedCommSemiring` - `StrictOrderedSemiring` & commutativity of multiplication - `OrderedCommSemiring` & `+` respects `<` & `*` respects `<` & nontriviality * `OrderedRing` - `OrderedSemiring` & additive inverses - `OrderedAddCommGroup` & multiplication & `*` respects `<` - `Ring` & partial order structure & `+` respects `≤` & `*` respects `<` * `StrictOrderedRing` - `StrictOrderedSemiring` & additive inverses - `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality * `OrderedCommRing` - `OrderedRing` & commutativity of multiplication - `OrderedCommSemiring` & additive inverses - `CommRing` & partial order structure & `+` respects `≤` & `*` respects `<` * `StrictOrderedCommRing` - `StrictOrderedCommSemiring` & additive inverses - `StrictOrderedRing` & commutativity of multiplication - `OrderedCommRing` & `+` respects `<` & `*` respects `<` & nontriviality * `LinearOrderedSemiring` - `StrictOrderedSemiring` & totality of the order - `LinearOrderedAddCommMonoid` & multiplication & nontriviality & `*` respects `<` * `LinearOrderedCommSemiring` - `StrictOrderedCommSemiring` & totality of the order - `LinearOrderedSemiring` & commutativity of multiplication * `LinearOrderedRing` - `StrictOrderedRing` & totality of the order - `LinearOrderedSemiring` & additive inverses - `LinearOrderedAddCommGroup` & multiplication & `*` respects `<` - `Ring` & `IsDomain` & linear order structure * `LinearOrderedCommRing` - `StrictOrderedCommRing` & totality of the order - `LinearOrderedRing` & commutativity of multiplication - `LinearOrderedCommSemiring` & additive inverses - `CommRing` & `IsDomain` & linear order structure -/ open Function universe u variable {α : Type u} {β : Type*} /-! Note that `OrderDual` does not satisfy any of the ordered ring typeclasses due to the `zero_le_one` field. -/ theorem add_one_le_two_mul [LE α] [Semiring α] [CovariantClass α α (· + ·) (· ≤ ·)] {a : α} (a1 : 1 ≤ a) : a + 1 ≤ 2 * a := calc a + 1 ≤ a + a := add_le_add_left a1 a _ = 2 * a := (two_mul _).symm #align add_one_le_two_mul add_one_le_two_mul /-- An `OrderedSemiring` is a semiring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ class OrderedSemiring (α : Type u) extends Semiring α, OrderedAddCommMonoid α where /-- `0 ≤ 1` in any ordered semiring. -/ protected zero_le_one : (0 : α) ≤ 1 /-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/ protected mul_le_mul_of_nonneg_left : ∀ a b c : α, a ≤ b → 0 ≤ c → c * a ≤ c * b /-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/ protected mul_le_mul_of_nonneg_right : ∀ a b c : α, a ≤ b → 0 ≤ c → a * c ≤ b * c #align ordered_semiring OrderedSemiring /-- An `OrderedCommSemiring` is a commutative semiring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ class OrderedCommSemiring (α : Type u) extends OrderedSemiring α, CommSemiring α where mul_le_mul_of_nonneg_right a b c ha hc := -- parentheses ensure this generates an `optParam` rather than an `autoParam` (by simpa only [mul_comm] using mul_le_mul_of_nonneg_left a b c ha hc) #align ordered_comm_semiring OrderedCommSemiring /-- An `OrderedRing` is a ring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ class OrderedRing (α : Type u) extends Ring α, OrderedAddCommGroup α where /-- `0 ≤ 1` in any ordered ring. -/ protected zero_le_one : 0 ≤ (1 : α) /-- The product of non-negative elements is non-negative. -/ protected mul_nonneg : ∀ a b : α, 0 ≤ a → 0 ≤ b → 0 ≤ a * b #align ordered_ring OrderedRing /-- An `OrderedCommRing` is a commutative ring with a partial order such that addition is monotone and multiplication by a nonnegative number is monotone. -/ class OrderedCommRing (α : Type u) extends OrderedRing α, CommRing α #align ordered_comm_ring OrderedCommRing /-- A `StrictOrderedSemiring` is a nontrivial semiring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ class StrictOrderedSemiring (α : Type u) extends Semiring α, OrderedCancelAddCommMonoid α, Nontrivial α where /-- In a strict ordered semiring, `0 ≤ 1`. -/ protected zero_le_one : (0 : α) ≤ 1 /-- Left multiplication by a positive element is strictly monotone. -/ protected mul_lt_mul_of_pos_left : ∀ a b c : α, a < b → 0 < c → c * a < c * b /-- Right multiplication by a positive element is strictly monotone. -/ protected mul_lt_mul_of_pos_right : ∀ a b c : α, a < b → 0 < c → a * c < b * c #align strict_ordered_semiring StrictOrderedSemiring /-- A `StrictOrderedCommSemiring` is a commutative semiring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ class StrictOrderedCommSemiring (α : Type u) extends StrictOrderedSemiring α, CommSemiring α #align strict_ordered_comm_semiring StrictOrderedCommSemiring /-- A `StrictOrderedRing` is a ring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ class StrictOrderedRing (α : Type u) extends Ring α, OrderedAddCommGroup α, Nontrivial α where /-- In a strict ordered ring, `0 ≤ 1`. -/ protected zero_le_one : 0 ≤ (1 : α) /-- The product of two positive elements is positive. -/ protected mul_pos : ∀ a b : α, 0 < a → 0 < b → 0 < a * b #align strict_ordered_ring StrictOrderedRing /-- A `StrictOrderedCommRing` is a commutative ring with a partial order such that addition is strictly monotone and multiplication by a positive number is strictly monotone. -/ class StrictOrderedCommRing (α : Type*) extends StrictOrderedRing α, CommRing α #align strict_ordered_comm_ring StrictOrderedCommRing /- It's not entirely clear we should assume `Nontrivial` at this point; it would be reasonable to explore changing this, but be warned that the instances involving `Domain` may cause typeclass search loops. -/ /-- A `LinearOrderedSemiring` is a nontrivial semiring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ class LinearOrderedSemiring (α : Type u) extends StrictOrderedSemiring α, LinearOrderedAddCommMonoid α #align linear_ordered_semiring LinearOrderedSemiring /-- A `LinearOrderedCommSemiring` is a nontrivial commutative semiring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ class LinearOrderedCommSemiring (α : Type*) extends StrictOrderedCommSemiring α, LinearOrderedSemiring α #align linear_ordered_comm_semiring LinearOrderedCommSemiring /-- A `LinearOrderedRing` is a ring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ class LinearOrderedRing (α : Type u) extends StrictOrderedRing α, LinearOrder α #align linear_ordered_ring LinearOrderedRing /-- A `LinearOrderedCommRing` is a commutative ring with a linear order such that addition is monotone and multiplication by a positive number is strictly monotone. -/ class LinearOrderedCommRing (α : Type u) extends LinearOrderedRing α, CommMonoid α #align linear_ordered_comm_ring LinearOrderedCommRing section OrderedSemiring variable [OrderedSemiring α] {a b c d : α} -- see Note [lower instance priority] instance (priority := 100) OrderedSemiring.zeroLEOneClass : ZeroLEOneClass α := { ‹OrderedSemiring α› with } #align ordered_semiring.zero_le_one_class OrderedSemiring.zeroLEOneClass -- see Note [lower instance priority] instance (priority := 200) OrderedSemiring.toPosMulMono : PosMulMono α := ⟨fun x _ _ h => OrderedSemiring.mul_le_mul_of_nonneg_left _ _ _ h x.2⟩ #align ordered_semiring.to_pos_mul_mono OrderedSemiring.toPosMulMono -- see Note [lower instance priority] instance (priority := 200) OrderedSemiring.toMulPosMono : MulPosMono α := ⟨fun x _ _ h => OrderedSemiring.mul_le_mul_of_nonneg_right _ _ _ h x.2⟩ #align ordered_semiring.to_mul_pos_mono OrderedSemiring.toMulPosMono set_option linter.deprecated false in theorem bit1_mono : Monotone (bit1 : α → α) := fun _ _ h => add_le_add_right (bit0_mono h) _ #align bit1_mono bit1_mono @[simp] theorem pow_nonneg (H : 0 ≤ a) : ∀ n : ℕ, 0 ≤ a ^ n | 0 => by rw [pow_zero] exact zero_le_one | n + 1 => by rw [pow_succ] exact mul_nonneg (pow_nonneg H _) H #align pow_nonneg pow_nonneg lemma pow_le_pow_of_le_one (ha₀ : 0 ≤ a) (ha₁ : a ≤ 1) : ∀ {m n : ℕ}, m ≤ n → a ^ n ≤ a ^ m | _, _, Nat.le.refl => le_rfl | _, _, Nat.le.step h => by rw [pow_succ'] exact (mul_le_of_le_one_left (pow_nonneg ha₀ _) ha₁).trans $ pow_le_pow_of_le_one ha₀ ha₁ h #align pow_le_pow_of_le_one pow_le_pow_of_le_one lemma pow_le_of_le_one (h₀ : 0 ≤ a) (h₁ : a ≤ 1) {n : ℕ} (hn : n ≠ 0) : a ^ n ≤ a := (pow_one a).subst (pow_le_pow_of_le_one h₀ h₁ (Nat.pos_of_ne_zero hn)) #align pow_le_of_le_one pow_le_of_le_one lemma sq_le (h₀ : 0 ≤ a) (h₁ : a ≤ 1) : a ^ 2 ≤ a := pow_le_of_le_one h₀ h₁ two_ne_zero #align sq_le sq_le -- Porting note: it's unfortunate we need to write `(@one_le_two α)` here. theorem add_le_mul_two_add (a2 : 2 ≤ a) (b0 : 0 ≤ b) : a + (2 + b) ≤ a * (2 + b) := calc a + (2 + b) ≤ a + (a + a * b) := add_le_add_left (add_le_add a2 <| le_mul_of_one_le_left b0 <| (@one_le_two α).trans a2) a _ ≤ a * (2 + b) := by rw [mul_add, mul_two, add_assoc] #align add_le_mul_two_add add_le_mul_two_add theorem one_le_mul_of_one_le_of_one_le (ha : 1 ≤ a) (hb : 1 ≤ b) : (1 : α) ≤ a * b := Left.one_le_mul_of_le_of_le ha hb <| zero_le_one.trans ha #align one_le_mul_of_one_le_of_one_le one_le_mul_of_one_le_of_one_le section Monotone variable [Preorder β] {f g : β → α} theorem monotone_mul_left_of_nonneg (ha : 0 ≤ a) : Monotone fun x => a * x := fun _ _ h => mul_le_mul_of_nonneg_left h ha #align monotone_mul_left_of_nonneg monotone_mul_left_of_nonneg theorem monotone_mul_right_of_nonneg (ha : 0 ≤ a) : Monotone fun x => x * a := fun _ _ h => mul_le_mul_of_nonneg_right h ha #align monotone_mul_right_of_nonneg monotone_mul_right_of_nonneg theorem Monotone.mul_const (hf : Monotone f) (ha : 0 ≤ a) : Monotone fun x => f x * a := (monotone_mul_right_of_nonneg ha).comp hf #align monotone.mul_const Monotone.mul_const theorem Monotone.const_mul (hf : Monotone f) (ha : 0 ≤ a) : Monotone fun x => a * f x := (monotone_mul_left_of_nonneg ha).comp hf #align monotone.const_mul Monotone.const_mul theorem Antitone.mul_const (hf : Antitone f) (ha : 0 ≤ a) : Antitone fun x => f x * a := (monotone_mul_right_of_nonneg ha).comp_antitone hf #align antitone.mul_const Antitone.mul_const theorem Antitone.const_mul (hf : Antitone f) (ha : 0 ≤ a) : Antitone fun x => a * f x := (monotone_mul_left_of_nonneg ha).comp_antitone hf #align antitone.const_mul Antitone.const_mul theorem Monotone.mul (hf : Monotone f) (hg : Monotone g) (hf₀ : ∀ x, 0 ≤ f x) (hg₀ : ∀ x, 0 ≤ g x) : Monotone (f * g) := fun _ _ h => mul_le_mul (hf h) (hg h) (hg₀ _) (hf₀ _) #align monotone.mul Monotone.mul end Monotone section set_option linter.deprecated false theorem bit1_pos [Nontrivial α] (h : 0 ≤ a) : 0 < bit1 a := zero_lt_one.trans_le <| bit1_zero.symm.trans_le <| bit1_mono h #align bit1_pos bit1_pos
Mathlib/Algebra/Order/Ring/Defs.lean
319
321
theorem bit1_pos' (h : 0 < a) : 0 < bit1 a := by
nontriviality exact bit1_pos h.le
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.BaseChange import Mathlib.Algebra.Lie.Solvable import Mathlib.Algebra.Lie.Quotient import Mathlib.Algebra.Lie.Normalizer import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.Order.Filter.AtTopBot import Mathlib.RingTheory.Artinian import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Tactic.Monotonicity #align_import algebra.lie.nilpotent from "leanprover-community/mathlib"@"6b0169218d01f2837d79ea2784882009a0da1aa1" /-! # Nilpotent Lie algebras Like groups, Lie algebras admit a natural concept of nilpotency. More generally, any Lie module carries a natural concept of nilpotency. We define these here via the lower central series. ## Main definitions * `LieModule.lowerCentralSeries` * `LieModule.IsNilpotent` ## Tags lie algebra, lower central series, nilpotent -/ universe u v w w₁ w₂ section NilpotentModules variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] [LieModule R L M] variable (k : ℕ) (N : LieSubmodule R L M) namespace LieSubmodule /-- A generalisation of the lower central series. The zeroth term is a specified Lie submodule of a Lie module. In the case when we specify the top ideal `⊤` of the Lie algebra, regarded as a Lie module over itself, we get the usual lower central series of a Lie algebra. It can be more convenient to work with this generalisation when considering the lower central series of a Lie submodule, regarded as a Lie module in its own right, since it provides a type-theoretic expression of the fact that the terms of the Lie submodule's lower central series are also Lie submodules of the enclosing Lie module. See also `LieSubmodule.lowerCentralSeries_eq_lcs_comap` and `LieSubmodule.lowerCentralSeries_map_eq_lcs` below, as well as `LieSubmodule.ucs`. -/ def lcs : LieSubmodule R L M → LieSubmodule R L M := (fun N => ⁅(⊤ : LieIdeal R L), N⁆)^[k] #align lie_submodule.lcs LieSubmodule.lcs @[simp] theorem lcs_zero (N : LieSubmodule R L M) : N.lcs 0 = N := rfl #align lie_submodule.lcs_zero LieSubmodule.lcs_zero @[simp] theorem lcs_succ : N.lcs (k + 1) = ⁅(⊤ : LieIdeal R L), N.lcs k⁆ := Function.iterate_succ_apply' (fun N' => ⁅⊤, N'⁆) k N #align lie_submodule.lcs_succ LieSubmodule.lcs_succ @[simp] lemma lcs_sup {N₁ N₂ : LieSubmodule R L M} {k : ℕ} : (N₁ ⊔ N₂).lcs k = N₁.lcs k ⊔ N₂.lcs k := by induction' k with k ih · simp · simp only [LieSubmodule.lcs_succ, ih, LieSubmodule.lie_sup] end LieSubmodule namespace LieModule variable (R L M) /-- The lower central series of Lie submodules of a Lie module. -/ def lowerCentralSeries : LieSubmodule R L M := (⊤ : LieSubmodule R L M).lcs k #align lie_module.lower_central_series LieModule.lowerCentralSeries @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries R L M 0 = ⊤ := rfl #align lie_module.lower_central_series_zero LieModule.lowerCentralSeries_zero @[simp] theorem lowerCentralSeries_succ : lowerCentralSeries R L M (k + 1) = ⁅(⊤ : LieIdeal R L), lowerCentralSeries R L M k⁆ := (⊤ : LieSubmodule R L M).lcs_succ k #align lie_module.lower_central_series_succ LieModule.lowerCentralSeries_succ end LieModule namespace LieSubmodule open LieModule theorem lcs_le_self : N.lcs k ≤ N := by induction' k with k ih · simp · simp only [lcs_succ] exact (LieSubmodule.mono_lie_right _ _ ⊤ ih).trans (N.lie_le_right ⊤) #align lie_submodule.lcs_le_self LieSubmodule.lcs_le_self theorem lowerCentralSeries_eq_lcs_comap : lowerCentralSeries R L N k = (N.lcs k).comap N.incl := by induction' k with k ih · simp · simp only [lcs_succ, lowerCentralSeries_succ] at ih ⊢ have : N.lcs k ≤ N.incl.range := by rw [N.range_incl] apply lcs_le_self rw [ih, LieSubmodule.comap_bracket_eq _ _ N.incl N.ker_incl this] #align lie_submodule.lower_central_series_eq_lcs_comap LieSubmodule.lowerCentralSeries_eq_lcs_comap theorem lowerCentralSeries_map_eq_lcs : (lowerCentralSeries R L N k).map N.incl = N.lcs k := by rw [lowerCentralSeries_eq_lcs_comap, LieSubmodule.map_comap_incl, inf_eq_right] apply lcs_le_self #align lie_submodule.lower_central_series_map_eq_lcs LieSubmodule.lowerCentralSeries_map_eq_lcs end LieSubmodule namespace LieModule variable {M₂ : Type w₁} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] variable (R L M)
Mathlib/Algebra/Lie/Nilpotent.lean
134
141
theorem antitone_lowerCentralSeries : Antitone <| lowerCentralSeries R L M := by
intro l k induction' k with k ih generalizing l <;> intro h · exact (Nat.le_zero.mp h).symm ▸ le_rfl · rcases Nat.of_le_succ h with (hk | hk) · rw [lowerCentralSeries_succ] exact (LieSubmodule.mono_lie_right _ _ ⊤ (ih hk)).trans (LieSubmodule.lie_le_right _ _) · exact hk.symm ▸ le_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.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.ParametricIntegral import Mathlib.MeasureTheory.Constructions.Prod.Integral import Mathlib.MeasureTheory.Function.LocallyIntegrable import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Group.Prod import Mathlib.MeasureTheory.Integral.IntervalIntegral #align_import analysis.convolution from "leanprover-community/mathlib"@"8905e5ed90859939681a725b00f6063e65096d95" /-! # Convolution of functions This file defines the convolution on two functions, i.e. `x ↦ ∫ f(t)g(x - t) ∂t`. In the general case, these functions can be vector-valued, and have an arbitrary (additive) group as domain. We use a continuous bilinear operation `L` on these function values as "multiplication". The domain must be equipped with a Haar measure `μ` (though many individual results have weaker conditions on `μ`). For many applications we can take `L = ContinuousLinearMap.lsmul ℝ ℝ` or `L = ContinuousLinearMap.mul ℝ ℝ`. We also define `ConvolutionExists` and `ConvolutionExistsAt` to state that the convolution is well-defined (everywhere or at a single point). These conditions are needed for pointwise computations (e.g. `ConvolutionExistsAt.distrib_add`), but are generally not strong enough for any local (or global) properties of the convolution. For this we need stronger assumptions on `f` and/or `g`, and generally if we impose stronger conditions on one of the functions, we can impose weaker conditions on the other. We have proven many of the properties of the convolution assuming one of these functions has compact support (in which case the other function only needs to be locally integrable). We still need to prove the properties for other pairs of conditions (e.g. both functions are rapidly decreasing) # Design Decisions We use a bilinear map `L` to "multiply" the two functions in the integrand. This generality has several advantages * This allows us to compute the total derivative of the convolution, in case the functions are multivariate. The total derivative is again a convolution, but where the codomains of the functions can be higher-dimensional. See `HasCompactSupport.hasFDerivAt_convolution_right`. * This allows us to use `@[to_additive]` everywhere (which would not be possible if we would use `mul`/`smul` in the integral, since `@[to_additive]` will incorrectly also try to additivize those definitions). * We need to support the case where at least one of the functions is vector-valued, but if we use `smul` to multiply the functions, that would be an asymmetric definition. # Main Definitions * `convolution f g L μ x = (f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ` is the convolution of `f` and `g` w.r.t. the continuous bilinear map `L` and measure `μ`. * `ConvolutionExistsAt f g x L μ` states that the convolution `(f ⋆[L, μ] g) x` is well-defined (i.e. the integral exists). * `ConvolutionExists f g L μ` states that the convolution `f ⋆[L, μ] g` is well-defined at each point. # Main Results * `HasCompactSupport.hasFDerivAt_convolution_right` and `HasCompactSupport.hasFDerivAt_convolution_left`: we can compute the total derivative of the convolution as a convolution with the total derivative of the right (left) function. * `HasCompactSupport.contDiff_convolution_right` and `HasCompactSupport.contDiff_convolution_left`: the convolution is `𝒞ⁿ` if one of the functions is `𝒞ⁿ` with compact support and the other function in locally integrable. Versions of these statements for functions depending on a parameter are also given. * `convolution_tendsto_right`: Given a sequence of nonnegative normalized functions whose support tends to a small neighborhood around `0`, the convolution tends to the right argument. This is specialized to bump functions in `ContDiffBump.convolution_tendsto_right`. # Notation The following notations are localized in the locale `convolution`: * `f ⋆[L, μ] g` for the convolution. Note: you have to use parentheses to apply the convolution to an argument: `(f ⋆[L, μ] g) x`. * `f ⋆[L] g := f ⋆[L, volume] g` * `f ⋆ g := f ⋆[lsmul ℝ ℝ] g` # To do * Existence and (uniform) continuity of the convolution if one of the maps is in `ℒ^p` and the other in `ℒ^q` with `1 / p + 1 / q = 1`. This might require a generalization of `MeasureTheory.Memℒp.smul` where `smul` is generalized to a continuous bilinear map. (see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255K) * The convolution is an `AEStronglyMeasurable` function (see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255I). * Prove properties about the convolution if both functions are rapidly decreasing. * Use `@[to_additive]` everywhere (this likely requires changes in `to_additive`) -/ open Set Function Filter MeasureTheory MeasureTheory.Measure TopologicalSpace open ContinuousLinearMap Metric Bornology open scoped Pointwise Topology NNReal Filter universe u𝕜 uG uE uE' uE'' uF uF' uF'' uP variable {𝕜 : Type u𝕜} {G : Type uG} {E : Type uE} {E' : Type uE'} {E'' : Type uE''} {F : Type uF} {F' : Type uF'} {F'' : Type uF''} {P : Type uP} variable [NormedAddCommGroup E] [NormedAddCommGroup E'] [NormedAddCommGroup E''] [NormedAddCommGroup F] {f f' : G → E} {g g' : G → E'} {x x' : G} {y y' : E} namespace MeasureTheory section NontriviallyNormedField variable [NontriviallyNormedField 𝕜] variable [NormedSpace 𝕜 E] [NormedSpace 𝕜 E'] [NormedSpace 𝕜 E''] [NormedSpace 𝕜 F] variable (L : E →L[𝕜] E' →L[𝕜] F) section NoMeasurability variable [AddGroup G] [TopologicalSpace G] theorem convolution_integrand_bound_right_of_le_of_subset {C : ℝ} (hC : ∀ i, ‖g i‖ ≤ C) {x t : G} {s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s ⊆ u) : ‖L (f t) (g (x - t))‖ ≤ u.indicator (fun t => ‖L‖ * ‖f t‖ * C) t := by -- Porting note: had to add `f := _` refine le_indicator (f := fun t ↦ ‖L (f t) (g (x - t))‖) (fun t _ => ?_) (fun t ht => ?_) t · apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl] · have : x - t ∉ support g := by refine mt (fun hxt => hu ?_) ht refine ⟨_, Set.neg_mem_neg.mpr (subset_closure hxt), _, hx, ?_⟩ simp only [neg_sub, sub_add_cancel] simp only [nmem_support.mp this, (L _).map_zero, norm_zero, le_rfl] #align convolution_integrand_bound_right_of_le_of_subset MeasureTheory.convolution_integrand_bound_right_of_le_of_subset theorem _root_.HasCompactSupport.convolution_integrand_bound_right_of_subset (hcg : HasCompactSupport g) (hg : Continuous g) {x t : G} {s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s ⊆ u) : ‖L (f t) (g (x - t))‖ ≤ u.indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖) t := by refine convolution_integrand_bound_right_of_le_of_subset _ (fun i => ?_) hx hu exact le_ciSup (hg.norm.bddAbove_range_of_hasCompactSupport hcg.norm) _ #align has_compact_support.convolution_integrand_bound_right_of_subset HasCompactSupport.convolution_integrand_bound_right_of_subset theorem _root_.HasCompactSupport.convolution_integrand_bound_right (hcg : HasCompactSupport g) (hg : Continuous g) {x t : G} {s : Set G} (hx : x ∈ s) : ‖L (f t) (g (x - t))‖ ≤ (-tsupport g + s).indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖) t := hcg.convolution_integrand_bound_right_of_subset L hg hx Subset.rfl #align has_compact_support.convolution_integrand_bound_right HasCompactSupport.convolution_integrand_bound_right theorem _root_.Continuous.convolution_integrand_fst [ContinuousSub G] (hg : Continuous g) (t : G) : Continuous fun x => L (f t) (g (x - t)) := L.continuous₂.comp₂ continuous_const <| hg.comp <| continuous_id.sub continuous_const #align continuous.convolution_integrand_fst Continuous.convolution_integrand_fst theorem _root_.HasCompactSupport.convolution_integrand_bound_left (hcf : HasCompactSupport f) (hf : Continuous f) {x t : G} {s : Set G} (hx : x ∈ s) : ‖L (f (x - t)) (g t)‖ ≤ (-tsupport f + s).indicator (fun t => (‖L‖ * ⨆ i, ‖f i‖) * ‖g t‖) t := by convert hcf.convolution_integrand_bound_right L.flip hf hx using 1 simp_rw [L.opNorm_flip, mul_right_comm] #align has_compact_support.convolution_integrand_bound_left HasCompactSupport.convolution_integrand_bound_left end NoMeasurability section Measurability variable [MeasurableSpace G] {μ ν : Measure G} /-- The convolution of `f` and `g` exists at `x` when the function `t ↦ L (f t) (g (x - t))` is integrable. There are various conditions on `f` and `g` to prove this. -/ def ConvolutionExistsAt [Sub G] (f : G → E) (g : G → E') (x : G) (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G := by volume_tac) : Prop := Integrable (fun t => L (f t) (g (x - t))) μ #align convolution_exists_at MeasureTheory.ConvolutionExistsAt /-- The convolution of `f` and `g` exists when the function `t ↦ L (f t) (g (x - t))` is integrable for all `x : G`. There are various conditions on `f` and `g` to prove this. -/ def ConvolutionExists [Sub G] (f : G → E) (g : G → E') (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G := by volume_tac) : Prop := ∀ x : G, ConvolutionExistsAt f g x L μ #align convolution_exists MeasureTheory.ConvolutionExists section ConvolutionExists variable {L} in theorem ConvolutionExistsAt.integrable [Sub G] {x : G} (h : ConvolutionExistsAt f g x L μ) : Integrable (fun t => L (f t) (g (x - t))) μ := h #align convolution_exists_at.integrable MeasureTheory.ConvolutionExistsAt.integrable section Group variable [AddGroup G] theorem AEStronglyMeasurable.convolution_integrand' [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite ν] (hf : AEStronglyMeasurable f ν) (hg : AEStronglyMeasurable g <| map (fun p : G × G => p.1 - p.2) (μ.prod ν)) : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := L.aestronglyMeasurable_comp₂ hf.snd <| hg.comp_measurable measurable_sub #align measure_theory.ae_strongly_measurable.convolution_integrand' MeasureTheory.AEStronglyMeasurable.convolution_integrand' section variable [MeasurableAdd G] [MeasurableNeg G] theorem AEStronglyMeasurable.convolution_integrand_snd' (hf : AEStronglyMeasurable f μ) {x : G} (hg : AEStronglyMeasurable g <| map (fun t => x - t) μ) : AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ := L.aestronglyMeasurable_comp₂ hf <| hg.comp_measurable <| measurable_id.const_sub x #align measure_theory.ae_strongly_measurable.convolution_integrand_snd' MeasureTheory.AEStronglyMeasurable.convolution_integrand_snd' theorem AEStronglyMeasurable.convolution_integrand_swap_snd' {x : G} (hf : AEStronglyMeasurable f <| map (fun t => x - t) μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) μ := L.aestronglyMeasurable_comp₂ (hf.comp_measurable <| measurable_id.const_sub x) hg #align measure_theory.ae_strongly_measurable.convolution_integrand_swap_snd' MeasureTheory.AEStronglyMeasurable.convolution_integrand_swap_snd' /-- A sufficient condition to prove that `f ⋆[L, μ] g` exists. We assume that `f` is integrable on a set `s` and `g` is bounded and ae strongly measurable on `x₀ - s` (note that both properties hold if `g` is continuous with compact support). -/ theorem _root_.BddAbove.convolutionExistsAt' {x₀ : G} {s : Set G} (hbg : BddAbove ((fun i => ‖g i‖) '' ((fun t => -t + x₀) ⁻¹' s))) (hs : MeasurableSet s) (h2s : (support fun t => L (f t) (g (x₀ - t))) ⊆ s) (hf : IntegrableOn f s μ) (hmg : AEStronglyMeasurable g <| map (fun t => x₀ - t) (μ.restrict s)) : ConvolutionExistsAt f g x₀ L μ := by rw [ConvolutionExistsAt] rw [← integrableOn_iff_integrable_of_support_subset h2s] set s' := (fun t => -t + x₀) ⁻¹' s have : ∀ᵐ t : G ∂μ.restrict s, ‖L (f t) (g (x₀ - t))‖ ≤ s.indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i : s', ‖g i‖) t := by filter_upwards refine le_indicator (fun t ht => ?_) fun t ht => ?_ · apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl] refine (le_ciSup_set hbg <| mem_preimage.mpr ?_) rwa [neg_sub, sub_add_cancel] · have : t ∉ support fun t => L (f t) (g (x₀ - t)) := mt (fun h => h2s h) ht rw [nmem_support.mp this, norm_zero] refine Integrable.mono' ?_ ?_ this · rw [integrable_indicator_iff hs]; exact ((hf.norm.const_mul _).mul_const _).integrableOn · exact hf.aestronglyMeasurable.convolution_integrand_snd' L hmg #align bdd_above.convolution_exists_at' BddAbove.convolutionExistsAt' /-- If `‖f‖ *[μ] ‖g‖` exists, then `f *[L, μ] g` exists. -/ theorem ConvolutionExistsAt.ofNorm' {x₀ : G} (h : ConvolutionExistsAt (fun x => ‖f x‖) (fun x => ‖g x‖) x₀ (mul ℝ ℝ) μ) (hmf : AEStronglyMeasurable f μ) (hmg : AEStronglyMeasurable g <| map (fun t => x₀ - t) μ) : ConvolutionExistsAt f g x₀ L μ := by refine (h.const_mul ‖L‖).mono' (hmf.convolution_integrand_snd' L hmg) (eventually_of_forall fun x => ?_) rw [mul_apply', ← mul_assoc] apply L.le_opNorm₂ #align convolution_exists_at.of_norm' MeasureTheory.ConvolutionExistsAt.ofNorm' end section Left variable [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite μ] [IsAddRightInvariant μ] theorem AEStronglyMeasurable.convolution_integrand_snd (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (x : G) : AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ := hf.convolution_integrand_snd' L <| hg.mono_ac <| (quasiMeasurePreserving_sub_left_of_right_invariant μ x).absolutelyContinuous #align measure_theory.ae_strongly_measurable.convolution_integrand_snd MeasureTheory.AEStronglyMeasurable.convolution_integrand_snd theorem AEStronglyMeasurable.convolution_integrand_swap_snd (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (x : G) : AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) μ := (hf.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x).absolutelyContinuous).convolution_integrand_swap_snd' L hg #align measure_theory.ae_strongly_measurable.convolution_integrand_swap_snd MeasureTheory.AEStronglyMeasurable.convolution_integrand_swap_snd /-- If `‖f‖ *[μ] ‖g‖` exists, then `f *[L, μ] g` exists. -/ theorem ConvolutionExistsAt.ofNorm {x₀ : G} (h : ConvolutionExistsAt (fun x => ‖f x‖) (fun x => ‖g x‖) x₀ (mul ℝ ℝ) μ) (hmf : AEStronglyMeasurable f μ) (hmg : AEStronglyMeasurable g μ) : ConvolutionExistsAt f g x₀ L μ := h.ofNorm' L hmf <| hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x₀).absolutelyContinuous #align convolution_exists_at.of_norm MeasureTheory.ConvolutionExistsAt.ofNorm end Left section Right variable [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite μ] [IsAddRightInvariant μ] [SigmaFinite ν] theorem AEStronglyMeasurable.convolution_integrand (hf : AEStronglyMeasurable f ν) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := hf.convolution_integrand' L <| hg.mono_ac (quasiMeasurePreserving_sub_of_right_invariant μ ν).absolutelyContinuous #align measure_theory.ae_strongly_measurable.convolution_integrand MeasureTheory.AEStronglyMeasurable.convolution_integrand theorem Integrable.convolution_integrand (hf : Integrable f ν) (hg : Integrable g μ) : Integrable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := by have h_meas : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable have h2_meas : AEStronglyMeasurable (fun y : G => ∫ x : G, ‖L (f y) (g (x - y))‖ ∂μ) ν := h_meas.prod_swap.norm.integral_prod_right' simp_rw [integrable_prod_iff' h_meas] refine ⟨eventually_of_forall fun t => (L (f t)).integrable_comp (hg.comp_sub_right t), ?_⟩ refine Integrable.mono' ?_ h2_meas (eventually_of_forall fun t => (?_ : _ ≤ ‖L‖ * ‖f t‖ * ∫ x, ‖g (x - t)‖ ∂μ)) · simp only [integral_sub_right_eq_self (‖g ·‖)] exact (hf.norm.const_mul _).mul_const _ · simp_rw [← integral_mul_left] rw [Real.norm_of_nonneg (by positivity)] exact integral_mono_of_nonneg (eventually_of_forall fun t => norm_nonneg _) ((hg.comp_sub_right t).norm.const_mul _) (eventually_of_forall fun t => L.le_opNorm₂ _ _) #align measure_theory.integrable.convolution_integrand MeasureTheory.Integrable.convolution_integrand theorem Integrable.ae_convolution_exists (hf : Integrable f ν) (hg : Integrable g μ) : ∀ᵐ x ∂μ, ConvolutionExistsAt f g x L ν := ((integrable_prod_iff <| hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable).mp <| hf.convolution_integrand L hg).1 #align measure_theory.integrable.ae_convolution_exists MeasureTheory.Integrable.ae_convolution_exists end Right variable [TopologicalSpace G] [TopologicalAddGroup G] [BorelSpace G] theorem _root_.HasCompactSupport.convolutionExistsAt {x₀ : G} (h : HasCompactSupport fun t => L (f t) (g (x₀ - t))) (hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExistsAt f g x₀ L μ := by let u := (Homeomorph.neg G).trans (Homeomorph.addRight x₀) let v := (Homeomorph.neg G).trans (Homeomorph.addLeft x₀) apply ((u.isCompact_preimage.mpr h).bddAbove_image hg.norm.continuousOn).convolutionExistsAt' L isClosed_closure.measurableSet subset_closure (hf.integrableOn_isCompact h) have A : AEStronglyMeasurable (g ∘ v) (μ.restrict (tsupport fun t : G => L (f t) (g (x₀ - t)))) := by apply (hg.comp v.continuous).continuousOn.aestronglyMeasurable_of_isCompact h exact (isClosed_tsupport _).measurableSet convert ((v.continuous.measurable.measurePreserving (μ.restrict (tsupport fun t => L (f t) (g (x₀ - t))))).aestronglyMeasurable_comp_iff v.measurableEmbedding).1 A ext x simp only [v, Homeomorph.neg, sub_eq_add_neg, val_toAddUnits_apply, Homeomorph.trans_apply, Equiv.neg_apply, Equiv.toFun_as_coe, Homeomorph.homeomorph_mk_coe, Equiv.coe_fn_mk, Homeomorph.coe_addLeft] #align has_compact_support.convolution_exists_at HasCompactSupport.convolutionExistsAt theorem _root_.HasCompactSupport.convolutionExists_right (hcg : HasCompactSupport g) (hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExists f g L μ := by intro x₀ refine HasCompactSupport.convolutionExistsAt L ?_ hf hg refine (hcg.comp_homeomorph (Homeomorph.subLeft x₀)).mono ?_ refine fun t => mt fun ht : g (x₀ - t) = 0 => ?_ simp_rw [ht, (L _).map_zero] #align has_compact_support.convolution_exists_right HasCompactSupport.convolutionExists_right theorem _root_.HasCompactSupport.convolutionExists_left_of_continuous_right (hcf : HasCompactSupport f) (hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExists f g L μ := by intro x₀ refine HasCompactSupport.convolutionExistsAt L ?_ hf hg refine hcf.mono ?_ refine fun t => mt fun ht : f t = 0 => ?_ simp_rw [ht, L.map_zero₂] #align has_compact_support.convolution_exists_left_of_continuous_right HasCompactSupport.convolutionExists_left_of_continuous_right end Group section CommGroup variable [AddCommGroup G] section MeasurableGroup variable [MeasurableNeg G] [IsAddLeftInvariant μ] /-- A sufficient condition to prove that `f ⋆[L, μ] g` exists. We assume that the integrand has compact support and `g` is bounded on this support (note that both properties hold if `g` is continuous with compact support). We also require that `f` is integrable on the support of the integrand, and that both functions are strongly measurable. This is a variant of `BddAbove.convolutionExistsAt'` in an abelian group with a left-invariant measure. This allows us to state the boundedness and measurability of `g` in a more natural way. -/ theorem _root_.BddAbove.convolutionExistsAt [MeasurableAdd₂ G] [SigmaFinite μ] {x₀ : G} {s : Set G} (hbg : BddAbove ((fun i => ‖g i‖) '' ((fun t => x₀ - t) ⁻¹' s))) (hs : MeasurableSet s) (h2s : (support fun t => L (f t) (g (x₀ - t))) ⊆ s) (hf : IntegrableOn f s μ) (hmg : AEStronglyMeasurable g μ) : ConvolutionExistsAt f g x₀ L μ := by refine BddAbove.convolutionExistsAt' L ?_ hs h2s hf ?_ · simp_rw [← sub_eq_neg_add, hbg] · have : AEStronglyMeasurable g (map (fun t : G => x₀ - t) μ) := hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x₀).absolutelyContinuous apply this.mono_measure exact map_mono restrict_le_self (measurable_const.sub measurable_id') #align bdd_above.convolution_exists_at BddAbove.convolutionExistsAt variable {L} [MeasurableAdd G] [IsNegInvariant μ] theorem convolutionExistsAt_flip : ConvolutionExistsAt g f x L.flip μ ↔ ConvolutionExistsAt f g x L μ := by simp_rw [ConvolutionExistsAt, ← integrable_comp_sub_left (fun t => L (f t) (g (x - t))) x, sub_sub_cancel, flip_apply] #align convolution_exists_at_flip MeasureTheory.convolutionExistsAt_flip theorem ConvolutionExistsAt.integrable_swap (h : ConvolutionExistsAt f g x L μ) : Integrable (fun t => L (f (x - t)) (g t)) μ := by convert h.comp_sub_left x simp_rw [sub_sub_self] #align convolution_exists_at.integrable_swap MeasureTheory.ConvolutionExistsAt.integrable_swap theorem convolutionExistsAt_iff_integrable_swap : ConvolutionExistsAt f g x L μ ↔ Integrable (fun t => L (f (x - t)) (g t)) μ := convolutionExistsAt_flip.symm #align convolution_exists_at_iff_integrable_swap MeasureTheory.convolutionExistsAt_iff_integrable_swap end MeasurableGroup variable [TopologicalSpace G] [TopologicalAddGroup G] [BorelSpace G] variable [IsAddLeftInvariant μ] [IsNegInvariant μ] theorem _root_.HasCompactSupport.convolutionExistsLeft (hcf : HasCompactSupport f) (hf : Continuous f) (hg : LocallyIntegrable g μ) : ConvolutionExists f g L μ := fun x₀ => convolutionExistsAt_flip.mp <| hcf.convolutionExists_right L.flip hg hf x₀ #align has_compact_support.convolution_exists_left HasCompactSupport.convolutionExistsLeft theorem _root_.HasCompactSupport.convolutionExistsRightOfContinuousLeft (hcg : HasCompactSupport g) (hf : Continuous f) (hg : LocallyIntegrable g μ) : ConvolutionExists f g L μ := fun x₀ => convolutionExistsAt_flip.mp <| hcg.convolutionExists_left_of_continuous_right L.flip hg hf x₀ #align has_compact_support.convolution_exists_right_of_continuous_left HasCompactSupport.convolutionExistsRightOfContinuousLeft end CommGroup end ConvolutionExists variable [NormedSpace ℝ F] /-- The convolution of two functions `f` and `g` with respect to a continuous bilinear map `L` and measure `μ`. It is defined to be `(f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ`. -/ noncomputable def convolution [Sub G] (f : G → E) (g : G → E') (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G := by volume_tac) : G → F := fun x => ∫ t, L (f t) (g (x - t)) ∂μ #align convolution MeasureTheory.convolution /-- The convolution of two functions with respect to a bilinear operation `L` and a measure `μ`. -/ scoped[Convolution] notation:67 f " ⋆[" L:67 ", " μ:67 "] " g:66 => convolution f g L μ /-- The convolution of two functions with respect to a bilinear operation `L` and the volume. -/ scoped[Convolution] notation:67 f " ⋆[" L:67 "]" g:66 => convolution f g L MeasureSpace.volume /-- The convolution of two real-valued functions with respect to volume. -/ scoped[Convolution] notation:67 f " ⋆ " g:66 => convolution f g (ContinuousLinearMap.lsmul ℝ ℝ) MeasureSpace.volume open scoped Convolution theorem convolution_def [Sub G] : (f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ := rfl #align convolution_def MeasureTheory.convolution_def /-- The definition of convolution where the bilinear operator is scalar multiplication. Note: it often helps the elaborator to give the type of the convolution explicitly. -/ theorem convolution_lsmul [Sub G] {f : G → 𝕜} {g : G → F} : (f ⋆[lsmul 𝕜 𝕜, μ] g : G → F) x = ∫ t, f t • g (x - t) ∂μ := rfl #align convolution_lsmul MeasureTheory.convolution_lsmul /-- The definition of convolution where the bilinear operator is multiplication. -/ theorem convolution_mul [Sub G] [NormedSpace ℝ 𝕜] {f : G → 𝕜} {g : G → 𝕜} : (f ⋆[mul 𝕜 𝕜, μ] g) x = ∫ t, f t * g (x - t) ∂μ := rfl #align convolution_mul MeasureTheory.convolution_mul section Group variable {L} [AddGroup G] theorem smul_convolution [SMulCommClass ℝ 𝕜 F] {y : 𝕜} : y • f ⋆[L, μ] g = y • (f ⋆[L, μ] g) := by ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, L.map_smul₂] #align smul_convolution MeasureTheory.smul_convolution theorem convolution_smul [SMulCommClass ℝ 𝕜 F] {y : 𝕜} : f ⋆[L, μ] y • g = y • (f ⋆[L, μ] g) := by ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, (L _).map_smul] #align convolution_smul MeasureTheory.convolution_smul @[simp] theorem zero_convolution : 0 ⋆[L, μ] g = 0 := by ext simp_rw [convolution_def, Pi.zero_apply, L.map_zero₂, integral_zero] #align zero_convolution MeasureTheory.zero_convolution @[simp] theorem convolution_zero : f ⋆[L, μ] 0 = 0 := by ext simp_rw [convolution_def, Pi.zero_apply, (L _).map_zero, integral_zero] #align convolution_zero MeasureTheory.convolution_zero
Mathlib/Analysis/Convolution.lean
494
497
theorem ConvolutionExistsAt.distrib_add {x : G} (hfg : ConvolutionExistsAt f g x L μ) (hfg' : ConvolutionExistsAt f g' x L μ) : (f ⋆[L, μ] (g + g')) x = (f ⋆[L, μ] g) x + (f ⋆[L, μ] g') x := by
simp only [convolution_def, (L _).map_add, Pi.add_apply, integral_add hfg hfg']
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Sébastien Gouëzel, Yury Kudryashov, Anatole Dedecker -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Add #align_import analysis.calculus.deriv.add from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # One-dimensional derivatives of sums etc In this file we prove formulas about derivatives of `f + g`, `-f`, `f - g`, and `∑ i, f i x` for functions from the base field to a normed space over this field. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative -/ universe u v w open scoped Classical open Topology Filter ENNReal open Filter Asymptotics Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L : Filter 𝕜} section Add /-! ### Derivative of the sum of two functions -/ nonrec theorem HasDerivAtFilter.add (hf : HasDerivAtFilter f f' x L) (hg : HasDerivAtFilter g g' x L) : HasDerivAtFilter (fun y => f y + g y) (f' + g') x L := by simpa using (hf.add hg).hasDerivAtFilter #align has_deriv_at_filter.add HasDerivAtFilter.add nonrec theorem HasStrictDerivAt.add (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) : HasStrictDerivAt (fun y => f y + g y) (f' + g') x := by simpa using (hf.add hg).hasStrictDerivAt #align has_strict_deriv_at.add HasStrictDerivAt.add nonrec theorem HasDerivWithinAt.add (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun y => f y + g y) (f' + g') s x := hf.add hg #align has_deriv_within_at.add HasDerivWithinAt.add nonrec theorem HasDerivAt.add (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) : HasDerivAt (fun x => f x + g x) (f' + g') x := hf.add hg #align has_deriv_at.add HasDerivAt.add theorem derivWithin_add (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : derivWithin (fun y => f y + g y) s x = derivWithin f s x + derivWithin g s x := (hf.hasDerivWithinAt.add hg.hasDerivWithinAt).derivWithin hxs #align deriv_within_add derivWithin_add @[simp] theorem deriv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : deriv (fun y => f y + g y) x = deriv f x + deriv g x := (hf.hasDerivAt.add hg.hasDerivAt).deriv #align deriv_add deriv_add -- Porting note (#10756): new theorem theorem HasStrictDerivAt.add_const (c : F) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun y ↦ f y + c) f' x := add_zero f' ▸ hf.add (hasStrictDerivAt_const x c) theorem HasDerivAtFilter.add_const (hf : HasDerivAtFilter f f' x L) (c : F) : HasDerivAtFilter (fun y => f y + c) f' x L := add_zero f' ▸ hf.add (hasDerivAtFilter_const x L c) #align has_deriv_at_filter.add_const HasDerivAtFilter.add_const nonrec theorem HasDerivWithinAt.add_const (hf : HasDerivWithinAt f f' s x) (c : F) : HasDerivWithinAt (fun y => f y + c) f' s x := hf.add_const c #align has_deriv_within_at.add_const HasDerivWithinAt.add_const nonrec theorem HasDerivAt.add_const (hf : HasDerivAt f f' x) (c : F) : HasDerivAt (fun x => f x + c) f' x := hf.add_const c #align has_deriv_at.add_const HasDerivAt.add_const
Mathlib/Analysis/Calculus/Deriv/Add.lean
97
99
theorem derivWithin_add_const (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : derivWithin (fun y => f y + c) s x = derivWithin f s x := by
simp only [derivWithin, fderivWithin_add_const hxs]
/- 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]
Mathlib/Algebra/BigOperators/Finsupp.lean
54
57
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
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Regular.Pow import Mathlib.Algebra.MonoidAlgebra.Support import Mathlib.Data.Finsupp.Antidiagonal import Mathlib.Order.SymmDiff import Mathlib.RingTheory.Adjoin.Basic #align_import data.mv_polynomial.basic from "leanprover-community/mathlib"@"c8734e8953e4b439147bd6f75c2163f6d27cdce6" /-! # Multivariate polynomials This file defines polynomial rings over a base ring (or even semiring), with variables from a general type `σ` (which could be infinite). ## Important definitions Let `R` be a commutative ring (or a semiring) and let `σ` be an arbitrary type. This file creates the type `MvPolynomial σ R`, which mathematicians might denote $R[X_i : i \in σ]$. It is the type of multivariate (a.k.a. multivariable) polynomials, with variables corresponding to the terms in `σ`, and coefficients in `R`. ### Notation In the definitions below, we use the following notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ### Definitions * `MvPolynomial σ R` : the type of polynomials with variables of type `σ` and coefficients in the commutative semiring `R` * `monomial s a` : the monomial which mathematically would be denoted `a * X^s` * `C a` : the constant polynomial with value `a` * `X i` : the degree one monomial corresponding to i; mathematically this might be denoted `Xᵢ`. * `coeff s p` : the coefficient of `s` in `p`. * `eval₂ (f : R → S₁) (g : σ → S₁) p` : given a semiring homomorphism from `R` to another semiring `S₁`, and a map `σ → S₁`, evaluates `p` at this valuation, returning a term of type `S₁`. Note that `eval₂` can be made using `eval` and `map` (see below), and it has been suggested that sticking to `eval` and `map` might make the code less brittle. * `eval (g : σ → R) p` : given a map `σ → R`, evaluates `p` at this valuation, returning a term of type `R` * `map (f : R → S₁) p` : returns the multivariate polynomial obtained from `p` by the change of coefficient semiring corresponding to `f` ## Implementation notes Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`. The definition of `MvPolynomial σ R` is `(σ →₀ ℕ) →₀ R`; here `σ →₀ ℕ` denotes the space of all monomials in the variables, and the function to `R` sends a monomial to its coefficient in the polynomial being represented. ## Tags polynomial, multivariate polynomial, multivariable polynomial -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra open scoped Pointwise universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} /-- Multivariate polynomial, where `σ` is the index set of the variables and `R` is the coefficient ring -/ def MvPolynomial (σ : Type*) (R : Type*) [CommSemiring R] := AddMonoidAlgebra R (σ →₀ ℕ) #align mv_polynomial MvPolynomial namespace MvPolynomial -- Porting note: because of `MvPolynomial.C` and `MvPolynomial.X` this linter throws -- tons of warnings in this file, and it's easier to just disable them globally in the file set_option linter.uppercaseLean3 false variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommSemiring section Instances instance decidableEqMvPolynomial [CommSemiring R] [DecidableEq σ] [DecidableEq R] : DecidableEq (MvPolynomial σ R) := Finsupp.instDecidableEq #align mv_polynomial.decidable_eq_mv_polynomial MvPolynomial.decidableEqMvPolynomial instance commSemiring [CommSemiring R] : CommSemiring (MvPolynomial σ R) := AddMonoidAlgebra.commSemiring instance inhabited [CommSemiring R] : Inhabited (MvPolynomial σ R) := ⟨0⟩ instance distribuMulAction [Monoid R] [CommSemiring S₁] [DistribMulAction R S₁] : DistribMulAction R (MvPolynomial σ S₁) := AddMonoidAlgebra.distribMulAction instance smulZeroClass [CommSemiring S₁] [SMulZeroClass R S₁] : SMulZeroClass R (MvPolynomial σ S₁) := AddMonoidAlgebra.smulZeroClass instance faithfulSMul [CommSemiring S₁] [SMulZeroClass R S₁] [FaithfulSMul R S₁] : FaithfulSMul R (MvPolynomial σ S₁) := AddMonoidAlgebra.faithfulSMul instance module [Semiring R] [CommSemiring S₁] [Module R S₁] : Module R (MvPolynomial σ S₁) := AddMonoidAlgebra.module instance isScalarTower [CommSemiring S₂] [SMul R S₁] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂] [IsScalarTower R S₁ S₂] : IsScalarTower R S₁ (MvPolynomial σ S₂) := AddMonoidAlgebra.isScalarTower instance smulCommClass [CommSemiring S₂] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂] [SMulCommClass R S₁ S₂] : SMulCommClass R S₁ (MvPolynomial σ S₂) := AddMonoidAlgebra.smulCommClass instance isCentralScalar [CommSemiring S₁] [SMulZeroClass R S₁] [SMulZeroClass Rᵐᵒᵖ S₁] [IsCentralScalar R S₁] : IsCentralScalar R (MvPolynomial σ S₁) := AddMonoidAlgebra.isCentralScalar instance algebra [CommSemiring R] [CommSemiring S₁] [Algebra R S₁] : Algebra R (MvPolynomial σ S₁) := AddMonoidAlgebra.algebra instance isScalarTower_right [CommSemiring S₁] [DistribSMul R S₁] [IsScalarTower R S₁ S₁] : IsScalarTower R (MvPolynomial σ S₁) (MvPolynomial σ S₁) := AddMonoidAlgebra.isScalarTower_self _ #align mv_polynomial.is_scalar_tower_right MvPolynomial.isScalarTower_right instance smulCommClass_right [CommSemiring S₁] [DistribSMul R S₁] [SMulCommClass R S₁ S₁] : SMulCommClass R (MvPolynomial σ S₁) (MvPolynomial σ S₁) := AddMonoidAlgebra.smulCommClass_self _ #align mv_polynomial.smul_comm_class_right MvPolynomial.smulCommClass_right /-- If `R` is a subsingleton, then `MvPolynomial σ R` has a unique element -/ instance unique [CommSemiring R] [Subsingleton R] : Unique (MvPolynomial σ R) := AddMonoidAlgebra.unique #align mv_polynomial.unique MvPolynomial.unique end Instances variable [CommSemiring R] [CommSemiring S₁] {p q : MvPolynomial σ R} /-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/ def monomial (s : σ →₀ ℕ) : R →ₗ[R] MvPolynomial σ R := lsingle s #align mv_polynomial.monomial MvPolynomial.monomial theorem single_eq_monomial (s : σ →₀ ℕ) (a : R) : Finsupp.single s a = monomial s a := rfl #align mv_polynomial.single_eq_monomial MvPolynomial.single_eq_monomial theorem mul_def : p * q = p.sum fun m a => q.sum fun n b => monomial (m + n) (a * b) := AddMonoidAlgebra.mul_def #align mv_polynomial.mul_def MvPolynomial.mul_def /-- `C a` is the constant polynomial with value `a` -/ def C : R →+* MvPolynomial σ R := { singleZeroRingHom with toFun := monomial 0 } #align mv_polynomial.C MvPolynomial.C variable (R σ) @[simp] theorem algebraMap_eq : algebraMap R (MvPolynomial σ R) = C := rfl #align mv_polynomial.algebra_map_eq MvPolynomial.algebraMap_eq variable {R σ} /-- `X n` is the degree `1` monomial $X_n$. -/ def X (n : σ) : MvPolynomial σ R := monomial (Finsupp.single n 1) 1 #align mv_polynomial.X MvPolynomial.X theorem monomial_left_injective {r : R} (hr : r ≠ 0) : Function.Injective fun s : σ →₀ ℕ => monomial s r := Finsupp.single_left_injective hr #align mv_polynomial.monomial_left_injective MvPolynomial.monomial_left_injective @[simp] theorem monomial_left_inj {s t : σ →₀ ℕ} {r : R} (hr : r ≠ 0) : monomial s r = monomial t r ↔ s = t := Finsupp.single_left_inj hr #align mv_polynomial.monomial_left_inj MvPolynomial.monomial_left_inj theorem C_apply : (C a : MvPolynomial σ R) = monomial 0 a := rfl #align mv_polynomial.C_apply MvPolynomial.C_apply -- Porting note (#10618): `simp` can prove this theorem C_0 : C 0 = (0 : MvPolynomial σ R) := map_zero _ #align mv_polynomial.C_0 MvPolynomial.C_0 -- Porting note (#10618): `simp` can prove this theorem C_1 : C 1 = (1 : MvPolynomial σ R) := rfl #align mv_polynomial.C_1 MvPolynomial.C_1 theorem C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by -- Porting note: this `show` feels like defeq abuse, but I can't find the appropriate lemmas show AddMonoidAlgebra.single _ _ * AddMonoidAlgebra.single _ _ = AddMonoidAlgebra.single _ _ simp [C_apply, single_mul_single] #align mv_polynomial.C_mul_monomial MvPolynomial.C_mul_monomial -- Porting note (#10618): `simp` can prove this theorem C_add : (C (a + a') : MvPolynomial σ R) = C a + C a' := Finsupp.single_add _ _ _ #align mv_polynomial.C_add MvPolynomial.C_add -- Porting note (#10618): `simp` can prove this theorem C_mul : (C (a * a') : MvPolynomial σ R) = C a * C a' := C_mul_monomial.symm #align mv_polynomial.C_mul MvPolynomial.C_mul -- Porting note (#10618): `simp` can prove this theorem C_pow (a : R) (n : ℕ) : (C (a ^ n) : MvPolynomial σ R) = C a ^ n := map_pow _ _ _ #align mv_polynomial.C_pow MvPolynomial.C_pow theorem C_injective (σ : Type*) (R : Type*) [CommSemiring R] : Function.Injective (C : R → MvPolynomial σ R) := Finsupp.single_injective _ #align mv_polynomial.C_injective MvPolynomial.C_injective theorem C_surjective {R : Type*} [CommSemiring R] (σ : Type*) [IsEmpty σ] : Function.Surjective (C : R → MvPolynomial σ R) := by refine fun p => ⟨p.toFun 0, Finsupp.ext fun a => ?_⟩ simp only [C_apply, ← single_eq_monomial, (Finsupp.ext isEmptyElim (α := σ) : a = 0), single_eq_same] rfl #align mv_polynomial.C_surjective MvPolynomial.C_surjective @[simp] theorem C_inj {σ : Type*} (R : Type*) [CommSemiring R] (r s : R) : (C r : MvPolynomial σ R) = C s ↔ r = s := (C_injective σ R).eq_iff #align mv_polynomial.C_inj MvPolynomial.C_inj instance nontrivial_of_nontrivial (σ : Type*) (R : Type*) [CommSemiring R] [Nontrivial R] : Nontrivial (MvPolynomial σ R) := inferInstanceAs (Nontrivial <| AddMonoidAlgebra R (σ →₀ ℕ)) instance infinite_of_infinite (σ : Type*) (R : Type*) [CommSemiring R] [Infinite R] : Infinite (MvPolynomial σ R) := Infinite.of_injective C (C_injective _ _) #align mv_polynomial.infinite_of_infinite MvPolynomial.infinite_of_infinite instance infinite_of_nonempty (σ : Type*) (R : Type*) [Nonempty σ] [CommSemiring R] [Nontrivial R] : Infinite (MvPolynomial σ R) := Infinite.of_injective ((fun s : σ →₀ ℕ => monomial s 1) ∘ Finsupp.single (Classical.arbitrary σ)) <| (monomial_left_injective one_ne_zero).comp (Finsupp.single_injective _) #align mv_polynomial.infinite_of_nonempty MvPolynomial.infinite_of_nonempty theorem C_eq_coe_nat (n : ℕ) : (C ↑n : MvPolynomial σ R) = n := by induction n <;> simp [Nat.succ_eq_add_one, *] #align mv_polynomial.C_eq_coe_nat MvPolynomial.C_eq_coe_nat theorem C_mul' : MvPolynomial.C a * p = a • p := (Algebra.smul_def a p).symm #align mv_polynomial.C_mul' MvPolynomial.C_mul' theorem smul_eq_C_mul (p : MvPolynomial σ R) (a : R) : a • p = C a * p := C_mul'.symm #align mv_polynomial.smul_eq_C_mul MvPolynomial.smul_eq_C_mul theorem C_eq_smul_one : (C a : MvPolynomial σ R) = a • (1 : MvPolynomial σ R) := by rw [← C_mul', mul_one] #align mv_polynomial.C_eq_smul_one MvPolynomial.C_eq_smul_one theorem smul_monomial {S₁ : Type*} [SMulZeroClass S₁ R] (r : S₁) : r • monomial s a = monomial s (r • a) := Finsupp.smul_single _ _ _ #align mv_polynomial.smul_monomial MvPolynomial.smul_monomial theorem X_injective [Nontrivial R] : Function.Injective (X : σ → MvPolynomial σ R) := (monomial_left_injective one_ne_zero).comp (Finsupp.single_left_injective one_ne_zero) #align mv_polynomial.X_injective MvPolynomial.X_injective @[simp] theorem X_inj [Nontrivial R] (m n : σ) : X m = (X n : MvPolynomial σ R) ↔ m = n := X_injective.eq_iff #align mv_polynomial.X_inj MvPolynomial.X_inj theorem monomial_pow : monomial s a ^ e = monomial (e • s) (a ^ e) := AddMonoidAlgebra.single_pow e #align mv_polynomial.monomial_pow MvPolynomial.monomial_pow @[simp] theorem monomial_mul {s s' : σ →₀ ℕ} {a b : R} : monomial s a * monomial s' b = monomial (s + s') (a * b) := AddMonoidAlgebra.single_mul_single #align mv_polynomial.monomial_mul MvPolynomial.monomial_mul variable (σ R) /-- `fun s ↦ monomial s 1` as a homomorphism. -/ def monomialOneHom : Multiplicative (σ →₀ ℕ) →* MvPolynomial σ R := AddMonoidAlgebra.of _ _ #align mv_polynomial.monomial_one_hom MvPolynomial.monomialOneHom variable {σ R} @[simp] theorem monomialOneHom_apply : monomialOneHom R σ s = (monomial s 1 : MvPolynomial σ R) := rfl #align mv_polynomial.monomial_one_hom_apply MvPolynomial.monomialOneHom_apply theorem X_pow_eq_monomial : X n ^ e = monomial (Finsupp.single n e) (1 : R) := by simp [X, monomial_pow] #align mv_polynomial.X_pow_eq_monomial MvPolynomial.X_pow_eq_monomial theorem monomial_add_single : monomial (s + Finsupp.single n e) a = monomial s a * X n ^ e := by rw [X_pow_eq_monomial, monomial_mul, mul_one] #align mv_polynomial.monomial_add_single MvPolynomial.monomial_add_single theorem monomial_single_add : monomial (Finsupp.single n e + s) a = X n ^ e * monomial s a := by rw [X_pow_eq_monomial, monomial_mul, one_mul] #align mv_polynomial.monomial_single_add MvPolynomial.monomial_single_add theorem C_mul_X_pow_eq_monomial {s : σ} {a : R} {n : ℕ} : C a * X s ^ n = monomial (Finsupp.single s n) a := by rw [← zero_add (Finsupp.single s n), monomial_add_single, C_apply] #align mv_polynomial.C_mul_X_pow_eq_monomial MvPolynomial.C_mul_X_pow_eq_monomial theorem C_mul_X_eq_monomial {s : σ} {a : R} : C a * X s = monomial (Finsupp.single s 1) a := by rw [← C_mul_X_pow_eq_monomial, pow_one] #align mv_polynomial.C_mul_X_eq_monomial MvPolynomial.C_mul_X_eq_monomial -- Porting note (#10618): `simp` can prove this theorem monomial_zero {s : σ →₀ ℕ} : monomial s (0 : R) = 0 := Finsupp.single_zero _ #align mv_polynomial.monomial_zero MvPolynomial.monomial_zero @[simp] theorem monomial_zero' : (monomial (0 : σ →₀ ℕ) : R → MvPolynomial σ R) = C := rfl #align mv_polynomial.monomial_zero' MvPolynomial.monomial_zero' @[simp] theorem monomial_eq_zero {s : σ →₀ ℕ} {b : R} : monomial s b = 0 ↔ b = 0 := Finsupp.single_eq_zero #align mv_polynomial.monomial_eq_zero MvPolynomial.monomial_eq_zero @[simp] theorem sum_monomial_eq {A : Type*} [AddCommMonoid A] {u : σ →₀ ℕ} {r : R} {b : (σ →₀ ℕ) → R → A} (w : b u 0 = 0) : sum (monomial u r) b = b u r := Finsupp.sum_single_index w #align mv_polynomial.sum_monomial_eq MvPolynomial.sum_monomial_eq @[simp] theorem sum_C {A : Type*} [AddCommMonoid A] {b : (σ →₀ ℕ) → R → A} (w : b 0 0 = 0) : sum (C a) b = b 0 a := sum_monomial_eq w #align mv_polynomial.sum_C MvPolynomial.sum_C theorem monomial_sum_one {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) : (monomial (∑ i ∈ s, f i) 1 : MvPolynomial σ R) = ∏ i ∈ s, monomial (f i) 1 := map_prod (monomialOneHom R σ) (fun i => Multiplicative.ofAdd (f i)) s #align mv_polynomial.monomial_sum_one MvPolynomial.monomial_sum_one theorem monomial_sum_index {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) (a : R) : monomial (∑ i ∈ s, f i) a = C a * ∏ i ∈ s, monomial (f i) 1 := by rw [← monomial_sum_one, C_mul', ← (monomial _).map_smul, smul_eq_mul, mul_one] #align mv_polynomial.monomial_sum_index MvPolynomial.monomial_sum_index theorem monomial_finsupp_sum_index {α β : Type*} [Zero β] (f : α →₀ β) (g : α → β → σ →₀ ℕ) (a : R) : monomial (f.sum g) a = C a * f.prod fun a b => monomial (g a b) 1 := monomial_sum_index _ _ _ #align mv_polynomial.monomial_finsupp_sum_index MvPolynomial.monomial_finsupp_sum_index theorem monomial_eq_monomial_iff {α : Type*} (a₁ a₂ : α →₀ ℕ) (b₁ b₂ : R) : monomial a₁ b₁ = monomial a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 := Finsupp.single_eq_single_iff _ _ _ _ #align mv_polynomial.monomial_eq_monomial_iff MvPolynomial.monomial_eq_monomial_iff theorem monomial_eq : monomial s a = C a * (s.prod fun n e => X n ^ e : MvPolynomial σ R) := by simp only [X_pow_eq_monomial, ← monomial_finsupp_sum_index, Finsupp.sum_single] #align mv_polynomial.monomial_eq MvPolynomial.monomial_eq @[simp] lemma prod_X_pow_eq_monomial : ∏ x ∈ s.support, X x ^ s x = monomial s (1 : R) := by simp only [monomial_eq, map_one, one_mul, Finsupp.prod] theorem induction_on_monomial {M : MvPolynomial σ R → Prop} (h_C : ∀ a, M (C a)) (h_X : ∀ p n, M p → M (p * X n)) : ∀ s a, M (monomial s a) := by intro s a apply @Finsupp.induction σ ℕ _ _ s · show M (monomial 0 a) exact h_C a · intro n e p _hpn _he ih have : ∀ e : ℕ, M (monomial p a * X n ^ e) := by intro e induction e with | zero => simp [ih] | succ e e_ih => simp [ih, pow_succ, (mul_assoc _ _ _).symm, h_X, e_ih] simp [add_comm, monomial_add_single, this] #align mv_polynomial.induction_on_monomial MvPolynomial.induction_on_monomial /-- Analog of `Polynomial.induction_on'`. To prove something about mv_polynomials, it suffices to show the condition is closed under taking sums, and it holds for monomials. -/ @[elab_as_elim] theorem induction_on' {P : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h1 : ∀ (u : σ →₀ ℕ) (a : R), P (monomial u a)) (h2 : ∀ p q : MvPolynomial σ R, P p → P q → P (p + q)) : P p := Finsupp.induction p (suffices P (monomial 0 0) by rwa [monomial_zero] at this show P (monomial 0 0) from h1 0 0) fun a b f _ha _hb hPf => h2 _ _ (h1 _ _) hPf #align mv_polynomial.induction_on' MvPolynomial.induction_on' /-- Similar to `MvPolynomial.induction_on` but only a weak form of `h_add` is required. -/ theorem induction_on''' {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a)) (h_add_weak : ∀ (a : σ →₀ ℕ) (b : R) (f : (σ →₀ ℕ) →₀ R), a ∉ f.support → b ≠ 0 → M f → M ((show (σ →₀ ℕ) →₀ R from monomial a b) + f)) : M p := -- Porting note: I had to add the `show ... from ...` above, a type ascription was insufficient. Finsupp.induction p (C_0.rec <| h_C 0) h_add_weak #align mv_polynomial.induction_on''' MvPolynomial.induction_on''' /-- Similar to `MvPolynomial.induction_on` but only a yet weaker form of `h_add` is required. -/ theorem induction_on'' {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a)) (h_add_weak : ∀ (a : σ →₀ ℕ) (b : R) (f : (σ →₀ ℕ) →₀ R), a ∉ f.support → b ≠ 0 → M f → M (monomial a b) → M ((show (σ →₀ ℕ) →₀ R from monomial a b) + f)) (h_X : ∀ (p : MvPolynomial σ R) (n : σ), M p → M (p * MvPolynomial.X n)) : M p := -- Porting note: I had to add the `show ... from ...` above, a type ascription was insufficient. induction_on''' p h_C fun a b f ha hb hf => h_add_weak a b f ha hb hf <| induction_on_monomial h_C h_X a b #align mv_polynomial.induction_on'' MvPolynomial.induction_on'' /-- Analog of `Polynomial.induction_on`. -/ @[recursor 5] theorem induction_on {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a)) (h_add : ∀ p q, M p → M q → M (p + q)) (h_X : ∀ p n, M p → M (p * X n)) : M p := induction_on'' p h_C (fun a b f _ha _hb hf hm => h_add (monomial a b) f hm hf) h_X #align mv_polynomial.induction_on MvPolynomial.induction_on theorem ringHom_ext {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A} (hC : ∀ r, f (C r) = g (C r)) (hX : ∀ i, f (X i) = g (X i)) : f = g := by refine AddMonoidAlgebra.ringHom_ext' ?_ ?_ -- Porting note: this has high priority, but Lean still chooses `RingHom.ext`, why? -- probably because of the type synonym · ext x exact hC _ · apply Finsupp.mulHom_ext'; intros x -- Porting note: `Finsupp.mulHom_ext'` needs to have increased priority apply MonoidHom.ext_mnat exact hX _ #align mv_polynomial.ring_hom_ext MvPolynomial.ringHom_ext /-- See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem ringHom_ext' {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A} (hC : f.comp C = g.comp C) (hX : ∀ i, f (X i) = g (X i)) : f = g := ringHom_ext (RingHom.ext_iff.1 hC) hX #align mv_polynomial.ring_hom_ext' MvPolynomial.ringHom_ext' theorem hom_eq_hom [Semiring S₂] (f g : MvPolynomial σ R →+* S₂) (hC : f.comp C = g.comp C) (hX : ∀ n : σ, f (X n) = g (X n)) (p : MvPolynomial σ R) : f p = g p := RingHom.congr_fun (ringHom_ext' hC hX) p #align mv_polynomial.hom_eq_hom MvPolynomial.hom_eq_hom theorem is_id (f : MvPolynomial σ R →+* MvPolynomial σ R) (hC : f.comp C = C) (hX : ∀ n : σ, f (X n) = X n) (p : MvPolynomial σ R) : f p = p := hom_eq_hom f (RingHom.id _) hC hX p #align mv_polynomial.is_id MvPolynomial.is_id @[ext 1100] theorem algHom_ext' {A B : Type*} [CommSemiring A] [CommSemiring B] [Algebra R A] [Algebra R B] {f g : MvPolynomial σ A →ₐ[R] B} (h₁ : f.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)) = g.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A))) (h₂ : ∀ i, f (X i) = g (X i)) : f = g := AlgHom.coe_ringHom_injective (MvPolynomial.ringHom_ext' (congr_arg AlgHom.toRingHom h₁) h₂) #align mv_polynomial.alg_hom_ext' MvPolynomial.algHom_ext' @[ext 1200] theorem algHom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : MvPolynomial σ R →ₐ[R] A} (hf : ∀ i : σ, f (X i) = g (X i)) : f = g := AddMonoidAlgebra.algHom_ext' (mulHom_ext' fun X : σ => MonoidHom.ext_mnat (hf X)) #align mv_polynomial.alg_hom_ext MvPolynomial.algHom_ext @[simp] theorem algHom_C {τ : Type*} (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) (r : R) : f (C r) = C r := f.commutes r #align mv_polynomial.alg_hom_C MvPolynomial.algHom_C @[simp] theorem adjoin_range_X : Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) = ⊤ := by set S := Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) refine top_unique fun p hp => ?_; clear hp induction p using MvPolynomial.induction_on with | h_C => exact S.algebraMap_mem _ | h_add p q hp hq => exact S.add_mem hp hq | h_X p i hp => exact S.mul_mem hp (Algebra.subset_adjoin <| mem_range_self _) #align mv_polynomial.adjoin_range_X MvPolynomial.adjoin_range_X @[ext] theorem linearMap_ext {M : Type*} [AddCommMonoid M] [Module R M] {f g : MvPolynomial σ R →ₗ[R] M} (h : ∀ s, f ∘ₗ monomial s = g ∘ₗ monomial s) : f = g := Finsupp.lhom_ext' h #align mv_polynomial.linear_map_ext MvPolynomial.linearMap_ext section Support /-- The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coefficient. -/ def support (p : MvPolynomial σ R) : Finset (σ →₀ ℕ) := Finsupp.support p #align mv_polynomial.support MvPolynomial.support theorem finsupp_support_eq_support (p : MvPolynomial σ R) : Finsupp.support p = p.support := rfl #align mv_polynomial.finsupp_support_eq_support MvPolynomial.finsupp_support_eq_support theorem support_monomial [h : Decidable (a = 0)] : (monomial s a).support = if a = 0 then ∅ else {s} := by rw [← Subsingleton.elim (Classical.decEq R a 0) h] rfl -- Porting note: the proof in Lean 3 wasn't fundamentally better and needed `by convert rfl` -- the issue is the different decidability instances in the `ite` expressions #align mv_polynomial.support_monomial MvPolynomial.support_monomial theorem support_monomial_subset : (monomial s a).support ⊆ {s} := support_single_subset #align mv_polynomial.support_monomial_subset MvPolynomial.support_monomial_subset theorem support_add [DecidableEq σ] : (p + q).support ⊆ p.support ∪ q.support := Finsupp.support_add #align mv_polynomial.support_add MvPolynomial.support_add theorem support_X [Nontrivial R] : (X n : MvPolynomial σ R).support = {Finsupp.single n 1} := by classical rw [X, support_monomial, if_neg]; exact one_ne_zero #align mv_polynomial.support_X MvPolynomial.support_X theorem support_X_pow [Nontrivial R] (s : σ) (n : ℕ) : (X s ^ n : MvPolynomial σ R).support = {Finsupp.single s n} := by classical rw [X_pow_eq_monomial, support_monomial, if_neg (one_ne_zero' R)] #align mv_polynomial.support_X_pow MvPolynomial.support_X_pow @[simp] theorem support_zero : (0 : MvPolynomial σ R).support = ∅ := rfl #align mv_polynomial.support_zero MvPolynomial.support_zero theorem support_smul {S₁ : Type*} [SMulZeroClass S₁ R] {a : S₁} {f : MvPolynomial σ R} : (a • f).support ⊆ f.support := Finsupp.support_smul #align mv_polynomial.support_smul MvPolynomial.support_smul theorem support_sum {α : Type*} [DecidableEq σ] {s : Finset α} {f : α → MvPolynomial σ R} : (∑ x ∈ s, f x).support ⊆ s.biUnion fun x => (f x).support := Finsupp.support_finset_sum #align mv_polynomial.support_sum MvPolynomial.support_sum end Support section Coeff /-- The coefficient of the monomial `m` in the multi-variable polynomial `p`. -/ def coeff (m : σ →₀ ℕ) (p : MvPolynomial σ R) : R := @DFunLike.coe ((σ →₀ ℕ) →₀ R) _ _ _ p m -- Porting note: I changed this from `@CoeFun.coe _ _ (MonoidAlgebra.coeFun _ _) p m` because -- I think it should work better syntactically. They are defeq. #align mv_polynomial.coeff MvPolynomial.coeff @[simp] theorem mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∈ p.support ↔ p.coeff m ≠ 0 := by simp [support, coeff] #align mv_polynomial.mem_support_iff MvPolynomial.mem_support_iff theorem not_mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∉ p.support ↔ p.coeff m = 0 := by simp #align mv_polynomial.not_mem_support_iff MvPolynomial.not_mem_support_iff theorem sum_def {A} [AddCommMonoid A] {p : MvPolynomial σ R} {b : (σ →₀ ℕ) → R → A} : p.sum b = ∑ m ∈ p.support, b m (p.coeff m) := by simp [support, Finsupp.sum, coeff] #align mv_polynomial.sum_def MvPolynomial.sum_def theorem support_mul [DecidableEq σ] (p q : MvPolynomial σ R) : (p * q).support ⊆ p.support + q.support := AddMonoidAlgebra.support_mul p q #align mv_polynomial.support_mul MvPolynomial.support_mul @[ext] theorem ext (p q : MvPolynomial σ R) : (∀ m, coeff m p = coeff m q) → p = q := Finsupp.ext #align mv_polynomial.ext MvPolynomial.ext theorem ext_iff (p q : MvPolynomial σ R) : p = q ↔ ∀ m, coeff m p = coeff m q := ⟨fun h m => by rw [h], ext p q⟩ #align mv_polynomial.ext_iff MvPolynomial.ext_iff @[simp] theorem coeff_add (m : σ →₀ ℕ) (p q : MvPolynomial σ R) : coeff m (p + q) = coeff m p + coeff m q := add_apply p q m #align mv_polynomial.coeff_add MvPolynomial.coeff_add @[simp] theorem coeff_smul {S₁ : Type*} [SMulZeroClass S₁ R] (m : σ →₀ ℕ) (C : S₁) (p : MvPolynomial σ R) : coeff m (C • p) = C • coeff m p := smul_apply C p m #align mv_polynomial.coeff_smul MvPolynomial.coeff_smul @[simp] theorem coeff_zero (m : σ →₀ ℕ) : coeff m (0 : MvPolynomial σ R) = 0 := rfl #align mv_polynomial.coeff_zero MvPolynomial.coeff_zero @[simp] theorem coeff_zero_X (i : σ) : coeff 0 (X i : MvPolynomial σ R) = 0 := single_eq_of_ne fun h => by cases Finsupp.single_eq_zero.1 h #align mv_polynomial.coeff_zero_X MvPolynomial.coeff_zero_X /-- `MvPolynomial.coeff m` but promoted to an `AddMonoidHom`. -/ @[simps] def coeffAddMonoidHom (m : σ →₀ ℕ) : MvPolynomial σ R →+ R where toFun := coeff m map_zero' := coeff_zero m map_add' := coeff_add m #align mv_polynomial.coeff_add_monoid_hom MvPolynomial.coeffAddMonoidHom variable (R) in /-- `MvPolynomial.coeff m` but promoted to a `LinearMap`. -/ @[simps] def lcoeff (m : σ →₀ ℕ) : MvPolynomial σ R →ₗ[R] R where toFun := coeff m map_add' := coeff_add m map_smul' := coeff_smul m theorem coeff_sum {X : Type*} (s : Finset X) (f : X → MvPolynomial σ R) (m : σ →₀ ℕ) : coeff m (∑ x ∈ s, f x) = ∑ x ∈ s, coeff m (f x) := map_sum (@coeffAddMonoidHom R σ _ _) _ s #align mv_polynomial.coeff_sum MvPolynomial.coeff_sum theorem monic_monomial_eq (m) : monomial m (1 : R) = (m.prod fun n e => X n ^ e : MvPolynomial σ R) := by simp [monomial_eq] #align mv_polynomial.monic_monomial_eq MvPolynomial.monic_monomial_eq @[simp] theorem coeff_monomial [DecidableEq σ] (m n) (a) : coeff m (monomial n a : MvPolynomial σ R) = if n = m then a else 0 := Finsupp.single_apply #align mv_polynomial.coeff_monomial MvPolynomial.coeff_monomial @[simp] theorem coeff_C [DecidableEq σ] (m) (a) : coeff m (C a : MvPolynomial σ R) = if 0 = m then a else 0 := Finsupp.single_apply #align mv_polynomial.coeff_C MvPolynomial.coeff_C lemma eq_C_of_isEmpty [IsEmpty σ] (p : MvPolynomial σ R) : p = C (p.coeff 0) := by obtain ⟨x, rfl⟩ := C_surjective σ p simp theorem coeff_one [DecidableEq σ] (m) : coeff m (1 : MvPolynomial σ R) = if 0 = m then 1 else 0 := coeff_C m 1 #align mv_polynomial.coeff_one MvPolynomial.coeff_one @[simp] theorem coeff_zero_C (a) : coeff 0 (C a : MvPolynomial σ R) = a := single_eq_same #align mv_polynomial.coeff_zero_C MvPolynomial.coeff_zero_C @[simp] theorem coeff_zero_one : coeff 0 (1 : MvPolynomial σ R) = 1 := coeff_zero_C 1 #align mv_polynomial.coeff_zero_one MvPolynomial.coeff_zero_one theorem coeff_X_pow [DecidableEq σ] (i : σ) (m) (k : ℕ) : coeff m (X i ^ k : MvPolynomial σ R) = if Finsupp.single i k = m then 1 else 0 := by have := coeff_monomial m (Finsupp.single i k) (1 : R) rwa [@monomial_eq _ _ (1 : R) (Finsupp.single i k) _, C_1, one_mul, Finsupp.prod_single_index] at this exact pow_zero _ #align mv_polynomial.coeff_X_pow MvPolynomial.coeff_X_pow theorem coeff_X' [DecidableEq σ] (i : σ) (m) : coeff m (X i : MvPolynomial σ R) = if Finsupp.single i 1 = m then 1 else 0 := by rw [← coeff_X_pow, pow_one] #align mv_polynomial.coeff_X' MvPolynomial.coeff_X' @[simp] theorem coeff_X (i : σ) : coeff (Finsupp.single i 1) (X i : MvPolynomial σ R) = 1 := by classical rw [coeff_X', if_pos rfl] #align mv_polynomial.coeff_X MvPolynomial.coeff_X @[simp] theorem coeff_C_mul (m) (a : R) (p : MvPolynomial σ R) : coeff m (C a * p) = a * coeff m p := by classical rw [mul_def, sum_C] · simp (config := { contextual := true }) [sum_def, coeff_sum] simp #align mv_polynomial.coeff_C_mul MvPolynomial.coeff_C_mul theorem coeff_mul [DecidableEq σ] (p q : MvPolynomial σ R) (n : σ →₀ ℕ) : coeff n (p * q) = ∑ x ∈ Finset.antidiagonal n, coeff x.1 p * coeff x.2 q := AddMonoidAlgebra.mul_apply_antidiagonal p q _ _ Finset.mem_antidiagonal #align mv_polynomial.coeff_mul MvPolynomial.coeff_mul @[simp] theorem coeff_mul_monomial (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) : coeff (m + s) (p * monomial s r) = coeff m p * r := AddMonoidAlgebra.mul_single_apply_aux p _ _ _ _ fun _a => add_left_inj _ #align mv_polynomial.coeff_mul_monomial MvPolynomial.coeff_mul_monomial @[simp] theorem coeff_monomial_mul (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) : coeff (s + m) (monomial s r * p) = r * coeff m p := AddMonoidAlgebra.single_mul_apply_aux p _ _ _ _ fun _a => add_right_inj _ #align mv_polynomial.coeff_monomial_mul MvPolynomial.coeff_monomial_mul @[simp] theorem coeff_mul_X (m) (s : σ) (p : MvPolynomial σ R) : coeff (m + Finsupp.single s 1) (p * X s) = coeff m p := (coeff_mul_monomial _ _ _ _).trans (mul_one _) #align mv_polynomial.coeff_mul_X MvPolynomial.coeff_mul_X @[simp] theorem coeff_X_mul (m) (s : σ) (p : MvPolynomial σ R) : coeff (Finsupp.single s 1 + m) (X s * p) = coeff m p := (coeff_monomial_mul _ _ _ _).trans (one_mul _) #align mv_polynomial.coeff_X_mul MvPolynomial.coeff_X_mul lemma coeff_single_X_pow [DecidableEq σ] (s s' : σ) (n n' : ℕ) : (X (R := R) s ^ n).coeff (Finsupp.single s' n') = if s = s' ∧ n = n' ∨ n = 0 ∧ n' = 0 then 1 else 0 := by simp only [coeff_X_pow, single_eq_single_iff] @[simp] lemma coeff_single_X [DecidableEq σ] (s s' : σ) (n : ℕ) : (X s).coeff (R := R) (Finsupp.single s' n) = if n = 1 ∧ s = s' then 1 else 0 := by simpa [eq_comm, and_comm] using coeff_single_X_pow s s' 1 n @[simp] theorem support_mul_X (s : σ) (p : MvPolynomial σ R) : (p * X s).support = p.support.map (addRightEmbedding (Finsupp.single s 1)) := AddMonoidAlgebra.support_mul_single p _ (by simp) _ #align mv_polynomial.support_mul_X MvPolynomial.support_mul_X @[simp] theorem support_X_mul (s : σ) (p : MvPolynomial σ R) : (X s * p).support = p.support.map (addLeftEmbedding (Finsupp.single s 1)) := AddMonoidAlgebra.support_single_mul p _ (by simp) _ #align mv_polynomial.support_X_mul MvPolynomial.support_X_mul @[simp] theorem support_smul_eq {S₁ : Type*} [Semiring S₁] [Module S₁ R] [NoZeroSMulDivisors S₁ R] {a : S₁} (h : a ≠ 0) (p : MvPolynomial σ R) : (a • p).support = p.support := Finsupp.support_smul_eq h #align mv_polynomial.support_smul_eq MvPolynomial.support_smul_eq theorem support_sdiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) : p.support \ q.support ⊆ (p + q).support := by intro m hm simp only [Classical.not_not, mem_support_iff, Finset.mem_sdiff, Ne] at hm simp [hm.2, hm.1] #align mv_polynomial.support_sdiff_support_subset_support_add MvPolynomial.support_sdiff_support_subset_support_add open scoped symmDiff in theorem support_symmDiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) : p.support ∆ q.support ⊆ (p + q).support := by rw [symmDiff_def, Finset.sup_eq_union] apply Finset.union_subset · exact support_sdiff_support_subset_support_add p q · rw [add_comm] exact support_sdiff_support_subset_support_add q p #align mv_polynomial.support_symm_diff_support_subset_support_add MvPolynomial.support_symmDiff_support_subset_support_add theorem coeff_mul_monomial' (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) : coeff m (p * monomial s r) = if s ≤ m then coeff (m - s) p * r else 0 := by classical split_ifs with h · conv_rhs => rw [← coeff_mul_monomial _ s] congr with t rw [tsub_add_cancel_of_le h] · contrapose! h rw [← mem_support_iff] at h obtain ⟨j, -, rfl⟩ : ∃ j ∈ support p, j + s = m := by simpa [Finset.add_singleton] using Finset.add_subset_add_left support_monomial_subset <| support_mul _ _ h exact le_add_left le_rfl #align mv_polynomial.coeff_mul_monomial' MvPolynomial.coeff_mul_monomial' theorem coeff_monomial_mul' (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) : coeff m (monomial s r * p) = if s ≤ m then r * coeff (m - s) p else 0 := by -- note that if we allow `R` to be non-commutative we will have to duplicate the proof above. rw [mul_comm, mul_comm r] exact coeff_mul_monomial' _ _ _ _ #align mv_polynomial.coeff_monomial_mul' MvPolynomial.coeff_monomial_mul' theorem coeff_mul_X' [DecidableEq σ] (m) (s : σ) (p : MvPolynomial σ R) : coeff m (p * X s) = if s ∈ m.support then coeff (m - Finsupp.single s 1) p else 0 := by refine (coeff_mul_monomial' _ _ _ _).trans ?_ simp_rw [Finsupp.single_le_iff, Finsupp.mem_support_iff, Nat.succ_le_iff, pos_iff_ne_zero, mul_one] #align mv_polynomial.coeff_mul_X' MvPolynomial.coeff_mul_X' theorem coeff_X_mul' [DecidableEq σ] (m) (s : σ) (p : MvPolynomial σ R) : coeff m (X s * p) = if s ∈ m.support then coeff (m - Finsupp.single s 1) p else 0 := by refine (coeff_monomial_mul' _ _ _ _).trans ?_ simp_rw [Finsupp.single_le_iff, Finsupp.mem_support_iff, Nat.succ_le_iff, pos_iff_ne_zero, one_mul] #align mv_polynomial.coeff_X_mul' MvPolynomial.coeff_X_mul' theorem eq_zero_iff {p : MvPolynomial σ R} : p = 0 ↔ ∀ d, coeff d p = 0 := by rw [ext_iff] simp only [coeff_zero] #align mv_polynomial.eq_zero_iff MvPolynomial.eq_zero_iff theorem ne_zero_iff {p : MvPolynomial σ R} : p ≠ 0 ↔ ∃ d, coeff d p ≠ 0 := by rw [Ne, eq_zero_iff] push_neg rfl #align mv_polynomial.ne_zero_iff MvPolynomial.ne_zero_iff @[simp]
Mathlib/Algebra/MvPolynomial/Basic.lean
843
847
theorem X_ne_zero [Nontrivial R] (s : σ) : X (R := R) s ≠ 0 := by
rw [ne_zero_iff] use Finsupp.single s 1 simp only [coeff_X, ne_eq, one_ne_zero, not_false_eq_true]
/- 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.Data.List.Sublists import Mathlib.Data.Multiset.Bind #align_import data.multiset.powerset from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # The powerset of a multiset -/ namespace Multiset open List variable {α : Type*} /-! ### powerset -/ -- Porting note (#11215): TODO: Write a more efficient version /-- A helper function for the powerset of a multiset. Given a list `l`, returns a list of sublists of `l` as multisets. -/ def powersetAux (l : List α) : List (Multiset α) := (sublists l).map (↑) #align multiset.powerset_aux Multiset.powersetAux theorem powersetAux_eq_map_coe {l : List α} : powersetAux l = (sublists l).map (↑) := rfl #align multiset.powerset_aux_eq_map_coe Multiset.powersetAux_eq_map_coe @[simp] theorem mem_powersetAux {l : List α} {s} : s ∈ powersetAux l ↔ s ≤ ↑l := Quotient.inductionOn s <| by simp [powersetAux_eq_map_coe, Subperm, and_comm] #align multiset.mem_powerset_aux Multiset.mem_powersetAux /-- Helper function for the powerset of a multiset. Given a list `l`, returns a list of sublists of `l` (using `sublists'`), as multisets. -/ def powersetAux' (l : List α) : List (Multiset α) := (sublists' l).map (↑) #align multiset.powerset_aux' Multiset.powersetAux' theorem powersetAux_perm_powersetAux' {l : List α} : powersetAux l ~ powersetAux' l := by rw [powersetAux_eq_map_coe]; exact (sublists_perm_sublists' _).map _ #align multiset.powerset_aux_perm_powerset_aux' Multiset.powersetAux_perm_powersetAux' @[simp] theorem powersetAux'_nil : powersetAux' (@nil α) = [0] := rfl #align multiset.powerset_aux'_nil Multiset.powersetAux'_nil @[simp]
Mathlib/Data/Multiset/Powerset.lean
55
57
theorem powersetAux'_cons (a : α) (l : List α) : powersetAux' (a :: l) = powersetAux' l ++ List.map (cons a) (powersetAux' l) := by
simp only [powersetAux', sublists'_cons, map_append, List.map_map, append_cancel_left_eq]; rfl
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.SetTheory.Cardinal.Finite #align_import data.set.ncard from "leanprover-community/mathlib"@"74c2af38a828107941029b03839882c5c6f87a04" /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `PartENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {α β : Type*} {s t : Set α} /-- The cardinality of a set as a term in `ℕ∞` -/ noncomputable def encard (s : Set α) : ℕ∞ := PartENat.withTopEquiv (PartENat.card s) @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by rw [encard, encard, PartENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (α : Type*) : encard (univ : Set α) = PartENat.withTopEquiv (PartENat.card α) := by rw [encard, PartENat.card_congr (Equiv.Set.univ α)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, PartENat.card_eq_coe_fintype_card, PartENat.withTopEquiv_natCast, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by have := h.to_subtype rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.withTopEquiv_symm_top, PartENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.withTopEquiv_symm_zero, PartENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]; rfl theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by classical have e := (Equiv.Set.union (by rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty])).symm simp [encard, ← PartENat.card_congr e, PartENat.card_sum, PartENat.withTopEquiv] theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by rw [← union_singleton, encard_union_eq (by simpa), encard_singleton] theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by refine h.induction_on (by simp) ?_ rintro a t hat _ ht' rw [encard_insert_of_not_mem hat] exact lt_tsub_iff_right.1 ht' theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard := (ENat.coe_toNat h.encard_lt_top.ne).symm theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n := ⟨_, h.encard_eq_coe⟩ @[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite := ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩ @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite] theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by simp theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _) theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite := finite_of_encard_le_coe h.le theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k := ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩, fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩ section Lattice theorem encard_le_card (h : s ⊆ t) : s.encard ≤ t.encard := by rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) := fun _ _ ↦ encard_le_card theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h] @[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero] theorem encard_diff_add_encard_inter (s t : Set α) : (s \ t).encard + (s ∩ t).encard = s.encard := by rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left), diff_union_inter] theorem encard_union_add_encard_inter (s t : Set α) : (s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm, encard_diff_add_encard_inter] theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) : s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_right_cancel_iff h.encard_lt_top.ne] theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) : s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_le_add_iff_right h.encard_lt_top.ne] theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) : s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_lt_add_iff_right h.encard_lt_top.ne] theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by rw [← encard_union_add_encard_inter]; exact le_self_add theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by rw [← encard_lt_top_iff, ← encard_lt_top_iff, h] theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) : s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff] theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite) (h : t.encard ≤ s.encard) : t.Finite := encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top) theorem Finite.eq_of_subset_of_encard_le (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := by rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff exact hst.antisymm hdiff theorem Finite.eq_of_subset_of_encard_le' (hs : s.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le hst hts theorem Finite.encard_lt_encard (ht : t.Finite) (h : s ⊂ t) : s.encard < t.encard := (encard_mono h.subset).lt_of_ne (fun he ↦ h.ne (ht.eq_of_subset_of_encard_le h.subset he.symm.le)) theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) := fun _ _ h ↦ (toFinite _).encard_lt_encard h theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self] theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard := (encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by rw [← encard_union_eq disjoint_compl_right, union_compl_self] end Lattice section InsertErase variable {a b : α}
Mathlib/Data/Set/Card.lean
237
238
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Mario Carneiro -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds #align_import data.real.pi.bounds from "leanprover-community/mathlib"@"402f8982dddc1864bd703da2d6e2ee304a866973" /-! # Pi This file contains lemmas which establish bounds on `real.pi`. Notably, these include `pi_gt_sqrtTwoAddSeries` and `pi_lt_sqrtTwoAddSeries`, which bound `π` using series; numerical bounds on `π` such as `pi_gt_314`and `pi_lt_315` (more precise versions are given, too). See also `Mathlib/Data/Real/Pi/Leibniz.lean` and `Mathlib/Data/Real/Pi/Wallis.lean` for infinite formulas for `π`. -/ -- Porting note: needed to add a lot of type ascriptions for lean to interpret numbers as reals. open scoped Real namespace Real theorem pi_gt_sqrtTwoAddSeries (n : ℕ) : (2 : ℝ) ^ (n + 1) * √(2 - sqrtTwoAddSeries 0 n) < π := by have : √(2 - sqrtTwoAddSeries 0 n) / (2 : ℝ) * (2 : ℝ) ^ (n + 2) < π := by rw [← lt_div_iff, ← sin_pi_over_two_pow_succ] focus apply sin_lt apply div_pos pi_pos all_goals apply pow_pos; norm_num apply lt_of_le_of_lt (le_of_eq _) this rw [pow_succ' _ (n + 1), ← mul_assoc, div_mul_cancel₀, mul_comm]; norm_num #align real.pi_gt_sqrt_two_add_series Real.pi_gt_sqrtTwoAddSeries theorem pi_lt_sqrtTwoAddSeries (n : ℕ) : π < (2 : ℝ) ^ (n + 1) * √(2 - sqrtTwoAddSeries 0 n) + 1 / (4 : ℝ) ^ n := by have : π < (√(2 - sqrtTwoAddSeries 0 n) / (2 : ℝ) + (1 : ℝ) / ((2 : ℝ) ^ n) ^ 3 / 4) * (2 : ℝ) ^ (n + 2) := by rw [← div_lt_iff (by norm_num), ← sin_pi_over_two_pow_succ] refine lt_of_lt_of_le (lt_add_of_sub_right_lt (sin_gt_sub_cube ?_ ?_)) ?_ · apply div_pos pi_pos; apply pow_pos; norm_num · rw [div_le_iff'] · refine le_trans pi_le_four ?_ simp only [show (4 : ℝ) = (2 : ℝ) ^ 2 by norm_num, mul_one] apply pow_le_pow_right (by norm_num) apply le_add_of_nonneg_left; apply Nat.zero_le · apply pow_pos; norm_num apply add_le_add_left; rw [div_le_div_right (by norm_num)] rw [le_div_iff (by norm_num), ← mul_pow] refine le_trans ?_ (le_of_eq (one_pow 3)); apply pow_le_pow_left · apply le_of_lt; apply mul_pos · apply div_pos pi_pos; apply pow_pos; norm_num · apply pow_pos; norm_num · rw [← le_div_iff (by norm_num)] refine le_trans ((div_le_div_right ?_).mpr pi_le_four) ?_ · apply pow_pos; norm_num · simp only [pow_succ', ← div_div, one_div] -- Porting note: removed `convert le_rfl` norm_num apply lt_of_lt_of_le this (le_of_eq _); rw [add_mul]; congr 1 · ring simp only [show (4 : ℝ) = 2 ^ 2 by norm_num, ← pow_mul, div_div, ← pow_add] rw [one_div, one_div, inv_mul_eq_iff_eq_mul₀, eq_comm, mul_inv_eq_iff_eq_mul₀, ← pow_add] · rw [add_assoc, Nat.mul_succ, add_comm, add_comm n, add_assoc, mul_comm n] all_goals norm_num #align real.pi_lt_sqrt_two_add_series Real.pi_lt_sqrtTwoAddSeries /-- From an upper bound on `sqrtTwoAddSeries 0 n = 2 cos (π / 2 ^ (n+1))` of the form `sqrtTwoAddSeries 0 n ≤ 2 - (a / 2 ^ (n + 1)) ^ 2)`, one can deduce the lower bound `a < π` thanks to basic trigonometric inequalities as expressed in `pi_gt_sqrtTwoAddSeries`. -/ theorem pi_lower_bound_start (n : ℕ) {a} (h : sqrtTwoAddSeries ((0 : ℕ) / (1 : ℕ)) n ≤ (2 : ℝ) - (a / (2 : ℝ) ^ (n + 1)) ^ 2) : a < π := by refine lt_of_le_of_lt ?_ (pi_gt_sqrtTwoAddSeries n); rw [mul_comm] refine (div_le_iff (pow_pos (by norm_num) _ : (0 : ℝ) < _)).mp (le_sqrt_of_sq_le ?_) rwa [le_sub_comm, show (0 : ℝ) = (0 : ℕ) / (1 : ℕ) by rw [Nat.cast_zero, zero_div]] #align real.pi_lower_bound_start Real.pi_lower_bound_start theorem sqrtTwoAddSeries_step_up (c d : ℕ) {a b n : ℕ} {z : ℝ} (hz : sqrtTwoAddSeries (c / d) n ≤ z) (hb : 0 < b) (hd : 0 < d) (h : (2 * b + a) * d ^ 2 ≤ c ^ 2 * b) : sqrtTwoAddSeries (a / b) (n + 1) ≤ z := by refine le_trans ?_ hz; rw [sqrtTwoAddSeries_succ]; apply sqrtTwoAddSeries_monotone_left have hb' : 0 < (b : ℝ) := Nat.cast_pos.2 hb have hd' : 0 < (d : ℝ) := Nat.cast_pos.2 hd rw [sqrt_le_left (div_nonneg c.cast_nonneg d.cast_nonneg), div_pow, add_div_eq_mul_add_div _ _ (ne_of_gt hb'), div_le_div_iff hb' (pow_pos hd' _)] exact mod_cast h #align real.sqrt_two_add_series_step_up Real.sqrtTwoAddSeries_step_up section Tactic open Lean Elab Tactic /-- `numDen stx` takes a syntax expression `stx` and * if it is of the form `a / b`, then it returns `some (a, b)`; * otherwise it returns `none`. -/ private def numDen : Syntax → Option (Syntax.Term × Syntax.Term) | `($a / $b) => some (a, b) | _ => none /-- Create a proof of `a < π` for a fixed rational number `a`, given a witness, which is a sequence of rational numbers `√2 < r 1 < r 2 < ... < r n < 2` satisfying the property that `√(2 + r i) ≤ r(i+1)`, where `r 0 = 0` and `√(2 - r n) ≥ a/2^(n+1)`. -/ elab "pi_lower_bound " "[" l:term,* "]" : tactic => do let rat_sep := l.elemsAndSeps let sep := rat_sep.getD 1 .missing let ratStx := rat_sep.filter (· != sep) let n := ← (toExpr ratStx.size).toSyntax let els := (ratStx.map numDen).reduceOption evalTactic (← `(tactic| apply pi_lower_bound_start $n)) let _ := ← els.mapM fun (x, y) => do evalTactic (← `(tactic| apply sqrtTwoAddSeries_step_up $x $y)) evalTactic (← `(tactic| simp [sqrtTwoAddSeries])) allGoals (evalTactic (← `(tactic| norm_num1))) end Tactic /-- From a lower bound on `sqrtTwoAddSeries 0 n = 2 cos (π / 2 ^ (n+1))` of the form `2 - ((a - 1 / 4 ^ n) / 2 ^ (n + 1)) ^ 2 ≤ sqrtTwoAddSeries 0 n`, one can deduce the upper bound `π < a` thanks to basic trigonometric formulas as expressed in `pi_lt_sqrtTwoAddSeries`. -/
Mathlib/Data/Real/Pi/Bounds.lean
128
136
theorem pi_upper_bound_start (n : ℕ) {a} (h : (2 : ℝ) - ((a - 1 / (4 : ℝ) ^ n) / (2 : ℝ) ^ (n + 1)) ^ 2 ≤ sqrtTwoAddSeries ((0 : ℕ) / (1 : ℕ)) n) (h₂ : (1 : ℝ) / (4 : ℝ) ^ n ≤ a) : π < a := by
refine lt_of_lt_of_le (pi_lt_sqrtTwoAddSeries n) ?_ rw [← le_sub_iff_add_le, ← le_div_iff', sqrt_le_left, sub_le_comm] · rwa [Nat.cast_zero, zero_div] at h · exact div_nonneg (sub_nonneg.2 h₂) (pow_nonneg (le_of_lt zero_lt_two) _) · exact pow_pos zero_lt_two _
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Alistair Tucker, Wen Yang -/ import Mathlib.Order.Interval.Set.Image import Mathlib.Order.CompleteLatticeIntervals import Mathlib.Topology.Order.DenselyOrdered import Mathlib.Topology.Order.Monotone #align_import topology.algebra.order.intermediate_value from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514" /-! # Intermediate Value Theorem In this file we prove the Intermediate Value Theorem: if `f : α → β` is a function defined on a connected set `s` that takes both values `≤ a` and values `≥ a` on `s`, then it is equal to `a` at some point of `s`. We also prove that intervals in a dense conditionally complete order are preconnected and any preconnected set is an interval. Then we specialize IVT to functions continuous on intervals. ## Main results * `IsPreconnected_I??` : all intervals `I??` are preconnected, * `IsPreconnected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for connected sets and connected spaces, respectively; * `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions on closed intervals. ### Miscellaneous facts * `IsClosed.Icc_subset_of_forall_mem_nhdsWithin` : “Continuous induction” principle; if `s ∩ [a, b]` is closed, `a ∈ s`, and for each `x ∈ [a, b) ∩ s` some of its right neighborhoods is included `s`, then `[a, b] ⊆ s`. * `IsClosed.Icc_subset_of_forall_exists_gt`, `IsClosed.mem_of_ge_of_forall_exists_gt` : two other versions of the “continuous induction” principle. * `ContinuousOn.StrictMonoOn_of_InjOn_Ioo` : Every continuous injective `f : (a, b) → δ` is strictly monotone or antitone (increasing or decreasing). ## Tags intermediate value theorem, connected space, connected set -/ open Filter OrderDual TopologicalSpace Function Set open Topology Filter universe u v w /-! ### Intermediate value theorem on a (pre)connected space In this section we prove the following theorem (see `IsPreconnected.intermediate_value₂`): if `f` and `g` are two functions continuous on a preconnected set `s`, `f a ≤ g a` at some `a ∈ s` and `g b ≤ f b` at some `b ∈ s`, then `f c = g c` at some `c ∈ s`. We prove several versions of this statement, including the classical IVT that corresponds to a constant function `g`. -/ section variable {X : Type u} {α : Type v} [TopologicalSpace X] [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] /-- Intermediate value theorem for two functions: if `f` and `g` are two continuous functions on a preconnected space and `f a ≤ g a` and `g b ≤ f b`, then for some `x` we have `f x = g x`. -/ theorem intermediate_value_univ₂ [PreconnectedSpace X] {a b : X} {f g : X → α} (hf : Continuous f) (hg : Continuous g) (ha : f a ≤ g a) (hb : g b ≤ f b) : ∃ x, f x = g x := by obtain ⟨x, _, hfg, hgf⟩ : (univ ∩ { x | f x ≤ g x ∧ g x ≤ f x }).Nonempty := isPreconnected_closed_iff.1 PreconnectedSpace.isPreconnected_univ _ _ (isClosed_le hf hg) (isClosed_le hg hf) (fun _ _ => le_total _ _) ⟨a, trivial, ha⟩ ⟨b, trivial, hb⟩ exact ⟨x, le_antisymm hfg hgf⟩ #align intermediate_value_univ₂ intermediate_value_univ₂ theorem intermediate_value_univ₂_eventually₁ [PreconnectedSpace X] {a : X} {l : Filter X} [NeBot l] {f g : X → α} (hf : Continuous f) (hg : Continuous g) (ha : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x, f x = g x := let ⟨_, h⟩ := he.exists; intermediate_value_univ₂ hf hg ha h #align intermediate_value_univ₂_eventually₁ intermediate_value_univ₂_eventually₁ theorem intermediate_value_univ₂_eventually₂ [PreconnectedSpace X] {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] {f g : X → α} (hf : Continuous f) (hg : Continuous g) (he₁ : f ≤ᶠ[l₁] g) (he₂ : g ≤ᶠ[l₂] f) : ∃ x, f x = g x := let ⟨_, h₁⟩ := he₁.exists let ⟨_, h₂⟩ := he₂.exists intermediate_value_univ₂ hf hg h₁ h₂ #align intermediate_value_univ₂_eventually₂ intermediate_value_univ₂_eventually₂ /-- Intermediate value theorem for two functions: if `f` and `g` are two functions continuous on a preconnected set `s` and for some `a b ∈ s` we have `f a ≤ g a` and `g b ≤ f b`, then for some `x ∈ s` we have `f x = g x`. -/ theorem IsPreconnected.intermediate_value₂ {s : Set X} (hs : IsPreconnected s) {a b : X} (ha : a ∈ s) (hb : b ∈ s) {f g : X → α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (ha' : f a ≤ g a) (hb' : g b ≤ f b) : ∃ x ∈ s, f x = g x := let ⟨x, hx⟩ := @intermediate_value_univ₂ s α _ _ _ _ (Subtype.preconnectedSpace hs) ⟨a, ha⟩ ⟨b, hb⟩ _ _ (continuousOn_iff_continuous_restrict.1 hf) (continuousOn_iff_continuous_restrict.1 hg) ha' hb' ⟨x, x.2, hx⟩ #align is_preconnected.intermediate_value₂ IsPreconnected.intermediate_value₂ theorem IsPreconnected.intermediate_value₂_eventually₁ {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f g : X → α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (ha' : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x ∈ s, f x = g x := by rw [continuousOn_iff_continuous_restrict] at hf hg obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₁ _ _ _ _ _ _ (Subtype.preconnectedSpace hs) ⟨a, ha⟩ _ (comap_coe_neBot_of_le_principal hl) _ _ hf hg ha' (he.comap _) exact ⟨b, b.prop, h⟩ #align is_preconnected.intermediate_value₂_eventually₁ IsPreconnected.intermediate_value₂_eventually₁ theorem IsPreconnected.intermediate_value₂_eventually₂ {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f g : X → α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (he₁ : f ≤ᶠ[l₁] g) (he₂ : g ≤ᶠ[l₂] f) : ∃ x ∈ s, f x = g x := by rw [continuousOn_iff_continuous_restrict] at hf hg obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₂ _ _ _ _ _ _ (Subtype.preconnectedSpace hs) _ _ (comap_coe_neBot_of_le_principal hl₁) (comap_coe_neBot_of_le_principal hl₂) _ _ hf hg (he₁.comap _) (he₂.comap _) exact ⟨b, b.prop, h⟩ #align is_preconnected.intermediate_value₂_eventually₂ IsPreconnected.intermediate_value₂_eventually₂ /-- **Intermediate Value Theorem** for continuous functions on connected sets. -/ theorem IsPreconnected.intermediate_value {s : Set X} (hs : IsPreconnected s) {a b : X} (ha : a ∈ s) (hb : b ∈ s) {f : X → α} (hf : ContinuousOn f s) : Icc (f a) (f b) ⊆ f '' s := fun _x hx => hs.intermediate_value₂ ha hb hf continuousOn_const hx.1 hx.2 #align is_preconnected.intermediate_value IsPreconnected.intermediate_value theorem IsPreconnected.intermediate_value_Ico {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht : Tendsto f l (𝓝 v)) : Ico (f a) v ⊆ f '' s := fun _ h => hs.intermediate_value₂_eventually₁ ha hl hf continuousOn_const h.1 (eventually_ge_of_tendsto_gt h.2 ht) #align is_preconnected.intermediate_value_Ico IsPreconnected.intermediate_value_Ico theorem IsPreconnected.intermediate_value_Ioc {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht : Tendsto f l (𝓝 v)) : Ioc v (f a) ⊆ f '' s := fun _ h => (hs.intermediate_value₂_eventually₁ ha hl continuousOn_const hf h.2 (eventually_le_of_tendsto_lt h.1 ht)).imp fun _ h => h.imp_right Eq.symm #align is_preconnected.intermediate_value_Ioc IsPreconnected.intermediate_value_Ioc theorem IsPreconnected.intermediate_value_Ioo {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v₁ v₂ : α} (ht₁ : Tendsto f l₁ (𝓝 v₁)) (ht₂ : Tendsto f l₂ (𝓝 v₂)) : Ioo v₁ v₂ ⊆ f '' s := fun _ h => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (eventually_le_of_tendsto_lt h.1 ht₁) (eventually_ge_of_tendsto_gt h.2 ht₂) #align is_preconnected.intermediate_value_Ioo IsPreconnected.intermediate_value_Ioo theorem IsPreconnected.intermediate_value_Ici {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) (ht : Tendsto f l atTop) : Ici (f a) ⊆ f '' s := fun y h => hs.intermediate_value₂_eventually₁ ha hl hf continuousOn_const h (tendsto_atTop.1 ht y) #align is_preconnected.intermediate_value_Ici IsPreconnected.intermediate_value_Ici theorem IsPreconnected.intermediate_value_Iic {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) (ht : Tendsto f l atBot) : Iic (f a) ⊆ f '' s := fun y h => (hs.intermediate_value₂_eventually₁ ha hl continuousOn_const hf h (tendsto_atBot.1 ht y)).imp fun _ h => h.imp_right Eq.symm #align is_preconnected.intermediate_value_Iic IsPreconnected.intermediate_value_Iic theorem IsPreconnected.intermediate_value_Ioi {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht₁ : Tendsto f l₁ (𝓝 v)) (ht₂ : Tendsto f l₂ atTop) : Ioi v ⊆ f '' s := fun y h => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (eventually_le_of_tendsto_lt h ht₁) (tendsto_atTop.1 ht₂ y) #align is_preconnected.intermediate_value_Ioi IsPreconnected.intermediate_value_Ioi theorem IsPreconnected.intermediate_value_Iio {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht₁ : Tendsto f l₁ atBot) (ht₂ : Tendsto f l₂ (𝓝 v)) : Iio v ⊆ f '' s := fun y h => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (tendsto_atBot.1 ht₁ y) (eventually_ge_of_tendsto_gt h ht₂) #align is_preconnected.intermediate_value_Iio IsPreconnected.intermediate_value_Iio theorem IsPreconnected.intermediate_value_Iii {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) (ht₁ : Tendsto f l₁ atBot) (ht₂ : Tendsto f l₂ atTop) : univ ⊆ f '' s := fun y _ => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (tendsto_atBot.1 ht₁ y) (tendsto_atTop.1 ht₂ y) set_option linter.uppercaseLean3 false in #align is_preconnected.intermediate_value_Iii IsPreconnected.intermediate_value_Iii /-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/ theorem intermediate_value_univ [PreconnectedSpace X] (a b : X) {f : X → α} (hf : Continuous f) : Icc (f a) (f b) ⊆ range f := fun _ hx => intermediate_value_univ₂ hf continuous_const hx.1 hx.2 #align intermediate_value_univ intermediate_value_univ /-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/ theorem mem_range_of_exists_le_of_exists_ge [PreconnectedSpace X] {c : α} {f : X → α} (hf : Continuous f) (h₁ : ∃ a, f a ≤ c) (h₂ : ∃ b, c ≤ f b) : c ∈ range f := let ⟨a, ha⟩ := h₁; let ⟨b, hb⟩ := h₂; intermediate_value_univ a b hf ⟨ha, hb⟩ #align mem_range_of_exists_le_of_exists_ge mem_range_of_exists_le_of_exists_ge /-! ### (Pre)connected sets in a linear order In this section we prove the following results: * `IsPreconnected.ordConnected`: any preconnected set `s` in a linear order is `OrdConnected`, i.e. `a ∈ s` and `b ∈ s` imply `Icc a b ⊆ s`; * `IsPreconnected.mem_intervals`: any preconnected set `s` in a conditionally complete linear order is one of the intervals `Set.Icc`, `set.`Ico`, `set.Ioc`, `set.Ioo`, ``Set.Ici`, `Set.Iic`, `Set.Ioi`, `Set.Iio`; note that this is false for non-complete orders: e.g., in `ℝ \ {0}`, the set of positive numbers cannot be represented as `Set.Ioi _`. -/ /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ theorem IsPreconnected.Icc_subset {s : Set α} (hs : IsPreconnected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := by simpa only [image_id] using hs.intermediate_value ha hb continuousOn_id #align is_preconnected.Icc_subset IsPreconnected.Icc_subset theorem IsPreconnected.ordConnected {s : Set α} (h : IsPreconnected s) : OrdConnected s := ⟨fun _ hx _ hy => h.Icc_subset hx hy⟩ #align is_preconnected.ord_connected IsPreconnected.ordConnected /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ theorem IsConnected.Icc_subset {s : Set α} (hs : IsConnected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := hs.2.Icc_subset ha hb #align is_connected.Icc_subset IsConnected.Icc_subset /-- If preconnected set in a linear order space is unbounded below and above, then it is the whole space. -/ theorem IsPreconnected.eq_univ_of_unbounded {s : Set α} (hs : IsPreconnected s) (hb : ¬BddBelow s) (ha : ¬BddAbove s) : s = univ := by refine eq_univ_of_forall fun x => ?_ obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := not_bddBelow_iff.1 hb x obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bddAbove_iff.1 ha x exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩ #align is_preconnected.eq_univ_of_unbounded IsPreconnected.eq_univ_of_unbounded end variable {α : Type u} {β : Type v} {γ : Type w} [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] [Nonempty γ] /-- A bounded connected subset of a conditionally complete linear order includes the open interval `(Inf s, Sup s)`. -/ theorem IsConnected.Ioo_csInf_csSup_subset {s : Set α} (hs : IsConnected s) (hb : BddBelow s) (ha : BddAbove s) : Ioo (sInf s) (sSup s) ⊆ s := fun _x hx => let ⟨_y, ys, hy⟩ := (isGLB_lt_iff (isGLB_csInf hs.nonempty hb)).1 hx.1 let ⟨_z, zs, hz⟩ := (lt_isLUB_iff (isLUB_csSup hs.nonempty ha)).1 hx.2 hs.Icc_subset ys zs ⟨hy.le, hz.le⟩ #align is_connected.Ioo_cInf_cSup_subset IsConnected.Ioo_csInf_csSup_subset theorem eq_Icc_csInf_csSup_of_connected_bdd_closed {s : Set α} (hc : IsConnected s) (hb : BddBelow s) (ha : BddAbove s) (hcl : IsClosed s) : s = Icc (sInf s) (sSup s) := (subset_Icc_csInf_csSup hb ha).antisymm <| hc.Icc_subset (hcl.csInf_mem hc.nonempty hb) (hcl.csSup_mem hc.nonempty ha) #align eq_Icc_cInf_cSup_of_connected_bdd_closed eq_Icc_csInf_csSup_of_connected_bdd_closed theorem IsPreconnected.Ioi_csInf_subset {s : Set α} (hs : IsPreconnected s) (hb : BddBelow s) (ha : ¬BddAbove s) : Ioi (sInf s) ⊆ s := fun x hx => have sne : s.Nonempty := nonempty_of_not_bddAbove ha let ⟨_y, ys, hy⟩ : ∃ y ∈ s, y < x := (isGLB_lt_iff (isGLB_csInf sne hb)).1 hx let ⟨_z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bddAbove_iff.1 ha x hs.Icc_subset ys zs ⟨hy.le, hz.le⟩ #align is_preconnected.Ioi_cInf_subset IsPreconnected.Ioi_csInf_subset theorem IsPreconnected.Iio_csSup_subset {s : Set α} (hs : IsPreconnected s) (hb : ¬BddBelow s) (ha : BddAbove s) : Iio (sSup s) ⊆ s := IsPreconnected.Ioi_csInf_subset (α := αᵒᵈ) hs ha hb #align is_preconnected.Iio_cSup_subset IsPreconnected.Iio_csSup_subset /-- A preconnected set in a conditionally complete linear order is either one of the intervals `[Inf s, Sup s]`, `[Inf s, Sup s)`, `(Inf s, Sup s]`, `(Inf s, Sup s)`, `[Inf s, +∞)`, `(Inf s, +∞)`, `(-∞, Sup s]`, `(-∞, Sup s)`, `(-∞, +∞)`, or `∅`. The converse statement requires `α` to be densely ordered. -/ theorem IsPreconnected.mem_intervals {s : Set α} (hs : IsPreconnected s) : s ∈ ({Icc (sInf s) (sSup s), Ico (sInf s) (sSup s), Ioc (sInf s) (sSup s), Ioo (sInf s) (sSup s), Ici (sInf s), Ioi (sInf s), Iic (sSup s), Iio (sSup s), univ, ∅} : Set (Set α)) := by rcases s.eq_empty_or_nonempty with (rfl | hne) · apply_rules [Or.inr, mem_singleton] have hs' : IsConnected s := ⟨hne, hs⟩ by_cases hb : BddBelow s <;> by_cases ha : BddAbove s · refine mem_of_subset_of_mem ?_ <| mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset (hs'.Ioo_csInf_csSup_subset hb ha) (subset_Icc_csInf_csSup hb ha) simp only [insert_subset_iff, mem_insert_iff, mem_singleton_iff, true_or, or_true, singleton_subset_iff, and_self] · refine Or.inr <| Or.inr <| Or.inr <| Or.inr ?_ cases' mem_Ici_Ioi_of_subset_of_subset (hs.Ioi_csInf_subset hb ha) fun x hx => csInf_le hb hx with hs hs · exact Or.inl hs · exact Or.inr (Or.inl hs) · iterate 6 apply Or.inr cases' mem_Iic_Iio_of_subset_of_subset (hs.Iio_csSup_subset hb ha) fun x hx => le_csSup ha hx with hs hs · exact Or.inl hs · exact Or.inr (Or.inl hs) · iterate 8 apply Or.inr exact Or.inl (hs.eq_univ_of_unbounded hb ha) #align is_preconnected.mem_intervals IsPreconnected.mem_intervals /-- A preconnected set is either one of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, or `univ`, or `∅`. The converse statement requires `α` to be densely ordered. Though one can represent `∅` as `(Inf ∅, Inf ∅)`, we include it into the list of possible cases to improve readability. -/ theorem setOf_isPreconnected_subset_of_ordered : { s : Set α | IsPreconnected s } ⊆ -- bounded intervals (range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪ -- unbounded intervals and `univ` (range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) := by intro s hs rcases hs.mem_intervals with (hs | hs | hs | hs | hs | hs | hs | hs | hs | hs) <;> rw [hs] <;> simp only [union_insert, union_singleton, mem_insert_iff, mem_union, mem_range, Prod.exists, uncurry_apply_pair, exists_apply_eq_apply, true_or, or_true, exists_apply_eq_apply2] #align set_of_is_preconnected_subset_of_ordered setOf_isPreconnected_subset_of_ordered /-! ### Intervals are connected In this section we prove that a closed interval (hence, any `OrdConnected` set) in a dense conditionally complete linear order is preconnected. -/ /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and the set `s ∩ [a, b)` has no maximal point, then `b ∈ s`. -/ theorem IsClosed.mem_of_ge_of_forall_exists_gt {a b : α} {s : Set α} (hs : IsClosed (s ∩ Icc a b)) (ha : a ∈ s) (hab : a ≤ b) (hgt : ∀ x ∈ s ∩ Ico a b, (s ∩ Ioc x b).Nonempty) : b ∈ s := by let S := s ∩ Icc a b replace ha : a ∈ S := ⟨ha, left_mem_Icc.2 hab⟩ have Sbd : BddAbove S := ⟨b, fun z hz => hz.2.2⟩ let c := sSup (s ∩ Icc a b) have c_mem : c ∈ S := hs.csSup_mem ⟨_, ha⟩ Sbd have c_le : c ≤ b := csSup_le ⟨_, ha⟩ fun x hx => hx.2.2 cases' eq_or_lt_of_le c_le with hc hc · exact hc ▸ c_mem.1 exfalso rcases hgt c ⟨c_mem.1, c_mem.2.1, hc⟩ with ⟨x, xs, cx, xb⟩ exact not_lt_of_le (le_csSup Sbd ⟨xs, le_trans (le_csSup Sbd ha) (le_of_lt cx), xb⟩) cx #align is_closed.mem_of_ge_of_forall_exists_gt IsClosed.mem_of_ge_of_forall_exists_gt /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `a ≤ x < y ≤ b`, `x ∈ s`, the set `s ∩ (x, y]` is not empty, then `[a, b] ⊆ s`. -/ theorem IsClosed.Icc_subset_of_forall_exists_gt {a b : α} {s : Set α} (hs : IsClosed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, ∀ y ∈ Ioi x, (s ∩ Ioc x y).Nonempty) : Icc a b ⊆ s := by intro y hy have : IsClosed (s ∩ Icc a y) := by suffices s ∩ Icc a y = s ∩ Icc a b ∩ Icc a y by rw [this] exact IsClosed.inter hs isClosed_Icc rw [inter_assoc] congr exact (inter_eq_self_of_subset_right <| Icc_subset_Icc_right hy.2).symm exact IsClosed.mem_of_ge_of_forall_exists_gt this ha hy.1 fun x hx => hgt x ⟨hx.1, Ico_subset_Ico_right hy.2 hx.2⟩ y hx.2.2 #align is_closed.Icc_subset_of_forall_exists_gt IsClosed.Icc_subset_of_forall_exists_gt variable [DenselyOrdered α] {a b : α} /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `x ∈ s ∩ [a, b)` the set `s` includes some open neighborhood of `x` within `(x, +∞)`, then `[a, b] ⊆ s`. -/ theorem IsClosed.Icc_subset_of_forall_mem_nhdsWithin {a b : α} {s : Set α} (hs : IsClosed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, s ∈ 𝓝[>] x) : Icc a b ⊆ s := by apply hs.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxs, hxab⟩ y hyxb have : s ∩ Ioc x y ∈ 𝓝[>] x := inter_mem (hgt x ⟨hxs, hxab⟩) (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hyxb⟩) exact (nhdsWithin_Ioi_self_neBot' ⟨b, hxab.2⟩).nonempty_of_mem this #align is_closed.Icc_subset_of_forall_mem_nhds_within IsClosed.Icc_subset_of_forall_mem_nhdsWithin theorem isPreconnected_Icc_aux (x y : α) (s t : Set α) (hxy : x ≤ y) (hs : IsClosed s) (ht : IsClosed t) (hab : Icc a b ⊆ s ∪ t) (hx : x ∈ Icc a b ∩ s) (hy : y ∈ Icc a b ∩ t) : (Icc a b ∩ (s ∩ t)).Nonempty := by have xyab : Icc x y ⊆ Icc a b := Icc_subset_Icc hx.1.1 hy.1.2 by_contra hst suffices Icc x y ⊆ s from hst ⟨y, xyab <| right_mem_Icc.2 hxy, this <| right_mem_Icc.2 hxy, hy.2⟩ apply (IsClosed.inter hs isClosed_Icc).Icc_subset_of_forall_mem_nhdsWithin hx.2 rintro z ⟨zs, hz⟩ have zt : z ∈ tᶜ := fun zt => hst ⟨z, xyab <| Ico_subset_Icc_self hz, zs, zt⟩ have : tᶜ ∩ Ioc z y ∈ 𝓝[>] z := by rw [← nhdsWithin_Ioc_eq_nhdsWithin_Ioi hz.2] exact mem_nhdsWithin.2 ⟨tᶜ, ht.isOpen_compl, zt, Subset.rfl⟩ apply mem_of_superset this have : Ioc z y ⊆ s ∪ t := fun w hw => hab (xyab ⟨le_trans hz.1 (le_of_lt hw.1), hw.2⟩) exact fun w ⟨wt, wzy⟩ => (this wzy).elim id fun h => (wt h).elim #align is_preconnected_Icc_aux isPreconnected_Icc_aux /-- A closed interval in a densely ordered conditionally complete linear order is preconnected. -/ theorem isPreconnected_Icc : IsPreconnected (Icc a b) := isPreconnected_closed_iff.2 (by rintro s t hs ht hab ⟨x, hx⟩ ⟨y, hy⟩ -- This used to use `wlog`, but it was causing timeouts. rcases le_total x y with h | h · exact isPreconnected_Icc_aux x y s t h hs ht hab hx hy · rw [inter_comm s t] rw [union_comm s t] at hab exact isPreconnected_Icc_aux y x t s h ht hs hab hy hx) #align is_preconnected_Icc isPreconnected_Icc theorem isPreconnected_uIcc : IsPreconnected (uIcc a b) := isPreconnected_Icc #align is_preconnected_uIcc isPreconnected_uIcc theorem Set.OrdConnected.isPreconnected {s : Set α} (h : s.OrdConnected) : IsPreconnected s := isPreconnected_of_forall_pair fun x hx y hy => ⟨uIcc x y, h.uIcc_subset hx hy, left_mem_uIcc, right_mem_uIcc, isPreconnected_uIcc⟩ #align set.ord_connected.is_preconnected Set.OrdConnected.isPreconnected theorem isPreconnected_iff_ordConnected {s : Set α} : IsPreconnected s ↔ OrdConnected s := ⟨IsPreconnected.ordConnected, Set.OrdConnected.isPreconnected⟩ #align is_preconnected_iff_ord_connected isPreconnected_iff_ordConnected theorem isPreconnected_Ici : IsPreconnected (Ici a) := ordConnected_Ici.isPreconnected #align is_preconnected_Ici isPreconnected_Ici theorem isPreconnected_Iic : IsPreconnected (Iic a) := ordConnected_Iic.isPreconnected #align is_preconnected_Iic isPreconnected_Iic theorem isPreconnected_Iio : IsPreconnected (Iio a) := ordConnected_Iio.isPreconnected #align is_preconnected_Iio isPreconnected_Iio theorem isPreconnected_Ioi : IsPreconnected (Ioi a) := ordConnected_Ioi.isPreconnected #align is_preconnected_Ioi isPreconnected_Ioi theorem isPreconnected_Ioo : IsPreconnected (Ioo a b) := ordConnected_Ioo.isPreconnected #align is_preconnected_Ioo isPreconnected_Ioo theorem isPreconnected_Ioc : IsPreconnected (Ioc a b) := ordConnected_Ioc.isPreconnected #align is_preconnected_Ioc isPreconnected_Ioc theorem isPreconnected_Ico : IsPreconnected (Ico a b) := ordConnected_Ico.isPreconnected #align is_preconnected_Ico isPreconnected_Ico theorem isConnected_Ici : IsConnected (Ici a) := ⟨nonempty_Ici, isPreconnected_Ici⟩ #align is_connected_Ici isConnected_Ici theorem isConnected_Iic : IsConnected (Iic a) := ⟨nonempty_Iic, isPreconnected_Iic⟩ #align is_connected_Iic isConnected_Iic theorem isConnected_Ioi [NoMaxOrder α] : IsConnected (Ioi a) := ⟨nonempty_Ioi, isPreconnected_Ioi⟩ #align is_connected_Ioi isConnected_Ioi theorem isConnected_Iio [NoMinOrder α] : IsConnected (Iio a) := ⟨nonempty_Iio, isPreconnected_Iio⟩ #align is_connected_Iio isConnected_Iio theorem isConnected_Icc (h : a ≤ b) : IsConnected (Icc a b) := ⟨nonempty_Icc.2 h, isPreconnected_Icc⟩ #align is_connected_Icc isConnected_Icc theorem isConnected_Ioo (h : a < b) : IsConnected (Ioo a b) := ⟨nonempty_Ioo.2 h, isPreconnected_Ioo⟩ #align is_connected_Ioo isConnected_Ioo theorem isConnected_Ioc (h : a < b) : IsConnected (Ioc a b) := ⟨nonempty_Ioc.2 h, isPreconnected_Ioc⟩ #align is_connected_Ioc isConnected_Ioc theorem isConnected_Ico (h : a < b) : IsConnected (Ico a b) := ⟨nonempty_Ico.2 h, isPreconnected_Ico⟩ #align is_connected_Ico isConnected_Ico instance (priority := 100) ordered_connected_space : PreconnectedSpace α := ⟨ordConnected_univ.isPreconnected⟩ #align ordered_connected_space ordered_connected_space /-- In a dense conditionally complete linear order, the set of preconnected sets is exactly the set of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, `(-∞, +∞)`, or `∅`. Though one can represent `∅` as `(sInf s, sInf s)`, we include it into the list of possible cases to improve readability. -/ theorem setOf_isPreconnected_eq_of_ordered : { s : Set α | IsPreconnected s } = -- bounded intervals range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo) ∪ -- unbounded intervals and `univ` (range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) := by refine Subset.antisymm setOf_isPreconnected_subset_of_ordered ?_ simp only [subset_def, forall_mem_range, uncurry, or_imp, forall_and, mem_union, mem_setOf_eq, insert_eq, mem_singleton_iff, forall_eq, forall_true_iff, and_true_iff, isPreconnected_Icc, isPreconnected_Ico, isPreconnected_Ioc, isPreconnected_Ioo, isPreconnected_Ioi, isPreconnected_Iio, isPreconnected_Ici, isPreconnected_Iic, isPreconnected_univ, isPreconnected_empty] #align set_of_is_preconnected_eq_of_ordered setOf_isPreconnected_eq_of_ordered /-- This lemmas characterizes when a subset `s` of a densely ordered conditionally complete linear order is totally disconnected with respect to the order topology: between any two distinct points of `s` must lie a point not in `s`. -/ lemma isTotallyDisconnected_iff_lt {s : Set α} : IsTotallyDisconnected s ↔ ∀ x ∈ s, ∀ y ∈ s, x < y → ∃ z ∉ s, z ∈ Ioo x y := by simp only [IsTotallyDisconnected, isPreconnected_iff_ordConnected, ← not_nontrivial_iff, nontrivial_iff_exists_lt, not_exists, not_and] refine ⟨fun h x hx y hy hxy ↦ ?_, fun h t hts ht x hx y hy hxy ↦ ?_⟩ · simp_rw [← not_ordConnected_inter_Icc_iff hx hy] exact fun hs ↦ h _ inter_subset_left hs _ ⟨hx, le_rfl, hxy.le⟩ _ ⟨hy, hxy.le, le_rfl⟩ hxy · obtain ⟨z, h1z, h2z⟩ := h x (hts hx) y (hts hy) hxy exact h1z <| hts <| ht.1 hx hy ⟨h2z.1.le, h2z.2.le⟩ /-! ### Intermediate Value Theorem on an interval In this section we prove several versions of the Intermediate Value Theorem for a function continuous on an interval. -/ variable {δ : Type*} [LinearOrder δ] [TopologicalSpace δ] [OrderClosedTopology δ] /-- **Intermediate Value Theorem** for continuous functions on closed intervals, case `f a ≤ t ≤ f b`. -/ theorem intermediate_value_Icc {a b : α} (hab : a ≤ b) {f : α → δ} (hf : ContinuousOn f (Icc a b)) : Icc (f a) (f b) ⊆ f '' Icc a b := isPreconnected_Icc.intermediate_value (left_mem_Icc.2 hab) (right_mem_Icc.2 hab) hf #align intermediate_value_Icc intermediate_value_Icc /-- **Intermediate Value Theorem** for continuous functions on closed intervals, case `f a ≥ t ≥ f b`. -/ theorem intermediate_value_Icc' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : ContinuousOn f (Icc a b)) : Icc (f b) (f a) ⊆ f '' Icc a b := isPreconnected_Icc.intermediate_value (right_mem_Icc.2 hab) (left_mem_Icc.2 hab) hf #align intermediate_value_Icc' intermediate_value_Icc' /-- **Intermediate Value Theorem** for continuous functions on closed intervals, unordered case. -/ theorem intermediate_value_uIcc {a b : α} {f : α → δ} (hf : ContinuousOn f (uIcc a b)) : uIcc (f a) (f b) ⊆ f '' uIcc a b := by cases le_total (f a) (f b) <;> simp [*, isPreconnected_uIcc.intermediate_value] #align intermediate_value_uIcc intermediate_value_uIcc theorem intermediate_value_Ico {a b : α} (hab : a ≤ b) {f : α → δ} (hf : ContinuousOn f (Icc a b)) : Ico (f a) (f b) ⊆ f '' Ico a b := Or.elim (eq_or_lt_of_le hab) (fun he _ h => absurd h.2 (not_lt_of_le (he ▸ h.1))) fun hlt => @IsPreconnected.intermediate_value_Ico _ _ _ _ _ _ _ isPreconnected_Ico _ _ ⟨refl a, hlt⟩ (right_nhdsWithin_Ico_neBot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self) _ ((hf.continuousWithinAt ⟨hab, refl b⟩).mono Ico_subset_Icc_self) #align intermediate_value_Ico intermediate_value_Ico theorem intermediate_value_Ico' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : ContinuousOn f (Icc a b)) : Ioc (f b) (f a) ⊆ f '' Ico a b := Or.elim (eq_or_lt_of_le hab) (fun he _ h => absurd h.1 (not_lt_of_le (he ▸ h.2))) fun hlt => @IsPreconnected.intermediate_value_Ioc _ _ _ _ _ _ _ isPreconnected_Ico _ _ ⟨refl a, hlt⟩ (right_nhdsWithin_Ico_neBot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self) _ ((hf.continuousWithinAt ⟨hab, refl b⟩).mono Ico_subset_Icc_self) #align intermediate_value_Ico' intermediate_value_Ico' theorem intermediate_value_Ioc {a b : α} (hab : a ≤ b) {f : α → δ} (hf : ContinuousOn f (Icc a b)) : Ioc (f a) (f b) ⊆ f '' Ioc a b := Or.elim (eq_or_lt_of_le hab) (fun he _ h => absurd h.2 (not_le_of_lt (he ▸ h.1))) fun hlt => @IsPreconnected.intermediate_value_Ioc _ _ _ _ _ _ _ isPreconnected_Ioc _ _ ⟨hlt, refl b⟩ (left_nhdsWithin_Ioc_neBot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self) _ ((hf.continuousWithinAt ⟨refl a, hab⟩).mono Ioc_subset_Icc_self) #align intermediate_value_Ioc intermediate_value_Ioc theorem intermediate_value_Ioc' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : ContinuousOn f (Icc a b)) : Ico (f b) (f a) ⊆ f '' Ioc a b := Or.elim (eq_or_lt_of_le hab) (fun he _ h => absurd h.1 (not_le_of_lt (he ▸ h.2))) fun hlt => @IsPreconnected.intermediate_value_Ico _ _ _ _ _ _ _ isPreconnected_Ioc _ _ ⟨hlt, refl b⟩ (left_nhdsWithin_Ioc_neBot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self) _ ((hf.continuousWithinAt ⟨refl a, hab⟩).mono Ioc_subset_Icc_self) #align intermediate_value_Ioc' intermediate_value_Ioc' theorem intermediate_value_Ioo {a b : α} (hab : a ≤ b) {f : α → δ} (hf : ContinuousOn f (Icc a b)) : Ioo (f a) (f b) ⊆ f '' Ioo a b := Or.elim (eq_or_lt_of_le hab) (fun he _ h => absurd h.2 (not_lt_of_lt (he ▸ h.1))) fun hlt => @IsPreconnected.intermediate_value_Ioo _ _ _ _ _ _ _ isPreconnected_Ioo _ _ (left_nhdsWithin_Ioo_neBot hlt) (right_nhdsWithin_Ioo_neBot hlt) inf_le_right inf_le_right _ (hf.mono Ioo_subset_Icc_self) _ _ ((hf.continuousWithinAt ⟨refl a, hab⟩).mono Ioo_subset_Icc_self) ((hf.continuousWithinAt ⟨hab, refl b⟩).mono Ioo_subset_Icc_self) #align intermediate_value_Ioo intermediate_value_Ioo theorem intermediate_value_Ioo' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : ContinuousOn f (Icc a b)) : Ioo (f b) (f a) ⊆ f '' Ioo a b := Or.elim (eq_or_lt_of_le hab) (fun he _ h => absurd h.1 (not_lt_of_lt (he ▸ h.2))) fun hlt => @IsPreconnected.intermediate_value_Ioo _ _ _ _ _ _ _ isPreconnected_Ioo _ _ (right_nhdsWithin_Ioo_neBot hlt) (left_nhdsWithin_Ioo_neBot hlt) inf_le_right inf_le_right _ (hf.mono Ioo_subset_Icc_self) _ _ ((hf.continuousWithinAt ⟨hab, refl b⟩).mono Ioo_subset_Icc_self) ((hf.continuousWithinAt ⟨refl a, hab⟩).mono Ioo_subset_Icc_self) #align intermediate_value_Ioo' intermediate_value_Ioo' /-- **Intermediate value theorem**: if `f` is continuous on an order-connected set `s` and `a`, `b` are two points of this set, then `f` sends `s` to a superset of `Icc (f x) (f y)`. -/ theorem ContinuousOn.surjOn_Icc {s : Set α} [hs : OrdConnected s] {f : α → δ} (hf : ContinuousOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : SurjOn f s (Icc (f a) (f b)) := hs.isPreconnected.intermediate_value ha hb hf #align continuous_on.surj_on_Icc ContinuousOn.surjOn_Icc /-- **Intermediate value theorem**: if `f` is continuous on an order-connected set `s` and `a`, `b` are two points of this set, then `f` sends `s` to a superset of `[f x, f y]`. -/ theorem ContinuousOn.surjOn_uIcc {s : Set α} [hs : OrdConnected s] {f : α → δ} (hf : ContinuousOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : SurjOn f s (uIcc (f a) (f b)) := by rcases le_total (f a) (f b) with hab | hab <;> simp [hf.surjOn_Icc, *] #align continuous_on.surj_on_uIcc ContinuousOn.surjOn_uIcc /-- A continuous function which tendsto `Filter.atTop` along `Filter.atTop` and to `atBot` along `at_bot` is surjective. -/ theorem Continuous.surjective {f : α → δ} (hf : Continuous f) (h_top : Tendsto f atTop atTop) (h_bot : Tendsto f atBot atBot) : Function.Surjective f := fun p => mem_range_of_exists_le_of_exists_ge hf (h_bot.eventually (eventually_le_atBot p)).exists (h_top.eventually (eventually_ge_atTop p)).exists #align continuous.surjective Continuous.surjective /-- A continuous function which tendsto `Filter.atBot` along `Filter.atTop` and to `Filter.atTop` along `atBot` is surjective. -/ theorem Continuous.surjective' {f : α → δ} (hf : Continuous f) (h_top : Tendsto f atBot atTop) (h_bot : Tendsto f atTop atBot) : Function.Surjective f := Continuous.surjective (α := αᵒᵈ) hf h_top h_bot #align continuous.surjective' Continuous.surjective' /-- If a function `f : α → β` is continuous on a nonempty interval `s`, its restriction to `s` tends to `at_bot : Filter β` along `at_bot : Filter ↥s` and tends to `Filter.atTop : Filter β` along `Filter.atTop : Filter ↥s`, then the restriction of `f` to `s` is surjective. We formulate the conclusion as `Function.surjOn f s Set.univ`. -/ theorem ContinuousOn.surjOn_of_tendsto {f : α → δ} {s : Set α} [OrdConnected s] (hs : s.Nonempty) (hf : ContinuousOn f s) (hbot : Tendsto (fun x : s => f x) atBot atBot) (htop : Tendsto (fun x : s => f x) atTop atTop) : SurjOn f s univ := haveI := Classical.inhabited_of_nonempty hs.to_subtype surjOn_iff_surjective.2 <| hf.restrict.surjective htop hbot #align continuous_on.surj_on_of_tendsto ContinuousOn.surjOn_of_tendsto /-- If a function `f : α → β` is continuous on a nonempty interval `s`, its restriction to `s` tends to `Filter.atTop : Filter β` along `Filter.atBot : Filter ↥s` and tends to `Filter.atBot : Filter β` along `Filter.atTop : Filter ↥s`, then the restriction of `f` to `s` is surjective. We formulate the conclusion as `Function.surjOn f s Set.univ`. -/ theorem ContinuousOn.surjOn_of_tendsto' {f : α → δ} {s : Set α} [OrdConnected s] (hs : s.Nonempty) (hf : ContinuousOn f s) (hbot : Tendsto (fun x : s => f x) atBot atTop) (htop : Tendsto (fun x : s => f x) atTop atBot) : SurjOn f s univ := ContinuousOn.surjOn_of_tendsto (δ := δᵒᵈ) hs hf hbot htop #align continuous_on.surj_on_of_tendsto' ContinuousOn.surjOn_of_tendsto' theorem Continuous.strictMono_of_inj_boundedOrder [BoundedOrder α] {f : α → δ} (hf_c : Continuous f) (hf : f ⊥ ≤ f ⊤) (hf_i : Injective f) : StrictMono f := by intro a b hab by_contra! h have H : f b < f a := lt_of_le_of_ne h <| hf_i.ne hab.ne' by_cases ha : f a ≤ f ⊥ · obtain ⟨u, hu⟩ := intermediate_value_Ioc le_top hf_c.continuousOn ⟨H.trans_le ha, hf⟩ have : u = ⊥ := hf_i hu.2 aesop · by_cases hb : f ⊥ < f b · obtain ⟨u, hu⟩ := intermediate_value_Ioo bot_le hf_c.continuousOn ⟨hb, H⟩ rw [hf_i hu.2] at hu exact (hab.trans hu.1.2).false · push_neg at ha hb replace hb : f b < f ⊥ := lt_of_le_of_ne hb <| hf_i.ne (lt_of_lt_of_le' hab bot_le).ne' obtain ⟨u, hu⟩ := intermediate_value_Ioo' hab.le hf_c.continuousOn ⟨hb, ha⟩ have : u = ⊥ := hf_i hu.2 aesop theorem Continuous.strictAnti_of_inj_boundedOrder [BoundedOrder α] {f : α → δ} (hf_c : Continuous f) (hf : f ⊤ ≤ f ⊥) (hf_i : Injective f) : StrictAnti f := hf_c.strictMono_of_inj_boundedOrder (δ := δᵒᵈ) hf hf_i theorem Continuous.strictMono_of_inj_boundedOrder' [BoundedOrder α] {f : α → δ} (hf_c : Continuous f) (hf_i : Injective f) : StrictMono f ∨ StrictAnti f := (le_total (f ⊥) (f ⊤)).imp (hf_c.strictMono_of_inj_boundedOrder · hf_i) (hf_c.strictAnti_of_inj_boundedOrder · hf_i) /-- Suppose `α` is equipped with a conditionally complete linear dense order and `f : α → δ` is continuous and injective. Then `f` is strictly monotone (increasing) if it is strictly monotone (increasing) on some closed interval `[a, b]`. -/ theorem Continuous.strictMonoOn_of_inj_rigidity {f : α → δ} (hf_c : Continuous f) (hf_i : Injective f) {a b : α} (hab : a < b) (hf_mono : StrictMonoOn f (Icc a b)) : StrictMono f := by intro x y hxy let s := min a x let t := max b y have hsa : s ≤ a := min_le_left a x have hbt : b ≤ t := le_max_left b y have hst : s ≤ t := hsa.trans $ hbt.trans' hab.le have hf_mono_st : StrictMonoOn f (Icc s t) ∨ StrictAntiOn f (Icc s t) := by letI := Icc.completeLinearOrder hst have := Continuous.strictMono_of_inj_boundedOrder' (f := Set.restrict (Icc s t) f) hf_c.continuousOn.restrict hf_i.injOn.injective exact this.imp strictMono_restrict.mp strictAntiOn_iff_strictAnti.mpr have (h : StrictAntiOn f (Icc s t)) : False := by have : Icc a b ⊆ Icc s t := Icc_subset_Icc hsa hbt replace : StrictAntiOn f (Icc a b) := StrictAntiOn.mono h this replace : IsAntichain (· ≤ ·) (Icc a b) := IsAntichain.of_strictMonoOn_antitoneOn hf_mono this.antitoneOn exact this.not_lt (left_mem_Icc.mpr (le_of_lt hab)) (right_mem_Icc.mpr (le_of_lt hab)) hab replace hf_mono_st : StrictMonoOn f (Icc s t) := hf_mono_st.resolve_right this have hsx : s ≤ x := min_le_right a x have hyt : y ≤ t := le_max_right b y replace : Icc x y ⊆ Icc s t := Icc_subset_Icc hsx hyt replace : StrictMonoOn f (Icc x y) := StrictMonoOn.mono hf_mono_st this exact this (left_mem_Icc.mpr (le_of_lt hxy)) (right_mem_Icc.mpr (le_of_lt hxy)) hxy /-- Suppose `f : [a, b] → δ` is continuous and injective. Then `f` is strictly monotone (increasing) if `f(a) ≤ f(b)`. -/ theorem ContinuousOn.strictMonoOn_of_injOn_Icc {a b : α} {f : α → δ} (hab : a ≤ b) (hfab : f a ≤ f b) (hf_c : ContinuousOn f (Icc a b)) (hf_i : InjOn f (Icc a b)) : StrictMonoOn f (Icc a b) := by letI := Icc.completeLinearOrder hab refine StrictMono.of_restrict ?_ set g : Icc a b → δ := Set.restrict (Icc a b) f have hgab : g ⊥ ≤ g ⊤ := by aesop exact Continuous.strictMono_of_inj_boundedOrder (f := g) hf_c.restrict hgab hf_i.injective /-- Suppose `f : [a, b] → δ` is continuous and injective. Then `f` is strictly antitone (decreasing) if `f(b) ≤ f(a)`. -/ theorem ContinuousOn.strictAntiOn_of_injOn_Icc {a b : α} {f : α → δ} (hab : a ≤ b) (hfab : f b ≤ f a) (hf_c : ContinuousOn f (Icc a b)) (hf_i : InjOn f (Icc a b)) : StrictAntiOn f (Icc a b) := ContinuousOn.strictMonoOn_of_injOn_Icc (δ := δᵒᵈ) hab hfab hf_c hf_i /-- Suppose `f : [a, b] → δ` is continuous and injective. Then `f` is strictly monotone or antitone (increasing or decreasing). -/ theorem ContinuousOn.strictMonoOn_of_injOn_Icc' {a b : α} {f : α → δ} (hab : a ≤ b) (hf_c : ContinuousOn f (Icc a b)) (hf_i : InjOn f (Icc a b)) : StrictMonoOn f (Icc a b) ∨ StrictAntiOn f (Icc a b) := (le_total (f a) (f b)).imp (ContinuousOn.strictMonoOn_of_injOn_Icc hab · hf_c hf_i) (ContinuousOn.strictAntiOn_of_injOn_Icc hab · hf_c hf_i) /-- Suppose `α` is equipped with a conditionally complete linear dense order and `f : α → δ` is continuous and injective. Then `f` is strictly monotone or antitone (increasing or decreasing). -/
Mathlib/Topology/Order/IntermediateValue.lean
743
761
theorem Continuous.strictMono_of_inj {f : α → δ} (hf_c : Continuous f) (hf_i : Injective f) : StrictMono f ∨ StrictAnti f := by
have H {c d : α} (hcd : c < d) : StrictMono f ∨ StrictAnti f := (hf_c.continuousOn.strictMonoOn_of_injOn_Icc' hcd.le hf_i.injOn).imp (hf_c.strictMonoOn_of_inj_rigidity hf_i hcd) (hf_c.strictMonoOn_of_inj_rigidity (δ := δᵒᵈ) hf_i hcd) by_cases hn : Nonempty α · let a : α := Classical.choice ‹_› by_cases h : ∃ b : α, a ≠ b · choose b hb using h by_cases hab : a < b · exact H hab · push_neg at hab have : b < a := by exact Ne.lt_of_le (id (Ne.symm hb)) hab exact H this · push_neg at h haveI : Subsingleton α := ⟨fun c d => Trans.trans (h c).symm (h d)⟩ exact Or.inl <| Subsingleton.strictMono f · aesop
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Shing Tak Lam, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Int.ModEq import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Log import Mathlib.Data.List.Indexes import Mathlib.Data.List.Palindrome import Mathlib.Tactic.IntervalCases import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring #align_import data.nat.digits from "leanprover-community/mathlib"@"369525b73f229ccd76a6ec0e0e0bf2be57599768" /-! # Digits of a natural number This provides a basic API for extracting the digits of a natural number in a given base, and reconstructing numbers from their digits. We also prove some divisibility tests based on digits, in particular completing Theorem #85 from https://www.cs.ru.nl/~freek/100/. Also included is a bound on the length of `Nat.toDigits` from core. ## TODO A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b` are numerals is not yet ported. -/ namespace Nat variable {n : ℕ} /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux0 : ℕ → List ℕ | 0 => [] | n + 1 => [n + 1] #align nat.digits_aux_0 Nat.digitsAux0 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux1 (n : ℕ) : List ℕ := List.replicate n 1 #align nat.digits_aux_1 Nat.digitsAux1 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ | 0 => [] | n + 1 => ((n + 1) % b) :: digitsAux b h ((n + 1) / b) decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h #align nat.digits_aux Nat.digitsAux @[simp] theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux] #align nat.digits_aux_zero Nat.digitsAux_zero theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) : digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by cases n · cases w · rw [digitsAux] #align nat.digits_aux_def Nat.digitsAux_def /-- `digits b n` gives the digits, in little-endian order, of a natural number `n` in a specified base `b`. In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`. * For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`, and the last digit is not zero. This uniquely specifies the behaviour of `digits b`. * For `b = 1`, we define `digits 1 n = List.replicate n 1`. * For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`. Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals. In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`. -/ def digits : ℕ → ℕ → List ℕ | 0 => digitsAux0 | 1 => digitsAux1 | b + 2 => digitsAux (b + 2) (by norm_num) #align nat.digits Nat.digits @[simp] theorem digits_zero (b : ℕ) : digits b 0 = [] := by rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1] #align nat.digits_zero Nat.digits_zero -- @[simp] -- Porting note (#10618): simp can prove this theorem digits_zero_zero : digits 0 0 = [] := rfl #align nat.digits_zero_zero Nat.digits_zero_zero @[simp] theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] := rfl #align nat.digits_zero_succ Nat.digits_zero_succ theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n] | 0, h => (h rfl).elim | _ + 1, _ => rfl #align nat.digits_zero_succ' Nat.digits_zero_succ' @[simp] theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 := rfl #align nat.digits_one Nat.digits_one -- @[simp] -- Porting note (#10685): dsimp can prove this theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n := rfl #align nat.digits_one_succ Nat.digits_one_succ theorem digits_add_two_add_one (b n : ℕ) : digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by simp [digits, digitsAux_def] #align nat.digits_add_two_add_one Nat.digits_add_two_add_one @[simp] lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) : Nat.digits b n = n % b :: Nat.digits b (n / b) := by rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one] theorem digits_def' : ∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b) | 0, h => absurd h (by decide) | 1, h => absurd h (by decide) | b + 2, _ => digitsAux_def _ (by simp) _ #align nat.digits_def' Nat.digits_def' @[simp] theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩ rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩ rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb] #align nat.digits_of_lt Nat.digits_of_lt theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) : digits b (x + b * y) = x :: digits b y := by rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩ cases y · simp [hxb, hxy.resolve_right (absurd rfl)] dsimp [digits] rw [digitsAux_def] · congr · simp [Nat.add_mod, mod_eq_of_lt hxb] · simp [add_mul_div_left, div_eq_of_lt hxb] · apply Nat.succ_pos #align nat.digits_add Nat.digits_add -- If we had a function converting a list into a polynomial, -- and appropriate lemmas about that function, -- we could rewrite this in terms of that. /-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them as a number in semiring, as the little-endian digits in base `b`. -/ def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α | [] => 0 | h :: t => h + b * ofDigits b t #align nat.of_digits Nat.ofDigits theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) : ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by induction' L with d L ih · rfl · dsimp [ofDigits] rw [ih] #align nat.of_digits_eq_foldr Nat.ofDigits_eq_foldr theorem ofDigits_eq_sum_map_with_index_aux (b : ℕ) (l : List ℕ) : ((List.range l.length).zipWith ((fun i a : ℕ => a * b ^ (i + 1))) l).sum = b * ((List.range l.length).zipWith (fun i a => a * b ^ i) l).sum := by suffices (List.range l.length).zipWith (fun i a : ℕ => a * b ^ (i + 1)) l = (List.range l.length).zipWith (fun i a => b * (a * b ^ i)) l by simp [this] congr; ext; simp [pow_succ]; ring #align nat.of_digits_eq_sum_map_with_index_aux Nat.ofDigits_eq_sum_map_with_index_aux theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) : ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by rw [List.mapIdx_eq_enum_map, List.enum_eq_zip_range, List.map_uncurry_zip_eq_zipWith, ofDigits_eq_foldr] induction' L with hd tl hl · simp · simpa [List.range_succ_eq_map, List.zipWith_map_left, ofDigits_eq_sum_map_with_index_aux] using Or.inl hl #align nat.of_digits_eq_sum_map_with_index Nat.ofDigits_eq_sum_mapIdx @[simp] theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl @[simp] theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits] #align nat.of_digits_singleton Nat.ofDigits_singleton @[simp] theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) : ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits] #align nat.of_digits_one_cons Nat.ofDigits_one_cons theorem ofDigits_cons {b hd} {tl : List ℕ} : ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} : ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by induction' l1 with hd tl IH · simp [ofDigits] · rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ'] ring #align nat.of_digits_append Nat.ofDigits_append @[norm_cast] theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by induction' L with d L ih · simp [ofDigits] · dsimp [ofDigits]; push_cast; rw [ih] #align nat.coe_of_digits Nat.coe_ofDigits @[norm_cast] theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by induction' L with d L _ · rfl · dsimp [ofDigits]; push_cast; simp only #align nat.coe_int_of_digits Nat.coe_int_ofDigits theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) : ∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0 | _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0 | _ :: _, h0, _, List.Mem.tail _ hL => digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL #align nat.digits_zero_of_eq_zero Nat.digits_zero_of_eq_zero theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b) (w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by induction' L with d L ih · dsimp [ofDigits] simp · dsimp [ofDigits] replace w₂ := w₂ (by simp) rw [digits_add b h] · rw [ih] · intro l m apply w₁ exact List.mem_cons_of_mem _ m · intro h rw [List.getLast_cons h] at w₂ convert w₂ · exact w₁ d (List.mem_cons_self _ _) · by_cases h' : L = [] · rcases h' with rfl left simpa using w₂ · right contrapose! w₂ refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_ rw [List.getLast_cons h'] exact List.getLast_mem h' #align nat.digits_of_digits Nat.digits_ofDigits theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by cases' b with b · cases' n with n · rfl · change ofDigits 0 [n + 1] = n + 1 dsimp [ofDigits] · cases' b with b · induction' n with n ih · rfl · rw [Nat.zero_add] at ih ⊢ simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ] · apply Nat.strongInductionOn n _ clear n intro n h cases n · rw [digits_zero] rfl · simp only [Nat.succ_eq_add_one, digits_add_two_add_one] dsimp [ofDigits] rw [h _ (Nat.div_lt_self' _ b)] rw [Nat.mod_add_div] #align nat.of_digits_digits Nat.ofDigits_digits theorem ofDigits_one (L : List ℕ) : ofDigits 1 L = L.sum := by induction' L with _ _ ih · rfl · simp [ofDigits, List.sum_cons, ih] #align nat.of_digits_one Nat.ofDigits_one /-! ### Properties This section contains various lemmas of properties relating to `digits` and `ofDigits`. -/ theorem digits_eq_nil_iff_eq_zero {b n : ℕ} : digits b n = [] ↔ n = 0 := by constructor · intro h have : ofDigits b (digits b n) = ofDigits b [] := by rw [h] convert this rw [ofDigits_digits] · rintro rfl simp #align nat.digits_eq_nil_iff_eq_zero Nat.digits_eq_nil_iff_eq_zero theorem digits_ne_nil_iff_ne_zero {b n : ℕ} : digits b n ≠ [] ↔ n ≠ 0 := not_congr digits_eq_nil_iff_eq_zero #align nat.digits_ne_nil_iff_ne_zero Nat.digits_ne_nil_iff_ne_zero theorem digits_eq_cons_digits_div {b n : ℕ} (h : 1 < b) (w : n ≠ 0) : digits b n = (n % b) :: digits b (n / b) := by rcases b with (_ | _ | b) · rw [digits_zero_succ' w, Nat.mod_zero, Nat.div_zero, Nat.digits_zero_zero] · norm_num at h rcases n with (_ | n) · norm_num at w · simp only [digits_add_two_add_one, ne_eq] #align nat.digits_eq_cons_digits_div Nat.digits_eq_cons_digits_div theorem digits_getLast {b : ℕ} (m : ℕ) (h : 1 < b) (p q) : (digits b m).getLast p = (digits b (m / b)).getLast q := by by_cases hm : m = 0 · simp [hm] simp only [digits_eq_cons_digits_div h hm] rw [List.getLast_cons] #align nat.digits_last Nat.digits_getLast theorem digits.injective (b : ℕ) : Function.Injective b.digits := Function.LeftInverse.injective (ofDigits_digits b) #align nat.digits.injective Nat.digits.injective @[simp] theorem digits_inj_iff {b n m : ℕ} : b.digits n = b.digits m ↔ n = m := (digits.injective b).eq_iff #align nat.digits_inj_iff Nat.digits_inj_iff theorem digits_len (b n : ℕ) (hb : 1 < b) (hn : n ≠ 0) : (b.digits n).length = b.log n + 1 := by induction' n using Nat.strong_induction_on with n IH rw [digits_eq_cons_digits_div hb hn, List.length] by_cases h : n / b = 0 · have hb0 : b ≠ 0 := (Nat.succ_le_iff.1 hb).ne_bot simp [h, log_eq_zero_iff, ← Nat.div_eq_zero_iff hb0.bot_lt] · have : n / b < n := div_lt_self (Nat.pos_of_ne_zero hn) hb rw [IH _ this h, log_div_base, tsub_add_cancel_of_le] refine Nat.succ_le_of_lt (log_pos hb ?_) contrapose! h exact div_eq_of_lt h #align nat.digits_len Nat.digits_len theorem getLast_digit_ne_zero (b : ℕ) {m : ℕ} (hm : m ≠ 0) : (digits b m).getLast (digits_ne_nil_iff_ne_zero.mpr hm) ≠ 0 := by rcases b with (_ | _ | b) · cases m · cases hm rfl · simp · cases m · cases hm rfl rename ℕ => m simp only [zero_add, digits_one, List.getLast_replicate_succ m 1] exact Nat.one_ne_zero revert hm apply Nat.strongInductionOn m intro n IH hn by_cases hnb : n < b + 2 · simpa only [digits_of_lt (b + 2) n hn hnb] · rw [digits_getLast n (le_add_left 2 b)] refine IH _ (Nat.div_lt_self hn.bot_lt (one_lt_succ_succ b)) ?_ rw [← pos_iff_ne_zero] exact Nat.div_pos (le_of_not_lt hnb) (zero_lt_succ (succ b)) #align nat.last_digit_ne_zero Nat.getLast_digit_ne_zero
Mathlib/Data/Nat/Digits.lean
379
385
theorem mul_ofDigits (n : ℕ) {b : ℕ} {l : List ℕ} : n * ofDigits b l = ofDigits b (l.map (n * ·)) := by
induction l with | nil => rfl | cons hd tl ih => rw [List.map_cons, ofDigits_cons, ofDigits_cons, ← ih] ring
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics import Mathlib.NumberTheory.Liouville.Basic import Mathlib.Topology.Instances.Irrational #align_import number_theory.liouville.liouville_with from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8" /-! # Liouville numbers with a given exponent We say that a real number `x` is a Liouville number with exponent `p : ℝ` if there exists a real number `C` such that for infinitely many denominators `n` there exists a numerator `m` such that `x ≠ m / n` and `|x - m / n| < C / n ^ p`. A number is a Liouville number in the sense of `Liouville` if it is `LiouvilleWith` any real exponent, see `forall_liouvilleWith_iff`. * If `p ≤ 1`, then this condition is trivial. * If `1 < p ≤ 2`, then this condition is equivalent to `Irrational x`. The forward implication does not require `p ≤ 2` and is formalized as `LiouvilleWith.irrational`; the other implication follows from approximations by continued fractions and is not formalized yet. * If `p > 2`, then this is a non-trivial condition on irrational numbers. In particular, [Thue–Siegel–Roth theorem](https://en.wikipedia.org/wiki/Roth's_theorem) states that such numbers must be transcendental. In this file we define the predicate `LiouvilleWith` and prove some basic facts about this predicate. ## Tags Liouville number, irrational, irrationality exponent -/ open Filter Metric Real Set open scoped Filter Topology /-- We say that a real number `x` is a Liouville number with exponent `p : ℝ` if there exists a real number `C` such that for infinitely many denominators `n` there exists a numerator `m` such that `x ≠ m / n` and `|x - m / n| < C / n ^ p`. A number is a Liouville number in the sense of `Liouville` if it is `LiouvilleWith` any real exponent. -/ def LiouvilleWith (p x : ℝ) : Prop := ∃ C, ∃ᶠ n : ℕ in atTop, ∃ m : ℤ, x ≠ m / n ∧ |x - m / n| < C / n ^ p #align liouville_with LiouvilleWith /-- For `p = 1` (hence, for any `p ≤ 1`), the condition `LiouvilleWith p x` is trivial. -/ theorem liouvilleWith_one (x : ℝ) : LiouvilleWith 1 x := by use 2 refine ((eventually_gt_atTop 0).mono fun n hn => ?_).frequently have hn' : (0 : ℝ) < n := by simpa have : x < ↑(⌊x * ↑n⌋ + 1) / ↑n := by rw [lt_div_iff hn', Int.cast_add, Int.cast_one]; exact Int.lt_floor_add_one _ refine ⟨⌊x * n⌋ + 1, this.ne, ?_⟩ rw [abs_sub_comm, abs_of_pos (sub_pos.2 this), rpow_one, sub_lt_iff_lt_add', add_div_eq_mul_add_div _ _ hn'.ne'] gcongr calc _ ≤ x * n + 1 := by push_cast; gcongr; apply Int.floor_le _ < x * n + 2 := by linarith #align liouville_with_one liouvilleWith_one namespace LiouvilleWith variable {p q x y : ℝ} {r : ℚ} {m : ℤ} {n : ℕ} /-- The constant `C` provided by the definition of `LiouvilleWith` can be made positive. We also add `1 ≤ n` to the list of assumptions about the denominator. While it is equivalent to the original statement, the case `n = 0` breaks many arguments. -/ theorem exists_pos (h : LiouvilleWith p x) : ∃ (C : ℝ) (_h₀ : 0 < C), ∃ᶠ n : ℕ in atTop, 1 ≤ n ∧ ∃ m : ℤ, x ≠ m / n ∧ |x - m / n| < C / n ^ p := by rcases h with ⟨C, hC⟩ refine ⟨max C 1, zero_lt_one.trans_le <| le_max_right _ _, ?_⟩ refine ((eventually_ge_atTop 1).and_frequently hC).mono ?_ rintro n ⟨hle, m, hne, hlt⟩ refine ⟨hle, m, hne, hlt.trans_le ?_⟩ gcongr apply le_max_left #align liouville_with.exists_pos LiouvilleWith.exists_pos /-- If a number is Liouville with exponent `p`, then it is Liouville with any smaller exponent. -/ theorem mono (h : LiouvilleWith p x) (hle : q ≤ p) : LiouvilleWith q x := by rcases h.exists_pos with ⟨C, hC₀, hC⟩ refine ⟨C, hC.mono ?_⟩; rintro n ⟨hn, m, hne, hlt⟩ refine ⟨m, hne, hlt.trans_le <| ?_⟩ gcongr exact_mod_cast hn #align liouville_with.mono LiouvilleWith.mono /-- If `x` satisfies Liouville condition with exponent `p` and `q < p`, then `x` satisfies Liouville condition with exponent `q` and constant `1`. -/ theorem frequently_lt_rpow_neg (h : LiouvilleWith p x) (hlt : q < p) : ∃ᶠ n : ℕ in atTop, ∃ m : ℤ, x ≠ m / n ∧ |x - m / n| < n ^ (-q) := by rcases h.exists_pos with ⟨C, _hC₀, hC⟩ have : ∀ᶠ n : ℕ in atTop, C < n ^ (p - q) := by simpa only [(· ∘ ·), neg_sub, one_div] using ((tendsto_rpow_atTop (sub_pos.2 hlt)).comp tendsto_natCast_atTop_atTop).eventually (eventually_gt_atTop C) refine (this.and_frequently hC).mono ?_ rintro n ⟨hnC, hn, m, hne, hlt⟩ replace hn : (0 : ℝ) < n := Nat.cast_pos.2 hn refine ⟨m, hne, hlt.trans <| (div_lt_iff <| rpow_pos_of_pos hn _).2 ?_⟩ rwa [mul_comm, ← rpow_add hn, ← sub_eq_add_neg] #align liouville_with.frequently_lt_rpow_neg LiouvilleWith.frequently_lt_rpow_neg /-- The product of a Liouville number and a nonzero rational number is again a Liouville number. -/ theorem mul_rat (h : LiouvilleWith p x) (hr : r ≠ 0) : LiouvilleWith p (x * r) := by rcases h.exists_pos with ⟨C, _hC₀, hC⟩ refine ⟨r.den ^ p * (|r| * C), (tendsto_id.nsmul_atTop r.pos).frequently (hC.mono ?_)⟩ rintro n ⟨_hn, m, hne, hlt⟩ have A : (↑(r.num * m) : ℝ) / ↑(r.den • id n) = m / n * r := by simp [← div_mul_div_comm, ← r.cast_def, mul_comm] refine ⟨r.num * m, ?_, ?_⟩ · rw [A]; simp [hne, hr] · rw [A, ← sub_mul, abs_mul] simp only [smul_eq_mul, id, Nat.cast_mul] calc _ < C / ↑n ^ p * |↑r| := by gcongr _ = ↑r.den ^ p * (↑|r| * C) / (↑r.den * ↑n) ^ p := ?_ rw [mul_rpow, mul_div_mul_left, mul_comm, mul_div_assoc] · simp only [Rat.cast_abs, le_refl] all_goals positivity #align liouville_with.mul_rat LiouvilleWith.mul_rat /-- The product `x * r`, `r : ℚ`, `r ≠ 0`, is a Liouville number with exponent `p` if and only if `x` satisfies the same condition. -/ theorem mul_rat_iff (hr : r ≠ 0) : LiouvilleWith p (x * r) ↔ LiouvilleWith p x := ⟨fun h => by simpa only [mul_assoc, ← Rat.cast_mul, mul_inv_cancel hr, Rat.cast_one, mul_one] using h.mul_rat (inv_ne_zero hr), fun h => h.mul_rat hr⟩ #align liouville_with.mul_rat_iff LiouvilleWith.mul_rat_iff /-- The product `r * x`, `r : ℚ`, `r ≠ 0`, is a Liouville number with exponent `p` if and only if `x` satisfies the same condition. -/ theorem rat_mul_iff (hr : r ≠ 0) : LiouvilleWith p (r * x) ↔ LiouvilleWith p x := by rw [mul_comm, mul_rat_iff hr] #align liouville_with.rat_mul_iff LiouvilleWith.rat_mul_iff theorem rat_mul (h : LiouvilleWith p x) (hr : r ≠ 0) : LiouvilleWith p (r * x) := (rat_mul_iff hr).2 h #align liouville_with.rat_mul LiouvilleWith.rat_mul theorem mul_int_iff (hm : m ≠ 0) : LiouvilleWith p (x * m) ↔ LiouvilleWith p x := by rw [← Rat.cast_intCast, mul_rat_iff (Int.cast_ne_zero.2 hm)] #align liouville_with.mul_int_iff LiouvilleWith.mul_int_iff theorem mul_int (h : LiouvilleWith p x) (hm : m ≠ 0) : LiouvilleWith p (x * m) := (mul_int_iff hm).2 h #align liouville_with.mul_int LiouvilleWith.mul_int theorem int_mul_iff (hm : m ≠ 0) : LiouvilleWith p (m * x) ↔ LiouvilleWith p x := by rw [mul_comm, mul_int_iff hm] #align liouville_with.int_mul_iff LiouvilleWith.int_mul_iff theorem int_mul (h : LiouvilleWith p x) (hm : m ≠ 0) : LiouvilleWith p (m * x) := (int_mul_iff hm).2 h #align liouville_with.int_mul LiouvilleWith.int_mul theorem mul_nat_iff (hn : n ≠ 0) : LiouvilleWith p (x * n) ↔ LiouvilleWith p x := by rw [← Rat.cast_natCast, mul_rat_iff (Nat.cast_ne_zero.2 hn)] #align liouville_with.mul_nat_iff LiouvilleWith.mul_nat_iff theorem mul_nat (h : LiouvilleWith p x) (hn : n ≠ 0) : LiouvilleWith p (x * n) := (mul_nat_iff hn).2 h #align liouville_with.mul_nat LiouvilleWith.mul_nat theorem nat_mul_iff (hn : n ≠ 0) : LiouvilleWith p (n * x) ↔ LiouvilleWith p x := by rw [mul_comm, mul_nat_iff hn] #align liouville_with.nat_mul_iff LiouvilleWith.nat_mul_iff theorem nat_mul (h : LiouvilleWith p x) (hn : n ≠ 0) : LiouvilleWith p (n * x) := by rw [mul_comm]; exact h.mul_nat hn #align liouville_with.nat_mul LiouvilleWith.nat_mul theorem add_rat (h : LiouvilleWith p x) (r : ℚ) : LiouvilleWith p (x + r) := by rcases h.exists_pos with ⟨C, _hC₀, hC⟩ refine ⟨r.den ^ p * C, (tendsto_id.nsmul_atTop r.pos).frequently (hC.mono ?_)⟩ rintro n ⟨hn, m, hne, hlt⟩ have : (↑(r.den * m + r.num * n : ℤ) / ↑(r.den • id n) : ℝ) = m / n + r := by rw [Algebra.id.smul_eq_mul, id] nth_rewrite 4 [← Rat.num_div_den r] push_cast rw [add_div, mul_div_mul_left _ _ (by positivity), mul_div_mul_right _ _ (by positivity)] refine ⟨r.den * m + r.num * n, ?_⟩; rw [this, add_sub_add_right_eq_sub] refine ⟨by simpa, hlt.trans_le (le_of_eq ?_)⟩ have : (r.den ^ p : ℝ) ≠ 0 := by positivity simp [mul_rpow, Nat.cast_nonneg, mul_div_mul_left, this] #align liouville_with.add_rat LiouvilleWith.add_rat @[simp] theorem add_rat_iff : LiouvilleWith p (x + r) ↔ LiouvilleWith p x := ⟨fun h => by simpa using h.add_rat (-r), fun h => h.add_rat r⟩ #align liouville_with.add_rat_iff LiouvilleWith.add_rat_iff @[simp] theorem rat_add_iff : LiouvilleWith p (r + x) ↔ LiouvilleWith p x := by rw [add_comm, add_rat_iff] #align liouville_with.rat_add_iff LiouvilleWith.rat_add_iff theorem rat_add (h : LiouvilleWith p x) (r : ℚ) : LiouvilleWith p (r + x) := add_comm x r ▸ h.add_rat r #align liouville_with.rat_add LiouvilleWith.rat_add @[simp] theorem add_int_iff : LiouvilleWith p (x + m) ↔ LiouvilleWith p x := by rw [← Rat.cast_intCast m, add_rat_iff] #align liouville_with.add_int_iff LiouvilleWith.add_int_iff @[simp] theorem int_add_iff : LiouvilleWith p (m + x) ↔ LiouvilleWith p x := by rw [add_comm, add_int_iff] #align liouville_with.int_add_iff LiouvilleWith.int_add_iff @[simp] theorem add_nat_iff : LiouvilleWith p (x + n) ↔ LiouvilleWith p x := by rw [← Rat.cast_natCast n, add_rat_iff] #align liouville_with.add_nat_iff LiouvilleWith.add_nat_iff @[simp]
Mathlib/NumberTheory/Liouville/LiouvilleWith.lean
225
225
theorem nat_add_iff : LiouvilleWith p (n + x) ↔ LiouvilleWith p x := by
rw [add_comm, add_nat_iff]
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot -/ import Mathlib.Data.Set.Image import Mathlib.Data.SProd #align_import data.set.prod from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Sets in product and pi types This file defines the product of sets in `α × β` and in `Π i, α i` along with the diagonal of a type. ## Main declarations * `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have `s.prod t : Set (α × β)`. * `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`. * `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal. * `Set.pi`: Arbitrary product of sets. -/ open Function namespace Set /-! ### Cartesian binary product of sets -/ section Prod variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β} theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) : (s ×ˢ t).Subsingleton := fun _x hx _y hy ↦ Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2) noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] : DecidablePred (· ∈ s ×ˢ t) := fun _ => And.decidable #align set.decidable_mem_prod Set.decidableMemProd @[gcongr] theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ := fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩ #align set.prod_mono Set.prod_mono @[gcongr] theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t := prod_mono hs Subset.rfl #align set.prod_mono_left Set.prod_mono_left @[gcongr] theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ := prod_mono Subset.rfl ht #align set.prod_mono_right Set.prod_mono_right @[simp] theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ := ⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩ #align set.prod_self_subset_prod_self Set.prod_self_subset_prod_self @[simp] theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ := and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self #align set.prod_self_ssubset_prod_self Set.prod_self_ssubset_prod_self theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P := ⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩ #align set.prod_subset_iff Set.prod_subset_iff theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) := prod_subset_iff #align set.forall_prod_set Set.forall_prod_set theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by simp [and_assoc] #align set.exists_prod_set Set.exists_prod_set @[simp] theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by ext exact and_false_iff _ #align set.prod_empty Set.prod_empty @[simp] theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by ext exact false_and_iff _ #align set.empty_prod Set.empty_prod @[simp, mfld_simps] theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by ext exact true_and_iff _ #align set.univ_prod_univ Set.univ_prod_univ theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq] #align set.univ_prod Set.univ_prod theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq] #align set.prod_univ Set.prod_univ @[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] @[simp] theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.singleton_prod Set.singleton_prod @[simp] theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.prod_singleton Set.prod_singleton theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by simp #align set.singleton_prod_singleton Set.singleton_prod_singleton @[simp] theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by ext ⟨x, y⟩ simp [or_and_right] #align set.union_prod Set.union_prod @[simp] theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by ext ⟨x, y⟩ simp [and_or_left] #align set.prod_union Set.prod_union theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by ext ⟨x, y⟩ simp only [← and_and_right, mem_inter_iff, mem_prod] #align set.inter_prod Set.inter_prod theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by ext ⟨x, y⟩ simp only [← and_and_left, mem_inter_iff, mem_prod] #align set.prod_inter Set.prod_inter @[mfld_simps] theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] #align set.prod_inter_prod Set.prod_inter_prod lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) : (s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by ext p simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and] constructor <;> intro h · by_cases fst_in_s : p.fst ∈ s · exact Or.inr (h fst_in_s) · exact Or.inl fst_in_s · intro fst_in_s simpa only [fst_in_s, not_true, false_or] using h @[simp] theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ← @forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)] #align set.disjoint_prod Set.disjoint_prod theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂ #align set.disjoint.set_prod_left Set.Disjoint.set_prod_left theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂ #align set.disjoint.set_prod_right Set.Disjoint.set_prod_right theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by ext ⟨x, y⟩ simp (config := { contextual := true }) [image, iff_def, or_imp] #align set.insert_prod Set.insert_prod theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by ext ⟨x, y⟩ -- porting note (#10745): -- was `simp (config := { contextual := true }) [image, iff_def, or_imp, Imp.swap]` simp only [mem_prod, mem_insert_iff, image, mem_union, mem_setOf_eq, Prod.mk.injEq] refine ⟨fun h => ?_, fun h => ?_⟩ · obtain ⟨hx, rfl|hy⟩ := h · exact Or.inl ⟨x, hx, rfl, rfl⟩ · exact Or.inr ⟨hx, hy⟩ · obtain ⟨x, hx, rfl, rfl⟩|⟨hx, hy⟩ := h · exact ⟨hx, Or.inl rfl⟩ · exact ⟨hx, Or.inr hy⟩ #align set.prod_insert Set.prod_insert theorem prod_preimage_eq {f : γ → α} {g : δ → β} : (f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_eq Set.prod_preimage_eq theorem prod_preimage_left {f : γ → α} : (f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_left Set.prod_preimage_left theorem prod_preimage_right {g : δ → β} : s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_right Set.prod_preimage_right theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) : Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) := rfl #align set.preimage_prod_map_prod Set.preimage_prod_map_prod theorem mk_preimage_prod (f : γ → α) (g : γ → β) : (fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t := rfl #align set.mk_preimage_prod Set.mk_preimage_prod @[simp] theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by ext a simp [hb] #align set.mk_preimage_prod_left Set.mk_preimage_prod_left @[simp] theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by ext b simp [ha] #align set.mk_preimage_prod_right Set.mk_preimage_prod_right @[simp] theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by ext a simp [hb] #align set.mk_preimage_prod_left_eq_empty Set.mk_preimage_prod_left_eq_empty @[simp] theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by ext b simp [ha] #align set.mk_preimage_prod_right_eq_empty Set.mk_preimage_prod_right_eq_empty theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] : (fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_left_eq_if Set.mk_preimage_prod_left_eq_if theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] : Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_right_eq_if Set.mk_preimage_prod_right_eq_if
Mathlib/Data/Set/Prod.lean
256
258
theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) : (fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by
rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage]
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Bhavik Mehta -/ import Mathlib.Analysis.Calculus.Deriv.Support import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.MeasureTheory.Integral.FundThmCalculus import Mathlib.Order.Filter.AtTopBot import Mathlib.MeasureTheory.Function.Jacobian import Mathlib.MeasureTheory.Measure.Haar.NormedSpace import Mathlib.MeasureTheory.Measure.Haar.Unique #align_import measure_theory.integral.integral_eq_improper from "leanprover-community/mathlib"@"b84aee748341da06a6d78491367e2c0e9f15e8a5" /-! # Links between an integral and its "improper" version In its current state, mathlib only knows how to talk about definite ("proper") integrals, in the sense that it treats integrals over `[x, +∞)` the same as it treats integrals over `[y, z]`. For example, the integral over `[1, +∞)` is **not** defined to be the limit of the integral over `[1, x]` as `x` tends to `+∞`, which is known as an **improper integral**. Indeed, the "proper" definition is stronger than the "improper" one. The usual counterexample is `x ↦ sin(x)/x`, which has an improper integral over `[1, +∞)` but no definite integral. Although definite integrals have better properties, they are hardly usable when it comes to computing integrals on unbounded sets, which is much easier using limits. Thus, in this file, we prove various ways of studying the proper integral by studying the improper one. ## Definitions The main definition of this file is `MeasureTheory.AECover`. It is a rather technical definition whose sole purpose is generalizing and factoring proofs. Given an index type `ι`, a countably generated filter `l` over `ι`, and an `ι`-indexed family `φ` of subsets of a measurable space `α` equipped with a measure `μ`, one should think of a hypothesis `hφ : MeasureTheory.AECover μ l φ` as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ i, f x ∂μ` as `i` tends to `l`. When using this definition with a measure restricted to a set `s`, which happens fairly often, one should not try too hard to use a `MeasureTheory.AECover` of subsets of `s`, as it often makes proofs more complicated than necessary. See for example the proof of `MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_tendsto` where we use `(fun x ↦ oi x)` as a `MeasureTheory.AECover` w.r.t. `μ.restrict (Iic b)`, instead of using `(fun x ↦ Ioc x b)`. ## Main statements - `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is a measurable `ENNReal`-valued function, then `∫⁻ x in φ n, f x ∂μ` tends to `∫⁻ x, f x ∂μ` as `n` tends to `l` - `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, if `f` is measurable and integrable on each `φ n`, and if `∫ x in φ n, ‖f x‖ ∂μ` tends to some `I : ℝ` as n tends to `l`, then `f` is integrable - `MeasureTheory.AECover.integral_tendsto_of_countably_generated` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is measurable and integrable (globally), then `∫ x in φ n, f x ∂μ` tends to `∫ x, f x ∂μ` as `n` tends to `+∞`. We then specialize these lemmas to various use cases involving intervals, which are frequent in analysis. In particular, - `MeasureTheory.integral_Ioi_of_hasDerivAt_of_tendsto` is a version of FTC-2 on the interval `(a, +∞)`, giving the formula `∫ x in (a, +∞), g' x = l - g a` if `g'` is integrable and `g` tends to `l` at `+∞`. - `MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonneg` gives the same result assuming that `g'` is nonnegative instead of integrable. Its automatic integrability in this context is proved in `MeasureTheory.integrableOn_Ioi_deriv_of_nonneg`. - `MeasureTheory.integral_comp_smul_deriv_Ioi` is a version of the change of variables formula on semi-infinite intervals. - `MeasureTheory.tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi` shows that a function whose derivative is integrable on `(a, +∞)` has a limit at `+∞`. - `MeasureTheory.tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi` shows that an integrable function whose derivative is integrable on `(a, +∞)` tends to `0` at `+∞`. Versions of these results are also given on the intervals `(-∞, a]` and `(-∞, +∞)`, as well as the corresponding versions of integration by parts. -/ open MeasureTheory Filter Set TopologicalSpace open scoped ENNReal NNReal Topology namespace MeasureTheory section AECover variable {α ι : Type*} [MeasurableSpace α] (μ : Measure α) (l : Filter ι) /-- A sequence `φ` of subsets of `α` is a `MeasureTheory.AECover` w.r.t. a measure `μ` and a filter `l` if almost every point (w.r.t. `μ`) of `α` eventually belongs to `φ n` (w.r.t. `l`), and if each `φ n` is measurable. This definition is a technical way to avoid duplicating a lot of proofs. It should be thought of as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ n, f x ∂μ` as `n` tends to `l`. See for example `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated`, `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` and `MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/ structure AECover (φ : ι → Set α) : Prop where ae_eventually_mem : ∀ᵐ x ∂μ, ∀ᶠ i in l, x ∈ φ i protected measurableSet : ∀ i, MeasurableSet <| φ i #align measure_theory.ae_cover MeasureTheory.AECover #align measure_theory.ae_cover.ae_eventually_mem MeasureTheory.AECover.ae_eventually_mem #align measure_theory.ae_cover.measurable MeasureTheory.AECover.measurableSet variable {μ} {l} namespace AECover /-! ## Operations on `AECover`s Porting note: this is a new section. -/ /-- Elementwise intersection of two `AECover`s is an `AECover`. -/ theorem inter {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hψ : AECover μ l ψ) : AECover μ l (fun i ↦ φ i ∩ ψ i) where ae_eventually_mem := hψ.1.mp <| hφ.1.mono fun _ ↦ Eventually.and measurableSet _ := (hφ.2 _).inter (hψ.2 _) theorem superset {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hsub : ∀ i, φ i ⊆ ψ i) (hmeas : ∀ i, MeasurableSet (ψ i)) : AECover μ l ψ := ⟨hφ.1.mono fun _x hx ↦ hx.mono fun i hi ↦ hsub i hi, hmeas⟩ theorem mono_ac {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≪ μ) : AECover ν l φ := ⟨hle hφ.1, hφ.2⟩ theorem mono {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≤ μ) : AECover ν l φ := hφ.mono_ac hle.absolutelyContinuous end AECover section MetricSpace variable [PseudoMetricSpace α] [OpensMeasurableSpace α] theorem aecover_ball {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) : AECover μ l (fun i ↦ Metric.ball x (r i)) where measurableSet _ := Metric.isOpen_ball.measurableSet ae_eventually_mem := by filter_upwards with y filter_upwards [hr (Ioi_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha theorem aecover_closedBall {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) : AECover μ l (fun i ↦ Metric.closedBall x (r i)) where measurableSet _ := Metric.isClosed_ball.measurableSet ae_eventually_mem := by filter_upwards with y filter_upwards [hr (Ici_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha end MetricSpace section Preorderα variable [Preorder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) theorem aecover_Ici : AECover μ l fun i => Ici (a i) where ae_eventually_mem := ae_of_all μ ha.eventually_le_atBot measurableSet _ := measurableSet_Ici #align measure_theory.ae_cover_Ici MeasureTheory.aecover_Ici theorem aecover_Iic : AECover μ l fun i => Iic <| b i := aecover_Ici (α := αᵒᵈ) hb #align measure_theory.ae_cover_Iic MeasureTheory.aecover_Iic theorem aecover_Icc : AECover μ l fun i => Icc (a i) (b i) := (aecover_Ici ha).inter (aecover_Iic hb) #align measure_theory.ae_cover_Icc MeasureTheory.aecover_Icc end Preorderα section LinearOrderα variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) theorem aecover_Ioi [NoMinOrder α] : AECover μ l fun i => Ioi (a i) where ae_eventually_mem := ae_of_all μ ha.eventually_lt_atBot measurableSet _ := measurableSet_Ioi #align measure_theory.ae_cover_Ioi MeasureTheory.aecover_Ioi theorem aecover_Iio [NoMaxOrder α] : AECover μ l fun i => Iio (b i) := aecover_Ioi (α := αᵒᵈ) hb #align measure_theory.ae_cover_Iio MeasureTheory.aecover_Iio theorem aecover_Ioo [NoMinOrder α] [NoMaxOrder α] : AECover μ l fun i => Ioo (a i) (b i) := (aecover_Ioi ha).inter (aecover_Iio hb) #align measure_theory.ae_cover_Ioo MeasureTheory.aecover_Ioo theorem aecover_Ioc [NoMinOrder α] : AECover μ l fun i => Ioc (a i) (b i) := (aecover_Ioi ha).inter (aecover_Iic hb) #align measure_theory.ae_cover_Ioc MeasureTheory.aecover_Ioc theorem aecover_Ico [NoMaxOrder α] : AECover μ l fun i => Ico (a i) (b i) := (aecover_Ici ha).inter (aecover_Iio hb) #align measure_theory.ae_cover_Ico MeasureTheory.aecover_Ico end LinearOrderα section FiniteIntervals variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} {A B : α} (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) -- Porting note (#10756): new lemma theorem aecover_Ioi_of_Ioi : AECover (μ.restrict (Ioi A)) l fun i ↦ Ioi (a i) where ae_eventually_mem := (ae_restrict_mem measurableSet_Ioi).mono fun _x hx ↦ ha.eventually <| eventually_lt_nhds hx measurableSet _ := measurableSet_Ioi -- Porting note (#10756): new lemma theorem aecover_Iio_of_Iio : AECover (μ.restrict (Iio B)) l fun i ↦ Iio (b i) := aecover_Ioi_of_Ioi (α := αᵒᵈ) hb -- Porting note (#10756): new lemma theorem aecover_Ioi_of_Ici : AECover (μ.restrict (Ioi A)) l fun i ↦ Ici (a i) := (aecover_Ioi_of_Ioi ha).superset (fun _ ↦ Ioi_subset_Ici_self) fun _ ↦ measurableSet_Ici -- Porting note (#10756): new lemma theorem aecover_Iio_of_Iic : AECover (μ.restrict (Iio B)) l fun i ↦ Iic (b i) := aecover_Ioi_of_Ici (α := αᵒᵈ) hb theorem aecover_Ioo_of_Ioo : AECover (μ.restrict <| Ioo A B) l fun i => Ioo (a i) (b i) := ((aecover_Ioi_of_Ioi ha).mono <| Measure.restrict_mono Ioo_subset_Ioi_self le_rfl).inter ((aecover_Iio_of_Iio hb).mono <| Measure.restrict_mono Ioo_subset_Iio_self le_rfl) #align measure_theory.ae_cover_Ioo_of_Ioo MeasureTheory.aecover_Ioo_of_Ioo theorem aecover_Ioo_of_Icc : AECover (μ.restrict <| Ioo A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Icc_self) fun _ ↦ measurableSet_Icc #align measure_theory.ae_cover_Ioo_of_Icc MeasureTheory.aecover_Ioo_of_Icc theorem aecover_Ioo_of_Ico : AECover (μ.restrict <| Ioo A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ico_self) fun _ ↦ measurableSet_Ico #align measure_theory.ae_cover_Ioo_of_Ico MeasureTheory.aecover_Ioo_of_Ico theorem aecover_Ioo_of_Ioc : AECover (μ.restrict <| Ioo A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ioc_self) fun _ ↦ measurableSet_Ioc #align measure_theory.ae_cover_Ioo_of_Ioc MeasureTheory.aecover_Ioo_of_Ioc variable [NoAtoms μ] theorem aecover_Ioc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge #align measure_theory.ae_cover_Ioc_of_Icc MeasureTheory.aecover_Ioc_of_Icc theorem aecover_Ioc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge #align measure_theory.ae_cover_Ioc_of_Ico MeasureTheory.aecover_Ioc_of_Ico theorem aecover_Ioc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge #align measure_theory.ae_cover_Ioc_of_Ioc MeasureTheory.aecover_Ioc_of_Ioc theorem aecover_Ioc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge #align measure_theory.ae_cover_Ioc_of_Ioo MeasureTheory.aecover_Ioc_of_Ioo theorem aecover_Ico_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge #align measure_theory.ae_cover_Ico_of_Icc MeasureTheory.aecover_Ico_of_Icc theorem aecover_Ico_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge #align measure_theory.ae_cover_Ico_of_Ico MeasureTheory.aecover_Ico_of_Ico theorem aecover_Ico_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge #align measure_theory.ae_cover_Ico_of_Ioc MeasureTheory.aecover_Ico_of_Ioc theorem aecover_Ico_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge #align measure_theory.ae_cover_Ico_of_Ioo MeasureTheory.aecover_Ico_of_Ioo theorem aecover_Icc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge #align measure_theory.ae_cover_Icc_of_Icc MeasureTheory.aecover_Icc_of_Icc theorem aecover_Icc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge #align measure_theory.ae_cover_Icc_of_Ico MeasureTheory.aecover_Icc_of_Ico theorem aecover_Icc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge #align measure_theory.ae_cover_Icc_of_Ioc MeasureTheory.aecover_Icc_of_Ioc theorem aecover_Icc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge #align measure_theory.ae_cover_Icc_of_Ioo MeasureTheory.aecover_Icc_of_Ioo end FiniteIntervals protected theorem AECover.restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} : AECover (μ.restrict s) l φ := hφ.mono Measure.restrict_le_self #align measure_theory.ae_cover.restrict MeasureTheory.AECover.restrict theorem aecover_restrict_of_ae_imp {s : Set α} {φ : ι → Set α} (hs : MeasurableSet s) (ae_eventually_mem : ∀ᵐ x ∂μ, x ∈ s → ∀ᶠ n in l, x ∈ φ n) (measurable : ∀ n, MeasurableSet <| φ n) : AECover (μ.restrict s) l φ where ae_eventually_mem := by rwa [ae_restrict_iff' hs] measurableSet := measurable #align measure_theory.ae_cover_restrict_of_ae_imp MeasureTheory.aecover_restrict_of_ae_imp theorem AECover.inter_restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} (hs : MeasurableSet s) : AECover (μ.restrict s) l fun i => φ i ∩ s := aecover_restrict_of_ae_imp hs (hφ.ae_eventually_mem.mono fun _x hx hxs => hx.mono fun _i hi => ⟨hi, hxs⟩) fun i => (hφ.measurableSet i).inter hs #align measure_theory.ae_cover.inter_restrict MeasureTheory.AECover.inter_restrict theorem AECover.ae_tendsto_indicator {β : Type*} [Zero β] [TopologicalSpace β] (f : α → β) {φ : ι → Set α} (hφ : AECover μ l φ) : ∀ᵐ x ∂μ, Tendsto (fun i => (φ i).indicator f x) l (𝓝 <| f x) := hφ.ae_eventually_mem.mono fun _x hx => tendsto_const_nhds.congr' <| hx.mono fun _n hn => (indicator_of_mem hn _).symm #align measure_theory.ae_cover.ae_tendsto_indicator MeasureTheory.AECover.ae_tendsto_indicator theorem AECover.aemeasurable {β : Type*} [MeasurableSpace β] [l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ) (hfm : ∀ i, AEMeasurable f (μ.restrict <| φ i)) : AEMeasurable f μ := by obtain ⟨u, hu⟩ := l.exists_seq_tendsto have := aemeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n) rwa [Measure.restrict_eq_self_of_ae_mem] at this filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists #align measure_theory.ae_cover.ae_measurable MeasureTheory.AECover.aemeasurable theorem AECover.aestronglyMeasurable {β : Type*} [TopologicalSpace β] [PseudoMetrizableSpace β] [l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ) (hfm : ∀ i, AEStronglyMeasurable f (μ.restrict <| φ i)) : AEStronglyMeasurable f μ := by obtain ⟨u, hu⟩ := l.exists_seq_tendsto have := aestronglyMeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n) rwa [Measure.restrict_eq_self_of_ae_mem] at this filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists #align measure_theory.ae_cover.ae_strongly_measurable MeasureTheory.AECover.aestronglyMeasurable end AECover theorem AECover.comp_tendsto {α ι ι' : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} {l' : Filter ι'} {φ : ι → Set α} (hφ : AECover μ l φ) {u : ι' → ι} (hu : Tendsto u l' l) : AECover μ l' (φ ∘ u) where ae_eventually_mem := hφ.ae_eventually_mem.mono fun _x hx => hu.eventually hx measurableSet i := hφ.measurableSet (u i) #align measure_theory.ae_cover.comp_tendsto MeasureTheory.AECover.comp_tendsto section AECoverUnionInterCountable variable {α ι : Type*} [Countable ι] [MeasurableSpace α] {μ : Measure α} theorem AECover.biUnion_Iic_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋃ (k) (_h : k ∈ Iic n), φ k := hφ.superset (fun _ ↦ subset_biUnion_of_mem right_mem_Iic) fun _ ↦ .biUnion (to_countable _) fun _ _ ↦ (hφ.2 _) #align measure_theory.ae_cover.bUnion_Iic_ae_cover MeasureTheory.AECover.biUnion_Iic_aecover -- Porting note: generalized from `[SemilatticeSup ι] [Nonempty ι]` to `[Preorder ι]` theorem AECover.biInter_Ici_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋂ (k) (_h : k ∈ Ici n), φ k where ae_eventually_mem := hφ.ae_eventually_mem.mono fun x h ↦ by simpa only [mem_iInter, mem_Ici, eventually_forall_ge_atTop] measurableSet i := .biInter (to_countable _) fun n _ => hφ.measurableSet n #align measure_theory.ae_cover.bInter_Ici_ae_cover MeasureTheory.AECover.biInter_Ici_aecover end AECoverUnionInterCountable section Lintegral variable {α ι : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} private theorem lintegral_tendsto_of_monotone_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) (hmono : Monotone φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := let F n := (φ n).indicator f have key₁ : ∀ n, AEMeasurable (F n) μ := fun n => hfm.indicator (hφ.measurableSet n) have key₂ : ∀ᵐ x : α ∂μ, Monotone fun n => F n x := ae_of_all _ fun x _i _j hij => indicator_le_indicator_of_subset (hmono hij) (fun x => zero_le <| f x) x have key₃ : ∀ᵐ x : α ∂μ, Tendsto (fun n => F n x) atTop (𝓝 (f x)) := hφ.ae_tendsto_indicator f (lintegral_tendsto_of_tendsto_of_monotone key₁ key₂ key₃).congr fun n => lintegral_indicator f (hφ.measurableSet n) theorem AECover.lintegral_tendsto_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (∫⁻ x in φ ·, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := by have lim₁ := lintegral_tendsto_of_monotone_of_nat hφ.biInter_Ici_aecover (fun i j hij => biInter_subset_biInter_left (Ici_subset_Ici.mpr hij)) hfm have lim₂ := lintegral_tendsto_of_monotone_of_nat hφ.biUnion_Iic_aecover (fun i j hij => biUnion_subset_biUnion_left (Iic_subset_Iic.mpr hij)) hfm refine tendsto_of_tendsto_of_tendsto_of_le_of_le lim₁ lim₂ (fun n ↦ ?_) fun n ↦ ?_ exacts [lintegral_mono_set (biInter_subset_of_mem left_mem_Ici), lintegral_mono_set (subset_biUnion_of_mem right_mem_Iic)] #align measure_theory.ae_cover.lintegral_tendsto_of_nat MeasureTheory.AECover.lintegral_tendsto_of_nat theorem AECover.lintegral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 <| ∫⁻ x, f x ∂μ) := tendsto_of_seq_tendsto fun _u hu => (hφ.comp_tendsto hu).lintegral_tendsto_of_nat hfm #align measure_theory.ae_cover.lintegral_tendsto_of_countably_generated MeasureTheory.AECover.lintegral_tendsto_of_countably_generated theorem AECover.lintegral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (I : ℝ≥0∞) (hfm : AEMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 I)) : ∫⁻ x, f x ∂μ = I := tendsto_nhds_unique (hφ.lintegral_tendsto_of_countably_generated hfm) htendsto #align measure_theory.ae_cover.lintegral_eq_of_tendsto MeasureTheory.AECover.lintegral_eq_of_tendsto theorem AECover.iSup_lintegral_eq_of_countably_generated [Nonempty ι] [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : ⨆ i : ι, ∫⁻ x in φ i, f x ∂μ = ∫⁻ x, f x ∂μ := by have := hφ.lintegral_tendsto_of_countably_generated hfm refine ciSup_eq_of_forall_le_of_forall_lt_exists_gt (fun i => lintegral_mono' Measure.restrict_le_self le_rfl) fun w hw => ?_ rcases exists_between hw with ⟨m, hm₁, hm₂⟩ rcases (eventually_ge_of_tendsto_gt hm₂ this).exists with ⟨i, hi⟩ exact ⟨i, lt_of_lt_of_le hm₁ hi⟩ #align measure_theory.ae_cover.supr_lintegral_eq_of_countably_generated MeasureTheory.AECover.iSup_lintegral_eq_of_countably_generated end Lintegral section Integrable variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E] theorem AECover.integrable_of_lintegral_nnnorm_bounded [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ) (hbounded : ∀ᶠ i in l, (∫⁻ x in φ i, ‖f x‖₊ ∂μ) ≤ ENNReal.ofReal I) : Integrable f μ := by refine ⟨hfm, (le_of_tendsto ?_ hbounded).trans_lt ENNReal.ofReal_lt_top⟩ exact hφ.lintegral_tendsto_of_countably_generated hfm.ennnorm #align measure_theory.ae_cover.integrable_of_lintegral_nnnorm_bounded MeasureTheory.AECover.integrable_of_lintegral_nnnorm_bounded theorem AECover.integrable_of_lintegral_nnnorm_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖₊ ∂μ) l (𝓝 <| ENNReal.ofReal I)) : Integrable f μ := by refine hφ.integrable_of_lintegral_nnnorm_bounded (max 1 (I + 1)) hfm ?_ refine htendsto.eventually (ge_mem_nhds ?_) refine (ENNReal.ofReal_lt_ofReal_iff (lt_max_of_lt_left zero_lt_one)).2 ?_ exact lt_max_of_lt_right (lt_add_one I) #align measure_theory.ae_cover.integrable_of_lintegral_nnnorm_tendsto MeasureTheory.AECover.integrable_of_lintegral_nnnorm_tendsto theorem AECover.integrable_of_lintegral_nnnorm_bounded' [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ) (hbounded : ∀ᶠ i in l, (∫⁻ x in φ i, ‖f x‖₊ ∂μ) ≤ I) : Integrable f μ := hφ.integrable_of_lintegral_nnnorm_bounded I hfm (by simpa only [ENNReal.ofReal_coe_nnreal] using hbounded) #align measure_theory.ae_cover.integrable_of_lintegral_nnnorm_bounded' MeasureTheory.AECover.integrable_of_lintegral_nnnorm_bounded' theorem AECover.integrable_of_lintegral_nnnorm_tendsto' [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖₊ ∂μ) l (𝓝 I)) : Integrable f μ := hφ.integrable_of_lintegral_nnnorm_tendsto I hfm (by simpa only [ENNReal.ofReal_coe_nnreal] using htendsto) #align measure_theory.ae_cover.integrable_of_lintegral_nnnorm_tendsto' MeasureTheory.AECover.integrable_of_lintegral_nnnorm_tendsto' theorem AECover.integrable_of_integral_norm_bounded [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hbounded : ∀ᶠ i in l, (∫ x in φ i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by have hfm : AEStronglyMeasurable f μ := hφ.aestronglyMeasurable fun i => (hfi i).aestronglyMeasurable refine hφ.integrable_of_lintegral_nnnorm_bounded I hfm ?_ conv at hbounded in integral _ _ => rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun x => @norm_nonneg E _ (f x)) hfm.norm.restrict] conv at hbounded in ENNReal.ofReal _ => rw [← coe_nnnorm] rw [ENNReal.ofReal_coe_nnreal] refine hbounded.mono fun i hi => ?_ rw [← ENNReal.ofReal_toReal (ne_top_of_lt (hfi i).2)] apply ENNReal.ofReal_le_ofReal hi #align measure_theory.ae_cover.integrable_of_integral_norm_bounded MeasureTheory.AECover.integrable_of_integral_norm_bounded theorem AECover.integrable_of_integral_norm_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (htendsto : Tendsto (fun i => ∫ x in φ i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le hφ.integrable_of_integral_norm_bounded I' hfi hI' #align measure_theory.ae_cover.integrable_of_integral_norm_tendsto MeasureTheory.AECover.integrable_of_integral_norm_tendsto theorem AECover.integrable_of_integral_bounded_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (hbounded : ∀ᶠ i in l, (∫ x in φ i, f x ∂μ) ≤ I) : Integrable f μ := hφ.integrable_of_integral_norm_bounded I hfi <| hbounded.mono fun _i hi => (integral_congr_ae <| ae_restrict_of_ae <| hnng.mono fun _ => Real.norm_of_nonneg).le.trans hi #align measure_theory.ae_cover.integrable_of_integral_bounded_of_nonneg_ae MeasureTheory.AECover.integrable_of_integral_bounded_of_nonneg_ae theorem AECover.integrable_of_integral_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (htendsto : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le hφ.integrable_of_integral_bounded_of_nonneg_ae I' hfi hnng hI' #align measure_theory.ae_cover.integrable_of_integral_tendsto_of_nonneg_ae MeasureTheory.AECover.integrable_of_integral_tendsto_of_nonneg_ae end Integrable section Integral variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] theorem AECover.integral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (hfi : Integrable f μ) : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := suffices h : Tendsto (fun i => ∫ x : α, (φ i).indicator f x ∂μ) l (𝓝 (∫ x : α, f x ∂μ)) from by convert h using 2; rw [integral_indicator (hφ.measurableSet _)] tendsto_integral_filter_of_dominated_convergence (fun x => ‖f x‖) (eventually_of_forall fun i => hfi.aestronglyMeasurable.indicator <| hφ.measurableSet i) (eventually_of_forall fun i => ae_of_all _ fun x => norm_indicator_le_norm_self _ _) hfi.norm (hφ.ae_tendsto_indicator f) #align measure_theory.ae_cover.integral_tendsto_of_countably_generated MeasureTheory.AECover.integral_tendsto_of_countably_generated /-- Slight reformulation of `MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/ theorem AECover.integral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : E) (hfi : Integrable f μ) (h : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := tendsto_nhds_unique (hφ.integral_tendsto_of_countably_generated hfi) h #align measure_theory.ae_cover.integral_eq_of_tendsto MeasureTheory.AECover.integral_eq_of_tendsto theorem AECover.integral_eq_of_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hnng : 0 ≤ᵐ[μ] f) (hfi : ∀ n, IntegrableOn f (φ n) μ) (htendsto : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := have hfi' : Integrable f μ := hφ.integrable_of_integral_tendsto_of_nonneg_ae I hfi hnng htendsto hφ.integral_eq_of_tendsto I hfi' htendsto #align measure_theory.ae_cover.integral_eq_of_tendsto_of_nonneg_ae MeasureTheory.AECover.integral_eq_of_tendsto_of_nonneg_ae end Integral section IntegrableOfIntervalIntegral variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [Filter.NeBot l] [IsCountablyGenerated l] [NormedAddCommGroup E] {a b : ι → ℝ} {f : ℝ → E} theorem integrable_of_intervalIntegral_norm_bounded (I : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a i..b i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by have hφ : AECover μ l _ := aecover_Ioc ha hb refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [ha.eventually (eventually_le_atBot 0), hb.eventually (eventually_ge_atTop 0)] with i hai hbi ht rwa [← intervalIntegral.integral_of_le (hai.trans hbi)] #align measure_theory.integrable_of_interval_integral_norm_bounded MeasureTheory.integrable_of_intervalIntegral_norm_bounded /-- If `f` is integrable on intervals `Ioc (a i) (b i)`, where `a i` tends to -∞ and `b i` tends to ∞, and `∫ x in a i .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, ∞) -/ theorem integrable_of_intervalIntegral_norm_tendsto (I : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a i..b i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrable_of_intervalIntegral_norm_bounded I' hfi ha hb hI' #align measure_theory.integrable_of_interval_integral_norm_tendsto MeasureTheory.integrable_of_intervalIntegral_norm_tendsto theorem integrableOn_Iic_of_intervalIntegral_norm_bounded (I b : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot) (h : ∀ᶠ i in l, (∫ x in a i..b, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Iic b) μ := by have hφ : AECover (μ.restrict <| Iic b) l _ := aecover_Ioi ha have hfi : ∀ i, IntegrableOn f (Ioi (a i)) (μ.restrict <| Iic b) := by intro i rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i)] exact hfi i refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [ha.eventually (eventually_le_atBot b)] with i hai rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)] exact id #align measure_theory.integrable_on_Iic_of_interval_integral_norm_bounded MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_bounded /-- If `f` is integrable on intervals `Ioc (a i) b`, where `a i` tends to -∞, and `∫ x in a i .. b, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, b) -/ theorem integrableOn_Iic_of_intervalIntegral_norm_tendsto (I b : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot) (h : Tendsto (fun i => ∫ x in a i..b, ‖f x‖ ∂μ) l (𝓝 I)) : IntegrableOn f (Iic b) μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrableOn_Iic_of_intervalIntegral_norm_bounded I' b hfi ha hI' #align measure_theory.integrable_on_Iic_of_interval_integral_norm_tendsto MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_tendsto theorem integrableOn_Ioi_of_intervalIntegral_norm_bounded (I a : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a..b i, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Ioi a) μ := by have hφ : AECover (μ.restrict <| Ioi a) l _ := aecover_Iic hb have hfi : ∀ i, IntegrableOn f (Iic (b i)) (μ.restrict <| Ioi a) := by intro i rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] exact hfi i refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [hb.eventually (eventually_ge_atTop a)] with i hbi rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] exact id #align measure_theory.integrable_on_Ioi_of_interval_integral_norm_bounded MeasureTheory.integrableOn_Ioi_of_intervalIntegral_norm_bounded /-- If `f` is integrable on intervals `Ioc a (b i)`, where `b i` tends to ∞, and `∫ x in a .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (a, ∞) -/ theorem integrableOn_Ioi_of_intervalIntegral_norm_tendsto (I a : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a..b i, ‖f x‖ ∂μ) l (𝓝 <| I)) : IntegrableOn f (Ioi a) μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrableOn_Ioi_of_intervalIntegral_norm_bounded I' a hfi hb hI' #align measure_theory.integrable_on_Ioi_of_interval_integral_norm_tendsto MeasureTheory.integrableOn_Ioi_of_intervalIntegral_norm_tendsto theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded {I a₀ b₀ : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc (a i) (b i)) (ha : Tendsto a l <| 𝓝 a₀) (hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b₀) := by refine (aecover_Ioc_of_Ioc ha hb).integrable_of_integral_norm_bounded I (fun i => (hfi i).restrict measurableSet_Ioc) (h.mono fun i hi ↦ ?_) rw [Measure.restrict_restrict measurableSet_Ioc] refine le_trans (setIntegral_mono_set (hfi i).norm ?_ ?_) hi <;> apply ae_of_all · simp only [Pi.zero_apply, norm_nonneg, forall_const] · intro c hc; exact hc.1 #align measure_theory.integrable_on_Ioc_of_interval_integral_norm_bounded MeasureTheory.integrableOn_Ioc_of_intervalIntegral_norm_bounded theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_left {I a₀ b : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc (a i) b) (ha : Tendsto a l <| 𝓝 a₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) b, ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b) := integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi ha tendsto_const_nhds h #align measure_theory.integrable_on_Ioc_of_interval_integral_norm_bounded_left MeasureTheory.integrableOn_Ioc_of_intervalIntegral_norm_bounded_left theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_right {I a b₀ : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc a (b i)) (hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc a (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a b₀) := integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi tendsto_const_nhds hb h #align measure_theory.integrable_on_Ioc_of_interval_integral_norm_bounded_right MeasureTheory.integrableOn_Ioc_of_intervalIntegral_norm_bounded_right @[deprecated (since := "2024-04-06")] alias integrableOn_Ioc_of_interval_integral_norm_bounded := integrableOn_Ioc_of_intervalIntegral_norm_bounded @[deprecated (since := "2024-04-06")] alias integrableOn_Ioc_of_interval_integral_norm_bounded_left := integrableOn_Ioc_of_intervalIntegral_norm_bounded_left @[deprecated (since := "2024-04-06")] alias integrableOn_Ioc_of_interval_integral_norm_bounded_right := integrableOn_Ioc_of_intervalIntegral_norm_bounded_right end IntegrableOfIntervalIntegral section IntegralOfIntervalIntegral variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [IsCountablyGenerated l] [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {a b : ι → ℝ} {f : ℝ → E} theorem intervalIntegral_tendsto_integral (hfi : Integrable f μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a i..b i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := by let φ i := Ioc (a i) (b i) have hφ : AECover μ l φ := aecover_Ioc ha hb refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [ha.eventually (eventually_le_atBot 0), hb.eventually (eventually_ge_atTop 0)] with i hai hbi exact (intervalIntegral.integral_of_le (hai.trans hbi)).symm #align measure_theory.interval_integral_tendsto_integral MeasureTheory.intervalIntegral_tendsto_integral theorem intervalIntegral_tendsto_integral_Iic (b : ℝ) (hfi : IntegrableOn f (Iic b) μ) (ha : Tendsto a l atBot) : Tendsto (fun i => ∫ x in a i..b, f x ∂μ) l (𝓝 <| ∫ x in Iic b, f x ∂μ) := by let φ i := Ioi (a i) have hφ : AECover (μ.restrict <| Iic b) l φ := aecover_Ioi ha refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [ha.eventually (eventually_le_atBot <| b)] with i hai rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)] rfl #align measure_theory.interval_integral_tendsto_integral_Iic MeasureTheory.intervalIntegral_tendsto_integral_Iic theorem intervalIntegral_tendsto_integral_Ioi (a : ℝ) (hfi : IntegrableOn f (Ioi a) μ) (hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a..b i, f x ∂μ) l (𝓝 <| ∫ x in Ioi a, f x ∂μ) := by let φ i := Iic (b i) have hφ : AECover (μ.restrict <| Ioi a) l φ := aecover_Iic hb refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [hb.eventually (eventually_ge_atTop <| a)] with i hbi rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] rfl #align measure_theory.interval_integral_tendsto_integral_Ioi MeasureTheory.intervalIntegral_tendsto_integral_Ioi end IntegralOfIntervalIntegral open Real open scoped Interval section IoiFTC variable {E : Type*} {f f' : ℝ → E} {g g' : ℝ → ℝ} {a b l : ℝ} {m : E} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- If the derivative of a function defined on the real line is integrable close to `+∞`, then the function has a limit at `+∞`. -/ theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi [CompleteSpace E] (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) : Tendsto f atTop (𝓝 (limUnder atTop f)) := by suffices ∃ a, Tendsto f atTop (𝓝 a) from tendsto_nhds_limUnder this suffices CauchySeq f from cauchySeq_tendsto_of_complete this apply Metric.cauchySeq_iff'.2 (fun ε εpos ↦ ?_) have A : ∀ᶠ (n : ℕ) in atTop, ∫ (x : ℝ) in Ici ↑n, ‖f' x‖ < ε := by have L : Tendsto (fun (n : ℕ) ↦ ∫ x in Ici (n : ℝ), ‖f' x‖) atTop (𝓝 (∫ x in ⋂ (n : ℕ), Ici (n : ℝ), ‖f' x‖)) := by apply tendsto_setIntegral_of_antitone (fun n ↦ measurableSet_Ici) · intro m n hmn exact Ici_subset_Ici.2 (Nat.cast_le.mpr hmn) · rcases exists_nat_gt a with ⟨n, hn⟩ exact ⟨n, IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 hn)⟩ have B : ⋂ (n : ℕ), Ici (n : ℝ) = ∅ := by apply eq_empty_of_forall_not_mem (fun x ↦ ?_) simpa only [mem_iInter, mem_Ici, not_forall, not_le] using exists_nat_gt x simp only [B, Measure.restrict_empty, integral_zero_measure] at L exact (tendsto_order.1 L).2 _ εpos have B : ∀ᶠ (n : ℕ) in atTop, a < n := by rcases exists_nat_gt a with ⟨n, hn⟩ filter_upwards [Ioi_mem_atTop n] with m (hm : n < m) using hn.trans (Nat.cast_lt.mpr hm) rcases (A.and B).exists with ⟨N, hN, h'N⟩ refine ⟨N, fun x hx ↦ ?_⟩ calc dist (f x) (f ↑N) = ‖f x - f N‖ := dist_eq_norm _ _ _ = ‖∫ t in Ioc ↑N x, f' t‖ := by rw [← intervalIntegral.integral_of_le hx, intervalIntegral.integral_eq_sub_of_hasDerivAt] · intro y hy simp only [hx, uIcc_of_le, mem_Icc] at hy exact hderiv _ (h'N.trans_le hy.1) · rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hx] exact f'int.mono_set (Ioc_subset_Ioi_self.trans (Ioi_subset_Ioi h'N.le)) _ ≤ ∫ t in Ioc ↑N x, ‖f' t‖ := norm_integral_le_integral_norm fun a ↦ f' a _ ≤ ∫ t in Ici ↑N, ‖f' t‖ := by apply setIntegral_mono_set · apply IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 h'N) · filter_upwards with x using norm_nonneg _ · have : Ioc (↑N) x ⊆ Ici ↑N := Ioc_subset_Ioi_self.trans Ioi_subset_Ici_self exact this.eventuallyLE _ < ε := hN open UniformSpace in /-- If a function and its derivative are integrable on `(a, +∞)`, then the function tends to zero at `+∞`. -/ theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (fint : IntegrableOn f (Ioi a)) : Tendsto f atTop (𝓝 0) := by let F : E →L[ℝ] Completion E := Completion.toComplL have Fderiv : ∀ x ∈ Ioi a, HasDerivAt (F ∘ f) (F (f' x)) x := fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx) have Fint : IntegrableOn (F ∘ f) (Ioi a) := by apply F.integrable_comp fint have F'int : IntegrableOn (F ∘ f') (Ioi a) := by apply F.integrable_comp f'int have A : Tendsto (F ∘ f) atTop (𝓝 (limUnder atTop (F ∘ f))) := by apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi Fderiv F'int have B : limUnder atTop (F ∘ f) = F 0 := by have : IntegrableAtFilter (F ∘ f) atTop := by exact ⟨Ioi a, Ioi_mem_atTop _, Fint⟩ apply IntegrableAtFilter.eq_zero_of_tendsto this ?_ A intro s hs rcases mem_atTop_sets.1 hs with ⟨b, hb⟩ rw [← top_le_iff, ← volume_Ici (a := b)] exact measure_mono hb rwa [B, ← Embedding.tendsto_nhds_iff] at A exact (Completion.uniformEmbedding_coe E).embedding variable [CompleteSpace E] /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`. When a function has a limit at infinity `m`, and its derivative is integrable, then the integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. Note that such a function always has a limit at infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/ theorem integral_Ioi_of_hasDerivAt_of_tendsto (hcont : ContinuousWithinAt f (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (hf : Tendsto f atTop (𝓝 m)) : ∫ x in Ioi a, f' x = m - f a := by have hcont : ContinuousOn f (Ici a) := by intro x hx rcases hx.out.eq_or_lt with rfl|hx · exact hcont · exact (hderiv x hx).continuousAt.continuousWithinAt refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Ioi a f'int tendsto_id) ?_ apply Tendsto.congr' _ (hf.sub_const _) filter_upwards [Ioi_mem_atTop a] with x hx have h'x : a ≤ id x := le_of_lt hx symm apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x (hcont.mono Icc_subset_Ici_self) fun y hy => hderiv y hy.1 rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x] exact f'int.mono (fun y hy => hy.1) le_rfl #align measure_theory.integral_Ioi_of_has_deriv_at_of_tendsto MeasureTheory.integral_Ioi_of_hasDerivAt_of_tendsto /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`. When a function has a limit at infinity `m`, and its derivative is integrable, then the integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability on `[a, +∞)`. Note that such a function always has a limit at infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/ theorem integral_Ioi_of_hasDerivAt_of_tendsto' (hderiv : ∀ x ∈ Ici a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (hf : Tendsto f atTop (𝓝 m)) : ∫ x in Ioi a, f' x = m - f a := by refine integral_Ioi_of_hasDerivAt_of_tendsto ?_ (fun x hx => hderiv x hx.out.le) f'int hf exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt #align measure_theory.integral_Ioi_of_has_deriv_at_of_tendsto' MeasureTheory.integral_Ioi_of_hasDerivAt_of_tendsto' /-- A special case of `integral_Ioi_of_hasDerivAt_of_tendsto` where we assume that `f` is C^1 with compact support. -/ theorem _root_.HasCompactSupport.integral_Ioi_deriv_eq (hf : ContDiff ℝ 1 f) (h2f : HasCompactSupport f) (b : ℝ) : ∫ x in Ioi b, deriv f x = - f b := by have := fun x (_ : x ∈ Ioi b) ↦ hf.differentiable le_rfl x |>.hasDerivAt rw [integral_Ioi_of_hasDerivAt_of_tendsto hf.continuous.continuousWithinAt this, zero_sub] · refine hf.continuous_deriv le_rfl |>.integrable_of_hasCompactSupport h2f.deriv |>.integrableOn rw [hasCompactSupport_iff_eventuallyEq, Filter.coclosedCompact_eq_cocompact] at h2f exact h2f.filter_mono _root_.atTop_le_cocompact |>.tendsto /-- When a function has a limit at infinity, and its derivative is nonnegative, then the derivative is automatically integrable on `(a, +∞)`. Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. -/ theorem integrableOn_Ioi_deriv_of_nonneg (hcont : ContinuousWithinAt g (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by have hcont : ContinuousOn g (Ici a) := by intro x hx rcases hx.out.eq_or_lt with rfl|hx · exact hcont · exact (hderiv x hx).continuousAt.continuousWithinAt refine integrableOn_Ioi_of_intervalIntegral_norm_tendsto (l - g a) a (fun x => ?_) tendsto_id ?_ · exact intervalIntegral.integrableOn_deriv_of_nonneg (hcont.mono Icc_subset_Ici_self) (fun y hy => hderiv y hy.1) fun y hy => g'pos y hy.1 apply Tendsto.congr' _ (hg.sub_const _) filter_upwards [Ioi_mem_atTop a] with x hx have h'x : a ≤ id x := le_of_lt hx calc g x - g a = ∫ y in a..id x, g' y := by symm apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x (hcont.mono Icc_subset_Ici_self) fun y hy => hderiv y hy.1 rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x] exact intervalIntegral.integrableOn_deriv_of_nonneg (hcont.mono Icc_subset_Ici_self) (fun y hy => hderiv y hy.1) fun y hy => g'pos y hy.1 _ = ∫ y in a..id x, ‖g' y‖ := by simp_rw [intervalIntegral.integral_of_le h'x] refine setIntegral_congr measurableSet_Ioc fun y hy => ?_ dsimp rw [abs_of_nonneg] exact g'pos _ hy.1 #align measure_theory.integrable_on_Ioi_deriv_of_nonneg MeasureTheory.integrableOn_Ioi_deriv_of_nonneg /-- When a function has a limit at infinity, and its derivative is nonnegative, then the derivative is automatically integrable on `(a, +∞)`. Version assuming differentiability on `[a, +∞)`. -/ theorem integrableOn_Ioi_deriv_of_nonneg' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by refine integrableOn_Ioi_deriv_of_nonneg ?_ (fun x hx => hderiv x hx.out.le) g'pos hg exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt #align measure_theory.integrable_on_Ioi_deriv_of_nonneg' MeasureTheory.integrableOn_Ioi_deriv_of_nonneg' /-- When a function has a limit at infinity `l`, and its derivative is nonnegative, then the integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see `integrable_on_Ioi_deriv_of_nonneg`). Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. -/ theorem integral_Ioi_of_hasDerivAt_of_nonneg (hcont : ContinuousWithinAt g (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a := integral_Ioi_of_hasDerivAt_of_tendsto hcont hderiv (integrableOn_Ioi_deriv_of_nonneg hcont hderiv g'pos hg) hg #align measure_theory.integral_Ioi_of_has_deriv_at_of_nonneg MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonneg /-- When a function has a limit at infinity `l`, and its derivative is nonnegative, then the integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see `integrable_on_Ioi_deriv_of_nonneg'`). Version assuming differentiability on `[a, +∞)`. -/ theorem integral_Ioi_of_hasDerivAt_of_nonneg' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a := integral_Ioi_of_hasDerivAt_of_tendsto' hderiv (integrableOn_Ioi_deriv_of_nonneg' hderiv g'pos hg) hg #align measure_theory.integral_Ioi_of_has_deriv_at_of_nonneg' MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonneg' /-- When a function has a limit at infinity, and its derivative is nonpositive, then the derivative is automatically integrable on `(a, +∞)`. Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. -/ theorem integrableOn_Ioi_deriv_of_nonpos (hcont : ContinuousWithinAt g (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by apply integrable_neg_iff.1 exact integrableOn_Ioi_deriv_of_nonneg hcont.neg (fun x hx => (hderiv x hx).neg) (fun x hx => neg_nonneg_of_nonpos (g'neg x hx)) hg.neg #align measure_theory.integrable_on_Ioi_deriv_of_nonpos MeasureTheory.integrableOn_Ioi_deriv_of_nonpos /-- When a function has a limit at infinity, and its derivative is nonpositive, then the derivative is automatically integrable on `(a, +∞)`. Version assuming differentiability on `[a, +∞)`. -/ theorem integrableOn_Ioi_deriv_of_nonpos' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by refine integrableOn_Ioi_deriv_of_nonpos ?_ (fun x hx ↦ hderiv x hx.out.le) g'neg hg exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt #align measure_theory.integrable_on_Ioi_deriv_of_nonpos' MeasureTheory.integrableOn_Ioi_deriv_of_nonpos' /-- When a function has a limit at infinity `l`, and its derivative is nonpositive, then the integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see `integrable_on_Ioi_deriv_of_nonneg`). Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. -/ theorem integral_Ioi_of_hasDerivAt_of_nonpos (hcont : ContinuousWithinAt g (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a := integral_Ioi_of_hasDerivAt_of_tendsto hcont hderiv (integrableOn_Ioi_deriv_of_nonpos hcont hderiv g'neg hg) hg #align measure_theory.integral_Ioi_of_has_deriv_at_of_nonpos MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonpos /-- When a function has a limit at infinity `l`, and its derivative is nonpositive, then the integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see `integrable_on_Ioi_deriv_of_nonneg'`). Version assuming differentiability on `[a, +∞)`. -/ theorem integral_Ioi_of_hasDerivAt_of_nonpos' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a := integral_Ioi_of_hasDerivAt_of_tendsto' hderiv (integrableOn_Ioi_deriv_of_nonpos' hderiv g'neg hg) hg #align measure_theory.integral_Ioi_of_has_deriv_at_of_nonpos' MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonpos' end IoiFTC section IicFTC variable {E : Type*} {f f' : ℝ → E} {g g' : ℝ → ℝ} {a b l : ℝ} {m : E} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- If the derivative of a function defined on the real line is integrable close to `-∞`, then the function has a limit at `-∞`. -/ theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic [CompleteSpace E] (hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) : Tendsto f atBot (𝓝 (limUnder atBot f)) := by suffices ∃ a, Tendsto f atBot (𝓝 a) from tendsto_nhds_limUnder this let g := f ∘ (fun x ↦ -x) have hdg : ∀ x ∈ Ioi (-a), HasDerivAt g (-f' (-x)) x := by intro x hx have : -x ∈ Iic a := by simp only [mem_Iic, mem_Ioi, neg_le] at *; exact hx.le simpa using HasDerivAt.scomp x (hderiv (-x) this) (hasDerivAt_neg' x) have L : Tendsto g atTop (𝓝 (limUnder atTop g)) := by apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi hdg exact ((MeasurePreserving.integrableOn_comp_preimage (Measure.measurePreserving_neg _) (Homeomorph.neg ℝ).measurableEmbedding).2 f'int.neg).mono_set (by simp) refine ⟨limUnder atTop g, ?_⟩ have : Tendsto (fun x ↦ g (-x)) atBot (𝓝 (limUnder atTop g)) := L.comp tendsto_neg_atBot_atTop simpa [g] using this open UniformSpace in /-- If a function and its derivative are integrable on `(-∞, a]`, then the function tends to zero at `-∞`. -/ theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Iic (hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) (fint : IntegrableOn f (Iic a)) : Tendsto f atBot (𝓝 0) := by let F : E →L[ℝ] Completion E := Completion.toComplL have Fderiv : ∀ x ∈ Iic a, HasDerivAt (F ∘ f) (F (f' x)) x := fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx) have Fint : IntegrableOn (F ∘ f) (Iic a) := by apply F.integrable_comp fint have F'int : IntegrableOn (F ∘ f') (Iic a) := by apply F.integrable_comp f'int have A : Tendsto (F ∘ f) atBot (𝓝 (limUnder atBot (F ∘ f))) := by apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic Fderiv F'int have B : limUnder atBot (F ∘ f) = F 0 := by have : IntegrableAtFilter (F ∘ f) atBot := by exact ⟨Iic a, Iic_mem_atBot _, Fint⟩ apply IntegrableAtFilter.eq_zero_of_tendsto this ?_ A intro s hs rcases mem_atBot_sets.1 hs with ⟨b, hb⟩ apply le_antisymm (le_top) rw [← volume_Iic (a := b)] exact measure_mono hb rwa [B, ← Embedding.tendsto_nhds_iff] at A exact (Completion.uniformEmbedding_coe E).embedding variable [CompleteSpace E] /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(-∞, a)`. When a function has a limit `m` at `-∞`, and its derivative is integrable, then the integral of the derivative on `(-∞, a)` is `f a - m`. Version assuming differentiability on `(-∞, a)` and continuity at `a⁻`. Note that such a function always has a limit at minus infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic`. -/ theorem integral_Iic_of_hasDerivAt_of_tendsto (hcont : ContinuousWithinAt f (Iic a) a) (hderiv : ∀ x ∈ Iio a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) (hf : Tendsto f atBot (𝓝 m)) : ∫ x in Iic a, f' x = f a - m := by have hcont : ContinuousOn f (Iic a) := by intro x hx rcases hx.out.eq_or_lt with rfl|hx · exact hcont · exact (hderiv x hx).continuousAt.continuousWithinAt refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Iic a f'int tendsto_id) ?_ apply Tendsto.congr' _ (hf.const_sub _) filter_upwards [Iic_mem_atBot a] with x hx symm apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hx (hcont.mono Icc_subset_Iic_self) fun y hy => hderiv y hy.2 rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hx] exact f'int.mono (fun y hy => hy.2) le_rfl /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(-∞, a)`. When a function has a limit `m` at `-∞`, and its derivative is integrable, then the integral of the derivative on `(-∞, a)` is `f a - m`. Version assuming differentiability on `(-∞, a]`. Note that such a function always has a limit at minus infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic`. -/ theorem integral_Iic_of_hasDerivAt_of_tendsto' (hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) (hf : Tendsto f atBot (𝓝 m)) : ∫ x in Iic a, f' x = f a - m := by refine integral_Iic_of_hasDerivAt_of_tendsto ?_ (fun x hx => hderiv x hx.out.le) f'int hf exact (hderiv a right_mem_Iic).continuousAt.continuousWithinAt /-- A special case of `integral_Iic_of_hasDerivAt_of_tendsto` where we assume that `f` is C^1 with compact support. -/ theorem _root_.HasCompactSupport.integral_Iic_deriv_eq (hf : ContDiff ℝ 1 f) (h2f : HasCompactSupport f) (b : ℝ) : ∫ x in Iic b, deriv f x = f b := by have := fun x (_ : x ∈ Iio b) ↦ hf.differentiable le_rfl x |>.hasDerivAt rw [integral_Iic_of_hasDerivAt_of_tendsto hf.continuous.continuousWithinAt this, sub_zero] · refine hf.continuous_deriv le_rfl |>.integrable_of_hasCompactSupport h2f.deriv |>.integrableOn rw [hasCompactSupport_iff_eventuallyEq, Filter.coclosedCompact_eq_cocompact] at h2f exact h2f.filter_mono _root_.atBot_le_cocompact |>.tendsto end IicFTC section UnivFTC variable {E : Type*} {f f' : ℝ → E} {g g' : ℝ → ℝ} {a b l : ℝ} {m n : E} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- **Fundamental theorem of calculus-2**, on the whole real line When a function has a limit `m` at `-∞` and `n` at `+∞`, and its derivative is integrable, then the integral of the derivative is `n - m`. Note that such a function always has a limit at `-∞` and `+∞`, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic` and `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/ theorem integral_of_hasDerivAt_of_tendsto [CompleteSpace E] (hderiv : ∀ x, HasDerivAt f (f' x) x) (hf' : Integrable f') (hbot : Tendsto f atBot (𝓝 m)) (htop : Tendsto f atTop (𝓝 n)) : ∫ x, f' x = n - m := by rw [← integral_univ, ← Set.Iic_union_Ioi (a := 0), integral_union (Iic_disjoint_Ioi le_rfl) measurableSet_Ioi hf'.integrableOn hf'.integrableOn, integral_Iic_of_hasDerivAt_of_tendsto' (fun x _ ↦ hderiv x) hf'.integrableOn hbot, integral_Ioi_of_hasDerivAt_of_tendsto' (fun x _ ↦ hderiv x) hf'.integrableOn htop] abel /-- If a function and its derivative are integrable on the real line, then the integral of the derivative is zero. -/ theorem integral_eq_zero_of_hasDerivAt_of_integrable (hderiv : ∀ x, HasDerivAt f (f' x) x) (hf' : Integrable f') (hf : Integrable f) : ∫ x, f' x = 0 := by by_cases hE : CompleteSpace E; swap · simp [integral, hE] have A : Tendsto f atBot (𝓝 0) := tendsto_zero_of_hasDerivAt_of_integrableOn_Iic (a := 0) (fun x _hx ↦ hderiv x) hf'.integrableOn hf.integrableOn have B : Tendsto f atTop (𝓝 0) := tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi (a := 0) (fun x _hx ↦ hderiv x) hf'.integrableOn hf.integrableOn simpa using integral_of_hasDerivAt_of_tendsto hderiv hf' A B end UnivFTC section IoiChangeVariables open Real open scoped Interval variable {E : Type*} {f : ℝ → E} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- Change-of-variables formula for `Ioi` integrals of vector-valued functions, proved by taking limits from the result for finite intervals. -/ theorem integral_comp_smul_deriv_Ioi {f f' : ℝ → ℝ} {g : ℝ → E} {a : ℝ} (hf : ContinuousOn f <| Ici a) (hft : Tendsto f atTop atTop) (hff' : ∀ x ∈ Ioi a, HasDerivWithinAt f (f' x) (Ioi x) x) (hg_cont : ContinuousOn g <| f '' Ioi a) (hg1 : IntegrableOn g <| f '' Ici a) (hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) (Ici a)) : (∫ x in Ioi a, f' x • (g ∘ f) x) = ∫ u in Ioi (f a), g u := by have eq : ∀ b : ℝ, a < b → (∫ x in a..b, f' x • (g ∘ f) x) = ∫ u in f a..f b, g u := fun b hb ↦ by have i1 : Ioo (min a b) (max a b) ⊆ Ioi a := by rw [min_eq_left hb.le] exact Ioo_subset_Ioi_self have i2 : [[a, b]] ⊆ Ici a := by rw [uIcc_of_le hb.le]; exact Icc_subset_Ici_self refine intervalIntegral.integral_comp_smul_deriv''' (hf.mono i2) (fun x hx => hff' x <| mem_of_mem_of_subset hx i1) (hg_cont.mono <| image_subset _ ?_) (hg1.mono_set <| image_subset _ ?_) (hg2.mono_set i2) · rw [min_eq_left hb.le]; exact Ioo_subset_Ioi_self · rw [uIcc_of_le hb.le]; exact Icc_subset_Ici_self rw [integrableOn_Ici_iff_integrableOn_Ioi] at hg2 have t2 := intervalIntegral_tendsto_integral_Ioi _ hg2 tendsto_id have : Ioi (f a) ⊆ f '' Ici a := Ioi_subset_Ici_self.trans <| IsPreconnected.intermediate_value_Ici isPreconnected_Ici left_mem_Ici (le_principal_iff.mpr <| Ici_mem_atTop _) hf hft have t1 := (intervalIntegral_tendsto_integral_Ioi _ (hg1.mono_set this) tendsto_id).comp hft exact tendsto_nhds_unique (Tendsto.congr' (eventuallyEq_of_mem (Ioi_mem_atTop a) eq) t2) t1 #align measure_theory.integral_comp_smul_deriv_Ioi MeasureTheory.integral_comp_smul_deriv_Ioi /-- Change-of-variables formula for `Ioi` integrals of scalar-valued functions -/
Mathlib/MeasureTheory/Integral/IntegralEqImproper.lean
1,107
1,114
theorem integral_comp_mul_deriv_Ioi {f f' : ℝ → ℝ} {g : ℝ → ℝ} {a : ℝ} (hf : ContinuousOn f <| Ici a) (hft : Tendsto f atTop atTop) (hff' : ∀ x ∈ Ioi a, HasDerivWithinAt f (f' x) (Ioi x) x) (hg_cont : ContinuousOn g <| f '' Ioi a) (hg1 : IntegrableOn g <| f '' Ici a) (hg2 : IntegrableOn (fun x => (g ∘ f) x * f' x) (Ici a)) : (∫ x in Ioi a, (g ∘ f) x * f' x) = ∫ u in Ioi (f a), g u := by
have hg2' : IntegrableOn (fun x => f' x • (g ∘ f) x) (Ici a) := by simpa [mul_comm] using hg2 simpa [mul_comm] using integral_comp_smul_deriv_Ioi hf hft hff' hg_cont hg1 hg2'
/- 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.AlgebraicGeometry.AffineScheme import Mathlib.AlgebraicGeometry.Pullbacks import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.Data.List.TFAE #align_import algebraic_geometry.morphisms.basic from "leanprover-community/mathlib"@"434e2fd21c1900747afc6d13d8be7f4eedba7218" /-! # Properties of morphisms between Schemes We provide the basic framework for talking about properties of morphisms between Schemes. A `MorphismProperty Scheme` is a predicate on morphisms between schemes, and an `AffineTargetMorphismProperty` is a predicate on morphisms into affine schemes. Given a `P : AffineTargetMorphismProperty`, we may construct a `MorphismProperty` called `targetAffineLocally P` that holds for `f : X ⟶ Y` whenever `P` holds for the restriction of `f` on every affine open subset of `Y`. ## Main definitions - `AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal`: We say that `P.IsLocal` if `P` satisfies the assumptions of the affine communication lemma (`AlgebraicGeometry.of_affine_open_cover`). That is, 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ Y.basicOpen r` for any global section `r`. 3. If `P` holds for `f ∣_ Y.basicOpen r` for all `r` in a spanning set of the global sections, then `P` holds for `f`. - `AlgebraicGeometry.PropertyIsLocalAtTarget`: We say that `PropertyIsLocalAtTarget P` for `P : MorphismProperty Scheme` if 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ U` for any `U`. 3. If `P` holds for `f ∣_ U` for an open cover `U` of `Y`, then `P` holds for `f`. ## Main results - `AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_openCover_TFAE`: If `P.IsLocal`, then `targetAffineLocally P f` iff there exists an affine cover `{ Uᵢ }` of `Y` such that `P` holds for `f ∣_ Uᵢ`. - `AlgebraicGeometry.AffineTargetMorphismProperty.isLocalOfOpenCoverImply`: If the existence of an affine cover `{ Uᵢ }` of `Y` such that `P` holds for `f ∣_ Uᵢ` implies `targetAffineLocally P f`, then `P.IsLocal`. - `AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_target_iff`: If `Y` is affine and `f : X ⟶ Y`, then `targetAffineLocally P f ↔ P f` provided `P.IsLocal`. - `AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.targetAffineLocallyIsLocal` : If `P.IsLocal`, then `PropertyIsLocalAtTarget (targetAffineLocally P)`. - `AlgebraicGeometry.PropertyIsLocalAtTarget.openCover_TFAE`: If `PropertyIsLocalAtTarget P`, then `P f` iff there exists an open cover `{ Uᵢ }` of `Y` such that `P` holds for `f ∣_ Uᵢ`. These results should not be used directly, and should be ported to each property that is local. -/ set_option linter.uppercaseLean3 false universe u open TopologicalSpace CategoryTheory CategoryTheory.Limits Opposite noncomputable section namespace AlgebraicGeometry /-- An `AffineTargetMorphismProperty` is a class of morphisms from an arbitrary scheme into an affine scheme. -/ def AffineTargetMorphismProperty := ∀ ⦃X Y : Scheme⦄ (_ : X ⟶ Y) [IsAffine Y], Prop #align algebraic_geometry.affine_target_morphism_property AlgebraicGeometry.AffineTargetMorphismProperty /-- `IsIso` as a `MorphismProperty`. -/ protected def Scheme.isIso : MorphismProperty Scheme := @IsIso Scheme _ #align algebraic_geometry.Scheme.is_iso AlgebraicGeometry.Scheme.isIso /-- `IsIso` as an `AffineTargetMorphismProperty`. -/ protected def Scheme.affineTargetIsIso : AffineTargetMorphismProperty := fun _ _ f _ => IsIso f #align algebraic_geometry.Scheme.affine_target_is_iso AlgebraicGeometry.Scheme.affineTargetIsIso instance : Inhabited AffineTargetMorphismProperty := ⟨Scheme.affineTargetIsIso⟩ /-- An `AffineTargetMorphismProperty` can be extended to a `MorphismProperty` such that it *never* holds when the target is not affine -/ def AffineTargetMorphismProperty.toProperty (P : AffineTargetMorphismProperty) : MorphismProperty Scheme := fun _ _ f => ∃ h, @P _ _ f h #align algebraic_geometry.affine_target_morphism_property.to_property AlgebraicGeometry.AffineTargetMorphismProperty.toProperty theorem AffineTargetMorphismProperty.toProperty_apply (P : AffineTargetMorphismProperty) {X Y : Scheme} (f : X ⟶ Y) [i : IsAffine Y] : P.toProperty f ↔ P f := by delta AffineTargetMorphismProperty.toProperty; simp [*] #align algebraic_geometry.affine_target_morphism_property.to_property_apply AlgebraicGeometry.AffineTargetMorphismProperty.toProperty_apply theorem affine_cancel_left_isIso {P : AffineTargetMorphismProperty} (hP : P.toProperty.RespectsIso) {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [IsAffine Z] : P (f ≫ g) ↔ P g := by rw [← P.toProperty_apply, ← P.toProperty_apply, hP.cancel_left_isIso] #align algebraic_geometry.affine_cancel_left_is_iso AlgebraicGeometry.affine_cancel_left_isIso theorem affine_cancel_right_isIso {P : AffineTargetMorphismProperty} (hP : P.toProperty.RespectsIso) {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso g] [IsAffine Z] [IsAffine Y] : P (f ≫ g) ↔ P f := by rw [← P.toProperty_apply, ← P.toProperty_apply, hP.cancel_right_isIso] #align algebraic_geometry.affine_cancel_right_is_iso AlgebraicGeometry.affine_cancel_right_isIso theorem AffineTargetMorphismProperty.respectsIso_mk {P : AffineTargetMorphismProperty} (h₁ : ∀ {X Y Z} (e : X ≅ Y) (f : Y ⟶ Z) [IsAffine Z], P f → P (e.hom ≫ f)) (h₂ : ∀ {X Y Z} (e : Y ≅ Z) (f : X ⟶ Y) [h : IsAffine Y], P f → @P _ _ (f ≫ e.hom) (isAffineOfIso e.inv)) : P.toProperty.RespectsIso := by constructor · rintro X Y Z e f ⟨a, h⟩; exact ⟨a, h₁ e f h⟩ · rintro X Y Z e f ⟨a, h⟩; exact ⟨isAffineOfIso e.inv, h₂ e f h⟩ #align algebraic_geometry.affine_target_morphism_property.respects_iso_mk AlgebraicGeometry.AffineTargetMorphismProperty.respectsIso_mk /-- For a `P : AffineTargetMorphismProperty`, `targetAffineLocally P` holds for `f : X ⟶ Y` whenever `P` holds for the restriction of `f` on every affine open subset of `Y`. -/ def targetAffineLocally (P : AffineTargetMorphismProperty) : MorphismProperty Scheme := fun {X Y : Scheme} (f : X ⟶ Y) => ∀ U : Y.affineOpens, @P _ _ (f ∣_ U) U.prop #align algebraic_geometry.target_affine_locally AlgebraicGeometry.targetAffineLocally theorem IsAffineOpen.map_isIso {X Y : Scheme} {U : Opens Y.carrier} (hU : IsAffineOpen U) (f : X ⟶ Y) [IsIso f] : IsAffineOpen ((Opens.map f.1.base).obj U) := haveI : IsAffine _ := hU isAffineOfIso (f ∣_ U) #align algebraic_geometry.is_affine_open.map_is_iso AlgebraicGeometry.IsAffineOpen.map_isIso theorem targetAffineLocally_respectsIso {P : AffineTargetMorphismProperty} (hP : P.toProperty.RespectsIso) : (targetAffineLocally P).RespectsIso := by constructor · introv H U rw [morphismRestrict_comp, affine_cancel_left_isIso hP] exact H U · introv H rintro ⟨U, hU : IsAffineOpen U⟩; dsimp haveI : IsAffine _ := hU.map_isIso e.hom rw [morphismRestrict_comp, affine_cancel_right_isIso hP] exact H ⟨(Opens.map e.hom.val.base).obj U, hU.map_isIso e.hom⟩ #align algebraic_geometry.target_affine_locally_respects_iso AlgebraicGeometry.targetAffineLocally_respectsIso /-- We say that `P : AffineTargetMorphismProperty` is a local property if 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ Y.basicOpen r` for any global section `r`. 3. If `P` holds for `f ∣_ Y.basicOpen r` for all `r` in a spanning set of the global sections, then `P` holds for `f`. -/ structure AffineTargetMorphismProperty.IsLocal (P : AffineTargetMorphismProperty) : Prop where /-- `P` as a morphism property respects isomorphisms -/ RespectsIso : P.toProperty.RespectsIso /-- `P` is stable under restriction to basic open set of global sections. -/ toBasicOpen : ∀ {X Y : Scheme} [IsAffine Y] (f : X ⟶ Y) (r : Y.presheaf.obj <| op ⊤), P f → @P _ _ (f ∣_ Y.basicOpen r) ((topIsAffineOpen Y).basicOpenIsAffine _) /-- `P` for `f` if `P` holds for `f` restricted to basic sets of a spanning set of the global sections -/ ofBasicOpenCover : ∀ {X Y : Scheme} [IsAffine Y] (f : X ⟶ Y) (s : Finset (Y.presheaf.obj <| op ⊤)) (_ : Ideal.span (s : Set (Y.presheaf.obj <| op ⊤)) = ⊤), (∀ r : s, @P _ _ (f ∣_ Y.basicOpen r.1) ((topIsAffineOpen Y).basicOpenIsAffine _)) → P f #align algebraic_geometry.affine_target_morphism_property.is_local AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal /-- Specialization of `ConcreteCategory.id_apply` because `simp` can't see through the defeq. -/ @[local simp] lemma CommRingCat.id_apply (R : CommRingCat) (x : R) : 𝟙 R x = x := rfl theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal) {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)] (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) : targetAffineLocally P f := by classical let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.isOpen_range⟩, rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens) intro U apply of_affine_open_cover (P := _) U (Set.range S) · intro U r h haveI : IsAffine _ := U.2 have := hP.2 (f ∣_ U.1) replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h rw [← P.toProperty_apply] at this ⊢ exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this · intro U s hs H haveI : IsAffine _ := U.2 apply hP.3 (f ∣_ U.1) (s.image (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op)) · apply_fun Ideal.comap (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top.symm).op) at hs rw [Ideal.comap_top] at hs rw [← hs] simp only [eqToHom_op, eqToHom_map, Finset.coe_image] have : ∀ {R S : CommRingCat} (e : S = R) (s : Set S), Ideal.span (eqToHom e '' s) = Ideal.comap (eqToHom e.symm) (Ideal.span s) := by intro _ S e _ subst e simp only [eqToHom_refl, CommRingCat.id_apply, Set.image_id'] -- Porting note: Lean didn't see `𝟙 _` is just ring hom id exact (Ideal.comap_id _).symm apply this · rintro ⟨r, hr⟩ obtain ⟨r, hr', rfl⟩ := Finset.mem_image.mp hr specialize H ⟨r, hr'⟩ rw [← P.toProperty_apply] at H ⊢ exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mpr H · rw [Set.eq_univ_iff_forall] simp only [Set.mem_iUnion] intro x exact ⟨⟨_, ⟨𝒰.f x, rfl⟩⟩, 𝒰.Covers x⟩ · rintro ⟨_, i, rfl⟩ specialize h𝒰 i rw [← P.toProperty_apply] at h𝒰 ⊢ exact (hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)).mpr h𝒰 #align algebraic_geometry.target_affine_locally_of_open_cover AlgebraicGeometry.targetAffineLocallyOfOpenCover open List in theorem AffineTargetMorphismProperty.IsLocal.affine_openCover_TFAE {P : AffineTargetMorphismProperty} (hP : P.IsLocal) {X Y : Scheme.{u}} (f : X ⟶ Y) : TFAE [targetAffineLocally P f, ∃ (𝒰 : Scheme.OpenCover.{u} Y) (_ : ∀ i, IsAffine (𝒰.obj i)), ∀ i : 𝒰.J, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ (𝒰 : Scheme.OpenCover.{u} Y) [∀ i, IsAffine (𝒰.obj i)] (i : 𝒰.J), P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ {U : Scheme} (g : U ⟶ Y) [IsAffine U] [IsOpenImmersion g], P (pullback.snd : pullback f g ⟶ U), ∃ (ι : Type u) (U : ι → Opens Y.carrier) (_ : iSup U = ⊤) (hU' : ∀ i, IsAffineOpen (U i)), ∀ i, @P _ _ (f ∣_ U i) (hU' i)] := by tfae_have 1 → 4 · intro H U g h₁ h₂ replace H := H ⟨⟨_, h₂.base_open.isOpen_range⟩, rangeIsAffineOpenOfOpenImmersion g⟩ rw [← P.toProperty_apply] at H ⊢ rwa [← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] tfae_have 4 → 3 · intro H 𝒰 h𝒰 i apply H tfae_have 3 → 2 · exact fun H => ⟨Y.affineCover, inferInstance, H Y.affineCover⟩ tfae_have 2 → 1 · rintro ⟨𝒰, h𝒰, H⟩; exact targetAffineLocallyOfOpenCover hP f 𝒰 H tfae_have 5 → 2 · rintro ⟨ι, U, hU, hU', H⟩ refine ⟨Y.openCoverOfSuprEqTop U hU, hU', ?_⟩ intro i specialize H i rw [← P.toProperty_apply, ← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] rw [← P.toProperty_apply] at H convert H all_goals ext1; exact Subtype.range_coe tfae_have 1 → 5 · intro H refine ⟨Y.carrier, fun x => (Scheme.Hom.opensRange <| Y.affineCover.map x), ?_, fun i => rangeIsAffineOpenOfOpenImmersion _, ?_⟩ · rw [eq_top_iff]; intro x _; erw [Opens.mem_iSup]; exact ⟨x, Y.affineCover.Covers x⟩ · intro i; exact H ⟨_, rangeIsAffineOpenOfOpenImmersion _⟩ tfae_finish #align algebraic_geometry.affine_target_morphism_property.is_local.affine_open_cover_tfae AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_openCover_TFAE theorem AffineTargetMorphismProperty.isLocalOfOpenCoverImply (P : AffineTargetMorphismProperty) (hP : P.toProperty.RespectsIso) (H : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y), (∃ (𝒰 : Scheme.OpenCover.{u} Y) (_ : ∀ i, IsAffine (𝒰.obj i)), ∀ i : 𝒰.J, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) → ∀ {U : Scheme} (g : U ⟶ Y) [IsAffine U] [IsOpenImmersion g], P (pullback.snd : pullback f g ⟶ U)) : P.IsLocal := by refine ⟨hP, ?_, ?_⟩ · introv h haveI : IsAffine _ := (topIsAffineOpen Y).basicOpenIsAffine r delta morphismRestrict rw [affine_cancel_left_isIso hP] refine @H _ _ f ⟨Scheme.openCoverOfIsIso (𝟙 Y), ?_, ?_⟩ _ (Y.ofRestrict _) _ _ · intro i; dsimp; infer_instance · intro i; dsimp rwa [← Category.comp_id pullback.snd, ← pullback.condition, affine_cancel_left_isIso hP] · introv hs hs' replace hs := ((topIsAffineOpen Y).basicOpen_union_eq_self_iff _).mpr hs have := H f ⟨Y.openCoverOfSuprEqTop _ hs, ?_, ?_⟩ (𝟙 _) · rwa [← Category.comp_id pullback.snd, ← pullback.condition, affine_cancel_left_isIso hP] at this · intro i; exact (topIsAffineOpen Y).basicOpenIsAffine _ · rintro (i : s) specialize hs' i haveI : IsAffine _ := (topIsAffineOpen Y).basicOpenIsAffine i.1 delta morphismRestrict at hs' rwa [affine_cancel_left_isIso hP] at hs' #align algebraic_geometry.affine_target_morphism_property.is_local_of_open_cover_imply AlgebraicGeometry.AffineTargetMorphismProperty.isLocalOfOpenCoverImply theorem AffineTargetMorphismProperty.IsLocal.affine_openCover_iff {P : AffineTargetMorphismProperty} (hP : P.IsLocal) {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y) [h𝒰 : ∀ i, IsAffine (𝒰.obj i)] : targetAffineLocally P f ↔ ∀ i, @P _ _ (pullback.snd : pullback f (𝒰.map i) ⟶ _) (h𝒰 i) := by refine ⟨fun H => let h := ((hP.affine_openCover_TFAE f).out 0 2).mp H; ?_, fun H => let h := ((hP.affine_openCover_TFAE f).out 1 0).mp; ?_⟩ · exact fun i => h 𝒰 i · exact h ⟨𝒰, inferInstance, H⟩ #align algebraic_geometry.affine_target_morphism_property.is_local.affine_open_cover_iff AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_openCover_iff theorem AffineTargetMorphismProperty.IsLocal.affine_target_iff {P : AffineTargetMorphismProperty} (hP : P.IsLocal) {X Y : Scheme.{u}} (f : X ⟶ Y) [IsAffine Y] : targetAffineLocally P f ↔ P f := by haveI : ∀ i, IsAffine (Scheme.OpenCover.obj (Scheme.openCoverOfIsIso (𝟙 Y)) i) := fun i => by dsimp; infer_instance rw [hP.affine_openCover_iff f (Scheme.openCoverOfIsIso (𝟙 Y))] trans P (pullback.snd : pullback f (𝟙 _) ⟶ _) · exact ⟨fun H => H PUnit.unit, fun H _ => H⟩ rw [← Category.comp_id pullback.snd, ← pullback.condition, affine_cancel_left_isIso hP.1] #align algebraic_geometry.affine_target_morphism_property.is_local.affine_target_iff AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_target_iff /-- We say that `P : MorphismProperty Scheme` is local at the target if 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ U` for any `U`. 3. If `P` holds for `f ∣_ U` for an open cover `U` of `Y`, then `P` holds for `f`. -/ structure PropertyIsLocalAtTarget (P : MorphismProperty Scheme) : Prop where /-- `P` respects isomorphisms. -/ RespectsIso : P.RespectsIso /-- If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ U` for any `U`. -/ restrict : ∀ {X Y : Scheme} (f : X ⟶ Y) (U : Opens Y.carrier), P f → P (f ∣_ U) /-- If `P` holds for `f ∣_ U` for an open cover `U` of `Y`, then `P` holds for `f`. -/ of_openCover : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y), (∀ i : 𝒰.J, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) → P f #align algebraic_geometry.property_is_local_at_target AlgebraicGeometry.PropertyIsLocalAtTarget lemma propertyIsLocalAtTarget_of_morphismRestrict (P : MorphismProperty Scheme) (hP₁ : P.RespectsIso) (hP₂ : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Opens Y.carrier), P f → P (f ∣_ U)) (hP₃ : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) {ι : Type u} (U : ι → Opens Y.carrier) (_ : iSup U = ⊤), (∀ i, P (f ∣_ U i)) → P f) : PropertyIsLocalAtTarget P where RespectsIso := hP₁ restrict := hP₂ of_openCover {X Y} f 𝒰 h𝒰 := by apply hP₃ f (fun i : 𝒰.J => Scheme.Hom.opensRange (𝒰.map i)) 𝒰.iSup_opensRange simp_rw [hP₁.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] exact h𝒰 theorem AffineTargetMorphismProperty.IsLocal.targetAffineLocallyIsLocal {P : AffineTargetMorphismProperty} (hP : P.IsLocal) : PropertyIsLocalAtTarget (targetAffineLocally P) := by constructor · exact targetAffineLocally_respectsIso hP.1 · intro X Y f U H V rw [← P.toProperty_apply (i := V.2), hP.1.arrow_mk_iso_iff (morphismRestrictRestrict f _ _)] convert H ⟨_, IsAffineOpen.imageIsOpenImmersion V.2 (Y.ofRestrict _)⟩ rw [← P.toProperty_apply] · rintro X Y f 𝒰 h𝒰 -- Porting note: rewrite `[(hP.affine_openCover_TFAE f).out 0 1` directly complains about -- metavariables have h01 := (hP.affine_openCover_TFAE f).out 0 1 rw [h01] refine ⟨𝒰.bind fun _ => Scheme.affineCover _, ?_, ?_⟩ · intro i; dsimp [Scheme.OpenCover.bind]; infer_instance · intro i specialize h𝒰 i.1 -- Porting note: rewrite `[(hP.affine_openCover_TFAE pullback.snd).out 0 1` directly -- complains about metavariables have h02 := (hP.affine_openCover_TFAE (pullback.snd : pullback f (𝒰.map i.fst) ⟶ _)).out 0 2 rw [h02] at h𝒰 specialize h𝒰 (Scheme.affineCover _) i.2 let e : pullback f ((𝒰.obj i.fst).affineCover.map i.snd ≫ 𝒰.map i.fst) ⟶ pullback (pullback.snd : pullback f (𝒰.map i.fst) ⟶ _) ((𝒰.obj i.fst).affineCover.map i.snd) := by refine (pullbackSymmetry _ _).hom ≫ ?_ refine (pullbackRightPullbackFstIso _ _ _).inv ≫ ?_ refine (pullbackSymmetry _ _).hom ≫ ?_ refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_ <;> simp only [Category.comp_id, Category.id_comp, pullbackSymmetry_hom_comp_snd] rw [← affine_cancel_left_isIso hP.1 e] at h𝒰 convert h𝒰 using 1 simp [e] #align algebraic_geometry.affine_target_morphism_property.is_local.target_affine_locally_is_local AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.targetAffineLocallyIsLocal open List in theorem PropertyIsLocalAtTarget.openCover_TFAE {P : MorphismProperty Scheme} (hP : PropertyIsLocalAtTarget P) {X Y : Scheme.{u}} (f : X ⟶ Y) : TFAE [P f, ∃ 𝒰 : Scheme.OpenCover.{u} Y, ∀ i : 𝒰.J, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ (𝒰 : Scheme.OpenCover.{u} Y) (i : 𝒰.J), P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ U : Opens Y.carrier, P (f ∣_ U), ∀ {U : Scheme} (g : U ⟶ Y) [IsOpenImmersion g], P (pullback.snd : pullback f g ⟶ U), ∃ (ι : Type u) (U : ι → Opens Y.carrier) (_ : iSup U = ⊤), ∀ i, P (f ∣_ U i)] := by tfae_have 2 → 1 · rintro ⟨𝒰, H⟩; exact hP.3 f 𝒰 H tfae_have 1 → 4 · intro H U; exact hP.2 f U H tfae_have 4 → 3 · intro H 𝒰 i rw [← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] exact H <| Scheme.Hom.opensRange (𝒰.map i) tfae_have 3 → 2 · exact fun H => ⟨Y.affineCover, H Y.affineCover⟩ tfae_have 4 → 5 · intro H U g hg rw [← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] apply H tfae_have 5 → 4 · intro H U erw [hP.1.cancel_left_isIso] apply H tfae_have 4 → 6 · intro H; exact ⟨PUnit, fun _ => ⊤, ciSup_const, fun _ => H _⟩ tfae_have 6 → 2 · rintro ⟨ι, U, hU, H⟩ refine ⟨Y.openCoverOfSuprEqTop U hU, ?_⟩ intro i rw [← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] convert H i all_goals ext1; exact Subtype.range_coe tfae_finish #align algebraic_geometry.property_is_local_at_target.open_cover_tfae AlgebraicGeometry.PropertyIsLocalAtTarget.openCover_TFAE theorem PropertyIsLocalAtTarget.openCover_iff {P : MorphismProperty Scheme} (hP : PropertyIsLocalAtTarget P) {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y) : P f ↔ ∀ i, P (pullback.snd : pullback f (𝒰.map i) ⟶ _) := by -- Porting note: couldn't get the term mode proof work refine ⟨fun H => let h := ((hP.openCover_TFAE f).out 0 2).mp H; fun i => ?_, fun H => let h := ((hP.openCover_TFAE f).out 1 0).mp; ?_⟩ · exact h 𝒰 i · exact h ⟨𝒰, H⟩ #align algebraic_geometry.property_is_local_at_target.open_cover_iff AlgebraicGeometry.PropertyIsLocalAtTarget.openCover_iff namespace AffineTargetMorphismProperty /-- A `P : AffineTargetMorphismProperty` is stable under base change if `P` holds for `Y ⟶ S` implies that `P` holds for `X ×ₛ Y ⟶ X` with `X` and `S` affine schemes. -/ def StableUnderBaseChange (P : AffineTargetMorphismProperty) : Prop := ∀ ⦃X Y S : Scheme⦄ [IsAffine S] [IsAffine X] (f : X ⟶ S) (g : Y ⟶ S), P g → P (pullback.fst : pullback f g ⟶ X) #align algebraic_geometry.affine_target_morphism_property.stable_under_base_change AlgebraicGeometry.AffineTargetMorphismProperty.StableUnderBaseChange theorem IsLocal.targetAffineLocallyPullbackFstOfRightOfStableUnderBaseChange {P : AffineTargetMorphismProperty} (hP : P.IsLocal) (hP' : P.StableUnderBaseChange) {X Y S : Scheme} (f : X ⟶ S) (g : Y ⟶ S) [IsAffine S] (H : P g) : targetAffineLocally P (pullback.fst : pullback f g ⟶ X) := by -- Porting note: rewrite `(hP.affine_openCover_TFAE ...).out 0 1` doesn't work have h01 := (hP.affine_openCover_TFAE (pullback.fst : pullback f g ⟶ X)).out 0 1 rw [h01] use X.affineCover, inferInstance intro i let e := pullbackSymmetry _ _ ≪≫ pullbackRightPullbackFstIso f g (X.affineCover.map i) have : e.hom ≫ pullback.fst = pullback.snd := by simp [e] rw [← this, affine_cancel_left_isIso hP.1] apply hP'; assumption #align algebraic_geometry.affine_target_morphism_property.is_local.target_affine_locally_pullback_fst_of_right_of_stable_under_base_change AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.targetAffineLocallyPullbackFstOfRightOfStableUnderBaseChange theorem IsLocal.stableUnderBaseChange {P : AffineTargetMorphismProperty} (hP : P.IsLocal) (hP' : P.StableUnderBaseChange) : (targetAffineLocally P).StableUnderBaseChange := MorphismProperty.StableUnderBaseChange.mk (targetAffineLocally_respectsIso hP.RespectsIso) (fun X Y S f g H => by -- Porting note: rewrite `(...openCover_TFAE).out 0 1` directly doesn't work, complains about -- metavariable have h01 := (hP.targetAffineLocallyIsLocal.openCover_TFAE (pullback.fst : pullback f g ⟶ X)).out 0 1 rw [h01] use S.affineCover.pullbackCover f intro i -- Porting note: rewrite `(hP.affine_openCover_TFAE g).out 0 3` directly doesn't work -- complains about metavariable have h03 := (hP.affine_openCover_TFAE g).out 0 3 rw [h03] at H let e : pullback (pullback.fst : pullback f g ⟶ _) ((S.affineCover.pullbackCover f).map i) ≅ _ := by refine pullbackSymmetry _ _ ≪≫ pullbackRightPullbackFstIso f g _ ≪≫ ?_ ≪≫ (pullbackRightPullbackFstIso (S.affineCover.map i) g (pullback.snd : pullback f (S.affineCover.map i) ⟶ _)).symm exact asIso (pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simpa using pullback.condition) (by simp)) have : e.hom ≫ pullback.fst = pullback.snd := by simp [e] rw [← this, (targetAffineLocally_respectsIso hP.1).cancel_left_isIso] apply hP.targetAffineLocallyPullbackFstOfRightOfStableUnderBaseChange hP' rw [← pullbackSymmetry_hom_comp_snd, affine_cancel_left_isIso hP.1] apply H) #align algebraic_geometry.affine_target_morphism_property.is_local.stable_under_base_change AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.stableUnderBaseChange end AffineTargetMorphismProperty /-- The `AffineTargetMorphismProperty` associated to `(targetAffineLocally P).diagonal`. See `diagonal_targetAffineLocally_eq_targetAffineLocally`. -/ def AffineTargetMorphismProperty.diagonal (P : AffineTargetMorphismProperty) : AffineTargetMorphismProperty := fun {X _} f _ => ∀ {U₁ U₂ : Scheme} (f₁ : U₁ ⟶ X) (f₂ : U₂ ⟶ X) [IsAffine U₁] [IsAffine U₂] [IsOpenImmersion f₁] [IsOpenImmersion f₂], P (pullback.mapDesc f₁ f₂ f) #align algebraic_geometry.affine_target_morphism_property.diagonal AlgebraicGeometry.AffineTargetMorphismProperty.diagonal theorem AffineTargetMorphismProperty.diagonal_respectsIso (P : AffineTargetMorphismProperty) (hP : P.toProperty.RespectsIso) : P.diagonal.toProperty.RespectsIso := by delta AffineTargetMorphismProperty.diagonal apply AffineTargetMorphismProperty.respectsIso_mk · introv H _ _ rw [pullback.mapDesc_comp, affine_cancel_left_isIso hP, affine_cancel_right_isIso hP] -- Porting note: add the following two instances have i1 : IsOpenImmersion (f₁ ≫ e.hom) := PresheafedSpace.IsOpenImmersion.comp _ _ have i2 : IsOpenImmersion (f₂ ≫ e.hom) := PresheafedSpace.IsOpenImmersion.comp _ _ apply H · introv H _ _ -- Porting note: add the following two instances have _ : IsAffine Z := isAffineOfIso e.inv rw [pullback.mapDesc_comp, affine_cancel_right_isIso hP] apply H #align algebraic_geometry.affine_target_morphism_property.diagonal_respects_iso AlgebraicGeometry.AffineTargetMorphismProperty.diagonal_respectsIso theorem diagonalTargetAffineLocallyOfOpenCover (P : AffineTargetMorphismProperty) (hP : P.IsLocal) {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y) [∀ i, IsAffine (𝒰.obj i)] (𝒰' : ∀ i, Scheme.OpenCover.{u} (pullback f (𝒰.map i))) [∀ i j, IsAffine ((𝒰' i).obj j)] (h𝒰' : ∀ i j k, P (pullback.mapDesc ((𝒰' i).map j) ((𝒰' i).map k) pullback.snd)) : (targetAffineLocally P).diagonal f := by let 𝒱 := (Scheme.Pullback.openCoverOfBase 𝒰 f f).bind fun i => Scheme.Pullback.openCoverOfLeftRight.{u} (𝒰' i) (𝒰' i) pullback.snd pullback.snd have i1 : ∀ i, IsAffine (𝒱.obj i) := fun i => by dsimp [𝒱]; infer_instance apply (hP.affine_openCover_iff _ 𝒱).mpr rintro ⟨i, j, k⟩ dsimp [𝒱] convert (affine_cancel_left_isIso hP.1 (pullbackDiagonalMapIso _ _ ((𝒰' i).map j) ((𝒰' i).map k)).inv pullback.snd).mp _ pick_goal 3 · convert h𝒰' i j k; apply pullback.hom_ext <;> simp all_goals apply pullback.hom_ext <;> simp only [Category.assoc, pullback.lift_fst, pullback.lift_snd, pullback.lift_fst_assoc, pullback.lift_snd_assoc] #align algebraic_geometry.diagonal_target_affine_locally_of_open_cover AlgebraicGeometry.diagonalTargetAffineLocallyOfOpenCover theorem AffineTargetMorphismProperty.diagonalOfTargetAffineLocally (P : AffineTargetMorphismProperty) (hP : P.IsLocal) {X Y U : Scheme.{u}} (f : X ⟶ Y) (g : U ⟶ Y) [IsAffine U] [IsOpenImmersion g] (H : (targetAffineLocally P).diagonal f) : P.diagonal (pullback.snd : pullback f g ⟶ _) := by rintro U V f₁ f₂ hU hV hf₁ hf₂ replace H := ((hP.affine_openCover_TFAE (pullback.diagonal f)).out 0 3).mp H let g₁ := pullback.map (f₁ ≫ pullback.snd) (f₂ ≫ pullback.snd) f f (f₁ ≫ pullback.fst) (f₂ ≫ pullback.fst) g (by rw [Category.assoc, Category.assoc, pullback.condition]) (by rw [Category.assoc, Category.assoc, pullback.condition]) specialize H g₁ rw [← affine_cancel_left_isIso hP.1 (pullbackDiagonalMapIso f _ f₁ f₂).hom] convert H apply pullback.hom_ext <;> simp only [Category.assoc, pullback.lift_fst, pullback.lift_snd, pullback.lift_fst_assoc, pullback.lift_snd_assoc, Category.comp_id, pullbackDiagonalMapIso_hom_fst, pullbackDiagonalMapIso_hom_snd] #align algebraic_geometry.affine_target_morphism_property.diagonal_of_target_affine_locally AlgebraicGeometry.AffineTargetMorphismProperty.diagonalOfTargetAffineLocally open List in theorem AffineTargetMorphismProperty.IsLocal.diagonal_affine_openCover_TFAE {P : AffineTargetMorphismProperty} (hP : P.IsLocal) {X Y : Scheme.{u}} (f : X ⟶ Y) : TFAE [(targetAffineLocally P).diagonal f, ∃ (𝒰 : Scheme.OpenCover.{u} Y) (_ : ∀ i, IsAffine (𝒰.obj i)), ∀ i : 𝒰.J, P.diagonal (pullback.snd : pullback f (𝒰.map i) ⟶ _), ∀ (𝒰 : Scheme.OpenCover.{u} Y) [∀ i, IsAffine (𝒰.obj i)] (i : 𝒰.J), P.diagonal (pullback.snd : pullback f (𝒰.map i) ⟶ _), ∀ {U : Scheme} (g : U ⟶ Y) [IsAffine U] [IsOpenImmersion g], P.diagonal (pullback.snd : pullback f g ⟶ _), ∃ (𝒰 : Scheme.OpenCover.{u} Y) (_ : ∀ i, IsAffine (𝒰.obj i)) (𝒰' : ∀ i, Scheme.OpenCover.{u} (pullback f (𝒰.map i))) (_ : ∀ i j, IsAffine ((𝒰' i).obj j)), ∀ i j k, P (pullback.mapDesc ((𝒰' i).map j) ((𝒰' i).map k) pullback.snd)] := by tfae_have 1 → 4 · introv H hU hg _ _; apply P.diagonalOfTargetAffineLocally <;> assumption tfae_have 4 → 3 · introv H h𝒰; apply H tfae_have 3 → 2 · exact fun H => ⟨Y.affineCover, inferInstance, H Y.affineCover⟩ tfae_have 2 → 5 · rintro ⟨𝒰, h𝒰, H⟩ refine ⟨𝒰, inferInstance, fun _ => Scheme.affineCover _, inferInstance, ?_⟩ intro i j k apply H tfae_have 5 → 1 · rintro ⟨𝒰, _, 𝒰', _, H⟩ exact diagonalTargetAffineLocallyOfOpenCover P hP f 𝒰 𝒰' H tfae_finish #align algebraic_geometry.affine_target_morphism_property.is_local.diagonal_affine_open_cover_tfae AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.diagonal_affine_openCover_TFAE theorem AffineTargetMorphismProperty.IsLocal.diagonal {P : AffineTargetMorphismProperty} (hP : P.IsLocal) : P.diagonal.IsLocal := AffineTargetMorphismProperty.isLocalOfOpenCoverImply P.diagonal (P.diagonal_respectsIso hP.1) fun {_ _} f => ((hP.diagonal_affine_openCover_TFAE f).out 1 3).mp #align algebraic_geometry.affine_target_morphism_property.is_local.diagonal AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.diagonal theorem diagonal_targetAffineLocally_eq_targetAffineLocally (P : AffineTargetMorphismProperty) (hP : P.IsLocal) : (targetAffineLocally P).diagonal = targetAffineLocally P.diagonal := by ext _ _ f exact ((hP.diagonal_affine_openCover_TFAE f).out 0 1).trans ((hP.diagonal.affine_openCover_TFAE f).out 1 0) #align algebraic_geometry.diagonal_target_affine_locally_eq_target_affine_locally AlgebraicGeometry.diagonal_targetAffineLocally_eq_targetAffineLocally
Mathlib/AlgebraicGeometry/Morphisms/Basic.lean
590
605
theorem universallyIsLocalAtTarget (P : MorphismProperty Scheme) (hP : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y), (∀ i : 𝒰.J, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) → P f) : PropertyIsLocalAtTarget P.universally := by
refine ⟨P.universally_respectsIso, fun {X Y} f U => P.universally_stableUnderBaseChange (isPullback_morphismRestrict f U).flip, ?_⟩ intro X Y f 𝒰 h X' Y' i₁ i₂ f' H apply hP _ (𝒰.pullbackCover i₂) intro i dsimp apply h i (pullback.lift (pullback.fst ≫ i₁) (pullback.snd ≫ pullback.snd) _) pullback.snd swap · rw [Category.assoc, Category.assoc, ← pullback.condition, ← pullback.condition_assoc, H.w] refine (IsPullback.of_right ?_ (pullback.lift_snd _ _ _) (IsPullback.of_hasPullback _ _)).flip rw [pullback.lift_fst, ← pullback.condition] exact (IsPullback.of_hasPullback _ _).paste_horiz H.flip
/- 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.Topology.Compactness.SigmaCompact import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.Inseparable #align_import topology.separation from "leanprover-community/mathlib"@"d91e7f7a7f1c7e9f0e18fdb6bde4f652004c735d" /-! # Separation properties of topological spaces. This file defines the predicate `SeparatedNhds`, and common separation axioms (under the Kolmogorov classification). ## Main definitions * `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint open sets. * `T0Space`: A T₀/Kolmogorov space is a space where, for every two points `x ≠ y`, there is an open set that contains one, but not the other. * `R0Space`: An R₀ space (sometimes called a *symmetric space*) is a topological space such that the `Specializes` relation is symmetric. * `T1Space`: A T₁/Fréchet space is a space where every singleton set is closed. This is equivalent to, for every pair `x ≠ y`, there existing an open set containing `x` but not `y` (`t1Space_iff_exists_open` shows that these conditions are equivalent.) T₁ implies T₀ and R₀. * `R1Space`: An R₁/preregular space is a space where any two topologically distinguishable points have disjoint neighbourhoods. R₁ implies R₀. * `T2Space`: A T₂/Hausdorff space is a space where, for every two points `x ≠ y`, there is two disjoint open sets, one containing `x`, and the other `y`. T₂ implies T₁ and R₁. * `T25Space`: A T₂.₅/Urysohn space is a space where, for every two points `x ≠ y`, there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint. T₂.₅ implies T₂. * `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`, there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily Hausdorff. * `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅. * `NormalSpace`: A normal space, is one where given two disjoint closed sets, we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if it is T₀. * `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃. * `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows us to conclude that this is equivalent to all subspaces being normal. Such a space is not necessarily Hausdorff or regular, even if it is T₀. * `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. ## Main results ### T₀ spaces * `IsClosed.exists_closed_singleton`: Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. * `exists_isOpen_singleton_of_isOpen_finite`: Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. ### T₁ spaces * `isClosedMap_const`: The constant map is a closed map. * `discrete_of_t1_of_finite`: A finite T₁ space must have the discrete topology. ### T₂ spaces * `t2_iff_nhds`: A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. * `t2_iff_isClosed_diagonal`: A space is T₂ iff the `diagonal` of `X` (that is, the set of all points of the form `(a, a) : X × X`) is closed under the product topology. * `separatedNhds_of_finset_finset`: Any two disjoint finsets are `SeparatedNhds`. * Most topological constructions preserve Hausdorffness; these results are part of the typeclass inference system (e.g. `Embedding.t2Space`) * `Set.EqOn.closure`: If two functions are equal on some set `s`, they are equal on its closure. * `IsCompact.isClosed`: All compact sets are closed. * `WeaklyLocallyCompactSpace.locallyCompactSpace`: If a topological space is both weakly locally compact (i.e., each point has a compact neighbourhood) and is T₂, then it is locally compact. * `totallySeparatedSpace_of_t1_of_basis_clopen`: If `X` has a clopen basis, then it is a `TotallySeparatedSpace`. * `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T₂ space is totally disconnected iff it is totally separated. * `t2Quotient`: the largest T2 quotient of a given topological space. If the space is also compact: * `normalOfCompactT2`: A compact T₂ space is a `NormalSpace`. * `connectedComponent_eq_iInter_isClopen`: The connected component of a point is the intersection of all its clopen neighbourhoods. * `compact_t2_tot_disc_iff_tot_sep`: Being a `TotallyDisconnectedSpace` is equivalent to being a `TotallySeparatedSpace`. * `ConnectedComponents.t2`: `ConnectedComponents X` is T₂ for `X` T₂ and compact. ### T₃ spaces * `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. ## References https://en.wikipedia.org/wiki/Separation_axiom -/ open Function Set Filter Topology TopologicalSpace open scoped Classical universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section Separation /-- `SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two sub`Set`s are contained in disjoint open sets. -/ def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X => ∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V #align separated_nhds SeparatedNhds theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align separated_nhds_iff_disjoint separatedNhds_iff_disjoint alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint namespace SeparatedNhds variable {s s₁ s₂ t t₁ t₂ u : Set X} @[symm] theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ => ⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩ #align separated_nhds.symm SeparatedNhds.symm theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s := ⟨symm, symm⟩ #align separated_nhds.comm SeparatedNhds.comm theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t) (hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) := let ⟨U, V, oU, oV, sU, tV, UV⟩ := h ⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV, UV.preimage f⟩ #align separated_nhds.preimage SeparatedNhds.preimage protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t := let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV #align separated_nhds.disjoint SeparatedNhds.disjoint theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t := let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h (hd.closure_left hV).mono (closure_mono hsU) htV #align separated_nhds.disjoint_closure_left SeparatedNhds.disjoint_closure_left theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) := h.symm.disjoint_closure_left.symm #align separated_nhds.disjoint_closure_right SeparatedNhds.disjoint_closure_right @[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ := ⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩ #align separated_nhds.empty_right SeparatedNhds.empty_right @[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s := (empty_right _).symm #align separated_nhds.empty_left SeparatedNhds.empty_left theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ := let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h ⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩ #align separated_nhds.mono SeparatedNhds.mono theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro #align separated_nhds.union_left SeparatedNhds.union_left theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) := (ht.symm.union_left hu.symm).symm #align separated_nhds.union_right SeparatedNhds.union_right end SeparatedNhds /-- A T₀ space, also known as a Kolmogorov space, is a topological space such that for every pair `x ≠ y`, there is an open set containing one but not the other. We formulate the definition in terms of the `Inseparable` relation. -/ class T0Space (X : Type u) [TopologicalSpace X] : Prop where /-- Two inseparable points in a T₀ space are equal. -/ t0 : ∀ ⦃x y : X⦄, Inseparable x y → x = y #align t0_space T0Space theorem t0Space_iff_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ ∀ x y : X, Inseparable x y → x = y := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align t0_space_iff_inseparable t0Space_iff_inseparable theorem t0Space_iff_not_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y : X => ¬Inseparable x y := by simp only [t0Space_iff_inseparable, Ne, not_imp_not, Pairwise] #align t0_space_iff_not_inseparable t0Space_iff_not_inseparable theorem Inseparable.eq [T0Space X] {x y : X} (h : Inseparable x y) : x = y := T0Space.t0 h #align inseparable.eq Inseparable.eq /-- A topology `Inducing` map from a T₀ space is injective. -/ protected theorem Inducing.injective [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Injective f := fun _ _ h => (hf.inseparable_iff.1 <| .of_eq h).eq #align inducing.injective Inducing.injective /-- A topology `Inducing` map from a T₀ space is a topological embedding. -/ protected theorem Inducing.embedding [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Embedding f := ⟨hf, hf.injective⟩ #align inducing.embedding Inducing.embedding lemma embedding_iff_inducing [TopologicalSpace Y] [T0Space X] {f : X → Y} : Embedding f ↔ Inducing f := ⟨Embedding.toInducing, Inducing.embedding⟩ #align embedding_iff_inducing embedding_iff_inducing theorem t0Space_iff_nhds_injective (X : Type u) [TopologicalSpace X] : T0Space X ↔ Injective (𝓝 : X → Filter X) := t0Space_iff_inseparable X #align t0_space_iff_nhds_injective t0Space_iff_nhds_injective theorem nhds_injective [T0Space X] : Injective (𝓝 : X → Filter X) := (t0Space_iff_nhds_injective X).1 ‹_› #align nhds_injective nhds_injective theorem inseparable_iff_eq [T0Space X] {x y : X} : Inseparable x y ↔ x = y := nhds_injective.eq_iff #align inseparable_iff_eq inseparable_iff_eq @[simp] theorem nhds_eq_nhds_iff [T0Space X] {a b : X} : 𝓝 a = 𝓝 b ↔ a = b := nhds_injective.eq_iff #align nhds_eq_nhds_iff nhds_eq_nhds_iff @[simp] theorem inseparable_eq_eq [T0Space X] : Inseparable = @Eq X := funext₂ fun _ _ => propext inseparable_iff_eq #align inseparable_eq_eq inseparable_eq_eq theorem TopologicalSpace.IsTopologicalBasis.inseparable_iff {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : Inseparable x y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := ⟨fun h s hs ↦ inseparable_iff_forall_open.1 h _ (hb.isOpen hs), fun h ↦ hb.nhds_hasBasis.eq_of_same_basis <| by convert hb.nhds_hasBasis using 2 exact and_congr_right (h _)⟩ theorem TopologicalSpace.IsTopologicalBasis.eq_iff [T0Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : x = y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := inseparable_iff_eq.symm.trans hb.inseparable_iff theorem t0Space_iff_exists_isOpen_xor'_mem (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := by simp only [t0Space_iff_not_inseparable, xor_iff_not_iff, not_forall, exists_prop, inseparable_iff_forall_open, Pairwise] #align t0_space_iff_exists_is_open_xor_mem t0Space_iff_exists_isOpen_xor'_mem theorem exists_isOpen_xor'_mem [T0Space X] {x y : X} (h : x ≠ y) : ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := (t0Space_iff_exists_isOpen_xor'_mem X).1 ‹_› h #align exists_is_open_xor_mem exists_isOpen_xor'_mem /-- Specialization forms a partial order on a t0 topological space. -/ def specializationOrder (X) [TopologicalSpace X] [T0Space X] : PartialOrder X := { specializationPreorder X, PartialOrder.lift (OrderDual.toDual ∘ 𝓝) nhds_injective with } #align specialization_order specializationOrder instance SeparationQuotient.instT0Space : T0Space (SeparationQuotient X) := ⟨fun x y => Quotient.inductionOn₂' x y fun _ _ h => SeparationQuotient.mk_eq_mk.2 <| SeparationQuotient.inducing_mk.inseparable_iff.1 h⟩ theorem minimal_nonempty_closed_subsingleton [T0Space X] {s : Set X} (hs : IsClosed s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · refine this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s \ U = s := hmin (s \ U) diff_subset ⟨y, hy, hyU⟩ (hs.sdiff hUo) exact (this.symm.subset hx).2 hxU #align minimal_nonempty_closed_subsingleton minimal_nonempty_closed_subsingleton theorem minimal_nonempty_closed_eq_singleton [T0Space X] {s : Set X} (hs : IsClosed s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_closed_subsingleton hs hmin⟩ #align minimal_nonempty_closed_eq_singleton minimal_nonempty_closed_eq_singleton /-- Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. -/ theorem IsClosed.exists_closed_singleton [T0Space X] [CompactSpace X] {S : Set X} (hS : IsClosed S) (hne : S.Nonempty) : ∃ x : X, x ∈ S ∧ IsClosed ({x} : Set X) := by obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne rcases minimal_nonempty_closed_eq_singleton Vcls Vne hV with ⟨x, rfl⟩ exact ⟨x, Vsub (mem_singleton x), Vcls⟩ #align is_closed.exists_closed_singleton IsClosed.exists_closed_singleton theorem minimal_nonempty_open_subsingleton [T0Space X] {s : Set X} (hs : IsOpen s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · exact this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s ∩ U = s := hmin (s ∩ U) inter_subset_left ⟨x, hx, hxU⟩ (hs.inter hUo) exact hyU (this.symm.subset hy).2 #align minimal_nonempty_open_subsingleton minimal_nonempty_open_subsingleton theorem minimal_nonempty_open_eq_singleton [T0Space X] {s : Set X} (hs : IsOpen s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_open_subsingleton hs hmin⟩ #align minimal_nonempty_open_eq_singleton minimal_nonempty_open_eq_singleton /-- Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. -/
Mathlib/Topology/Separation.lean
326
340
theorem exists_isOpen_singleton_of_isOpen_finite [T0Space X] {s : Set X} (hfin : s.Finite) (hne : s.Nonempty) (ho : IsOpen s) : ∃ x ∈ s, IsOpen ({x} : Set X) := by
lift s to Finset X using hfin induction' s using Finset.strongInductionOn with s ihs rcases em (∃ t, t ⊂ s ∧ t.Nonempty ∧ IsOpen (t : Set X)) with (⟨t, hts, htne, hto⟩ | ht) · rcases ihs t hts htne hto with ⟨x, hxt, hxo⟩ exact ⟨x, hts.1 hxt, hxo⟩ · -- Porting note: was `rcases minimal_nonempty_open_eq_singleton ho hne _ with ⟨x, hx⟩` -- https://github.com/leanprover/std4/issues/116 rsuffices ⟨x, hx⟩ : ∃ x, s.toSet = {x} · exact ⟨x, hx.symm ▸ rfl, hx ▸ ho⟩ refine minimal_nonempty_open_eq_singleton ho hne ?_ refine fun t hts htne hto => of_not_not fun hts' => ht ?_ lift t to Finset X using s.finite_toSet.subset hts exact ⟨t, ssubset_iff_subset_ne.2 ⟨hts, mt Finset.coe_inj.2 hts'⟩, htne, hto⟩
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Mario Carneiro -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds #align_import data.real.pi.bounds from "leanprover-community/mathlib"@"402f8982dddc1864bd703da2d6e2ee304a866973" /-! # Pi This file contains lemmas which establish bounds on `real.pi`. Notably, these include `pi_gt_sqrtTwoAddSeries` and `pi_lt_sqrtTwoAddSeries`, which bound `π` using series; numerical bounds on `π` such as `pi_gt_314`and `pi_lt_315` (more precise versions are given, too). See also `Mathlib/Data/Real/Pi/Leibniz.lean` and `Mathlib/Data/Real/Pi/Wallis.lean` for infinite formulas for `π`. -/ -- Porting note: needed to add a lot of type ascriptions for lean to interpret numbers as reals. open scoped Real namespace Real theorem pi_gt_sqrtTwoAddSeries (n : ℕ) : (2 : ℝ) ^ (n + 1) * √(2 - sqrtTwoAddSeries 0 n) < π := by have : √(2 - sqrtTwoAddSeries 0 n) / (2 : ℝ) * (2 : ℝ) ^ (n + 2) < π := by rw [← lt_div_iff, ← sin_pi_over_two_pow_succ] focus apply sin_lt apply div_pos pi_pos all_goals apply pow_pos; norm_num apply lt_of_le_of_lt (le_of_eq _) this rw [pow_succ' _ (n + 1), ← mul_assoc, div_mul_cancel₀, mul_comm]; norm_num #align real.pi_gt_sqrt_two_add_series Real.pi_gt_sqrtTwoAddSeries theorem pi_lt_sqrtTwoAddSeries (n : ℕ) : π < (2 : ℝ) ^ (n + 1) * √(2 - sqrtTwoAddSeries 0 n) + 1 / (4 : ℝ) ^ n := by have : π < (√(2 - sqrtTwoAddSeries 0 n) / (2 : ℝ) + (1 : ℝ) / ((2 : ℝ) ^ n) ^ 3 / 4) * (2 : ℝ) ^ (n + 2) := by rw [← div_lt_iff (by norm_num), ← sin_pi_over_two_pow_succ] refine lt_of_lt_of_le (lt_add_of_sub_right_lt (sin_gt_sub_cube ?_ ?_)) ?_ · apply div_pos pi_pos; apply pow_pos; norm_num · rw [div_le_iff'] · refine le_trans pi_le_four ?_ simp only [show (4 : ℝ) = (2 : ℝ) ^ 2 by norm_num, mul_one] apply pow_le_pow_right (by norm_num) apply le_add_of_nonneg_left; apply Nat.zero_le · apply pow_pos; norm_num apply add_le_add_left; rw [div_le_div_right (by norm_num)] rw [le_div_iff (by norm_num), ← mul_pow] refine le_trans ?_ (le_of_eq (one_pow 3)); apply pow_le_pow_left · apply le_of_lt; apply mul_pos · apply div_pos pi_pos; apply pow_pos; norm_num · apply pow_pos; norm_num · rw [← le_div_iff (by norm_num)] refine le_trans ((div_le_div_right ?_).mpr pi_le_four) ?_ · apply pow_pos; norm_num · simp only [pow_succ', ← div_div, one_div] -- Porting note: removed `convert le_rfl` norm_num apply lt_of_lt_of_le this (le_of_eq _); rw [add_mul]; congr 1 · ring simp only [show (4 : ℝ) = 2 ^ 2 by norm_num, ← pow_mul, div_div, ← pow_add] rw [one_div, one_div, inv_mul_eq_iff_eq_mul₀, eq_comm, mul_inv_eq_iff_eq_mul₀, ← pow_add] · rw [add_assoc, Nat.mul_succ, add_comm, add_comm n, add_assoc, mul_comm n] all_goals norm_num #align real.pi_lt_sqrt_two_add_series Real.pi_lt_sqrtTwoAddSeries /-- From an upper bound on `sqrtTwoAddSeries 0 n = 2 cos (π / 2 ^ (n+1))` of the form `sqrtTwoAddSeries 0 n ≤ 2 - (a / 2 ^ (n + 1)) ^ 2)`, one can deduce the lower bound `a < π` thanks to basic trigonometric inequalities as expressed in `pi_gt_sqrtTwoAddSeries`. -/ theorem pi_lower_bound_start (n : ℕ) {a} (h : sqrtTwoAddSeries ((0 : ℕ) / (1 : ℕ)) n ≤ (2 : ℝ) - (a / (2 : ℝ) ^ (n + 1)) ^ 2) : a < π := by refine lt_of_le_of_lt ?_ (pi_gt_sqrtTwoAddSeries n); rw [mul_comm] refine (div_le_iff (pow_pos (by norm_num) _ : (0 : ℝ) < _)).mp (le_sqrt_of_sq_le ?_) rwa [le_sub_comm, show (0 : ℝ) = (0 : ℕ) / (1 : ℕ) by rw [Nat.cast_zero, zero_div]] #align real.pi_lower_bound_start Real.pi_lower_bound_start theorem sqrtTwoAddSeries_step_up (c d : ℕ) {a b n : ℕ} {z : ℝ} (hz : sqrtTwoAddSeries (c / d) n ≤ z) (hb : 0 < b) (hd : 0 < d) (h : (2 * b + a) * d ^ 2 ≤ c ^ 2 * b) : sqrtTwoAddSeries (a / b) (n + 1) ≤ z := by refine le_trans ?_ hz; rw [sqrtTwoAddSeries_succ]; apply sqrtTwoAddSeries_monotone_left have hb' : 0 < (b : ℝ) := Nat.cast_pos.2 hb have hd' : 0 < (d : ℝ) := Nat.cast_pos.2 hd rw [sqrt_le_left (div_nonneg c.cast_nonneg d.cast_nonneg), div_pow, add_div_eq_mul_add_div _ _ (ne_of_gt hb'), div_le_div_iff hb' (pow_pos hd' _)] exact mod_cast h #align real.sqrt_two_add_series_step_up Real.sqrtTwoAddSeries_step_up section Tactic open Lean Elab Tactic /-- `numDen stx` takes a syntax expression `stx` and * if it is of the form `a / b`, then it returns `some (a, b)`; * otherwise it returns `none`. -/ private def numDen : Syntax → Option (Syntax.Term × Syntax.Term) | `($a / $b) => some (a, b) | _ => none /-- Create a proof of `a < π` for a fixed rational number `a`, given a witness, which is a sequence of rational numbers `√2 < r 1 < r 2 < ... < r n < 2` satisfying the property that `√(2 + r i) ≤ r(i+1)`, where `r 0 = 0` and `√(2 - r n) ≥ a/2^(n+1)`. -/ elab "pi_lower_bound " "[" l:term,* "]" : tactic => do let rat_sep := l.elemsAndSeps let sep := rat_sep.getD 1 .missing let ratStx := rat_sep.filter (· != sep) let n := ← (toExpr ratStx.size).toSyntax let els := (ratStx.map numDen).reduceOption evalTactic (← `(tactic| apply pi_lower_bound_start $n)) let _ := ← els.mapM fun (x, y) => do evalTactic (← `(tactic| apply sqrtTwoAddSeries_step_up $x $y)) evalTactic (← `(tactic| simp [sqrtTwoAddSeries])) allGoals (evalTactic (← `(tactic| norm_num1))) end Tactic /-- From a lower bound on `sqrtTwoAddSeries 0 n = 2 cos (π / 2 ^ (n+1))` of the form `2 - ((a - 1 / 4 ^ n) / 2 ^ (n + 1)) ^ 2 ≤ sqrtTwoAddSeries 0 n`, one can deduce the upper bound `π < a` thanks to basic trigonometric formulas as expressed in `pi_lt_sqrtTwoAddSeries`. -/ theorem pi_upper_bound_start (n : ℕ) {a} (h : (2 : ℝ) - ((a - 1 / (4 : ℝ) ^ n) / (2 : ℝ) ^ (n + 1)) ^ 2 ≤ sqrtTwoAddSeries ((0 : ℕ) / (1 : ℕ)) n) (h₂ : (1 : ℝ) / (4 : ℝ) ^ n ≤ a) : π < a := by refine lt_of_lt_of_le (pi_lt_sqrtTwoAddSeries n) ?_ rw [← le_sub_iff_add_le, ← le_div_iff', sqrt_le_left, sub_le_comm] · rwa [Nat.cast_zero, zero_div] at h · exact div_nonneg (sub_nonneg.2 h₂) (pow_nonneg (le_of_lt zero_lt_two) _) · exact pow_pos zero_lt_two _ #align real.pi_upper_bound_start Real.pi_upper_bound_start theorem sqrtTwoAddSeries_step_down (a b : ℕ) {c d n : ℕ} {z : ℝ} (hz : z ≤ sqrtTwoAddSeries (a / b) n) (hb : 0 < b) (hd : 0 < d) (h : a ^ 2 * d ≤ (2 * d + c) * b ^ 2) : z ≤ sqrtTwoAddSeries (c / d) (n + 1) := by apply le_trans hz; rw [sqrtTwoAddSeries_succ]; apply sqrtTwoAddSeries_monotone_left apply le_sqrt_of_sq_le have hb' : 0 < (b : ℝ) := Nat.cast_pos.2 hb have hd' : 0 < (d : ℝ) := Nat.cast_pos.2 hd rw [div_pow, add_div_eq_mul_add_div _ _ (ne_of_gt hd'), div_le_div_iff (pow_pos hb' _) hd'] exact mod_cast h #align real.sqrt_two_add_series_step_down Real.sqrtTwoAddSeries_step_down section Tactic open Lean Elab Tactic /-- Create a proof of `π < a` for a fixed rational number `a`, given a witness, which is a sequence of rational numbers `√2 < r 1 < r 2 < ... < r n < 2` satisfying the property that `√(2 + r i) ≥ r(i+1)`, where `r 0 = 0` and `√(2 - r n) ≥ (a - 1/4^n) / 2^(n+1)`. -/ elab "pi_upper_bound " "[" l:term,* "]" : tactic => do let rat_sep := l.elemsAndSeps let sep := rat_sep.getD 1 .missing let ratStx := rat_sep.filter (· != sep) let n := ← (toExpr ratStx.size).toSyntax let els := (ratStx.map numDen).reduceOption evalTactic (← `(tactic| apply pi_upper_bound_start $n)) let _ := ← els.mapM fun (x, y) => do evalTactic (← `(tactic| apply sqrtTwoAddSeries_step_down $x $y)) evalTactic (← `(tactic| simp [sqrtTwoAddSeries])) allGoals (evalTactic (← `(tactic| norm_num1))) end Tactic
Mathlib/Data/Real/Pi/Bounds.lean
171
172
theorem pi_gt_three : 3 < π := by
pi_lower_bound [23/16]
/- 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.Sub import Mathlib.MeasureTheory.Decomposition.SignedHahn import Mathlib.MeasureTheory.Function.AEEqOfIntegral #align_import measure_theory.decomposition.lebesgue from "leanprover-community/mathlib"@"b2ff9a3d7a15fd5b0f060b135421d6a89a999c2f" /-! # Lebesgue decomposition This file proves the Lebesgue decomposition theorem. The Lebesgue decomposition theorem states that, given two σ-finite measures `μ` and `ν`, there exists a σ-finite measure `ξ` and a measurable function `f` such that `μ = ξ + fν` and `ξ` is mutually singular with respect to `ν`. The Lebesgue decomposition provides the Radon-Nikodym theorem readily. ## Main definitions * `MeasureTheory.Measure.HaveLebesgueDecomposition` : A pair of measures `μ` and `ν` is said to `HaveLebesgueDecomposition` if there exist a measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.withDensity f` * `MeasureTheory.Measure.singularPart` : If a pair of measures `HaveLebesgueDecomposition`, then `singularPart` chooses the measure from `HaveLebesgueDecomposition`, otherwise it returns the zero measure. * `MeasureTheory.Measure.rnDeriv`: If a pair of measures `HaveLebesgueDecomposition`, then `rnDeriv` chooses the measurable function from `HaveLebesgueDecomposition`, otherwise it returns the zero function. ## Main results * `MeasureTheory.Measure.haveLebesgueDecomposition_of_sigmaFinite` : the Lebesgue decomposition theorem. * `MeasureTheory.Measure.eq_singularPart` : Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `s = μ.singularPart ν`. * `MeasureTheory.Measure.eq_rnDeriv` : Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`. ## Tags Lebesgue decomposition theorem -/ open scoped MeasureTheory NNReal ENNReal open Set namespace MeasureTheory namespace Measure variable {α β : Type*} {m : MeasurableSpace α} {μ ν : Measure α} /-- A pair of measures `μ` and `ν` is said to `HaveLebesgueDecomposition` if there exists a measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.withDensity f`. -/ class HaveLebesgueDecomposition (μ ν : Measure α) : Prop where lebesgue_decomposition : ∃ p : Measure α × (α → ℝ≥0∞), Measurable p.2 ∧ p.1 ⟂ₘ ν ∧ μ = p.1 + ν.withDensity p.2 #align measure_theory.measure.have_lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition #align measure_theory.measure.have_lebesgue_decomposition.lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition.lebesgue_decomposition open Classical in /-- If a pair of measures `HaveLebesgueDecomposition`, then `singularPart` chooses the measure from `HaveLebesgueDecomposition`, otherwise it returns the zero measure. For sigma-finite measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/ noncomputable irreducible_def singularPart (μ ν : Measure α) : Measure α := if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).1 else 0 #align measure_theory.measure.singular_part MeasureTheory.Measure.singularPart open Classical in /-- If a pair of measures `HaveLebesgueDecomposition`, then `rnDeriv` chooses the measurable function from `HaveLebesgueDecomposition`, otherwise it returns the zero function. For sigma-finite measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/ noncomputable irreducible_def rnDeriv (μ ν : Measure α) : α → ℝ≥0∞ := if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).2 else 0 #align measure_theory.measure.rn_deriv MeasureTheory.Measure.rnDeriv section ByDefinition theorem haveLebesgueDecomposition_spec (μ ν : Measure α) [h : HaveLebesgueDecomposition μ ν] : Measurable (μ.rnDeriv ν) ∧ μ.singularPart ν ⟂ₘ ν ∧ μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) := by rw [singularPart, rnDeriv, dif_pos h, dif_pos h] exact Classical.choose_spec h.lebesgue_decomposition #align measure_theory.measure.have_lebesgue_decomposition_spec MeasureTheory.Measure.haveLebesgueDecomposition_spec lemma rnDeriv_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) : μ.rnDeriv ν = 0 := by rw [rnDeriv, dif_neg h] lemma singularPart_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) : μ.singularPart ν = 0 := by rw [singularPart, dif_neg h] @[measurability] theorem measurable_rnDeriv (μ ν : Measure α) : Measurable <| μ.rnDeriv ν := by by_cases h : HaveLebesgueDecomposition μ ν · exact (haveLebesgueDecomposition_spec μ ν).1 · rw [rnDeriv_of_not_haveLebesgueDecomposition h] exact measurable_zero #align measure_theory.measure.measurable_rn_deriv MeasureTheory.Measure.measurable_rnDeriv theorem mutuallySingular_singularPart (μ ν : Measure α) : μ.singularPart ν ⟂ₘ ν := by by_cases h : HaveLebesgueDecomposition μ ν · exact (haveLebesgueDecomposition_spec μ ν).2.1 · rw [singularPart_of_not_haveLebesgueDecomposition h] exact MutuallySingular.zero_left #align measure_theory.measure.mutually_singular_singular_part MeasureTheory.Measure.mutuallySingular_singularPart theorem haveLebesgueDecomposition_add (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] : μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) := (haveLebesgueDecomposition_spec μ ν).2.2 #align measure_theory.measure.have_lebesgue_decomposition_add MeasureTheory.Measure.haveLebesgueDecomposition_add lemma singularPart_add_rnDeriv (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] : μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) = μ := (haveLebesgueDecomposition_add μ ν).symm lemma rnDeriv_add_singularPart (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] : ν.withDensity (μ.rnDeriv ν) + μ.singularPart ν = μ := by rw [add_comm, singularPart_add_rnDeriv] end ByDefinition section HaveLebesgueDecomposition instance instHaveLebesgueDecompositionZeroLeft : HaveLebesgueDecomposition 0 ν where lebesgue_decomposition := ⟨⟨0, 0⟩, measurable_zero, MutuallySingular.zero_left, by simp⟩ instance instHaveLebesgueDecompositionZeroRight : HaveLebesgueDecomposition μ 0 where lebesgue_decomposition := ⟨⟨μ, 0⟩, measurable_zero, MutuallySingular.zero_right, by simp⟩ instance instHaveLebesgueDecompositionSelf : HaveLebesgueDecomposition μ μ where lebesgue_decomposition := ⟨⟨0, 1⟩, measurable_const, MutuallySingular.zero_left, by simp⟩ instance haveLebesgueDecompositionSMul' (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] (r : ℝ≥0∞) : (r • μ).HaveLebesgueDecomposition ν where lebesgue_decomposition := by obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν refine ⟨⟨r • μ.singularPart ν, r • μ.rnDeriv ν⟩, hmeas.const_smul _, hsing.smul _, ?_⟩ simp only [ENNReal.smul_def] rw [withDensity_smul _ hmeas, ← smul_add, ← hadd] instance haveLebesgueDecompositionSMul (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] (r : ℝ≥0) : (r • μ).HaveLebesgueDecomposition ν := by rw [ENNReal.smul_def]; infer_instance #align measure_theory.measure.have_lebesgue_decomposition_smul MeasureTheory.Measure.haveLebesgueDecompositionSMul instance haveLebesgueDecompositionSMulRight (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] (r : ℝ≥0) : μ.HaveLebesgueDecomposition (r • ν) where lebesgue_decomposition := by obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν by_cases hr : r = 0 · exact ⟨⟨μ, 0⟩, measurable_const, by simp [hr], by simp⟩ refine ⟨⟨μ.singularPart ν, r⁻¹ • μ.rnDeriv ν⟩, hmeas.const_smul _, hsing.mono_ac AbsolutelyContinuous.rfl smul_absolutelyContinuous, ?_⟩ have : r⁻¹ • rnDeriv μ ν = ((r⁻¹ : ℝ≥0) : ℝ≥0∞) • rnDeriv μ ν := by simp [ENNReal.smul_def] rw [this, withDensity_smul _ hmeas, ENNReal.smul_def r, withDensity_smul_measure, ← smul_assoc, smul_eq_mul, ENNReal.coe_inv hr, ENNReal.inv_mul_cancel, one_smul] · exact hadd · simp [hr] · exact ENNReal.coe_ne_top theorem haveLebesgueDecomposition_withDensity (μ : Measure α) {f : α → ℝ≥0∞} (hf : Measurable f) : (μ.withDensity f).HaveLebesgueDecomposition μ := ⟨⟨⟨0, f⟩, hf, .zero_left, (zero_add _).symm⟩⟩ instance haveLebesgueDecompositionRnDeriv (μ ν : Measure α) : HaveLebesgueDecomposition (ν.withDensity (μ.rnDeriv ν)) ν := haveLebesgueDecomposition_withDensity ν (measurable_rnDeriv _ _) instance instHaveLebesgueDecompositionSingularPart : HaveLebesgueDecomposition (μ.singularPart ν) ν := ⟨⟨μ.singularPart ν, 0⟩, measurable_zero, mutuallySingular_singularPart μ ν, by simp⟩ end HaveLebesgueDecomposition theorem singularPart_le (μ ν : Measure α) : μ.singularPart ν ≤ μ := by by_cases hl : HaveLebesgueDecomposition μ ν · conv_rhs => rw [haveLebesgueDecomposition_add μ ν] exact Measure.le_add_right le_rfl · rw [singularPart, dif_neg hl] exact Measure.zero_le μ #align measure_theory.measure.singular_part_le MeasureTheory.Measure.singularPart_le theorem withDensity_rnDeriv_le (μ ν : Measure α) : ν.withDensity (μ.rnDeriv ν) ≤ μ := by by_cases hl : HaveLebesgueDecomposition μ ν · conv_rhs => rw [haveLebesgueDecomposition_add μ ν] exact Measure.le_add_left le_rfl · rw [rnDeriv, dif_neg hl, withDensity_zero] exact Measure.zero_le μ #align measure_theory.measure.with_density_rn_deriv_le MeasureTheory.Measure.withDensity_rnDeriv_le lemma _root_.AEMeasurable.singularPart {β : Type*} {_ : MeasurableSpace β} {f : α → β} (hf : AEMeasurable f μ) (ν : Measure α) : AEMeasurable f (μ.singularPart ν) := AEMeasurable.mono_measure hf (Measure.singularPart_le _ _) lemma _root_.AEMeasurable.withDensity_rnDeriv {β : Type*} {_ : MeasurableSpace β} {f : α → β} (hf : AEMeasurable f μ) (ν : Measure α) : AEMeasurable f (ν.withDensity (μ.rnDeriv ν)) := AEMeasurable.mono_measure hf (Measure.withDensity_rnDeriv_le _ _) lemma MutuallySingular.singularPart (h : μ ⟂ₘ ν) (ν' : Measure α) : μ.singularPart ν' ⟂ₘ ν := h.mono (singularPart_le μ ν') le_rfl lemma absolutelyContinuous_withDensity_rnDeriv [HaveLebesgueDecomposition ν μ] (hμν : μ ≪ ν) : μ ≪ μ.withDensity (ν.rnDeriv μ) := by rw [haveLebesgueDecomposition_add ν μ] at hμν refine AbsolutelyContinuous.mk (fun s _ hνs ↦ ?_) obtain ⟨t, _, ht1, ht2⟩ := mutuallySingular_singularPart ν μ rw [← inter_union_compl s] refine le_antisymm ((measure_union_le (s ∩ t) (s ∩ tᶜ)).trans ?_) (zero_le _) simp only [nonpos_iff_eq_zero, add_eq_zero] constructor · refine hμν ?_ simp only [coe_add, Pi.add_apply, add_eq_zero] constructor · exact measure_mono_null Set.inter_subset_right ht1 · exact measure_mono_null Set.inter_subset_left hνs · exact measure_mono_null Set.inter_subset_right ht2 lemma singularPart_eq_zero_of_ac (h : μ ≪ ν) : μ.singularPart ν = 0 := by rw [← MutuallySingular.self_iff] exact MutuallySingular.mono_ac (mutuallySingular_singularPart _ _) AbsolutelyContinuous.rfl ((absolutelyContinuous_of_le (singularPart_le _ _)).trans h) @[simp] theorem singularPart_zero (ν : Measure α) : (0 : Measure α).singularPart ν = 0 := singularPart_eq_zero_of_ac (AbsolutelyContinuous.zero _) #align measure_theory.measure.singular_part_zero MeasureTheory.Measure.singularPart_zero @[simp] lemma singularPart_zero_right (μ : Measure α) : μ.singularPart 0 = μ := by conv_rhs => rw [haveLebesgueDecomposition_add μ 0] simp lemma singularPart_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] : μ.singularPart ν = 0 ↔ μ ≪ ν := by have h_dec := haveLebesgueDecomposition_add μ ν refine ⟨fun h ↦ ?_, singularPart_eq_zero_of_ac⟩ rw [h, zero_add] at h_dec rw [h_dec] exact withDensity_absolutelyContinuous ν _ @[simp] lemma withDensity_rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] : ν.withDensity (μ.rnDeriv ν) = 0 ↔ μ ⟂ₘ ν := by have h_dec := haveLebesgueDecomposition_add μ ν refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [h, add_zero] at h_dec rw [h_dec] exact mutuallySingular_singularPart μ ν · rw [← MutuallySingular.self_iff] rw [h_dec, MutuallySingular.add_left_iff] at h refine MutuallySingular.mono_ac h.2 AbsolutelyContinuous.rfl ?_ exact withDensity_absolutelyContinuous _ _ @[simp] lemma rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] : μ.rnDeriv ν =ᵐ[ν] 0 ↔ μ ⟂ₘ ν := by rw [← withDensity_rnDeriv_eq_zero, withDensity_eq_zero_iff (measurable_rnDeriv _ _).aemeasurable] lemma rnDeriv_zero (ν : Measure α) : (0 : Measure α).rnDeriv ν =ᵐ[ν] 0 := by rw [rnDeriv_eq_zero] exact MutuallySingular.zero_left lemma MutuallySingular.rnDeriv_ae_eq_zero (hμν : μ ⟂ₘ ν) : μ.rnDeriv ν =ᵐ[ν] 0 := by by_cases h : μ.HaveLebesgueDecomposition ν · rw [rnDeriv_eq_zero] exact hμν · rw [rnDeriv_of_not_haveLebesgueDecomposition h] @[simp] theorem singularPart_withDensity (ν : Measure α) (f : α → ℝ≥0∞) : (ν.withDensity f).singularPart ν = 0 := singularPart_eq_zero_of_ac (withDensity_absolutelyContinuous _ _) #align measure_theory.measure.singular_part_with_density MeasureTheory.Measure.singularPart_withDensity lemma rnDeriv_singularPart (μ ν : Measure α) : (μ.singularPart ν).rnDeriv ν =ᵐ[ν] 0 := by rw [rnDeriv_eq_zero] exact mutuallySingular_singularPart μ ν @[simp] lemma singularPart_self (μ : Measure α) : μ.singularPart μ = 0 := singularPart_eq_zero_of_ac Measure.AbsolutelyContinuous.rfl lemma rnDeriv_self (μ : Measure α) [SigmaFinite μ] : μ.rnDeriv μ =ᵐ[μ] fun _ ↦ 1 := by have h := rnDeriv_add_singularPart μ μ rw [singularPart_self, add_zero] at h have h_one : μ = μ.withDensity 1 := by simp conv_rhs at h => rw [h_one] rwa [withDensity_eq_iff_of_sigmaFinite (measurable_rnDeriv _ _).aemeasurable] at h exact aemeasurable_const lemma singularPart_eq_self [μ.HaveLebesgueDecomposition ν] : μ.singularPart ν = μ ↔ μ ⟂ₘ ν := by have h_dec := haveLebesgueDecomposition_add μ ν refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [← h] exact mutuallySingular_singularPart _ _ · conv_rhs => rw [h_dec] rw [(withDensity_rnDeriv_eq_zero _ _).mpr h, add_zero] @[simp] lemma singularPart_singularPart (μ ν : Measure α) : (μ.singularPart ν).singularPart ν = μ.singularPart ν := by rw [Measure.singularPart_eq_self] exact Measure.mutuallySingular_singularPart _ _ instance singularPart.instIsFiniteMeasure [IsFiniteMeasure μ] : IsFiniteMeasure (μ.singularPart ν) := isFiniteMeasure_of_le μ <| singularPart_le μ ν #align measure_theory.measure.singular_part.measure_theory.is_finite_measure MeasureTheory.Measure.singularPart.instIsFiniteMeasure instance singularPart.instSigmaFinite [SigmaFinite μ] : SigmaFinite (μ.singularPart ν) := sigmaFinite_of_le μ <| singularPart_le μ ν #align measure_theory.measure.singular_part.measure_theory.sigma_finite MeasureTheory.Measure.singularPart.instSigmaFinite instance singularPart.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] : IsLocallyFiniteMeasure (μ.singularPart ν) := isLocallyFiniteMeasure_of_le <| singularPart_le μ ν #align measure_theory.measure.singular_part.measure_theory.is_locally_finite_measure MeasureTheory.Measure.singularPart.instIsLocallyFiniteMeasure instance withDensity.instIsFiniteMeasure [IsFiniteMeasure μ] : IsFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) := isFiniteMeasure_of_le μ <| withDensity_rnDeriv_le μ ν #align measure_theory.measure.with_density.measure_theory.is_finite_measure MeasureTheory.Measure.withDensity.instIsFiniteMeasure instance withDensity.instSigmaFinite [SigmaFinite μ] : SigmaFinite (ν.withDensity <| μ.rnDeriv ν) := sigmaFinite_of_le μ <| withDensity_rnDeriv_le μ ν #align measure_theory.measure.with_density.measure_theory.sigma_finite MeasureTheory.Measure.withDensity.instSigmaFinite instance withDensity.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] : IsLocallyFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) := isLocallyFiniteMeasure_of_le <| withDensity_rnDeriv_le μ ν #align measure_theory.measure.with_density.measure_theory.is_locally_finite_measure MeasureTheory.Measure.withDensity.instIsLocallyFiniteMeasure section RNDerivFinite theorem lintegral_rnDeriv_lt_top_of_measure_ne_top (ν : Measure α) {s : Set α} (hs : μ s ≠ ∞) : ∫⁻ x in s, μ.rnDeriv ν x ∂ν < ∞ := by by_cases hl : HaveLebesgueDecomposition μ ν · suffices (∫⁻ x in toMeasurable μ s, μ.rnDeriv ν x ∂ν) < ∞ from lt_of_le_of_lt (lintegral_mono_set (subset_toMeasurable _ _)) this rw [← withDensity_apply _ (measurableSet_toMeasurable _ _)] calc _ ≤ (singularPart μ ν) (toMeasurable μ s) + _ := le_add_self _ = μ s := by rw [← Measure.add_apply, ← haveLebesgueDecomposition_add, measure_toMeasurable] _ < ⊤ := hs.lt_top · simp only [Measure.rnDeriv, dif_neg hl, Pi.zero_apply, lintegral_zero, ENNReal.zero_lt_top] #align measure_theory.measure.lintegral_rn_deriv_lt_top_of_measure_ne_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top_of_measure_ne_top theorem lintegral_rnDeriv_lt_top (μ ν : Measure α) [IsFiniteMeasure μ] : ∫⁻ x, μ.rnDeriv ν x ∂ν < ∞ := by rw [← set_lintegral_univ] exact lintegral_rnDeriv_lt_top_of_measure_ne_top _ (measure_lt_top _ _).ne #align measure_theory.measure.lintegral_rn_deriv_lt_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top lemma integrable_toReal_rnDeriv [IsFiniteMeasure μ] : Integrable (fun x ↦ (μ.rnDeriv ν x).toReal) ν := integrable_toReal_of_lintegral_ne_top (Measure.measurable_rnDeriv _ _).aemeasurable (Measure.lintegral_rnDeriv_lt_top _ _).ne /-- The Radon-Nikodym derivative of a sigma-finite measure `μ` with respect to another measure `ν` is `ν`-almost everywhere finite. -/ theorem rnDeriv_lt_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x < ∞ := by suffices ∀ n, ∀ᵐ x ∂ν, x ∈ spanningSets μ n → μ.rnDeriv ν x < ∞ by filter_upwards [ae_all_iff.2 this] with _ hx using hx _ (mem_spanningSetsIndex _ _) intro n rw [← ae_restrict_iff' (measurable_spanningSets _ _)] apply ae_lt_top (measurable_rnDeriv _ _) refine (lintegral_rnDeriv_lt_top_of_measure_ne_top _ ?_).ne exact (measure_spanningSets_lt_top _ _).ne #align measure_theory.measure.rn_deriv_lt_top MeasureTheory.Measure.rnDeriv_lt_top lemma rnDeriv_ne_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x ≠ ∞ := by filter_upwards [Measure.rnDeriv_lt_top μ ν] with x hx using hx.ne end RNDerivFinite /-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then `s = μ.singularPart μ`. This theorem provides the uniqueness of the `singularPart` in the Lebesgue decomposition theorem, while `MeasureTheory.Measure.eq_rnDeriv` provides the uniqueness of the `rnDeriv`. -/ theorem eq_singularPart {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) : s = μ.singularPart ν := by have : HaveLebesgueDecomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩ obtain ⟨hmeas, hsing, hadd'⟩ := haveLebesgueDecomposition_spec μ ν obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := hs, hsing rw [hadd'] at hadd have hνinter : ν (S ∩ T)ᶜ = 0 := by rw [compl_inter] refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) ?_) rw [hT₃, hS₃, add_zero] have heq : s.restrict (S ∩ T)ᶜ = (μ.singularPart ν).restrict (S ∩ T)ᶜ := by ext1 A hA have hf : ν.withDensity f (A ∩ (S ∩ T)ᶜ) = 0 := by refine withDensity_absolutelyContinuous ν _ ?_ rw [← nonpos_iff_eq_zero] exact hνinter ▸ measure_mono inter_subset_right have hrn : ν.withDensity (μ.rnDeriv ν) (A ∩ (S ∩ T)ᶜ) = 0 := by refine withDensity_absolutelyContinuous ν _ ?_ rw [← nonpos_iff_eq_zero] exact hνinter ▸ measure_mono inter_subset_right rw [restrict_apply hA, restrict_apply hA, ← add_zero (s (A ∩ (S ∩ T)ᶜ)), ← hf, ← add_apply, ← hadd, add_apply, hrn, add_zero] have heq' : ∀ A : Set α, MeasurableSet A → s A = s.restrict (S ∩ T)ᶜ A := by intro A hA have hsinter : s (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hS₂ ▸ measure_mono (inter_subset_right.trans inter_subset_left) rw [restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hsinter] ext1 A hA have hμinter : μ.singularPart ν (A ∩ (S ∩ T)) = 0 := by rw [← nonpos_iff_eq_zero] exact hT₂ ▸ measure_mono (inter_subset_right.trans inter_subset_right) rw [heq' A hA, heq, restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hμinter] #align measure_theory.measure.eq_singular_part MeasureTheory.Measure.eq_singularPart theorem singularPart_smul (μ ν : Measure α) (r : ℝ≥0) : (r • μ).singularPart ν = r • μ.singularPart ν := by by_cases hr : r = 0 · rw [hr, zero_smul, zero_smul, singularPart_zero] by_cases hl : HaveLebesgueDecomposition μ ν · refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul (r : ℝ≥0∞)) (MutuallySingular.smul r (mutuallySingular_singularPart _ _)) ?_).symm rw [withDensity_smul _ (measurable_rnDeriv _ _), ← smul_add, ← haveLebesgueDecomposition_add μ ν, ENNReal.smul_def] · rw [singularPart, singularPart, dif_neg hl, dif_neg, smul_zero] refine fun hl' ↦ hl ?_ rw [← inv_smul_smul₀ hr μ] infer_instance #align measure_theory.measure.singular_part_smul MeasureTheory.Measure.singularPart_smul
Mathlib/MeasureTheory/Decomposition/Lebesgue.lean
445
460
theorem singularPart_smul_right (μ ν : Measure α) (r : ℝ≥0) (hr : r ≠ 0) : μ.singularPart (r • ν) = μ.singularPart ν := by
by_cases hl : HaveLebesgueDecomposition μ ν · refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul r⁻¹) ?_ ?_).symm · exact (mutuallySingular_singularPart μ ν).mono_ac AbsolutelyContinuous.rfl smul_absolutelyContinuous · rw [ENNReal.smul_def r, withDensity_smul_measure, ← withDensity_smul] swap; · exact (measurable_rnDeriv _ _).const_smul _ convert haveLebesgueDecomposition_add μ ν ext x simp only [Pi.smul_apply] rw [← ENNReal.smul_def, smul_inv_smul₀ hr] · rw [singularPart, singularPart, dif_neg hl, dif_neg] refine fun hl' ↦ hl ?_ rw [← inv_smul_smul₀ hr ν] infer_instance
/- Copyright (c) 2024 Judith Ludwig, Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Judith Ludwig, Christian Merten -/ import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.AdicCompletion.Algebra import Mathlib.Algebra.DirectSum.Basic /-! # Functoriality of adic completions In this file we establish functorial properties of the adic completion. ## Main definitions - `LinearMap.adicCauchy I f`: the linear map on `I`-adic cauchy sequences induced by `f` - `LinearMap.adicCompletion I f`: the linear map on `I`-adic completions induced by `f` ## Main results - `sumEquivOfFintype`: adic completion commutes with finite sums - `piEquivOfFintype`: adic completion commutes with finite products -/ variable {R : Type*} [CommRing R] (I : Ideal R) variable {M : Type*} [AddCommGroup M] [Module R M] variable {N : Type*} [AddCommGroup N] [Module R N] variable {P : Type*} [AddCommGroup P] [Module R P] variable {T : Type*} [AddCommGroup T] [Module (AdicCompletion I R) T] namespace LinearMap /-- `R`-linear version of `reduceModIdeal`. -/ private def reduceModIdealAux (f : M →ₗ[R] N) : M ⧸ (I • ⊤ : Submodule R M) →ₗ[R] N ⧸ (I • ⊤ : Submodule R N) := Submodule.mapQ (I • ⊤ : Submodule R M) (I • ⊤ : Submodule R N) f (fun x hx ↦ by refine Submodule.smul_induction_on hx (fun r hr x _ ↦ ?_) (fun x y hx hy ↦ ?_) · simp [Submodule.smul_mem_smul hr Submodule.mem_top] · simp [Submodule.add_mem _ hx hy]) @[local simp] private theorem reduceModIdealAux_apply (f : M →ₗ[R] N) (x : M) : (f.reduceModIdealAux I) (Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) x) = Submodule.Quotient.mk (p := (I • ⊤ : Submodule R N)) (f x) := rfl /-- The induced linear map on the quotients mod `I • ⊤`. -/ def reduceModIdeal (f : M →ₗ[R] N) : M ⧸ (I • ⊤ : Submodule R M) →ₗ[R ⧸ I] N ⧸ (I • ⊤ : Submodule R N) where toFun := f.reduceModIdealAux I map_add' := by simp map_smul' r x := by refine Quotient.inductionOn' r (fun r ↦ ?_) refine Quotient.inductionOn' x (fun x ↦ ?_) simp only [Submodule.Quotient.mk''_eq_mk, Ideal.Quotient.mk_eq_mk, Module.Quotient.mk_smul_mk, Submodule.Quotient.mk_smul, LinearMapClass.map_smul, reduceModIdealAux_apply] rfl @[simp] theorem reduceModIdeal_apply (f : M →ₗ[R] N) (x : M) : (f.reduceModIdeal I) (Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) x) = Submodule.Quotient.mk (p := (I • ⊤ : Submodule R N)) (f x) := rfl end LinearMap namespace AdicCompletion open LinearMap theorem transitionMap_comp_reduceModIdeal (f : M →ₗ[R] N) {m n : ℕ} (hmn : m ≤ n) : transitionMap I N hmn ∘ₗ f.reduceModIdeal (I ^ n) = (f.reduceModIdeal (I ^ m) : _ →ₗ[R] _) ∘ₗ transitionMap I M hmn := by ext x simp namespace AdicCauchySequence /-- A linear map induces a linear map on adic cauchy sequences. -/ @[simps] def map (f : M →ₗ[R] N) : AdicCauchySequence I M →ₗ[R] AdicCauchySequence I N where toFun a := ⟨fun n ↦ f (a n), fun {m n} hmn ↦ by have hm : Submodule.map f (I ^ m • ⊤ : Submodule R M) ≤ (I ^ m • ⊤ : Submodule R N) := by rw [Submodule.map_smul''] exact smul_mono_right _ le_top apply SModEq.mono hm apply SModEq.map (a.property hmn) f⟩ map_add' a b := by ext n; simp map_smul' r a := by ext n; simp variable (M) in @[simp] theorem map_id : map I (LinearMap.id (M := M)) = LinearMap.id := rfl theorem map_comp (f : M →ₗ[R] N) (g : N →ₗ[R] P) : map I g ∘ₗ map I f = map I (g ∘ₗ f) := rfl theorem map_comp_apply (f : M →ₗ[R] N) (g : N →ₗ[R] P) (a : AdicCauchySequence I M) : map I g (map I f a) = map I (g ∘ₗ f) a := rfl end AdicCauchySequence /-- `R`-linear version of `adicCompletion`. -/ private def adicCompletionAux (f : M →ₗ[R] N) : AdicCompletion I M →ₗ[R] AdicCompletion I N := AdicCompletion.lift I (fun n ↦ reduceModIdeal (I ^ n) f ∘ₗ AdicCompletion.eval I M n) (fun {m n} hmn ↦ by rw [← comp_assoc, AdicCompletion.transitionMap_comp_reduceModIdeal, comp_assoc, transitionMap_comp_eval]) @[local simp] private theorem adicCompletionAux_val_apply (f : M →ₗ[R] N) {n : ℕ} (x : AdicCompletion I M) : (adicCompletionAux I f x).val n = f.reduceModIdeal (I ^ n) (x.val n) := rfl /-- A linear map induces a map on adic completions. -/ def map (f : M →ₗ[R] N) : AdicCompletion I M →ₗ[AdicCompletion I R] AdicCompletion I N where toFun := adicCompletionAux I f map_add' := by aesop map_smul' r x := by ext n simp only [adicCompletionAux_val_apply, smul_eval, smul_eq_mul, RingHom.id_apply] rw [val_smul_eq_evalₐ_smul, val_smul_eq_evalₐ_smul, map_smul] @[simp] theorem map_val_apply (f : M →ₗ[R] N) {n : ℕ} (x : AdicCompletion I M) : (map I f x).val n = f.reduceModIdeal (I ^ n) (x.val n) := rfl /-- Equality of maps out of an adic completion can be checked on Cauchy sequences. -/ theorem map_ext {f g : AdicCompletion I M → N} (h : ∀ (a : AdicCauchySequence I M), f (AdicCompletion.mk I M a) = g (AdicCompletion.mk I M a)) : f = g := by ext x apply induction_on I M x (fun a ↦ h a) /-- Equality of linear maps out of an adic completion can be checked on Cauchy sequences. -/ @[ext] theorem map_ext' {f g : AdicCompletion I M →ₗ[AdicCompletion I R] T} (h : ∀ (a : AdicCauchySequence I M), f (AdicCompletion.mk I M a) = g (AdicCompletion.mk I M a)) : f = g := by ext x apply induction_on I M x (fun a ↦ h a) /-- Equality of linear maps out of an adic completion can be checked on Cauchy sequences. -/ @[ext] theorem map_ext'' {f g : AdicCompletion I M →ₗ[R] N} (h : f.comp (AdicCompletion.mk I M) = g.comp (AdicCompletion.mk I M)) : f = g := by ext x apply induction_on I M x (fun a ↦ LinearMap.ext_iff.mp h a) variable (M) in @[simp] theorem map_id : map I (LinearMap.id (M := M)) = LinearMap.id (R := AdicCompletion I R) (M := AdicCompletion I M) := by ext a n simp theorem map_comp (f : M →ₗ[R] N) (g : N →ₗ[R] P) : map I g ∘ₗ map I f = map I (g ∘ₗ f) := by ext simp theorem map_comp_apply (f : M →ₗ[R] N) (g : N →ₗ[R] P) (x : AdicCompletion I M) : map I g (map I f x) = map I (g ∘ₗ f) x := by show (map I g ∘ₗ map I f) x = map I (g ∘ₗ f) x rw [map_comp] @[simp] theorem map_mk (f : M →ₗ[R] N) (a : AdicCauchySequence I M) : map I f (AdicCompletion.mk I M a) = AdicCompletion.mk I N (AdicCauchySequence.map I f a) := rfl @[simp] theorem val_sum {α : Type*} (s : Finset α) (f : α → AdicCompletion I M) (n : ℕ) : (Finset.sum s f).val n = Finset.sum s (fun a ↦ (f a).val n) := by change (Submodule.subtype (AdicCompletion.submodule I M) _) n = _ rw [map_sum, Finset.sum_apply, Submodule.coeSubtype] /-- A linear equiv induces a linear equiv on adic completions. -/ def congr (f : M ≃ₗ[R] N) : AdicCompletion I M ≃ₗ[AdicCompletion I R] AdicCompletion I N := LinearEquiv.ofLinear (map I f) (map I f.symm) (by simp [map_comp]) (by simp [map_comp]) @[simp] theorem congr_apply (f : M ≃ₗ[R] N) (x : AdicCompletion I M) : congr I f x = map I f x := rfl @[simp] theorem congr_symm_apply (f : M ≃ₗ[R] N) (x : AdicCompletion I N) : (congr I f).symm x = map I f.symm x := rfl section Families /-! ### Adic completion in families In this section we consider a family `M : ι → Type*` of `R`-modules. Purely from the formal properties of adic completions we obtain two canonical maps - `AdicCompleiton I (∀ j, M j) →ₗ[R] ∀ j, AdicCompletion I (M j)` - `(⨁ j, (AdicCompletion I (M j))) →ₗ[R] AdicCompletion I (⨁ j, M j)` If `ι` is finite, both are isomorphisms and, modulo the equivalence `⨁ j, (AdicCompletion I (M j)` and `∀ j, AdicCompletion I (M j)`, inverse to each other. -/ variable {ι : Type*} [DecidableEq ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] section Pi /-- The canonical map from the adic completion of the product to the product of the adic completions. -/ @[simps!] def pi : AdicCompletion I (∀ j, M j) →ₗ[AdicCompletion I R] ∀ j, AdicCompletion I (M j) := LinearMap.pi (fun j ↦ map I (LinearMap.proj j)) end Pi section Sum open DirectSum /-- The canonical map from the sum of the adic completions to the adic completion of the sum. -/ def sum : (⨁ j, (AdicCompletion I (M j))) →ₗ[AdicCompletion I R] AdicCompletion I (⨁ j, M j) := toModule (AdicCompletion I R) ι (AdicCompletion I (⨁ j, M j)) (fun j ↦ map I (lof R ι M j)) @[simp] theorem sum_lof (j : ι) (x : AdicCompletion I (M j)) : sum I M ((DirectSum.lof (AdicCompletion I R) ι (fun i ↦ AdicCompletion I (M i)) j) x) = map I (lof R ι M j) x := by simp [sum] @[simp] theorem sum_of (j : ι) (x : AdicCompletion I (M j)) : sum I M ((DirectSum.of (fun i ↦ AdicCompletion I (M i)) j) x) = map I (lof R ι M j) x := by rw [← lof_eq_of R] apply sum_lof variable [Fintype ι] /-- If `ι` is finite, we use the equivalence of sum and product to obtain an inverse for `AdicCompletion.sum` from `AdicCompletion.pi`. -/ def sumInv : AdicCompletion I (⨁ j, M j) →ₗ[AdicCompletion I R] (⨁ j, (AdicCompletion I (M j))) := letI f := map I (linearEquivFunOnFintype R ι M) letI g := linearEquivFunOnFintype (AdicCompletion I R) ι (fun j ↦ AdicCompletion I (M j)) g.symm.toLinearMap ∘ₗ pi I M ∘ₗ f @[simp]
Mathlib/RingTheory/AdicCompletion/Functoriality.lean
270
274
theorem component_sumInv (x : AdicCompletion I (⨁ j, M j)) (j : ι) : component (AdicCompletion I R) ι _ j (sumInv I M x) = map I (component R ι _ j) x := by
apply induction_on I _ x (fun x ↦ ?_) rfl
/- 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 -/ import Mathlib.Data.Sum.Order import Mathlib.Order.InitialSeg import Mathlib.SetTheory.Cardinal.Basic import Mathlib.Tactic.PPWithUniv #align_import set_theory.ordinal.basic from "leanprover-community/mathlib"@"8ea5598db6caeddde6cb734aa179cc2408dbd345" /-! # Ordinals Ordinals are defined as equivalences of well-ordered sets under order isomorphism. They are endowed with a total order, where an ordinal is smaller than another one if it embeds into it as an initial segment (or, equivalently, in any way). This total order is well founded. ## Main definitions * `Ordinal`: the type of ordinals (in a given universe) * `Ordinal.type r`: given a well-founded order `r`, this is the corresponding ordinal * `Ordinal.typein r a`: given a well-founded order `r` on a type `α`, and `a : α`, the ordinal corresponding to all elements smaller than `a`. * `enum r o h`: given a well-order `r` on a type `α`, and an ordinal `o` strictly smaller than the ordinal corresponding to `r` (this is the assumption `h`), returns the `o`-th element of `α`. In other words, the elements of `α` can be enumerated using ordinals up to `type r`. * `Ordinal.card o`: the cardinality of an ordinal `o`. * `Ordinal.lift` lifts an ordinal in universe `u` to an ordinal in universe `max u v`. For a version registering additionally that this is an initial segment embedding, see `Ordinal.lift.initialSeg`. For a version registering that it is a principal segment embedding if `u < v`, see `Ordinal.lift.principalSeg`. * `Ordinal.omega` or `ω` is the order type of `ℕ`. This definition is universe polymorphic: `Ordinal.omega.{u} : Ordinal.{u}` (contrast with `ℕ : Type`, which lives in a specific universe). In some cases the universe level has to be given explicitly. * `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₂`. The main properties of addition (and the other operations on ordinals) are stated and proved in `Mathlib/SetTheory/Ordinal/Arithmetic.lean`. Here, we only introduce it and prove its basic properties to deduce the fact that the order on ordinals is total (and well founded). * `succ o` is the successor of the ordinal `o`. * `Cardinal.ord c`: when `c` is a cardinal, `ord c` is the smallest ordinal with this cardinality. It is the canonical way to represent a cardinal with an ordinal. A conditionally complete linear order with bot structure is registered on ordinals, where `⊥` is `0`, the ordinal corresponding to the empty type, and `Inf` is the minimum for nonempty sets and `0` for the empty set by convention. ## Notations * `ω` is a notation for the first infinite ordinal in the locale `Ordinal`. -/ assert_not_exists Module assert_not_exists Field noncomputable section open Function Cardinal Set Equiv Order open scoped Classical open Cardinal InitialSeg universe u v w variable {α : Type u} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} /-! ### Well order on an arbitrary type -/ section WellOrderingThm -- Porting note: `parameter` does not work -- parameter {σ : Type u} variable {σ : Type u} open Function theorem nonempty_embedding_to_cardinal : Nonempty (σ ↪ Cardinal.{u}) := (Embedding.total _ _).resolve_left fun ⟨⟨f, hf⟩⟩ => let g : σ → Cardinal.{u} := invFun f let ⟨x, (hx : g x = 2 ^ sum g)⟩ := invFun_surjective hf (2 ^ sum g) have : g x ≤ sum g := le_sum.{u, u} g x not_le_of_gt (by rw [hx]; exact cantor _) this #align nonempty_embedding_to_cardinal nonempty_embedding_to_cardinal /-- An embedding of any type to the set of cardinals. -/ def embeddingToCardinal : σ ↪ Cardinal.{u} := Classical.choice nonempty_embedding_to_cardinal #align embedding_to_cardinal embeddingToCardinal /-- Any type can be endowed with a well order, obtained by pulling back the well order over cardinals by some embedding. -/ def WellOrderingRel : σ → σ → Prop := embeddingToCardinal ⁻¹'o (· < ·) #align well_ordering_rel WellOrderingRel instance WellOrderingRel.isWellOrder : IsWellOrder σ WellOrderingRel := (RelEmbedding.preimage _ _).isWellOrder #align well_ordering_rel.is_well_order WellOrderingRel.isWellOrder instance IsWellOrder.subtype_nonempty : Nonempty { r // IsWellOrder σ r } := ⟨⟨WellOrderingRel, inferInstance⟩⟩ #align is_well_order.subtype_nonempty IsWellOrder.subtype_nonempty end WellOrderingThm /-! ### Definition of ordinals -/ /-- Bundled structure registering a well order on a type. Ordinals will be defined as a quotient of this type. -/ structure WellOrder : Type (u + 1) where /-- The underlying type of the order. -/ α : Type u /-- The underlying relation of the order. -/ r : α → α → Prop /-- The proposition that `r` is a well-ordering for `α`. -/ wo : IsWellOrder α r set_option linter.uppercaseLean3 false in #align Well_order WellOrder attribute [instance] WellOrder.wo namespace WellOrder instance inhabited : Inhabited WellOrder := ⟨⟨PEmpty, _, inferInstanceAs (IsWellOrder PEmpty EmptyRelation)⟩⟩ @[simp] theorem eta (o : WellOrder) : mk o.α o.r o.wo = o := by cases o rfl set_option linter.uppercaseLean3 false in #align Well_order.eta WellOrder.eta end WellOrder /-- Equivalence relation on well orders on arbitrary types in universe `u`, given by order isomorphism. -/ instance Ordinal.isEquivalent : Setoid WellOrder where r := fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≃r s) iseqv := ⟨fun _ => ⟨RelIso.refl _⟩, fun ⟨e⟩ => ⟨e.symm⟩, fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩ #align ordinal.is_equivalent Ordinal.isEquivalent /-- `Ordinal.{u}` is the type of well orders in `Type u`, up to order isomorphism. -/ @[pp_with_univ] def Ordinal : Type (u + 1) := Quotient Ordinal.isEquivalent #align ordinal Ordinal instance hasWellFoundedOut (o : Ordinal) : WellFoundedRelation o.out.α := ⟨o.out.r, o.out.wo.wf⟩ #align has_well_founded_out hasWellFoundedOut instance linearOrderOut (o : Ordinal) : LinearOrder o.out.α := IsWellOrder.linearOrder o.out.r #align linear_order_out linearOrderOut instance isWellOrder_out_lt (o : Ordinal) : IsWellOrder o.out.α (· < ·) := o.out.wo #align is_well_order_out_lt isWellOrder_out_lt namespace Ordinal /-! ### Basic properties of the order type -/ /-- The order type of a well order is an ordinal. -/ def type (r : α → α → Prop) [wo : IsWellOrder α r] : Ordinal := ⟦⟨α, r, wo⟩⟧ #align ordinal.type Ordinal.type instance zero : Zero Ordinal := ⟨type <| @EmptyRelation PEmpty⟩ instance inhabited : Inhabited Ordinal := ⟨0⟩ instance one : One Ordinal := ⟨type <| @EmptyRelation PUnit⟩ /-- The order type of an element inside a well order. For the embedding as a principal segment, see `typein.principalSeg`. -/ def typein (r : α → α → Prop) [IsWellOrder α r] (a : α) : Ordinal := type (Subrel r { b | r b a }) #align ordinal.typein Ordinal.typein @[simp] theorem type_def' (w : WellOrder) : ⟦w⟧ = type w.r := by cases w rfl #align ordinal.type_def' Ordinal.type_def' @[simp, nolint simpNF] -- Porting note (#10675): dsimp can not prove this theorem type_def (r) [wo : IsWellOrder α r] : (⟦⟨α, r, wo⟩⟧ : Ordinal) = type r := by rfl #align ordinal.type_def Ordinal.type_def @[simp]
Mathlib/SetTheory/Ordinal/Basic.lean
207
208
theorem type_out (o : Ordinal) : Ordinal.type o.out.r = o := by
rw [Ordinal.type, WellOrder.eta, Quotient.out_eq]
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Bhavik Mehta -/ import Mathlib.Analysis.Calculus.Deriv.Support import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.MeasureTheory.Integral.FundThmCalculus import Mathlib.Order.Filter.AtTopBot import Mathlib.MeasureTheory.Function.Jacobian import Mathlib.MeasureTheory.Measure.Haar.NormedSpace import Mathlib.MeasureTheory.Measure.Haar.Unique #align_import measure_theory.integral.integral_eq_improper from "leanprover-community/mathlib"@"b84aee748341da06a6d78491367e2c0e9f15e8a5" /-! # Links between an integral and its "improper" version In its current state, mathlib only knows how to talk about definite ("proper") integrals, in the sense that it treats integrals over `[x, +∞)` the same as it treats integrals over `[y, z]`. For example, the integral over `[1, +∞)` is **not** defined to be the limit of the integral over `[1, x]` as `x` tends to `+∞`, which is known as an **improper integral**. Indeed, the "proper" definition is stronger than the "improper" one. The usual counterexample is `x ↦ sin(x)/x`, which has an improper integral over `[1, +∞)` but no definite integral. Although definite integrals have better properties, they are hardly usable when it comes to computing integrals on unbounded sets, which is much easier using limits. Thus, in this file, we prove various ways of studying the proper integral by studying the improper one. ## Definitions The main definition of this file is `MeasureTheory.AECover`. It is a rather technical definition whose sole purpose is generalizing and factoring proofs. Given an index type `ι`, a countably generated filter `l` over `ι`, and an `ι`-indexed family `φ` of subsets of a measurable space `α` equipped with a measure `μ`, one should think of a hypothesis `hφ : MeasureTheory.AECover μ l φ` as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ i, f x ∂μ` as `i` tends to `l`. When using this definition with a measure restricted to a set `s`, which happens fairly often, one should not try too hard to use a `MeasureTheory.AECover` of subsets of `s`, as it often makes proofs more complicated than necessary. See for example the proof of `MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_tendsto` where we use `(fun x ↦ oi x)` as a `MeasureTheory.AECover` w.r.t. `μ.restrict (Iic b)`, instead of using `(fun x ↦ Ioc x b)`. ## Main statements - `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is a measurable `ENNReal`-valued function, then `∫⁻ x in φ n, f x ∂μ` tends to `∫⁻ x, f x ∂μ` as `n` tends to `l` - `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, if `f` is measurable and integrable on each `φ n`, and if `∫ x in φ n, ‖f x‖ ∂μ` tends to some `I : ℝ` as n tends to `l`, then `f` is integrable - `MeasureTheory.AECover.integral_tendsto_of_countably_generated` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is measurable and integrable (globally), then `∫ x in φ n, f x ∂μ` tends to `∫ x, f x ∂μ` as `n` tends to `+∞`. We then specialize these lemmas to various use cases involving intervals, which are frequent in analysis. In particular, - `MeasureTheory.integral_Ioi_of_hasDerivAt_of_tendsto` is a version of FTC-2 on the interval `(a, +∞)`, giving the formula `∫ x in (a, +∞), g' x = l - g a` if `g'` is integrable and `g` tends to `l` at `+∞`. - `MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonneg` gives the same result assuming that `g'` is nonnegative instead of integrable. Its automatic integrability in this context is proved in `MeasureTheory.integrableOn_Ioi_deriv_of_nonneg`. - `MeasureTheory.integral_comp_smul_deriv_Ioi` is a version of the change of variables formula on semi-infinite intervals. - `MeasureTheory.tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi` shows that a function whose derivative is integrable on `(a, +∞)` has a limit at `+∞`. - `MeasureTheory.tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi` shows that an integrable function whose derivative is integrable on `(a, +∞)` tends to `0` at `+∞`. Versions of these results are also given on the intervals `(-∞, a]` and `(-∞, +∞)`, as well as the corresponding versions of integration by parts. -/ open MeasureTheory Filter Set TopologicalSpace open scoped ENNReal NNReal Topology namespace MeasureTheory section AECover variable {α ι : Type*} [MeasurableSpace α] (μ : Measure α) (l : Filter ι) /-- A sequence `φ` of subsets of `α` is a `MeasureTheory.AECover` w.r.t. a measure `μ` and a filter `l` if almost every point (w.r.t. `μ`) of `α` eventually belongs to `φ n` (w.r.t. `l`), and if each `φ n` is measurable. This definition is a technical way to avoid duplicating a lot of proofs. It should be thought of as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ n, f x ∂μ` as `n` tends to `l`. See for example `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated`, `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` and `MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/ structure AECover (φ : ι → Set α) : Prop where ae_eventually_mem : ∀ᵐ x ∂μ, ∀ᶠ i in l, x ∈ φ i protected measurableSet : ∀ i, MeasurableSet <| φ i #align measure_theory.ae_cover MeasureTheory.AECover #align measure_theory.ae_cover.ae_eventually_mem MeasureTheory.AECover.ae_eventually_mem #align measure_theory.ae_cover.measurable MeasureTheory.AECover.measurableSet variable {μ} {l} namespace AECover /-! ## Operations on `AECover`s Porting note: this is a new section. -/ /-- Elementwise intersection of two `AECover`s is an `AECover`. -/ theorem inter {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hψ : AECover μ l ψ) : AECover μ l (fun i ↦ φ i ∩ ψ i) where ae_eventually_mem := hψ.1.mp <| hφ.1.mono fun _ ↦ Eventually.and measurableSet _ := (hφ.2 _).inter (hψ.2 _) theorem superset {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hsub : ∀ i, φ i ⊆ ψ i) (hmeas : ∀ i, MeasurableSet (ψ i)) : AECover μ l ψ := ⟨hφ.1.mono fun _x hx ↦ hx.mono fun i hi ↦ hsub i hi, hmeas⟩ theorem mono_ac {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≪ μ) : AECover ν l φ := ⟨hle hφ.1, hφ.2⟩ theorem mono {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≤ μ) : AECover ν l φ := hφ.mono_ac hle.absolutelyContinuous end AECover section MetricSpace variable [PseudoMetricSpace α] [OpensMeasurableSpace α] theorem aecover_ball {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) : AECover μ l (fun i ↦ Metric.ball x (r i)) where measurableSet _ := Metric.isOpen_ball.measurableSet ae_eventually_mem := by filter_upwards with y filter_upwards [hr (Ioi_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha theorem aecover_closedBall {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) : AECover μ l (fun i ↦ Metric.closedBall x (r i)) where measurableSet _ := Metric.isClosed_ball.measurableSet ae_eventually_mem := by filter_upwards with y filter_upwards [hr (Ici_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha end MetricSpace section Preorderα variable [Preorder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) theorem aecover_Ici : AECover μ l fun i => Ici (a i) where ae_eventually_mem := ae_of_all μ ha.eventually_le_atBot measurableSet _ := measurableSet_Ici #align measure_theory.ae_cover_Ici MeasureTheory.aecover_Ici theorem aecover_Iic : AECover μ l fun i => Iic <| b i := aecover_Ici (α := αᵒᵈ) hb #align measure_theory.ae_cover_Iic MeasureTheory.aecover_Iic theorem aecover_Icc : AECover μ l fun i => Icc (a i) (b i) := (aecover_Ici ha).inter (aecover_Iic hb) #align measure_theory.ae_cover_Icc MeasureTheory.aecover_Icc end Preorderα section LinearOrderα variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) theorem aecover_Ioi [NoMinOrder α] : AECover μ l fun i => Ioi (a i) where ae_eventually_mem := ae_of_all μ ha.eventually_lt_atBot measurableSet _ := measurableSet_Ioi #align measure_theory.ae_cover_Ioi MeasureTheory.aecover_Ioi theorem aecover_Iio [NoMaxOrder α] : AECover μ l fun i => Iio (b i) := aecover_Ioi (α := αᵒᵈ) hb #align measure_theory.ae_cover_Iio MeasureTheory.aecover_Iio theorem aecover_Ioo [NoMinOrder α] [NoMaxOrder α] : AECover μ l fun i => Ioo (a i) (b i) := (aecover_Ioi ha).inter (aecover_Iio hb) #align measure_theory.ae_cover_Ioo MeasureTheory.aecover_Ioo theorem aecover_Ioc [NoMinOrder α] : AECover μ l fun i => Ioc (a i) (b i) := (aecover_Ioi ha).inter (aecover_Iic hb) #align measure_theory.ae_cover_Ioc MeasureTheory.aecover_Ioc theorem aecover_Ico [NoMaxOrder α] : AECover μ l fun i => Ico (a i) (b i) := (aecover_Ici ha).inter (aecover_Iio hb) #align measure_theory.ae_cover_Ico MeasureTheory.aecover_Ico end LinearOrderα section FiniteIntervals variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} {A B : α} (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) -- Porting note (#10756): new lemma theorem aecover_Ioi_of_Ioi : AECover (μ.restrict (Ioi A)) l fun i ↦ Ioi (a i) where ae_eventually_mem := (ae_restrict_mem measurableSet_Ioi).mono fun _x hx ↦ ha.eventually <| eventually_lt_nhds hx measurableSet _ := measurableSet_Ioi -- Porting note (#10756): new lemma theorem aecover_Iio_of_Iio : AECover (μ.restrict (Iio B)) l fun i ↦ Iio (b i) := aecover_Ioi_of_Ioi (α := αᵒᵈ) hb -- Porting note (#10756): new lemma theorem aecover_Ioi_of_Ici : AECover (μ.restrict (Ioi A)) l fun i ↦ Ici (a i) := (aecover_Ioi_of_Ioi ha).superset (fun _ ↦ Ioi_subset_Ici_self) fun _ ↦ measurableSet_Ici -- Porting note (#10756): new lemma theorem aecover_Iio_of_Iic : AECover (μ.restrict (Iio B)) l fun i ↦ Iic (b i) := aecover_Ioi_of_Ici (α := αᵒᵈ) hb theorem aecover_Ioo_of_Ioo : AECover (μ.restrict <| Ioo A B) l fun i => Ioo (a i) (b i) := ((aecover_Ioi_of_Ioi ha).mono <| Measure.restrict_mono Ioo_subset_Ioi_self le_rfl).inter ((aecover_Iio_of_Iio hb).mono <| Measure.restrict_mono Ioo_subset_Iio_self le_rfl) #align measure_theory.ae_cover_Ioo_of_Ioo MeasureTheory.aecover_Ioo_of_Ioo theorem aecover_Ioo_of_Icc : AECover (μ.restrict <| Ioo A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Icc_self) fun _ ↦ measurableSet_Icc #align measure_theory.ae_cover_Ioo_of_Icc MeasureTheory.aecover_Ioo_of_Icc theorem aecover_Ioo_of_Ico : AECover (μ.restrict <| Ioo A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ico_self) fun _ ↦ measurableSet_Ico #align measure_theory.ae_cover_Ioo_of_Ico MeasureTheory.aecover_Ioo_of_Ico theorem aecover_Ioo_of_Ioc : AECover (μ.restrict <| Ioo A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ioc_self) fun _ ↦ measurableSet_Ioc #align measure_theory.ae_cover_Ioo_of_Ioc MeasureTheory.aecover_Ioo_of_Ioc variable [NoAtoms μ] theorem aecover_Ioc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge #align measure_theory.ae_cover_Ioc_of_Icc MeasureTheory.aecover_Ioc_of_Icc theorem aecover_Ioc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge #align measure_theory.ae_cover_Ioc_of_Ico MeasureTheory.aecover_Ioc_of_Ico theorem aecover_Ioc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge #align measure_theory.ae_cover_Ioc_of_Ioc MeasureTheory.aecover_Ioc_of_Ioc theorem aecover_Ioc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge #align measure_theory.ae_cover_Ioc_of_Ioo MeasureTheory.aecover_Ioc_of_Ioo theorem aecover_Ico_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge #align measure_theory.ae_cover_Ico_of_Icc MeasureTheory.aecover_Ico_of_Icc theorem aecover_Ico_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge #align measure_theory.ae_cover_Ico_of_Ico MeasureTheory.aecover_Ico_of_Ico theorem aecover_Ico_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge #align measure_theory.ae_cover_Ico_of_Ioc MeasureTheory.aecover_Ico_of_Ioc theorem aecover_Ico_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge #align measure_theory.ae_cover_Ico_of_Ioo MeasureTheory.aecover_Ico_of_Ioo theorem aecover_Icc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge #align measure_theory.ae_cover_Icc_of_Icc MeasureTheory.aecover_Icc_of_Icc theorem aecover_Icc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge #align measure_theory.ae_cover_Icc_of_Ico MeasureTheory.aecover_Icc_of_Ico theorem aecover_Icc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge #align measure_theory.ae_cover_Icc_of_Ioc MeasureTheory.aecover_Icc_of_Ioc theorem aecover_Icc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge #align measure_theory.ae_cover_Icc_of_Ioo MeasureTheory.aecover_Icc_of_Ioo end FiniteIntervals protected theorem AECover.restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} : AECover (μ.restrict s) l φ := hφ.mono Measure.restrict_le_self #align measure_theory.ae_cover.restrict MeasureTheory.AECover.restrict theorem aecover_restrict_of_ae_imp {s : Set α} {φ : ι → Set α} (hs : MeasurableSet s) (ae_eventually_mem : ∀ᵐ x ∂μ, x ∈ s → ∀ᶠ n in l, x ∈ φ n) (measurable : ∀ n, MeasurableSet <| φ n) : AECover (μ.restrict s) l φ where ae_eventually_mem := by rwa [ae_restrict_iff' hs] measurableSet := measurable #align measure_theory.ae_cover_restrict_of_ae_imp MeasureTheory.aecover_restrict_of_ae_imp theorem AECover.inter_restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} (hs : MeasurableSet s) : AECover (μ.restrict s) l fun i => φ i ∩ s := aecover_restrict_of_ae_imp hs (hφ.ae_eventually_mem.mono fun _x hx hxs => hx.mono fun _i hi => ⟨hi, hxs⟩) fun i => (hφ.measurableSet i).inter hs #align measure_theory.ae_cover.inter_restrict MeasureTheory.AECover.inter_restrict theorem AECover.ae_tendsto_indicator {β : Type*} [Zero β] [TopologicalSpace β] (f : α → β) {φ : ι → Set α} (hφ : AECover μ l φ) : ∀ᵐ x ∂μ, Tendsto (fun i => (φ i).indicator f x) l (𝓝 <| f x) := hφ.ae_eventually_mem.mono fun _x hx => tendsto_const_nhds.congr' <| hx.mono fun _n hn => (indicator_of_mem hn _).symm #align measure_theory.ae_cover.ae_tendsto_indicator MeasureTheory.AECover.ae_tendsto_indicator theorem AECover.aemeasurable {β : Type*} [MeasurableSpace β] [l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ) (hfm : ∀ i, AEMeasurable f (μ.restrict <| φ i)) : AEMeasurable f μ := by obtain ⟨u, hu⟩ := l.exists_seq_tendsto have := aemeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n) rwa [Measure.restrict_eq_self_of_ae_mem] at this filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists #align measure_theory.ae_cover.ae_measurable MeasureTheory.AECover.aemeasurable theorem AECover.aestronglyMeasurable {β : Type*} [TopologicalSpace β] [PseudoMetrizableSpace β] [l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ) (hfm : ∀ i, AEStronglyMeasurable f (μ.restrict <| φ i)) : AEStronglyMeasurable f μ := by obtain ⟨u, hu⟩ := l.exists_seq_tendsto have := aestronglyMeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n) rwa [Measure.restrict_eq_self_of_ae_mem] at this filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists #align measure_theory.ae_cover.ae_strongly_measurable MeasureTheory.AECover.aestronglyMeasurable end AECover theorem AECover.comp_tendsto {α ι ι' : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} {l' : Filter ι'} {φ : ι → Set α} (hφ : AECover μ l φ) {u : ι' → ι} (hu : Tendsto u l' l) : AECover μ l' (φ ∘ u) where ae_eventually_mem := hφ.ae_eventually_mem.mono fun _x hx => hu.eventually hx measurableSet i := hφ.measurableSet (u i) #align measure_theory.ae_cover.comp_tendsto MeasureTheory.AECover.comp_tendsto section AECoverUnionInterCountable variable {α ι : Type*} [Countable ι] [MeasurableSpace α] {μ : Measure α} theorem AECover.biUnion_Iic_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋃ (k) (_h : k ∈ Iic n), φ k := hφ.superset (fun _ ↦ subset_biUnion_of_mem right_mem_Iic) fun _ ↦ .biUnion (to_countable _) fun _ _ ↦ (hφ.2 _) #align measure_theory.ae_cover.bUnion_Iic_ae_cover MeasureTheory.AECover.biUnion_Iic_aecover -- Porting note: generalized from `[SemilatticeSup ι] [Nonempty ι]` to `[Preorder ι]` theorem AECover.biInter_Ici_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋂ (k) (_h : k ∈ Ici n), φ k where ae_eventually_mem := hφ.ae_eventually_mem.mono fun x h ↦ by simpa only [mem_iInter, mem_Ici, eventually_forall_ge_atTop] measurableSet i := .biInter (to_countable _) fun n _ => hφ.measurableSet n #align measure_theory.ae_cover.bInter_Ici_ae_cover MeasureTheory.AECover.biInter_Ici_aecover end AECoverUnionInterCountable section Lintegral variable {α ι : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} private theorem lintegral_tendsto_of_monotone_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) (hmono : Monotone φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := let F n := (φ n).indicator f have key₁ : ∀ n, AEMeasurable (F n) μ := fun n => hfm.indicator (hφ.measurableSet n) have key₂ : ∀ᵐ x : α ∂μ, Monotone fun n => F n x := ae_of_all _ fun x _i _j hij => indicator_le_indicator_of_subset (hmono hij) (fun x => zero_le <| f x) x have key₃ : ∀ᵐ x : α ∂μ, Tendsto (fun n => F n x) atTop (𝓝 (f x)) := hφ.ae_tendsto_indicator f (lintegral_tendsto_of_tendsto_of_monotone key₁ key₂ key₃).congr fun n => lintegral_indicator f (hφ.measurableSet n) theorem AECover.lintegral_tendsto_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (∫⁻ x in φ ·, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := by have lim₁ := lintegral_tendsto_of_monotone_of_nat hφ.biInter_Ici_aecover (fun i j hij => biInter_subset_biInter_left (Ici_subset_Ici.mpr hij)) hfm have lim₂ := lintegral_tendsto_of_monotone_of_nat hφ.biUnion_Iic_aecover (fun i j hij => biUnion_subset_biUnion_left (Iic_subset_Iic.mpr hij)) hfm refine tendsto_of_tendsto_of_tendsto_of_le_of_le lim₁ lim₂ (fun n ↦ ?_) fun n ↦ ?_ exacts [lintegral_mono_set (biInter_subset_of_mem left_mem_Ici), lintegral_mono_set (subset_biUnion_of_mem right_mem_Iic)] #align measure_theory.ae_cover.lintegral_tendsto_of_nat MeasureTheory.AECover.lintegral_tendsto_of_nat theorem AECover.lintegral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 <| ∫⁻ x, f x ∂μ) := tendsto_of_seq_tendsto fun _u hu => (hφ.comp_tendsto hu).lintegral_tendsto_of_nat hfm #align measure_theory.ae_cover.lintegral_tendsto_of_countably_generated MeasureTheory.AECover.lintegral_tendsto_of_countably_generated theorem AECover.lintegral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (I : ℝ≥0∞) (hfm : AEMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 I)) : ∫⁻ x, f x ∂μ = I := tendsto_nhds_unique (hφ.lintegral_tendsto_of_countably_generated hfm) htendsto #align measure_theory.ae_cover.lintegral_eq_of_tendsto MeasureTheory.AECover.lintegral_eq_of_tendsto theorem AECover.iSup_lintegral_eq_of_countably_generated [Nonempty ι] [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : ⨆ i : ι, ∫⁻ x in φ i, f x ∂μ = ∫⁻ x, f x ∂μ := by have := hφ.lintegral_tendsto_of_countably_generated hfm refine ciSup_eq_of_forall_le_of_forall_lt_exists_gt (fun i => lintegral_mono' Measure.restrict_le_self le_rfl) fun w hw => ?_ rcases exists_between hw with ⟨m, hm₁, hm₂⟩ rcases (eventually_ge_of_tendsto_gt hm₂ this).exists with ⟨i, hi⟩ exact ⟨i, lt_of_lt_of_le hm₁ hi⟩ #align measure_theory.ae_cover.supr_lintegral_eq_of_countably_generated MeasureTheory.AECover.iSup_lintegral_eq_of_countably_generated end Lintegral section Integrable variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E] theorem AECover.integrable_of_lintegral_nnnorm_bounded [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ) (hbounded : ∀ᶠ i in l, (∫⁻ x in φ i, ‖f x‖₊ ∂μ) ≤ ENNReal.ofReal I) : Integrable f μ := by refine ⟨hfm, (le_of_tendsto ?_ hbounded).trans_lt ENNReal.ofReal_lt_top⟩ exact hφ.lintegral_tendsto_of_countably_generated hfm.ennnorm #align measure_theory.ae_cover.integrable_of_lintegral_nnnorm_bounded MeasureTheory.AECover.integrable_of_lintegral_nnnorm_bounded theorem AECover.integrable_of_lintegral_nnnorm_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖₊ ∂μ) l (𝓝 <| ENNReal.ofReal I)) : Integrable f μ := by refine hφ.integrable_of_lintegral_nnnorm_bounded (max 1 (I + 1)) hfm ?_ refine htendsto.eventually (ge_mem_nhds ?_) refine (ENNReal.ofReal_lt_ofReal_iff (lt_max_of_lt_left zero_lt_one)).2 ?_ exact lt_max_of_lt_right (lt_add_one I) #align measure_theory.ae_cover.integrable_of_lintegral_nnnorm_tendsto MeasureTheory.AECover.integrable_of_lintegral_nnnorm_tendsto theorem AECover.integrable_of_lintegral_nnnorm_bounded' [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ) (hbounded : ∀ᶠ i in l, (∫⁻ x in φ i, ‖f x‖₊ ∂μ) ≤ I) : Integrable f μ := hφ.integrable_of_lintegral_nnnorm_bounded I hfm (by simpa only [ENNReal.ofReal_coe_nnreal] using hbounded) #align measure_theory.ae_cover.integrable_of_lintegral_nnnorm_bounded' MeasureTheory.AECover.integrable_of_lintegral_nnnorm_bounded' theorem AECover.integrable_of_lintegral_nnnorm_tendsto' [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖₊ ∂μ) l (𝓝 I)) : Integrable f μ := hφ.integrable_of_lintegral_nnnorm_tendsto I hfm (by simpa only [ENNReal.ofReal_coe_nnreal] using htendsto) #align measure_theory.ae_cover.integrable_of_lintegral_nnnorm_tendsto' MeasureTheory.AECover.integrable_of_lintegral_nnnorm_tendsto' theorem AECover.integrable_of_integral_norm_bounded [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hbounded : ∀ᶠ i in l, (∫ x in φ i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by have hfm : AEStronglyMeasurable f μ := hφ.aestronglyMeasurable fun i => (hfi i).aestronglyMeasurable refine hφ.integrable_of_lintegral_nnnorm_bounded I hfm ?_ conv at hbounded in integral _ _ => rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun x => @norm_nonneg E _ (f x)) hfm.norm.restrict] conv at hbounded in ENNReal.ofReal _ => rw [← coe_nnnorm] rw [ENNReal.ofReal_coe_nnreal] refine hbounded.mono fun i hi => ?_ rw [← ENNReal.ofReal_toReal (ne_top_of_lt (hfi i).2)] apply ENNReal.ofReal_le_ofReal hi #align measure_theory.ae_cover.integrable_of_integral_norm_bounded MeasureTheory.AECover.integrable_of_integral_norm_bounded theorem AECover.integrable_of_integral_norm_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (htendsto : Tendsto (fun i => ∫ x in φ i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le hφ.integrable_of_integral_norm_bounded I' hfi hI' #align measure_theory.ae_cover.integrable_of_integral_norm_tendsto MeasureTheory.AECover.integrable_of_integral_norm_tendsto theorem AECover.integrable_of_integral_bounded_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (hbounded : ∀ᶠ i in l, (∫ x in φ i, f x ∂μ) ≤ I) : Integrable f μ := hφ.integrable_of_integral_norm_bounded I hfi <| hbounded.mono fun _i hi => (integral_congr_ae <| ae_restrict_of_ae <| hnng.mono fun _ => Real.norm_of_nonneg).le.trans hi #align measure_theory.ae_cover.integrable_of_integral_bounded_of_nonneg_ae MeasureTheory.AECover.integrable_of_integral_bounded_of_nonneg_ae theorem AECover.integrable_of_integral_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (htendsto : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le hφ.integrable_of_integral_bounded_of_nonneg_ae I' hfi hnng hI' #align measure_theory.ae_cover.integrable_of_integral_tendsto_of_nonneg_ae MeasureTheory.AECover.integrable_of_integral_tendsto_of_nonneg_ae end Integrable section Integral variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] theorem AECover.integral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (hfi : Integrable f μ) : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := suffices h : Tendsto (fun i => ∫ x : α, (φ i).indicator f x ∂μ) l (𝓝 (∫ x : α, f x ∂μ)) from by convert h using 2; rw [integral_indicator (hφ.measurableSet _)] tendsto_integral_filter_of_dominated_convergence (fun x => ‖f x‖) (eventually_of_forall fun i => hfi.aestronglyMeasurable.indicator <| hφ.measurableSet i) (eventually_of_forall fun i => ae_of_all _ fun x => norm_indicator_le_norm_self _ _) hfi.norm (hφ.ae_tendsto_indicator f) #align measure_theory.ae_cover.integral_tendsto_of_countably_generated MeasureTheory.AECover.integral_tendsto_of_countably_generated /-- Slight reformulation of `MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/ theorem AECover.integral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : E) (hfi : Integrable f μ) (h : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := tendsto_nhds_unique (hφ.integral_tendsto_of_countably_generated hfi) h #align measure_theory.ae_cover.integral_eq_of_tendsto MeasureTheory.AECover.integral_eq_of_tendsto theorem AECover.integral_eq_of_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hnng : 0 ≤ᵐ[μ] f) (hfi : ∀ n, IntegrableOn f (φ n) μ) (htendsto : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := have hfi' : Integrable f μ := hφ.integrable_of_integral_tendsto_of_nonneg_ae I hfi hnng htendsto hφ.integral_eq_of_tendsto I hfi' htendsto #align measure_theory.ae_cover.integral_eq_of_tendsto_of_nonneg_ae MeasureTheory.AECover.integral_eq_of_tendsto_of_nonneg_ae end Integral section IntegrableOfIntervalIntegral variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [Filter.NeBot l] [IsCountablyGenerated l] [NormedAddCommGroup E] {a b : ι → ℝ} {f : ℝ → E} theorem integrable_of_intervalIntegral_norm_bounded (I : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a i..b i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by have hφ : AECover μ l _ := aecover_Ioc ha hb refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [ha.eventually (eventually_le_atBot 0), hb.eventually (eventually_ge_atTop 0)] with i hai hbi ht rwa [← intervalIntegral.integral_of_le (hai.trans hbi)] #align measure_theory.integrable_of_interval_integral_norm_bounded MeasureTheory.integrable_of_intervalIntegral_norm_bounded /-- If `f` is integrable on intervals `Ioc (a i) (b i)`, where `a i` tends to -∞ and `b i` tends to ∞, and `∫ x in a i .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, ∞) -/ theorem integrable_of_intervalIntegral_norm_tendsto (I : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a i..b i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrable_of_intervalIntegral_norm_bounded I' hfi ha hb hI' #align measure_theory.integrable_of_interval_integral_norm_tendsto MeasureTheory.integrable_of_intervalIntegral_norm_tendsto theorem integrableOn_Iic_of_intervalIntegral_norm_bounded (I b : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot) (h : ∀ᶠ i in l, (∫ x in a i..b, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Iic b) μ := by have hφ : AECover (μ.restrict <| Iic b) l _ := aecover_Ioi ha have hfi : ∀ i, IntegrableOn f (Ioi (a i)) (μ.restrict <| Iic b) := by intro i rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i)] exact hfi i refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [ha.eventually (eventually_le_atBot b)] with i hai rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)] exact id #align measure_theory.integrable_on_Iic_of_interval_integral_norm_bounded MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_bounded /-- If `f` is integrable on intervals `Ioc (a i) b`, where `a i` tends to -∞, and `∫ x in a i .. b, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, b) -/ theorem integrableOn_Iic_of_intervalIntegral_norm_tendsto (I b : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot) (h : Tendsto (fun i => ∫ x in a i..b, ‖f x‖ ∂μ) l (𝓝 I)) : IntegrableOn f (Iic b) μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrableOn_Iic_of_intervalIntegral_norm_bounded I' b hfi ha hI' #align measure_theory.integrable_on_Iic_of_interval_integral_norm_tendsto MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_tendsto theorem integrableOn_Ioi_of_intervalIntegral_norm_bounded (I a : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a..b i, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Ioi a) μ := by have hφ : AECover (μ.restrict <| Ioi a) l _ := aecover_Iic hb have hfi : ∀ i, IntegrableOn f (Iic (b i)) (μ.restrict <| Ioi a) := by intro i rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] exact hfi i refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [hb.eventually (eventually_ge_atTop a)] with i hbi rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] exact id #align measure_theory.integrable_on_Ioi_of_interval_integral_norm_bounded MeasureTheory.integrableOn_Ioi_of_intervalIntegral_norm_bounded /-- If `f` is integrable on intervals `Ioc a (b i)`, where `b i` tends to ∞, and `∫ x in a .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (a, ∞) -/ theorem integrableOn_Ioi_of_intervalIntegral_norm_tendsto (I a : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a..b i, ‖f x‖ ∂μ) l (𝓝 <| I)) : IntegrableOn f (Ioi a) μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrableOn_Ioi_of_intervalIntegral_norm_bounded I' a hfi hb hI' #align measure_theory.integrable_on_Ioi_of_interval_integral_norm_tendsto MeasureTheory.integrableOn_Ioi_of_intervalIntegral_norm_tendsto theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded {I a₀ b₀ : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc (a i) (b i)) (ha : Tendsto a l <| 𝓝 a₀) (hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b₀) := by refine (aecover_Ioc_of_Ioc ha hb).integrable_of_integral_norm_bounded I (fun i => (hfi i).restrict measurableSet_Ioc) (h.mono fun i hi ↦ ?_) rw [Measure.restrict_restrict measurableSet_Ioc] refine le_trans (setIntegral_mono_set (hfi i).norm ?_ ?_) hi <;> apply ae_of_all · simp only [Pi.zero_apply, norm_nonneg, forall_const] · intro c hc; exact hc.1 #align measure_theory.integrable_on_Ioc_of_interval_integral_norm_bounded MeasureTheory.integrableOn_Ioc_of_intervalIntegral_norm_bounded theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_left {I a₀ b : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc (a i) b) (ha : Tendsto a l <| 𝓝 a₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) b, ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b) := integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi ha tendsto_const_nhds h #align measure_theory.integrable_on_Ioc_of_interval_integral_norm_bounded_left MeasureTheory.integrableOn_Ioc_of_intervalIntegral_norm_bounded_left theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_right {I a b₀ : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc a (b i)) (hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc a (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a b₀) := integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi tendsto_const_nhds hb h #align measure_theory.integrable_on_Ioc_of_interval_integral_norm_bounded_right MeasureTheory.integrableOn_Ioc_of_intervalIntegral_norm_bounded_right @[deprecated (since := "2024-04-06")] alias integrableOn_Ioc_of_interval_integral_norm_bounded := integrableOn_Ioc_of_intervalIntegral_norm_bounded @[deprecated (since := "2024-04-06")] alias integrableOn_Ioc_of_interval_integral_norm_bounded_left := integrableOn_Ioc_of_intervalIntegral_norm_bounded_left @[deprecated (since := "2024-04-06")] alias integrableOn_Ioc_of_interval_integral_norm_bounded_right := integrableOn_Ioc_of_intervalIntegral_norm_bounded_right end IntegrableOfIntervalIntegral section IntegralOfIntervalIntegral variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [IsCountablyGenerated l] [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {a b : ι → ℝ} {f : ℝ → E} theorem intervalIntegral_tendsto_integral (hfi : Integrable f μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a i..b i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := by let φ i := Ioc (a i) (b i) have hφ : AECover μ l φ := aecover_Ioc ha hb refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [ha.eventually (eventually_le_atBot 0), hb.eventually (eventually_ge_atTop 0)] with i hai hbi exact (intervalIntegral.integral_of_le (hai.trans hbi)).symm #align measure_theory.interval_integral_tendsto_integral MeasureTheory.intervalIntegral_tendsto_integral theorem intervalIntegral_tendsto_integral_Iic (b : ℝ) (hfi : IntegrableOn f (Iic b) μ) (ha : Tendsto a l atBot) : Tendsto (fun i => ∫ x in a i..b, f x ∂μ) l (𝓝 <| ∫ x in Iic b, f x ∂μ) := by let φ i := Ioi (a i) have hφ : AECover (μ.restrict <| Iic b) l φ := aecover_Ioi ha refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [ha.eventually (eventually_le_atBot <| b)] with i hai rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)] rfl #align measure_theory.interval_integral_tendsto_integral_Iic MeasureTheory.intervalIntegral_tendsto_integral_Iic theorem intervalIntegral_tendsto_integral_Ioi (a : ℝ) (hfi : IntegrableOn f (Ioi a) μ) (hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a..b i, f x ∂μ) l (𝓝 <| ∫ x in Ioi a, f x ∂μ) := by let φ i := Iic (b i) have hφ : AECover (μ.restrict <| Ioi a) l φ := aecover_Iic hb refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [hb.eventually (eventually_ge_atTop <| a)] with i hbi rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] rfl #align measure_theory.interval_integral_tendsto_integral_Ioi MeasureTheory.intervalIntegral_tendsto_integral_Ioi end IntegralOfIntervalIntegral open Real open scoped Interval section IoiFTC variable {E : Type*} {f f' : ℝ → E} {g g' : ℝ → ℝ} {a b l : ℝ} {m : E} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- If the derivative of a function defined on the real line is integrable close to `+∞`, then the function has a limit at `+∞`. -/ theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi [CompleteSpace E] (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) : Tendsto f atTop (𝓝 (limUnder atTop f)) := by suffices ∃ a, Tendsto f atTop (𝓝 a) from tendsto_nhds_limUnder this suffices CauchySeq f from cauchySeq_tendsto_of_complete this apply Metric.cauchySeq_iff'.2 (fun ε εpos ↦ ?_) have A : ∀ᶠ (n : ℕ) in atTop, ∫ (x : ℝ) in Ici ↑n, ‖f' x‖ < ε := by have L : Tendsto (fun (n : ℕ) ↦ ∫ x in Ici (n : ℝ), ‖f' x‖) atTop (𝓝 (∫ x in ⋂ (n : ℕ), Ici (n : ℝ), ‖f' x‖)) := by apply tendsto_setIntegral_of_antitone (fun n ↦ measurableSet_Ici) · intro m n hmn exact Ici_subset_Ici.2 (Nat.cast_le.mpr hmn) · rcases exists_nat_gt a with ⟨n, hn⟩ exact ⟨n, IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 hn)⟩ have B : ⋂ (n : ℕ), Ici (n : ℝ) = ∅ := by apply eq_empty_of_forall_not_mem (fun x ↦ ?_) simpa only [mem_iInter, mem_Ici, not_forall, not_le] using exists_nat_gt x simp only [B, Measure.restrict_empty, integral_zero_measure] at L exact (tendsto_order.1 L).2 _ εpos have B : ∀ᶠ (n : ℕ) in atTop, a < n := by rcases exists_nat_gt a with ⟨n, hn⟩ filter_upwards [Ioi_mem_atTop n] with m (hm : n < m) using hn.trans (Nat.cast_lt.mpr hm) rcases (A.and B).exists with ⟨N, hN, h'N⟩ refine ⟨N, fun x hx ↦ ?_⟩ calc dist (f x) (f ↑N) = ‖f x - f N‖ := dist_eq_norm _ _ _ = ‖∫ t in Ioc ↑N x, f' t‖ := by rw [← intervalIntegral.integral_of_le hx, intervalIntegral.integral_eq_sub_of_hasDerivAt] · intro y hy simp only [hx, uIcc_of_le, mem_Icc] at hy exact hderiv _ (h'N.trans_le hy.1) · rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hx] exact f'int.mono_set (Ioc_subset_Ioi_self.trans (Ioi_subset_Ioi h'N.le)) _ ≤ ∫ t in Ioc ↑N x, ‖f' t‖ := norm_integral_le_integral_norm fun a ↦ f' a _ ≤ ∫ t in Ici ↑N, ‖f' t‖ := by apply setIntegral_mono_set · apply IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 h'N) · filter_upwards with x using norm_nonneg _ · have : Ioc (↑N) x ⊆ Ici ↑N := Ioc_subset_Ioi_self.trans Ioi_subset_Ici_self exact this.eventuallyLE _ < ε := hN open UniformSpace in /-- If a function and its derivative are integrable on `(a, +∞)`, then the function tends to zero at `+∞`. -/ theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (fint : IntegrableOn f (Ioi a)) : Tendsto f atTop (𝓝 0) := by let F : E →L[ℝ] Completion E := Completion.toComplL have Fderiv : ∀ x ∈ Ioi a, HasDerivAt (F ∘ f) (F (f' x)) x := fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx) have Fint : IntegrableOn (F ∘ f) (Ioi a) := by apply F.integrable_comp fint have F'int : IntegrableOn (F ∘ f') (Ioi a) := by apply F.integrable_comp f'int have A : Tendsto (F ∘ f) atTop (𝓝 (limUnder atTop (F ∘ f))) := by apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi Fderiv F'int have B : limUnder atTop (F ∘ f) = F 0 := by have : IntegrableAtFilter (F ∘ f) atTop := by exact ⟨Ioi a, Ioi_mem_atTop _, Fint⟩ apply IntegrableAtFilter.eq_zero_of_tendsto this ?_ A intro s hs rcases mem_atTop_sets.1 hs with ⟨b, hb⟩ rw [← top_le_iff, ← volume_Ici (a := b)] exact measure_mono hb rwa [B, ← Embedding.tendsto_nhds_iff] at A exact (Completion.uniformEmbedding_coe E).embedding variable [CompleteSpace E] /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`. When a function has a limit at infinity `m`, and its derivative is integrable, then the integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. Note that such a function always has a limit at infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/
Mathlib/MeasureTheory/Integral/IntegralEqImproper.lean
781
798
theorem integral_Ioi_of_hasDerivAt_of_tendsto (hcont : ContinuousWithinAt f (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (hf : Tendsto f atTop (𝓝 m)) : ∫ x in Ioi a, f' x = m - f a := by
have hcont : ContinuousOn f (Ici a) := by intro x hx rcases hx.out.eq_or_lt with rfl|hx · exact hcont · exact (hderiv x hx).continuousAt.continuousWithinAt refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Ioi a f'int tendsto_id) ?_ apply Tendsto.congr' _ (hf.sub_const _) filter_upwards [Ioi_mem_atTop a] with x hx have h'x : a ≤ id x := le_of_lt hx symm apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x (hcont.mono Icc_subset_Ici_self) fun y hy => hderiv y hy.1 rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x] exact f'int.mono (fun y hy => hy.1) le_rfl
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Data.Fintype.Card import Mathlib.Data.Set.Finite import Mathlib.Data.Set.Pointwise.SMul import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.GroupAction.Defs import Mathlib.GroupTheory.GroupAction.Group #align_import group_theory.group_action.basic from "leanprover-community/mathlib"@"d30d31261cdb4d2f5e612eabc3c4bf45556350d5" /-! # Basic properties of group actions This file primarily concerns itself with orbits, stabilizers, and other objects defined in terms of actions. Despite this file being called `basic`, low-level helper lemmas for algebraic manipulation of `•` belong elsewhere. ## Main definitions * `MulAction.orbit` * `MulAction.fixedPoints` * `MulAction.fixedBy` * `MulAction.stabilizer` -/ universe u v open Pointwise open Function namespace MulAction variable (M : Type u) [Monoid M] (α : Type v) [MulAction M α] section Orbit variable {α} /-- The orbit of an element under an action. -/ @[to_additive "The orbit of an element under an action."] def orbit (a : α) := Set.range fun m : M => m • a #align mul_action.orbit MulAction.orbit #align add_action.orbit AddAction.orbit variable {M} @[to_additive] theorem mem_orbit_iff {a₁ a₂ : α} : a₂ ∈ orbit M a₁ ↔ ∃ x : M, x • a₁ = a₂ := Iff.rfl #align mul_action.mem_orbit_iff MulAction.mem_orbit_iff #align add_action.mem_orbit_iff AddAction.mem_orbit_iff @[to_additive (attr := simp)] theorem mem_orbit (a : α) (m : M) : m • a ∈ orbit M a := ⟨m, rfl⟩ #align mul_action.mem_orbit MulAction.mem_orbit #align add_action.mem_orbit AddAction.mem_orbit @[to_additive (attr := simp)] theorem mem_orbit_self (a : α) : a ∈ orbit M a := ⟨1, by simp [MulAction.one_smul]⟩ #align mul_action.mem_orbit_self MulAction.mem_orbit_self #align add_action.mem_orbit_self AddAction.mem_orbit_self @[to_additive] theorem orbit_nonempty (a : α) : Set.Nonempty (orbit M a) := Set.range_nonempty _ #align mul_action.orbit_nonempty MulAction.orbit_nonempty #align add_action.orbit_nonempty AddAction.orbit_nonempty @[to_additive] theorem mapsTo_smul_orbit (m : M) (a : α) : Set.MapsTo (m • ·) (orbit M a) (orbit M a) := Set.range_subset_iff.2 fun m' => ⟨m * m', mul_smul _ _ _⟩ #align mul_action.maps_to_smul_orbit MulAction.mapsTo_smul_orbit #align add_action.maps_to_vadd_orbit AddAction.mapsTo_vadd_orbit @[to_additive] theorem smul_orbit_subset (m : M) (a : α) : m • orbit M a ⊆ orbit M a := (mapsTo_smul_orbit m a).image_subset #align mul_action.smul_orbit_subset MulAction.smul_orbit_subset #align add_action.vadd_orbit_subset AddAction.vadd_orbit_subset @[to_additive] theorem orbit_smul_subset (m : M) (a : α) : orbit M (m • a) ⊆ orbit M a := Set.range_subset_iff.2 fun m' => mul_smul m' m a ▸ mem_orbit _ _ #align mul_action.orbit_smul_subset MulAction.orbit_smul_subset #align add_action.orbit_vadd_subset AddAction.orbit_vadd_subset @[to_additive] instance {a : α} : MulAction M (orbit M a) where smul m := (mapsTo_smul_orbit m a).restrict _ _ _ one_smul m := Subtype.ext (one_smul M (m : α)) mul_smul m m' a' := Subtype.ext (mul_smul m m' (a' : α)) @[to_additive (attr := simp)] theorem orbit.coe_smul {a : α} {m : M} {a' : orbit M a} : ↑(m • a') = m • (a' : α) := rfl #align mul_action.orbit.coe_smul MulAction.orbit.coe_smul #align add_action.orbit.coe_vadd AddAction.orbit.coe_vadd @[to_additive] lemma orbit_submonoid_subset (S : Submonoid M) (a : α) : orbit S a ⊆ orbit M a := by rintro b ⟨g, rfl⟩ exact mem_orbit _ _ @[to_additive] lemma mem_orbit_of_mem_orbit_submonoid {S : Submonoid M} {a b : α} (h : a ∈ orbit S b) : a ∈ orbit M b := orbit_submonoid_subset S _ h variable (M) @[to_additive] theorem orbit_eq_univ [IsPretransitive M α] (a : α) : orbit M a = Set.univ := (surjective_smul M a).range_eq #align mul_action.orbit_eq_univ MulAction.orbit_eq_univ #align add_action.orbit_eq_univ AddAction.orbit_eq_univ end Orbit section FixedPoints /-- The set of elements fixed under the whole action. -/ @[to_additive "The set of elements fixed under the whole action."] def fixedPoints : Set α := { a : α | ∀ m : M, m • a = a } #align mul_action.fixed_points MulAction.fixedPoints #align add_action.fixed_points AddAction.fixedPoints variable {M} /-- `fixedBy m` is the set of elements fixed by `m`. -/ @[to_additive "`fixedBy m` is the set of elements fixed by `m`."] def fixedBy (m : M) : Set α := { x | m • x = x } #align mul_action.fixed_by MulAction.fixedBy #align add_action.fixed_by AddAction.fixedBy variable (M) @[to_additive] theorem fixed_eq_iInter_fixedBy : fixedPoints M α = ⋂ m : M, fixedBy α m := Set.ext fun _ => ⟨fun hx => Set.mem_iInter.2 fun m => hx m, fun hx m => (Set.mem_iInter.1 hx m : _)⟩ #align mul_action.fixed_eq_Inter_fixed_by MulAction.fixed_eq_iInter_fixedBy #align add_action.fixed_eq_Inter_fixed_by AddAction.fixed_eq_iInter_fixedBy variable {M α} @[to_additive (attr := simp)] theorem mem_fixedPoints {a : α} : a ∈ fixedPoints M α ↔ ∀ m : M, m • a = a := Iff.rfl #align mul_action.mem_fixed_points MulAction.mem_fixedPoints #align add_action.mem_fixed_points AddAction.mem_fixedPoints @[to_additive (attr := simp)] theorem mem_fixedBy {m : M} {a : α} : a ∈ fixedBy α m ↔ m • a = a := Iff.rfl #align mul_action.mem_fixed_by MulAction.mem_fixedBy #align add_action.mem_fixed_by AddAction.mem_fixedBy @[to_additive] theorem mem_fixedPoints' {a : α} : a ∈ fixedPoints M α ↔ ∀ a', a' ∈ orbit M a → a' = a := ⟨fun h _ h₁ => let ⟨m, hm⟩ := mem_orbit_iff.1 h₁ hm ▸ h m, fun h _ => h _ (mem_orbit _ _)⟩ #align mul_action.mem_fixed_points' MulAction.mem_fixedPoints' #align add_action.mem_fixed_points' AddAction.mem_fixedPoints' @[to_additive mem_fixedPoints_iff_card_orbit_eq_one] theorem mem_fixedPoints_iff_card_orbit_eq_one {a : α} [Fintype (orbit M a)] : a ∈ fixedPoints M α ↔ Fintype.card (orbit M a) = 1 := by rw [Fintype.card_eq_one_iff, mem_fixedPoints] constructor · exact fun h => ⟨⟨a, mem_orbit_self _⟩, fun ⟨a, ⟨x, hx⟩⟩ => Subtype.eq <| by simp [h x, hx.symm]⟩ · intro h x rcases h with ⟨⟨z, hz⟩, hz₁⟩ calc x • a = z := Subtype.mk.inj (hz₁ ⟨x • a, mem_orbit _ _⟩) _ = a := (Subtype.mk.inj (hz₁ ⟨a, mem_orbit_self _⟩)).symm #align mul_action.mem_fixed_points_iff_card_orbit_eq_one MulAction.mem_fixedPoints_iff_card_orbit_eq_one #align add_action.mem_fixed_points_iff_card_orbit_eq_zero AddAction.mem_fixedPoints_iff_card_orbit_eq_one end FixedPoints section Stabilizers variable {α} /-- The stabilizer of a point `a` as a submonoid of `M`. -/ @[to_additive "The stabilizer of a point `a` as an additive submonoid of `M`."] def stabilizerSubmonoid (a : α) : Submonoid M where carrier := { m | m • a = a } one_mem' := one_smul _ a mul_mem' {m m'} (ha : m • a = a) (hb : m' • a = a) := show (m * m') • a = a by rw [← smul_smul, hb, ha] #align mul_action.stabilizer.submonoid MulAction.stabilizerSubmonoid #align add_action.stabilizer.add_submonoid AddAction.stabilizerAddSubmonoid variable {M} @[to_additive] instance [DecidableEq α] (a : α) : DecidablePred (· ∈ stabilizerSubmonoid M a) := fun _ => inferInstanceAs <| Decidable (_ = _) @[to_additive (attr := simp)] theorem mem_stabilizerSubmonoid_iff {a : α} {m : M} : m ∈ stabilizerSubmonoid M a ↔ m • a = a := Iff.rfl #align mul_action.mem_stabilizer_submonoid_iff MulAction.mem_stabilizerSubmonoid_iff #align add_action.mem_stabilizer_add_submonoid_iff AddAction.mem_stabilizerAddSubmonoid_iff end Stabilizers end MulAction section FixedPoints variable (M : Type u) (α : Type v) [Monoid M] section Monoid variable [Monoid α] [MulDistribMulAction M α] /-- The submonoid of elements fixed under the whole action. -/ def FixedPoints.submonoid : Submonoid α where carrier := MulAction.fixedPoints M α one_mem' := smul_one mul_mem' ha hb _ := by rw [smul_mul', ha, hb] @[simp] lemma FixedPoints.mem_submonoid (a : α) : a ∈ submonoid M α ↔ ∀ m : M, m • a = a := Iff.rfl end Monoid section Group namespace FixedPoints variable [Group α] [MulDistribMulAction M α] /-- The subgroup of elements fixed under the whole action. -/ def subgroup : Subgroup α where __ := submonoid M α inv_mem' ha _ := by rw [smul_inv', ha] /-- The notation for `FixedPoints.subgroup`, chosen to resemble `αᴹ`. -/ scoped notation α "^*" M:51 => FixedPoints.subgroup M α @[simp] lemma mem_subgroup (a : α) : a ∈ α^*M ↔ ∀ m : M, m • a = a := Iff.rfl @[simp] lemma subgroup_toSubmonoid : (α^*M).toSubmonoid = submonoid M α := rfl end FixedPoints end Group section AddMonoid variable [AddMonoid α] [DistribMulAction M α] /-- The additive submonoid of elements fixed under the whole action. -/ def FixedPoints.addSubmonoid : AddSubmonoid α where carrier := MulAction.fixedPoints M α zero_mem' := smul_zero add_mem' ha hb _ := by rw [smul_add, ha, hb] @[simp] lemma FixedPoints.mem_addSubmonoid (a : α) : a ∈ addSubmonoid M α ↔ ∀ m : M, m • a = a := Iff.rfl end AddMonoid section AddGroup variable [AddGroup α] [DistribMulAction M α] /-- The additive subgroup of elements fixed under the whole action. -/ def FixedPoints.addSubgroup : AddSubgroup α where __ := addSubmonoid M α neg_mem' ha _ := by rw [smul_neg, ha] /-- The notation for `FixedPoints.addSubgroup`, chosen to resemble `αᴹ`. -/ notation α "^+" M:51 => FixedPoints.addSubgroup M α @[simp] lemma FixedPoints.mem_addSubgroup (a : α) : a ∈ α^+M ↔ ∀ m : M, m • a = a := Iff.rfl @[simp] lemma FixedPoints.addSubgroup_toAddSubmonoid : (α^+M).toAddSubmonoid = addSubmonoid M α := rfl end AddGroup end FixedPoints /-- `smul` by a `k : M` over a ring is injective, if `k` is not a zero divisor. The general theory of such `k` is elaborated by `IsSMulRegular`. The typeclass that restricts all terms of `M` to have this property is `NoZeroSMulDivisors`. -/ theorem smul_cancel_of_non_zero_divisor {M R : Type*} [Monoid M] [NonUnitalNonAssocRing R] [DistribMulAction M R] (k : M) (h : ∀ x : R, k • x = 0 → x = 0) {a b : R} (h' : k • a = k • b) : a = b := by rw [← sub_eq_zero] refine h _ ?_ rw [smul_sub, h', sub_self] #align smul_cancel_of_non_zero_divisor smul_cancel_of_non_zero_divisor namespace MulAction variable {G α β : Type*} [Group G] [MulAction G α] [MulAction G β] section Orbit @[to_additive (attr := simp)] theorem smul_orbit (g : G) (a : α) : g • orbit G a = orbit G a := (smul_orbit_subset g a).antisymm <| calc orbit G a = g • g⁻¹ • orbit G a := (smul_inv_smul _ _).symm _ ⊆ g • orbit G a := Set.image_subset _ (smul_orbit_subset _ _) #align mul_action.smul_orbit MulAction.smul_orbit #align add_action.vadd_orbit AddAction.vadd_orbit @[to_additive (attr := simp)] theorem orbit_smul (g : G) (a : α) : orbit G (g • a) = orbit G a := (orbit_smul_subset g a).antisymm <| calc orbit G a = orbit G (g⁻¹ • g • a) := by rw [inv_smul_smul] _ ⊆ orbit G (g • a) := orbit_smul_subset _ _ #align mul_action.orbit_smul MulAction.orbit_smul #align add_action.orbit_vadd AddAction.orbit_vadd /-- The action of a group on an orbit is transitive. -/ @[to_additive "The action of an additive group on an orbit is transitive."] instance (a : α) : IsPretransitive G (orbit G a) := ⟨by rintro ⟨_, g, rfl⟩ ⟨_, h, rfl⟩ use h * g⁻¹ ext1 simp [mul_smul]⟩ @[to_additive] theorem orbit_eq_iff {a b : α} : orbit G a = orbit G b ↔ a ∈ orbit G b := ⟨fun h => h ▸ mem_orbit_self _, fun ⟨_, hc⟩ => hc ▸ orbit_smul _ _⟩ #align mul_action.orbit_eq_iff MulAction.orbit_eq_iff #align add_action.orbit_eq_iff AddAction.orbit_eq_iff @[to_additive] theorem mem_orbit_smul (g : G) (a : α) : a ∈ orbit G (g • a) := by simp only [orbit_smul, mem_orbit_self] #align mul_action.mem_orbit_smul MulAction.mem_orbit_smul #align add_action.mem_orbit_vadd AddAction.mem_orbit_vadd @[to_additive] theorem smul_mem_orbit_smul (g h : G) (a : α) : g • a ∈ orbit G (h • a) := by simp only [orbit_smul, mem_orbit] #align mul_action.smul_mem_orbit_smul MulAction.smul_mem_orbit_smul #align add_action.vadd_mem_orbit_vadd AddAction.vadd_mem_orbit_vadd @[to_additive] lemma orbit_subgroup_subset (H : Subgroup G) (a : α) : orbit H a ⊆ orbit G a := orbit_submonoid_subset H.toSubmonoid a @[to_additive] lemma mem_orbit_of_mem_orbit_subgroup {H : Subgroup G} {a b : α} (h : a ∈ orbit H b) : a ∈ orbit G b := orbit_subgroup_subset H _ h @[to_additive] lemma mem_orbit_symm {a₁ a₂ : α} : a₁ ∈ orbit G a₂ ↔ a₂ ∈ orbit G a₁ := by simp_rw [← orbit_eq_iff, eq_comm] @[to_additive] lemma mem_subgroup_orbit_iff {H : Subgroup G} {x : α} {a b : orbit G x} : a ∈ MulAction.orbit H b ↔ (a : α) ∈ MulAction.orbit H (b : α) := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h with ⟨g, rfl⟩ simp_rw [Submonoid.smul_def, Subgroup.coe_toSubmonoid, orbit.coe_smul, ← Submonoid.smul_def] exact MulAction.mem_orbit _ g · rcases h with ⟨g, h⟩ simp_rw [Submonoid.smul_def, Subgroup.coe_toSubmonoid, ← orbit.coe_smul, ← Submonoid.smul_def, ← Subtype.ext_iff] at h subst h exact MulAction.mem_orbit _ g variable (G α) /-- The relation 'in the same orbit'. -/ @[to_additive "The relation 'in the same orbit'."] def orbitRel : Setoid α where r a b := a ∈ orbit G b iseqv := ⟨mem_orbit_self, fun {a b} => by simp [orbit_eq_iff.symm, eq_comm], fun {a b} => by simp (config := { contextual := true }) [orbit_eq_iff.symm, eq_comm]⟩ #align mul_action.orbit_rel MulAction.orbitRel #align add_action.orbit_rel AddAction.orbitRel variable {G α} @[to_additive] theorem orbitRel_apply {a b : α} : (orbitRel G α).Rel a b ↔ a ∈ orbit G b := Iff.rfl #align mul_action.orbit_rel_apply MulAction.orbitRel_apply #align add_action.orbit_rel_apply AddAction.orbitRel_apply @[to_additive] lemma orbitRel_r_apply {a b : α} : (orbitRel G _).r a b ↔ a ∈ orbit G b := Iff.rfl @[to_additive] lemma orbitRel_subgroup_le (H : Subgroup G) : orbitRel H α ≤ orbitRel G α := Setoid.le_def.2 mem_orbit_of_mem_orbit_subgroup /-- When you take a set `U` in `α`, push it down to the quotient, and pull back, you get the union of the orbit of `U` under `G`. -/ @[to_additive "When you take a set `U` in `α`, push it down to the quotient, and pull back, you get the union of the orbit of `U` under `G`."] theorem quotient_preimage_image_eq_union_mul (U : Set α) : letI := orbitRel G α Quotient.mk' ⁻¹' (Quotient.mk' '' U) = ⋃ g : G, (g • ·) '' U := by letI := orbitRel G α set f : α → Quotient (MulAction.orbitRel G α) := Quotient.mk' ext a constructor · rintro ⟨b, hb, hab⟩ obtain ⟨g, rfl⟩ := Quotient.exact hab rw [Set.mem_iUnion] exact ⟨g⁻¹, g • a, hb, inv_smul_smul g a⟩ · intro hx rw [Set.mem_iUnion] at hx obtain ⟨g, u, hu₁, hu₂⟩ := hx rw [Set.mem_preimage, Set.mem_image] refine ⟨g⁻¹ • a, ?_, by simp only [f, Quotient.eq']; use g⁻¹⟩ rw [← hu₂] convert hu₁ simp only [inv_smul_smul] #align mul_action.quotient_preimage_image_eq_union_mul MulAction.quotient_preimage_image_eq_union_mul #align add_action.quotient_preimage_image_eq_union_add AddAction.quotient_preimage_image_eq_union_add @[to_additive]
Mathlib/GroupTheory/GroupAction/Basic.lean
452
465
theorem disjoint_image_image_iff {U V : Set α} : letI := orbitRel G α Disjoint (Quotient.mk' '' U) (Quotient.mk' '' V) ↔ ∀ x ∈ U, ∀ g : G, g • x ∉ V := by
letI := orbitRel G α set f : α → Quotient (MulAction.orbitRel G α) := Quotient.mk' refine ⟨fun h a a_in_U g g_in_V => h.le_bot ⟨⟨a, a_in_U, Quotient.sound ⟨g⁻¹, ?_⟩⟩, ⟨g • a, g_in_V, rfl⟩⟩, ?_⟩ · simp · intro h rw [Set.disjoint_left] rintro _ ⟨b, hb₁, hb₂⟩ ⟨c, hc₁, hc₂⟩ obtain ⟨g, rfl⟩ := Quotient.exact (hc₂.trans hb₂.symm) exact h b hb₁ g hc₁
/- 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.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.InvariantBasisNumber #align_import linear_algebra.dimension from "leanprover-community/mathlib"@"47a5f8186becdbc826190ced4312f8199f9db6a5" /-! # Lemmas about rank and finrank in rings satisfying strong rank condition. ## Main statements For modules over rings satisfying the rank condition * `Basis.le_span`: the cardinality of a basis is bounded by the cardinality of any spanning set For modules over rings satisfying the strong rank condition * `linearIndependent_le_span`: For any linearly independent family `v : ι → M` and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. * `linearIndependent_le_basis`: If `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. For modules over rings with invariant basis number (including all commutative rings and all noetherian rings) * `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same cardinality. -/ noncomputable section universe u v w w' variable {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [Module R M] variable {ι : Type w} {ι' : Type w'} open Cardinal Basis Submodule Function Set attribute [local instance] nontrivial_of_invariantBasisNumber section InvariantBasisNumber variable [InvariantBasisNumber R] /-- The dimension theorem: if `v` and `v'` are two bases, their index types have the same cardinalities. -/ theorem mk_eq_mk_of_basis (v : Basis ι R M) (v' : Basis ι' R M) : Cardinal.lift.{w'} #ι = Cardinal.lift.{w} #ι' := by classical haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite ι · -- `v` is a finite basis, so by `basis_finite_of_finite_spans` so is `v'`. -- haveI : Finite (range v) := Set.finite_range v haveI := basis_finite_of_finite_spans _ (Set.finite_range v) v.span_eq v' cases nonempty_fintype ι' -- We clean up a little: rw [Cardinal.mk_fintype, Cardinal.mk_fintype] simp only [Cardinal.lift_natCast, Cardinal.natCast_inj] -- Now we can use invariant basis number to show they have the same cardinality. apply card_eq_of_linearEquiv R exact (Finsupp.linearEquivFunOnFinite R R ι).symm.trans v.repr.symm ≪≫ₗ v'.repr ≪≫ₗ Finsupp.linearEquivFunOnFinite R R ι' · -- `v` is an infinite basis, -- so by `infinite_basis_le_maximal_linearIndependent`, `v'` is at least as big, -- and then applying `infinite_basis_le_maximal_linearIndependent` again -- we see they have the same cardinality. have w₁ := infinite_basis_le_maximal_linearIndependent' v _ v'.linearIndependent v'.maximal rcases Cardinal.lift_mk_le'.mp w₁ with ⟨f⟩ haveI : Infinite ι' := Infinite.of_injective f f.2 have w₂ := infinite_basis_le_maximal_linearIndependent' v' _ v.linearIndependent v.maximal exact le_antisymm w₁ w₂ #align mk_eq_mk_of_basis mk_eq_mk_of_basis /-- Given two bases indexed by `ι` and `ι'` of an `R`-module, where `R` satisfies the invariant basis number property, an equiv `ι ≃ ι'`. -/ def Basis.indexEquiv (v : Basis ι R M) (v' : Basis ι' R M) : ι ≃ ι' := (Cardinal.lift_mk_eq'.1 <| mk_eq_mk_of_basis v v').some #align basis.index_equiv Basis.indexEquiv theorem mk_eq_mk_of_basis' {ι' : Type w} (v : Basis ι R M) (v' : Basis ι' R M) : #ι = #ι' := Cardinal.lift_inj.1 <| mk_eq_mk_of_basis v v' #align mk_eq_mk_of_basis' mk_eq_mk_of_basis' end InvariantBasisNumber section RankCondition variable [RankCondition R] /-- An auxiliary lemma for `Basis.le_span`. If `R` satisfies the rank condition, then for any finite basis `b : Basis ι R M`, and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem Basis.le_span'' {ι : Type*} [Fintype ι] (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊤) : Fintype.card ι ≤ Fintype.card w := by -- We construct a surjective linear map `(w → R) →ₗ[R] (ι → R)`, -- by expressing a linear combination in `w` as a linear combination in `ι`. fapply card_le_of_surjective' R · exact b.repr.toLinearMap.comp (Finsupp.total w M R (↑)) · apply Surjective.comp (g := b.repr.toLinearMap) · apply LinearEquiv.surjective rw [← LinearMap.range_eq_top, Finsupp.range_total] simpa using s #align basis.le_span'' Basis.le_span'' /-- Another auxiliary lemma for `Basis.le_span`, which does not require assuming the basis is finite, but still assumes we have a finite spanning set. -/ theorem basis_le_span' {ι : Type*} (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊤) : #ι ≤ Fintype.card w := by haveI := nontrivial_of_invariantBasisNumber R haveI := basis_finite_of_finite_spans w (toFinite _) s b cases nonempty_fintype ι rw [Cardinal.mk_fintype ι] simp only [Cardinal.natCast_le] exact Basis.le_span'' b s #align basis_le_span' basis_le_span' -- Note that if `R` satisfies the strong rank condition, -- this also follows from `linearIndependent_le_span` below. /-- If `R` satisfies the rank condition, then the cardinality of any basis is bounded by the cardinality of any spanning set. -/ theorem Basis.le_span {J : Set M} (v : Basis ι R M) (hJ : span R J = ⊤) : #(range v) ≤ #J := by haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite J · rw [← Cardinal.lift_le, Cardinal.mk_range_eq_of_injective v.injective, Cardinal.mk_fintype J] convert Cardinal.lift_le.{v}.2 (basis_le_span' v hJ) simp · let S : J → Set ι := fun j => ↑(v.repr j).support let S' : J → Set M := fun j => v '' S j have hs : range v ⊆ ⋃ j, S' j := by intro b hb rcases mem_range.1 hb with ⟨i, hi⟩ have : span R J ≤ comap v.repr.toLinearMap (Finsupp.supported R R (⋃ j, S j)) := span_le.2 fun j hj x hx => ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩ rw [hJ] at this replace : v.repr (v i) ∈ Finsupp.supported R R (⋃ j, S j) := this trivial rw [v.repr_self, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ one_ne_zero] at this · subst b rcases mem_iUnion.1 (this (Finset.mem_singleton_self _)) with ⟨j, hj⟩ exact mem_iUnion.2 ⟨j, (mem_image _ _ _).2 ⟨i, hj, rfl⟩⟩ refine le_of_not_lt fun IJ => ?_ suffices #(⋃ j, S' j) < #(range v) by exact not_le_of_lt this ⟨Set.embeddingOfSubset _ _ hs⟩ refine lt_of_le_of_lt (le_trans Cardinal.mk_iUnion_le_sum_mk (Cardinal.sum_le_sum _ (fun _ => ℵ₀) ?_)) ?_ · exact fun j => (Cardinal.lt_aleph0_of_finite _).le · simpa #align basis.le_span Basis.le_span end RankCondition section StrongRankCondition variable [StrongRankCondition R] open Submodule -- An auxiliary lemma for `linearIndependent_le_span'`, -- with the additional assumption that the linearly independent family is finite. theorem linearIndependent_le_span_aux' {ι : Type*} [Fintype ι] (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≤ span R w) : Fintype.card ι ≤ Fintype.card w := by -- We construct an injective linear map `(ι → R) →ₗ[R] (w → R)`, -- by thinking of `f : ι → R` as a linear combination of the finite family `v`, -- and expressing that (using the axiom of choice) as a linear combination over `w`. -- We can do this linearly by constructing the map on a basis. fapply card_le_of_injective' R · apply Finsupp.total exact fun i => Span.repr R w ⟨v i, s (mem_range_self i)⟩ · intro f g h apply_fun Finsupp.total w M R (↑) at h simp only [Finsupp.total_total, Submodule.coe_mk, Span.finsupp_total_repr] at h rw [← sub_eq_zero, ← LinearMap.map_sub] at h exact sub_eq_zero.mp (linearIndependent_iff.mp i _ h) #align linear_independent_le_span_aux' linearIndependent_le_span_aux' /-- If `R` satisfies the strong rank condition, then any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, is itself finite. -/ lemma LinearIndependent.finite_of_le_span_finite {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Finite w] (s : range v ≤ span R w) : Finite ι := letI := Fintype.ofFinite w Fintype.finite <| fintypeOfFinsetCardLe (Fintype.card w) fun t => by let v' := fun x : (t : Set ι) => v x have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective have s' : range v' ≤ span R w := (range_comp_subset_range _ _).trans s simpa using linearIndependent_le_span_aux' v' i' w s' #align linear_independent_fintype_of_le_span_fintype LinearIndependent.finite_of_le_span_finite /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/
Mathlib/LinearAlgebra/Dimension/StrongRankCondition.lean
214
220
theorem linearIndependent_le_span' {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≤ span R w) : #ι ≤ Fintype.card w := by
haveI : Finite ι := i.finite_of_le_span_finite v w s letI := Fintype.ofFinite ι rw [Cardinal.mk_fintype] simp only [Cardinal.natCast_le] exact linearIndependent_le_span_aux' v i w s
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Induction #align_import data.polynomial.eval from "leanprover-community/mathlib"@"728baa2f54e6062c5879a3e397ac6bac323e506f" /-! # Theory of univariate polynomials The main defs here are `eval₂`, `eval`, and `map`. We give several lemmas about their interaction with each other and with module operations. -/ set_option linter.uppercaseLean3 false noncomputable section open Finset AddMonoidAlgebra open Polynomial namespace Polynomial universe u v w y variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} section variable [Semiring S] variable (f : R →+* S) (x : S) /-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring to the target and a value `x` for the variable in the target -/ irreducible_def eval₂ (p : R[X]) : S := p.sum fun e a => f a * x ^ e #align polynomial.eval₂ Polynomial.eval₂ theorem eval₂_eq_sum {f : R →+* S} {x : S} : p.eval₂ f x = p.sum fun e a => f a * x ^ e := by rw [eval₂_def] #align polynomial.eval₂_eq_sum Polynomial.eval₂_eq_sum theorem eval₂_congr {R S : Type*} [Semiring R] [Semiring S] {f g : R →+* S} {s t : S} {φ ψ : R[X]} : f = g → s = t → φ = ψ → eval₂ f s φ = eval₂ g t ψ := by rintro rfl rfl rfl; rfl #align polynomial.eval₂_congr Polynomial.eval₂_congr @[simp] theorem eval₂_at_zero : p.eval₂ f 0 = f (coeff p 0) := by simp (config := { contextual := true }) only [eval₂_eq_sum, zero_pow_eq, mul_ite, mul_zero, mul_one, sum, Classical.not_not, mem_support_iff, sum_ite_eq', ite_eq_left_iff, RingHom.map_zero, imp_true_iff, eq_self_iff_true] #align polynomial.eval₂_at_zero Polynomial.eval₂_at_zero @[simp] theorem eval₂_zero : (0 : R[X]).eval₂ f x = 0 := by simp [eval₂_eq_sum] #align polynomial.eval₂_zero Polynomial.eval₂_zero @[simp] theorem eval₂_C : (C a).eval₂ f x = f a := by simp [eval₂_eq_sum] #align polynomial.eval₂_C Polynomial.eval₂_C @[simp] theorem eval₂_X : X.eval₂ f x = x := by simp [eval₂_eq_sum] #align polynomial.eval₂_X Polynomial.eval₂_X @[simp] theorem eval₂_monomial {n : ℕ} {r : R} : (monomial n r).eval₂ f x = f r * x ^ n := by simp [eval₂_eq_sum] #align polynomial.eval₂_monomial Polynomial.eval₂_monomial @[simp] theorem eval₂_X_pow {n : ℕ} : (X ^ n).eval₂ f x = x ^ n := by rw [X_pow_eq_monomial] convert eval₂_monomial f x (n := n) (r := 1) simp #align polynomial.eval₂_X_pow Polynomial.eval₂_X_pow @[simp] theorem eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x := by simp only [eval₂_eq_sum] apply sum_add_index <;> simp [add_mul] #align polynomial.eval₂_add Polynomial.eval₂_add @[simp] theorem eval₂_one : (1 : R[X]).eval₂ f x = 1 := by rw [← C_1, eval₂_C, f.map_one] #align polynomial.eval₂_one Polynomial.eval₂_one set_option linter.deprecated false in @[simp] theorem eval₂_bit0 : (bit0 p).eval₂ f x = bit0 (p.eval₂ f x) := by rw [bit0, eval₂_add, bit0] #align polynomial.eval₂_bit0 Polynomial.eval₂_bit0 set_option linter.deprecated false in @[simp] theorem eval₂_bit1 : (bit1 p).eval₂ f x = bit1 (p.eval₂ f x) := by rw [bit1, eval₂_add, eval₂_bit0, eval₂_one, bit1] #align polynomial.eval₂_bit1 Polynomial.eval₂_bit1 @[simp] theorem eval₂_smul (g : R →+* S) (p : R[X]) (x : S) {s : R} : eval₂ g x (s • p) = g s * eval₂ g x p := by have A : p.natDegree < p.natDegree.succ := Nat.lt_succ_self _ have B : (s • p).natDegree < p.natDegree.succ := (natDegree_smul_le _ _).trans_lt A rw [eval₂_eq_sum, eval₂_eq_sum, sum_over_range' _ _ _ A, sum_over_range' _ _ _ B] <;> simp [mul_sum, mul_assoc] #align polynomial.eval₂_smul Polynomial.eval₂_smul @[simp] theorem eval₂_C_X : eval₂ C X p = p := Polynomial.induction_on' p (fun p q hp hq => by simp [hp, hq]) fun n x => by rw [eval₂_monomial, ← smul_X_eq_monomial, C_mul'] #align polynomial.eval₂_C_X Polynomial.eval₂_C_X /-- `eval₂AddMonoidHom (f : R →+* S) (x : S)` is the `AddMonoidHom` from `R[X]` to `S` obtained by evaluating the pushforward of `p` along `f` at `x`. -/ @[simps] def eval₂AddMonoidHom : R[X] →+ S where toFun := eval₂ f x map_zero' := eval₂_zero _ _ map_add' _ _ := eval₂_add _ _ #align polynomial.eval₂_add_monoid_hom Polynomial.eval₂AddMonoidHom #align polynomial.eval₂_add_monoid_hom_apply Polynomial.eval₂AddMonoidHom_apply @[simp] theorem eval₂_natCast (n : ℕ) : (n : R[X]).eval₂ f x = n := by induction' n with n ih -- Porting note: `Nat.zero_eq` is required. · simp only [eval₂_zero, Nat.cast_zero, Nat.zero_eq] · rw [n.cast_succ, eval₂_add, ih, eval₂_one, n.cast_succ] #align polynomial.eval₂_nat_cast Polynomial.eval₂_natCast @[deprecated (since := "2024-04-17")] alias eval₂_nat_cast := eval₂_natCast -- See note [no_index around OfNat.ofNat] @[simp] lemma eval₂_ofNat {S : Type*} [Semiring S] (n : ℕ) [n.AtLeastTwo] (f : R →+* S) (a : S) : (no_index (OfNat.ofNat n : R[X])).eval₂ f a = OfNat.ofNat n := by simp [OfNat.ofNat] variable [Semiring T] theorem eval₂_sum (p : T[X]) (g : ℕ → T → R[X]) (x : S) : (p.sum g).eval₂ f x = p.sum fun n a => (g n a).eval₂ f x := by let T : R[X] →+ S := { toFun := eval₂ f x map_zero' := eval₂_zero _ _ map_add' := fun p q => eval₂_add _ _ } have A : ∀ y, eval₂ f x y = T y := fun y => rfl simp only [A] rw [sum, map_sum, sum] #align polynomial.eval₂_sum Polynomial.eval₂_sum theorem eval₂_list_sum (l : List R[X]) (x : S) : eval₂ f x l.sum = (l.map (eval₂ f x)).sum := map_list_sum (eval₂AddMonoidHom f x) l #align polynomial.eval₂_list_sum Polynomial.eval₂_list_sum theorem eval₂_multiset_sum (s : Multiset R[X]) (x : S) : eval₂ f x s.sum = (s.map (eval₂ f x)).sum := map_multiset_sum (eval₂AddMonoidHom f x) s #align polynomial.eval₂_multiset_sum Polynomial.eval₂_multiset_sum theorem eval₂_finset_sum (s : Finset ι) (g : ι → R[X]) (x : S) : (∑ i ∈ s, g i).eval₂ f x = ∑ i ∈ s, (g i).eval₂ f x := map_sum (eval₂AddMonoidHom f x) _ _ #align polynomial.eval₂_finset_sum Polynomial.eval₂_finset_sum theorem eval₂_ofFinsupp {f : R →+* S} {x : S} {p : R[ℕ]} : eval₂ f x (⟨p⟩ : R[X]) = liftNC (↑f) (powersHom S x) p := by simp only [eval₂_eq_sum, sum, toFinsupp_sum, support, coeff] rfl #align polynomial.eval₂_of_finsupp Polynomial.eval₂_ofFinsupp theorem eval₂_mul_noncomm (hf : ∀ k, Commute (f <| q.coeff k) x) : eval₂ f x (p * q) = eval₂ f x p * eval₂ f x q := by rcases p with ⟨p⟩; rcases q with ⟨q⟩ simp only [coeff] at hf simp only [← ofFinsupp_mul, eval₂_ofFinsupp] exact liftNC_mul _ _ p q fun {k n} _hn => (hf k).pow_right n #align polynomial.eval₂_mul_noncomm Polynomial.eval₂_mul_noncomm @[simp] theorem eval₂_mul_X : eval₂ f x (p * X) = eval₂ f x p * x := by refine _root_.trans (eval₂_mul_noncomm _ _ fun k => ?_) (by rw [eval₂_X]) rcases em (k = 1) with (rfl | hk) · simp · simp [coeff_X_of_ne_one hk] #align polynomial.eval₂_mul_X Polynomial.eval₂_mul_X @[simp] theorem eval₂_X_mul : eval₂ f x (X * p) = eval₂ f x p * x := by rw [X_mul, eval₂_mul_X] #align polynomial.eval₂_X_mul Polynomial.eval₂_X_mul theorem eval₂_mul_C' (h : Commute (f a) x) : eval₂ f x (p * C a) = eval₂ f x p * f a := by rw [eval₂_mul_noncomm, eval₂_C] intro k by_cases hk : k = 0 · simp only [hk, h, coeff_C_zero, coeff_C_ne_zero] · simp only [coeff_C_ne_zero hk, RingHom.map_zero, Commute.zero_left] #align polynomial.eval₂_mul_C' Polynomial.eval₂_mul_C' theorem eval₂_list_prod_noncomm (ps : List R[X]) (hf : ∀ p ∈ ps, ∀ (k), Commute (f <| coeff p k) x) : eval₂ f x ps.prod = (ps.map (Polynomial.eval₂ f x)).prod := by induction' ps using List.reverseRecOn with ps p ihp · simp · simp only [List.forall_mem_append, List.forall_mem_singleton] at hf simp [eval₂_mul_noncomm _ _ hf.2, ihp hf.1] #align polynomial.eval₂_list_prod_noncomm Polynomial.eval₂_list_prod_noncomm /-- `eval₂` as a `RingHom` for noncommutative rings -/ @[simps] def eval₂RingHom' (f : R →+* S) (x : S) (hf : ∀ a, Commute (f a) x) : R[X] →+* S where toFun := eval₂ f x map_add' _ _ := eval₂_add _ _ map_zero' := eval₂_zero _ _ map_mul' _p q := eval₂_mul_noncomm f x fun k => hf <| coeff q k map_one' := eval₂_one _ _ #align polynomial.eval₂_ring_hom' Polynomial.eval₂RingHom' end /-! We next prove that eval₂ is multiplicative as long as target ring is commutative (even if the source ring is not). -/ section Eval₂ section variable [Semiring S] (f : R →+* S) (x : S) theorem eval₂_eq_sum_range : p.eval₂ f x = ∑ i ∈ Finset.range (p.natDegree + 1), f (p.coeff i) * x ^ i := _root_.trans (congr_arg _ p.as_sum_range) (_root_.trans (eval₂_finset_sum f _ _ x) (congr_arg _ (by simp))) #align polynomial.eval₂_eq_sum_range Polynomial.eval₂_eq_sum_range theorem eval₂_eq_sum_range' (f : R →+* S) {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : S) : eval₂ f x p = ∑ i ∈ Finset.range n, f (p.coeff i) * x ^ i := by rw [eval₂_eq_sum, p.sum_over_range' _ _ hn] intro i rw [f.map_zero, zero_mul] #align polynomial.eval₂_eq_sum_range' Polynomial.eval₂_eq_sum_range' end section variable [CommSemiring S] (f : R →+* S) (x : S) @[simp] theorem eval₂_mul : (p * q).eval₂ f x = p.eval₂ f x * q.eval₂ f x := eval₂_mul_noncomm _ _ fun _k => Commute.all _ _ #align polynomial.eval₂_mul Polynomial.eval₂_mul theorem eval₂_mul_eq_zero_of_left (q : R[X]) (hp : p.eval₂ f x = 0) : (p * q).eval₂ f x = 0 := by rw [eval₂_mul f x] exact mul_eq_zero_of_left hp (q.eval₂ f x) #align polynomial.eval₂_mul_eq_zero_of_left Polynomial.eval₂_mul_eq_zero_of_left theorem eval₂_mul_eq_zero_of_right (p : R[X]) (hq : q.eval₂ f x = 0) : (p * q).eval₂ f x = 0 := by rw [eval₂_mul f x] exact mul_eq_zero_of_right (p.eval₂ f x) hq #align polynomial.eval₂_mul_eq_zero_of_right Polynomial.eval₂_mul_eq_zero_of_right /-- `eval₂` as a `RingHom` -/ def eval₂RingHom (f : R →+* S) (x : S) : R[X] →+* S := { eval₂AddMonoidHom f x with map_one' := eval₂_one _ _ map_mul' := fun _ _ => eval₂_mul _ _ } #align polynomial.eval₂_ring_hom Polynomial.eval₂RingHom @[simp] theorem coe_eval₂RingHom (f : R →+* S) (x) : ⇑(eval₂RingHom f x) = eval₂ f x := rfl #align polynomial.coe_eval₂_ring_hom Polynomial.coe_eval₂RingHom theorem eval₂_pow (n : ℕ) : (p ^ n).eval₂ f x = p.eval₂ f x ^ n := (eval₂RingHom _ _).map_pow _ _ #align polynomial.eval₂_pow Polynomial.eval₂_pow theorem eval₂_dvd : p ∣ q → eval₂ f x p ∣ eval₂ f x q := (eval₂RingHom f x).map_dvd #align polynomial.eval₂_dvd Polynomial.eval₂_dvd theorem eval₂_eq_zero_of_dvd_of_eval₂_eq_zero (h : p ∣ q) (h0 : eval₂ f x p = 0) : eval₂ f x q = 0 := zero_dvd_iff.mp (h0 ▸ eval₂_dvd f x h) #align polynomial.eval₂_eq_zero_of_dvd_of_eval₂_eq_zero Polynomial.eval₂_eq_zero_of_dvd_of_eval₂_eq_zero theorem eval₂_list_prod (l : List R[X]) (x : S) : eval₂ f x l.prod = (l.map (eval₂ f x)).prod := map_list_prod (eval₂RingHom f x) l #align polynomial.eval₂_list_prod Polynomial.eval₂_list_prod end end Eval₂ section Eval variable {x : R} /-- `eval x p` is the evaluation of the polynomial `p` at `x` -/ def eval : R → R[X] → R := eval₂ (RingHom.id _) #align polynomial.eval Polynomial.eval theorem eval_eq_sum : p.eval x = p.sum fun e a => a * x ^ e := by rw [eval, eval₂_eq_sum] rfl #align polynomial.eval_eq_sum Polynomial.eval_eq_sum theorem eval_eq_sum_range {p : R[X]} (x : R) : p.eval x = ∑ i ∈ Finset.range (p.natDegree + 1), p.coeff i * x ^ i := by rw [eval_eq_sum, sum_over_range]; simp #align polynomial.eval_eq_sum_range Polynomial.eval_eq_sum_range theorem eval_eq_sum_range' {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : R) : p.eval x = ∑ i ∈ Finset.range n, p.coeff i * x ^ i := by rw [eval_eq_sum, p.sum_over_range' _ _ hn]; simp #align polynomial.eval_eq_sum_range' Polynomial.eval_eq_sum_range' @[simp] theorem eval₂_at_apply {S : Type*} [Semiring S] (f : R →+* S) (r : R) : p.eval₂ f (f r) = f (p.eval r) := by rw [eval₂_eq_sum, eval_eq_sum, sum, sum, map_sum f] simp only [f.map_mul, f.map_pow] #align polynomial.eval₂_at_apply Polynomial.eval₂_at_apply @[simp] theorem eval₂_at_one {S : Type*} [Semiring S] (f : R →+* S) : p.eval₂ f 1 = f (p.eval 1) := by convert eval₂_at_apply (p := p) f 1 simp #align polynomial.eval₂_at_one Polynomial.eval₂_at_one @[simp] theorem eval₂_at_natCast {S : Type*} [Semiring S] (f : R →+* S) (n : ℕ) : p.eval₂ f n = f (p.eval n) := by convert eval₂_at_apply (p := p) f n simp #align polynomial.eval₂_at_nat_cast Polynomial.eval₂_at_natCast @[deprecated (since := "2024-04-17")] alias eval₂_at_nat_cast := eval₂_at_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem eval₂_at_ofNat {S : Type*} [Semiring S] (f : R →+* S) (n : ℕ) [n.AtLeastTwo] : p.eval₂ f (no_index (OfNat.ofNat n)) = f (p.eval (OfNat.ofNat n)) := by simp [OfNat.ofNat] @[simp] theorem eval_C : (C a).eval x = a := eval₂_C _ _ #align polynomial.eval_C Polynomial.eval_C @[simp] theorem eval_natCast {n : ℕ} : (n : R[X]).eval x = n := by simp only [← C_eq_natCast, eval_C] #align polynomial.eval_nat_cast Polynomial.eval_natCast @[deprecated (since := "2024-04-17")] alias eval_nat_cast := eval_natCast -- See note [no_index around OfNat.ofNat] @[simp] lemma eval_ofNat (n : ℕ) [n.AtLeastTwo] (a : R) : (no_index (OfNat.ofNat n : R[X])).eval a = OfNat.ofNat n := by simp only [OfNat.ofNat, eval_natCast] @[simp] theorem eval_X : X.eval x = x := eval₂_X _ _ #align polynomial.eval_X Polynomial.eval_X @[simp] theorem eval_monomial {n a} : (monomial n a).eval x = a * x ^ n := eval₂_monomial _ _ #align polynomial.eval_monomial Polynomial.eval_monomial @[simp] theorem eval_zero : (0 : R[X]).eval x = 0 := eval₂_zero _ _ #align polynomial.eval_zero Polynomial.eval_zero @[simp] theorem eval_add : (p + q).eval x = p.eval x + q.eval x := eval₂_add _ _ #align polynomial.eval_add Polynomial.eval_add @[simp] theorem eval_one : (1 : R[X]).eval x = 1 := eval₂_one _ _ #align polynomial.eval_one Polynomial.eval_one set_option linter.deprecated false in @[simp] theorem eval_bit0 : (bit0 p).eval x = bit0 (p.eval x) := eval₂_bit0 _ _ #align polynomial.eval_bit0 Polynomial.eval_bit0 set_option linter.deprecated false in @[simp] theorem eval_bit1 : (bit1 p).eval x = bit1 (p.eval x) := eval₂_bit1 _ _ #align polynomial.eval_bit1 Polynomial.eval_bit1 @[simp] theorem eval_smul [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S) (p : R[X]) (x : R) : (s • p).eval x = s • p.eval x := by rw [← smul_one_smul R s p, eval, eval₂_smul, RingHom.id_apply, smul_one_mul] #align polynomial.eval_smul Polynomial.eval_smul @[simp] theorem eval_C_mul : (C a * p).eval x = a * p.eval x := by induction p using Polynomial.induction_on' with | h_add p q ph qh => simp only [mul_add, eval_add, ph, qh] | h_monomial n b => simp only [mul_assoc, C_mul_monomial, eval_monomial] #align polynomial.eval_C_mul Polynomial.eval_C_mul /-- A reformulation of the expansion of (1 + y)^d: $$(d + 1) (1 + y)^d - (d + 1)y^d = \sum_{i = 0}^d {d + 1 \choose i} \cdot i \cdot y^{i - 1}.$$ -/ theorem eval_monomial_one_add_sub [CommRing S] (d : ℕ) (y : S) : eval (1 + y) (monomial d (d + 1 : S)) - eval y (monomial d (d + 1 : S)) = ∑ x_1 ∈ range (d + 1), ↑((d + 1).choose x_1) * (↑x_1 * y ^ (x_1 - 1)) := by have cast_succ : (d + 1 : S) = ((d.succ : ℕ) : S) := by simp only [Nat.cast_succ] rw [cast_succ, eval_monomial, eval_monomial, add_comm, add_pow] -- Porting note: `apply_congr` hadn't been ported yet, so `congr` & `ext` is used. conv_lhs => congr · congr · skip · congr · skip · ext rw [one_pow, mul_one, mul_comm] rw [sum_range_succ, mul_add, Nat.choose_self, Nat.cast_one, one_mul, add_sub_cancel_right, mul_sum, sum_range_succ', Nat.cast_zero, zero_mul, mul_zero, add_zero] refine sum_congr rfl fun y _hy => ?_ rw [← mul_assoc, ← mul_assoc, ← Nat.cast_mul, Nat.succ_mul_choose_eq, Nat.cast_mul, Nat.add_sub_cancel] #align polynomial.eval_monomial_one_add_sub Polynomial.eval_monomial_one_add_sub /-- `Polynomial.eval` as linear map -/ @[simps] def leval {R : Type*} [Semiring R] (r : R) : R[X] →ₗ[R] R where toFun f := f.eval r map_add' _f _g := eval_add map_smul' c f := eval_smul c f r #align polynomial.leval Polynomial.leval #align polynomial.leval_apply Polynomial.leval_apply @[simp] theorem eval_natCast_mul {n : ℕ} : ((n : R[X]) * p).eval x = n * p.eval x := by rw [← C_eq_natCast, eval_C_mul] #align polynomial.eval_nat_cast_mul Polynomial.eval_natCast_mul @[deprecated (since := "2024-04-17")] alias eval_nat_cast_mul := eval_natCast_mul @[simp] theorem eval_mul_X : (p * X).eval x = p.eval x * x := by induction p using Polynomial.induction_on' with | h_add p q ph qh => simp only [add_mul, eval_add, ph, qh] | h_monomial n a => simp only [← monomial_one_one_eq_X, monomial_mul_monomial, eval_monomial, mul_one, pow_succ, mul_assoc] #align polynomial.eval_mul_X Polynomial.eval_mul_X @[simp] theorem eval_mul_X_pow {k : ℕ} : (p * X ^ k).eval x = p.eval x * x ^ k := by induction' k with k ih · simp · simp [pow_succ, ← mul_assoc, ih] #align polynomial.eval_mul_X_pow Polynomial.eval_mul_X_pow theorem eval_sum (p : R[X]) (f : ℕ → R → R[X]) (x : R) : (p.sum f).eval x = p.sum fun n a => (f n a).eval x := eval₂_sum _ _ _ _ #align polynomial.eval_sum Polynomial.eval_sum theorem eval_finset_sum (s : Finset ι) (g : ι → R[X]) (x : R) : (∑ i ∈ s, g i).eval x = ∑ i ∈ s, (g i).eval x := eval₂_finset_sum _ _ _ _ #align polynomial.eval_finset_sum Polynomial.eval_finset_sum /-- `IsRoot p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/ def IsRoot (p : R[X]) (a : R) : Prop := p.eval a = 0 #align polynomial.is_root Polynomial.IsRoot instance IsRoot.decidable [DecidableEq R] : Decidable (IsRoot p a) := by unfold IsRoot; infer_instance #align polynomial.is_root.decidable Polynomial.IsRoot.decidable @[simp] theorem IsRoot.def : IsRoot p a ↔ p.eval a = 0 := Iff.rfl #align polynomial.is_root.def Polynomial.IsRoot.def theorem IsRoot.eq_zero (h : IsRoot p x) : eval x p = 0 := h #align polynomial.is_root.eq_zero Polynomial.IsRoot.eq_zero theorem coeff_zero_eq_eval_zero (p : R[X]) : coeff p 0 = p.eval 0 := calc coeff p 0 = coeff p 0 * 0 ^ 0 := by simp _ = p.eval 0 := by symm rw [eval_eq_sum] exact Finset.sum_eq_single _ (fun b _ hb => by simp [zero_pow hb]) (by simp) #align polynomial.coeff_zero_eq_eval_zero Polynomial.coeff_zero_eq_eval_zero theorem zero_isRoot_of_coeff_zero_eq_zero {p : R[X]} (hp : p.coeff 0 = 0) : IsRoot p 0 := by rwa [coeff_zero_eq_eval_zero] at hp #align polynomial.zero_is_root_of_coeff_zero_eq_zero Polynomial.zero_isRoot_of_coeff_zero_eq_zero theorem IsRoot.dvd {R : Type*} [CommSemiring R] {p q : R[X]} {x : R} (h : p.IsRoot x) (hpq : p ∣ q) : q.IsRoot x := by rwa [IsRoot, eval, eval₂_eq_zero_of_dvd_of_eval₂_eq_zero _ _ hpq] #align polynomial.is_root.dvd Polynomial.IsRoot.dvd theorem not_isRoot_C (r a : R) (hr : r ≠ 0) : ¬IsRoot (C r) a := by simpa using hr #align polynomial.not_is_root_C Polynomial.not_isRoot_C theorem eval_surjective (x : R) : Function.Surjective <| eval x := fun y => ⟨C y, eval_C⟩ #align polynomial.eval_surjective Polynomial.eval_surjective end Eval section Comp /-- The composition of polynomials as a polynomial. -/ def comp (p q : R[X]) : R[X] := p.eval₂ C q #align polynomial.comp Polynomial.comp theorem comp_eq_sum_left : p.comp q = p.sum fun e a => C a * q ^ e := by rw [comp, eval₂_eq_sum] #align polynomial.comp_eq_sum_left Polynomial.comp_eq_sum_left @[simp] theorem comp_X : p.comp X = p := by simp only [comp, eval₂_def, C_mul_X_pow_eq_monomial] exact sum_monomial_eq _ #align polynomial.comp_X Polynomial.comp_X @[simp] theorem X_comp : X.comp p = p := eval₂_X _ _ #align polynomial.X_comp Polynomial.X_comp @[simp] theorem comp_C : p.comp (C a) = C (p.eval a) := by simp [comp, map_sum (C : R →+* _)] #align polynomial.comp_C Polynomial.comp_C @[simp] theorem C_comp : (C a).comp p = C a := eval₂_C _ _ #align polynomial.C_comp Polynomial.C_comp @[simp] theorem natCast_comp {n : ℕ} : (n : R[X]).comp p = n := by rw [← C_eq_natCast, C_comp] #align polynomial.nat_cast_comp Polynomial.natCast_comp @[deprecated (since := "2024-04-17")] alias nat_cast_comp := natCast_comp -- Porting note (#10756): new theorem @[simp] theorem ofNat_comp (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : R[X]).comp p = n := natCast_comp @[simp] theorem comp_zero : p.comp (0 : R[X]) = C (p.eval 0) := by rw [← C_0, comp_C] #align polynomial.comp_zero Polynomial.comp_zero @[simp] theorem zero_comp : comp (0 : R[X]) p = 0 := by rw [← C_0, C_comp] #align polynomial.zero_comp Polynomial.zero_comp @[simp] theorem comp_one : p.comp 1 = C (p.eval 1) := by rw [← C_1, comp_C] #align polynomial.comp_one Polynomial.comp_one @[simp] theorem one_comp : comp (1 : R[X]) p = 1 := by rw [← C_1, C_comp] #align polynomial.one_comp Polynomial.one_comp @[simp] theorem add_comp : (p + q).comp r = p.comp r + q.comp r := eval₂_add _ _ #align polynomial.add_comp Polynomial.add_comp @[simp] theorem monomial_comp (n : ℕ) : (monomial n a).comp p = C a * p ^ n := eval₂_monomial _ _ #align polynomial.monomial_comp Polynomial.monomial_comp @[simp] theorem mul_X_comp : (p * X).comp r = p.comp r * r := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp only [hp, hq, add_mul, add_comp] | h_monomial n b => simp only [pow_succ, mul_assoc, monomial_mul_X, monomial_comp] #align polynomial.mul_X_comp Polynomial.mul_X_comp @[simp] theorem X_pow_comp {k : ℕ} : (X ^ k).comp p = p ^ k := by induction' k with k ih · simp · simp [pow_succ, mul_X_comp, ih] #align polynomial.X_pow_comp Polynomial.X_pow_comp @[simp] theorem mul_X_pow_comp {k : ℕ} : (p * X ^ k).comp r = p.comp r * r ^ k := by induction' k with k ih · simp · simp [ih, pow_succ, ← mul_assoc, mul_X_comp] #align polynomial.mul_X_pow_comp Polynomial.mul_X_pow_comp @[simp] theorem C_mul_comp : (C a * p).comp r = C a * p.comp r := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp [hp, hq, mul_add] | h_monomial n b => simp [mul_assoc] #align polynomial.C_mul_comp Polynomial.C_mul_comp @[simp] theorem natCast_mul_comp {n : ℕ} : ((n : R[X]) * p).comp r = n * p.comp r := by rw [← C_eq_natCast, C_mul_comp] #align polynomial.nat_cast_mul_comp Polynomial.natCast_mul_comp @[deprecated (since := "2024-04-17")] alias nat_cast_mul_comp := natCast_mul_comp theorem mul_X_add_natCast_comp {n : ℕ} : (p * (X + (n : R[X]))).comp q = p.comp q * (q + n) := by rw [mul_add, add_comp, mul_X_comp, ← Nat.cast_comm, natCast_mul_comp, Nat.cast_comm, mul_add] set_option linter.uppercaseLean3 false in #align polynomial.mul_X_add_nat_cast_comp Polynomial.mul_X_add_natCast_comp @[deprecated (since := "2024-04-17")] alias mul_X_add_nat_cast_comp := mul_X_add_natCast_comp @[simp] theorem mul_comp {R : Type*} [CommSemiring R] (p q r : R[X]) : (p * q).comp r = p.comp r * q.comp r := eval₂_mul _ _ #align polynomial.mul_comp Polynomial.mul_comp @[simp] theorem pow_comp {R : Type*} [CommSemiring R] (p q : R[X]) (n : ℕ) : (p ^ n).comp q = p.comp q ^ n := (MonoidHom.mk (OneHom.mk (fun r : R[X] => r.comp q) one_comp) fun r s => mul_comp r s q).map_pow p n #align polynomial.pow_comp Polynomial.pow_comp set_option linter.deprecated false in @[simp] theorem bit0_comp : comp (bit0 p : R[X]) q = bit0 (p.comp q) := by simp only [bit0, add_comp] #align polynomial.bit0_comp Polynomial.bit0_comp set_option linter.deprecated false in @[simp] theorem bit1_comp : comp (bit1 p : R[X]) q = bit1 (p.comp q) := by simp only [bit1, add_comp, bit0_comp, one_comp] #align polynomial.bit1_comp Polynomial.bit1_comp @[simp] theorem smul_comp [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S) (p q : R[X]) : (s • p).comp q = s • p.comp q := by rw [← smul_one_smul R s p, comp, comp, eval₂_smul, ← smul_eq_C_mul, smul_assoc, one_smul] #align polynomial.smul_comp Polynomial.smul_comp theorem comp_assoc {R : Type*} [CommSemiring R] (φ ψ χ : R[X]) : (φ.comp ψ).comp χ = φ.comp (ψ.comp χ) := by refine Polynomial.induction_on φ ?_ ?_ ?_ <;> · intros simp_all only [add_comp, mul_comp, C_comp, X_comp, pow_succ, ← mul_assoc] #align polynomial.comp_assoc Polynomial.comp_assoc theorem coeff_comp_degree_mul_degree (hqd0 : natDegree q ≠ 0) : coeff (p.comp q) (natDegree p * natDegree q) = leadingCoeff p * leadingCoeff q ^ natDegree p := by rw [comp, eval₂_def, coeff_sum] -- Porting note: `convert` → `refine` refine Eq.trans (Finset.sum_eq_single p.natDegree ?h₀ ?h₁) ?h₂ case h₂ => simp only [coeff_natDegree, coeff_C_mul, coeff_pow_mul_natDegree] case h₀ => intro b hbs hbp refine coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt ?_) rw [natDegree_C, zero_add] refine natDegree_pow_le.trans_lt ((mul_lt_mul_right (pos_iff_ne_zero.mpr hqd0)).mpr ?_) exact lt_of_le_of_ne (le_natDegree_of_mem_supp _ hbs) hbp case h₁ => simp (config := { contextual := true }) #align polynomial.coeff_comp_degree_mul_degree Polynomial.coeff_comp_degree_mul_degree @[simp] lemma sum_comp (s : Finset ι) (p : ι → R[X]) (q : R[X]) : (∑ i ∈ s, p i).comp q = ∑ i ∈ s, (p i).comp q := Polynomial.eval₂_finset_sum _ _ _ _ end Comp section Map variable [Semiring S] variable (f : R →+* S) /-- `map f p` maps a polynomial `p` across a ring hom `f` -/ def map : R[X] → S[X] := eval₂ (C.comp f) X #align polynomial.map Polynomial.map @[simp] theorem map_C : (C a).map f = C (f a) := eval₂_C _ _ #align polynomial.map_C Polynomial.map_C @[simp] theorem map_X : X.map f = X := eval₂_X _ _ #align polynomial.map_X Polynomial.map_X @[simp] theorem map_monomial {n a} : (monomial n a).map f = monomial n (f a) := by dsimp only [map] rw [eval₂_monomial, ← C_mul_X_pow_eq_monomial]; rfl #align polynomial.map_monomial Polynomial.map_monomial @[simp] protected theorem map_zero : (0 : R[X]).map f = 0 := eval₂_zero _ _ #align polynomial.map_zero Polynomial.map_zero @[simp] protected theorem map_add : (p + q).map f = p.map f + q.map f := eval₂_add _ _ #align polynomial.map_add Polynomial.map_add @[simp] protected theorem map_one : (1 : R[X]).map f = 1 := eval₂_one _ _ #align polynomial.map_one Polynomial.map_one @[simp] protected theorem map_mul : (p * q).map f = p.map f * q.map f := by rw [map, eval₂_mul_noncomm] exact fun k => (commute_X _).symm #align polynomial.map_mul Polynomial.map_mul @[simp] protected theorem map_smul (r : R) : (r • p).map f = f r • p.map f := by rw [map, eval₂_smul, RingHom.comp_apply, C_mul'] #align polynomial.map_smul Polynomial.map_smul -- `map` is a ring-hom unconditionally, and theoretically the definition could be replaced, -- but this turns out not to be easy because `p.map f` does not resolve to `Polynomial.map` -- if `map` is a `RingHom` instead of a plain function; the elaborator does not try to coerce -- to a function before trying field (dot) notation (this may be technically infeasible); -- the relevant code is (both lines): https://github.com/leanprover-community/ -- lean/blob/487ac5d7e9b34800502e1ddf3c7c806c01cf9d51/src/frontends/lean/elaborator.cpp#L1876-L1913 /-- `Polynomial.map` as a `RingHom`. -/ def mapRingHom (f : R →+* S) : R[X] →+* S[X] where toFun := Polynomial.map f map_add' _ _ := Polynomial.map_add f map_zero' := Polynomial.map_zero f map_mul' _ _ := Polynomial.map_mul f map_one' := Polynomial.map_one f #align polynomial.map_ring_hom Polynomial.mapRingHom @[simp] theorem coe_mapRingHom (f : R →+* S) : ⇑(mapRingHom f) = map f := rfl #align polynomial.coe_map_ring_hom Polynomial.coe_mapRingHom -- This is protected to not clash with the global `map_natCast`. @[simp] protected theorem map_natCast (n : ℕ) : (n : R[X]).map f = n := map_natCast (mapRingHom f) n #align polynomial.map_nat_cast Polynomial.map_natCast @[deprecated (since := "2024-04-17")] alias map_nat_cast := map_natCast -- Porting note (#10756): new theorem -- See note [no_index around OfNat.ofNat] @[simp] protected theorem map_ofNat (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : R[X]).map f = OfNat.ofNat n := show (n : R[X]).map f = n by rw [Polynomial.map_natCast] #noalign polynomial.map_bit0 #noalign polynomial.map_bit1 --TODO rename to `map_dvd_map` theorem map_dvd (f : R →+* S) {x y : R[X]} : x ∣ y → x.map f ∣ y.map f := (mapRingHom f).map_dvd #align polynomial.map_dvd Polynomial.map_dvd @[simp] theorem coeff_map (n : ℕ) : coeff (p.map f) n = f (coeff p n) := by rw [map, eval₂_def, coeff_sum, sum] conv_rhs => rw [← sum_C_mul_X_pow_eq p, coeff_sum, sum, map_sum] refine Finset.sum_congr rfl fun x _hx => ?_ simp only [RingHom.coe_comp, Function.comp, coeff_C_mul_X_pow] split_ifs <;> simp [f.map_zero] #align polynomial.coeff_map Polynomial.coeff_map /-- If `R` and `S` are isomorphic, then so are their polynomial rings. -/ @[simps!] def mapEquiv (e : R ≃+* S) : R[X] ≃+* S[X] := RingEquiv.ofHomInv (mapRingHom (e : R →+* S)) (mapRingHom (e.symm : S →+* R)) (by ext <;> simp) (by ext <;> simp) #align polynomial.map_equiv Polynomial.mapEquiv #align polynomial.map_equiv_apply Polynomial.mapEquiv_apply #align polynomial.map_equiv_symm_apply Polynomial.mapEquiv_symm_apply theorem map_map [Semiring T] (g : S →+* T) (p : R[X]) : (p.map f).map g = p.map (g.comp f) := ext (by simp [coeff_map]) #align polynomial.map_map Polynomial.map_map @[simp] theorem map_id : p.map (RingHom.id _) = p := by simp [Polynomial.ext_iff, coeff_map] #align polynomial.map_id Polynomial.map_id /-- The polynomial ring over a finite product of rings is isomorphic to the product of polynomial rings over individual rings. -/ def piEquiv {ι} [Finite ι] (R : ι → Type*) [∀ i, Semiring (R i)] : (∀ i, R i)[X] ≃+* ∀ i, (R i)[X] := .ofBijective (Pi.ringHom fun i ↦ mapRingHom (Pi.evalRingHom R i)) ⟨fun p q h ↦ by ext n i; simpa using congr_arg (fun p ↦ coeff (p i) n) h, fun p ↦ ⟨.ofFinsupp (.ofSupportFinite (fun n i ↦ coeff (p i) n) <| (Set.finite_iUnion fun i ↦ (p i).support.finite_toSet).subset fun n hn ↦ by simp only [Set.mem_iUnion, Finset.mem_coe, mem_support_iff, Function.mem_support] at hn ⊢ contrapose! hn; exact funext hn), by ext i n; exact coeff_map _ _⟩⟩ theorem eval₂_eq_eval_map {x : S} : p.eval₂ f x = (p.map f).eval x := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp [hp, hq] | h_monomial n r => simp #align polynomial.eval₂_eq_eval_map Polynomial.eval₂_eq_eval_map theorem map_injective (hf : Function.Injective f) : Function.Injective (map f) := fun p q h => ext fun m => hf <| by rw [← coeff_map f, ← coeff_map f, h] #align polynomial.map_injective Polynomial.map_injective theorem map_surjective (hf : Function.Surjective f) : Function.Surjective (map f) := fun p => Polynomial.induction_on' p (fun p q hp hq => let ⟨p', hp'⟩ := hp let ⟨q', hq'⟩ := hq ⟨p' + q', by rw [Polynomial.map_add f, hp', hq']⟩) fun n s => let ⟨r, hr⟩ := hf s ⟨monomial n r, by rw [map_monomial f, hr]⟩ #align polynomial.map_surjective Polynomial.map_surjective theorem degree_map_le (p : R[X]) : degree (p.map f) ≤ degree p := by refine (degree_le_iff_coeff_zero _ _).2 fun m hm => ?_ rw [degree_lt_iff_coeff_zero] at hm simp [hm m le_rfl] #align polynomial.degree_map_le Polynomial.degree_map_le theorem natDegree_map_le (p : R[X]) : natDegree (p.map f) ≤ natDegree p := natDegree_le_natDegree (degree_map_le f p) #align polynomial.nat_degree_map_le Polynomial.natDegree_map_le variable {f} protected theorem map_eq_zero_iff (hf : Function.Injective f) : p.map f = 0 ↔ p = 0 := map_eq_zero_iff (mapRingHom f) (map_injective f hf) #align polynomial.map_eq_zero_iff Polynomial.map_eq_zero_iff protected theorem map_ne_zero_iff (hf : Function.Injective f) : p.map f ≠ 0 ↔ p ≠ 0 := (Polynomial.map_eq_zero_iff hf).not #align polynomial.map_ne_zero_iff Polynomial.map_ne_zero_iff theorem map_monic_eq_zero_iff (hp : p.Monic) : p.map f = 0 ↔ ∀ x, f x = 0 := ⟨fun hfp x => calc f x = f x * f p.leadingCoeff := by simp only [mul_one, hp.leadingCoeff, f.map_one] _ = f x * (p.map f).coeff p.natDegree := congr_arg _ (coeff_map _ _).symm _ = 0 := by simp only [hfp, mul_zero, coeff_zero] , fun h => ext fun n => by simp only [h, coeff_map, coeff_zero]⟩ #align polynomial.map_monic_eq_zero_iff Polynomial.map_monic_eq_zero_iff theorem map_monic_ne_zero (hp : p.Monic) [Nontrivial S] : p.map f ≠ 0 := fun h => f.map_one_ne_zero ((map_monic_eq_zero_iff hp).mp h _) #align polynomial.map_monic_ne_zero Polynomial.map_monic_ne_zero theorem degree_map_eq_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f (leadingCoeff p) ≠ 0) : degree (p.map f) = degree p := le_antisymm (degree_map_le f _) <| by have hp0 : p ≠ 0 := leadingCoeff_ne_zero.mp fun hp0 => hf (_root_.trans (congr_arg _ hp0) f.map_zero) rw [degree_eq_natDegree hp0] refine le_degree_of_ne_zero ?_ rw [coeff_map] exact hf #align polynomial.degree_map_eq_of_leading_coeff_ne_zero Polynomial.degree_map_eq_of_leadingCoeff_ne_zero theorem natDegree_map_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f (leadingCoeff p) ≠ 0) : natDegree (p.map f) = natDegree p := natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f hf) #align polynomial.nat_degree_map_of_leading_coeff_ne_zero Polynomial.natDegree_map_of_leadingCoeff_ne_zero theorem leadingCoeff_map_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f (leadingCoeff p) ≠ 0) : leadingCoeff (p.map f) = f (leadingCoeff p) := by unfold leadingCoeff rw [coeff_map, natDegree_map_of_leadingCoeff_ne_zero f hf] #align polynomial.leading_coeff_map_of_leading_coeff_ne_zero Polynomial.leadingCoeff_map_of_leadingCoeff_ne_zero variable (f) @[simp] theorem mapRingHom_id : mapRingHom (RingHom.id R) = RingHom.id R[X] := RingHom.ext fun _x => map_id #align polynomial.map_ring_hom_id Polynomial.mapRingHom_id @[simp] theorem mapRingHom_comp [Semiring T] (f : S →+* T) (g : R →+* S) : (mapRingHom f).comp (mapRingHom g) = mapRingHom (f.comp g) := RingHom.ext <| Polynomial.map_map g f #align polynomial.map_ring_hom_comp Polynomial.mapRingHom_comp protected theorem map_list_prod (L : List R[X]) : L.prod.map f = (L.map <| map f).prod := Eq.symm <| List.prod_hom _ (mapRingHom f).toMonoidHom #align polynomial.map_list_prod Polynomial.map_list_prod @[simp] protected theorem map_pow (n : ℕ) : (p ^ n).map f = p.map f ^ n := (mapRingHom f).map_pow _ _ #align polynomial.map_pow Polynomial.map_pow theorem mem_map_rangeS {p : S[X]} : p ∈ (mapRingHom f).rangeS ↔ ∀ n, p.coeff n ∈ f.rangeS := by constructor · rintro ⟨p, rfl⟩ n rw [coe_mapRingHom, coeff_map] exact Set.mem_range_self _ · intro h rw [p.as_sum_range_C_mul_X_pow] refine (mapRingHom f).rangeS.sum_mem ?_ intro i _hi rcases h i with ⟨c, hc⟩ use C c * X ^ i rw [coe_mapRingHom, Polynomial.map_mul, map_C, hc, Polynomial.map_pow, map_X] #align polynomial.mem_map_srange Polynomial.mem_map_rangeS theorem mem_map_range {R S : Type*} [Ring R] [Ring S] (f : R →+* S) {p : S[X]} : p ∈ (mapRingHom f).range ↔ ∀ n, p.coeff n ∈ f.range := mem_map_rangeS f #align polynomial.mem_map_range Polynomial.mem_map_range theorem eval₂_map [Semiring T] (g : S →+* T) (x : T) : (p.map f).eval₂ g x = p.eval₂ (g.comp f) x := by rw [eval₂_eq_eval_map, eval₂_eq_eval_map, map_map] #align polynomial.eval₂_map Polynomial.eval₂_map theorem eval_map (x : S) : (p.map f).eval x = p.eval₂ f x := (eval₂_eq_eval_map f).symm #align polynomial.eval_map Polynomial.eval_map protected theorem map_sum {ι : Type*} (g : ι → R[X]) (s : Finset ι) : (∑ i ∈ s, g i).map f = ∑ i ∈ s, (g i).map f := map_sum (mapRingHom f) _ _ #align polynomial.map_sum Polynomial.map_sum theorem map_comp (p q : R[X]) : map f (p.comp q) = (map f p).comp (map f q) := Polynomial.induction_on p (by simp only [map_C, forall_const, C_comp, eq_self_iff_true]) (by simp (config := { contextual := true }) only [Polynomial.map_add, add_comp, forall_const, imp_true_iff, eq_self_iff_true]) (by simp (config := { contextual := true }) only [pow_succ, ← mul_assoc, comp, forall_const, eval₂_mul_X, imp_true_iff, eq_self_iff_true, map_X, Polynomial.map_mul]) #align polynomial.map_comp Polynomial.map_comp @[simp] theorem eval_zero_map (f : R →+* S) (p : R[X]) : (p.map f).eval 0 = f (p.eval 0) := by simp [← coeff_zero_eq_eval_zero] #align polynomial.eval_zero_map Polynomial.eval_zero_map @[simp] theorem eval_one_map (f : R →+* S) (p : R[X]) : (p.map f).eval 1 = f (p.eval 1) := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add] | h_monomial n r => simp only [one_pow, mul_one, eval_monomial, map_monomial] #align polynomial.eval_one_map Polynomial.eval_one_map @[simp] theorem eval_natCast_map (f : R →+* S) (p : R[X]) (n : ℕ) : (p.map f).eval (n : S) = f (p.eval n) := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add] | h_monomial n r => simp only [map_natCast f, eval_monomial, map_monomial, f.map_pow, f.map_mul] #align polynomial.eval_nat_cast_map Polynomial.eval_natCast_map @[deprecated (since := "2024-04-17")] alias eval_nat_cast_map := eval_natCast_map @[simp] theorem eval_intCast_map {R S : Type*} [Ring R] [Ring S] (f : R →+* S) (p : R[X]) (i : ℤ) : (p.map f).eval (i : S) = f (p.eval i) := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add] | h_monomial n r => simp only [map_intCast, eval_monomial, map_monomial, map_pow, map_mul] #align polynomial.eval_int_cast_map Polynomial.eval_intCast_map @[deprecated (since := "2024-04-17")] alias eval_int_cast_map := eval_intCast_map end Map /-! we have made `eval₂` irreducible from the start. Perhaps we can make also `eval`, `comp`, and `map` irreducible too? -/ section HomEval₂ variable [Semiring S] [Semiring T] (f : R →+* S) (g : S →+* T) (p) theorem hom_eval₂ (x : S) : g (p.eval₂ f x) = p.eval₂ (g.comp f) (g x) := by rw [← eval₂_map, eval₂_at_apply, eval_map] #align polynomial.hom_eval₂ Polynomial.hom_eval₂ end HomEval₂ end Semiring section CommSemiring section Eval section variable [Semiring R] {p q : R[X]} {x : R} [Semiring S] (f : R →+* S) theorem eval₂_hom (x : R) : p.eval₂ f (f x) = f (p.eval x) := RingHom.comp_id f ▸ (hom_eval₂ p (RingHom.id R) f x).symm #align polynomial.eval₂_hom Polynomial.eval₂_hom end section variable [Semiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R →+* S) theorem eval₂_comp {x : S} : eval₂ f x (p.comp q) = eval₂ f (eval₂ f x q) p := by rw [comp, p.as_sum_range]; simp [eval₂_finset_sum, eval₂_pow] #align polynomial.eval₂_comp Polynomial.eval₂_comp @[simp]
Mathlib/Algebra/Polynomial/Eval.lean
1,086
1,090
theorem iterate_comp_eval₂ (k : ℕ) (t : S) : eval₂ f t (p.comp^[k] q) = (fun x => eval₂ f x p)^[k] (eval₂ f t q) := by
induction' k with k IH · simp · rw [Function.iterate_succ_apply', Function.iterate_succ_apply', eval₂_comp, IH]
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Data.ENNReal.Real import Mathlib.Order.Interval.Finset.Nat import Mathlib.Topology.UniformSpace.Pi import Mathlib.Topology.UniformSpace.UniformConvergence import Mathlib.Topology.UniformSpace.UniformEmbedding #align_import topology.metric_space.emetric_space from "leanprover-community/mathlib"@"c8f305514e0d47dfaa710f5a52f0d21b588e6328" /-! # Extended metric spaces This file is devoted to the definition and study of `EMetricSpace`s, i.e., metric spaces in which the distance is allowed to take the value ∞. This extended distance is called `edist`, and takes values in `ℝ≥0∞`. Many definitions and theorems expected on emetric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity. The class `EMetricSpace` therefore extends `UniformSpace` (and `TopologicalSpace`). Since a lot of elementary properties don't require `eq_of_edist_eq_zero` we start setting up the theory of `PseudoEMetricSpace`, where we don't require `edist x y = 0 → x = y` and we specialize to `EMetricSpace` at the end. -/ open Set Filter Classical open scoped Uniformity Topology Filter NNReal ENNReal Pointwise universe u v w variable {α : Type u} {β : Type v} {X : Type*} /-- Characterizing uniformities associated to a (generalized) distance function `D` in terms of the elements of the uniformity. -/ theorem uniformity_dist_of_mem_uniformity [LinearOrder β] {U : Filter (α × α)} (z : β) (D : α → α → β) (H : ∀ s, s ∈ U ↔ ∃ ε > z, ∀ {a b : α}, D a b < ε → (a, b) ∈ s) : U = ⨅ ε > z, 𝓟 { p : α × α | D p.1 p.2 < ε } := HasBasis.eq_biInf ⟨fun s => by simp only [H, subset_def, Prod.forall, mem_setOf]⟩ #align uniformity_dist_of_mem_uniformity uniformity_dist_of_mem_uniformity /-- `EDist α` means that `α` is equipped with an extended distance. -/ @[ext] class EDist (α : Type*) where edist : α → α → ℝ≥0∞ #align has_edist EDist export EDist (edist) /-- Creating a uniform space from an extended distance. -/ def uniformSpaceOfEDist (edist : α → α → ℝ≥0∞) (edist_self : ∀ x : α, edist x x = 0) (edist_comm : ∀ x y : α, edist x y = edist y x) (edist_triangle : ∀ x y z : α, edist x z ≤ edist x y + edist y z) : UniformSpace α := .ofFun edist edist_self edist_comm edist_triangle fun ε ε0 => ⟨ε / 2, ENNReal.half_pos ε0.ne', fun _ h₁ _ h₂ => (ENNReal.add_lt_add h₁ h₂).trans_eq (ENNReal.add_halves _)⟩ #align uniform_space_of_edist uniformSpaceOfEDist -- the uniform structure is embedded in the emetric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- Extended (pseudo) metric spaces, with an extended distance `edist` possibly taking the value ∞ Each pseudo_emetric space induces a canonical `UniformSpace` and hence a canonical `TopologicalSpace`. This is enforced in the type class definition, by extending the `UniformSpace` structure. When instantiating a `PseudoEMetricSpace` structure, the uniformity fields are not necessary, they will be filled in by default. There is a default value for the uniformity, that can be substituted in cases of interest, for instance when instantiating a `PseudoEMetricSpace` structure on a product. Continuity of `edist` is proved in `Topology.Instances.ENNReal` -/ class PseudoEMetricSpace (α : Type u) extends EDist α : Type u where edist_self : ∀ x : α, edist x x = 0 edist_comm : ∀ x y : α, edist x y = edist y x edist_triangle : ∀ x y z : α, edist x z ≤ edist x y + edist y z toUniformSpace : UniformSpace α := uniformSpaceOfEDist edist edist_self edist_comm edist_triangle uniformity_edist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | edist p.1 p.2 < ε } := by rfl #align pseudo_emetric_space PseudoEMetricSpace attribute [instance] PseudoEMetricSpace.toUniformSpace /- Pseudoemetric spaces are less common than metric spaces. Therefore, we work in a dedicated namespace, while notions associated to metric spaces are mostly in the root namespace. -/ /-- Two pseudo emetric space structures with the same edistance function coincide. -/ @[ext] protected theorem PseudoEMetricSpace.ext {α : Type*} {m m' : PseudoEMetricSpace α} (h : m.toEDist = m'.toEDist) : m = m' := by cases' m with ed _ _ _ U hU cases' m' with ed' _ _ _ U' hU' congr 1 exact UniformSpace.ext (((show ed = ed' from h) ▸ hU).trans hU'.symm) variable [PseudoEMetricSpace α] export PseudoEMetricSpace (edist_self edist_comm edist_triangle) attribute [simp] edist_self /-- Triangle inequality for the extended distance -/ theorem edist_triangle_left (x y z : α) : edist x y ≤ edist z x + edist z y := by rw [edist_comm z]; apply edist_triangle #align edist_triangle_left edist_triangle_left theorem edist_triangle_right (x y z : α) : edist x y ≤ edist x z + edist y z := by rw [edist_comm y]; apply edist_triangle #align edist_triangle_right edist_triangle_right theorem edist_congr_right {x y z : α} (h : edist x y = 0) : edist x z = edist y z := by apply le_antisymm · rw [← zero_add (edist y z), ← h] apply edist_triangle · rw [edist_comm] at h rw [← zero_add (edist x z), ← h] apply edist_triangle #align edist_congr_right edist_congr_right theorem edist_congr_left {x y z : α} (h : edist x y = 0) : edist z x = edist z y := by rw [edist_comm z x, edist_comm z y] apply edist_congr_right h #align edist_congr_left edist_congr_left -- new theorem theorem edist_congr {w x y z : α} (hl : edist w x = 0) (hr : edist y z = 0) : edist w y = edist x z := (edist_congr_right hl).trans (edist_congr_left hr) theorem edist_triangle4 (x y z t : α) : edist x t ≤ edist x y + edist y z + edist z t := calc edist x t ≤ edist x z + edist z t := edist_triangle x z t _ ≤ edist x y + edist y z + edist z t := add_le_add_right (edist_triangle x y z) _ #align edist_triangle4 edist_triangle4 /-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/ theorem edist_le_Ico_sum_edist (f : ℕ → α) {m n} (h : m ≤ n) : edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, edist (f i) (f (i + 1)) := by induction n, h using Nat.le_induction with | base => rw [Finset.Ico_self, Finset.sum_empty, edist_self] | succ n hle ihn => calc edist (f m) (f (n + 1)) ≤ edist (f m) (f n) + edist (f n) (f (n + 1)) := edist_triangle _ _ _ _ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl _ = ∑ i ∈ Finset.Ico m (n + 1), _ := by { rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp } #align edist_le_Ico_sum_edist edist_le_Ico_sum_edist /-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/ theorem edist_le_range_sum_edist (f : ℕ → α) (n : ℕ) : edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, edist (f i) (f (i + 1)) := Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_edist f (Nat.zero_le n) #align edist_le_range_sum_edist edist_le_range_sum_edist /-- A version of `edist_le_Ico_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_Ico_sum_of_edist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, m ≤ k → k < n → edist (f k) (f (k + 1)) ≤ d k) : edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i := le_trans (edist_le_Ico_sum_edist f hmn) <| Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2 #align edist_le_Ico_sum_of_edist_le edist_le_Ico_sum_of_edist_le /-- A version of `edist_le_range_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_range_sum_of_edist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, k < n → edist (f k) (f (k + 1)) ≤ d k) : edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i := Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_of_edist_le (zero_le n) fun _ => hd #align edist_le_range_sum_of_edist_le edist_le_range_sum_of_edist_le /-- Reformulation of the uniform structure in terms of the extended distance -/ theorem uniformity_pseudoedist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | edist p.1 p.2 < ε } := PseudoEMetricSpace.uniformity_edist #align uniformity_pseudoedist uniformity_pseudoedist theorem uniformSpace_edist : ‹PseudoEMetricSpace α›.toUniformSpace = uniformSpaceOfEDist edist edist_self edist_comm edist_triangle := UniformSpace.ext uniformity_pseudoedist #align uniform_space_edist uniformSpace_edist theorem uniformity_basis_edist : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 < ε } := (@uniformSpace_edist α _).symm ▸ UniformSpace.hasBasis_ofFun ⟨1, one_pos⟩ _ _ _ _ _ #align uniformity_basis_edist uniformity_basis_edist /-- Characterization of the elements of the uniformity in terms of the extended distance -/ theorem mem_uniformity_edist {s : Set (α × α)} : s ∈ 𝓤 α ↔ ∃ ε > 0, ∀ {a b : α}, edist a b < ε → (a, b) ∈ s := uniformity_basis_edist.mem_uniformity_iff #align mem_uniformity_edist mem_uniformity_edist /-- Given `f : β → ℝ≥0∞`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`. For specific bases see `uniformity_basis_edist`, `uniformity_basis_edist'`, `uniformity_basis_edist_nnreal`, and `uniformity_basis_edist_inv_nat`. -/ protected theorem EMetric.mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ≥0∞} (hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x, p x ∧ f x ≤ ε) : (𝓤 α).HasBasis p fun x => { p : α × α | edist p.1 p.2 < f x } := by refine ⟨fun s => uniformity_basis_edist.mem_iff.trans ?_⟩ constructor · rintro ⟨ε, ε₀, hε⟩ rcases hf ε ε₀ with ⟨i, hi, H⟩ exact ⟨i, hi, fun x hx => hε <| lt_of_lt_of_le hx.out H⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, H⟩ #align emetric.mk_uniformity_basis EMetric.mk_uniformity_basis /-- Given `f : β → ℝ≥0∞`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then closed `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`. For specific bases see `uniformity_basis_edist_le` and `uniformity_basis_edist_le'`. -/ protected theorem EMetric.mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ≥0∞} (hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x, p x ∧ f x ≤ ε) : (𝓤 α).HasBasis p fun x => { p : α × α | edist p.1 p.2 ≤ f x } := by refine ⟨fun s => uniformity_basis_edist.mem_iff.trans ?_⟩ constructor · rintro ⟨ε, ε₀, hε⟩ rcases exists_between ε₀ with ⟨ε', hε'⟩ rcases hf ε' hε'.1 with ⟨i, hi, H⟩ exact ⟨i, hi, fun x hx => hε <| lt_of_le_of_lt (le_trans hx.out H) hε'.2⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, fun x hx => H (le_of_lt hx.out)⟩ #align emetric.mk_uniformity_basis_le EMetric.mk_uniformity_basis_le theorem uniformity_basis_edist_le : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 ≤ ε } := EMetric.mk_uniformity_basis_le (fun _ => id) fun ε ε₀ => ⟨ε, ε₀, le_refl ε⟩ #align uniformity_basis_edist_le uniformity_basis_edist_le theorem uniformity_basis_edist' (ε' : ℝ≥0∞) (hε' : 0 < ε') : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => ε ∈ Ioo 0 ε') fun ε => { p : α × α | edist p.1 p.2 < ε } := EMetric.mk_uniformity_basis (fun _ => And.left) fun ε ε₀ => let ⟨δ, hδ⟩ := exists_between hε' ⟨min ε δ, ⟨lt_min ε₀ hδ.1, lt_of_le_of_lt (min_le_right _ _) hδ.2⟩, min_le_left _ _⟩ #align uniformity_basis_edist' uniformity_basis_edist' theorem uniformity_basis_edist_le' (ε' : ℝ≥0∞) (hε' : 0 < ε') : (𝓤 α).HasBasis (fun ε : ℝ≥0∞ => ε ∈ Ioo 0 ε') fun ε => { p : α × α | edist p.1 p.2 ≤ ε } := EMetric.mk_uniformity_basis_le (fun _ => And.left) fun ε ε₀ => let ⟨δ, hδ⟩ := exists_between hε' ⟨min ε δ, ⟨lt_min ε₀ hδ.1, lt_of_le_of_lt (min_le_right _ _) hδ.2⟩, min_le_left _ _⟩ #align uniformity_basis_edist_le' uniformity_basis_edist_le' theorem uniformity_basis_edist_nnreal : (𝓤 α).HasBasis (fun ε : ℝ≥0 => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 < ε } := EMetric.mk_uniformity_basis (fun _ => ENNReal.coe_pos.2) fun _ε ε₀ => let ⟨δ, hδ⟩ := ENNReal.lt_iff_exists_nnreal_btwn.1 ε₀ ⟨δ, ENNReal.coe_pos.1 hδ.1, le_of_lt hδ.2⟩ #align uniformity_basis_edist_nnreal uniformity_basis_edist_nnreal theorem uniformity_basis_edist_nnreal_le : (𝓤 α).HasBasis (fun ε : ℝ≥0 => 0 < ε) fun ε => { p : α × α | edist p.1 p.2 ≤ ε } := EMetric.mk_uniformity_basis_le (fun _ => ENNReal.coe_pos.2) fun _ε ε₀ => let ⟨δ, hδ⟩ := ENNReal.lt_iff_exists_nnreal_btwn.1 ε₀ ⟨δ, ENNReal.coe_pos.1 hδ.1, le_of_lt hδ.2⟩ #align uniformity_basis_edist_nnreal_le uniformity_basis_edist_nnreal_le theorem uniformity_basis_edist_inv_nat : (𝓤 α).HasBasis (fun _ => True) fun n : ℕ => { p : α × α | edist p.1 p.2 < (↑n)⁻¹ } := EMetric.mk_uniformity_basis (fun n _ ↦ ENNReal.inv_pos.2 <| ENNReal.natCast_ne_top n) fun _ε ε₀ ↦ let ⟨n, hn⟩ := ENNReal.exists_inv_nat_lt (ne_of_gt ε₀) ⟨n, trivial, le_of_lt hn⟩ #align uniformity_basis_edist_inv_nat uniformity_basis_edist_inv_nat theorem uniformity_basis_edist_inv_two_pow : (𝓤 α).HasBasis (fun _ => True) fun n : ℕ => { p : α × α | edist p.1 p.2 < 2⁻¹ ^ n } := EMetric.mk_uniformity_basis (fun _ _ => ENNReal.pow_pos (ENNReal.inv_pos.2 ENNReal.two_ne_top) _) fun _ε ε₀ => let ⟨n, hn⟩ := ENNReal.exists_inv_two_pow_lt (ne_of_gt ε₀) ⟨n, trivial, le_of_lt hn⟩ #align uniformity_basis_edist_inv_two_pow uniformity_basis_edist_inv_two_pow /-- Fixed size neighborhoods of the diagonal belong to the uniform structure -/ theorem edist_mem_uniformity {ε : ℝ≥0∞} (ε0 : 0 < ε) : { p : α × α | edist p.1 p.2 < ε } ∈ 𝓤 α := mem_uniformity_edist.2 ⟨ε, ε0, id⟩ #align edist_mem_uniformity edist_mem_uniformity namespace EMetric instance (priority := 900) instIsCountablyGeneratedUniformity : IsCountablyGenerated (𝓤 α) := isCountablyGenerated_of_seq ⟨_, uniformity_basis_edist_inv_nat.eq_iInf⟩ -- Porting note: changed explicit/implicit /-- ε-δ characterization of uniform continuity on a set for pseudoemetric spaces -/ theorem uniformContinuousOn_iff [PseudoEMetricSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ {a}, a ∈ s → ∀ {b}, b ∈ s → edist a b < δ → edist (f a) (f b) < ε := uniformity_basis_edist.uniformContinuousOn_iff uniformity_basis_edist #align emetric.uniform_continuous_on_iff EMetric.uniformContinuousOn_iff /-- ε-δ characterization of uniform continuity on pseudoemetric spaces -/ theorem uniformContinuous_iff [PseudoEMetricSpace β] {f : α → β} : UniformContinuous f ↔ ∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε := uniformity_basis_edist.uniformContinuous_iff uniformity_basis_edist #align emetric.uniform_continuous_iff EMetric.uniformContinuous_iff -- Porting note (#10756): new lemma theorem uniformInducing_iff [PseudoEMetricSpace β] {f : α → β} : UniformInducing f ↔ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := uniformInducing_iff'.trans <| Iff.rfl.and <| ((uniformity_basis_edist.comap _).le_basis_iff uniformity_basis_edist).trans <| by simp only [subset_def, Prod.forall]; rfl /-- ε-δ characterization of uniform embeddings on pseudoemetric spaces -/ nonrec theorem uniformEmbedding_iff [PseudoEMetricSpace β] {f : α → β} : UniformEmbedding f ↔ Function.Injective f ∧ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := (uniformEmbedding_iff _).trans <| and_comm.trans <| Iff.rfl.and uniformInducing_iff #align emetric.uniform_embedding_iff EMetric.uniformEmbedding_iff /-- If a map between pseudoemetric spaces is a uniform embedding then the edistance between `f x` and `f y` is controlled in terms of the distance between `x` and `y`. In fact, this lemma holds for a `UniformInducing` map. TODO: generalize? -/ theorem controlled_of_uniformEmbedding [PseudoEMetricSpace β] {f : α → β} (h : UniformEmbedding f) : (∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε) ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := ⟨uniformContinuous_iff.1 h.uniformContinuous, (uniformEmbedding_iff.1 h).2.2⟩ #align emetric.controlled_of_uniform_embedding EMetric.controlled_of_uniformEmbedding /-- ε-δ characterization of Cauchy sequences on pseudoemetric spaces -/ protected theorem cauchy_iff {f : Filter α} : Cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x, x ∈ t → ∀ y, y ∈ t → edist x y < ε := by rw [← neBot_iff]; exact uniformity_basis_edist.cauchy_iff #align emetric.cauchy_iff EMetric.cauchy_iff /-- A very useful criterion to show that a space is complete is to show that all sequences which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m ≥ N` are converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to `0`, which makes it possible to use arguments of converging series, while this is impossible to do in general for arbitrary Cauchy sequences. -/ theorem complete_of_convergent_controlled_sequences (B : ℕ → ℝ≥0∞) (hB : ∀ n, 0 < B n) (H : ∀ u : ℕ → α, (∀ N n m : ℕ, N ≤ n → N ≤ m → edist (u n) (u m) < B N) → ∃ x, Tendsto u atTop (𝓝 x)) : CompleteSpace α := UniformSpace.complete_of_convergent_controlled_sequences (fun n => { p : α × α | edist p.1 p.2 < B n }) (fun n => edist_mem_uniformity <| hB n) H #align emetric.complete_of_convergent_controlled_sequences EMetric.complete_of_convergent_controlled_sequences /-- A sequentially complete pseudoemetric space is complete. -/ theorem complete_of_cauchySeq_tendsto : (∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) → CompleteSpace α := UniformSpace.complete_of_cauchySeq_tendsto #align emetric.complete_of_cauchy_seq_tendsto EMetric.complete_of_cauchySeq_tendsto /-- Expressing locally uniform convergence on a set using `edist`. -/ theorem tendstoLocallyUniformlyOn_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoLocallyUniformlyOn F f p s ↔ ∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu x hx => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩ rcases H ε εpos x hx with ⟨t, ht, Ht⟩ exact ⟨t, ht, Ht.mono fun n hs x hx => hε (hs x hx)⟩ #align emetric.tendsto_locally_uniformly_on_iff EMetric.tendstoLocallyUniformlyOn_iff /-- Expressing uniform convergence on a set using `edist`. -/ theorem tendstoUniformlyOn_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoUniformlyOn F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, edist (f x) (F n x) < ε := by refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩ exact (H ε εpos).mono fun n hs x hx => hε (hs x hx) #align emetric.tendsto_uniformly_on_iff EMetric.tendstoUniformlyOn_iff /-- Expressing locally uniform convergence using `edist`. -/ theorem tendstoLocallyUniformly_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoLocallyUniformly F f p ↔ ∀ ε > 0, ∀ x : β, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by simp only [← tendstoLocallyUniformlyOn_univ, tendstoLocallyUniformlyOn_iff, mem_univ, forall_const, exists_prop, nhdsWithin_univ] #align emetric.tendsto_locally_uniformly_iff EMetric.tendstoLocallyUniformly_iff /-- Expressing uniform convergence using `edist`. -/ theorem tendstoUniformly_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoUniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, edist (f x) (F n x) < ε := by simp only [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff, mem_univ, forall_const] #align emetric.tendsto_uniformly_iff EMetric.tendstoUniformly_iff end EMetric open EMetric /-- Auxiliary function to replace the uniformity on a pseudoemetric space with a uniformity which is equal to the original one, but maybe not defeq. This is useful if one wants to construct a pseudoemetric space with a specified uniformity. See Note [forgetful inheritance] explaining why having definitionally the right uniformity is often important. -/ def PseudoEMetricSpace.replaceUniformity {α} [U : UniformSpace α] (m : PseudoEMetricSpace α) (H : 𝓤[U] = 𝓤[PseudoEMetricSpace.toUniformSpace]) : PseudoEMetricSpace α where edist := @edist _ m.toEDist edist_self := edist_self edist_comm := edist_comm edist_triangle := edist_triangle toUniformSpace := U uniformity_edist := H.trans (@PseudoEMetricSpace.uniformity_edist α _) #align pseudo_emetric_space.replace_uniformity PseudoEMetricSpace.replaceUniformity /-- The extended pseudometric induced by a function taking values in a pseudoemetric space. -/ def PseudoEMetricSpace.induced {α β} (f : α → β) (m : PseudoEMetricSpace β) : PseudoEMetricSpace α where edist x y := edist (f x) (f y) edist_self _ := edist_self _ edist_comm _ _ := edist_comm _ _ edist_triangle _ _ _ := edist_triangle _ _ _ toUniformSpace := UniformSpace.comap f m.toUniformSpace uniformity_edist := (uniformity_basis_edist.comap (Prod.map f f)).eq_biInf #align pseudo_emetric_space.induced PseudoEMetricSpace.induced /-- Pseudoemetric space instance on subsets of pseudoemetric spaces -/ instance {α : Type*} {p : α → Prop} [PseudoEMetricSpace α] : PseudoEMetricSpace (Subtype p) := PseudoEMetricSpace.induced Subtype.val ‹_› /-- The extended pseudodistance on a subset of a pseudoemetric space is the restriction of the original pseudodistance, by definition -/ theorem Subtype.edist_eq {p : α → Prop} (x y : Subtype p) : edist x y = edist (x : α) y := rfl #align subtype.edist_eq Subtype.edist_eq namespace MulOpposite /-- Pseudoemetric space instance on the multiplicative opposite of a pseudoemetric space. -/ @[to_additive "Pseudoemetric space instance on the additive opposite of a pseudoemetric space."] instance {α : Type*} [PseudoEMetricSpace α] : PseudoEMetricSpace αᵐᵒᵖ := PseudoEMetricSpace.induced unop ‹_› @[to_additive] theorem edist_unop (x y : αᵐᵒᵖ) : edist (unop x) (unop y) = edist x y := rfl #align mul_opposite.edist_unop MulOpposite.edist_unop #align add_opposite.edist_unop AddOpposite.edist_unop @[to_additive] theorem edist_op (x y : α) : edist (op x) (op y) = edist x y := rfl #align mul_opposite.edist_op MulOpposite.edist_op #align add_opposite.edist_op AddOpposite.edist_op end MulOpposite section ULift instance : PseudoEMetricSpace (ULift α) := PseudoEMetricSpace.induced ULift.down ‹_› theorem ULift.edist_eq (x y : ULift α) : edist x y = edist x.down y.down := rfl #align ulift.edist_eq ULift.edist_eq @[simp] theorem ULift.edist_up_up (x y : α) : edist (ULift.up x) (ULift.up y) = edist x y := rfl #align ulift.edist_up_up ULift.edist_up_up end ULift /-- The product of two pseudoemetric spaces, with the max distance, is an extended pseudometric spaces. We make sure that the uniform structure thus constructed is the one corresponding to the product of uniform spaces, to avoid diamond problems. -/ instance Prod.pseudoEMetricSpaceMax [PseudoEMetricSpace β] : PseudoEMetricSpace (α × β) where edist x y := edist x.1 y.1 ⊔ edist x.2 y.2 edist_self x := by simp edist_comm x y := by simp [edist_comm] edist_triangle x y z := max_le (le_trans (edist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _))) (le_trans (edist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))) uniformity_edist := uniformity_prod.trans <| by simp [PseudoEMetricSpace.uniformity_edist, ← iInf_inf_eq, setOf_and] toUniformSpace := inferInstance #align prod.pseudo_emetric_space_max Prod.pseudoEMetricSpaceMax theorem Prod.edist_eq [PseudoEMetricSpace β] (x y : α × β) : edist x y = max (edist x.1 y.1) (edist x.2 y.2) := rfl #align prod.edist_eq Prod.edist_eq section Pi open Finset variable {π : β → Type*} [Fintype β] -- Porting note: reordered instances instance [∀ b, EDist (π b)] : EDist (∀ b, π b) where edist f g := Finset.sup univ fun b => edist (f b) (g b) theorem edist_pi_def [∀ b, EDist (π b)] (f g : ∀ b, π b) : edist f g = Finset.sup univ fun b => edist (f b) (g b) := rfl #align edist_pi_def edist_pi_def theorem edist_le_pi_edist [∀ b, EDist (π b)] (f g : ∀ b, π b) (b : β) : edist (f b) (g b) ≤ edist f g := le_sup (f := fun b => edist (f b) (g b)) (Finset.mem_univ b) #align edist_le_pi_edist edist_le_pi_edist theorem edist_pi_le_iff [∀ b, EDist (π b)] {f g : ∀ b, π b} {d : ℝ≥0∞} : edist f g ≤ d ↔ ∀ b, edist (f b) (g b) ≤ d := Finset.sup_le_iff.trans <| by simp only [Finset.mem_univ, forall_const] #align edist_pi_le_iff edist_pi_le_iff theorem edist_pi_const_le (a b : α) : (edist (fun _ : β => a) fun _ => b) ≤ edist a b := edist_pi_le_iff.2 fun _ => le_rfl #align edist_pi_const_le edist_pi_const_le @[simp] theorem edist_pi_const [Nonempty β] (a b : α) : (edist (fun _ : β => a) fun _ => b) = edist a b := Finset.sup_const univ_nonempty (edist a b) #align edist_pi_const edist_pi_const /-- The product of a finite number of pseudoemetric spaces, with the max distance, is still a pseudoemetric space. This construction would also work for infinite products, but it would not give rise to the product topology. Hence, we only formalize it in the good situation of finitely many spaces. -/ instance pseudoEMetricSpacePi [∀ b, PseudoEMetricSpace (π b)] : PseudoEMetricSpace (∀ b, π b) where edist_self f := bot_unique <| Finset.sup_le <| by simp edist_comm f g := by simp [edist_pi_def, edist_comm] edist_triangle f g h := edist_pi_le_iff.2 fun b => le_trans (edist_triangle _ (g b) _) (add_le_add (edist_le_pi_edist _ _ _) (edist_le_pi_edist _ _ _)) toUniformSpace := Pi.uniformSpace _ uniformity_edist := by simp only [Pi.uniformity, PseudoEMetricSpace.uniformity_edist, comap_iInf, gt_iff_lt, preimage_setOf_eq, comap_principal, edist_pi_def] rw [iInf_comm]; congr; funext ε rw [iInf_comm]; congr; funext εpos simp [setOf_forall, εpos] #align pseudo_emetric_space_pi pseudoEMetricSpacePi end Pi namespace EMetric variable {x y z : α} {ε ε₁ ε₂ : ℝ≥0∞} {s t : Set α} /-- `EMetric.ball x ε` is the set of all points `y` with `edist y x < ε` -/ def ball (x : α) (ε : ℝ≥0∞) : Set α := { y | edist y x < ε } #align emetric.ball EMetric.ball @[simp] theorem mem_ball : y ∈ ball x ε ↔ edist y x < ε := Iff.rfl #align emetric.mem_ball EMetric.mem_ball theorem mem_ball' : y ∈ ball x ε ↔ edist x y < ε := by rw [edist_comm, mem_ball] #align emetric.mem_ball' EMetric.mem_ball' /-- `EMetric.closedBall x ε` is the set of all points `y` with `edist y x ≤ ε` -/ def closedBall (x : α) (ε : ℝ≥0∞) := { y | edist y x ≤ ε } #align emetric.closed_ball EMetric.closedBall @[simp] theorem mem_closedBall : y ∈ closedBall x ε ↔ edist y x ≤ ε := Iff.rfl #align emetric.mem_closed_ball EMetric.mem_closedBall theorem mem_closedBall' : y ∈ closedBall x ε ↔ edist x y ≤ ε := by rw [edist_comm, mem_closedBall] #align emetric.mem_closed_ball' EMetric.mem_closedBall' @[simp] theorem closedBall_top (x : α) : closedBall x ∞ = univ := eq_univ_of_forall fun _ => mem_setOf.2 le_top #align emetric.closed_ball_top EMetric.closedBall_top theorem ball_subset_closedBall : ball x ε ⊆ closedBall x ε := fun _ h => le_of_lt h.out #align emetric.ball_subset_closed_ball EMetric.ball_subset_closedBall theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε := lt_of_le_of_lt (zero_le _) hy #align emetric.pos_of_mem_ball EMetric.pos_of_mem_ball theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε := by rwa [mem_ball, edist_self] #align emetric.mem_ball_self EMetric.mem_ball_self theorem mem_closedBall_self : x ∈ closedBall x ε := by rw [mem_closedBall, edist_self]; apply zero_le #align emetric.mem_closed_ball_self EMetric.mem_closedBall_self theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε := by rw [mem_ball', mem_ball] #align emetric.mem_ball_comm EMetric.mem_ball_comm theorem mem_closedBall_comm : x ∈ closedBall y ε ↔ y ∈ closedBall x ε := by rw [mem_closedBall', mem_closedBall] #align emetric.mem_closed_ball_comm EMetric.mem_closedBall_comm @[gcongr] theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ := fun _y (yx : _ < ε₁) => lt_of_lt_of_le yx h #align emetric.ball_subset_ball EMetric.ball_subset_ball @[gcongr] theorem closedBall_subset_closedBall (h : ε₁ ≤ ε₂) : closedBall x ε₁ ⊆ closedBall x ε₂ := fun _y (yx : _ ≤ ε₁) => le_trans yx h #align emetric.closed_ball_subset_closed_ball EMetric.closedBall_subset_closedBall theorem ball_disjoint (h : ε₁ + ε₂ ≤ edist x y) : Disjoint (ball x ε₁) (ball y ε₂) := Set.disjoint_left.mpr fun z h₁ h₂ => (edist_triangle_left x y z).not_lt <| (ENNReal.add_lt_add h₁ h₂).trans_le h #align emetric.ball_disjoint EMetric.ball_disjoint theorem ball_subset (h : edist x y + ε₁ ≤ ε₂) (h' : edist x y ≠ ∞) : ball x ε₁ ⊆ ball y ε₂ := fun z zx => calc edist z y ≤ edist z x + edist x y := edist_triangle _ _ _ _ = edist x y + edist z x := add_comm _ _ _ < edist x y + ε₁ := ENNReal.add_lt_add_left h' zx _ ≤ ε₂ := h #align emetric.ball_subset EMetric.ball_subset theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε := by have : 0 < ε - edist y x := by simpa using h refine ⟨ε - edist y x, this, ball_subset ?_ (ne_top_of_lt h)⟩ exact (add_tsub_cancel_of_le (mem_ball.mp h).le).le #align emetric.exists_ball_subset_ball EMetric.exists_ball_subset_ball theorem ball_eq_empty_iff : ball x ε = ∅ ↔ ε = 0 := eq_empty_iff_forall_not_mem.trans ⟨fun h => le_bot_iff.1 (le_of_not_gt fun ε0 => h _ (mem_ball_self ε0)), fun ε0 _ h => not_lt_of_le (le_of_eq ε0) (pos_of_mem_ball h)⟩ #align emetric.ball_eq_empty_iff EMetric.ball_eq_empty_iff theorem ordConnected_setOf_closedBall_subset (x : α) (s : Set α) : OrdConnected { r | closedBall x r ⊆ s } := ⟨fun _ _ _ h₁ _ h₂ => (closedBall_subset_closedBall h₂.2).trans h₁⟩ #align emetric.ord_connected_set_of_closed_ball_subset EMetric.ordConnected_setOf_closedBall_subset theorem ordConnected_setOf_ball_subset (x : α) (s : Set α) : OrdConnected { r | ball x r ⊆ s } := ⟨fun _ _ _ h₁ _ h₂ => (ball_subset_ball h₂.2).trans h₁⟩ #align emetric.ord_connected_set_of_ball_subset EMetric.ordConnected_setOf_ball_subset /-- Relation “two points are at a finite edistance” is an equivalence relation. -/ def edistLtTopSetoid : Setoid α where r x y := edist x y < ⊤ iseqv := ⟨fun x => by rw [edist_self]; exact ENNReal.coe_lt_top, fun h => by rwa [edist_comm], fun hxy hyz => lt_of_le_of_lt (edist_triangle _ _ _) (ENNReal.add_lt_top.2 ⟨hxy, hyz⟩)⟩ #align emetric.edist_lt_top_setoid EMetric.edistLtTopSetoid @[simp] theorem ball_zero : ball x 0 = ∅ := by rw [EMetric.ball_eq_empty_iff] #align emetric.ball_zero EMetric.ball_zero theorem nhds_basis_eball : (𝓝 x).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) (ball x) := nhds_basis_uniformity uniformity_basis_edist #align emetric.nhds_basis_eball EMetric.nhds_basis_eball theorem nhdsWithin_basis_eball : (𝓝[s] x).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) fun ε => ball x ε ∩ s := nhdsWithin_hasBasis nhds_basis_eball s #align emetric.nhds_within_basis_eball EMetric.nhdsWithin_basis_eball theorem nhds_basis_closed_eball : (𝓝 x).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) (closedBall x) := nhds_basis_uniformity uniformity_basis_edist_le #align emetric.nhds_basis_closed_eball EMetric.nhds_basis_closed_eball theorem nhdsWithin_basis_closed_eball : (𝓝[s] x).HasBasis (fun ε : ℝ≥0∞ => 0 < ε) fun ε => closedBall x ε ∩ s := nhdsWithin_hasBasis nhds_basis_closed_eball s #align emetric.nhds_within_basis_closed_eball EMetric.nhdsWithin_basis_closed_eball theorem nhds_eq : 𝓝 x = ⨅ ε > 0, 𝓟 (ball x ε) := nhds_basis_eball.eq_biInf #align emetric.nhds_eq EMetric.nhds_eq theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ ε > 0, ball x ε ⊆ s := nhds_basis_eball.mem_iff #align emetric.mem_nhds_iff EMetric.mem_nhds_iff theorem mem_nhdsWithin_iff : s ∈ 𝓝[t] x ↔ ∃ ε > 0, ball x ε ∩ t ⊆ s := nhdsWithin_basis_eball.mem_iff #align emetric.mem_nhds_within_iff EMetric.mem_nhdsWithin_iff section variable [PseudoEMetricSpace β] {f : α → β} theorem tendsto_nhdsWithin_nhdsWithin {t : Set β} {a b} : Tendsto f (𝓝[s] a) (𝓝[t] b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x⦄, x ∈ s → edist x a < δ → f x ∈ t ∧ edist (f x) b < ε := (nhdsWithin_basis_eball.tendsto_iff nhdsWithin_basis_eball).trans <| forall₂_congr fun ε _ => exists_congr fun δ => and_congr_right fun _ => forall_congr' fun x => by simp; tauto #align emetric.tendsto_nhds_within_nhds_within EMetric.tendsto_nhdsWithin_nhdsWithin theorem tendsto_nhdsWithin_nhds {a b} : Tendsto f (𝓝[s] a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ {x : α}, x ∈ s → edist x a < δ → edist (f x) b < ε := by rw [← nhdsWithin_univ b, tendsto_nhdsWithin_nhdsWithin] simp only [mem_univ, true_and_iff] #align emetric.tendsto_nhds_within_nhds EMetric.tendsto_nhdsWithin_nhds theorem tendsto_nhds_nhds {a b} : Tendsto f (𝓝 a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x⦄, edist x a < δ → edist (f x) b < ε := nhds_basis_eball.tendsto_iff nhds_basis_eball #align emetric.tendsto_nhds_nhds EMetric.tendsto_nhds_nhds end theorem isOpen_iff : IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ball x ε ⊆ s := by simp [isOpen_iff_nhds, mem_nhds_iff] #align emetric.is_open_iff EMetric.isOpen_iff theorem isOpen_ball : IsOpen (ball x ε) := isOpen_iff.2 fun _ => exists_ball_subset_ball #align emetric.is_open_ball EMetric.isOpen_ball theorem isClosed_ball_top : IsClosed (ball x ⊤) := isOpen_compl_iff.1 <| isOpen_iff.2 fun _y hy => ⟨⊤, ENNReal.coe_lt_top, fun _z hzy hzx => hy (edistLtTopSetoid.trans (edistLtTopSetoid.symm hzy) hzx)⟩ #align emetric.is_closed_ball_top EMetric.isClosed_ball_top theorem ball_mem_nhds (x : α) {ε : ℝ≥0∞} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x := isOpen_ball.mem_nhds (mem_ball_self ε0) #align emetric.ball_mem_nhds EMetric.ball_mem_nhds theorem closedBall_mem_nhds (x : α) {ε : ℝ≥0∞} (ε0 : 0 < ε) : closedBall x ε ∈ 𝓝 x := mem_of_superset (ball_mem_nhds x ε0) ball_subset_closedBall #align emetric.closed_ball_mem_nhds EMetric.closedBall_mem_nhds theorem ball_prod_same [PseudoEMetricSpace β] (x : α) (y : β) (r : ℝ≥0∞) : ball x r ×ˢ ball y r = ball (x, y) r := ext fun z => by simp [Prod.edist_eq] #align emetric.ball_prod_same EMetric.ball_prod_same theorem closedBall_prod_same [PseudoEMetricSpace β] (x : α) (y : β) (r : ℝ≥0∞) : closedBall x r ×ˢ closedBall y r = closedBall (x, y) r := ext fun z => by simp [Prod.edist_eq] #align emetric.closed_ball_prod_same EMetric.closedBall_prod_same /-- ε-characterization of the closure in pseudoemetric spaces -/ theorem mem_closure_iff : x ∈ closure s ↔ ∀ ε > 0, ∃ y ∈ s, edist x y < ε := (mem_closure_iff_nhds_basis nhds_basis_eball).trans <| by simp only [mem_ball, edist_comm x] #align emetric.mem_closure_iff EMetric.mem_closure_iff theorem tendsto_nhds {f : Filter β} {u : β → α} {a : α} : Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, edist (u x) a < ε := nhds_basis_eball.tendsto_right_iff #align emetric.tendsto_nhds EMetric.tendsto_nhds theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {u : β → α} {a : α} : Tendsto u atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, edist (u n) a < ε := (atTop_basis.tendsto_iff nhds_basis_eball).trans <| by simp only [exists_prop, true_and_iff, mem_Ici, mem_ball] #align emetric.tendsto_at_top EMetric.tendsto_atTop
Mathlib/Topology/EMetricSpace/Basic.lean
751
752
theorem inseparable_iff : Inseparable x y ↔ edist x y = 0 := by
simp [inseparable_iff_mem_closure, mem_closure_iff, edist_comm, forall_lt_iff_le']
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yakov Pechersky -/ import Mathlib.Data.List.Nodup import Mathlib.Data.List.Zip import Mathlib.Data.Nat.Defs import Mathlib.Data.List.Infix #align_import data.list.rotate from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # List rotation This file proves basic results about `List.rotate`, the list rotation. ## Main declarations * `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`. * `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`. ## Tags rotated, rotation, permutation, cycle -/ universe u variable {α : Type u} open Nat Function namespace List theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] #align list.rotate_mod List.rotate_mod @[simp] theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate] #align list.rotate_nil List.rotate_nil @[simp] theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate] #align list.rotate_zero List.rotate_zero -- Porting note: removing simp, simp can prove it theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by cases n <;> rfl #align list.rotate'_nil List.rotate'_nil @[simp] theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl #align list.rotate'_zero List.rotate'_zero theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate'] #align list.rotate'_cons_succ List.rotate'_cons_succ @[simp] theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length | [], _ => by simp | a :: l, 0 => rfl | a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp #align list.length_rotate' List.length_rotate' theorem rotate'_eq_drop_append_take : ∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n | [], n, h => by simp [drop_append_of_le_length h] | l, 0, h => by simp [take_append_of_le_length h] | a :: l, n + 1, h => by have hnl : n ≤ l.length := le_of_succ_le_succ h have hnl' : n ≤ (l ++ [a]).length := by rw [length_append, length_cons, List.length]; exact le_of_succ_le h rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take, drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp #align list.rotate'_eq_drop_append_take List.rotate'_eq_drop_append_take theorem rotate'_rotate' : ∀ (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m) | a :: l, 0, m => by simp | [], n, m => by simp | a :: l, n + 1, m => by rw [rotate'_cons_succ, rotate'_rotate' _ n, Nat.add_right_comm, ← rotate'_cons_succ, Nat.succ_eq_add_one] #align list.rotate'_rotate' List.rotate'_rotate' @[simp] theorem rotate'_length (l : List α) : rotate' l l.length = l := by rw [rotate'_eq_drop_append_take le_rfl]; simp #align list.rotate'_length List.rotate'_length @[simp] theorem rotate'_length_mul (l : List α) : ∀ n : ℕ, l.rotate' (l.length * n) = l | 0 => by simp | n + 1 => calc l.rotate' (l.length * (n + 1)) = (l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length := by simp [-rotate'_length, Nat.mul_succ, rotate'_rotate'] _ = l := by rw [rotate'_length, rotate'_length_mul l n] #align list.rotate'_length_mul List.rotate'_length_mul theorem rotate'_mod (l : List α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n := calc l.rotate' (n % l.length) = (l.rotate' (n % l.length)).rotate' ((l.rotate' (n % l.length)).length * (n / l.length)) := by rw [rotate'_length_mul] _ = l.rotate' n := by rw [rotate'_rotate', length_rotate', Nat.mod_add_div] #align list.rotate'_mod List.rotate'_mod theorem rotate_eq_rotate' (l : List α) (n : ℕ) : l.rotate n = l.rotate' n := if h : l.length = 0 then by simp_all [length_eq_zero] else by rw [← rotate'_mod, rotate'_eq_drop_append_take (le_of_lt (Nat.mod_lt _ (Nat.pos_of_ne_zero h)))]; simp [rotate] #align list.rotate_eq_rotate' List.rotate_eq_rotate' theorem rotate_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate (n + 1) = (l ++ [a]).rotate n := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate'_cons_succ] #align list.rotate_cons_succ List.rotate_cons_succ @[simp] theorem mem_rotate : ∀ {l : List α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l | [], _, n => by simp | a :: l, _, 0 => by simp | a :: l, _, n + 1 => by simp [rotate_cons_succ, mem_rotate, or_comm] #align list.mem_rotate List.mem_rotate @[simp] theorem length_rotate (l : List α) (n : ℕ) : (l.rotate n).length = l.length := by rw [rotate_eq_rotate', length_rotate'] #align list.length_rotate List.length_rotate @[simp] theorem rotate_replicate (a : α) (n : ℕ) (k : ℕ) : (replicate n a).rotate k = replicate n a := eq_replicate.2 ⟨by rw [length_rotate, length_replicate], fun b hb => eq_of_mem_replicate <| mem_rotate.1 hb⟩ #align list.rotate_replicate List.rotate_replicate theorem rotate_eq_drop_append_take {l : List α} {n : ℕ} : n ≤ l.length → l.rotate n = l.drop n ++ l.take n := by rw [rotate_eq_rotate']; exact rotate'_eq_drop_append_take #align list.rotate_eq_drop_append_take List.rotate_eq_drop_append_take theorem rotate_eq_drop_append_take_mod {l : List α} {n : ℕ} : l.rotate n = l.drop (n % l.length) ++ l.take (n % l.length) := by rcases l.length.zero_le.eq_or_lt with hl | hl · simp [eq_nil_of_length_eq_zero hl.symm] rw [← rotate_eq_drop_append_take (n.mod_lt hl).le, rotate_mod] #align list.rotate_eq_drop_append_take_mod List.rotate_eq_drop_append_take_mod @[simp] theorem rotate_append_length_eq (l l' : List α) : (l ++ l').rotate l.length = l' ++ l := by rw [rotate_eq_rotate'] induction l generalizing l' · simp · simp_all [rotate'] #align list.rotate_append_length_eq List.rotate_append_length_eq theorem rotate_rotate (l : List α) (n m : ℕ) : (l.rotate n).rotate m = l.rotate (n + m) := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate_eq_rotate', rotate'_rotate'] #align list.rotate_rotate List.rotate_rotate @[simp] theorem rotate_length (l : List α) : rotate l l.length = l := by rw [rotate_eq_rotate', rotate'_length] #align list.rotate_length List.rotate_length @[simp] theorem rotate_length_mul (l : List α) (n : ℕ) : l.rotate (l.length * n) = l := by rw [rotate_eq_rotate', rotate'_length_mul] #align list.rotate_length_mul List.rotate_length_mul theorem rotate_perm (l : List α) (n : ℕ) : l.rotate n ~ l := by rw [rotate_eq_rotate'] induction' n with n hn generalizing l · simp · cases' l with hd tl · simp · rw [rotate'_cons_succ] exact (hn _).trans (perm_append_singleton _ _) #align list.rotate_perm List.rotate_perm @[simp] theorem nodup_rotate {l : List α} {n : ℕ} : Nodup (l.rotate n) ↔ Nodup l := (rotate_perm l n).nodup_iff #align list.nodup_rotate List.nodup_rotate @[simp] theorem rotate_eq_nil_iff {l : List α} {n : ℕ} : l.rotate n = [] ↔ l = [] := by induction' n with n hn generalizing l · simp · cases' l with hd tl · simp · simp [rotate_cons_succ, hn] #align list.rotate_eq_nil_iff List.rotate_eq_nil_iff @[simp] theorem nil_eq_rotate_iff {l : List α} {n : ℕ} : [] = l.rotate n ↔ [] = l := by rw [eq_comm, rotate_eq_nil_iff, eq_comm] #align list.nil_eq_rotate_iff List.nil_eq_rotate_iff @[simp] theorem rotate_singleton (x : α) (n : ℕ) : [x].rotate n = [x] := rotate_replicate x 1 n #align list.rotate_singleton List.rotate_singleton theorem zipWith_rotate_distrib {β γ : Type*} (f : α → β → γ) (l : List α) (l' : List β) (n : ℕ) (h : l.length = l'.length) : (zipWith f l l').rotate n = zipWith f (l.rotate n) (l'.rotate n) := by rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, h, zipWith_append, ← zipWith_distrib_drop, ← zipWith_distrib_take, List.length_zipWith, h, min_self] rw [length_drop, length_drop, h] #align list.zip_with_rotate_distrib List.zipWith_rotate_distrib attribute [local simp] rotate_cons_succ -- Porting note: removing @[simp], simp can prove it theorem zipWith_rotate_one {β : Type*} (f : α → α → β) (x y : α) (l : List α) : zipWith f (x :: y :: l) ((x :: y :: l).rotate 1) = f x y :: zipWith f (y :: l) (l ++ [x]) := by simp #align list.zip_with_rotate_one List.zipWith_rotate_one theorem get?_rotate {l : List α} {n m : ℕ} (hml : m < l.length) : (l.rotate n).get? m = l.get? ((m + n) % l.length) := by rw [rotate_eq_drop_append_take_mod] rcases lt_or_le m (l.drop (n % l.length)).length with hm | hm · rw [get?_append hm, get?_drop, ← add_mod_mod] rw [length_drop, Nat.lt_sub_iff_add_lt] at hm rw [mod_eq_of_lt hm, Nat.add_comm] · have hlt : n % length l < length l := mod_lt _ (m.zero_le.trans_lt hml) rw [get?_append_right hm, get?_take, length_drop] · congr 1 rw [length_drop] at hm have hm' := Nat.sub_le_iff_le_add'.1 hm have : n % length l + m - length l < length l := by rw [Nat.sub_lt_iff_lt_add' hm'] exact Nat.add_lt_add hlt hml conv_rhs => rw [Nat.add_comm m, ← mod_add_mod, mod_eq_sub_mod hm', mod_eq_of_lt this] rw [← Nat.add_right_inj, ← Nat.add_sub_assoc, Nat.add_sub_sub_cancel, Nat.add_sub_cancel', Nat.add_comm] exacts [hm', hlt.le, hm] · rwa [Nat.sub_lt_iff_lt_add hm, length_drop, Nat.sub_add_cancel hlt.le] #align list.nth_rotate List.get?_rotate -- Porting note (#10756): new lemma theorem get_rotate (l : List α) (n : ℕ) (k : Fin (l.rotate n).length) : (l.rotate n).get k = l.get ⟨(k + n) % l.length, mod_lt _ (length_rotate l n ▸ k.1.zero_le.trans_lt k.2)⟩ := by rw [← Option.some_inj, ← get?_eq_get, ← get?_eq_get, get?_rotate] exact k.2.trans_eq (length_rotate _ _) theorem head?_rotate {l : List α} {n : ℕ} (h : n < l.length) : head? (l.rotate n) = l.get? n := by rw [← get?_zero, get?_rotate (n.zero_le.trans_lt h), Nat.zero_add, Nat.mod_eq_of_lt h] #align list.head'_rotate List.head?_rotate -- Porting note: moved down from its original location below `get_rotate` so that the -- non-deprecated lemma does not use the deprecated version set_option linter.deprecated false in @[deprecated get_rotate (since := "2023-01-13")] theorem nthLe_rotate (l : List α) (n k : ℕ) (hk : k < (l.rotate n).length) : (l.rotate n).nthLe k hk = l.nthLe ((k + n) % l.length) (mod_lt _ (length_rotate l n ▸ k.zero_le.trans_lt hk)) := get_rotate l n ⟨k, hk⟩ #align list.nth_le_rotate List.nthLe_rotate set_option linter.deprecated false in theorem nthLe_rotate_one (l : List α) (k : ℕ) (hk : k < (l.rotate 1).length) : (l.rotate 1).nthLe k hk = l.nthLe ((k + 1) % l.length) (mod_lt _ (length_rotate l 1 ▸ k.zero_le.trans_lt hk)) := nthLe_rotate l 1 k hk #align list.nth_le_rotate_one List.nthLe_rotate_one -- Porting note (#10756): new lemma /-- A version of `List.get_rotate` that represents `List.get l` in terms of `List.get (List.rotate l n)`, not vice versa. Can be used instead of rewriting `List.get_rotate` from right to left. -/ theorem get_eq_get_rotate (l : List α) (n : ℕ) (k : Fin l.length) : l.get k = (l.rotate n).get ⟨(l.length - n % l.length + k) % l.length, (Nat.mod_lt _ (k.1.zero_le.trans_lt k.2)).trans_eq (length_rotate _ _).symm⟩ := by rw [get_rotate] refine congr_arg l.get (Fin.eq_of_val_eq ?_) simp only [mod_add_mod] rw [← add_mod_mod, Nat.add_right_comm, Nat.sub_add_cancel, add_mod_left, mod_eq_of_lt] exacts [k.2, (mod_lt _ (k.1.zero_le.trans_lt k.2)).le] set_option linter.deprecated false in /-- A variant of `List.nthLe_rotate` useful for rewrites from right to left. -/ @[deprecated get_eq_get_rotate] theorem nthLe_rotate' (l : List α) (n k : ℕ) (hk : k < l.length) : (l.rotate n).nthLe ((l.length - n % l.length + k) % l.length) ((Nat.mod_lt _ (k.zero_le.trans_lt hk)).trans_le (length_rotate _ _).ge) = l.nthLe k hk := (get_eq_get_rotate l n ⟨k, hk⟩).symm #align list.nth_le_rotate' List.nthLe_rotate' theorem rotate_eq_self_iff_eq_replicate [hα : Nonempty α] : ∀ {l : List α}, (∀ n, l.rotate n = l) ↔ ∃ a, l = replicate l.length a | [] => by simp | a :: l => ⟨fun h => ⟨a, ext_get (length_replicate _ _).symm fun n h₁ h₂ => by rw [get_replicate, ← Option.some_inj, ← get?_eq_get, ← head?_rotate h₁, h, head?_cons]⟩, fun ⟨b, hb⟩ n => by rw [hb, rotate_replicate]⟩ #align list.rotate_eq_self_iff_eq_replicate List.rotate_eq_self_iff_eq_replicate theorem rotate_one_eq_self_iff_eq_replicate [Nonempty α] {l : List α} : l.rotate 1 = l ↔ ∃ a : α, l = List.replicate l.length a := ⟨fun h => rotate_eq_self_iff_eq_replicate.mp fun n => Nat.rec l.rotate_zero (fun n hn => by rwa [Nat.succ_eq_add_one, ← l.rotate_rotate, hn]) n, fun h => rotate_eq_self_iff_eq_replicate.mpr h 1⟩ #align list.rotate_one_eq_self_iff_eq_replicate List.rotate_one_eq_self_iff_eq_replicate theorem rotate_injective (n : ℕ) : Function.Injective fun l : List α => l.rotate n := by rintro l l' (h : l.rotate n = l'.rotate n) have hle : l.length = l'.length := (l.length_rotate n).symm.trans (h.symm ▸ l'.length_rotate n) rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod] at h obtain ⟨hd, ht⟩ := append_inj h (by simp_all) rw [← take_append_drop _ l, ht, hd, take_append_drop] #align list.rotate_injective List.rotate_injective @[simp] theorem rotate_eq_rotate {l l' : List α} {n : ℕ} : l.rotate n = l'.rotate n ↔ l = l' := (rotate_injective n).eq_iff #align list.rotate_eq_rotate List.rotate_eq_rotate theorem rotate_eq_iff {l l' : List α} {n : ℕ} : l.rotate n = l' ↔ l = l'.rotate (l'.length - n % l'.length) := by rw [← @rotate_eq_rotate _ l _ n, rotate_rotate, ← rotate_mod l', add_mod] rcases l'.length.zero_le.eq_or_lt with hl | hl · rw [eq_nil_of_length_eq_zero hl.symm, rotate_nil] · rcases (Nat.zero_le (n % l'.length)).eq_or_lt with hn | hn · simp [← hn] · rw [mod_eq_of_lt (Nat.sub_lt hl hn), Nat.sub_add_cancel, mod_self, rotate_zero] exact (Nat.mod_lt _ hl).le #align list.rotate_eq_iff List.rotate_eq_iff @[simp] theorem rotate_eq_singleton_iff {l : List α} {n : ℕ} {x : α} : l.rotate n = [x] ↔ l = [x] := by rw [rotate_eq_iff, rotate_singleton] #align list.rotate_eq_singleton_iff List.rotate_eq_singleton_iff @[simp] theorem singleton_eq_rotate_iff {l : List α} {n : ℕ} {x : α} : [x] = l.rotate n ↔ [x] = l := by rw [eq_comm, rotate_eq_singleton_iff, eq_comm] #align list.singleton_eq_rotate_iff List.singleton_eq_rotate_iff theorem reverse_rotate (l : List α) (n : ℕ) : (l.rotate n).reverse = l.reverse.rotate (l.length - n % l.length) := by rw [← length_reverse l, ← rotate_eq_iff] induction' n with n hn generalizing l · simp · cases' l with hd tl · simp · rw [rotate_cons_succ, ← rotate_rotate, hn] simp #align list.reverse_rotate List.reverse_rotate theorem rotate_reverse (l : List α) (n : ℕ) : l.reverse.rotate n = (l.rotate (l.length - n % l.length)).reverse := by rw [← reverse_reverse l] simp_rw [reverse_rotate, reverse_reverse, rotate_eq_iff, rotate_rotate, length_rotate, length_reverse] rw [← length_reverse l] let k := n % l.reverse.length cases' hk' : k with k' · simp_all! [k, length_reverse, ← rotate_rotate] · cases' l with x l · simp · rw [Nat.mod_eq_of_lt, Nat.sub_add_cancel, rotate_length] · exact Nat.sub_le _ _ · exact Nat.sub_lt (by simp) (by simp_all! [k]) #align list.rotate_reverse List.rotate_reverse theorem map_rotate {β : Type*} (f : α → β) (l : List α) (n : ℕ) : map f (l.rotate n) = (map f l).rotate n := by induction' n with n hn IH generalizing l · simp · cases' l with hd tl · simp · simp [hn] #align list.map_rotate List.map_rotate theorem Nodup.rotate_congr {l : List α} (hl : l.Nodup) (hn : l ≠ []) (i j : ℕ) (h : l.rotate i = l.rotate j) : i % l.length = j % l.length := by rw [← rotate_mod l i, ← rotate_mod l j] at h simpa only [head?_rotate, mod_lt, length_pos_of_ne_nil hn, get?_eq_get, Option.some_inj, hl.get_inj_iff, Fin.ext_iff] using congr_arg head? h #align list.nodup.rotate_congr List.Nodup.rotate_congr theorem Nodup.rotate_congr_iff {l : List α} (hl : l.Nodup) {i j : ℕ} : l.rotate i = l.rotate j ↔ i % l.length = j % l.length ∨ l = [] := by rcases eq_or_ne l [] with rfl | hn · simp · simp only [hn, or_false] refine ⟨hl.rotate_congr hn _ _, fun h ↦ ?_⟩ rw [← rotate_mod, h, rotate_mod] theorem Nodup.rotate_eq_self_iff {l : List α} (hl : l.Nodup) {n : ℕ} : l.rotate n = l ↔ n % l.length = 0 ∨ l = [] := by rw [← zero_mod, ← hl.rotate_congr_iff, rotate_zero] #align list.nodup.rotate_eq_self_iff List.Nodup.rotate_eq_self_iff section IsRotated variable (l l' : List α) /-- `IsRotated l₁ l₂` or `l₁ ~r l₂` asserts that `l₁` and `l₂` are cyclic permutations of each other. This is defined by claiming that `∃ n, l.rotate n = l'`. -/ def IsRotated : Prop := ∃ n, l.rotate n = l' #align list.is_rotated List.IsRotated @[inherit_doc List.IsRotated] infixr:1000 " ~r " => IsRotated variable {l l'} @[refl] theorem IsRotated.refl (l : List α) : l ~r l := ⟨0, by simp⟩ #align list.is_rotated.refl List.IsRotated.refl @[symm] theorem IsRotated.symm (h : l ~r l') : l' ~r l := by obtain ⟨n, rfl⟩ := h cases' l with hd tl · exists 0 · use (hd :: tl).length * n - n rw [rotate_rotate, Nat.add_sub_cancel', rotate_length_mul] exact Nat.le_mul_of_pos_left _ (by simp) #align list.is_rotated.symm List.IsRotated.symm theorem isRotated_comm : l ~r l' ↔ l' ~r l := ⟨IsRotated.symm, IsRotated.symm⟩ #align list.is_rotated_comm List.isRotated_comm @[simp] protected theorem IsRotated.forall (l : List α) (n : ℕ) : l.rotate n ~r l := IsRotated.symm ⟨n, rfl⟩ #align list.is_rotated.forall List.IsRotated.forall @[trans] theorem IsRotated.trans : ∀ {l l' l'' : List α}, l ~r l' → l' ~r l'' → l ~r l'' | _, _, _, ⟨n, rfl⟩, ⟨m, rfl⟩ => ⟨n + m, by rw [rotate_rotate]⟩ #align list.is_rotated.trans List.IsRotated.trans theorem IsRotated.eqv : Equivalence (@IsRotated α) := Equivalence.mk IsRotated.refl IsRotated.symm IsRotated.trans #align list.is_rotated.eqv List.IsRotated.eqv /-- The relation `List.IsRotated l l'` forms a `Setoid` of cycles. -/ def IsRotated.setoid (α : Type*) : Setoid (List α) where r := IsRotated iseqv := IsRotated.eqv #align list.is_rotated.setoid List.IsRotated.setoid theorem IsRotated.perm (h : l ~r l') : l ~ l' := Exists.elim h fun _ hl => hl ▸ (rotate_perm _ _).symm #align list.is_rotated.perm List.IsRotated.perm theorem IsRotated.nodup_iff (h : l ~r l') : Nodup l ↔ Nodup l' := h.perm.nodup_iff #align list.is_rotated.nodup_iff List.IsRotated.nodup_iff theorem IsRotated.mem_iff (h : l ~r l') {a : α} : a ∈ l ↔ a ∈ l' := h.perm.mem_iff #align list.is_rotated.mem_iff List.IsRotated.mem_iff @[simp] theorem isRotated_nil_iff : l ~r [] ↔ l = [] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ #align list.is_rotated_nil_iff List.isRotated_nil_iff @[simp] theorem isRotated_nil_iff' : [] ~r l ↔ [] = l := by rw [isRotated_comm, isRotated_nil_iff, eq_comm] #align list.is_rotated_nil_iff' List.isRotated_nil_iff' @[simp] theorem isRotated_singleton_iff {x : α} : l ~r [x] ↔ l = [x] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ #align list.is_rotated_singleton_iff List.isRotated_singleton_iff @[simp] theorem isRotated_singleton_iff' {x : α} : [x] ~r l ↔ [x] = l := by rw [isRotated_comm, isRotated_singleton_iff, eq_comm] #align list.is_rotated_singleton_iff' List.isRotated_singleton_iff' theorem isRotated_concat (hd : α) (tl : List α) : (tl ++ [hd]) ~r (hd :: tl) := IsRotated.symm ⟨1, by simp⟩ #align list.is_rotated_concat List.isRotated_concat theorem isRotated_append : (l ++ l') ~r (l' ++ l) := ⟨l.length, by simp⟩ #align list.is_rotated_append List.isRotated_append theorem IsRotated.reverse (h : l ~r l') : l.reverse ~r l'.reverse := by obtain ⟨n, rfl⟩ := h exact ⟨_, (reverse_rotate _ _).symm⟩ #align list.is_rotated.reverse List.IsRotated.reverse theorem isRotated_reverse_comm_iff : l.reverse ~r l' ↔ l ~r l'.reverse := by constructor <;> · intro h simpa using h.reverse #align list.is_rotated_reverse_comm_iff List.isRotated_reverse_comm_iff @[simp]
Mathlib/Data/List/Rotate.lean
512
513
theorem isRotated_reverse_iff : l.reverse ~r l'.reverse ↔ l ~r l' := by
simp [isRotated_reverse_comm_iff]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Frédéric Dupuis -/ import Mathlib.Analysis.Convex.Hull #align_import analysis.convex.cone.basic from "leanprover-community/mathlib"@"915591b2bb3ea303648db07284a161a7f2a9e3d4" /-! # Convex cones In a `𝕜`-module `E`, we define a convex cone as a set `s` such that `a • x + b • y ∈ s` whenever `x, y ∈ s` and `a, b > 0`. We prove that convex cones form a `CompleteLattice`, and define their images (`ConvexCone.map`) and preimages (`ConvexCone.comap`) under linear maps. We define pointed, blunt, flat and salient cones, and prove the correspondence between convex cones and ordered modules. We define `Convex.toCone` to be the minimal cone that includes a given convex set. ## Main statements In `Mathlib/Analysis/Convex/Cone/Extension.lean` we prove the M. Riesz extension theorem and a form of the Hahn-Banach theorem. In `Mathlib/Analysis/Convex/Cone/Dual.lean` we prove a variant of the hyperplane separation theorem. ## Implementation notes While `Convex 𝕜` is a predicate on sets, `ConvexCone 𝕜 E` is a bundled convex cone. ## References * https://en.wikipedia.org/wiki/Convex_cone * [Stephen P. Boyd and Lieven Vandenberghe, *Convex Optimization*][boydVandenberghe2004] * [Emo Welzl and Bernd Gärtner, *Cone Programming*][welzl_garter] -/ assert_not_exists NormedSpace assert_not_exists Real open Set LinearMap open scoped Classical open Pointwise variable {𝕜 E F G : Type*} /-! ### Definition of `ConvexCone` and basic properties -/ section Definitions variable (𝕜 E) variable [OrderedSemiring 𝕜] /-- A convex cone is a subset `s` of a `𝕜`-module such that `a • x + b • y ∈ s` whenever `a, b > 0` and `x, y ∈ s`. -/ structure ConvexCone [AddCommMonoid E] [SMul 𝕜 E] where /-- The **carrier set** underlying this cone: the set of points contained in it -/ carrier : Set E smul_mem' : ∀ ⦃c : 𝕜⦄, 0 < c → ∀ ⦃x : E⦄, x ∈ carrier → c • x ∈ carrier add_mem' : ∀ ⦃x⦄ (_ : x ∈ carrier) ⦃y⦄ (_ : y ∈ carrier), x + y ∈ carrier #align convex_cone ConvexCone end Definitions namespace ConvexCone section OrderedSemiring variable [OrderedSemiring 𝕜] [AddCommMonoid E] section SMul variable [SMul 𝕜 E] (S T : ConvexCone 𝕜 E) instance : SetLike (ConvexCone 𝕜 E) E where coe := carrier coe_injective' S T h := by cases S; cases T; congr @[simp] theorem coe_mk {s : Set E} {h₁ h₂} : ↑(@mk 𝕜 _ _ _ _ s h₁ h₂) = s := rfl #align convex_cone.coe_mk ConvexCone.coe_mk @[simp] theorem mem_mk {s : Set E} {h₁ h₂ x} : x ∈ @mk 𝕜 _ _ _ _ s h₁ h₂ ↔ x ∈ s := Iff.rfl #align convex_cone.mem_mk ConvexCone.mem_mk /-- Two `ConvexCone`s are equal if they have the same elements. -/ @[ext] theorem ext {S T : ConvexCone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h #align convex_cone.ext ConvexCone.ext @[aesop safe apply (rule_sets := [SetLike])] theorem smul_mem {c : 𝕜} {x : E} (hc : 0 < c) (hx : x ∈ S) : c • x ∈ S := S.smul_mem' hc hx #align convex_cone.smul_mem ConvexCone.smul_mem theorem add_mem ⦃x⦄ (hx : x ∈ S) ⦃y⦄ (hy : y ∈ S) : x + y ∈ S := S.add_mem' hx hy #align convex_cone.add_mem ConvexCone.add_mem instance : AddMemClass (ConvexCone 𝕜 E) E where add_mem ha hb := add_mem _ ha hb instance : Inf (ConvexCone 𝕜 E) := ⟨fun S T => ⟨S ∩ T, fun _ hc _ hx => ⟨S.smul_mem hc hx.1, T.smul_mem hc hx.2⟩, fun _ hx _ hy => ⟨S.add_mem hx.1 hy.1, T.add_mem hx.2 hy.2⟩⟩⟩ @[simp] theorem coe_inf : ((S ⊓ T : ConvexCone 𝕜 E) : Set E) = ↑S ∩ ↑T := rfl #align convex_cone.coe_inf ConvexCone.coe_inf theorem mem_inf {x} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl #align convex_cone.mem_inf ConvexCone.mem_inf instance : InfSet (ConvexCone 𝕜 E) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, fun _ hc _ hx => mem_biInter fun s hs => s.smul_mem hc <| mem_iInter₂.1 hx s hs, fun _ hx _ hy => mem_biInter fun s hs => s.add_mem (mem_iInter₂.1 hx s hs) (mem_iInter₂.1 hy s hs)⟩⟩ @[simp] theorem coe_sInf (S : Set (ConvexCone 𝕜 E)) : ↑(sInf S) = ⋂ s ∈ S, (s : Set E) := rfl #align convex_cone.coe_Inf ConvexCone.coe_sInf theorem mem_sInf {x : E} {S : Set (ConvexCone 𝕜 E)} : x ∈ sInf S ↔ ∀ s ∈ S, x ∈ s := mem_iInter₂ #align convex_cone.mem_Inf ConvexCone.mem_sInf @[simp] theorem coe_iInf {ι : Sort*} (f : ι → ConvexCone 𝕜 E) : ↑(iInf f) = ⋂ i, (f i : Set E) := by simp [iInf] #align convex_cone.coe_infi ConvexCone.coe_iInf theorem mem_iInf {ι : Sort*} {x : E} {f : ι → ConvexCone 𝕜 E} : x ∈ iInf f ↔ ∀ i, x ∈ f i := mem_iInter₂.trans <| by simp #align convex_cone.mem_infi ConvexCone.mem_iInf variable (𝕜) instance : Bot (ConvexCone 𝕜 E) := ⟨⟨∅, fun _ _ _ => False.elim, fun _ => False.elim⟩⟩ theorem mem_bot (x : E) : (x ∈ (⊥ : ConvexCone 𝕜 E)) = False := rfl #align convex_cone.mem_bot ConvexCone.mem_bot @[simp] theorem coe_bot : ↑(⊥ : ConvexCone 𝕜 E) = (∅ : Set E) := rfl #align convex_cone.coe_bot ConvexCone.coe_bot instance : Top (ConvexCone 𝕜 E) := ⟨⟨univ, fun _ _ _ _ => mem_univ _, fun _ _ _ _ => mem_univ _⟩⟩ theorem mem_top (x : E) : x ∈ (⊤ : ConvexCone 𝕜 E) := mem_univ x #align convex_cone.mem_top ConvexCone.mem_top @[simp] theorem coe_top : ↑(⊤ : ConvexCone 𝕜 E) = (univ : Set E) := rfl #align convex_cone.coe_top ConvexCone.coe_top instance : CompleteLattice (ConvexCone 𝕜 E) := { SetLike.instPartialOrder with le := (· ≤ ·) lt := (· < ·) bot := ⊥ bot_le := fun _ _ => False.elim top := ⊤ le_top := fun _ x _ => mem_top 𝕜 x inf := (· ⊓ ·) sInf := InfSet.sInf sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x } sSup := fun s => sInf { T | ∀ S ∈ s, S ≤ T } le_sup_left := fun _ _ => fun _ hx => mem_sInf.2 fun _ hs => hs.1 hx le_sup_right := fun _ _ => fun _ hx => mem_sInf.2 fun _ hs => hs.2 hx sup_le := fun _ _ c ha hb _ hx => mem_sInf.1 hx c ⟨ha, hb⟩ le_inf := fun _ _ _ ha hb _ hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_sSup := fun _ p hs _ hx => mem_sInf.2 fun _ ht => ht p hs hx sSup_le := fun _ p hs _ hx => mem_sInf.1 hx p hs le_sInf := fun _ _ ha _ hx => mem_sInf.2 fun t ht => ha t ht hx sInf_le := fun _ _ ha _ hx => mem_sInf.1 hx _ ha } instance : Inhabited (ConvexCone 𝕜 E) := ⟨⊥⟩ end SMul section Module variable [Module 𝕜 E] (S : ConvexCone 𝕜 E) protected theorem convex : Convex 𝕜 (S : Set E) := convex_iff_forall_pos.2 fun _ hx _ hy _ _ ha hb _ => S.add_mem (S.smul_mem ha hx) (S.smul_mem hb hy) #align convex_cone.convex ConvexCone.convex end Module section Maps variable [AddCommMonoid E] [AddCommMonoid F] [AddCommMonoid G] variable [Module 𝕜 E] [Module 𝕜 F] [Module 𝕜 G] /-- The image of a convex cone under a `𝕜`-linear map is a convex cone. -/ def map (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 E) : ConvexCone 𝕜 F where carrier := f '' S smul_mem' := fun c hc _ ⟨x, hx, hy⟩ => hy ▸ f.map_smul c x ▸ mem_image_of_mem f (S.smul_mem hc hx) add_mem' := fun _ ⟨x₁, hx₁, hy₁⟩ _ ⟨x₂, hx₂, hy₂⟩ => hy₁ ▸ hy₂ ▸ f.map_add x₁ x₂ ▸ mem_image_of_mem f (S.add_mem hx₁ hx₂) #align convex_cone.map ConvexCone.map @[simp, norm_cast] theorem coe_map (S : ConvexCone 𝕜 E) (f : E →ₗ[𝕜] F) : (S.map f : Set F) = f '' S := rfl @[simp] theorem mem_map {f : E →ₗ[𝕜] F} {S : ConvexCone 𝕜 E} {y : F} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := Set.mem_image f S y #align convex_cone.mem_map ConvexCone.mem_map theorem map_map (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 E) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| image_image g f S #align convex_cone.map_map ConvexCone.map_map @[simp] theorem map_id (S : ConvexCone 𝕜 E) : S.map LinearMap.id = S := SetLike.coe_injective <| image_id _ #align convex_cone.map_id ConvexCone.map_id /-- The preimage of a convex cone under a `𝕜`-linear map is a convex cone. -/ def comap (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 F) : ConvexCone 𝕜 E where carrier := f ⁻¹' S smul_mem' c hc x hx := by rw [mem_preimage, f.map_smul c] exact S.smul_mem hc hx add_mem' x hx y hy := by rw [mem_preimage, f.map_add] exact S.add_mem hx hy #align convex_cone.comap ConvexCone.comap @[simp] theorem coe_comap (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 F) : (S.comap f : Set E) = f ⁻¹' S := rfl #align convex_cone.coe_comap ConvexCone.coe_comap @[simp] -- Porting note: was not a `dsimp` lemma theorem comap_id (S : ConvexCone 𝕜 E) : S.comap LinearMap.id = S := rfl #align convex_cone.comap_id ConvexCone.comap_id theorem comap_comap (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 G) : (S.comap g).comap f = S.comap (g.comp f) := rfl #align convex_cone.comap_comap ConvexCone.comap_comap @[simp] theorem mem_comap {f : E →ₗ[𝕜] F} {S : ConvexCone 𝕜 F} {x : E} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl #align convex_cone.mem_comap ConvexCone.mem_comap end Maps end OrderedSemiring section LinearOrderedField variable [LinearOrderedField 𝕜] section MulAction variable [AddCommMonoid E] variable [MulAction 𝕜 E] (S : ConvexCone 𝕜 E) theorem smul_mem_iff {c : 𝕜} (hc : 0 < c) {x : E} : c • x ∈ S ↔ x ∈ S := ⟨fun h => inv_smul_smul₀ hc.ne' x ▸ S.smul_mem (inv_pos.2 hc) h, S.smul_mem hc⟩ #align convex_cone.smul_mem_iff ConvexCone.smul_mem_iff end MulAction section OrderedAddCommGroup variable [OrderedAddCommGroup E] [Module 𝕜 E] /-- Constructs an ordered module given an `OrderedAddCommGroup`, a cone, and a proof that the order relation is the one defined by the cone. -/ theorem to_orderedSMul (S : ConvexCone 𝕜 E) (h : ∀ x y : E, x ≤ y ↔ y - x ∈ S) : OrderedSMul 𝕜 E := OrderedSMul.mk' (by intro x y z xy hz rw [h (z • x) (z • y), ← smul_sub z y x] exact smul_mem S hz ((h x y).mp xy.le)) #align convex_cone.to_ordered_smul ConvexCone.to_orderedSMul end OrderedAddCommGroup end LinearOrderedField /-! ### Convex cones with extra properties -/ section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [SMul 𝕜 E] (S : ConvexCone 𝕜 E) /-- A convex cone is pointed if it includes `0`. -/ def Pointed (S : ConvexCone 𝕜 E) : Prop := (0 : E) ∈ S #align convex_cone.pointed ConvexCone.Pointed /-- A convex cone is blunt if it doesn't include `0`. -/ def Blunt (S : ConvexCone 𝕜 E) : Prop := (0 : E) ∉ S #align convex_cone.blunt ConvexCone.Blunt theorem pointed_iff_not_blunt (S : ConvexCone 𝕜 E) : S.Pointed ↔ ¬S.Blunt := ⟨fun h₁ h₂ => h₂ h₁, Classical.not_not.mp⟩ #align convex_cone.pointed_iff_not_blunt ConvexCone.pointed_iff_not_blunt theorem blunt_iff_not_pointed (S : ConvexCone 𝕜 E) : S.Blunt ↔ ¬S.Pointed := by rw [pointed_iff_not_blunt, Classical.not_not] #align convex_cone.blunt_iff_not_pointed ConvexCone.blunt_iff_not_pointed theorem Pointed.mono {S T : ConvexCone 𝕜 E} (h : S ≤ T) : S.Pointed → T.Pointed := @h _ #align convex_cone.pointed.mono ConvexCone.Pointed.mono theorem Blunt.anti {S T : ConvexCone 𝕜 E} (h : T ≤ S) : S.Blunt → T.Blunt := (· ∘ @h 0) #align convex_cone.blunt.anti ConvexCone.Blunt.anti end AddCommMonoid section AddCommGroup variable [AddCommGroup E] [SMul 𝕜 E] (S : ConvexCone 𝕜 E) /-- A convex cone is flat if it contains some nonzero vector `x` and its opposite `-x`. -/ def Flat : Prop := ∃ x ∈ S, x ≠ (0 : E) ∧ -x ∈ S #align convex_cone.flat ConvexCone.Flat /-- A convex cone is salient if it doesn't include `x` and `-x` for any nonzero `x`. -/ def Salient : Prop := ∀ x ∈ S, x ≠ (0 : E) → -x ∉ S #align convex_cone.salient ConvexCone.Salient theorem salient_iff_not_flat (S : ConvexCone 𝕜 E) : S.Salient ↔ ¬S.Flat := by simp [Salient, Flat] #align convex_cone.salient_iff_not_flat ConvexCone.salient_iff_not_flat theorem Flat.mono {S T : ConvexCone 𝕜 E} (h : S ≤ T) : S.Flat → T.Flat | ⟨x, hxS, hx, hnxS⟩ => ⟨x, h hxS, hx, h hnxS⟩ #align convex_cone.flat.mono ConvexCone.Flat.mono theorem Salient.anti {S T : ConvexCone 𝕜 E} (h : T ≤ S) : S.Salient → T.Salient := fun hS x hxT hx hnT => hS x (h hxT) hx (h hnT) #align convex_cone.salient.anti ConvexCone.Salient.anti /-- A flat cone is always pointed (contains `0`). -/ theorem Flat.pointed {S : ConvexCone 𝕜 E} (hS : S.Flat) : S.Pointed := by obtain ⟨x, hx, _, hxneg⟩ := hS rw [Pointed, ← add_neg_self x] exact add_mem S hx hxneg #align convex_cone.flat.pointed ConvexCone.Flat.pointed /-- A blunt cone (one not containing `0`) is always salient. -/ theorem Blunt.salient {S : ConvexCone 𝕜 E} : S.Blunt → S.Salient := by rw [salient_iff_not_flat, blunt_iff_not_pointed] exact mt Flat.pointed #align convex_cone.blunt.salient ConvexCone.Blunt.salient /-- A pointed convex cone defines a preorder. -/ def toPreorder (h₁ : S.Pointed) : Preorder E where le x y := y - x ∈ S le_refl x := by change x - x ∈ S; rw [sub_self x]; exact h₁ le_trans x y z xy zy := by simpa using add_mem S zy xy #align convex_cone.to_preorder ConvexCone.toPreorder /-- A pointed and salient cone defines a partial order. -/ def toPartialOrder (h₁ : S.Pointed) (h₂ : S.Salient) : PartialOrder E := { toPreorder S h₁ with le_antisymm := by intro a b ab ba by_contra h have h' : b - a ≠ 0 := fun h'' => h (eq_of_sub_eq_zero h'').symm have H := h₂ (b - a) ab h' rw [neg_sub b a] at H exact H ba } #align convex_cone.to_partial_order ConvexCone.toPartialOrder /-- A pointed and salient cone defines an `OrderedAddCommGroup`. -/ def toOrderedAddCommGroup (h₁ : S.Pointed) (h₂ : S.Salient) : OrderedAddCommGroup E := { toPartialOrder S h₁ h₂, show AddCommGroup E by infer_instance with add_le_add_left := by intro a b hab c change c + b - (c + a) ∈ S rw [add_sub_add_left_eq_sub] exact hab } #align convex_cone.to_ordered_add_comm_group ConvexCone.toOrderedAddCommGroup end AddCommGroup section Module variable [AddCommMonoid E] [Module 𝕜 E] instance : Zero (ConvexCone 𝕜 E) := ⟨⟨0, fun _ _ => by simp, fun _ => by simp⟩⟩ @[simp] theorem mem_zero (x : E) : x ∈ (0 : ConvexCone 𝕜 E) ↔ x = 0 := Iff.rfl #align convex_cone.mem_zero ConvexCone.mem_zero @[simp] theorem coe_zero : ((0 : ConvexCone 𝕜 E) : Set E) = 0 := rfl #align convex_cone.coe_zero ConvexCone.coe_zero theorem pointed_zero : (0 : ConvexCone 𝕜 E).Pointed := by rw [Pointed, mem_zero] #align convex_cone.pointed_zero ConvexCone.pointed_zero instance instAdd : Add (ConvexCone 𝕜 E) := ⟨fun K₁ K₂ => { carrier := { z | ∃ x ∈ K₁, ∃ y ∈ K₂, x + y = z } smul_mem' := by rintro c hc _ ⟨x, hx, y, hy, rfl⟩ rw [smul_add] use c • x, K₁.smul_mem hc hx, c • y, K₂.smul_mem hc hy add_mem' := by rintro _ ⟨x₁, hx₁, x₂, hx₂, rfl⟩ y ⟨y₁, hy₁, y₂, hy₂, rfl⟩ use x₁ + y₁, K₁.add_mem hx₁ hy₁, x₂ + y₂, K₂.add_mem hx₂ hy₂ abel }⟩ @[simp] theorem mem_add {K₁ K₂ : ConvexCone 𝕜 E} {a : E} : a ∈ K₁ + K₂ ↔ ∃ x ∈ K₁, ∃ y ∈ K₂, x + y = a := Iff.rfl #align convex_cone.mem_add ConvexCone.mem_add instance instAddZeroClass : AddZeroClass (ConvexCone 𝕜 E) where zero_add _ := by ext; simp add_zero _ := by ext; simp instance instAddCommSemigroup : AddCommSemigroup (ConvexCone 𝕜 E) where add := Add.add add_assoc _ _ _ := SetLike.coe_injective <| add_assoc _ _ _ add_comm _ _ := SetLike.coe_injective <| add_comm _ _ end Module end OrderedSemiring end ConvexCone namespace Submodule /-! ### Submodules are cones -/ section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [Module 𝕜 E] /-- Every submodule is trivially a convex cone. -/ def toConvexCone (S : Submodule 𝕜 E) : ConvexCone 𝕜 E where carrier := S smul_mem' c _ _ hx := S.smul_mem c hx add_mem' _ hx _ hy := S.add_mem hx hy #align submodule.to_convex_cone Submodule.toConvexCone @[simp] theorem coe_toConvexCone (S : Submodule 𝕜 E) : ↑S.toConvexCone = (S : Set E) := rfl #align submodule.coe_to_convex_cone Submodule.coe_toConvexCone @[simp] theorem mem_toConvexCone {x : E} {S : Submodule 𝕜 E} : x ∈ S.toConvexCone ↔ x ∈ S := Iff.rfl #align submodule.mem_to_convex_cone Submodule.mem_toConvexCone @[simp] theorem toConvexCone_le_iff {S T : Submodule 𝕜 E} : S.toConvexCone ≤ T.toConvexCone ↔ S ≤ T := Iff.rfl #align submodule.to_convex_cone_le_iff Submodule.toConvexCone_le_iff @[simp] theorem toConvexCone_bot : (⊥ : Submodule 𝕜 E).toConvexCone = 0 := rfl #align submodule.to_convex_cone_bot Submodule.toConvexCone_bot @[simp] theorem toConvexCone_top : (⊤ : Submodule 𝕜 E).toConvexCone = ⊤ := rfl #align submodule.to_convex_cone_top Submodule.toConvexCone_top @[simp] theorem toConvexCone_inf (S T : Submodule 𝕜 E) : (S ⊓ T).toConvexCone = S.toConvexCone ⊓ T.toConvexCone := rfl #align submodule.to_convex_cone_inf Submodule.toConvexCone_inf @[simp] theorem pointed_toConvexCone (S : Submodule 𝕜 E) : S.toConvexCone.Pointed := S.zero_mem #align submodule.pointed_to_convex_cone Submodule.pointed_toConvexCone end AddCommMonoid end OrderedSemiring end Submodule namespace ConvexCone /-! ### Positive cone of an ordered module -/ section PositiveCone variable (𝕜 E) [OrderedSemiring 𝕜] [OrderedAddCommGroup E] [Module 𝕜 E] [OrderedSMul 𝕜 E] /-- The positive cone is the convex cone formed by the set of nonnegative elements in an ordered module. -/ def positive : ConvexCone 𝕜 E where carrier := Set.Ici 0 smul_mem' _ hc _ (hx : _ ≤ _) := smul_nonneg hc.le hx add_mem' _ (hx : _ ≤ _) _ (hy : _ ≤ _) := add_nonneg hx hy #align convex_cone.positive ConvexCone.positive @[simp] theorem mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x := Iff.rfl #align convex_cone.mem_positive ConvexCone.mem_positive @[simp] theorem coe_positive : ↑(positive 𝕜 E) = Set.Ici (0 : E) := rfl #align convex_cone.coe_positive ConvexCone.coe_positive /-- The positive cone of an ordered module is always salient. -/ theorem salient_positive : Salient (positive 𝕜 E) := fun x xs hx hx' => lt_irrefl (0 : E) (calc 0 < x := lt_of_le_of_ne xs hx.symm _ ≤ x + -x := le_add_of_nonneg_right hx' _ = 0 := add_neg_self x ) #align convex_cone.salient_positive ConvexCone.salient_positive /-- The positive cone of an ordered module is always pointed. -/ theorem pointed_positive : Pointed (positive 𝕜 E) := le_refl 0 #align convex_cone.pointed_positive ConvexCone.pointed_positive /-- The cone of strictly positive elements. Note that this naming diverges from the mathlib convention of `pos` and `nonneg` due to "positive cone" (`ConvexCone.positive`) being established terminology for the non-negative elements. -/ def strictlyPositive : ConvexCone 𝕜 E where carrier := Set.Ioi 0 smul_mem' _ hc _ (hx : _ < _) := smul_pos hc hx add_mem' _ hx _ hy := add_pos hx hy #align convex_cone.strictly_positive ConvexCone.strictlyPositive @[simp] theorem mem_strictlyPositive {x : E} : x ∈ strictlyPositive 𝕜 E ↔ 0 < x := Iff.rfl #align convex_cone.mem_strictly_positive ConvexCone.mem_strictlyPositive @[simp] theorem coe_strictlyPositive : ↑(strictlyPositive 𝕜 E) = Set.Ioi (0 : E) := rfl #align convex_cone.coe_strictly_positive ConvexCone.coe_strictlyPositive theorem positive_le_strictlyPositive : strictlyPositive 𝕜 E ≤ positive 𝕜 E := fun _ => le_of_lt #align convex_cone.positive_le_strictly_positive ConvexCone.positive_le_strictlyPositive /-- The strictly positive cone of an ordered module is always salient. -/ theorem salient_strictlyPositive : Salient (strictlyPositive 𝕜 E) := (salient_positive 𝕜 E).anti <| positive_le_strictlyPositive 𝕜 E #align convex_cone.salient_strictly_positive ConvexCone.salient_strictlyPositive /-- The strictly positive cone of an ordered module is always blunt. -/ theorem blunt_strictlyPositive : Blunt (strictlyPositive 𝕜 E) := lt_irrefl 0 #align convex_cone.blunt_strictly_positive ConvexCone.blunt_strictlyPositive end PositiveCone end ConvexCone /-! ### Cone over a convex set -/ section ConeFromConvex variable [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] namespace Convex /-- The set of vectors proportional to those in a convex set forms a convex cone. -/ def toCone (s : Set E) (hs : Convex 𝕜 s) : ConvexCone 𝕜 E := by apply ConvexCone.mk (⋃ (c : 𝕜) (_ : 0 < c), c • s) <;> simp only [mem_iUnion, mem_smul_set] · rintro c c_pos _ ⟨c', c'_pos, x, hx, rfl⟩ exact ⟨c * c', mul_pos c_pos c'_pos, x, hx, (smul_smul _ _ _).symm⟩ · rintro _ ⟨cx, cx_pos, x, hx, rfl⟩ _ ⟨cy, cy_pos, y, hy, rfl⟩ have : 0 < cx + cy := add_pos cx_pos cy_pos refine ⟨_, this, _, convex_iff_div.1 hs hx hy cx_pos.le cy_pos.le this, ?_⟩ simp only [smul_add, smul_smul, mul_div_assoc', mul_div_cancel_left₀ _ this.ne'] #align convex.to_cone Convex.toCone variable {s : Set E} (hs : Convex 𝕜 s) {x : E} theorem mem_toCone : x ∈ hs.toCone s ↔ ∃ c : 𝕜, 0 < c ∧ ∃ y ∈ s, c • y = x := by simp only [toCone, ConvexCone.mem_mk, mem_iUnion, mem_smul_set, eq_comm, exists_prop] #align convex.mem_to_cone Convex.mem_toCone theorem mem_toCone' : x ∈ hs.toCone s ↔ ∃ c : 𝕜, 0 < c ∧ c • x ∈ s := by refine hs.mem_toCone.trans ⟨?_, ?_⟩ · rintro ⟨c, hc, y, hy, rfl⟩ exact ⟨c⁻¹, inv_pos.2 hc, by rwa [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ · rintro ⟨c, hc, hcx⟩ exact ⟨c⁻¹, inv_pos.2 hc, _, hcx, by rw [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ #align convex.mem_to_cone' Convex.mem_toCone' theorem subset_toCone : s ⊆ hs.toCone s := fun x hx => hs.mem_toCone'.2 ⟨1, zero_lt_one, by rwa [one_smul]⟩ #align convex.subset_to_cone Convex.subset_toCone /-- `hs.toCone s` is the least cone that includes `s`. -/
Mathlib/Analysis/Convex/Cone/Basic.lean
658
661
theorem toCone_isLeast : IsLeast { t : ConvexCone 𝕜 E | s ⊆ t } (hs.toCone s) := by
refine ⟨hs.subset_toCone, fun t ht x hx => ?_⟩ rcases hs.mem_toCone.1 hx with ⟨c, hc, y, hy, rfl⟩ exact t.smul_mem hc (ht hy)
/- 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.Topology.Algebra.Algebra import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Topology.UrysohnsLemma import Mathlib.Analysis.RCLike.Basic import Mathlib.Analysis.NormedSpace.Units import Mathlib.Topology.Algebra.Module.CharacterSpace #align_import topology.continuous_function.ideals from "leanprover-community/mathlib"@"c2258f7bf086b17eac0929d635403780c39e239f" /-! # Ideals of continuous functions For a topological semiring `R` and a topological space `X` there is a Galois connection between `Ideal C(X, R)` and `Set X` given by sending each `I : Ideal C(X, R)` to `{x : X | ∀ f ∈ I, f x = 0}ᶜ` and mapping `s : Set X` to the ideal with carrier `{f : C(X, R) | ∀ x ∈ sᶜ, f x = 0}`, and we call these maps `ContinuousMap.setOfIdeal` and `ContinuousMap.idealOfSet`. As long as `R` is Hausdorff, `ContinuousMap.setOfIdeal I` is open, and if, in addition, `X` is locally compact, then `ContinuousMap.setOfIdeal s` is closed. When `R = 𝕜` with `RCLike 𝕜` and `X` is compact Hausdorff, then this Galois connection can be improved to a true Galois correspondence (i.e., order isomorphism) between the type `opens X` and the subtype of closed ideals of `C(X, 𝕜)`. Because we do not have a bundled type of closed ideals, we simply register this as a Galois insertion between `Ideal C(X, 𝕜)` and `opens X`, which is `ContinuousMap.idealOpensGI`. Consequently, the maximal ideals of `C(X, 𝕜)` are precisely those ideals corresponding to (complements of) singletons in `X`. In addition, when `X` is locally compact and `𝕜` is a nontrivial topological integral domain, then there is a natural continuous map from `X` to `WeakDual.characterSpace 𝕜 C(X, 𝕜)` given by point evaluation, which is herein called `WeakDual.CharacterSpace.continuousMapEval`. Again, when `X` is compact Hausdorff and `RCLike 𝕜`, more can be obtained. In particular, in that context this map is bijective, and since the domain is compact and the codomain is Hausdorff, it is a homeomorphism, herein called `WeakDual.CharacterSpace.homeoEval`. ## Main definitions * `ContinuousMap.idealOfSet`: ideal of functions which vanish on the complement of a set. * `ContinuousMap.setOfIdeal`: complement of the set on which all functions in the ideal vanish. * `ContinuousMap.opensOfIdeal`: `ContinuousMap.setOfIdeal` as a term of `opens X`. * `ContinuousMap.idealOpensGI`: The Galois insertion `ContinuousMap.opensOfIdeal` and `fun s ↦ ContinuousMap.idealOfSet ↑s`. * `WeakDual.CharacterSpace.continuousMapEval`: the natural continuous map from a locally compact topological space `X` to the `WeakDual.characterSpace 𝕜 C(X, 𝕜)` which sends `x : X` to point evaluation at `x`, with modest hypothesis on `𝕜`. * `WeakDual.CharacterSpace.homeoEval`: this is `WeakDual.CharacterSpace.continuousMapEval` upgraded to a homeomorphism when `X` is compact Hausdorff and `RCLike 𝕜`. ## Main statements * `ContinuousMap.idealOfSet_ofIdeal_eq_closure`: when `X` is compact Hausdorff and `RCLike 𝕜`, `idealOfSet 𝕜 (setOfIdeal I) = I.closure` for any ideal `I : Ideal C(X, 𝕜)`. * `ContinuousMap.setOfIdeal_ofSet_eq_interior`: when `X` is compact Hausdorff and `RCLike 𝕜`, `setOfIdeal (idealOfSet 𝕜 s) = interior s` for any `s : Set X`. * `ContinuousMap.ideal_isMaximal_iff`: when `X` is compact Hausdorff and `RCLike 𝕜`, a closed ideal of `C(X, 𝕜)` is maximal if and only if it is `idealOfSet 𝕜 {x}ᶜ` for some `x : X`. ## Implementation details Because there does not currently exist a bundled type of closed ideals, we don't provide the actual order isomorphism described above, and instead we only consider the Galois insertion `ContinuousMap.idealOpensGI`. ## Tags ideal, continuous function, compact, Hausdorff -/ open scoped NNReal namespace ContinuousMap open TopologicalSpace section TopologicalRing variable {X R : Type*} [TopologicalSpace X] [Semiring R] variable [TopologicalSpace R] [TopologicalSemiring R] variable (R) /-- Given a topological ring `R` and `s : Set X`, construct the ideal in `C(X, R)` of functions which vanish on the complement of `s`. -/ def idealOfSet (s : Set X) : Ideal C(X, R) where carrier := {f : C(X, R) | ∀ x ∈ sᶜ, f x = 0} add_mem' {f g} hf hg x hx := by simp [hf x hx, hg x hx, coe_add, Pi.add_apply, add_zero] zero_mem' _ _ := rfl smul_mem' c f hf x hx := mul_zero (c x) ▸ congr_arg (fun y => c x * y) (hf x hx) #align continuous_map.ideal_of_set ContinuousMap.idealOfSet theorem idealOfSet_closed [T2Space R] (s : Set X) : IsClosed (idealOfSet R s : Set C(X, R)) := by simp only [idealOfSet, Submodule.coe_set_mk, Set.setOf_forall] exact isClosed_iInter fun x => isClosed_iInter fun _ => isClosed_eq (continuous_eval_const x) continuous_const #align continuous_map.ideal_of_set_closed ContinuousMap.idealOfSet_closed variable {R} theorem mem_idealOfSet {s : Set X} {f : C(X, R)} : f ∈ idealOfSet R s ↔ ∀ ⦃x : X⦄, x ∈ sᶜ → f x = 0 := by convert Iff.rfl #align continuous_map.mem_ideal_of_set ContinuousMap.mem_idealOfSet theorem not_mem_idealOfSet {s : Set X} {f : C(X, R)} : f ∉ idealOfSet R s ↔ ∃ x ∈ sᶜ, f x ≠ 0 := by simp_rw [mem_idealOfSet]; push_neg; rfl #align continuous_map.not_mem_ideal_of_set ContinuousMap.not_mem_idealOfSet /-- Given an ideal `I` of `C(X, R)`, construct the set of points for which every function in the ideal vanishes on the complement. -/ def setOfIdeal (I : Ideal C(X, R)) : Set X := {x : X | ∀ f ∈ I, (f : C(X, R)) x = 0}ᶜ #align continuous_map.set_of_ideal ContinuousMap.setOfIdeal theorem not_mem_setOfIdeal {I : Ideal C(X, R)} {x : X} : x ∉ setOfIdeal I ↔ ∀ ⦃f : C(X, R)⦄, f ∈ I → f x = 0 := by rw [← Set.mem_compl_iff, setOfIdeal, compl_compl, Set.mem_setOf] #align continuous_map.not_mem_set_of_ideal ContinuousMap.not_mem_setOfIdeal theorem mem_setOfIdeal {I : Ideal C(X, R)} {x : X} : x ∈ setOfIdeal I ↔ ∃ f ∈ I, (f : C(X, R)) x ≠ 0 := by simp_rw [setOfIdeal, Set.mem_compl_iff, Set.mem_setOf]; push_neg; rfl #align continuous_map.mem_set_of_ideal ContinuousMap.mem_setOfIdeal theorem setOfIdeal_open [T2Space R] (I : Ideal C(X, R)) : IsOpen (setOfIdeal I) := by simp only [setOfIdeal, Set.setOf_forall, isOpen_compl_iff] exact isClosed_iInter fun f => isClosed_iInter fun _ => isClosed_eq (map_continuous f) continuous_const #align continuous_map.set_of_ideal_open ContinuousMap.setOfIdeal_open /-- The open set `ContinuousMap.setOfIdeal I` realized as a term of `opens X`. -/ @[simps] def opensOfIdeal [T2Space R] (I : Ideal C(X, R)) : Opens X := ⟨setOfIdeal I, setOfIdeal_open I⟩ #align continuous_map.opens_of_ideal ContinuousMap.opensOfIdeal @[simp] theorem setOfTop_eq_univ [Nontrivial R] : setOfIdeal (⊤ : Ideal C(X, R)) = Set.univ := Set.univ_subset_iff.mp fun _ _ => mem_setOfIdeal.mpr ⟨1, Submodule.mem_top, one_ne_zero⟩ #align continuous_map.set_of_top_eq_univ ContinuousMap.setOfTop_eq_univ @[simp] theorem idealOfEmpty_eq_bot : idealOfSet R (∅ : Set X) = ⊥ := Ideal.ext fun f => by simp only [mem_idealOfSet, Set.compl_empty, Set.mem_univ, forall_true_left, Ideal.mem_bot, DFunLike.ext_iff, zero_apply] #align continuous_map.ideal_of_empty_eq_bot ContinuousMap.idealOfEmpty_eq_bot @[simp] theorem mem_idealOfSet_compl_singleton (x : X) (f : C(X, R)) : f ∈ idealOfSet R ({x}ᶜ : Set X) ↔ f x = 0 := by simp only [mem_idealOfSet, compl_compl, Set.mem_singleton_iff, forall_eq] #align continuous_map.mem_ideal_of_set_compl_singleton ContinuousMap.mem_idealOfSet_compl_singleton variable (X R) theorem ideal_gc : GaloisConnection (setOfIdeal : Ideal C(X, R) → Set X) (idealOfSet R) := by refine fun I s => ⟨fun h f hf => ?_, fun h x hx => ?_⟩ · by_contra h' rcases not_mem_idealOfSet.mp h' with ⟨x, hx, hfx⟩ exact hfx (not_mem_setOfIdeal.mp (mt (@h x) hx) hf) · obtain ⟨f, hf, hfx⟩ := mem_setOfIdeal.mp hx by_contra hx' exact not_mem_idealOfSet.mpr ⟨x, hx', hfx⟩ (h hf) #align continuous_map.ideal_gc ContinuousMap.ideal_gc end TopologicalRing section RCLike open RCLike variable {X 𝕜 : Type*} [RCLike 𝕜] [TopologicalSpace X] /-- An auxiliary lemma used in the proof of `ContinuousMap.idealOfSet_ofIdeal_eq_closure` which may be useful on its own. -/ theorem exists_mul_le_one_eqOn_ge (f : C(X, ℝ≥0)) {c : ℝ≥0} (hc : 0 < c) : ∃ g : C(X, ℝ≥0), (∀ x : X, (g * f) x ≤ 1) ∧ {x : X | c ≤ f x}.EqOn (g * f) 1 := ⟨{ toFun := (f ⊔ const X c)⁻¹ continuous_toFun := ((map_continuous f).sup <| map_continuous _).inv₀ fun _ => (hc.trans_le le_sup_right).ne' }, fun x => (inv_mul_le_iff (hc.trans_le le_sup_right)).mpr ((mul_one (f x ⊔ c)).symm ▸ le_sup_left), fun x hx => by simpa only [coe_const, ge_iff_le, mul_apply, coe_mk, Pi.inv_apply, Pi.sup_apply, Function.const_apply, sup_eq_left.mpr (Set.mem_setOf.mp hx), ne_eq, Pi.one_apply] using inv_mul_cancel (hc.trans_le hx).ne' ⟩ #align continuous_map.exists_mul_le_one_eq_on_ge ContinuousMap.exists_mul_le_one_eqOn_ge variable [CompactSpace X] [T2Space X] @[simp] theorem idealOfSet_ofIdeal_eq_closure (I : Ideal C(X, 𝕜)) : idealOfSet 𝕜 (setOfIdeal I) = I.closure := by /- Since `idealOfSet 𝕜 (setOfIdeal I)` is closed and contains `I`, it contains `I.closure`. For the reverse inclusion, given `f ∈ idealOfSet 𝕜 (setOfIdeal I)` and `(ε : ℝ≥0) > 0` it suffices to show that `f` is within `ε` of `I`. -/ refine le_antisymm ?_ ((idealOfSet_closed 𝕜 <| setOfIdeal I).closure_subset_iff.mpr fun f hf x hx => not_mem_setOfIdeal.mp hx hf) refine (fun f hf => Metric.mem_closure_iff.mpr fun ε hε => ?_) lift ε to ℝ≥0 using hε.lt.le replace hε := show (0 : ℝ≥0) < ε from hε simp_rw [dist_nndist] norm_cast -- Let `t := {x : X | ε / 2 ≤ ‖f x‖₊}}` which is closed and disjoint from `set_of_ideal I`. set t := {x : X | ε / 2 ≤ ‖f x‖₊} have ht : IsClosed t := isClosed_le continuous_const (map_continuous f).nnnorm have htI : Disjoint t (setOfIdeal I)ᶜ := by refine Set.subset_compl_iff_disjoint_left.mp fun x hx => ?_ simpa only [t, Set.mem_setOf, Set.mem_compl_iff, not_le] using (nnnorm_eq_zero.mpr (mem_idealOfSet.mp hf hx)).trans_lt (half_pos hε) /- It suffices to produce `g : C(X, ℝ≥0)` which takes values in `[0,1]` and is constantly `1` on `t` such that when composed with the natural embedding of `ℝ≥0` into `𝕜` lies in the ideal `I`. Indeed, then `‖f - f * ↑g‖ ≤ ‖f * (1 - ↑g)‖ ≤ ⨆ ‖f * (1 - ↑g) x‖`. When `x ∉ t`, `‖f x‖ < ε / 2` and `‖(1 - ↑g) x‖ ≤ 1`, and when `x ∈ t`, `(1 - ↑g) x = 0`, and clearly `f * ↑g ∈ I`. -/ suffices ∃ g : C(X, ℝ≥0), (algebraMapCLM ℝ≥0 𝕜 : C(ℝ≥0, 𝕜)).comp g ∈ I ∧ (∀ x, g x ≤ 1) ∧ t.EqOn g 1 by obtain ⟨g, hgI, hg, hgt⟩ := this refine ⟨f * (algebraMapCLM ℝ≥0 𝕜 : C(ℝ≥0, 𝕜)).comp g, I.mul_mem_left f hgI, ?_⟩ rw [nndist_eq_nnnorm] refine (nnnorm_lt_iff _ hε).2 fun x => ?_ simp only [coe_sub, coe_mul, Pi.sub_apply, Pi.mul_apply] by_cases hx : x ∈ t · simpa only [hgt hx, comp_apply, Pi.one_apply, ContinuousMap.coe_coe, algebraMapCLM_apply, map_one, mul_one, sub_self, nnnorm_zero] using hε · refine lt_of_le_of_lt ?_ (half_lt_self hε) have := calc ‖((1 - (algebraMapCLM ℝ≥0 𝕜 : C(ℝ≥0, 𝕜)).comp g) x : 𝕜)‖₊ = ‖1 - algebraMap ℝ≥0 𝕜 (g x)‖₊ := by simp only [coe_sub, coe_one, coe_comp, ContinuousMap.coe_coe, Pi.sub_apply, Pi.one_apply, Function.comp_apply, algebraMapCLM_apply] _ = ‖algebraMap ℝ≥0 𝕜 (1 - g x)‖₊ := by simp only [Algebra.algebraMap_eq_smul_one, NNReal.smul_def, ge_iff_le, NNReal.coe_sub (hg x), NNReal.coe_one, sub_smul, one_smul] _ ≤ 1 := (nnnorm_algebraMap_nnreal 𝕜 (1 - g x)).trans_le tsub_le_self calc ‖f x - f x * (algebraMapCLM ℝ≥0 𝕜 : C(ℝ≥0, 𝕜)).comp g x‖₊ = ‖f x * (1 - (algebraMapCLM ℝ≥0 𝕜 : C(ℝ≥0, 𝕜)).comp g) x‖₊ := by simp only [mul_sub, coe_sub, coe_one, Pi.sub_apply, Pi.one_apply, mul_one] _ ≤ ε / 2 * ‖(1 - (algebraMapCLM ℝ≥0 𝕜 : C(ℝ≥0, 𝕜)).comp g) x‖₊ := ((nnnorm_mul_le _ _).trans (mul_le_mul_right' (not_le.mp <| show ¬ε / 2 ≤ ‖f x‖₊ from hx).le _)) _ ≤ ε / 2 := by simpa only [mul_one] using mul_le_mul_left' this _ /- There is some `g' : C(X, ℝ≥0)` which is strictly positive on `t` such that the composition `↑g` with the natural embedding of `ℝ≥0` into `𝕜` lies in `I`. This follows from compactness of `t` and that we can do it in any neighborhood of a point `x ∈ t`. Indeed, since `x ∈ t`, then `fₓ x ≠ 0` for some `fₓ ∈ I` and so `fun y ↦ ‖(star fₓ * fₓ) y‖₊` is strictly posiive in a neighborhood of `y`. Moreover, `(‖(star fₓ * fₓ) y‖₊ : 𝕜) = (star fₓ * fₓ) y`, so composition of this map with the natural embedding is just `star fₓ * fₓ ∈ I`. -/ have : ∃ g' : C(X, ℝ≥0), (algebraMapCLM ℝ≥0 𝕜 : C(ℝ≥0, 𝕜)).comp g' ∈ I ∧ ∀ x ∈ t, 0 < g' x := by refine ht.isCompact.induction_on ?_ ?_ ?_ ?_ · refine ⟨0, ?_, fun x hx => False.elim hx⟩ convert I.zero_mem ext simp only [comp_apply, zero_apply, ContinuousMap.coe_coe, map_zero] · rintro s₁ s₂ hs ⟨g, hI, hgt⟩; exact ⟨g, hI, fun x hx => hgt x (hs hx)⟩ · rintro s₁ s₂ ⟨g₁, hI₁, hgt₁⟩ ⟨g₂, hI₂, hgt₂⟩ refine ⟨g₁ + g₂, ?_, fun x hx => ?_⟩ · convert I.add_mem hI₁ hI₂ ext y simp only [coe_add, Pi.add_apply, map_add, coe_comp, Function.comp_apply, ContinuousMap.coe_coe] · rcases hx with (hx | hx) · simpa only [zero_add] using add_lt_add_of_lt_of_le (hgt₁ x hx) zero_le' · simpa only [zero_add] using add_lt_add_of_le_of_lt zero_le' (hgt₂ x hx) · intro x hx replace hx := htI.subset_compl_right hx rw [compl_compl, mem_setOfIdeal] at hx obtain ⟨g, hI, hgx⟩ := hx have := (map_continuous g).continuousAt.eventually_ne hgx refine ⟨{y : X | g y ≠ 0} ∩ t, mem_nhdsWithin_iff_exists_mem_nhds_inter.mpr ⟨_, this, Set.Subset.rfl⟩, ⟨⟨fun x => ‖g x‖₊ ^ 2, (map_continuous g).nnnorm.pow 2⟩, ?_, fun x hx => pow_pos (norm_pos_iff.mpr hx.1) 2⟩⟩ convert I.mul_mem_left (star g) hI ext simp only [comp_apply, ContinuousMap.coe_coe, coe_mk, algebraMapCLM_toFun, map_pow, mul_apply, star_apply, star_def] simp only [normSq_eq_def', RCLike.conj_mul, ofReal_pow] rfl /- Get the function `g'` which is guaranteed to exist above. By the extreme value theorem and compactness of `t`, there is some `0 < c` such that `c ≤ g' x` for all `x ∈ t`. Then by `exists_mul_le_one_eqOn_ge` there is some `g` for which `g * g'` is the desired function. -/ obtain ⟨g', hI', hgt'⟩ := this obtain ⟨c, hc, hgc'⟩ : ∃ c > 0, ∀ y : X, y ∈ t → c ≤ g' y := t.eq_empty_or_nonempty.elim (fun ht' => ⟨1, zero_lt_one, fun y hy => False.elim (by rwa [ht'] at hy)⟩) fun ht' => let ⟨x, hx, hx'⟩ := ht.isCompact.exists_isMinOn ht' (map_continuous g').continuousOn ⟨g' x, hgt' x hx, hx'⟩ obtain ⟨g, hg, hgc⟩ := exists_mul_le_one_eqOn_ge g' hc refine ⟨g * g', ?_, hg, hgc.mono hgc'⟩ convert I.mul_mem_left ((algebraMapCLM ℝ≥0 𝕜 : C(ℝ≥0, 𝕜)).comp g) hI' ext simp only [algebraMapCLM_coe, comp_apply, mul_apply, ContinuousMap.coe_coe, map_mul] #align continuous_map.ideal_of_set_of_ideal_eq_closure ContinuousMap.idealOfSet_ofIdeal_eq_closure theorem idealOfSet_ofIdeal_isClosed {I : Ideal C(X, 𝕜)} (hI : IsClosed (I : Set C(X, 𝕜))) : idealOfSet 𝕜 (setOfIdeal I) = I := (idealOfSet_ofIdeal_eq_closure I).trans (Ideal.ext <| Set.ext_iff.mp hI.closure_eq) #align continuous_map.ideal_of_set_of_ideal_is_closed ContinuousMap.idealOfSet_ofIdeal_isClosed variable (𝕜) @[simp] theorem setOfIdeal_ofSet_eq_interior (s : Set X) : setOfIdeal (idealOfSet 𝕜 s) = interior s := by refine Set.Subset.antisymm ((setOfIdeal_open (idealOfSet 𝕜 s)).subset_interior_iff.mpr fun x hx => let ⟨f, hf, hfx⟩ := mem_setOfIdeal.mp hx Set.not_mem_compl_iff.mp (mt (@hf x) hfx)) fun x hx => ?_ -- If `x ∉ closure sᶜ`, we must produce `f : C(X, 𝕜)` which is zero on `sᶜ` and `f x ≠ 0`. rw [← compl_compl (interior s), ← closure_compl] at hx simp_rw [mem_setOfIdeal, mem_idealOfSet] /- Apply Urysohn's lemma to get `g : C(X, ℝ)` which is zero on `sᶜ` and `g x ≠ 0`, then compose with the natural embedding `ℝ ↪ 𝕜` to produce the desired `f`. -/ obtain ⟨g, hgs, hgx : Set.EqOn g 1 {x}, -⟩ := exists_continuous_zero_one_of_isClosed isClosed_closure isClosed_singleton (Set.disjoint_singleton_right.mpr hx) exact ⟨⟨fun x => g x, continuous_ofReal.comp (map_continuous g)⟩, by simpa only [coe_mk, ofReal_eq_zero] using fun x hx => hgs (subset_closure hx), by simpa only [coe_mk, hgx (Set.mem_singleton x), Pi.one_apply, RCLike.ofReal_one] using one_ne_zero⟩ #align continuous_map.set_of_ideal_of_set_eq_interior ContinuousMap.setOfIdeal_ofSet_eq_interior theorem setOfIdeal_ofSet_of_isOpen {s : Set X} (hs : IsOpen s) : setOfIdeal (idealOfSet 𝕜 s) = s := (setOfIdeal_ofSet_eq_interior 𝕜 s).trans hs.interior_eq #align continuous_map.set_of_ideal_of_set_of_is_open ContinuousMap.setOfIdeal_ofSet_of_isOpen variable (X) /-- The Galois insertion `ContinuousMap.opensOfIdeal : Ideal C(X, 𝕜) → Opens X` and `fun s ↦ ContinuousMap.idealOfSet ↑s`. -/ @[simps] def idealOpensGI : GaloisInsertion (opensOfIdeal : Ideal C(X, 𝕜) → Opens X) fun s => idealOfSet 𝕜 s where choice I _ := opensOfIdeal I.closure gc I s := ideal_gc X 𝕜 I s le_l_u s := (setOfIdeal_ofSet_of_isOpen 𝕜 s.isOpen).ge choice_eq I hI := congr_arg _ <| Ideal.ext (Set.ext_iff.mp (isClosed_of_closure_subset <| (idealOfSet_ofIdeal_eq_closure I ▸ hI : I.closure ≤ I)).closure_eq) #align continuous_map.ideal_opens_gi ContinuousMap.idealOpensGI variable {X}
Mathlib/Topology/ContinuousFunction/Ideals.lean
358
363
theorem idealOfSet_isMaximal_iff (s : Opens X) : (idealOfSet 𝕜 (s : Set X)).IsMaximal ↔ IsCoatom s := by
rw [Ideal.isMaximal_def] refine (idealOpensGI X 𝕜).isCoatom_iff (fun I hI => ?_) s rw [← Ideal.isMaximal_def] at hI exact idealOfSet_ofIdeal_isClosed inferInstance
/- Copyright (c) 2024 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.NumberTheory.NumberField.Basic import Mathlib.RingTheory.FractionalIdeal.Norm import Mathlib.RingTheory.FractionalIdeal.Operations /-! # Fractional ideals of number fields Prove some results on the fractional ideals of number fields. ## Main definitions and results * `NumberField.basisOfFractionalIdeal`: A `ℚ`-basis of `K` that spans `I` over `ℤ` where `I` is a fractional ideal of a number field `K`. * `NumberField.det_basisOfFractionalIdeal_eq_absNorm`: for `I` a fractional ideal of a number field `K`, the absolute value of the determinant of the base change from `integralBasis` to `basisOfFractionalIdeal I` is equal to the norm of `I`. -/ variable (K : Type*) [Field K] [NumberField K] namespace NumberField open scoped nonZeroDivisors section Basis open Module -- This is necessary to avoid several timeouts attribute [local instance 2000] Submodule.module instance (I : FractionalIdeal (𝓞 K)⁰ K) : Module.Free ℤ I := by refine Free.of_equiv (LinearEquiv.restrictScalars ℤ (I.equivNum ?_)).symm exact nonZeroDivisors.coe_ne_zero I.den instance (I : FractionalIdeal (𝓞 K)⁰ K) : Module.Finite ℤ I := by refine Module.Finite.of_surjective (LinearEquiv.restrictScalars ℤ (I.equivNum ?_)).symm.toLinearMap (LinearEquiv.surjective _) exact nonZeroDivisors.coe_ne_zero I.den instance (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) : IsLocalizedModule ℤ⁰ ((Submodule.subtype (I : Submodule (𝓞 K) K)).restrictScalars ℤ) where map_units x := by rw [← (Algebra.lmul _ _).commutes, Algebra.lmul_isUnit_iff, isUnit_iff_ne_zero, eq_intCast, Int.cast_ne_zero] exact nonZeroDivisors.coe_ne_zero x surj' x := by obtain ⟨⟨a, _, d, hd, rfl⟩, h⟩ := IsLocalization.surj (Algebra.algebraMapSubmonoid (𝓞 K) ℤ⁰) x refine ⟨⟨⟨Ideal.absNorm I.1.num * (algebraMap _ K a), I.1.num_le ?_⟩, d * Ideal.absNorm I.1.num, ?_⟩ , ?_⟩ · simp_rw [FractionalIdeal.val_eq_coe, FractionalIdeal.coe_coeIdeal] refine (IsLocalization.mem_coeSubmodule _ _).mpr ⟨Ideal.absNorm I.1.num * a, ?_, ?_⟩ · exact Ideal.mul_mem_right _ _ I.1.num.absNorm_mem · rw [map_mul, map_natCast] · refine Submonoid.mul_mem _ hd (mem_nonZeroDivisors_of_ne_zero ?_) rw [Nat.cast_ne_zero, ne_eq, Ideal.absNorm_eq_zero_iff] exact FractionalIdeal.num_eq_zero_iff.not.mpr <| Units.ne_zero I · simp_rw [LinearMap.coe_restrictScalars, Submodule.coeSubtype] at h ⊢ rw [← h] simp only [Submonoid.mk_smul, zsmul_eq_mul, Int.cast_mul, Int.cast_natCast, algebraMap_int_eq, eq_intCast, map_intCast] ring exists_of_eq h := ⟨1, by rwa [one_smul, one_smul, ← (Submodule.injective_subtype I.1.coeToSubmodule).eq_iff]⟩ /-- A `ℤ`-basis of a fractional ideal. -/ noncomputable def fractionalIdealBasis (I : FractionalIdeal (𝓞 K)⁰ K) : Basis (Free.ChooseBasisIndex ℤ I) ℤ I := Free.chooseBasis ℤ I /-- A `ℚ`-basis of `K` that spans `I` over `ℤ`, see `mem_span_basisOfFractionalIdeal` below. -/ noncomputable def basisOfFractionalIdeal (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) : Basis (Free.ChooseBasisIndex ℤ I) ℚ K := (fractionalIdealBasis K I.1).ofIsLocalizedModule ℚ ℤ⁰ ((Submodule.subtype (I : Submodule (𝓞 K) K)).restrictScalars ℤ) theorem basisOfFractionalIdeal_apply (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) (i : Free.ChooseBasisIndex ℤ I) : basisOfFractionalIdeal K I i = fractionalIdealBasis K I.1 i := (fractionalIdealBasis K I.1).ofIsLocalizedModule_apply ℚ ℤ⁰ _ i theorem mem_span_basisOfFractionalIdeal {I : (FractionalIdeal (𝓞 K)⁰ K)ˣ} {x : K} : x ∈ Submodule.span ℤ (Set.range (basisOfFractionalIdeal K I)) ↔ x ∈ (I : Set K) := by rw [basisOfFractionalIdeal, (fractionalIdealBasis K I.1).ofIsLocalizedModule_span ℚ ℤ⁰ _] simp open FiniteDimensional in theorem fractionalIdeal_rank (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) : finrank ℤ I = finrank ℤ (𝓞 K) := by rw [finrank_eq_card_chooseBasisIndex, RingOfIntegers.rank, finrank_eq_card_basis (basisOfFractionalIdeal K I)] end Basis section Norm open Module /-- The absolute value of the determinant of the base change from `integralBasis` to `basisOfFractionalIdeal I` is equal to the norm of `I`. -/
Mathlib/NumberTheory/NumberField/FractionalIdeal.lean
106
114
theorem det_basisOfFractionalIdeal_eq_absNorm (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) (e : (Free.ChooseBasisIndex ℤ (𝓞 K)) ≃ (Free.ChooseBasisIndex ℤ I)) : |(integralBasis K).det ((basisOfFractionalIdeal K I).reindex e.symm)| = FractionalIdeal.absNorm I.1 := by
rw [← FractionalIdeal.abs_det_basis_change (RingOfIntegers.basis K) I.1 ((fractionalIdealBasis K I.1).reindex e.symm)] congr ext simpa using basisOfFractionalIdeal_apply K I _
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp #align_import analysis.calculus.fderiv.equiv from "leanprover-community/mathlib"@"e3fb84046afd187b710170887195d50bada934ee" /-! # The derivative of a linear equivalence For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of continuous linear equivalences. We also prove the usual formula for the derivative of the inverse function, assuming it exists. The inverse function theorem is in `Mathlib/Analysis/Calculus/InverseFunctionTheorem/FDeriv.lean`. -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} namespace ContinuousLinearEquiv /-! ### Differentiability of linear equivs, and invariance of differentiability -/ variable (iso : E ≃L[𝕜] F) @[fun_prop] protected theorem hasStrictFDerivAt : HasStrictFDerivAt iso (iso : E →L[𝕜] F) x := iso.toContinuousLinearMap.hasStrictFDerivAt #align continuous_linear_equiv.has_strict_fderiv_at ContinuousLinearEquiv.hasStrictFDerivAt @[fun_prop] protected theorem hasFDerivWithinAt : HasFDerivWithinAt iso (iso : E →L[𝕜] F) s x := iso.toContinuousLinearMap.hasFDerivWithinAt #align continuous_linear_equiv.has_fderiv_within_at ContinuousLinearEquiv.hasFDerivWithinAt @[fun_prop] protected theorem hasFDerivAt : HasFDerivAt iso (iso : E →L[𝕜] F) x := iso.toContinuousLinearMap.hasFDerivAtFilter #align continuous_linear_equiv.has_fderiv_at ContinuousLinearEquiv.hasFDerivAt @[fun_prop] protected theorem differentiableAt : DifferentiableAt 𝕜 iso x := iso.hasFDerivAt.differentiableAt #align continuous_linear_equiv.differentiable_at ContinuousLinearEquiv.differentiableAt @[fun_prop] protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 iso s x := iso.differentiableAt.differentiableWithinAt #align continuous_linear_equiv.differentiable_within_at ContinuousLinearEquiv.differentiableWithinAt protected theorem fderiv : fderiv 𝕜 iso x = iso := iso.hasFDerivAt.fderiv #align continuous_linear_equiv.fderiv ContinuousLinearEquiv.fderiv protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 iso s x = iso := iso.toContinuousLinearMap.fderivWithin hxs #align continuous_linear_equiv.fderiv_within ContinuousLinearEquiv.fderivWithin @[fun_prop] protected theorem differentiable : Differentiable 𝕜 iso := fun _ => iso.differentiableAt #align continuous_linear_equiv.differentiable ContinuousLinearEquiv.differentiable @[fun_prop] protected theorem differentiableOn : DifferentiableOn 𝕜 iso s := iso.differentiable.differentiableOn #align continuous_linear_equiv.differentiable_on ContinuousLinearEquiv.differentiableOn theorem comp_differentiableWithinAt_iff {f : G → E} {s : Set G} {x : G} : DifferentiableWithinAt 𝕜 (iso ∘ f) s x ↔ DifferentiableWithinAt 𝕜 f s x := by refine ⟨fun H => ?_, fun H => iso.differentiable.differentiableAt.comp_differentiableWithinAt x H⟩ have : DifferentiableWithinAt 𝕜 (iso.symm ∘ iso ∘ f) s x := iso.symm.differentiable.differentiableAt.comp_differentiableWithinAt x H rwa [← Function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this #align continuous_linear_equiv.comp_differentiable_within_at_iff ContinuousLinearEquiv.comp_differentiableWithinAt_iff theorem comp_differentiableAt_iff {f : G → E} {x : G} : DifferentiableAt 𝕜 (iso ∘ f) x ↔ DifferentiableAt 𝕜 f x := by rw [← differentiableWithinAt_univ, ← differentiableWithinAt_univ, iso.comp_differentiableWithinAt_iff] #align continuous_linear_equiv.comp_differentiable_at_iff ContinuousLinearEquiv.comp_differentiableAt_iff theorem comp_differentiableOn_iff {f : G → E} {s : Set G} : DifferentiableOn 𝕜 (iso ∘ f) s ↔ DifferentiableOn 𝕜 f s := by rw [DifferentiableOn, DifferentiableOn] simp only [iso.comp_differentiableWithinAt_iff] #align continuous_linear_equiv.comp_differentiable_on_iff ContinuousLinearEquiv.comp_differentiableOn_iff theorem comp_differentiable_iff {f : G → E} : Differentiable 𝕜 (iso ∘ f) ↔ Differentiable 𝕜 f := by rw [← differentiableOn_univ, ← differentiableOn_univ] exact iso.comp_differentiableOn_iff #align continuous_linear_equiv.comp_differentiable_iff ContinuousLinearEquiv.comp_differentiable_iff theorem comp_hasFDerivWithinAt_iff {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] E} : HasFDerivWithinAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ HasFDerivWithinAt f f' s x := by refine ⟨fun H => ?_, fun H => iso.hasFDerivAt.comp_hasFDerivWithinAt x H⟩ have A : f = iso.symm ∘ iso ∘ f := by rw [← Function.comp.assoc, iso.symm_comp_self] rfl have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f') := by rw [← ContinuousLinearMap.comp_assoc, iso.coe_symm_comp_coe, ContinuousLinearMap.id_comp] rw [A, B] exact iso.symm.hasFDerivAt.comp_hasFDerivWithinAt x H #align continuous_linear_equiv.comp_has_fderiv_within_at_iff ContinuousLinearEquiv.comp_hasFDerivWithinAt_iff theorem comp_hasStrictFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : HasStrictFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasStrictFDerivAt f f' x := by refine ⟨fun H => ?_, fun H => iso.hasStrictFDerivAt.comp x H⟩ convert iso.symm.hasStrictFDerivAt.comp x H using 1 <;> ext z <;> apply (iso.symm_apply_apply _).symm #align continuous_linear_equiv.comp_has_strict_fderiv_at_iff ContinuousLinearEquiv.comp_hasStrictFDerivAt_iff theorem comp_hasFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : HasFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasFDerivAt f f' x := by simp_rw [← hasFDerivWithinAt_univ, iso.comp_hasFDerivWithinAt_iff] #align continuous_linear_equiv.comp_has_fderiv_at_iff ContinuousLinearEquiv.comp_hasFDerivAt_iff
Mathlib/Analysis/Calculus/FDeriv/Equiv.lean
145
149
theorem comp_hasFDerivWithinAt_iff' {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] F} : HasFDerivWithinAt (iso ∘ f) f' s x ↔ HasFDerivWithinAt f ((iso.symm : F →L[𝕜] E).comp f') s x := by
rw [← iso.comp_hasFDerivWithinAt_iff, ← ContinuousLinearMap.comp_assoc, iso.coe_comp_coe_symm, ContinuousLinearMap.id_comp]
/- 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)]
Mathlib/GroupTheory/MonoidLocalization.lean
557
561
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
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Set.Card import Mathlib.Order.Minimal import Mathlib.Data.Matroid.Init /-! # Matroids A `Matroid` is a structure that combinatorially abstracts the notion of linear independence and dependence; matroids have connections with graph theory, discrete optimization, additive combinatorics and algebraic geometry. Mathematically, a matroid `M` is a structure on a set `E` comprising a collection of subsets of `E` called the bases of `M`, where the bases are required to obey certain axioms. This file gives a definition of a matroid `M` in terms of its bases, and some API relating independent sets (subsets of bases) and the notion of a basis of a set `X` (a maximal independent subset of `X`). ## Main definitions * a `Matroid α` on a type `α` is a structure comprising a 'ground set' and a suitably behaved 'base' predicate. Given `M : Matroid α` ... * `M.E` denotes the ground set of `M`, which has type `Set α` * For `B : Set α`, `M.Base B` means that `B` is a base of `M`. * For `I : Set α`, `M.Indep I` means that `I` is independent in `M` (that is, `I` is contained in a base of `M`). * For `D : Set α`, `M.Dep D` means that `D` is contained in the ground set of `M` but isn't independent. * For `I : Set α` and `X : Set α`, `M.Basis I X` means that `I` is a maximal independent subset of `X`. * `M.Finite` means that `M` has finite ground set. * `M.Nonempty` means that the ground set of `M` is nonempty. * `FiniteRk M` means that the bases of `M` are finite. * `InfiniteRk M` means that the bases of `M` are infinite. * `RkPos M` means that the bases of `M` are nonempty. * `Finitary M` means that a set is independent if and only if all its finite subsets are independent. * `aesop_mat` : a tactic designed to prove `X ⊆ M.E` for some set `X` and matroid `M`. ## Implementation details There are a few design decisions worth discussing. ### Finiteness The first is that our matroids are allowed to be infinite. Unlike with many mathematical structures, this isn't such an obvious choice. Finite matroids have been studied since the 1930's, and there was never controversy as to what is and isn't an example of a finite matroid - in fact, surprisingly many apparently different definitions of a matroid give rise to the same class of objects. However, generalizing different definitions of a finite matroid to the infinite in the obvious way (i.e. by simply allowing the ground set to be infinite) gives a number of different notions of 'infinite matroid' that disagree with each other, and that all lack nice properties. Many different competing notions of infinite matroid were studied through the years; in fact, the problem of which definition is the best was only really solved in 2013, when Bruhn et al. [2] showed that there is a unique 'reasonable' notion of an infinite matroid (these objects had previously defined by Higgs under the name 'B-matroid'). These are defined by adding one carefully chosen axiom to the standard set, and adapting existing axioms to not mention set cardinalities; they enjoy nearly all the nice properties of standard finite matroids. Even though at least 90% of the literature is on finite matroids, B-matroids are the definition we use, because they allow for additional generality, nearly all theorems are still true and just as easy to state, and (hopefully) the more general definition will prevent the need for a costly future refactor. The disadvantage is that developing API for the finite case is harder work (for instance, it is harder to prove that something is a matroid in the first place, and one must deal with `ℕ∞` rather than `ℕ`). For serious work on finite matroids, we provide the typeclasses `[M.Finite]` and `[FiniteRk M]` and associated API. ### Cardinality Just as with bases of a vector space, all bases of a finite matroid `M` are finite and have the same cardinality; this cardinality is an important invariant known as the 'rank' of `M`. For infinite matroids, bases are not in general equicardinal; in fact the equicardinality of bases of infinite matroids is independent of ZFC [3]. What is still true is that either all bases are finite and equicardinal, or all bases are infinite. This means that the natural notion of 'size' for a set in matroid theory is given by the function `Set.encard`, which is the cardinality as a term in `ℕ∞`. We use this function extensively in building the API; it is preferable to both `Set.ncard` and `Finset.card` because it allows infinite sets to be handled without splitting into cases. ### The ground `Set` A last place where we make a consequential choice is making the ground set of a matroid a structure field of type `Set α` (where `α` is the type of 'possible matroid elements') rather than just having a type `α` of all the matroid elements. This is because of how common it is to simultaneously consider a number of matroids on different but related ground sets. For example, a matroid `M` on ground set `E` can have its structure 'restricted' to some subset `R ⊆ E` to give a smaller matroid `M ↾ R` with ground set `R`. A statement like `(M ↾ R₁) ↾ R₂ = M ↾ R₂` is mathematically obvious. But if the ground set of a matroid is a type, this doesn't typecheck, and is only true up to canonical isomorphism. Restriction is just the tip of the iceberg here; one can also 'contract' and 'delete' elements and sets of elements in a matroid to give a smaller matroid, and in practice it is common to make statements like `M₁.E = M₂.E ∩ M₃.E` and `((M ⟋ e) ↾ R) ⟋ C = M ⟋ (C ∪ {e}) ↾ R`. Such things are a nightmare to work with unless `=` is actually propositional equality (especially because the relevant coercions are usually between sets and not just elements). So the solution is that the ground set `M.E` has type `Set α`, and there are elements of type `α` that aren't in the matroid. The tradeoff is that for many statements, one now has to add hypotheses of the form `X ⊆ M.E` to make sure than `X` is actually 'in the matroid', rather than letting a 'type of matroid elements' take care of this invisibly. It still seems that this is worth it. The tactic `aesop_mat` exists specifically to discharge such goals with minimal fuss (using default values). The tactic works fairly well, but has room for improvement. Even though the carrier set is written `M.E`, A related decision is to not have matroids themselves be a typeclass. This would make things be notationally simpler (having `Base` in the presence of `[Matroid α]` rather than `M.Base` for a term `M : Matroid α`) but is again just too awkward when one has multiple matroids on the same type. In fact, in regular written mathematics, it is normal to explicitly indicate which matroid something is happening in, so our notation mirrors common practice. ### Notation We use a couple of nonstandard conventions in theorem names that are related to the above. First, we mirror common informal practice by referring explicitly to the `ground` set rather than the notation `E`. (Writing `ground` everywhere in a proof term would be unwieldy, and writing `E` in theorem names would be unnatural to read.) Second, because we are typically interested in subsets of the ground set `M.E`, using `Set.compl` is inconvenient, since `Xᶜ ⊆ M.E` is typically false for `X ⊆ M.E`. On the other hand (especially when duals arise), it is common to complement a set `X ⊆ M.E` *within* the ground set, giving `M.E \ X`. For this reason, we use the term `compl` in theorem names to refer to taking a set difference with respect to the ground set, rather than a complement within a type. The lemma `compl_base_dual` is one of the many examples of this. ## References [1] The standard text on matroid theory [J. G. Oxley, Matroid Theory, Oxford University Press, New York, 2011.] [2] The robust axiomatic definition of infinite matroids [H. Bruhn, R. Diestel, M. Kriesell, R. Pendavingh, P. Wollan, Axioms for infinite matroids, Adv. Math 239 (2013), 18-46] [3] Equicardinality of matroid bases is independent of ZFC. [N. Bowler, S. Geschke, Self-dual uniform matroids on infinite sets, Proc. Amer. Math. Soc. 144 (2016), 459-471] -/ set_option autoImplicit true open Set /-- A predicate `P` on sets satisfies the **exchange property** if, for all `X` and `Y` satisfying `P` and all `a ∈ X \ Y`, there exists `b ∈ Y \ X` so that swapping `a` for `b` in `X` maintains `P`. -/ def Matroid.ExchangeProperty {α : Type _} (P : Set α → Prop) : Prop := ∀ X Y, P X → P Y → ∀ a ∈ X \ Y, ∃ b ∈ Y \ X, P (insert b (X \ {a})) /-- A set `X` has the maximal subset property for a predicate `P` if every subset of `X` satisfying `P` is contained in a maximal subset of `X` satisfying `P`. -/ def Matroid.ExistsMaximalSubsetProperty {α : Type _} (P : Set α → Prop) (X : Set α) : Prop := ∀ I, P I → I ⊆ X → (maximals (· ⊆ ·) {Y | P Y ∧ I ⊆ Y ∧ Y ⊆ X}).Nonempty /-- A `Matroid α` is a ground set `E` of type `Set α`, and a nonempty collection of its subsets satisfying the exchange property and the maximal subset property. Each such set is called a `Base` of `M`. An `Indep`endent set is just a set contained in a base, but we include this predicate as a structure field for better definitional properties. In most cases, using this definition directly is not the best way to construct a matroid, since it requires specifying both the bases and independent sets. If the bases are known, use `Matroid.ofBase` or a variant. If just the independent sets are known, define an `IndepMatroid`, and then use `IndepMatroid.matroid`. -/ @[ext] structure Matroid (α : Type _) where /-- `M` has a ground set `E`. -/ (E : Set α) /-- `M` has a predicate `Base` definining its bases. -/ (Base : Set α → Prop) /-- `M` has a predicate `Indep` defining its independent sets. -/ (Indep : Set α → Prop) /-- The `Indep`endent sets are those contained in `Base`s. -/ (indep_iff' : ∀ ⦃I⦄, Indep I ↔ ∃ B, Base B ∧ I ⊆ B) /-- There is at least one `Base`. -/ (exists_base : ∃ B, Base B) /-- For any bases `B`, `B'` and `e ∈ B \ B'`, there is some `f ∈ B' \ B` for which `B-e+f` is a base. -/ (base_exchange : Matroid.ExchangeProperty Base) /-- Every independent subset `I` of a set `X` for is contained in a maximal independent subset of `X`. -/ (maximality : ∀ X, X ⊆ E → Matroid.ExistsMaximalSubsetProperty Indep X) /-- Every base is contained in the ground set. -/ (subset_ground : ∀ B, Base B → B ⊆ E) namespace Matroid variable {α : Type*} {M : Matroid α} /-- Typeclass for a matroid having finite ground set. Just a wrapper for `M.E.Finite`-/ protected class Finite (M : Matroid α) : Prop where /-- The ground set is finite -/ (ground_finite : M.E.Finite) /-- Typeclass for a matroid having nonempty ground set. Just a wrapper for `M.E.Nonempty`-/ protected class Nonempty (M : Matroid α) : Prop where /-- The ground set is nonempty -/ (ground_nonempty : M.E.Nonempty) theorem ground_nonempty (M : Matroid α) [M.Nonempty] : M.E.Nonempty := Nonempty.ground_nonempty theorem ground_nonempty_iff (M : Matroid α) : M.E.Nonempty ↔ M.Nonempty := ⟨fun h ↦ ⟨h⟩, fun ⟨h⟩ ↦ h⟩ theorem ground_finite (M : Matroid α) [M.Finite] : M.E.Finite := Finite.ground_finite theorem set_finite (M : Matroid α) [M.Finite] (X : Set α) (hX : X ⊆ M.E := by aesop) : X.Finite := M.ground_finite.subset hX instance finite_of_finite [Finite α] {M : Matroid α} : M.Finite := ⟨Set.toFinite _⟩ /-- A `FiniteRk` matroid is one whose bases are finite -/ class FiniteRk (M : Matroid α) : Prop where /-- There is a finite base -/ exists_finite_base : ∃ B, M.Base B ∧ B.Finite instance finiteRk_of_finite (M : Matroid α) [M.Finite] : FiniteRk M := ⟨M.exists_base.imp (fun B hB ↦ ⟨hB, M.set_finite B (M.subset_ground _ hB)⟩)⟩ /-- An `InfiniteRk` matroid is one whose bases are infinite. -/ class InfiniteRk (M : Matroid α) : Prop where /-- There is an infinite base -/ exists_infinite_base : ∃ B, M.Base B ∧ B.Infinite /-- A `RkPos` matroid is one whose bases are nonempty. -/ class RkPos (M : Matroid α) : Prop where /-- The empty set isn't a base -/ empty_not_base : ¬M.Base ∅ theorem rkPos_iff_empty_not_base : M.RkPos ↔ ¬M.Base ∅ := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ section exchange namespace ExchangeProperty variable {Base : Set α → Prop} (exch : ExchangeProperty Base) /-- A family of sets with the exchange property is an antichain. -/ theorem antichain (hB : Base B) (hB' : Base B') (h : B ⊆ B') : B = B' := h.antisymm (fun x hx ↦ by_contra (fun hxB ↦ let ⟨_, hy, _⟩ := exch B' B hB' hB x ⟨hx, hxB⟩; hy.2 <| h hy.1)) theorem encard_diff_le_aux (exch : ExchangeProperty Base) (hB₁ : Base B₁) (hB₂ : Base B₂) : (B₁ \ B₂).encard ≤ (B₂ \ B₁).encard := by obtain (he | hinf | ⟨e, he, hcard⟩) := (B₂ \ B₁).eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · rw [exch.antichain hB₂ hB₁ (diff_eq_empty.mp he)] · exact le_top.trans_eq hinf.symm obtain ⟨f, hf, hB'⟩ := exch B₂ B₁ hB₂ hB₁ e he have : encard (insert f (B₂ \ {e}) \ B₁) < encard (B₂ \ B₁) := by rw [insert_diff_of_mem _ hf.1, diff_diff_comm]; exact hcard have hencard := encard_diff_le_aux exch hB₁ hB' rw [insert_diff_of_mem _ hf.1, diff_diff_comm, ← union_singleton, ← diff_diff, diff_diff_right, inter_singleton_eq_empty.mpr he.2, union_empty] at hencard rw [← encard_diff_singleton_add_one he, ← encard_diff_singleton_add_one hf] exact add_le_add_right hencard 1 termination_by (B₂ \ B₁).encard /-- For any two sets `B₁`, `B₂` in a family with the exchange property, the differences `B₁ \ B₂` and `B₂ \ B₁` have the same `ℕ∞`-cardinality. -/ theorem encard_diff_eq (hB₁ : Base B₁) (hB₂ : Base B₂) : (B₁ \ B₂).encard = (B₂ \ B₁).encard := (encard_diff_le_aux exch hB₁ hB₂).antisymm (encard_diff_le_aux exch hB₂ hB₁) /-- Any two sets `B₁`, `B₂` in a family with the exchange property have the same `ℕ∞`-cardinality. -/ theorem encard_base_eq (hB₁ : Base B₁) (hB₂ : Base B₂) : B₁.encard = B₂.encard := by rw [← encard_diff_add_encard_inter B₁ B₂, exch.encard_diff_eq hB₁ hB₂, inter_comm, encard_diff_add_encard_inter] end ExchangeProperty end exchange section aesop /-- The `aesop_mat` tactic attempts to prove a set is contained in the ground set of a matroid. It uses a `[Matroid]` ruleset, and is allowed to fail. -/ macro (name := aesop_mat) "aesop_mat" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { terminal := true }) (rule_sets := [$(Lean.mkIdent `Matroid):ident])) /- We add a number of trivial lemmas (deliberately specialized to statements in terms of the ground set of a matroid) to the ruleset `Matroid` for `aesop`. -/ @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem inter_right_subset_ground (hX : X ⊆ M.E) : X ∩ Y ⊆ M.E := inter_subset_left.trans hX @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem inter_left_subset_ground (hX : X ⊆ M.E) : Y ∩ X ⊆ M.E := inter_subset_right.trans hX @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem diff_subset_ground (hX : X ⊆ M.E) : X \ Y ⊆ M.E := diff_subset.trans hX @[aesop unsafe 10% (rule_sets := [Matroid])] private theorem ground_diff_subset_ground : M.E \ X ⊆ M.E := diff_subset_ground rfl.subset @[aesop unsafe 10% (rule_sets := [Matroid])] private theorem singleton_subset_ground (he : e ∈ M.E) : {e} ⊆ M.E := singleton_subset_iff.mpr he @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem subset_ground_of_subset (hXY : X ⊆ Y) (hY : Y ⊆ M.E) : X ⊆ M.E := hXY.trans hY @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem mem_ground_of_mem_of_subset (hX : X ⊆ M.E) (heX : e ∈ X) : e ∈ M.E := hX heX @[aesop safe (rule_sets := [Matroid])] private theorem insert_subset_ground {e : α} {X : Set α} {M : Matroid α} (he : e ∈ M.E) (hX : X ⊆ M.E) : insert e X ⊆ M.E := insert_subset he hX @[aesop safe (rule_sets := [Matroid])] private theorem ground_subset_ground {M : Matroid α} : M.E ⊆ M.E := rfl.subset attribute [aesop safe (rule_sets := [Matroid])] empty_subset union_subset iUnion_subset end aesop section Base @[aesop unsafe 10% (rule_sets := [Matroid])] theorem Base.subset_ground (hB : M.Base B) : B ⊆ M.E := M.subset_ground B hB theorem Base.exchange (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) (hx : e ∈ B₁ \ B₂) : ∃ y ∈ B₂ \ B₁, M.Base (insert y (B₁ \ {e})) := M.base_exchange B₁ B₂ hB₁ hB₂ _ hx theorem Base.exchange_mem (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) (hxB₁ : e ∈ B₁) (hxB₂ : e ∉ B₂) : ∃ y, (y ∈ B₂ ∧ y ∉ B₁) ∧ M.Base (insert y (B₁ \ {e})) := by simpa using hB₁.exchange hB₂ ⟨hxB₁, hxB₂⟩ theorem Base.eq_of_subset_base (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) (hB₁B₂ : B₁ ⊆ B₂) : B₁ = B₂ := M.base_exchange.antichain hB₁ hB₂ hB₁B₂ theorem Base.not_base_of_ssubset (hB : M.Base B) (hX : X ⊂ B) : ¬ M.Base X := fun h ↦ hX.ne (h.eq_of_subset_base hB hX.subset) theorem Base.insert_not_base (hB : M.Base B) (heB : e ∉ B) : ¬ M.Base (insert e B) := fun h ↦ h.not_base_of_ssubset (ssubset_insert heB) hB theorem Base.encard_diff_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : (B₁ \ B₂).encard = (B₂ \ B₁).encard := M.base_exchange.encard_diff_eq hB₁ hB₂ theorem Base.ncard_diff_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : (B₁ \ B₂).ncard = (B₂ \ B₁).ncard := by rw [ncard_def, hB₁.encard_diff_comm hB₂, ← ncard_def] theorem Base.card_eq_card_of_base (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : B₁.encard = B₂.encard := by rw [M.base_exchange.encard_base_eq hB₁ hB₂] theorem Base.ncard_eq_ncard_of_base (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : B₁.ncard = B₂.ncard := by rw [ncard_def B₁, hB₁.card_eq_card_of_base hB₂, ← ncard_def] theorem Base.finite_of_finite (hB : M.Base B) (h : B.Finite) (hB' : M.Base B') : B'.Finite := (finite_iff_finite_of_encard_eq_encard (hB.card_eq_card_of_base hB')).mp h theorem Base.infinite_of_infinite (hB : M.Base B) (h : B.Infinite) (hB₁ : M.Base B₁) : B₁.Infinite := by_contra (fun hB_inf ↦ (hB₁.finite_of_finite (not_infinite.mp hB_inf) hB).not_infinite h) theorem Base.finite [FiniteRk M] (hB : M.Base B) : B.Finite := let ⟨B₀,hB₀⟩ := ‹FiniteRk M›.exists_finite_base hB₀.1.finite_of_finite hB₀.2 hB theorem Base.infinite [InfiniteRk M] (hB : M.Base B) : B.Infinite := let ⟨B₀,hB₀⟩ := ‹InfiniteRk M›.exists_infinite_base hB₀.1.infinite_of_infinite hB₀.2 hB theorem empty_not_base [h : RkPos M] : ¬M.Base ∅ := h.empty_not_base theorem Base.nonempty [RkPos M] (hB : M.Base B) : B.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; exact M.empty_not_base hB theorem Base.rkPos_of_nonempty (hB : M.Base B) (h : B.Nonempty) : M.RkPos := by rw [rkPos_iff_empty_not_base] intro he obtain rfl := he.eq_of_subset_base hB (empty_subset B) simp at h theorem Base.finiteRk_of_finite (hB : M.Base B) (hfin : B.Finite) : FiniteRk M := ⟨⟨B, hB, hfin⟩⟩ theorem Base.infiniteRk_of_infinite (hB : M.Base B) (h : B.Infinite) : InfiniteRk M := ⟨⟨B, hB, h⟩⟩ theorem not_finiteRk (M : Matroid α) [InfiniteRk M] : ¬ FiniteRk M := by intro h; obtain ⟨B,hB⟩ := M.exists_base; exact hB.infinite hB.finite theorem not_infiniteRk (M : Matroid α) [FiniteRk M] : ¬ InfiniteRk M := by intro h; obtain ⟨B,hB⟩ := M.exists_base; exact hB.infinite hB.finite theorem finite_or_infiniteRk (M : Matroid α) : FiniteRk M ∨ InfiniteRk M := let ⟨B, hB⟩ := M.exists_base B.finite_or_infinite.elim (Or.inl ∘ hB.finiteRk_of_finite) (Or.inr ∘ hB.infiniteRk_of_infinite) theorem Base.diff_finite_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : (B₁ \ B₂).Finite ↔ (B₂ \ B₁).Finite := finite_iff_finite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂) theorem Base.diff_infinite_comm (hB₁ : M.Base B₁) (hB₂ : M.Base B₂) : (B₁ \ B₂).Infinite ↔ (B₂ \ B₁).Infinite := infinite_iff_infinite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂) theorem eq_of_base_iff_base_forall {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (h : ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.Base B ↔ M₂.Base B)) : M₁ = M₂ := by have h' : ∀ B, M₁.Base B ↔ M₂.Base B := fun B ↦ ⟨fun hB ↦ (h hB.subset_ground).1 hB, fun hB ↦ (h <| hB.subset_ground.trans_eq hE.symm).2 hB⟩ ext <;> simp [hE, M₁.indep_iff', M₂.indep_iff', h'] theorem base_compl_iff_mem_maximals_disjoint_base (hB : B ⊆ M.E := by aesop_mat) : M.Base (M.E \ B) ↔ B ∈ maximals (· ⊆ ·) {I | I ⊆ M.E ∧ ∃ B, M.Base B ∧ Disjoint I B} := by simp_rw [mem_maximals_setOf_iff, and_iff_right hB, and_imp, forall_exists_index] refine ⟨fun h ↦ ⟨⟨_, h, disjoint_sdiff_right⟩, fun I hI B' ⟨hB', hIB'⟩ hBI ↦ hBI.antisymm ?_⟩, fun ⟨⟨B', hB', hBB'⟩,h⟩ ↦ ?_⟩ · rw [hB'.eq_of_subset_base h, ← subset_compl_iff_disjoint_right, diff_eq, compl_inter, compl_compl] at hIB' · exact fun e he ↦ (hIB' he).elim (fun h' ↦ (h' (hI he)).elim) id rw [subset_diff, and_iff_right hB'.subset_ground, disjoint_comm] exact disjoint_of_subset_left hBI hIB' rw [h diff_subset B' ⟨hB', disjoint_sdiff_left⟩] · simpa [hB'.subset_ground] simp [subset_diff, hB, hBB'] end Base section dep_indep /-- A subset of `M.E` is `Dep`endent if it is not `Indep`endent . -/ def Dep (M : Matroid α) (D : Set α) : Prop := ¬M.Indep D ∧ D ⊆ M.E theorem indep_iff : M.Indep I ↔ ∃ B, M.Base B ∧ I ⊆ B := M.indep_iff' (I := I)
Mathlib/Data/Matroid/Basic.lean
476
478
theorem setOf_indep_eq (M : Matroid α) : {I | M.Indep I} = lowerClosure ({B | M.Base B}) := by
simp_rw [indep_iff] rfl
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.RatFunc.Basic import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Content /-! # Generalities on the polynomial structure of rational functions ## Main definitions - `RatFunc.C` is the constant polynomial - `RatFunc.X` is the indeterminate - `RatFunc.eval` evaluates a rational function given a value for the indeterminate -/ noncomputable section universe u variable {K : Type u} namespace RatFunc section Eval open scoped Classical open scoped nonZeroDivisors Polynomial open RatFunc /-! ### Polynomial structure: `C`, `X`, `eval` -/ section Domain variable [CommRing K] [IsDomain K] /-- `RatFunc.C a` is the constant rational function `a`. -/ def C : K →+* RatFunc K := algebraMap _ _ set_option linter.uppercaseLean3 false in #align ratfunc.C RatFunc.C @[simp] theorem algebraMap_eq_C : algebraMap K (RatFunc K) = C := rfl set_option linter.uppercaseLean3 false in #align ratfunc.algebra_map_eq_C RatFunc.algebraMap_eq_C @[simp] theorem algebraMap_C (a : K) : algebraMap K[X] (RatFunc K) (Polynomial.C a) = C a := rfl set_option linter.uppercaseLean3 false in #align ratfunc.algebra_map_C RatFunc.algebraMap_C @[simp] theorem algebraMap_comp_C : (algebraMap K[X] (RatFunc K)).comp Polynomial.C = C := rfl set_option linter.uppercaseLean3 false in #align ratfunc.algebra_map_comp_C RatFunc.algebraMap_comp_C theorem smul_eq_C_mul (r : K) (x : RatFunc K) : r • x = C r * x := by rw [Algebra.smul_def, algebraMap_eq_C] set_option linter.uppercaseLean3 false in #align ratfunc.smul_eq_C_mul RatFunc.smul_eq_C_mul /-- `RatFunc.X` is the polynomial variable (aka indeterminate). -/ def X : RatFunc K := algebraMap K[X] (RatFunc K) Polynomial.X set_option linter.uppercaseLean3 false in #align ratfunc.X RatFunc.X @[simp] theorem algebraMap_X : algebraMap K[X] (RatFunc K) Polynomial.X = X := rfl set_option linter.uppercaseLean3 false in #align ratfunc.algebra_map_X RatFunc.algebraMap_X end Domain section Field variable [Field K] @[simp] theorem num_C (c : K) : num (C c) = Polynomial.C c := num_algebraMap _ set_option linter.uppercaseLean3 false in #align ratfunc.num_C RatFunc.num_C @[simp] theorem denom_C (c : K) : denom (C c) = 1 := denom_algebraMap _ set_option linter.uppercaseLean3 false in #align ratfunc.denom_C RatFunc.denom_C @[simp] theorem num_X : num (X : RatFunc K) = Polynomial.X := num_algebraMap _ set_option linter.uppercaseLean3 false in #align ratfunc.num_X RatFunc.num_X @[simp] theorem denom_X : denom (X : RatFunc K) = 1 := denom_algebraMap _ set_option linter.uppercaseLean3 false in #align ratfunc.denom_X RatFunc.denom_X theorem X_ne_zero : (X : RatFunc K) ≠ 0 := RatFunc.algebraMap_ne_zero Polynomial.X_ne_zero set_option linter.uppercaseLean3 false in #align ratfunc.X_ne_zero RatFunc.X_ne_zero variable {L : Type u} [Field L] /-- Evaluate a rational function `p` given a ring hom `f` from the scalar field to the target and a value `x` for the variable in the target. Fractions are reduced by clearing common denominators before evaluating: `eval id 1 ((X^2 - 1) / (X - 1)) = eval id 1 (X + 1) = 2`, not `0 / 0 = 0`. -/ def eval (f : K →+* L) (a : L) (p : RatFunc K) : L := (num p).eval₂ f a / (denom p).eval₂ f a #align ratfunc.eval RatFunc.eval variable {f : K →+* L} {a : L}
Mathlib/FieldTheory/RatFunc/AsPolynomial.lean
119
120
theorem eval_eq_zero_of_eval₂_denom_eq_zero {x : RatFunc K} (h : Polynomial.eval₂ f a (denom x) = 0) : eval f a x = 0 := by
rw [eval, h, div_zero]
/- Copyright (c) 2020 Kenji Nakagawa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.Algebra.Algebra.Subalgebra.Pointwise import Mathlib.AlgebraicGeometry.PrimeSpectrum.Maximal import Mathlib.AlgebraicGeometry.PrimeSpectrum.Noetherian import Mathlib.RingTheory.ChainOfDivisors import Mathlib.RingTheory.DedekindDomain.Basic import Mathlib.RingTheory.FractionalIdeal.Operations #align_import ring_theory.dedekind_domain.ideal from "leanprover-community/mathlib"@"2bbc7e3884ba234309d2a43b19144105a753292e" /-! # Dedekind domains and ideals In this file, we show a ring is a Dedekind domain iff all fractional ideals are invertible. Then we prove some results on the unique factorization monoid structure of the ideals. ## Main definitions - `IsDedekindDomainInv` alternatively defines a Dedekind domain as an integral domain where every nonzero fractional ideal is invertible. - `isDedekindDomainInv_iff` shows that this does note depend on the choice of field of fractions. - `IsDedekindDomain.HeightOneSpectrum` defines the type of nonzero prime ideals of `R`. ## Main results: - `isDedekindDomain_iff_isDedekindDomainInv` - `Ideal.uniqueFactorizationMonoid` ## Implementation notes The definitions that involve a field of fractions choose a canonical field of fractions, but are independent of that choice. The `..._iff` lemmas express this independence. Often, definitions assume that Dedekind domains are not fields. We found it more practical to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed. ## References * [D. Marcus, *Number Fields*][marcus1977number] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring -/ variable (R A K : Type*) [CommRing R] [CommRing A] [Field K] open scoped nonZeroDivisors Polynomial section Inverse namespace FractionalIdeal variable {R₁ : Type*} [CommRing R₁] [IsDomain R₁] [Algebra R₁ K] [IsFractionRing R₁ K] variable {I J : FractionalIdeal R₁⁰ K} noncomputable instance : Inv (FractionalIdeal R₁⁰ K) := ⟨fun I => 1 / I⟩ theorem inv_eq : I⁻¹ = 1 / I := rfl #align fractional_ideal.inv_eq FractionalIdeal.inv_eq theorem inv_zero' : (0 : FractionalIdeal R₁⁰ K)⁻¹ = 0 := div_zero #align fractional_ideal.inv_zero' FractionalIdeal.inv_zero' theorem inv_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : J⁻¹ = ⟨(1 : FractionalIdeal R₁⁰ K) / J, fractional_div_of_nonzero h⟩ := div_nonzero h #align fractional_ideal.inv_nonzero FractionalIdeal.inv_nonzero theorem coe_inv_of_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : (↑J⁻¹ : Submodule R₁ K) = IsLocalization.coeSubmodule K ⊤ / (J : Submodule R₁ K) := by simp_rw [inv_nonzero _ h, coe_one, coe_mk, IsLocalization.coeSubmodule_top] #align fractional_ideal.coe_inv_of_nonzero FractionalIdeal.coe_inv_of_nonzero variable {K} theorem mem_inv_iff (hI : I ≠ 0) {x : K} : x ∈ I⁻¹ ↔ ∀ y ∈ I, x * y ∈ (1 : FractionalIdeal R₁⁰ K) := mem_div_iff_of_nonzero hI #align fractional_ideal.mem_inv_iff FractionalIdeal.mem_inv_iff theorem inv_anti_mono (hI : I ≠ 0) (hJ : J ≠ 0) (hIJ : I ≤ J) : J⁻¹ ≤ I⁻¹ := by -- Porting note: in Lean3, introducing `x` would just give `x ∈ J⁻¹ → x ∈ I⁻¹`, but -- in Lean4, it goes all the way down to the subtypes intro x simp only [val_eq_coe, mem_coe, mem_inv_iff hJ, mem_inv_iff hI] exact fun h y hy => h y (hIJ hy) #align fractional_ideal.inv_anti_mono FractionalIdeal.inv_anti_mono theorem le_self_mul_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * I⁻¹ := le_self_mul_one_div hI #align fractional_ideal.le_self_mul_inv FractionalIdeal.le_self_mul_inv variable (K) theorem coe_ideal_le_self_mul_inv (I : Ideal R₁) : (I : FractionalIdeal R₁⁰ K) ≤ I * (I : FractionalIdeal R₁⁰ K)⁻¹ := le_self_mul_inv coeIdeal_le_one #align fractional_ideal.coe_ideal_le_self_mul_inv FractionalIdeal.coe_ideal_le_self_mul_inv /-- `I⁻¹` is the inverse of `I` if `I` has an inverse. -/ theorem right_inverse_eq (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = I⁻¹ := by have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h suffices h' : I * (1 / I) = 1 from congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl apply le_antisymm · apply mul_le.mpr _ intro x hx y hy rw [mul_comm] exact (mem_div_iff_of_nonzero hI).mp hy x hx rw [← h] apply mul_left_mono I apply (le_div_iff_of_nonzero hI).mpr _ intro y hy x hx rw [mul_comm] exact mul_mem_mul hx hy #align fractional_ideal.right_inverse_eq FractionalIdeal.right_inverse_eq theorem mul_inv_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨I⁻¹, h⟩, fun ⟨J, hJ⟩ => by rwa [← right_inverse_eq K I J hJ]⟩ #align fractional_ideal.mul_inv_cancel_iff FractionalIdeal.mul_inv_cancel_iff theorem mul_inv_cancel_iff_isUnit {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ IsUnit I := (mul_inv_cancel_iff K).trans isUnit_iff_exists_inv.symm #align fractional_ideal.mul_inv_cancel_iff_is_unit FractionalIdeal.mul_inv_cancel_iff_isUnit variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] theorem map_inv (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : I⁻¹.map (h : K →ₐ[R₁] K') = (I.map h)⁻¹ := by rw [inv_eq, map_div, map_one, inv_eq] #align fractional_ideal.map_inv FractionalIdeal.map_inv open Submodule Submodule.IsPrincipal @[simp] theorem spanSingleton_inv (x : K) : (spanSingleton R₁⁰ x)⁻¹ = spanSingleton _ x⁻¹ := one_div_spanSingleton x #align fractional_ideal.span_singleton_inv FractionalIdeal.spanSingleton_inv -- @[simp] -- Porting note: not in simpNF form theorem spanSingleton_div_spanSingleton (x y : K) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ y = spanSingleton R₁⁰ (x / y) := by rw [div_spanSingleton, mul_comm, spanSingleton_mul_spanSingleton, div_eq_mul_inv] #align fractional_ideal.span_singleton_div_span_singleton FractionalIdeal.spanSingleton_div_spanSingleton theorem spanSingleton_div_self {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x / spanSingleton R₁⁰ x = 1 := by rw [spanSingleton_div_spanSingleton, div_self hx, spanSingleton_one] #align fractional_ideal.span_singleton_div_self FractionalIdeal.spanSingleton_div_self theorem coe_ideal_span_singleton_div_self {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) / Ideal.span ({x} : Set R₁) = 1 := by rw [coeIdeal_span_singleton, spanSingleton_div_self K <| (map_ne_zero_iff _ <| NoZeroSMulDivisors.algebraMap_injective R₁ K).mpr hx] #align fractional_ideal.coe_ideal_span_singleton_div_self FractionalIdeal.coe_ideal_span_singleton_div_self theorem spanSingleton_mul_inv {x : K} (hx : x ≠ 0) : spanSingleton R₁⁰ x * (spanSingleton R₁⁰ x)⁻¹ = 1 := by rw [spanSingleton_inv, spanSingleton_mul_spanSingleton, mul_inv_cancel hx, spanSingleton_one] #align fractional_ideal.span_singleton_mul_inv FractionalIdeal.spanSingleton_mul_inv theorem coe_ideal_span_singleton_mul_inv {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) * (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ = 1 := by rw [coeIdeal_span_singleton, spanSingleton_mul_inv K <| (map_ne_zero_iff _ <| NoZeroSMulDivisors.algebraMap_injective R₁ K).mpr hx] #align fractional_ideal.coe_ideal_span_singleton_mul_inv FractionalIdeal.coe_ideal_span_singleton_mul_inv theorem spanSingleton_inv_mul {x : K} (hx : x ≠ 0) : (spanSingleton R₁⁰ x)⁻¹ * spanSingleton R₁⁰ x = 1 := by rw [mul_comm, spanSingleton_mul_inv K hx] #align fractional_ideal.span_singleton_inv_mul FractionalIdeal.spanSingleton_inv_mul theorem coe_ideal_span_singleton_inv_mul {x : R₁} (hx : x ≠ 0) : (Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ * Ideal.span ({x} : Set R₁) = 1 := by rw [mul_comm, coe_ideal_span_singleton_mul_inv K hx] #align fractional_ideal.coe_ideal_span_singleton_inv_mul FractionalIdeal.coe_ideal_span_singleton_inv_mul theorem mul_generator_self_inv {R₁ : Type*} [CommRing R₁] [Algebra R₁ K] [IsLocalization R₁⁰ K] (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := by -- Rewrite only the `I` that appears alone. conv_lhs => congr; rw [eq_spanSingleton_of_principal I] rw [spanSingleton_mul_spanSingleton, mul_inv_cancel, spanSingleton_one] intro generator_I_eq_zero apply h rw [eq_spanSingleton_of_principal I, generator_I_eq_zero, spanSingleton_zero] #align fractional_ideal.mul_generator_self_inv FractionalIdeal.mul_generator_self_inv theorem invertible_of_principal (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * I⁻¹ = 1 := mul_div_self_cancel_iff.mpr ⟨spanSingleton _ (generator (I : Submodule R₁ K))⁻¹, mul_generator_self_inv _ I h⟩ #align fractional_ideal.invertible_of_principal FractionalIdeal.invertible_of_principal theorem invertible_iff_generator_nonzero (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] : I * I⁻¹ = 1 ↔ generator (I : Submodule R₁ K) ≠ 0 := by constructor · intro hI hg apply ne_zero_of_mul_eq_one _ _ hI rw [eq_spanSingleton_of_principal I, hg, spanSingleton_zero] · intro hg apply invertible_of_principal rw [eq_spanSingleton_of_principal I] intro hI have := mem_spanSingleton_self R₁⁰ (generator (I : Submodule R₁ K)) rw [hI, mem_zero_iff] at this contradiction #align fractional_ideal.invertible_iff_generator_nonzero FractionalIdeal.invertible_iff_generator_nonzero theorem isPrincipal_inv (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : Submodule.IsPrincipal I⁻¹.1 := by rw [val_eq_coe, isPrincipal_iff] use (generator (I : Submodule R₁ K))⁻¹ have hI : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := mul_generator_self_inv _ I h exact (right_inverse_eq _ I (spanSingleton _ (generator (I : Submodule R₁ K))⁻¹) hI).symm #align fractional_ideal.is_principal_inv FractionalIdeal.isPrincipal_inv noncomputable instance : InvOneClass (FractionalIdeal R₁⁰ K) := { inv_one := div_one } end FractionalIdeal section IsDedekindDomainInv variable [IsDomain A] /-- A Dedekind domain is an integral domain such that every fractional ideal has an inverse. This is equivalent to `IsDedekindDomain`. In particular we provide a `fractional_ideal.comm_group_with_zero` instance, assuming `IsDedekindDomain A`, which implies `IsDedekindDomainInv`. For **integral** ideals, `IsDedekindDomain`(`_inv`) implies only `Ideal.cancelCommMonoidWithZero`. -/ def IsDedekindDomainInv : Prop := ∀ I ≠ (⊥ : FractionalIdeal A⁰ (FractionRing A)), I * I⁻¹ = 1 #align is_dedekind_domain_inv IsDedekindDomainInv open FractionalIdeal variable {R A K}
Mathlib/RingTheory/DedekindDomain/Ideal.lean
253
259
theorem isDedekindDomainInv_iff [Algebra A K] [IsFractionRing A K] : IsDedekindDomainInv A ↔ ∀ I ≠ (⊥ : FractionalIdeal A⁰ K), I * I⁻¹ = 1 := by
let h : FractionalIdeal A⁰ (FractionRing A) ≃+* FractionalIdeal A⁰ K := FractionalIdeal.mapEquiv (FractionRing.algEquiv A K) refine h.toEquiv.forall_congr (fun {x} => ?_) rw [← h.toEquiv.apply_eq_iff_eq] simp [h, IsDedekindDomainInv]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Ring.Prod import Mathlib.GroupTheory.OrderOfElement import Mathlib.Tactic.FinCases #align_import data.zmod.basic from "leanprover-community/mathlib"@"74ad1c88c77e799d2fea62801d1dbbd698cff1b7" /-! # Integers mod `n` Definition of the integers mod n, and the field structure on the integers mod p. ## Definitions * `ZMod n`, which is for integers modulo a nat `n : ℕ` * `val a` is defined as a natural number: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class * `valMinAbs` returns the integer closest to zero in the equivalence class. * A coercion `cast` is defined from `ZMod n` into any ring. This is a ring hom if the ring has characteristic dividing `n` -/ assert_not_exists Submodule open Function namespace ZMod instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ) /-- `val a` is a natural number defined as: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class See `ZMod.valMinAbs` for a variant that takes values in the integers. -/ def val : ∀ {n : ℕ}, ZMod n → ℕ | 0 => Int.natAbs | n + 1 => ((↑) : Fin (n + 1) → ℕ) #align zmod.val ZMod.val theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by cases n · cases NeZero.ne 0 rfl exact Fin.is_lt a #align zmod.val_lt ZMod.val_lt theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n := a.val_lt.le #align zmod.val_le ZMod.val_le @[simp] theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0 | 0 => rfl | _ + 1 => rfl #align zmod.val_zero ZMod.val_zero @[simp] theorem val_one' : (1 : ZMod 0).val = 1 := rfl #align zmod.val_one' ZMod.val_one' @[simp] theorem val_neg' {n : ZMod 0} : (-n).val = n.val := Int.natAbs_neg n #align zmod.val_neg' ZMod.val_neg' @[simp] theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val := Int.natAbs_mul m n #align zmod.val_mul' ZMod.val_mul' @[simp] theorem val_natCast {n : ℕ} (a : ℕ) : (a : ZMod n).val = a % n := by cases n · rw [Nat.mod_zero] exact Int.natAbs_ofNat a · apply Fin.val_natCast #align zmod.val_nat_cast ZMod.val_natCast @[deprecated (since := "2024-04-17")] alias val_nat_cast := val_natCast theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by simp only [val] rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one] lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h] theorem val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by rwa [val_natCast, Nat.mod_eq_of_lt] @[deprecated (since := "2024-04-17")] alias val_nat_cast_of_lt := val_natCast_of_lt instance charP (n : ℕ) : CharP (ZMod n) n where cast_eq_zero_iff' := by intro k cases' n with n · simp [zero_dvd_iff, Int.natCast_eq_zero, Nat.zero_eq] · exact Fin.natCast_eq_zero @[simp] theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n := CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n) #align zmod.add_order_of_one ZMod.addOrderOf_one /-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version where `a ≠ 0` is `addOrderOf_coe'`. -/ @[simp] theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by cases' a with a · simp only [Nat.zero_eq, Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right, Nat.pos_of_ne_zero n0, Nat.div_self] rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one] #align zmod.add_order_of_coe ZMod.addOrderOf_coe /-- This lemma works in the case in which `a ≠ 0`. The version where `ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/ @[simp] theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one] #align zmod.add_order_of_coe' ZMod.addOrderOf_coe' /-- We have that `ringChar (ZMod n) = n`. -/ theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by rw [ringChar.eq_iff] exact ZMod.charP n #align zmod.ring_char_zmod_n ZMod.ringChar_zmod_n -- @[simp] -- Porting note (#10618): simp can prove this theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 := CharP.cast_eq_zero (ZMod n) n #align zmod.nat_cast_self ZMod.natCast_self @[deprecated (since := "2024-04-17")] alias nat_cast_self := natCast_self @[simp] theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by rw [← Nat.cast_add_one, natCast_self (n + 1)] #align zmod.nat_cast_self' ZMod.natCast_self' @[deprecated (since := "2024-04-17")] alias nat_cast_self' := natCast_self' section UniversalProperty variable {n : ℕ} {R : Type*} section variable [AddGroupWithOne R] /-- Cast an integer modulo `n` to another semiring. This function is a morphism if the characteristic of `R` divides `n`. See `ZMod.castHom` for a bundled version. -/ def cast : ∀ {n : ℕ}, ZMod n → R | 0 => Int.cast | _ + 1 => fun i => i.val #align zmod.cast ZMod.cast @[simp] theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by delta ZMod.cast cases n · exact Int.cast_zero · simp #align zmod.cast_zero ZMod.cast_zero theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by cases n · cases NeZero.ne 0 rfl rfl #align zmod.cast_eq_val ZMod.cast_eq_val variable {S : Type*} [AddGroupWithOne S] @[simp] theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by cases n · rfl · simp [ZMod.cast] #align prod.fst_zmod_cast Prod.fst_zmod_cast @[simp] theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by cases n · rfl · simp [ZMod.cast] #align prod.snd_zmod_cast Prod.snd_zmod_cast end /-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring, see `ZMod.natCast_val`. -/ theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by cases n · cases NeZero.ne 0 rfl · apply Fin.cast_val_eq_self #align zmod.nat_cast_zmod_val ZMod.natCast_zmod_val @[deprecated (since := "2024-04-17")] alias nat_cast_zmod_val := natCast_zmod_val theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) := natCast_zmod_val #align zmod.nat_cast_right_inverse ZMod.natCast_rightInverse @[deprecated (since := "2024-04-17")] alias nat_cast_rightInverse := natCast_rightInverse theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) := natCast_rightInverse.surjective #align zmod.nat_cast_zmod_surjective ZMod.natCast_zmod_surjective @[deprecated (since := "2024-04-17")] alias nat_cast_zmod_surjective := natCast_zmod_surjective /-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary ring, see `ZMod.intCast_cast`. -/ @[norm_cast] theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by cases n · simp [ZMod.cast, ZMod] · dsimp [ZMod.cast, ZMod] erw [Int.cast_natCast, Fin.cast_val_eq_self] #align zmod.int_cast_zmod_cast ZMod.intCast_zmod_cast @[deprecated (since := "2024-04-17")] alias int_cast_zmod_cast := intCast_zmod_cast theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) := intCast_zmod_cast #align zmod.int_cast_right_inverse ZMod.intCast_rightInverse @[deprecated (since := "2024-04-17")] alias int_cast_rightInverse := intCast_rightInverse theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) := intCast_rightInverse.surjective #align zmod.int_cast_surjective ZMod.intCast_surjective @[deprecated (since := "2024-04-17")] alias int_cast_surjective := intCast_surjective theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i | 0, _ => Int.cast_id | _ + 1, i => natCast_zmod_val i #align zmod.cast_id ZMod.cast_id @[simp] theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id := funext (cast_id n) #align zmod.cast_id' ZMod.cast_id' variable (R) [Ring R] /-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/ @[simp] theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by cases n · cases NeZero.ne 0 rfl rfl #align zmod.nat_cast_comp_val ZMod.natCast_comp_val @[deprecated (since := "2024-04-17")] alias nat_cast_comp_val := natCast_comp_val /-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/ @[simp] theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by cases n · exact congr_arg (Int.cast ∘ ·) ZMod.cast_id' · ext simp [ZMod, ZMod.cast] #align zmod.int_cast_comp_cast ZMod.intCast_comp_cast @[deprecated (since := "2024-04-17")] alias int_cast_comp_cast := intCast_comp_cast variable {R} @[simp] theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i := congr_fun (natCast_comp_val R) i #align zmod.nat_cast_val ZMod.natCast_val @[deprecated (since := "2024-04-17")] alias nat_cast_val := natCast_val @[simp] theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i := congr_fun (intCast_comp_cast R) i #align zmod.int_cast_cast ZMod.intCast_cast @[deprecated (since := "2024-04-17")] alias int_cast_cast := intCast_cast theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) : (cast (a + b) : ℤ) = if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by cases' n with n · simp; rfl change Fin (n + 1) at a b change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _ simp only [Fin.val_add_eq_ite, Int.ofNat_succ, Int.ofNat_le] norm_cast split_ifs with h · rw [Nat.cast_sub h] congr · rfl #align zmod.coe_add_eq_ite ZMod.cast_add_eq_ite section CharDvd /-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/ variable {m : ℕ} [CharP R m] @[simp] theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by cases' n with n · exact Int.cast_one show ((1 % (n + 1) : ℕ) : R) = 1 cases n; · rw [Nat.dvd_one] at h subst m have : Subsingleton R := CharP.CharOne.subsingleton apply Subsingleton.elim rw [Nat.mod_eq_of_lt] · exact Nat.cast_one exact Nat.lt_of_sub_eq_succ rfl #align zmod.cast_one ZMod.cast_one theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by cases n · apply Int.cast_add symm dsimp [ZMod, ZMod.cast] erw [← Nat.cast_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _), @CharP.cast_eq_zero_iff R _ m] exact h.trans (Nat.dvd_sub_mod _) #align zmod.cast_add ZMod.cast_add theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by cases n · apply Int.cast_mul symm dsimp [ZMod, ZMod.cast] erw [← Nat.cast_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _), @CharP.cast_eq_zero_iff R _ m] exact h.trans (Nat.dvd_sub_mod _) #align zmod.cast_mul ZMod.cast_mul /-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`. See also `ZMod.lift` for a generalized version working in `AddGroup`s. -/ def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where toFun := cast map_zero' := cast_zero map_one' := cast_one h map_add' := cast_add h map_mul' := cast_mul h #align zmod.cast_hom ZMod.castHom @[simp] theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i := rfl #align zmod.cast_hom_apply ZMod.castHom_apply @[simp] theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b := (castHom h R).map_sub a b #align zmod.cast_sub ZMod.cast_sub @[simp] theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) := (castHom h R).map_neg a #align zmod.cast_neg ZMod.cast_neg @[simp] theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k := (castHom h R).map_pow a k #align zmod.cast_pow ZMod.cast_pow @[simp, norm_cast] theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k := map_natCast (castHom h R) k #align zmod.cast_nat_cast ZMod.cast_natCast @[deprecated (since := "2024-04-17")] alias cast_nat_cast := cast_natCast @[simp, norm_cast] theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k := map_intCast (castHom h R) k #align zmod.cast_int_cast ZMod.cast_intCast @[deprecated (since := "2024-04-17")] alias cast_int_cast := cast_intCast end CharDvd section CharEq /-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/ variable [CharP R n] @[simp] theorem cast_one' : (cast (1 : ZMod n) : R) = 1 := cast_one dvd_rfl #align zmod.cast_one' ZMod.cast_one' @[simp] theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := cast_add dvd_rfl a b #align zmod.cast_add' ZMod.cast_add' @[simp] theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := cast_mul dvd_rfl a b #align zmod.cast_mul' ZMod.cast_mul' @[simp] theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b := cast_sub dvd_rfl a b #align zmod.cast_sub' ZMod.cast_sub' @[simp] theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k := cast_pow dvd_rfl a k #align zmod.cast_pow' ZMod.cast_pow' @[simp, norm_cast] theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k := cast_natCast dvd_rfl k #align zmod.cast_nat_cast' ZMod.cast_natCast' @[deprecated (since := "2024-04-17")] alias cast_nat_cast' := cast_natCast' @[simp, norm_cast] theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k := cast_intCast dvd_rfl k #align zmod.cast_int_cast' ZMod.cast_intCast' @[deprecated (since := "2024-04-17")] alias cast_int_cast' := cast_intCast' variable (R) theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by rw [injective_iff_map_eq_zero] intro x obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n] exact id #align zmod.cast_hom_injective ZMod.castHom_injective theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) : Function.Bijective (ZMod.castHom (dvd_refl n) R) := by haveI : NeZero n := ⟨by intro hn rw [hn] at h exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩ rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true_iff] apply ZMod.castHom_injective #align zmod.cast_hom_bijective ZMod.castHom_bijective /-- The unique ring isomorphism between `ZMod n` and a ring `R` of characteristic `n` and cardinality `n`. -/ noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R := RingEquiv.ofBijective _ (ZMod.castHom_bijective R h) #align zmod.ring_equiv ZMod.ringEquiv /-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/ def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by cases' m with m <;> cases' n with n · exact RingEquiv.refl _ · exfalso exact n.succ_ne_zero h.symm · exfalso exact m.succ_ne_zero h · exact { finCongr h with map_mul' := fun a b => by dsimp [ZMod] ext rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h] map_add' := fun a b => by dsimp [ZMod] ext rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] } #align zmod.ring_equiv_congr ZMod.ringEquivCongr @[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by cases a <;> rfl lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by rw [ringEquivCongr_refl] rfl lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) : (ringEquivCongr hab).symm = ringEquivCongr hab.symm := by subst hab cases a <;> rfl lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) : (ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by subst hab hbc cases a <;> rfl lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) : ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by rw [← ringEquivCongr_trans hab hbc] rfl lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) : ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by subst h cases a <;> rfl lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) : ZMod.ringEquivCongr h z = z := by subst h cases a <;> rfl @[deprecated (since := "2024-05-25")] alias int_coe_ringEquivCongr := ringEquivCongr_intCast end CharEq end UniversalProperty theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] := CharP.intCast_eq_intCast (ZMod c) c #align zmod.int_coe_eq_int_coe_iff ZMod.intCast_eq_intCast_iff @[deprecated (since := "2024-04-17")] alias int_cast_eq_int_cast_iff := intCast_eq_intCast_iff theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c := ZMod.intCast_eq_intCast_iff a b c #align zmod.int_coe_eq_int_coe_iff' ZMod.intCast_eq_intCast_iff' @[deprecated (since := "2024-04-17")] alias int_cast_eq_int_cast_iff' := intCast_eq_intCast_iff' theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c #align zmod.nat_coe_eq_nat_coe_iff ZMod.natCast_eq_natCast_iff @[deprecated (since := "2024-04-17")] alias nat_cast_eq_nat_cast_iff := natCast_eq_natCast_iff theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c := ZMod.natCast_eq_natCast_iff a b c #align zmod.nat_coe_eq_nat_coe_iff' ZMod.natCast_eq_natCast_iff' @[deprecated (since := "2024-04-17")] alias nat_cast_eq_nat_cast_iff' := natCast_eq_natCast_iff' theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd] #align zmod.int_coe_zmod_eq_zero_iff_dvd ZMod.intCast_zmod_eq_zero_iff_dvd @[deprecated (since := "2024-04-17")] alias int_cast_zmod_eq_zero_iff_dvd := intCast_zmod_eq_zero_iff_dvd theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd] #align zmod.int_coe_eq_int_coe_iff_dvd_sub ZMod.intCast_eq_intCast_iff_dvd_sub @[deprecated (since := "2024-04-17")] alias int_cast_eq_int_cast_iff_dvd_sub := intCast_eq_intCast_iff_dvd_sub theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd] #align zmod.nat_coe_zmod_eq_zero_iff_dvd ZMod.natCast_zmod_eq_zero_iff_dvd @[deprecated (since := "2024-04-17")] alias nat_cast_zmod_eq_zero_iff_dvd := natCast_zmod_eq_zero_iff_dvd theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _ have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a) refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_ rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id] #align zmod.val_int_cast ZMod.val_intCast @[deprecated (since := "2024-04-17")] alias val_int_cast := val_intCast theorem coe_intCast {n : ℕ} (a : ℤ) : cast (a : ZMod n) = a % n := by cases n · rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl · rw [← val_intCast, val]; rfl #align zmod.coe_int_cast ZMod.coe_intCast @[deprecated (since := "2024-04-17")] alias coe_int_cast := coe_intCast @[simp] theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by dsimp [val, Fin.coe_neg] cases n · simp [Nat.mod_one] · dsimp [ZMod, ZMod.cast] rw [Fin.coe_neg_one] #align zmod.val_neg_one ZMod.val_neg_one /-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/ theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by cases' n with n · dsimp [ZMod, ZMod.cast]; simp · rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right] #align zmod.cast_neg_one ZMod.cast_neg_one theorem cast_sub_one {R : Type*} [Ring R] {n : ℕ} (k : ZMod n) : (cast (k - 1 : ZMod n) : R) = (if k = 0 then (n : R) else cast k) - 1 := by split_ifs with hk · rw [hk, zero_sub, ZMod.cast_neg_one] · cases n · dsimp [ZMod, ZMod.cast] rw [Int.cast_sub, Int.cast_one] · dsimp [ZMod, ZMod.cast, ZMod.val] rw [Fin.coe_sub_one, if_neg] · rw [Nat.cast_sub, Nat.cast_one] rwa [Fin.ext_iff, Fin.val_zero, ← Ne, ← Nat.one_le_iff_ne_zero] at hk · exact hk #align zmod.cast_sub_one ZMod.cast_sub_one theorem natCast_eq_iff (p : ℕ) (n : ℕ) (z : ZMod p) [NeZero p] : ↑n = z ↔ ∃ k, n = z.val + p * k := by constructor · rintro rfl refine ⟨n / p, ?_⟩ rw [val_natCast, Nat.mod_add_div] · rintro ⟨k, rfl⟩ rw [Nat.cast_add, natCast_zmod_val, Nat.cast_mul, natCast_self, zero_mul, add_zero] #align zmod.nat_coe_zmod_eq_iff ZMod.natCast_eq_iff theorem intCast_eq_iff (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p] : ↑n = z ↔ ∃ k, n = z.val + p * k := by constructor · rintro rfl refine ⟨n / p, ?_⟩ rw [val_intCast, Int.emod_add_ediv] · rintro ⟨k, rfl⟩ rw [Int.cast_add, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_val, ZMod.natCast_self, zero_mul, add_zero, cast_id] #align zmod.int_coe_zmod_eq_iff ZMod.intCast_eq_iff @[deprecated (since := "2024-05-25")] alias nat_coe_zmod_eq_iff := natCast_eq_iff @[deprecated (since := "2024-05-25")] alias int_coe_zmod_eq_iff := intCast_eq_iff @[push_cast, simp] theorem intCast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : ZMod b) = (a : ZMod b) := by rw [ZMod.intCast_eq_intCast_iff] apply Int.mod_modEq #align zmod.int_cast_mod ZMod.intCast_mod @[deprecated (since := "2024-04-17")] alias int_cast_mod := intCast_mod theorem ker_intCastAddHom (n : ℕ) : (Int.castAddHom (ZMod n)).ker = AddSubgroup.zmultiples (n : ℤ) := by ext rw [Int.mem_zmultiples_iff, AddMonoidHom.mem_ker, Int.coe_castAddHom, intCast_zmod_eq_zero_iff_dvd] #align zmod.ker_int_cast_add_hom ZMod.ker_intCastAddHom @[deprecated (since := "2024-04-17")] alias ker_int_castAddHom := ker_intCastAddHom theorem cast_injective_of_le {m n : ℕ} [nzm : NeZero m] (h : m ≤ n) : Function.Injective (@cast (ZMod n) _ m) := by cases m with | zero => cases nzm; simp_all | succ m => rintro ⟨x, hx⟩ ⟨y, hy⟩ f simp only [cast, val, natCast_eq_natCast_iff', Nat.mod_eq_of_lt (hx.trans_le h), Nat.mod_eq_of_lt (hy.trans_le h)] at f apply Fin.ext exact f theorem cast_zmod_eq_zero_iff_of_le {m n : ℕ} [NeZero m] (h : m ≤ n) (a : ZMod m) : (cast a : ZMod n) = 0 ↔ a = 0 := by rw [← ZMod.cast_zero (n := m)] exact Injective.eq_iff' (cast_injective_of_le h) rfl -- Porting note: commented -- unseal Int.NonNeg @[simp] theorem natCast_toNat (p : ℕ) : ∀ {z : ℤ} (_h : 0 ≤ z), (z.toNat : ZMod p) = z | (n : ℕ), _h => by simp only [Int.cast_natCast, Int.toNat_natCast] | Int.negSucc n, h => by simp at h #align zmod.nat_cast_to_nat ZMod.natCast_toNat @[deprecated (since := "2024-04-17")] alias nat_cast_toNat := natCast_toNat theorem val_injective (n : ℕ) [NeZero n] : Function.Injective (val : ZMod n → ℕ) := by cases n · cases NeZero.ne 0 rfl intro a b h dsimp [ZMod] ext exact h #align zmod.val_injective ZMod.val_injective theorem val_one_eq_one_mod (n : ℕ) : (1 : ZMod n).val = 1 % n := by rw [← Nat.cast_one, val_natCast] #align zmod.val_one_eq_one_mod ZMod.val_one_eq_one_mod theorem val_one (n : ℕ) [Fact (1 < n)] : (1 : ZMod n).val = 1 := by rw [val_one_eq_one_mod] exact Nat.mod_eq_of_lt Fact.out #align zmod.val_one ZMod.val_one theorem val_add {n : ℕ} [NeZero n] (a b : ZMod n) : (a + b).val = (a.val + b.val) % n := by cases n · cases NeZero.ne 0 rfl · apply Fin.val_add #align zmod.val_add ZMod.val_add theorem val_add_of_lt {n : ℕ} {a b : ZMod n} (h : a.val + b.val < n) : (a + b).val = a.val + b.val := by have : NeZero n := by constructor; rintro rfl; simp at h rw [ZMod.val_add, Nat.mod_eq_of_lt h] theorem val_add_val_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) : a.val + b.val = (a + b).val + n := by rw [val_add, Nat.add_mod_add_of_le_add_mod, Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)] rwa [Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)] theorem val_add_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) : (a + b).val = a.val + b.val - n := by rw [val_add_val_of_le h] exact eq_tsub_of_add_eq rfl theorem val_add_le {n : ℕ} (a b : ZMod n) : (a + b).val ≤ a.val + b.val := by cases n · simp [ZMod.val]; apply Int.natAbs_add_le · simp [ZMod.val_add]; apply Nat.mod_le theorem val_mul {n : ℕ} (a b : ZMod n) : (a * b).val = a.val * b.val % n := by cases n · rw [Nat.mod_zero] apply Int.natAbs_mul · apply Fin.val_mul #align zmod.val_mul ZMod.val_mul theorem val_mul_le {n : ℕ} (a b : ZMod n) : (a * b).val ≤ a.val * b.val := by rw [val_mul] apply Nat.mod_le theorem val_mul_of_lt {n : ℕ} {a b : ZMod n} (h : a.val * b.val < n) : (a * b).val = a.val * b.val := by rw [val_mul] apply Nat.mod_eq_of_lt h instance nontrivial (n : ℕ) [Fact (1 < n)] : Nontrivial (ZMod n) := ⟨⟨0, 1, fun h => zero_ne_one <| calc 0 = (0 : ZMod n).val := by rw [val_zero] _ = (1 : ZMod n).val := congr_arg ZMod.val h _ = 1 := val_one n ⟩⟩ #align zmod.nontrivial ZMod.nontrivial instance nontrivial' : Nontrivial (ZMod 0) := by delta ZMod; infer_instance #align zmod.nontrivial' ZMod.nontrivial' /-- The inversion on `ZMod n`. It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`. In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/ def inv : ∀ n : ℕ, ZMod n → ZMod n | 0, i => Int.sign i | n + 1, i => Nat.gcdA i.val (n + 1) #align zmod.inv ZMod.inv instance (n : ℕ) : Inv (ZMod n) := ⟨inv n⟩ @[nolint unusedHavesSuffices] theorem inv_zero : ∀ n : ℕ, (0 : ZMod n)⁻¹ = 0 | 0 => Int.sign_zero | n + 1 => show (Nat.gcdA _ (n + 1) : ZMod (n + 1)) = 0 by rw [val_zero] unfold Nat.gcdA Nat.xgcd Nat.xgcdAux rfl #align zmod.inv_zero ZMod.inv_zero theorem mul_inv_eq_gcd {n : ℕ} (a : ZMod n) : a * a⁻¹ = Nat.gcd a.val n := by cases' n with n · dsimp [ZMod] at a ⊢ calc _ = a * Int.sign a := rfl _ = a.natAbs := by rw [Int.mul_sign] _ = a.natAbs.gcd 0 := by rw [Nat.gcd_zero_right] · calc a * a⁻¹ = a * a⁻¹ + n.succ * Nat.gcdB (val a) n.succ := by rw [natCast_self, zero_mul, add_zero] _ = ↑(↑a.val * Nat.gcdA (val a) n.succ + n.succ * Nat.gcdB (val a) n.succ) := by push_cast rw [natCast_zmod_val] rfl _ = Nat.gcd a.val n.succ := by rw [← Nat.gcd_eq_gcd_ab a.val n.succ]; rfl #align zmod.mul_inv_eq_gcd ZMod.mul_inv_eq_gcd @[simp] theorem natCast_mod (a : ℕ) (n : ℕ) : ((a % n : ℕ) : ZMod n) = a := by conv => rhs rw [← Nat.mod_add_div a n] simp #align zmod.nat_cast_mod ZMod.natCast_mod @[deprecated (since := "2024-04-17")] alias nat_cast_mod := natCast_mod theorem eq_iff_modEq_nat (n : ℕ) {a b : ℕ} : (a : ZMod n) = b ↔ a ≡ b [MOD n] := by cases n · simp [Nat.ModEq, Int.natCast_inj, Nat.mod_zero] · rw [Fin.ext_iff, Nat.ModEq, ← val_natCast, ← val_natCast] exact Iff.rfl #align zmod.eq_iff_modeq_nat ZMod.eq_iff_modEq_nat theorem coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : ((x : ZMod n) * (x : ZMod n)⁻¹) = 1 := by rw [Nat.Coprime, Nat.gcd_comm, Nat.gcd_rec] at h rw [mul_inv_eq_gcd, val_natCast, h, Nat.cast_one] #align zmod.coe_mul_inv_eq_one ZMod.coe_mul_inv_eq_one /-- `unitOfCoprime` makes an element of `(ZMod n)ˣ` given a natural number `x` and a proof that `x` is coprime to `n` -/ def unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : (ZMod n)ˣ := ⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩ #align zmod.unit_of_coprime ZMod.unitOfCoprime @[simp] theorem coe_unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : (unitOfCoprime x h : ZMod n) = x := rfl #align zmod.coe_unit_of_coprime ZMod.coe_unitOfCoprime theorem val_coe_unit_coprime {n : ℕ} (u : (ZMod n)ˣ) : Nat.Coprime (u : ZMod n).val n := by cases' n with n · rcases Int.units_eq_one_or u with (rfl | rfl) <;> simp apply Nat.coprime_of_mul_modEq_one ((u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1)).val have := Units.ext_iff.1 (mul_right_inv u) rw [Units.val_one] at this rw [← eq_iff_modEq_nat, Nat.cast_one, ← this]; clear this rw [← natCast_zmod_val ((u * u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1))] rw [Units.val_mul, val_mul, natCast_mod] #align zmod.val_coe_unit_coprime ZMod.val_coe_unit_coprime lemma isUnit_iff_coprime (m n : ℕ) : IsUnit (m : ZMod n) ↔ m.Coprime n := by refine ⟨fun H ↦ ?_, fun H ↦ (unitOfCoprime m H).isUnit⟩ have H' := val_coe_unit_coprime H.unit rw [IsUnit.unit_spec, val_natCast m, Nat.coprime_iff_gcd_eq_one] at H' rw [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm, ← H'] exact Nat.gcd_rec n m lemma isUnit_prime_iff_not_dvd {n p : ℕ} (hp : p.Prime) : IsUnit (p : ZMod n) ↔ ¬p ∣ n := by rw [isUnit_iff_coprime, Nat.Prime.coprime_iff_not_dvd hp] lemma isUnit_prime_of_not_dvd {n p : ℕ} (hp : p.Prime) (h : ¬ p ∣ n) : IsUnit (p : ZMod n) := (isUnit_prime_iff_not_dvd hp).mpr h @[simp] theorem inv_coe_unit {n : ℕ} (u : (ZMod n)ˣ) : (u : ZMod n)⁻¹ = (u⁻¹ : (ZMod n)ˣ) := by have := congr_arg ((↑) : ℕ → ZMod n) (val_coe_unit_coprime u) rw [← mul_inv_eq_gcd, Nat.cast_one] at this let u' : (ZMod n)ˣ := ⟨u, (u : ZMod n)⁻¹, this, by rwa [mul_comm]⟩ have h : u = u' := by apply Units.ext rfl rw [h] rfl #align zmod.inv_coe_unit ZMod.inv_coe_unit theorem mul_inv_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a * a⁻¹ = 1 := by rcases h with ⟨u, rfl⟩ rw [inv_coe_unit, u.mul_inv] #align zmod.mul_inv_of_unit ZMod.mul_inv_of_unit theorem inv_mul_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a⁻¹ * a = 1 := by rw [mul_comm, mul_inv_of_unit a h] #align zmod.inv_mul_of_unit ZMod.inv_mul_of_unit -- TODO: If we changed `⁻¹` so that `ZMod n` is always a `DivisionMonoid`, -- then we could use the general lemma `inv_eq_of_mul_eq_one` protected theorem inv_eq_of_mul_eq_one (n : ℕ) (a b : ZMod n) (h : a * b = 1) : a⁻¹ = b := left_inv_eq_right_inv (inv_mul_of_unit a ⟨⟨a, b, h, mul_comm a b ▸ h⟩, rfl⟩) h -- TODO: this equivalence is true for `ZMod 0 = ℤ`, but needs to use different functions. /-- Equivalence between the units of `ZMod n` and the subtype of terms `x : ZMod n` for which `x.val` is coprime to `n` -/ def unitsEquivCoprime {n : ℕ} [NeZero n] : (ZMod n)ˣ ≃ { x : ZMod n // Nat.Coprime x.val n } where toFun x := ⟨x, val_coe_unit_coprime x⟩ invFun x := unitOfCoprime x.1.val x.2 left_inv := fun ⟨_, _, _, _⟩ => Units.ext (natCast_zmod_val _) right_inv := fun ⟨_, _⟩ => by simp #align zmod.units_equiv_coprime ZMod.unitsEquivCoprime /-- The **Chinese remainder theorem**. For a pair of coprime natural numbers, `m` and `n`, the rings `ZMod (m * n)` and `ZMod m × ZMod n` are isomorphic. See `Ideal.quotientInfRingEquivPiQuotient` for the Chinese remainder theorem for ideals in any ring. -/ def chineseRemainder {m n : ℕ} (h : m.Coprime n) : ZMod (m * n) ≃+* ZMod m × ZMod n := let to_fun : ZMod (m * n) → ZMod m × ZMod n := ZMod.castHom (show m.lcm n ∣ m * n by simp [Nat.lcm_dvd_iff]) (ZMod m × ZMod n) let inv_fun : ZMod m × ZMod n → ZMod (m * n) := fun x => if m * n = 0 then if m = 1 then cast (RingHom.snd _ (ZMod n) x) else cast (RingHom.fst (ZMod m) _ x) else Nat.chineseRemainder h x.1.val x.2.val have inv : Function.LeftInverse inv_fun to_fun ∧ Function.RightInverse inv_fun to_fun := if hmn0 : m * n = 0 then by rcases h.eq_of_mul_eq_zero hmn0 with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · constructor · intro x; rfl · rintro ⟨x, y⟩ fin_cases y simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton] · constructor · intro x; rfl · rintro ⟨x, y⟩ fin_cases x simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton] else by haveI : NeZero (m * n) := ⟨hmn0⟩ haveI : NeZero m := ⟨left_ne_zero_of_mul hmn0⟩ haveI : NeZero n := ⟨right_ne_zero_of_mul hmn0⟩ have left_inv : Function.LeftInverse inv_fun to_fun := by intro x dsimp only [to_fun, inv_fun, ZMod.castHom_apply] conv_rhs => rw [← ZMod.natCast_zmod_val x] rw [if_neg hmn0, ZMod.eq_iff_modEq_nat, ← Nat.modEq_and_modEq_iff_modEq_mul h, Prod.fst_zmod_cast, Prod.snd_zmod_cast] refine ⟨(Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.left.trans ?_, (Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.right.trans ?_⟩ · rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val] · rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val] exact ⟨left_inv, left_inv.rightInverse_of_card_le (by simp)⟩ { toFun := to_fun, invFun := inv_fun, map_mul' := RingHom.map_mul _ map_add' := RingHom.map_add _ left_inv := inv.1 right_inv := inv.2 } #align zmod.chinese_remainder ZMod.chineseRemainder lemma subsingleton_iff {n : ℕ} : Subsingleton (ZMod n) ↔ n = 1 := by constructor · obtain (_ | _ | n) := n · simpa [ZMod] using not_subsingleton _ · simp [ZMod] · simpa [ZMod] using not_subsingleton _ · rintro rfl infer_instance lemma nontrivial_iff {n : ℕ} : Nontrivial (ZMod n) ↔ n ≠ 1 := by rw [← not_subsingleton_iff_nontrivial, subsingleton_iff] -- todo: this can be made a `Unique` instance. instance subsingleton_units : Subsingleton (ZMod 2)ˣ := ⟨by decide⟩ #align zmod.subsingleton_units ZMod.subsingleton_units @[simp] theorem add_self_eq_zero_iff_eq_zero {n : ℕ} (hn : Odd n) {a : ZMod n} : a + a = 0 ↔ a = 0 := by rw [Nat.odd_iff, ← Nat.two_dvd_ne_zero, ← Nat.prime_two.coprime_iff_not_dvd] at hn rw [← mul_two, ← @Nat.cast_two (ZMod n), ← ZMod.coe_unitOfCoprime 2 hn, Units.mul_left_eq_zero] theorem ne_neg_self {n : ℕ} (hn : Odd n) {a : ZMod n} (ha : a ≠ 0) : a ≠ -a := by rwa [Ne, eq_neg_iff_add_eq_zero, add_self_eq_zero_iff_eq_zero hn] #align zmod.ne_neg_self ZMod.ne_neg_self theorem neg_one_ne_one {n : ℕ} [Fact (2 < n)] : (-1 : ZMod n) ≠ 1 := CharP.neg_one_ne_one (ZMod n) n #align zmod.neg_one_ne_one ZMod.neg_one_ne_one theorem neg_eq_self_mod_two (a : ZMod 2) : -a = a := by fin_cases a <;> apply Fin.ext <;> simp [Fin.coe_neg, Int.natMod]; rfl #align zmod.neg_eq_self_mod_two ZMod.neg_eq_self_mod_two @[simp] theorem natAbs_mod_two (a : ℤ) : (a.natAbs : ZMod 2) = a := by cases a · simp only [Int.natAbs_ofNat, Int.cast_natCast, Int.ofNat_eq_coe] · simp only [neg_eq_self_mod_two, Nat.cast_succ, Int.natAbs, Int.cast_negSucc] #align zmod.nat_abs_mod_two ZMod.natAbs_mod_two @[simp] theorem val_eq_zero : ∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0 | 0, a => Int.natAbs_eq_zero | n + 1, a => by rw [Fin.ext_iff] exact Iff.rfl #align zmod.val_eq_zero ZMod.val_eq_zero theorem val_ne_zero {n : ℕ} (a : ZMod n) : a.val ≠ 0 ↔ a ≠ 0 := (val_eq_zero a).not theorem neg_eq_self_iff {n : ℕ} (a : ZMod n) : -a = a ↔ a = 0 ∨ 2 * a.val = n := by rw [neg_eq_iff_add_eq_zero, ← two_mul] cases n · erw [@mul_eq_zero ℤ, @mul_eq_zero ℕ, val_eq_zero] exact ⟨fun h => h.elim (by simp) Or.inl, fun h => Or.inr (h.elim id fun h => h.elim (by simp) id)⟩ conv_lhs => rw [← a.natCast_zmod_val, ← Nat.cast_two, ← Nat.cast_mul, natCast_zmod_eq_zero_iff_dvd] constructor · rintro ⟨m, he⟩ cases' m with m · erw [mul_zero, mul_eq_zero] at he rcases he with (⟨⟨⟩⟩ | he) exact Or.inl (a.val_eq_zero.1 he) cases m · right rwa [show 0 + 1 = 1 from rfl, mul_one] at he refine (a.val_lt.not_le <| Nat.le_of_mul_le_mul_left ?_ zero_lt_two).elim rw [he, mul_comm] apply Nat.mul_le_mul_left erw [Nat.succ_le_succ_iff, Nat.succ_le_succ_iff]; simp · rintro (rfl | h) · rw [val_zero, mul_zero] apply dvd_zero · rw [h] #align zmod.neg_eq_self_iff ZMod.neg_eq_self_iff
Mathlib/Data/ZMod/Basic.lean
1,062
1,063
theorem val_cast_of_lt {n : ℕ} {a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rw [val_natCast, Nat.mod_eq_of_lt 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, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.NullMeasurable import Mathlib.MeasureTheory.MeasurableSpace.Basic import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import measure_theory.measure.measure_space from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace open scoped Classical symmDiff open Topology Filter ENNReal NNReal Interval MeasureTheory variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ #align measure_theory.ae_is_measurably_generated MeasureTheory.ae_isMeasurablyGenerated /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] #align measure_theory.ae_uIoc_iff MeasureTheory.ae_uIoc_iff theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union MeasureTheory.measure_union theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union' MeasureTheory.measure_union' theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet #align measure_theory.measure_inter_add_diff MeasureTheory.measure_inter_add_diff theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) #align measure_theory.measure_diff_add_inter MeasureTheory.measure_diff_add_inter theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl #align measure_theory.measure_union_add_inter MeasureTheory.measure_union_add_inter theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] #align measure_theory.measure_union_add_inter' MeasureTheory.measure_union_add_inter' lemma measure_symmDiff_eq (hs : MeasurableSet s) (ht : MeasurableSet t) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union disjoint_sdiff_sdiff (ht.diff hs) lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet #align measure_theory.measure_add_measure_compl MeasureTheory.measure_add_measure_compl theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 #align measure_theory.measure_bUnion₀ MeasureTheory.measure_biUnion₀ theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet #align measure_theory.measure_bUnion MeasureTheory.measure_biUnion theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] #align measure_theory.measure_sUnion₀ MeasureTheory.measure_sUnion₀ theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] #align measure_theory.measure_sUnion MeasureTheory.measure_sUnion theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm #align measure_theory.measure_bUnion_finset₀ MeasureTheory.measure_biUnion_finset₀ theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet #align measure_theory.measure_bUnion_finset MeasureTheory.measure_biUnion_finset /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) #align measure_theory.tsum_meas_le_meas_Union_of_disjoint MeasureTheory.tsum_meas_le_meas_iUnion_of_disjoint /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
209
211
theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by
rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf]
/- Copyright (c) 2023 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.MeasureTheory.Constructions.Pi import Mathlib.MeasureTheory.Integral.Lebesgue /-! # Marginals of multivariate functions In this file, we define a convenient way to compute integrals of multivariate functions, especially if you want to write expressions where you integrate only over some of the variables that the function depends on. This is common in induction arguments involving integrals of multivariate functions. This constructions allows working with iterated integrals and applying Tonelli's theorem and Fubini's theorem, without using measurable equivalences by changing the representation of your space (e.g. `((ι ⊕ ι') → ℝ) ≃ (ι → ℝ) × (ι' → ℝ)`). ## Main Definitions * Assume that `∀ i : ι, π i` is a product of measurable spaces with measures `μ i` on `π i`, `f : (∀ i, π i) → ℝ≥0∞` is a function and `s : Finset ι`. Then `lmarginal μ s f` or `∫⋯∫⁻_s, f ∂μ` is the function that integrates `f` over all variables in `s`. It returns a function that still takes the same variables as `f`, but is constant in the variables in `s`. Mathematically, if `s = {i₁, ..., iₖ}`, then `lmarginal μ s f` is the expression $$ \vec{x}\mapsto \int\!\!\cdots\!\!\int f(\vec{x}[\vec{y}])dy_{i_1}\cdots dy_{i_k}. $$ where $\vec{x}[\vec{y}]$ is the vector $\vec{x}$ with $x_{i_j}$ replaced by $y_{i_j}$ for all $1 \le j \le k$. If `f` is the distribution of a random variable, this is the marginal distribution of all variables not in `s` (but not the most general notion, since we only consider product measures here). Note that the notation `∫⋯∫⁻_s, f ∂μ` is not a binder, and returns a function. ## Main Results * `lmarginal_union` is the analogue of Tonelli's theorem for iterated integrals. It states that for measurable functions `f` and disjoint finsets `s` and `t` we have `∫⋯∫⁻_s ∪ t, f ∂μ = ∫⋯∫⁻_s, ∫⋯∫⁻_t, f ∂μ ∂μ`. ## Implementation notes The function `f` can have an arbitrary product as its domain (even infinite products), but the set `s` of integration variables is a `Finset`. We are assuming that the function `f` is measurable for most of this file. Note that asking whether it is `AEMeasurable` is not even well-posed, since there is no well-behaved measure on the domain of `f`. ## Todo * Define the marginal function for functions taking values in a Banach space. -/ open scoped Classical ENNReal open Set Function Equiv Finset noncomputable section namespace MeasureTheory section LMarginal variable {δ δ' : Type*} {π : δ → Type*} [∀ x, MeasurableSpace (π x)] variable {μ : ∀ i, Measure (π i)} [∀ i, SigmaFinite (μ i)] [DecidableEq δ] variable {s t : Finset δ} {f g : (∀ i, π i) → ℝ≥0∞} {x y : ∀ i, π i} {i : δ} /-- Integrate `f(x₁,…,xₙ)` over all variables `xᵢ` where `i ∈ s`. Return a function in the remaining variables (it will be constant in the `xᵢ` for `i ∈ s`). This is the marginal distribution of all variables not in `s` when the considered measure is the product measure. -/ def lmarginal (μ : ∀ i, Measure (π i)) (s : Finset δ) (f : (∀ i, π i) → ℝ≥0∞) (x : ∀ i, π i) : ℝ≥0∞ := ∫⁻ y : ∀ i : s, π i, f (updateFinset x s y) ∂Measure.pi fun i : s => μ i -- Note: this notation is not a binder. This is more convenient since it returns a function. @[inherit_doc] notation "∫⋯∫⁻_" s ", " f " ∂" μ:70 => lmarginal μ s f @[inherit_doc] notation "∫⋯∫⁻_" s ", " f => lmarginal (fun _ ↦ volume) s f variable (μ) theorem _root_.Measurable.lmarginal (hf : Measurable f) : Measurable (∫⋯∫⁻_s, f ∂μ) := by refine Measurable.lintegral_prod_right ?_ refine hf.comp ?_ rw [measurable_pi_iff]; intro i by_cases hi : i ∈ s · simp [hi, updateFinset] exact measurable_pi_iff.1 measurable_snd _ · simp [hi, updateFinset] exact measurable_pi_iff.1 measurable_fst _ @[simp] theorem lmarginal_empty (f : (∀ i, π i) → ℝ≥0∞) : ∫⋯∫⁻_∅, f ∂μ = f := by ext1 x simp_rw [lmarginal, Measure.pi_of_empty fun i : (∅ : Finset δ) => μ i] apply lintegral_dirac' exact Subsingleton.measurable /-- The marginal distribution is independent of the variables in `s`. -/ theorem lmarginal_congr {x y : ∀ i, π i} (f : (∀ i, π i) → ℝ≥0∞) (h : ∀ i ∉ s, x i = y i) : (∫⋯∫⁻_s, f ∂μ) x = (∫⋯∫⁻_s, f ∂μ) y := by dsimp [lmarginal, updateFinset_def]; rcongr; exact h _ ‹_› theorem lmarginal_update_of_mem {i : δ} (hi : i ∈ s) (f : (∀ i, π i) → ℝ≥0∞) (x : ∀ i, π i) (y : π i) : (∫⋯∫⁻_s, f ∂μ) (Function.update x i y) = (∫⋯∫⁻_s, f ∂μ) x := by apply lmarginal_congr intro j hj have : j ≠ i := by rintro rfl; exact hj hi apply update_noteq this theorem lmarginal_union (f : (∀ i, π i) → ℝ≥0∞) (hf : Measurable f) (hst : Disjoint s t) : ∫⋯∫⁻_s ∪ t, f ∂μ = ∫⋯∫⁻_s, ∫⋯∫⁻_t, f ∂μ ∂μ := by ext1 x let e := MeasurableEquiv.piFinsetUnion π hst calc (∫⋯∫⁻_s ∪ t, f ∂μ) x = ∫⁻ (y : (i : ↥(s ∪ t)) → π i), f (updateFinset x (s ∪ t) y) ∂.pi fun i' : ↥(s ∪ t) ↦ μ i' := rfl _ = ∫⁻ (y : ((i : s) → π i) × ((j : t) → π j)), f (updateFinset x (s ∪ t) _) ∂(Measure.pi fun i : s ↦ μ i).prod (.pi fun j : t ↦ μ j) := by rw [measurePreserving_piFinsetUnion hst μ |>.lintegral_map_equiv] _ = ∫⁻ (y : (i : s) → π i), ∫⁻ (z : (j : t) → π j), f (updateFinset x (s ∪ t) (e (y, z))) ∂.pi fun j : t ↦ μ j ∂.pi fun i : s ↦ μ i := by apply lintegral_prod apply Measurable.aemeasurable exact hf.comp <| measurable_updateFinset.comp e.measurable _ = (∫⋯∫⁻_s, ∫⋯∫⁻_t, f ∂μ ∂μ) x := by simp_rw [lmarginal, updateFinset_updateFinset hst] rfl theorem lmarginal_union' (f : (∀ i, π i) → ℝ≥0∞) (hf : Measurable f) {s t : Finset δ} (hst : Disjoint s t) : ∫⋯∫⁻_s ∪ t, f ∂μ = ∫⋯∫⁻_t, ∫⋯∫⁻_s, f ∂μ ∂μ := by rw [Finset.union_comm, lmarginal_union μ f hf hst.symm] variable {μ} set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem lmarginal_singleton (f : (∀ i, π i) → ℝ≥0∞) (i : δ) : ∫⋯∫⁻_{i}, f ∂μ = fun x => ∫⁻ xᵢ, f (Function.update x i xᵢ) ∂μ i := by let α : Type _ := ({i} : Finset δ) let e := (MeasurableEquiv.piUnique fun j : α ↦ π j).symm ext1 x calc (∫⋯∫⁻_{i}, f ∂μ) x = ∫⁻ (y : π (default : α)), f (updateFinset x {i} (e y)) ∂μ (default : α) := by simp_rw [lmarginal, measurePreserving_piUnique (fun j : ({i} : Finset δ) ↦ μ j) |>.symm _ |>.lintegral_map_equiv] _ = ∫⁻ xᵢ, f (Function.update x i xᵢ) ∂μ i := by simp [update_eq_updateFinset]; rfl /-- Peel off a single integral from a `lmarginal` integral at the beginning (compare with `lmarginal_insert'`, which peels off an integral at the end). -/ theorem lmarginal_insert (f : (∀ i, π i) → ℝ≥0∞) (hf : Measurable f) {i : δ} (hi : i ∉ s) (x : ∀ i, π i) : (∫⋯∫⁻_insert i s, f ∂μ) x = ∫⁻ xᵢ, (∫⋯∫⁻_s, f ∂μ) (Function.update x i xᵢ) ∂μ i := by rw [Finset.insert_eq, lmarginal_union μ f hf (Finset.disjoint_singleton_left.mpr hi), lmarginal_singleton] /-- Peel off a single integral from a `lmarginal` integral at the beginning (compare with `lmarginal_erase'`, which peels off an integral at the end). -/ theorem lmarginal_erase (f : (∀ i, π i) → ℝ≥0∞) (hf : Measurable f) {i : δ} (hi : i ∈ s) (x : ∀ i, π i) : (∫⋯∫⁻_s, f ∂μ) x = ∫⁻ xᵢ, (∫⋯∫⁻_(erase s i), f ∂μ) (Function.update x i xᵢ) ∂μ i := by simpa [insert_erase hi] using lmarginal_insert _ hf (not_mem_erase i s) x /-- Peel off a single integral from a `lmarginal` integral at the end (compare with `lmarginal_insert`, which peels off an integral at the beginning). -/ theorem lmarginal_insert' (f : (∀ i, π i) → ℝ≥0∞) (hf : Measurable f) {i : δ} (hi : i ∉ s) : ∫⋯∫⁻_insert i s, f ∂μ = ∫⋯∫⁻_s, (fun x ↦ ∫⁻ xᵢ, f (Function.update x i xᵢ) ∂μ i) ∂μ := by rw [Finset.insert_eq, Finset.union_comm, lmarginal_union (s := s) μ f hf (Finset.disjoint_singleton_right.mpr hi), lmarginal_singleton] /-- Peel off a single integral from a `lmarginal` integral at the end (compare with `lmarginal_erase`, which peels off an integral at the beginning). -/ theorem lmarginal_erase' (f : (∀ i, π i) → ℝ≥0∞) (hf : Measurable f) {i : δ} (hi : i ∈ s) : ∫⋯∫⁻_s, f ∂μ = ∫⋯∫⁻_(erase s i), (fun x ↦ ∫⁻ xᵢ, f (Function.update x i xᵢ) ∂μ i) ∂μ := by simpa [insert_erase hi] using lmarginal_insert' _ hf (not_mem_erase i s) open Filter @[gcongr] theorem lmarginal_mono {f g : (∀ i, π i) → ℝ≥0∞} (hfg : f ≤ g) : ∫⋯∫⁻_s, f ∂μ ≤ ∫⋯∫⁻_s, g ∂μ := fun _ => lintegral_mono fun _ => hfg _ @[simp] theorem lmarginal_univ [Fintype δ] {f : (∀ i, π i) → ℝ≥0∞} : ∫⋯∫⁻_univ, f ∂μ = fun _ => ∫⁻ x, f x ∂Measure.pi μ := by let e : { j // j ∈ Finset.univ } ≃ δ := Equiv.subtypeUnivEquiv mem_univ ext1 x simp_rw [lmarginal, measurePreserving_piCongrLeft μ e |>.lintegral_map_equiv, updateFinset_def] simp rfl theorem lintegral_eq_lmarginal_univ [Fintype δ] {f : (∀ i, π i) → ℝ≥0∞} (x : ∀ i, π i) : ∫⁻ x, f x ∂Measure.pi μ = (∫⋯∫⁻_univ, f ∂μ) x := by simp theorem lmarginal_image [DecidableEq δ'] {e : δ' → δ} (he : Injective e) (s : Finset δ') {f : (∀ i, π (e i)) → ℝ≥0∞} (hf : Measurable f) (x : ∀ i, π i) : (∫⋯∫⁻_s.image e, f ∘ (· ∘' e) ∂μ) x = (∫⋯∫⁻_s, f ∂μ ∘' e) (x ∘' e) := by have h : Measurable ((· ∘' e) : (∀ i, π i) → _) := measurable_pi_iff.mpr <| fun i ↦ measurable_pi_apply (e i) induction s using Finset.induction generalizing x with | empty => simp | insert hi ih => rw [image_insert, lmarginal_insert _ (hf.comp h) (he.mem_finset_image.not.mpr hi), lmarginal_insert _ hf hi] simp_rw [ih, ← update_comp_eq_of_injective' x he] theorem lmarginal_update_of_not_mem {i : δ} {f : (∀ i, π i) → ℝ≥0∞} (hf : Measurable f) (hi : i ∉ s) (x : ∀ i, π i) (y : π i) : (∫⋯∫⁻_s, f ∂μ) (Function.update x i y) = (∫⋯∫⁻_s, f ∘ (Function.update · i y) ∂μ) x := by induction s using Finset.induction generalizing x with | empty => simp | @insert i' s hi' ih => rw [lmarginal_insert _ hf hi', lmarginal_insert _ (hf.comp measurable_update_left) hi'] have hii' : i ≠ i' := mt (by rintro rfl; exact mem_insert_self i s) hi simp_rw [update_comm hii', ih (mt Finset.mem_insert_of_mem hi)] theorem lmarginal_eq_of_subset {f g : (∀ i, π i) → ℝ≥0∞} (hst : s ⊆ t) (hf : Measurable f) (hg : Measurable g) (hfg : ∫⋯∫⁻_s, f ∂μ = ∫⋯∫⁻_s, g ∂μ) : ∫⋯∫⁻_t, f ∂μ = ∫⋯∫⁻_t, g ∂μ := by rw [← union_sdiff_of_subset hst, lmarginal_union' μ f hf disjoint_sdiff, lmarginal_union' μ g hg disjoint_sdiff, hfg] theorem lmarginal_le_of_subset {f g : (∀ i, π i) → ℝ≥0∞} (hst : s ⊆ t) (hf : Measurable f) (hg : Measurable g) (hfg : ∫⋯∫⁻_s, f ∂μ ≤ ∫⋯∫⁻_s, g ∂μ) : ∫⋯∫⁻_t, f ∂μ ≤ ∫⋯∫⁻_t, g ∂μ := by rw [← union_sdiff_of_subset hst, lmarginal_union' μ f hf disjoint_sdiff, lmarginal_union' μ g hg disjoint_sdiff] exact lmarginal_mono hfg
Mathlib/MeasureTheory/Integral/Marginal.lean
237
242
theorem lintegral_eq_of_lmarginal_eq [Fintype δ] (s : Finset δ) {f g : (∀ i, π i) → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∫⋯∫⁻_s, f ∂μ = ∫⋯∫⁻_s, g ∂μ) : ∫⁻ x, f x ∂Measure.pi μ = ∫⁻ x, g x ∂Measure.pi μ := by
rcases isEmpty_or_nonempty (∀ i, π i) with h|⟨⟨x⟩⟩ · simp_rw [lintegral_of_isEmpty] simp_rw [lintegral_eq_lmarginal_univ x, lmarginal_eq_of_subset (Finset.subset_univ s) hf hg hfg]
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Algebra.Order.Field.Canonical.Basic import Mathlib.Algebra.Order.Nonneg.Field import Mathlib.Algebra.Order.Nonneg.Floor import Mathlib.Data.Real.Pointwise import Mathlib.Order.ConditionallyCompleteLattice.Group import Mathlib.Tactic.GCongr.Core #align_import data.real.nnreal from "leanprover-community/mathlib"@"b1abe23ae96fef89ad30d9f4362c307f72a55010" /-! # Nonnegative real numbers In this file we define `NNReal` (notation: `ℝ≥0`) to be the type of non-negative real numbers, a.k.a. the interval `[0, ∞)`. We also define the following operations and structures on `ℝ≥0`: * the order on `ℝ≥0` is the restriction of the order on `ℝ`; these relations define a conditionally complete linear order with a bottom element, `ConditionallyCompleteLinearOrderBot`; * `a + b` and `a * b` are the restrictions of addition and multiplication of real numbers to `ℝ≥0`; these operations together with `0 = ⟨0, _⟩` and `1 = ⟨1, _⟩` turn `ℝ≥0` into a conditionally complete linear ordered archimedean commutative semifield; we have no typeclass for this in `mathlib` yet, so we define the following instances instead: - `LinearOrderedSemiring ℝ≥0`; - `OrderedCommSemiring ℝ≥0`; - `CanonicallyOrderedCommSemiring ℝ≥0`; - `LinearOrderedCommGroupWithZero ℝ≥0`; - `CanonicallyLinearOrderedAddCommMonoid ℝ≥0`; - `Archimedean ℝ≥0`; - `ConditionallyCompleteLinearOrderBot ℝ≥0`. These instances are derived from corresponding instances about the type `{x : α // 0 ≤ x}` in an appropriate ordered field/ring/group/monoid `α`, see `Mathlib.Algebra.Order.Nonneg.Ring`. * `Real.toNNReal x` is defined as `⟨max x 0, _⟩`, i.e. `↑(Real.toNNReal x) = x` when `0 ≤ x` and `↑(Real.toNNReal x) = 0` otherwise. We also define an instance `CanLift ℝ ℝ≥0`. This instance can be used by the `lift` tactic to replace `x : ℝ` and `hx : 0 ≤ x` in the proof context with `x : ℝ≥0` while replacing all occurrences of `x` with `↑x`. This tactic also works for a function `f : α → ℝ` with a hypothesis `hf : ∀ x, 0 ≤ f x`. ## Notations This file defines `ℝ≥0` as a localized notation for `NNReal`. -/ open Function -- to ensure these instances are computable /-- Nonnegative real numbers. -/ def NNReal := { r : ℝ // 0 ≤ r } deriving Zero, One, Semiring, StrictOrderedSemiring, CommMonoidWithZero, CommSemiring, SemilatticeInf, SemilatticeSup, DistribLattice, OrderedCommSemiring, CanonicallyOrderedCommSemiring, Inhabited #align nnreal NNReal namespace NNReal scoped notation "ℝ≥0" => NNReal noncomputable instance : FloorSemiring ℝ≥0 := Nonneg.floorSemiring instance instDenselyOrdered : DenselyOrdered ℝ≥0 := Nonneg.instDenselyOrdered instance : OrderBot ℝ≥0 := inferInstance instance : Archimedean ℝ≥0 := Nonneg.archimedean noncomputable instance : Sub ℝ≥0 := Nonneg.sub noncomputable instance : OrderedSub ℝ≥0 := Nonneg.orderedSub noncomputable instance : CanonicallyLinearOrderedSemifield ℝ≥0 := Nonneg.canonicallyLinearOrderedSemifield /-- Coercion `ℝ≥0 → ℝ`. -/ @[coe] def toReal : ℝ≥0 → ℝ := Subtype.val instance : Coe ℝ≥0 ℝ := ⟨toReal⟩ -- Simp lemma to put back `n.val` into the normal form given by the coercion. @[simp] theorem val_eq_coe (n : ℝ≥0) : n.val = n := rfl #align nnreal.val_eq_coe NNReal.val_eq_coe instance canLift : CanLift ℝ ℝ≥0 toReal fun r => 0 ≤ r := Subtype.canLift _ #align nnreal.can_lift NNReal.canLift @[ext] protected theorem eq {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) → n = m := Subtype.eq #align nnreal.eq NNReal.eq protected theorem eq_iff {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) ↔ n = m := Subtype.ext_iff.symm #align nnreal.eq_iff NNReal.eq_iff theorem ne_iff {x y : ℝ≥0} : (x : ℝ) ≠ (y : ℝ) ↔ x ≠ y := not_congr <| NNReal.eq_iff #align nnreal.ne_iff NNReal.ne_iff protected theorem «forall» {p : ℝ≥0 → Prop} : (∀ x : ℝ≥0, p x) ↔ ∀ (x : ℝ) (hx : 0 ≤ x), p ⟨x, hx⟩ := Subtype.forall #align nnreal.forall NNReal.forall protected theorem «exists» {p : ℝ≥0 → Prop} : (∃ x : ℝ≥0, p x) ↔ ∃ (x : ℝ) (hx : 0 ≤ x), p ⟨x, hx⟩ := Subtype.exists #align nnreal.exists NNReal.exists /-- Reinterpret a real number `r` as a non-negative real number. Returns `0` if `r < 0`. -/ noncomputable def _root_.Real.toNNReal (r : ℝ) : ℝ≥0 := ⟨max r 0, le_max_right _ _⟩ #align real.to_nnreal Real.toNNReal theorem _root_.Real.coe_toNNReal (r : ℝ) (hr : 0 ≤ r) : (Real.toNNReal r : ℝ) = r := max_eq_left hr #align real.coe_to_nnreal Real.coe_toNNReal theorem _root_.Real.toNNReal_of_nonneg {r : ℝ} (hr : 0 ≤ r) : r.toNNReal = ⟨r, hr⟩ := by simp_rw [Real.toNNReal, max_eq_left hr] #align real.to_nnreal_of_nonneg Real.toNNReal_of_nonneg theorem _root_.Real.le_coe_toNNReal (r : ℝ) : r ≤ Real.toNNReal r := le_max_left r 0 #align real.le_coe_to_nnreal Real.le_coe_toNNReal theorem coe_nonneg (r : ℝ≥0) : (0 : ℝ) ≤ r := r.2 #align nnreal.coe_nonneg NNReal.coe_nonneg @[simp, norm_cast] theorem coe_mk (a : ℝ) (ha) : toReal ⟨a, ha⟩ = a := rfl #align nnreal.coe_mk NNReal.coe_mk example : Zero ℝ≥0 := by infer_instance example : One ℝ≥0 := by infer_instance example : Add ℝ≥0 := by infer_instance noncomputable example : Sub ℝ≥0 := by infer_instance example : Mul ℝ≥0 := by infer_instance noncomputable example : Inv ℝ≥0 := by infer_instance noncomputable example : Div ℝ≥0 := by infer_instance example : LE ℝ≥0 := by infer_instance example : Bot ℝ≥0 := by infer_instance example : Inhabited ℝ≥0 := by infer_instance example : Nontrivial ℝ≥0 := by infer_instance protected theorem coe_injective : Injective ((↑) : ℝ≥0 → ℝ) := Subtype.coe_injective #align nnreal.coe_injective NNReal.coe_injective @[simp, norm_cast] lemma coe_inj {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) = r₂ ↔ r₁ = r₂ := NNReal.coe_injective.eq_iff #align nnreal.coe_eq NNReal.coe_inj @[deprecated (since := "2024-02-03")] protected alias coe_eq := coe_inj @[simp, norm_cast] lemma coe_zero : ((0 : ℝ≥0) : ℝ) = 0 := rfl #align nnreal.coe_zero NNReal.coe_zero @[simp, norm_cast] lemma coe_one : ((1 : ℝ≥0) : ℝ) = 1 := rfl #align nnreal.coe_one NNReal.coe_one @[simp, norm_cast] protected theorem coe_add (r₁ r₂ : ℝ≥0) : ((r₁ + r₂ : ℝ≥0) : ℝ) = r₁ + r₂ := rfl #align nnreal.coe_add NNReal.coe_add @[simp, norm_cast] protected theorem coe_mul (r₁ r₂ : ℝ≥0) : ((r₁ * r₂ : ℝ≥0) : ℝ) = r₁ * r₂ := rfl #align nnreal.coe_mul NNReal.coe_mul @[simp, norm_cast] protected theorem coe_inv (r : ℝ≥0) : ((r⁻¹ : ℝ≥0) : ℝ) = (r : ℝ)⁻¹ := rfl #align nnreal.coe_inv NNReal.coe_inv @[simp, norm_cast] protected theorem coe_div (r₁ r₂ : ℝ≥0) : ((r₁ / r₂ : ℝ≥0) : ℝ) = (r₁ : ℝ) / r₂ := rfl #align nnreal.coe_div NNReal.coe_div #noalign nnreal.coe_bit0 #noalign nnreal.coe_bit1 protected theorem coe_two : ((2 : ℝ≥0) : ℝ) = 2 := rfl #align nnreal.coe_two NNReal.coe_two @[simp, norm_cast] protected theorem coe_sub {r₁ r₂ : ℝ≥0} (h : r₂ ≤ r₁) : ((r₁ - r₂ : ℝ≥0) : ℝ) = ↑r₁ - ↑r₂ := max_eq_left <| le_sub_comm.2 <| by simp [show (r₂ : ℝ) ≤ r₁ from h] #align nnreal.coe_sub NNReal.coe_sub variable {r r₁ r₂ : ℝ≥0} {x y : ℝ} @[simp, norm_cast] lemma coe_eq_zero : (r : ℝ) = 0 ↔ r = 0 := by rw [← coe_zero, coe_inj] #align coe_eq_zero NNReal.coe_eq_zero @[simp, norm_cast] lemma coe_eq_one : (r : ℝ) = 1 ↔ r = 1 := by rw [← coe_one, coe_inj] #align coe_inj_one NNReal.coe_eq_one @[norm_cast] lemma coe_ne_zero : (r : ℝ) ≠ 0 ↔ r ≠ 0 := coe_eq_zero.not #align nnreal.coe_ne_zero NNReal.coe_ne_zero @[norm_cast] lemma coe_ne_one : (r : ℝ) ≠ 1 ↔ r ≠ 1 := coe_eq_one.not example : CommSemiring ℝ≥0 := by infer_instance /-- Coercion `ℝ≥0 → ℝ` as a `RingHom`. Porting note (#11215): TODO: what if we define `Coe ℝ≥0 ℝ` using this function? -/ def toRealHom : ℝ≥0 →+* ℝ where toFun := (↑) map_one' := NNReal.coe_one map_mul' := NNReal.coe_mul map_zero' := NNReal.coe_zero map_add' := NNReal.coe_add #align nnreal.to_real_hom NNReal.toRealHom @[simp] theorem coe_toRealHom : ⇑toRealHom = toReal := rfl #align nnreal.coe_to_real_hom NNReal.coe_toRealHom section Actions /-- A `MulAction` over `ℝ` restricts to a `MulAction` over `ℝ≥0`. -/ instance {M : Type*} [MulAction ℝ M] : MulAction ℝ≥0 M := MulAction.compHom M toRealHom.toMonoidHom theorem smul_def {M : Type*} [MulAction ℝ M] (c : ℝ≥0) (x : M) : c • x = (c : ℝ) • x := rfl #align nnreal.smul_def NNReal.smul_def instance {M N : Type*} [MulAction ℝ M] [MulAction ℝ N] [SMul M N] [IsScalarTower ℝ M N] : IsScalarTower ℝ≥0 M N where smul_assoc r := (smul_assoc (r : ℝ) : _) instance smulCommClass_left {M N : Type*} [MulAction ℝ N] [SMul M N] [SMulCommClass ℝ M N] : SMulCommClass ℝ≥0 M N where smul_comm r := (smul_comm (r : ℝ) : _) #align nnreal.smul_comm_class_left NNReal.smulCommClass_left instance smulCommClass_right {M N : Type*} [MulAction ℝ N] [SMul M N] [SMulCommClass M ℝ N] : SMulCommClass M ℝ≥0 N where smul_comm m r := (smul_comm m (r : ℝ) : _) #align nnreal.smul_comm_class_right NNReal.smulCommClass_right /-- A `DistribMulAction` over `ℝ` restricts to a `DistribMulAction` over `ℝ≥0`. -/ instance {M : Type*} [AddMonoid M] [DistribMulAction ℝ M] : DistribMulAction ℝ≥0 M := DistribMulAction.compHom M toRealHom.toMonoidHom /-- A `Module` over `ℝ` restricts to a `Module` over `ℝ≥0`. -/ instance {M : Type*} [AddCommMonoid M] [Module ℝ M] : Module ℝ≥0 M := Module.compHom M toRealHom -- Porting note (#11215): TODO: after this line, `↑` uses `Algebra.cast` instead of `toReal` /-- An `Algebra` over `ℝ` restricts to an `Algebra` over `ℝ≥0`. -/ instance {A : Type*} [Semiring A] [Algebra ℝ A] : Algebra ℝ≥0 A where smul := (· • ·) commutes' r x := by simp [Algebra.commutes] smul_def' r x := by simp [← Algebra.smul_def (r : ℝ) x, smul_def] toRingHom := (algebraMap ℝ A).comp (toRealHom : ℝ≥0 →+* ℝ) instance : StarRing ℝ≥0 := starRingOfComm instance : TrivialStar ℝ≥0 where star_trivial _ := rfl instance : StarModule ℝ≥0 ℝ where star_smul := by simp only [star_trivial, eq_self_iff_true, forall_const] -- verify that the above produces instances we might care about example : Algebra ℝ≥0 ℝ := by infer_instance example : DistribMulAction ℝ≥0ˣ ℝ := by infer_instance end Actions example : MonoidWithZero ℝ≥0 := by infer_instance example : CommMonoidWithZero ℝ≥0 := by infer_instance noncomputable example : CommGroupWithZero ℝ≥0 := by infer_instance @[simp, norm_cast] theorem coe_indicator {α} (s : Set α) (f : α → ℝ≥0) (a : α) : ((s.indicator f a : ℝ≥0) : ℝ) = s.indicator (fun x => ↑(f x)) a := (toRealHom : ℝ≥0 →+ ℝ).map_indicator _ _ _ #align nnreal.coe_indicator NNReal.coe_indicator @[simp, norm_cast] theorem coe_pow (r : ℝ≥0) (n : ℕ) : ((r ^ n : ℝ≥0) : ℝ) = (r : ℝ) ^ n := rfl #align nnreal.coe_pow NNReal.coe_pow @[simp, norm_cast] theorem coe_zpow (r : ℝ≥0) (n : ℤ) : ((r ^ n : ℝ≥0) : ℝ) = (r : ℝ) ^ n := rfl #align nnreal.coe_zpow NNReal.coe_zpow @[norm_cast] theorem coe_list_sum (l : List ℝ≥0) : ((l.sum : ℝ≥0) : ℝ) = (l.map (↑)).sum := map_list_sum toRealHom l #align nnreal.coe_list_sum NNReal.coe_list_sum @[norm_cast] theorem coe_list_prod (l : List ℝ≥0) : ((l.prod : ℝ≥0) : ℝ) = (l.map (↑)).prod := map_list_prod toRealHom l #align nnreal.coe_list_prod NNReal.coe_list_prod @[norm_cast] theorem coe_multiset_sum (s : Multiset ℝ≥0) : ((s.sum : ℝ≥0) : ℝ) = (s.map (↑)).sum := map_multiset_sum toRealHom s #align nnreal.coe_multiset_sum NNReal.coe_multiset_sum @[norm_cast] theorem coe_multiset_prod (s : Multiset ℝ≥0) : ((s.prod : ℝ≥0) : ℝ) = (s.map (↑)).prod := map_multiset_prod toRealHom s #align nnreal.coe_multiset_prod NNReal.coe_multiset_prod @[norm_cast] theorem coe_sum {α} {s : Finset α} {f : α → ℝ≥0} : ↑(∑ a ∈ s, f a) = ∑ a ∈ s, (f a : ℝ) := map_sum toRealHom _ _ #align nnreal.coe_sum NNReal.coe_sum theorem _root_.Real.toNNReal_sum_of_nonneg {α} {s : Finset α} {f : α → ℝ} (hf : ∀ a, a ∈ s → 0 ≤ f a) : Real.toNNReal (∑ a ∈ s, f a) = ∑ a ∈ s, Real.toNNReal (f a) := by rw [← coe_inj, NNReal.coe_sum, Real.coe_toNNReal _ (Finset.sum_nonneg hf)] exact Finset.sum_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)] #align real.to_nnreal_sum_of_nonneg Real.toNNReal_sum_of_nonneg @[norm_cast] theorem coe_prod {α} {s : Finset α} {f : α → ℝ≥0} : ↑(∏ a ∈ s, f a) = ∏ a ∈ s, (f a : ℝ) := map_prod toRealHom _ _ #align nnreal.coe_prod NNReal.coe_prod theorem _root_.Real.toNNReal_prod_of_nonneg {α} {s : Finset α} {f : α → ℝ} (hf : ∀ a, a ∈ s → 0 ≤ f a) : Real.toNNReal (∏ a ∈ s, f a) = ∏ a ∈ s, Real.toNNReal (f a) := by rw [← coe_inj, NNReal.coe_prod, Real.coe_toNNReal _ (Finset.prod_nonneg hf)] exact Finset.prod_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)] #align real.to_nnreal_prod_of_nonneg Real.toNNReal_prod_of_nonneg -- Porting note (#11215): TODO: `simp`? `norm_cast`? theorem coe_nsmul (r : ℝ≥0) (n : ℕ) : ↑(n • r) = n • (r : ℝ) := rfl #align nnreal.nsmul_coe NNReal.coe_nsmul @[simp, norm_cast] protected theorem coe_natCast (n : ℕ) : (↑(↑n : ℝ≥0) : ℝ) = n := map_natCast toRealHom n #align nnreal.coe_nat_cast NNReal.coe_natCast @[deprecated (since := "2024-04-17")] alias coe_nat_cast := NNReal.coe_natCast -- See note [no_index around OfNat.ofNat] @[simp, norm_cast] protected theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n : ℝ≥0) : ℝ) = OfNat.ofNat n := rfl @[simp, norm_cast] protected theorem coe_ofScientific (m : ℕ) (s : Bool) (e : ℕ) : ↑(OfScientific.ofScientific m s e : ℝ≥0) = (OfScientific.ofScientific m s e : ℝ) := rfl noncomputable example : LinearOrder ℝ≥0 := by infer_instance @[simp, norm_cast] lemma coe_le_coe : (r₁ : ℝ) ≤ r₂ ↔ r₁ ≤ r₂ := Iff.rfl #align nnreal.coe_le_coe NNReal.coe_le_coe @[simp, norm_cast] lemma coe_lt_coe : (r₁ : ℝ) < r₂ ↔ r₁ < r₂ := Iff.rfl #align nnreal.coe_lt_coe NNReal.coe_lt_coe @[simp, norm_cast] lemma coe_pos : (0 : ℝ) < r ↔ 0 < r := Iff.rfl #align nnreal.coe_pos NNReal.coe_pos @[simp, norm_cast] lemma one_le_coe : 1 ≤ (r : ℝ) ↔ 1 ≤ r := by rw [← coe_le_coe, coe_one] @[simp, norm_cast] lemma one_lt_coe : 1 < (r : ℝ) ↔ 1 < r := by rw [← coe_lt_coe, coe_one] @[simp, norm_cast] lemma coe_le_one : (r : ℝ) ≤ 1 ↔ r ≤ 1 := by rw [← coe_le_coe, coe_one] @[simp, norm_cast] lemma coe_lt_one : (r : ℝ) < 1 ↔ r < 1 := by rw [← coe_lt_coe, coe_one] @[mono] lemma coe_mono : Monotone ((↑) : ℝ≥0 → ℝ) := fun _ _ => NNReal.coe_le_coe.2 #align nnreal.coe_mono NNReal.coe_mono /-- Alias for the use of `gcongr` -/ @[gcongr] alias ⟨_, GCongr.toReal_le_toReal⟩ := coe_le_coe protected theorem _root_.Real.toNNReal_mono : Monotone Real.toNNReal := fun _ _ h => max_le_max h (le_refl 0) #align real.to_nnreal_mono Real.toNNReal_mono @[simp] theorem _root_.Real.toNNReal_coe {r : ℝ≥0} : Real.toNNReal r = r := NNReal.eq <| max_eq_left r.2 #align real.to_nnreal_coe Real.toNNReal_coe @[simp] theorem mk_natCast (n : ℕ) : @Eq ℝ≥0 (⟨(n : ℝ), n.cast_nonneg⟩ : ℝ≥0) n := NNReal.eq (NNReal.coe_natCast n).symm #align nnreal.mk_coe_nat NNReal.mk_natCast @[deprecated (since := "2024-04-05")] alias mk_coe_nat := mk_natCast -- Porting note: place this in the `Real` namespace @[simp] theorem toNNReal_coe_nat (n : ℕ) : Real.toNNReal n = n := NNReal.eq <| by simp [Real.coe_toNNReal] #align nnreal.to_nnreal_coe_nat NNReal.toNNReal_coe_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem _root_.Real.toNNReal_ofNat (n : ℕ) [n.AtLeastTwo] : Real.toNNReal (no_index (OfNat.ofNat n)) = OfNat.ofNat n := toNNReal_coe_nat n /-- `Real.toNNReal` and `NNReal.toReal : ℝ≥0 → ℝ` form a Galois insertion. -/ noncomputable def gi : GaloisInsertion Real.toNNReal (↑) := GaloisInsertion.monotoneIntro NNReal.coe_mono Real.toNNReal_mono Real.le_coe_toNNReal fun _ => Real.toNNReal_coe #align nnreal.gi NNReal.gi -- note that anything involving the (decidability of the) linear order, -- will be noncomputable, everything else should not be. example : OrderBot ℝ≥0 := by infer_instance example : PartialOrder ℝ≥0 := by infer_instance noncomputable example : CanonicallyLinearOrderedAddCommMonoid ℝ≥0 := by infer_instance noncomputable example : LinearOrderedAddCommMonoid ℝ≥0 := by infer_instance example : DistribLattice ℝ≥0 := by infer_instance example : SemilatticeInf ℝ≥0 := by infer_instance example : SemilatticeSup ℝ≥0 := by infer_instance noncomputable example : LinearOrderedSemiring ℝ≥0 := by infer_instance example : OrderedCommSemiring ℝ≥0 := by infer_instance noncomputable example : LinearOrderedCommMonoid ℝ≥0 := by infer_instance noncomputable example : LinearOrderedCommMonoidWithZero ℝ≥0 := by infer_instance noncomputable example : LinearOrderedCommGroupWithZero ℝ≥0 := by infer_instance example : CanonicallyOrderedCommSemiring ℝ≥0 := by infer_instance example : DenselyOrdered ℝ≥0 := by infer_instance example : NoMaxOrder ℝ≥0 := by infer_instance instance instPosSMulStrictMono {α} [Preorder α] [MulAction ℝ α] [PosSMulStrictMono ℝ α] : PosSMulStrictMono ℝ≥0 α where elim _r hr _a₁ _a₂ ha := (smul_lt_smul_of_pos_left ha (coe_pos.2 hr):) instance instSMulPosStrictMono {α} [Zero α] [Preorder α] [MulAction ℝ α] [SMulPosStrictMono ℝ α] : SMulPosStrictMono ℝ≥0 α where elim _a ha _r₁ _r₂ hr := (smul_lt_smul_of_pos_right (coe_lt_coe.2 hr) ha:) /-- If `a` is a nonnegative real number, then the closed interval `[0, a]` in `ℝ` is order isomorphic to the interval `Set.Iic a`. -/ -- Porting note (#11215): TODO: restore once `simps` supports `ℝ≥0` @[simps!? apply_coe_coe] def orderIsoIccZeroCoe (a : ℝ≥0) : Set.Icc (0 : ℝ) a ≃o Set.Iic a where toEquiv := Equiv.Set.sep (Set.Ici 0) fun x : ℝ => x ≤ a map_rel_iff' := Iff.rfl #align nnreal.order_iso_Icc_zero_coe NNReal.orderIsoIccZeroCoe @[simp] theorem orderIsoIccZeroCoe_apply_coe_coe (a : ℝ≥0) (b : Set.Icc (0 : ℝ) a) : (orderIsoIccZeroCoe a b : ℝ) = b := rfl @[simp] theorem orderIsoIccZeroCoe_symm_apply_coe (a : ℝ≥0) (b : Set.Iic a) : ((orderIsoIccZeroCoe a).symm b : ℝ) = b := rfl #align nnreal.order_iso_Icc_zero_coe_symm_apply_coe NNReal.orderIsoIccZeroCoe_symm_apply_coe -- note we need the `@` to make the `Membership.mem` have a sensible type theorem coe_image {s : Set ℝ≥0} : (↑) '' s = { x : ℝ | ∃ h : 0 ≤ x, @Membership.mem ℝ≥0 _ _ ⟨x, h⟩ s } := Subtype.coe_image #align nnreal.coe_image NNReal.coe_image theorem bddAbove_coe {s : Set ℝ≥0} : BddAbove (((↑) : ℝ≥0 → ℝ) '' s) ↔ BddAbove s := Iff.intro (fun ⟨b, hb⟩ => ⟨Real.toNNReal b, fun ⟨y, _⟩ hys => show y ≤ max b 0 from le_max_of_le_left <| hb <| Set.mem_image_of_mem _ hys⟩) fun ⟨b, hb⟩ => ⟨b, fun _ ⟨_, hx, eq⟩ => eq ▸ hb hx⟩ #align nnreal.bdd_above_coe NNReal.bddAbove_coe theorem bddBelow_coe (s : Set ℝ≥0) : BddBelow (((↑) : ℝ≥0 → ℝ) '' s) := ⟨0, fun _ ⟨q, _, eq⟩ => eq ▸ q.2⟩ #align nnreal.bdd_below_coe NNReal.bddBelow_coe noncomputable instance : ConditionallyCompleteLinearOrderBot ℝ≥0 := Nonneg.conditionallyCompleteLinearOrderBot 0 @[norm_cast] theorem coe_sSup (s : Set ℝ≥0) : (↑(sSup s) : ℝ) = sSup (((↑) : ℝ≥0 → ℝ) '' s) := by rcases Set.eq_empty_or_nonempty s with rfl|hs · simp by_cases H : BddAbove s · have A : sSup (Subtype.val '' s) ∈ Set.Ici 0 := by apply Real.sSup_nonneg rintro - ⟨y, -, rfl⟩ exact y.2 exact (@subset_sSup_of_within ℝ (Set.Ici (0 : ℝ)) _ _ (_) s hs H A).symm · simp only [csSup_of_not_bddAbove H, csSup_empty, bot_eq_zero', NNReal.coe_zero] apply (Real.sSup_of_not_bddAbove ?_).symm contrapose! H exact bddAbove_coe.1 H #align nnreal.coe_Sup NNReal.coe_sSup @[simp, norm_cast] -- Porting note: add `simp` theorem coe_iSup {ι : Sort*} (s : ι → ℝ≥0) : (↑(⨆ i, s i) : ℝ) = ⨆ i, ↑(s i) := by rw [iSup, iSup, coe_sSup, ← Set.range_comp]; rfl #align nnreal.coe_supr NNReal.coe_iSup @[norm_cast] theorem coe_sInf (s : Set ℝ≥0) : (↑(sInf s) : ℝ) = sInf (((↑) : ℝ≥0 → ℝ) '' s) := by rcases Set.eq_empty_or_nonempty s with rfl|hs · simp only [Set.image_empty, Real.sInf_empty, coe_eq_zero] exact @subset_sInf_emptyset ℝ (Set.Ici (0 : ℝ)) _ _ (_) have A : sInf (Subtype.val '' s) ∈ Set.Ici 0 := by apply Real.sInf_nonneg rintro - ⟨y, -, rfl⟩ exact y.2 exact (@subset_sInf_of_within ℝ (Set.Ici (0 : ℝ)) _ _ (_) s hs (OrderBot.bddBelow s) A).symm #align nnreal.coe_Inf NNReal.coe_sInf @[simp] theorem sInf_empty : sInf (∅ : Set ℝ≥0) = 0 := by rw [← coe_eq_zero, coe_sInf, Set.image_empty, Real.sInf_empty] #align nnreal.Inf_empty NNReal.sInf_empty @[norm_cast] theorem coe_iInf {ι : Sort*} (s : ι → ℝ≥0) : (↑(⨅ i, s i) : ℝ) = ⨅ i, ↑(s i) := by rw [iInf, iInf, coe_sInf, ← Set.range_comp]; rfl #align nnreal.coe_infi NNReal.coe_iInf theorem le_iInf_add_iInf {ι ι' : Sort*} [Nonempty ι] [Nonempty ι'] {f : ι → ℝ≥0} {g : ι' → ℝ≥0} {a : ℝ≥0} (h : ∀ i j, a ≤ f i + g j) : a ≤ (⨅ i, f i) + ⨅ j, g j := by rw [← NNReal.coe_le_coe, NNReal.coe_add, coe_iInf, coe_iInf] exact le_ciInf_add_ciInf h #align nnreal.le_infi_add_infi NNReal.le_iInf_add_iInf example : Archimedean ℝ≥0 := by infer_instance -- Porting note (#11215): TODO: remove? instance covariant_add : CovariantClass ℝ≥0 ℝ≥0 (· + ·) (· ≤ ·) := inferInstance #align nnreal.covariant_add NNReal.covariant_add instance contravariant_add : ContravariantClass ℝ≥0 ℝ≥0 (· + ·) (· < ·) := inferInstance #align nnreal.contravariant_add NNReal.contravariant_add instance covariant_mul : CovariantClass ℝ≥0 ℝ≥0 (· * ·) (· ≤ ·) := inferInstance #align nnreal.covariant_mul NNReal.covariant_mul -- Porting note (#11215): TODO: delete? nonrec theorem le_of_forall_pos_le_add {a b : ℝ≥0} (h : ∀ ε, 0 < ε → a ≤ b + ε) : a ≤ b := le_of_forall_pos_le_add h #align nnreal.le_of_forall_pos_le_add NNReal.le_of_forall_pos_le_add theorem lt_iff_exists_rat_btwn (a b : ℝ≥0) : a < b ↔ ∃ q : ℚ, 0 ≤ q ∧ a < Real.toNNReal q ∧ Real.toNNReal q < b := Iff.intro (fun h : (↑a : ℝ) < (↑b : ℝ) => let ⟨q, haq, hqb⟩ := exists_rat_btwn h have : 0 ≤ (q : ℝ) := le_trans a.2 <| le_of_lt haq ⟨q, Rat.cast_nonneg.1 this, by simp [Real.coe_toNNReal _ this, NNReal.coe_lt_coe.symm, haq, hqb]⟩) fun ⟨q, _, haq, hqb⟩ => lt_trans haq hqb #align nnreal.lt_iff_exists_rat_btwn NNReal.lt_iff_exists_rat_btwn theorem bot_eq_zero : (⊥ : ℝ≥0) = 0 := rfl #align nnreal.bot_eq_zero NNReal.bot_eq_zero theorem mul_sup (a b c : ℝ≥0) : a * (b ⊔ c) = a * b ⊔ a * c := mul_max_of_nonneg _ _ <| zero_le a #align nnreal.mul_sup NNReal.mul_sup theorem sup_mul (a b c : ℝ≥0) : (a ⊔ b) * c = a * c ⊔ b * c := max_mul_of_nonneg _ _ <| zero_le c #align nnreal.sup_mul NNReal.sup_mul theorem mul_finset_sup {α} (r : ℝ≥0) (s : Finset α) (f : α → ℝ≥0) : r * s.sup f = s.sup fun a => r * f a := Finset.comp_sup_eq_sup_comp _ (NNReal.mul_sup r) (mul_zero r) #align nnreal.mul_finset_sup NNReal.mul_finset_sup theorem finset_sup_mul {α} (s : Finset α) (f : α → ℝ≥0) (r : ℝ≥0) : s.sup f * r = s.sup fun a => f a * r := Finset.comp_sup_eq_sup_comp (· * r) (fun x y => NNReal.sup_mul x y r) (zero_mul r) #align nnreal.finset_sup_mul NNReal.finset_sup_mul theorem finset_sup_div {α} {f : α → ℝ≥0} {s : Finset α} (r : ℝ≥0) : s.sup f / r = s.sup fun a => f a / r := by simp only [div_eq_inv_mul, mul_finset_sup] #align nnreal.finset_sup_div NNReal.finset_sup_div @[simp, norm_cast] theorem coe_max (x y : ℝ≥0) : ((max x y : ℝ≥0) : ℝ) = max (x : ℝ) (y : ℝ) := NNReal.coe_mono.map_max #align nnreal.coe_max NNReal.coe_max @[simp, norm_cast] theorem coe_min (x y : ℝ≥0) : ((min x y : ℝ≥0) : ℝ) = min (x : ℝ) (y : ℝ) := NNReal.coe_mono.map_min #align nnreal.coe_min NNReal.coe_min @[simp] theorem zero_le_coe {q : ℝ≥0} : 0 ≤ (q : ℝ) := q.2 #align nnreal.zero_le_coe NNReal.zero_le_coe instance instOrderedSMul {M : Type*} [OrderedAddCommMonoid M] [Module ℝ M] [OrderedSMul ℝ M] : OrderedSMul ℝ≥0 M where smul_lt_smul_of_pos hab hc := (smul_lt_smul_of_pos_left hab (NNReal.coe_pos.2 hc) : _) lt_of_smul_lt_smul_of_pos {a b c} hab _ := lt_of_smul_lt_smul_of_nonneg_left (by exact hab) (NNReal.coe_nonneg c) end NNReal open NNReal namespace Real section ToNNReal @[simp] theorem coe_toNNReal' (r : ℝ) : (Real.toNNReal r : ℝ) = max r 0 := rfl #align real.coe_to_nnreal' Real.coe_toNNReal' @[simp] theorem toNNReal_zero : Real.toNNReal 0 = 0 := NNReal.eq <| coe_toNNReal _ le_rfl #align real.to_nnreal_zero Real.toNNReal_zero @[simp] theorem toNNReal_one : Real.toNNReal 1 = 1 := NNReal.eq <| coe_toNNReal _ zero_le_one #align real.to_nnreal_one Real.toNNReal_one @[simp] theorem toNNReal_pos {r : ℝ} : 0 < Real.toNNReal r ↔ 0 < r := by simp [← NNReal.coe_lt_coe, lt_irrefl] #align real.to_nnreal_pos Real.toNNReal_pos @[simp] theorem toNNReal_eq_zero {r : ℝ} : Real.toNNReal r = 0 ↔ r ≤ 0 := by simpa [-toNNReal_pos] using not_iff_not.2 (@toNNReal_pos r) #align real.to_nnreal_eq_zero Real.toNNReal_eq_zero theorem toNNReal_of_nonpos {r : ℝ} : r ≤ 0 → Real.toNNReal r = 0 := toNNReal_eq_zero.2 #align real.to_nnreal_of_nonpos Real.toNNReal_of_nonpos lemma toNNReal_eq_iff_eq_coe {r : ℝ} {p : ℝ≥0} (hp : p ≠ 0) : r.toNNReal = p ↔ r = p := ⟨fun h ↦ h ▸ (coe_toNNReal _ <| not_lt.1 fun hlt ↦ hp <| h ▸ toNNReal_of_nonpos hlt.le).symm, fun h ↦ h.symm ▸ toNNReal_coe⟩ @[simp] lemma toNNReal_eq_one {r : ℝ} : r.toNNReal = 1 ↔ r = 1 := toNNReal_eq_iff_eq_coe one_ne_zero @[simp] lemma toNNReal_eq_natCast {r : ℝ} {n : ℕ} (hn : n ≠ 0) : r.toNNReal = n ↔ r = n := mod_cast toNNReal_eq_iff_eq_coe <| Nat.cast_ne_zero.2 hn @[deprecated (since := "2024-04-17")] alias toNNReal_eq_nat_cast := toNNReal_eq_natCast @[simp] lemma toNNReal_eq_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : r.toNNReal = no_index (OfNat.ofNat n) ↔ r = OfNat.ofNat n := toNNReal_eq_natCast (NeZero.ne n) @[simp] theorem toNNReal_le_toNNReal_iff {r p : ℝ} (hp : 0 ≤ p) : toNNReal r ≤ toNNReal p ↔ r ≤ p := by simp [← NNReal.coe_le_coe, hp] #align real.to_nnreal_le_to_nnreal_iff Real.toNNReal_le_toNNReal_iff @[simp] lemma toNNReal_le_one {r : ℝ} : r.toNNReal ≤ 1 ↔ r ≤ 1 := by simpa using toNNReal_le_toNNReal_iff zero_le_one @[simp] lemma one_lt_toNNReal {r : ℝ} : 1 < r.toNNReal ↔ 1 < r := by simpa only [not_le] using toNNReal_le_one.not @[simp] lemma toNNReal_le_natCast {r : ℝ} {n : ℕ} : r.toNNReal ≤ n ↔ r ≤ n := by simpa using toNNReal_le_toNNReal_iff n.cast_nonneg @[deprecated (since := "2024-04-17")] alias toNNReal_le_nat_cast := toNNReal_le_natCast @[simp] lemma natCast_lt_toNNReal {r : ℝ} {n : ℕ} : n < r.toNNReal ↔ n < r := by simpa only [not_le] using toNNReal_le_natCast.not @[deprecated (since := "2024-04-17")] alias nat_cast_lt_toNNReal := natCast_lt_toNNReal @[simp] lemma toNNReal_le_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : r.toNNReal ≤ no_index (OfNat.ofNat n) ↔ r ≤ n := toNNReal_le_natCast @[simp] lemma ofNat_lt_toNNReal {r : ℝ} {n : ℕ} [n.AtLeastTwo] : no_index (OfNat.ofNat n) < r.toNNReal ↔ n < r := natCast_lt_toNNReal @[simp] theorem toNNReal_eq_toNNReal_iff {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) : toNNReal r = toNNReal p ↔ r = p := by simp [← coe_inj, coe_toNNReal, hr, hp] #align real.to_nnreal_eq_to_nnreal_iff Real.toNNReal_eq_toNNReal_iff @[simp] theorem toNNReal_lt_toNNReal_iff' {r p : ℝ} : Real.toNNReal r < Real.toNNReal p ↔ r < p ∧ 0 < p := NNReal.coe_lt_coe.symm.trans max_lt_max_left_iff #align real.to_nnreal_lt_to_nnreal_iff' Real.toNNReal_lt_toNNReal_iff' theorem toNNReal_lt_toNNReal_iff {r p : ℝ} (h : 0 < p) : Real.toNNReal r < Real.toNNReal p ↔ r < p := toNNReal_lt_toNNReal_iff'.trans (and_iff_left h) #align real.to_nnreal_lt_to_nnreal_iff Real.toNNReal_lt_toNNReal_iff theorem lt_of_toNNReal_lt {r p : ℝ} (h : r.toNNReal < p.toNNReal) : r < p := (Real.toNNReal_lt_toNNReal_iff <| Real.toNNReal_pos.1 (ne_bot_of_gt h).bot_lt).1 h theorem toNNReal_lt_toNNReal_iff_of_nonneg {r p : ℝ} (hr : 0 ≤ r) : Real.toNNReal r < Real.toNNReal p ↔ r < p := toNNReal_lt_toNNReal_iff'.trans ⟨And.left, fun h => ⟨h, lt_of_le_of_lt hr h⟩⟩ #align real.to_nnreal_lt_to_nnreal_iff_of_nonneg Real.toNNReal_lt_toNNReal_iff_of_nonneg lemma toNNReal_le_toNNReal_iff' {r p : ℝ} : r.toNNReal ≤ p.toNNReal ↔ r ≤ p ∨ r ≤ 0 := by simp_rw [← not_lt, toNNReal_lt_toNNReal_iff', not_and_or] lemma toNNReal_le_toNNReal_iff_of_pos {r p : ℝ} (hr : 0 < r) : r.toNNReal ≤ p.toNNReal ↔ r ≤ p := by simp [toNNReal_le_toNNReal_iff', hr.not_le] @[simp] lemma one_le_toNNReal {r : ℝ} : 1 ≤ r.toNNReal ↔ 1 ≤ r := by simpa using toNNReal_le_toNNReal_iff_of_pos one_pos @[simp] lemma toNNReal_lt_one {r : ℝ} : r.toNNReal < 1 ↔ r < 1 := by simp only [← not_le, one_le_toNNReal] @[simp] lemma natCastle_toNNReal' {n : ℕ} {r : ℝ} : ↑n ≤ r.toNNReal ↔ n ≤ r ∨ n = 0 := by simpa [n.cast_nonneg.le_iff_eq] using toNNReal_le_toNNReal_iff' (r := n) @[deprecated (since := "2024-04-17")] alias nat_cast_le_toNNReal' := natCastle_toNNReal' @[simp] lemma toNNReal_lt_natCast' {n : ℕ} {r : ℝ} : r.toNNReal < n ↔ r < n ∧ n ≠ 0 := by simpa [pos_iff_ne_zero] using toNNReal_lt_toNNReal_iff' (r := r) (p := n) @[deprecated (since := "2024-04-17")] alias toNNReal_lt_nat_cast' := toNNReal_lt_natCast' lemma natCast_le_toNNReal {n : ℕ} {r : ℝ} (hn : n ≠ 0) : ↑n ≤ r.toNNReal ↔ n ≤ r := by simp [hn] @[deprecated (since := "2024-04-17")] alias nat_cast_le_toNNReal := natCast_le_toNNReal lemma toNNReal_lt_natCast {r : ℝ} {n : ℕ} (hn : n ≠ 0) : r.toNNReal < n ↔ r < n := by simp [hn] @[deprecated (since := "2024-04-17")] alias toNNReal_lt_nat_cast := toNNReal_lt_natCast @[simp] lemma toNNReal_lt_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : r.toNNReal < no_index (OfNat.ofNat n) ↔ r < OfNat.ofNat n := toNNReal_lt_natCast (NeZero.ne n) @[simp] lemma ofNat_le_toNNReal {n : ℕ} {r : ℝ} [n.AtLeastTwo] : no_index (OfNat.ofNat n) ≤ r.toNNReal ↔ OfNat.ofNat n ≤ r := natCast_le_toNNReal (NeZero.ne n) @[simp] theorem toNNReal_add {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) : Real.toNNReal (r + p) = Real.toNNReal r + Real.toNNReal p := NNReal.eq <| by simp [hr, hp, add_nonneg] #align real.to_nnreal_add Real.toNNReal_add theorem toNNReal_add_toNNReal {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) : Real.toNNReal r + Real.toNNReal p = Real.toNNReal (r + p) := (Real.toNNReal_add hr hp).symm #align real.to_nnreal_add_to_nnreal Real.toNNReal_add_toNNReal theorem toNNReal_le_toNNReal {r p : ℝ} (h : r ≤ p) : Real.toNNReal r ≤ Real.toNNReal p := Real.toNNReal_mono h #align real.to_nnreal_le_to_nnreal Real.toNNReal_le_toNNReal theorem toNNReal_add_le {r p : ℝ} : Real.toNNReal (r + p) ≤ Real.toNNReal r + Real.toNNReal p := NNReal.coe_le_coe.1 <| max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) NNReal.zero_le_coe #align real.to_nnreal_add_le Real.toNNReal_add_le theorem toNNReal_le_iff_le_coe {r : ℝ} {p : ℝ≥0} : toNNReal r ≤ p ↔ r ≤ ↑p := NNReal.gi.gc r p #align real.to_nnreal_le_iff_le_coe Real.toNNReal_le_iff_le_coe theorem le_toNNReal_iff_coe_le {r : ℝ≥0} {p : ℝ} (hp : 0 ≤ p) : r ≤ Real.toNNReal p ↔ ↑r ≤ p := by rw [← NNReal.coe_le_coe, Real.coe_toNNReal p hp] #align real.le_to_nnreal_iff_coe_le Real.le_toNNReal_iff_coe_le theorem le_toNNReal_iff_coe_le' {r : ℝ≥0} {p : ℝ} (hr : 0 < r) : r ≤ Real.toNNReal p ↔ ↑r ≤ p := (le_or_lt 0 p).elim le_toNNReal_iff_coe_le fun hp => by simp only [(hp.trans_le r.coe_nonneg).not_le, toNNReal_eq_zero.2 hp.le, hr.not_le] #align real.le_to_nnreal_iff_coe_le' Real.le_toNNReal_iff_coe_le' theorem toNNReal_lt_iff_lt_coe {r : ℝ} {p : ℝ≥0} (ha : 0 ≤ r) : Real.toNNReal r < p ↔ r < ↑p := by rw [← NNReal.coe_lt_coe, Real.coe_toNNReal r ha] #align real.to_nnreal_lt_iff_lt_coe Real.toNNReal_lt_iff_lt_coe theorem lt_toNNReal_iff_coe_lt {r : ℝ≥0} {p : ℝ} : r < Real.toNNReal p ↔ ↑r < p := lt_iff_lt_of_le_iff_le toNNReal_le_iff_le_coe #align real.lt_to_nnreal_iff_coe_lt Real.lt_toNNReal_iff_coe_lt #noalign real.to_nnreal_bit0 #noalign real.to_nnreal_bit1 theorem toNNReal_pow {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : (x ^ n).toNNReal = x.toNNReal ^ n := by rw [← coe_inj, NNReal.coe_pow, Real.coe_toNNReal _ (pow_nonneg hx _), Real.coe_toNNReal x hx] #align real.to_nnreal_pow Real.toNNReal_pow theorem toNNReal_mul {p q : ℝ} (hp : 0 ≤ p) : Real.toNNReal (p * q) = Real.toNNReal p * Real.toNNReal q := NNReal.eq <| by simp [mul_max_of_nonneg, hp] #align real.to_nnreal_mul Real.toNNReal_mul end ToNNReal end Real open Real namespace NNReal section Mul theorem mul_eq_mul_left {a b c : ℝ≥0} (h : a ≠ 0) : a * b = a * c ↔ b = c := by rw [mul_eq_mul_left_iff, or_iff_left h] #align nnreal.mul_eq_mul_left NNReal.mul_eq_mul_left end Mul section Pow theorem pow_antitone_exp {a : ℝ≥0} (m n : ℕ) (mn : m ≤ n) (a1 : a ≤ 1) : a ^ n ≤ a ^ m := pow_le_pow_of_le_one (zero_le a) a1 mn #align nnreal.pow_antitone_exp NNReal.pow_antitone_exp nonrec theorem exists_pow_lt_of_lt_one {a b : ℝ≥0} (ha : 0 < a) (hb : b < 1) : ∃ n : ℕ, b ^ n < a := by simpa only [← coe_pow, NNReal.coe_lt_coe] using exists_pow_lt_of_lt_one (NNReal.coe_pos.2 ha) (NNReal.coe_lt_coe.2 hb) #align nnreal.exists_pow_lt_of_lt_one NNReal.exists_pow_lt_of_lt_one nonrec theorem exists_mem_Ico_zpow {x : ℝ≥0} {y : ℝ≥0} (hx : x ≠ 0) (hy : 1 < y) : ∃ n : ℤ, x ∈ Set.Ico (y ^ n) (y ^ (n + 1)) := exists_mem_Ico_zpow (α := ℝ) hx.bot_lt hy #align nnreal.exists_mem_Ico_zpow NNReal.exists_mem_Ico_zpow nonrec theorem exists_mem_Ioc_zpow {x : ℝ≥0} {y : ℝ≥0} (hx : x ≠ 0) (hy : 1 < y) : ∃ n : ℤ, x ∈ Set.Ioc (y ^ n) (y ^ (n + 1)) := exists_mem_Ioc_zpow (α := ℝ) hx.bot_lt hy #align nnreal.exists_mem_Ioc_zpow NNReal.exists_mem_Ioc_zpow end Pow section Sub /-! ### Lemmas about subtraction In this section we provide a few lemmas about subtraction that do not fit well into any other typeclass. For lemmas about subtraction and addition see lemmas about `OrderedSub` in the file `Mathlib.Algebra.Order.Sub.Basic`. See also `mul_tsub` and `tsub_mul`. -/ theorem sub_def {r p : ℝ≥0} : r - p = Real.toNNReal (r - p) := rfl #align nnreal.sub_def NNReal.sub_def theorem coe_sub_def {r p : ℝ≥0} : ↑(r - p) = max (r - p : ℝ) 0 := rfl #align nnreal.coe_sub_def NNReal.coe_sub_def example : OrderedSub ℝ≥0 := by infer_instance theorem sub_div (a b c : ℝ≥0) : (a - b) / c = a / c - b / c := tsub_div _ _ _ #align nnreal.sub_div NNReal.sub_div end Sub section Inv #align nnreal.sum_div Finset.sum_div @[simp] theorem inv_le {r p : ℝ≥0} (h : r ≠ 0) : r⁻¹ ≤ p ↔ 1 ≤ r * p := by rw [← mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h] #align nnreal.inv_le NNReal.inv_le theorem inv_le_of_le_mul {r p : ℝ≥0} (h : 1 ≤ r * p) : r⁻¹ ≤ p := by by_cases r = 0 <;> simp [*, inv_le] #align nnreal.inv_le_of_le_mul NNReal.inv_le_of_le_mul @[simp] theorem le_inv_iff_mul_le {r p : ℝ≥0} (h : p ≠ 0) : r ≤ p⁻¹ ↔ r * p ≤ 1 := by rw [← mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm] #align nnreal.le_inv_iff_mul_le NNReal.le_inv_iff_mul_le @[simp] theorem lt_inv_iff_mul_lt {r p : ℝ≥0} (h : p ≠ 0) : r < p⁻¹ ↔ r * p < 1 := by rw [← mul_lt_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm] #align nnreal.lt_inv_iff_mul_lt NNReal.lt_inv_iff_mul_lt theorem mul_le_iff_le_inv {a b r : ℝ≥0} (hr : r ≠ 0) : r * a ≤ b ↔ a ≤ r⁻¹ * b := by have : 0 < r := lt_of_le_of_ne (zero_le r) hr.symm rw [← mul_le_mul_left (inv_pos.mpr this), ← mul_assoc, inv_mul_cancel hr, one_mul] #align nnreal.mul_le_iff_le_inv NNReal.mul_le_iff_le_inv theorem le_div_iff_mul_le {a b r : ℝ≥0} (hr : r ≠ 0) : a ≤ b / r ↔ a * r ≤ b := le_div_iff₀ hr #align nnreal.le_div_iff_mul_le NNReal.le_div_iff_mul_le theorem div_le_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a / r ≤ b ↔ a ≤ b * r := div_le_iff₀ hr #align nnreal.div_le_iff NNReal.div_le_iff nonrec theorem div_le_iff' {a b r : ℝ≥0} (hr : r ≠ 0) : a / r ≤ b ↔ a ≤ r * b := @div_le_iff' ℝ _ a r b <| pos_iff_ne_zero.2 hr #align nnreal.div_le_iff' NNReal.div_le_iff' theorem div_le_of_le_mul {a b c : ℝ≥0} (h : a ≤ b * c) : a / c ≤ b := if h0 : c = 0 then by simp [h0] else (div_le_iff h0).2 h #align nnreal.div_le_of_le_mul NNReal.div_le_of_le_mul theorem div_le_of_le_mul' {a b c : ℝ≥0} (h : a ≤ b * c) : a / b ≤ c := div_le_of_le_mul <| mul_comm b c ▸ h #align nnreal.div_le_of_le_mul' NNReal.div_le_of_le_mul' nonrec theorem le_div_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a ≤ b / r ↔ a * r ≤ b := @le_div_iff ℝ _ a b r <| pos_iff_ne_zero.2 hr #align nnreal.le_div_iff NNReal.le_div_iff nonrec theorem le_div_iff' {a b r : ℝ≥0} (hr : r ≠ 0) : a ≤ b / r ↔ r * a ≤ b := @le_div_iff' ℝ _ a b r <| pos_iff_ne_zero.2 hr #align nnreal.le_div_iff' NNReal.le_div_iff' theorem div_lt_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a / r < b ↔ a < b * r := lt_iff_lt_of_le_iff_le (le_div_iff hr) #align nnreal.div_lt_iff NNReal.div_lt_iff theorem div_lt_iff' {a b r : ℝ≥0} (hr : r ≠ 0) : a / r < b ↔ a < r * b := lt_iff_lt_of_le_iff_le (le_div_iff' hr) #align nnreal.div_lt_iff' NNReal.div_lt_iff' theorem lt_div_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a < b / r ↔ a * r < b := lt_iff_lt_of_le_iff_le (div_le_iff hr) #align nnreal.lt_div_iff NNReal.lt_div_iff theorem lt_div_iff' {a b r : ℝ≥0} (hr : r ≠ 0) : a < b / r ↔ r * a < b := lt_iff_lt_of_le_iff_le (div_le_iff' hr) #align nnreal.lt_div_iff' NNReal.lt_div_iff' theorem mul_lt_of_lt_div {a b r : ℝ≥0} (h : a < b / r) : a * r < b := (lt_div_iff fun hr => False.elim <| by simp [hr] at h).1 h #align nnreal.mul_lt_of_lt_div NNReal.mul_lt_of_lt_div theorem div_le_div_left_of_le {a b c : ℝ≥0} (c0 : c ≠ 0) (cb : c ≤ b) : a / b ≤ a / c := div_le_div_of_nonneg_left (zero_le _) c0.bot_lt cb #align nnreal.div_le_div_left_of_le NNReal.div_le_div_left_of_leₓ nonrec theorem div_le_div_left {a b c : ℝ≥0} (a0 : 0 < a) (b0 : 0 < b) (c0 : 0 < c) : a / b ≤ a / c ↔ c ≤ b := div_le_div_left a0 b0 c0 #align nnreal.div_le_div_left NNReal.div_le_div_left theorem le_of_forall_lt_one_mul_le {x y : ℝ≥0} (h : ∀ a < 1, a * x ≤ y) : x ≤ y := le_of_forall_ge_of_dense fun a ha => by have hx : x ≠ 0 := pos_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha) have hx' : x⁻¹ ≠ 0 := by rwa [Ne, inv_eq_zero] have : a * x⁻¹ < 1 := by rwa [← lt_inv_iff_mul_lt hx', inv_inv] have : a * x⁻¹ * x ≤ y := h _ this rwa [mul_assoc, inv_mul_cancel hx, mul_one] at this #align nnreal.le_of_forall_lt_one_mul_le NNReal.le_of_forall_lt_one_mul_le nonrec theorem half_le_self (a : ℝ≥0) : a / 2 ≤ a := half_le_self bot_le #align nnreal.half_le_self NNReal.half_le_self nonrec theorem half_lt_self {a : ℝ≥0} (h : a ≠ 0) : a / 2 < a := half_lt_self h.bot_lt #align nnreal.half_lt_self NNReal.half_lt_self theorem div_lt_one_of_lt {a b : ℝ≥0} (h : a < b) : a / b < 1 := by rwa [div_lt_iff, one_mul] exact ne_of_gt (lt_of_le_of_lt (zero_le _) h) #align nnreal.div_lt_one_of_lt NNReal.div_lt_one_of_lt theorem _root_.Real.toNNReal_inv {x : ℝ} : Real.toNNReal x⁻¹ = (Real.toNNReal x)⁻¹ := by rcases le_total 0 x with hx | hx · nth_rw 1 [← Real.coe_toNNReal x hx] rw [← NNReal.coe_inv, Real.toNNReal_coe] · rw [toNNReal_eq_zero.mpr hx, inv_zero, toNNReal_eq_zero.mpr (inv_nonpos.mpr hx)] #align real.to_nnreal_inv Real.toNNReal_inv theorem _root_.Real.toNNReal_div {x y : ℝ} (hx : 0 ≤ x) : Real.toNNReal (x / y) = Real.toNNReal x / Real.toNNReal y := by rw [div_eq_mul_inv, div_eq_mul_inv, ← Real.toNNReal_inv, ← Real.toNNReal_mul hx] #align real.to_nnreal_div Real.toNNReal_div theorem _root_.Real.toNNReal_div' {x y : ℝ} (hy : 0 ≤ y) : Real.toNNReal (x / y) = Real.toNNReal x / Real.toNNReal y := by rw [div_eq_inv_mul, div_eq_inv_mul, Real.toNNReal_mul (inv_nonneg.2 hy), Real.toNNReal_inv] #align real.to_nnreal_div' Real.toNNReal_div' theorem inv_lt_one_iff {x : ℝ≥0} (hx : x ≠ 0) : x⁻¹ < 1 ↔ 1 < x := by rw [← one_div, div_lt_iff hx, one_mul] #align nnreal.inv_lt_one_iff NNReal.inv_lt_one_iff theorem zpow_pos {x : ℝ≥0} (hx : x ≠ 0) (n : ℤ) : 0 < x ^ n := zpow_pos_of_pos hx.bot_lt _ #align nnreal.zpow_pos NNReal.zpow_pos theorem inv_lt_inv {x y : ℝ≥0} (hx : x ≠ 0) (h : x < y) : y⁻¹ < x⁻¹ := inv_lt_inv_of_lt hx.bot_lt h #align nnreal.inv_lt_inv NNReal.inv_lt_inv end Inv @[simp] theorem abs_eq (x : ℝ≥0) : |(x : ℝ)| = x := abs_of_nonneg x.property #align nnreal.abs_eq NNReal.abs_eq section Csupr open Set variable {ι : Sort*} {f : ι → ℝ≥0} theorem le_toNNReal_of_coe_le {x : ℝ≥0} {y : ℝ} (h : ↑x ≤ y) : x ≤ y.toNNReal := (le_toNNReal_iff_coe_le <| x.2.trans h).2 h #align nnreal.le_to_nnreal_of_coe_le NNReal.le_toNNReal_of_coe_le nonrec theorem sSup_of_not_bddAbove {s : Set ℝ≥0} (hs : ¬BddAbove s) : SupSet.sSup s = 0 := by rw [← bddAbove_coe] at hs rw [← coe_inj, coe_sSup, NNReal.coe_zero] exact sSup_of_not_bddAbove hs #align nnreal.Sup_of_not_bdd_above NNReal.sSup_of_not_bddAbove theorem iSup_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = 0 := sSup_of_not_bddAbove hf #align nnreal.supr_of_not_bdd_above NNReal.iSup_of_not_bddAbove theorem iSup_empty [IsEmpty ι] (f : ι → ℝ≥0) : ⨆ i, f i = 0 := ciSup_of_empty f theorem iInf_empty [IsEmpty ι] (f : ι → ℝ≥0) : ⨅ i, f i = 0 := by rw [_root_.iInf_of_isEmpty, sInf_empty] #align nnreal.infi_empty NNReal.iInf_empty @[simp] theorem iInf_const_zero {α : Sort*} : ⨅ _ : α, (0 : ℝ≥0) = 0 := by rw [← coe_inj, coe_iInf] exact Real.ciInf_const_zero #align nnreal.infi_const_zero NNReal.iInf_const_zero theorem iInf_mul (f : ι → ℝ≥0) (a : ℝ≥0) : iInf f * a = ⨅ i, f i * a := by rw [← coe_inj, NNReal.coe_mul, coe_iInf, coe_iInf] exact Real.iInf_mul_of_nonneg (NNReal.coe_nonneg _) _ #align nnreal.infi_mul NNReal.iInf_mul theorem mul_iInf (f : ι → ℝ≥0) (a : ℝ≥0) : a * iInf f = ⨅ i, a * f i := by simpa only [mul_comm] using iInf_mul f a #align nnreal.mul_infi NNReal.mul_iInf theorem mul_iSup (f : ι → ℝ≥0) (a : ℝ≥0) : (a * ⨆ i, f i) = ⨆ i, a * f i := by rw [← coe_inj, NNReal.coe_mul, NNReal.coe_iSup, NNReal.coe_iSup] exact Real.mul_iSup_of_nonneg (NNReal.coe_nonneg _) _ #align nnreal.mul_supr NNReal.mul_iSup theorem iSup_mul (f : ι → ℝ≥0) (a : ℝ≥0) : (⨆ i, f i) * a = ⨆ i, f i * a := by rw [mul_comm, mul_iSup] simp_rw [mul_comm] #align nnreal.supr_mul NNReal.iSup_mul theorem iSup_div (f : ι → ℝ≥0) (a : ℝ≥0) : (⨆ i, f i) / a = ⨆ i, f i / a := by simp only [div_eq_mul_inv, iSup_mul] #align nnreal.supr_div NNReal.iSup_div -- Porting note: generalized to allow empty `ι` theorem mul_iSup_le {a : ℝ≥0} {g : ℝ≥0} {h : ι → ℝ≥0} (H : ∀ j, g * h j ≤ a) : g * iSup h ≤ a := by rw [mul_iSup] exact ciSup_le' H #align nnreal.mul_supr_le NNReal.mul_iSup_le -- Porting note: generalized to allow empty `ι` theorem iSup_mul_le {a : ℝ≥0} {g : ι → ℝ≥0} {h : ℝ≥0} (H : ∀ i, g i * h ≤ a) : iSup g * h ≤ a := by rw [iSup_mul] exact ciSup_le' H #align nnreal.supr_mul_le NNReal.iSup_mul_le -- Porting note: generalized to allow empty `ι` theorem iSup_mul_iSup_le {a : ℝ≥0} {g h : ι → ℝ≥0} (H : ∀ i j, g i * h j ≤ a) : iSup g * iSup h ≤ a := iSup_mul_le fun _ => mul_iSup_le <| H _ #align nnreal.supr_mul_supr_le NNReal.iSup_mul_iSup_le variable [Nonempty ι] theorem le_mul_iInf {a : ℝ≥0} {g : ℝ≥0} {h : ι → ℝ≥0} (H : ∀ j, a ≤ g * h j) : a ≤ g * iInf h := by rw [mul_iInf] exact le_ciInf H #align nnreal.le_mul_infi NNReal.le_mul_iInf
Mathlib/Data/Real/NNReal.lean
1,138
1,140
theorem le_iInf_mul {a : ℝ≥0} {g : ι → ℝ≥0} {h : ℝ≥0} (H : ∀ i, a ≤ g i * h) : a ≤ iInf g * h := by
rw [iInf_mul] exact le_ciInf H
/- 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. -/
Mathlib/Analysis/Calculus/FDeriv/Measurable.lean
742
746
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
/- Copyright (c) 2020 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Yury Kudryashov -/ import Mathlib.Topology.UniformSpace.UniformConvergence import Mathlib.Topology.UniformSpace.Equicontinuity import Mathlib.Topology.Separation import Mathlib.Topology.Support #align_import topology.uniform_space.compact from "leanprover-community/mathlib"@"735b22f8f9ff9792cf4212d7cb051c4c994bc685" /-! # Compact separated uniform spaces ## Main statements * `compactSpace_uniformity`: On a compact uniform space, the topology determines the uniform structure, entourages are exactly the neighborhoods of the diagonal. * `uniformSpace_of_compact_t2`: every compact T2 topological structure is induced by a uniform structure. This uniform structure is described in the previous item. * **Heine-Cantor** theorem: continuous functions on compact uniform spaces with values in uniform spaces are automatically uniformly continuous. There are several variations, the main one is `CompactSpace.uniformContinuous_of_continuous`. ## Implementation notes The construction `uniformSpace_of_compact_t2` is not declared as an instance, as it would badly loop. ## Tags uniform space, uniform continuity, compact space -/ open scoped Classical open Uniformity Topology Filter UniformSpace Set variable {α β γ : Type*} [UniformSpace α] [UniformSpace β] /-! ### Uniformity on compact spaces -/ /-- On a compact uniform space, the topology determines the uniform structure, entourages are exactly the neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_eq_uniformity [CompactSpace α] : 𝓝ˢ (diagonal α) = 𝓤 α := by refine nhdsSet_diagonal_le_uniformity.antisymm ?_ have : (𝓤 (α × α)).HasBasis (fun U => U ∈ 𝓤 α) fun U => (fun p : (α × α) × α × α => ((p.1.1, p.2.1), p.1.2, p.2.2)) ⁻¹' U ×ˢ U := by rw [uniformity_prod_eq_comap_prod] exact (𝓤 α).basis_sets.prod_self.comap _ refine (isCompact_diagonal.nhdsSet_basis_uniformity this).ge_iff.2 fun U hU => ?_ exact mem_of_superset hU fun ⟨x, y⟩ hxy => mem_iUnion₂.2 ⟨(x, x), rfl, refl_mem_uniformity hU, hxy⟩ #align nhds_set_diagonal_eq_uniformity nhdsSet_diagonal_eq_uniformity /-- On a compact uniform space, the topology determines the uniform structure, entourages are exactly the neighborhoods of the diagonal. -/ theorem compactSpace_uniformity [CompactSpace α] : 𝓤 α = ⨆ x, 𝓝 (x, x) := nhdsSet_diagonal_eq_uniformity.symm.trans (nhdsSet_diagonal _) #align compact_space_uniformity compactSpace_uniformity theorem unique_uniformity_of_compact [t : TopologicalSpace γ] [CompactSpace γ] {u u' : UniformSpace γ} (h : u.toTopologicalSpace = t) (h' : u'.toTopologicalSpace = t) : u = u' := by refine UniformSpace.ext ?_ have : @CompactSpace γ u.toTopologicalSpace := by rwa [h] have : @CompactSpace γ u'.toTopologicalSpace := by rwa [h'] rw [@compactSpace_uniformity _ u, compactSpace_uniformity, h, h'] #align unique_uniformity_of_compact unique_uniformity_of_compact /-- The unique uniform structure inducing a given compact topological structure. -/ def uniformSpaceOfCompactT2 [TopologicalSpace γ] [CompactSpace γ] [T2Space γ] : UniformSpace γ where uniformity := 𝓝ˢ (diagonal γ) symm := continuous_swap.tendsto_nhdsSet fun x => Eq.symm comp := by /- This is the difficult part of the proof. We need to prove that, for each neighborhood `W` of the diagonal `Δ`, there exists a smaller neighborhood `V` such that `V ○ V ⊆ W`. -/ set 𝓝Δ := 𝓝ˢ (diagonal γ) -- The filter of neighborhoods of Δ set F := 𝓝Δ.lift' fun s : Set (γ × γ) => s ○ s -- Compositions of neighborhoods of Δ -- If this weren't true, then there would be V ∈ 𝓝Δ such that F ⊓ 𝓟 Vᶜ ≠ ⊥ rw [le_iff_forall_inf_principal_compl] intro V V_in by_contra H haveI : NeBot (F ⊓ 𝓟 Vᶜ) := ⟨H⟩ -- Hence compactness would give us a cluster point (x, y) for F ⊓ 𝓟 Vᶜ obtain ⟨⟨x, y⟩, hxy⟩ : ∃ p : γ × γ, ClusterPt p (F ⊓ 𝓟 Vᶜ) := exists_clusterPt_of_compactSpace _ -- In particular (x, y) is a cluster point of 𝓟 Vᶜ, hence is not in the interior of V, -- and a fortiori not in Δ, so x ≠ y have clV : ClusterPt (x, y) (𝓟 <| Vᶜ) := hxy.of_inf_right have : (x, y) ∉ interior V := by have : (x, y) ∈ closure Vᶜ := by rwa [mem_closure_iff_clusterPt] rwa [closure_compl] at this have diag_subset : diagonal γ ⊆ interior V := subset_interior_iff_mem_nhdsSet.2 V_in have x_ne_y : x ≠ y := mt (@diag_subset (x, y)) this -- Since γ is compact and Hausdorff, it is T₄, hence T₃. -- So there are closed neighborhoods V₁ and V₂ of x and y contained in -- disjoint open neighborhoods U₁ and U₂. obtain ⟨U₁, _, V₁, V₁_in, U₂, _, V₂, V₂_in, V₁_cl, V₂_cl, U₁_op, U₂_op, VU₁, VU₂, hU₁₂⟩ := disjoint_nested_nhds x_ne_y -- We set U₃ := (V₁ ∪ V₂)ᶜ so that W := U₁ ×ˢ U₁ ∪ U₂ ×ˢ U₂ ∪ U₃ ×ˢ U₃ is an open -- neighborhood of Δ. let U₃ := (V₁ ∪ V₂)ᶜ have U₃_op : IsOpen U₃ := (V₁_cl.union V₂_cl).isOpen_compl let W := U₁ ×ˢ U₁ ∪ U₂ ×ˢ U₂ ∪ U₃ ×ˢ U₃ have W_in : W ∈ 𝓝Δ := by rw [mem_nhdsSet_iff_forall] rintro ⟨z, z'⟩ (rfl : z = z') refine IsOpen.mem_nhds ?_ ?_ · apply_rules [IsOpen.union, IsOpen.prod] · simp only [W, mem_union, mem_prod, and_self_iff] exact (_root_.em _).imp_left fun h => union_subset_union VU₁ VU₂ h -- So W ○ W ∈ F by definition of F have : W ○ W ∈ F := @mem_lift' _ _ _ (fun s => s ○ s) _ W_in -- Porting note: was `by simpa only using mem_lift' W_in` -- And V₁ ×ˢ V₂ ∈ 𝓝 (x, y) have hV₁₂ : V₁ ×ˢ V₂ ∈ 𝓝 (x, y) := prod_mem_nhds V₁_in V₂_in -- But (x, y) is also a cluster point of F so (V₁ ×ˢ V₂) ∩ (W ○ W) ≠ ∅ -- However the construction of W implies (V₁ ×ˢ V₂) ∩ (W ○ W) = ∅. -- Indeed assume for contradiction there is some (u, v) in the intersection. obtain ⟨⟨u, v⟩, ⟨u_in, v_in⟩, w, huw, hwv⟩ := clusterPt_iff.mp hxy.of_inf_left hV₁₂ this -- So u ∈ V₁, v ∈ V₂, and there exists some w such that (u, w) ∈ W and (w ,v) ∈ W. -- Because u is in V₁ which is disjoint from U₂ and U₃, (u, w) ∈ W forces (u, w) ∈ U₁ ×ˢ U₁. have uw_in : (u, w) ∈ U₁ ×ˢ U₁ := (huw.resolve_right fun h => h.1 <| Or.inl u_in).resolve_right fun h => hU₁₂.le_bot ⟨VU₁ u_in, h.1⟩ -- Similarly, because v ∈ V₂, (w ,v) ∈ W forces (w, v) ∈ U₂ ×ˢ U₂. have wv_in : (w, v) ∈ U₂ ×ˢ U₂ := (hwv.resolve_right fun h => h.2 <| Or.inr v_in).resolve_left fun h => hU₁₂.le_bot ⟨h.2, VU₂ v_in⟩ -- Hence w ∈ U₁ ∩ U₂ which is empty. -- So we have a contradiction exact hU₁₂.le_bot ⟨uw_in.2, wv_in.1⟩ nhds_eq_comap_uniformity x := by simp_rw [nhdsSet_diagonal, comap_iSup, nhds_prod_eq, comap_prod, (· ∘ ·), comap_id'] rw [iSup_split_single _ x, comap_const_of_mem fun V => mem_of_mem_nhds] suffices ∀ y ≠ x, comap (fun _ : γ ↦ x) (𝓝 y) ⊓ 𝓝 y ≤ 𝓝 x by simpa intro y hxy simp [comap_const_of_not_mem (compl_singleton_mem_nhds hxy) (not_not_intro rfl)] #align uniform_space_of_compact_t2 uniformSpaceOfCompactT2 /-! ### Heine-Cantor theorem -/ /-- Heine-Cantor: a continuous function on a compact uniform space is uniformly continuous. -/ theorem CompactSpace.uniformContinuous_of_continuous [CompactSpace α] {f : α → β} (h : Continuous f) : UniformContinuous f := calc map (Prod.map f f) (𝓤 α) = map (Prod.map f f) (𝓝ˢ (diagonal α)) := by rw [nhdsSet_diagonal_eq_uniformity] _ ≤ 𝓝ˢ (diagonal β) := (h.prod_map h).tendsto_nhdsSet mapsTo_prod_map_diagonal _ ≤ 𝓤 β := nhdsSet_diagonal_le_uniformity #align compact_space.uniform_continuous_of_continuous CompactSpace.uniformContinuous_of_continuous /-- Heine-Cantor: a continuous function on a compact set of a uniform space is uniformly continuous. -/ theorem IsCompact.uniformContinuousOn_of_continuous {s : Set α} {f : α → β} (hs : IsCompact s) (hf : ContinuousOn f s) : UniformContinuousOn f s := by rw [uniformContinuousOn_iff_restrict] rw [isCompact_iff_compactSpace] at hs rw [continuousOn_iff_continuous_restrict] at hf exact CompactSpace.uniformContinuous_of_continuous hf #align is_compact.uniform_continuous_on_of_continuous IsCompact.uniformContinuousOn_of_continuous /-- If `s` is compact and `f` is continuous at all points of `s`, then `f` is "uniformly continuous at the set `s`", i.e. `f x` is close to `f y` whenever `x ∈ s` and `y` is close to `x` (even if `y` is not itself in `s`, so this is a stronger assertion than `UniformContinuousOn s`). -/
Mathlib/Topology/UniformSpace/Compact.lean
181
193
theorem IsCompact.uniformContinuousAt_of_continuousAt {r : Set (β × β)} {s : Set α} (hs : IsCompact s) (f : α → β) (hf : ∀ a ∈ s, ContinuousAt f a) (hr : r ∈ 𝓤 β) : { x : α × α | x.1 ∈ s → (f x.1, f x.2) ∈ r } ∈ 𝓤 α := by
obtain ⟨t, ht, htsymm, htr⟩ := comp_symm_mem_uniformity_sets hr choose U hU T hT hb using fun a ha => exists_mem_nhds_ball_subset_of_mem_nhds ((hf a ha).preimage_mem_nhds <| mem_nhds_left _ ht) obtain ⟨fs, hsU⟩ := hs.elim_nhds_subcover' U hU apply mem_of_superset ((biInter_finset_mem fs).2 fun a _ => hT a a.2) rintro ⟨a₁, a₂⟩ h h₁ obtain ⟨a, ha, haU⟩ := Set.mem_iUnion₂.1 (hsU h₁) apply htr refine ⟨f a, htsymm.mk_mem_comm.1 (hb _ _ _ haU ?_), hb _ _ _ haU ?_⟩ exacts [mem_ball_self _ (hT a a.2), mem_iInter₂.1 h a ha]
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.Algebra.Valuation import Mathlib.Topology.Algebra.WithZeroTopology import Mathlib.Topology.Algebra.UniformField #align_import topology.algebra.valued_field from "leanprover-community/mathlib"@"3e0c4d76b6ebe9dfafb67d16f7286d2731ed6064" /-! # Valued fields and their completions In this file we study the topology of a field `K` endowed with a valuation (in our application to adic spaces, `K` will be the valuation field associated to some valuation on a ring, defined in valuation.basic). We already know from valuation.topology that one can build a topology on `K` which makes it a topological ring. The first goal is to show `K` is a topological *field*, ie inversion is continuous at every non-zero element. The next goal is to prove `K` is a *completable* topological field. This gives us a completion `hat K` which is a topological field. We also prove that `K` is automatically separated, so the map from `K` to `hat K` is injective. Then we extend the valuation given on `K` to a valuation on `hat K`. -/ open Filter Set open Topology section DivisionRing variable {K : Type*} [DivisionRing K] {Γ₀ : Type*} [LinearOrderedCommGroupWithZero Γ₀] section ValuationTopologicalDivisionRing section InversionEstimate variable (v : Valuation K Γ₀) -- The following is the main technical lemma ensuring that inversion is continuous -- in the topology induced by a valuation on a division ring (i.e. the next instance) -- and the fact that a valued field is completable -- [BouAC, VI.5.1 Lemme 1] theorem Valuation.inversion_estimate {x y : K} {γ : Γ₀ˣ} (y_ne : y ≠ 0) (h : v (x - y) < min (γ * (v y * v y)) (v y)) : v (x⁻¹ - y⁻¹) < γ := by have hyp1 : v (x - y) < γ * (v y * v y) := lt_of_lt_of_le h (min_le_left _ _) have hyp1' : v (x - y) * (v y * v y)⁻¹ < γ := mul_inv_lt_of_lt_mul₀ hyp1 have hyp2 : v (x - y) < v y := lt_of_lt_of_le h (min_le_right _ _) have key : v x = v y := Valuation.map_eq_of_sub_lt v hyp2 have x_ne : x ≠ 0 := by intro h apply y_ne rw [h, v.map_zero] at key exact v.zero_iff.1 key.symm have decomp : x⁻¹ - y⁻¹ = x⁻¹ * (y - x) * y⁻¹ := by rw [mul_sub_left_distrib, sub_mul, mul_assoc, show y * y⁻¹ = 1 from mul_inv_cancel y_ne, show x⁻¹ * x = 1 from inv_mul_cancel x_ne, mul_one, one_mul] calc v (x⁻¹ - y⁻¹) = v (x⁻¹ * (y - x) * y⁻¹) := by rw [decomp] _ = v x⁻¹ * (v <| y - x) * v y⁻¹ := by repeat' rw [Valuation.map_mul] _ = (v x)⁻¹ * (v <| y - x) * (v y)⁻¹ := by rw [map_inv₀, map_inv₀] _ = (v <| y - x) * (v y * v y)⁻¹ := by rw [mul_assoc, mul_comm, key, mul_assoc, mul_inv_rev] _ = (v <| y - x) * (v y * v y)⁻¹ := rfl _ = (v <| x - y) * (v y * v y)⁻¹ := by rw [Valuation.map_sub_swap] _ < γ := hyp1' #align valuation.inversion_estimate Valuation.inversion_estimate end InversionEstimate open Valued /-- The topology coming from a valuation on a division ring makes it a topological division ring [BouAC, VI.5.1 middle of Proposition 1] -/ instance (priority := 100) Valued.topologicalDivisionRing [Valued K Γ₀] : TopologicalDivisionRing K := { (by infer_instance : TopologicalRing K) with continuousAt_inv₀ := by intro x x_ne s s_in cases' Valued.mem_nhds.mp s_in with γ hs; clear s_in rw [mem_map, Valued.mem_nhds] change ∃ γ : Γ₀ˣ, { y : K | (v (y - x) : Γ₀) < γ } ⊆ { x : K | x⁻¹ ∈ s } have vx_ne := (Valuation.ne_zero_iff <| v).mpr x_ne let γ' := Units.mk0 _ vx_ne use min (γ * (γ' * γ')) γ' intro y y_in apply hs simp only [mem_setOf_eq] at y_in rw [Units.min_val, Units.val_mul, Units.val_mul] at y_in exact Valuation.inversion_estimate _ x_ne y_in } #align valued.topological_division_ring Valued.topologicalDivisionRing /-- A valued division ring is separated. -/ instance (priority := 100) ValuedRing.separated [Valued K Γ₀] : T0Space K := by suffices T2Space K by infer_instance apply TopologicalAddGroup.t2Space_of_zero_sep intro x x_ne refine ⟨{ k | v k < v x }, ?_, fun h => lt_irrefl _ h⟩ rw [Valued.mem_nhds] have vx_ne := (Valuation.ne_zero_iff <| v).mpr x_ne let γ' := Units.mk0 _ vx_ne exact ⟨γ', fun y hy => by simpa using hy⟩ #align valued_ring.separated ValuedRing.separated section open WithZeroTopology open Valued theorem Valued.continuous_valuation [Valued K Γ₀] : Continuous (v : K → Γ₀) := by rw [continuous_iff_continuousAt] intro x rcases eq_or_ne x 0 with (rfl | h) · rw [ContinuousAt, map_zero, WithZeroTopology.tendsto_zero] intro γ hγ rw [Filter.Eventually, Valued.mem_nhds_zero] use Units.mk0 γ hγ; rfl · have v_ne : (v x : Γ₀) ≠ 0 := (Valuation.ne_zero_iff _).mpr h rw [ContinuousAt, WithZeroTopology.tendsto_of_ne_zero v_ne] apply Valued.loc_const v_ne #align valued.continuous_valuation Valued.continuous_valuation end end ValuationTopologicalDivisionRing end DivisionRing namespace Valued open UniformSpace variable {K : Type*} [Field K] {Γ₀ : Type*} [LinearOrderedCommGroupWithZero Γ₀] [hv : Valued K Γ₀] local notation "hat " => Completion /-- A valued field is completable. -/ instance (priority := 100) completable : CompletableTopField K := { ValuedRing.separated with nice := by rintro F hF h0 have : ∃ γ₀ : Γ₀ˣ, ∃ M ∈ F, ∀ x ∈ M, (γ₀ : Γ₀) ≤ v x := by rcases Filter.inf_eq_bot_iff.mp h0 with ⟨U, U_in, M, M_in, H⟩ rcases Valued.mem_nhds_zero.mp U_in with ⟨γ₀, hU⟩ exists γ₀, M, M_in intro x xM apply le_of_not_lt _ intro hyp have : x ∈ U ∩ M := ⟨hU hyp, xM⟩ rwa [H] at this rcases this with ⟨γ₀, M₀, M₀_in, H₀⟩ rw [Valued.cauchy_iff] at hF ⊢ refine ⟨hF.1.map _, ?_⟩ replace hF := hF.2 intro γ rcases hF (min (γ * γ₀ * γ₀) γ₀) with ⟨M₁, M₁_in, H₁⟩ clear hF use (fun x : K => x⁻¹) '' (M₀ ∩ M₁) constructor · rw [mem_map] apply mem_of_superset (Filter.inter_mem M₀_in M₁_in) exact subset_preimage_image _ _ · rintro _ ⟨x, ⟨x_in₀, x_in₁⟩, rfl⟩ _ ⟨y, ⟨_, y_in₁⟩, rfl⟩ simp only [mem_setOf_eq] specialize H₁ x x_in₁ y y_in₁ replace x_in₀ := H₀ x x_in₀ clear H₀ apply Valuation.inversion_estimate · have : (v x : Γ₀) ≠ 0 := by intro h rw [h] at x_in₀ simp at x_in₀ exact (Valuation.ne_zero_iff _).mp this · refine lt_of_lt_of_le H₁ ?_ rw [Units.min_val] apply min_le_min _ x_in₀ rw [mul_assoc] have : ((γ₀ * γ₀ : Γ₀ˣ) : Γ₀) ≤ v x * v x := calc ↑γ₀ * ↑γ₀ ≤ ↑γ₀ * v x := mul_le_mul_left' x_in₀ ↑γ₀ _ ≤ _ := mul_le_mul_right' x_in₀ (v x) rw [Units.val_mul] exact mul_le_mul_left' this γ } #align valued.completable Valued.completable open WithZeroTopology /-- The extension of the valuation of a valued field to the completion of the field. -/ noncomputable def extension : hat K → Γ₀ := Completion.denseInducing_coe.extend (v : K → Γ₀) #align valued.extension Valued.extension theorem continuous_extension : Continuous (Valued.extension : hat K → Γ₀) := by refine Completion.denseInducing_coe.continuous_extend ?_ intro x₀ rcases eq_or_ne x₀ 0 with (rfl | h) · refine ⟨0, ?_⟩ erw [← Completion.denseInducing_coe.toInducing.nhds_eq_comap] exact Valued.continuous_valuation.tendsto' 0 0 (map_zero v) · have preimage_one : v ⁻¹' {(1 : Γ₀)} ∈ 𝓝 (1 : K) := by have : (v (1 : K) : Γ₀) ≠ 0 := by rw [Valuation.map_one] exact zero_ne_one.symm convert Valued.loc_const this ext x rw [Valuation.map_one, mem_preimage, mem_singleton_iff, mem_setOf_eq] obtain ⟨V, V_in, hV⟩ : ∃ V ∈ 𝓝 (1 : hat K), ∀ x : K, (x : hat K) ∈ V → (v x : Γ₀) = 1 := by rwa [Completion.denseInducing_coe.nhds_eq_comap, mem_comap] at preimage_one have : ∃ V' ∈ 𝓝 (1 : hat K), (0 : hat K) ∉ V' ∧ ∀ (x) (_ : x ∈ V') (y) (_ : y ∈ V'), x * y⁻¹ ∈ V := by have : Tendsto (fun p : hat K × hat K => p.1 * p.2⁻¹) ((𝓝 1) ×ˢ (𝓝 1)) (𝓝 1) := by rw [← nhds_prod_eq] conv => congr rfl rfl rw [← one_mul (1 : hat K)] refine Tendsto.mul continuous_fst.continuousAt (Tendsto.comp ?_ continuous_snd.continuousAt) -- Porting note: Added `ContinuousAt.tendsto` convert (continuousAt_inv₀ (zero_ne_one.symm : 1 ≠ (0 : hat K))).tendsto exact inv_one.symm rcases tendsto_prod_self_iff.mp this V V_in with ⟨U, U_in, hU⟩ let hatKstar := ({0}ᶜ : Set <| hat K) have : hatKstar ∈ 𝓝 (1 : hat K) := compl_singleton_mem_nhds zero_ne_one.symm use U ∩ hatKstar, Filter.inter_mem U_in this constructor · rintro ⟨_, h'⟩ rw [mem_compl_singleton_iff] at h' exact h' rfl · rintro x ⟨hx, _⟩ y ⟨hy, _⟩ apply hU <;> assumption rcases this with ⟨V', V'_in, zeroV', hV'⟩ have nhds_right : (fun x => x * x₀) '' V' ∈ 𝓝 x₀ := by have l : Function.LeftInverse (fun x : hat K => x * x₀⁻¹) fun x : hat K => x * x₀ := by intro x simp only [mul_assoc, mul_inv_cancel h, mul_one] have r : Function.RightInverse (fun x : hat K => x * x₀⁻¹) fun x : hat K => x * x₀ := by intro x simp only [mul_assoc, inv_mul_cancel h, mul_one] have c : Continuous fun x : hat K => x * x₀⁻¹ := continuous_id.mul continuous_const rw [image_eq_preimage_of_inverse l r] rw [← mul_inv_cancel h] at V'_in exact c.continuousAt V'_in have : ∃ z₀ : K, ∃ y₀ ∈ V', ↑z₀ = y₀ * x₀ ∧ z₀ ≠ 0 := by rcases Completion.denseRange_coe.mem_nhds nhds_right with ⟨z₀, y₀, y₀_in, H : y₀ * x₀ = z₀⟩ refine ⟨z₀, y₀, y₀_in, ⟨H.symm, ?_⟩⟩ rintro rfl exact mul_ne_zero (ne_of_mem_of_not_mem y₀_in zeroV') h H rcases this with ⟨z₀, y₀, y₀_in, hz₀, z₀_ne⟩ have vz₀_ne : (v z₀ : Γ₀) ≠ 0 := by rwa [Valuation.ne_zero_iff] refine ⟨v z₀, ?_⟩ rw [WithZeroTopology.tendsto_of_ne_zero vz₀_ne, eventually_comap] filter_upwards [nhds_right] with x x_in a ha rcases x_in with ⟨y, y_in, rfl⟩ have : (v (a * z₀⁻¹) : Γ₀) = 1 := by apply hV have : (z₀⁻¹ : K) = (z₀ : hat K)⁻¹ := map_inv₀ (Completion.coeRingHom : K →+* hat K) z₀ rw [Completion.coe_mul, this, ha, hz₀, mul_inv, mul_comm y₀⁻¹, ← mul_assoc, mul_assoc y, mul_inv_cancel h, mul_one] solve_by_elim calc v a = v (a * z₀⁻¹ * z₀) := by rw [mul_assoc, inv_mul_cancel z₀_ne, mul_one] _ = v (a * z₀⁻¹) * v z₀ := Valuation.map_mul _ _ _ _ = v z₀ := by rw [this, one_mul] #align valued.continuous_extension Valued.continuous_extension @[simp, norm_cast]
Mathlib/Topology/Algebra/ValuedField.lean
276
279
theorem extension_extends (x : K) : extension (x : hat K) = v x := by
refine Completion.denseInducing_coe.extend_eq_of_tendsto ?_ rw [← Completion.denseInducing_coe.nhds_eq_comap] exact Valued.continuous_valuation.continuousAt
/- Copyright (c) 2022 Felix Weilacher. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Felix Weilacher -/ import Mathlib.Topology.Separation /-! # Perfect Sets In this file we define perfect subsets of a topological space, and prove some basic properties, including a version of the Cantor-Bendixson Theorem. ## Main Definitions * `Perfect C`: A set `C` is perfect, meaning it is closed and every point of it is an accumulation point of itself. * `PerfectSpace X`: A topological space `X` is perfect if its universe is a perfect set. ## Main Statements * `Perfect.splitting`: A perfect nonempty set contains two disjoint perfect nonempty subsets. The main inductive step in the construction of an embedding from the Cantor space to a perfect nonempty complete metric space. * `exists_countable_union_perfect_of_isClosed`: One version of the **Cantor-Bendixson Theorem**: A closed set in a second countable space can be written as the union of a countable set and a perfect set. ## Implementation Notes We do not require perfect sets to be nonempty. We define a nonstandard predicate, `Preperfect`, which drops the closed-ness requirement from the definition of perfect. In T1 spaces, this is equivalent to having a perfect closure, see `preperfect_iff_perfect_closure`. ## See also `Mathlib.Topology.MetricSpace.Perfect`, for properties of perfect sets in metric spaces, namely Polish spaces. ## References * [kechris1995] (Chapters 6-7) ## Tags accumulation point, perfect set, cantor-bendixson. -/ open Topology Filter Set TopologicalSpace section Basic variable {α : Type*} [TopologicalSpace α] {C : Set α} /-- If `x` is an accumulation point of a set `C` and `U` is a neighborhood of `x`, then `x` is an accumulation point of `U ∩ C`. -/ theorem AccPt.nhds_inter {x : α} {U : Set α} (h_acc : AccPt x (𝓟 C)) (hU : U ∈ 𝓝 x) : AccPt x (𝓟 (U ∩ C)) := by have : 𝓝[≠] x ≤ 𝓟 U := by rw [le_principal_iff] exact mem_nhdsWithin_of_mem_nhds hU rw [AccPt, ← inf_principal, ← inf_assoc, inf_of_le_left this] exact h_acc #align acc_pt.nhds_inter AccPt.nhds_inter /-- A set `C` is preperfect if all of its points are accumulation points of itself. If `C` is nonempty and `α` is a T1 space, this is equivalent to the closure of `C` being perfect. See `preperfect_iff_perfect_closure`. -/ def Preperfect (C : Set α) : Prop := ∀ x ∈ C, AccPt x (𝓟 C) #align preperfect Preperfect /-- A set `C` is called perfect if it is closed and all of its points are accumulation points of itself. Note that we do not require `C` to be nonempty. -/ @[mk_iff perfect_def] structure Perfect (C : Set α) : Prop where closed : IsClosed C acc : Preperfect C #align perfect Perfect theorem preperfect_iff_nhds : Preperfect C ↔ ∀ x ∈ C, ∀ U ∈ 𝓝 x, ∃ y ∈ U ∩ C, y ≠ x := by simp only [Preperfect, accPt_iff_nhds] #align preperfect_iff_nhds preperfect_iff_nhds section PerfectSpace variable (α) /-- A topological space `X` is said to be perfect if its universe is a perfect set. Equivalently, this means that `𝓝[≠] x ≠ ⊥` for every point `x : X`. -/ @[mk_iff perfectSpace_def] class PerfectSpace : Prop := univ_preperfect : Preperfect (Set.univ : Set α) theorem PerfectSpace.univ_perfect [PerfectSpace α] : Perfect (Set.univ : Set α) := ⟨isClosed_univ, PerfectSpace.univ_preperfect⟩ end PerfectSpace section Preperfect /-- The intersection of a preperfect set and an open set is preperfect. -/ theorem Preperfect.open_inter {U : Set α} (hC : Preperfect C) (hU : IsOpen U) : Preperfect (U ∩ C) := by rintro x ⟨xU, xC⟩ apply (hC _ xC).nhds_inter exact hU.mem_nhds xU #align preperfect.open_inter Preperfect.open_inter /-- The closure of a preperfect set is perfect. For a converse, see `preperfect_iff_perfect_closure`. -/ theorem Preperfect.perfect_closure (hC : Preperfect C) : Perfect (closure C) := by constructor; · exact isClosed_closure intro x hx by_cases h : x ∈ C <;> apply AccPt.mono _ (principal_mono.mpr subset_closure) · exact hC _ h have : {x}ᶜ ∩ C = C := by simp [h] rw [AccPt, nhdsWithin, inf_assoc, inf_principal, this] rw [closure_eq_cluster_pts] at hx exact hx #align preperfect.perfect_closure Preperfect.perfect_closure /-- In a T1 space, being preperfect is equivalent to having perfect closure. -/ theorem preperfect_iff_perfect_closure [T1Space α] : Preperfect C ↔ Perfect (closure C) := by constructor <;> intro h · exact h.perfect_closure intro x xC have H : AccPt x (𝓟 (closure C)) := h.acc _ (subset_closure xC) rw [accPt_iff_frequently] at * have : ∀ y, y ≠ x ∧ y ∈ closure C → ∃ᶠ z in 𝓝 y, z ≠ x ∧ z ∈ C := by rintro y ⟨hyx, yC⟩ simp only [← mem_compl_singleton_iff, and_comm, ← frequently_nhdsWithin_iff, hyx.nhdsWithin_compl_singleton, ← mem_closure_iff_frequently] exact yC rw [← frequently_frequently_nhds] exact H.mono this #align preperfect_iff_perfect_closure preperfect_iff_perfect_closure theorem Perfect.closure_nhds_inter {U : Set α} (hC : Perfect C) (x : α) (xC : x ∈ C) (xU : x ∈ U) (Uop : IsOpen U) : Perfect (closure (U ∩ C)) ∧ (closure (U ∩ C)).Nonempty := by constructor · apply Preperfect.perfect_closure exact hC.acc.open_inter Uop apply Nonempty.closure exact ⟨x, ⟨xU, xC⟩⟩ #align perfect.closure_nhds_inter Perfect.closure_nhds_inter /-- Given a perfect nonempty set in a T2.5 space, we can find two disjoint perfect subsets. This is the main inductive step in the proof of the Cantor-Bendixson Theorem. -/ theorem Perfect.splitting [T25Space α] (hC : Perfect C) (hnonempty : C.Nonempty) : ∃ C₀ C₁ : Set α, (Perfect C₀ ∧ C₀.Nonempty ∧ C₀ ⊆ C) ∧ (Perfect C₁ ∧ C₁.Nonempty ∧ C₁ ⊆ C) ∧ Disjoint C₀ C₁ := by cases' hnonempty with y yC obtain ⟨x, xC, hxy⟩ : ∃ x ∈ C, x ≠ y := by have := hC.acc _ yC rw [accPt_iff_nhds] at this rcases this univ univ_mem with ⟨x, xC, hxy⟩ exact ⟨x, xC.2, hxy⟩ obtain ⟨U, xU, Uop, V, yV, Vop, hUV⟩ := exists_open_nhds_disjoint_closure hxy use closure (U ∩ C), closure (V ∩ C) constructor <;> rw [← and_assoc] · refine ⟨hC.closure_nhds_inter x xC xU Uop, ?_⟩ rw [hC.closed.closure_subset_iff] exact inter_subset_right constructor · refine ⟨hC.closure_nhds_inter y yC yV Vop, ?_⟩ rw [hC.closed.closure_subset_iff] exact inter_subset_right apply Disjoint.mono _ _ hUV <;> apply closure_mono <;> exact inter_subset_left #align perfect.splitting Perfect.splitting end Preperfect section Kernel /-- The **Cantor-Bendixson Theorem**: Any closed subset of a second countable space can be written as the union of a countable set and a perfect set. -/ theorem exists_countable_union_perfect_of_isClosed [SecondCountableTopology α] (hclosed : IsClosed C) : ∃ V D : Set α, V.Countable ∧ Perfect D ∧ C = V ∪ D := by obtain ⟨b, bct, _, bbasis⟩ := TopologicalSpace.exists_countable_basis α let v := { U ∈ b | (U ∩ C).Countable } let V := ⋃ U ∈ v, U let D := C \ V have Vct : (V ∩ C).Countable := by simp only [V, iUnion_inter, mem_sep_iff] apply Countable.biUnion · exact Countable.mono inter_subset_left bct · exact inter_subset_right refine ⟨V ∩ C, D, Vct, ⟨?_, ?_⟩, ?_⟩ · refine hclosed.sdiff (isOpen_biUnion fun _ ↦ ?_) exact fun ⟨Ub, _⟩ ↦ IsTopologicalBasis.isOpen bbasis Ub · rw [preperfect_iff_nhds] intro x xD E xE have : ¬(E ∩ D).Countable := by intro h obtain ⟨U, hUb, xU, hU⟩ : ∃ U ∈ b, x ∈ U ∧ U ⊆ E := (IsTopologicalBasis.mem_nhds_iff bbasis).mp xE have hU_cnt : (U ∩ C).Countable := by apply @Countable.mono _ _ (E ∩ D ∪ V ∩ C) · rintro y ⟨yU, yC⟩ by_cases h : y ∈ V · exact mem_union_right _ (mem_inter h yC) · exact mem_union_left _ (mem_inter (hU yU) ⟨yC, h⟩) exact Countable.union h Vct have : U ∈ v := ⟨hUb, hU_cnt⟩ apply xD.2 exact mem_biUnion this xU by_contra! h exact absurd (Countable.mono h (Set.countable_singleton _)) this · rw [inter_comm, inter_union_diff] #align exists_countable_union_perfect_of_is_closed exists_countable_union_perfect_of_isClosed /-- Any uncountable closed set in a second countable space contains a nonempty perfect subset. -/ theorem exists_perfect_nonempty_of_isClosed_of_not_countable [SecondCountableTopology α] (hclosed : IsClosed C) (hunc : ¬C.Countable) : ∃ D : Set α, Perfect D ∧ D.Nonempty ∧ D ⊆ C := by rcases exists_countable_union_perfect_of_isClosed hclosed with ⟨V, D, Vct, Dperf, VD⟩ refine ⟨D, ⟨Dperf, ?_⟩⟩ constructor · rw [nonempty_iff_ne_empty] by_contra h rw [h, union_empty] at VD rw [VD] at hunc contradiction rw [VD] exact subset_union_right #align exists_perfect_nonempty_of_is_closed_of_not_countable exists_perfect_nonempty_of_isClosed_of_not_countable end Kernel end Basic section PerfectSpace variable {X : Type*} [TopologicalSpace X]
Mathlib/Topology/Perfect.lean
244
245
theorem perfectSpace_iff_forall_not_isolated : PerfectSpace X ↔ ∀ x : X, Filter.NeBot (𝓝[≠] x) := by
simp [perfectSpace_def, Preperfect, AccPt]
/- 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] 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₂') #align real.rpow_le_rpow Real.rpow_le_rpow theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≤ r) : MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_le_rpow ha hab hr lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by have := hx.trans hxy rw [← inv_lt_inv, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz) all_goals positivity lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z := by have := hx.trans_le hxy rw [← inv_le_inv, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz) all_goals positivity theorem rpow_lt_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := ⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩ #align real.rpow_lt_rpow_iff Real.rpow_lt_rpow_iff theorem rpow_le_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz #align real.rpow_le_rpow_iff Real.rpow_le_rpow_iff lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := ⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le, fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩ lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz lemma le_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity lemma rpow_inv_le_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity lemma lt_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz lemma rpow_inv_lt_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z := by rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.le_rpow_inv_iff_of_neg Real.le_rpow_inv_iff_of_neg theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := by rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.lt_rpow_inv_iff_of_neg Real.lt_rpow_inv_iff_of_neg theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := by rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.rpow_inv_lt_iff_of_neg Real.rpow_inv_lt_iff_of_neg theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x := by rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.rpow_inv_le_iff_of_neg Real.rpow_inv_le_iff_of_neg theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)] rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx) #align real.rpow_lt_rpow_of_exponent_lt Real.rpow_lt_rpow_of_exponent_lt @[gcongr] theorem rpow_le_rpow_of_exponent_le (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)] rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx) #align real.rpow_le_rpow_of_exponent_le Real.rpow_le_rpow_of_exponent_le theorem rpow_lt_rpow_of_exponent_neg {x y z : ℝ} (hy : 0 < y) (hxy : y < x) (hz : z < 0) : x ^ z < y ^ z := by have hx : 0 < x := hy.trans hxy rw [← neg_neg z, Real.rpow_neg (le_of_lt hx) (-z), Real.rpow_neg (le_of_lt hy) (-z), inv_lt_inv (rpow_pos_of_pos hx _) (rpow_pos_of_pos hy _)] exact Real.rpow_lt_rpow (by positivity) hxy <| neg_pos_of_neg hz theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) : StrictAntiOn (fun (x:ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_lt_rpow_of_exponent_neg ha hab hr theorem rpow_le_rpow_of_exponent_nonpos {x y : ℝ} (hy : 0 < y) (hxy : y ≤ x) (hz : z ≤ 0) : x ^ z ≤ y ^ z := by rcases ne_or_eq z 0 with hz_zero | rfl case inl => rcases ne_or_eq x y with hxy' | rfl case inl => exact le_of_lt <| rpow_lt_rpow_of_exponent_neg hy (Ne.lt_of_le (id (Ne.symm hxy')) hxy) (Ne.lt_of_le hz_zero hz) case inr => simp case inr => simp theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≤ 0) : AntitoneOn (fun (x:ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_le_rpow_of_exponent_nonpos ha hab hr @[simp] theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≤ x ^ z ↔ y ≤ z := by have x_pos : 0 < x := lt_trans zero_lt_one hx rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos, log_rpow x_pos, mul_le_mul_right (log_pos hx)] #align real.rpow_le_rpow_left_iff Real.rpow_le_rpow_left_iff @[simp] theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le] #align real.rpow_lt_rpow_left_iff Real.rpow_lt_rpow_left_iff theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1) #align real.rpow_lt_rpow_of_exponent_gt Real.rpow_lt_rpow_of_exponent_gt theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1) #align real.rpow_le_rpow_of_exponent_ge Real.rpow_le_rpow_of_exponent_ge @[simp] theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y ≤ x ^ z ↔ z ≤ y := by rw [← log_le_log_iff (rpow_pos_of_pos hx0 y) (rpow_pos_of_pos hx0 z), log_rpow hx0, log_rpow hx0, mul_le_mul_right_of_neg (log_neg hx0 hx1)] #align real.rpow_le_rpow_left_iff_of_base_lt_one Real.rpow_le_rpow_left_iff_of_base_lt_one @[simp] theorem rpow_lt_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y < x ^ z ↔ z < y := by rw [lt_iff_not_le, rpow_le_rpow_left_iff_of_base_lt_one hx0 hx1, lt_iff_not_le] #align real.rpow_lt_rpow_left_iff_of_base_lt_one Real.rpow_lt_rpow_left_iff_of_base_lt_one theorem rpow_lt_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x < 1) (hz : 0 < z) : x ^ z < 1 := by rw [← one_rpow z] exact rpow_lt_rpow hx1 hx2 hz #align real.rpow_lt_one Real.rpow_lt_one
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
698
700
theorem rpow_le_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by
rw [← one_rpow z] exact rpow_le_rpow hx1 hx2 hz
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Function.SimpleFuncDenseLp #align_import measure_theory.integral.set_to_l1 from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Extension of a linear function from indicators to L1 Let `T : Set α → E →L[ℝ] F` be additive for measurable sets with finite measure, in the sense that for `s, t` two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. `T` is akin to a bilinear map on `Set α × E`, or a linear map on indicator functions. This file constructs an extension of `T` to integrable simple functions, which are finite sums of indicators of measurable sets with finite measure, then to integrable functions, which are limits of integrable simple functions. The main result is a continuous linear map `(α →₁[μ] E) →L[ℝ] F`. This extension process is used to define the Bochner integral in the `MeasureTheory.Integral.Bochner` file and the conditional expectation of an integrable function in `MeasureTheory.Function.ConditionalExpectation`. ## Main Definitions - `FinMeasAdditive μ T`: the property that `T` is additive on measurable sets with finite measure. For two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. - `DominatedFinMeasAdditive μ T C`: `FinMeasAdditive μ T ∧ ∀ s, ‖T s‖ ≤ C * (μ s).toReal`. This is the property needed to perform the extension from indicators to L1. - `setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F`: the extension of `T` from indicators to L1. - `setToFun μ T (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F`: a version of the extension which applies to functions (with value 0 if the function is not integrable). ## Properties For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on measurable sets with finite measure, like `∀ s, MeasurableSet s → μ s < ∞ → T s = T' s`. The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details. Linearity: - `setToFun_zero_left : setToFun μ 0 hT f = 0` - `setToFun_add_left : setToFun μ (T + T') _ f = setToFun μ T hT f + setToFun μ T' hT' f` - `setToFun_smul_left : setToFun μ (fun s ↦ c • (T s)) (hT.smul c) f = c • setToFun μ T hT f` - `setToFun_zero : setToFun μ T hT (0 : α → E) = 0` - `setToFun_neg : setToFun μ T hT (-f) = - setToFun μ T hT f` If `f` and `g` are integrable: - `setToFun_add : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g` - `setToFun_sub : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g` If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`: - `setToFun_smul : setToFun μ T hT (c • f) = c • setToFun μ T hT f` Other: - `setToFun_congr_ae (h : f =ᵐ[μ] g) : setToFun μ T hT f = setToFun μ T hT g` - `setToFun_measure_zero (h : μ = 0) : setToFun μ T hT f = 0` If the space is a `NormedLatticeAddCommGroup` and `T` is such that `0 ≤ T s x` for `0 ≤ x`, we also prove order-related properties: - `setToFun_mono_left (h : ∀ s x, T s x ≤ T' s x) : setToFun μ T hT f ≤ setToFun μ T' hT' f` - `setToFun_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f` - `setToFun_mono (hfg : f ≤ᵐ[μ] g) : setToFun μ T hT f ≤ setToFun μ T hT g` ## Implementation notes The starting object `T : Set α → E →L[ℝ] F` matters only through its restriction on measurable sets with finite measure. Its value on other sets is ignored. -/ noncomputable section open scoped Classical Topology NNReal ENNReal MeasureTheory Pointwise open Set Filter TopologicalSpace ENNReal EMetric namespace MeasureTheory variable {α E F F' G 𝕜 : Type*} {p : ℝ≥0∞} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedAddCommGroup G] {m : MeasurableSpace α} {μ : Measure α} local infixr:25 " →ₛ " => SimpleFunc open Finset section FinMeasAdditive /-- A set function is `FinMeasAdditive` if its value on the union of two disjoint measurable sets with finite measure is the sum of its values on each set. -/ def FinMeasAdditive {β} [AddMonoid β] {_ : MeasurableSpace α} (μ : Measure α) (T : Set α → β) : Prop := ∀ s t, MeasurableSet s → MeasurableSet t → μ s ≠ ∞ → μ t ≠ ∞ → s ∩ t = ∅ → T (s ∪ t) = T s + T t #align measure_theory.fin_meas_additive MeasureTheory.FinMeasAdditive namespace FinMeasAdditive variable {β : Type*} [AddCommMonoid β] {T T' : Set α → β} theorem zero : FinMeasAdditive μ (0 : Set α → β) := fun s t _ _ _ _ _ => by simp #align measure_theory.fin_meas_additive.zero MeasureTheory.FinMeasAdditive.zero
Mathlib/MeasureTheory/Integral/SetToL1.lean
105
109
theorem add (hT : FinMeasAdditive μ T) (hT' : FinMeasAdditive μ T') : FinMeasAdditive μ (T + T') := by
intro s t hs ht hμs hμt hst simp only [hT s t hs ht hμs hμt hst, hT' s t hs ht hμs hμt hst, Pi.add_apply] abel
/- Copyright (c) 2021 Jordan Brown, Thomas Browning, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jordan Brown, Thomas Browning, Patrick Lutz -/ import Mathlib.Data.Fin.VecNotation import Mathlib.GroupTheory.Abelianization import Mathlib.GroupTheory.Perm.ViaEmbedding import Mathlib.GroupTheory.Subgroup.Simple import Mathlib.SetTheory.Cardinal.Basic #align_import group_theory.solvable from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Solvable Groups In this file we introduce the notion of a solvable group. We define a solvable group as one whose derived series is eventually trivial. This requires defining the commutator of two subgroups and the derived series of a group. ## Main definitions * `derivedSeries G n` : the `n`th term in the derived series of `G`, defined by iterating `general_commutator` starting with the top subgroup * `IsSolvable G` : the group `G` is solvable -/ open Subgroup variable {G G' : Type*} [Group G] [Group G'] {f : G →* G'} section derivedSeries variable (G) /-- The derived series of the group `G`, obtained by starting from the subgroup `⊤` and repeatedly taking the commutator of the previous subgroup with itself for `n` times. -/ def derivedSeries : ℕ → Subgroup G | 0 => ⊤ | n + 1 => ⁅derivedSeries n, derivedSeries n⁆ #align derived_series derivedSeries @[simp] theorem derivedSeries_zero : derivedSeries G 0 = ⊤ := rfl #align derived_series_zero derivedSeries_zero @[simp] theorem derivedSeries_succ (n : ℕ) : derivedSeries G (n + 1) = ⁅derivedSeries G n, derivedSeries G n⁆ := rfl #align derived_series_succ derivedSeries_succ -- Porting note: had to provide inductive hypothesis explicitly theorem derivedSeries_normal (n : ℕ) : (derivedSeries G n).Normal := by induction' n with n ih · exact (⊤ : Subgroup G).normal_of_characteristic · exact @Subgroup.commutator_normal G _ (derivedSeries G n) (derivedSeries G n) ih ih #align derived_series_normal derivedSeries_normal -- Porting note: higher simp priority to restore Lean 3 behavior @[simp 1100] theorem derivedSeries_one : derivedSeries G 1 = commutator G := rfl #align derived_series_one derivedSeries_one end derivedSeries section CommutatorMap section DerivedSeriesMap variable (f) theorem map_derivedSeries_le_derivedSeries (n : ℕ) : (derivedSeries G n).map f ≤ derivedSeries G' n := by induction' n with n ih · exact le_top · simp only [derivedSeries_succ, map_commutator, commutator_mono, ih] #align map_derived_series_le_derived_series map_derivedSeries_le_derivedSeries variable {f} theorem derivedSeries_le_map_derivedSeries (hf : Function.Surjective f) (n : ℕ) : derivedSeries G' n ≤ (derivedSeries G n).map f := by induction' n with n ih · exact (map_top_of_surjective f hf).ge · exact commutator_le_map_commutator ih ih #align derived_series_le_map_derived_series derivedSeries_le_map_derivedSeries theorem map_derivedSeries_eq (hf : Function.Surjective f) (n : ℕ) : (derivedSeries G n).map f = derivedSeries G' n := le_antisymm (map_derivedSeries_le_derivedSeries f n) (derivedSeries_le_map_derivedSeries hf n) #align map_derived_series_eq map_derivedSeries_eq end DerivedSeriesMap end CommutatorMap section Solvable variable (G) /-- A group `G` is solvable if its derived series is eventually trivial. We use this definition because it's the most convenient one to work with. -/ @[mk_iff isSolvable_def] class IsSolvable : Prop where /-- A group `G` is solvable if its derived series is eventually trivial. -/ solvable : ∃ n : ℕ, derivedSeries G n = ⊥ #align is_solvable IsSolvable #align is_solvable_def isSolvable_def instance (priority := 100) CommGroup.isSolvable {G : Type*} [CommGroup G] : IsSolvable G := ⟨⟨1, le_bot_iff.mp (Abelianization.commutator_subset_ker (MonoidHom.id G))⟩⟩ #align comm_group.is_solvable CommGroup.isSolvable theorem isSolvable_of_comm {G : Type*} [hG : Group G] (h : ∀ a b : G, a * b = b * a) : IsSolvable G := by letI hG' : CommGroup G := { hG with mul_comm := h } cases hG exact CommGroup.isSolvable #align is_solvable_of_comm isSolvable_of_comm theorem isSolvable_of_top_eq_bot (h : (⊤ : Subgroup G) = ⊥) : IsSolvable G := ⟨⟨0, h⟩⟩ #align is_solvable_of_top_eq_bot isSolvable_of_top_eq_bot instance (priority := 100) isSolvable_of_subsingleton [Subsingleton G] : IsSolvable G := isSolvable_of_top_eq_bot G (by simp [eq_iff_true_of_subsingleton]) #align is_solvable_of_subsingleton isSolvable_of_subsingleton variable {G} theorem solvable_of_ker_le_range {G' G'' : Type*} [Group G'] [Group G''] (f : G' →* G) (g : G →* G'') (hfg : g.ker ≤ f.range) [hG' : IsSolvable G'] [hG'' : IsSolvable G''] : IsSolvable G := by obtain ⟨n, hn⟩ := id hG'' obtain ⟨m, hm⟩ := id hG' refine ⟨⟨n + m, le_bot_iff.mp (Subgroup.map_bot f ▸ hm ▸ ?_)⟩⟩ clear hm induction' m with m hm · exact f.range_eq_map ▸ ((derivedSeries G n).map_eq_bot_iff.mp (le_bot_iff.mp ((map_derivedSeries_le_derivedSeries g n).trans hn.le))).trans hfg · exact commutator_le_map_commutator hm hm #align solvable_of_ker_le_range solvable_of_ker_le_range theorem solvable_of_solvable_injective (hf : Function.Injective f) [IsSolvable G'] : IsSolvable G := solvable_of_ker_le_range (1 : G' →* G) f ((f.ker_eq_bot_iff.mpr hf).symm ▸ bot_le) #align solvable_of_solvable_injective solvable_of_solvable_injective instance subgroup_solvable_of_solvable (H : Subgroup G) [IsSolvable G] : IsSolvable H := solvable_of_solvable_injective H.subtype_injective #align subgroup_solvable_of_solvable subgroup_solvable_of_solvable theorem solvable_of_surjective (hf : Function.Surjective f) [IsSolvable G] : IsSolvable G' := solvable_of_ker_le_range f (1 : G' →* G) ((f.range_top_of_surjective hf).symm ▸ le_top) #align solvable_of_surjective solvable_of_surjective instance solvable_quotient_of_solvable (H : Subgroup G) [H.Normal] [IsSolvable G] : IsSolvable (G ⧸ H) := solvable_of_surjective (QuotientGroup.mk'_surjective H) #align solvable_quotient_of_solvable solvable_quotient_of_solvable instance solvable_prod {G' : Type*} [Group G'] [IsSolvable G] [IsSolvable G'] : IsSolvable (G × G') := solvable_of_ker_le_range (MonoidHom.inl G G') (MonoidHom.snd G G') fun x hx => ⟨x.1, Prod.ext rfl hx.symm⟩ #align solvable_prod solvable_prod end Solvable section IsSimpleGroup variable [IsSimpleGroup G] theorem IsSimpleGroup.derivedSeries_succ {n : ℕ} : derivedSeries G n.succ = commutator G := by induction' n with n ih · exact derivedSeries_one G rw [_root_.derivedSeries_succ, ih, _root_.commutator] cases' (commutator_normal (⊤ : Subgroup G) (⊤ : Subgroup G)).eq_bot_or_eq_top with h h · rw [h, commutator_bot_left] · rwa [h] #align is_simple_group.derived_series_succ IsSimpleGroup.derivedSeries_succ theorem IsSimpleGroup.comm_iff_isSolvable : (∀ a b : G, a * b = b * a) ↔ IsSolvable G := ⟨isSolvable_of_comm, fun ⟨⟨n, hn⟩⟩ => by cases n · intro a b refine (mem_bot.1 ?_).trans (mem_bot.1 ?_).symm <;> · rw [← hn] exact mem_top _ · rw [IsSimpleGroup.derivedSeries_succ] at hn intro a b rw [← mul_inv_eq_one, mul_inv_rev, ← mul_assoc, ← mem_bot, ← hn, commutator_eq_closure] exact subset_closure ⟨a, b, rfl⟩⟩ #align is_simple_group.comm_iff_is_solvable IsSimpleGroup.comm_iff_isSolvable end IsSimpleGroup section PermNotSolvable theorem not_solvable_of_mem_derivedSeries {g : G} (h1 : g ≠ 1) (h2 : ∀ n : ℕ, g ∈ derivedSeries G n) : ¬IsSolvable G := mt (isSolvable_def _).mp (not_exists_of_forall_not fun n h => h1 (Subgroup.mem_bot.mp ((congr_arg (Membership.mem g) h).mp (h2 n)))) #align not_solvable_of_mem_derived_series not_solvable_of_mem_derivedSeries theorem Equiv.Perm.fin_5_not_solvable : ¬IsSolvable (Equiv.Perm (Fin 5)) := by let x : Equiv.Perm (Fin 5) := ⟨![1, 2, 0, 3, 4], ![2, 0, 1, 3, 4], by decide, by decide⟩ let y : Equiv.Perm (Fin 5) := ⟨![3, 4, 2, 0, 1], ![3, 4, 2, 0, 1], by decide, by decide⟩ let z : Equiv.Perm (Fin 5) := ⟨![0, 3, 2, 1, 4], ![0, 3, 2, 1, 4], by decide, by decide⟩ have key : x = z * ⁅x, y * x * y⁻¹⁆ * z⁻¹ := by unfold_let; decide refine not_solvable_of_mem_derivedSeries (show x ≠ 1 by decide) fun n => ?_ induction' n with n ih · exact mem_top x · rw [key, (derivedSeries_normal _ _).mem_comm_iff, inv_mul_cancel_left] exact commutator_mem_commutator ih ((derivedSeries_normal _ _).conj_mem _ ih _) #align equiv.perm.fin_5_not_solvable Equiv.Perm.fin_5_not_solvable
Mathlib/GroupTheory/Solvable.lean
223
230
theorem Equiv.Perm.not_solvable (X : Type*) (hX : 5 ≤ Cardinal.mk X) : ¬IsSolvable (Equiv.Perm X) := by
intro h have key : Nonempty (Fin 5 ↪ X) := by rwa [← Cardinal.lift_mk_le, Cardinal.mk_fin, Cardinal.lift_natCast, Cardinal.lift_id] exact Equiv.Perm.fin_5_not_solvable (solvable_of_solvable_injective (Equiv.Perm.viaEmbeddingHom_injective (Nonempty.some key)))
/- Copyright (c) 2021 Henry Swanson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Henry Swanson -/ import Mathlib.Algebra.BigOperators.Ring import Mathlib.Combinatorics.Derangements.Basic import Mathlib.Data.Fintype.BigOperators import Mathlib.Tactic.Ring #align_import combinatorics.derangements.finite from "leanprover-community/mathlib"@"c3019c79074b0619edb4b27553a91b2e82242395" /-! # Derangements on fintypes This file contains lemmas that describe the cardinality of `derangements α` when `α` is a fintype. # Main definitions * `card_derangements_invariant`: A lemma stating that the number of derangements on a type `α` depends only on the cardinality of `α`. * `numDerangements n`: The number of derangements on an n-element set, defined in a computation- friendly way. * `card_derangements_eq_numDerangements`: Proof that `numDerangements` really does compute the number of derangements. * `numDerangements_sum`: A lemma giving an expression for `numDerangements n` in terms of factorials. -/ open derangements Equiv Fintype variable {α : Type*} [DecidableEq α] [Fintype α] instance : DecidablePred (derangements α) := fun _ => Fintype.decidableForallFintype -- Porting note: used to use the tactic delta_instance instance : Fintype (derangements α) := Subtype.fintype (fun (_ : Perm α) => ∀ (x_1 : α), ¬_ = x_1) theorem card_derangements_invariant {α β : Type*} [Fintype α] [DecidableEq α] [Fintype β] [DecidableEq β] (h : card α = card β) : card (derangements α) = card (derangements β) := Fintype.card_congr (Equiv.derangementsCongr <| equivOfCardEq h) #align card_derangements_invariant card_derangements_invariant theorem card_derangements_fin_add_two (n : ℕ) : card (derangements (Fin (n + 2))) = (n + 1) * card (derangements (Fin n)) + (n + 1) * card (derangements (Fin (n + 1))) := by -- get some basic results about the size of fin (n+1) plus or minus an element have h1 : ∀ a : Fin (n + 1), card ({a}ᶜ : Set (Fin (n + 1))) = card (Fin n) := by intro a simp only [Fintype.card_fin, Finset.card_fin, Fintype.card_ofFinset, Finset.filter_ne' _ a, Set.mem_compl_singleton_iff, Finset.card_erase_of_mem (Finset.mem_univ a), add_tsub_cancel_right] have h2 : card (Fin (n + 2)) = card (Option (Fin (n + 1))) := by simp only [card_fin, card_option] -- rewrite the LHS and substitute in our fintype-level equivalence simp only [card_derangements_invariant h2, card_congr (@derangementsRecursionEquiv (Fin (n + 1)) _),-- push the cardinality through the Σ and ⊕ so that we can use `card_n` card_sigma, card_sum, card_derangements_invariant (h1 _), Finset.sum_const, nsmul_eq_mul, Finset.card_fin, mul_add, Nat.cast_id] #align card_derangements_fin_add_two card_derangements_fin_add_two /-- The number of derangements of an `n`-element set. -/ def numDerangements : ℕ → ℕ | 0 => 1 | 1 => 0 | n + 2 => (n + 1) * (numDerangements n + numDerangements (n + 1)) #align num_derangements numDerangements @[simp] theorem numDerangements_zero : numDerangements 0 = 1 := rfl #align num_derangements_zero numDerangements_zero @[simp] theorem numDerangements_one : numDerangements 1 = 0 := rfl #align num_derangements_one numDerangements_one theorem numDerangements_add_two (n : ℕ) : numDerangements (n + 2) = (n + 1) * (numDerangements n + numDerangements (n + 1)) := rfl #align num_derangements_add_two numDerangements_add_two
Mathlib/Combinatorics/Derangements/Finite.lean
87
92
theorem numDerangements_succ (n : ℕ) : (numDerangements (n + 1) : ℤ) = (n + 1) * (numDerangements n : ℤ) - (-1) ^ n := by
induction' n with n hn · rfl · simp only [numDerangements_add_two, hn, pow_succ, Int.ofNat_mul, Int.ofNat_add, Int.ofNat_succ] ring
/- 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.GelfandDuality import Mathlib.Topology.Algebra.StarSubalgebra #align_import analysis.normed_space.star.continuous_functional_calculus from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004" /-! # Continuous functional calculus In this file we construct the `continuousFunctionalCalculus` for a normal element `a` of a (unital) C⋆-algebra over `ℂ`. This is a star algebra equivalence `C(spectrum ℂ a, ℂ) ≃⋆ₐ[ℂ] elementalStarAlgebra ℂ a` which sends the (restriction of) the identity map `ContinuousMap.id ℂ` to the (unique) preimage of `a` under the coercion of `elementalStarAlgebra ℂ a` to `A`. Being a star algebra equivalence between C⋆-algebras, this map is continuous (even an isometry), and by the Stone-Weierstrass theorem it is the unique star algebra equivalence which extends the polynomial functional calculus (i.e., `Polynomial.aeval`). For any continuous function `f : spectrum ℂ a → ℂ`, this makes it possible to define an element `f a` (not valid notation) in the original algebra, which heuristically has the same eigenspaces as `a` and acts on eigenvector of `a` for an eigenvalue `λ` as multiplication by `f λ`. This description is perfectly accurate in finite dimension, but only heuristic in infinite dimension as there might be no genuine eigenvector. In particular, when `f` is a polynomial `∑ cᵢ Xⁱ`, then `f a` is `∑ cᵢ aⁱ`. Also, `id a = a`. This file also includes a proof of the **spectral permanence** theorem for (unital) C⋆-algebras (see `StarSubalgebra.spectrum_eq`) ## Main definitions * `continuousFunctionalCalculus : C(spectrum ℂ a, ℂ) ≃⋆ₐ[ℂ] elementalStarAlgebra ℂ a`: this is the composition of the inverse of the `gelfandStarTransform` with the natural isomorphism induced by the homeomorphism `elementalStarAlgebra.characterSpaceHomeo`. * `elementalStarAlgebra.characterSpaceHomeo` : `characterSpace ℂ (elementalStarAlgebra ℂ a) ≃ₜ spectrum ℂ a`: this homeomorphism is defined by evaluating a character `φ` at `a`, and noting that `φ a ∈ spectrum ℂ a` since `φ` is an algebra homomorphism. Moreover, this map is continuous and bijective and since the spaces involved are compact Hausdorff, it is a homeomorphism. ## Main statements * `StarSubalgebra.coe_isUnit`: for `x : S` in a C⋆-Subalgebra `S` of `A`, then `↑x : A` is a Unit if and only if `x` is a unit. * `StarSubalgebra.spectrum_eq`: **spectral_permanence** for `x : S`, where `S` is a C⋆-Subalgebra of `A`, `spectrum ℂ x = spectrum ℂ (x : A)`. ## Notes The result we have established here is the strongest possible, but it is likely not the version which will be most useful in practice. Future work will include developing an appropriate API for the continuous functional calculus (including one for real-valued functions with real argument that applies to self-adjoint elements of the algebra). -/ open scoped Pointwise ENNReal NNReal ComplexOrder open WeakDual WeakDual.CharacterSpace elementalStarAlgebra variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] variable [StarRing A] [CstarRing A] [StarModule ℂ A] instance {R A : Type*} [CommRing R] [StarRing R] [NormedRing A] [Algebra R A] [StarRing A] [ContinuousStar A] [StarModule R A] (a : A) [IsStarNormal a] : NormedCommRing (elementalStarAlgebra R a) := { SubringClass.toNormedRing (elementalStarAlgebra R a) with mul_comm := mul_comm } -- Porting note: these hack instances no longer seem to be necessary #noalign elemental_star_algebra.complex.normed_algebra variable [CompleteSpace A] (a : A) [IsStarNormal a] (S : StarSubalgebra ℂ A) /-- This lemma is used in the proof of `elementalStarAlgebra.isUnit_of_isUnit_of_isStarNormal`, which in turn is the key to spectral permanence `StarSubalgebra.spectrum_eq`, which is itself necessary for the continuous functional calculus. Using the continuous functional calculus, this lemma can be superseded by one that omits the `IsStarNormal` hypothesis. -/
Mathlib/Analysis/NormedSpace/Star/ContinuousFunctionalCalculus.lean
81
94
theorem spectrum_star_mul_self_of_isStarNormal : spectrum ℂ (star a * a) ⊆ Set.Icc (0 : ℂ) ‖star a * a‖ := by
-- this instance should be found automatically, but without providing it Lean goes on a wild -- goose chase when trying to apply `spectrum.gelfandTransform_eq`. --letI := elementalStarAlgebra.Complex.normedAlgebra a rcases subsingleton_or_nontrivial A with ⟨⟩ · simp only [spectrum.of_subsingleton, Set.empty_subset] · set a' : elementalStarAlgebra ℂ a := ⟨a, self_mem ℂ a⟩ refine (spectrum.subset_starSubalgebra (star a' * a')).trans ?_ rw [← spectrum.gelfandTransform_eq (star a' * a'), ContinuousMap.spectrum_eq_range] rintro - ⟨φ, rfl⟩ rw [gelfandTransform_apply_apply ℂ _ (star a' * a') φ, map_mul φ, map_star φ] rw [Complex.eq_coe_norm_of_nonneg (star_mul_self_nonneg _), ← map_star, ← map_mul] exact ⟨by positivity, Complex.real_le_real.2 (AlgHom.norm_apply_le_self φ (star a' * a'))⟩
/- 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, Johan Commelin -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Combinatorics.Enumerative.Composition #align_import analysis.analytic.composition from "leanprover-community/mathlib"@"ce11c3c2a285bbe6937e26d9792fda4e51f3fe1a" /-! # Composition of analytic functions In this file we prove that the composition of analytic functions is analytic. The argument is the following. Assume `g z = ∑' qₙ (z, ..., z)` and `f y = ∑' pₖ (y, ..., y)`. Then `g (f y) = ∑' qₙ (∑' pₖ (y, ..., y), ..., ∑' pₖ (y, ..., y)) = ∑' qₙ (p_{i₁} (y, ..., y), ..., p_{iₙ} (y, ..., y))`. For each `n` and `i₁, ..., iₙ`, define a `i₁ + ... + iₙ` multilinear function mapping `(y₀, ..., y_{i₁ + ... + iₙ - 1})` to `qₙ (p_{i₁} (y₀, ..., y_{i₁-1}), p_{i₂} (y_{i₁}, ..., y_{i₁ + i₂ - 1}), ..., p_{iₙ} (....)))`. Then `g ∘ f` is obtained by summing all these multilinear functions. To formalize this, we use compositions of an integer `N`, i.e., its decompositions into a sum `i₁ + ... + iₙ` of positive integers. Given such a composition `c` and two formal multilinear series `q` and `p`, let `q.comp_along_composition p c` be the above multilinear function. Then the `N`-th coefficient in the power series expansion of `g ∘ f` is the sum of these terms over all `c : composition N`. To complete the proof, we need to show that this power series has a positive radius of convergence. This follows from the fact that `composition N` has cardinality `2^(N-1)` and estimates on the norm of `qₙ` and `pₖ`, which give summability. We also need to show that it indeed converges to `g ∘ f`. For this, we note that the composition of partial sums converges to `g ∘ f`, and that it corresponds to a part of the whole sum, on a subset that increases to the whole space. By summability of the norms, this implies the overall convergence. ## Main results * `q.comp p` is the formal composition of the formal multilinear series `q` and `p`. * `HasFPowerSeriesAt.comp` states that if two functions `g` and `f` admit power series expansions `q` and `p`, then `g ∘ f` admits a power series expansion given by `q.comp p`. * `AnalyticAt.comp` states that the composition of analytic functions is analytic. * `FormalMultilinearSeries.comp_assoc` states that composition is associative on formal multilinear series. ## Implementation details The main technical difficulty is to write down things. In particular, we need to define precisely `q.comp_along_composition p c` and to show that it is indeed a continuous multilinear function. This requires a whole interface built on the class `Composition`. Once this is set, the main difficulty is to reorder the sums, writing the composition of the partial sums as a sum over some subset of `Σ n, composition n`. We need to check that the reordering is a bijection, running over difficulties due to the dependent nature of the types under consideration, that are controlled thanks to the interface for `Composition`. The associativity of composition on formal multilinear series is a nontrivial result: it does not follow from the associativity of composition of analytic functions, as there is no uniqueness for the formal multilinear series representing a function (and also, it holds even when the radius of convergence of the series is `0`). Instead, we give a direct proof, which amounts to reordering double sums in a careful way. The change of variables is a canonical (combinatorial) bijection `Composition.sigmaEquivSigmaPi` between `(Σ (a : composition n), composition a.length)` and `(Σ (c : composition n), Π (i : fin c.length), composition (c.blocks_fun i))`, and is described in more details below in the paragraph on associativity. -/ noncomputable section variable {𝕜 : Type*} {E F G H : Type*} open Filter List open scoped Topology Classical NNReal ENNReal section Topological variable [CommRing 𝕜] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G] variable [Module 𝕜 E] [Module 𝕜 F] [Module 𝕜 G] variable [TopologicalSpace E] [TopologicalSpace F] [TopologicalSpace G] /-! ### Composing formal multilinear series -/ namespace FormalMultilinearSeries variable [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] variable [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] variable [TopologicalAddGroup G] [ContinuousConstSMul 𝕜 G] /-! In this paragraph, we define the composition of formal multilinear series, by summing over all possible compositions of `n`. -/ /-- Given a formal multilinear series `p`, a composition `c` of `n` and the index `i` of a block of `c`, we may define a function on `fin n → E` by picking the variables in the `i`-th block of `n`, and applying the corresponding coefficient of `p` to these variables. This function is called `p.apply_composition c v i` for `v : fin n → E` and `i : fin c.length`. -/ def applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) : (Fin n → E) → Fin c.length → F := fun v i => p (c.blocksFun i) (v ∘ c.embedding i) #align formal_multilinear_series.apply_composition FormalMultilinearSeries.applyComposition theorem applyComposition_ones (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : p.applyComposition (Composition.ones n) = fun v i => p 1 fun _ => v (Fin.castLE (Composition.length_le _) i) := by funext v i apply p.congr (Composition.ones_blocksFun _ _) intro j hjn hj1 obtain rfl : j = 0 := by omega refine congr_arg v ?_ rw [Fin.ext_iff, Fin.coe_castLE, Composition.ones_embedding, Fin.val_mk] #align formal_multilinear_series.apply_composition_ones FormalMultilinearSeries.applyComposition_ones theorem applyComposition_single (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : 0 < n) (v : Fin n → E) : p.applyComposition (Composition.single n hn) v = fun _j => p n v := by ext j refine p.congr (by simp) fun i hi1 hi2 => ?_ dsimp congr 1 convert Composition.single_embedding hn ⟨i, hi2⟩ using 1 cases' j with j_val j_property have : j_val = 0 := le_bot_iff.1 (Nat.lt_succ_iff.1 j_property) congr! simp #align formal_multilinear_series.apply_composition_single FormalMultilinearSeries.applyComposition_single @[simp] theorem removeZero_applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) : p.removeZero.applyComposition c = p.applyComposition c := by ext v i simp [applyComposition, zero_lt_one.trans_le (c.one_le_blocksFun i), removeZero_of_pos] #align formal_multilinear_series.remove_zero_apply_composition FormalMultilinearSeries.removeZero_applyComposition /-- Technical lemma stating how `p.apply_composition` commutes with updating variables. This will be the key point to show that functions constructed from `apply_composition` retain multilinearity. -/ theorem applyComposition_update (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) (j : Fin n) (v : Fin n → E) (z : E) : p.applyComposition c (Function.update v j z) = Function.update (p.applyComposition c v) (c.index j) (p (c.blocksFun (c.index j)) (Function.update (v ∘ c.embedding (c.index j)) (c.invEmbedding j) z)) := by ext k by_cases h : k = c.index j · rw [h] let r : Fin (c.blocksFun (c.index j)) → Fin n := c.embedding (c.index j) simp only [Function.update_same] change p (c.blocksFun (c.index j)) (Function.update v j z ∘ r) = _ let j' := c.invEmbedding j suffices B : Function.update v j z ∘ r = Function.update (v ∘ r) j' z by rw [B] suffices C : Function.update v (r j') z ∘ r = Function.update (v ∘ r) j' z by convert C; exact (c.embedding_comp_inv j).symm exact Function.update_comp_eq_of_injective _ (c.embedding _).injective _ _ · simp only [h, Function.update_eq_self, Function.update_noteq, Ne, not_false_iff] let r : Fin (c.blocksFun k) → Fin n := c.embedding k change p (c.blocksFun k) (Function.update v j z ∘ r) = p (c.blocksFun k) (v ∘ r) suffices B : Function.update v j z ∘ r = v ∘ r by rw [B] apply Function.update_comp_eq_of_not_mem_range rwa [c.mem_range_embedding_iff'] #align formal_multilinear_series.apply_composition_update FormalMultilinearSeries.applyComposition_update @[simp]
Mathlib/Analysis/Analytic/Composition.lean
166
169
theorem compContinuousLinearMap_applyComposition {n : ℕ} (p : FormalMultilinearSeries 𝕜 F G) (f : E →L[𝕜] F) (c : Composition n) (v : Fin n → E) : (p.compContinuousLinearMap f).applyComposition c v = p.applyComposition c (f ∘ v) := by
simp (config := {unfoldPartialApp := true}) [applyComposition]; rfl
/- 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.NNReal #align_import analysis.special_functions.pow.asymptotics from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8" /-! # Limits and asymptotics of power functions at `+∞` This file contains results about the limiting behaviour of power functions at `+∞`. For convenience some results on asymptotics as `x → 0` (those which are not just continuity statements) are also located here. -/ set_option linter.uppercaseLean3 false noncomputable section open scoped Classical open Real Topology NNReal ENNReal Filter ComplexConjugate Finset Set /-! ## Limits at `+∞` -/ section Limits open Real Filter /-- The function `x ^ y` tends to `+∞` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ y) atTop atTop := by rw [tendsto_atTop_atTop] intro b use max b 0 ^ (1 / y) intro x hx exact le_of_max_le_left (by convert rpow_le_rpow (rpow_nonneg (le_max_right b 0) (1 / y)) hx (le_of_lt hy) using 1 rw [← rpow_mul (le_max_right b 0), (eq_div_iff (ne_of_gt hy)).mp rfl, Real.rpow_one]) #align tendsto_rpow_at_top tendsto_rpow_atTop /-- The function `x ^ (-y)` tends to `0` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_neg_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ (-y)) atTop (𝓝 0) := Tendsto.congr' (eventuallyEq_of_mem (Ioi_mem_atTop 0) fun _ hx => (rpow_neg (le_of_lt hx) y).symm) (tendsto_rpow_atTop hy).inv_tendsto_atTop #align tendsto_rpow_neg_at_top tendsto_rpow_neg_atTop open Asymptotics in lemma tendsto_rpow_atTop_of_base_lt_one (b : ℝ) (hb₀ : -1 < b) (hb₁ : b < 1) : Tendsto (b ^ · : ℝ → ℝ) atTop (𝓝 (0:ℝ)) := by rcases lt_trichotomy b 0 with hb|rfl|hb case inl => -- b < 0 simp_rw [Real.rpow_def_of_nonpos hb.le, hb.ne, ite_false] rw [← isLittleO_const_iff (c := (1:ℝ)) one_ne_zero, (one_mul (1 : ℝ)).symm] refine IsLittleO.mul_isBigO ?exp ?cos case exp => rw [isLittleO_const_iff one_ne_zero] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id rw [← log_neg_eq_log, log_neg_iff (by linarith)] linarith case cos => rw [isBigO_iff] exact ⟨1, eventually_of_forall fun x => by simp [Real.abs_cos_le_one]⟩ case inr.inl => -- b = 0 refine Tendsto.mono_right ?_ (Iff.mpr pure_le_nhds_iff rfl) rw [tendsto_pure] filter_upwards [eventually_ne_atTop 0] with _ hx simp [hx] case inr.inr => -- b > 0 simp_rw [Real.rpow_def_of_pos hb] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id exact (log_neg_iff hb).mpr hb₁ lemma tendsto_rpow_atTop_of_base_gt_one (b : ℝ) (hb : 1 < b) : Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 (0:ℝ)) := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_pos ?_).mpr tendsto_id exact (log_pos_iff (by positivity)).mpr <| by aesop lemma tendsto_rpow_atBot_of_base_lt_one (b : ℝ) (hb₀ : 0 < b) (hb₁ : b < 1) : Tendsto (b ^ · : ℝ → ℝ) atBot atTop := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atTop.comp <| (tendsto_const_mul_atTop_iff_neg <| tendsto_id (α := ℝ)).mpr ?_ exact (log_neg_iff hb₀).mpr hb₁ lemma tendsto_rpow_atBot_of_base_gt_one (b : ℝ) (hb : 1 < b) : Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 0) := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_iff_pos <| tendsto_id (α := ℝ)).mpr ?_ exact (log_pos_iff (by positivity)).mpr <| by aesop /-- The function `x ^ (a / (b * x + c))` tends to `1` at `+∞`, for any real numbers `a`, `b`, and `c` such that `b` is nonzero. -/ theorem tendsto_rpow_div_mul_add (a b c : ℝ) (hb : 0 ≠ b) : Tendsto (fun x => x ^ (a / (b * x + c))) atTop (𝓝 1) := by refine Tendsto.congr' ?_ ((tendsto_exp_nhds_zero_nhds_one.comp (by simpa only [mul_zero, pow_one] using (tendsto_const_nhds (x := a)).mul (tendsto_div_pow_mul_exp_add_atTop b c 1 hb))).comp tendsto_log_atTop) apply eventuallyEq_of_mem (Ioi_mem_atTop (0 : ℝ)) intro x hx simp only [Set.mem_Ioi, Function.comp_apply] at hx ⊢ rw [exp_log hx, ← exp_log (rpow_pos_of_pos hx (a / (b * x + c))), log_rpow hx (a / (b * x + c))] field_simp #align tendsto_rpow_div_mul_add tendsto_rpow_div_mul_add /-- The function `x ^ (1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_div : Tendsto (fun x => x ^ ((1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (1 : ℝ) _ (0 : ℝ) zero_ne_one ring #align tendsto_rpow_div tendsto_rpow_div /-- The function `x ^ (-1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_neg_div : Tendsto (fun x => x ^ (-(1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (-(1 : ℝ)) _ (0 : ℝ) zero_ne_one ring #align tendsto_rpow_neg_div tendsto_rpow_neg_div /-- The function `exp(x) / x ^ s` tends to `+∞` at `+∞`, for any real number `s`. -/ theorem tendsto_exp_div_rpow_atTop (s : ℝ) : Tendsto (fun x : ℝ => exp x / x ^ s) atTop atTop := by cases' archimedean_iff_nat_lt.1 Real.instArchimedean s with n hn refine tendsto_atTop_mono' _ ?_ (tendsto_exp_div_pow_atTop n) filter_upwards [eventually_gt_atTop (0 : ℝ), eventually_ge_atTop (1 : ℝ)] with x hx₀ hx₁ rw [div_le_div_left (exp_pos _) (pow_pos hx₀ _) (rpow_pos_of_pos hx₀ _), ← Real.rpow_natCast] exact rpow_le_rpow_of_exponent_le hx₁ hn.le #align tendsto_exp_div_rpow_at_top tendsto_exp_div_rpow_atTop /-- The function `exp (b * x) / x ^ s` tends to `+∞` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_exp_mul_div_rpow_atTop (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => exp (b * x) / x ^ s) atTop atTop := by refine ((tendsto_rpow_atTop hb).comp (tendsto_exp_div_rpow_atTop (s / b))).congr' ?_ filter_upwards [eventually_ge_atTop (0 : ℝ)] with x hx₀ simp [Real.div_rpow, (exp_pos x).le, rpow_nonneg, ← Real.rpow_mul, ← exp_mul, mul_comm x, hb.ne', *] #align tendsto_exp_mul_div_rpow_at_top tendsto_exp_mul_div_rpow_atTop /-- The function `x ^ s * exp (-b * x)` tends to `0` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => x ^ s * exp (-b * x)) atTop (𝓝 0) := by refine (tendsto_exp_mul_div_rpow_atTop s b hb).inv_tendsto_atTop.congr' ?_ filter_upwards with x using by simp [exp_neg, inv_div, div_eq_mul_inv _ (exp _)] #align tendsto_rpow_mul_exp_neg_mul_at_top_nhds_0 tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero @[deprecated (since := "2024-01-31")] alias tendsto_rpow_mul_exp_neg_mul_atTop_nhds_0 := tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero nonrec theorem NNReal.tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ≥0 => x ^ y) atTop atTop := by rw [Filter.tendsto_atTop_atTop] intro b obtain ⟨c, hc⟩ := tendsto_atTop_atTop.mp (tendsto_rpow_atTop hy) b use c.toNNReal intro a ha exact mod_cast hc a (Real.toNNReal_le_iff_le_coe.mp ha) #align nnreal.tendsto_rpow_at_top NNReal.tendsto_rpow_atTop theorem ENNReal.tendsto_rpow_at_top {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ≥0∞ => x ^ y) (𝓝 ⊤) (𝓝 ⊤) := by rw [ENNReal.tendsto_nhds_top_iff_nnreal] intro x obtain ⟨c, _, hc⟩ := (atTop_basis_Ioi.tendsto_iff atTop_basis_Ioi).mp (NNReal.tendsto_rpow_atTop hy) x trivial have hc' : Set.Ioi ↑c ∈ 𝓝 (⊤ : ℝ≥0∞) := Ioi_mem_nhds ENNReal.coe_lt_top filter_upwards [hc'] with a ha by_cases ha' : a = ⊤ · simp [ha', hy] lift a to ℝ≥0 using ha' -- Porting note: reduced defeq abuse simp only [Set.mem_Ioi, coe_lt_coe] at ha hc rw [ENNReal.coe_rpow_of_nonneg _ hy.le] exact mod_cast hc a ha #align ennreal.tendsto_rpow_at_top ENNReal.tendsto_rpow_at_top end Limits /-! ## Asymptotic results: `IsBigO`, `IsLittleO` and `IsTheta` -/ namespace Complex section variable {α : Type*} {l : Filter α} {f g : α → ℂ} open Asymptotics theorem isTheta_exp_arg_mul_im (hl : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) : (fun x => Real.exp (arg (f x) * im (g x))) =Θ[l] fun _ => (1 : ℝ) := by rcases hl with ⟨b, hb⟩ refine Real.isTheta_exp_comp_one.2 ⟨π * b, ?_⟩ rw [eventually_map] at hb ⊢ refine hb.mono fun x hx => ?_ erw [abs_mul] exact mul_le_mul (abs_arg_le_pi _) hx (abs_nonneg _) Real.pi_pos.le #align complex.is_Theta_exp_arg_mul_im Complex.isTheta_exp_arg_mul_im theorem isBigO_cpow_rpow (hl : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) : (fun x => f x ^ g x) =O[l] fun x => abs (f x) ^ (g x).re := calc (fun x => f x ^ g x) =O[l] (show α → ℝ from fun x => abs (f x) ^ (g x).re / Real.exp (arg (f x) * im (g x))) := isBigO_of_le _ fun x => (abs_cpow_le _ _).trans (le_abs_self _) _ =Θ[l] (show α → ℝ from fun x => abs (f x) ^ (g x).re / (1 : ℝ)) := ((isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl)) _ =ᶠ[l] (show α → ℝ from fun x => abs (f x) ^ (g x).re) := by simp only [ofReal_one, div_one] rfl #align complex.is_O_cpow_rpow Complex.isBigO_cpow_rpow theorem isTheta_cpow_rpow (hl_im : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) (hl : ∀ᶠ x in l, f x = 0 → re (g x) = 0 → g x = 0) : (fun x => f x ^ g x) =Θ[l] fun x => abs (f x) ^ (g x).re := calc (fun x => f x ^ g x) =Θ[l] (show α → ℝ from fun x => abs (f x) ^ (g x).re / Real.exp (arg (f x) * im (g x))) := isTheta_of_norm_eventuallyEq' <| hl.mono fun x => abs_cpow_of_imp _ =Θ[l] (show α → ℝ from fun x => abs (f x) ^ (g x).re / (1 : ℝ)) := ((isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl_im)) _ =ᶠ[l] (show α → ℝ from fun x => abs (f x) ^ (g x).re) := by simp only [ofReal_one, div_one] rfl #align complex.is_Theta_cpow_rpow Complex.isTheta_cpow_rpow theorem isTheta_cpow_const_rpow {b : ℂ} (hl : b.re = 0 → b ≠ 0 → ∀ᶠ x in l, f x ≠ 0) : (fun x => f x ^ b) =Θ[l] fun x => abs (f x) ^ b.re := isTheta_cpow_rpow isBoundedUnder_const <| by -- Porting note: was -- simpa only [eventually_imp_distrib_right, Ne.def, ← not_frequently, not_imp_not, Imp.swap] -- using hl -- but including `Imp.swap` caused an infinite loop convert hl rw [eventually_imp_distrib_right] tauto #align complex.is_Theta_cpow_const_rpow Complex.isTheta_cpow_const_rpow end end Complex open Real namespace Asymptotics variable {α : Type*} {r c : ℝ} {l : Filter α} {f g : α → ℝ} theorem IsBigOWith.rpow (h : IsBigOWith c l f g) (hc : 0 ≤ c) (hr : 0 ≤ r) (hg : 0 ≤ᶠ[l] g) : IsBigOWith (c ^ r) l (fun x => f x ^ r) fun x => g x ^ r := by apply IsBigOWith.of_bound filter_upwards [hg, h.bound] with x hgx hx calc |f x ^ r| ≤ |f x| ^ r := abs_rpow_le_abs_rpow _ _ _ ≤ (c * |g x|) ^ r := rpow_le_rpow (abs_nonneg _) hx hr _ = c ^ r * |g x ^ r| := by rw [mul_rpow hc (abs_nonneg _), abs_rpow_of_nonneg hgx] #align asymptotics.is_O_with.rpow Asymptotics.IsBigOWith.rpow theorem IsBigO.rpow (hr : 0 ≤ r) (hg : 0 ≤ᶠ[l] g) (h : f =O[l] g) : (fun x => f x ^ r) =O[l] fun x => g x ^ r := let ⟨_, hc, h'⟩ := h.exists_nonneg (h'.rpow hc hr hg).isBigO #align asymptotics.is_O.rpow Asymptotics.IsBigO.rpow theorem IsTheta.rpow (hr : 0 ≤ r) (hf : 0 ≤ᶠ[l] f) (hg : 0 ≤ᶠ[l] g) (h : f =Θ[l] g) : (fun x => f x ^ r) =Θ[l] fun x => g x ^ r := ⟨h.1.rpow hr hg, h.2.rpow hr hf⟩ theorem IsLittleO.rpow (hr : 0 < r) (hg : 0 ≤ᶠ[l] g) (h : f =o[l] g) : (fun x => f x ^ r) =o[l] fun x => g x ^ r := by refine .of_isBigOWith fun c hc ↦ ?_ rw [← rpow_inv_rpow hc.le hr.ne'] refine (h.forall_isBigOWith ?_).rpow ?_ ?_ hg <;> positivity #align asymptotics.is_o.rpow Asymptotics.IsLittleO.rpow protected lemma IsBigO.sqrt (hfg : f =O[l] g) (hg : 0 ≤ᶠ[l] g) : (Real.sqrt <| f ·) =O[l] (Real.sqrt <| g ·) := by simpa [Real.sqrt_eq_rpow] using hfg.rpow one_half_pos.le hg protected lemma IsLittleO.sqrt (hfg : f =o[l] g) (hg : 0 ≤ᶠ[l] g) : (Real.sqrt <| f ·) =o[l] (Real.sqrt <| g ·) := by simpa [Real.sqrt_eq_rpow] using hfg.rpow one_half_pos hg protected lemma IsTheta.sqrt (hfg : f =Θ[l] g) (hf : 0 ≤ᶠ[l] f) (hg : 0 ≤ᶠ[l] g) : (Real.sqrt <| f ·) =Θ[l] (Real.sqrt <| g ·) := ⟨hfg.1.sqrt hg, hfg.2.sqrt hf⟩ end Asymptotics open Asymptotics /-- `x ^ s = o(exp(b * x))` as `x → ∞` for any real `s` and positive `b`. -/ theorem isLittleO_rpow_exp_pos_mul_atTop (s : ℝ) {b : ℝ} (hb : 0 < b) : (fun x : ℝ => x ^ s) =o[atTop] fun x => exp (b * x) := isLittleO_of_tendsto (fun x h => absurd h (exp_pos _).ne') <| by simpa only [div_eq_mul_inv, exp_neg, neg_mul] using tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero s b hb #align is_o_rpow_exp_pos_mul_at_top isLittleO_rpow_exp_pos_mul_atTop /-- `x ^ k = o(exp(b * x))` as `x → ∞` for any integer `k` and positive `b`. -/
Mathlib/Analysis/SpecialFunctions/Pow/Asymptotics.lean
311
313
theorem isLittleO_zpow_exp_pos_mul_atTop (k : ℤ) {b : ℝ} (hb : 0 < b) : (fun x : ℝ => x ^ k) =o[atTop] fun x => exp (b * x) := by
simpa only [Real.rpow_intCast] using isLittleO_rpow_exp_pos_mul_atTop k hb
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Subgraph import Mathlib.Data.List.Rotate #align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4" /-! # Graph connectivity In a simple graph, * A *walk* is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges. * A *trail* is a walk whose edges each appear no more than once. * A *path* is a trail whose vertices appear no more than once. * A *cycle* is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once. **Warning:** graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path." Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994]. ## Main definitions * `SimpleGraph.Walk` (with accompanying pattern definitions `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`) * `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`. * `SimpleGraph.Path` * `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks, given an (injective) graph homomorphism. * `SimpleGraph.Reachable` for the relation of whether there exists a walk between a given pair of vertices * `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty. * `SimpleGraph.ConnectedComponent` is the type of connected components of a given graph. * `SimpleGraph.IsBridge` for whether an edge is a bridge edge ## Main statements * `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of there being no cycle containing them. ## Tags walks, trails, paths, circuits, cycles, bridge edges -/ open Function universe u v w namespace SimpleGraph variable {V : Type u} {V' : Type v} {V'' : Type w} variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'') /-- A walk is a sequence of adjacent vertices. For vertices `u v : V`, the type `walk u v` consists of all walks starting at `u` and ending at `v`. We say that a walk *visits* the vertices it contains. The set of vertices a walk visits is `SimpleGraph.Walk.support`. See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that can be useful in definitions since they make the vertices explicit. -/ inductive Walk : V → V → Type u | nil {u : V} : Walk u u | cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w deriving DecidableEq #align simple_graph.walk SimpleGraph.Walk attribute [refl] Walk.nil @[simps] instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩ #align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited /-- The one-edge walk associated to a pair of adjacent vertices. -/ @[match_pattern, reducible] def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v := Walk.cons h Walk.nil #align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk namespace Walk variable {G} /-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/ @[match_pattern] abbrev nil' (u : V) : G.Walk u u := Walk.nil #align simple_graph.walk.nil' SimpleGraph.Walk.nil' /-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/ @[match_pattern] abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p #align simple_graph.walk.cons' SimpleGraph.Walk.cons' /-- Change the endpoints of a walk using equalities. This is helpful for relaxing definitional equality constraints and to be able to state otherwise difficult-to-state lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it. The simp-normal form is for the `copy` to be pushed outward. That way calculations can occur within the "copy context." -/ protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' := hu ▸ hv ▸ p #align simple_graph.walk.copy SimpleGraph.Walk.copy @[simp] theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl #align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl @[simp] theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v) (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') : (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by subst_vars rfl #align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy @[simp] theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by subst_vars rfl #align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') : (Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by subst_vars rfl #align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons @[simp] theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) : Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by subst_vars rfl #align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) : ∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p' | nil => (hne rfl).elim | cons h p' => ⟨_, h, p', rfl⟩ #align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne /-- The length of a walk is the number of edges/darts along it. -/ def length {u v : V} : G.Walk u v → ℕ | nil => 0 | cons _ q => q.length.succ #align simple_graph.walk.length SimpleGraph.Walk.length /-- The concatenation of two compatible walks. -/ @[trans] def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w | nil, q => q | cons h p, q => cons h (p.append q) #align simple_graph.walk.append SimpleGraph.Walk.append /-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to the end of a walk. -/ def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil) #align simple_graph.walk.concat SimpleGraph.Walk.concat theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : p.concat h = p.append (cons h nil) := rfl #align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append /-- The concatenation of the reverse of the first walk with the second walk. -/ protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w | nil, q => q | cons h p, q => Walk.reverseAux p (cons (G.symm h) q) #align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux /-- The walk in reverse. -/ @[symm] def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil #align simple_graph.walk.reverse SimpleGraph.Walk.reverse /-- Get the `n`th vertex from a walk, where `n` is generally expected to be between `0` and `p.length`, inclusive. If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/ def getVert {u v : V} : G.Walk u v → ℕ → V | nil, _ => u | cons _ _, 0 => u | cons _ q, n + 1 => q.getVert n #align simple_graph.walk.get_vert SimpleGraph.Walk.getVert @[simp] theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl #align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) : w.getVert i = v := by induction w generalizing i with | nil => rfl | cons _ _ ih => cases i · cases hi · exact ih (Nat.succ_le_succ_iff.1 hi) #align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le @[simp] theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v := w.getVert_of_length_le rfl.le #align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) : G.Adj (w.getVert i) (w.getVert (i + 1)) := by induction w generalizing i with | nil => cases hi | cons hxy _ ih => cases i · simp [getVert, hxy] · exact ih (Nat.succ_lt_succ_iff.1 hi) #align simple_graph.walk.adj_get_vert_succ SimpleGraph.Walk.adj_getVert_succ @[simp] theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) : (cons h p).append q = cons h (p.append q) := rfl #align simple_graph.walk.cons_append SimpleGraph.Walk.cons_append @[simp] theorem cons_nil_append {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h nil).append p = cons h p := rfl #align simple_graph.walk.cons_nil_append SimpleGraph.Walk.cons_nil_append @[simp] theorem append_nil {u v : V} (p : G.Walk u v) : p.append nil = p := by induction p with | nil => rfl | cons _ _ ih => rw [cons_append, ih] #align simple_graph.walk.append_nil SimpleGraph.Walk.append_nil @[simp] theorem nil_append {u v : V} (p : G.Walk u v) : nil.append p = p := rfl #align simple_graph.walk.nil_append SimpleGraph.Walk.nil_append theorem append_assoc {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk w x) : p.append (q.append r) = (p.append q).append r := by induction p with | nil => rfl | cons h p' ih => dsimp only [append] rw [ih] #align simple_graph.walk.append_assoc SimpleGraph.Walk.append_assoc @[simp] theorem append_copy_copy {u v w u' v' w'} (p : G.Walk u v) (q : G.Walk v w) (hu : u = u') (hv : v = v') (hw : w = w') : (p.copy hu hv).append (q.copy hv hw) = (p.append q).copy hu hw := by subst_vars rfl #align simple_graph.walk.append_copy_copy SimpleGraph.Walk.append_copy_copy theorem concat_nil {u v : V} (h : G.Adj u v) : nil.concat h = cons h nil := rfl #align simple_graph.walk.concat_nil SimpleGraph.Walk.concat_nil @[simp] theorem concat_cons {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (h' : G.Adj w x) : (cons h p).concat h' = cons h (p.concat h') := rfl #align simple_graph.walk.concat_cons SimpleGraph.Walk.concat_cons theorem append_concat {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (h : G.Adj w x) : p.append (q.concat h) = (p.append q).concat h := append_assoc _ _ _ #align simple_graph.walk.append_concat SimpleGraph.Walk.append_concat theorem concat_append {u v w x : V} (p : G.Walk u v) (h : G.Adj v w) (q : G.Walk w x) : (p.concat h).append q = p.append (cons h q) := by rw [concat_eq_append, ← append_assoc, cons_nil_append] #align simple_graph.walk.concat_append SimpleGraph.Walk.concat_append /-- A non-trivial `cons` walk is representable as a `concat` walk. -/ theorem exists_cons_eq_concat {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : ∃ (x : V) (q : G.Walk u x) (h' : G.Adj x w), cons h p = q.concat h' := by induction p generalizing u with | nil => exact ⟨_, nil, h, rfl⟩ | cons h' p ih => obtain ⟨y, q, h'', hc⟩ := ih h' refine ⟨y, cons h q, h'', ?_⟩ rw [concat_cons, hc] #align simple_graph.walk.exists_cons_eq_concat SimpleGraph.Walk.exists_cons_eq_concat /-- A non-trivial `concat` walk is representable as a `cons` walk. -/ theorem exists_concat_eq_cons {u v w : V} : ∀ (p : G.Walk u v) (h : G.Adj v w), ∃ (x : V) (h' : G.Adj u x) (q : G.Walk x w), p.concat h = cons h' q | nil, h => ⟨_, h, nil, rfl⟩ | cons h' p, h => ⟨_, h', Walk.concat p h, concat_cons _ _ _⟩ #align simple_graph.walk.exists_concat_eq_cons SimpleGraph.Walk.exists_concat_eq_cons @[simp] theorem reverse_nil {u : V} : (nil : G.Walk u u).reverse = nil := rfl #align simple_graph.walk.reverse_nil SimpleGraph.Walk.reverse_nil theorem reverse_singleton {u v : V} (h : G.Adj u v) : (cons h nil).reverse = cons (G.symm h) nil := rfl #align simple_graph.walk.reverse_singleton SimpleGraph.Walk.reverse_singleton @[simp] theorem cons_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk w x) (h : G.Adj w u) : (cons h p).reverseAux q = p.reverseAux (cons (G.symm h) q) := rfl #align simple_graph.walk.cons_reverse_aux SimpleGraph.Walk.cons_reverseAux @[simp] protected theorem append_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk u x) : (p.append q).reverseAux r = q.reverseAux (p.reverseAux r) := by induction p with | nil => rfl | cons h _ ih => exact ih q (cons (G.symm h) r) #align simple_graph.walk.append_reverse_aux SimpleGraph.Walk.append_reverseAux @[simp] protected theorem reverseAux_append {u v w x : V} (p : G.Walk u v) (q : G.Walk u w) (r : G.Walk w x) : (p.reverseAux q).append r = p.reverseAux (q.append r) := by induction p with | nil => rfl | cons h _ ih => simp [ih (cons (G.symm h) q)] #align simple_graph.walk.reverse_aux_append SimpleGraph.Walk.reverseAux_append protected theorem reverseAux_eq_reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : p.reverseAux q = p.reverse.append q := by simp [reverse] #align simple_graph.walk.reverse_aux_eq_reverse_append SimpleGraph.Walk.reverseAux_eq_reverse_append @[simp] theorem reverse_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).reverse = p.reverse.append (cons (G.symm h) nil) := by simp [reverse] #align simple_graph.walk.reverse_cons SimpleGraph.Walk.reverse_cons @[simp] theorem reverse_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).reverse = p.reverse.copy hv hu := by subst_vars rfl #align simple_graph.walk.reverse_copy SimpleGraph.Walk.reverse_copy @[simp] theorem reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).reverse = q.reverse.append p.reverse := by simp [reverse] #align simple_graph.walk.reverse_append SimpleGraph.Walk.reverse_append @[simp] theorem reverse_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).reverse = cons (G.symm h) p.reverse := by simp [concat_eq_append] #align simple_graph.walk.reverse_concat SimpleGraph.Walk.reverse_concat @[simp] theorem reverse_reverse {u v : V} (p : G.Walk u v) : p.reverse.reverse = p := by induction p with | nil => rfl | cons _ _ ih => simp [ih] #align simple_graph.walk.reverse_reverse SimpleGraph.Walk.reverse_reverse @[simp] theorem length_nil {u : V} : (nil : G.Walk u u).length = 0 := rfl #align simple_graph.walk.length_nil SimpleGraph.Walk.length_nil @[simp] theorem length_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).length = p.length + 1 := rfl #align simple_graph.walk.length_cons SimpleGraph.Walk.length_cons @[simp] theorem length_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).length = p.length := by subst_vars rfl #align simple_graph.walk.length_copy SimpleGraph.Walk.length_copy @[simp] theorem length_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).length = p.length + q.length := by induction p with | nil => simp | cons _ _ ih => simp [ih, add_comm, add_left_comm, add_assoc] #align simple_graph.walk.length_append SimpleGraph.Walk.length_append @[simp] theorem length_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).length = p.length + 1 := length_append _ _ #align simple_graph.walk.length_concat SimpleGraph.Walk.length_concat @[simp] protected theorem length_reverseAux {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : (p.reverseAux q).length = p.length + q.length := by induction p with | nil => simp! | cons _ _ ih => simp [ih, Nat.succ_add, Nat.add_assoc] #align simple_graph.walk.length_reverse_aux SimpleGraph.Walk.length_reverseAux @[simp] theorem length_reverse {u v : V} (p : G.Walk u v) : p.reverse.length = p.length := by simp [reverse] #align simple_graph.walk.length_reverse SimpleGraph.Walk.length_reverse theorem eq_of_length_eq_zero {u v : V} : ∀ {p : G.Walk u v}, p.length = 0 → u = v | nil, _ => rfl #align simple_graph.walk.eq_of_length_eq_zero SimpleGraph.Walk.eq_of_length_eq_zero theorem adj_of_length_eq_one {u v : V} : ∀ {p : G.Walk u v}, p.length = 1 → G.Adj u v | cons h nil, _ => h @[simp] theorem exists_length_eq_zero_iff {u v : V} : (∃ p : G.Walk u v, p.length = 0) ↔ u = v := by constructor · rintro ⟨p, hp⟩ exact eq_of_length_eq_zero hp · rintro rfl exact ⟨nil, rfl⟩ #align simple_graph.walk.exists_length_eq_zero_iff SimpleGraph.Walk.exists_length_eq_zero_iff @[simp] theorem length_eq_zero_iff {u : V} {p : G.Walk u u} : p.length = 0 ↔ p = nil := by cases p <;> simp #align simple_graph.walk.length_eq_zero_iff SimpleGraph.Walk.length_eq_zero_iff theorem getVert_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) (i : ℕ) : (p.append q).getVert i = if i < p.length then p.getVert i else q.getVert (i - p.length) := by induction p generalizing i with | nil => simp | cons h p ih => cases i <;> simp [getVert, ih, Nat.succ_lt_succ_iff] theorem getVert_reverse {u v : V} (p : G.Walk u v) (i : ℕ) : p.reverse.getVert i = p.getVert (p.length - i) := by induction p with | nil => rfl | cons h p ih => simp only [reverse_cons, getVert_append, length_reverse, ih, length_cons] split_ifs next hi => rw [Nat.succ_sub hi.le] simp [getVert] next hi => obtain rfl | hi' := Nat.eq_or_lt_of_not_lt hi · simp [getVert] · rw [Nat.eq_add_of_sub_eq (Nat.sub_pos_of_lt hi') rfl, Nat.sub_eq_zero_of_le hi'] simp [getVert] section ConcatRec variable {motive : ∀ u v : V, G.Walk u v → Sort*} (Hnil : ∀ {u : V}, motive u u nil) (Hconcat : ∀ {u v w : V} (p : G.Walk u v) (h : G.Adj v w), motive u v p → motive u w (p.concat h)) /-- Auxiliary definition for `SimpleGraph.Walk.concatRec` -/ def concatRecAux {u v : V} : (p : G.Walk u v) → motive v u p.reverse | nil => Hnil | cons h p => reverse_cons h p ▸ Hconcat p.reverse h.symm (concatRecAux p) #align simple_graph.walk.concat_rec_aux SimpleGraph.Walk.concatRecAux /-- Recursor on walks by inducting on `SimpleGraph.Walk.concat`. This is inducting from the opposite end of the walk compared to `SimpleGraph.Walk.rec`, which inducts on `SimpleGraph.Walk.cons`. -/ @[elab_as_elim] def concatRec {u v : V} (p : G.Walk u v) : motive u v p := reverse_reverse p ▸ concatRecAux @Hnil @Hconcat p.reverse #align simple_graph.walk.concat_rec SimpleGraph.Walk.concatRec @[simp] theorem concatRec_nil (u : V) : @concatRec _ _ motive @Hnil @Hconcat _ _ (nil : G.Walk u u) = Hnil := rfl #align simple_graph.walk.concat_rec_nil SimpleGraph.Walk.concatRec_nil @[simp] theorem concatRec_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : @concatRec _ _ motive @Hnil @Hconcat _ _ (p.concat h) = Hconcat p h (concatRec @Hnil @Hconcat p) := by simp only [concatRec] apply eq_of_heq apply rec_heq_of_heq trans concatRecAux @Hnil @Hconcat (cons h.symm p.reverse) · congr simp · rw [concatRecAux, rec_heq_iff_heq] congr <;> simp [heq_rec_iff_heq] #align simple_graph.walk.concat_rec_concat SimpleGraph.Walk.concatRec_concat end ConcatRec theorem concat_ne_nil {u v : V} (p : G.Walk u v) (h : G.Adj v u) : p.concat h ≠ nil := by cases p <;> simp [concat] #align simple_graph.walk.concat_ne_nil SimpleGraph.Walk.concat_ne_nil theorem concat_inj {u v v' w : V} {p : G.Walk u v} {h : G.Adj v w} {p' : G.Walk u v'} {h' : G.Adj v' w} (he : p.concat h = p'.concat h') : ∃ hv : v = v', p.copy rfl hv = p' := by induction p with | nil => cases p' · exact ⟨rfl, rfl⟩ · exfalso simp only [concat_nil, concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he simp only [heq_iff_eq] at he exact concat_ne_nil _ _ he.symm | cons _ _ ih => rw [concat_cons] at he cases p' · exfalso simp only [concat_nil, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he exact concat_ne_nil _ _ he · rw [concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he obtain ⟨rfl, rfl⟩ := ih he exact ⟨rfl, rfl⟩ #align simple_graph.walk.concat_inj SimpleGraph.Walk.concat_inj /-- The `support` of a walk is the list of vertices it visits in order. -/ def support {u v : V} : G.Walk u v → List V | nil => [u] | cons _ p => u :: p.support #align simple_graph.walk.support SimpleGraph.Walk.support /-- The `darts` of a walk is the list of darts it visits in order. -/ def darts {u v : V} : G.Walk u v → List G.Dart | nil => [] | cons h p => ⟨(u, _), h⟩ :: p.darts #align simple_graph.walk.darts SimpleGraph.Walk.darts /-- The `edges` of a walk is the list of edges it visits in order. This is defined to be the list of edges underlying `SimpleGraph.Walk.darts`. -/ def edges {u v : V} (p : G.Walk u v) : List (Sym2 V) := p.darts.map Dart.edge #align simple_graph.walk.edges SimpleGraph.Walk.edges @[simp] theorem support_nil {u : V} : (nil : G.Walk u u).support = [u] := rfl #align simple_graph.walk.support_nil SimpleGraph.Walk.support_nil @[simp] theorem support_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).support = u :: p.support := rfl #align simple_graph.walk.support_cons SimpleGraph.Walk.support_cons @[simp] theorem support_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).support = p.support.concat w := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.support_concat SimpleGraph.Walk.support_concat @[simp] theorem support_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).support = p.support := by subst_vars rfl #align simple_graph.walk.support_copy SimpleGraph.Walk.support_copy theorem support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support = p.support ++ p'.support.tail := by induction p <;> cases p' <;> simp [*] #align simple_graph.walk.support_append SimpleGraph.Walk.support_append @[simp] theorem support_reverse {u v : V} (p : G.Walk u v) : p.reverse.support = p.support.reverse := by induction p <;> simp [support_append, *] #align simple_graph.walk.support_reverse SimpleGraph.Walk.support_reverse @[simp] theorem support_ne_nil {u v : V} (p : G.Walk u v) : p.support ≠ [] := by cases p <;> simp #align simple_graph.walk.support_ne_nil SimpleGraph.Walk.support_ne_nil theorem tail_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support.tail = p.support.tail ++ p'.support.tail := by rw [support_append, List.tail_append_of_ne_nil _ _ (support_ne_nil _)] #align simple_graph.walk.tail_support_append SimpleGraph.Walk.tail_support_append theorem support_eq_cons {u v : V} (p : G.Walk u v) : p.support = u :: p.support.tail := by cases p <;> simp #align simple_graph.walk.support_eq_cons SimpleGraph.Walk.support_eq_cons @[simp] theorem start_mem_support {u v : V} (p : G.Walk u v) : u ∈ p.support := by cases p <;> simp #align simple_graph.walk.start_mem_support SimpleGraph.Walk.start_mem_support @[simp] theorem end_mem_support {u v : V} (p : G.Walk u v) : v ∈ p.support := by induction p <;> simp [*] #align simple_graph.walk.end_mem_support SimpleGraph.Walk.end_mem_support @[simp] theorem support_nonempty {u v : V} (p : G.Walk u v) : { w | w ∈ p.support }.Nonempty := ⟨u, by simp⟩ #align simple_graph.walk.support_nonempty SimpleGraph.Walk.support_nonempty theorem mem_support_iff {u v w : V} (p : G.Walk u v) : w ∈ p.support ↔ w = u ∨ w ∈ p.support.tail := by cases p <;> simp #align simple_graph.walk.mem_support_iff SimpleGraph.Walk.mem_support_iff theorem mem_support_nil_iff {u v : V} : u ∈ (nil : G.Walk v v).support ↔ u = v := by simp #align simple_graph.walk.mem_support_nil_iff SimpleGraph.Walk.mem_support_nil_iff @[simp] theorem mem_tail_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support.tail ↔ t ∈ p.support.tail ∨ t ∈ p'.support.tail := by rw [tail_support_append, List.mem_append] #align simple_graph.walk.mem_tail_support_append_iff SimpleGraph.Walk.mem_tail_support_append_iff @[simp] theorem end_mem_tail_support_of_ne {u v : V} (h : u ≠ v) (p : G.Walk u v) : v ∈ p.support.tail := by obtain ⟨_, _, _, rfl⟩ := exists_eq_cons_of_ne h p simp #align simple_graph.walk.end_mem_tail_support_of_ne SimpleGraph.Walk.end_mem_tail_support_of_ne @[simp, nolint unusedHavesSuffices] theorem mem_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support ↔ t ∈ p.support ∨ t ∈ p'.support := by simp only [mem_support_iff, mem_tail_support_append_iff] obtain rfl | h := eq_or_ne t v <;> obtain rfl | h' := eq_or_ne t u <;> -- this `have` triggers the unusedHavesSuffices linter: (try have := h'.symm) <;> simp [*] #align simple_graph.walk.mem_support_append_iff SimpleGraph.Walk.mem_support_append_iff @[simp] theorem subset_support_append_left {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : p.support ⊆ (p.append q).support := by simp only [Walk.support_append, List.subset_append_left] #align simple_graph.walk.subset_support_append_left SimpleGraph.Walk.subset_support_append_left @[simp] theorem subset_support_append_right {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : q.support ⊆ (p.append q).support := by intro h simp (config := { contextual := true }) only [mem_support_append_iff, or_true_iff, imp_true_iff] #align simple_graph.walk.subset_support_append_right SimpleGraph.Walk.subset_support_append_right
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
645
646
theorem coe_support {u v : V} (p : G.Walk u v) : (p.support : Multiset V) = {u} + p.support.tail := by
cases p <;> rfl
/- 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.Group.Basic import Mathlib.Algebra.GroupWithZero.NeZero import Mathlib.Logic.Unique #align_import algebra.group_with_zero.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Groups with an adjoined zero element This file describes structures that are not usually studied on their own right in mathematics, namely a special sort of monoid: apart from a distinguished “zero element” they form a group, or in other words, they are groups with an adjoined zero element. Examples are: * division rings; * the value monoid of a multiplicative valuation; * in particular, the non-negative real numbers. ## Main definitions Various lemmas about `GroupWithZero` and `CommGroupWithZero`. To reduce import dependencies, the type-classes themselves are in `Algebra.GroupWithZero.Defs`. ## Implementation details As is usual in mathlib, we extend the inverse function to the zero element, and require `0⁻¹ = 0`. -/ assert_not_exists DenselyOrdered open scoped Classical open Function variable {α M₀ G₀ M₀' G₀' F F' : Type*} section section MulZeroClass variable [MulZeroClass M₀] {a b : M₀} theorem left_ne_zero_of_mul : a * b ≠ 0 → a ≠ 0 := mt fun h => mul_eq_zero_of_left h b #align left_ne_zero_of_mul left_ne_zero_of_mul theorem right_ne_zero_of_mul : a * b ≠ 0 → b ≠ 0 := mt (mul_eq_zero_of_right a) #align right_ne_zero_of_mul right_ne_zero_of_mul theorem ne_zero_and_ne_zero_of_mul (h : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 := ⟨left_ne_zero_of_mul h, right_ne_zero_of_mul h⟩ #align ne_zero_and_ne_zero_of_mul ne_zero_and_ne_zero_of_mul theorem mul_eq_zero_of_ne_zero_imp_eq_zero {a b : M₀} (h : a ≠ 0 → b = 0) : a * b = 0 := if ha : a = 0 then by rw [ha, zero_mul] else by rw [h ha, mul_zero] #align mul_eq_zero_of_ne_zero_imp_eq_zero mul_eq_zero_of_ne_zero_imp_eq_zero /-- To match `one_mul_eq_id`. -/ theorem zero_mul_eq_const : ((0 : M₀) * ·) = Function.const _ 0 := funext zero_mul #align zero_mul_eq_const zero_mul_eq_const /-- To match `mul_one_eq_id`. -/ theorem mul_zero_eq_const : (· * (0 : M₀)) = Function.const _ 0 := funext mul_zero #align mul_zero_eq_const mul_zero_eq_const end MulZeroClass section Mul variable [Mul M₀] [Zero M₀] [NoZeroDivisors M₀] {a b : M₀} theorem eq_zero_of_mul_self_eq_zero (h : a * a = 0) : a = 0 := (eq_zero_or_eq_zero_of_mul_eq_zero h).elim id id #align eq_zero_of_mul_self_eq_zero eq_zero_of_mul_self_eq_zero @[field_simps] theorem mul_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a * b ≠ 0 := mt eq_zero_or_eq_zero_of_mul_eq_zero <| not_or.mpr ⟨ha, hb⟩ #align mul_ne_zero mul_ne_zero end Mul namespace NeZero instance mul [Zero M₀] [Mul M₀] [NoZeroDivisors M₀] {x y : M₀} [NeZero x] [NeZero y] : NeZero (x * y) := ⟨mul_ne_zero out out⟩ end NeZero end section variable [MulZeroOneClass M₀] /-- In a monoid with zero, if zero equals one, then zero is the only element. -/ theorem eq_zero_of_zero_eq_one (h : (0 : M₀) = 1) (a : M₀) : a = 0 := by rw [← mul_one a, ← h, mul_zero] #align eq_zero_of_zero_eq_one eq_zero_of_zero_eq_one /-- In a monoid with zero, if zero equals one, then zero is the unique element. Somewhat arbitrarily, we define the default element to be `0`. All other elements will be provably equal to it, but not necessarily definitionally equal. -/ def uniqueOfZeroEqOne (h : (0 : M₀) = 1) : Unique M₀ where default := 0 uniq := eq_zero_of_zero_eq_one h #align unique_of_zero_eq_one uniqueOfZeroEqOne /-- In a monoid with zero, zero equals one if and only if all elements of that semiring are equal. -/ theorem subsingleton_iff_zero_eq_one : (0 : M₀) = 1 ↔ Subsingleton M₀ := ⟨fun h => haveI := uniqueOfZeroEqOne h; inferInstance, fun h => @Subsingleton.elim _ h _ _⟩ #align subsingleton_iff_zero_eq_one subsingleton_iff_zero_eq_one alias ⟨subsingleton_of_zero_eq_one, _⟩ := subsingleton_iff_zero_eq_one #align subsingleton_of_zero_eq_one subsingleton_of_zero_eq_one theorem eq_of_zero_eq_one (h : (0 : M₀) = 1) (a b : M₀) : a = b := @Subsingleton.elim _ (subsingleton_of_zero_eq_one h) a b #align eq_of_zero_eq_one eq_of_zero_eq_one /-- In a monoid with zero, either zero and one are nonequal, or zero is the only element. -/ theorem zero_ne_one_or_forall_eq_0 : (0 : M₀) ≠ 1 ∨ ∀ a : M₀, a = 0 := not_or_of_imp eq_zero_of_zero_eq_one #align zero_ne_one_or_forall_eq_0 zero_ne_one_or_forall_eq_0 end section variable [MulZeroOneClass M₀] [Nontrivial M₀] {a b : M₀} theorem left_ne_zero_of_mul_eq_one (h : a * b = 1) : a ≠ 0 := left_ne_zero_of_mul <| ne_zero_of_eq_one h #align left_ne_zero_of_mul_eq_one left_ne_zero_of_mul_eq_one theorem right_ne_zero_of_mul_eq_one (h : a * b = 1) : b ≠ 0 := right_ne_zero_of_mul <| ne_zero_of_eq_one h #align right_ne_zero_of_mul_eq_one right_ne_zero_of_mul_eq_one end section MonoidWithZero variable [MonoidWithZero M₀] {a : M₀} {m n : ℕ} @[simp] lemma zero_pow : ∀ {n : ℕ}, n ≠ 0 → (0 : M₀) ^ n = 0 | n + 1, _ => by rw [pow_succ, mul_zero] #align zero_pow zero_pow #align zero_pow' zero_pow lemma zero_pow_eq (n : ℕ) : (0 : M₀) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, pow_zero] · rw [zero_pow h] #align zero_pow_eq zero_pow_eq lemma pow_eq_zero_of_le : ∀ {m n} (hmn : m ≤ n) (ha : a ^ m = 0), a ^ n = 0 | _, _, Nat.le.refl, ha => ha | _, _, Nat.le.step hmn, ha => by rw [pow_succ, pow_eq_zero_of_le hmn ha, zero_mul] #align pow_eq_zero_of_le pow_eq_zero_of_le lemma ne_zero_pow (hn : n ≠ 0) (ha : a ^ n ≠ 0) : a ≠ 0 := by rintro rfl; exact ha $ zero_pow hn #align ne_zero_pow ne_zero_pow @[simp] lemma zero_pow_eq_zero [Nontrivial M₀] : (0 : M₀) ^ n = 0 ↔ n ≠ 0 := ⟨by rintro h rfl; simp at h, zero_pow⟩ #align zero_pow_eq_zero zero_pow_eq_zero variable [NoZeroDivisors M₀] lemma pow_eq_zero : ∀ {n}, a ^ n = 0 → a = 0 | 0, ha => by simpa using congr_arg (a * ·) ha | n + 1, ha => by rw [pow_succ, mul_eq_zero] at ha; exact ha.elim pow_eq_zero id #align pow_eq_zero pow_eq_zero @[simp] lemma pow_eq_zero_iff (hn : n ≠ 0) : a ^ n = 0 ↔ a = 0 := ⟨pow_eq_zero, by rintro rfl; exact zero_pow hn⟩ #align pow_eq_zero_iff pow_eq_zero_iff lemma pow_ne_zero_iff (hn : n ≠ 0) : a ^ n ≠ 0 ↔ a ≠ 0 := (pow_eq_zero_iff hn).not #align pow_ne_zero_iff pow_ne_zero_iff @[field_simps] lemma pow_ne_zero (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 := mt pow_eq_zero h #align pow_ne_zero pow_ne_zero instance NeZero.pow [NeZero a] : NeZero (a ^ n) := ⟨pow_ne_zero n NeZero.out⟩ #align ne_zero.pow NeZero.pow lemma sq_eq_zero_iff : a ^ 2 = 0 ↔ a = 0 := pow_eq_zero_iff two_ne_zero #align sq_eq_zero_iff sq_eq_zero_iff @[simp] lemma pow_eq_zero_iff' [Nontrivial M₀] : a ^ n = 0 ↔ a = 0 ∧ n ≠ 0 := by obtain rfl | hn := eq_or_ne n 0 <;> simp [*] #align pow_eq_zero_iff' pow_eq_zero_iff' end MonoidWithZero section CancelMonoidWithZero variable [CancelMonoidWithZero M₀] {a b c : M₀} -- see Note [lower instance priority] instance (priority := 10) CancelMonoidWithZero.to_noZeroDivisors : NoZeroDivisors M₀ := ⟨fun ab0 => or_iff_not_imp_left.mpr fun ha => mul_left_cancel₀ ha <| ab0.trans (mul_zero _).symm⟩ #align cancel_monoid_with_zero.to_no_zero_divisors CancelMonoidWithZero.to_noZeroDivisors @[simp] theorem mul_eq_mul_right_iff : a * c = b * c ↔ a = b ∨ c = 0 := by by_cases hc : c = 0 <;> [simp only [hc, mul_zero, or_true]; simp [mul_left_inj', hc]] #align mul_eq_mul_right_iff mul_eq_mul_right_iff @[simp] theorem mul_eq_mul_left_iff : a * b = a * c ↔ b = c ∨ a = 0 := by by_cases ha : a = 0 <;> [simp only [ha, zero_mul, or_true]; simp [mul_right_inj', ha]] #align mul_eq_mul_left_iff mul_eq_mul_left_iff theorem mul_right_eq_self₀ : a * b = a ↔ b = 1 ∨ a = 0 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 ∨ a = 0 := mul_eq_mul_left_iff #align mul_right_eq_self₀ mul_right_eq_self₀ theorem mul_left_eq_self₀ : a * b = b ↔ a = 1 ∨ b = 0 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 ∨ b = 0 := mul_eq_mul_right_iff #align mul_left_eq_self₀ mul_left_eq_self₀ @[simp]
Mathlib/Algebra/GroupWithZero/Basic.lean
248
249
theorem mul_eq_left₀ (ha : a ≠ 0) : a * b = a ↔ b = 1 := by
rw [Iff.comm, ← mul_right_inj' ha, mul_one]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Aurélien Saue, Anne Baanen -/ import Mathlib.Algebra.Order.Ring.Rat import Mathlib.Tactic.NormNum.Inv import Mathlib.Tactic.NormNum.Pow import Mathlib.Util.AtomM /-! # `ring` tactic A tactic for solving equations in commutative (semi)rings, where the exponents can also contain variables. Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> . More precisely, expressions of the following form are supported: - constants (non-negative integers) - variables - coefficients (any rational number, embedded into the (semi)ring) - addition of expressions - multiplication of expressions (`a * b`) - scalar multiplication of expressions (`n • a`; the multiplier must have type `ℕ`) - exponentiation of expressions (the exponent must have type `ℕ`) - subtraction and negation of expressions (if the base is a full ring) The extension to exponents means that something like `2 * 2^n * b = b * 2^(n+1)` can be proved, even though it is not strictly speaking an equation in the language of commutative rings. ## Implementation notes The basic approach to prove equalities is to normalise both sides and check for equality. The normalisation is guided by building a value in the type `ExSum` at the meta level, together with a proof (at the base level) that the original value is equal to the normalised version. The outline of the file: - Define a mutual inductive family of types `ExSum`, `ExProd`, `ExBase`, which can represent expressions with `+`, `*`, `^` and rational numerals. The mutual induction ensures that associativity and distributivity are applied, by restricting which kinds of subexpressions appear as arguments to the various operators. - Represent addition, multiplication and exponentiation in the `ExSum` type, thus allowing us to map expressions to `ExSum` (the `eval` function drives this). We apply associativity and distributivity of the operators here (helped by `Ex*` types) and commutativity as well (by sorting the subterms; unfortunately not helped by anything). Any expression not of the above formats is treated as an atom (the same as a variable). There are some details we glossed over which make the plan more complicated: - The order on atoms is not initially obvious. We construct a list containing them in order of initial appearance in the expression, then use the index into the list as a key to order on. - For `pow`, the exponent must be a natural number, while the base can be any semiring `α`. We swap out operations for the base ring `α` with those for the exponent ring `ℕ` as soon as we deal with exponents. ## Caveats and future work The normalized form of an expression is the one that is useful for the tactic, but not as nice to read. To remedy this, the user-facing normalization calls `ringNFCore`. Subtraction cancels out identical terms, but division does not. That is: `a - a = 0 := by ring` solves the goal, but `a / a := 1 by ring` doesn't. Note that `0 / 0` is generally defined to be `0`, so division cancelling out is not true in general. Multiplication of powers can be simplified a little bit further: `2 ^ n * 2 ^ n = 4 ^ n := by ring` could be implemented in a similar way that `2 * a + 2 * a = 4 * a := by ring` already works. This feature wasn't needed yet, so it's not implemented yet. ## Tags ring, semiring, exponent, power -/ set_option autoImplicit true namespace Mathlib.Tactic namespace Ring open Mathlib.Meta Qq NormNum Lean.Meta AtomM open Lean (MetaM Expr mkRawNatLit) /-- A shortcut instance for `CommSemiring ℕ` used by ring. -/ def instCommSemiringNat : CommSemiring ℕ := inferInstance /-- A typed expression of type `CommSemiring ℕ` used when we are working on ring subexpressions of type `ℕ`. -/ def sℕ : Q(CommSemiring ℕ) := q(instCommSemiringNat) -- In this file, we would like to use multi-character auto-implicits. set_option relaxedAutoImplicit true mutual /-- The base `e` of a normalized exponent expression. -/ inductive ExBase : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- An atomic expression `e` with id `id`. Atomic expressions are those which `ring` cannot parse any further. For instance, `a + (a % b)` has `a` and `(a % b)` as atoms. The `ring1` tactic does not normalize the subexpressions in atoms, but `ring_nf` does. Atoms in fact represent equivalence classes of expressions, modulo definitional equality. The field `index : ℕ` should be a unique number for each class, while `value : expr` contains a representative of this class. The function `resolve_atom` determines the appropriate atom for a given expression. -/ | atom (id : ℕ) : ExBase sα e /-- A sum of monomials. -/ | sum (_ : ExSum sα e) : ExBase sα e /-- A monomial, which is a product of powers of `ExBase` expressions, terminated by a (nonzero) constant coefficient. -/ inductive ExProd : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- A coefficient `value`, which must not be `0`. `e` is a raw rat cast. If `value` is not an integer, then `hyp` should be a proof of `(value.den : α) ≠ 0`. -/ | const (value : ℚ) (hyp : Option Expr := none) : ExProd sα e /-- A product `x ^ e * b` is a monomial if `b` is a monomial. Here `x` is an `ExBase` and `e` is an `ExProd` representing a monomial expression in `ℕ` (it is a monomial instead of a polynomial because we eagerly normalize `x ^ (a + b) = x ^ a * x ^ b`.) -/ | mul {α : Q(Type u)} {sα : Q(CommSemiring $α)} {x : Q($α)} {e : Q(ℕ)} {b : Q($α)} : ExBase sα x → ExProd sℕ e → ExProd sα b → ExProd sα q($x ^ $e * $b) /-- A polynomial expression, which is a sum of monomials. -/ inductive ExSum : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- Zero is a polynomial. `e` is the expression `0`. -/ | zero {α : Q(Type u)} {sα : Q(CommSemiring $α)} : ExSum sα q(0 : $α) /-- A sum `a + b` is a polynomial if `a` is a monomial and `b` is another polynomial. -/ | add {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExProd sα a → ExSum sα b → ExSum sα q($a + $b) end mutual -- partial only to speed up compilation /-- Equality test for expressions. This is not a `BEq` instance because it is heterogeneous. -/ partial def ExBase.eq : ExBase sα a → ExBase sα b → Bool | .atom i, .atom j => i == j | .sum a, .sum b => a.eq b | _, _ => false @[inherit_doc ExBase.eq] partial def ExProd.eq : ExProd sα a → ExProd sα b → Bool | .const i _, .const j _ => i == j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => a₁.eq b₁ && a₂.eq b₂ && a₃.eq b₃ | _, _ => false @[inherit_doc ExBase.eq] partial def ExSum.eq : ExSum sα a → ExSum sα b → Bool | .zero, .zero => true | .add a₁ a₂, .add b₁ b₂ => a₁.eq b₁ && a₂.eq b₂ | _, _ => false end mutual -- partial only to speed up compilation /-- A total order on normalized expressions. This is not an `Ord` instance because it is heterogeneous. -/ partial def ExBase.cmp : ExBase sα a → ExBase sα b → Ordering | .atom i, .atom j => compare i j | .sum a, .sum b => a.cmp b | .atom .., .sum .. => .lt | .sum .., .atom .. => .gt @[inherit_doc ExBase.cmp] partial def ExProd.cmp : ExProd sα a → ExProd sα b → Ordering | .const i _, .const j _ => compare i j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => (a₁.cmp b₁).then (a₂.cmp b₂) |>.then (a₃.cmp b₃) | .const _ _, .mul .. => .lt | .mul .., .const _ _ => .gt @[inherit_doc ExBase.cmp] partial def ExSum.cmp : ExSum sα a → ExSum sα b → Ordering | .zero, .zero => .eq | .add a₁ a₂, .add b₁ b₂ => (a₁.cmp b₁).then (a₂.cmp b₂) | .zero, .add .. => .lt | .add .., .zero => .gt end instance : Inhabited (Σ e, (ExBase sα) e) := ⟨default, .atom 0⟩ instance : Inhabited (Σ e, (ExSum sα) e) := ⟨_, .zero⟩ instance : Inhabited (Σ e, (ExProd sα) e) := ⟨default, .const 0 none⟩ mutual /-- Converts `ExBase sα` to `ExBase sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExBase.cast : ExBase sα a → Σ a, ExBase sβ a | .atom i => ⟨a, .atom i⟩ | .sum a => let ⟨_, vb⟩ := a.cast; ⟨_, .sum vb⟩ /-- Converts `ExProd sα` to `ExProd sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExProd.cast : ExProd sα a → Σ a, ExProd sβ a | .const i h => ⟨a, .const i h⟩ | .mul a₁ a₂ a₃ => ⟨_, .mul a₁.cast.2 a₂ a₃.cast.2⟩ /-- Converts `ExSum sα` to `ExSum sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExSum.cast : ExSum sα a → Σ a, ExSum sβ a | .zero => ⟨_, .zero⟩ | .add a₁ a₂ => ⟨_, .add a₁.cast.2 a₂.cast.2⟩ end /-- The result of evaluating an (unnormalized) expression `e` into the type family `E` (one of `ExSum`, `ExProd`, `ExBase`) is a (normalized) element `e'` and a representation `E e'` for it, and a proof of `e = e'`. -/ structure Result {α : Q(Type u)} (E : Q($α) → Type) (e : Q($α)) where /-- The normalized result. -/ expr : Q($α) /-- The data associated to the normalization. -/ val : E expr /-- A proof that the original expression is equal to the normalized result. -/ proof : Q($e = $expr) instance [Inhabited (Σ e, E e)] : Inhabited (Result E e) := let ⟨e', v⟩ : Σ e, E e := default; ⟨e', v, default⟩ variable {α : Q(Type u)} (sα : Q(CommSemiring $α)) [CommSemiring R] /-- Constructs the expression corresponding to `.const n`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNat (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q(($lit).rawCast : $α), .const n none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNegNat (_ : Q(Ring $α)) (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q((Int.negOfNat $lit).rawCast : $α), .const (-n) none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkRat (_ : Q(DivisionRing $α)) (q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (h : Expr) : (e : Q($α)) × ExProd sα e := ⟨q(Rat.rawCast $n $d : $α), .const q h⟩ section variable {sα} /-- Embed an exponent (an `ExBase, ExProd` pair) as an `ExProd` by multiplying by 1. -/ def ExBase.toProd (va : ExBase sα a) (vb : ExProd sℕ b) : ExProd sα q($a ^ $b * (nat_lit 1).rawCast) := .mul va vb (.const 1 none) /-- Embed `ExProd` in `ExSum` by adding 0. -/ def ExProd.toSum (v : ExProd sα e) : ExSum sα q($e + 0) := .add v .zero /-- Get the leading coefficient of an `ExProd`. -/ def ExProd.coeff : ExProd sα e → ℚ | .const q _ => q | .mul _ _ v => v.coeff end /-- Two monomials are said to "overlap" if they differ by a constant factor, in which case the constants just add. When this happens, the constant may be either zero (if the monomials cancel) or nonzero (if they add up); the zero case is handled specially. -/ inductive Overlap (e : Q($α)) where /-- The expression `e` (the sum of monomials) is equal to `0`. -/ | zero (_ : Q(IsNat $e (nat_lit 0))) /-- The expression `e` (the sum of monomials) is equal to another monomial (with nonzero leading coefficient). -/ | nonzero (_ : Result (ExProd sα) e) theorem add_overlap_pf (x : R) (e) (pq_pf : a + b = c) : x ^ e * a + x ^ e * b = x ^ e * c := by subst_vars; simp [mul_add] theorem add_overlap_pf_zero (x : R) (e) : IsNat (a + b) (nat_lit 0) → IsNat (x ^ e * a + x ^ e * b) (nat_lit 0) | ⟨h⟩ => ⟨by simp [h, ← mul_add]⟩ /-- Given monomials `va, vb`, attempts to add them together to get another monomial. If the monomials are not compatible, returns `none`. For example, `xy + 2xy = 3xy` is a `.nonzero` overlap, while `xy + xz` returns `none` and `xy + -xy = 0` is a `.zero` overlap. -/ def evalAddOverlap (va : ExProd sα a) (vb : ExProd sα b) : Option (Overlap sα q($a + $b)) := match va, vb with | .const za ha, .const zb hb => do let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let res ← NormNum.evalAdd.core q($a + $b) q(HAdd.hAdd) a b ra rb match res with | .isNat _ (.lit (.natVal 0)) p => pure <| .zero p | rc => let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq pure <| .nonzero ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .mul vb₁ vb₂ vb₃ => do guard (va₁.eq vb₁ && va₂.eq vb₂) match ← evalAddOverlap va₃ vb₃ with | .zero p => pure <| .zero (q(add_overlap_pf_zero $a₁ $a₂ $p) : Expr) | .nonzero ⟨_, vc, p⟩ => pure <| .nonzero ⟨_, .mul va₁ va₂ vc, (q(add_overlap_pf $a₁ $a₂ $p) : Expr)⟩ | _, _ => none theorem add_pf_zero_add (b : R) : 0 + b = b := by simp theorem add_pf_add_zero (a : R) : a + 0 = a := by simp theorem add_pf_add_overlap (_ : a₁ + b₁ = c₁) (_ : a₂ + b₂ = c₂) : (a₁ + a₂ : R) + (b₁ + b₂) = c₁ + c₂ := by subst_vars; simp [add_assoc, add_left_comm] theorem add_pf_add_overlap_zero (h : IsNat (a₁ + b₁) (nat_lit 0)) (h₄ : a₂ + b₂ = c) : (a₁ + a₂ : R) + (b₁ + b₂) = c := by subst_vars; rw [add_add_add_comm, h.1, Nat.cast_zero, add_pf_zero_add] theorem add_pf_add_lt (a₁ : R) (_ : a₂ + b = c) : (a₁ + a₂) + b = a₁ + c := by simp [*, add_assoc] theorem add_pf_add_gt (b₁ : R) (_ : a + b₂ = c) : a + (b₁ + b₂) = b₁ + c := by subst_vars; simp [add_left_comm] /-- Adds two polynomials `va, vb` together to get a normalized result polynomial. * `0 + b = b` * `a + 0 = a` * `a * x + a * y = a * (x + y)` (for `x`, `y` coefficients; uses `evalAddOverlap`) * `(a₁ + a₂) + (b₁ + b₂) = a₁ + (a₂ + (b₁ + b₂))` (if `a₁.lt b₁`) * `(a₁ + a₂) + (b₁ + b₂) = b₁ + ((a₁ + a₂) + b₂)` (if not `a₁.lt b₁`) -/ partial def evalAdd (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a + $b) := match va, vb with | .zero, vb => ⟨b, vb, q(add_pf_zero_add $b)⟩ | va, .zero => ⟨a, va, q(add_pf_add_zero $a)⟩ | .add (a := a₁) (b := _a₂) va₁ va₂, .add (a := b₁) (b := _b₂) vb₁ vb₂ => match evalAddOverlap sα va₁ vb₁ with | some (.nonzero ⟨_, vc₁, pc₁⟩) => let ⟨_, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨_, .add vc₁ vc₂, q(add_pf_add_overlap $pc₁ $pc₂)⟩ | some (.zero pc₁) => let ⟨c₂, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨c₂, vc₂, q(add_pf_add_overlap_zero $pc₁ $pc₂)⟩ | none => if let .lt := va₁.cmp vb₁ then let ⟨_c, vc, (pc : Q($_a₂ + ($b₁ + $_b₂) = $_c))⟩ := evalAdd va₂ vb ⟨_, .add va₁ vc, q(add_pf_add_lt $a₁ $pc)⟩ else let ⟨_c, vc, (pc : Q($a₁ + $_a₂ + $_b₂ = $_c))⟩ := evalAdd va vb₂ ⟨_, .add vb₁ vc, q(add_pf_add_gt $b₁ $pc)⟩ theorem one_mul (a : R) : (nat_lit 1).rawCast * a = a := by simp [Nat.rawCast] theorem mul_one (a : R) : a * (nat_lit 1).rawCast = a := by simp [Nat.rawCast] theorem mul_pf_left (a₁ : R) (a₂) (_ : a₃ * b = c) : (a₁ ^ a₂ * a₃ : R) * b = a₁ ^ a₂ * c := by subst_vars; rw [mul_assoc] theorem mul_pf_right (b₁ : R) (b₂) (_ : a * b₃ = c) : a * (b₁ ^ b₂ * b₃) = b₁ ^ b₂ * c := by subst_vars; rw [mul_left_comm] theorem mul_pp_pf_overlap (x : R) (_ : ea + eb = e) (_ : a₂ * b₂ = c) : (x ^ ea * a₂ : R) * (x ^ eb * b₂) = x ^ e * c := by subst_vars; simp [pow_add, mul_mul_mul_comm] /-- Multiplies two monomials `va, vb` together to get a normalized result monomial. * `x * y = (x * y)` (for `x`, `y` coefficients) * `x * (b₁ * b₂) = b₁ * (b₂ * x)` (for `x` coefficient) * `(a₁ * a₂) * y = a₁ * (a₂ * y)` (for `y` coefficient) * `(x ^ ea * a₂) * (x ^ eb * b₂) = x ^ (ea + eb) * (a₂ * b₂)` (if `ea` and `eb` are identical except coefficient) * `(a₁ * a₂) * (b₁ * b₂) = a₁ * (a₂ * (b₁ * b₂))` (if `a₁.lt b₁`) * `(a₁ * a₂) * (b₁ * b₂) = b₁ * ((a₁ * a₂) * b₂)` (if not `a₁.lt b₁`) -/ partial def evalMulProd (va : ExProd sα a) (vb : ExProd sα b) : Result (ExProd sα) q($a * $b) := match va, vb with | .const za ha, .const zb hb => if za = 1 then ⟨b, .const zb hb, (q(one_mul $b) : Expr)⟩ else if zb = 1 then ⟨a, .const za ha, (q(mul_one $a) : Expr)⟩ else let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let rc := (NormNum.evalMul.core q($a * $b) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) ra rb).get! let ⟨zc, hc⟩ := rc.toRatNZ.get! let ⟨c, pc⟩ := rc.toRawEq ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .const _ _ => let ⟨_, vc, pc⟩ := evalMulProd va₃ vb ⟨_, .mul va₁ va₂ vc, (q(mul_pf_left $a₁ $a₂ $pc) : Expr)⟩ | .const _ _, .mul (x := b₁) (e := b₂) vb₁ vb₂ vb₃ => let ⟨_, vc, pc⟩ := evalMulProd va vb₃ ⟨_, .mul vb₁ vb₂ vc, (q(mul_pf_right $b₁ $b₂ $pc) : Expr)⟩ | .mul (x := xa) (e := ea) vxa vea va₂, .mul (x := xb) (e := eb) vxb veb vb₂ => Id.run do if vxa.eq vxb then if let some (.nonzero ⟨_, ve, pe⟩) := evalAddOverlap sℕ vea veb then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb₂ return ⟨_, .mul vxa ve vc, (q(mul_pp_pf_overlap $xa $pe $pc) : Expr)⟩ if let .lt := (vxa.cmp vxb).then (vea.cmp veb) then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb ⟨_, .mul vxa vea vc, (q(mul_pf_left $xa $ea $pc) : Expr)⟩ else let ⟨_, vc, pc⟩ := evalMulProd va vb₂ ⟨_, .mul vxb veb vc, (q(mul_pf_right $xb $eb $pc) : Expr)⟩ theorem mul_zero (a : R) : a * 0 = 0 := by simp theorem mul_add (_ : (a : R) * b₁ = c₁) (_ : a * b₂ = c₂) (_ : c₁ + 0 + c₂ = d) : a * (b₁ + b₂) = d := by subst_vars; simp [_root_.mul_add] /-- Multiplies a monomial `va` to a polynomial `vb` to get a normalized result polynomial. * `a * 0 = 0` * `a * (b₁ + b₂) = (a * b₁) + (a * b₂)` -/ def evalMul₁ (va : ExProd sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match vb with | .zero => ⟨_, .zero, q(mul_zero $a)⟩ | .add vb₁ vb₂ => let ⟨_, vc₁, pc₁⟩ := evalMulProd sα va vb₁ let ⟨_, vc₂, pc₂⟩ := evalMul₁ va vb₂ let ⟨_, vd, pd⟩ := evalAdd sα vc₁.toSum vc₂ ⟨_, vd, q(mul_add $pc₁ $pc₂ $pd)⟩ theorem zero_mul (b : R) : 0 * b = 0 := by simp theorem add_mul (_ : (a₁ : R) * b = c₁) (_ : a₂ * b = c₂) (_ : c₁ + c₂ = d) : (a₁ + a₂) * b = d := by subst_vars; simp [_root_.add_mul] /-- Multiplies two polynomials `va, vb` together to get a normalized result polynomial. * `0 * b = 0` * `(a₁ + a₂) * b = (a₁ * b) + (a₂ * b)` -/ def evalMul (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match va with | .zero => ⟨_, .zero, q(zero_mul $b)⟩ | .add va₁ va₂ => let ⟨_, vc₁, pc₁⟩ := evalMul₁ sα va₁ vb let ⟨_, vc₂, pc₂⟩ := evalMul va₂ vb let ⟨_, vd, pd⟩ := evalAdd sα vc₁ vc₂ ⟨_, vd, q(add_mul $pc₁ $pc₂ $pd)⟩ theorem natCast_nat (n) : ((Nat.rawCast n : ℕ) : R) = Nat.rawCast n := by simp theorem natCast_mul (a₂) (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₃ : ℕ) : R) = b₃) : ((a₁ ^ a₂ * a₃ : ℕ) : R) = b₁ ^ a₂ * b₃ := by subst_vars; simp theorem natCast_zero : ((0 : ℕ) : R) = 0 := Nat.cast_zero theorem natCast_add (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by subst_vars; simp mutual /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * An atom `e` causes `↑e` to be allocated as a new atom. * A sum delegates to `ExSum.evalNatCast`. -/ partial def ExBase.evalNatCast (va : ExBase sℕ a) : AtomM (Result (ExBase sα) q($a)) := match va with | .atom _ => do let a' : Q($α) := q($a) let i ← addAtom a' pure ⟨a', ExBase.atom i, (q(Eq.refl $a') : Expr)⟩ | .sum va => do let ⟨_, vc, p⟩ ← va.evalNatCast pure ⟨_, .sum vc, p⟩ /-- Applies `Nat.cast` to a nat monomial to produce a monomial in `α`. * `↑c = c` if `c` is a numeric literal * `↑(a ^ n * b) = ↑a ^ n * ↑b` -/ partial def ExProd.evalNatCast (va : ExProd sℕ a) : AtomM (Result (ExProd sα) q($a)) := match va with | .const c hc => have n : Q(ℕ) := a.appArg! pure ⟨q(Nat.rawCast $n), .const c hc, (q(natCast_nat (R := $α) $n) : Expr)⟩ | .mul (e := a₂) va₁ va₂ va₃ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₃, pb₃⟩ ← va₃.evalNatCast pure ⟨_, .mul vb₁ va₂ vb₃, q(natCast_mul $a₂ $pb₁ $pb₃)⟩ /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * `↑0 = 0` * `↑(a + b) = ↑a + ↑b` -/ partial def ExSum.evalNatCast (va : ExSum sℕ a) : AtomM (Result (ExSum sα) q($a)) := match va with | .zero => pure ⟨_, .zero, q(natCast_zero (R := $α))⟩ | .add va₁ va₂ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₂, pb₂⟩ ← va₂.evalNatCast pure ⟨_, .add vb₁ vb₂, q(natCast_add $pb₁ $pb₂)⟩ end theorem smul_nat (_ : (a * b : ℕ) = c) : a • b = c := by subst_vars; simp theorem smul_eq_cast (_ : ((a : ℕ) : R) = a') (_ : a' * b = c) : a • b = c := by subst_vars; simp /-- Constructs the scalar multiplication `n • a`, where both `n : ℕ` and `a : α` are normalized polynomial expressions. * `a • b = a * b` if `α = ℕ` * `a • b = ↑a * b` otherwise -/ def evalNSMul (va : ExSum sℕ a) (vb : ExSum sα b) : AtomM (Result (ExSum sα) q($a • $b)) := do if ← isDefEq sα sℕ then let ⟨_, va'⟩ := va.cast have _b : Q(ℕ) := b let ⟨(_c : Q(ℕ)), vc, (pc : Q($a * $_b = $_c))⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_nat $pc) : Expr)⟩ else let ⟨_, va', pa'⟩ ← va.evalNatCast sα let ⟨_, vc, pc⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_eq_cast $pa' $pc) : Expr)⟩ theorem neg_one_mul {R} [Ring R] {a b : R} (_ : (Int.negOfNat (nat_lit 1)).rawCast * a = b) : -a = b := by subst_vars; simp [Int.negOfNat] theorem neg_mul {R} [Ring R] (a₁ : R) (a₂) {a₃ b : R} (_ : -a₃ = b) : -(a₁ ^ a₂ * a₃) = a₁ ^ a₂ * b := by subst_vars; simp /-- Negates a monomial `va` to get another monomial. * `-c = (-c)` (for `c` coefficient) * `-(a₁ * a₂) = a₁ * -a₂` -/ def evalNegProd (rα : Q(Ring $α)) (va : ExProd sα a) : Result (ExProd sα) q(-$a) := match va with | .const za ha => let lit : Q(ℕ) := mkRawNatLit 1 let ⟨m1, _⟩ := ExProd.mkNegNat sα rα 1 let rm := Result.isNegNat rα lit (q(IsInt.of_raw $α (.negOfNat $lit)) : Expr) let ra := Result.ofRawRat za a ha let rb := (NormNum.evalMul.core q($m1 * $a) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) rm ra).get! let ⟨zb, hb⟩ := rb.toRatNZ.get! let ⟨b, (pb : Q((Int.negOfNat (nat_lit 1)).rawCast * $a = $b))⟩ := rb.toRawEq ⟨b, .const zb hb, (q(neg_one_mul (R := $α) $pb) : Expr)⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃ => let ⟨_, vb, pb⟩ := evalNegProd rα va₃ ⟨_, .mul va₁ va₂ vb, (q(neg_mul $a₁ $a₂ $pb) : Expr)⟩ theorem neg_zero {R} [Ring R] : -(0 : R) = 0 := by simp theorem neg_add {R} [Ring R] {a₁ a₂ b₁ b₂ : R} (_ : -a₁ = b₁) (_ : -a₂ = b₂) : -(a₁ + a₂) = b₁ + b₂ := by subst_vars; simp [add_comm] /-- Negates a polynomial `va` to get another polynomial. * `-0 = 0` (for `c` coefficient) * `-(a₁ + a₂) = -a₁ + -a₂` -/ def evalNeg (rα : Q(Ring $α)) (va : ExSum sα a) : Result (ExSum sα) q(-$a) := match va with | .zero => ⟨_, .zero, (q(neg_zero (R := $α)) : Expr)⟩ | .add va₁ va₂ => let ⟨_, vb₁, pb₁⟩ := evalNegProd sα rα va₁ let ⟨_, vb₂, pb₂⟩ := evalNeg rα va₂ ⟨_, .add vb₁ vb₂, (q(neg_add $pb₁ $pb₂) : Expr)⟩ theorem sub_pf {R} [Ring R] {a b c d : R} (_ : -b = c) (_ : a + c = d) : a - b = d := by subst_vars; simp [sub_eq_add_neg] /-- Subtracts two polynomials `va, vb` to get a normalized result polynomial. * `a - b = a + -b` -/ def evalSub (rα : Q(Ring $α)) (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a - $b) := let ⟨_c, vc, pc⟩ := evalNeg sα rα vb let ⟨d, vd, (pd : Q($a + $_c = $d))⟩ := evalAdd sα va vc ⟨d, vd, (q(sub_pf $pc $pd) : Expr)⟩ theorem pow_prod_atom (a : R) (b) : a ^ b = (a + 0) ^ b * (nat_lit 1).rawCast := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. (This has a slightly different normalization than `evalPowAtom` because the input types are different.) * `x ^ e = (x + 0) ^ e * 1` -/ def evalPowProdAtom (va : ExProd sα a) (vb : ExProd sℕ b) : Result (ExProd sα) q($a ^ $b) := ⟨_, (ExBase.sum va.toSum).toProd vb, q(pow_prod_atom $a $b)⟩ theorem pow_atom (a : R) (b) : a ^ b = a ^ b * (nat_lit 1).rawCast + 0 := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. * `x ^ e = x ^ e * 1 + 0` -/ def evalPowAtom (va : ExBase sα a) (vb : ExProd sℕ b) : Result (ExSum sα) q($a ^ $b) := ⟨_, (va.toProd vb).toSum, q(pow_atom $a $b)⟩ theorem const_pos (n : ℕ) (h : Nat.ble 1 n = true) : 0 < (n.rawCast : ℕ) := Nat.le_of_ble_eq_true h theorem mul_exp_pos (n) (h₁ : 0 < a₁) (h₂ : 0 < a₂) : 0 < a₁ ^ n * a₂ := Nat.mul_pos (Nat.pos_pow_of_pos _ h₁) h₂ theorem add_pos_left (a₂) (h : 0 < a₁) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_right ..) theorem add_pos_right (a₁) (h : 0 < a₂) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_left ..) mutual /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * Atoms are not (necessarily) positive * Sums defer to `ExSum.evalPos` -/ partial def ExBase.evalPos (va : ExBase sℕ a) : Option Q(0 < $a) := match va with | .atom _ => none | .sum va => va.evalPos /-- Attempts to prove that a monomial expression in `ℕ` is positive. * `0 < c` (where `c` is a numeral) is true by the normalization invariant (`c` is not zero) * `0 < x ^ e * b` if `0 < x` and `0 < b` -/ partial def ExProd.evalPos (va : ExProd sℕ a) : Option Q(0 < $a) := match va with | .const _ _ => -- it must be positive because it is a nonzero nat literal have lit : Q(ℕ) := a.appArg! haveI : $a =Q Nat.rawCast $lit := ⟨⟩ haveI p : Nat.ble 1 $lit =Q true := ⟨⟩ some q(const_pos $lit $p) | .mul (e := ea₁) vxa₁ _ va₂ => do let pa₁ ← vxa₁.evalPos let pa₂ ← va₂.evalPos some q(mul_exp_pos $ea₁ $pa₁ $pa₂) /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * `0 < 0` fails * `0 < a + b` if `0 < a` or `0 < b` -/ partial def ExSum.evalPos (va : ExSum sℕ a) : Option Q(0 < $a) := match va with | .zero => none | .add (a := a₁) (b := a₂) va₁ va₂ => do match va₁.evalPos with | some p => some q(add_pos_left $a₂ $p) | none => let p ← va₂.evalPos; some q(add_pos_right $a₁ $p) end theorem pow_one (a : R) : a ^ nat_lit 1 = a := by simp theorem pow_bit0 (_ : (a : R) ^ k = b) (_ : b * b = c) : a ^ (Nat.mul (nat_lit 2) k) = c := by subst_vars; simp [Nat.succ_mul, pow_add] theorem pow_bit1 (_ : (a : R) ^ k = b) (_ : b * b = c) (_ : c * a = d) : a ^ (Nat.add (Nat.mul (nat_lit 2) k) (nat_lit 1)) = d := by subst_vars; simp [Nat.succ_mul, pow_add] /-- The main case of exponentiation of ring expressions is when `va` is a polynomial and `n` is a nonzero literal expression, like `(x + y)^5`. In this case we work out the polynomial completely into a sum of monomials. * `x ^ 1 = x` * `x ^ (2*n) = x ^ n * x ^ n` * `x ^ (2*n+1) = x ^ n * x ^ n * x` -/ partial def evalPowNat (va : ExSum sα a) (n : Q(ℕ)) : Result (ExSum sα) q($a ^ $n) := let nn := n.natLit! if nn = 1 then ⟨_, va, (q(pow_one $a) : Expr)⟩ else let nm := nn >>> 1 have m : Q(ℕ) := mkRawNatLit nm if nn &&& 1 = 0 then let ⟨_, vb, pb⟩ := evalPowNat va m let ⟨_, vc, pc⟩ := evalMul sα vb vb ⟨_, vc, (q(pow_bit0 $pb $pc) : Expr)⟩ else let ⟨_, vb, pb⟩ := evalPowNat va m let ⟨_, vc, pc⟩ := evalMul sα vb vb let ⟨_, vd, pd⟩ := evalMul sα vc va ⟨_, vd, (q(pow_bit1 $pb $pc $pd) : Expr)⟩ theorem one_pow (b : ℕ) : ((nat_lit 1).rawCast : R) ^ b = (nat_lit 1).rawCast := by simp theorem mul_pow (_ : ea₁ * b = c₁) (_ : a₂ ^ b = c₂) : (xa₁ ^ ea₁ * a₂ : R) ^ b = xa₁ ^ c₁ * c₂ := by subst_vars; simp [_root_.mul_pow, pow_mul] /-- There are several special cases when exponentiating monomials: * `1 ^ n = 1` * `x ^ y = (x ^ y)` when `x` and `y` are constants * `(a * b) ^ e = a ^ e * b ^ e` In all other cases we use `evalPowProdAtom`. -/ def evalPowProd (va : ExProd sα a) (vb : ExProd sℕ b) : Result (ExProd sα) q($a ^ $b) := let res : Option (Result (ExProd sα) q($a ^ $b)) := do match va, vb with | .const 1, _ => some ⟨_, va, (q(one_pow (R := $α) $b) : Expr)⟩ | .const za ha, .const zb hb => assert! 0 ≤ zb let ra := Result.ofRawRat za a ha have lit : Q(ℕ) := b.appArg! let rb := (q(IsNat.of_raw ℕ $lit) : Expr) let rc ← NormNum.evalPow.core q($a ^ $b) q(HPow.hPow) q($a) q($b) lit rb q(CommSemiring.toSemiring) ra let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq some ⟨c, .const zc hc, pc⟩ | .mul vxa₁ vea₁ va₂, vb => do let ⟨_, vc₁, pc₁⟩ := evalMulProd sℕ vea₁ vb let ⟨_, vc₂, pc₂⟩ := evalPowProd va₂ vb some ⟨_, .mul vxa₁ vc₁ vc₂, q(mul_pow $pc₁ $pc₂)⟩ | _, _ => none res.getD (evalPowProdAtom sα va vb) /-- The result of `extractCoeff` is a numeral and a proof that the original expression factors by this numeral. -/ structure ExtractCoeff (e : Q(ℕ)) where /-- A raw natural number literal. -/ k : Q(ℕ) /-- The result of extracting the coefficient is a monic monomial. -/ e' : Q(ℕ) /-- `e'` is a monomial. -/ ve' : ExProd sℕ e' /-- The proof that `e` splits into the coefficient `k` and the monic monomial `e'`. -/ p : Q($e = $e' * $k) theorem coeff_one (k : ℕ) : k.rawCast = (nat_lit 1).rawCast * k := by simp theorem coeff_mul (a₁ a₂ : ℕ) (_ : a₃ = c₂ * k) : a₁ ^ a₂ * a₃ = (a₁ ^ a₂ * c₂) * k := by subst_vars; rw [mul_assoc] /-- Given a monomial expression `va`, splits off the leading coefficient `k` and the remainder `e'`, stored in the `ExtractCoeff` structure. * `c = 1 * c` (if `c` is a constant) * `a * b = (a * b') * k` if `b = b' * k` -/ def extractCoeff (va : ExProd sℕ a) : ExtractCoeff a := match va with | .const _ _ => have k : Q(ℕ) := a.appArg! ⟨k, q((nat_lit 1).rawCast), .const 1, (q(coeff_one $k) : Expr)⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃ => let ⟨k, _, vc, pc⟩ := extractCoeff va₃ ⟨k, _, .mul va₁ va₂ vc, q(coeff_mul $a₁ $a₂ $pc)⟩ theorem pow_one_cast (a : R) : a ^ (nat_lit 1).rawCast = a := by simp theorem zero_pow (_ : 0 < b) : (0 : R) ^ b = 0 := match b with | b+1 => by simp [pow_succ] theorem single_pow (_ : (a : R) ^ b = c) : (a + 0) ^ b = c + 0 := by simp [*] theorem pow_nat (_ : b = c * k) (_ : a ^ c = d) (_ : d ^ k = e) : (a : R) ^ b = e := by subst_vars; simp [pow_mul] /-- Exponentiates a polynomial `va` by a monomial `vb`, including several special cases. * `a ^ 1 = a` * `0 ^ e = 0` if `0 < e` * `(a + 0) ^ b = a ^ b` computed using `evalPowProd` * `a ^ b = (a ^ b') ^ k` if `b = b' * k` and `k > 1` Otherwise `a ^ b` is just encoded as `a ^ b * 1 + 0` using `evalPowAtom`. -/ partial def evalPow₁ (va : ExSum sα a) (vb : ExProd sℕ b) : Result (ExSum sα) q($a ^ $b) := match va, vb with | va, .const 1 => haveI : $b =Q Nat.rawCast (nat_lit 1) := ⟨⟩ ⟨_, va, q(pow_one_cast $a)⟩ | .zero, vb => match vb.evalPos with | some p => ⟨_, .zero, q(zero_pow (R := $α) $p)⟩ | none => evalPowAtom sα (.sum .zero) vb | ExSum.add va .zero, vb => -- TODO: using `.add` here takes a while to compile? let ⟨_, vc, pc⟩ := evalPowProd sα va vb ⟨_, vc.toSum, q(single_pow $pc)⟩ | va, vb => if vb.coeff > 1 then let ⟨k, _, vc, pc⟩ := extractCoeff vb let ⟨_, vd, pd⟩ := evalPow₁ va vc let ⟨_, ve, pe⟩ := evalPowNat sα vd k ⟨_, ve, q(pow_nat $pc $pd $pe)⟩ else evalPowAtom sα (.sum va) vb theorem pow_zero (a : R) : a ^ 0 = (nat_lit 1).rawCast + 0 := by simp theorem pow_add (_ : a ^ b₁ = c₁) (_ : a ^ b₂ = c₂) (_ : c₁ * c₂ = d) : (a : R) ^ (b₁ + b₂) = d := by subst_vars; simp [_root_.pow_add] /-- Exponentiates two polynomials `va, vb`. * `a ^ 0 = 1` * `a ^ (b₁ + b₂) = a ^ b₁ * a ^ b₂` -/ def evalPow (va : ExSum sα a) (vb : ExSum sℕ b) : Result (ExSum sα) q($a ^ $b) := match vb with | .zero => ⟨_, (ExProd.mkNat sα 1).2.toSum, q(pow_zero $a)⟩ | .add vb₁ vb₂ => let ⟨_, vc₁, pc₁⟩ := evalPow₁ sα va vb₁ let ⟨_, vc₂, pc₂⟩ := evalPow va vb₂ let ⟨_, vd, pd⟩ := evalMul sα vc₁ vc₂ ⟨_, vd, q(pow_add $pc₁ $pc₂ $pd)⟩ /-- This cache contains data required by the `ring` tactic during execution. -/ structure Cache {α : Q(Type u)} (sα : Q(CommSemiring $α)) := /-- A ring instance on `α`, if available. -/ rα : Option Q(Ring $α) /-- A division ring instance on `α`, if available. -/ dα : Option Q(DivisionRing $α) /-- A characteristic zero ring instance on `α`, if available. -/ czα : Option Q(CharZero $α) /-- Create a new cache for `α` by doing the necessary instance searches. -/ def mkCache {α : Q(Type u)} (sα : Q(CommSemiring $α)) : MetaM (Cache sα) := return { rα := (← trySynthInstanceQ q(Ring $α)).toOption dα := (← trySynthInstanceQ q(DivisionRing $α)).toOption czα := (← trySynthInstanceQ q(CharZero $α)).toOption } theorem cast_pos : IsNat (a : R) n → a = n.rawCast + 0 | ⟨e⟩ => by simp [e] theorem cast_zero : IsNat (a : R) (nat_lit 0) → a = 0 | ⟨e⟩ => by simp [e] theorem cast_neg {R} [Ring R] {a : R} : IsInt a (.negOfNat n) → a = (Int.negOfNat n).rawCast + 0 | ⟨e⟩ => by simp [e] theorem cast_rat {R} [DivisionRing R] {a : R} : IsRat a n d → a = Rat.rawCast n d + 0 | ⟨_, e⟩ => by simp [e, div_eq_mul_inv] /-- Converts a proof by `norm_num` that `e` is a numeral, into a normalization as a monomial: * `e = 0` if `norm_num` returns `IsNat e 0` * `e = Nat.rawCast n + 0` if `norm_num` returns `IsNat e n` * `e = Int.rawCast n + 0` if `norm_num` returns `IsInt e n` * `e = Rat.rawCast n d + 0` if `norm_num` returns `IsRat e n d` -/ def evalCast : NormNum.Result e → Option (Result (ExSum sα) e) | .isNat _ (.lit (.natVal 0)) p => do assumeInstancesCommute pure ⟨_, .zero, q(cast_zero $p)⟩ | .isNat _ lit p => do assumeInstancesCommute pure ⟨_, (ExProd.mkNat sα lit.natLit!).2.toSum, (q(cast_pos $p) :)⟩ | .isNegNat rα lit p => pure ⟨_, (ExProd.mkNegNat _ rα lit.natLit!).2.toSum, (q(cast_neg $p) : Expr)⟩ | .isRat dα q n d p => pure ⟨_, (ExProd.mkRat sα dα q n d q(IsRat.den_nz $p)).2.toSum, (q(cast_rat $p) : Expr)⟩ | _ => none theorem toProd_pf (p : (a : R) = a') : a = a' ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast := by simp [*] theorem atom_pf (a : R) : a = a ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast + 0 := by simp theorem atom_pf' (p : (a : R) = a') : a = a' ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast + 0 := by simp [*] /-- Evaluates an atom, an expression where `ring` can find no additional structure. * `a = a ^ 1 * 1 + 0` -/ def evalAtom (e : Q($α)) : AtomM (Result (ExSum sα) e) := do let r ← (← read).evalAtom e have e' : Q($α) := r.expr let i ← addAtom e' let ve' := (ExBase.atom i (e := e')).toProd (ExProd.mkNat sℕ 1).2 |>.toSum pure ⟨_, ve', match r.proof? with | none => (q(atom_pf $e) : Expr) | some (p : Q($e = $e')) => (q(atom_pf' $p) : Expr)⟩ theorem inv_mul {R} [DivisionRing R] {a₁ a₂ a₃ b₁ b₃ c} (_ : (a₁⁻¹ : R) = b₁) (_ : (a₃⁻¹ : R) = b₃) (_ : b₃ * (b₁ ^ a₂ * (nat_lit 1).rawCast) = c) : (a₁ ^ a₂ * a₃ : R)⁻¹ = c := by subst_vars; simp nonrec theorem inv_zero {R} [DivisionRing R] : (0 : R)⁻¹ = 0 := inv_zero theorem inv_single {R} [DivisionRing R] {a b : R} (_ : (a : R)⁻¹ = b) : (a + 0)⁻¹ = b + 0 := by simp [*] theorem inv_add (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by subst_vars; simp section variable (dα : Q(DivisionRing $α)) /-- Applies `⁻¹` to a polynomial to get an atom. -/ def evalInvAtom (a : Q($α)) : AtomM (Result (ExBase sα) q($a⁻¹)) := do let a' : Q($α) := q($a⁻¹) let i ← addAtom a' pure ⟨a', ExBase.atom i, (q(Eq.refl $a') : Expr)⟩ /-- Inverts a polynomial `va` to get a normalized result polynomial. * `c⁻¹ = (c⁻¹)` if `c` is a constant * `(a ^ b * c)⁻¹ = a⁻¹ ^ b * c⁻¹` -/ def ExProd.evalInv (czα : Option Q(CharZero $α)) (va : ExProd sα a) : AtomM (Result (ExProd sα) q($a⁻¹)) := do match va with | .const c hc => let ra := Result.ofRawRat c a hc match NormNum.evalInv.core q($a⁻¹) a ra dα czα with | some rc => let ⟨zc, hc⟩ := rc.toRatNZ.get! let ⟨c, pc⟩ := rc.toRawEq pure ⟨c, .const zc hc, pc⟩ | none => let ⟨_, vc, pc⟩ ← evalInvAtom sα dα a pure ⟨_, vc.toProd (ExProd.mkNat sℕ 1).2, q(toProd_pf $pc)⟩ | .mul (x := a₁) (e := _a₂) _va₁ va₂ va₃ => do let ⟨_b₁, vb₁, pb₁⟩ ← evalInvAtom sα dα a₁ let ⟨_b₃, vb₃, pb₃⟩ ← va₃.evalInv czα let ⟨c, vc, (pc : Q($_b₃ * ($_b₁ ^ $_a₂ * Nat.rawCast 1) = $c))⟩ := evalMulProd sα vb₃ (vb₁.toProd va₂) pure ⟨c, vc, (q(inv_mul $pb₁ $pb₃ $pc) : Expr)⟩ /-- Inverts a polynomial `va` to get a normalized result polynomial. * `0⁻¹ = 0` * `a⁻¹ = (a⁻¹)` if `a` is a nontrivial sum -/ def ExSum.evalInv (czα : Option Q(CharZero $α)) (va : ExSum sα a) : AtomM (Result (ExSum sα) q($a⁻¹)) := match va with | ExSum.zero => pure ⟨_, .zero, (q(inv_zero (R := $α)) : Expr)⟩ | ExSum.add va ExSum.zero => do let ⟨_, vb, pb⟩ ← va.evalInv dα czα pure ⟨_, vb.toSum, (q(inv_single $pb) : Expr)⟩ | va => do let ⟨_, vb, pb⟩ ← evalInvAtom sα dα a pure ⟨_, vb.toProd (ExProd.mkNat sℕ 1).2 |>.toSum, q(atom_pf' $pb)⟩ end theorem div_pf {R} [DivisionRing R] {a b c d : R} (_ : b⁻¹ = c) (_ : a * c = d) : a / b = d := by subst_vars; simp [div_eq_mul_inv] /-- Divides two polynomials `va, vb` to get a normalized result polynomial. * `a / b = a * b⁻¹` -/ def evalDiv (rα : Q(DivisionRing $α)) (czα : Option Q(CharZero $α)) (va : ExSum sα a) (vb : ExSum sα b) : AtomM (Result (ExSum sα) q($a / $b)) := do let ⟨_c, vc, pc⟩ ← vb.evalInv sα rα czα let ⟨d, vd, (pd : Q($a * $_c = $d))⟩ := evalMul sα va vc pure ⟨d, vd, (q(div_pf $pc $pd) : Expr)⟩
Mathlib/Tactic/Ring/Basic.lean
968
969
theorem add_congr (_ : a = a') (_ : b = b') (_ : a' + b' = c) : (a + b : R) = c := by
subst_vars; rfl
/- 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.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Eval import Mathlib.Algebra.Polynomial.Monic import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Tactic.Abel #align_import ring_theory.polynomial.pochhammer from "leanprover-community/mathlib"@"53b216bcc1146df1c4a0a86877890ea9f1f01589" /-! # The Pochhammer polynomials We define and prove some basic relations about `ascPochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)` which is also known as the rising factorial and about `descPochhammer R n : R[X] := X * (X - 1) * ... * (X - n + 1)` which is also known as the falling factorial. Versions of this definition that are focused on `Nat` can be found in `Data.Nat.Factorial` as `Nat.ascFactorial` and `Nat.descFactorial`. ## Implementation As with many other families of polynomials, even though the coefficients are always in `ℕ` or `ℤ` , we define the polynomial with coefficients in any `[Semiring S]` or `[Ring R]`. ## TODO There is lots more in this direction: * q-factorials, q-binomials, q-Pochhammer. -/ universe u v open Polynomial open Polynomial section Semiring variable (S : Type u) [Semiring S] /-- `ascPochhammer S n` is the polynomial `X * (X + 1) * ... * (X + n - 1)`, with coefficients in the semiring `S`. -/ noncomputable def ascPochhammer : ℕ → S[X] | 0 => 1 | n + 1 => X * (ascPochhammer n).comp (X + 1) #align pochhammer ascPochhammer @[simp] theorem ascPochhammer_zero : ascPochhammer S 0 = 1 := rfl #align pochhammer_zero ascPochhammer_zero @[simp] theorem ascPochhammer_one : ascPochhammer S 1 = X := by simp [ascPochhammer] #align pochhammer_one ascPochhammer_one theorem ascPochhammer_succ_left (n : ℕ) : ascPochhammer S (n + 1) = X * (ascPochhammer S n).comp (X + 1) := by rw [ascPochhammer] #align pochhammer_succ_left ascPochhammer_succ_left theorem monic_ascPochhammer (n : ℕ) [Nontrivial S] [NoZeroDivisors S] : Monic <| ascPochhammer S n := by induction' n with n hn · simp · have : leadingCoeff (X + 1 : S[X]) = 1 := leadingCoeff_X_add_C 1 rw [ascPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp (ne_zero_of_eq_one <| natDegree_X_add_C 1 : natDegree (X + 1) ≠ 0), hn, monic_X, one_mul, one_mul, this, one_pow] section variable {S} {T : Type v} [Semiring T] @[simp] theorem ascPochhammer_map (f : S →+* T) (n : ℕ) : (ascPochhammer S n).map f = ascPochhammer T n := by induction' n with n ih · simp · simp [ih, ascPochhammer_succ_left, map_comp] #align pochhammer_map ascPochhammer_map theorem ascPochhammer_eval₂ (f : S →+* T) (n : ℕ) (t : T) : (ascPochhammer T n).eval t = (ascPochhammer S n).eval₂ f t := by rw [← ascPochhammer_map f] exact eval_map f t theorem ascPochhammer_eval_comp {R : Type*} [CommSemiring R] (n : ℕ) (p : R[X]) [Algebra R S] (x : S) : ((ascPochhammer S n).comp (p.map (algebraMap R S))).eval x = (ascPochhammer S n).eval (p.eval₂ (algebraMap R S) x) := by rw [ascPochhammer_eval₂ (algebraMap R S), ← eval₂_comp', ← ascPochhammer_map (algebraMap R S), ← map_comp, eval_map] end @[simp, norm_cast] theorem ascPochhammer_eval_cast (n k : ℕ) : (((ascPochhammer ℕ n).eval k : ℕ) : S) = ((ascPochhammer S n).eval k : S) := by rw [← ascPochhammer_map (algebraMap ℕ S), eval_map, ← eq_natCast (algebraMap ℕ S), eval₂_at_natCast,Nat.cast_id] #align pochhammer_eval_cast ascPochhammer_eval_cast theorem ascPochhammer_eval_zero {n : ℕ} : (ascPochhammer S n).eval 0 = if n = 0 then 1 else 0 := by cases n · simp · simp [X_mul, Nat.succ_ne_zero, ascPochhammer_succ_left] #align pochhammer_eval_zero ascPochhammer_eval_zero theorem ascPochhammer_zero_eval_zero : (ascPochhammer S 0).eval 0 = 1 := by simp #align pochhammer_zero_eval_zero ascPochhammer_zero_eval_zero @[simp] theorem ascPochhammer_ne_zero_eval_zero {n : ℕ} (h : n ≠ 0) : (ascPochhammer S n).eval 0 = 0 := by simp [ascPochhammer_eval_zero, h] #align pochhammer_ne_zero_eval_zero ascPochhammer_ne_zero_eval_zero theorem ascPochhammer_succ_right (n : ℕ) : ascPochhammer S (n + 1) = ascPochhammer S n * (X + (n : S[X])) := by suffices h : ascPochhammer ℕ (n + 1) = ascPochhammer ℕ n * (X + (n : ℕ[X])) by apply_fun Polynomial.map (algebraMap ℕ S) at h simpa only [ascPochhammer_map, Polynomial.map_mul, Polynomial.map_add, map_X, Polynomial.map_natCast] using h induction' n with n ih · simp · conv_lhs => rw [ascPochhammer_succ_left, ih, mul_comp, ← mul_assoc, ← ascPochhammer_succ_left, add_comp, X_comp, natCast_comp, add_assoc, add_comm (1 : ℕ[X]), ← Nat.cast_succ] #align pochhammer_succ_right ascPochhammer_succ_right theorem ascPochhammer_succ_eval {S : Type*} [Semiring S] (n : ℕ) (k : S) : (ascPochhammer S (n + 1)).eval k = (ascPochhammer S n).eval k * (k + n) := by rw [ascPochhammer_succ_right, mul_add, eval_add, eval_mul_X, ← Nat.cast_comm, ← C_eq_natCast, eval_C_mul, Nat.cast_comm, ← mul_add] #align pochhammer_succ_eval ascPochhammer_succ_eval theorem ascPochhammer_succ_comp_X_add_one (n : ℕ) : (ascPochhammer S (n + 1)).comp (X + 1) = ascPochhammer S (n + 1) + (n + 1) • (ascPochhammer S n).comp (X + 1) := by suffices (ascPochhammer ℕ (n + 1)).comp (X + 1) = ascPochhammer ℕ (n + 1) + (n + 1) * (ascPochhammer ℕ n).comp (X + 1) by simpa [map_comp] using congr_arg (Polynomial.map (Nat.castRingHom S)) this nth_rw 2 [ascPochhammer_succ_left] rw [← add_mul, ascPochhammer_succ_right ℕ n, mul_comp, mul_comm, add_comp, X_comp, natCast_comp, add_comm, ← add_assoc] ring set_option linter.uppercaseLean3 false in #align pochhammer_succ_comp_X_add_one ascPochhammer_succ_comp_X_add_one theorem ascPochhammer_mul (n m : ℕ) : ascPochhammer S n * (ascPochhammer S m).comp (X + (n : S[X])) = ascPochhammer S (n + m) := by induction' m with m ih · simp · rw [ascPochhammer_succ_right, Polynomial.mul_X_add_natCast_comp, ← mul_assoc, ih, ← add_assoc, ascPochhammer_succ_right, Nat.cast_add, add_assoc] #align pochhammer_mul ascPochhammer_mul theorem ascPochhammer_nat_eq_ascFactorial (n : ℕ) : ∀ k, (ascPochhammer ℕ k).eval n = n.ascFactorial k | 0 => by rw [ascPochhammer_zero, eval_one, Nat.ascFactorial_zero] | t + 1 => by rw [ascPochhammer_succ_right, eval_mul, ascPochhammer_nat_eq_ascFactorial n t, eval_add, eval_X, eval_natCast, Nat.cast_id, Nat.ascFactorial_succ, mul_comm] #align pochhammer_nat_eq_asc_factorial ascPochhammer_nat_eq_ascFactorial theorem ascPochhammer_nat_eq_descFactorial (a b : ℕ) : (ascPochhammer ℕ b).eval a = (a + b - 1).descFactorial b := by rw [ascPochhammer_nat_eq_ascFactorial, Nat.add_descFactorial_eq_ascFactorial'] #align pochhammer_nat_eq_desc_factorial ascPochhammer_nat_eq_descFactorial @[simp] theorem ascPochhammer_natDegree (n : ℕ) [NoZeroDivisors S] [Nontrivial S] : (ascPochhammer S n).natDegree = n := by induction' n with n hn · simp · have : natDegree (X + (n : S[X])) = 1 := natDegree_X_add_C (n : S) rw [ascPochhammer_succ_right, natDegree_mul _ (ne_zero_of_natDegree_gt <| this.symm ▸ Nat.zero_lt_one), hn, this] cases n · simp · refine ne_zero_of_natDegree_gt <| hn.symm ▸ Nat.add_one_pos _ end Semiring section StrictOrderedSemiring variable {S : Type*} [StrictOrderedSemiring S] theorem ascPochhammer_pos (n : ℕ) (s : S) (h : 0 < s) : 0 < (ascPochhammer S n).eval s := by induction' n with n ih · simp only [Nat.zero_eq, ascPochhammer_zero, eval_one] exact zero_lt_one · rw [ascPochhammer_succ_right, mul_add, eval_add, ← Nat.cast_comm, eval_natCast_mul, eval_mul_X, Nat.cast_comm, ← mul_add] exact mul_pos ih (lt_of_lt_of_le h ((le_add_iff_nonneg_right _).mpr (Nat.cast_nonneg n))) #align pochhammer_pos ascPochhammer_pos end StrictOrderedSemiring section Factorial open Nat variable (S : Type*) [Semiring S] (r n : ℕ) @[simp] theorem ascPochhammer_eval_one (S : Type*) [Semiring S] (n : ℕ) : (ascPochhammer S n).eval (1 : S) = (n ! : S) := by rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.one_ascFactorial] #align pochhammer_eval_one ascPochhammer_eval_one theorem factorial_mul_ascPochhammer (S : Type*) [Semiring S] (r n : ℕ) : (r ! : S) * (ascPochhammer S n).eval (r + 1 : S) = (r + n)! := by rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.factorial_mul_ascFactorial] #align factorial_mul_pochhammer factorial_mul_ascPochhammer theorem ascPochhammer_nat_eval_succ (r : ℕ) : ∀ n : ℕ, n * (ascPochhammer ℕ r).eval (n + 1) = (n + r) * (ascPochhammer ℕ r).eval n | 0 => by by_cases h : r = 0 · simp only [h, zero_mul, zero_add] · simp only [ascPochhammer_eval_zero, zero_mul, if_neg h, mul_zero] | k + 1 => by simp only [ascPochhammer_nat_eq_ascFactorial, Nat.succ_ascFactorial, add_right_comm] #align pochhammer_nat_eval_succ ascPochhammer_nat_eval_succ theorem ascPochhammer_eval_succ (r n : ℕ) : (n : S) * (ascPochhammer S r).eval (n + 1 : S) = (n + r) * (ascPochhammer S r).eval (n : S) := mod_cast congr_arg Nat.cast (ascPochhammer_nat_eval_succ r n) #align pochhammer_eval_succ ascPochhammer_eval_succ end Factorial section Ring variable (R : Type u) [Ring R] /-- `descPochhammer R n` is the polynomial `X * (X - 1) * ... * (X - n + 1)`, with coefficients in the ring `R`. -/ noncomputable def descPochhammer : ℕ → R[X] | 0 => 1 | n + 1 => X * (descPochhammer n).comp (X - 1) @[simp] theorem descPochhammer_zero : descPochhammer R 0 = 1 := rfl @[simp] theorem descPochhammer_one : descPochhammer R 1 = X := by simp [descPochhammer] theorem descPochhammer_succ_left (n : ℕ) : descPochhammer R (n + 1) = X * (descPochhammer R n).comp (X - 1) := by rw [descPochhammer] theorem monic_descPochhammer (n : ℕ) [Nontrivial R] [NoZeroDivisors R] : Monic <| descPochhammer R n := by induction' n with n hn · simp · have h : leadingCoeff (X - 1 : R[X]) = 1 := leadingCoeff_X_sub_C 1 have : natDegree (X - (1 : R[X])) ≠ 0 := ne_zero_of_eq_one <| natDegree_X_sub_C (1 : R) rw [descPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp this, hn, monic_X, one_mul, one_mul, h, one_pow] section variable {R} {T : Type v} [Ring T] @[simp] theorem descPochhammer_map (f : R →+* T) (n : ℕ) : (descPochhammer R n).map f = descPochhammer T n := by induction' n with n ih · simp · simp [ih, descPochhammer_succ_left, map_comp] end @[simp, norm_cast] theorem descPochhammer_eval_cast (n : ℕ) (k : ℤ) : (((descPochhammer ℤ n).eval k : ℤ) : R) = ((descPochhammer R n).eval k : R) := by rw [← descPochhammer_map (algebraMap ℤ R), eval_map, ← eq_intCast (algebraMap ℤ R)] simp only [algebraMap_int_eq, eq_intCast, eval₂_at_intCast, Nat.cast_id, eq_natCast, Int.cast_id] theorem descPochhammer_eval_zero {n : ℕ} : (descPochhammer R n).eval 0 = if n = 0 then 1 else 0 := by cases n · simp · simp [X_mul, Nat.succ_ne_zero, descPochhammer_succ_left]
Mathlib/RingTheory/Polynomial/Pochhammer.lean
295
295
theorem descPochhammer_zero_eval_zero : (descPochhammer R 0).eval 0 = 1 := by
simp
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, 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]
Mathlib/SetTheory/Cardinal/Basic.lean
1,350
1,352
theorem one_eq_lift_iff {a : Cardinal.{u}} : (1 : Cardinal) = lift.{v} a ↔ 1 = a := by
simpa using nat_eq_lift_iff (n := 1)
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Functor.FullyFaithful import Mathlib.CategoryTheory.FullSubcategory import Mathlib.CategoryTheory.Whiskering import Mathlib.CategoryTheory.EssentialImage import Mathlib.Tactic.CategoryTheory.Slice #align_import category_theory.equivalence from "leanprover-community/mathlib"@"9aba7801eeecebb61f58a5763c2b6dd1b47dc6ef" /-! # Equivalence of categories An equivalence of categories `C` and `D` is a pair of functors `F : C ⥤ D` and `G : D ⥤ C` such that `η : 𝟭 C ≅ F ⋙ G` and `ε : G ⋙ F ≅ 𝟭 D`. In many situations, equivalences are a better notion of "sameness" of categories than the stricter isomorphism of categories. Recall that one way to express that two functors `F : C ⥤ D` and `G : D ⥤ C` are adjoint is using two natural transformations `η : 𝟭 C ⟶ F ⋙ G` and `ε : G ⋙ F ⟶ 𝟭 D`, called the unit and the counit, such that the compositions `F ⟶ FGF ⟶ F` and `G ⟶ GFG ⟶ G` are the identity. Unfortunately, it is not the case that the natural isomorphisms `η` and `ε` in the definition of an equivalence automatically give an adjunction. However, it is true that * if one of the two compositions is the identity, then so is the other, and * given an equivalence of categories, it is always possible to refine `η` in such a way that the identities are satisfied. For this reason, in mathlib we define an equivalence to be a "half-adjoint equivalence", which is a tuple `(F, G, η, ε)` as in the first paragraph such that the composite `F ⟶ FGF ⟶ F` is the identity. By the remark above, this already implies that the tuple is an "adjoint equivalence", i.e., that the composite `G ⟶ GFG ⟶ G` is also the identity. We also define essentially surjective functors and show that a functor is an equivalence if and only if it is full, faithful and essentially surjective. ## Main definitions * `Equivalence`: bundled (half-)adjoint equivalences of categories * `Functor.EssSurj`: type class on a functor `F` containing the data of the preimages and the isomorphisms `F.obj (preimage d) ≅ d`. * `Functor.IsEquivalence`: type class on a functor `F` which is full, faithful and essentially surjective. ## Main results * `Equivalence.mk`: upgrade an equivalence to a (half-)adjoint equivalence * `isEquivalence_iff_of_iso`: when `F` and `G` are isomorphic functors, `F` is an equivalence iff `G` is. * `Functor.asEquivalenceFunctor`: construction of an equivalence of categories from a functor `F` which satisfies the property `F.IsEquivalence` (i.e. `F` is full, faithful and essentially surjective). ## Notations We write `C ≌ D` (`\backcong`, not to be confused with `≅`/`\cong`) for a bundled equivalence. -/ namespace CategoryTheory open CategoryTheory.Functor NatIso Category -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ v₂ v₃ u₁ u₂ u₃ /-- We define an equivalence as a (half)-adjoint equivalence, a pair of functors with a unit and counit which are natural isomorphisms and the triangle law `Fη ≫ εF = 1`, or in other words the composite `F ⟶ FGF ⟶ F` is the identity. In `unit_inverse_comp`, we show that this is actually an adjoint equivalence, i.e., that the composite `G ⟶ GFG ⟶ G` is also the identity. The triangle equation is written as a family of equalities between morphisms, it is more complicated if we write it as an equality of natural transformations, because then we would have to insert natural transformations like `F ⟶ F1`. See <https://stacks.math.columbia.edu/tag/001J> -/ @[ext] structure Equivalence (C : Type u₁) (D : Type u₂) [Category.{v₁} C] [Category.{v₂} D] where mk' :: /-- A functor in one direction -/ functor : C ⥤ D /-- A functor in the other direction -/ inverse : D ⥤ C /-- The composition `functor ⋙ inverse` is isomorphic to the identity -/ unitIso : 𝟭 C ≅ functor ⋙ inverse /-- The composition `inverse ⋙ functor` is also isomorphic to the identity -/ counitIso : inverse ⋙ functor ≅ 𝟭 D /-- The natural isomorphisms compose to the identity. -/ functor_unitIso_comp : ∀ X : C, functor.map (unitIso.hom.app X) ≫ counitIso.hom.app (functor.obj X) = 𝟙 (functor.obj X) := by aesop_cat #align category_theory.equivalence CategoryTheory.Equivalence #align category_theory.equivalence.unit_iso CategoryTheory.Equivalence.unitIso #align category_theory.equivalence.counit_iso CategoryTheory.Equivalence.counitIso #align category_theory.equivalence.functor_unit_iso_comp CategoryTheory.Equivalence.functor_unitIso_comp /-- We infix the usual notation for an equivalence -/ infixr:10 " ≌ " => Equivalence variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] namespace Equivalence /-- The unit of an equivalence of categories. -/ abbrev unit (e : C ≌ D) : 𝟭 C ⟶ e.functor ⋙ e.inverse := e.unitIso.hom #align category_theory.equivalence.unit CategoryTheory.Equivalence.unit /-- The counit of an equivalence of categories. -/ abbrev counit (e : C ≌ D) : e.inverse ⋙ e.functor ⟶ 𝟭 D := e.counitIso.hom #align category_theory.equivalence.counit CategoryTheory.Equivalence.counit /-- The inverse of the unit of an equivalence of categories. -/ abbrev unitInv (e : C ≌ D) : e.functor ⋙ e.inverse ⟶ 𝟭 C := e.unitIso.inv #align category_theory.equivalence.unit_inv CategoryTheory.Equivalence.unitInv /-- The inverse of the counit of an equivalence of categories. -/ abbrev counitInv (e : C ≌ D) : 𝟭 D ⟶ e.inverse ⋙ e.functor := e.counitIso.inv #align category_theory.equivalence.counit_inv CategoryTheory.Equivalence.counitInv /- While these abbreviations are convenient, they also cause some trouble, preventing structure projections from unfolding. -/ @[simp] theorem Equivalence_mk'_unit (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unit = unit_iso.hom := rfl #align category_theory.equivalence.equivalence_mk'_unit CategoryTheory.Equivalence.Equivalence_mk'_unit @[simp] theorem Equivalence_mk'_counit (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counit = counit_iso.hom := rfl #align category_theory.equivalence.equivalence_mk'_counit CategoryTheory.Equivalence.Equivalence_mk'_counit @[simp] theorem Equivalence_mk'_unitInv (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unitInv = unit_iso.inv := rfl #align category_theory.equivalence.equivalence_mk'_unit_inv CategoryTheory.Equivalence.Equivalence_mk'_unitInv @[simp] theorem Equivalence_mk'_counitInv (functor inverse unit_iso counit_iso f) : (⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counitInv = counit_iso.inv := rfl #align category_theory.equivalence.equivalence_mk'_counit_inv CategoryTheory.Equivalence.Equivalence_mk'_counitInv @[reassoc (attr := simp)] theorem functor_unit_comp (e : C ≌ D) (X : C) : e.functor.map (e.unit.app X) ≫ e.counit.app (e.functor.obj X) = 𝟙 (e.functor.obj X) := e.functor_unitIso_comp X #align category_theory.equivalence.functor_unit_comp CategoryTheory.Equivalence.functor_unit_comp @[reassoc (attr := simp)] theorem counitInv_functor_comp (e : C ≌ D) (X : C) : e.counitInv.app (e.functor.obj X) ≫ e.functor.map (e.unitInv.app X) = 𝟙 (e.functor.obj X) := by erw [Iso.inv_eq_inv (e.functor.mapIso (e.unitIso.app X) ≪≫ e.counitIso.app (e.functor.obj X)) (Iso.refl _)] exact e.functor_unit_comp X #align category_theory.equivalence.counit_inv_functor_comp CategoryTheory.Equivalence.counitInv_functor_comp theorem counitInv_app_functor (e : C ≌ D) (X : C) : e.counitInv.app (e.functor.obj X) = e.functor.map (e.unit.app X) := by symm erw [← Iso.comp_hom_eq_id (e.counitIso.app _), functor_unit_comp] rfl #align category_theory.equivalence.counit_inv_app_functor CategoryTheory.Equivalence.counitInv_app_functor theorem counit_app_functor (e : C ≌ D) (X : C) : e.counit.app (e.functor.obj X) = e.functor.map (e.unitInv.app X) := by erw [← Iso.hom_comp_eq_id (e.functor.mapIso (e.unitIso.app X)), functor_unit_comp] rfl #align category_theory.equivalence.counit_app_functor CategoryTheory.Equivalence.counit_app_functor /-- The other triangle equality. The proof follows the following proof in Globular: http://globular.science/1905.001 -/ @[reassoc (attr := simp)] theorem unit_inverse_comp (e : C ≌ D) (Y : D) : e.unit.app (e.inverse.obj Y) ≫ e.inverse.map (e.counit.app Y) = 𝟙 (e.inverse.obj Y) := by rw [← id_comp (e.inverse.map _), ← map_id e.inverse, ← counitInv_functor_comp, map_comp] dsimp rw [← Iso.hom_inv_id_assoc (e.unitIso.app _) (e.inverse.map (e.functor.map _)), app_hom, app_inv] slice_lhs 2 3 => erw [e.unit.naturality] slice_lhs 1 2 => erw [e.unit.naturality] slice_lhs 4 4 => rw [← Iso.hom_inv_id_assoc (e.inverse.mapIso (e.counitIso.app _)) (e.unitInv.app _)] slice_lhs 3 4 => erw [← map_comp e.inverse, e.counit.naturality] erw [(e.counitIso.app _).hom_inv_id, map_id] erw [id_comp] slice_lhs 2 3 => erw [← map_comp e.inverse, e.counitIso.inv.naturality, map_comp] slice_lhs 3 4 => erw [e.unitInv.naturality] slice_lhs 4 5 => erw [← map_comp (e.functor ⋙ e.inverse), (e.unitIso.app _).hom_inv_id, map_id] erw [id_comp] slice_lhs 3 4 => erw [← e.unitInv.naturality] slice_lhs 2 3 => erw [← map_comp e.inverse, ← e.counitIso.inv.naturality, (e.counitIso.app _).hom_inv_id, map_id] erw [id_comp, (e.unitIso.app _).hom_inv_id]; rfl #align category_theory.equivalence.unit_inverse_comp CategoryTheory.Equivalence.unit_inverse_comp @[reassoc (attr := simp)] theorem inverse_counitInv_comp (e : C ≌ D) (Y : D) : e.inverse.map (e.counitInv.app Y) ≫ e.unitInv.app (e.inverse.obj Y) = 𝟙 (e.inverse.obj Y) := by erw [Iso.inv_eq_inv (e.unitIso.app (e.inverse.obj Y) ≪≫ e.inverse.mapIso (e.counitIso.app Y)) (Iso.refl _)] exact e.unit_inverse_comp Y #align category_theory.equivalence.inverse_counit_inv_comp CategoryTheory.Equivalence.inverse_counitInv_comp
Mathlib/CategoryTheory/Equivalence.lean
214
217
theorem unit_app_inverse (e : C ≌ D) (Y : D) : e.unit.app (e.inverse.obj Y) = e.inverse.map (e.counitInv.app Y) := by
erw [← Iso.comp_hom_eq_id (e.inverse.mapIso (e.counitIso.app Y)), unit_inverse_comp] dsimp
/- 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.Exp import Mathlib.Tactic.Positivity.Core import Mathlib.Algebra.Ring.NegOnePow #align_import analysis.special_functions.trigonometric.basic from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # Trigonometric functions ## Main definitions This file contains the definition of `π`. See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions. See also `Analysis.SpecialFunctions.Complex.Arg` and `Analysis.SpecialFunctions.Complex.Log` for the complex argument function and the complex logarithm. ## Main statements Many basic inequalities on the real trigonometric functions are established. The continuity of the usual trigonometric functions is proved. Several facts about the real trigonometric functions have the proofs deferred to `Analysis.SpecialFunctions.Trigonometric.Complex`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas in terms of Chebyshev polynomials. ## Tags sin, cos, tan, angle -/ noncomputable section open scoped Classical open Topology Filter Set namespace Complex @[continuity, fun_prop] theorem continuous_sin : Continuous sin := by change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 continuity #align complex.continuous_sin Complex.continuous_sin @[fun_prop] theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s := continuous_sin.continuousOn #align complex.continuous_on_sin Complex.continuousOn_sin @[continuity, fun_prop] theorem continuous_cos : Continuous cos := by change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 continuity #align complex.continuous_cos Complex.continuous_cos @[fun_prop] theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s := continuous_cos.continuousOn #align complex.continuous_on_cos Complex.continuousOn_cos @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := by change Continuous fun z => (exp z - exp (-z)) / 2 continuity #align complex.continuous_sinh Complex.continuous_sinh @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := by change Continuous fun z => (exp z + exp (-z)) / 2 continuity #align complex.continuous_cosh Complex.continuous_cosh end Complex namespace Real variable {x y z : ℝ} @[continuity, fun_prop] theorem continuous_sin : Continuous sin := Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal) #align real.continuous_sin Real.continuous_sin @[fun_prop] theorem continuousOn_sin {s} : ContinuousOn sin s := continuous_sin.continuousOn #align real.continuous_on_sin Real.continuousOn_sin @[continuity, fun_prop] theorem continuous_cos : Continuous cos := Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal) #align real.continuous_cos Real.continuous_cos @[fun_prop] theorem continuousOn_cos {s} : ContinuousOn cos s := continuous_cos.continuousOn #align real.continuous_on_cos Real.continuousOn_cos @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal) #align real.continuous_sinh Real.continuous_sinh @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal) #align real.continuous_cosh Real.continuous_cosh end Real namespace Real theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 := intermediate_value_Icc' (by norm_num) continuousOn_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ #align real.exists_cos_eq_zero Real.exists_cos_eq_zero /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. -/ protected noncomputable def pi : ℝ := 2 * Classical.choose exists_cos_eq_zero #align real.pi Real.pi @[inherit_doc] scoped notation "π" => Real.pi @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).2 #align real.cos_pi_div_two Real.cos_pi_div_two theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.1 #align real.one_le_pi_div_two Real.one_le_pi_div_two theorem pi_div_two_le_two : π / 2 ≤ 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.2 #align real.pi_div_two_le_two Real.pi_div_two_le_two theorem two_le_pi : (2 : ℝ) ≤ π := (div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1 (by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two) #align real.two_le_pi Real.two_le_pi theorem pi_le_four : π ≤ 4 := (div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1 (calc π / 2 ≤ 2 := pi_div_two_le_two _ = 4 / 2 := by norm_num) #align real.pi_le_four Real.pi_le_four theorem pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi #align real.pi_pos Real.pi_pos theorem pi_nonneg : 0 ≤ π := pi_pos.le theorem pi_ne_zero : π ≠ 0 := pi_pos.ne' #align real.pi_ne_zero Real.pi_ne_zero theorem pi_div_two_pos : 0 < π / 2 := half_pos pi_pos #align real.pi_div_two_pos Real.pi_div_two_pos theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos] #align real.two_pi_pos Real.two_pi_pos end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `π` is always positive. -/ @[positivity Real.pi] def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.pi) => assertInstancesCommute pure (.positive q(Real.pi_pos)) | _, _, _ => throwError "not Real.pi" end Mathlib.Meta.Positivity namespace NNReal open Real open Real NNReal /-- `π` considered as a nonnegative real. -/ noncomputable def pi : ℝ≥0 := ⟨π, Real.pi_pos.le⟩ #align nnreal.pi NNReal.pi @[simp] theorem coe_real_pi : (pi : ℝ) = π := rfl #align nnreal.coe_real_pi NNReal.coe_real_pi theorem pi_pos : 0 < pi := mod_cast Real.pi_pos #align nnreal.pi_pos NNReal.pi_pos theorem pi_ne_zero : pi ≠ 0 := pi_pos.ne' #align nnreal.pi_ne_zero NNReal.pi_ne_zero end NNReal namespace Real open Real @[simp] theorem sin_pi : sin π = 0 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp #align real.sin_pi Real.sin_pi @[simp] theorem cos_pi : cos π = -1 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two] norm_num #align real.cos_pi Real.cos_pi @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] #align real.sin_two_pi Real.sin_two_pi @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] #align real.cos_two_pi Real.cos_two_pi theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] #align real.sin_antiperiodic Real.sin_antiperiodic theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul #align real.sin_periodic Real.sin_periodic @[simp] theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x := sin_antiperiodic x #align real.sin_add_pi Real.sin_add_pi @[simp] theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := sin_periodic x #align real.sin_add_two_pi Real.sin_add_two_pi @[simp] theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x #align real.sin_sub_pi Real.sin_sub_pi @[simp] theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x #align real.sin_sub_two_pi Real.sin_sub_two_pi @[simp] theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x := neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq' #align real.sin_pi_sub Real.sin_pi_sub @[simp] theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x := sin_neg x ▸ sin_periodic.sub_eq' #align real.sin_two_pi_sub Real.sin_two_pi_sub @[simp] theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n #align real.sin_nat_mul_pi Real.sin_nat_mul_pi @[simp] theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n #align real.sin_int_mul_pi Real.sin_int_mul_pi @[simp] theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x #align real.sin_add_nat_mul_two_pi Real.sin_add_nat_mul_two_pi @[simp] theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x #align real.sin_add_int_mul_two_pi Real.sin_add_int_mul_two_pi @[simp] theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n #align real.sin_sub_nat_mul_two_pi Real.sin_sub_nat_mul_two_pi @[simp] theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n #align real.sin_sub_int_mul_two_pi Real.sin_sub_int_mul_two_pi @[simp] theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.nat_mul_sub_eq n #align real.sin_nat_mul_two_pi_sub Real.sin_nat_mul_two_pi_sub @[simp] theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.int_mul_sub_eq n #align real.sin_int_mul_two_pi_sub Real.sin_int_mul_two_pi_sub theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x := n.coe_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x := sin_antiperiodic.add_nat_mul_eq n theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x := n.coe_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x := sin_antiperiodic.sub_nat_mul_eq n theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg, Int.coe_negOnePow] using sin_antiperiodic.int_mul_sub_eq n theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] #align real.cos_antiperiodic Real.cos_antiperiodic theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul #align real.cos_periodic Real.cos_periodic @[simp] theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x := cos_antiperiodic x #align real.cos_add_pi Real.cos_add_pi @[simp] theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := cos_periodic x #align real.cos_add_two_pi Real.cos_add_two_pi @[simp] theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x #align real.cos_sub_pi Real.cos_sub_pi @[simp] theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x #align real.cos_sub_two_pi Real.cos_sub_two_pi @[simp] theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := cos_neg x ▸ cos_antiperiodic.sub_eq' #align real.cos_pi_sub Real.cos_pi_sub @[simp] theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x := cos_neg x ▸ cos_periodic.sub_eq' #align real.cos_two_pi_sub Real.cos_two_pi_sub @[simp] theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero #align real.cos_nat_mul_two_pi Real.cos_nat_mul_two_pi @[simp] theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero #align real.cos_int_mul_two_pi Real.cos_int_mul_two_pi @[simp] theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x #align real.cos_add_nat_mul_two_pi Real.cos_add_nat_mul_two_pi @[simp] theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x #align real.cos_add_int_mul_two_pi Real.cos_add_int_mul_two_pi @[simp] theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_nat_mul_eq n #align real.cos_sub_nat_mul_two_pi Real.cos_sub_nat_mul_two_pi @[simp] theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n #align real.cos_sub_int_mul_two_pi Real.cos_sub_int_mul_two_pi @[simp] theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.nat_mul_sub_eq n #align real.cos_nat_mul_two_pi_sub Real.cos_nat_mul_two_pi_sub @[simp] theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.int_mul_sub_eq n #align real.cos_int_mul_two_pi_sub Real.cos_int_mul_two_pi_sub theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x := n.coe_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x := cos_antiperiodic.add_nat_mul_eq n theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x := n.coe_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x := cos_antiperiodic.sub_nat_mul_eq n theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x := n.coe_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x := cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n -- Porting note (#10618): was @[simp], but simp can prove it theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic #align real.cos_nat_mul_two_pi_add_pi Real.cos_nat_mul_two_pi_add_pi -- Porting note (#10618): was @[simp], but simp can prove it theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic #align real.cos_int_mul_two_pi_add_pi Real.cos_int_mul_two_pi_add_pi -- Porting note (#10618): was @[simp], but simp can prove it theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic #align real.cos_nat_mul_two_pi_sub_pi Real.cos_nat_mul_two_pi_sub_pi -- Porting note (#10618): was @[simp], but simp can prove it theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic #align real.cos_int_mul_two_pi_sub_pi Real.cos_int_mul_two_pi_sub_pi theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have : (2 : ℝ) + 2 = 4 := by norm_num have : π - x ≤ 2 := sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)) sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this #align real.sin_pos_of_pos_of_lt_pi Real.sin_pos_of_pos_of_lt_pi theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 #align real.sin_pos_of_mem_Ioo Real.sin_pos_of_mem_Ioo theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by rw [← closure_Ioo pi_ne_zero.symm] at hx exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) #align real.sin_nonneg_of_mem_Icc Real.sin_nonneg_of_mem_Icc theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ #align real.sin_nonneg_of_nonneg_of_le_pi Real.sin_nonneg_of_nonneg_of_le_pi theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) #align real.sin_neg_of_neg_of_neg_pi_lt Real.sin_neg_of_neg_of_neg_pi_lt theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 := neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) #align real.sin_nonpos_of_nonnpos_of_neg_pi_le Real.sin_nonpos_of_nonnpos_of_neg_pi_le @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2) this.resolve_right fun h => show ¬(0 : ℝ) < -1 by norm_num <| h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos) #align real.sin_pi_div_two Real.sin_pi_div_two theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] #align real.sin_add_pi_div_two Real.sin_add_pi_div_two theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] #align real.sin_sub_pi_div_two Real.sin_sub_pi_div_two theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] #align real.sin_pi_div_two_sub Real.sin_pi_div_two_sub theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] #align real.cos_add_pi_div_two Real.cos_add_pi_div_two theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] #align real.cos_sub_pi_div_two Real.cos_sub_pi_div_two theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] #align real.cos_pi_div_two_sub Real.cos_pi_div_two_sub theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x := sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ #align real.cos_pos_of_mem_Ioo Real.cos_pos_of_mem_Ioo theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x := sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ #align real.cos_nonneg_of_mem_Icc Real.cos_nonneg_of_mem_Icc theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : 0 ≤ cos x := cos_nonneg_of_mem_Icc ⟨hl, hu⟩ #align real.cos_nonneg_of_neg_pi_div_two_le_of_le Real.cos_nonneg_of_neg_pi_div_two_le_of_le theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ #align real.cos_neg_of_pi_div_two_lt_of_lt Real.cos_neg_of_pi_div_two_lt_of_lt theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 := neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ #align real.cos_nonpos_of_pi_div_two_le_of_le Real.cos_nonpos_of_pi_div_two_le_of_le theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) : sin x = √(1 - cos x ^ 2) := by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] #align real.sin_eq_sqrt_one_sub_cos_sq Real.sin_eq_sqrt_one_sub_cos_sq
Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean
549
551
theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : cos x = √(1 - sin x ^ 2) := by
rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)]
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison -/ import Mathlib.Algebra.Order.ZeroLEOne import Mathlib.Data.List.InsertNth import Mathlib.Logic.Relation import Mathlib.Logic.Small.Defs import Mathlib.Order.GameAdd #align_import set_theory.game.pgame from "leanprover-community/mathlib"@"8900d545017cd21961daa2a1734bb658ef52c618" /-! # Combinatorial (pre-)games. The basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We construct "pregames", define an ordering and arithmetic operations on them, then show that the operations descend to "games", defined via the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p`. The surreal numbers will be built as a quotient of a subtype of pregames. A pregame (`SetTheory.PGame` below) is axiomatised via an inductive type, whose sole constructor takes two types (thought of as indexing the possible moves for the players Left and Right), and a pair of functions out of these types to `SetTheory.PGame` (thought of as describing the resulting game after making a move). Combinatorial games themselves, as a quotient of pregames, are constructed in `Game.lean`. ## Conway induction By construction, the induction principle for pregames is exactly "Conway induction". That is, to prove some predicate `SetTheory.PGame → Prop` holds for all pregames, it suffices to prove that for every pregame `g`, if the predicate holds for every game resulting from making a move, then it also holds for `g`. While it is often convenient to work "by induction" on pregames, in some situations this becomes awkward, so we also define accessor functions `SetTheory.PGame.LeftMoves`, `SetTheory.PGame.RightMoves`, `SetTheory.PGame.moveLeft` and `SetTheory.PGame.moveRight`. There is a relation `PGame.Subsequent p q`, saying that `p` can be reached by playing some non-empty sequence of moves starting from `q`, an instance `WellFounded Subsequent`, and a local tactic `pgame_wf_tac` which is helpful for discharging proof obligations in inductive proofs relying on this relation. ## Order properties Pregames have both a `≤` and a `<` relation, satisfying the usual properties of a `Preorder`. The relation `0 < x` means that `x` can always be won by Left, while `0 ≤ x` means that `x` can be won by Left as the second player. It turns out to be quite convenient to define various relations on top of these. We define the "less or fuzzy" relation `x ⧏ y` as `¬ y ≤ x`, the equivalence relation `x ≈ y` as `x ≤ y ∧ y ≤ x`, and the fuzzy relation `x ‖ y` as `x ⧏ y ∧ y ⧏ x`. If `0 ⧏ x`, then `x` can be won by Left as the first player. If `x ≈ 0`, then `x` can be won by the second player. If `x ‖ 0`, then `x` can be won by the first player. Statements like `zero_le_lf`, `zero_lf_le`, etc. unfold these definitions. The theorems `le_def` and `lf_def` give a recursive characterisation of each relation in terms of themselves two moves later. The theorems `zero_le`, `zero_lf`, etc. also take into account that `0` has no moves. Later, games will be defined as the quotient by the `≈` relation; that is to say, the `Antisymmetrization` of `SetTheory.PGame`. ## Algebraic structures We next turn to defining the operations necessary to make games into a commutative additive group. Addition is defined for $x = \{xL | xR\}$ and $y = \{yL | yR\}$ by $x + y = \{xL + y, x + yL | xR + y, x + yR\}$. Negation is defined by $\{xL | xR\} = \{-xR | -xL\}$. The order structures interact in the expected way with addition, so we have ``` theorem le_iff_sub_nonneg {x y : PGame} : x ≤ y ↔ 0 ≤ y - x := sorry theorem lt_iff_sub_pos {x y : PGame} : x < y ↔ 0 < y - x := sorry ``` We show that these operations respect the equivalence relation, and hence descend to games. At the level of games, these operations satisfy all the laws of a commutative group. To prove the necessary equivalence relations at the level of pregames, we introduce the notion of a `Relabelling` of a game, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`. ## Future work * The theory of dominated and reversible positions, and unique normal form for short games. * Analysis of basic domineering positions. * Hex. * Temperature. * The development of surreal numbers, based on this development of combinatorial games, is still quite incomplete. ## References The material here is all drawn from * [Conway, *On numbers and games*][conway2001] An interested reader may like to formalise some of the material from * [Andreas Blass, *A game semantics for linear logic*][MR1167694] * [André Joyal, *Remarques sur la théorie des jeux à deux personnes*][joyal1997] -/ set_option autoImplicit true namespace SetTheory open Function Relation -- We'd like to be able to use multi-character auto-implicits in this file. set_option relaxedAutoImplicit true /-! ### Pre-game moves -/ /-- The type of pre-games, before we have quotiented by equivalence (`PGame.Setoid`). In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a pre-game is built inductively from two families of pre-games indexed over any type in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. -/ inductive PGame : Type (u + 1) | mk : ∀ α β : Type u, (α → PGame) → (β → PGame) → PGame #align pgame SetTheory.PGame compile_inductive% PGame namespace PGame /-- The indexing type for allowable moves by Left. -/ def LeftMoves : PGame → Type u | mk l _ _ _ => l #align pgame.left_moves SetTheory.PGame.LeftMoves /-- The indexing type for allowable moves by Right. -/ def RightMoves : PGame → Type u | mk _ r _ _ => r #align pgame.right_moves SetTheory.PGame.RightMoves /-- The new game after Left makes an allowed move. -/ def moveLeft : ∀ g : PGame, LeftMoves g → PGame | mk _l _ L _ => L #align pgame.move_left SetTheory.PGame.moveLeft /-- The new game after Right makes an allowed move. -/ def moveRight : ∀ g : PGame, RightMoves g → PGame | mk _ _r _ R => R #align pgame.move_right SetTheory.PGame.moveRight @[simp] theorem leftMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).LeftMoves = xl := rfl #align pgame.left_moves_mk SetTheory.PGame.leftMoves_mk @[simp] theorem moveLeft_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveLeft = xL := rfl #align pgame.move_left_mk SetTheory.PGame.moveLeft_mk @[simp] theorem rightMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).RightMoves = xr := rfl #align pgame.right_moves_mk SetTheory.PGame.rightMoves_mk @[simp] theorem moveRight_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveRight = xR := rfl #align pgame.move_right_mk SetTheory.PGame.moveRight_mk -- TODO define this at the level of games, as well, and perhaps also for finsets of games. /-- Construct a pre-game from list of pre-games describing the available moves for Left and Right. -/ def ofLists (L R : List PGame.{u}) : PGame.{u} := mk (ULift (Fin L.length)) (ULift (Fin R.length)) (fun i => L.get i.down) fun j ↦ R.get j.down #align pgame.of_lists SetTheory.PGame.ofLists theorem leftMoves_ofLists (L R : List PGame) : (ofLists L R).LeftMoves = ULift (Fin L.length) := rfl #align pgame.left_moves_of_lists SetTheory.PGame.leftMoves_ofLists theorem rightMoves_ofLists (L R : List PGame) : (ofLists L R).RightMoves = ULift (Fin R.length) := rfl #align pgame.right_moves_of_lists SetTheory.PGame.rightMoves_ofLists /-- Converts a number into a left move for `ofLists`. -/ def toOfListsLeftMoves {L R : List PGame} : Fin L.length ≃ (ofLists L R).LeftMoves := ((Equiv.cast (leftMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_left_moves SetTheory.PGame.toOfListsLeftMoves /-- Converts a number into a right move for `ofLists`. -/ def toOfListsRightMoves {L R : List PGame} : Fin R.length ≃ (ofLists L R).RightMoves := ((Equiv.cast (rightMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_right_moves SetTheory.PGame.toOfListsRightMoves theorem ofLists_moveLeft {L R : List PGame} (i : Fin L.length) : (ofLists L R).moveLeft (toOfListsLeftMoves i) = L.get i := rfl #align pgame.of_lists_move_left SetTheory.PGame.ofLists_moveLeft @[simp] theorem ofLists_moveLeft' {L R : List PGame} (i : (ofLists L R).LeftMoves) : (ofLists L R).moveLeft i = L.get (toOfListsLeftMoves.symm i) := rfl #align pgame.of_lists_move_left' SetTheory.PGame.ofLists_moveLeft' theorem ofLists_moveRight {L R : List PGame} (i : Fin R.length) : (ofLists L R).moveRight (toOfListsRightMoves i) = R.get i := rfl #align pgame.of_lists_move_right SetTheory.PGame.ofLists_moveRight @[simp] theorem ofLists_moveRight' {L R : List PGame} (i : (ofLists L R).RightMoves) : (ofLists L R).moveRight i = R.get (toOfListsRightMoves.symm i) := rfl #align pgame.of_lists_move_right' SetTheory.PGame.ofLists_moveRight' /-- A variant of `PGame.recOn` expressed in terms of `PGame.moveLeft` and `PGame.moveRight`. Both this and `PGame.recOn` describe Conway induction on games. -/ @[elab_as_elim] def moveRecOn {C : PGame → Sort*} (x : PGame) (IH : ∀ y : PGame, (∀ i, C (y.moveLeft i)) → (∀ j, C (y.moveRight j)) → C y) : C x := x.recOn fun yl yr yL yR => IH (mk yl yr yL yR) #align pgame.move_rec_on SetTheory.PGame.moveRecOn /-- `IsOption x y` means that `x` is either a left or right option for `y`. -/ @[mk_iff] inductive IsOption : PGame → PGame → Prop | moveLeft {x : PGame} (i : x.LeftMoves) : IsOption (x.moveLeft i) x | moveRight {x : PGame} (i : x.RightMoves) : IsOption (x.moveRight i) x #align pgame.is_option SetTheory.PGame.IsOption theorem IsOption.mk_left {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : (xL i).IsOption (mk xl xr xL xR) := @IsOption.moveLeft (mk _ _ _ _) i #align pgame.is_option.mk_left SetTheory.PGame.IsOption.mk_left theorem IsOption.mk_right {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xr) : (xR i).IsOption (mk xl xr xL xR) := @IsOption.moveRight (mk _ _ _ _) i #align pgame.is_option.mk_right SetTheory.PGame.IsOption.mk_right theorem wf_isOption : WellFounded IsOption := ⟨fun x => moveRecOn x fun x IHl IHr => Acc.intro x fun y h => by induction' h with _ i _ j · exact IHl i · exact IHr j⟩ #align pgame.wf_is_option SetTheory.PGame.wf_isOption /-- `Subsequent x y` says that `x` can be obtained by playing some nonempty sequence of moves from `y`. It is the transitive closure of `IsOption`. -/ def Subsequent : PGame → PGame → Prop := TransGen IsOption #align pgame.subsequent SetTheory.PGame.Subsequent instance : IsTrans _ Subsequent := inferInstanceAs <| IsTrans _ (TransGen _) @[trans] theorem Subsequent.trans {x y z} : Subsequent x y → Subsequent y z → Subsequent x z := TransGen.trans #align pgame.subsequent.trans SetTheory.PGame.Subsequent.trans theorem wf_subsequent : WellFounded Subsequent := wf_isOption.transGen #align pgame.wf_subsequent SetTheory.PGame.wf_subsequent instance : WellFoundedRelation PGame := ⟨_, wf_subsequent⟩ @[simp] theorem Subsequent.moveLeft {x : PGame} (i : x.LeftMoves) : Subsequent (x.moveLeft i) x := TransGen.single (IsOption.moveLeft i) #align pgame.subsequent.move_left SetTheory.PGame.Subsequent.moveLeft @[simp] theorem Subsequent.moveRight {x : PGame} (j : x.RightMoves) : Subsequent (x.moveRight j) x := TransGen.single (IsOption.moveRight j) #align pgame.subsequent.move_right SetTheory.PGame.Subsequent.moveRight @[simp] theorem Subsequent.mk_left {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : Subsequent (xL i) (mk xl xr xL xR) := @Subsequent.moveLeft (mk _ _ _ _) i #align pgame.subsequent.mk_left SetTheory.PGame.Subsequent.mk_left @[simp] theorem Subsequent.mk_right {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j : xr) : Subsequent (xR j) (mk xl xr xL xR) := @Subsequent.moveRight (mk _ _ _ _) j #align pgame.subsequent.mk_right SetTheory.PGame.Subsequent.mk_right /-- Discharges proof obligations of the form `⊢ Subsequent ..` arising in termination proofs of definitions using well-founded recursion on `PGame`. -/ macro "pgame_wf_tac" : tactic => `(tactic| solve_by_elim (config := { maxDepth := 8 }) [Prod.Lex.left, Prod.Lex.right, PSigma.Lex.left, PSigma.Lex.right, Subsequent.moveLeft, Subsequent.moveRight, Subsequent.mk_left, Subsequent.mk_right, Subsequent.trans] ) -- Register some consequences of pgame_wf_tac as simp-lemmas for convenience -- (which are applied by default for WF goals) -- This is different from mk_right from the POV of the simplifier, -- because the unifier can't solve `xr =?= RightMoves (mk xl xr xL xR)` at reducible transparency. @[simp] theorem Subsequent.mk_right' (xL : xl → PGame) (xR : xr → PGame) (j : RightMoves (mk xl xr xL xR)) : Subsequent (xR j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac -- Porting note: linter claims these lemmas don't simplify? open Subsequent in attribute [nolint simpNF] mk_left mk_right mk_right' moveRight_mk_left moveRight_mk_right moveLeft_mk_left moveLeft_mk_right /-! ### Basic pre-games -/ /-- The pre-game `Zero` is defined by `0 = { | }`. -/ instance : Zero PGame := ⟨⟨PEmpty, PEmpty, PEmpty.elim, PEmpty.elim⟩⟩ @[simp] theorem zero_leftMoves : LeftMoves 0 = PEmpty := rfl #align pgame.zero_left_moves SetTheory.PGame.zero_leftMoves @[simp] theorem zero_rightMoves : RightMoves 0 = PEmpty := rfl #align pgame.zero_right_moves SetTheory.PGame.zero_rightMoves instance isEmpty_zero_leftMoves : IsEmpty (LeftMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_left_moves SetTheory.PGame.isEmpty_zero_leftMoves instance isEmpty_zero_rightMoves : IsEmpty (RightMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_right_moves SetTheory.PGame.isEmpty_zero_rightMoves instance : Inhabited PGame := ⟨0⟩ /-- The pre-game `One` is defined by `1 = { 0 | }`. -/ instance instOnePGame : One PGame := ⟨⟨PUnit, PEmpty, fun _ => 0, PEmpty.elim⟩⟩ @[simp] theorem one_leftMoves : LeftMoves 1 = PUnit := rfl #align pgame.one_left_moves SetTheory.PGame.one_leftMoves @[simp] theorem one_moveLeft (x) : moveLeft 1 x = 0 := rfl #align pgame.one_move_left SetTheory.PGame.one_moveLeft @[simp] theorem one_rightMoves : RightMoves 1 = PEmpty := rfl #align pgame.one_right_moves SetTheory.PGame.one_rightMoves instance uniqueOneLeftMoves : Unique (LeftMoves 1) := PUnit.unique #align pgame.unique_one_left_moves SetTheory.PGame.uniqueOneLeftMoves instance isEmpty_one_rightMoves : IsEmpty (RightMoves 1) := instIsEmptyPEmpty #align pgame.is_empty_one_right_moves SetTheory.PGame.isEmpty_one_rightMoves /-! ### Pre-game order relations -/ /-- The less or equal relation on pre-games. If `0 ≤ x`, then Left can win `x` as the second player. -/ instance le : LE PGame := ⟨Sym2.GameAdd.fix wf_isOption fun x y le => (∀ i, ¬le y (x.moveLeft i) (Sym2.GameAdd.snd_fst <| IsOption.moveLeft i)) ∧ ∀ j, ¬le (y.moveRight j) x (Sym2.GameAdd.fst_snd <| IsOption.moveRight j)⟩ /-- The less or fuzzy relation on pre-games. If `0 ⧏ x`, then Left can win `x` as the first player. -/ def LF (x y : PGame) : Prop := ¬y ≤ x #align pgame.lf SetTheory.PGame.LF @[inherit_doc] scoped infixl:50 " ⧏ " => PGame.LF @[simp] protected theorem not_le {x y : PGame} : ¬x ≤ y ↔ y ⧏ x := Iff.rfl #align pgame.not_le SetTheory.PGame.not_le @[simp] theorem not_lf {x y : PGame} : ¬x ⧏ y ↔ y ≤ x := Classical.not_not #align pgame.not_lf SetTheory.PGame.not_lf theorem _root_.LE.le.not_gf {x y : PGame} : x ≤ y → ¬y ⧏ x := not_lf.2 #align has_le.le.not_gf LE.le.not_gf theorem LF.not_ge {x y : PGame} : x ⧏ y → ¬y ≤ x := id #align pgame.lf.not_ge SetTheory.PGame.LF.not_ge /-- Definition of `x ≤ y` on pre-games, in terms of `⧏`. The ordering here is chosen so that `And.left` refer to moves by Left, and `And.right` refer to moves by Right. -/ theorem le_iff_forall_lf {x y : PGame} : x ≤ y ↔ (∀ i, x.moveLeft i ⧏ y) ∧ ∀ j, x ⧏ y.moveRight j := by unfold LE.le le simp only rw [Sym2.GameAdd.fix_eq] rfl #align pgame.le_iff_forall_lf SetTheory.PGame.le_iff_forall_lf /-- Definition of `x ≤ y` on pre-games built using the constructor. -/ @[simp] theorem mk_le_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ≤ mk yl yr yL yR ↔ (∀ i, xL i ⧏ mk yl yr yL yR) ∧ ∀ j, mk xl xr xL xR ⧏ yR j := le_iff_forall_lf #align pgame.mk_le_mk SetTheory.PGame.mk_le_mk theorem le_of_forall_lf {x y : PGame} (h₁ : ∀ i, x.moveLeft i ⧏ y) (h₂ : ∀ j, x ⧏ y.moveRight j) : x ≤ y := le_iff_forall_lf.2 ⟨h₁, h₂⟩ #align pgame.le_of_forall_lf SetTheory.PGame.le_of_forall_lf /-- Definition of `x ⧏ y` on pre-games, in terms of `≤`. The ordering here is chosen so that `or.inl` refer to moves by Left, and `or.inr` refer to moves by Right. -/ theorem lf_iff_exists_le {x y : PGame} : x ⧏ y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by rw [LF, le_iff_forall_lf, not_and_or] simp #align pgame.lf_iff_exists_le SetTheory.PGame.lf_iff_exists_le /-- Definition of `x ⧏ y` on pre-games built using the constructor. -/ @[simp] theorem mk_lf_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ⧏ mk yl yr yL yR ↔ (∃ i, mk xl xr xL xR ≤ yL i) ∨ ∃ j, xR j ≤ mk yl yr yL yR := lf_iff_exists_le #align pgame.mk_lf_mk SetTheory.PGame.mk_lf_mk theorem le_or_gf (x y : PGame) : x ≤ y ∨ y ⧏ x := by rw [← PGame.not_le] apply em #align pgame.le_or_gf SetTheory.PGame.le_or_gf theorem moveLeft_lf_of_le {x y : PGame} (h : x ≤ y) (i) : x.moveLeft i ⧏ y := (le_iff_forall_lf.1 h).1 i #align pgame.move_left_lf_of_le SetTheory.PGame.moveLeft_lf_of_le alias _root_.LE.le.moveLeft_lf := moveLeft_lf_of_le #align has_le.le.move_left_lf LE.le.moveLeft_lf theorem lf_moveRight_of_le {x y : PGame} (h : x ≤ y) (j) : x ⧏ y.moveRight j := (le_iff_forall_lf.1 h).2 j #align pgame.lf_move_right_of_le SetTheory.PGame.lf_moveRight_of_le alias _root_.LE.le.lf_moveRight := lf_moveRight_of_le #align has_le.le.lf_move_right LE.le.lf_moveRight theorem lf_of_moveRight_le {x y : PGame} {j} (h : x.moveRight j ≤ y) : x ⧏ y := lf_iff_exists_le.2 <| Or.inr ⟨j, h⟩ #align pgame.lf_of_move_right_le SetTheory.PGame.lf_of_moveRight_le theorem lf_of_le_moveLeft {x y : PGame} {i} (h : x ≤ y.moveLeft i) : x ⧏ y := lf_iff_exists_le.2 <| Or.inl ⟨i, h⟩ #align pgame.lf_of_le_move_left SetTheory.PGame.lf_of_le_moveLeft theorem lf_of_le_mk {xl xr xL xR y} : mk xl xr xL xR ≤ y → ∀ i, xL i ⧏ y := moveLeft_lf_of_le #align pgame.lf_of_le_mk SetTheory.PGame.lf_of_le_mk theorem lf_of_mk_le {x yl yr yL yR} : x ≤ mk yl yr yL yR → ∀ j, x ⧏ yR j := lf_moveRight_of_le #align pgame.lf_of_mk_le SetTheory.PGame.lf_of_mk_le theorem mk_lf_of_le {xl xr y j} (xL) {xR : xr → PGame} : xR j ≤ y → mk xl xr xL xR ⧏ y := @lf_of_moveRight_le (mk _ _ _ _) y j #align pgame.mk_lf_of_le SetTheory.PGame.mk_lf_of_le theorem lf_mk_of_le {x yl yr} {yL : yl → PGame} (yR) {i} : x ≤ yL i → x ⧏ mk yl yr yL yR := @lf_of_le_moveLeft x (mk _ _ _ _) i #align pgame.lf_mk_of_le SetTheory.PGame.lf_mk_of_le /- We prove that `x ≤ y → y ≤ z → x ≤ z` inductively, by also simultaneously proving its cyclic reorderings. This auxiliary lemma is used during said induction. -/ private theorem le_trans_aux {x y z : PGame} (h₁ : ∀ {i}, y ≤ z → z ≤ x.moveLeft i → y ≤ x.moveLeft i) (h₂ : ∀ {j}, z.moveRight j ≤ x → x ≤ y → z.moveRight j ≤ y) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := le_of_forall_lf (fun i => PGame.not_le.1 fun h => (h₁ hyz h).not_gf <| hxy.moveLeft_lf i) fun j => PGame.not_le.1 fun h => (h₂ h hxy).not_gf <| hyz.lf_moveRight j instance : Preorder PGame := { PGame.le with le_refl := fun x => by induction' x with _ _ _ _ IHl IHr exact le_of_forall_lf (fun i => lf_of_le_moveLeft (IHl i)) fun i => lf_of_moveRight_le (IHr i) le_trans := by suffices ∀ {x y z : PGame}, (x ≤ y → y ≤ z → x ≤ z) ∧ (y ≤ z → z ≤ x → y ≤ x) ∧ (z ≤ x → x ≤ y → z ≤ y) from fun x y z => this.1 intro x y z induction' x with xl xr xL xR IHxl IHxr generalizing y z induction' y with yl yr yL yR IHyl IHyr generalizing z induction' z with zl zr zL zR IHzl IHzr exact ⟨le_trans_aux (fun {i} => (IHxl i).2.1) fun {j} => (IHzr j).2.2, le_trans_aux (fun {i} => (IHyl i).2.2) fun {j} => (IHxr j).1, le_trans_aux (fun {i} => (IHzl i).1) fun {j} => (IHyr j).2.1⟩ lt := fun x y => x ≤ y ∧ x ⧏ y } theorem lt_iff_le_and_lf {x y : PGame} : x < y ↔ x ≤ y ∧ x ⧏ y := Iff.rfl #align pgame.lt_iff_le_and_lf SetTheory.PGame.lt_iff_le_and_lf theorem lt_of_le_of_lf {x y : PGame} (h₁ : x ≤ y) (h₂ : x ⧏ y) : x < y := ⟨h₁, h₂⟩ #align pgame.lt_of_le_of_lf SetTheory.PGame.lt_of_le_of_lf theorem lf_of_lt {x y : PGame} (h : x < y) : x ⧏ y := h.2 #align pgame.lf_of_lt SetTheory.PGame.lf_of_lt alias _root_.LT.lt.lf := lf_of_lt #align has_lt.lt.lf LT.lt.lf theorem lf_irrefl (x : PGame) : ¬x ⧏ x := le_rfl.not_gf #align pgame.lf_irrefl SetTheory.PGame.lf_irrefl instance : IsIrrefl _ (· ⧏ ·) := ⟨lf_irrefl⟩ @[trans] theorem lf_of_le_of_lf {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ⧏ z) : x ⧏ z := by rw [← PGame.not_le] at h₂ ⊢ exact fun h₃ => h₂ (h₃.trans h₁) #align pgame.lf_of_le_of_lf SetTheory.PGame.lf_of_le_of_lf -- Porting note (#10754): added instance instance : Trans (· ≤ ·) (· ⧏ ·) (· ⧏ ·) := ⟨lf_of_le_of_lf⟩ @[trans] theorem lf_of_lf_of_le {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≤ z) : x ⧏ z := by rw [← PGame.not_le] at h₁ ⊢ exact fun h₃ => h₁ (h₂.trans h₃) #align pgame.lf_of_lf_of_le SetTheory.PGame.lf_of_lf_of_le -- Porting note (#10754): added instance instance : Trans (· ⧏ ·) (· ≤ ·) (· ⧏ ·) := ⟨lf_of_lf_of_le⟩ alias _root_.LE.le.trans_lf := lf_of_le_of_lf #align has_le.le.trans_lf LE.le.trans_lf alias LF.trans_le := lf_of_lf_of_le #align pgame.lf.trans_le SetTheory.PGame.LF.trans_le @[trans] theorem lf_of_lt_of_lf {x y z : PGame} (h₁ : x < y) (h₂ : y ⧏ z) : x ⧏ z := h₁.le.trans_lf h₂ #align pgame.lf_of_lt_of_lf SetTheory.PGame.lf_of_lt_of_lf @[trans] theorem lf_of_lf_of_lt {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y < z) : x ⧏ z := h₁.trans_le h₂.le #align pgame.lf_of_lf_of_lt SetTheory.PGame.lf_of_lf_of_lt alias _root_.LT.lt.trans_lf := lf_of_lt_of_lf #align has_lt.lt.trans_lf LT.lt.trans_lf alias LF.trans_lt := lf_of_lf_of_lt #align pgame.lf.trans_lt SetTheory.PGame.LF.trans_lt theorem moveLeft_lf {x : PGame} : ∀ i, x.moveLeft i ⧏ x := le_rfl.moveLeft_lf #align pgame.move_left_lf SetTheory.PGame.moveLeft_lf theorem lf_moveRight {x : PGame} : ∀ j, x ⧏ x.moveRight j := le_rfl.lf_moveRight #align pgame.lf_move_right SetTheory.PGame.lf_moveRight theorem lf_mk {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i) : xL i ⧏ mk xl xr xL xR := @moveLeft_lf (mk _ _ _ _) i #align pgame.lf_mk SetTheory.PGame.lf_mk theorem mk_lf {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j) : mk xl xr xL xR ⧏ xR j := @lf_moveRight (mk _ _ _ _) j #align pgame.mk_lf SetTheory.PGame.mk_lf /-- This special case of `PGame.le_of_forall_lf` is useful when dealing with surreals, where `<` is preferred over `⧏`. -/ theorem le_of_forall_lt {x y : PGame} (h₁ : ∀ i, x.moveLeft i < y) (h₂ : ∀ j, x < y.moveRight j) : x ≤ y := le_of_forall_lf (fun i => (h₁ i).lf) fun i => (h₂ i).lf #align pgame.le_of_forall_lt SetTheory.PGame.le_of_forall_lt /-- The definition of `x ≤ y` on pre-games, in terms of `≤` two moves later. -/ theorem le_def {x y : PGame} : x ≤ y ↔ (∀ i, (∃ i', x.moveLeft i ≤ y.moveLeft i') ∨ ∃ j, (x.moveLeft i).moveRight j ≤ y) ∧ ∀ j, (∃ i, x ≤ (y.moveRight j).moveLeft i) ∨ ∃ j', x.moveRight j' ≤ y.moveRight j := by rw [le_iff_forall_lf] conv => lhs simp only [lf_iff_exists_le] #align pgame.le_def SetTheory.PGame.le_def /-- The definition of `x ⧏ y` on pre-games, in terms of `⧏` two moves later. -/ theorem lf_def {x y : PGame} : x ⧏ y ↔ (∃ i, (∀ i', x.moveLeft i' ⧏ y.moveLeft i) ∧ ∀ j, x ⧏ (y.moveLeft i).moveRight j) ∨ ∃ j, (∀ i, (x.moveRight j).moveLeft i ⧏ y) ∧ ∀ j', x.moveRight j ⧏ y.moveRight j' := by rw [lf_iff_exists_le] conv => lhs simp only [le_iff_forall_lf] #align pgame.lf_def SetTheory.PGame.lf_def /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ⧏`. -/ theorem zero_le_lf {x : PGame} : 0 ≤ x ↔ ∀ j, 0 ⧏ x.moveRight j := by rw [le_iff_forall_lf] simp #align pgame.zero_le_lf SetTheory.PGame.zero_le_lf /-- The definition of `x ≤ 0` on pre-games, in terms of `⧏ 0`. -/ theorem le_zero_lf {x : PGame} : x ≤ 0 ↔ ∀ i, x.moveLeft i ⧏ 0 := by rw [le_iff_forall_lf] simp #align pgame.le_zero_lf SetTheory.PGame.le_zero_lf /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ≤`. -/ theorem zero_lf_le {x : PGame} : 0 ⧏ x ↔ ∃ i, 0 ≤ x.moveLeft i := by rw [lf_iff_exists_le] simp #align pgame.zero_lf_le SetTheory.PGame.zero_lf_le /-- The definition of `x ⧏ 0` on pre-games, in terms of `≤ 0`. -/ theorem lf_zero_le {x : PGame} : x ⧏ 0 ↔ ∃ j, x.moveRight j ≤ 0 := by rw [lf_iff_exists_le] simp #align pgame.lf_zero_le SetTheory.PGame.lf_zero_le /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ≤` two moves later. -/ theorem zero_le {x : PGame} : 0 ≤ x ↔ ∀ j, ∃ i, 0 ≤ (x.moveRight j).moveLeft i := by rw [le_def] simp #align pgame.zero_le SetTheory.PGame.zero_le /-- The definition of `x ≤ 0` on pre-games, in terms of `≤ 0` two moves later. -/ theorem le_zero {x : PGame} : x ≤ 0 ↔ ∀ i, ∃ j, (x.moveLeft i).moveRight j ≤ 0 := by rw [le_def] simp #align pgame.le_zero SetTheory.PGame.le_zero /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ⧏` two moves later. -/ theorem zero_lf {x : PGame} : 0 ⧏ x ↔ ∃ i, ∀ j, 0 ⧏ (x.moveLeft i).moveRight j := by rw [lf_def] simp #align pgame.zero_lf SetTheory.PGame.zero_lf /-- The definition of `x ⧏ 0` on pre-games, in terms of `⧏ 0` two moves later. -/ theorem lf_zero {x : PGame} : x ⧏ 0 ↔ ∃ j, ∀ i, (x.moveRight j).moveLeft i ⧏ 0 := by rw [lf_def] simp #align pgame.lf_zero SetTheory.PGame.lf_zero @[simp] theorem zero_le_of_isEmpty_rightMoves (x : PGame) [IsEmpty x.RightMoves] : 0 ≤ x := zero_le.2 isEmptyElim #align pgame.zero_le_of_is_empty_right_moves SetTheory.PGame.zero_le_of_isEmpty_rightMoves @[simp] theorem le_zero_of_isEmpty_leftMoves (x : PGame) [IsEmpty x.LeftMoves] : x ≤ 0 := le_zero.2 isEmptyElim #align pgame.le_zero_of_is_empty_left_moves SetTheory.PGame.le_zero_of_isEmpty_leftMoves /-- Given a game won by the right player when they play second, provide a response to any move by left. -/ noncomputable def rightResponse {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).RightMoves := Classical.choose <| (le_zero.1 h) i #align pgame.right_response SetTheory.PGame.rightResponse /-- Show that the response for right provided by `rightResponse` preserves the right-player-wins condition. -/ theorem rightResponse_spec {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).moveRight (rightResponse h i) ≤ 0 := Classical.choose_spec <| (le_zero.1 h) i #align pgame.right_response_spec SetTheory.PGame.rightResponse_spec /-- Given a game won by the left player when they play second, provide a response to any move by right. -/ noncomputable def leftResponse {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : (x.moveRight j).LeftMoves := Classical.choose <| (zero_le.1 h) j #align pgame.left_response SetTheory.PGame.leftResponse /-- Show that the response for left provided by `leftResponse` preserves the left-player-wins condition. -/ theorem leftResponse_spec {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : 0 ≤ (x.moveRight j).moveLeft (leftResponse h j) := Classical.choose_spec <| (zero_le.1 h) j #align pgame.left_response_spec SetTheory.PGame.leftResponse_spec #noalign pgame.upper_bound #noalign pgame.upper_bound_right_moves_empty #noalign pgame.le_upper_bound #noalign pgame.upper_bound_mem_upper_bounds /-- A small family of pre-games is bounded above. -/ lemma bddAbove_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddAbove (Set.range f) := by let x : PGame.{u} := ⟨Σ i, (f $ (equivShrink.{u} ι).symm i).LeftMoves, PEmpty, fun x ↦ moveLeft _ x.2, PEmpty.elim⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @moveLeft_lf x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded above. -/ lemma bddAbove_of_small (s : Set PGame.{u}) [Small.{u} s] : BddAbove s := by simpa using bddAbove_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_above_of_small SetTheory.PGame.bddAbove_of_small #noalign pgame.lower_bound #noalign pgame.lower_bound_left_moves_empty #noalign pgame.lower_bound_le #noalign pgame.lower_bound_mem_lower_bounds /-- A small family of pre-games is bounded below. -/ lemma bddBelow_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddBelow (Set.range f) := by let x : PGame.{u} := ⟨PEmpty, Σ i, (f $ (equivShrink.{u} ι).symm i).RightMoves, PEmpty.elim, fun x ↦ moveRight _ x.2⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @lf_moveRight x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded below. -/ lemma bddBelow_of_small (s : Set PGame.{u}) [Small.{u} s] : BddBelow s := by simpa using bddBelow_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_below_of_small SetTheory.PGame.bddBelow_of_small /-- The equivalence relation on pre-games. Two pre-games `x`, `y` are equivalent if `x ≤ y` and `y ≤ x`. If `x ≈ 0`, then the second player can always win `x`. -/ def Equiv (x y : PGame) : Prop := x ≤ y ∧ y ≤ x #align pgame.equiv SetTheory.PGame.Equiv -- Porting note: deleted the scoped notation due to notation overloading with the setoid -- instance and this causes the PGame.equiv docstring to not show up on hover. instance : IsEquiv _ PGame.Equiv where refl _ := ⟨le_rfl, le_rfl⟩ trans := fun _ _ _ ⟨xy, yx⟩ ⟨yz, zy⟩ => ⟨xy.trans yz, zy.trans yx⟩ symm _ _ := And.symm -- Porting note: moved the setoid instance from Basic.lean to here instance setoid : Setoid PGame := ⟨Equiv, refl, symm, Trans.trans⟩ #align pgame.setoid SetTheory.PGame.setoid theorem Equiv.le {x y : PGame} (h : x ≈ y) : x ≤ y := h.1 #align pgame.equiv.le SetTheory.PGame.Equiv.le theorem Equiv.ge {x y : PGame} (h : x ≈ y) : y ≤ x := h.2 #align pgame.equiv.ge SetTheory.PGame.Equiv.ge @[refl, simp] theorem equiv_rfl {x : PGame} : x ≈ x := refl x #align pgame.equiv_rfl SetTheory.PGame.equiv_rfl theorem equiv_refl (x : PGame) : x ≈ x := refl x #align pgame.equiv_refl SetTheory.PGame.equiv_refl @[symm] protected theorem Equiv.symm {x y : PGame} : (x ≈ y) → (y ≈ x) := symm #align pgame.equiv.symm SetTheory.PGame.Equiv.symm @[trans] protected theorem Equiv.trans {x y z : PGame} : (x ≈ y) → (y ≈ z) → (x ≈ z) := _root_.trans #align pgame.equiv.trans SetTheory.PGame.Equiv.trans protected theorem equiv_comm {x y : PGame} : (x ≈ y) ↔ (y ≈ x) := comm #align pgame.equiv_comm SetTheory.PGame.equiv_comm theorem equiv_of_eq {x y : PGame} (h : x = y) : x ≈ y := by subst h; rfl #align pgame.equiv_of_eq SetTheory.PGame.equiv_of_eq @[trans] theorem le_of_le_of_equiv {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ≈ z) : x ≤ z := h₁.trans h₂.1 #align pgame.le_of_le_of_equiv SetTheory.PGame.le_of_le_of_equiv instance : Trans ((· ≤ ·) : PGame → PGame → Prop) ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_le_of_equiv @[trans] theorem le_of_equiv_of_le {x y z : PGame} (h₁ : x ≈ y) : y ≤ z → x ≤ z := h₁.1.trans #align pgame.le_of_equiv_of_le SetTheory.PGame.le_of_equiv_of_le instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_equiv_of_le theorem LF.not_equiv {x y : PGame} (h : x ⧏ y) : ¬(x ≈ y) := fun h' => h.not_ge h'.2 #align pgame.lf.not_equiv SetTheory.PGame.LF.not_equiv theorem LF.not_equiv' {x y : PGame} (h : x ⧏ y) : ¬(y ≈ x) := fun h' => h.not_ge h'.1 #align pgame.lf.not_equiv' SetTheory.PGame.LF.not_equiv' theorem LF.not_gt {x y : PGame} (h : x ⧏ y) : ¬y < x := fun h' => h.not_ge h'.le #align pgame.lf.not_gt SetTheory.PGame.LF.not_gt theorem le_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ ≤ y₁) : x₂ ≤ y₂ := hx.2.trans (h.trans hy.1) #align pgame.le_congr_imp SetTheory.PGame.le_congr_imp theorem le_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ≤ y₁ ↔ x₂ ≤ y₂ := ⟨le_congr_imp hx hy, le_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.le_congr SetTheory.PGame.le_congr theorem le_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ≤ y ↔ x₂ ≤ y := le_congr hx equiv_rfl #align pgame.le_congr_left SetTheory.PGame.le_congr_left theorem le_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ≤ y₁ ↔ x ≤ y₂ := le_congr equiv_rfl hy #align pgame.le_congr_right SetTheory.PGame.le_congr_right theorem lf_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ ↔ x₂ ⧏ y₂ := PGame.not_le.symm.trans <| (not_congr (le_congr hy hx)).trans PGame.not_le #align pgame.lf_congr SetTheory.PGame.lf_congr theorem lf_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ → x₂ ⧏ y₂ := (lf_congr hx hy).1 #align pgame.lf_congr_imp SetTheory.PGame.lf_congr_imp theorem lf_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ⧏ y ↔ x₂ ⧏ y := lf_congr hx equiv_rfl #align pgame.lf_congr_left SetTheory.PGame.lf_congr_left theorem lf_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ⧏ y₁ ↔ x ⧏ y₂ := lf_congr equiv_rfl hy #align pgame.lf_congr_right SetTheory.PGame.lf_congr_right @[trans] theorem lf_of_lf_of_equiv {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≈ z) : x ⧏ z := lf_congr_imp equiv_rfl h₂ h₁ #align pgame.lf_of_lf_of_equiv SetTheory.PGame.lf_of_lf_of_equiv @[trans] theorem lf_of_equiv_of_lf {x y z : PGame} (h₁ : x ≈ y) : y ⧏ z → x ⧏ z := lf_congr_imp (Equiv.symm h₁) equiv_rfl #align pgame.lf_of_equiv_of_lf SetTheory.PGame.lf_of_equiv_of_lf @[trans] theorem lt_of_lt_of_equiv {x y z : PGame} (h₁ : x < y) (h₂ : y ≈ z) : x < z := h₁.trans_le h₂.1 #align pgame.lt_of_lt_of_equiv SetTheory.PGame.lt_of_lt_of_equiv @[trans] theorem lt_of_equiv_of_lt {x y z : PGame} (h₁ : x ≈ y) : y < z → x < z := h₁.1.trans_lt #align pgame.lt_of_equiv_of_lt SetTheory.PGame.lt_of_equiv_of_lt instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) where trans := lt_of_equiv_of_lt theorem lt_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ < y₁) : x₂ < y₂ := hx.2.trans_lt (h.trans_le hy.1) #align pgame.lt_congr_imp SetTheory.PGame.lt_congr_imp theorem lt_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ < y₁ ↔ x₂ < y₂ := ⟨lt_congr_imp hx hy, lt_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.lt_congr SetTheory.PGame.lt_congr theorem lt_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ < y ↔ x₂ < y := lt_congr hx equiv_rfl #align pgame.lt_congr_left SetTheory.PGame.lt_congr_left theorem lt_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x < y₁ ↔ x < y₂ := lt_congr equiv_rfl hy #align pgame.lt_congr_right SetTheory.PGame.lt_congr_right theorem lt_or_equiv_of_le {x y : PGame} (h : x ≤ y) : x < y ∨ (x ≈ y) := and_or_left.mp ⟨h, (em <| y ≤ x).symm.imp_left PGame.not_le.1⟩ #align pgame.lt_or_equiv_of_le SetTheory.PGame.lt_or_equiv_of_le theorem lf_or_equiv_or_gf (x y : PGame) : x ⧏ y ∨ (x ≈ y) ∨ y ⧏ x := by by_cases h : x ⧏ y · exact Or.inl h · right cases' lt_or_equiv_of_le (PGame.not_lf.1 h) with h' h' · exact Or.inr h'.lf · exact Or.inl (Equiv.symm h') #align pgame.lf_or_equiv_or_gf SetTheory.PGame.lf_or_equiv_or_gf theorem equiv_congr_left {y₁ y₂ : PGame} : (y₁ ≈ y₂) ↔ ∀ x₁, (x₁ ≈ y₁) ↔ (x₁ ≈ y₂) := ⟨fun h _ => ⟨fun h' => Equiv.trans h' h, fun h' => Equiv.trans h' (Equiv.symm h)⟩, fun h => (h y₁).1 <| equiv_rfl⟩ #align pgame.equiv_congr_left SetTheory.PGame.equiv_congr_left theorem equiv_congr_right {x₁ x₂ : PGame} : (x₁ ≈ x₂) ↔ ∀ y₁, (x₁ ≈ y₁) ↔ (x₂ ≈ y₁) := ⟨fun h _ => ⟨fun h' => Equiv.trans (Equiv.symm h) h', fun h' => Equiv.trans h h'⟩, fun h => (h x₂).2 <| equiv_rfl⟩ #align pgame.equiv_congr_right SetTheory.PGame.equiv_congr_right theorem equiv_of_mk_equiv {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves) (hl : ∀ i, x.moveLeft i ≈ y.moveLeft (L i)) (hr : ∀ j, x.moveRight j ≈ y.moveRight (R j)) : x ≈ y := by constructor <;> rw [le_def] · exact ⟨fun i => Or.inl ⟨_, (hl i).1⟩, fun j => Or.inr ⟨_, by simpa using (hr (R.symm j)).1⟩⟩ · exact ⟨fun i => Or.inl ⟨_, by simpa using (hl (L.symm i)).2⟩, fun j => Or.inr ⟨_, (hr j).2⟩⟩ #align pgame.equiv_of_mk_equiv SetTheory.PGame.equiv_of_mk_equiv /-- The fuzzy, confused, or incomparable relation on pre-games. If `x ‖ 0`, then the first player can always win `x`. -/ def Fuzzy (x y : PGame) : Prop := x ⧏ y ∧ y ⧏ x #align pgame.fuzzy SetTheory.PGame.Fuzzy @[inherit_doc] scoped infixl:50 " ‖ " => PGame.Fuzzy @[symm] theorem Fuzzy.swap {x y : PGame} : x ‖ y → y ‖ x := And.symm #align pgame.fuzzy.swap SetTheory.PGame.Fuzzy.swap instance : IsSymm _ (· ‖ ·) := ⟨fun _ _ => Fuzzy.swap⟩ theorem Fuzzy.swap_iff {x y : PGame} : x ‖ y ↔ y ‖ x := ⟨Fuzzy.swap, Fuzzy.swap⟩ #align pgame.fuzzy.swap_iff SetTheory.PGame.Fuzzy.swap_iff theorem fuzzy_irrefl (x : PGame) : ¬x ‖ x := fun h => lf_irrefl x h.1 #align pgame.fuzzy_irrefl SetTheory.PGame.fuzzy_irrefl instance : IsIrrefl _ (· ‖ ·) := ⟨fuzzy_irrefl⟩ theorem lf_iff_lt_or_fuzzy {x y : PGame} : x ⧏ y ↔ x < y ∨ x ‖ y := by simp only [lt_iff_le_and_lf, Fuzzy, ← PGame.not_le] tauto #align pgame.lf_iff_lt_or_fuzzy SetTheory.PGame.lf_iff_lt_or_fuzzy theorem lf_of_fuzzy {x y : PGame} (h : x ‖ y) : x ⧏ y := lf_iff_lt_or_fuzzy.2 (Or.inr h) #align pgame.lf_of_fuzzy SetTheory.PGame.lf_of_fuzzy alias Fuzzy.lf := lf_of_fuzzy #align pgame.fuzzy.lf SetTheory.PGame.Fuzzy.lf theorem lt_or_fuzzy_of_lf {x y : PGame} : x ⧏ y → x < y ∨ x ‖ y := lf_iff_lt_or_fuzzy.1 #align pgame.lt_or_fuzzy_of_lf SetTheory.PGame.lt_or_fuzzy_of_lf theorem Fuzzy.not_equiv {x y : PGame} (h : x ‖ y) : ¬(x ≈ y) := fun h' => h'.1.not_gf h.2 #align pgame.fuzzy.not_equiv SetTheory.PGame.Fuzzy.not_equiv theorem Fuzzy.not_equiv' {x y : PGame} (h : x ‖ y) : ¬(y ≈ x) := fun h' => h'.2.not_gf h.2 #align pgame.fuzzy.not_equiv' SetTheory.PGame.Fuzzy.not_equiv' theorem not_fuzzy_of_le {x y : PGame} (h : x ≤ y) : ¬x ‖ y := fun h' => h'.2.not_ge h #align pgame.not_fuzzy_of_le SetTheory.PGame.not_fuzzy_of_le theorem not_fuzzy_of_ge {x y : PGame} (h : y ≤ x) : ¬x ‖ y := fun h' => h'.1.not_ge h #align pgame.not_fuzzy_of_ge SetTheory.PGame.not_fuzzy_of_ge theorem Equiv.not_fuzzy {x y : PGame} (h : x ≈ y) : ¬x ‖ y := not_fuzzy_of_le h.1 #align pgame.equiv.not_fuzzy SetTheory.PGame.Equiv.not_fuzzy theorem Equiv.not_fuzzy' {x y : PGame} (h : x ≈ y) : ¬y ‖ x := not_fuzzy_of_le h.2 #align pgame.equiv.not_fuzzy' SetTheory.PGame.Equiv.not_fuzzy' theorem fuzzy_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ ↔ x₂ ‖ y₂ := show _ ∧ _ ↔ _ ∧ _ by rw [lf_congr hx hy, lf_congr hy hx] #align pgame.fuzzy_congr SetTheory.PGame.fuzzy_congr theorem fuzzy_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ → x₂ ‖ y₂ := (fuzzy_congr hx hy).1 #align pgame.fuzzy_congr_imp SetTheory.PGame.fuzzy_congr_imp theorem fuzzy_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ‖ y ↔ x₂ ‖ y := fuzzy_congr hx equiv_rfl #align pgame.fuzzy_congr_left SetTheory.PGame.fuzzy_congr_left theorem fuzzy_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ‖ y₁ ↔ x ‖ y₂ := fuzzy_congr equiv_rfl hy #align pgame.fuzzy_congr_right SetTheory.PGame.fuzzy_congr_right @[trans] theorem fuzzy_of_fuzzy_of_equiv {x y z : PGame} (h₁ : x ‖ y) (h₂ : y ≈ z) : x ‖ z := (fuzzy_congr_right h₂).1 h₁ #align pgame.fuzzy_of_fuzzy_of_equiv SetTheory.PGame.fuzzy_of_fuzzy_of_equiv @[trans] theorem fuzzy_of_equiv_of_fuzzy {x y z : PGame} (h₁ : x ≈ y) (h₂ : y ‖ z) : x ‖ z := (fuzzy_congr_left h₁).2 h₂ #align pgame.fuzzy_of_equiv_of_fuzzy SetTheory.PGame.fuzzy_of_equiv_of_fuzzy /-- Exactly one of the following is true (although we don't prove this here). -/ theorem lt_or_equiv_or_gt_or_fuzzy (x y : PGame) : x < y ∨ (x ≈ y) ∨ y < x ∨ x ‖ y := by cases' le_or_gf x y with h₁ h₁ <;> cases' le_or_gf y x with h₂ h₂ · right left exact ⟨h₁, h₂⟩ · left exact ⟨h₁, h₂⟩ · right right left exact ⟨h₂, h₁⟩ · right right right exact ⟨h₂, h₁⟩ #align pgame.lt_or_equiv_or_gt_or_fuzzy SetTheory.PGame.lt_or_equiv_or_gt_or_fuzzy theorem lt_or_equiv_or_gf (x y : PGame) : x < y ∨ (x ≈ y) ∨ y ⧏ x := by rw [lf_iff_lt_or_fuzzy, Fuzzy.swap_iff] exact lt_or_equiv_or_gt_or_fuzzy x y #align pgame.lt_or_equiv_or_gf SetTheory.PGame.lt_or_equiv_or_gf /-! ### Relabellings -/ /-- `Relabelling x y` says that `x` and `y` are really the same game, just dressed up differently. Specifically, there is a bijection between the moves for Left in `x` and in `y`, and similarly for Right, and under these bijections we inductively have `Relabelling`s for the consequent games. -/ inductive Relabelling : PGame.{u} → PGame.{u} → Type (u + 1) | mk : ∀ {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves), (∀ i, Relabelling (x.moveLeft i) (y.moveLeft (L i))) → (∀ j, Relabelling (x.moveRight j) (y.moveRight (R j))) → Relabelling x y #align pgame.relabelling SetTheory.PGame.Relabelling @[inherit_doc] scoped infixl:50 " ≡r " => PGame.Relabelling namespace Relabelling variable {x y : PGame.{u}} /-- A constructor for relabellings swapping the equivalences. -/ def mk' (L : y.LeftMoves ≃ x.LeftMoves) (R : y.RightMoves ≃ x.RightMoves) (hL : ∀ i, x.moveLeft (L i) ≡r y.moveLeft i) (hR : ∀ j, x.moveRight (R j) ≡r y.moveRight j) : x ≡r y := ⟨L.symm, R.symm, fun i => by simpa using hL (L.symm i), fun j => by simpa using hR (R.symm j)⟩ #align pgame.relabelling.mk' SetTheory.PGame.Relabelling.mk' /-- The equivalence between left moves of `x` and `y` given by the relabelling. -/ def leftMovesEquiv : x ≡r y → x.LeftMoves ≃ y.LeftMoves | ⟨L,_, _,_⟩ => L #align pgame.relabelling.left_moves_equiv SetTheory.PGame.Relabelling.leftMovesEquiv @[simp] theorem mk_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).leftMovesEquiv = L := rfl #align pgame.relabelling.mk_left_moves_equiv SetTheory.PGame.Relabelling.mk_leftMovesEquiv @[simp] theorem mk'_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).leftMovesEquiv = L.symm := rfl #align pgame.relabelling.mk'_left_moves_equiv SetTheory.PGame.Relabelling.mk'_leftMovesEquiv /-- The equivalence between right moves of `x` and `y` given by the relabelling. -/ def rightMovesEquiv : x ≡r y → x.RightMoves ≃ y.RightMoves | ⟨_, R, _, _⟩ => R #align pgame.relabelling.right_moves_equiv SetTheory.PGame.Relabelling.rightMovesEquiv @[simp] theorem mk_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).rightMovesEquiv = R := rfl #align pgame.relabelling.mk_right_moves_equiv SetTheory.PGame.Relabelling.mk_rightMovesEquiv @[simp] theorem mk'_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).rightMovesEquiv = R.symm := rfl #align pgame.relabelling.mk'_right_moves_equiv SetTheory.PGame.Relabelling.mk'_rightMovesEquiv /-- A left move of `x` is a relabelling of a left move of `y`. -/ def moveLeft : ∀ (r : x ≡r y) (i : x.LeftMoves), x.moveLeft i ≡r y.moveLeft (r.leftMovesEquiv i) | ⟨_, _, hL, _⟩ => hL #align pgame.relabelling.move_left SetTheory.PGame.Relabelling.moveLeft /-- A left move of `y` is a relabelling of a left move of `x`. -/ def moveLeftSymm : ∀ (r : x ≡r y) (i : y.LeftMoves), x.moveLeft (r.leftMovesEquiv.symm i) ≡r y.moveLeft i | ⟨L, R, hL, hR⟩, i => by simpa using hL (L.symm i) #align pgame.relabelling.move_left_symm SetTheory.PGame.Relabelling.moveLeftSymm /-- A right move of `x` is a relabelling of a right move of `y`. -/ def moveRight : ∀ (r : x ≡r y) (i : x.RightMoves), x.moveRight i ≡r y.moveRight (r.rightMovesEquiv i) | ⟨_, _, _, hR⟩ => hR #align pgame.relabelling.move_right SetTheory.PGame.Relabelling.moveRight /-- A right move of `y` is a relabelling of a right move of `x`. -/ def moveRightSymm : ∀ (r : x ≡r y) (i : y.RightMoves), x.moveRight (r.rightMovesEquiv.symm i) ≡r y.moveRight i | ⟨L, R, hL, hR⟩, i => by simpa using hR (R.symm i) #align pgame.relabelling.move_right_symm SetTheory.PGame.Relabelling.moveRightSymm /-- The identity relabelling. -/ @[refl] def refl (x : PGame) : x ≡r x := ⟨Equiv.refl _, Equiv.refl _, fun i => refl _, fun j => refl _⟩ termination_by x #align pgame.relabelling.refl SetTheory.PGame.Relabelling.refl instance (x : PGame) : Inhabited (x ≡r x) := ⟨refl _⟩ /-- Flip a relabelling. -/ @[symm] def symm : ∀ {x y : PGame}, x ≡r y → y ≡r x | _, _, ⟨L, R, hL, hR⟩ => mk' L R (fun i => (hL i).symm) fun j => (hR j).symm #align pgame.relabelling.symm SetTheory.PGame.Relabelling.symm theorem le {x y : PGame} (r : x ≡r y) : x ≤ y := le_def.2 ⟨fun i => Or.inl ⟨_, (r.moveLeft i).le⟩, fun j => Or.inr ⟨_, (r.moveRightSymm j).le⟩⟩ termination_by x #align pgame.relabelling.le SetTheory.PGame.Relabelling.le theorem ge {x y : PGame} (r : x ≡r y) : y ≤ x := r.symm.le #align pgame.relabelling.ge SetTheory.PGame.Relabelling.ge /-- A relabelling lets us prove equivalence of games. -/ theorem equiv (r : x ≡r y) : x ≈ y := ⟨r.le, r.ge⟩ #align pgame.relabelling.equiv SetTheory.PGame.Relabelling.equiv /-- Transitivity of relabelling. -/ @[trans] def trans : ∀ {x y z : PGame}, x ≡r y → y ≡r z → x ≡r z | _, _, _, ⟨L₁, R₁, hL₁, hR₁⟩, ⟨L₂, R₂, hL₂, hR₂⟩ => ⟨L₁.trans L₂, R₁.trans R₂, fun i => (hL₁ i).trans (hL₂ _), fun j => (hR₁ j).trans (hR₂ _)⟩ #align pgame.relabelling.trans SetTheory.PGame.Relabelling.trans /-- Any game without left or right moves is a relabelling of 0. -/ def isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≡r 0 := ⟨Equiv.equivPEmpty _, Equiv.equivOfIsEmpty _ _, isEmptyElim, isEmptyElim⟩ #align pgame.relabelling.is_empty SetTheory.PGame.Relabelling.isEmpty end Relabelling theorem Equiv.isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≈ 0 := (Relabelling.isEmpty x).equiv #align pgame.equiv.is_empty SetTheory.PGame.Equiv.isEmpty instance {x y : PGame} : Coe (x ≡r y) (x ≈ y) := ⟨Relabelling.equiv⟩ /-- Replace the types indexing the next moves for Left and Right by equivalent types. -/ def relabel {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) : PGame := ⟨xl', xr', x.moveLeft ∘ el, x.moveRight ∘ er⟩ #align pgame.relabel SetTheory.PGame.relabel @[simp] theorem relabel_moveLeft' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : xl') : moveLeft (relabel el er) i = x.moveLeft (el i) := rfl #align pgame.relabel_move_left' SetTheory.PGame.relabel_moveLeft'
Mathlib/SetTheory/Game/PGame.lean
1,221
1,222
theorem relabel_moveLeft {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : x.LeftMoves) : moveLeft (relabel el er) (el.symm i) = x.moveLeft i := by
simp
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import Mathlib.Algebra.BigOperators.Ring import Mathlib.Data.Fintype.Basic import Mathlib.Data.Int.GCD import Mathlib.RingTheory.Coprime.Basic #align_import ring_theory.coprime.lemmas from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226" /-! # Additional lemmas about elements of a ring satisfying `IsCoprime` and elements of a monoid satisfying `IsRelPrime` These lemmas are in a separate file to the definition of `IsCoprime` or `IsRelPrime` as they require more imports. Notably, this includes lemmas about `Finset.prod` as this requires importing BigOperators, and lemmas about `Pow` since these are easiest to prove via `Finset.prod`. -/ universe u v section IsCoprime variable {R : Type u} {I : Type v} [CommSemiring R] {x y z : R} {s : I → R} {t : Finset I} section theorem Int.isCoprime_iff_gcd_eq_one {m n : ℤ} : IsCoprime m n ↔ Int.gcd m n = 1 := by constructor · rintro ⟨a, b, h⟩ have : 1 = m * a + n * b := by rwa [mul_comm m, mul_comm n, eq_comm] exact Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, this⟩) · rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one] intro h exact ⟨_, _, h⟩ theorem Nat.isCoprime_iff_coprime {m n : ℕ} : IsCoprime (m : ℤ) n ↔ Nat.Coprime m n := by rw [Int.isCoprime_iff_gcd_eq_one, Int.gcd_natCast_natCast] #align nat.is_coprime_iff_coprime Nat.isCoprime_iff_coprime alias ⟨IsCoprime.nat_coprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime #align is_coprime.nat_coprime IsCoprime.nat_coprime #align nat.coprime.is_coprime Nat.Coprime.isCoprime theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) : IsCoprime (a : R) (b : R) := by rw [← isCoprime_iff_coprime] at h rw [← Int.cast_natCast a, ← Int.cast_natCast b] exact IsCoprime.intCast h theorem ne_zero_or_ne_zero_of_nat_coprime {A : Type u} [CommRing A] [Nontrivial A] {a b : ℕ} (h : Nat.Coprime a b) : (a : A) ≠ 0 ∨ (b : A) ≠ 0 := IsCoprime.ne_zero_or_ne_zero (R := A) <| by simpa only [map_natCast] using IsCoprime.map (Nat.Coprime.isCoprime h) (Int.castRingHom A) theorem IsCoprime.prod_left : (∀ i ∈ t, IsCoprime (s i) x) → IsCoprime (∏ i ∈ t, s i) x := by classical refine Finset.induction_on t (fun _ ↦ isCoprime_one_left) fun b t hbt ih H ↦ ?_ rw [Finset.prod_insert hbt] rw [Finset.forall_mem_insert] at H exact H.1.mul_left (ih H.2) #align is_coprime.prod_left IsCoprime.prod_left theorem IsCoprime.prod_right : (∀ i ∈ t, IsCoprime x (s i)) → IsCoprime x (∏ i ∈ t, s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left (R := R) #align is_coprime.prod_right IsCoprime.prod_right theorem IsCoprime.prod_left_iff : IsCoprime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsCoprime (s i) x := by classical refine Finset.induction_on t (iff_of_true isCoprime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_ rw [Finset.prod_insert hbt, IsCoprime.mul_left_iff, ih, Finset.forall_mem_insert] #align is_coprime.prod_left_iff IsCoprime.prod_left_iff
Mathlib/RingTheory/Coprime/Lemmas.lean
79
80
theorem IsCoprime.prod_right_iff : IsCoprime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsCoprime x (s i) := by
simpa only [isCoprime_comm] using IsCoprime.prod_left_iff (R := R)
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.Data.List.Basic #align_import data.list.forall2 from "leanprover-community/mathlib"@"5a3e819569b0f12cbec59d740a2613018e7b8eec" /-! # Double universal quantification on a list This file provides an API for `List.Forall₂` (definition in `Data.List.Defs`). `Forall₂ R l₁ l₂` means that `l₁` and `l₂` have the same length, and whenever `a` is the nth element of `l₁`, and `b` is the nth element of `l₂`, then `R a b` is satisfied. -/ open Nat Function namespace List variable {α β γ δ : Type*} {R S : α → β → Prop} {P : γ → δ → Prop} {Rₐ : α → α → Prop} open Relator mk_iff_of_inductive_prop List.Forall₂ List.forall₂_iff #align list.forall₂_iff List.forall₂_iff #align list.forall₂.nil List.Forall₂.nil #align list.forall₂.cons List.Forall₂.cons #align list.forall₂_cons List.forall₂_cons theorem Forall₂.imp (H : ∀ a b, R a b → S a b) {l₁ l₂} (h : Forall₂ R l₁ l₂) : Forall₂ S l₁ l₂ := by induction h <;> constructor <;> solve_by_elim #align list.forall₂.imp List.Forall₂.imp theorem Forall₂.mp {Q : α → β → Prop} (h : ∀ a b, Q a b → R a b → S a b) : ∀ {l₁ l₂}, Forall₂ Q l₁ l₂ → Forall₂ R l₁ l₂ → Forall₂ S l₁ l₂ | [], [], Forall₂.nil, Forall₂.nil => Forall₂.nil | a :: _, b :: _, Forall₂.cons hr hrs, Forall₂.cons hq hqs => Forall₂.cons (h a b hr hq) (Forall₂.mp h hrs hqs) #align list.forall₂.mp List.Forall₂.mp theorem Forall₂.flip : ∀ {a b}, Forall₂ (flip R) b a → Forall₂ R a b | _, _, Forall₂.nil => Forall₂.nil | _ :: _, _ :: _, Forall₂.cons h₁ h₂ => Forall₂.cons h₁ h₂.flip #align list.forall₂.flip List.Forall₂.flip @[simp] theorem forall₂_same : ∀ {l : List α}, Forall₂ Rₐ l l ↔ ∀ x ∈ l, Rₐ x x | [] => by simp | a :: l => by simp [@forall₂_same l] #align list.forall₂_same List.forall₂_same theorem forall₂_refl [IsRefl α Rₐ] (l : List α) : Forall₂ Rₐ l l := forall₂_same.2 fun _ _ => refl _ #align list.forall₂_refl List.forall₂_refl @[simp] theorem forall₂_eq_eq_eq : Forall₂ ((· = ·) : α → α → Prop) = Eq := by funext a b; apply propext constructor · intro h induction h · rfl simp only [*] · rintro rfl exact forall₂_refl _ #align list.forall₂_eq_eq_eq List.forall₂_eq_eq_eq @[simp] theorem forall₂_nil_left_iff {l} : Forall₂ R nil l ↔ l = nil := ⟨fun H => by cases H; rfl, by rintro rfl; exact Forall₂.nil⟩ #align list.forall₂_nil_left_iff List.forall₂_nil_left_iff @[simp] theorem forall₂_nil_right_iff {l} : Forall₂ R l nil ↔ l = nil := ⟨fun H => by cases H; rfl, by rintro rfl; exact Forall₂.nil⟩ #align list.forall₂_nil_right_iff List.forall₂_nil_right_iff theorem forall₂_cons_left_iff {a l u} : Forall₂ R (a :: l) u ↔ ∃ b u', R a b ∧ Forall₂ R l u' ∧ u = b :: u' := Iff.intro (fun h => match u, h with | b :: u', Forall₂.cons h₁ h₂ => ⟨b, u', h₁, h₂, rfl⟩) fun h => match u, h with | _, ⟨_, _, h₁, h₂, rfl⟩ => Forall₂.cons h₁ h₂ #align list.forall₂_cons_left_iff List.forall₂_cons_left_iff theorem forall₂_cons_right_iff {b l u} : Forall₂ R u (b :: l) ↔ ∃ a u', R a b ∧ Forall₂ R u' l ∧ u = a :: u' := Iff.intro (fun h => match u, h with | b :: u', Forall₂.cons h₁ h₂ => ⟨b, u', h₁, h₂, rfl⟩) fun h => match u, h with | _, ⟨_, _, h₁, h₂, rfl⟩ => Forall₂.cons h₁ h₂ #align list.forall₂_cons_right_iff List.forall₂_cons_right_iff theorem forall₂_and_left {p : α → Prop} : ∀ l u, Forall₂ (fun a b => p a ∧ R a b) l u ↔ (∀ a ∈ l, p a) ∧ Forall₂ R l u | [], u => by simp only [forall₂_nil_left_iff, forall_prop_of_false (not_mem_nil _), imp_true_iff, true_and_iff] | a :: l, u => by simp only [forall₂_and_left l, forall₂_cons_left_iff, forall_mem_cons, and_assoc, @and_comm _ (p a), @and_left_comm _ (p a), exists_and_left] simp only [and_comm, and_assoc, and_left_comm, ← exists_and_right] #align list.forall₂_and_left List.forall₂_and_left @[simp] theorem forall₂_map_left_iff {f : γ → α} : ∀ {l u}, Forall₂ R (map f l) u ↔ Forall₂ (fun c b => R (f c) b) l u | [], _ => by simp only [map, forall₂_nil_left_iff] | a :: l, _ => by simp only [map, forall₂_cons_left_iff, forall₂_map_left_iff] #align list.forall₂_map_left_iff List.forall₂_map_left_iff @[simp] theorem forall₂_map_right_iff {f : γ → β} : ∀ {l u}, Forall₂ R l (map f u) ↔ Forall₂ (fun a c => R a (f c)) l u | _, [] => by simp only [map, forall₂_nil_right_iff] | _, b :: u => by simp only [map, forall₂_cons_right_iff, forall₂_map_right_iff] #align list.forall₂_map_right_iff List.forall₂_map_right_iff theorem left_unique_forall₂' (hr : LeftUnique R) : ∀ {a b c}, Forall₂ R a c → Forall₂ R b c → a = b | _, _, _, Forall₂.nil, Forall₂.nil => rfl | _, _, _, Forall₂.cons ha₀ h₀, Forall₂.cons ha₁ h₁ => hr ha₀ ha₁ ▸ left_unique_forall₂' hr h₀ h₁ ▸ rfl #align list.left_unique_forall₂' List.left_unique_forall₂' theorem _root_.Relator.LeftUnique.forall₂ (hr : LeftUnique R) : LeftUnique (Forall₂ R) := @left_unique_forall₂' _ _ _ hr #align relator.left_unique.forall₂ Relator.LeftUnique.forall₂ theorem right_unique_forall₂' (hr : RightUnique R) : ∀ {a b c}, Forall₂ R a b → Forall₂ R a c → b = c | _, _, _, Forall₂.nil, Forall₂.nil => rfl | _, _, _, Forall₂.cons ha₀ h₀, Forall₂.cons ha₁ h₁ => hr ha₀ ha₁ ▸ right_unique_forall₂' hr h₀ h₁ ▸ rfl #align list.right_unique_forall₂' List.right_unique_forall₂' theorem _root_.Relator.RightUnique.forall₂ (hr : RightUnique R) : RightUnique (Forall₂ R) := @right_unique_forall₂' _ _ _ hr #align relator.right_unique.forall₂ Relator.RightUnique.forall₂ theorem _root_.Relator.BiUnique.forall₂ (hr : BiUnique R) : BiUnique (Forall₂ R) := ⟨hr.left.forall₂, hr.right.forall₂⟩ #align relator.bi_unique.forall₂ Relator.BiUnique.forall₂ theorem Forall₂.length_eq : ∀ {l₁ l₂}, Forall₂ R l₁ l₂ → length l₁ = length l₂ | _, _, Forall₂.nil => rfl | _, _, Forall₂.cons _ h₂ => congr_arg succ (Forall₂.length_eq h₂) #align list.forall₂.length_eq List.Forall₂.length_eq theorem Forall₂.get : ∀ {x : List α} {y : List β}, Forall₂ R x y → ∀ ⦃i : ℕ⦄ (hx : i < x.length) (hy : i < y.length), R (x.get ⟨i, hx⟩) (y.get ⟨i, hy⟩) | _, _, Forall₂.cons ha _, 0, _, _ => ha | _, _, Forall₂.cons _ hl, succ _, _, _ => hl.get _ _ set_option linter.deprecated false in @[deprecated (since := "2024-05-05")] theorem Forall₂.nthLe {x y} (h : Forall₂ R x y) ⦃i : ℕ⦄ (hx : i < x.length) (hy : i < y.length) : R (x.nthLe i hx) (y.nthLe i hy) := h.get hx hy #align list.forall₂.nth_le List.Forall₂.nthLe theorem forall₂_of_length_eq_of_get : ∀ {x : List α} {y : List β}, x.length = y.length → (∀ i h₁ h₂, R (x.get ⟨i, h₁⟩) (y.get ⟨i, h₂⟩)) → Forall₂ R x y | [], [], _, _ => Forall₂.nil | _ :: _, _ :: _, hl, h => Forall₂.cons (h 0 (Nat.zero_lt_succ _) (Nat.zero_lt_succ _)) (forall₂_of_length_eq_of_get (succ.inj hl) fun i h₁ h₂ => h i.succ (succ_lt_succ h₁) (succ_lt_succ h₂)) set_option linter.deprecated false in @[deprecated (since := "2024-05-05")] theorem forall₂_of_length_eq_of_nthLe {x y} (H : x.length = y.length) (H' : ∀ i h₁ h₂, R (x.nthLe i h₁) (y.nthLe i h₂)) : Forall₂ R x y := forall₂_of_length_eq_of_get H H' #align list.forall₂_of_length_eq_of_nth_le List.forall₂_of_length_eq_of_nthLe theorem forall₂_iff_get {l₁ : List α} {l₂ : List β} : Forall₂ R l₁ l₂ ↔ l₁.length = l₂.length ∧ ∀ i h₁ h₂, R (l₁.get ⟨i, h₁⟩) (l₂.get ⟨i, h₂⟩) := ⟨fun h => ⟨h.length_eq, h.get⟩, fun h => forall₂_of_length_eq_of_get h.1 h.2⟩ set_option linter.deprecated false in @[deprecated (since := "2024-05-05")] theorem forall₂_iff_nthLe {l₁ : List α} {l₂ : List β} : Forall₂ R l₁ l₂ ↔ l₁.length = l₂.length ∧ ∀ i h₁ h₂, R (l₁.nthLe i h₁) (l₂.nthLe i h₂) := forall₂_iff_get #align list.forall₂_iff_nth_le List.forall₂_iff_nthLe theorem forall₂_zip : ∀ {l₁ l₂}, Forall₂ R l₁ l₂ → ∀ {a b}, (a, b) ∈ zip l₁ l₂ → R a b | _, _, Forall₂.cons h₁ h₂, x, y, hx => by rw [zip, zipWith, mem_cons] at hx match hx with | Or.inl rfl => exact h₁ | Or.inr h₃ => exact forall₂_zip h₂ h₃ #align list.forall₂_zip List.forall₂_zip theorem forall₂_iff_zip {l₁ l₂} : Forall₂ R l₁ l₂ ↔ length l₁ = length l₂ ∧ ∀ {a b}, (a, b) ∈ zip l₁ l₂ → R a b := ⟨fun h => ⟨Forall₂.length_eq h, @forall₂_zip _ _ _ _ _ h⟩, fun h => by cases' h with h₁ h₂ induction' l₁ with a l₁ IH generalizing l₂ · cases length_eq_zero.1 h₁.symm constructor · cases' l₂ with b l₂ · simp at h₁ · simp only [length_cons, succ.injEq] at h₁ exact Forall₂.cons (h₂ <| by simp [zip]) (IH h₁ fun h => h₂ <| by simp only [zip, zipWith, find?, mem_cons, Prod.mk.injEq]; right simpa [zip] using h)⟩ #align list.forall₂_iff_zip List.forall₂_iff_zip theorem forall₂_take : ∀ (n) {l₁ l₂}, Forall₂ R l₁ l₂ → Forall₂ R (take n l₁) (take n l₂) | 0, _, _, _ => by simp only [Forall₂.nil, take] | _ + 1, _, _, Forall₂.nil => by simp only [Forall₂.nil, take] | n + 1, _, _, Forall₂.cons h₁ h₂ => by simp [And.intro h₁ h₂, forall₂_take n] #align list.forall₂_take List.forall₂_take theorem forall₂_drop : ∀ (n) {l₁ l₂}, Forall₂ R l₁ l₂ → Forall₂ R (drop n l₁) (drop n l₂) | 0, _, _, h => by simp only [drop, h] | _ + 1, _, _, Forall₂.nil => by simp only [Forall₂.nil, drop] | n + 1, _, _, Forall₂.cons h₁ h₂ => by simp [And.intro h₁ h₂, forall₂_drop n] #align list.forall₂_drop List.forall₂_drop theorem forall₂_take_append (l : List α) (l₁ : List β) (l₂ : List β) (h : Forall₂ R l (l₁ ++ l₂)) : Forall₂ R (List.take (length l₁) l) l₁ := by have h' : Forall₂ R (take (length l₁) l) (take (length l₁) (l₁ ++ l₂)) := forall₂_take (length l₁) h rwa [take_left] at h' #align list.forall₂_take_append List.forall₂_take_append theorem forall₂_drop_append (l : List α) (l₁ : List β) (l₂ : List β) (h : Forall₂ R l (l₁ ++ l₂)) : Forall₂ R (List.drop (length l₁) l) l₂ := by have h' : Forall₂ R (drop (length l₁) l) (drop (length l₁) (l₁ ++ l₂)) := forall₂_drop (length l₁) h rwa [drop_left] at h' #align list.forall₂_drop_append List.forall₂_drop_append theorem rel_mem (hr : BiUnique R) : (R ⇒ Forall₂ R ⇒ Iff) (· ∈ ·) (· ∈ ·) | a, b, _, [], [], Forall₂.nil => by simp only [not_mem_nil] | a, b, h, a' :: as, b' :: bs, Forall₂.cons h₁ h₂ => by simp only [mem_cons] exact rel_or (rel_eq hr h h₁) (rel_mem hr h h₂) #align list.rel_mem List.rel_mem theorem rel_map : ((R ⇒ P) ⇒ Forall₂ R ⇒ Forall₂ P) map map | _, _, _, [], [], Forall₂.nil => Forall₂.nil | _, _, h, _ :: _, _ :: _, Forall₂.cons h₁ h₂ => Forall₂.cons (h h₁) (rel_map (@h) h₂) #align list.rel_map List.rel_map theorem rel_append : (Forall₂ R ⇒ Forall₂ R ⇒ Forall₂ R) (· ++ ·) (· ++ ·) | [], [], _, _, _, hl => hl | _, _, Forall₂.cons h₁ h₂, _, _, hl => Forall₂.cons h₁ (rel_append h₂ hl) #align list.rel_append List.rel_append theorem rel_reverse : (Forall₂ R ⇒ Forall₂ R) reverse reverse | [], [], Forall₂.nil => Forall₂.nil | _, _, Forall₂.cons h₁ h₂ => by simp only [reverse_cons] exact rel_append (rel_reverse h₂) (Forall₂.cons h₁ Forall₂.nil) #align list.rel_reverse List.rel_reverse @[simp] theorem forall₂_reverse_iff {l₁ l₂} : Forall₂ R (reverse l₁) (reverse l₂) ↔ Forall₂ R l₁ l₂ := Iff.intro (fun h => by rw [← reverse_reverse l₁, ← reverse_reverse l₂] exact rel_reverse h) fun h => rel_reverse h #align list.forall₂_reverse_iff List.forall₂_reverse_iff theorem rel_join : (Forall₂ (Forall₂ R) ⇒ Forall₂ R) join join | [], [], Forall₂.nil => Forall₂.nil | _, _, Forall₂.cons h₁ h₂ => rel_append h₁ (rel_join h₂) #align list.rel_join List.rel_join theorem rel_bind : (Forall₂ R ⇒ (R ⇒ Forall₂ P) ⇒ Forall₂ P) List.bind List.bind := fun _ _ h₁ _ _ h₂ => rel_join (rel_map (@h₂) h₁) #align list.rel_bind List.rel_bind theorem rel_foldl : ((P ⇒ R ⇒ P) ⇒ P ⇒ Forall₂ R ⇒ P) foldl foldl | _, _, _, _, _, h, _, _, Forall₂.nil => h | _, _, hfg, _, _, hxy, _, _, Forall₂.cons hab hs => rel_foldl (@hfg) (hfg hxy hab) hs #align list.rel_foldl List.rel_foldl theorem rel_foldr : ((R ⇒ P ⇒ P) ⇒ P ⇒ Forall₂ R ⇒ P) foldr foldr | _, _, _, _, _, h, _, _, Forall₂.nil => h | _, _, hfg, _, _, hxy, _, _, Forall₂.cons hab hs => hfg hab (rel_foldr (@hfg) hxy hs) #align list.rel_foldr List.rel_foldr
Mathlib/Data/List/Forall2.lean
297
308
theorem rel_filter {p : α → Bool} {q : β → Bool} (hpq : (R ⇒ (· ↔ ·)) (fun x => p x) (fun x => q x)) : (Forall₂ R ⇒ Forall₂ R) (filter p) (filter q) | _, _, Forall₂.nil => Forall₂.nil | a :: as, b :: bs, Forall₂.cons h₁ h₂ => by dsimp [LiftFun] at hpq by_cases h : p a · have : q b := by
rwa [← hpq h₁] simp only [filter_cons_of_pos _ h, filter_cons_of_pos _ this, forall₂_cons, h₁, true_and_iff, rel_filter hpq h₂] · have : ¬q b := by rwa [← hpq h₁] simp only [filter_cons_of_neg _ h, filter_cons_of_neg _ this, rel_filter hpq h₂]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Aurélien Saue, Anne Baanen -/ import Mathlib.Algebra.Order.Ring.Rat import Mathlib.Tactic.NormNum.Inv import Mathlib.Tactic.NormNum.Pow import Mathlib.Util.AtomM /-! # `ring` tactic A tactic for solving equations in commutative (semi)rings, where the exponents can also contain variables. Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> . More precisely, expressions of the following form are supported: - constants (non-negative integers) - variables - coefficients (any rational number, embedded into the (semi)ring) - addition of expressions - multiplication of expressions (`a * b`) - scalar multiplication of expressions (`n • a`; the multiplier must have type `ℕ`) - exponentiation of expressions (the exponent must have type `ℕ`) - subtraction and negation of expressions (if the base is a full ring) The extension to exponents means that something like `2 * 2^n * b = b * 2^(n+1)` can be proved, even though it is not strictly speaking an equation in the language of commutative rings. ## Implementation notes The basic approach to prove equalities is to normalise both sides and check for equality. The normalisation is guided by building a value in the type `ExSum` at the meta level, together with a proof (at the base level) that the original value is equal to the normalised version. The outline of the file: - Define a mutual inductive family of types `ExSum`, `ExProd`, `ExBase`, which can represent expressions with `+`, `*`, `^` and rational numerals. The mutual induction ensures that associativity and distributivity are applied, by restricting which kinds of subexpressions appear as arguments to the various operators. - Represent addition, multiplication and exponentiation in the `ExSum` type, thus allowing us to map expressions to `ExSum` (the `eval` function drives this). We apply associativity and distributivity of the operators here (helped by `Ex*` types) and commutativity as well (by sorting the subterms; unfortunately not helped by anything). Any expression not of the above formats is treated as an atom (the same as a variable). There are some details we glossed over which make the plan more complicated: - The order on atoms is not initially obvious. We construct a list containing them in order of initial appearance in the expression, then use the index into the list as a key to order on. - For `pow`, the exponent must be a natural number, while the base can be any semiring `α`. We swap out operations for the base ring `α` with those for the exponent ring `ℕ` as soon as we deal with exponents. ## Caveats and future work The normalized form of an expression is the one that is useful for the tactic, but not as nice to read. To remedy this, the user-facing normalization calls `ringNFCore`. Subtraction cancels out identical terms, but division does not. That is: `a - a = 0 := by ring` solves the goal, but `a / a := 1 by ring` doesn't. Note that `0 / 0` is generally defined to be `0`, so division cancelling out is not true in general. Multiplication of powers can be simplified a little bit further: `2 ^ n * 2 ^ n = 4 ^ n := by ring` could be implemented in a similar way that `2 * a + 2 * a = 4 * a := by ring` already works. This feature wasn't needed yet, so it's not implemented yet. ## Tags ring, semiring, exponent, power -/ set_option autoImplicit true namespace Mathlib.Tactic namespace Ring open Mathlib.Meta Qq NormNum Lean.Meta AtomM open Lean (MetaM Expr mkRawNatLit) /-- A shortcut instance for `CommSemiring ℕ` used by ring. -/ def instCommSemiringNat : CommSemiring ℕ := inferInstance /-- A typed expression of type `CommSemiring ℕ` used when we are working on ring subexpressions of type `ℕ`. -/ def sℕ : Q(CommSemiring ℕ) := q(instCommSemiringNat) -- In this file, we would like to use multi-character auto-implicits. set_option relaxedAutoImplicit true mutual /-- The base `e` of a normalized exponent expression. -/ inductive ExBase : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- An atomic expression `e` with id `id`. Atomic expressions are those which `ring` cannot parse any further. For instance, `a + (a % b)` has `a` and `(a % b)` as atoms. The `ring1` tactic does not normalize the subexpressions in atoms, but `ring_nf` does. Atoms in fact represent equivalence classes of expressions, modulo definitional equality. The field `index : ℕ` should be a unique number for each class, while `value : expr` contains a representative of this class. The function `resolve_atom` determines the appropriate atom for a given expression. -/ | atom (id : ℕ) : ExBase sα e /-- A sum of monomials. -/ | sum (_ : ExSum sα e) : ExBase sα e /-- A monomial, which is a product of powers of `ExBase` expressions, terminated by a (nonzero) constant coefficient. -/ inductive ExProd : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- A coefficient `value`, which must not be `0`. `e` is a raw rat cast. If `value` is not an integer, then `hyp` should be a proof of `(value.den : α) ≠ 0`. -/ | const (value : ℚ) (hyp : Option Expr := none) : ExProd sα e /-- A product `x ^ e * b` is a monomial if `b` is a monomial. Here `x` is an `ExBase` and `e` is an `ExProd` representing a monomial expression in `ℕ` (it is a monomial instead of a polynomial because we eagerly normalize `x ^ (a + b) = x ^ a * x ^ b`.) -/ | mul {α : Q(Type u)} {sα : Q(CommSemiring $α)} {x : Q($α)} {e : Q(ℕ)} {b : Q($α)} : ExBase sα x → ExProd sℕ e → ExProd sα b → ExProd sα q($x ^ $e * $b) /-- A polynomial expression, which is a sum of monomials. -/ inductive ExSum : ∀ {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- Zero is a polynomial. `e` is the expression `0`. -/ | zero {α : Q(Type u)} {sα : Q(CommSemiring $α)} : ExSum sα q(0 : $α) /-- A sum `a + b` is a polynomial if `a` is a monomial and `b` is another polynomial. -/ | add {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExProd sα a → ExSum sα b → ExSum sα q($a + $b) end mutual -- partial only to speed up compilation /-- Equality test for expressions. This is not a `BEq` instance because it is heterogeneous. -/ partial def ExBase.eq : ExBase sα a → ExBase sα b → Bool | .atom i, .atom j => i == j | .sum a, .sum b => a.eq b | _, _ => false @[inherit_doc ExBase.eq] partial def ExProd.eq : ExProd sα a → ExProd sα b → Bool | .const i _, .const j _ => i == j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => a₁.eq b₁ && a₂.eq b₂ && a₃.eq b₃ | _, _ => false @[inherit_doc ExBase.eq] partial def ExSum.eq : ExSum sα a → ExSum sα b → Bool | .zero, .zero => true | .add a₁ a₂, .add b₁ b₂ => a₁.eq b₁ && a₂.eq b₂ | _, _ => false end mutual -- partial only to speed up compilation /-- A total order on normalized expressions. This is not an `Ord` instance because it is heterogeneous. -/ partial def ExBase.cmp : ExBase sα a → ExBase sα b → Ordering | .atom i, .atom j => compare i j | .sum a, .sum b => a.cmp b | .atom .., .sum .. => .lt | .sum .., .atom .. => .gt @[inherit_doc ExBase.cmp] partial def ExProd.cmp : ExProd sα a → ExProd sα b → Ordering | .const i _, .const j _ => compare i j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => (a₁.cmp b₁).then (a₂.cmp b₂) |>.then (a₃.cmp b₃) | .const _ _, .mul .. => .lt | .mul .., .const _ _ => .gt @[inherit_doc ExBase.cmp] partial def ExSum.cmp : ExSum sα a → ExSum sα b → Ordering | .zero, .zero => .eq | .add a₁ a₂, .add b₁ b₂ => (a₁.cmp b₁).then (a₂.cmp b₂) | .zero, .add .. => .lt | .add .., .zero => .gt end instance : Inhabited (Σ e, (ExBase sα) e) := ⟨default, .atom 0⟩ instance : Inhabited (Σ e, (ExSum sα) e) := ⟨_, .zero⟩ instance : Inhabited (Σ e, (ExProd sα) e) := ⟨default, .const 0 none⟩ mutual /-- Converts `ExBase sα` to `ExBase sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExBase.cast : ExBase sα a → Σ a, ExBase sβ a | .atom i => ⟨a, .atom i⟩ | .sum a => let ⟨_, vb⟩ := a.cast; ⟨_, .sum vb⟩ /-- Converts `ExProd sα` to `ExProd sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExProd.cast : ExProd sα a → Σ a, ExProd sβ a | .const i h => ⟨a, .const i h⟩ | .mul a₁ a₂ a₃ => ⟨_, .mul a₁.cast.2 a₂ a₃.cast.2⟩ /-- Converts `ExSum sα` to `ExSum sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExSum.cast : ExSum sα a → Σ a, ExSum sβ a | .zero => ⟨_, .zero⟩ | .add a₁ a₂ => ⟨_, .add a₁.cast.2 a₂.cast.2⟩ end /-- The result of evaluating an (unnormalized) expression `e` into the type family `E` (one of `ExSum`, `ExProd`, `ExBase`) is a (normalized) element `e'` and a representation `E e'` for it, and a proof of `e = e'`. -/ structure Result {α : Q(Type u)} (E : Q($α) → Type) (e : Q($α)) where /-- The normalized result. -/ expr : Q($α) /-- The data associated to the normalization. -/ val : E expr /-- A proof that the original expression is equal to the normalized result. -/ proof : Q($e = $expr) instance [Inhabited (Σ e, E e)] : Inhabited (Result E e) := let ⟨e', v⟩ : Σ e, E e := default; ⟨e', v, default⟩ variable {α : Q(Type u)} (sα : Q(CommSemiring $α)) [CommSemiring R] /-- Constructs the expression corresponding to `.const n`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNat (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q(($lit).rawCast : $α), .const n none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNegNat (_ : Q(Ring $α)) (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q((Int.negOfNat $lit).rawCast : $α), .const (-n) none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkRat (_ : Q(DivisionRing $α)) (q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (h : Expr) : (e : Q($α)) × ExProd sα e := ⟨q(Rat.rawCast $n $d : $α), .const q h⟩ section variable {sα} /-- Embed an exponent (an `ExBase, ExProd` pair) as an `ExProd` by multiplying by 1. -/ def ExBase.toProd (va : ExBase sα a) (vb : ExProd sℕ b) : ExProd sα q($a ^ $b * (nat_lit 1).rawCast) := .mul va vb (.const 1 none) /-- Embed `ExProd` in `ExSum` by adding 0. -/ def ExProd.toSum (v : ExProd sα e) : ExSum sα q($e + 0) := .add v .zero /-- Get the leading coefficient of an `ExProd`. -/ def ExProd.coeff : ExProd sα e → ℚ | .const q _ => q | .mul _ _ v => v.coeff end /-- Two monomials are said to "overlap" if they differ by a constant factor, in which case the constants just add. When this happens, the constant may be either zero (if the monomials cancel) or nonzero (if they add up); the zero case is handled specially. -/ inductive Overlap (e : Q($α)) where /-- The expression `e` (the sum of monomials) is equal to `0`. -/ | zero (_ : Q(IsNat $e (nat_lit 0))) /-- The expression `e` (the sum of monomials) is equal to another monomial (with nonzero leading coefficient). -/ | nonzero (_ : Result (ExProd sα) e) theorem add_overlap_pf (x : R) (e) (pq_pf : a + b = c) : x ^ e * a + x ^ e * b = x ^ e * c := by subst_vars; simp [mul_add] theorem add_overlap_pf_zero (x : R) (e) : IsNat (a + b) (nat_lit 0) → IsNat (x ^ e * a + x ^ e * b) (nat_lit 0) | ⟨h⟩ => ⟨by simp [h, ← mul_add]⟩ /-- Given monomials `va, vb`, attempts to add them together to get another monomial. If the monomials are not compatible, returns `none`. For example, `xy + 2xy = 3xy` is a `.nonzero` overlap, while `xy + xz` returns `none` and `xy + -xy = 0` is a `.zero` overlap. -/ def evalAddOverlap (va : ExProd sα a) (vb : ExProd sα b) : Option (Overlap sα q($a + $b)) := match va, vb with | .const za ha, .const zb hb => do let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let res ← NormNum.evalAdd.core q($a + $b) q(HAdd.hAdd) a b ra rb match res with | .isNat _ (.lit (.natVal 0)) p => pure <| .zero p | rc => let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq pure <| .nonzero ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .mul vb₁ vb₂ vb₃ => do guard (va₁.eq vb₁ && va₂.eq vb₂) match ← evalAddOverlap va₃ vb₃ with | .zero p => pure <| .zero (q(add_overlap_pf_zero $a₁ $a₂ $p) : Expr) | .nonzero ⟨_, vc, p⟩ => pure <| .nonzero ⟨_, .mul va₁ va₂ vc, (q(add_overlap_pf $a₁ $a₂ $p) : Expr)⟩ | _, _ => none theorem add_pf_zero_add (b : R) : 0 + b = b := by simp theorem add_pf_add_zero (a : R) : a + 0 = a := by simp theorem add_pf_add_overlap (_ : a₁ + b₁ = c₁) (_ : a₂ + b₂ = c₂) : (a₁ + a₂ : R) + (b₁ + b₂) = c₁ + c₂ := by subst_vars; simp [add_assoc, add_left_comm] theorem add_pf_add_overlap_zero (h : IsNat (a₁ + b₁) (nat_lit 0)) (h₄ : a₂ + b₂ = c) : (a₁ + a₂ : R) + (b₁ + b₂) = c := by subst_vars; rw [add_add_add_comm, h.1, Nat.cast_zero, add_pf_zero_add] theorem add_pf_add_lt (a₁ : R) (_ : a₂ + b = c) : (a₁ + a₂) + b = a₁ + c := by simp [*, add_assoc] theorem add_pf_add_gt (b₁ : R) (_ : a + b₂ = c) : a + (b₁ + b₂) = b₁ + c := by subst_vars; simp [add_left_comm] /-- Adds two polynomials `va, vb` together to get a normalized result polynomial. * `0 + b = b` * `a + 0 = a` * `a * x + a * y = a * (x + y)` (for `x`, `y` coefficients; uses `evalAddOverlap`) * `(a₁ + a₂) + (b₁ + b₂) = a₁ + (a₂ + (b₁ + b₂))` (if `a₁.lt b₁`) * `(a₁ + a₂) + (b₁ + b₂) = b₁ + ((a₁ + a₂) + b₂)` (if not `a₁.lt b₁`) -/ partial def evalAdd (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a + $b) := match va, vb with | .zero, vb => ⟨b, vb, q(add_pf_zero_add $b)⟩ | va, .zero => ⟨a, va, q(add_pf_add_zero $a)⟩ | .add (a := a₁) (b := _a₂) va₁ va₂, .add (a := b₁) (b := _b₂) vb₁ vb₂ => match evalAddOverlap sα va₁ vb₁ with | some (.nonzero ⟨_, vc₁, pc₁⟩) => let ⟨_, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨_, .add vc₁ vc₂, q(add_pf_add_overlap $pc₁ $pc₂)⟩ | some (.zero pc₁) => let ⟨c₂, vc₂, pc₂⟩ := evalAdd va₂ vb₂ ⟨c₂, vc₂, q(add_pf_add_overlap_zero $pc₁ $pc₂)⟩ | none => if let .lt := va₁.cmp vb₁ then let ⟨_c, vc, (pc : Q($_a₂ + ($b₁ + $_b₂) = $_c))⟩ := evalAdd va₂ vb ⟨_, .add va₁ vc, q(add_pf_add_lt $a₁ $pc)⟩ else let ⟨_c, vc, (pc : Q($a₁ + $_a₂ + $_b₂ = $_c))⟩ := evalAdd va vb₂ ⟨_, .add vb₁ vc, q(add_pf_add_gt $b₁ $pc)⟩ theorem one_mul (a : R) : (nat_lit 1).rawCast * a = a := by simp [Nat.rawCast] theorem mul_one (a : R) : a * (nat_lit 1).rawCast = a := by simp [Nat.rawCast] theorem mul_pf_left (a₁ : R) (a₂) (_ : a₃ * b = c) : (a₁ ^ a₂ * a₃ : R) * b = a₁ ^ a₂ * c := by subst_vars; rw [mul_assoc] theorem mul_pf_right (b₁ : R) (b₂) (_ : a * b₃ = c) : a * (b₁ ^ b₂ * b₃) = b₁ ^ b₂ * c := by subst_vars; rw [mul_left_comm] theorem mul_pp_pf_overlap (x : R) (_ : ea + eb = e) (_ : a₂ * b₂ = c) : (x ^ ea * a₂ : R) * (x ^ eb * b₂) = x ^ e * c := by subst_vars; simp [pow_add, mul_mul_mul_comm] /-- Multiplies two monomials `va, vb` together to get a normalized result monomial. * `x * y = (x * y)` (for `x`, `y` coefficients) * `x * (b₁ * b₂) = b₁ * (b₂ * x)` (for `x` coefficient) * `(a₁ * a₂) * y = a₁ * (a₂ * y)` (for `y` coefficient) * `(x ^ ea * a₂) * (x ^ eb * b₂) = x ^ (ea + eb) * (a₂ * b₂)` (if `ea` and `eb` are identical except coefficient) * `(a₁ * a₂) * (b₁ * b₂) = a₁ * (a₂ * (b₁ * b₂))` (if `a₁.lt b₁`) * `(a₁ * a₂) * (b₁ * b₂) = b₁ * ((a₁ * a₂) * b₂)` (if not `a₁.lt b₁`) -/ partial def evalMulProd (va : ExProd sα a) (vb : ExProd sα b) : Result (ExProd sα) q($a * $b) := match va, vb with | .const za ha, .const zb hb => if za = 1 then ⟨b, .const zb hb, (q(one_mul $b) : Expr)⟩ else if zb = 1 then ⟨a, .const za ha, (q(mul_one $a) : Expr)⟩ else let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let rc := (NormNum.evalMul.core q($a * $b) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) ra rb).get! let ⟨zc, hc⟩ := rc.toRatNZ.get! let ⟨c, pc⟩ := rc.toRawEq ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .const _ _ => let ⟨_, vc, pc⟩ := evalMulProd va₃ vb ⟨_, .mul va₁ va₂ vc, (q(mul_pf_left $a₁ $a₂ $pc) : Expr)⟩ | .const _ _, .mul (x := b₁) (e := b₂) vb₁ vb₂ vb₃ => let ⟨_, vc, pc⟩ := evalMulProd va vb₃ ⟨_, .mul vb₁ vb₂ vc, (q(mul_pf_right $b₁ $b₂ $pc) : Expr)⟩ | .mul (x := xa) (e := ea) vxa vea va₂, .mul (x := xb) (e := eb) vxb veb vb₂ => Id.run do if vxa.eq vxb then if let some (.nonzero ⟨_, ve, pe⟩) := evalAddOverlap sℕ vea veb then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb₂ return ⟨_, .mul vxa ve vc, (q(mul_pp_pf_overlap $xa $pe $pc) : Expr)⟩ if let .lt := (vxa.cmp vxb).then (vea.cmp veb) then let ⟨_, vc, pc⟩ := evalMulProd va₂ vb ⟨_, .mul vxa vea vc, (q(mul_pf_left $xa $ea $pc) : Expr)⟩ else let ⟨_, vc, pc⟩ := evalMulProd va vb₂ ⟨_, .mul vxb veb vc, (q(mul_pf_right $xb $eb $pc) : Expr)⟩ theorem mul_zero (a : R) : a * 0 = 0 := by simp theorem mul_add (_ : (a : R) * b₁ = c₁) (_ : a * b₂ = c₂) (_ : c₁ + 0 + c₂ = d) : a * (b₁ + b₂) = d := by subst_vars; simp [_root_.mul_add] /-- Multiplies a monomial `va` to a polynomial `vb` to get a normalized result polynomial. * `a * 0 = 0` * `a * (b₁ + b₂) = (a * b₁) + (a * b₂)` -/ def evalMul₁ (va : ExProd sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match vb with | .zero => ⟨_, .zero, q(mul_zero $a)⟩ | .add vb₁ vb₂ => let ⟨_, vc₁, pc₁⟩ := evalMulProd sα va vb₁ let ⟨_, vc₂, pc₂⟩ := evalMul₁ va vb₂ let ⟨_, vd, pd⟩ := evalAdd sα vc₁.toSum vc₂ ⟨_, vd, q(mul_add $pc₁ $pc₂ $pd)⟩ theorem zero_mul (b : R) : 0 * b = 0 := by simp theorem add_mul (_ : (a₁ : R) * b = c₁) (_ : a₂ * b = c₂) (_ : c₁ + c₂ = d) : (a₁ + a₂) * b = d := by subst_vars; simp [_root_.add_mul] /-- Multiplies two polynomials `va, vb` together to get a normalized result polynomial. * `0 * b = 0` * `(a₁ + a₂) * b = (a₁ * b) + (a₂ * b)` -/ def evalMul (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a * $b) := match va with | .zero => ⟨_, .zero, q(zero_mul $b)⟩ | .add va₁ va₂ => let ⟨_, vc₁, pc₁⟩ := evalMul₁ sα va₁ vb let ⟨_, vc₂, pc₂⟩ := evalMul va₂ vb let ⟨_, vd, pd⟩ := evalAdd sα vc₁ vc₂ ⟨_, vd, q(add_mul $pc₁ $pc₂ $pd)⟩ theorem natCast_nat (n) : ((Nat.rawCast n : ℕ) : R) = Nat.rawCast n := by simp theorem natCast_mul (a₂) (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₃ : ℕ) : R) = b₃) : ((a₁ ^ a₂ * a₃ : ℕ) : R) = b₁ ^ a₂ * b₃ := by subst_vars; simp theorem natCast_zero : ((0 : ℕ) : R) = 0 := Nat.cast_zero theorem natCast_add (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by subst_vars; simp mutual /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * An atom `e` causes `↑e` to be allocated as a new atom. * A sum delegates to `ExSum.evalNatCast`. -/ partial def ExBase.evalNatCast (va : ExBase sℕ a) : AtomM (Result (ExBase sα) q($a)) := match va with | .atom _ => do let a' : Q($α) := q($a) let i ← addAtom a' pure ⟨a', ExBase.atom i, (q(Eq.refl $a') : Expr)⟩ | .sum va => do let ⟨_, vc, p⟩ ← va.evalNatCast pure ⟨_, .sum vc, p⟩ /-- Applies `Nat.cast` to a nat monomial to produce a monomial in `α`. * `↑c = c` if `c` is a numeric literal * `↑(a ^ n * b) = ↑a ^ n * ↑b` -/ partial def ExProd.evalNatCast (va : ExProd sℕ a) : AtomM (Result (ExProd sα) q($a)) := match va with | .const c hc => have n : Q(ℕ) := a.appArg! pure ⟨q(Nat.rawCast $n), .const c hc, (q(natCast_nat (R := $α) $n) : Expr)⟩ | .mul (e := a₂) va₁ va₂ va₃ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₃, pb₃⟩ ← va₃.evalNatCast pure ⟨_, .mul vb₁ va₂ vb₃, q(natCast_mul $a₂ $pb₁ $pb₃)⟩ /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * `↑0 = 0` * `↑(a + b) = ↑a + ↑b` -/ partial def ExSum.evalNatCast (va : ExSum sℕ a) : AtomM (Result (ExSum sα) q($a)) := match va with | .zero => pure ⟨_, .zero, q(natCast_zero (R := $α))⟩ | .add va₁ va₂ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₂, pb₂⟩ ← va₂.evalNatCast pure ⟨_, .add vb₁ vb₂, q(natCast_add $pb₁ $pb₂)⟩ end theorem smul_nat (_ : (a * b : ℕ) = c) : a • b = c := by subst_vars; simp theorem smul_eq_cast (_ : ((a : ℕ) : R) = a') (_ : a' * b = c) : a • b = c := by subst_vars; simp /-- Constructs the scalar multiplication `n • a`, where both `n : ℕ` and `a : α` are normalized polynomial expressions. * `a • b = a * b` if `α = ℕ` * `a • b = ↑a * b` otherwise -/ def evalNSMul (va : ExSum sℕ a) (vb : ExSum sα b) : AtomM (Result (ExSum sα) q($a • $b)) := do if ← isDefEq sα sℕ then let ⟨_, va'⟩ := va.cast have _b : Q(ℕ) := b let ⟨(_c : Q(ℕ)), vc, (pc : Q($a * $_b = $_c))⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_nat $pc) : Expr)⟩ else let ⟨_, va', pa'⟩ ← va.evalNatCast sα let ⟨_, vc, pc⟩ := evalMul sα va' vb pure ⟨_, vc, (q(smul_eq_cast $pa' $pc) : Expr)⟩ theorem neg_one_mul {R} [Ring R] {a b : R} (_ : (Int.negOfNat (nat_lit 1)).rawCast * a = b) : -a = b := by subst_vars; simp [Int.negOfNat] theorem neg_mul {R} [Ring R] (a₁ : R) (a₂) {a₃ b : R} (_ : -a₃ = b) : -(a₁ ^ a₂ * a₃) = a₁ ^ a₂ * b := by subst_vars; simp /-- Negates a monomial `va` to get another monomial. * `-c = (-c)` (for `c` coefficient) * `-(a₁ * a₂) = a₁ * -a₂` -/ def evalNegProd (rα : Q(Ring $α)) (va : ExProd sα a) : Result (ExProd sα) q(-$a) := match va with | .const za ha => let lit : Q(ℕ) := mkRawNatLit 1 let ⟨m1, _⟩ := ExProd.mkNegNat sα rα 1 let rm := Result.isNegNat rα lit (q(IsInt.of_raw $α (.negOfNat $lit)) : Expr) let ra := Result.ofRawRat za a ha let rb := (NormNum.evalMul.core q($m1 * $a) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) rm ra).get! let ⟨zb, hb⟩ := rb.toRatNZ.get! let ⟨b, (pb : Q((Int.negOfNat (nat_lit 1)).rawCast * $a = $b))⟩ := rb.toRawEq ⟨b, .const zb hb, (q(neg_one_mul (R := $α) $pb) : Expr)⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃ => let ⟨_, vb, pb⟩ := evalNegProd rα va₃ ⟨_, .mul va₁ va₂ vb, (q(neg_mul $a₁ $a₂ $pb) : Expr)⟩ theorem neg_zero {R} [Ring R] : -(0 : R) = 0 := by simp theorem neg_add {R} [Ring R] {a₁ a₂ b₁ b₂ : R} (_ : -a₁ = b₁) (_ : -a₂ = b₂) : -(a₁ + a₂) = b₁ + b₂ := by subst_vars; simp [add_comm] /-- Negates a polynomial `va` to get another polynomial. * `-0 = 0` (for `c` coefficient) * `-(a₁ + a₂) = -a₁ + -a₂` -/ def evalNeg (rα : Q(Ring $α)) (va : ExSum sα a) : Result (ExSum sα) q(-$a) := match va with | .zero => ⟨_, .zero, (q(neg_zero (R := $α)) : Expr)⟩ | .add va₁ va₂ => let ⟨_, vb₁, pb₁⟩ := evalNegProd sα rα va₁ let ⟨_, vb₂, pb₂⟩ := evalNeg rα va₂ ⟨_, .add vb₁ vb₂, (q(neg_add $pb₁ $pb₂) : Expr)⟩ theorem sub_pf {R} [Ring R] {a b c d : R} (_ : -b = c) (_ : a + c = d) : a - b = d := by subst_vars; simp [sub_eq_add_neg] /-- Subtracts two polynomials `va, vb` to get a normalized result polynomial. * `a - b = a + -b` -/ def evalSub (rα : Q(Ring $α)) (va : ExSum sα a) (vb : ExSum sα b) : Result (ExSum sα) q($a - $b) := let ⟨_c, vc, pc⟩ := evalNeg sα rα vb let ⟨d, vd, (pd : Q($a + $_c = $d))⟩ := evalAdd sα va vc ⟨d, vd, (q(sub_pf $pc $pd) : Expr)⟩ theorem pow_prod_atom (a : R) (b) : a ^ b = (a + 0) ^ b * (nat_lit 1).rawCast := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. (This has a slightly different normalization than `evalPowAtom` because the input types are different.) * `x ^ e = (x + 0) ^ e * 1` -/ def evalPowProdAtom (va : ExProd sα a) (vb : ExProd sℕ b) : Result (ExProd sα) q($a ^ $b) := ⟨_, (ExBase.sum va.toSum).toProd vb, q(pow_prod_atom $a $b)⟩ theorem pow_atom (a : R) (b) : a ^ b = a ^ b * (nat_lit 1).rawCast + 0 := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. * `x ^ e = x ^ e * 1 + 0` -/ def evalPowAtom (va : ExBase sα a) (vb : ExProd sℕ b) : Result (ExSum sα) q($a ^ $b) := ⟨_, (va.toProd vb).toSum, q(pow_atom $a $b)⟩ theorem const_pos (n : ℕ) (h : Nat.ble 1 n = true) : 0 < (n.rawCast : ℕ) := Nat.le_of_ble_eq_true h theorem mul_exp_pos (n) (h₁ : 0 < a₁) (h₂ : 0 < a₂) : 0 < a₁ ^ n * a₂ := Nat.mul_pos (Nat.pos_pow_of_pos _ h₁) h₂ theorem add_pos_left (a₂) (h : 0 < a₁) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_right ..) theorem add_pos_right (a₁) (h : 0 < a₂) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_left ..) mutual /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * Atoms are not (necessarily) positive * Sums defer to `ExSum.evalPos` -/ partial def ExBase.evalPos (va : ExBase sℕ a) : Option Q(0 < $a) := match va with | .atom _ => none | .sum va => va.evalPos /-- Attempts to prove that a monomial expression in `ℕ` is positive. * `0 < c` (where `c` is a numeral) is true by the normalization invariant (`c` is not zero) * `0 < x ^ e * b` if `0 < x` and `0 < b` -/ partial def ExProd.evalPos (va : ExProd sℕ a) : Option Q(0 < $a) := match va with | .const _ _ => -- it must be positive because it is a nonzero nat literal have lit : Q(ℕ) := a.appArg! haveI : $a =Q Nat.rawCast $lit := ⟨⟩ haveI p : Nat.ble 1 $lit =Q true := ⟨⟩ some q(const_pos $lit $p) | .mul (e := ea₁) vxa₁ _ va₂ => do let pa₁ ← vxa₁.evalPos let pa₂ ← va₂.evalPos some q(mul_exp_pos $ea₁ $pa₁ $pa₂) /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * `0 < 0` fails * `0 < a + b` if `0 < a` or `0 < b` -/ partial def ExSum.evalPos (va : ExSum sℕ a) : Option Q(0 < $a) := match va with | .zero => none | .add (a := a₁) (b := a₂) va₁ va₂ => do match va₁.evalPos with | some p => some q(add_pos_left $a₂ $p) | none => let p ← va₂.evalPos; some q(add_pos_right $a₁ $p) end theorem pow_one (a : R) : a ^ nat_lit 1 = a := by simp theorem pow_bit0 (_ : (a : R) ^ k = b) (_ : b * b = c) : a ^ (Nat.mul (nat_lit 2) k) = c := by subst_vars; simp [Nat.succ_mul, pow_add] theorem pow_bit1 (_ : (a : R) ^ k = b) (_ : b * b = c) (_ : c * a = d) : a ^ (Nat.add (Nat.mul (nat_lit 2) k) (nat_lit 1)) = d := by subst_vars; simp [Nat.succ_mul, pow_add] /-- The main case of exponentiation of ring expressions is when `va` is a polynomial and `n` is a nonzero literal expression, like `(x + y)^5`. In this case we work out the polynomial completely into a sum of monomials. * `x ^ 1 = x` * `x ^ (2*n) = x ^ n * x ^ n` * `x ^ (2*n+1) = x ^ n * x ^ n * x` -/ partial def evalPowNat (va : ExSum sα a) (n : Q(ℕ)) : Result (ExSum sα) q($a ^ $n) := let nn := n.natLit! if nn = 1 then ⟨_, va, (q(pow_one $a) : Expr)⟩ else let nm := nn >>> 1 have m : Q(ℕ) := mkRawNatLit nm if nn &&& 1 = 0 then let ⟨_, vb, pb⟩ := evalPowNat va m let ⟨_, vc, pc⟩ := evalMul sα vb vb ⟨_, vc, (q(pow_bit0 $pb $pc) : Expr)⟩ else let ⟨_, vb, pb⟩ := evalPowNat va m let ⟨_, vc, pc⟩ := evalMul sα vb vb let ⟨_, vd, pd⟩ := evalMul sα vc va ⟨_, vd, (q(pow_bit1 $pb $pc $pd) : Expr)⟩ theorem one_pow (b : ℕ) : ((nat_lit 1).rawCast : R) ^ b = (nat_lit 1).rawCast := by simp theorem mul_pow (_ : ea₁ * b = c₁) (_ : a₂ ^ b = c₂) : (xa₁ ^ ea₁ * a₂ : R) ^ b = xa₁ ^ c₁ * c₂ := by subst_vars; simp [_root_.mul_pow, pow_mul] /-- There are several special cases when exponentiating monomials: * `1 ^ n = 1` * `x ^ y = (x ^ y)` when `x` and `y` are constants * `(a * b) ^ e = a ^ e * b ^ e` In all other cases we use `evalPowProdAtom`. -/ def evalPowProd (va : ExProd sα a) (vb : ExProd sℕ b) : Result (ExProd sα) q($a ^ $b) := let res : Option (Result (ExProd sα) q($a ^ $b)) := do match va, vb with | .const 1, _ => some ⟨_, va, (q(one_pow (R := $α) $b) : Expr)⟩ | .const za ha, .const zb hb => assert! 0 ≤ zb let ra := Result.ofRawRat za a ha have lit : Q(ℕ) := b.appArg! let rb := (q(IsNat.of_raw ℕ $lit) : Expr) let rc ← NormNum.evalPow.core q($a ^ $b) q(HPow.hPow) q($a) q($b) lit rb q(CommSemiring.toSemiring) ra let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq some ⟨c, .const zc hc, pc⟩ | .mul vxa₁ vea₁ va₂, vb => do let ⟨_, vc₁, pc₁⟩ := evalMulProd sℕ vea₁ vb let ⟨_, vc₂, pc₂⟩ := evalPowProd va₂ vb some ⟨_, .mul vxa₁ vc₁ vc₂, q(mul_pow $pc₁ $pc₂)⟩ | _, _ => none res.getD (evalPowProdAtom sα va vb) /-- The result of `extractCoeff` is a numeral and a proof that the original expression factors by this numeral. -/ structure ExtractCoeff (e : Q(ℕ)) where /-- A raw natural number literal. -/ k : Q(ℕ) /-- The result of extracting the coefficient is a monic monomial. -/ e' : Q(ℕ) /-- `e'` is a monomial. -/ ve' : ExProd sℕ e' /-- The proof that `e` splits into the coefficient `k` and the monic monomial `e'`. -/ p : Q($e = $e' * $k) theorem coeff_one (k : ℕ) : k.rawCast = (nat_lit 1).rawCast * k := by simp theorem coeff_mul (a₁ a₂ : ℕ) (_ : a₃ = c₂ * k) : a₁ ^ a₂ * a₃ = (a₁ ^ a₂ * c₂) * k := by subst_vars; rw [mul_assoc] /-- Given a monomial expression `va`, splits off the leading coefficient `k` and the remainder `e'`, stored in the `ExtractCoeff` structure. * `c = 1 * c` (if `c` is a constant) * `a * b = (a * b') * k` if `b = b' * k` -/ def extractCoeff (va : ExProd sℕ a) : ExtractCoeff a := match va with | .const _ _ => have k : Q(ℕ) := a.appArg! ⟨k, q((nat_lit 1).rawCast), .const 1, (q(coeff_one $k) : Expr)⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃ => let ⟨k, _, vc, pc⟩ := extractCoeff va₃ ⟨k, _, .mul va₁ va₂ vc, q(coeff_mul $a₁ $a₂ $pc)⟩ theorem pow_one_cast (a : R) : a ^ (nat_lit 1).rawCast = a := by simp theorem zero_pow (_ : 0 < b) : (0 : R) ^ b = 0 := match b with | b+1 => by simp [pow_succ] theorem single_pow (_ : (a : R) ^ b = c) : (a + 0) ^ b = c + 0 := by simp [*] theorem pow_nat (_ : b = c * k) (_ : a ^ c = d) (_ : d ^ k = e) : (a : R) ^ b = e := by subst_vars; simp [pow_mul] /-- Exponentiates a polynomial `va` by a monomial `vb`, including several special cases. * `a ^ 1 = a` * `0 ^ e = 0` if `0 < e` * `(a + 0) ^ b = a ^ b` computed using `evalPowProd` * `a ^ b = (a ^ b') ^ k` if `b = b' * k` and `k > 1` Otherwise `a ^ b` is just encoded as `a ^ b * 1 + 0` using `evalPowAtom`. -/ partial def evalPow₁ (va : ExSum sα a) (vb : ExProd sℕ b) : Result (ExSum sα) q($a ^ $b) := match va, vb with | va, .const 1 => haveI : $b =Q Nat.rawCast (nat_lit 1) := ⟨⟩ ⟨_, va, q(pow_one_cast $a)⟩ | .zero, vb => match vb.evalPos with | some p => ⟨_, .zero, q(zero_pow (R := $α) $p)⟩ | none => evalPowAtom sα (.sum .zero) vb | ExSum.add va .zero, vb => -- TODO: using `.add` here takes a while to compile? let ⟨_, vc, pc⟩ := evalPowProd sα va vb ⟨_, vc.toSum, q(single_pow $pc)⟩ | va, vb => if vb.coeff > 1 then let ⟨k, _, vc, pc⟩ := extractCoeff vb let ⟨_, vd, pd⟩ := evalPow₁ va vc let ⟨_, ve, pe⟩ := evalPowNat sα vd k ⟨_, ve, q(pow_nat $pc $pd $pe)⟩ else evalPowAtom sα (.sum va) vb theorem pow_zero (a : R) : a ^ 0 = (nat_lit 1).rawCast + 0 := by simp theorem pow_add (_ : a ^ b₁ = c₁) (_ : a ^ b₂ = c₂) (_ : c₁ * c₂ = d) : (a : R) ^ (b₁ + b₂) = d := by subst_vars; simp [_root_.pow_add] /-- Exponentiates two polynomials `va, vb`. * `a ^ 0 = 1` * `a ^ (b₁ + b₂) = a ^ b₁ * a ^ b₂` -/ def evalPow (va : ExSum sα a) (vb : ExSum sℕ b) : Result (ExSum sα) q($a ^ $b) := match vb with | .zero => ⟨_, (ExProd.mkNat sα 1).2.toSum, q(pow_zero $a)⟩ | .add vb₁ vb₂ => let ⟨_, vc₁, pc₁⟩ := evalPow₁ sα va vb₁ let ⟨_, vc₂, pc₂⟩ := evalPow va vb₂ let ⟨_, vd, pd⟩ := evalMul sα vc₁ vc₂ ⟨_, vd, q(pow_add $pc₁ $pc₂ $pd)⟩ /-- This cache contains data required by the `ring` tactic during execution. -/ structure Cache {α : Q(Type u)} (sα : Q(CommSemiring $α)) := /-- A ring instance on `α`, if available. -/ rα : Option Q(Ring $α) /-- A division ring instance on `α`, if available. -/ dα : Option Q(DivisionRing $α) /-- A characteristic zero ring instance on `α`, if available. -/ czα : Option Q(CharZero $α) /-- Create a new cache for `α` by doing the necessary instance searches. -/ def mkCache {α : Q(Type u)} (sα : Q(CommSemiring $α)) : MetaM (Cache sα) := return { rα := (← trySynthInstanceQ q(Ring $α)).toOption dα := (← trySynthInstanceQ q(DivisionRing $α)).toOption czα := (← trySynthInstanceQ q(CharZero $α)).toOption } theorem cast_pos : IsNat (a : R) n → a = n.rawCast + 0 | ⟨e⟩ => by simp [e] theorem cast_zero : IsNat (a : R) (nat_lit 0) → a = 0 | ⟨e⟩ => by simp [e] theorem cast_neg {R} [Ring R] {a : R} : IsInt a (.negOfNat n) → a = (Int.negOfNat n).rawCast + 0 | ⟨e⟩ => by simp [e] theorem cast_rat {R} [DivisionRing R] {a : R} : IsRat a n d → a = Rat.rawCast n d + 0 | ⟨_, e⟩ => by simp [e, div_eq_mul_inv] /-- Converts a proof by `norm_num` that `e` is a numeral, into a normalization as a monomial: * `e = 0` if `norm_num` returns `IsNat e 0` * `e = Nat.rawCast n + 0` if `norm_num` returns `IsNat e n` * `e = Int.rawCast n + 0` if `norm_num` returns `IsInt e n` * `e = Rat.rawCast n d + 0` if `norm_num` returns `IsRat e n d` -/ def evalCast : NormNum.Result e → Option (Result (ExSum sα) e) | .isNat _ (.lit (.natVal 0)) p => do assumeInstancesCommute pure ⟨_, .zero, q(cast_zero $p)⟩ | .isNat _ lit p => do assumeInstancesCommute pure ⟨_, (ExProd.mkNat sα lit.natLit!).2.toSum, (q(cast_pos $p) :)⟩ | .isNegNat rα lit p => pure ⟨_, (ExProd.mkNegNat _ rα lit.natLit!).2.toSum, (q(cast_neg $p) : Expr)⟩ | .isRat dα q n d p => pure ⟨_, (ExProd.mkRat sα dα q n d q(IsRat.den_nz $p)).2.toSum, (q(cast_rat $p) : Expr)⟩ | _ => none theorem toProd_pf (p : (a : R) = a') : a = a' ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast := by simp [*] theorem atom_pf (a : R) : a = a ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast + 0 := by simp theorem atom_pf' (p : (a : R) = a') : a = a' ^ (nat_lit 1).rawCast * (nat_lit 1).rawCast + 0 := by simp [*] /-- Evaluates an atom, an expression where `ring` can find no additional structure. * `a = a ^ 1 * 1 + 0` -/ def evalAtom (e : Q($α)) : AtomM (Result (ExSum sα) e) := do let r ← (← read).evalAtom e have e' : Q($α) := r.expr let i ← addAtom e' let ve' := (ExBase.atom i (e := e')).toProd (ExProd.mkNat sℕ 1).2 |>.toSum pure ⟨_, ve', match r.proof? with | none => (q(atom_pf $e) : Expr) | some (p : Q($e = $e')) => (q(atom_pf' $p) : Expr)⟩ theorem inv_mul {R} [DivisionRing R] {a₁ a₂ a₃ b₁ b₃ c} (_ : (a₁⁻¹ : R) = b₁) (_ : (a₃⁻¹ : R) = b₃) (_ : b₃ * (b₁ ^ a₂ * (nat_lit 1).rawCast) = c) : (a₁ ^ a₂ * a₃ : R)⁻¹ = c := by subst_vars; simp nonrec theorem inv_zero {R} [DivisionRing R] : (0 : R)⁻¹ = 0 := inv_zero theorem inv_single {R} [DivisionRing R] {a b : R} (_ : (a : R)⁻¹ = b) : (a + 0)⁻¹ = b + 0 := by simp [*]
Mathlib/Tactic/Ring/Basic.lean
900
901
theorem inv_add (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by
subst_vars; simp
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johan Commelin -/ import Mathlib.RingTheory.IntegralClosure #align_import field_theory.minpoly.basic from "leanprover-community/mathlib"@"df0098f0db291900600f32070f6abb3e178be2ba" /-! # Minimal polynomials This file defines the minimal polynomial of an element `x` of an `A`-algebra `B`, under the assumption that x is integral over `A`, and derives some basic properties such as irreducibility under the assumption `B` is a domain. -/ open scoped Classical open Polynomial Set Function variable {A B B' : Type*} section MinPolyDef variable (A) [CommRing A] [Ring B] [Algebra A B] /-- Suppose `x : B`, where `B` is an `A`-algebra. The minimal polynomial `minpoly A x` of `x` is a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root, if such exists (`IsIntegral A x`) or zero otherwise. For example, if `V` is a `𝕜`-vector space for some field `𝕜` and `f : V →ₗ[𝕜] V` then the minimal polynomial of `f` is `minpoly 𝕜 f`. -/ noncomputable def minpoly (x : B) : A[X] := if hx : IsIntegral A x then degree_lt_wf.min _ hx else 0 #align minpoly minpoly end MinPolyDef namespace minpoly section Ring variable [CommRing A] [Ring B] [Ring B'] [Algebra A B] [Algebra A B'] variable {x : B} /-- A minimal polynomial is monic. -/ theorem monic (hx : IsIntegral A x) : Monic (minpoly A x) := by delta minpoly rw [dif_pos hx] exact (degree_lt_wf.min_mem _ hx).1 #align minpoly.monic minpoly.monic /-- A minimal polynomial is nonzero. -/ theorem ne_zero [Nontrivial A] (hx : IsIntegral A x) : minpoly A x ≠ 0 := (monic hx).ne_zero #align minpoly.ne_zero minpoly.ne_zero theorem eq_zero (hx : ¬IsIntegral A x) : minpoly A x = 0 := dif_neg hx #align minpoly.eq_zero minpoly.eq_zero theorem algHom_eq (f : B →ₐ[A] B') (hf : Function.Injective f) (x : B) : minpoly A (f x) = minpoly A x := by refine dif_ctx_congr (isIntegral_algHom_iff _ hf) (fun _ => ?_) fun _ => rfl simp_rw [← Polynomial.aeval_def, aeval_algHom, AlgHom.comp_apply, _root_.map_eq_zero_iff f hf] #align minpoly.minpoly_alg_hom minpoly.algHom_eq theorem algebraMap_eq {B} [CommRing B] [Algebra A B] [Algebra B B'] [IsScalarTower A B B'] (h : Function.Injective (algebraMap B B')) (x : B) : minpoly A (algebraMap B B' x) = minpoly A x := algHom_eq (IsScalarTower.toAlgHom A B B') h x @[simp] theorem algEquiv_eq (f : B ≃ₐ[A] B') (x : B) : minpoly A (f x) = minpoly A x := algHom_eq (f : B →ₐ[A] B') f.injective x #align minpoly.minpoly_alg_equiv minpoly.algEquiv_eq variable (A x) /-- An element is a root of its minimal polynomial. -/ @[simp] theorem aeval : aeval x (minpoly A x) = 0 := by delta minpoly split_ifs with hx · exact (degree_lt_wf.min_mem _ hx).2 · exact aeval_zero _ #align minpoly.aeval minpoly.aeval /-- Given any `f : B →ₐ[A] B'` and any `x : L`, the minimal polynomial of `x` vanishes at `f x`. -/ @[simp] theorem aeval_algHom (f : B →ₐ[A] B') (x : B) : (Polynomial.aeval (f x)) (minpoly A x) = 0 := by rw [Polynomial.aeval_algHom, AlgHom.coe_comp, comp_apply, aeval, map_zero] /-- A minimal polynomial is not `1`. -/ theorem ne_one [Nontrivial B] : minpoly A x ≠ 1 := by intro h refine (one_ne_zero : (1 : B) ≠ 0) ?_ simpa using congr_arg (Polynomial.aeval x) h #align minpoly.ne_one minpoly.ne_one theorem map_ne_one [Nontrivial B] {R : Type*} [Semiring R] [Nontrivial R] (f : A →+* R) : (minpoly A x).map f ≠ 1 := by by_cases hx : IsIntegral A x · exact mt ((monic hx).eq_one_of_map_eq_one f) (ne_one A x) · rw [eq_zero hx, Polynomial.map_zero] exact zero_ne_one #align minpoly.map_ne_one minpoly.map_ne_one /-- A minimal polynomial is not a unit. -/ theorem not_isUnit [Nontrivial B] : ¬IsUnit (minpoly A x) := by haveI : Nontrivial A := (algebraMap A B).domain_nontrivial by_cases hx : IsIntegral A x · exact mt (monic hx).eq_one_of_isUnit (ne_one A x) · rw [eq_zero hx] exact not_isUnit_zero #align minpoly.not_is_unit minpoly.not_isUnit theorem mem_range_of_degree_eq_one (hx : (minpoly A x).degree = 1) : x ∈ (algebraMap A B).range := by have h : IsIntegral A x := by by_contra h rw [eq_zero h, degree_zero, ← WithBot.coe_one] at hx exact ne_of_lt (show ⊥ < ↑1 from WithBot.bot_lt_coe 1) hx have key := minpoly.aeval A x rw [eq_X_add_C_of_degree_eq_one hx, (minpoly.monic h).leadingCoeff, C_1, one_mul, aeval_add, aeval_C, aeval_X, ← eq_neg_iff_add_eq_zero, ← RingHom.map_neg] at key exact ⟨-(minpoly A x).coeff 0, key.symm⟩ #align minpoly.mem_range_of_degree_eq_one minpoly.mem_range_of_degree_eq_one /-- The defining property of the minimal polynomial of an element `x`: it is the monic polynomial with smallest degree that has `x` as its root. -/ theorem min {p : A[X]} (pmonic : p.Monic) (hp : Polynomial.aeval x p = 0) : degree (minpoly A x) ≤ degree p := by delta minpoly; split_ifs with hx · exact le_of_not_lt (degree_lt_wf.not_lt_min _ hx ⟨pmonic, hp⟩) · simp only [degree_zero, bot_le] #align minpoly.min minpoly.min theorem unique' {p : A[X]} (hm : p.Monic) (hp : Polynomial.aeval x p = 0) (hl : ∀ q : A[X], degree q < degree p → q = 0 ∨ Polynomial.aeval x q ≠ 0) : p = minpoly A x := by nontriviality A have hx : IsIntegral A x := ⟨p, hm, hp⟩ obtain h | h := hl _ ((minpoly A x).degree_modByMonic_lt hm) swap · exact (h <| (aeval_modByMonic_eq_self_of_root hm hp).trans <| aeval A x).elim obtain ⟨r, hr⟩ := (modByMonic_eq_zero_iff_dvd hm).1 h rw [hr] have hlead := congr_arg leadingCoeff hr rw [mul_comm, leadingCoeff_mul_monic hm, (monic hx).leadingCoeff] at hlead have : natDegree r ≤ 0 := by have hr0 : r ≠ 0 := by rintro rfl exact ne_zero hx (mul_zero p ▸ hr) apply_fun natDegree at hr rw [hm.natDegree_mul' hr0] at hr apply Nat.le_of_add_le_add_left rw [add_zero] exact hr.symm.trans_le (natDegree_le_natDegree <| min A x hm hp) rw [eq_C_of_natDegree_le_zero this, ← Nat.eq_zero_of_le_zero this, ← leadingCoeff, ← hlead, C_1, mul_one] #align minpoly.unique' minpoly.unique' @[nontriviality] theorem subsingleton [Subsingleton B] : minpoly A x = 1 := by nontriviality A have := minpoly.min A x monic_one (Subsingleton.elim _ _) rw [degree_one] at this rcases le_or_lt (minpoly A x).degree 0 with h | h · rwa [(monic ⟨1, monic_one, by simp [eq_iff_true_of_subsingleton]⟩ : (minpoly A x).Monic).degree_le_zero_iff_eq_one] at h · exact (this.not_lt h).elim #align minpoly.subsingleton minpoly.subsingleton end Ring section CommRing variable [CommRing A] section Ring variable [Ring B] [Algebra A B] variable {x : B} /-- The degree of a minimal polynomial, as a natural number, is positive. -/ theorem natDegree_pos [Nontrivial B] (hx : IsIntegral A x) : 0 < natDegree (minpoly A x) := by rw [pos_iff_ne_zero] intro ndeg_eq_zero have eq_one : minpoly A x = 1 := by rw [eq_C_of_natDegree_eq_zero ndeg_eq_zero] convert C_1 (R := A) simpa only [ndeg_eq_zero.symm] using (monic hx).leadingCoeff simpa only [eq_one, AlgHom.map_one, one_ne_zero] using aeval A x #align minpoly.nat_degree_pos minpoly.natDegree_pos /-- The degree of a minimal polynomial is positive. -/ theorem degree_pos [Nontrivial B] (hx : IsIntegral A x) : 0 < degree (minpoly A x) := natDegree_pos_iff_degree_pos.mp (natDegree_pos hx) #align minpoly.degree_pos minpoly.degree_pos section variable [Nontrivial B] open Polynomial in theorem degree_eq_one_iff : (minpoly A x).degree = 1 ↔ x ∈ (algebraMap A B).range := by refine ⟨minpoly.mem_range_of_degree_eq_one _ _, ?_⟩ rintro ⟨x, rfl⟩ haveI := Module.nontrivial A B exact (degree_X_sub_C x ▸ minpoly.min A (algebraMap A B x) (monic_X_sub_C x) (by simp)).antisymm (Nat.WithBot.add_one_le_of_lt <| minpoly.degree_pos isIntegral_algebraMap) theorem natDegree_eq_one_iff : (minpoly A x).natDegree = 1 ↔ x ∈ (algebraMap A B).range := by rw [← Polynomial.degree_eq_iff_natDegree_eq_of_pos zero_lt_one] exact degree_eq_one_iff theorem two_le_natDegree_iff (int : IsIntegral A x) : 2 ≤ (minpoly A x).natDegree ↔ x ∉ (algebraMap A B).range := by rw [iff_not_comm, ← natDegree_eq_one_iff, not_le] exact ⟨fun h ↦ h.trans_lt one_lt_two, fun h ↦ by linarith only [minpoly.natDegree_pos int, h]⟩
Mathlib/FieldTheory/Minpoly/Basic.lean
228
231
theorem two_le_natDegree_subalgebra {B} [CommRing B] [Algebra A B] [Nontrivial B] {S : Subalgebra A B} {x : B} (int : IsIntegral S x) : 2 ≤ (minpoly S x).natDegree ↔ x ∉ S := by
rw [two_le_natDegree_iff int, Iff.not] apply Set.ext_iff.mp Subtype.range_val_subtype
/- Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn -/ import Mathlib.Data.Finset.Basic import Mathlib.ModelTheory.Syntax import Mathlib.Data.List.ProdSigma #align_import model_theory.semantics from "leanprover-community/mathlib"@"d565b3df44619c1498326936be16f1a935df0728" /-! # Basics on First-Order Semantics This file defines the interpretations of first-order terms, formulas, sentences, and theories in a style inspired by the [Flypitch project](https://flypitch.github.io/). ## Main Definitions * `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at variables `v`. * `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded formula `φ` evaluated at tuples of variables `v` and `xs`. * `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ` evaluated at variables `v`. * `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ` evaluated in the structure `M`. Also denoted `M ⊨ φ`. * `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`. ## Main Results * `FirstOrder.Language.BoundedFormula.realize_toPrenex` shows that the prenex normal form of a formula has the same realization as the original formula. * Several results in this file show that syntactic constructions such as `relabel`, `castLE`, `liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas, sentences, and theories. ## Implementation Notes * Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n` is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula `∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by `n : Fin (n + 1)`. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v w u' v' namespace FirstOrder namespace Language variable {L : Language.{u, v}} {L' : Language} variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P] variable {α : Type u'} {β : Type v'} {γ : Type*} open FirstOrder Cardinal open Structure Cardinal Fin namespace Term -- Porting note: universes in different order /-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/ def realize (v : α → M) : ∀ _t : L.Term α, M | var k => v k | func f ts => funMap f fun i => (ts i).realize v #align first_order.language.term.realize FirstOrder.Language.Term.realize /- Porting note: The equation lemma of `realize` is too strong; it simplifies terms like the LHS of `realize_functions_apply₁`. Even `eqns` can't fix this. We removed `simp` attr from `realize` and prepare new simp lemmas for `realize`. -/ @[simp] theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl @[simp] theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) : realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl @[simp] theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} : (t.relabel g).realize v = t.realize (v ∘ g) := by induction' t with _ n f ts ih · rfl · simp [ih] #align first_order.language.term.realize_relabel FirstOrder.Language.Term.realize_relabel @[simp] theorem realize_liftAt {n n' m : ℕ} {t : L.Term (Sum α (Fin n))} {v : Sum α (Fin (n + n')) → M} : (t.liftAt n' m).realize v = t.realize (v ∘ Sum.map id fun i : Fin _ => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := realize_relabel #align first_order.language.term.realize_lift_at FirstOrder.Language.Term.realize_liftAt @[simp] theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c := funMap_eq_coe_constants #align first_order.language.term.realize_constants FirstOrder.Language.Term.realize_constants @[simp] theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} : (f.apply₁ t).realize v = funMap f ![t.realize v] := by rw [Functions.apply₁, Term.realize] refine congr rfl (funext fun i => ?_) simp only [Matrix.cons_val_fin_one] #align first_order.language.term.realize_functions_apply₁ FirstOrder.Language.Term.realize_functions_apply₁ @[simp] theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} : (f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by rw [Functions.apply₂, Term.realize] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] #align first_order.language.term.realize_functions_apply₂ FirstOrder.Language.Term.realize_functions_apply₂ theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a := rfl #align first_order.language.term.realize_con FirstOrder.Language.Term.realize_con @[simp] theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} : (t.subst tf).realize v = t.realize fun a => (tf a).realize v := by induction' t with _ _ _ _ ih · rfl · simp [ih] #align first_order.language.term.realize_subst FirstOrder.Language.Term.realize_subst @[simp] theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s) {v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v := by induction' t with _ _ _ _ ih · rfl · simp_rw [varFinset, Finset.coe_biUnion, Set.iUnion_subset_iff] at h exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i))) #align first_order.language.term.realize_restrict_var FirstOrder.Language.Term.realize_restrictVar @[simp] theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (Sum α γ)} {s : Set α} (h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} : (t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) = t.realize (Sum.elim v xs) := by induction' t with a _ _ _ ih · cases a <;> rfl · simp_rw [varFinsetLeft, Finset.coe_biUnion, Set.iUnion_subset_iff] at h exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i))) #align first_order.language.term.realize_restrict_var_left FirstOrder.Language.Term.realize_restrictVarLeft @[simp] theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L[[α]].Term β} {v : β → M} : t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by induction' t with _ n f ts ih · simp · cases n · cases f · simp only [realize, ih, Nat.zero_eq, constantsOn, mk₂_Functions] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] · simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants] rfl · cases' f with _ f · simp only [realize, ih, constantsOn, mk₂_Functions] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] · exact isEmptyElim f #align first_order.language.term.realize_constants_to_vars FirstOrder.Language.Term.realize_constantsToVars @[simp] theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L.Term (Sum α β)} {v : β → M} : t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by induction' t with ab n f ts ih · cases' ab with a b -- Porting note: both cases were `simp [Language.con]` · simp [Language.con, realize, funMap_eq_coe_constants] · simp [realize, constantMap] · simp only [realize, constantsOn, mk₂_Functions, ih] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] #align first_order.language.term.realize_vars_to_constants FirstOrder.Language.Term.realize_varsToConstants theorem realize_constantsVarsEquivLeft [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (Sum β (Fin n))} {v : β → M} {xs : Fin n → M} : (constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) = t.realize (Sum.elim v xs) := by simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply, constantsVarsEquiv_apply, relabelEquiv_symm_apply] refine _root_.trans ?_ realize_constantsToVars rcongr x rcases x with (a | (b | i)) <;> simp #align first_order.language.term.realize_constants_vars_equiv_left FirstOrder.Language.Term.realize_constantsVarsEquivLeft end Term namespace LHom @[simp] theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α) (v : α → M) : (φ.onTerm t).realize v = t.realize v := by induction' t with _ n f ts ih · rfl · simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih] set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_term FirstOrder.Language.LHom.realize_onTerm end LHom @[simp] theorem Hom.realize_term (g : M →[L] N) {t : L.Term α} {v : α → M} : t.realize (g ∘ v) = g (t.realize v) := by induction t · rfl · rw [Term.realize, Term.realize, g.map_fun] refine congr rfl ?_ ext x simp [*] #align first_order.language.hom.realize_term FirstOrder.Language.Hom.realize_term @[simp] theorem Embedding.realize_term {v : α → M} (t : L.Term α) (g : M ↪[L] N) : t.realize (g ∘ v) = g (t.realize v) := g.toHom.realize_term #align first_order.language.embedding.realize_term FirstOrder.Language.Embedding.realize_term @[simp] theorem Equiv.realize_term {v : α → M} (t : L.Term α) (g : M ≃[L] N) : t.realize (g ∘ v) = g (t.realize v) := g.toHom.realize_term #align first_order.language.equiv.realize_term FirstOrder.Language.Equiv.realize_term variable {n : ℕ} namespace BoundedFormula open Term -- Porting note: universes in different order /-- A bounded formula can be evaluated as true or false by giving values to each free variable. -/ def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop | _, falsum, _v, _xs => False | _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) | _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs) | _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs | _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x) #align first_order.language.bounded_formula.realize FirstOrder.Language.BoundedFormula.Realize variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ} variable {v : α → M} {xs : Fin l → M} @[simp] theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False := Iff.rfl #align first_order.language.bounded_formula.realize_bot FirstOrder.Language.BoundedFormula.realize_bot @[simp] theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs := Iff.rfl #align first_order.language.bounded_formula.realize_not FirstOrder.Language.BoundedFormula.realize_not @[simp] theorem realize_bdEqual (t₁ t₂ : L.Term (Sum α (Fin l))) : (t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) := Iff.rfl #align first_order.language.bounded_formula.realize_bd_equal FirstOrder.Language.BoundedFormula.realize_bdEqual @[simp] theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by simp [Top.top] #align first_order.language.bounded_formula.realize_top FirstOrder.Language.BoundedFormula.realize_top @[simp] theorem realize_inf : (φ ⊓ ψ).Realize v xs ↔ φ.Realize v xs ∧ ψ.Realize v xs := by simp [Inf.inf, Realize] #align first_order.language.bounded_formula.realize_inf FirstOrder.Language.BoundedFormula.realize_inf @[simp] theorem realize_foldr_inf (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊓ ·) ⊤).Realize v xs ↔ ∀ φ ∈ l, BoundedFormula.Realize φ v xs := by induction' l with φ l ih · simp · simp [ih] #align first_order.language.bounded_formula.realize_foldr_inf FirstOrder.Language.BoundedFormula.realize_foldr_inf @[simp] theorem realize_imp : (φ.imp ψ).Realize v xs ↔ φ.Realize v xs → ψ.Realize v xs := by simp only [Realize] #align first_order.language.bounded_formula.realize_imp FirstOrder.Language.BoundedFormula.realize_imp @[simp] theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term _} : (R.boundedFormula ts).Realize v xs ↔ RelMap R fun i => (ts i).realize (Sum.elim v xs) := Iff.rfl #align first_order.language.bounded_formula.realize_rel FirstOrder.Language.BoundedFormula.realize_rel @[simp] theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} : (R.boundedFormula₁ t).Realize v xs ↔ RelMap R ![t.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₁, realize_rel, iff_eq_eq] refine congr rfl (funext fun _ => ?_) simp only [Matrix.cons_val_fin_one] #align first_order.language.bounded_formula.realize_rel₁ FirstOrder.Language.BoundedFormula.realize_rel₁ @[simp] theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} : (R.boundedFormula₂ t₁ t₂).Realize v xs ↔ RelMap R ![t₁.realize (Sum.elim v xs), t₂.realize (Sum.elim v xs)] := by rw [Relations.boundedFormula₂, realize_rel, iff_eq_eq] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] #align first_order.language.bounded_formula.realize_rel₂ FirstOrder.Language.BoundedFormula.realize_rel₂ @[simp] theorem realize_sup : (φ ⊔ ψ).Realize v xs ↔ φ.Realize v xs ∨ ψ.Realize v xs := by simp only [realize, Sup.sup, realize_not, eq_iff_iff] tauto #align first_order.language.bounded_formula.realize_sup FirstOrder.Language.BoundedFormula.realize_sup @[simp] theorem realize_foldr_sup (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) : (l.foldr (· ⊔ ·) ⊥).Realize v xs ↔ ∃ φ ∈ l, BoundedFormula.Realize φ v xs := by induction' l with φ l ih · simp · simp_rw [List.foldr_cons, realize_sup, ih, List.mem_cons, or_and_right, exists_or, exists_eq_left] #align first_order.language.bounded_formula.realize_foldr_sup FirstOrder.Language.BoundedFormula.realize_foldr_sup @[simp] theorem realize_all : (all θ).Realize v xs ↔ ∀ a : M, θ.Realize v (Fin.snoc xs a) := Iff.rfl #align first_order.language.bounded_formula.realize_all FirstOrder.Language.BoundedFormula.realize_all @[simp] theorem realize_ex : θ.ex.Realize v xs ↔ ∃ a : M, θ.Realize v (Fin.snoc xs a) := by rw [BoundedFormula.ex, realize_not, realize_all, not_forall] simp_rw [realize_not, Classical.not_not] #align first_order.language.bounded_formula.realize_ex FirstOrder.Language.BoundedFormula.realize_ex @[simp] theorem realize_iff : (φ.iff ψ).Realize v xs ↔ (φ.Realize v xs ↔ ψ.Realize v xs) := by simp only [BoundedFormula.iff, realize_inf, realize_imp, and_imp, ← iff_def] #align first_order.language.bounded_formula.realize_iff FirstOrder.Language.BoundedFormula.realize_iff theorem realize_castLE_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} {φ : L.BoundedFormula α m} {v : α → M} {xs : Fin n → M} : (φ.castLE h').Realize v xs ↔ φ.Realize v (xs ∘ cast h) := by subst h simp only [castLE_rfl, cast_refl, OrderIso.coe_refl, Function.comp_id] #align first_order.language.bounded_formula.realize_cast_le_of_eq FirstOrder.Language.BoundedFormula.realize_castLE_of_eq theorem realize_mapTermRel_id [L'.Structure M] {ft : ∀ n, L.Term (Sum α (Fin n)) → L'.Term (Sum β (Fin n))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} {v : α → M} {v' : β → M} {xs : Fin n → M} (h1 : ∀ (n) (t : L.Term (Sum α (Fin n))) (xs : Fin n → M), (ft n t).realize (Sum.elim v' xs) = t.realize (Sum.elim v xs)) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) : (φ.mapTermRel ft fr fun _ => id).Realize v' xs ↔ φ.Realize v xs := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih · rfl · simp [mapTermRel, Realize, h1] · simp [mapTermRel, Realize, h1, h2] · simp [mapTermRel, Realize, ih1, ih2] · simp only [mapTermRel, Realize, ih, id] #align first_order.language.bounded_formula.realize_map_term_rel_id FirstOrder.Language.BoundedFormula.realize_mapTermRel_id theorem realize_mapTermRel_add_castLe [L'.Structure M] {k : ℕ} {ft : ∀ n, L.Term (Sum α (Fin n)) → L'.Term (Sum β (Fin (k + n)))} {fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} (v : ∀ {n}, (Fin (k + n) → M) → α → M) {v' : β → M} (xs : Fin (k + n) → M) (h1 : ∀ (n) (t : L.Term (Sum α (Fin n))) (xs' : Fin (k + n) → M), (ft n t).realize (Sum.elim v' xs') = t.realize (Sum.elim (v xs') (xs' ∘ Fin.natAdd _))) (h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) (hv : ∀ (n) (xs : Fin (k + n) → M) (x : M), @v (n + 1) (snoc xs x : Fin _ → M) = v xs) : (φ.mapTermRel ft fr fun n => castLE (add_assoc _ _ _).symm.le).Realize v' xs ↔ φ.Realize (v xs) (xs ∘ Fin.natAdd _) := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih · rfl · simp [mapTermRel, Realize, h1] · simp [mapTermRel, Realize, h1, h2] · simp [mapTermRel, Realize, ih1, ih2] · simp [mapTermRel, Realize, ih, hv] #align first_order.language.bounded_formula.realize_map_term_rel_add_cast_le FirstOrder.Language.BoundedFormula.realize_mapTermRel_add_castLe @[simp] theorem realize_relabel {m n : ℕ} {φ : L.BoundedFormula α n} {g : α → Sum β (Fin m)} {v : β → M} {xs : Fin (m + n) → M} : (φ.relabel g).Realize v xs ↔ φ.Realize (Sum.elim v (xs ∘ Fin.castAdd n) ∘ g) (xs ∘ Fin.natAdd m) := by rw [relabel, realize_mapTermRel_add_castLe] <;> intros <;> simp #align first_order.language.bounded_formula.realize_relabel FirstOrder.Language.BoundedFormula.realize_relabel theorem realize_liftAt {n n' m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + n') → M} (hmn : m + n' ≤ n + 1) : (φ.liftAt n' m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := by rw [liftAt] induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 k _ ih3 · simp [mapTermRel, Realize] · simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map] · simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map] · simp only [mapTermRel, Realize, ih1 hmn, ih2 hmn] · have h : k + 1 + n' = k + n' + 1 := by rw [add_assoc, add_comm 1 n', ← add_assoc] simp only [mapTermRel, Realize, realize_castLE_of_eq h, ih3 (hmn.trans k.succ.le_succ)] refine forall_congr' fun x => iff_eq_eq.mpr (congr rfl (funext (Fin.lastCases ?_ fun i => ?_))) · simp only [Function.comp_apply, val_last, snoc_last] by_cases h : k < m · rw [if_pos h] refine (congr rfl (ext ?_)).trans (snoc_last _ _) simp only [coe_cast, coe_castAdd, val_last, self_eq_add_right] refine le_antisymm (le_of_add_le_add_left ((hmn.trans (Nat.succ_le_of_lt h)).trans ?_)) n'.zero_le rw [add_zero] · rw [if_neg h] refine (congr rfl (ext ?_)).trans (snoc_last _ _) simp · simp only [Function.comp_apply, Fin.snoc_castSucc] refine (congr rfl (ext ?_)).trans (snoc_castSucc _ _ _) simp only [coe_castSucc, coe_cast] split_ifs <;> simp #align first_order.language.bounded_formula.realize_lift_at FirstOrder.Language.BoundedFormula.realize_liftAt theorem realize_liftAt_one {n m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} (hmn : m ≤ n) : (φ.liftAt 1 m).Realize v xs ↔ φ.Realize v (xs ∘ fun i => if ↑i < m then castSucc i else i.succ) := by simp [realize_liftAt (add_le_add_right hmn 1), castSucc] #align first_order.language.bounded_formula.realize_lift_at_one FirstOrder.Language.BoundedFormula.realize_liftAt_one @[simp] theorem realize_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M} : (φ.liftAt 1 n).Realize v xs ↔ φ.Realize v (xs ∘ castSucc) := by rw [realize_liftAt_one (refl n), iff_eq_eq] refine congr rfl (congr rfl (funext fun i => ?_)) rw [if_pos i.is_lt] #align first_order.language.bounded_formula.realize_lift_at_one_self FirstOrder.Language.BoundedFormula.realize_liftAt_one_self @[simp] theorem realize_subst {φ : L.BoundedFormula α n} {tf : α → L.Term β} {v : β → M} {xs : Fin n → M} : (φ.subst tf).Realize v xs ↔ φ.Realize (fun a => (tf a).realize v) xs := realize_mapTermRel_id (fun n t x => by rw [Term.realize_subst] rcongr a cases a · simp only [Sum.elim_inl, Function.comp_apply, Term.realize_relabel, Sum.elim_comp_inl] · rfl) (by simp) #align first_order.language.bounded_formula.realize_subst FirstOrder.Language.BoundedFormula.realize_subst @[simp] theorem realize_restrictFreeVar [DecidableEq α] {n : ℕ} {φ : L.BoundedFormula α n} {s : Set α} (h : ↑φ.freeVarFinset ⊆ s) {v : α → M} {xs : Fin n → M} : (φ.restrictFreeVar (Set.inclusion h)).Realize (v ∘ (↑)) xs ↔ φ.Realize v xs := by induction' φ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 · rfl · simp [restrictFreeVar, Realize] · simp [restrictFreeVar, Realize] · simp [restrictFreeVar, Realize, ih1, ih2] · simp [restrictFreeVar, Realize, ih3] #align first_order.language.bounded_formula.realize_restrict_free_var FirstOrder.Language.BoundedFormula.realize_restrictFreeVar theorem realize_constantsVarsEquiv [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {φ : L[[α]].BoundedFormula β n} {v : β → M} {xs : Fin n → M} : (constantsVarsEquiv φ).Realize (Sum.elim (fun a => ↑(L.con a)) v) xs ↔ φ.Realize v xs := by refine realize_mapTermRel_id (fun n t xs => realize_constantsVarsEquivLeft) fun n R xs => ?_ -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [← (lhomWithConstants L α).map_onRelation (Equiv.sumEmpty (L.Relations n) ((constantsOn α).Relations n) R) xs] rcongr cases' R with R R · simp · exact isEmptyElim R #align first_order.language.bounded_formula.realize_constants_vars_equiv FirstOrder.Language.BoundedFormula.realize_constantsVarsEquiv @[simp] theorem realize_relabelEquiv {g : α ≃ β} {k} {φ : L.BoundedFormula α k} {v : β → M} {xs : Fin k → M} : (relabelEquiv g φ).Realize v xs ↔ φ.Realize (v ∘ g) xs := by simp only [relabelEquiv, mapTermRelEquiv_apply, Equiv.coe_refl] refine realize_mapTermRel_id (fun n t xs => ?_) fun _ _ _ => rfl simp only [relabelEquiv_apply, Term.realize_relabel] refine congr (congr rfl ?_) rfl ext (i | i) <;> rfl #align first_order.language.bounded_formula.realize_relabel_equiv FirstOrder.Language.BoundedFormula.realize_relabelEquiv variable [Nonempty M] theorem realize_all_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin n → M} : (φ.liftAt 1 n).all.Realize v xs ↔ φ.Realize v xs := by inhabit M simp only [realize_all, realize_liftAt_one_self] refine ⟨fun h => ?_, fun h a => ?_⟩ · refine (congr rfl (funext fun i => ?_)).mp (h default) simp · refine (congr rfl (funext fun i => ?_)).mp h simp #align first_order.language.bounded_formula.realize_all_lift_at_one_self FirstOrder.Language.BoundedFormula.realize_all_liftAt_one_self theorem realize_toPrenexImpRight {φ ψ : L.BoundedFormula α n} (hφ : IsQF φ) (hψ : IsPrenex ψ) {v : α → M} {xs : Fin n → M} : (φ.toPrenexImpRight ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by induction' hψ with _ _ hψ _ _ _hψ ih _ _ _hψ ih · rw [hψ.toPrenexImpRight] · refine _root_.trans (forall_congr' fun _ => ih hφ.liftAt) ?_ simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all] exact ⟨fun h1 a h2 => h1 h2 a, fun h1 h2 a => h1 a h2⟩ · unfold toPrenexImpRight rw [realize_ex] refine _root_.trans (exists_congr fun _ => ih hφ.liftAt) ?_ simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_ex] refine ⟨?_, fun h' => ?_⟩ · rintro ⟨a, ha⟩ h exact ⟨a, ha h⟩ · by_cases h : φ.Realize v xs · obtain ⟨a, ha⟩ := h' h exact ⟨a, fun _ => ha⟩ · inhabit M exact ⟨default, fun h'' => (h h'').elim⟩ #align first_order.language.bounded_formula.realize_to_prenex_imp_right FirstOrder.Language.BoundedFormula.realize_toPrenexImpRight theorem realize_toPrenexImp {φ ψ : L.BoundedFormula α n} (hφ : IsPrenex φ) (hψ : IsPrenex ψ) {v : α → M} {xs : Fin n → M} : (φ.toPrenexImp ψ).Realize v xs ↔ (φ.imp ψ).Realize v xs := by revert ψ induction' hφ with _ _ hφ _ _ _hφ ih _ _ _hφ ih <;> intro ψ hψ · rw [hφ.toPrenexImp] exact realize_toPrenexImpRight hφ hψ · unfold toPrenexImp rw [realize_ex] refine _root_.trans (exists_congr fun _ => ih hψ.liftAt) ?_ simp only [realize_imp, realize_liftAt_one_self, snoc_comp_castSucc, realize_all] refine ⟨?_, fun h' => ?_⟩ · rintro ⟨a, ha⟩ h exact ha (h a) · by_cases h : ψ.Realize v xs · inhabit M exact ⟨default, fun _h'' => h⟩ · obtain ⟨a, ha⟩ := not_forall.1 (h ∘ h') exact ⟨a, fun h => (ha h).elim⟩ · refine _root_.trans (forall_congr' fun _ => ih hψ.liftAt) ?_ simp #align first_order.language.bounded_formula.realize_to_prenex_imp FirstOrder.Language.BoundedFormula.realize_toPrenexImp @[simp] theorem realize_toPrenex (φ : L.BoundedFormula α n) {v : α → M} : ∀ {xs : Fin n → M}, φ.toPrenex.Realize v xs ↔ φ.Realize v xs := by induction' φ with _ _ _ _ _ _ _ _ _ f1 f2 h1 h2 _ _ h · exact Iff.rfl · exact Iff.rfl · exact Iff.rfl · intros rw [toPrenex, realize_toPrenexImp f1.toPrenex_isPrenex f2.toPrenex_isPrenex, realize_imp, realize_imp, h1, h2] · intros rw [realize_all, toPrenex, realize_all] exact forall_congr' fun a => h #align first_order.language.bounded_formula.realize_to_prenex FirstOrder.Language.BoundedFormula.realize_toPrenex end BoundedFormula -- Porting note: no `protected` attribute in Lean4 -- attribute [protected] bounded_formula.falsum bounded_formula.equal bounded_formula.rel -- attribute [protected] bounded_formula.imp bounded_formula.all namespace LHom open BoundedFormula @[simp] theorem realize_onBoundedFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] {n : ℕ} (ψ : L.BoundedFormula α n) {v : α → M} {xs : Fin n → M} : (φ.onBoundedFormula ψ).Realize v xs ↔ ψ.Realize v xs := by induction' ψ with _ _ _ _ _ _ _ _ _ _ _ ih1 ih2 _ _ ih3 · rfl · simp only [onBoundedFormula, realize_bdEqual, realize_onTerm] rfl · simp only [onBoundedFormula, realize_rel, LHom.map_onRelation, Function.comp_apply, realize_onTerm] rfl · simp only [onBoundedFormula, ih1, ih2, realize_imp] · simp only [onBoundedFormula, ih3, realize_all] set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_bounded_formula FirstOrder.Language.LHom.realize_onBoundedFormula end LHom -- Porting note: no `protected` attribute in Lean4 -- attribute [protected] bounded_formula.falsum bounded_formula.equal bounded_formula.rel -- attribute [protected] bounded_formula.imp bounded_formula.all namespace Formula /-- A formula can be evaluated as true or false by giving values to each free variable. -/ nonrec def Realize (φ : L.Formula α) (v : α → M) : Prop := φ.Realize v default #align first_order.language.formula.realize FirstOrder.Language.Formula.Realize variable {φ ψ : L.Formula α} {v : α → M} @[simp] theorem realize_not : φ.not.Realize v ↔ ¬φ.Realize v := Iff.rfl #align first_order.language.formula.realize_not FirstOrder.Language.Formula.realize_not @[simp] theorem realize_bot : (⊥ : L.Formula α).Realize v ↔ False := Iff.rfl #align first_order.language.formula.realize_bot FirstOrder.Language.Formula.realize_bot @[simp] theorem realize_top : (⊤ : L.Formula α).Realize v ↔ True := BoundedFormula.realize_top #align first_order.language.formula.realize_top FirstOrder.Language.Formula.realize_top @[simp] theorem realize_inf : (φ ⊓ ψ).Realize v ↔ φ.Realize v ∧ ψ.Realize v := BoundedFormula.realize_inf #align first_order.language.formula.realize_inf FirstOrder.Language.Formula.realize_inf @[simp] theorem realize_imp : (φ.imp ψ).Realize v ↔ φ.Realize v → ψ.Realize v := BoundedFormula.realize_imp #align first_order.language.formula.realize_imp FirstOrder.Language.Formula.realize_imp @[simp] theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term α} : (R.formula ts).Realize v ↔ RelMap R fun i => (ts i).realize v := BoundedFormula.realize_rel.trans (by simp) #align first_order.language.formula.realize_rel FirstOrder.Language.Formula.realize_rel @[simp] theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} : (R.formula₁ t).Realize v ↔ RelMap R ![t.realize v] := by rw [Relations.formula₁, realize_rel, iff_eq_eq] refine congr rfl (funext fun _ => ?_) simp only [Matrix.cons_val_fin_one] #align first_order.language.formula.realize_rel₁ FirstOrder.Language.Formula.realize_rel₁ @[simp] theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} : (R.formula₂ t₁ t₂).Realize v ↔ RelMap R ![t₁.realize v, t₂.realize v] := by rw [Relations.formula₂, realize_rel, iff_eq_eq] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] #align first_order.language.formula.realize_rel₂ FirstOrder.Language.Formula.realize_rel₂ @[simp] theorem realize_sup : (φ ⊔ ψ).Realize v ↔ φ.Realize v ∨ ψ.Realize v := BoundedFormula.realize_sup #align first_order.language.formula.realize_sup FirstOrder.Language.Formula.realize_sup @[simp] theorem realize_iff : (φ.iff ψ).Realize v ↔ (φ.Realize v ↔ ψ.Realize v) := BoundedFormula.realize_iff #align first_order.language.formula.realize_iff FirstOrder.Language.Formula.realize_iff @[simp] theorem realize_relabel {φ : L.Formula α} {g : α → β} {v : β → M} : (φ.relabel g).Realize v ↔ φ.Realize (v ∘ g) := by rw [Realize, Realize, relabel, BoundedFormula.realize_relabel, iff_eq_eq, Fin.castAdd_zero] exact congr rfl (funext finZeroElim) #align first_order.language.formula.realize_relabel FirstOrder.Language.Formula.realize_relabel theorem realize_relabel_sum_inr (φ : L.Formula (Fin n)) {v : Empty → M} {x : Fin n → M} : (BoundedFormula.relabel Sum.inr φ).Realize v x ↔ φ.Realize x := by rw [BoundedFormula.realize_relabel, Formula.Realize, Sum.elim_comp_inr, Fin.castAdd_zero, cast_refl, Function.comp_id, Subsingleton.elim (x ∘ (natAdd n : Fin 0 → Fin n)) default] #align first_order.language.formula.realize_relabel_sum_inr FirstOrder.Language.Formula.realize_relabel_sum_inr @[simp] theorem realize_equal {t₁ t₂ : L.Term α} {x : α → M} : (t₁.equal t₂).Realize x ↔ t₁.realize x = t₂.realize x := by simp [Term.equal, Realize] #align first_order.language.formula.realize_equal FirstOrder.Language.Formula.realize_equal @[simp] theorem realize_graph {f : L.Functions n} {x : Fin n → M} {y : M} : (Formula.graph f).Realize (Fin.cons y x : _ → M) ↔ funMap f x = y := by simp only [Formula.graph, Term.realize, realize_equal, Fin.cons_zero, Fin.cons_succ] rw [eq_comm] #align first_order.language.formula.realize_graph FirstOrder.Language.Formula.realize_graph end Formula @[simp] theorem LHom.realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α) {v : α → M} : (φ.onFormula ψ).Realize v ↔ ψ.Realize v := φ.realize_onBoundedFormula ψ set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_formula FirstOrder.Language.LHom.realize_onFormula @[simp] theorem LHom.setOf_realize_onFormula [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Formula α) : (setOf (φ.onFormula ψ).Realize : Set (α → M)) = setOf ψ.Realize := by ext simp set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.set_of_realize_on_formula FirstOrder.Language.LHom.setOf_realize_onFormula variable (M) /-- A sentence can be evaluated as true or false in a structure. -/ nonrec def Sentence.Realize (φ : L.Sentence) : Prop := φ.Realize (default : _ → M) #align first_order.language.sentence.realize FirstOrder.Language.Sentence.Realize -- input using \|= or \vDash, but not using \models @[inherit_doc Sentence.Realize] infixl:51 " ⊨ " => Sentence.Realize @[simp] theorem Sentence.realize_not {φ : L.Sentence} : M ⊨ φ.not ↔ ¬M ⊨ φ := Iff.rfl #align first_order.language.sentence.realize_not FirstOrder.Language.Sentence.realize_not namespace Formula @[simp] theorem realize_equivSentence_symm_con [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M] (φ : L[[α]].Sentence) : ((equivSentence.symm φ).Realize fun a => (L.con a : M)) ↔ φ.Realize M := by simp only [equivSentence, _root_.Equiv.symm_symm, Equiv.coe_trans, Realize, BoundedFormula.realize_relabelEquiv, Function.comp] refine _root_.trans ?_ BoundedFormula.realize_constantsVarsEquiv rw [iff_iff_eq] congr with (_ | a) · simp · cases a #align first_order.language.formula.realize_equiv_sentence_symm_con FirstOrder.Language.Formula.realize_equivSentence_symm_con @[simp] theorem realize_equivSentence [L[[α]].Structure M] [(L.lhomWithConstants α).IsExpansionOn M] (φ : L.Formula α) : (equivSentence φ).Realize M ↔ φ.Realize fun a => (L.con a : M) := by rw [← realize_equivSentence_symm_con M (equivSentence φ), _root_.Equiv.symm_apply_apply] #align first_order.language.formula.realize_equiv_sentence FirstOrder.Language.Formula.realize_equivSentence theorem realize_equivSentence_symm (φ : L[[α]].Sentence) (v : α → M) : (equivSentence.symm φ).Realize v ↔ @Sentence.Realize _ M (@Language.withConstantsStructure L M _ α (constantsOn.structure v)) φ := letI := constantsOn.structure v realize_equivSentence_symm_con M φ #align first_order.language.formula.realize_equiv_sentence_symm FirstOrder.Language.Formula.realize_equivSentence_symm end Formula @[simp] theorem LHom.realize_onSentence [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (ψ : L.Sentence) : M ⊨ φ.onSentence ψ ↔ M ⊨ ψ := φ.realize_onFormula ψ set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_sentence FirstOrder.Language.LHom.realize_onSentence variable (L) /-- The complete theory of a structure `M` is the set of all sentences `M` satisfies. -/ def completeTheory : L.Theory := { φ | M ⊨ φ } #align first_order.language.complete_theory FirstOrder.Language.completeTheory variable (N) /-- Two structures are elementarily equivalent when they satisfy the same sentences. -/ def ElementarilyEquivalent : Prop := L.completeTheory M = L.completeTheory N #align first_order.language.elementarily_equivalent FirstOrder.Language.ElementarilyEquivalent @[inherit_doc FirstOrder.Language.ElementarilyEquivalent] scoped[FirstOrder] notation:25 A " ≅[" L "] " B:50 => FirstOrder.Language.ElementarilyEquivalent L A B variable {L} {M} {N} @[simp] theorem mem_completeTheory {φ : Sentence L} : φ ∈ L.completeTheory M ↔ M ⊨ φ := Iff.rfl #align first_order.language.mem_complete_theory FirstOrder.Language.mem_completeTheory theorem elementarilyEquivalent_iff : M ≅[L] N ↔ ∀ φ : L.Sentence, M ⊨ φ ↔ N ⊨ φ := by simp only [ElementarilyEquivalent, Set.ext_iff, completeTheory, Set.mem_setOf_eq] #align first_order.language.elementarily_equivalent_iff FirstOrder.Language.elementarilyEquivalent_iff variable (M) /-- A model of a theory is a structure in which every sentence is realized as true. -/ class Theory.Model (T : L.Theory) : Prop where realize_of_mem : ∀ φ ∈ T, M ⊨ φ set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model FirstOrder.Language.Theory.Model -- input using \|= or \vDash, but not using \models @[inherit_doc Theory.Model] infixl:51 " ⊨ " => Theory.Model variable {M} (T : L.Theory) @[simp default-10] theorem Theory.model_iff : M ⊨ T ↔ ∀ φ ∈ T, M ⊨ φ := ⟨fun h => h.realize_of_mem, fun h => ⟨h⟩⟩ set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model_iff FirstOrder.Language.Theory.model_iff theorem Theory.realize_sentence_of_mem [M ⊨ T] {φ : L.Sentence} (h : φ ∈ T) : M ⊨ φ := Theory.Model.realize_of_mem φ h set_option linter.uppercaseLean3 false in #align first_order.language.Theory.realize_sentence_of_mem FirstOrder.Language.Theory.realize_sentence_of_mem @[simp] theorem LHom.onTheory_model [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (T : L.Theory) : M ⊨ φ.onTheory T ↔ M ⊨ T := by simp [Theory.model_iff, LHom.onTheory] set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.on_Theory_model FirstOrder.Language.LHom.onTheory_model variable {T} instance model_empty : M ⊨ (∅ : L.Theory) := ⟨fun φ hφ => (Set.not_mem_empty φ hφ).elim⟩ #align first_order.language.model_empty FirstOrder.Language.model_empty namespace Theory theorem Model.mono {T' : L.Theory} (_h : M ⊨ T') (hs : T ⊆ T') : M ⊨ T := ⟨fun _φ hφ => T'.realize_sentence_of_mem (hs hφ)⟩ set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model.mono FirstOrder.Language.Theory.Model.mono
Mathlib/ModelTheory/Semantics.lean
840
842
theorem Model.union {T' : L.Theory} (h : M ⊨ T) (h' : M ⊨ T') : M ⊨ T ∪ T' := by
simp only [model_iff, Set.mem_union] at * exact fun φ hφ => hφ.elim (h _) (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, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Order.MinMax import Mathlib.Data.Set.Subsingleton import Mathlib.Tactic.Says #align_import data.set.intervals.basic from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c" /-! # Intervals In any preorder `α`, we define intervals (which on each side can be either infinite, open, or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. This file contains these definitions, and basic facts on inclusion, intersection, difference of intervals (where the precise statements may depend on the properties of the order, in particular for some statements it should be `LinearOrder` or `DenselyOrdered`). TODO: This is just the beginning; a lot of rules are missing -/ open Function open OrderDual (toDual ofDual) variable {α β : Type*} namespace Set section Preorder variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α} /-- Left-open right-open interval -/ def Ioo (a b : α) := { x | a < x ∧ x < b } #align set.Ioo Set.Ioo /-- Left-closed right-open interval -/ def Ico (a b : α) := { x | a ≤ x ∧ x < b } #align set.Ico Set.Ico /-- Left-infinite right-open interval -/ def Iio (a : α) := { x | x < a } #align set.Iio Set.Iio /-- Left-closed right-closed interval -/ def Icc (a b : α) := { x | a ≤ x ∧ x ≤ b } #align set.Icc Set.Icc /-- Left-infinite right-closed interval -/ def Iic (b : α) := { x | x ≤ b } #align set.Iic Set.Iic /-- Left-open right-closed interval -/ def Ioc (a b : α) := { x | a < x ∧ x ≤ b } #align set.Ioc Set.Ioc /-- Left-closed right-infinite interval -/ def Ici (a : α) := { x | a ≤ x } #align set.Ici Set.Ici /-- Left-open right-infinite interval -/ def Ioi (a : α) := { x | a < x } #align set.Ioi Set.Ioi theorem Ioo_def (a b : α) : { x | a < x ∧ x < b } = Ioo a b := rfl #align set.Ioo_def Set.Ioo_def theorem Ico_def (a b : α) : { x | a ≤ x ∧ x < b } = Ico a b := rfl #align set.Ico_def Set.Ico_def theorem Iio_def (a : α) : { x | x < a } = Iio a := rfl #align set.Iio_def Set.Iio_def theorem Icc_def (a b : α) : { x | a ≤ x ∧ x ≤ b } = Icc a b := rfl #align set.Icc_def Set.Icc_def theorem Iic_def (b : α) : { x | x ≤ b } = Iic b := rfl #align set.Iic_def Set.Iic_def theorem Ioc_def (a b : α) : { x | a < x ∧ x ≤ b } = Ioc a b := rfl #align set.Ioc_def Set.Ioc_def theorem Ici_def (a : α) : { x | a ≤ x } = Ici a := rfl #align set.Ici_def Set.Ici_def theorem Ioi_def (a : α) : { x | a < x } = Ioi a := rfl #align set.Ioi_def Set.Ioi_def @[simp] theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := Iff.rfl #align set.mem_Ioo Set.mem_Ioo @[simp] theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := Iff.rfl #align set.mem_Ico Set.mem_Ico @[simp] theorem mem_Iio : x ∈ Iio b ↔ x < b := Iff.rfl #align set.mem_Iio Set.mem_Iio @[simp] theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := Iff.rfl #align set.mem_Icc Set.mem_Icc @[simp] theorem mem_Iic : x ∈ Iic b ↔ x ≤ b := Iff.rfl #align set.mem_Iic Set.mem_Iic @[simp] theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := Iff.rfl #align set.mem_Ioc Set.mem_Ioc @[simp] theorem mem_Ici : x ∈ Ici a ↔ a ≤ x := Iff.rfl #align set.mem_Ici Set.mem_Ici @[simp] theorem mem_Ioi : x ∈ Ioi a ↔ a < x := Iff.rfl #align set.mem_Ioi Set.mem_Ioi instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption #align set.decidable_mem_Ioo Set.decidableMemIoo instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption #align set.decidable_mem_Ico Set.decidableMemIco instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption #align set.decidable_mem_Iio Set.decidableMemIio instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption #align set.decidable_mem_Icc Set.decidableMemIcc instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption #align set.decidable_mem_Iic Set.decidableMemIic instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption #align set.decidable_mem_Ioc Set.decidableMemIoc instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption #align set.decidable_mem_Ici Set.decidableMemIci instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption #align set.decidable_mem_Ioi Set.decidableMemIoi -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioo Set.left_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] #align set.left_mem_Ico Set.left_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.left_mem_Icc Set.left_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioc Set.left_mem_Ioc theorem left_mem_Ici : a ∈ Ici a := by simp #align set.left_mem_Ici Set.left_mem_Ici -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ioo Set.right_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ico Set.right_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.right_mem_Icc Set.right_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] #align set.right_mem_Ioc Set.right_mem_Ioc theorem right_mem_Iic : a ∈ Iic a := by simp #align set.right_mem_Iic Set.right_mem_Iic @[simp] theorem dual_Ici : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl #align set.dual_Ici Set.dual_Ici @[simp] theorem dual_Iic : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl #align set.dual_Iic Set.dual_Iic @[simp] theorem dual_Ioi : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl #align set.dual_Ioi Set.dual_Ioi @[simp] theorem dual_Iio : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl #align set.dual_Iio Set.dual_Iio @[simp] theorem dual_Icc : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm #align set.dual_Icc Set.dual_Icc @[simp] theorem dual_Ioc : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm #align set.dual_Ioc Set.dual_Ioc @[simp] theorem dual_Ico : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm #align set.dual_Ico Set.dual_Ico @[simp] theorem dual_Ioo : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm #align set.dual_Ioo Set.dual_Ioo @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := ⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩ #align set.nonempty_Icc Set.nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩ #align set.nonempty_Ico Set.nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩ #align set.nonempty_Ioc Set.nonempty_Ioc @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ #align set.nonempty_Ici Set.nonempty_Ici @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ #align set.nonempty_Iic Set.nonempty_Iic @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ #align set.nonempty_Ioo Set.nonempty_Ioo @[simp] theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty := exists_gt a #align set.nonempty_Ioi Set.nonempty_Ioi @[simp] theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty := exists_lt a #align set.nonempty_Iio Set.nonempty_Iio theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) #align set.nonempty_Icc_subtype Set.nonempty_Icc_subtype theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) #align set.nonempty_Ico_subtype Set.nonempty_Ico_subtype theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) #align set.nonempty_Ioc_subtype Set.nonempty_Ioc_subtype /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici #align set.nonempty_Ici_subtype Set.nonempty_Ici_subtype /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic #align set.nonempty_Iic_subtype Set.nonempty_Iic_subtype theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) #align set.nonempty_Ioo_subtype Set.nonempty_Ioo_subtype /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi #align set.nonempty_Ioi_subtype Set.nonempty_Ioi_subtype /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio #align set.nonempty_Iio_subtype Set.nonempty_Iio_subtype instance [NoMinOrder α] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder α] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder α] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (α := Iio (toDual a)) instance [NoMaxOrder α] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (α := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Icc_eq_empty Set.Icc_eq_empty @[simp] theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) #align set.Ico_eq_empty Set.Ico_eq_empty @[simp] theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) #align set.Ioc_eq_empty Set.Ioc_eq_empty @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Ioo_eq_empty Set.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align set.Icc_eq_empty_of_lt Set.Icc_eq_empty_of_lt @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt #align set.Ico_eq_empty_of_le Set.Ico_eq_empty_of_le @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt #align set.Ioc_eq_empty_of_le Set.Ioc_eq_empty_of_le @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt #align set.Ioo_eq_empty_of_le Set.Ioo_eq_empty_of_le -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ #align set.Ico_self Set.Ico_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ #align set.Ioc_self Set.Ioc_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ #align set.Ioo_self Set.Ioo_self theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ #align set.Ici_subset_Ici Set.Ici_subset_Ici @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := @Ici_subset_Ici αᵒᵈ _ _ _ #align set.Iic_subset_Iic Set.Iic_subset_Iic @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ #align set.Ici_subset_Ioi Set.Ici_subset_Ioi theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ #align set.Iic_subset_Iio Set.Iic_subset_Iio @[gcongr] theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩ #align set.Ioo_subset_Ioo Set.Ioo_subset_Ioo @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align set.Ioo_subset_Ioo_left Set.Ioo_subset_Ioo_left @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align set.Ioo_subset_Ioo_right Set.Ioo_subset_Ioo_right @[gcongr] theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, hx₂.trans_le h₂⟩ #align set.Ico_subset_Ico Set.Ico_subset_Ico @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align set.Ico_subset_Ico_left Set.Ico_subset_Ico_left @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align set.Ico_subset_Ico_right Set.Ico_subset_Ico_right @[gcongr] theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, le_trans hx₂ h₂⟩ #align set.Icc_subset_Icc Set.Icc_subset_Icc @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align set.Icc_subset_Icc_left Set.Icc_subset_Icc_left @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align set.Icc_subset_Icc_right Set.Icc_subset_Icc_right theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ #align set.Icc_subset_Ioo Set.Icc_subset_Ioo theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left #align set.Icc_subset_Ici_self Set.Icc_subset_Ici_self theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right #align set.Icc_subset_Iic_self Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right #align set.Ioc_subset_Iic_self Set.Ioc_subset_Iic_self @[gcongr] theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩ #align set.Ioc_subset_Ioc Set.Ioc_subset_Ioc @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align set.Ioc_subset_Ioc_left Set.Ioc_subset_Ioc_left @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align set.Ioc_subset_Ioc_right Set.Ioc_subset_Ioc_right theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ => And.imp_left h₁.trans_le #align set.Ico_subset_Ioo_left Set.Ico_subset_Ioo_left theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ => And.imp_right fun h' => h'.trans_lt h #align set.Ioc_subset_Ioo_right Set.Ioc_subset_Ioo_right theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ => And.imp_right fun h₂ => h₂.trans_lt h₁ #align set.Icc_subset_Ico_right Set.Icc_subset_Ico_right theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt #align set.Ioo_subset_Ico_self Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt #align set.Ioo_subset_Ioc_self Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt #align set.Ico_subset_Icc_self Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt #align set.Ioc_subset_Icc_self Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self #align set.Ioo_subset_Icc_self Set.Ioo_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right #align set.Ico_subset_Iio_self Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right #align set.Ioo_subset_Iio_self Set.Ioo_subset_Iio_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left #align set.Ioc_subset_Ioi_self Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left #align set.Ioo_subset_Ioi_self Set.Ioo_subset_Ioi_self theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx #align set.Ioi_subset_Ici_self Set.Ioi_subset_Ici_self theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx #align set.Iio_subset_Iic_self Set.Iio_subset_Iic_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left #align set.Ico_subset_Ici_self Set.Ico_subset_Ici_self theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ #align set.Ioi_ssubset_Ici_self Set.Ioi_ssubset_Ici_self theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a := @Ioi_ssubset_Ici_self αᵒᵈ _ _ #align set.Iio_ssubset_Iic_self Set.Iio_ssubset_Iic_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Icc_iff Set.Icc_subset_Icc_iff theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ioo_iff Set.Icc_subset_Ioo_iff theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ico_iff Set.Icc_subset_Ico_iff theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Ioc_iff Set.Icc_subset_Ioc_iff theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ #align set.Icc_subset_Iio_iff Set.Icc_subset_Iio_iff theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ #align set.Icc_subset_Ioi_iff Set.Icc_subset_Ioi_iff theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ #align set.Icc_subset_Iic_iff Set.Icc_subset_Iic_iff theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩ #align set.Icc_subset_Ici_iff Set.Icc_subset_Ici_iff theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩ #align set.Icc_ssubset_Icc_left Set.Icc_ssubset_Icc_left theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ #align set.Icc_ssubset_Icc_right Set.Icc_ssubset_Icc_right /-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx #align set.Ioi_subset_Ioi Set.Ioi_subset_Ioi /-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self #align set.Ioi_subset_Ici Set.Ioi_subset_Ici /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h #align set.Iio_subset_Iio Set.Iio_subset_Iio /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self #align set.Iio_subset_Iic Set.Iio_subset_Iic theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl #align set.Ici_inter_Iic Set.Ici_inter_Iic theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl #align set.Ici_inter_Iio Set.Ici_inter_Iio theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl #align set.Ioi_inter_Iic Set.Ioi_inter_Iic theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl #align set.Ioi_inter_Iio Set.Ioi_inter_Iio theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ #align set.Iic_inter_Ici Set.Iic_inter_Ici theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ #align set.Iio_inter_Ici Set.Iio_inter_Ici theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ #align set.Iic_inter_Ioi Set.Iic_inter_Ioi theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ #align set.Iio_inter_Ioi Set.Iio_inter_Ioi theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h #align set.mem_Icc_of_Ioo Set.mem_Icc_of_Ioo theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h #align set.mem_Ico_of_Ioo Set.mem_Ico_of_Ioo theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h #align set.mem_Ioc_of_Ioo Set.mem_Ioc_of_Ioo theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h #align set.mem_Icc_of_Ico Set.mem_Icc_of_Ico theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h #align set.mem_Icc_of_Ioc Set.mem_Icc_of_Ioc theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h #align set.mem_Ici_of_Ioi Set.mem_Ici_of_Ioi theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h #align set.mem_Iic_of_Iio Set.mem_Iic_of_Iio theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] #align set.Icc_eq_empty_iff Set.Icc_eq_empty_iff theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico] #align set.Ico_eq_empty_iff Set.Ico_eq_empty_iff theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc] #align set.Ioc_eq_empty_iff Set.Ioc_eq_empty_iff theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo] #align set.Ioo_eq_empty_iff Set.Ioo_eq_empty_iff theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ := eq_univ_of_forall h #align is_top.Iic_eq IsTop.Iic_eq theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ := eq_univ_of_forall h #align is_bot.Ici_eq IsBot.Ici_eq theorem _root_.IsMax.Ioi_eq (h : IsMax a) : Ioi a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_max.Ioi_eq IsMax.Ioi_eq theorem _root_.IsMin.Iio_eq (h : IsMin a) : Iio a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_min.Iio_eq IsMin.Iio_eq theorem Iic_inter_Ioc_of_le (h : a ≤ c) : Iic a ∩ Ioc b c = Ioc b a := ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩ #align set.Iic_inter_Ioc_of_le Set.Iic_inter_Ioc_of_le theorem not_mem_Icc_of_lt (ha : c < a) : c ∉ Icc a b := fun h => ha.not_le h.1 #align set.not_mem_Icc_of_lt Set.not_mem_Icc_of_lt theorem not_mem_Icc_of_gt (hb : b < c) : c ∉ Icc a b := fun h => hb.not_le h.2 #align set.not_mem_Icc_of_gt Set.not_mem_Icc_of_gt theorem not_mem_Ico_of_lt (ha : c < a) : c ∉ Ico a b := fun h => ha.not_le h.1 #align set.not_mem_Ico_of_lt Set.not_mem_Ico_of_lt theorem not_mem_Ioc_of_gt (hb : b < c) : c ∉ Ioc a b := fun h => hb.not_le h.2 #align set.not_mem_Ioc_of_gt Set.not_mem_Ioc_of_gt -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Ioi_self : a ∉ Ioi a := lt_irrefl _ #align set.not_mem_Ioi_self Set.not_mem_Ioi_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Iio_self : b ∉ Iio b := lt_irrefl _ #align set.not_mem_Iio_self Set.not_mem_Iio_self theorem not_mem_Ioc_of_le (ha : c ≤ a) : c ∉ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioc_of_le Set.not_mem_Ioc_of_le theorem not_mem_Ico_of_ge (hb : b ≤ c) : c ∉ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ico_of_ge Set.not_mem_Ico_of_ge theorem not_mem_Ioo_of_le (ha : c ≤ a) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioo_of_le Set.not_mem_Ioo_of_le theorem not_mem_Ioo_of_ge (hb : b ≤ c) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ioo_of_ge Set.not_mem_Ioo_of_ge end Preorder section PartialOrder variable [PartialOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := Set.ext <| by simp [Icc, le_antisymm_iff, and_comm] #align set.Icc_self Set.Icc_self instance instIccUnique : Unique (Set.Icc a a) where default := ⟨a, by simp⟩ uniq y := Subtype.ext <| by simpa using y.2 @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by refine ⟨fun h => ?_, ?_⟩ · have hab : a ≤ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c) exact ⟨eq_of_mem_singleton <| h.subst <| left_mem_Icc.2 hab, eq_of_mem_singleton <| h.subst <| right_mem_Icc.2 hab⟩ · rintro ⟨rfl, rfl⟩ exact Icc_self _ #align set.Icc_eq_singleton_iff Set.Icc_eq_singleton_iff lemma subsingleton_Icc_of_ge (hba : b ≤ a) : Set.Subsingleton (Icc a b) := fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm (le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba) #align set.subsingleton_Icc_of_ge Set.subsingleton_Icc_of_ge @[simp] lemma subsingleton_Icc_iff {α : Type*} [LinearOrder α] {a b : α} : Set.Subsingleton (Icc a b) ↔ b ≤ a := by refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩ contrapose! h simp only [ge_iff_le, gt_iff_lt, not_subsingleton_iff] exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩ @[simp] theorem Icc_diff_left : Icc a b \ {a} = Ioc a b := ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm] #align set.Icc_diff_left Set.Icc_diff_left @[simp] theorem Icc_diff_right : Icc a b \ {b} = Ico a b := ext fun x => by simp [lt_iff_le_and_ne, and_assoc] #align set.Icc_diff_right Set.Icc_diff_right @[simp] theorem Ico_diff_left : Ico a b \ {a} = Ioo a b := ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm] #align set.Ico_diff_left Set.Ico_diff_left @[simp] theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b := ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne] #align set.Ioc_diff_right Set.Ioc_diff_right @[simp] theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right] #align set.Icc_diff_both Set.Icc_diff_both @[simp] theorem Ici_diff_left : Ici a \ {a} = Ioi a := ext fun x => by simp [lt_iff_le_and_ne, eq_comm] #align set.Ici_diff_left Set.Ici_diff_left @[simp] theorem Iic_diff_right : Iic a \ {a} = Iio a := ext fun x => by simp [lt_iff_le_and_ne] #align set.Iic_diff_right Set.Iic_diff_right @[simp] theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)] #align set.Ico_diff_Ioo_same Set.Ico_diff_Ioo_same @[simp] theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)] #align set.Ioc_diff_Ioo_same Set.Ioc_diff_Ioo_same @[simp] theorem Icc_diff_Ico_same (h : a ≤ b) : Icc a b \ Ico a b = {b} := by rw [← Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)] #align set.Icc_diff_Ico_same Set.Icc_diff_Ico_same @[simp] theorem Icc_diff_Ioc_same (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by rw [← Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)] #align set.Icc_diff_Ioc_same Set.Icc_diff_Ioc_same @[simp] theorem Icc_diff_Ioo_same (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by rw [← Icc_diff_both, diff_diff_cancel_left] simp [insert_subset_iff, h] #align set.Icc_diff_Ioo_same Set.Icc_diff_Ioo_same @[simp] theorem Ici_diff_Ioi_same : Ici a \ Ioi a = {a} := by rw [← Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)] #align set.Ici_diff_Ioi_same Set.Ici_diff_Ioi_same @[simp] theorem Iic_diff_Iio_same : Iic a \ Iio a = {a} := by rw [← Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)] #align set.Iic_diff_Iio_same Set.Iic_diff_Iio_same -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioi_union_left : Ioi a ∪ {a} = Ici a := ext fun x => by simp [eq_comm, le_iff_eq_or_lt] #align set.Ioi_union_left Set.Ioi_union_left -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Iio_union_right : Iio a ∪ {a} = Iic a := ext fun _ => le_iff_lt_or_eq.symm #align set.Iio_union_right Set.Iio_union_right theorem Ioo_union_left (hab : a < b) : Ioo a b ∪ {a} = Ico a b := by rw [← Ico_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Ico.2 hab)] #align set.Ioo_union_left Set.Ioo_union_left theorem Ioo_union_right (hab : a < b) : Ioo a b ∪ {b} = Ioc a b := by simpa only [dual_Ioo, dual_Ico] using Ioo_union_left hab.dual #align set.Ioo_union_right Set.Ioo_union_right theorem Ioo_union_both (h : a ≤ b) : Ioo a b ∪ {a, b} = Icc a b := by have : (Icc a b \ {a, b}) ∪ {a, b} = Icc a b := diff_union_of_subset fun | x, .inl rfl => left_mem_Icc.mpr h | x, .inr rfl => right_mem_Icc.mpr h rw [← this, Icc_diff_both] theorem Ioc_union_left (hab : a ≤ b) : Ioc a b ∪ {a} = Icc a b := by rw [← Icc_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Icc.2 hab)] #align set.Ioc_union_left Set.Ioc_union_left theorem Ico_union_right (hab : a ≤ b) : Ico a b ∪ {b} = Icc a b := by simpa only [dual_Ioc, dual_Icc] using Ioc_union_left hab.dual #align set.Ico_union_right Set.Ico_union_right @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [insert_eq, union_comm, Ico_union_right h] #align set.Ico_insert_right Set.Ico_insert_right @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [insert_eq, union_comm, Ioc_union_left h] #align set.Ioc_insert_left Set.Ioc_insert_left @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [insert_eq, union_comm, Ioo_union_left h] #align set.Ioo_insert_left Set.Ioo_insert_left @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [insert_eq, union_comm, Ioo_union_right h] #align set.Ioo_insert_right Set.Ioo_insert_right @[simp] theorem Iio_insert : insert a (Iio a) = Iic a := ext fun _ => le_iff_eq_or_lt.symm #align set.Iio_insert Set.Iio_insert @[simp] theorem Ioi_insert : insert a (Ioi a) = Ici a := ext fun _ => (or_congr_left eq_comm).trans le_iff_eq_or_lt.symm #align set.Ioi_insert Set.Ioi_insert theorem mem_Ici_Ioi_of_subset_of_subset {s : Set α} (ho : Ioi a ⊆ s) (hc : s ⊆ Ici a) : s ∈ ({Ici a, Ioi a} : Set (Set α)) := by_cases (fun h : a ∈ s => Or.inl <| Subset.antisymm hc <| by rw [← Ioi_union_left, union_subset_iff]; simp [*]) fun h => Or.inr <| Subset.antisymm (fun x hx => lt_of_le_of_ne (hc hx) fun heq => h <| heq.symm ▸ hx) ho #align set.mem_Ici_Ioi_of_subset_of_subset Set.mem_Ici_Ioi_of_subset_of_subset theorem mem_Iic_Iio_of_subset_of_subset {s : Set α} (ho : Iio a ⊆ s) (hc : s ⊆ Iic a) : s ∈ ({Iic a, Iio a} : Set (Set α)) := @mem_Ici_Ioi_of_subset_of_subset αᵒᵈ _ a s ho hc #align set.mem_Iic_Iio_of_subset_of_subset Set.mem_Iic_Iio_of_subset_of_subset theorem mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : Set α} (ho : Ioo a b ⊆ s) (hc : s ⊆ Icc a b) : s ∈ ({Icc a b, Ico a b, Ioc a b, Ioo a b} : Set (Set α)) := by classical by_cases ha : a ∈ s <;> by_cases hb : b ∈ s · refine Or.inl (Subset.antisymm hc ?_) rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha, ← Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_right] exact subset_diff_singleton hc hb · rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho · refine Or.inr <| Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_left] exact subset_diff_singleton hc ha · rwa [← Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inr <| Or.inr <| Subset.antisymm ?_ ho rw [← Ico_diff_left, ← Icc_diff_right] apply_rules [subset_diff_singleton] #align set.mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset Set.mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset theorem eq_left_or_mem_Ioo_of_mem_Ico {x : α} (hmem : x ∈ Ico a b) : x = a ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => ⟨h, hmem.2⟩ #align set.eq_left_or_mem_Ioo_of_mem_Ico Set.eq_left_or_mem_Ioo_of_mem_Ico theorem eq_right_or_mem_Ioo_of_mem_Ioc {x : α} (hmem : x ∈ Ioc a b) : x = b ∨ x ∈ Ioo a b := hmem.2.eq_or_lt.imp_right <| And.intro hmem.1 #align set.eq_right_or_mem_Ioo_of_mem_Ioc Set.eq_right_or_mem_Ioo_of_mem_Ioc theorem eq_endpoints_or_mem_Ioo_of_mem_Icc {x : α} (hmem : x ∈ Icc a b) : x = a ∨ x = b ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => eq_right_or_mem_Ioo_of_mem_Ioc ⟨h, hmem.2⟩ #align set.eq_endpoints_or_mem_Ioo_of_mem_Icc Set.eq_endpoints_or_mem_Ioo_of_mem_Icc theorem _root_.IsMax.Ici_eq (h : IsMax a) : Ici a = {a} := eq_singleton_iff_unique_mem.2 ⟨left_mem_Ici, fun _ => h.eq_of_ge⟩ #align is_max.Ici_eq IsMax.Ici_eq theorem _root_.IsMin.Iic_eq (h : IsMin a) : Iic a = {a} := h.toDual.Ici_eq #align is_min.Iic_eq IsMin.Iic_eq theorem Ici_injective : Injective (Ici : α → Set α) := fun _ _ => eq_of_forall_ge_iff ∘ Set.ext_iff.1 #align set.Ici_injective Set.Ici_injective theorem Iic_injective : Injective (Iic : α → Set α) := fun _ _ => eq_of_forall_le_iff ∘ Set.ext_iff.1 #align set.Iic_injective Set.Iic_injective theorem Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff #align set.Ici_inj Set.Ici_inj theorem Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff #align set.Iic_inj Set.Iic_inj end PartialOrder section OrderTop @[simp] theorem Ici_top [PartialOrder α] [OrderTop α] : Ici (⊤ : α) = {⊤} := isMax_top.Ici_eq #align set.Ici_top Set.Ici_top variable [Preorder α] [OrderTop α] {a : α} @[simp] theorem Ioi_top : Ioi (⊤ : α) = ∅ := isMax_top.Ioi_eq #align set.Ioi_top Set.Ioi_top @[simp] theorem Iic_top : Iic (⊤ : α) = univ := isTop_top.Iic_eq #align set.Iic_top Set.Iic_top @[simp] theorem Icc_top : Icc a ⊤ = Ici a := by simp [← Ici_inter_Iic] #align set.Icc_top Set.Icc_top @[simp] theorem Ioc_top : Ioc a ⊤ = Ioi a := by simp [← Ioi_inter_Iic] #align set.Ioc_top Set.Ioc_top end OrderTop section OrderBot @[simp] theorem Iic_bot [PartialOrder α] [OrderBot α] : Iic (⊥ : α) = {⊥} := isMin_bot.Iic_eq #align set.Iic_bot Set.Iic_bot variable [Preorder α] [OrderBot α] {a : α} @[simp] theorem Iio_bot : Iio (⊥ : α) = ∅ := isMin_bot.Iio_eq #align set.Iio_bot Set.Iio_bot @[simp] theorem Ici_bot : Ici (⊥ : α) = univ := isBot_bot.Ici_eq #align set.Ici_bot Set.Ici_bot @[simp] theorem Icc_bot : Icc ⊥ a = Iic a := by simp [← Ici_inter_Iic] #align set.Icc_bot Set.Icc_bot @[simp] theorem Ico_bot : Ico ⊥ a = Iio a := by simp [← Ici_inter_Iio] #align set.Ico_bot Set.Ico_bot end OrderBot theorem Icc_bot_top [PartialOrder α] [BoundedOrder α] : Icc (⊥ : α) ⊤ = univ := by simp #align set.Icc_bot_top Set.Icc_bot_top section LinearOrder variable [LinearOrder α] {a a₁ a₂ b b₁ b₂ c d : α} theorem not_mem_Ici : c ∉ Ici a ↔ c < a := not_le #align set.not_mem_Ici Set.not_mem_Ici theorem not_mem_Iic : c ∉ Iic b ↔ b < c := not_le #align set.not_mem_Iic Set.not_mem_Iic theorem not_mem_Ioi : c ∉ Ioi a ↔ c ≤ a := not_lt #align set.not_mem_Ioi Set.not_mem_Ioi theorem not_mem_Iio : c ∉ Iio b ↔ b ≤ c := not_lt #align set.not_mem_Iio Set.not_mem_Iio @[simp] theorem compl_Iic : (Iic a)ᶜ = Ioi a := ext fun _ => not_le #align set.compl_Iic Set.compl_Iic @[simp] theorem compl_Ici : (Ici a)ᶜ = Iio a := ext fun _ => not_le #align set.compl_Ici Set.compl_Ici @[simp] theorem compl_Iio : (Iio a)ᶜ = Ici a := ext fun _ => not_lt #align set.compl_Iio Set.compl_Iio @[simp] theorem compl_Ioi : (Ioi a)ᶜ = Iic a := ext fun _ => not_lt #align set.compl_Ioi Set.compl_Ioi @[simp] theorem Ici_diff_Ici : Ici a \ Ici b = Ico a b := by rw [diff_eq, compl_Ici, Ici_inter_Iio] #align set.Ici_diff_Ici Set.Ici_diff_Ici @[simp] theorem Ici_diff_Ioi : Ici a \ Ioi b = Icc a b := by rw [diff_eq, compl_Ioi, Ici_inter_Iic] #align set.Ici_diff_Ioi Set.Ici_diff_Ioi @[simp] theorem Ioi_diff_Ioi : Ioi a \ Ioi b = Ioc a b := by rw [diff_eq, compl_Ioi, Ioi_inter_Iic] #align set.Ioi_diff_Ioi Set.Ioi_diff_Ioi @[simp] theorem Ioi_diff_Ici : Ioi a \ Ici b = Ioo a b := by rw [diff_eq, compl_Ici, Ioi_inter_Iio] #align set.Ioi_diff_Ici Set.Ioi_diff_Ici @[simp] theorem Iic_diff_Iic : Iic b \ Iic a = Ioc a b := by rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iic] #align set.Iic_diff_Iic Set.Iic_diff_Iic @[simp]
Mathlib/Order/Interval/Set/Basic.lean
1,137
1,138
theorem Iio_diff_Iic : Iio b \ Iic a = Ioo a b := by
rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iio]
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Scott Morrison, Jakob von Raumer, Joël Riou -/ import Mathlib.CategoryTheory.Preadditive.ProjectiveResolution import Mathlib.Algebra.Homology.HomotopyCategory import Mathlib.Tactic.SuppressCompilation /-! # Abelian categories with enough projectives have projective resolutions ## Main results When the underlying category is abelian: * `CategoryTheory.ProjectiveResolution.lift`: Given `P : ProjectiveResolution X` and `Q : ProjectiveResolution Y`, any morphism `X ⟶ Y` admits a lifting to a chain map `P.complex ⟶ Q.complex`. It is a lifting in the sense that `P.ι` intertwines the lift and the original morphism, see `CategoryTheory.ProjectiveResolution.lift_commutes`. * `CategoryTheory.ProjectiveResolution.liftHomotopy`: Any two such descents are homotopic. * `CategoryTheory.ProjectiveResolution.homotopyEquiv`: Any two projective resolutions of the same object are homotopy equivalent. * `CategoryTheory.projectiveResolutions`: If every object admits a projective resolution, we can construct a functor `projectiveResolutions C : C ⥤ HomotopyCategory C (ComplexShape.down ℕ)`. * `CategoryTheory.exact_d_f`: `Projective.d f` and `f` are exact. * `CategoryTheory.ProjectiveResolution.of`: Hence, starting from an epimorphism `P ⟶ X`, where `P` is projective, we can apply `Projective.d` repeatedly to obtain a projective resolution of `X`. -/ suppress_compilation noncomputable section universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] open Category Limits Projective set_option linter.uppercaseLean3 false -- `ProjectiveResolution` namespace ProjectiveResolution section variable [HasZeroObject C] [HasZeroMorphisms C] /-- Auxiliary construction for `lift`. -/ def liftFZero {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) : P.complex.X 0 ⟶ Q.complex.X 0 := Projective.factorThru (P.π.f 0 ≫ f) (Q.π.f 0) #align category_theory.ProjectiveResolution.lift_f_zero CategoryTheory.ProjectiveResolution.liftFZero end section Abelian variable [Abelian C] lemma exact₀ {Z : C} (P : ProjectiveResolution Z) : (ShortComplex.mk _ _ P.complex_d_comp_π_f_zero).Exact := ShortComplex.exact_of_g_is_cokernel _ P.isColimitCokernelCofork /-- Auxiliary construction for `lift`. -/ def liftFOne {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) : P.complex.X 1 ⟶ Q.complex.X 1 := Q.exact₀.liftFromProjective (P.complex.d 1 0 ≫ liftFZero f P Q) (by simp [liftFZero]) #align category_theory.ProjectiveResolution.lift_f_one CategoryTheory.ProjectiveResolution.liftFOne @[simp] theorem liftFOne_zero_comm {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) : liftFOne f P Q ≫ Q.complex.d 1 0 = P.complex.d 1 0 ≫ liftFZero f P Q := by apply Q.exact₀.liftFromProjective_comp #align category_theory.ProjectiveResolution.lift_f_one_zero_comm CategoryTheory.ProjectiveResolution.liftFOne_zero_comm /-- Auxiliary construction for `lift`. -/ def liftFSucc {Y Z : C} (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) (n : ℕ) (g : P.complex.X n ⟶ Q.complex.X n) (g' : P.complex.X (n + 1) ⟶ Q.complex.X (n + 1)) (w : g' ≫ Q.complex.d (n + 1) n = P.complex.d (n + 1) n ≫ g) : Σ'g'' : P.complex.X (n + 2) ⟶ Q.complex.X (n + 2), g'' ≫ Q.complex.d (n + 2) (n + 1) = P.complex.d (n + 2) (n + 1) ≫ g' := ⟨(Q.exact_succ n).liftFromProjective (P.complex.d (n + 2) (n + 1) ≫ g') (by simp [w]), (Q.exact_succ n).liftFromProjective_comp _ _⟩ #align category_theory.ProjectiveResolution.lift_f_succ CategoryTheory.ProjectiveResolution.liftFSucc /-- A morphism in `C` lift to a chain map between projective resolutions. -/ def lift {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) : P.complex ⟶ Q.complex := ChainComplex.mkHom _ _ (liftFZero f _ _) (liftFOne f _ _) (liftFOne_zero_comm f P Q) fun n ⟨g, g', w⟩ => ⟨(liftFSucc P Q n g g' w).1, (liftFSucc P Q n g g' w).2⟩ #align category_theory.ProjectiveResolution.lift CategoryTheory.ProjectiveResolution.lift /-- The resolution maps intertwine the lift of a morphism and that morphism. -/ @[reassoc (attr := simp)] theorem lift_commutes {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) : lift f P Q ≫ Q.π = P.π ≫ (ChainComplex.single₀ C).map f := by ext simp [lift, liftFZero, liftFOne] #align category_theory.ProjectiveResolution.lift_commutes CategoryTheory.ProjectiveResolution.lift_commutes @[reassoc (attr := simp)] lemma lift_commutes_zero {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) : (lift f P Q).f 0 ≫ Q.π.f 0 = P.π.f 0 ≫ f := (HomologicalComplex.congr_hom (lift_commutes f P Q) 0).trans (by simp) /-- An auxiliary definition for `liftHomotopyZero`. -/ def liftHomotopyZeroZero {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z} (f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) : P.complex.X 0 ⟶ Q.complex.X 1 := Q.exact₀.liftFromProjective (f.f 0) (congr_fun (congr_arg HomologicalComplex.Hom.f comm) 0) #align category_theory.ProjectiveResolution.lift_homotopy_zero_zero CategoryTheory.ProjectiveResolution.liftHomotopyZeroZero @[reassoc (attr := simp)] lemma liftHomotopyZeroZero_comp {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z} (f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) : liftHomotopyZeroZero f comm ≫ Q.complex.d 1 0 = f.f 0 := Q.exact₀.liftFromProjective_comp _ _ /-- An auxiliary definition for `liftHomotopyZero`. -/ def liftHomotopyZeroOne {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z} (f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) : P.complex.X 1 ⟶ Q.complex.X 2 := (Q.exact_succ 0).liftFromProjective (f.f 1 - P.complex.d 1 0 ≫ liftHomotopyZeroZero f comm) (by rw [Preadditive.sub_comp, assoc, HomologicalComplex.Hom.comm, liftHomotopyZeroZero_comp, sub_self]) #align category_theory.ProjectiveResolution.lift_homotopy_zero_one CategoryTheory.ProjectiveResolution.liftHomotopyZeroOne @[reassoc (attr := simp)] lemma liftHomotopyZeroOne_comp {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z} (f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) : liftHomotopyZeroOne f comm ≫ Q.complex.d 2 1 = f.f 1 - P.complex.d 1 0 ≫ liftHomotopyZeroZero f comm := (Q.exact_succ 0).liftFromProjective_comp _ _ /-- An auxiliary definition for `liftHomotopyZero`. -/ def liftHomotopyZeroSucc {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z} (f : P.complex ⟶ Q.complex) (n : ℕ) (g : P.complex.X n ⟶ Q.complex.X (n + 1)) (g' : P.complex.X (n + 1) ⟶ Q.complex.X (n + 2)) (w : f.f (n + 1) = P.complex.d (n + 1) n ≫ g + g' ≫ Q.complex.d (n + 2) (n + 1)) : P.complex.X (n + 2) ⟶ Q.complex.X (n + 3) := (Q.exact_succ (n + 1)).liftFromProjective (f.f (n + 2) - P.complex.d _ _ ≫ g') (by simp [w]) #align category_theory.ProjectiveResolution.lift_homotopy_zero_succ CategoryTheory.ProjectiveResolution.liftHomotopyZeroSucc @[reassoc (attr := simp)] lemma liftHomotopyZeroSucc_comp {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z} (f : P.complex ⟶ Q.complex) (n : ℕ) (g : P.complex.X n ⟶ Q.complex.X (n + 1)) (g' : P.complex.X (n + 1) ⟶ Q.complex.X (n + 2)) (w : f.f (n + 1) = P.complex.d (n + 1) n ≫ g + g' ≫ Q.complex.d (n + 2) (n + 1)) : liftHomotopyZeroSucc f n g g' w ≫ Q.complex.d (n + 3) (n + 2) = f.f (n + 2) - P.complex.d _ _ ≫ g' := (Q.exact_succ (n+1)).liftFromProjective_comp _ _ /-- Any lift of the zero morphism is homotopic to zero. -/ def liftHomotopyZero {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z} (f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) : Homotopy f 0 := Homotopy.mkInductive _ (liftHomotopyZeroZero f comm) (by simp ) (liftHomotopyZeroOne f comm) (by simp) fun n ⟨g, g', w⟩ => ⟨liftHomotopyZeroSucc f n g g' w, by simp⟩ #align category_theory.ProjectiveResolution.lift_homotopy_zero CategoryTheory.ProjectiveResolution.liftHomotopyZero /-- Two lifts of the same morphism are homotopic. -/ def liftHomotopy {Y Z : C} (f : Y ⟶ Z) {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z} (g h : P.complex ⟶ Q.complex) (g_comm : g ≫ Q.π = P.π ≫ (ChainComplex.single₀ C).map f) (h_comm : h ≫ Q.π = P.π ≫ (ChainComplex.single₀ C).map f) : Homotopy g h := Homotopy.equivSubZero.invFun (liftHomotopyZero _ (by simp [g_comm, h_comm])) #align category_theory.ProjectiveResolution.lift_homotopy CategoryTheory.ProjectiveResolution.liftHomotopy /-- The lift of the identity morphism is homotopic to the identity chain map. -/ def liftIdHomotopy (X : C) (P : ProjectiveResolution X) : Homotopy (lift (𝟙 X) P P) (𝟙 P.complex) := by apply liftHomotopy (𝟙 X) <;> simp #align category_theory.ProjectiveResolution.lift_id_homotopy CategoryTheory.ProjectiveResolution.liftIdHomotopy /-- The lift of a composition is homotopic to the composition of the lifts. -/ def liftCompHomotopy {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (P : ProjectiveResolution X) (Q : ProjectiveResolution Y) (R : ProjectiveResolution Z) : Homotopy (lift (f ≫ g) P R) (lift f P Q ≫ lift g Q R) := by apply liftHomotopy (f ≫ g) <;> simp #align category_theory.ProjectiveResolution.lift_comp_homotopy CategoryTheory.ProjectiveResolution.liftCompHomotopy -- We don't care about the actual definitions of these homotopies. /-- Any two projective resolutions are homotopy equivalent. -/ def homotopyEquiv {X : C} (P Q : ProjectiveResolution X) : HomotopyEquiv P.complex Q.complex where hom := lift (𝟙 X) P Q inv := lift (𝟙 X) Q P homotopyHomInvId := (liftCompHomotopy (𝟙 X) (𝟙 X) P Q P).symm.trans <| by simpa [id_comp] using liftIdHomotopy _ _ homotopyInvHomId := (liftCompHomotopy (𝟙 X) (𝟙 X) Q P Q).symm.trans <| by simpa [id_comp] using liftIdHomotopy _ _ #align category_theory.ProjectiveResolution.homotopy_equiv CategoryTheory.ProjectiveResolution.homotopyEquiv @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Abelian/ProjectiveResolution.lean
198
199
theorem homotopyEquiv_hom_π {X : C} (P Q : ProjectiveResolution X) : (homotopyEquiv P Q).hom ≫ Q.π = P.π := by
simp [homotopyEquiv]
/- 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, Heather Macbeth -/ import Mathlib.Geometry.Manifold.VectorBundle.Basic import Mathlib.Analysis.Convex.Normed #align_import geometry.manifold.vector_bundle.tangent from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833" /-! # Tangent bundles This file defines the tangent bundle as a smooth vector bundle. Let `M` be a smooth manifold with corners with model `I` on `(E, H)`. We define the tangent bundle of `M` using the `VectorBundleCore` construction indexed by the charts of `M` with fibers `E`. Given two charts `i, j : PartialHomeomorph M H`, the coordinate change between `i` and `j` at a point `x : M` is the derivative of the composite ``` I.symm i.symm j I E -----> H -----> M --> H --> E ``` within the set `range I ⊆ E` at `I (i x) : E`. This defines a smooth vector bundle `TangentBundle` with fibers `TangentSpace`. ## Main definitions * `TangentSpace I M x` is the fiber of the tangent bundle at `x : M`, which is defined to be `E`. * `TangentBundle I M` is the total space of `TangentSpace I M`, proven to be a smooth vector bundle. -/ open Bundle Set SmoothManifoldWithCorners PartialHomeomorph ContinuousLinearMap open scoped Manifold Topology Bundle noncomputable section section General variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [SmoothManifoldWithCorners I M] {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] [SmoothManifoldWithCorners I' M'] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable (I) /-- Auxiliary lemma for tangent spaces: the derivative of a coordinate change between two charts is smooth on its source. -/ theorem contDiffOn_fderiv_coord_change (i j : atlas H M) : ContDiffOn 𝕜 ∞ (fderivWithin 𝕜 (j.1.extend I ∘ (i.1.extend I).symm) (range I)) ((i.1.extend I).symm ≫ j.1.extend I).source := by have h : ((i.1.extend I).symm ≫ j.1.extend I).source ⊆ range I := by rw [i.1.extend_coord_change_source]; apply image_subset_range intro x hx refine (ContDiffWithinAt.fderivWithin_right ?_ I.unique_diff le_top <| h hx).mono h refine (PartialHomeomorph.contDiffOn_extend_coord_change I (subset_maximalAtlas I j.2) (subset_maximalAtlas I i.2) x hx).mono_of_mem ?_ exact i.1.extend_coord_change_source_mem_nhdsWithin j.1 I hx #align cont_diff_on_fderiv_coord_change contDiffOn_fderiv_coord_change variable (M) open SmoothManifoldWithCorners /-- Let `M` be a smooth manifold with corners with model `I` on `(E, H)`. Then `VectorBundleCore I M` is the vector bundle core for the tangent bundle over `M`. It is indexed by the atlas of `M`, with fiber `E` and its change of coordinates from the chart `i` to the chart `j` at point `x : M` is the derivative of the composite ``` I.symm i.symm j I E -----> H -----> M --> H --> E ``` within the set `range I ⊆ E` at `I (i x) : E`. -/ @[simps indexAt coordChange] def tangentBundleCore : VectorBundleCore 𝕜 M E (atlas H M) where baseSet i := i.1.source isOpen_baseSet i := i.1.open_source indexAt := achart H mem_baseSet_at := mem_chart_source H coordChange i j x := fderivWithin 𝕜 (j.1.extend I ∘ (i.1.extend I).symm) (range I) (i.1.extend I x) coordChange_self i x hx v := by simp only rw [Filter.EventuallyEq.fderivWithin_eq, fderivWithin_id', ContinuousLinearMap.id_apply] · exact I.unique_diff_at_image · filter_upwards [i.1.extend_target_mem_nhdsWithin I hx] with y hy exact (i.1.extend I).right_inv hy · simp_rw [Function.comp_apply, i.1.extend_left_inv I hx] continuousOn_coordChange i j := by refine (contDiffOn_fderiv_coord_change I i j).continuousOn.comp ((i.1.continuousOn_extend I).mono ?_) ?_ · rw [i.1.extend_source]; exact inter_subset_left simp_rw [← i.1.extend_image_source_inter, mapsTo_image] coordChange_comp := by rintro i j k x ⟨⟨hxi, hxj⟩, hxk⟩ v rw [fderivWithin_fderivWithin, Filter.EventuallyEq.fderivWithin_eq] · have := i.1.extend_preimage_mem_nhds I hxi (j.1.extend_source_mem_nhds I hxj) filter_upwards [nhdsWithin_le_nhds this] with y hy simp_rw [Function.comp_apply, (j.1.extend I).left_inv hy] · simp_rw [Function.comp_apply, i.1.extend_left_inv I hxi, j.1.extend_left_inv I hxj] · exact (contDiffWithinAt_extend_coord_change' I (subset_maximalAtlas I k.2) (subset_maximalAtlas I j.2) hxk hxj).differentiableWithinAt le_top · exact (contDiffWithinAt_extend_coord_change' I (subset_maximalAtlas I j.2) (subset_maximalAtlas I i.2) hxj hxi).differentiableWithinAt le_top · intro x _; exact mem_range_self _ · exact I.unique_diff_at_image · rw [Function.comp_apply, i.1.extend_left_inv I hxi] #align tangent_bundle_core tangentBundleCore -- Porting note: moved to a separate `simp high` lemma b/c `simp` can simplify the LHS @[simp high] theorem tangentBundleCore_baseSet (i) : (tangentBundleCore I M).baseSet i = i.1.source := rfl variable {M} theorem tangentBundleCore_coordChange_achart (x x' z : M) : (tangentBundleCore I M).coordChange (achart H x) (achart H x') z = fderivWithin 𝕜 (extChartAt I x' ∘ (extChartAt I x).symm) (range I) (extChartAt I x z) := rfl #align tangent_bundle_core_coord_change_achart tangentBundleCore_coordChange_achart section tangentCoordChange /-- In a manifold `M`, given two preferred charts indexed by `x y : M`, `tangentCoordChange I x y` is the family of derivatives of the corresponding change-of-coordinates map. It takes junk values outside the intersection of the sources of the two charts. Note that this definition takes advantage of the fact that `tangentBundleCore` has the same base sets as the preferred charts of the base manifold. -/ abbrev tangentCoordChange (x y : M) : M → E →L[𝕜] E := (tangentBundleCore I M).coordChange (achart H x) (achart H y) variable {I} lemma tangentCoordChange_def {x y z : M} : tangentCoordChange I x y z = fderivWithin 𝕜 (extChartAt I y ∘ (extChartAt I x).symm) (range I) (extChartAt I x z) := rfl lemma tangentCoordChange_self {x z : M} {v : E} (h : z ∈ (extChartAt I x).source) : tangentCoordChange I x x z v = v := by apply (tangentBundleCore I M).coordChange_self rw [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I] exact h lemma tangentCoordChange_comp {w x y z : M} {v : E} (h : z ∈ (extChartAt I w).source ∩ (extChartAt I x).source ∩ (extChartAt I y).source) : tangentCoordChange I x y z (tangentCoordChange I w x z v) = tangentCoordChange I w y z v := by apply (tangentBundleCore I M).coordChange_comp simp only [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I] exact h lemma hasFDerivWithinAt_tangentCoordChange {x y z : M} (h : z ∈ (extChartAt I x).source ∩ (extChartAt I y).source) : HasFDerivWithinAt ((extChartAt I y) ∘ (extChartAt I x).symm) (tangentCoordChange I x y z) (range I) (extChartAt I x z) := have h' : extChartAt I x z ∈ ((extChartAt I x).symm ≫ (extChartAt I y)).source := by rw [PartialEquiv.trans_source'', PartialEquiv.symm_symm, PartialEquiv.symm_target] exact mem_image_of_mem _ h ((contDiffWithinAt_ext_coord_change I y x h').differentiableWithinAt (by simp)).hasFDerivWithinAt lemma continuousOn_tangentCoordChange (x y : M) : ContinuousOn (tangentCoordChange I x y) ((extChartAt I x).source ∩ (extChartAt I y).source) := by convert (tangentBundleCore I M).continuousOn_coordChange (achart H x) (achart H y) <;> simp only [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I] end tangentCoordChange /-- The tangent space at a point of the manifold `M`. It is just `E`. We could use instead `(tangentBundleCore I M).to_topological_vector_bundle_core.fiber x`, but we use `E` to help the kernel. -/ @[nolint unusedArguments] def TangentSpace {𝕜} [NontriviallyNormedField 𝕜] {E} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M} [TopologicalSpace M] [ChartedSpace H M] [SmoothManifoldWithCorners I M] (_x : M) : Type* := E -- Porting note: was deriving TopologicalSpace, AddCommGroup, TopologicalAddGroup #align tangent_space TangentSpace instance {x : M} : TopologicalSpace (TangentSpace I x) := inferInstanceAs (TopologicalSpace E) instance {x : M} : AddCommGroup (TangentSpace I x) := inferInstanceAs (AddCommGroup E) instance {x : M} : TopologicalAddGroup (TangentSpace I x) := inferInstanceAs (TopologicalAddGroup E) variable (M) -- is empty if the base manifold is empty /-- The tangent bundle to a smooth manifold, as a Sigma type. Defined in terms of `Bundle.TotalSpace` to be able to put a suitable topology on it. -/ -- Porting note(#5171): was nolint has_nonempty_instance abbrev TangentBundle := Bundle.TotalSpace E (TangentSpace I : M → Type _) #align tangent_bundle TangentBundle local notation "TM" => TangentBundle I M section TangentBundleInstances /- In general, the definition of `TangentSpace` is not reducible, so that type class inference does not pick wrong instances. In this section, we record the right instances for them, noting in particular that the tangent bundle is a smooth manifold. -/ section variable {M} (x : M) instance : Module 𝕜 (TangentSpace I x) := inferInstanceAs (Module 𝕜 E) instance : Inhabited (TangentSpace I x) := ⟨0⟩ -- Porting note: removed unneeded ContinuousAdd (TangentSpace I x) end instance : TopologicalSpace TM := (tangentBundleCore I M).toTopologicalSpace instance TangentSpace.fiberBundle : FiberBundle E (TangentSpace I : M → Type _) := (tangentBundleCore I M).fiberBundle instance TangentSpace.vectorBundle : VectorBundle 𝕜 E (TangentSpace I : M → Type _) := (tangentBundleCore I M).vectorBundle namespace TangentBundle protected theorem chartAt (p : TM) : chartAt (ModelProd H E) p = ((tangentBundleCore I M).toFiberBundleCore.localTriv (achart H p.1)).toPartialHomeomorph ≫ₕ (chartAt H p.1).prod (PartialHomeomorph.refl E) := rfl #align tangent_bundle.chart_at TangentBundle.chartAt theorem chartAt_toPartialEquiv (p : TM) : (chartAt (ModelProd H E) p).toPartialEquiv = (tangentBundleCore I M).toFiberBundleCore.localTrivAsPartialEquiv (achart H p.1) ≫ (chartAt H p.1).toPartialEquiv.prod (PartialEquiv.refl E) := rfl #align tangent_bundle.chart_at_to_local_equiv TangentBundle.chartAt_toPartialEquiv theorem trivializationAt_eq_localTriv (x : M) : trivializationAt E (TangentSpace I) x = (tangentBundleCore I M).toFiberBundleCore.localTriv (achart H x) := rfl #align tangent_bundle.trivialization_at_eq_local_triv TangentBundle.trivializationAt_eq_localTriv @[simp, mfld_simps] theorem trivializationAt_source (x : M) : (trivializationAt E (TangentSpace I) x).source = π E (TangentSpace I) ⁻¹' (chartAt H x).source := rfl #align tangent_bundle.trivialization_at_source TangentBundle.trivializationAt_source @[simp, mfld_simps] theorem trivializationAt_target (x : M) : (trivializationAt E (TangentSpace I) x).target = (chartAt H x).source ×ˢ univ := rfl #align tangent_bundle.trivialization_at_target TangentBundle.trivializationAt_target @[simp, mfld_simps] theorem trivializationAt_baseSet (x : M) : (trivializationAt E (TangentSpace I) x).baseSet = (chartAt H x).source := rfl #align tangent_bundle.trivialization_at_base_set TangentBundle.trivializationAt_baseSet theorem trivializationAt_apply (x : M) (z : TM) : trivializationAt E (TangentSpace I) x z = (z.1, fderivWithin 𝕜 ((chartAt H x).extend I ∘ ((chartAt H z.1).extend I).symm) (range I) ((chartAt H z.1).extend I z.1) z.2) := rfl #align tangent_bundle.trivialization_at_apply TangentBundle.trivializationAt_apply @[simp, mfld_simps] theorem trivializationAt_fst (x : M) (z : TM) : (trivializationAt E (TangentSpace I) x z).1 = z.1 := rfl #align tangent_bundle.trivialization_at_fst TangentBundle.trivializationAt_fst @[simp, mfld_simps] theorem mem_chart_source_iff (p q : TM) : p ∈ (chartAt (ModelProd H E) q).source ↔ p.1 ∈ (chartAt H q.1).source := by simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] #align tangent_bundle.mem_chart_source_iff TangentBundle.mem_chart_source_iff @[simp, mfld_simps] theorem mem_chart_target_iff (p : H × E) (q : TM) : p ∈ (chartAt (ModelProd H E) q).target ↔ p.1 ∈ (chartAt H q.1).target := by /- porting note: was simp (config := { contextual := true }) only [FiberBundle.chartedSpace_chartAt, and_iff_left_iff_imp, mfld_simps] -/ simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] rw [PartialEquiv.prod_symm] simp (config := { contextual := true }) only [and_iff_left_iff_imp, mfld_simps] #align tangent_bundle.mem_chart_target_iff TangentBundle.mem_chart_target_iff @[simp, mfld_simps] theorem coe_chartAt_fst (p q : TM) : ((chartAt (ModelProd H E) q) p).1 = chartAt H q.1 p.1 := rfl #align tangent_bundle.coe_chart_at_fst TangentBundle.coe_chartAt_fst @[simp, mfld_simps] theorem coe_chartAt_symm_fst (p : H × E) (q : TM) : ((chartAt (ModelProd H E) q).symm p).1 = ((chartAt H q.1).symm : H → M) p.1 := rfl #align tangent_bundle.coe_chart_at_symm_fst TangentBundle.coe_chartAt_symm_fst @[simp, mfld_simps] theorem trivializationAt_continuousLinearMapAt {b₀ b : M} (hb : b ∈ (trivializationAt E (TangentSpace I) b₀).baseSet) : (trivializationAt E (TangentSpace I) b₀).continuousLinearMapAt 𝕜 b = (tangentBundleCore I M).coordChange (achart H b) (achart H b₀) b := (tangentBundleCore I M).localTriv_continuousLinearMapAt hb #align tangent_bundle.trivialization_at_continuous_linear_map_at TangentBundle.trivializationAt_continuousLinearMapAt @[simp, mfld_simps] theorem trivializationAt_symmL {b₀ b : M} (hb : b ∈ (trivializationAt E (TangentSpace I) b₀).baseSet) : (trivializationAt E (TangentSpace I) b₀).symmL 𝕜 b = (tangentBundleCore I M).coordChange (achart H b₀) (achart H b) b := (tangentBundleCore I M).localTriv_symmL hb set_option linter.uppercaseLean3 false in #align tangent_bundle.trivialization_at_symmL TangentBundle.trivializationAt_symmL -- Porting note: `simp` simplifies LHS to `.id _ _` @[simp high, mfld_simps] theorem coordChange_model_space (b b' x : F) : (tangentBundleCore 𝓘(𝕜, F) F).coordChange (achart F b) (achart F b') x = 1 := by simpa only [tangentBundleCore_coordChange, mfld_simps] using fderivWithin_id uniqueDiffWithinAt_univ #align tangent_bundle.coord_change_model_space TangentBundle.coordChange_model_space -- Porting note: `simp` simplifies LHS to `.id _ _` @[simp high, mfld_simps] theorem symmL_model_space (b b' : F) : (trivializationAt F (TangentSpace 𝓘(𝕜, F)) b).symmL 𝕜 b' = (1 : F →L[𝕜] F) := by rw [TangentBundle.trivializationAt_symmL, coordChange_model_space] apply mem_univ set_option linter.uppercaseLean3 false in #align tangent_bundle.symmL_model_space TangentBundle.symmL_model_space -- Porting note: `simp` simplifies LHS to `.id _ _` @[simp high, mfld_simps] theorem continuousLinearMapAt_model_space (b b' : F) : (trivializationAt F (TangentSpace 𝓘(𝕜, F)) b).continuousLinearMapAt 𝕜 b' = (1 : F →L[𝕜] F) := by rw [TangentBundle.trivializationAt_continuousLinearMapAt, coordChange_model_space] apply mem_univ #align tangent_bundle.continuous_linear_map_at_model_space TangentBundle.continuousLinearMapAt_model_space end TangentBundle instance tangentBundleCore.isSmooth : (tangentBundleCore I M).IsSmooth I := by refine ⟨fun i j => ?_⟩ rw [SmoothOn, contMDiffOn_iff_source_of_mem_maximalAtlas (subset_maximalAtlas I i.2), contMDiffOn_iff_contDiffOn] · refine ((contDiffOn_fderiv_coord_change I i j).congr fun x hx => ?_).mono ?_ · rw [PartialEquiv.trans_source'] at hx simp_rw [Function.comp_apply, tangentBundleCore_coordChange, (i.1.extend I).right_inv hx.1] · exact (i.1.extend_image_source_inter j.1 I).subset · apply inter_subset_left #align tangent_bundle_core.is_smooth tangentBundleCore.isSmooth instance TangentBundle.smoothVectorBundle : SmoothVectorBundle E (TangentSpace I : M → Type _) I := (tangentBundleCore I M).smoothVectorBundle _ #align tangent_bundle.smooth_vector_bundle TangentBundle.smoothVectorBundle end TangentBundleInstances /-! ## The tangent bundle to the model space -/ /-- In the tangent bundle to the model space, the charts are just the canonical identification between a product type and a sigma type, a.k.a. `TotalSpace.toProd`. -/ @[simp, mfld_simps] theorem tangentBundle_model_space_chartAt (p : TangentBundle I H) : (chartAt (ModelProd H E) p).toPartialEquiv = (TotalSpace.toProd H E).toPartialEquiv := by ext x : 1 · ext; · rfl exact (tangentBundleCore I H).coordChange_self (achart _ x.1) x.1 (mem_achart_source H x.1) x.2 · ext; · rfl apply heq_of_eq exact (tangentBundleCore I H).coordChange_self (achart _ x.1) x.1 (mem_achart_source H x.1) x.2 simp_rw [TangentBundle.chartAt, FiberBundleCore.localTriv, FiberBundleCore.localTrivAsPartialEquiv, VectorBundleCore.toFiberBundleCore_baseSet, tangentBundleCore_baseSet] simp only [mfld_simps] #align tangent_bundle_model_space_chart_at tangentBundle_model_space_chartAt @[simp, mfld_simps] theorem tangentBundle_model_space_coe_chartAt (p : TangentBundle I H) : ⇑(chartAt (ModelProd H E) p) = TotalSpace.toProd H E := by rw [← PartialHomeomorph.coe_coe, tangentBundle_model_space_chartAt]; rfl #align tangent_bundle_model_space_coe_chart_at tangentBundle_model_space_coe_chartAt @[simp, mfld_simps]
Mathlib/Geometry/Manifold/VectorBundle/Tangent.lean
395
399
theorem tangentBundle_model_space_coe_chartAt_symm (p : TangentBundle I H) : ((chartAt (ModelProd H E) p).symm : ModelProd H E → TangentBundle I H) = (TotalSpace.toProd H E).symm := by
rw [← PartialHomeomorph.coe_coe, PartialHomeomorph.symm_toPartialEquiv, tangentBundle_model_space_chartAt]; rfl
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.RatFunc.Defs import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Content #align_import field_theory.ratfunc from "leanprover-community/mathlib"@"bf9bbbcf0c1c1ead18280b0d010e417b10abb1b6" /-! # The field structure of rational functions ## Main definitions Working with rational functions as polynomials: - `RatFunc.instField` provides a field structure You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials: * `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions * `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`, in particular: * `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`. Working with rational functions as fractions: - `RatFunc.num` and `RatFunc.denom` give the numerator and denominator. These values are chosen to be coprime and such that `RatFunc.denom` is monic. Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long as the homomorphism retains the non-zero-divisor property: - `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]` - `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`, where `[CommRing K] [Field L]` - `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`, where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]` This is satisfied by injective homs. We also have lifting homomorphisms of polynomials to other polynomials, with the same condition on retaining the non-zero-divisor property across the map: - `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when `[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]` -/ universe u v noncomputable section open scoped Classical open scoped nonZeroDivisors Polynomial variable {K : Type u} namespace RatFunc section Field variable [CommRing K] /-- The zero rational function. -/ protected irreducible_def zero : RatFunc K := ⟨0⟩ #align ratfunc.zero RatFunc.zero instance : Zero (RatFunc K) := ⟨RatFunc.zero⟩ -- Porting note: added `OfNat.ofNat`. using `simp?` produces `simp only [zero_def]` -- that does not close the goal theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 := by simp only [Zero.zero, OfNat.ofNat, RatFunc.zero] #align ratfunc.of_fraction_ring_zero RatFunc.ofFractionRing_zero /-- Addition of rational functions. -/ protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p + q⟩ #align ratfunc.add RatFunc.add instance : Add (RatFunc K) := ⟨RatFunc.add⟩ -- Porting note: added `HAdd.hAdd`. using `simp?` produces `simp only [add_def]` -- that does not close the goal theorem ofFractionRing_add (p q : FractionRing K[X]) : ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q := by simp only [HAdd.hAdd, Add.add, RatFunc.add] #align ratfunc.of_fraction_ring_add RatFunc.ofFractionRing_add /-- Subtraction of rational functions. -/ protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p - q⟩ #align ratfunc.sub RatFunc.sub instance : Sub (RatFunc K) := ⟨RatFunc.sub⟩ -- Porting note: added `HSub.hSub`. using `simp?` produces `simp only [sub_def]` -- that does not close the goal theorem ofFractionRing_sub (p q : FractionRing K[X]) : ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q := by simp only [Sub.sub, HSub.hSub, RatFunc.sub] #align ratfunc.of_fraction_ring_sub RatFunc.ofFractionRing_sub /-- Additive inverse of a rational function. -/ protected irreducible_def neg : RatFunc K → RatFunc K | ⟨p⟩ => ⟨-p⟩ #align ratfunc.neg RatFunc.neg instance : Neg (RatFunc K) := ⟨RatFunc.neg⟩ theorem ofFractionRing_neg (p : FractionRing K[X]) : ofFractionRing (-p) = -ofFractionRing p := by simp only [Neg.neg, RatFunc.neg] #align ratfunc.of_fraction_ring_neg RatFunc.ofFractionRing_neg /-- The multiplicative unit of rational functions. -/ protected irreducible_def one : RatFunc K := ⟨1⟩ #align ratfunc.one RatFunc.one instance : One (RatFunc K) := ⟨RatFunc.one⟩ -- Porting note: added `OfNat.ofNat`. using `simp?` produces `simp only [one_def]` -- that does not close the goal theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 := by simp only [One.one, OfNat.ofNat, RatFunc.one] #align ratfunc.of_fraction_ring_one RatFunc.ofFractionRing_one /-- Multiplication of rational functions. -/ protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p * q⟩ #align ratfunc.mul RatFunc.mul instance : Mul (RatFunc K) := ⟨RatFunc.mul⟩ -- Porting note: added `HMul.hMul`. using `simp?` produces `simp only [mul_def]` -- that does not close the goal theorem ofFractionRing_mul (p q : FractionRing K[X]) : ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q := by simp only [Mul.mul, HMul.hMul, RatFunc.mul] #align ratfunc.of_fraction_ring_mul RatFunc.ofFractionRing_mul section IsDomain variable [IsDomain K] /-- Division of rational functions. -/ protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p / q⟩ #align ratfunc.div RatFunc.div instance : Div (RatFunc K) := ⟨RatFunc.div⟩ -- Porting note: added `HDiv.hDiv`. using `simp?` produces `simp only [div_def]` -- that does not close the goal theorem ofFractionRing_div (p q : FractionRing K[X]) : ofFractionRing (p / q) = ofFractionRing p / ofFractionRing q := by simp only [Div.div, HDiv.hDiv, RatFunc.div] #align ratfunc.of_fraction_ring_div RatFunc.ofFractionRing_div /-- Multiplicative inverse of a rational function. -/ protected irreducible_def inv : RatFunc K → RatFunc K | ⟨p⟩ => ⟨p⁻¹⟩ #align ratfunc.inv RatFunc.inv instance : Inv (RatFunc K) := ⟨RatFunc.inv⟩ theorem ofFractionRing_inv (p : FractionRing K[X]) : ofFractionRing p⁻¹ = (ofFractionRing p)⁻¹ := by simp only [Inv.inv, RatFunc.inv] #align ratfunc.of_fraction_ring_inv RatFunc.ofFractionRing_inv -- Auxiliary lemma for the `Field` instance theorem mul_inv_cancel : ∀ {p : RatFunc K}, p ≠ 0 → p * p⁻¹ = 1 | ⟨p⟩, h => by have : p ≠ 0 := fun hp => h <| by rw [hp, ofFractionRing_zero] simpa only [← ofFractionRing_inv, ← ofFractionRing_mul, ← ofFractionRing_one, ofFractionRing.injEq] using -- Porting note: `ofFractionRing.injEq` was not present _root_.mul_inv_cancel this #align ratfunc.mul_inv_cancel RatFunc.mul_inv_cancel end IsDomain section SMul variable {R : Type*} /-- Scalar multiplication of rational functions. -/ protected irreducible_def smul [SMul R (FractionRing K[X])] : R → RatFunc K → RatFunc K | r, ⟨p⟩ => ⟨r • p⟩ #align ratfunc.smul RatFunc.smul -- cannot reproduce --@[nolint fails_quickly] -- Porting note: `linter 'fails_quickly' not found` instance [SMul R (FractionRing K[X])] : SMul R (RatFunc K) := ⟨RatFunc.smul⟩ -- Porting note: added `SMul.hSMul`. using `simp?` produces `simp only [smul_def]` -- that does not close the goal theorem ofFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : FractionRing K[X]) : ofFractionRing (c • p) = c • ofFractionRing p := by simp only [SMul.smul, HSMul.hSMul, RatFunc.smul] #align ratfunc.of_fraction_ring_smul RatFunc.ofFractionRing_smul theorem toFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : RatFunc K) : toFractionRing (c • p) = c • toFractionRing p := by cases p rw [← ofFractionRing_smul] #align ratfunc.to_fraction_ring_smul RatFunc.toFractionRing_smul theorem smul_eq_C_smul (x : RatFunc K) (r : K) : r • x = Polynomial.C r • x := by cases' x with x -- Porting note: had to specify the induction principle manually induction x using Localization.induction_on rw [← ofFractionRing_smul, ← ofFractionRing_smul, Localization.smul_mk, Localization.smul_mk, smul_eq_mul, Polynomial.smul_eq_C_mul] set_option linter.uppercaseLean3 false in #align ratfunc.smul_eq_C_smul RatFunc.smul_eq_C_smul section IsDomain variable [IsDomain K] variable [Monoid R] [DistribMulAction R K[X]] variable [IsScalarTower R K[X] K[X]]
Mathlib/FieldTheory/RatFunc/Basic.lean
235
239
theorem mk_smul (c : R) (p q : K[X]) : RatFunc.mk (c • p) q = c • RatFunc.mk p q := by
by_cases hq : q = 0 · rw [hq, mk_zero, mk_zero, ← ofFractionRing_smul, smul_zero] · rw [mk_eq_localization_mk _ hq, mk_eq_localization_mk _ hq, ← Localization.smul_mk, ← ofFractionRing_smul]
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, Frédéric Dupuis -/ import Mathlib.Analysis.InnerProductSpace.Calculus import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.Adjoint import Mathlib.Analysis.Calculus.LagrangeMultipliers import Mathlib.LinearAlgebra.Eigenspace.Basic #align_import analysis.inner_product_space.rayleigh from "leanprover-community/mathlib"@"6b0169218d01f2837d79ea2784882009a0da1aa1" /-! # The Rayleigh quotient The Rayleigh quotient of a self-adjoint operator `T` on an inner product space `E` is the function `fun x ↦ ⟪T x, x⟫ / ‖x‖ ^ 2`. The main results of this file are `IsSelfAdjoint.hasEigenvector_of_isMaxOn` and `IsSelfAdjoint.hasEigenvector_of_isMinOn`, which state that if `E` is complete, and if the Rayleigh quotient attains its global maximum/minimum over some sphere at the point `x₀`, then `x₀` is an eigenvector of `T`, and the `iSup`/`iInf` of `fun x ↦ ⟪T x, x⟫ / ‖x‖ ^ 2` is the corresponding eigenvalue. The corollaries `LinearMap.IsSymmetric.hasEigenvalue_iSup_of_finiteDimensional` and `LinearMap.IsSymmetric.hasEigenvalue_iSup_of_finiteDimensional` state that if `E` is finite-dimensional and nontrivial, then `T` has some (nonzero) eigenvectors with eigenvalue the `iSup`/`iInf` of `fun x ↦ ⟪T x, x⟫ / ‖x‖ ^ 2`. ## TODO A slightly more elaborate corollary is that if `E` is complete and `T` is a compact operator, then `T` has some (nonzero) eigenvector with eigenvalue either `⨆ x, ⟪T x, x⟫ / ‖x‖ ^ 2` or `⨅ x, ⟪T x, x⟫ / ‖x‖ ^ 2` (not necessarily both). -/ variable {𝕜 : Type*} [RCLike 𝕜] variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y open scoped NNReal open Module.End Metric namespace ContinuousLinearMap variable (T : E →L[𝕜] E) /-- The *Rayleigh quotient* of a continuous linear map `T` (over `ℝ` or `ℂ`) at a vector `x` is the quantity `re ⟪T x, x⟫ / ‖x‖ ^ 2`. -/ noncomputable abbrev rayleighQuotient (x : E) := T.reApplyInnerSelf x / ‖(x : E)‖ ^ 2 theorem rayleigh_smul (x : E) {c : 𝕜} (hc : c ≠ 0) : rayleighQuotient T (c • x) = rayleighQuotient T x := by by_cases hx : x = 0 · simp [hx] have : ‖c‖ ≠ 0 := by simp [hc] have : ‖x‖ ≠ 0 := by simp [hx] field_simp [norm_smul, T.reApplyInnerSelf_smul] ring #align continuous_linear_map.rayleigh_smul ContinuousLinearMap.rayleigh_smul theorem image_rayleigh_eq_image_rayleigh_sphere {r : ℝ} (hr : 0 < r) : rayleighQuotient T '' {0}ᶜ = rayleighQuotient T '' sphere 0 r := by ext a constructor · rintro ⟨x, hx : x ≠ 0, hxT⟩ have : ‖x‖ ≠ 0 := by simp [hx] let c : 𝕜 := ↑‖x‖⁻¹ * r have : c ≠ 0 := by simp [c, hx, hr.ne'] refine ⟨c • x, ?_, ?_⟩ · field_simp [c, norm_smul, abs_of_pos hr] · rw [T.rayleigh_smul x this] exact hxT · rintro ⟨x, hx, hxT⟩ exact ⟨x, ne_zero_of_mem_sphere hr.ne' ⟨x, hx⟩, hxT⟩ #align continuous_linear_map.image_rayleigh_eq_image_rayleigh_sphere ContinuousLinearMap.image_rayleigh_eq_image_rayleigh_sphere theorem iSup_rayleigh_eq_iSup_rayleigh_sphere {r : ℝ} (hr : 0 < r) : ⨆ x : { x : E // x ≠ 0 }, rayleighQuotient T x = ⨆ x : sphere (0 : E) r, rayleighQuotient T x := show ⨆ x : ({0}ᶜ : Set E), rayleighQuotient T x = _ by simp only [← @sSup_image' _ _ _ _ (rayleighQuotient T), T.image_rayleigh_eq_image_rayleigh_sphere hr] #align continuous_linear_map.supr_rayleigh_eq_supr_rayleigh_sphere ContinuousLinearMap.iSup_rayleigh_eq_iSup_rayleigh_sphere theorem iInf_rayleigh_eq_iInf_rayleigh_sphere {r : ℝ} (hr : 0 < r) : ⨅ x : { x : E // x ≠ 0 }, rayleighQuotient T x = ⨅ x : sphere (0 : E) r, rayleighQuotient T x := show ⨅ x : ({0}ᶜ : Set E), rayleighQuotient T x = _ by simp only [← @sInf_image' _ _ _ _ (rayleighQuotient T), T.image_rayleigh_eq_image_rayleigh_sphere hr] #align continuous_linear_map.infi_rayleigh_eq_infi_rayleigh_sphere ContinuousLinearMap.iInf_rayleigh_eq_iInf_rayleigh_sphere end ContinuousLinearMap namespace IsSelfAdjoint section Real variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] theorem _root_.LinearMap.IsSymmetric.hasStrictFDerivAt_reApplyInnerSelf {T : F →L[ℝ] F} (hT : (T : F →ₗ[ℝ] F).IsSymmetric) (x₀ : F) : HasStrictFDerivAt T.reApplyInnerSelf (2 • (innerSL ℝ (T x₀))) x₀ := by convert T.hasStrictFDerivAt.inner ℝ (hasStrictFDerivAt_id x₀) using 1 ext y rw [ContinuousLinearMap.smul_apply, ContinuousLinearMap.comp_apply, fderivInnerCLM_apply, ContinuousLinearMap.prod_apply, innerSL_apply, id, ContinuousLinearMap.id_apply, hT.apply_clm x₀ y, real_inner_comm _ x₀, two_smul] #align linear_map.is_symmetric.has_strict_fderiv_at_re_apply_inner_self LinearMap.IsSymmetric.hasStrictFDerivAt_reApplyInnerSelf variable [CompleteSpace F] {T : F →L[ℝ] F} theorem linearly_dependent_of_isLocalExtrOn (hT : IsSelfAdjoint T) {x₀ : F} (hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : F) ‖x₀‖) x₀) : ∃ a b : ℝ, (a, b) ≠ 0 ∧ a • x₀ + b • T x₀ = 0 := by have H : IsLocalExtrOn T.reApplyInnerSelf {x : F | ‖x‖ ^ 2 = ‖x₀‖ ^ 2} x₀ := by convert hextr ext x simp [dist_eq_norm] -- find Lagrange multipliers for the function `T.re_apply_inner_self` and the -- hypersurface-defining function `fun x ↦ ‖x‖ ^ 2` obtain ⟨a, b, h₁, h₂⟩ := IsLocalExtrOn.exists_multipliers_of_hasStrictFDerivAt_1d H (hasStrictFDerivAt_norm_sq x₀) (hT.isSymmetric.hasStrictFDerivAt_reApplyInnerSelf x₀) refine ⟨a, b, h₁, ?_⟩ apply (InnerProductSpace.toDualMap ℝ F).injective simp only [LinearIsometry.map_add, LinearIsometry.map_smul, LinearIsometry.map_zero] -- Note: #8386 changed `map_smulₛₗ` into `map_smulₛₗ _` simp only [map_smulₛₗ _, RCLike.conj_to_real] change a • innerSL ℝ x₀ + b • innerSL ℝ (T x₀) = 0 apply smul_right_injective (F →L[ℝ] ℝ) (two_ne_zero : (2 : ℝ) ≠ 0) simpa only [two_smul, smul_add, add_smul, add_zero] using h₂ #align is_self_adjoint.linearly_dependent_of_is_local_extr_on IsSelfAdjoint.linearly_dependent_of_isLocalExtrOn theorem eq_smul_self_of_isLocalExtrOn_real (hT : IsSelfAdjoint T) {x₀ : F} (hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : F) ‖x₀‖) x₀) : T x₀ = T.rayleighQuotient x₀ • x₀ := by obtain ⟨a, b, h₁, h₂⟩ := hT.linearly_dependent_of_isLocalExtrOn hextr by_cases hx₀ : x₀ = 0 · simp [hx₀] by_cases hb : b = 0 · have : a ≠ 0 := by simpa [hb] using h₁ refine absurd ?_ hx₀ apply smul_right_injective F this simpa [hb] using h₂ let c : ℝ := -b⁻¹ * a have hc : T x₀ = c • x₀ := by have : b * (b⁻¹ * a) = a := by field_simp [mul_comm] apply smul_right_injective F hb simp [c, eq_neg_of_add_eq_zero_left h₂, ← mul_smul, this] convert hc have : ‖x₀‖ ≠ 0 := by simp [hx₀] have := congr_arg (fun x => ⟪x, x₀⟫_ℝ) hc field_simp [inner_smul_left, real_inner_self_eq_norm_mul_norm, sq] at this ⊢ exact this #align is_self_adjoint.eq_smul_self_of_is_local_extr_on_real IsSelfAdjoint.eq_smul_self_of_isLocalExtrOn_real end Real section CompleteSpace variable [CompleteSpace E] {T : E →L[𝕜] E} theorem eq_smul_self_of_isLocalExtrOn (hT : IsSelfAdjoint T) {x₀ : E} (hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) : T x₀ = (↑(T.rayleighQuotient x₀) : 𝕜) • x₀ := by letI := InnerProductSpace.rclikeToReal 𝕜 E let hSA := hT.isSymmetric.restrictScalars.toSelfAdjoint.prop exact hSA.eq_smul_self_of_isLocalExtrOn_real hextr #align is_self_adjoint.eq_smul_self_of_is_local_extr_on IsSelfAdjoint.eq_smul_self_of_isLocalExtrOn /-- For a self-adjoint operator `T`, a local extremum of the Rayleigh quotient of `T` on a sphere centred at the origin is an eigenvector of `T`. -/ theorem hasEigenvector_of_isLocalExtrOn (hT : IsSelfAdjoint T) {x₀ : E} (hx₀ : x₀ ≠ 0) (hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) : HasEigenvector (T : E →ₗ[𝕜] E) (↑(T.rayleighQuotient x₀)) x₀ := by refine ⟨?_, hx₀⟩ rw [Module.End.mem_eigenspace_iff] exact hT.eq_smul_self_of_isLocalExtrOn hextr #align is_self_adjoint.has_eigenvector_of_is_local_extr_on IsSelfAdjoint.hasEigenvector_of_isLocalExtrOn /-- For a self-adjoint operator `T`, a maximum of the Rayleigh quotient of `T` on a sphere centred at the origin is an eigenvector of `T`, with eigenvalue the global supremum of the Rayleigh quotient. -/ theorem hasEigenvector_of_isMaxOn (hT : IsSelfAdjoint T) {x₀ : E} (hx₀ : x₀ ≠ 0) (hextr : IsMaxOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) : HasEigenvector (T : E →ₗ[𝕜] E) (↑(⨆ x : { x : E // x ≠ 0 }, T.rayleighQuotient x)) x₀ := by convert hT.hasEigenvector_of_isLocalExtrOn hx₀ (Or.inr hextr.localize) have hx₀' : 0 < ‖x₀‖ := by simp [hx₀] have hx₀'' : x₀ ∈ sphere (0 : E) ‖x₀‖ := by simp rw [T.iSup_rayleigh_eq_iSup_rayleigh_sphere hx₀'] refine IsMaxOn.iSup_eq hx₀'' ?_ intro x hx dsimp have : ‖x‖ = ‖x₀‖ := by simpa using hx simp only [ContinuousLinearMap.rayleighQuotient] rw [this] gcongr exact hextr hx #align is_self_adjoint.has_eigenvector_of_is_max_on IsSelfAdjoint.hasEigenvector_of_isMaxOn /-- For a self-adjoint operator `T`, a minimum of the Rayleigh quotient of `T` on a sphere centred at the origin is an eigenvector of `T`, with eigenvalue the global infimum of the Rayleigh quotient. -/
Mathlib/Analysis/InnerProductSpace/Rayleigh.lean
211
225
theorem hasEigenvector_of_isMinOn (hT : IsSelfAdjoint T) {x₀ : E} (hx₀ : x₀ ≠ 0) (hextr : IsMinOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) : HasEigenvector (T : E →ₗ[𝕜] E) (↑(⨅ x : { x : E // x ≠ 0 }, T.rayleighQuotient x)) x₀ := by
convert hT.hasEigenvector_of_isLocalExtrOn hx₀ (Or.inl hextr.localize) have hx₀' : 0 < ‖x₀‖ := by simp [hx₀] have hx₀'' : x₀ ∈ sphere (0 : E) ‖x₀‖ := by simp rw [T.iInf_rayleigh_eq_iInf_rayleigh_sphere hx₀'] refine IsMinOn.iInf_eq hx₀'' ?_ intro x hx dsimp have : ‖x‖ = ‖x₀‖ := by simpa using hx simp only [ContinuousLinearMap.rayleighQuotient] rw [this] gcongr exact hextr hx
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Scott Morrison -/ import Mathlib.Algebra.Module.Torsion import Mathlib.SetTheory.Cardinal.Cofinality import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Dimension.StrongRankCondition #align_import linear_algebra.dimension from "leanprover-community/mathlib"@"47a5f8186becdbc826190ced4312f8199f9db6a5" /-! # Conditions for rank to be finite Also contains characterization for when rank equals zero or rank equals one. -/ noncomputable section universe u v v' w variable {R : Type u} {M M₁ : Type v} {M' : Type v'} {ι : Type w} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] [Module R M'] [Module R M₁] attribute [local instance] nontrivial_of_invariantBasisNumber open Cardinal Basis Submodule Function Set FiniteDimensional theorem rank_le {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : Module.rank R M ≤ n := by rw [Module.rank_def] apply ciSup_le' rintro ⟨s, li⟩ exact linearIndependent_bounded_of_finset_linearIndependent_bounded H _ li #align rank_le rank_le section RankZero /-- See `rank_zero_iff` for a stronger version with `NoZeroSMulDivisor R M`. -/ lemma rank_eq_zero_iff : Module.rank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by nontriviality R constructor · contrapose! rintro ⟨x, hx⟩ rw [← Cardinal.one_le_iff_ne_zero] have : LinearIndependent R (fun _ : Unit ↦ x) := linearIndependent_iff.mpr (fun l hl ↦ Finsupp.unique_ext <| not_not.mp fun H ↦ hx _ H ((Finsupp.total_unique _ _ _).symm.trans hl)) simpa using this.cardinal_lift_le_rank · intro h rw [← le_zero_iff, Module.rank_def] apply ciSup_le' intro ⟨s, hs⟩ rw [nonpos_iff_eq_zero, Cardinal.mk_eq_zero_iff, ← not_nonempty_iff] rintro ⟨i : s⟩ obtain ⟨a, ha, ha'⟩ := h i apply ha simpa using DFunLike.congr_fun (linearIndependent_iff.mp hs (Finsupp.single i a) (by simpa)) i variable [Nontrivial R] variable [NoZeroSMulDivisors R M] theorem rank_zero_iff_forall_zero : Module.rank R M = 0 ↔ ∀ x : M, x = 0 := by simp_rw [rank_eq_zero_iff, smul_eq_zero, and_or_left, not_and_self_iff, false_or, exists_and_right, and_iff_right (exists_ne (0 : R))] #align rank_zero_iff_forall_zero rank_zero_iff_forall_zero /-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. Also see `rank_eq_zero_iff` for the version without `NoZeroSMulDivisor R M`. -/ theorem rank_zero_iff : Module.rank R M = 0 ↔ Subsingleton M := rank_zero_iff_forall_zero.trans (subsingleton_iff_forall_eq 0).symm #align rank_zero_iff rank_zero_iff theorem rank_pos_iff_exists_ne_zero : 0 < Module.rank R M ↔ ∃ x : M, x ≠ 0 := by rw [← not_iff_not] simpa using rank_zero_iff_forall_zero #align rank_pos_iff_exists_ne_zero rank_pos_iff_exists_ne_zero theorem rank_pos_iff_nontrivial : 0 < Module.rank R M ↔ Nontrivial M := rank_pos_iff_exists_ne_zero.trans (nontrivial_iff_exists_ne 0).symm #align rank_pos_iff_nontrivial rank_pos_iff_nontrivial lemma rank_eq_zero_iff_isTorsion {R M} [CommRing R] [IsDomain R] [AddCommGroup M] [Module R M] : Module.rank R M = 0 ↔ Module.IsTorsion R M := by rw [Module.IsTorsion, rank_eq_zero_iff] simp [mem_nonZeroDivisors_iff_ne_zero] theorem rank_pos [Nontrivial M] : 0 < Module.rank R M := rank_pos_iff_nontrivial.mpr ‹_› #align rank_pos rank_pos variable (R M) /-- See `rank_subsingleton` that assumes `Subsingleton R` instead. -/ theorem rank_subsingleton' [Subsingleton M] : Module.rank R M = 0 := rank_eq_zero_iff.mpr fun _ ↦ ⟨1, one_ne_zero, Subsingleton.elim _ _⟩ @[simp] theorem rank_punit : Module.rank R PUnit = 0 := rank_subsingleton' _ _ #align rank_punit rank_punit @[simp] theorem rank_bot : Module.rank R (⊥ : Submodule R M) = 0 := rank_subsingleton' _ _ #align rank_bot rank_bot variable {R M} theorem exists_mem_ne_zero_of_rank_pos {s : Submodule R M} (h : 0 < Module.rank R s) : ∃ b : M, b ∈ s ∧ b ≠ 0 := exists_mem_ne_zero_of_ne_bot fun eq => by rw [eq, rank_bot] at h; exact lt_irrefl _ h #align exists_mem_ne_zero_of_rank_pos exists_mem_ne_zero_of_rank_pos end RankZero section Finite theorem Module.finite_of_rank_eq_nat [Module.Free R M] {n : ℕ} (h : Module.rank R M = n) : Module.Finite R M := by nontriviality R obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M) have := mk_lt_aleph0_iff.mp <| b.linearIndependent.cardinal_le_rank |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n exact Module.Finite.of_basis b theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) : Module.Finite R M := by nontriviality R rw [rank_zero_iff] at h infer_instance theorem Module.finite_of_rank_eq_one [Module.Free R M] (h : Module.rank R M = 1) : Module.Finite R M := Module.finite_of_rank_eq_nat <| h.trans Nat.cast_one.symm variable [StrongRankCondition R] /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ theorem Basis.nonempty_fintype_index_of_rank_lt_aleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Nonempty (Fintype ι) := by rwa [← Cardinal.lift_lt, ← b.mk_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_lt_aleph0, Cardinal.lt_aleph0_iff_fintype] at h #align basis.nonempty_fintype_index_of_rank_lt_aleph_0 Basis.nonempty_fintype_index_of_rank_lt_aleph0 /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ noncomputable def Basis.fintypeIndexOfRankLtAleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Fintype ι := Classical.choice (b.nonempty_fintype_index_of_rank_lt_aleph0 h) #align basis.fintype_index_of_rank_lt_aleph_0 Basis.fintypeIndexOfRankLtAleph0 /-- If a module has a finite dimension, all bases are indexed by a finite set. -/ theorem Basis.finite_index_of_rank_lt_aleph0 {ι : Type*} {s : Set ι} (b : Basis s R M) (h : Module.rank R M < ℵ₀) : s.Finite := finite_def.2 (b.nonempty_fintype_index_of_rank_lt_aleph0 h) #align basis.finite_index_of_rank_lt_aleph_0 Basis.finite_index_of_rank_lt_aleph0 namespace LinearIndependent theorem cardinal_mk_le_finrank [Module.Finite R M] {ι : Type w} {b : ι → M} (h : LinearIndependent R b) : #ι ≤ finrank R M := by rw [← lift_le.{max v w}] simpa only [← finrank_eq_rank, lift_natCast, lift_le_nat_iff] using h.cardinal_lift_le_rank #align finite_dimensional.cardinal_mk_le_finrank_of_linear_independent LinearIndependent.cardinal_mk_le_finrank theorem fintype_card_le_finrank [Module.Finite R M] {ι : Type*} [Fintype ι] {b : ι → M} (h : LinearIndependent R b) : Fintype.card ι ≤ finrank R M := by simpa using h.cardinal_mk_le_finrank #align finite_dimensional.fintype_card_le_finrank_of_linear_independent LinearIndependent.fintype_card_le_finrank theorem finset_card_le_finrank [Module.Finite R M] {b : Finset M} (h : LinearIndependent R (fun x => x : b → M)) : b.card ≤ finrank R M := by rw [← Fintype.card_coe] exact h.fintype_card_le_finrank #align finite_dimensional.finset_card_le_finrank_of_linear_independent LinearIndependent.finset_card_le_finrank theorem lt_aleph0_of_finite {ι : Type w} [Module.Finite R M] {v : ι → M} (h : LinearIndependent R v) : #ι < ℵ₀ := by apply Cardinal.lift_lt.1 apply lt_of_le_of_lt · apply h.cardinal_lift_le_rank · rw [← finrank_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_natCast] apply Cardinal.nat_lt_aleph0 theorem finite [Module.Finite R M] {ι : Type*} {f : ι → M} (h : LinearIndependent R f) : Finite ι := Cardinal.lt_aleph0_iff_finite.1 <| h.lt_aleph0_of_finite theorem setFinite [Module.Finite R M] {b : Set M} (h : LinearIndependent R fun x : b => (x : M)) : b.Finite := Cardinal.lt_aleph0_iff_set_finite.mp h.lt_aleph0_of_finite #align linear_independent.finite LinearIndependent.setFinite end LinearIndependent @[deprecated (since := "2023-12-27")] alias cardinal_mk_le_finrank_of_linearIndependent := LinearIndependent.cardinal_mk_le_finrank @[deprecated (since := "2023-12-27")] alias fintype_card_le_finrank_of_linearIndependent := LinearIndependent.fintype_card_le_finrank @[deprecated (since := "2023-12-27")] alias finset_card_le_finrank_of_linearIndependent := LinearIndependent.finset_card_le_finrank @[deprecated (since := "2023-12-27")] alias Module.Finite.lt_aleph0_of_linearIndependent := LinearIndependent.lt_aleph0_of_finite lemma exists_set_linearIndependent_of_lt_rank {n : Cardinal} (hn : n < Module.rank R M) : ∃ s : Set M, #s = n ∧ LinearIndependent R ((↑) : s → M) := by obtain ⟨⟨s, hs⟩, hs'⟩ := exists_lt_of_lt_ciSup' (hn.trans_eq (Module.rank_def R M)) obtain ⟨t, ht, ht'⟩ := le_mk_iff_exists_subset.mp hs'.le exact ⟨t, ht', .mono ht hs⟩ lemma exists_finset_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) : ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := by have := nonempty_linearIndependent_set cases' hn.eq_or_lt with h h · obtain ⟨⟨s, hs⟩, hs'⟩ := Cardinal.exists_eq_natCast_of_iSup_eq _ (Cardinal.bddAbove_range.{v, v} _) _ (h.trans (Module.rank_def R M)).symm have : Finite s := lt_aleph0_iff_finite.mp (hs' ▸ nat_lt_aleph0 n) cases nonempty_fintype s exact ⟨s.toFinset, by simpa using hs', by convert hs <;> exact Set.mem_toFinset⟩ · obtain ⟨s, hs, hs'⟩ := exists_set_linearIndependent_of_lt_rank h have : Finite s := lt_aleph0_iff_finite.mp (hs ▸ nat_lt_aleph0 n) cases nonempty_fintype s exact ⟨s.toFinset, by simpa using hs, by convert hs' <;> exact Set.mem_toFinset⟩ lemma exists_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) : ∃ f : Fin n → M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_rank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ lemma natCast_le_rank_iff {n : ℕ} : n ≤ Module.rank R M ↔ ∃ f : Fin n → M, LinearIndependent R f := ⟨exists_linearIndependent_of_le_rank, fun H ↦ by simpa using H.choose_spec.cardinal_lift_le_rank⟩ lemma natCast_le_rank_iff_finset {n : ℕ} : n ≤ Module.rank R M ↔ ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := ⟨exists_finset_linearIndependent_of_le_rank, fun ⟨s, h₁, h₂⟩ ↦ by simpa [h₁] using h₂.cardinal_le_rank⟩ lemma exists_finset_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) : ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := by by_cases h : finrank R M = 0 · rw [le_zero_iff.mp (hn.trans_eq h)] exact ⟨∅, rfl, by convert linearIndependent_empty R M using 2 <;> aesop⟩ exact exists_finset_linearIndependent_of_le_rank ((natCast_le.mpr hn).trans_eq (cast_toNat_of_lt_aleph0 (toNat_ne_zero.mp h).2)) lemma exists_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) : ∃ f : Fin n → M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_finrank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ variable [Module.Finite R M] theorem Module.Finite.not_linearIndependent_of_infinite {ι : Type*} [Infinite ι] (v : ι → M) : ¬LinearIndependent R v := mt LinearIndependent.finite <| @not_finite _ _ #align finite_dimensional.not_linear_independent_of_infinite Module.Finite.not_linearIndependent_of_infinite variable [NoZeroSMulDivisors R M] theorem CompleteLattice.Independent.subtype_ne_bot_le_rank [Nontrivial R] {V : ι → Submodule R M} (hV : CompleteLattice.Independent V) : Cardinal.lift.{v} #{ i : ι // V i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) := by set I := { i : ι // V i ≠ ⊥ } have hI : ∀ i : I, ∃ v ∈ V i, v ≠ (0 : M) := by intro i rw [← Submodule.ne_bot_iff] exact i.prop choose v hvV hv using hI have : LinearIndependent R v := (hV.comp Subtype.coe_injective).linearIndependent _ hvV hv exact this.cardinal_lift_le_rank #align complete_lattice.independent.subtype_ne_bot_le_rank CompleteLattice.Independent.subtype_ne_bot_le_rank theorem CompleteLattice.Independent.subtype_ne_bot_le_finrank_aux {p : ι → Submodule R M} (hp : CompleteLattice.Independent p) : #{ i // p i ≠ ⊥ } ≤ (finrank R M : Cardinal.{w}) := by suffices Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{v} (finrank R M : Cardinal.{w}) by rwa [Cardinal.lift_le] at this calc Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) := hp.subtype_ne_bot_le_rank _ = Cardinal.lift.{w} (finrank R M : Cardinal.{v}) := by rw [finrank_eq_rank] _ = Cardinal.lift.{v} (finrank R M : Cardinal.{w}) := by simp #align complete_lattice.independent.subtype_ne_bot_le_finrank_aux CompleteLattice.Independent.subtype_ne_bot_le_finrank_aux /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is finite. -/ noncomputable def CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional {p : ι → Submodule R M} (hp : CompleteLattice.Independent p) : Fintype { i : ι // p i ≠ ⊥ } := by suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by rw [Cardinal.lt_aleph0_iff_fintype] at this exact this.some refine lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux ?_ simp [Cardinal.nat_lt_aleph0] #align complete_lattice.independent.fintype_ne_bot_of_finite_dimensional CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is bounded above by the dimension of `M`. Note that the `Fintype` hypothesis required here can be provided by `CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional`. -/ theorem CompleteLattice.Independent.subtype_ne_bot_le_finrank {p : ι → Submodule R M} (hp : CompleteLattice.Independent p) [Fintype { i // p i ≠ ⊥ }] : Fintype.card { i // p i ≠ ⊥ } ≤ finrank R M := by simpa using hp.subtype_ne_bot_le_finrank_aux #align complete_lattice.independent.subtype_ne_bot_le_finrank CompleteLattice.Independent.subtype_ne_bot_le_finrank section open Finset /-- If a finset has cardinality larger than the rank of a module, then there is a nontrivial linear relation amongst its elements. -/ theorem Module.exists_nontrivial_relation_of_finrank_lt_card {t : Finset M} (h : finrank R M < t.card) : ∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by obtain ⟨g, sum, z, nonzero⟩ := Fintype.not_linearIndependent_iff.mp (mt LinearIndependent.finset_card_le_finrank h.not_le) refine ⟨Subtype.val.extend g 0, ?_, z, z.2, by rwa [Subtype.val_injective.extend_apply]⟩ rw [← Finset.sum_finset_coe]; convert sum; apply Subtype.val_injective.extend_apply #align finite_dimensional.exists_nontrivial_relation_of_rank_lt_card Module.exists_nontrivial_relation_of_finrank_lt_card /-- If a finset has cardinality larger than `finrank + 1`, then there is a nontrivial linear relation amongst its elements, such that the coefficients of the relation sum to zero. -/ theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card {t : Finset M} (h : finrank R M + 1 < t.card) : ∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by -- Pick an element x₀ ∈ t, obtain ⟨x₀, x₀_mem⟩ := card_pos.1 ((Nat.succ_pos _).trans h) -- and apply the previous lemma to the {xᵢ - x₀} let shift : M ↪ M := ⟨(· - x₀), sub_left_injective⟩ classical let t' := (t.erase x₀).map shift have h' : finrank R M < t'.card := by rw [card_map, card_erase_of_mem x₀_mem] exact Nat.lt_pred_iff.mpr h -- to obtain a function `g`. obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h' -- Then obtain `f` by translating back by `x₀`, -- and setting the value of `f` at `x₀` to ensure `∑ e ∈ t, f e = 0`. let f : M → R := fun z ↦ if z = x₀ then -∑ z ∈ t.erase x₀, g (z - x₀) else g (z - x₀) refine ⟨f, ?_, ?_, ?_⟩ -- After this, it's a matter of verifying the properties, -- based on the corresponding properties for `g`. · rw [sum_map, Embedding.coeFn_mk] at gsum simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, neg_smul, sum_smul, ← sub_eq_add_neg, ← sum_sub_distrib, ← gsum, smul_sub] refine sum_congr rfl fun x x_mem ↦ ?_ rw [if_neg (mem_erase.mp x_mem).1] · simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, add_neg_eq_zero] exact sum_congr rfl fun x x_mem ↦ if_neg (mem_erase.mp x_mem).1 · obtain ⟨x₁, x₁_mem', rfl⟩ := Finset.mem_map.mp x₁_mem have := mem_erase.mp x₁_mem' exact ⟨x₁, by simpa only [f, Embedding.coeFn_mk, sub_add_cancel, this.2, true_and, if_neg this.1]⟩ #align finite_dimensional.exists_nontrivial_relation_sum_zero_of_rank_succ_lt_card Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card end end Finite section FinrankZero variable [Nontrivial R] [NoZeroSMulDivisors R M] /-- A finite dimensional space is nontrivial if it has positive `finrank`. -/ theorem FiniteDimensional.nontrivial_of_finrank_pos (h : 0 < finrank R M) : Nontrivial M := rank_pos_iff_nontrivial.mp (lt_rank_of_lt_finrank h) #align finite_dimensional.nontrivial_of_finrank_pos FiniteDimensional.nontrivial_of_finrank_pos /-- A finite dimensional space is nontrivial if it has `finrank` equal to the successor of a natural number. -/ theorem FiniteDimensional.nontrivial_of_finrank_eq_succ {n : ℕ} (hn : finrank R M = n.succ) : Nontrivial M := nontrivial_of_finrank_pos (by rw [hn]; exact n.succ_pos) #align finite_dimensional.nontrivial_of_finrank_eq_succ FiniteDimensional.nontrivial_of_finrank_eq_succ /-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/ @[nontriviality] theorem FiniteDimensional.finrank_zero_of_subsingleton [Subsingleton M] : finrank R M = 0 := by rw [finrank, rank_subsingleton', _root_.map_zero] #align finite_dimensional.finrank_zero_of_subsingleton FiniteDimensional.finrank_zero_of_subsingleton lemma LinearIndependent.finrank_eq_zero_of_infinite {ι} [Nontrivial R] [Infinite ι] {v : ι → M} (hv : LinearIndependent R v) : finrank R M = 0 := toNat_eq_zero.mpr <| .inr hv.aleph0_le_rank variable (R M) @[simp] theorem finrank_bot : finrank R (⊥ : Submodule R M) = 0 := finrank_eq_of_rank_eq (rank_bot _ _) #align finrank_bot finrank_bot variable {R M} section StrongRankCondition variable [StrongRankCondition R] [Module.Finite R M] /-- A finite rank torsion-free module has positive `finrank` iff it has a nonzero element. -/ theorem FiniteDimensional.finrank_pos_iff_exists_ne_zero [NoZeroSMulDivisors R M] : 0 < finrank R M ↔ ∃ x : M, x ≠ 0 := by rw [← @rank_pos_iff_exists_ne_zero R M, ← finrank_eq_rank] norm_cast #align finite_dimensional.finrank_pos_iff_exists_ne_zero FiniteDimensional.finrank_pos_iff_exists_ne_zero /-- An `R`-finite torsion-free module has positive `finrank` iff it is nontrivial. -/ theorem FiniteDimensional.finrank_pos_iff [NoZeroSMulDivisors R M] : 0 < finrank R M ↔ Nontrivial M := by rw [← rank_pos_iff_nontrivial (R := R), ← finrank_eq_rank] norm_cast #align finite_dimensional.finrank_pos_iff FiniteDimensional.finrank_pos_iff /-- A nontrivial finite dimensional space has positive `finrank`. -/ theorem FiniteDimensional.finrank_pos [NoZeroSMulDivisors R M] [h : Nontrivial M] : 0 < finrank R M := finrank_pos_iff.mpr h #align finite_dimensional.finrank_pos FiniteDimensional.finrank_pos /-- See `FiniteDimensional.finrank_zero_iff` for the stronger version with `NoZeroSMulDivisors R M`. -/ theorem FiniteDimensional.finrank_eq_zero_iff : finrank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by rw [← rank_eq_zero_iff (R := R), ← finrank_eq_rank] norm_cast /-- The `StrongRankCondition` is automatic. See `commRing_strongRankCondition`. -/ theorem FiniteDimensional.finrank_eq_zero_iff_isTorsion {R} [CommRing R] [StrongRankCondition R] [IsDomain R] [Module R M] [Module.Finite R M] : finrank R M = 0 ↔ Module.IsTorsion R M := by rw [← rank_eq_zero_iff_isTorsion (R := R), ← finrank_eq_rank] norm_cast /-- A finite dimensional space has zero `finrank` iff it is a subsingleton. This is the `finrank` version of `rank_zero_iff`. -/ theorem FiniteDimensional.finrank_zero_iff [NoZeroSMulDivisors R M] : finrank R M = 0 ↔ Subsingleton M := by rw [← rank_zero_iff (R := R), ← finrank_eq_rank] norm_cast #align finite_dimensional.finrank_zero_iff FiniteDimensional.finrank_zero_iff end StrongRankCondition theorem FiniteDimensional.finrank_eq_zero_of_rank_eq_zero (h : Module.rank R M = 0) : finrank R M = 0 := by delta finrank rw [h, zero_toNat] #align finrank_eq_zero_of_rank_eq_zero FiniteDimensional.finrank_eq_zero_of_rank_eq_zero theorem Submodule.bot_eq_top_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) : (⊥ : Submodule R M) = ⊤ := by nontriviality R rw [rank_zero_iff] at h exact Subsingleton.elim _ _ #align bot_eq_top_of_rank_eq_zero Submodule.bot_eq_top_of_rank_eq_zero /-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. -/ @[simp] theorem Submodule.rank_eq_zero [Nontrivial R] [NoZeroSMulDivisors R M] {S : Submodule R M} : Module.rank R S = 0 ↔ S = ⊥ := ⟨fun h => (Submodule.eq_bot_iff _).2 fun x hx => congr_arg Subtype.val <| ((Submodule.eq_bot_iff _).1 <| Eq.symm <| Submodule.bot_eq_top_of_rank_eq_zero h) ⟨x, hx⟩ Submodule.mem_top, fun h => by rw [h, rank_bot]⟩ #align rank_eq_zero Submodule.rank_eq_zero @[simp]
Mathlib/LinearAlgebra/Dimension/Finite.lean
479
482
theorem Submodule.finrank_eq_zero [StrongRankCondition R] [NoZeroSMulDivisors R M] {S : Submodule R M} [Module.Finite R S] : finrank R S = 0 ↔ S = ⊥ := by
rw [← Submodule.rank_eq_zero, ← finrank_eq_rank, ← @Nat.cast_zero Cardinal, Cardinal.natCast_inj]
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro Coinductive formalization of unbounded computations. -/ import Mathlib.Data.Stream.Init import Mathlib.Tactic.Common #align_import data.seq.computation from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! # Coinductive formalization of unbounded computations. This file provides a `Computation` type where `Computation α` is the type of unbounded computations returning `α`. -/ open Function universe u v w /- coinductive Computation (α : Type u) : Type u | pure : α → Computation α | think : Computation α → Computation α -/ /-- `Computation α` is the type of unbounded computations returning `α`. An element of `Computation α` is an infinite sequence of `Option α` such that if `f n = some a` for some `n` then it is constantly `some a` after that. -/ def Computation (α : Type u) : Type u := { f : Stream' (Option α) // ∀ ⦃n a⦄, f n = some a → f (n + 1) = some a } #align computation Computation namespace Computation variable {α : Type u} {β : Type v} {γ : Type w} -- constructors /-- `pure a` is the computation that immediately terminates with result `a`. -/ -- Porting note: `return` is reserved, so changed to `pure` def pure (a : α) : Computation α := ⟨Stream'.const (some a), fun _ _ => id⟩ #align computation.return Computation.pure instance : CoeTC α (Computation α) := ⟨pure⟩ -- note [use has_coe_t] /-- `think c` is the computation that delays for one "tick" and then performs computation `c`. -/ def think (c : Computation α) : Computation α := ⟨Stream'.cons none c.1, fun n a h => by cases' n with n · contradiction · exact c.2 h⟩ #align computation.think Computation.think /-- `thinkN c n` is the computation that delays for `n` ticks and then performs computation `c`. -/ def thinkN (c : Computation α) : ℕ → Computation α | 0 => c | n + 1 => think (thinkN c n) set_option linter.uppercaseLean3 false in #align computation.thinkN Computation.thinkN -- check for immediate result /-- `head c` is the first step of computation, either `some a` if `c = pure a` or `none` if `c = think c'`. -/ def head (c : Computation α) : Option α := c.1.head #align computation.head Computation.head -- one step of computation /-- `tail c` is the remainder of computation, either `c` if `c = pure a` or `c'` if `c = think c'`. -/ def tail (c : Computation α) : Computation α := ⟨c.1.tail, fun _ _ h => c.2 h⟩ #align computation.tail Computation.tail /-- `empty α` is the computation that never returns, an infinite sequence of `think`s. -/ def empty (α) : Computation α := ⟨Stream'.const none, fun _ _ => id⟩ #align computation.empty Computation.empty instance : Inhabited (Computation α) := ⟨empty _⟩ /-- `runFor c n` evaluates `c` for `n` steps and returns the result, or `none` if it did not terminate after `n` steps. -/ def runFor : Computation α → ℕ → Option α := Subtype.val #align computation.run_for Computation.runFor /-- `destruct c` is the destructor for `Computation α` as a coinductive type. It returns `inl a` if `c = pure a` and `inr c'` if `c = think c'`. -/ def destruct (c : Computation α) : Sum α (Computation α) := match c.1 0 with | none => Sum.inr (tail c) | some a => Sum.inl a #align computation.destruct Computation.destruct /-- `run c` is an unsound meta function that runs `c` to completion, possibly resulting in an infinite loop in the VM. -/ unsafe def run : Computation α → α | c => match destruct c with | Sum.inl a => a | Sum.inr ca => run ca #align computation.run Computation.run theorem destruct_eq_pure {s : Computation α} {a : α} : destruct s = Sum.inl a → s = pure a := by dsimp [destruct] induction' f0 : s.1 0 with _ <;> intro h · contradiction · apply Subtype.eq funext n induction' n with n IH · injection h with h' rwa [h'] at f0 · exact s.2 IH #align computation.destruct_eq_ret Computation.destruct_eq_pure theorem destruct_eq_think {s : Computation α} {s'} : destruct s = Sum.inr s' → s = think s' := by dsimp [destruct] induction' f0 : s.1 0 with a' <;> intro h · injection h with h' rw [← h'] cases' s with f al apply Subtype.eq dsimp [think, tail] rw [← f0] exact (Stream'.eta f).symm · contradiction #align computation.destruct_eq_think Computation.destruct_eq_think @[simp] theorem destruct_pure (a : α) : destruct (pure a) = Sum.inl a := rfl #align computation.destruct_ret Computation.destruct_pure @[simp] theorem destruct_think : ∀ s : Computation α, destruct (think s) = Sum.inr s | ⟨_, _⟩ => rfl #align computation.destruct_think Computation.destruct_think @[simp] theorem destruct_empty : destruct (empty α) = Sum.inr (empty α) := rfl #align computation.destruct_empty Computation.destruct_empty @[simp] theorem head_pure (a : α) : head (pure a) = some a := rfl #align computation.head_ret Computation.head_pure @[simp] theorem head_think (s : Computation α) : head (think s) = none := rfl #align computation.head_think Computation.head_think @[simp] theorem head_empty : head (empty α) = none := rfl #align computation.head_empty Computation.head_empty @[simp] theorem tail_pure (a : α) : tail (pure a) = pure a := rfl #align computation.tail_ret Computation.tail_pure @[simp] theorem tail_think (s : Computation α) : tail (think s) = s := by cases' s with f al; apply Subtype.eq; dsimp [tail, think] #align computation.tail_think Computation.tail_think @[simp] theorem tail_empty : tail (empty α) = empty α := rfl #align computation.tail_empty Computation.tail_empty theorem think_empty : empty α = think (empty α) := destruct_eq_think destruct_empty #align computation.think_empty Computation.think_empty /-- Recursion principle for computations, compare with `List.recOn`. -/ def recOn {C : Computation α → Sort v} (s : Computation α) (h1 : ∀ a, C (pure a)) (h2 : ∀ s, C (think s)) : C s := match H : destruct s with | Sum.inl v => by rw [destruct_eq_pure H] apply h1 | Sum.inr v => match v with | ⟨a, s'⟩ => by rw [destruct_eq_think H] apply h2 #align computation.rec_on Computation.recOn /-- Corecursor constructor for `corec`-/ def Corec.f (f : β → Sum α β) : Sum α β → Option α × Sum α β | Sum.inl a => (some a, Sum.inl a) | Sum.inr b => (match f b with | Sum.inl a => some a | Sum.inr _ => none, f b) set_option linter.uppercaseLean3 false in #align computation.corec.F Computation.Corec.f /-- `corec f b` is the corecursor for `Computation α` as a coinductive type. If `f b = inl a` then `corec f b = pure a`, and if `f b = inl b'` then `corec f b = think (corec f b')`. -/ def corec (f : β → Sum α β) (b : β) : Computation α := by refine ⟨Stream'.corec' (Corec.f f) (Sum.inr b), fun n a' h => ?_⟩ rw [Stream'.corec'_eq] change Stream'.corec' (Corec.f f) (Corec.f f (Sum.inr b)).2 n = some a' revert h; generalize Sum.inr b = o; revert o induction' n with n IH <;> intro o · change (Corec.f f o).1 = some a' → (Corec.f f (Corec.f f o).2).1 = some a' cases' o with _ b <;> intro h · exact h unfold Corec.f at *; split <;> simp_all · rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o] exact IH (Corec.f f o).2 #align computation.corec Computation.corec /-- left map of `⊕` -/ def lmap (f : α → β) : Sum α γ → Sum β γ | Sum.inl a => Sum.inl (f a) | Sum.inr b => Sum.inr b #align computation.lmap Computation.lmap /-- right map of `⊕` -/ def rmap (f : β → γ) : Sum α β → Sum α γ | Sum.inl a => Sum.inl a | Sum.inr b => Sum.inr (f b) #align computation.rmap Computation.rmap attribute [simp] lmap rmap -- Porting note: this was far less painful in mathlib3. There seem to be two issues; -- firstly, in mathlib3 we have `corec.F._match_1` and it's the obvious map α ⊕ β → option α. -- In mathlib4 we have `Corec.f.match_1` and it's something completely different. -- Secondly, the proof that `Stream'.corec' (Corec.f f) (Sum.inr b) 0` is this function -- evaluated at `f b`, used to be `rfl` and now is `cases, rfl`. @[simp] theorem corec_eq (f : β → Sum α β) (b : β) : destruct (corec f b) = rmap (corec f) (f b) := by dsimp [corec, destruct] rw [show Stream'.corec' (Corec.f f) (Sum.inr b) 0 = Sum.rec Option.some (fun _ ↦ none) (f b) by dsimp [Corec.f, Stream'.corec', Stream'.corec, Stream'.map, Stream'.get, Stream'.iterate] match (f b) with | Sum.inl x => rfl | Sum.inr x => rfl ] induction' h : f b with a b'; · rfl dsimp [Corec.f, destruct] apply congr_arg; apply Subtype.eq dsimp [corec, tail] rw [Stream'.corec'_eq, Stream'.tail_cons] dsimp [Corec.f]; rw [h] #align computation.corec_eq Computation.corec_eq section Bisim variable (R : Computation α → Computation α → Prop) /-- bisimilarity relation-/ local infixl:50 " ~ " => R /-- Bisimilarity over a sum of `Computation`s-/ def BisimO : Sum α (Computation α) → Sum α (Computation α) → Prop | Sum.inl a, Sum.inl a' => a = a' | Sum.inr s, Sum.inr s' => R s s' | _, _ => False #align computation.bisim_o Computation.BisimO attribute [simp] BisimO /-- Attribute expressing bisimilarity over two `Computation`s-/ def IsBisimulation := ∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂) #align computation.is_bisimulation Computation.IsBisimulation -- If two computations are bisimilar, then they are equal
Mathlib/Data/Seq/Computation.lean
288
309
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by
apply Subtype.eq apply Stream'.eq_of_bisim fun x y => ∃ s s' : Computation α, s.1 = x ∧ s'.1 = y ∧ R s s' · dsimp [Stream'.IsBisimulation] intro t₁ t₂ e match t₁, t₂, e with | _, _, ⟨s, s', rfl, rfl, r⟩ => suffices head s = head s' ∧ R (tail s) (tail s') from And.imp id (fun r => ⟨tail s, tail s', by cases s; rfl, by cases s'; rfl, r⟩) this have h := bisim r; revert r h apply recOn s _ _ <;> intro r' <;> apply recOn s' _ _ <;> intro a' r h · constructor <;> dsimp at h · rw [h] · rw [h] at r rw [tail_pure, tail_pure,h] assumption · rw [destruct_pure, destruct_think] at h exact False.elim h · rw [destruct_pure, destruct_think] at h exact False.elim h · simp_all · exact ⟨s₁, s₂, rfl, rfl, r⟩
/- 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]`. -/ 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] set_option linter.uppercaseLean3 false in #align polynomial_functions.comap_comp_right_alg_hom_Icc_homeo_I polynomialFunctions.comap_compRightAlgHom_iccHomeoI theorem polynomialFunctions.eq_adjoin_X (s : Set R) : polynomialFunctions s = Algebra.adjoin R {toContinuousMapOnAlgHom s X} := by refine le_antisymm ?_ (Algebra.adjoin_le fun _ h => ⟨X, trivial, (Set.mem_singleton_iff.1 h).symm⟩) rintro - ⟨p, -, rfl⟩ rw [AlgHom.coe_toRingHom] refine p.induction_on (fun r => ?_) (fun f g hf hg => ?_) fun n r hn => ?_ · rw [Polynomial.C_eq_algebraMap, AlgHomClass.commutes] exact Subalgebra.algebraMap_mem _ r · rw [map_add] exact add_mem hf hg · rw [pow_succ, ← mul_assoc, map_mul] exact mul_mem hn (Algebra.subset_adjoin <| Set.mem_singleton _) theorem polynomialFunctions.le_equalizer {A : Type*} [Semiring A] [Algebra R A] (s : Set R) (φ ψ : C(s, R) →ₐ[R] A) (h : φ (toContinuousMapOnAlgHom s X) = ψ (toContinuousMapOnAlgHom s X)) : polynomialFunctions s ≤ φ.equalizer ψ := by rw [polynomialFunctions.eq_adjoin_X s] exact φ.adjoin_le_equalizer ψ fun x hx => (Set.mem_singleton_iff.1 hx).symm ▸ h open StarAlgebra
Mathlib/Topology/ContinuousFunction/Polynomial.lean
242
244
theorem polynomialFunctions.starClosure_eq_adjoin_X [StarRing R] [ContinuousStar R] (s : Set R) : (polynomialFunctions s).starClosure = adjoin R {toContinuousMapOnAlgHom s X} := by
rw [polynomialFunctions.eq_adjoin_X s, adjoin_eq_starClosure_adjoin]
/- 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.Topology.Order.MonotoneContinuity import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.Instances.NNReal import Mathlib.Topology.EMetricSpace.Lipschitz import Mathlib.Topology.Metrizable.Basic import Mathlib.Topology.Order.T5 #align_import topology.instances.ennreal from "leanprover-community/mathlib"@"ec4b2eeb50364487f80421c0b4c41328a611f30d" /-! # Topology on extended non-negative reals -/ noncomputable section open Set Filter Metric Function open scoped Classical Topology ENNReal NNReal Filter variable {α : Type*} {β : Type*} {γ : Type*} namespace ENNReal variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : Set ℝ≥0∞} section TopologicalSpace open TopologicalSpace /-- Topology on `ℝ≥0∞`. Note: this is different from the `EMetricSpace` topology. The `EMetricSpace` topology has `IsOpen {∞}`, while this topology doesn't have singleton elements. -/ instance : TopologicalSpace ℝ≥0∞ := Preorder.topology ℝ≥0∞ instance : OrderTopology ℝ≥0∞ := ⟨rfl⟩ -- short-circuit type class inference instance : T2Space ℝ≥0∞ := inferInstance instance : T5Space ℝ≥0∞ := inferInstance instance : T4Space ℝ≥0∞ := inferInstance instance : SecondCountableTopology ℝ≥0∞ := orderIsoUnitIntervalBirational.toHomeomorph.embedding.secondCountableTopology instance : MetrizableSpace ENNReal := orderIsoUnitIntervalBirational.toHomeomorph.embedding.metrizableSpace theorem embedding_coe : Embedding ((↑) : ℝ≥0 → ℝ≥0∞) := coe_strictMono.embedding_of_ordConnected <| by rw [range_coe']; exact ordConnected_Iio #align ennreal.embedding_coe ENNReal.embedding_coe theorem isOpen_ne_top : IsOpen { a : ℝ≥0∞ | a ≠ ∞ } := isOpen_ne #align ennreal.is_open_ne_top ENNReal.isOpen_ne_top theorem isOpen_Ico_zero : IsOpen (Ico 0 b) := by rw [ENNReal.Ico_eq_Iio] exact isOpen_Iio #align ennreal.is_open_Ico_zero ENNReal.isOpen_Ico_zero theorem openEmbedding_coe : OpenEmbedding ((↑) : ℝ≥0 → ℝ≥0∞) := ⟨embedding_coe, by rw [range_coe']; exact isOpen_Iio⟩ #align ennreal.open_embedding_coe ENNReal.openEmbedding_coe theorem coe_range_mem_nhds : range ((↑) : ℝ≥0 → ℝ≥0∞) ∈ 𝓝 (r : ℝ≥0∞) := IsOpen.mem_nhds openEmbedding_coe.isOpen_range <| mem_range_self _ #align ennreal.coe_range_mem_nhds ENNReal.coe_range_mem_nhds @[norm_cast] theorem tendsto_coe {f : Filter α} {m : α → ℝ≥0} {a : ℝ≥0} : Tendsto (fun a => (m a : ℝ≥0∞)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) := embedding_coe.tendsto_nhds_iff.symm #align ennreal.tendsto_coe ENNReal.tendsto_coe theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ≥0∞) := embedding_coe.continuous #align ennreal.continuous_coe ENNReal.continuous_coe theorem continuous_coe_iff {α} [TopologicalSpace α] {f : α → ℝ≥0} : (Continuous fun a => (f a : ℝ≥0∞)) ↔ Continuous f := embedding_coe.continuous_iff.symm #align ennreal.continuous_coe_iff ENNReal.continuous_coe_iff theorem nhds_coe {r : ℝ≥0} : 𝓝 (r : ℝ≥0∞) = (𝓝 r).map (↑) := (openEmbedding_coe.map_nhds_eq r).symm #align ennreal.nhds_coe ENNReal.nhds_coe theorem tendsto_nhds_coe_iff {α : Type*} {l : Filter α} {x : ℝ≥0} {f : ℝ≥0∞ → α} : Tendsto f (𝓝 ↑x) l ↔ Tendsto (f ∘ (↑) : ℝ≥0 → α) (𝓝 x) l := by rw [nhds_coe, tendsto_map'_iff] #align ennreal.tendsto_nhds_coe_iff ENNReal.tendsto_nhds_coe_iff theorem continuousAt_coe_iff {α : Type*} [TopologicalSpace α] {x : ℝ≥0} {f : ℝ≥0∞ → α} : ContinuousAt f ↑x ↔ ContinuousAt (f ∘ (↑) : ℝ≥0 → α) x := tendsto_nhds_coe_iff #align ennreal.continuous_at_coe_iff ENNReal.continuousAt_coe_iff theorem nhds_coe_coe {r p : ℝ≥0} : 𝓝 ((r : ℝ≥0∞), (p : ℝ≥0∞)) = (𝓝 (r, p)).map fun p : ℝ≥0 × ℝ≥0 => (↑p.1, ↑p.2) := ((openEmbedding_coe.prod openEmbedding_coe).map_nhds_eq (r, p)).symm #align ennreal.nhds_coe_coe ENNReal.nhds_coe_coe theorem continuous_ofReal : Continuous ENNReal.ofReal := (continuous_coe_iff.2 continuous_id).comp continuous_real_toNNReal #align ennreal.continuous_of_real ENNReal.continuous_ofReal theorem tendsto_ofReal {f : Filter α} {m : α → ℝ} {a : ℝ} (h : Tendsto m f (𝓝 a)) : Tendsto (fun a => ENNReal.ofReal (m a)) f (𝓝 (ENNReal.ofReal a)) := (continuous_ofReal.tendsto a).comp h #align ennreal.tendsto_of_real ENNReal.tendsto_ofReal theorem tendsto_toNNReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toNNReal (𝓝 a) (𝓝 a.toNNReal) := by lift a to ℝ≥0 using ha rw [nhds_coe, tendsto_map'_iff] exact tendsto_id #align ennreal.tendsto_to_nnreal ENNReal.tendsto_toNNReal theorem eventuallyEq_of_toReal_eventuallyEq {l : Filter α} {f g : α → ℝ≥0∞} (hfi : ∀ᶠ x in l, f x ≠ ∞) (hgi : ∀ᶠ x in l, g x ≠ ∞) (hfg : (fun x => (f x).toReal) =ᶠ[l] fun x => (g x).toReal) : f =ᶠ[l] g := by filter_upwards [hfi, hgi, hfg] with _ hfx hgx _ rwa [← ENNReal.toReal_eq_toReal hfx hgx] #align ennreal.eventually_eq_of_to_real_eventually_eq ENNReal.eventuallyEq_of_toReal_eventuallyEq theorem continuousOn_toNNReal : ContinuousOn ENNReal.toNNReal { a | a ≠ ∞ } := fun _a ha => ContinuousAt.continuousWithinAt (tendsto_toNNReal ha) #align ennreal.continuous_on_to_nnreal ENNReal.continuousOn_toNNReal theorem tendsto_toReal {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto ENNReal.toReal (𝓝 a) (𝓝 a.toReal) := NNReal.tendsto_coe.2 <| tendsto_toNNReal ha #align ennreal.tendsto_to_real ENNReal.tendsto_toReal lemma continuousOn_toReal : ContinuousOn ENNReal.toReal { a | a ≠ ∞ } := NNReal.continuous_coe.comp_continuousOn continuousOn_toNNReal lemma continuousAt_toReal (hx : x ≠ ∞) : ContinuousAt ENNReal.toReal x := continuousOn_toReal.continuousAt (isOpen_ne_top.mem_nhds_iff.mpr hx) /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def neTopHomeomorphNNReal : { a | a ≠ ∞ } ≃ₜ ℝ≥0 where toEquiv := neTopEquivNNReal continuous_toFun := continuousOn_iff_continuous_restrict.1 continuousOn_toNNReal continuous_invFun := continuous_coe.subtype_mk _ #align ennreal.ne_top_homeomorph_nnreal ENNReal.neTopHomeomorphNNReal /-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/ def ltTopHomeomorphNNReal : { a | a < ∞ } ≃ₜ ℝ≥0 := by refine (Homeomorph.setCongr ?_).trans neTopHomeomorphNNReal simp only [mem_setOf_eq, lt_top_iff_ne_top] #align ennreal.lt_top_homeomorph_nnreal ENNReal.ltTopHomeomorphNNReal theorem nhds_top : 𝓝 ∞ = ⨅ (a) (_ : a ≠ ∞), 𝓟 (Ioi a) := nhds_top_order.trans <| by simp [lt_top_iff_ne_top, Ioi] #align ennreal.nhds_top ENNReal.nhds_top theorem nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi ↑r) := nhds_top.trans <| iInf_ne_top _ #align ennreal.nhds_top' ENNReal.nhds_top' theorem nhds_top_basis : (𝓝 ∞).HasBasis (fun a => a < ∞) fun a => Ioi a := _root_.nhds_top_basis #align ennreal.nhds_top_basis ENNReal.nhds_top_basis theorem tendsto_nhds_top_iff_nnreal {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a := by simp only [nhds_top', tendsto_iInf, tendsto_principal, mem_Ioi] #align ennreal.tendsto_nhds_top_iff_nnreal ENNReal.tendsto_nhds_top_iff_nnreal theorem tendsto_nhds_top_iff_nat {m : α → ℝ≥0∞} {f : Filter α} : Tendsto m f (𝓝 ∞) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a := tendsto_nhds_top_iff_nnreal.trans ⟨fun h n => by simpa only [ENNReal.coe_natCast] using h n, fun h x => let ⟨n, hn⟩ := exists_nat_gt x (h n).mono fun y => lt_trans <| by rwa [← ENNReal.coe_natCast, coe_lt_coe]⟩ #align ennreal.tendsto_nhds_top_iff_nat ENNReal.tendsto_nhds_top_iff_nat theorem tendsto_nhds_top {m : α → ℝ≥0∞} {f : Filter α} (h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : Tendsto m f (𝓝 ∞) := tendsto_nhds_top_iff_nat.2 h #align ennreal.tendsto_nhds_top ENNReal.tendsto_nhds_top theorem tendsto_nat_nhds_top : Tendsto (fun n : ℕ => ↑n) atTop (𝓝 ∞) := tendsto_nhds_top fun n => mem_atTop_sets.2 ⟨n + 1, fun _m hm => mem_setOf.2 <| Nat.cast_lt.2 <| Nat.lt_of_succ_le hm⟩ #align ennreal.tendsto_nat_nhds_top ENNReal.tendsto_nat_nhds_top @[simp, norm_cast] theorem tendsto_coe_nhds_top {f : α → ℝ≥0} {l : Filter α} : Tendsto (fun x => (f x : ℝ≥0∞)) l (𝓝 ∞) ↔ Tendsto f l atTop := by rw [tendsto_nhds_top_iff_nnreal, atTop_basis_Ioi.tendsto_right_iff]; simp #align ennreal.tendsto_coe_nhds_top ENNReal.tendsto_coe_nhds_top theorem tendsto_ofReal_atTop : Tendsto ENNReal.ofReal atTop (𝓝 ∞) := tendsto_coe_nhds_top.2 tendsto_real_toNNReal_atTop #align ennreal.tendsto_of_real_at_top ENNReal.tendsto_ofReal_atTop theorem nhds_zero : 𝓝 (0 : ℝ≥0∞) = ⨅ (a) (_ : a ≠ 0), 𝓟 (Iio a) := nhds_bot_order.trans <| by simp [pos_iff_ne_zero, Iio] #align ennreal.nhds_zero ENNReal.nhds_zero theorem nhds_zero_basis : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) fun a => Iio a := nhds_bot_basis #align ennreal.nhds_zero_basis ENNReal.nhds_zero_basis theorem nhds_zero_basis_Iic : (𝓝 (0 : ℝ≥0∞)).HasBasis (fun a : ℝ≥0∞ => 0 < a) Iic := nhds_bot_basis_Iic #align ennreal.nhds_zero_basis_Iic ENNReal.nhds_zero_basis_Iic -- Porting note (#11215): TODO: add a TC for `≠ ∞`? @[instance] theorem nhdsWithin_Ioi_coe_neBot {r : ℝ≥0} : (𝓝[>] (r : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_self_neBot' ⟨∞, ENNReal.coe_lt_top⟩ #align ennreal.nhds_within_Ioi_coe_ne_bot ENNReal.nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_zero_neBot : (𝓝[>] (0 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot #align ennreal.nhds_within_Ioi_zero_ne_bot ENNReal.nhdsWithin_Ioi_zero_neBot @[instance] theorem nhdsWithin_Ioi_one_neBot : (𝓝[>] (1 : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_nat_neBot (n : ℕ) : (𝓝[>] (n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Ioi_ofNat_nebot (n : ℕ) [n.AtLeastTwo] : (𝓝[>] (OfNat.ofNat n : ℝ≥0∞)).NeBot := nhdsWithin_Ioi_coe_neBot @[instance] theorem nhdsWithin_Iio_neBot [NeZero x] : (𝓝[<] x).NeBot := nhdsWithin_Iio_self_neBot' ⟨0, NeZero.pos x⟩ /-- Closed intervals `Set.Icc (x - ε) (x + ε)`, `ε ≠ 0`, form a basis of neighborhoods of an extended nonnegative real number `x ≠ ∞`. We use `Set.Icc` instead of `Set.Ioo` because this way the statement works for `x = 0`. -/ theorem hasBasis_nhds_of_ne_top' (xt : x ≠ ∞) : (𝓝 x).HasBasis (· ≠ 0) (fun ε => Icc (x - ε) (x + ε)) := by rcases (zero_le x).eq_or_gt with rfl | x0 · simp_rw [zero_tsub, zero_add, ← bot_eq_zero, Icc_bot, ← bot_lt_iff_ne_bot] exact nhds_bot_basis_Iic · refine (nhds_basis_Ioo' ⟨_, x0⟩ ⟨_, xt.lt_top⟩).to_hasBasis ?_ fun ε ε0 => ?_ · rintro ⟨a, b⟩ ⟨ha, hb⟩ rcases exists_between (tsub_pos_of_lt ha) with ⟨ε, ε0, hε⟩ rcases lt_iff_exists_add_pos_lt.1 hb with ⟨δ, δ0, hδ⟩ refine ⟨min ε δ, (lt_min ε0 (coe_pos.2 δ0)).ne', Icc_subset_Ioo ?_ ?_⟩ · exact lt_tsub_comm.2 ((min_le_left _ _).trans_lt hε) · exact (add_le_add_left (min_le_right _ _) _).trans_lt hδ · exact ⟨(x - ε, x + ε), ⟨ENNReal.sub_lt_self xt x0.ne' ε0, lt_add_right xt ε0⟩, Ioo_subset_Icc_self⟩ theorem hasBasis_nhds_of_ne_top (xt : x ≠ ∞) : (𝓝 x).HasBasis (0 < ·) (fun ε => Icc (x - ε) (x + ε)) := by simpa only [pos_iff_ne_zero] using hasBasis_nhds_of_ne_top' xt theorem Icc_mem_nhds (xt : x ≠ ∞) (ε0 : ε ≠ 0) : Icc (x - ε) (x + ε) ∈ 𝓝 x := (hasBasis_nhds_of_ne_top' xt).mem_of_mem ε0 #align ennreal.Icc_mem_nhds ENNReal.Icc_mem_nhds theorem nhds_of_ne_top (xt : x ≠ ∞) : 𝓝 x = ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) := (hasBasis_nhds_of_ne_top xt).eq_biInf #align ennreal.nhds_of_ne_top ENNReal.nhds_of_ne_top theorem biInf_le_nhds : ∀ x : ℝ≥0∞, ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) ≤ 𝓝 x | ∞ => iInf₂_le_of_le 1 one_pos <| by simpa only [← coe_one, top_sub_coe, top_add, Icc_self, principal_singleton] using pure_le_nhds _ | (x : ℝ≥0) => (nhds_of_ne_top coe_ne_top).ge -- Porting note (#10756): new lemma protected theorem tendsto_nhds_of_Icc {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε)) : Tendsto u f (𝓝 a) := by refine Tendsto.mono_right ?_ (biInf_le_nhds _) simpa only [tendsto_iInf, tendsto_principal] /-- Characterization of neighborhoods for `ℝ≥0∞` numbers. See also `tendsto_order` for a version with strict inequalities. -/ protected theorem tendsto_nhds {f : Filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ∈ Icc (a - ε) (a + ε) := by simp only [nhds_of_ne_top ha, tendsto_iInf, tendsto_principal] #align ennreal.tendsto_nhds ENNReal.tendsto_nhds protected theorem tendsto_nhds_zero {f : Filter α} {u : α → ℝ≥0∞} : Tendsto u f (𝓝 0) ↔ ∀ ε > 0, ∀ᶠ x in f, u x ≤ ε := nhds_zero_basis_Iic.tendsto_right_iff #align ennreal.tendsto_nhds_zero ENNReal.tendsto_nhds_zero protected theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ∞) : Tendsto f atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ∈ Icc (a - ε) (a + ε) := .trans (atTop_basis.tendsto_iff (hasBasis_nhds_of_ne_top ha)) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top ENNReal.tendsto_atTop instance : ContinuousAdd ℝ≥0∞ := by refine ⟨continuous_iff_continuousAt.2 ?_⟩ rintro ⟨_ | a, b⟩ · exact tendsto_nhds_top_mono' continuousAt_fst fun p => le_add_right le_rfl rcases b with (_ | b) · exact tendsto_nhds_top_mono' continuousAt_snd fun p => le_add_left le_rfl simp only [ContinuousAt, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (· ∘ ·), tendsto_coe, tendsto_add] protected theorem tendsto_atTop_zero [Nonempty β] [SemilatticeSup β] {f : β → ℝ≥0∞} : Tendsto f atTop (𝓝 0) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ≤ ε := .trans (atTop_basis.tendsto_iff nhds_zero_basis_Iic) (by simp only [true_and]; rfl) #align ennreal.tendsto_at_top_zero ENNReal.tendsto_atTop_zero theorem tendsto_sub : ∀ {a b : ℝ≥0∞}, (a ≠ ∞ ∨ b ≠ ∞) → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) (𝓝 (a, b)) (𝓝 (a - b)) | ∞, ∞, h => by simp only [ne_eq, not_true_eq_false, or_self] at h | ∞, (b : ℝ≥0), _ => by rw [top_sub_coe, tendsto_nhds_top_iff_nnreal] refine fun x => ((lt_mem_nhds <| @coe_lt_top (b + 1 + x)).prod_nhds (ge_mem_nhds <| coe_lt_coe.2 <| lt_add_one b)).mono fun y hy => ?_ rw [lt_tsub_iff_left] calc y.2 + x ≤ ↑(b + 1) + x := add_le_add_right hy.2 _ _ < y.1 := hy.1 | (a : ℝ≥0), ∞, _ => by rw [sub_top] refine (tendsto_pure.2 ?_).mono_right (pure_le_nhds _) exact ((gt_mem_nhds <| coe_lt_coe.2 <| lt_add_one a).prod_nhds (lt_mem_nhds <| @coe_lt_top (a + 1))).mono fun x hx => tsub_eq_zero_iff_le.2 (hx.1.trans hx.2).le | (a : ℝ≥0), (b : ℝ≥0), _ => by simp only [nhds_coe_coe, tendsto_map'_iff, ← ENNReal.coe_sub, (· ∘ ·), tendsto_coe] exact continuous_sub.tendsto (a, b) #align ennreal.tendsto_sub ENNReal.tendsto_sub protected theorem Tendsto.sub {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (hmb : Tendsto mb f (𝓝 b)) (h : a ≠ ∞ ∨ b ≠ ∞) : Tendsto (fun a => ma a - mb a) f (𝓝 (a - b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 - p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a - b)) from Tendsto.comp (ENNReal.tendsto_sub h) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.sub ENNReal.Tendsto.sub protected theorem tendsto_mul (ha : a ≠ 0 ∨ b ≠ ∞) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) := by have ht : ∀ b : ℝ≥0∞, b ≠ 0 → Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) (𝓝 (∞, b)) (𝓝 ∞) := fun b hb => by refine tendsto_nhds_top_iff_nnreal.2 fun n => ?_ rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩ have : ∀ᶠ c : ℝ≥0∞ × ℝ≥0∞ in 𝓝 (∞, b), ↑n / ↑ε < c.1 ∧ ↑ε < c.2 := (lt_mem_nhds <| div_lt_top coe_ne_top hε.ne').prod_nhds (lt_mem_nhds hεb) refine this.mono fun c hc => ?_ exact (ENNReal.div_mul_cancel hε.ne' coe_ne_top).symm.trans_lt (mul_lt_mul hc.1 hc.2) induction a with | top => simp only [ne_eq, or_false, not_true_eq_false] at hb; simp [ht b hb, top_mul hb] | coe a => induction b with | top => simp only [ne_eq, or_false, not_true_eq_false] at ha simpa [(· ∘ ·), mul_comm, mul_top ha] using (ht a ha).comp (continuous_swap.tendsto (ofNNReal a, ∞)) | coe b => simp only [nhds_coe_coe, ← coe_mul, tendsto_coe, tendsto_map'_iff, (· ∘ ·), tendsto_mul] #align ennreal.tendsto_mul ENNReal.tendsto_mul protected theorem Tendsto.mul {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun a => ma a * mb a) f (𝓝 (a * b)) := show Tendsto ((fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 * p.2) ∘ fun a => (ma a, mb a)) f (𝓝 (a * b)) from Tendsto.comp (ENNReal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb) #align ennreal.tendsto.mul ENNReal.Tendsto.mul theorem _root_.ContinuousOn.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h₁ : ∀ x ∈ s, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x ∈ s, g x ≠ 0 ∨ f x ≠ ∞) : ContinuousOn (fun x => f x * g x) s := fun x hx => ENNReal.Tendsto.mul (hf x hx) (h₁ x hx) (hg x hx) (h₂ x hx) #align continuous_on.ennreal_mul ContinuousOn.ennreal_mul theorem _root_.Continuous.ennreal_mul [TopologicalSpace α] {f g : α → ℝ≥0∞} (hf : Continuous f) (hg : Continuous g) (h₁ : ∀ x, f x ≠ 0 ∨ g x ≠ ∞) (h₂ : ∀ x, g x ≠ 0 ∨ f x ≠ ∞) : Continuous fun x => f x * g x := continuous_iff_continuousAt.2 fun x => ENNReal.Tendsto.mul hf.continuousAt (h₁ x) hg.continuousAt (h₂ x) #align continuous.ennreal_mul Continuous.ennreal_mul protected theorem Tendsto.const_mul {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ∞) : Tendsto (fun b => a * m b) f (𝓝 (a * b)) := by_cases (fun (this : a = 0) => by simp [this, tendsto_const_nhds]) fun ha : a ≠ 0 => ENNReal.Tendsto.mul tendsto_const_nhds (Or.inl ha) hm hb #align ennreal.tendsto.const_mul ENNReal.Tendsto.const_mul protected theorem Tendsto.mul_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ∞) : Tendsto (fun x => m x * b) f (𝓝 (a * b)) := by simpa only [mul_comm] using ENNReal.Tendsto.const_mul hm ha #align ennreal.tendsto.mul_const ENNReal.Tendsto.mul_const theorem tendsto_finset_prod_of_ne_top {ι : Type*} {f : ι → α → ℝ≥0∞} {x : Filter α} {a : ι → ℝ≥0∞} (s : Finset ι) (h : ∀ i ∈ s, Tendsto (f i) x (𝓝 (a i))) (h' : ∀ i ∈ s, a i ≠ ∞) : Tendsto (fun b => ∏ c ∈ s, f c b) x (𝓝 (∏ c ∈ s, a c)) := by induction' s using Finset.induction with a s has IH · simp [tendsto_const_nhds] simp only [Finset.prod_insert has] apply Tendsto.mul (h _ (Finset.mem_insert_self _ _)) · right exact (prod_lt_top fun i hi => h' _ (Finset.mem_insert_of_mem hi)).ne · exact IH (fun i hi => h _ (Finset.mem_insert_of_mem hi)) fun i hi => h' _ (Finset.mem_insert_of_mem hi) · exact Or.inr (h' _ (Finset.mem_insert_self _ _)) #align ennreal.tendsto_finset_prod_of_ne_top ENNReal.tendsto_finset_prod_of_ne_top protected theorem continuousAt_const_mul {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (a * ·) b := Tendsto.const_mul tendsto_id h.symm #align ennreal.continuous_at_const_mul ENNReal.continuousAt_const_mul protected theorem continuousAt_mul_const {a b : ℝ≥0∞} (h : a ≠ ∞ ∨ b ≠ 0) : ContinuousAt (fun x => x * a) b := Tendsto.mul_const tendsto_id h.symm #align ennreal.continuous_at_mul_const ENNReal.continuousAt_mul_const protected theorem continuous_const_mul {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous (a * ·) := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_const_mul (Or.inl ha) #align ennreal.continuous_const_mul ENNReal.continuous_const_mul protected theorem continuous_mul_const {a : ℝ≥0∞} (ha : a ≠ ∞) : Continuous fun x => x * a := continuous_iff_continuousAt.2 fun _ => ENNReal.continuousAt_mul_const (Or.inl ha) #align ennreal.continuous_mul_const ENNReal.continuous_mul_const protected theorem continuous_div_const (c : ℝ≥0∞) (c_ne_zero : c ≠ 0) : Continuous fun x : ℝ≥0∞ => x / c := by simp_rw [div_eq_mul_inv, continuous_iff_continuousAt] intro x exact ENNReal.continuousAt_mul_const (Or.intro_left _ (inv_ne_top.mpr c_ne_zero)) #align ennreal.continuous_div_const ENNReal.continuous_div_const @[continuity] theorem continuous_pow (n : ℕ) : Continuous fun a : ℝ≥0∞ => a ^ n := by induction' n with n IH · simp [continuous_const] simp_rw [pow_add, pow_one, continuous_iff_continuousAt] intro x refine ENNReal.Tendsto.mul (IH.tendsto _) ?_ tendsto_id ?_ <;> by_cases H : x = 0 · simp only [H, zero_ne_top, Ne, or_true_iff, not_false_iff] · exact Or.inl fun h => H (pow_eq_zero h) · simp only [H, pow_eq_top_iff, zero_ne_top, false_or_iff, eq_self_iff_true, not_true, Ne, not_false_iff, false_and_iff] · simp only [H, true_or_iff, Ne, not_false_iff] #align ennreal.continuous_pow ENNReal.continuous_pow theorem continuousOn_sub : ContinuousOn (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) { p : ℝ≥0∞ × ℝ≥0∞ | p ≠ ⟨∞, ∞⟩ } := by rw [ContinuousOn] rintro ⟨x, y⟩ hp simp only [Ne, Set.mem_setOf_eq, Prod.mk.inj_iff] at hp exact tendsto_nhdsWithin_of_tendsto_nhds (tendsto_sub (not_and_or.mp hp)) #align ennreal.continuous_on_sub ENNReal.continuousOn_sub theorem continuous_sub_left {a : ℝ≥0∞} (a_ne_top : a ≠ ∞) : Continuous (a - ·) := by change Continuous (Function.uncurry Sub.sub ∘ (a, ·)) refine continuousOn_sub.comp_continuous (Continuous.Prod.mk a) fun x => ?_ simp only [a_ne_top, Ne, mem_setOf_eq, Prod.mk.inj_iff, false_and_iff, not_false_iff] #align ennreal.continuous_sub_left ENNReal.continuous_sub_left theorem continuous_nnreal_sub {a : ℝ≥0} : Continuous fun x : ℝ≥0∞ => (a : ℝ≥0∞) - x := continuous_sub_left coe_ne_top #align ennreal.continuous_nnreal_sub ENNReal.continuous_nnreal_sub theorem continuousOn_sub_left (a : ℝ≥0∞) : ContinuousOn (a - ·) { x : ℝ≥0∞ | x ≠ ∞ } := by rw [show (fun x => a - x) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨a, x⟩ by rfl] apply ContinuousOn.comp continuousOn_sub (Continuous.continuousOn (Continuous.Prod.mk a)) rintro _ h (_ | _) exact h none_eq_top #align ennreal.continuous_on_sub_left ENNReal.continuousOn_sub_left theorem continuous_sub_right (a : ℝ≥0∞) : Continuous fun x : ℝ≥0∞ => x - a := by by_cases a_infty : a = ∞ · simp [a_infty, continuous_const] · rw [show (fun x => x - a) = (fun p : ℝ≥0∞ × ℝ≥0∞ => p.fst - p.snd) ∘ fun x => ⟨x, a⟩ by rfl] apply ContinuousOn.comp_continuous continuousOn_sub (continuous_id'.prod_mk continuous_const) intro x simp only [a_infty, Ne, mem_setOf_eq, Prod.mk.inj_iff, and_false_iff, not_false_iff] #align ennreal.continuous_sub_right ENNReal.continuous_sub_right protected theorem Tendsto.pow {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} {n : ℕ} (hm : Tendsto m f (𝓝 a)) : Tendsto (fun x => m x ^ n) f (𝓝 (a ^ n)) := ((continuous_pow n).tendsto a).comp hm #align ennreal.tendsto.pow ENNReal.Tendsto.pow theorem le_of_forall_lt_one_mul_le {x y : ℝ≥0∞} (h : ∀ a < 1, a * x ≤ y) : x ≤ y := by have : Tendsto (· * x) (𝓝[<] 1) (𝓝 (1 * x)) := (ENNReal.continuousAt_mul_const (Or.inr one_ne_zero)).mono_left inf_le_left rw [one_mul] at this exact le_of_tendsto this (eventually_nhdsWithin_iff.2 <| eventually_of_forall h) #align ennreal.le_of_forall_lt_one_mul_le ENNReal.le_of_forall_lt_one_mul_le theorem iInf_mul_left' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, a * f i = a * ⨅ i, f i := by by_cases H : a = ∞ ∧ ⨅ i, f i = 0 · rcases h H.1 H.2 with ⟨i, hi⟩ rw [H.2, mul_zero, ← bot_eq_zero, iInf_eq_bot] exact fun b hb => ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ · rw [not_and_or] at H cases isEmpty_or_nonempty ι · rw [iInf_of_empty, iInf_of_empty, mul_top] exact mt h0 (not_nonempty_iff.2 ‹_›) · exact (ENNReal.mul_left_mono.map_iInf_of_continuousAt' (ENNReal.continuousAt_const_mul H)).symm #align ennreal.infi_mul_left' ENNReal.iInf_mul_left' theorem iInf_mul_left {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, a * f i = a * ⨅ i, f i := iInf_mul_left' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_left ENNReal.iInf_mul_left theorem iInf_mul_right' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) (h0 : a = 0 → Nonempty ι) : ⨅ i, f i * a = (⨅ i, f i) * a := by simpa only [mul_comm a] using iInf_mul_left' h h0 #align ennreal.infi_mul_right' ENNReal.iInf_mul_right' theorem iInf_mul_right {ι} [Nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞} (h : a = ∞ → ⨅ i, f i = 0 → ∃ i, f i = 0) : ⨅ i, f i * a = (⨅ i, f i) * a := iInf_mul_right' h fun _ => ‹Nonempty ι› #align ennreal.infi_mul_right ENNReal.iInf_mul_right theorem inv_map_iInf {ι : Sort*} {x : ι → ℝ≥0∞} : (iInf x)⁻¹ = ⨆ i, (x i)⁻¹ := OrderIso.invENNReal.map_iInf x #align ennreal.inv_map_infi ENNReal.inv_map_iInf theorem inv_map_iSup {ι : Sort*} {x : ι → ℝ≥0∞} : (iSup x)⁻¹ = ⨅ i, (x i)⁻¹ := OrderIso.invENNReal.map_iSup x #align ennreal.inv_map_supr ENNReal.inv_map_iSup theorem inv_limsup {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (limsup x l)⁻¹ = liminf (fun i => (x i)⁻¹) l := OrderIso.invENNReal.limsup_apply #align ennreal.inv_limsup ENNReal.inv_limsup theorem inv_liminf {ι : Sort _} {x : ι → ℝ≥0∞} {l : Filter ι} : (liminf x l)⁻¹ = limsup (fun i => (x i)⁻¹) l := OrderIso.invENNReal.liminf_apply #align ennreal.inv_liminf ENNReal.inv_liminf instance : ContinuousInv ℝ≥0∞ := ⟨OrderIso.invENNReal.continuous⟩ @[simp] -- Porting note (#11215): TODO: generalize to `[InvolutiveInv _] [ContinuousInv _]` protected theorem tendsto_inv_iff {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} : Tendsto (fun x => (m x)⁻¹) f (𝓝 a⁻¹) ↔ Tendsto m f (𝓝 a) := ⟨fun h => by simpa only [inv_inv] using Tendsto.inv h, Tendsto.inv⟩ #align ennreal.tendsto_inv_iff ENNReal.tendsto_inv_iff protected theorem Tendsto.div {f : Filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞} (hma : Tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : Tendsto mb f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun a => ma a / mb a) f (𝓝 (a / b)) := by apply Tendsto.mul hma _ (ENNReal.tendsto_inv_iff.2 hmb) _ <;> simp [ha, hb] #align ennreal.tendsto.div ENNReal.Tendsto.div protected theorem Tendsto.const_div {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 b)) (hb : b ≠ ∞ ∨ a ≠ ∞) : Tendsto (fun b => a / m b) f (𝓝 (a / b)) := by apply Tendsto.const_mul (ENNReal.tendsto_inv_iff.2 hm) simp [hb] #align ennreal.tendsto.const_div ENNReal.Tendsto.const_div protected theorem Tendsto.div_const {f : Filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞} (hm : Tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : Tendsto (fun x => m x / b) f (𝓝 (a / b)) := by apply Tendsto.mul_const hm simp [ha] #align ennreal.tendsto.div_const ENNReal.Tendsto.div_const protected theorem tendsto_inv_nat_nhds_zero : Tendsto (fun n : ℕ => (n : ℝ≥0∞)⁻¹) atTop (𝓝 0) := ENNReal.inv_top ▸ ENNReal.tendsto_inv_iff.2 tendsto_nat_nhds_top #align ennreal.tendsto_inv_nat_nhds_zero ENNReal.tendsto_inv_nat_nhds_zero theorem iSup_add {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : iSup s + a = ⨆ b, s b + a := Monotone.map_iSup_of_continuousAt' (continuousAt_id.add continuousAt_const) <| monotone_id.add monotone_const #align ennreal.supr_add ENNReal.iSup_add theorem biSup_add' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (⨆ (i) (_ : p i), f i) + a = ⨆ (i) (_ : p i), f i + a := by haveI : Nonempty { i // p i } := nonempty_subtype.2 h simp only [iSup_subtype', iSup_add] #align ennreal.bsupr_add' ENNReal.biSup_add' theorem add_biSup' {ι : Sort*} {p : ι → Prop} (h : ∃ i, p i) {f : ι → ℝ≥0∞} : (a + ⨆ (i) (_ : p i), f i) = ⨆ (i) (_ : p i), a + f i := by simp only [add_comm a, biSup_add' h] #align ennreal.add_bsupr' ENNReal.add_biSup' theorem biSup_add {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (⨆ i ∈ s, f i) + a = ⨆ i ∈ s, f i + a := biSup_add' hs #align ennreal.bsupr_add ENNReal.biSup_add theorem add_biSup {ι} {s : Set ι} (hs : s.Nonempty) {f : ι → ℝ≥0∞} : (a + ⨆ i ∈ s, f i) = ⨆ i ∈ s, a + f i := add_biSup' hs #align ennreal.add_bsupr ENNReal.add_biSup theorem sSup_add {s : Set ℝ≥0∞} (hs : s.Nonempty) : sSup s + a = ⨆ b ∈ s, b + a := by rw [sSup_eq_iSup, biSup_add hs] #align ennreal.Sup_add ENNReal.sSup_add theorem add_iSup {ι : Sort*} {s : ι → ℝ≥0∞} [Nonempty ι] : a + iSup s = ⨆ b, a + s b := by rw [add_comm, iSup_add]; simp [add_comm] #align ennreal.add_supr ENNReal.add_iSup theorem iSup_add_iSup_le {ι ι' : Sort*} [Nonempty ι] [Nonempty ι'] {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i j, f i + g j ≤ a) : iSup f + iSup g ≤ a := by simp_rw [iSup_add, add_iSup]; exact iSup₂_le h #align ennreal.supr_add_supr_le ENNReal.iSup_add_iSup_le theorem biSup_add_biSup_le' {ι ι'} {p : ι → Prop} {q : ι' → Prop} (hp : ∃ i, p i) (hq : ∃ j, q j) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i, p i → ∀ j, q j → f i + g j ≤ a) : ((⨆ (i) (_ : p i), f i) + ⨆ (j) (_ : q j), g j) ≤ a := by simp_rw [biSup_add' hp, add_biSup' hq] exact iSup₂_le fun i hi => iSup₂_le (h i hi) #align ennreal.bsupr_add_bsupr_le' ENNReal.biSup_add_biSup_le' theorem biSup_add_biSup_le {ι ι'} {s : Set ι} {t : Set ι'} (hs : s.Nonempty) (ht : t.Nonempty) {f : ι → ℝ≥0∞} {g : ι' → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i ∈ s, ∀ j ∈ t, f i + g j ≤ a) : ((⨆ i ∈ s, f i) + ⨆ j ∈ t, g j) ≤ a := biSup_add_biSup_le' hs ht h #align ennreal.bsupr_add_bsupr_le ENNReal.biSup_add_biSup_le theorem iSup_add_iSup {ι : Sort*} {f g : ι → ℝ≥0∞} (h : ∀ i j, ∃ k, f i + g j ≤ f k + g k) : iSup f + iSup g = ⨆ a, f a + g a := by cases isEmpty_or_nonempty ι · simp only [iSup_of_empty, bot_eq_zero, zero_add] · refine le_antisymm ?_ (iSup_le fun a => add_le_add (le_iSup _ _) (le_iSup _ _)) refine iSup_add_iSup_le fun i j => ?_ rcases h i j with ⟨k, hk⟩ exact le_iSup_of_le k hk #align ennreal.supr_add_supr ENNReal.iSup_add_iSup theorem iSup_add_iSup_of_monotone {ι : Type*} [SemilatticeSup ι] {f g : ι → ℝ≥0∞} (hf : Monotone f) (hg : Monotone g) : iSup f + iSup g = ⨆ a, f a + g a := iSup_add_iSup fun i j => ⟨i ⊔ j, add_le_add (hf <| le_sup_left) (hg <| le_sup_right)⟩ #align ennreal.supr_add_supr_of_monotone ENNReal.iSup_add_iSup_of_monotone theorem finset_sum_iSup_nat {α} {ι} [SemilatticeSup ι] {s : Finset α} {f : α → ι → ℝ≥0∞} (hf : ∀ a, Monotone (f a)) : (∑ a ∈ s, iSup (f a)) = ⨆ n, ∑ a ∈ s, f a n := by refine Finset.induction_on s ?_ ?_ · simp · intro a s has ih simp only [Finset.sum_insert has] rw [ih, iSup_add_iSup_of_monotone (hf a)] intro i j h exact Finset.sum_le_sum fun a _ => hf a h #align ennreal.finset_sum_supr_nat ENNReal.finset_sum_iSup_nat theorem mul_iSup {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : a * iSup f = ⨆ i, a * f i := by by_cases hf : ∀ i, f i = 0 · obtain rfl : f = fun _ => 0 := funext hf simp only [iSup_zero_eq_zero, mul_zero] · refine (monotone_id.const_mul' _).map_iSup_of_continuousAt ?_ (mul_zero a) refine ENNReal.Tendsto.const_mul tendsto_id (Or.inl ?_) exact mt iSup_eq_zero.1 hf #align ennreal.mul_supr ENNReal.mul_iSup theorem mul_sSup {s : Set ℝ≥0∞} {a : ℝ≥0∞} : a * sSup s = ⨆ i ∈ s, a * i := by simp only [sSup_eq_iSup, mul_iSup] #align ennreal.mul_Sup ENNReal.mul_sSup theorem iSup_mul {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f * a = ⨆ i, f i * a := by rw [mul_comm, mul_iSup]; congr; funext; rw [mul_comm] #align ennreal.supr_mul ENNReal.iSup_mul theorem smul_iSup {ι : Sort*} {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (f : ι → ℝ≥0∞) (c : R) : (c • ⨆ i, f i) = ⨆ i, c • f i := by -- Porting note: replaced `iSup _` with `iSup f` simp only [← smul_one_mul c (f _), ← smul_one_mul c (iSup f), ENNReal.mul_iSup] #align ennreal.smul_supr ENNReal.smul_iSup theorem smul_sSup {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (s : Set ℝ≥0∞) (c : R) : c • sSup s = ⨆ i ∈ s, c • i := by -- Porting note: replaced `_` with `s` simp_rw [← smul_one_mul c (sSup s), ENNReal.mul_sSup, smul_one_mul] #align ennreal.smul_Sup ENNReal.smul_sSup theorem iSup_div {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : iSup f / a = ⨆ i, f i / a := iSup_mul #align ennreal.supr_div ENNReal.iSup_div protected theorem tendsto_coe_sub {b : ℝ≥0∞} : Tendsto (fun b : ℝ≥0∞ => ↑r - b) (𝓝 b) (𝓝 (↑r - b)) := continuous_nnreal_sub.tendsto _ #align ennreal.tendsto_coe_sub ENNReal.tendsto_coe_sub theorem sub_iSup {ι : Sort*} [Nonempty ι] {b : ι → ℝ≥0∞} (hr : a < ∞) : (a - ⨆ i, b i) = ⨅ i, a - b i := antitone_const_tsub.map_iSup_of_continuousAt' (continuous_sub_left hr.ne).continuousAt #align ennreal.sub_supr ENNReal.sub_iSup theorem exists_countable_dense_no_zero_top : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ 0 ∉ s ∧ ∞ ∉ s := by obtain ⟨s, s_count, s_dense, hs⟩ : ∃ s : Set ℝ≥0∞, s.Countable ∧ Dense s ∧ (∀ x, IsBot x → x ∉ s) ∧ ∀ x, IsTop x → x ∉ s := exists_countable_dense_no_bot_top ℝ≥0∞ exact ⟨s, s_count, s_dense, fun h => hs.1 0 (by simp) h, fun h => hs.2 ∞ (by simp) h⟩ #align ennreal.exists_countable_dense_no_zero_top ENNReal.exists_countable_dense_no_zero_top theorem exists_lt_add_of_lt_add {x y z : ℝ≥0∞} (h : x < y + z) (hy : y ≠ 0) (hz : z ≠ 0) : ∃ y' z', y' < y ∧ z' < z ∧ x < y' + z' := by have : NeZero y := ⟨hy⟩ have : NeZero z := ⟨hz⟩ have A : Tendsto (fun p : ℝ≥0∞ × ℝ≥0∞ => p.1 + p.2) (𝓝[<] y ×ˢ 𝓝[<] z) (𝓝 (y + z)) := by apply Tendsto.mono_left _ (Filter.prod_mono nhdsWithin_le_nhds nhdsWithin_le_nhds) rw [← nhds_prod_eq] exact tendsto_add rcases ((A.eventually (lt_mem_nhds h)).and (Filter.prod_mem_prod self_mem_nhdsWithin self_mem_nhdsWithin)).exists with ⟨⟨y', z'⟩, hx, hy', hz'⟩ exact ⟨y', z', hy', hz', hx⟩ #align ennreal.exists_lt_add_of_lt_add ENNReal.exists_lt_add_of_lt_add theorem ofReal_cinfi (f : α → ℝ) [Nonempty α] : ENNReal.ofReal (⨅ i, f i) = ⨅ i, ENNReal.ofReal (f i) := by by_cases hf : BddBelow (range f) · exact Monotone.map_ciInf_of_continuousAt ENNReal.continuous_ofReal.continuousAt (fun i j hij => ENNReal.ofReal_le_ofReal hij) hf · symm rw [Real.iInf_of_not_bddBelow hf, ENNReal.ofReal_zero, ← ENNReal.bot_eq_zero, iInf_eq_bot] obtain ⟨y, hy_mem, hy_neg⟩ := not_bddBelow_iff.mp hf 0 obtain ⟨i, rfl⟩ := mem_range.mpr hy_mem refine fun x hx => ⟨i, ?_⟩ rwa [ENNReal.ofReal_of_nonpos hy_neg.le] #align ennreal.of_real_cinfi ENNReal.ofReal_cinfi end TopologicalSpace section Liminf theorem exists_frequently_lt_of_liminf_ne_top {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, x n < R := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h r] with i hi using hi.trans (le_abs_self (x i)) #align ennreal.exists_frequently_lt_of_liminf_ne_top ENNReal.exists_frequently_lt_of_liminf_ne_top theorem exists_frequently_lt_of_liminf_ne_top' {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hx : liminf (fun n => (Real.nnabs (x n) : ℝ≥0∞)) l ≠ ∞) : ∃ R, ∃ᶠ n in l, R < x n := by by_contra h simp_rw [not_exists, not_frequently, not_lt] at h refine hx (ENNReal.eq_top_of_forall_nnreal_le fun r => le_limsInf_of_le (by isBoundedDefault) ?_) simp only [eventually_map, ENNReal.coe_le_coe] filter_upwards [h (-r)] with i hi using(le_neg.1 hi).trans (neg_le_abs _) #align ennreal.exists_frequently_lt_of_liminf_ne_top' ENNReal.exists_frequently_lt_of_liminf_ne_top' theorem exists_upcrossings_of_not_bounded_under {ι : Type*} {l : Filter ι} {x : ι → ℝ} (hf : liminf (fun i => (Real.nnabs (x i) : ℝ≥0∞)) l ≠ ∞) (hbdd : ¬IsBoundedUnder (· ≤ ·) l fun i => |x i|) : ∃ a b : ℚ, a < b ∧ (∃ᶠ i in l, x i < a) ∧ ∃ᶠ i in l, ↑b < x i := by rw [isBoundedUnder_le_abs, not_and_or] at hbdd obtain hbdd | hbdd := hbdd · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top hf obtain ⟨q, hq⟩ := exists_rat_gt R refine ⟨q, q + 1, (lt_add_iff_pos_right _).2 zero_lt_one, ?_, ?_⟩ · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 (lt_of_lt_of_le hq (not_lt.1 hx)).le · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q + 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · obtain ⟨R, hR⟩ := exists_frequently_lt_of_liminf_ne_top' hf obtain ⟨q, hq⟩ := exists_rat_lt R refine ⟨q - 1, q, (sub_lt_self_iff _).2 zero_lt_one, ?_, ?_⟩ · simp only [IsBoundedUnder, IsBounded, eventually_map, eventually_atTop, ge_iff_le, not_exists, not_forall, not_le, exists_prop] at hbdd refine fun hcon => hbdd ↑(q - 1) ?_ filter_upwards [hcon] with x hx using not_lt.1 hx · refine fun hcon => hR ?_ filter_upwards [hcon] with x hx using not_lt.2 ((not_lt.1 hx).trans hq.le) #align ennreal.exists_upcrossings_of_not_bounded_under ENNReal.exists_upcrossings_of_not_bounded_under end Liminf section tsum variable {f g : α → ℝ≥0∞} @[norm_cast] protected theorem hasSum_coe {f : α → ℝ≥0} {r : ℝ≥0} : HasSum (fun a => (f a : ℝ≥0∞)) ↑r ↔ HasSum f r := by simp only [HasSum, ← coe_finset_sum, tendsto_coe] #align ennreal.has_sum_coe ENNReal.hasSum_coe protected theorem tsum_coe_eq {f : α → ℝ≥0} (h : HasSum f r) : (∑' a, (f a : ℝ≥0∞)) = r := (ENNReal.hasSum_coe.2 h).tsum_eq #align ennreal.tsum_coe_eq ENNReal.tsum_coe_eq protected theorem coe_tsum {f : α → ℝ≥0} : Summable f → ↑(tsum f) = ∑' a, (f a : ℝ≥0∞) | ⟨r, hr⟩ => by rw [hr.tsum_eq, ENNReal.tsum_coe_eq hr] #align ennreal.coe_tsum ENNReal.coe_tsum protected theorem hasSum : HasSum f (⨆ s : Finset α, ∑ a ∈ s, f a) := tendsto_atTop_iSup fun _ _ => Finset.sum_le_sum_of_subset #align ennreal.has_sum ENNReal.hasSum @[simp] protected theorem summable : Summable f := ⟨_, ENNReal.hasSum⟩ #align ennreal.summable ENNReal.summable theorem tsum_coe_ne_top_iff_summable {f : β → ℝ≥0} : (∑' b, (f b : ℝ≥0∞)) ≠ ∞ ↔ Summable f := by refine ⟨fun h => ?_, fun h => ENNReal.coe_tsum h ▸ ENNReal.coe_ne_top⟩ lift ∑' b, (f b : ℝ≥0∞) to ℝ≥0 using h with a ha refine ⟨a, ENNReal.hasSum_coe.1 ?_⟩ rw [ha] exact ENNReal.summable.hasSum #align ennreal.tsum_coe_ne_top_iff_summable ENNReal.tsum_coe_ne_top_iff_summable protected theorem tsum_eq_iSup_sum : ∑' a, f a = ⨆ s : Finset α, ∑ a ∈ s, f a := ENNReal.hasSum.tsum_eq #align ennreal.tsum_eq_supr_sum ENNReal.tsum_eq_iSup_sum protected theorem tsum_eq_iSup_sum' {ι : Type*} (s : ι → Finset α) (hs : ∀ t, ∃ i, t ⊆ s i) : ∑' a, f a = ⨆ i, ∑ a ∈ s i, f a := by rw [ENNReal.tsum_eq_iSup_sum] symm change ⨆ i : ι, (fun t : Finset α => ∑ a ∈ t, f a) (s i) = ⨆ s : Finset α, ∑ a ∈ s, f a exact (Finset.sum_mono_set f).iSup_comp_eq hs #align ennreal.tsum_eq_supr_sum' ENNReal.tsum_eq_iSup_sum' protected theorem tsum_sigma {β : α → Type*} (f : ∀ a, β a → ℝ≥0∞) : ∑' p : Σa, β a, f p.1 p.2 = ∑' (a) (b), f a b := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma ENNReal.tsum_sigma protected theorem tsum_sigma' {β : α → Type*} (f : (Σa, β a) → ℝ≥0∞) : ∑' p : Σa, β a, f p = ∑' (a) (b), f ⟨a, b⟩ := tsum_sigma' (fun _ => ENNReal.summable) ENNReal.summable #align ennreal.tsum_sigma' ENNReal.tsum_sigma' protected theorem tsum_prod {f : α → β → ℝ≥0∞} : ∑' p : α × β, f p.1 p.2 = ∑' (a) (b), f a b := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod ENNReal.tsum_prod protected theorem tsum_prod' {f : α × β → ℝ≥0∞} : ∑' p : α × β, f p = ∑' (a) (b), f (a, b) := tsum_prod' ENNReal.summable fun _ => ENNReal.summable #align ennreal.tsum_prod' ENNReal.tsum_prod' protected theorem tsum_comm {f : α → β → ℝ≥0∞} : ∑' a, ∑' b, f a b = ∑' b, ∑' a, f a b := tsum_comm' ENNReal.summable (fun _ => ENNReal.summable) fun _ => ENNReal.summable #align ennreal.tsum_comm ENNReal.tsum_comm protected theorem tsum_add : ∑' a, (f a + g a) = ∑' a, f a + ∑' a, g a := tsum_add ENNReal.summable ENNReal.summable #align ennreal.tsum_add ENNReal.tsum_add protected theorem tsum_le_tsum (h : ∀ a, f a ≤ g a) : ∑' a, f a ≤ ∑' a, g a := tsum_le_tsum h ENNReal.summable ENNReal.summable #align ennreal.tsum_le_tsum ENNReal.tsum_le_tsum @[gcongr] protected theorem _root_.GCongr.ennreal_tsum_le_tsum (h : ∀ a, f a ≤ g a) : tsum f ≤ tsum g := ENNReal.tsum_le_tsum h protected theorem sum_le_tsum {f : α → ℝ≥0∞} (s : Finset α) : ∑ x ∈ s, f x ≤ ∑' x, f x := sum_le_tsum s (fun _ _ => zero_le _) ENNReal.summable #align ennreal.sum_le_tsum ENNReal.sum_le_tsum protected theorem tsum_eq_iSup_nat' {f : ℕ → ℝ≥0∞} {N : ℕ → ℕ} (hN : Tendsto N atTop atTop) : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range (N i), f a := ENNReal.tsum_eq_iSup_sum' _ fun t => let ⟨n, hn⟩ := t.exists_nat_subset_range let ⟨k, _, hk⟩ := exists_le_of_tendsto_atTop hN 0 n ⟨k, Finset.Subset.trans hn (Finset.range_mono hk)⟩ #align ennreal.tsum_eq_supr_nat' ENNReal.tsum_eq_iSup_nat' protected theorem tsum_eq_iSup_nat {f : ℕ → ℝ≥0∞} : ∑' i : ℕ, f i = ⨆ i : ℕ, ∑ a ∈ Finset.range i, f a := ENNReal.tsum_eq_iSup_sum' _ Finset.exists_nat_subset_range #align ennreal.tsum_eq_supr_nat ENNReal.tsum_eq_iSup_nat protected theorem tsum_eq_liminf_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = liminf (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.liminf_eq.symm #align ennreal.tsum_eq_liminf_sum_nat ENNReal.tsum_eq_liminf_sum_nat protected theorem tsum_eq_limsup_sum_nat {f : ℕ → ℝ≥0∞} : ∑' i, f i = limsup (fun n => ∑ i ∈ Finset.range n, f i) atTop := ENNReal.summable.hasSum.tendsto_sum_nat.limsup_eq.symm protected theorem le_tsum (a : α) : f a ≤ ∑' a, f a := le_tsum' ENNReal.summable a #align ennreal.le_tsum ENNReal.le_tsum @[simp] protected theorem tsum_eq_zero : ∑' i, f i = 0 ↔ ∀ i, f i = 0 := tsum_eq_zero_iff ENNReal.summable #align ennreal.tsum_eq_zero ENNReal.tsum_eq_zero protected theorem tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → ∑' a, f a = ∞ | ⟨a, ha⟩ => top_unique <| ha ▸ ENNReal.le_tsum a #align ennreal.tsum_eq_top_of_eq_top ENNReal.tsum_eq_top_of_eq_top protected theorem lt_top_of_tsum_ne_top {a : α → ℝ≥0∞} (tsum_ne_top : ∑' i, a i ≠ ∞) (j : α) : a j < ∞ := by contrapose! tsum_ne_top with h exact ENNReal.tsum_eq_top_of_eq_top ⟨j, top_unique h⟩ #align ennreal.lt_top_of_tsum_ne_top ENNReal.lt_top_of_tsum_ne_top @[simp] protected theorem tsum_top [Nonempty α] : ∑' _ : α, ∞ = ∞ := let ⟨a⟩ := ‹Nonempty α› ENNReal.tsum_eq_top_of_eq_top ⟨a, rfl⟩ #align ennreal.tsum_top ENNReal.tsum_top theorem tsum_const_eq_top_of_ne_zero {α : Type*} [Infinite α] {c : ℝ≥0∞} (hc : c ≠ 0) : ∑' _ : α, c = ∞ := by have A : Tendsto (fun n : ℕ => (n : ℝ≥0∞) * c) atTop (𝓝 (∞ * c)) := by apply ENNReal.Tendsto.mul_const tendsto_nat_nhds_top simp only [true_or_iff, top_ne_zero, Ne, not_false_iff] have B : ∀ n : ℕ, (n : ℝ≥0∞) * c ≤ ∑' _ : α, c := fun n => by rcases Infinite.exists_subset_card_eq α n with ⟨s, hs⟩ simpa [hs] using @ENNReal.sum_le_tsum α (fun _ => c) s simpa [hc] using le_of_tendsto' A B #align ennreal.tsum_const_eq_top_of_ne_zero ENNReal.tsum_const_eq_top_of_ne_zero protected theorem ne_top_of_tsum_ne_top (h : ∑' a, f a ≠ ∞) (a : α) : f a ≠ ∞ := fun ha => h <| ENNReal.tsum_eq_top_of_eq_top ⟨a, ha⟩ #align ennreal.ne_top_of_tsum_ne_top ENNReal.ne_top_of_tsum_ne_top protected theorem tsum_mul_left : ∑' i, a * f i = a * ∑' i, f i := by by_cases hf : ∀ i, f i = 0 · simp [hf] · rw [← ENNReal.tsum_eq_zero] at hf have : Tendsto (fun s : Finset α => ∑ j ∈ s, a * f j) atTop (𝓝 (a * ∑' i, f i)) := by simp only [← Finset.mul_sum] exact ENNReal.Tendsto.const_mul ENNReal.summable.hasSum (Or.inl hf) exact HasSum.tsum_eq this #align ennreal.tsum_mul_left ENNReal.tsum_mul_left protected theorem tsum_mul_right : ∑' i, f i * a = (∑' i, f i) * a := by simp [mul_comm, ENNReal.tsum_mul_left] #align ennreal.tsum_mul_right ENNReal.tsum_mul_right protected theorem tsum_const_smul {R} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (a : R) : ∑' i, a • f i = a • ∑' i, f i := by simpa only [smul_one_mul] using @ENNReal.tsum_mul_left _ (a • (1 : ℝ≥0∞)) _ #align ennreal.tsum_const_smul ENNReal.tsum_const_smul @[simp] theorem tsum_iSup_eq {α : Type*} (a : α) {f : α → ℝ≥0∞} : (∑' b : α, ⨆ _ : a = b, f b) = f a := (tsum_eq_single a fun _ h => by simp [h.symm]).trans <| by simp #align ennreal.tsum_supr_eq ENNReal.tsum_iSup_eq theorem hasSum_iff_tendsto_nat {f : ℕ → ℝ≥0∞} (r : ℝ≥0∞) : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by refine ⟨HasSum.tendsto_sum_nat, fun h => ?_⟩ rw [← iSup_eq_of_tendsto _ h, ← ENNReal.tsum_eq_iSup_nat] · exact ENNReal.summable.hasSum · exact fun s t hst => Finset.sum_le_sum_of_subset (Finset.range_subset.2 hst) #align ennreal.has_sum_iff_tendsto_nat ENNReal.hasSum_iff_tendsto_nat theorem tendsto_nat_tsum (f : ℕ → ℝ≥0∞) : Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 (∑' n, f n)) := by rw [← hasSum_iff_tendsto_nat] exact ENNReal.summable.hasSum #align ennreal.tendsto_nat_tsum ENNReal.tendsto_nat_tsum theorem toNNReal_apply_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) (x : α) : (((ENNReal.toNNReal ∘ f) x : ℝ≥0) : ℝ≥0∞) = f x := coe_toNNReal <| ENNReal.ne_top_of_tsum_ne_top hf _ #align ennreal.to_nnreal_apply_of_tsum_ne_top ENNReal.toNNReal_apply_of_tsum_ne_top theorem summable_toNNReal_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) : Summable (ENNReal.toNNReal ∘ f) := by simpa only [← tsum_coe_ne_top_iff_summable, toNNReal_apply_of_tsum_ne_top hf] using hf #align ennreal.summable_to_nnreal_of_tsum_ne_top ENNReal.summable_toNNReal_of_tsum_ne_top theorem tendsto_cofinite_zero_of_tsum_ne_top {α} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto f cofinite (𝓝 0) := by have f_ne_top : ∀ n, f n ≠ ∞ := ENNReal.ne_top_of_tsum_ne_top hf have h_f_coe : f = fun n => ((f n).toNNReal : ENNReal) := funext fun n => (coe_toNNReal (f_ne_top n)).symm rw [h_f_coe, ← @coe_zero, tendsto_coe] exact NNReal.tendsto_cofinite_zero_of_summable (summable_toNNReal_of_tsum_ne_top hf) #align ennreal.tendsto_cofinite_zero_of_tsum_ne_top ENNReal.tendsto_cofinite_zero_of_tsum_ne_top theorem tendsto_atTop_zero_of_tsum_ne_top {f : ℕ → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto f atTop (𝓝 0) := by rw [← Nat.cofinite_eq_atTop] exact tendsto_cofinite_zero_of_tsum_ne_top hf #align ennreal.tendsto_at_top_zero_of_tsum_ne_top ENNReal.tendsto_atTop_zero_of_tsum_ne_top /-- The sum over the complement of a finset tends to `0` when the finset grows to cover the whole space. This does not need a summability assumption, as otherwise all sums are zero. -/ theorem tendsto_tsum_compl_atTop_zero {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) : Tendsto (fun s : Finset α => ∑' b : { x // x ∉ s }, f b) atTop (𝓝 0) := by lift f to α → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hf convert ENNReal.tendsto_coe.2 (NNReal.tendsto_tsum_compl_atTop_zero f) rw [ENNReal.coe_tsum] exact NNReal.summable_comp_injective (tsum_coe_ne_top_iff_summable.1 hf) Subtype.coe_injective #align ennreal.tendsto_tsum_compl_at_top_zero ENNReal.tendsto_tsum_compl_atTop_zero protected theorem tsum_apply {ι α : Type*} {f : ι → α → ℝ≥0∞} {x : α} : (∑' i, f i) x = ∑' i, f i x := tsum_apply <| Pi.summable.mpr fun _ => ENNReal.summable #align ennreal.tsum_apply ENNReal.tsum_apply theorem tsum_sub {f : ℕ → ℝ≥0∞} {g : ℕ → ℝ≥0∞} (h₁ : ∑' i, g i ≠ ∞) (h₂ : g ≤ f) : ∑' i, (f i - g i) = ∑' i, f i - ∑' i, g i := have : ∀ i, f i - g i + g i = f i := fun i => tsub_add_cancel_of_le (h₂ i) ENNReal.eq_sub_of_add_eq h₁ <| by simp only [← ENNReal.tsum_add, this] #align ennreal.tsum_sub ENNReal.tsum_sub theorem tsum_comp_le_tsum_of_injective {f : α → β} (hf : Injective f) (g : β → ℝ≥0∞) : ∑' x, g (f x) ≤ ∑' y, g y := tsum_le_tsum_of_inj f hf (fun _ _ => zero_le _) (fun _ => le_rfl) ENNReal.summable ENNReal.summable theorem tsum_le_tsum_comp_of_surjective {f : α → β} (hf : Surjective f) (g : β → ℝ≥0∞) : ∑' y, g y ≤ ∑' x, g (f x) := calc ∑' y, g y = ∑' y, g (f (surjInv hf y)) := by simp only [surjInv_eq hf] _ ≤ ∑' x, g (f x) := tsum_comp_le_tsum_of_injective (injective_surjInv hf) _ theorem tsum_mono_subtype (f : α → ℝ≥0∞) {s t : Set α} (h : s ⊆ t) : ∑' x : s, f x ≤ ∑' x : t, f x := tsum_comp_le_tsum_of_injective (inclusion_injective h) _ #align ennreal.tsum_mono_subtype ENNReal.tsum_mono_subtype theorem tsum_iUnion_le_tsum {ι : Type*} (f : α → ℝ≥0∞) (t : ι → Set α) : ∑' x : ⋃ i, t i, f x ≤ ∑' i, ∑' x : t i, f x := calc ∑' x : ⋃ i, t i, f x ≤ ∑' x : Σ i, t i, f x.2 := tsum_le_tsum_comp_of_surjective (sigmaToiUnion_surjective t) _ _ = ∑' i, ∑' x : t i, f x := ENNReal.tsum_sigma' _ theorem tsum_biUnion_le_tsum {ι : Type*} (f : α → ℝ≥0∞) (s : Set ι) (t : ι → Set α) : ∑' x : ⋃ i ∈ s , t i, f x ≤ ∑' i : s, ∑' x : t i, f x := calc ∑' x : ⋃ i ∈ s, t i, f x = ∑' x : ⋃ i : s, t i, f x := tsum_congr_set_coe _ <| by simp _ ≤ ∑' i : s, ∑' x : t i, f x := tsum_iUnion_le_tsum _ _ theorem tsum_biUnion_le {ι : Type*} (f : α → ℝ≥0∞) (s : Finset ι) (t : ι → Set α) : ∑' x : ⋃ i ∈ s, t i, f x ≤ ∑ i ∈ s, ∑' x : t i, f x := (tsum_biUnion_le_tsum f s.toSet t).trans_eq (Finset.tsum_subtype s fun i => ∑' x : t i, f x) #align ennreal.tsum_bUnion_le ENNReal.tsum_biUnion_le theorem tsum_iUnion_le {ι : Type*} [Fintype ι] (f : α → ℝ≥0∞) (t : ι → Set α) : ∑' x : ⋃ i, t i, f x ≤ ∑ i, ∑' x : t i, f x := by rw [← tsum_fintype] exact tsum_iUnion_le_tsum f t #align ennreal.tsum_Union_le ENNReal.tsum_iUnion_le theorem tsum_union_le (f : α → ℝ≥0∞) (s t : Set α) : ∑' x : ↑(s ∪ t), f x ≤ ∑' x : s, f x + ∑' x : t, f x := calc ∑' x : ↑(s ∪ t), f x = ∑' x : ⋃ b, cond b s t, f x := tsum_congr_set_coe _ union_eq_iUnion _ ≤ _ := by simpa using tsum_iUnion_le f (cond · s t) #align ennreal.tsum_union_le ENNReal.tsum_union_le theorem tsum_eq_add_tsum_ite {f : β → ℝ≥0∞} (b : β) : ∑' x, f x = f b + ∑' x, ite (x = b) 0 (f x) := tsum_eq_add_tsum_ite' b ENNReal.summable #align ennreal.tsum_eq_add_tsum_ite ENNReal.tsum_eq_add_tsum_ite theorem tsum_add_one_eq_top {f : ℕ → ℝ≥0∞} (hf : ∑' n, f n = ∞) (hf0 : f 0 ≠ ∞) : ∑' n, f (n + 1) = ∞ := by rw [tsum_eq_zero_add' ENNReal.summable, add_eq_top] at hf exact hf.resolve_left hf0 #align ennreal.tsum_add_one_eq_top ENNReal.tsum_add_one_eq_top /-- A sum of extended nonnegative reals which is finite can have only finitely many terms above any positive threshold. -/ theorem finite_const_le_of_tsum_ne_top {ι : Type*} {a : ι → ℝ≥0∞} (tsum_ne_top : ∑' i, a i ≠ ∞) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) : { i : ι | ε ≤ a i }.Finite := by by_contra h have := Infinite.to_subtype h refine tsum_ne_top (top_unique ?_) calc ∞ = ∑' _ : { i | ε ≤ a i }, ε := (tsum_const_eq_top_of_ne_zero ε_ne_zero).symm _ ≤ ∑' i, a i := tsum_le_tsum_of_inj (↑) Subtype.val_injective (fun _ _ => zero_le _) (fun i => i.2) ENNReal.summable ENNReal.summable #align ennreal.finite_const_le_of_tsum_ne_top ENNReal.finite_const_le_of_tsum_ne_top /-- Markov's inequality for `Finset.card` and `tsum` in `ℝ≥0∞`. -/ theorem finset_card_const_le_le_of_tsum_le {ι : Type*} {a : ι → ℝ≥0∞} {c : ℝ≥0∞} (c_ne_top : c ≠ ∞) (tsum_le_c : ∑' i, a i ≤ c) {ε : ℝ≥0∞} (ε_ne_zero : ε ≠ 0) : ∃ hf : { i : ι | ε ≤ a i }.Finite, ↑hf.toFinset.card ≤ c / ε := by have hf : { i : ι | ε ≤ a i }.Finite := finite_const_le_of_tsum_ne_top (ne_top_of_le_ne_top c_ne_top tsum_le_c) ε_ne_zero refine ⟨hf, (ENNReal.le_div_iff_mul_le (.inl ε_ne_zero) (.inr c_ne_top)).2 ?_⟩ calc ↑hf.toFinset.card * ε = ∑ _i ∈ hf.toFinset, ε := by rw [Finset.sum_const, nsmul_eq_mul] _ ≤ ∑ i ∈ hf.toFinset, a i := Finset.sum_le_sum fun i => hf.mem_toFinset.1 _ ≤ ∑' i, a i := ENNReal.sum_le_tsum _ _ ≤ c := tsum_le_c #align ennreal.finset_card_const_le_le_of_tsum_le ENNReal.finset_card_const_le_le_of_tsum_le theorem tsum_fiberwise (f : β → ℝ≥0∞) (g : β → γ) : ∑' x, ∑' b : g ⁻¹' {x}, f b = ∑' i, f i := by apply HasSum.tsum_eq let equiv := Equiv.sigmaFiberEquiv g apply (equiv.hasSum_iff.mpr ENNReal.summable.hasSum).sigma exact fun _ ↦ ENNReal.summable.hasSum_iff.mpr rfl end tsum theorem tendsto_toReal_iff {ι} {fi : Filter ι} {f : ι → ℝ≥0∞} (hf : ∀ i, f i ≠ ∞) {x : ℝ≥0∞} (hx : x ≠ ∞) : Tendsto (fun n => (f n).toReal) fi (𝓝 x.toReal) ↔ Tendsto f fi (𝓝 x) := by lift f to ι → ℝ≥0 using hf lift x to ℝ≥0 using hx simp [tendsto_coe] #align ennreal.tendsto_to_real_iff ENNReal.tendsto_toReal_iff theorem tsum_coe_ne_top_iff_summable_coe {f : α → ℝ≥0} : (∑' a, (f a : ℝ≥0∞)) ≠ ∞ ↔ Summable fun a => (f a : ℝ) := by rw [NNReal.summable_coe] exact tsum_coe_ne_top_iff_summable #align ennreal.tsum_coe_ne_top_iff_summable_coe ENNReal.tsum_coe_ne_top_iff_summable_coe theorem tsum_coe_eq_top_iff_not_summable_coe {f : α → ℝ≥0} : (∑' a, (f a : ℝ≥0∞)) = ∞ ↔ ¬Summable fun a => (f a : ℝ) := tsum_coe_ne_top_iff_summable_coe.not_right #align ennreal.tsum_coe_eq_top_iff_not_summable_coe ENNReal.tsum_coe_eq_top_iff_not_summable_coe theorem hasSum_toReal {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) : HasSum (fun x => (f x).toReal) (∑' x, (f x).toReal) := by lift f to α → ℝ≥0 using ENNReal.ne_top_of_tsum_ne_top hsum simp only [coe_toReal, ← NNReal.coe_tsum, NNReal.hasSum_coe] exact (tsum_coe_ne_top_iff_summable.1 hsum).hasSum #align ennreal.has_sum_to_real ENNReal.hasSum_toReal theorem summable_toReal {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) : Summable fun x => (f x).toReal := (hasSum_toReal hsum).summable #align ennreal.summable_to_real ENNReal.summable_toReal end ENNReal namespace NNReal theorem tsum_eq_toNNReal_tsum {f : β → ℝ≥0} : ∑' b, f b = (∑' b, (f b : ℝ≥0∞)).toNNReal := by by_cases h : Summable f · rw [← ENNReal.coe_tsum h, ENNReal.toNNReal_coe] · have A := tsum_eq_zero_of_not_summable h simp only [← ENNReal.tsum_coe_ne_top_iff_summable, Classical.not_not] at h simp only [h, ENNReal.top_toNNReal, A] #align nnreal.tsum_eq_to_nnreal_tsum NNReal.tsum_eq_toNNReal_tsum /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ theorem exists_le_hasSum_of_le {f g : β → ℝ≥0} {r : ℝ≥0} (hgf : ∀ b, g b ≤ f b) (hfr : HasSum f r) : ∃ p ≤ r, HasSum g p := have : (∑' b, (g b : ℝ≥0∞)) ≤ r := by refine hasSum_le (fun b => ?_) ENNReal.summable.hasSum (ENNReal.hasSum_coe.2 hfr) exact ENNReal.coe_le_coe.2 (hgf _) let ⟨p, Eq, hpr⟩ := ENNReal.le_coe_iff.1 this ⟨p, hpr, ENNReal.hasSum_coe.1 <| Eq ▸ ENNReal.summable.hasSum⟩ #align nnreal.exists_le_has_sum_of_le NNReal.exists_le_hasSum_of_le /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ theorem summable_of_le {f g : β → ℝ≥0} (hgf : ∀ b, g b ≤ f b) : Summable f → Summable g | ⟨_r, hfr⟩ => let ⟨_p, _, hp⟩ := exists_le_hasSum_of_le hgf hfr hp.summable #align nnreal.summable_of_le NNReal.summable_of_le /-- Summable non-negative functions have countable support -/ theorem _root_.Summable.countable_support_nnreal (f : α → ℝ≥0) (h : Summable f) : f.support.Countable := by rw [← NNReal.summable_coe] at h simpa [support] using h.countable_support /-- A series of non-negative real numbers converges to `r` in the sense of `HasSum` if and only if the sequence of partial sum converges to `r`. -/ theorem hasSum_iff_tendsto_nat {f : ℕ → ℝ≥0} {r : ℝ≥0} : HasSum f r ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop (𝓝 r) := by rw [← ENNReal.hasSum_coe, ENNReal.hasSum_iff_tendsto_nat] simp only [← ENNReal.coe_finset_sum] exact ENNReal.tendsto_coe #align nnreal.has_sum_iff_tendsto_nat NNReal.hasSum_iff_tendsto_nat theorem not_summable_iff_tendsto_nat_atTop {f : ℕ → ℝ≥0} : ¬Summable f ↔ Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop atTop := by constructor · intro h refine ((tendsto_of_monotone ?_).resolve_right h).comp ?_ exacts [Finset.sum_mono_set _, tendsto_finset_range] · rintro hnat ⟨r, hr⟩ exact not_tendsto_nhds_of_tendsto_atTop hnat _ (hasSum_iff_tendsto_nat.1 hr) #align nnreal.not_summable_iff_tendsto_nat_at_top NNReal.not_summable_iff_tendsto_nat_atTop theorem summable_iff_not_tendsto_nat_atTop {f : ℕ → ℝ≥0} : Summable f ↔ ¬Tendsto (fun n : ℕ => ∑ i ∈ Finset.range n, f i) atTop atTop := by rw [← not_iff_not, Classical.not_not, not_summable_iff_tendsto_nat_atTop] #align nnreal.summable_iff_not_tendsto_nat_at_top NNReal.summable_iff_not_tendsto_nat_atTop theorem summable_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : Summable f := by refine summable_iff_not_tendsto_nat_atTop.2 fun H => ?_ rcases exists_lt_of_tendsto_atTop H 0 c with ⟨n, -, hn⟩ exact lt_irrefl _ (hn.trans_le (h n)) #align nnreal.summable_of_sum_range_le NNReal.summable_of_sum_range_le theorem tsum_le_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i ∈ Finset.range n, f i ≤ c) : ∑' n, f n ≤ c := _root_.tsum_le_of_sum_range_le (summable_of_sum_range_le h) h #align nnreal.tsum_le_of_sum_range_le NNReal.tsum_le_of_sum_range_le theorem tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ≥0} (hf : Summable f) {i : β → α} (hi : Function.Injective i) : (∑' x, f (i x)) ≤ ∑' x, f x := tsum_le_tsum_of_inj i hi (fun _ _ => zero_le _) (fun _ => le_rfl) (summable_comp_injective hf hi) hf #align nnreal.tsum_comp_le_tsum_of_inj NNReal.tsum_comp_le_tsum_of_inj
Mathlib/Topology/Instances/ENNReal.lean
1,201
1,208
theorem summable_sigma {β : α → Type*} {f : (Σ x, β x) → ℝ≥0} : Summable f ↔ (∀ x, Summable fun y => f ⟨x, y⟩) ∧ Summable fun x => ∑' y, f ⟨x, y⟩ := by
constructor · simp only [← NNReal.summable_coe, NNReal.coe_tsum] exact fun h => ⟨h.sigma_factor, h.sigma⟩ · rintro ⟨h₁, h₂⟩ simpa only [← ENNReal.tsum_coe_ne_top_iff_summable, ENNReal.tsum_sigma', ENNReal.coe_tsum (h₁ _)] using h₂
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Game.Basic import Mathlib.SetTheory.Ordinal.NaturalOps #align_import set_theory.game.ordinal from "leanprover-community/mathlib"@"b90e72c7eebbe8de7c8293a80208ea2ba135c834" /-! # Ordinals as games We define the canonical map `Ordinal → SetTheory.PGame`, where every ordinal is mapped to the game whose left set consists of all previous ordinals. The map to surreals is defined in `Ordinal.toSurreal`. # Main declarations - `Ordinal.toPGame`: The canonical map between ordinals and pre-games. - `Ordinal.toPGameEmbedding`: The order embedding version of the previous map. -/ universe u open SetTheory PGame open scoped NaturalOps PGame namespace Ordinal /-- Converts an ordinal into the corresponding pre-game. -/ noncomputable def toPGame : Ordinal.{u} → PGame.{u} | o => have : IsWellOrder o.out.α (· < ·) := isWellOrder_out_lt o ⟨o.out.α, PEmpty, fun x => have := Ordinal.typein_lt_self x (typein (· < ·) x).toPGame, PEmpty.elim⟩ termination_by x => x #align ordinal.to_pgame Ordinal.toPGame @[nolint unusedHavesSuffices] theorem toPGame_def (o : Ordinal) : have : IsWellOrder o.out.α (· < ·) := isWellOrder_out_lt o o.toPGame = ⟨o.out.α, PEmpty, fun x => (typein (· < ·) x).toPGame, PEmpty.elim⟩ := by rw [toPGame] #align ordinal.to_pgame_def Ordinal.toPGame_def @[simp, nolint unusedHavesSuffices] theorem toPGame_leftMoves (o : Ordinal) : o.toPGame.LeftMoves = o.out.α := by rw [toPGame, LeftMoves] #align ordinal.to_pgame_left_moves Ordinal.toPGame_leftMoves @[simp, nolint unusedHavesSuffices] theorem toPGame_rightMoves (o : Ordinal) : o.toPGame.RightMoves = PEmpty := by rw [toPGame, RightMoves] #align ordinal.to_pgame_right_moves Ordinal.toPGame_rightMoves instance isEmpty_zero_toPGame_leftMoves : IsEmpty (toPGame 0).LeftMoves := by rw [toPGame_leftMoves]; infer_instance #align ordinal.is_empty_zero_to_pgame_left_moves Ordinal.isEmpty_zero_toPGame_leftMoves instance isEmpty_toPGame_rightMoves (o : Ordinal) : IsEmpty o.toPGame.RightMoves := by rw [toPGame_rightMoves]; infer_instance #align ordinal.is_empty_to_pgame_right_moves Ordinal.isEmpty_toPGame_rightMoves /-- Converts an ordinal less than `o` into a move for the `PGame` corresponding to `o`, and vice versa. -/ noncomputable def toLeftMovesToPGame {o : Ordinal} : Set.Iio o ≃ o.toPGame.LeftMoves := (enumIsoOut o).toEquiv.trans (Equiv.cast (toPGame_leftMoves o).symm) #align ordinal.to_left_moves_to_pgame Ordinal.toLeftMovesToPGame @[simp] theorem toLeftMovesToPGame_symm_lt {o : Ordinal} (i : o.toPGame.LeftMoves) : ↑(toLeftMovesToPGame.symm i) < o := (toLeftMovesToPGame.symm i).prop #align ordinal.to_left_moves_to_pgame_symm_lt Ordinal.toLeftMovesToPGame_symm_lt @[nolint unusedHavesSuffices] theorem toPGame_moveLeft_hEq {o : Ordinal} : have : IsWellOrder o.out.α (· < ·) := isWellOrder_out_lt o HEq o.toPGame.moveLeft fun x : o.out.α => (typein (· < ·) x).toPGame := by rw [toPGame] rfl #align ordinal.to_pgame_move_left_heq Ordinal.toPGame_moveLeft_hEq @[simp] theorem toPGame_moveLeft' {o : Ordinal} (i) : o.toPGame.moveLeft i = (toLeftMovesToPGame.symm i).val.toPGame := (congr_heq toPGame_moveLeft_hEq.symm (cast_heq _ i)).symm #align ordinal.to_pgame_move_left' Ordinal.toPGame_moveLeft'
Mathlib/SetTheory/Game/Ordinal.lean
96
97
theorem toPGame_moveLeft {o : Ordinal} (i) : o.toPGame.moveLeft (toLeftMovesToPGame i) = i.val.toPGame := by
simp
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp #align_import analysis.calculus.fderiv.equiv from "leanprover-community/mathlib"@"e3fb84046afd187b710170887195d50bada934ee" /-! # The derivative of a linear equivalence For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of continuous linear equivalences. We also prove the usual formula for the derivative of the inverse function, assuming it exists. The inverse function theorem is in `Mathlib/Analysis/Calculus/InverseFunctionTheorem/FDeriv.lean`. -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} namespace ContinuousLinearEquiv /-! ### Differentiability of linear equivs, and invariance of differentiability -/ variable (iso : E ≃L[𝕜] F) @[fun_prop] protected theorem hasStrictFDerivAt : HasStrictFDerivAt iso (iso : E →L[𝕜] F) x := iso.toContinuousLinearMap.hasStrictFDerivAt #align continuous_linear_equiv.has_strict_fderiv_at ContinuousLinearEquiv.hasStrictFDerivAt @[fun_prop] protected theorem hasFDerivWithinAt : HasFDerivWithinAt iso (iso : E →L[𝕜] F) s x := iso.toContinuousLinearMap.hasFDerivWithinAt #align continuous_linear_equiv.has_fderiv_within_at ContinuousLinearEquiv.hasFDerivWithinAt @[fun_prop] protected theorem hasFDerivAt : HasFDerivAt iso (iso : E →L[𝕜] F) x := iso.toContinuousLinearMap.hasFDerivAtFilter #align continuous_linear_equiv.has_fderiv_at ContinuousLinearEquiv.hasFDerivAt @[fun_prop] protected theorem differentiableAt : DifferentiableAt 𝕜 iso x := iso.hasFDerivAt.differentiableAt #align continuous_linear_equiv.differentiable_at ContinuousLinearEquiv.differentiableAt @[fun_prop] protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 iso s x := iso.differentiableAt.differentiableWithinAt #align continuous_linear_equiv.differentiable_within_at ContinuousLinearEquiv.differentiableWithinAt protected theorem fderiv : fderiv 𝕜 iso x = iso := iso.hasFDerivAt.fderiv #align continuous_linear_equiv.fderiv ContinuousLinearEquiv.fderiv protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 iso s x = iso := iso.toContinuousLinearMap.fderivWithin hxs #align continuous_linear_equiv.fderiv_within ContinuousLinearEquiv.fderivWithin @[fun_prop] protected theorem differentiable : Differentiable 𝕜 iso := fun _ => iso.differentiableAt #align continuous_linear_equiv.differentiable ContinuousLinearEquiv.differentiable @[fun_prop] protected theorem differentiableOn : DifferentiableOn 𝕜 iso s := iso.differentiable.differentiableOn #align continuous_linear_equiv.differentiable_on ContinuousLinearEquiv.differentiableOn theorem comp_differentiableWithinAt_iff {f : G → E} {s : Set G} {x : G} : DifferentiableWithinAt 𝕜 (iso ∘ f) s x ↔ DifferentiableWithinAt 𝕜 f s x := by refine ⟨fun H => ?_, fun H => iso.differentiable.differentiableAt.comp_differentiableWithinAt x H⟩ have : DifferentiableWithinAt 𝕜 (iso.symm ∘ iso ∘ f) s x := iso.symm.differentiable.differentiableAt.comp_differentiableWithinAt x H rwa [← Function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this #align continuous_linear_equiv.comp_differentiable_within_at_iff ContinuousLinearEquiv.comp_differentiableWithinAt_iff theorem comp_differentiableAt_iff {f : G → E} {x : G} : DifferentiableAt 𝕜 (iso ∘ f) x ↔ DifferentiableAt 𝕜 f x := by rw [← differentiableWithinAt_univ, ← differentiableWithinAt_univ, iso.comp_differentiableWithinAt_iff] #align continuous_linear_equiv.comp_differentiable_at_iff ContinuousLinearEquiv.comp_differentiableAt_iff theorem comp_differentiableOn_iff {f : G → E} {s : Set G} : DifferentiableOn 𝕜 (iso ∘ f) s ↔ DifferentiableOn 𝕜 f s := by rw [DifferentiableOn, DifferentiableOn] simp only [iso.comp_differentiableWithinAt_iff] #align continuous_linear_equiv.comp_differentiable_on_iff ContinuousLinearEquiv.comp_differentiableOn_iff theorem comp_differentiable_iff {f : G → E} : Differentiable 𝕜 (iso ∘ f) ↔ Differentiable 𝕜 f := by rw [← differentiableOn_univ, ← differentiableOn_univ] exact iso.comp_differentiableOn_iff #align continuous_linear_equiv.comp_differentiable_iff ContinuousLinearEquiv.comp_differentiable_iff
Mathlib/Analysis/Calculus/FDeriv/Equiv.lean
121
130
theorem comp_hasFDerivWithinAt_iff {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] E} : HasFDerivWithinAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ HasFDerivWithinAt f f' s x := by
refine ⟨fun H => ?_, fun H => iso.hasFDerivAt.comp_hasFDerivWithinAt x H⟩ have A : f = iso.symm ∘ iso ∘ f := by rw [← Function.comp.assoc, iso.symm_comp_self] rfl have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f') := by rw [← ContinuousLinearMap.comp_assoc, iso.coe_symm_comp_coe, ContinuousLinearMap.id_comp] rw [A, B] exact iso.symm.hasFDerivAt.comp_hasFDerivWithinAt x H