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) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed import Mathlib.RingTheory.PowerBasis #align_import ring_theory.is_adjoin_root from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c" /-! # A predicate on adjoining roots of polynomial This file defines a predicate `IsAdjoinRoot S f`, which states that the ring `S` can be constructed by adjoining a specified root of the polynomial `f : R[X]` to `R`. This predicate is useful when the same ring can be generated by adjoining the root of different polynomials, and you want to vary which polynomial you're considering. The results in this file are intended to mirror those in `RingTheory.AdjoinRoot`, in order to provide an easier way to translate results from one to the other. ## Motivation `AdjoinRoot` presents one construction of a ring `R[α]`. However, it is possible to obtain rings of this form in many ways, such as `NumberField.ringOfIntegers ℚ(√-5)`, or `Algebra.adjoin R {α, α^2}`, or `IntermediateField.adjoin R {α, 2 - α}`, or even if we want to view `ℂ` as adjoining a root of `X^2 + 1` to `ℝ`. ## Main definitions The two main predicates in this file are: * `IsAdjoinRoot S f`: `S` is generated by adjoining a specified root of `f : R[X]` to `R` * `IsAdjoinRootMonic S f`: `S` is generated by adjoining a root of the monic polynomial `f : R[X]` to `R` Using `IsAdjoinRoot` to map into `S`: * `IsAdjoinRoot.map`: inclusion from `R[X]` to `S` * `IsAdjoinRoot.root`: the specific root adjoined to `R` to give `S` Using `IsAdjoinRoot` to map out of `S`: * `IsAdjoinRoot.repr`: choose a non-unique representative in `R[X]` * `IsAdjoinRoot.lift`, `IsAdjoinRoot.liftHom`: lift a morphism `R →+* T` to `S →+* T` * `IsAdjoinRootMonic.modByMonicHom`: a unique representative in `R[X]` if `f` is monic ## Main results * `AdjoinRoot.isAdjoinRoot` and `AdjoinRoot.isAdjoinRootMonic`: `AdjoinRoot` satisfies the conditions on `IsAdjoinRoot`(`_monic`) * `IsAdjoinRootMonic.powerBasis`: the `root` generates a power basis on `S` over `R` * `IsAdjoinRoot.aequiv`: algebra isomorphism showing adjoining a root gives a unique ring up to isomorphism * `IsAdjoinRoot.ofEquiv`: transfer `IsAdjoinRoot` across an algebra isomorphism * `IsAdjoinRootMonic.minpoly_eq`: the minimal polynomial of the adjoined root of `f` is equal to `f`, if `f` is irreducible and monic, and `R` is a GCD domain -/ open scoped Polynomial open Polynomial noncomputable section universe u v -- Porting note: this looks like something that should not be here -- section MoveMe -- -- end MoveMe -- This class doesn't really make sense on a predicate /-- `IsAdjoinRoot S f` states that the ring `S` can be constructed by adjoining a specified root of the polynomial `f : R[X]` to `R`. Compare `PowerBasis R S`, which does not explicitly specify which polynomial we adjoin a root of (in particular `f` does not need to be the minimal polynomial of the root we adjoin), and `AdjoinRoot` which constructs a new type. This is not a typeclass because the choice of root given `S` and `f` is not unique. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure IsAdjoinRoot {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S] (f : R[X]) : Type max u v where map : R[X] →+* S map_surjective : Function.Surjective map ker_map : RingHom.ker map = Ideal.span {f} algebraMap_eq : algebraMap R S = map.comp Polynomial.C #align is_adjoin_root IsAdjoinRoot -- This class doesn't really make sense on a predicate /-- `IsAdjoinRootMonic S f` states that the ring `S` can be constructed by adjoining a specified root of the monic polynomial `f : R[X]` to `R`. As long as `f` is monic, there is a well-defined representation of elements of `S` as polynomials in `R[X]` of degree lower than `deg f` (see `modByMonicHom` and `coeff`). In particular, we have `IsAdjoinRootMonic.powerBasis`. Bundling `Monic` into this structure is very useful when working with explicit `f`s such as `X^2 - C a * X - C b` since it saves you carrying around the proofs of monicity. -/ -- @[nolint has_nonempty_instance] -- Porting note: This linter does not exist yet. structure IsAdjoinRootMonic {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S] (f : R[X]) extends IsAdjoinRoot S f where Monic : Monic f #align is_adjoin_root_monic IsAdjoinRootMonic section Ring variable {R : Type u} {S : Type v} [CommRing R] [Ring S] {f : R[X]} [Algebra R S] namespace IsAdjoinRoot /-- `(h : IsAdjoinRoot S f).root` is the root of `f` that can be adjoined to generate `S`. -/ def root (h : IsAdjoinRoot S f) : S := h.map X #align is_adjoin_root.root IsAdjoinRoot.root theorem subsingleton (h : IsAdjoinRoot S f) [Subsingleton R] : Subsingleton S := h.map_surjective.subsingleton #align is_adjoin_root.subsingleton IsAdjoinRoot.subsingleton theorem algebraMap_apply (h : IsAdjoinRoot S f) (x : R) : algebraMap R S x = h.map (Polynomial.C x) := by rw [h.algebraMap_eq, RingHom.comp_apply] #align is_adjoin_root.algebra_map_apply IsAdjoinRoot.algebraMap_apply @[simp] theorem mem_ker_map (h : IsAdjoinRoot S f) {p} : p ∈ RingHom.ker h.map ↔ f ∣ p := by rw [h.ker_map, Ideal.mem_span_singleton] #align is_adjoin_root.mem_ker_map IsAdjoinRoot.mem_ker_map theorem map_eq_zero_iff (h : IsAdjoinRoot S f) {p} : h.map p = 0 ↔ f ∣ p := by rw [← h.mem_ker_map, RingHom.mem_ker] #align is_adjoin_root.map_eq_zero_iff IsAdjoinRoot.map_eq_zero_iff @[simp] theorem map_X (h : IsAdjoinRoot S f) : h.map X = h.root := rfl set_option linter.uppercaseLean3 false in #align is_adjoin_root.map_X IsAdjoinRoot.map_X @[simp] theorem map_self (h : IsAdjoinRoot S f) : h.map f = 0 := h.map_eq_zero_iff.mpr dvd_rfl #align is_adjoin_root.map_self IsAdjoinRoot.map_self @[simp] theorem aeval_eq (h : IsAdjoinRoot S f) (p : R[X]) : aeval h.root p = h.map p := Polynomial.induction_on p (fun x => by rw [aeval_C, h.algebraMap_apply]) (fun p q ihp ihq => by rw [AlgHom.map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by rw [AlgHom.map_mul, aeval_C, AlgHom.map_pow, aeval_X, RingHom.map_mul, ← h.algebraMap_apply, RingHom.map_pow, map_X] #align is_adjoin_root.aeval_eq IsAdjoinRoot.aeval_eq -- @[simp] -- Porting note (#10618): simp can prove this theorem aeval_root (h : IsAdjoinRoot S f) : aeval h.root f = 0 := by rw [aeval_eq, map_self] #align is_adjoin_root.aeval_root IsAdjoinRoot.aeval_root /-- Choose an arbitrary representative so that `h.map (h.repr x) = x`. If `f` is monic, use `IsAdjoinRootMonic.modByMonicHom` for a unique choice of representative. -/ def repr (h : IsAdjoinRoot S f) (x : S) : R[X] := (h.map_surjective x).choose #align is_adjoin_root.repr IsAdjoinRoot.repr theorem map_repr (h : IsAdjoinRoot S f) (x : S) : h.map (h.repr x) = x := (h.map_surjective x).choose_spec #align is_adjoin_root.map_repr IsAdjoinRoot.map_repr /-- `repr` preserves zero, up to multiples of `f` -/ theorem repr_zero_mem_span (h : IsAdjoinRoot S f) : h.repr 0 ∈ Ideal.span ({f} : Set R[X]) := by rw [← h.ker_map, RingHom.mem_ker, h.map_repr] #align is_adjoin_root.repr_zero_mem_span IsAdjoinRoot.repr_zero_mem_span /-- `repr` preserves addition, up to multiples of `f` -/ theorem repr_add_sub_repr_add_repr_mem_span (h : IsAdjoinRoot S f) (x y : S) : h.repr (x + y) - (h.repr x + h.repr y) ∈ Ideal.span ({f} : Set R[X]) := by rw [← h.ker_map, RingHom.mem_ker, map_sub, h.map_repr, map_add, h.map_repr, h.map_repr, sub_self] #align is_adjoin_root.repr_add_sub_repr_add_repr_mem_span IsAdjoinRoot.repr_add_sub_repr_add_repr_mem_span /-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem` for extensionality of the ring elements. -/ theorem ext_map (h h' : IsAdjoinRoot S f) (eq : ∀ x, h.map x = h'.map x) : h = h' := by cases h; cases h'; congr exact RingHom.ext eq #align is_adjoin_root.ext_map IsAdjoinRoot.ext_map /-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem` for extensionality of the ring elements. -/ @[ext] theorem ext (h h' : IsAdjoinRoot S f) (eq : h.root = h'.root) : h = h' := h.ext_map h' fun x => by rw [← h.aeval_eq, ← h'.aeval_eq, eq] #align is_adjoin_root.ext IsAdjoinRoot.ext section lift variable {T : Type*} [CommRing T] {i : R →+* T} {x : T} (hx : f.eval₂ i x = 0) /-- Auxiliary lemma for `IsAdjoinRoot.lift` -/ theorem eval₂_repr_eq_eval₂_of_map_eq (h : IsAdjoinRoot S f) (z : S) (w : R[X]) (hzw : h.map w = z) : (h.repr z).eval₂ i x = w.eval₂ i x := by rw [eq_comm, ← sub_eq_zero, ← h.map_repr z, ← map_sub, h.map_eq_zero_iff] at hzw obtain ⟨y, hy⟩ := hzw rw [← sub_eq_zero, ← eval₂_sub, hy, eval₂_mul, hx, zero_mul] #align is_adjoin_root.eval₂_repr_eq_eval₂_of_map_eq IsAdjoinRoot.eval₂_repr_eq_eval₂_of_map_eq variable (i x) -- To match `AdjoinRoot.lift` /-- Lift a ring homomorphism `R →+* T` to `S →+* T` by specifying a root `x` of `f` in `T`, where `S` is given by adjoining a root of `f` to `R`. -/ def lift (h : IsAdjoinRoot S f) : S →+* T where toFun z := (h.repr z).eval₂ i x map_zero' := by dsimp only -- Porting note (#10752): added `dsimp only` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_zero _), eval₂_zero] map_add' z w := by dsimp only -- Porting note (#10752): added `dsimp only` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z + h.repr w), eval₂_add] rw [map_add, map_repr, map_repr] map_one' := by beta_reduce -- Porting note (#12129): additional beta reduction needed rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_one _), eval₂_one] map_mul' z w := by dsimp only -- Porting note (#10752): added `dsimp only` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z * h.repr w), eval₂_mul] rw [map_mul, map_repr, map_repr] #align is_adjoin_root.lift IsAdjoinRoot.lift variable {i x} @[simp] theorem lift_map (h : IsAdjoinRoot S f) (z : R[X]) : h.lift i x hx (h.map z) = z.eval₂ i x := by rw [lift, RingHom.coe_mk] dsimp -- Porting note (#11227):added a `dsimp` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ rfl] #align is_adjoin_root.lift_map IsAdjoinRoot.lift_map @[simp] theorem lift_root (h : IsAdjoinRoot S f) : h.lift i x hx h.root = x := by rw [← h.map_X, lift_map, eval₂_X] #align is_adjoin_root.lift_root IsAdjoinRoot.lift_root @[simp]
Mathlib/RingTheory/IsAdjoinRoot.lean
248
249
theorem lift_algebraMap (h : IsAdjoinRoot S f) (a : R) : h.lift i x hx (algebraMap R S a) = i a := by
rw [h.algebraMap_apply, lift_map, eval₂_C]
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Associated import Mathlib.Algebra.Ring.Regular import Mathlib.Tactic.Common #align_import algebra.gcd_monoid.basic from "leanprover-community/mathlib"@"550b58538991c8977703fdeb7c9d51a5aa27df11" /-! # Monoids with normalization functions, `gcd`, and `lcm` This file defines extra structures on `CancelCommMonoidWithZero`s, including `IsDomain`s. ## Main Definitions * `NormalizationMonoid` * `GCDMonoid` * `NormalizedGCDMonoid` * `gcdMonoid_of_gcd`, `gcdMonoid_of_exists_gcd`, `normalizedGCDMonoid_of_gcd`, `normalizedGCDMonoid_of_exists_gcd` * `gcdMonoid_of_lcm`, `gcdMonoid_of_exists_lcm`, `normalizedGCDMonoid_of_lcm`, `normalizedGCDMonoid_of_exists_lcm` For the `NormalizedGCDMonoid` instances on `ℕ` and `ℤ`, see `Mathlib.Algebra.GCDMonoid.Nat`. ## Implementation Notes * `NormalizationMonoid` is defined by assigning to each element a `normUnit` such that multiplying by that unit normalizes the monoid, and `normalize` is an idempotent monoid homomorphism. This definition as currently implemented does casework on `0`. * `GCDMonoid` contains the definitions of `gcd` and `lcm` with the usual properties. They are both determined up to a unit. * `NormalizedGCDMonoid` extends `NormalizationMonoid`, so the `gcd` and `lcm` are always normalized. This makes `gcd`s of polynomials easier to work with, but excludes Euclidean domains, and monoids without zero. * `gcdMonoid_of_gcd` and `normalizedGCDMonoid_of_gcd` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from the `gcd` and its properties. * `gcdMonoid_of_exists_gcd` and `normalizedGCDMonoid_of_exists_gcd` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements have a (not necessarily normalized) `gcd`. * `gcdMonoid_of_lcm` and `normalizedGCDMonoid_of_lcm` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from the `lcm` and its properties. * `gcdMonoid_of_exists_lcm` and `normalizedGCDMonoid_of_exists_lcm` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements have a (not necessarily normalized) `lcm`. ## TODO * Port GCD facts about nats, definition of coprime * Generalize normalization monoids to commutative (cancellative) monoids with or without zero ## Tags divisibility, gcd, lcm, normalize -/ variable {α : Type*} -- Porting note: mathlib3 had a `@[protect_proj]` here, but adding `protected` to all the fields -- adds unnecessary clutter to later code /-- Normalization monoid: multiplying with `normUnit` gives a normal form for associated elements. -/ class NormalizationMonoid (α : Type*) [CancelCommMonoidWithZero α] where /-- `normUnit` assigns to each element of the monoid a unit of the monoid. -/ normUnit : α → αˣ /-- The proposition that `normUnit` maps `0` to the identity. -/ normUnit_zero : normUnit 0 = 1 /-- The proposition that `normUnit` respects multiplication of non-zero elements. -/ normUnit_mul : ∀ {a b}, a ≠ 0 → b ≠ 0 → normUnit (a * b) = normUnit a * normUnit b /-- The proposition that `normUnit` maps units to their inverses. -/ normUnit_coe_units : ∀ u : αˣ, normUnit u = u⁻¹ #align normalization_monoid NormalizationMonoid export NormalizationMonoid (normUnit normUnit_zero normUnit_mul normUnit_coe_units) attribute [simp] normUnit_coe_units normUnit_zero normUnit_mul section NormalizationMonoid variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] @[simp] theorem normUnit_one : normUnit (1 : α) = 1 := normUnit_coe_units 1 #align norm_unit_one normUnit_one -- Porting note (#11083): quite slow. Improve performance? /-- Chooses an element of each associate class, by multiplying by `normUnit` -/ def normalize : α →*₀ α where toFun x := x * normUnit x map_zero' := by simp only [normUnit_zero] exact mul_one (0:α) map_one' := by dsimp only; rw [normUnit_one, one_mul]; rfl map_mul' x y := (by_cases fun hx : x = 0 => by dsimp only; rw [hx, zero_mul, zero_mul, zero_mul]) fun hx => (by_cases fun hy : y = 0 => by dsimp only; rw [hy, mul_zero, zero_mul, mul_zero]) fun hy => by simp only [normUnit_mul hx hy, Units.val_mul]; simp only [mul_assoc, mul_left_comm y] #align normalize normalize theorem associated_normalize (x : α) : Associated x (normalize x) := ⟨_, rfl⟩ #align associated_normalize associated_normalize theorem normalize_associated (x : α) : Associated (normalize x) x := (associated_normalize _).symm #align normalize_associated normalize_associated theorem associated_normalize_iff {x y : α} : Associated x (normalize y) ↔ Associated x y := ⟨fun h => h.trans (normalize_associated y), fun h => h.trans (associated_normalize y)⟩ #align associated_normalize_iff associated_normalize_iff theorem normalize_associated_iff {x y : α} : Associated (normalize x) y ↔ Associated x y := ⟨fun h => (associated_normalize _).trans h, fun h => (normalize_associated _).trans h⟩ #align normalize_associated_iff normalize_associated_iff theorem Associates.mk_normalize (x : α) : Associates.mk (normalize x) = Associates.mk x := Associates.mk_eq_mk_iff_associated.2 (normalize_associated _) #align associates.mk_normalize Associates.mk_normalize @[simp] theorem normalize_apply (x : α) : normalize x = x * normUnit x := rfl #align normalize_apply normalize_apply -- Porting note (#10618): `simp` can prove this -- @[simp] theorem normalize_zero : normalize (0 : α) = 0 := normalize.map_zero #align normalize_zero normalize_zero -- Porting note (#10618): `simp` can prove this -- @[simp] theorem normalize_one : normalize (1 : α) = 1 := normalize.map_one #align normalize_one normalize_one theorem normalize_coe_units (u : αˣ) : normalize (u : α) = 1 := by simp #align normalize_coe_units normalize_coe_units theorem normalize_eq_zero {x : α} : normalize x = 0 ↔ x = 0 := ⟨fun hx => (associated_zero_iff_eq_zero x).1 <| hx ▸ associated_normalize _, by rintro rfl; exact normalize_zero⟩ #align normalize_eq_zero normalize_eq_zero theorem normalize_eq_one {x : α} : normalize x = 1 ↔ IsUnit x := ⟨fun hx => isUnit_iff_exists_inv.2 ⟨_, hx⟩, fun ⟨u, hu⟩ => hu ▸ normalize_coe_units u⟩ #align normalize_eq_one normalize_eq_one -- Porting note (#11083): quite slow. Improve performance? @[simp] theorem normUnit_mul_normUnit (a : α) : normUnit (a * normUnit a) = 1 := by nontriviality α using Subsingleton.elim a 0 obtain rfl | h := eq_or_ne a 0 · rw [normUnit_zero, zero_mul, normUnit_zero] · rw [normUnit_mul h (Units.ne_zero _), normUnit_coe_units, mul_inv_eq_one] #align norm_unit_mul_norm_unit normUnit_mul_normUnit theorem normalize_idem (x : α) : normalize (normalize x) = normalize x := by simp #align normalize_idem normalize_idem theorem normalize_eq_normalize {a b : α} (hab : a ∣ b) (hba : b ∣ a) : normalize a = normalize b := by nontriviality α rcases associated_of_dvd_dvd hab hba with ⟨u, rfl⟩ refine by_cases (by rintro rfl; simp only [zero_mul]) fun ha : a ≠ 0 => ?_ suffices a * ↑(normUnit a) = a * ↑u * ↑(normUnit a) * ↑u⁻¹ by simpa only [normalize_apply, mul_assoc, normUnit_mul ha u.ne_zero, normUnit_coe_units] calc a * ↑(normUnit a) = a * ↑(normUnit a) * ↑u * ↑u⁻¹ := (Units.mul_inv_cancel_right _ _).symm _ = a * ↑u * ↑(normUnit a) * ↑u⁻¹ := by rw [mul_right_comm a] #align normalize_eq_normalize normalize_eq_normalize theorem normalize_eq_normalize_iff {x y : α} : normalize x = normalize y ↔ x ∣ y ∧ y ∣ x := ⟨fun h => ⟨Units.dvd_mul_right.1 ⟨_, h.symm⟩, Units.dvd_mul_right.1 ⟨_, h⟩⟩, fun ⟨hxy, hyx⟩ => normalize_eq_normalize hxy hyx⟩ #align normalize_eq_normalize_iff normalize_eq_normalize_iff theorem dvd_antisymm_of_normalize_eq {a b : α} (ha : normalize a = a) (hb : normalize b = b) (hab : a ∣ b) (hba : b ∣ a) : a = b := ha ▸ hb ▸ normalize_eq_normalize hab hba #align dvd_antisymm_of_normalize_eq dvd_antisymm_of_normalize_eq theorem Associated.eq_of_normalized {a b : α} (h : Associated a b) (ha : normalize a = a) (hb : normalize b = b) : a = b := dvd_antisymm_of_normalize_eq ha hb h.dvd h.dvd' --can be proven by simp theorem dvd_normalize_iff {a b : α} : a ∣ normalize b ↔ a ∣ b := Units.dvd_mul_right #align dvd_normalize_iff dvd_normalize_iff --can be proven by simp theorem normalize_dvd_iff {a b : α} : normalize a ∣ b ↔ a ∣ b := Units.mul_right_dvd #align normalize_dvd_iff normalize_dvd_iff end NormalizationMonoid namespace Associates variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] /-- Maps an element of `Associates` back to the normalized element of its associate class -/ protected def out : Associates α → α := (Quotient.lift (normalize : α → α)) fun a _ ⟨_, hu⟩ => hu ▸ normalize_eq_normalize ⟨_, rfl⟩ (Units.mul_right_dvd.2 <| dvd_refl a) #align associates.out Associates.out @[simp] theorem out_mk (a : α) : (Associates.mk a).out = normalize a := rfl #align associates.out_mk Associates.out_mk @[simp] theorem out_one : (1 : Associates α).out = 1 := normalize_one #align associates.out_one Associates.out_one theorem out_mul (a b : Associates α) : (a * b).out = a.out * b.out := Quotient.inductionOn₂ a b fun _ _ => by simp only [Associates.quotient_mk_eq_mk, out_mk, mk_mul_mk, normalize.map_mul] #align associates.out_mul Associates.out_mul theorem dvd_out_iff (a : α) (b : Associates α) : a ∣ b.out ↔ Associates.mk a ≤ b := Quotient.inductionOn b <| by simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd] #align associates.dvd_out_iff Associates.dvd_out_iff theorem out_dvd_iff (a : α) (b : Associates α) : b.out ∣ a ↔ b ≤ Associates.mk a := Quotient.inductionOn b <| by simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd] #align associates.out_dvd_iff Associates.out_dvd_iff @[simp] theorem out_top : (⊤ : Associates α).out = 0 := normalize_zero #align associates.out_top Associates.out_top -- Porting note: lower priority to avoid linter complaints about simp-normal form @[simp 1100] theorem normalize_out (a : Associates α) : normalize a.out = a.out := Quotient.inductionOn a normalize_idem #align associates.normalize_out Associates.normalize_out @[simp] theorem mk_out (a : Associates α) : Associates.mk a.out = a := Quotient.inductionOn a mk_normalize #align associates.mk_out Associates.mk_out theorem out_injective : Function.Injective (Associates.out : _ → α) := Function.LeftInverse.injective mk_out #align associates.out_injective Associates.out_injective end Associates -- Porting note: mathlib3 had a `@[protect_proj]` here, but adding `protected` to all the fields -- adds unnecessary clutter to later code /-- GCD monoid: a `CancelCommMonoidWithZero` with `gcd` (greatest common divisor) and `lcm` (least common multiple) operations, determined up to a unit. The type class focuses on `gcd` and we derive the corresponding `lcm` facts from `gcd`. -/ class GCDMonoid (α : Type*) [CancelCommMonoidWithZero α] where /-- The greatest common divisor between two elements. -/ gcd : α → α → α /-- The least common multiple between two elements. -/ lcm : α → α → α /-- The GCD is a divisor of the first element. -/ gcd_dvd_left : ∀ a b, gcd a b ∣ a /-- The GCD is a divisor of the second element. -/ gcd_dvd_right : ∀ a b, gcd a b ∣ b /-- Any common divisor of both elements is a divisor of the GCD. -/ dvd_gcd : ∀ {a b c}, a ∣ c → a ∣ b → a ∣ gcd c b /-- The product of two elements is `Associated` with the product of their GCD and LCM. -/ gcd_mul_lcm : ∀ a b, Associated (gcd a b * lcm a b) (a * b) /-- `0` is left-absorbing. -/ lcm_zero_left : ∀ a, lcm 0 a = 0 /-- `0` is right-absorbing. -/ lcm_zero_right : ∀ a, lcm a 0 = 0 #align gcd_monoid GCDMonoid /-- Normalized GCD monoid: a `CancelCommMonoidWithZero` with normalization and `gcd` (greatest common divisor) and `lcm` (least common multiple) operations. In this setting `gcd` and `lcm` form a bounded lattice on the associated elements where `gcd` is the infimum, `lcm` is the supremum, `1` is bottom, and `0` is top. The type class focuses on `gcd` and we derive the corresponding `lcm` facts from `gcd`. -/ class NormalizedGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] extends NormalizationMonoid α, GCDMonoid α where /-- The GCD is normalized to itself. -/ normalize_gcd : ∀ a b, normalize (gcd a b) = gcd a b /-- The LCM is normalized to itself. -/ normalize_lcm : ∀ a b, normalize (lcm a b) = lcm a b #align normalized_gcd_monoid NormalizedGCDMonoid export GCDMonoid (gcd lcm gcd_dvd_left gcd_dvd_right dvd_gcd lcm_zero_left lcm_zero_right) attribute [simp] lcm_zero_left lcm_zero_right section GCDMonoid variable [CancelCommMonoidWithZero α] instance [NormalizationMonoid α] : Nonempty (NormalizationMonoid α) := ⟨‹_›⟩ instance [GCDMonoid α] : Nonempty (GCDMonoid α) := ⟨‹_›⟩ instance [NormalizedGCDMonoid α] : Nonempty (NormalizedGCDMonoid α) := ⟨‹_›⟩ instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (NormalizationMonoid α) := h.elim fun _ ↦ inferInstance instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (GCDMonoid α) := h.elim fun _ ↦ inferInstance theorem gcd_isUnit_iff_isRelPrime [GCDMonoid α] {a b : α} : IsUnit (gcd a b) ↔ IsRelPrime a b := ⟨fun h _ ha hb ↦ isUnit_of_dvd_unit (dvd_gcd ha hb) h, (· (gcd_dvd_left a b) (gcd_dvd_right a b))⟩ -- Porting note: lower priority to avoid linter complaints about simp-normal form @[simp 1100] theorem normalize_gcd [NormalizedGCDMonoid α] : ∀ a b : α, normalize (gcd a b) = gcd a b := NormalizedGCDMonoid.normalize_gcd #align normalize_gcd normalize_gcd theorem gcd_mul_lcm [GCDMonoid α] : ∀ a b : α, Associated (gcd a b * lcm a b) (a * b) := GCDMonoid.gcd_mul_lcm #align gcd_mul_lcm gcd_mul_lcm section GCD theorem dvd_gcd_iff [GCDMonoid α] (a b c : α) : a ∣ gcd b c ↔ a ∣ b ∧ a ∣ c := Iff.intro (fun h => ⟨h.trans (gcd_dvd_left _ _), h.trans (gcd_dvd_right _ _)⟩) fun ⟨hab, hac⟩ => dvd_gcd hab hac #align dvd_gcd_iff dvd_gcd_iff theorem gcd_comm [NormalizedGCDMonoid α] (a b : α) : gcd a b = gcd b a := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) #align gcd_comm gcd_comm theorem gcd_comm' [GCDMonoid α] (a b : α) : Associated (gcd a b) (gcd b a) := associated_of_dvd_dvd (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) #align gcd_comm' gcd_comm' theorem gcd_assoc [NormalizedGCDMonoid α] (m n k : α) : gcd (gcd m n) k = gcd m (gcd n k) := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n)) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k))) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k))) #align gcd_assoc gcd_assoc theorem gcd_assoc' [GCDMonoid α] (m n k : α) : Associated (gcd (gcd m n) k) (gcd m (gcd n k)) := associated_of_dvd_dvd (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n)) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k))) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k))) #align gcd_assoc' gcd_assoc' instance [NormalizedGCDMonoid α] : Std.Commutative (α := α) gcd where comm := gcd_comm instance [NormalizedGCDMonoid α] : Std.Associative (α := α) gcd where assoc := gcd_assoc theorem gcd_eq_normalize [NormalizedGCDMonoid α] {a b c : α} (habc : gcd a b ∣ c) (hcab : c ∣ gcd a b) : gcd a b = normalize c := normalize_gcd a b ▸ normalize_eq_normalize habc hcab #align gcd_eq_normalize gcd_eq_normalize @[simp] theorem gcd_zero_left [NormalizedGCDMonoid α] (a : α) : gcd 0 a = normalize a := gcd_eq_normalize (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a)) #align gcd_zero_left gcd_zero_left theorem gcd_zero_left' [GCDMonoid α] (a : α) : Associated (gcd 0 a) a := associated_of_dvd_dvd (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a)) #align gcd_zero_left' gcd_zero_left' @[simp] theorem gcd_zero_right [NormalizedGCDMonoid α] (a : α) : gcd a 0 = normalize a := gcd_eq_normalize (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _)) #align gcd_zero_right gcd_zero_right theorem gcd_zero_right' [GCDMonoid α] (a : α) : Associated (gcd a 0) a := associated_of_dvd_dvd (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _)) #align gcd_zero_right' gcd_zero_right' @[simp] theorem gcd_eq_zero_iff [GCDMonoid α] (a b : α) : gcd a b = 0 ↔ a = 0 ∧ b = 0 := Iff.intro (fun h => by let ⟨ca, ha⟩ := gcd_dvd_left a b let ⟨cb, hb⟩ := gcd_dvd_right a b rw [h, zero_mul] at ha hb exact ⟨ha, hb⟩) fun ⟨ha, hb⟩ => by rw [ha, hb, ← zero_dvd_iff] apply dvd_gcd <;> rfl #align gcd_eq_zero_iff gcd_eq_zero_iff @[simp] theorem gcd_one_left [NormalizedGCDMonoid α] (a : α) : gcd 1 a = 1 := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_left _ _) (one_dvd _) #align gcd_one_left gcd_one_left @[simp] theorem isUnit_gcd_one_left [GCDMonoid α] (a : α) : IsUnit (gcd 1 a) := isUnit_of_dvd_one (gcd_dvd_left _ _) theorem gcd_one_left' [GCDMonoid α] (a : α) : Associated (gcd 1 a) 1 := by simp #align gcd_one_left' gcd_one_left' @[simp] theorem gcd_one_right [NormalizedGCDMonoid α] (a : α) : gcd a 1 = 1 := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_right _ _) (one_dvd _) #align gcd_one_right gcd_one_right @[simp] theorem isUnit_gcd_one_right [GCDMonoid α] (a : α) : IsUnit (gcd a 1) := isUnit_of_dvd_one (gcd_dvd_right _ _) theorem gcd_one_right' [GCDMonoid α] (a : α) : Associated (gcd a 1) 1 := by simp #align gcd_one_right' gcd_one_right' theorem gcd_dvd_gcd [GCDMonoid α] {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d) : gcd a c ∣ gcd b d := dvd_gcd ((gcd_dvd_left _ _).trans hab) ((gcd_dvd_right _ _).trans hcd) #align gcd_dvd_gcd gcd_dvd_gcd protected theorem Associated.gcd [GCDMonoid α] {a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) : Associated (gcd a₁ b₁) (gcd a₂ b₂) := associated_of_dvd_dvd (gcd_dvd_gcd ha.dvd hb.dvd) (gcd_dvd_gcd ha.dvd' hb.dvd') @[simp] theorem gcd_same [NormalizedGCDMonoid α] (a : α) : gcd a a = normalize a := gcd_eq_normalize (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) (dvd_refl a)) #align gcd_same gcd_same @[simp] theorem gcd_mul_left [NormalizedGCDMonoid α] (a b c : α) : gcd (a * b) (a * c) = normalize a * gcd b c := (by_cases (by rintro rfl; simp only [zero_mul, gcd_zero_left, normalize_zero])) fun ha : a ≠ 0 => suffices gcd (a * b) (a * c) = normalize (a * gcd b c) by simpa let ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c) gcd_eq_normalize (eq.symm ▸ mul_dvd_mul_left a (show d ∣ gcd b c from dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _) ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _))) (dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _)) #align gcd_mul_left gcd_mul_left theorem gcd_mul_left' [GCDMonoid α] (a b c : α) : Associated (gcd (a * b) (a * c)) (a * gcd b c) := by obtain rfl | ha := eq_or_ne a 0 · simp only [zero_mul, gcd_zero_left'] obtain ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c) apply associated_of_dvd_dvd · rw [eq] apply mul_dvd_mul_left exact dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _) ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _) · exact dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _) #align gcd_mul_left' gcd_mul_left' @[simp] theorem gcd_mul_right [NormalizedGCDMonoid α] (a b c : α) : gcd (b * a) (c * a) = gcd b c * normalize a := by simp only [mul_comm, gcd_mul_left] #align gcd_mul_right gcd_mul_right @[simp] theorem gcd_mul_right' [GCDMonoid α] (a b c : α) : Associated (gcd (b * a) (c * a)) (gcd b c * a) := by simp only [mul_comm, gcd_mul_left'] #align gcd_mul_right' gcd_mul_right' theorem gcd_eq_left_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize a = a) : gcd a b = a ↔ a ∣ b := (Iff.intro fun eq => eq ▸ gcd_dvd_right _ _) fun hab => dvd_antisymm_of_normalize_eq (normalize_gcd _ _) h (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) hab) #align gcd_eq_left_iff gcd_eq_left_iff theorem gcd_eq_right_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize b = b) : gcd a b = b ↔ b ∣ a := by simpa only [gcd_comm a b] using gcd_eq_left_iff b a h #align gcd_eq_right_iff gcd_eq_right_iff theorem gcd_dvd_gcd_mul_left [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (k * m) n := gcd_dvd_gcd (dvd_mul_left _ _) dvd_rfl #align gcd_dvd_gcd_mul_left gcd_dvd_gcd_mul_left theorem gcd_dvd_gcd_mul_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (m * k) n := gcd_dvd_gcd (dvd_mul_right _ _) dvd_rfl #align gcd_dvd_gcd_mul_right gcd_dvd_gcd_mul_right theorem gcd_dvd_gcd_mul_left_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (k * n) := gcd_dvd_gcd dvd_rfl (dvd_mul_left _ _) #align gcd_dvd_gcd_mul_left_right gcd_dvd_gcd_mul_left_right theorem gcd_dvd_gcd_mul_right_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (n * k) := gcd_dvd_gcd dvd_rfl (dvd_mul_right _ _) #align gcd_dvd_gcd_mul_right_right gcd_dvd_gcd_mul_right_right theorem Associated.gcd_eq_left [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) : gcd m k = gcd n k := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd h.dvd dvd_rfl) (gcd_dvd_gcd h.symm.dvd dvd_rfl) #align associated.gcd_eq_left Associated.gcd_eq_left theorem Associated.gcd_eq_right [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) : gcd k m = gcd k n := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd dvd_rfl h.dvd) (gcd_dvd_gcd dvd_rfl h.symm.dvd) #align associated.gcd_eq_right Associated.gcd_eq_right theorem dvd_gcd_mul_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ gcd k m * n := (dvd_gcd (dvd_mul_right _ n) H).trans (gcd_mul_right' n k m).dvd #align dvd_gcd_mul_of_dvd_mul dvd_gcd_mul_of_dvd_mul theorem dvd_gcd_mul_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ gcd k m * n ↔ k ∣ m * n := ⟨fun h => h.trans (mul_dvd_mul (gcd_dvd_right k m) dvd_rfl), dvd_gcd_mul_of_dvd_mul⟩ theorem dvd_mul_gcd_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ m * gcd k n := by rw [mul_comm] at H ⊢ exact dvd_gcd_mul_of_dvd_mul H #align dvd_mul_gcd_of_dvd_mul dvd_mul_gcd_of_dvd_mul theorem dvd_mul_gcd_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ m * gcd k n ↔ k ∣ m * n := ⟨fun h => h.trans (mul_dvd_mul dvd_rfl (gcd_dvd_right k n)), dvd_mul_gcd_of_dvd_mul⟩ /-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`. Note: In general, this representation is highly non-unique. See `Nat.prodDvdAndDvdOfDvdProd` for a constructive version on `ℕ`. -/ instance [h : Nonempty (GCDMonoid α)] : DecompositionMonoid α where primal k m n H := by cases h by_cases h0 : gcd k m = 0 · rw [gcd_eq_zero_iff] at h0 rcases h0 with ⟨rfl, rfl⟩ exact ⟨0, n, dvd_refl 0, dvd_refl n, by simp⟩ · obtain ⟨a, ha⟩ := gcd_dvd_left k m refine ⟨gcd k m, a, gcd_dvd_right _ _, ?_, ha⟩ rw [← mul_dvd_mul_iff_left h0, ← ha] exact dvd_gcd_mul_of_dvd_mul H theorem gcd_mul_dvd_mul_gcd [GCDMonoid α] (k m n : α) : gcd k (m * n) ∣ gcd k m * gcd k n := by obtain ⟨m', n', hm', hn', h⟩ := exists_dvd_and_dvd_of_dvd_mul (gcd_dvd_right k (m * n)) replace h : gcd k (m * n) = m' * n' := h rw [h] have hm'n' : m' * n' ∣ k := h ▸ gcd_dvd_left _ _ apply mul_dvd_mul · have hm'k : m' ∣ k := (dvd_mul_right m' n').trans hm'n' exact dvd_gcd hm'k hm' · have hn'k : n' ∣ k := (dvd_mul_left n' m').trans hm'n' exact dvd_gcd hn'k hn' #align gcd_mul_dvd_mul_gcd gcd_mul_dvd_mul_gcd theorem gcd_pow_right_dvd_pow_gcd [GCDMonoid α] {a b : α} {k : ℕ} : gcd a (b ^ k) ∣ gcd a b ^ k := by by_cases hg : gcd a b = 0 · rw [gcd_eq_zero_iff] at hg rcases hg with ⟨rfl, rfl⟩ exact (gcd_zero_left' (0 ^ k : α)).dvd.trans (pow_dvd_pow_of_dvd (gcd_zero_left' (0 : α)).symm.dvd _) · induction' k with k hk · rw [pow_zero, pow_zero] exact (gcd_one_right' a).dvd rw [pow_succ', pow_succ'] trans gcd a b * gcd a (b ^ k) · exact gcd_mul_dvd_mul_gcd a b (b ^ k) · exact (mul_dvd_mul_iff_left hg).mpr hk #align gcd_pow_right_dvd_pow_gcd gcd_pow_right_dvd_pow_gcd theorem gcd_pow_left_dvd_pow_gcd [GCDMonoid α] {a b : α} {k : ℕ} : gcd (a ^ k) b ∣ gcd a b ^ k := calc gcd (a ^ k) b ∣ gcd b (a ^ k) := (gcd_comm' _ _).dvd _ ∣ gcd b a ^ k := gcd_pow_right_dvd_pow_gcd _ ∣ gcd a b ^ k := pow_dvd_pow_of_dvd (gcd_comm' _ _).dvd _ #align gcd_pow_left_dvd_pow_gcd gcd_pow_left_dvd_pow_gcd theorem pow_dvd_of_mul_eq_pow [GCDMonoid α] {a b c d₁ d₂ : α} (ha : a ≠ 0) (hab : IsUnit (gcd a b)) {k : ℕ} (h : a * b = c ^ k) (hc : c = d₁ * d₂) (hd₁ : d₁ ∣ a) : d₁ ^ k ≠ 0 ∧ d₁ ^ k ∣ a := by have h1 : IsUnit (gcd (d₁ ^ k) b) := by apply isUnit_of_dvd_one trans gcd d₁ b ^ k · exact gcd_pow_left_dvd_pow_gcd · apply IsUnit.dvd apply IsUnit.pow apply isUnit_of_dvd_one apply dvd_trans _ hab.dvd apply gcd_dvd_gcd hd₁ (dvd_refl b) have h2 : d₁ ^ k ∣ a * b := by use d₂ ^ k rw [h, hc] exact mul_pow d₁ d₂ k rw [mul_comm] at h2 have h3 : d₁ ^ k ∣ a := by apply (dvd_gcd_mul_of_dvd_mul h2).trans rw [h1.mul_left_dvd] have h4 : d₁ ^ k ≠ 0 := by intro hdk rw [hdk] at h3 apply absurd (zero_dvd_iff.mp h3) ha exact ⟨h4, h3⟩ #align pow_dvd_of_mul_eq_pow pow_dvd_of_mul_eq_pow theorem exists_associated_pow_of_mul_eq_pow [GCDMonoid α] {a b c : α} (hab : IsUnit (gcd a b)) {k : ℕ} (h : a * b = c ^ k) : ∃ d : α, Associated (d ^ k) a := by cases subsingleton_or_nontrivial α · use 0 rw [Subsingleton.elim a (0 ^ k)] by_cases ha : a = 0 · use 0 obtain rfl | hk := eq_or_ne k 0 · simp [ha] at h · rw [ha, zero_pow hk] by_cases hb : b = 0 · use 1 rw [one_pow] apply (associated_one_iff_isUnit.mpr hab).symm.trans rw [hb] exact gcd_zero_right' a obtain rfl | hk := k.eq_zero_or_pos · use 1 rw [pow_zero] at h ⊢ use Units.mkOfMulEqOne _ _ h rw [Units.val_mkOfMulEqOne, one_mul] have hc : c ∣ a * b := by rw [h] exact dvd_pow_self _ hk.ne' obtain ⟨d₁, d₂, hd₁, hd₂, hc⟩ := exists_dvd_and_dvd_of_dvd_mul hc use d₁ obtain ⟨h0₁, ⟨a', ha'⟩⟩ := pow_dvd_of_mul_eq_pow ha hab h hc hd₁ rw [mul_comm] at h hc rw [(gcd_comm' a b).isUnit_iff] at hab obtain ⟨h0₂, ⟨b', hb'⟩⟩ := pow_dvd_of_mul_eq_pow hb hab h hc hd₂ rw [ha', hb', hc, mul_pow] at h have h' : a' * b' = 1 := by apply (mul_right_inj' h0₁).mp rw [mul_one] apply (mul_right_inj' h0₂).mp rw [← h] rw [mul_assoc, mul_comm a', ← mul_assoc _ b', ← mul_assoc b', mul_comm b'] use Units.mkOfMulEqOne _ _ h' rw [Units.val_mkOfMulEqOne, ha'] #align exists_associated_pow_of_mul_eq_pow exists_associated_pow_of_mul_eq_pow theorem exists_eq_pow_of_mul_eq_pow [GCDMonoid α] [Unique αˣ] {a b c : α} (hab : IsUnit (gcd a b)) {k : ℕ} (h : a * b = c ^ k) : ∃ d : α, a = d ^ k := let ⟨d, hd⟩ := exists_associated_pow_of_mul_eq_pow hab h ⟨d, (associated_iff_eq.mp hd).symm⟩ #align exists_eq_pow_of_mul_eq_pow exists_eq_pow_of_mul_eq_pow theorem gcd_greatest {α : Type*} [CancelCommMonoidWithZero α] [NormalizedGCDMonoid α] {a b d : α} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : α, e ∣ a → e ∣ b → e ∣ d) : GCDMonoid.gcd a b = normalize d := haveI h := hd _ (GCDMonoid.gcd_dvd_left a b) (GCDMonoid.gcd_dvd_right a b) gcd_eq_normalize h (GCDMonoid.dvd_gcd hda hdb) #align gcd_greatest gcd_greatest theorem gcd_greatest_associated {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α] {a b d : α} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : α, e ∣ a → e ∣ b → e ∣ d) : Associated d (GCDMonoid.gcd a b) := haveI h := hd _ (GCDMonoid.gcd_dvd_left a b) (GCDMonoid.gcd_dvd_right a b) associated_of_dvd_dvd (GCDMonoid.dvd_gcd hda hdb) h #align gcd_greatest_associated gcd_greatest_associated theorem isUnit_gcd_of_eq_mul_gcd {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α] {x y x' y' : α} (ex : x = gcd x y * x') (ey : y = gcd x y * y') (h : gcd x y ≠ 0) : IsUnit (gcd x' y') := by rw [← associated_one_iff_isUnit] refine Associated.of_mul_left ?_ (Associated.refl <| gcd x y) h convert (gcd_mul_left' (gcd x y) x' y').symm using 1 rw [← ex, ← ey, mul_one] #align is_unit_gcd_of_eq_mul_gcd isUnit_gcd_of_eq_mul_gcd theorem extract_gcd {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α] (x y : α) : ∃ x' y', x = gcd x y * x' ∧ y = gcd x y * y' ∧ IsUnit (gcd x' y') := by by_cases h : gcd x y = 0 · obtain ⟨rfl, rfl⟩ := (gcd_eq_zero_iff x y).1 h simp_rw [← associated_one_iff_isUnit] exact ⟨1, 1, by rw [h, zero_mul], by rw [h, zero_mul], gcd_one_left' 1⟩ obtain ⟨x', ex⟩ := gcd_dvd_left x y obtain ⟨y', ey⟩ := gcd_dvd_right x y exact ⟨x', y', ex, ey, isUnit_gcd_of_eq_mul_gcd ex ey h⟩ #align extract_gcd extract_gcd theorem associated_gcd_left_iff [GCDMonoid α] {x y : α} : Associated x (gcd x y) ↔ x ∣ y := ⟨fun hx => hx.dvd.trans (gcd_dvd_right x y), fun hxy => associated_of_dvd_dvd (dvd_gcd dvd_rfl hxy) (gcd_dvd_left x y)⟩ theorem associated_gcd_right_iff [GCDMonoid α] {x y : α} : Associated y (gcd x y) ↔ y ∣ x := ⟨fun hx => hx.dvd.trans (gcd_dvd_left x y), fun hxy => associated_of_dvd_dvd (dvd_gcd hxy dvd_rfl) (gcd_dvd_right x y)⟩ theorem Irreducible.isUnit_gcd_iff [GCDMonoid α] {x y : α} (hx : Irreducible x) : IsUnit (gcd x y) ↔ ¬(x ∣ y) := by rw [hx.isUnit_iff_not_associated_of_dvd (gcd_dvd_left x y), not_iff_not, associated_gcd_left_iff] theorem Irreducible.gcd_eq_one_iff [NormalizedGCDMonoid α] {x y : α} (hx : Irreducible x) : gcd x y = 1 ↔ ¬(x ∣ y) := by rw [← hx.isUnit_gcd_iff, ← normalize_eq_one, NormalizedGCDMonoid.normalize_gcd] section Neg variable [HasDistribNeg α] lemma gcd_neg' [GCDMonoid α] {a b : α} : Associated (gcd a (-b)) (gcd a b) := Associated.gcd .rfl (.neg_left .rfl) lemma gcd_neg [NormalizedGCDMonoid α] {a b : α} : gcd a (-b) = gcd a b := gcd_neg'.eq_of_normalized (normalize_gcd _ _) (normalize_gcd _ _) lemma neg_gcd' [GCDMonoid α] {a b : α} : Associated (gcd (-a) b) (gcd a b) := Associated.gcd (.neg_left .rfl) .rfl lemma neg_gcd [NormalizedGCDMonoid α] {a b : α} : gcd (-a) b = gcd a b := neg_gcd'.eq_of_normalized (normalize_gcd _ _) (normalize_gcd _ _) end Neg end GCD section LCM
Mathlib/Algebra/GCDMonoid/Basic.lean
744
753
theorem lcm_dvd_iff [GCDMonoid α] {a b c : α} : lcm a b ∣ c ↔ a ∣ c ∧ b ∣ c := by
by_cases h : a = 0 ∨ b = 0 · rcases h with (rfl | rfl) <;> simp (config := { contextual := true }) only [iff_def, lcm_zero_left, lcm_zero_right, zero_dvd_iff, dvd_zero, eq_self_iff_true, and_true_iff, imp_true_iff] · obtain ⟨h1, h2⟩ := not_or.1 h have h : gcd a b ≠ 0 := fun H => h1 ((gcd_eq_zero_iff _ _).1 H).1 rw [← mul_dvd_mul_iff_left h, (gcd_mul_lcm a b).dvd_iff_dvd_left, ← (gcd_mul_right' c a b).dvd_iff_dvd_right, dvd_gcd_iff, mul_comm b c, mul_dvd_mul_iff_left h1, mul_dvd_mul_iff_right h2, and_comm]
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Eric Rodriguez -/ import Mathlib.Algebra.Order.Field.Basic import Mathlib.Data.Nat.Cast.Order import Mathlib.Data.Nat.Choose.Basic import Mathlib.Data.Nat.Cast.Order #align_import data.nat.choose.bounds from "leanprover-community/mathlib"@"550b58538991c8977703fdeb7c9d51a5aa27df11" /-! # Inequalities for binomial coefficients This file proves exponential bounds on binomial coefficients. We might want to add here the bounds `n^r/r^r ≤ n.choose r ≤ e^r n^r/r^r` in the future. ## Main declarations * `Nat.choose_le_pow`: `n.choose r ≤ n^r / r!` * `Nat.pow_le_choose`: `(n + 1 - r)^r / r! ≤ n.choose r`. Beware of the fishy ℕ-subtraction. -/ open Nat variable {α : Type*} [LinearOrderedSemifield α] namespace Nat
Mathlib/Data/Nat/Choose/Bounds.lean
32
37
theorem choose_le_pow (r n : ℕ) : (n.choose r : α) ≤ (n ^ r : α) / r ! := by
rw [le_div_iff'] · norm_cast rw [← Nat.descFactorial_eq_factorial_mul_choose] exact n.descFactorial_le_pow r exact mod_cast r.factorial_pos
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland -/ import Mathlib.Tactic.Ring import Mathlib.Data.PNat.Prime #align_import data.pnat.xgcd from "leanprover-community/mathlib"@"6afc9b06856ad973f6a2619e3e8a0a8d537a58f2" /-! # Euclidean algorithm for ℕ This file sets up a version of the Euclidean algorithm that only works with natural numbers. Given `0 < a, b`, it computes the unique `(w, x, y, z, d)` such that the following identities hold: * `a = (w + x) d` * `b = (y + z) d` * `w * z = x * y + 1` `d` is then the gcd of `a` and `b`, and `a' := a / d = w + x` and `b' := b / d = y + z` are coprime. This story is closely related to the structure of SL₂(ℕ) (as a free monoid on two generators) and the theory of continued fractions. ## Main declarations * `XgcdType`: Helper type in defining the gcd. Encapsulates `(wp, x, y, zp, ap, bp)`. where `wp` `zp`, `ap`, `bp` are the variables getting changed through the algorithm. * `IsSpecial`: States `wp * zp = x * y + 1` * `IsReduced`: States `ap = a ∧ bp = b` ## Notes See `Nat.Xgcd` for a very similar algorithm allowing values in `ℤ`. -/ open Nat namespace PNat /-- A term of `XgcdType` is a system of six naturals. They should be thought of as representing the matrix [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]] together with the vector [a, b] = [ap + 1, bp + 1]. -/ structure XgcdType where /-- `wp` is a variable which changes through the algorithm. -/ wp : ℕ /-- `x` satisfies `a / d = w + x` at the final step. -/ x : ℕ /-- `y` satisfies `b / d = z + y` at the final step. -/ y : ℕ /-- `zp` is a variable which changes through the algorithm. -/ zp : ℕ /-- `ap` is a variable which changes through the algorithm. -/ ap : ℕ /-- `bp` is a variable which changes through the algorithm. -/ bp : ℕ deriving Inhabited #align pnat.xgcd_type PNat.XgcdType namespace XgcdType variable (u : XgcdType) instance : SizeOf XgcdType := ⟨fun u => u.bp⟩ /-- The `Repr` instance converts terms to strings in a way that reflects the matrix/vector interpretation as above. -/ instance : Repr XgcdType where reprPrec | g, _ => s!"[[[{repr (g.wp + 1)}, {repr g.x}], \ [{repr g.y}, {repr (g.zp + 1)}]], \ [{repr (g.ap + 1)}, {repr (g.bp + 1)}]]" /-- Another `mk` using ℕ and ℕ+ -/ def mk' (w : ℕ+) (x : ℕ) (y : ℕ) (z : ℕ+) (a : ℕ+) (b : ℕ+) : XgcdType := mk w.val.pred x y z.val.pred a.val.pred b.val.pred #align pnat.xgcd_type.mk' PNat.XgcdType.mk' /-- `w = wp + 1` -/ def w : ℕ+ := succPNat u.wp #align pnat.xgcd_type.w PNat.XgcdType.w /-- `z = zp + 1` -/ def z : ℕ+ := succPNat u.zp #align pnat.xgcd_type.z PNat.XgcdType.z /-- `a = ap + 1` -/ def a : ℕ+ := succPNat u.ap #align pnat.xgcd_type.a PNat.XgcdType.a /-- `b = bp + 1` -/ def b : ℕ+ := succPNat u.bp #align pnat.xgcd_type.b PNat.XgcdType.b /-- `r = a % b`: remainder -/ def r : ℕ := (u.ap + 1) % (u.bp + 1) #align pnat.xgcd_type.r PNat.XgcdType.r /-- `q = ap / bp`: quotient -/ def q : ℕ := (u.ap + 1) / (u.bp + 1) #align pnat.xgcd_type.q PNat.XgcdType.q /-- `qp = q - 1` -/ def qp : ℕ := u.q - 1 #align pnat.xgcd_type.qp PNat.XgcdType.qp /-- The map `v` gives the product of the matrix [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]] and the vector [a, b] = [ap + 1, bp + 1]. The map `vp` gives [sp, tp] such that v = [sp + 1, tp + 1]. -/ def vp : ℕ × ℕ := ⟨u.wp + u.x + u.ap + u.wp * u.ap + u.x * u.bp, u.y + u.zp + u.bp + u.y * u.ap + u.zp * u.bp⟩ #align pnat.xgcd_type.vp PNat.XgcdType.vp /-- `v = [sp + 1, tp + 1]`, check `vp` -/ def v : ℕ × ℕ := ⟨u.w * u.a + u.x * u.b, u.y * u.a + u.z * u.b⟩ #align pnat.xgcd_type.v PNat.XgcdType.v /-- `succ₂ [t.1, t.2] = [t.1.succ, t.2.succ]` -/ def succ₂ (t : ℕ × ℕ) : ℕ × ℕ := ⟨t.1.succ, t.2.succ⟩ #align pnat.xgcd_type.succ₂ PNat.XgcdType.succ₂ theorem v_eq_succ_vp : u.v = succ₂ u.vp := by ext <;> dsimp [v, vp, w, z, a, b, succ₂] <;> ring_nf #align pnat.xgcd_type.v_eq_succ_vp PNat.XgcdType.v_eq_succ_vp /-- `IsSpecial` holds if the matrix has determinant one. -/ def IsSpecial : Prop := u.wp + u.zp + u.wp * u.zp = u.x * u.y #align pnat.xgcd_type.is_special PNat.XgcdType.IsSpecial /-- `IsSpecial'` is an alternative of `IsSpecial`. -/ def IsSpecial' : Prop := u.w * u.z = succPNat (u.x * u.y) #align pnat.xgcd_type.is_special' PNat.XgcdType.IsSpecial' theorem isSpecial_iff : u.IsSpecial ↔ u.IsSpecial' := by dsimp [IsSpecial, IsSpecial'] let ⟨wp, x, y, zp, ap, bp⟩ := u constructor <;> intro h <;> simp [w, z, succPNat] at * <;> simp only [← coe_inj, mul_coe, mk_coe] at * · simp_all [← h, Nat.mul, Nat.succ_eq_add_one]; ring · simp [Nat.succ_eq_add_one, Nat.mul_add, Nat.add_mul, ← Nat.add_assoc] at h; rw [← h]; ring -- Porting note: Old code has been removed as it was much more longer. #align pnat.xgcd_type.is_special_iff PNat.XgcdType.isSpecial_iff /-- `IsReduced` holds if the two entries in the vector are the same. The reduction algorithm will produce a system with this property, whose product vector is the same as for the original system. -/ def IsReduced : Prop := u.ap = u.bp #align pnat.xgcd_type.is_reduced PNat.XgcdType.IsReduced /-- `IsReduced'` is an alternative of `IsReduced`. -/ def IsReduced' : Prop := u.a = u.b #align pnat.xgcd_type.is_reduced' PNat.XgcdType.IsReduced' theorem isReduced_iff : u.IsReduced ↔ u.IsReduced' := succPNat_inj.symm #align pnat.xgcd_type.is_reduced_iff PNat.XgcdType.isReduced_iff /-- `flip` flips the placement of variables during the algorithm. -/ def flip : XgcdType where wp := u.zp x := u.y y := u.x zp := u.wp ap := u.bp bp := u.ap #align pnat.xgcd_type.flip PNat.XgcdType.flip @[simp] theorem flip_w : (flip u).w = u.z := rfl #align pnat.xgcd_type.flip_w PNat.XgcdType.flip_w @[simp] theorem flip_x : (flip u).x = u.y := rfl #align pnat.xgcd_type.flip_x PNat.XgcdType.flip_x @[simp] theorem flip_y : (flip u).y = u.x := rfl #align pnat.xgcd_type.flip_y PNat.XgcdType.flip_y @[simp] theorem flip_z : (flip u).z = u.w := rfl #align pnat.xgcd_type.flip_z PNat.XgcdType.flip_z @[simp] theorem flip_a : (flip u).a = u.b := rfl #align pnat.xgcd_type.flip_a PNat.XgcdType.flip_a @[simp] theorem flip_b : (flip u).b = u.a := rfl #align pnat.xgcd_type.flip_b PNat.XgcdType.flip_b theorem flip_isReduced : (flip u).IsReduced ↔ u.IsReduced := by dsimp [IsReduced, flip] constructor <;> intro h <;> exact h.symm #align pnat.xgcd_type.flip_is_reduced PNat.XgcdType.flip_isReduced theorem flip_isSpecial : (flip u).IsSpecial ↔ u.IsSpecial := by dsimp [IsSpecial, flip] rw [mul_comm u.x, mul_comm u.zp, add_comm u.zp] #align pnat.xgcd_type.flip_is_special PNat.XgcdType.flip_isSpecial theorem flip_v : (flip u).v = u.v.swap := by dsimp [v] ext · simp only ring · simp only ring #align pnat.xgcd_type.flip_v PNat.XgcdType.flip_v /-- Properties of division with remainder for a / b. -/ theorem rq_eq : u.r + (u.bp + 1) * u.q = u.ap + 1 := Nat.mod_add_div (u.ap + 1) (u.bp + 1) #align pnat.xgcd_type.rq_eq PNat.XgcdType.rq_eq theorem qp_eq (hr : u.r = 0) : u.q = u.qp + 1 := by by_cases hq : u.q = 0 · let h := u.rq_eq rw [hr, hq, mul_zero, add_zero] at h cases h · exact (Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hq)).symm #align pnat.xgcd_type.qp_eq PNat.XgcdType.qp_eq /-- The following function provides the starting point for our algorithm. We will apply an iterative reduction process to it, which will produce a system satisfying IsReduced. The gcd can be read off from this final system. -/ def start (a b : ℕ+) : XgcdType := ⟨0, 0, 0, 0, a - 1, b - 1⟩ #align pnat.xgcd_type.start PNat.XgcdType.start theorem start_isSpecial (a b : ℕ+) : (start a b).IsSpecial := by dsimp [start, IsSpecial] #align pnat.xgcd_type.start_is_special PNat.XgcdType.start_isSpecial theorem start_v (a b : ℕ+) : (start a b).v = ⟨a, b⟩ := by dsimp [start, v, XgcdType.a, XgcdType.b, w, z] rw [one_mul, one_mul, zero_mul, zero_mul] have := a.pos have := b.pos congr <;> omega #align pnat.xgcd_type.start_v PNat.XgcdType.start_v /-- `finish` happens when the reducing process ends. -/ def finish : XgcdType := XgcdType.mk u.wp ((u.wp + 1) * u.qp + u.x) u.y (u.y * u.qp + u.zp) u.bp u.bp #align pnat.xgcd_type.finish PNat.XgcdType.finish
Mathlib/Data/PNat/Xgcd.lean
275
277
theorem finish_isReduced : u.finish.IsReduced := by
dsimp [IsReduced] rfl
/- Copyright (c) 2020 Thomas Browning and Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Patrick Lutz -/ import Mathlib.GroupTheory.Solvable import Mathlib.FieldTheory.PolynomialGaloisGroup import Mathlib.RingTheory.RootsOfUnity.Basic #align_import field_theory.abel_ruffini from "leanprover-community/mathlib"@"e3f4be1fcb5376c4948d7f095bec45350bfb9d1a" /-! # The Abel-Ruffini Theorem This file proves one direction of the Abel-Ruffini theorem, namely that if an element is solvable by radicals, then its minimal polynomial has solvable Galois group. ## Main definitions * `solvableByRad F E` : the intermediate field of solvable-by-radicals elements ## Main results * the Abel-Ruffini Theorem `solvableByRad.isSolvable'` : An irreducible polynomial with a root that is solvable by radicals has a solvable Galois group. -/ noncomputable section open scoped Classical Polynomial IntermediateField open Polynomial IntermediateField section AbelRuffini variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E] theorem gal_zero_isSolvable : IsSolvable (0 : F[X]).Gal := by infer_instance #align gal_zero_is_solvable gal_zero_isSolvable theorem gal_one_isSolvable : IsSolvable (1 : F[X]).Gal := by infer_instance #align gal_one_is_solvable gal_one_isSolvable theorem gal_C_isSolvable (x : F) : IsSolvable (C x).Gal := by infer_instance set_option linter.uppercaseLean3 false in #align gal_C_is_solvable gal_C_isSolvable
Mathlib/FieldTheory/AbelRuffini.lean
49
49
theorem gal_X_isSolvable : IsSolvable (X : F[X]).Gal := by
infer_instance
/- 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.GroupWithZero.Divisibility import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.Data.Finset.Sort #align_import data.polynomial.basic from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Theory of univariate polynomials This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds a semiring structure on it, and gives basic definitions that are expanded in other files in this directory. ## Main definitions * `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map. * `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism. * `X` is the polynomial `X`, i.e., `monomial 1 1`. * `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied to coefficients of the polynomial `p`. * `p.erase n` is the polynomial `p` in which one removes the `c X^n` term. There are often two natural variants of lemmas involving sums, depending on whether one acts on the polynomials, or on the function. The naming convention is that one adds `index` when acting on the polynomials. For instance, * `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`; * `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`. * Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`. ## Implementation Polynomials are defined using `R[ℕ]`, where `R` is a semiring. The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity `X * p = p * X`. The relationship to `R[ℕ]` is through a structure to make polynomials irreducible from the point of view of the kernel. Most operations are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two exceptions that we make semireducible: * The zero polynomial, so that its coefficients are definitionally equal to `0`. * The scalar action, to permit typeclass search to unfold it to resolve potential instance diamonds. The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should in general not be used once the basic API for polynomials is constructed. -/ set_option linter.uppercaseLean3 false noncomputable section /-- `Polynomial R` is the type of univariate polynomials over `R`. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from `R` is called `C`. -/ structure Polynomial (R : Type*) [Semiring R] where ofFinsupp :: toFinsupp : AddMonoidAlgebra R ℕ #align polynomial Polynomial #align polynomial.of_finsupp Polynomial.ofFinsupp #align polynomial.to_finsupp Polynomial.toFinsupp @[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R open AddMonoidAlgebra open Finsupp hiding single open Function hiding Commute open Polynomial namespace Polynomial universe u variable {R : Type u} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q : R[X]} theorem forall_iff_forall_finsupp (P : R[X] → Prop) : (∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ := ⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩ #align polynomial.forall_iff_forall_finsupp Polynomial.forall_iff_forall_finsupp theorem exists_iff_exists_finsupp (P : R[X] → Prop) : (∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ := ⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩ #align polynomial.exists_iff_exists_finsupp Polynomial.exists_iff_exists_finsupp @[simp] theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl #align polynomial.eta Polynomial.eta /-! ### Conversions to and from `AddMonoidAlgebra` Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping it, we have to copy across all the arithmetic operators manually, along with the lemmas about how they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`. -/ section AddMonoidAlgebra private irreducible_def add : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a + b⟩ private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X] | ⟨a⟩ => ⟨-a⟩ private irreducible_def mul : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a * b⟩ instance zero : Zero R[X] := ⟨⟨0⟩⟩ #align polynomial.has_zero Polynomial.zero instance one : One R[X] := ⟨⟨1⟩⟩ #align polynomial.one Polynomial.one instance add' : Add R[X] := ⟨add⟩ #align polynomial.has_add Polynomial.add' instance neg' {R : Type u} [Ring R] : Neg R[X] := ⟨neg⟩ #align polynomial.has_neg Polynomial.neg' instance sub {R : Type u} [Ring R] : Sub R[X] := ⟨fun a b => a + -b⟩ #align polynomial.has_sub Polynomial.sub instance mul' : Mul R[X] := ⟨mul⟩ #align polynomial.has_mul Polynomial.mul' -- If the private definitions are accidentally exposed, simplify them away. @[simp] theorem add_eq_add : add p q = p + q := rfl @[simp] theorem mul_eq_mul : mul p q = p * q := rfl instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where smul r p := ⟨r • p.toFinsupp⟩ smul_zero a := congr_arg ofFinsupp (smul_zero a) #align polynomial.smul_zero_class Polynomial.smulZeroClass -- to avoid a bug in the `ring` tactic instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p #align polynomial.has_pow Polynomial.pow @[simp] theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 := rfl #align polynomial.of_finsupp_zero Polynomial.ofFinsupp_zero @[simp] theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 := rfl #align polynomial.of_finsupp_one Polynomial.ofFinsupp_one @[simp] theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ := show _ = add _ _ by rw [add_def] #align polynomial.of_finsupp_add Polynomial.ofFinsupp_add @[simp] theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ := show _ = neg _ by rw [neg_def] #align polynomial.of_finsupp_neg Polynomial.ofFinsupp_neg @[simp] theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg] rfl #align polynomial.of_finsupp_sub Polynomial.ofFinsupp_sub @[simp] theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ := show _ = mul _ _ by rw [mul_def] #align polynomial.of_finsupp_mul Polynomial.ofFinsupp_mul @[simp] theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) : (⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) := rfl #align polynomial.of_finsupp_smul Polynomial.ofFinsupp_smul @[simp] theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by change _ = npowRec n _ induction n with | zero => simp [npowRec] | succ n n_ih => simp [npowRec, n_ih, pow_succ] #align polynomial.of_finsupp_pow Polynomial.ofFinsupp_pow @[simp] theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 := rfl #align polynomial.to_finsupp_zero Polynomial.toFinsupp_zero @[simp] theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 := rfl #align polynomial.to_finsupp_one Polynomial.toFinsupp_one @[simp] theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by cases a cases b rw [← ofFinsupp_add] #align polynomial.to_finsupp_add Polynomial.toFinsupp_add @[simp] theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by cases a rw [← ofFinsupp_neg] #align polynomial.to_finsupp_neg Polynomial.toFinsupp_neg @[simp] theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) : (a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add] rfl #align polynomial.to_finsupp_sub Polynomial.toFinsupp_sub @[simp] theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by cases a cases b rw [← ofFinsupp_mul] #align polynomial.to_finsupp_mul Polynomial.toFinsupp_mul @[simp] theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) : (a • b).toFinsupp = a • b.toFinsupp := rfl #align polynomial.to_finsupp_smul Polynomial.toFinsupp_smul @[simp] theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by cases a rw [← ofFinsupp_pow] #align polynomial.to_finsupp_pow Polynomial.toFinsupp_pow theorem _root_.IsSMulRegular.polynomial {S : Type*} [Monoid S] [DistribMulAction S R] {a : S} (ha : IsSMulRegular R a) : IsSMulRegular R[X] a | ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h) #align is_smul_regular.polynomial IsSMulRegular.polynomial theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) := fun ⟨_x⟩ ⟨_y⟩ => congr_arg _ #align polynomial.to_finsupp_injective Polynomial.toFinsupp_injective @[simp] theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b := toFinsupp_injective.eq_iff #align polynomial.to_finsupp_inj Polynomial.toFinsupp_inj @[simp] theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by rw [← toFinsupp_zero, toFinsupp_inj] #align polynomial.to_finsupp_eq_zero Polynomial.toFinsupp_eq_zero @[simp] theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by rw [← toFinsupp_one, toFinsupp_inj] #align polynomial.to_finsupp_eq_one Polynomial.toFinsupp_eq_one /-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/ theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b := iff_of_eq (ofFinsupp.injEq _ _) #align polynomial.of_finsupp_inj Polynomial.ofFinsupp_inj @[simp] theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by rw [← ofFinsupp_zero, ofFinsupp_inj] #align polynomial.of_finsupp_eq_zero Polynomial.ofFinsupp_eq_zero @[simp] theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj] #align polynomial.of_finsupp_eq_one Polynomial.ofFinsupp_eq_one instance inhabited : Inhabited R[X] := ⟨0⟩ #align polynomial.inhabited Polynomial.inhabited instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n #align polynomial.has_nat_cast Polynomial.instNatCast instance semiring : Semiring R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.semiring toFinsupp toFinsupp_injective toFinsupp_zero toFinsupp_one toFinsupp_add toFinsupp_mul (fun _ _ => toFinsupp_smul _ _) toFinsupp_pow fun _ => rfl with toAdd := Polynomial.add' toMul := Polynomial.mul' toZero := Polynomial.zero toOne := Polynomial.one nsmul := (· • ·) npow := fun n x => (x ^ n) } #align polynomial.semiring Polynomial.semiring instance distribSMul {S} [DistribSMul S R] : DistribSMul S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toSMulZeroClass := Polynomial.smulZeroClass } #align polynomial.distrib_smul Polynomial.distribSMul instance distribMulAction {S} [Monoid S] [DistribMulAction S R] : DistribMulAction S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.distribMulAction ⟨⟨toFinsupp, toFinsupp_zero (R := R)⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toSMul := Polynomial.smulZeroClass.toSMul } #align polynomial.distrib_mul_action Polynomial.distribMulAction instance faithfulSMul {S} [SMulZeroClass S R] [FaithfulSMul S R] : FaithfulSMul S R[X] where eq_of_smul_eq_smul {_s₁ _s₂} h := eq_of_smul_eq_smul fun a : ℕ →₀ R => congr_arg toFinsupp (h ⟨a⟩) #align polynomial.has_faithful_smul Polynomial.faithfulSMul instance module {S} [Semiring S] [Module S R] : Module S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toDistribMulAction := Polynomial.distribMulAction } #align polynomial.module Polynomial.module instance smulCommClass {S₁ S₂} [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [SMulCommClass S₁ S₂ R] : SMulCommClass S₁ S₂ R[X] := ⟨by rintro m n ⟨f⟩ simp_rw [← ofFinsupp_smul, smul_comm m n f]⟩ #align polynomial.smul_comm_class Polynomial.smulCommClass instance isScalarTower {S₁ S₂} [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ R[X] := ⟨by rintro _ _ ⟨⟩ simp_rw [← ofFinsupp_smul, smul_assoc]⟩ #align polynomial.is_scalar_tower Polynomial.isScalarTower instance isScalarTower_right {α K : Type*} [Semiring K] [DistribSMul α K] [IsScalarTower α K K] : IsScalarTower α K[X] K[X] := ⟨by rintro _ ⟨⟩ ⟨⟩; simp_rw [smul_eq_mul, ← ofFinsupp_smul, ← ofFinsupp_mul, ← ofFinsupp_smul, smul_mul_assoc]⟩ #align polynomial.is_scalar_tower_right Polynomial.isScalarTower_right instance isCentralScalar {S} [SMulZeroClass S R] [SMulZeroClass Sᵐᵒᵖ R] [IsCentralScalar S R] : IsCentralScalar S R[X] := ⟨by rintro _ ⟨⟩ simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩ #align polynomial.is_central_scalar Polynomial.isCentralScalar instance unique [Subsingleton R] : Unique R[X] := { Polynomial.inhabited with uniq := by rintro ⟨x⟩ apply congr_arg ofFinsupp simp [eq_iff_true_of_subsingleton] } #align polynomial.unique Polynomial.unique variable (R) /-- Ring isomorphism between `R[X]` and `R[ℕ]`. This is just an implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/ @[simps apply symm_apply] def toFinsuppIso : R[X] ≃+* R[ℕ] where toFun := toFinsupp invFun := ofFinsupp left_inv := fun ⟨_p⟩ => rfl right_inv _p := rfl map_mul' := toFinsupp_mul map_add' := toFinsupp_add #align polynomial.to_finsupp_iso Polynomial.toFinsuppIso #align polynomial.to_finsupp_iso_apply Polynomial.toFinsuppIso_apply #align polynomial.to_finsupp_iso_symm_apply Polynomial.toFinsuppIso_symm_apply instance [DecidableEq R] : DecidableEq R[X] := @Equiv.decidableEq R[X] _ (toFinsuppIso R).toEquiv (Finsupp.instDecidableEq) end AddMonoidAlgebra theorem ofFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[ℕ]) : (⟨∑ i ∈ s, f i⟩ : R[X]) = ∑ i ∈ s, ⟨f i⟩ := map_sum (toFinsuppIso R).symm f s #align polynomial.of_finsupp_sum Polynomial.ofFinsupp_sum theorem toFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[X]) : (∑ i ∈ s, f i : R[X]).toFinsupp = ∑ i ∈ s, (f i).toFinsupp := map_sum (toFinsuppIso R) f s #align polynomial.to_finsupp_sum Polynomial.toFinsupp_sum /-- The set of all `n` such that `X^n` has a non-zero coefficient. -/ -- @[simp] -- Porting note: The original generated theorem is same to `support_ofFinsupp` and -- the new generated theorem is different, so this attribute should be -- removed. def support : R[X] → Finset ℕ | ⟨p⟩ => p.support #align polynomial.support Polynomial.support @[simp] theorem support_ofFinsupp (p) : support (⟨p⟩ : R[X]) = p.support := by rw [support] #align polynomial.support_of_finsupp Polynomial.support_ofFinsupp theorem support_toFinsupp (p : R[X]) : p.toFinsupp.support = p.support := by rw [support] @[simp] theorem support_zero : (0 : R[X]).support = ∅ := rfl #align polynomial.support_zero Polynomial.support_zero @[simp] theorem support_eq_empty : p.support = ∅ ↔ p = 0 := by rcases p with ⟨⟩ simp [support] #align polynomial.support_eq_empty Polynomial.support_eq_empty @[simp] lemma support_nonempty : p.support.Nonempty ↔ p ≠ 0 := Finset.nonempty_iff_ne_empty.trans support_eq_empty.not theorem card_support_eq_zero : p.support.card = 0 ↔ p = 0 := by simp #align polynomial.card_support_eq_zero Polynomial.card_support_eq_zero /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (n : ℕ) : R →ₗ[R] R[X] where toFun t := ⟨Finsupp.single n t⟩ -- porting note (#10745): was `simp`. map_add' x y := by simp; rw [ofFinsupp_add] -- porting note (#10745): was `simp [← ofFinsupp_smul]`. map_smul' r x := by simp; rw [← ofFinsupp_smul, smul_single'] #align polynomial.monomial Polynomial.monomial @[simp] theorem toFinsupp_monomial (n : ℕ) (r : R) : (monomial n r).toFinsupp = Finsupp.single n r := by simp [monomial] #align polynomial.to_finsupp_monomial Polynomial.toFinsupp_monomial @[simp] theorem ofFinsupp_single (n : ℕ) (r : R) : (⟨Finsupp.single n r⟩ : R[X]) = monomial n r := by simp [monomial] #align polynomial.of_finsupp_single Polynomial.ofFinsupp_single -- @[simp] -- Porting note (#10618): simp can prove this theorem monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 := (monomial n).map_zero #align polynomial.monomial_zero_right Polynomial.monomial_zero_right -- This is not a `simp` lemma as `monomial_zero_left` is more general. theorem monomial_zero_one : monomial 0 (1 : R) = 1 := rfl #align polynomial.monomial_zero_one Polynomial.monomial_zero_one -- TODO: can't we just delete this one? theorem monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s := (monomial n).map_add _ _ #align polynomial.monomial_add Polynomial.monomial_add theorem monomial_mul_monomial (n m : ℕ) (r s : R) : monomial n r * monomial m s = monomial (n + m) (r * s) := toFinsupp_injective <| by simp only [toFinsupp_monomial, toFinsupp_mul, AddMonoidAlgebra.single_mul_single] #align polynomial.monomial_mul_monomial Polynomial.monomial_mul_monomial @[simp] theorem monomial_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r ^ k = monomial (n * k) (r ^ k) := by induction' k with k ih · simp [pow_zero, monomial_zero_one] · simp [pow_succ, ih, monomial_mul_monomial, Nat.succ_eq_add_one, mul_add, add_comm] #align polynomial.monomial_pow Polynomial.monomial_pow theorem smul_monomial {S} [SMulZeroClass S R] (a : S) (n : ℕ) (b : R) : a • monomial n b = monomial n (a • b) := toFinsupp_injective <| by simp; rw [smul_single] #align polynomial.smul_monomial Polynomial.smul_monomial theorem monomial_injective (n : ℕ) : Function.Injective (monomial n : R → R[X]) := (toFinsuppIso R).symm.injective.comp (single_injective n) #align polynomial.monomial_injective Polynomial.monomial_injective @[simp] theorem monomial_eq_zero_iff (t : R) (n : ℕ) : monomial n t = 0 ↔ t = 0 := LinearMap.map_eq_zero_iff _ (Polynomial.monomial_injective n) #align polynomial.monomial_eq_zero_iff Polynomial.monomial_eq_zero_iff theorem support_add : (p + q).support ⊆ p.support ∪ q.support := by simpa [support] using Finsupp.support_add #align polynomial.support_add Polynomial.support_add /-- `C a` is the constant polynomial `a`. `C` is provided as a ring homomorphism. -/ def C : R →+* R[X] := { monomial 0 with map_one' := by simp [monomial_zero_one] map_mul' := by simp [monomial_mul_monomial] map_zero' := by simp } #align polynomial.C Polynomial.C @[simp] theorem monomial_zero_left (a : R) : monomial 0 a = C a := rfl #align polynomial.monomial_zero_left Polynomial.monomial_zero_left @[simp] theorem toFinsupp_C (a : R) : (C a).toFinsupp = single 0 a := rfl #align polynomial.to_finsupp_C Polynomial.toFinsupp_C theorem C_0 : C (0 : R) = 0 := by simp #align polynomial.C_0 Polynomial.C_0 theorem C_1 : C (1 : R) = 1 := rfl #align polynomial.C_1 Polynomial.C_1 theorem C_mul : C (a * b) = C a * C b := C.map_mul a b #align polynomial.C_mul Polynomial.C_mul theorem C_add : C (a + b) = C a + C b := C.map_add a b #align polynomial.C_add Polynomial.C_add @[simp] theorem smul_C {S} [SMulZeroClass S R] (s : S) (r : R) : s • C r = C (s • r) := smul_monomial _ _ r #align polynomial.smul_C Polynomial.smul_C set_option linter.deprecated false in -- @[simp] -- Porting note (#10618): simp can prove this theorem C_bit0 : C (bit0 a) = bit0 (C a) := C_add #align polynomial.C_bit0 Polynomial.C_bit0 set_option linter.deprecated false in -- @[simp] -- Porting note (#10618): simp can prove this theorem C_bit1 : C (bit1 a) = bit1 (C a) := by simp [bit1, C_bit0] #align polynomial.C_bit1 Polynomial.C_bit1 theorem C_pow : C (a ^ n) = C a ^ n := C.map_pow a n #align polynomial.C_pow Polynomial.C_pow -- @[simp] -- Porting note (#10618): simp can prove this theorem C_eq_natCast (n : ℕ) : C (n : R) = (n : R[X]) := map_natCast C n #align polynomial.C_eq_nat_cast Polynomial.C_eq_natCast @[deprecated (since := "2024-04-17")] alias C_eq_nat_cast := C_eq_natCast @[simp] theorem C_mul_monomial : C a * monomial n b = monomial n (a * b) := by simp only [← monomial_zero_left, monomial_mul_monomial, zero_add] #align polynomial.C_mul_monomial Polynomial.C_mul_monomial @[simp] theorem monomial_mul_C : monomial n a * C b = monomial n (a * b) := by simp only [← monomial_zero_left, monomial_mul_monomial, add_zero] #align polynomial.monomial_mul_C Polynomial.monomial_mul_C /-- `X` is the polynomial variable (aka indeterminate). -/ def X : R[X] := monomial 1 1 #align polynomial.X Polynomial.X theorem monomial_one_one_eq_X : monomial 1 (1 : R) = X := rfl #align polynomial.monomial_one_one_eq_X Polynomial.monomial_one_one_eq_X theorem monomial_one_right_eq_X_pow (n : ℕ) : monomial n (1 : R) = X ^ n := by induction' n with n ih · simp [monomial_zero_one] · rw [pow_succ, ← ih, ← monomial_one_one_eq_X, monomial_mul_monomial, mul_one] #align polynomial.monomial_one_right_eq_X_pow Polynomial.monomial_one_right_eq_X_pow @[simp] theorem toFinsupp_X : X.toFinsupp = Finsupp.single 1 (1 : R) := rfl #align polynomial.to_finsupp_X Polynomial.toFinsupp_X /-- `X` commutes with everything, even when the coefficients are noncommutative. -/ theorem X_mul : X * p = p * X := by rcases p with ⟨⟩ -- Porting note: `ofFinsupp.injEq` is required. simp only [X, ← ofFinsupp_single, ← ofFinsupp_mul, LinearMap.coe_mk, ofFinsupp.injEq] -- Porting note: Was `ext`. refine Finsupp.ext fun _ => ?_ simp [AddMonoidAlgebra.mul_apply, AddMonoidAlgebra.sum_single_index, add_comm] #align polynomial.X_mul Polynomial.X_mul theorem X_pow_mul {n : ℕ} : X ^ n * p = p * X ^ n := by induction' n with n ih · simp · conv_lhs => rw [pow_succ] rw [mul_assoc, X_mul, ← mul_assoc, ih, mul_assoc, ← pow_succ] #align polynomial.X_pow_mul Polynomial.X_pow_mul /-- Prefer putting constants to the left of `X`. This lemma is the loop-avoiding `simp` version of `Polynomial.X_mul`. -/ @[simp] theorem X_mul_C (r : R) : X * C r = C r * X := X_mul #align polynomial.X_mul_C Polynomial.X_mul_C /-- Prefer putting constants to the left of `X ^ n`. This lemma is the loop-avoiding `simp` version of `X_pow_mul`. -/ @[simp] theorem X_pow_mul_C (r : R) (n : ℕ) : X ^ n * C r = C r * X ^ n := X_pow_mul #align polynomial.X_pow_mul_C Polynomial.X_pow_mul_C theorem X_pow_mul_assoc {n : ℕ} : p * X ^ n * q = p * q * X ^ n := by rw [mul_assoc, X_pow_mul, ← mul_assoc] #align polynomial.X_pow_mul_assoc Polynomial.X_pow_mul_assoc /-- Prefer putting constants to the left of `X ^ n`. This lemma is the loop-avoiding `simp` version of `X_pow_mul_assoc`. -/ @[simp] theorem X_pow_mul_assoc_C {n : ℕ} (r : R) : p * X ^ n * C r = p * C r * X ^ n := X_pow_mul_assoc #align polynomial.X_pow_mul_assoc_C Polynomial.X_pow_mul_assoc_C theorem commute_X (p : R[X]) : Commute X p := X_mul #align polynomial.commute_X Polynomial.commute_X theorem commute_X_pow (p : R[X]) (n : ℕ) : Commute (X ^ n) p := X_pow_mul #align polynomial.commute_X_pow Polynomial.commute_X_pow @[simp] theorem monomial_mul_X (n : ℕ) (r : R) : monomial n r * X = monomial (n + 1) r := by erw [monomial_mul_monomial, mul_one] #align polynomial.monomial_mul_X Polynomial.monomial_mul_X @[simp] theorem monomial_mul_X_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r * X ^ k = monomial (n + k) r := by induction' k with k ih · simp · simp [ih, pow_succ, ← mul_assoc, add_assoc, Nat.succ_eq_add_one] #align polynomial.monomial_mul_X_pow Polynomial.monomial_mul_X_pow @[simp] theorem X_mul_monomial (n : ℕ) (r : R) : X * monomial n r = monomial (n + 1) r := by rw [X_mul, monomial_mul_X] #align polynomial.X_mul_monomial Polynomial.X_mul_monomial @[simp] theorem X_pow_mul_monomial (k n : ℕ) (r : R) : X ^ k * monomial n r = monomial (n + k) r := by rw [X_pow_mul, monomial_mul_X_pow] #align polynomial.X_pow_mul_monomial Polynomial.X_pow_mul_monomial /-- `coeff p n` (often denoted `p.coeff n`) is the coefficient of `X^n` in `p`. -/ -- @[simp] -- Porting note: The original generated theorem is same to `coeff_ofFinsupp` and -- the new generated theorem is different, so this attribute should be -- removed. def coeff : R[X] → ℕ → R | ⟨p⟩ => p #align polynomial.coeff Polynomial.coeff -- Porting note (#10756): new theorem @[simp] theorem coeff_ofFinsupp (p) : coeff (⟨p⟩ : R[X]) = p := by rw [coeff] theorem coeff_injective : Injective (coeff : R[X] → ℕ → R) := by rintro ⟨p⟩ ⟨q⟩ -- Porting note: `ofFinsupp.injEq` is required. simp only [coeff, DFunLike.coe_fn_eq, imp_self, ofFinsupp.injEq] #align polynomial.coeff_injective Polynomial.coeff_injective @[simp] theorem coeff_inj : p.coeff = q.coeff ↔ p = q := coeff_injective.eq_iff #align polynomial.coeff_inj Polynomial.coeff_inj theorem toFinsupp_apply (f : R[X]) (i) : f.toFinsupp i = f.coeff i := by cases f; rfl #align polynomial.to_finsupp_apply Polynomial.toFinsupp_apply theorem coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by simp [coeff, Finsupp.single_apply] #align polynomial.coeff_monomial Polynomial.coeff_monomial @[simp] theorem coeff_zero (n : ℕ) : coeff (0 : R[X]) n = 0 := rfl #align polynomial.coeff_zero Polynomial.coeff_zero theorem coeff_one {n : ℕ} : coeff (1 : R[X]) n = if n = 0 then 1 else 0 := by simp_rw [eq_comm (a := n) (b := 0)] exact coeff_monomial #align polynomial.coeff_one Polynomial.coeff_one @[simp] theorem coeff_one_zero : coeff (1 : R[X]) 0 = 1 := by simp [coeff_one] #align polynomial.coeff_one_zero Polynomial.coeff_one_zero @[simp] theorem coeff_X_one : coeff (X : R[X]) 1 = 1 := coeff_monomial #align polynomial.coeff_X_one Polynomial.coeff_X_one @[simp] theorem coeff_X_zero : coeff (X : R[X]) 0 = 0 := coeff_monomial #align polynomial.coeff_X_zero Polynomial.coeff_X_zero @[simp] theorem coeff_monomial_succ : coeff (monomial (n + 1) a) 0 = 0 := by simp [coeff_monomial] #align polynomial.coeff_monomial_succ Polynomial.coeff_monomial_succ theorem coeff_X : coeff (X : R[X]) n = if 1 = n then 1 else 0 := coeff_monomial #align polynomial.coeff_X Polynomial.coeff_X theorem coeff_X_of_ne_one {n : ℕ} (hn : n ≠ 1) : coeff (X : R[X]) n = 0 := by rw [coeff_X, if_neg hn.symm] #align polynomial.coeff_X_of_ne_one Polynomial.coeff_X_of_ne_one @[simp] theorem mem_support_iff : n ∈ p.support ↔ p.coeff n ≠ 0 := by rcases p with ⟨⟩ simp #align polynomial.mem_support_iff Polynomial.mem_support_iff theorem not_mem_support_iff : n ∉ p.support ↔ p.coeff n = 0 := by simp #align polynomial.not_mem_support_iff Polynomial.not_mem_support_iff theorem coeff_C : coeff (C a) n = ite (n = 0) a 0 := by convert coeff_monomial (a := a) (m := n) (n := 0) using 2 simp [eq_comm] #align polynomial.coeff_C Polynomial.coeff_C @[simp] theorem coeff_C_zero : coeff (C a) 0 = a := coeff_monomial #align polynomial.coeff_C_zero Polynomial.coeff_C_zero theorem coeff_C_ne_zero (h : n ≠ 0) : (C a).coeff n = 0 := by rw [coeff_C, if_neg h] #align polynomial.coeff_C_ne_zero Polynomial.coeff_C_ne_zero @[simp] lemma coeff_C_succ {r : R} {n : ℕ} : coeff (C r) (n + 1) = 0 := by simp [coeff_C] @[simp] theorem coeff_natCast_ite : (Nat.cast m : R[X]).coeff n = ite (n = 0) m 0 := by simp only [← C_eq_natCast, coeff_C, Nat.cast_ite, Nat.cast_zero] @[deprecated (since := "2024-04-17")] alias coeff_nat_cast_ite := coeff_natCast_ite -- See note [no_index around OfNat.ofNat] @[simp] theorem coeff_ofNat_zero (a : ℕ) [a.AtLeastTwo] : coeff (no_index (OfNat.ofNat a : R[X])) 0 = OfNat.ofNat a := coeff_monomial -- See note [no_index around OfNat.ofNat] @[simp] theorem coeff_ofNat_succ (a n : ℕ) [h : a.AtLeastTwo] : coeff (no_index (OfNat.ofNat a : R[X])) (n + 1) = 0 := by rw [← Nat.cast_eq_ofNat] simp theorem C_mul_X_pow_eq_monomial : ∀ {n : ℕ}, C a * X ^ n = monomial n a | 0 => mul_one _ | n + 1 => by rw [pow_succ, ← mul_assoc, C_mul_X_pow_eq_monomial, X, monomial_mul_monomial, mul_one] #align polynomial.C_mul_X_pow_eq_monomial Polynomial.C_mul_X_pow_eq_monomial @[simp high] theorem toFinsupp_C_mul_X_pow (a : R) (n : ℕ) : Polynomial.toFinsupp (C a * X ^ n) = Finsupp.single n a := by rw [C_mul_X_pow_eq_monomial, toFinsupp_monomial] #align polynomial.to_finsupp_C_mul_X_pow Polynomial.toFinsupp_C_mul_X_pow theorem C_mul_X_eq_monomial : C a * X = monomial 1 a := by rw [← C_mul_X_pow_eq_monomial, pow_one] #align polynomial.C_mul_X_eq_monomial Polynomial.C_mul_X_eq_monomial @[simp high] theorem toFinsupp_C_mul_X (a : R) : Polynomial.toFinsupp (C a * X) = Finsupp.single 1 a := by rw [C_mul_X_eq_monomial, toFinsupp_monomial] #align polynomial.to_finsupp_C_mul_X Polynomial.toFinsupp_C_mul_X theorem C_injective : Injective (C : R → R[X]) := monomial_injective 0 #align polynomial.C_injective Polynomial.C_injective @[simp] theorem C_inj : C a = C b ↔ a = b := C_injective.eq_iff #align polynomial.C_inj Polynomial.C_inj @[simp] theorem C_eq_zero : C a = 0 ↔ a = 0 := C_injective.eq_iff' (map_zero C) #align polynomial.C_eq_zero Polynomial.C_eq_zero theorem C_ne_zero : C a ≠ 0 ↔ a ≠ 0 := C_eq_zero.not #align polynomial.C_ne_zero Polynomial.C_ne_zero theorem subsingleton_iff_subsingleton : Subsingleton R[X] ↔ Subsingleton R := ⟨@Injective.subsingleton _ _ _ C_injective, by intro infer_instance⟩ #align polynomial.subsingleton_iff_subsingleton Polynomial.subsingleton_iff_subsingleton theorem Nontrivial.of_polynomial_ne (h : p ≠ q) : Nontrivial R := (subsingleton_or_nontrivial R).resolve_left fun _hI => h <| Subsingleton.elim _ _ #align polynomial.nontrivial.of_polynomial_ne Polynomial.Nontrivial.of_polynomial_ne theorem forall_eq_iff_forall_eq : (∀ f g : R[X], f = g) ↔ ∀ a b : R, a = b := by simpa only [← subsingleton_iff] using subsingleton_iff_subsingleton #align polynomial.forall_eq_iff_forall_eq Polynomial.forall_eq_iff_forall_eq theorem ext_iff {p q : R[X]} : p = q ↔ ∀ n, coeff p n = coeff q n := by rcases p with ⟨f : ℕ →₀ R⟩ rcases q with ⟨g : ℕ →₀ R⟩ -- porting note (#10745): was `simp [coeff, DFunLike.ext_iff]` simpa [coeff] using DFunLike.ext_iff (f := f) (g := g) #align polynomial.ext_iff Polynomial.ext_iff @[ext] theorem ext {p q : R[X]} : (∀ n, coeff p n = coeff q n) → p = q := ext_iff.2 #align polynomial.ext Polynomial.ext /-- Monomials generate the additive monoid of polynomials. -/ theorem addSubmonoid_closure_setOf_eq_monomial : AddSubmonoid.closure { p : R[X] | ∃ n a, p = monomial n a } = ⊤ := by apply top_unique rw [← AddSubmonoid.map_equiv_top (toFinsuppIso R).symm.toAddEquiv, ← Finsupp.add_closure_setOf_eq_single, AddMonoidHom.map_mclosure] refine AddSubmonoid.closure_mono (Set.image_subset_iff.2 ?_) rintro _ ⟨n, a, rfl⟩ exact ⟨n, a, Polynomial.ofFinsupp_single _ _⟩ #align polynomial.add_submonoid_closure_set_of_eq_monomial Polynomial.addSubmonoid_closure_setOf_eq_monomial theorem addHom_ext {M : Type*} [AddMonoid M] {f g : R[X] →+ M} (h : ∀ n a, f (monomial n a) = g (monomial n a)) : f = g := AddMonoidHom.eq_of_eqOn_denseM addSubmonoid_closure_setOf_eq_monomial <| by rintro p ⟨n, a, rfl⟩ exact h n a #align polynomial.add_hom_ext Polynomial.addHom_ext @[ext high] theorem addHom_ext' {M : Type*} [AddMonoid M] {f g : R[X] →+ M} (h : ∀ n, f.comp (monomial n).toAddMonoidHom = g.comp (monomial n).toAddMonoidHom) : f = g := addHom_ext fun n => DFunLike.congr_fun (h n) #align polynomial.add_hom_ext' Polynomial.addHom_ext' @[ext high] theorem lhom_ext' {M : Type*} [AddCommMonoid M] [Module R M] {f g : R[X] →ₗ[R] M} (h : ∀ n, f.comp (monomial n) = g.comp (monomial n)) : f = g := LinearMap.toAddMonoidHom_injective <| addHom_ext fun n => LinearMap.congr_fun (h n) #align polynomial.lhom_ext' Polynomial.lhom_ext' -- this has the same content as the subsingleton theorem eq_zero_of_eq_zero (h : (0 : R) = (1 : R)) (p : R[X]) : p = 0 := by rw [← one_smul R p, ← h, zero_smul] #align polynomial.eq_zero_of_eq_zero Polynomial.eq_zero_of_eq_zero section Fewnomials theorem support_monomial (n) {a : R} (H : a ≠ 0) : (monomial n a).support = singleton n := by rw [← ofFinsupp_single, support]; exact Finsupp.support_single_ne_zero _ H #align polynomial.support_monomial Polynomial.support_monomial theorem support_monomial' (n) (a : R) : (monomial n a).support ⊆ singleton n := by rw [← ofFinsupp_single, support] exact Finsupp.support_single_subset #align polynomial.support_monomial' Polynomial.support_monomial' theorem support_C_mul_X {c : R} (h : c ≠ 0) : Polynomial.support (C c * X) = singleton 1 := by rw [C_mul_X_eq_monomial, support_monomial 1 h] #align polynomial.support_C_mul_X Polynomial.support_C_mul_X theorem support_C_mul_X' (c : R) : Polynomial.support (C c * X) ⊆ singleton 1 := by simpa only [C_mul_X_eq_monomial] using support_monomial' 1 c #align polynomial.support_C_mul_X' Polynomial.support_C_mul_X' theorem support_C_mul_X_pow (n : ℕ) {c : R} (h : c ≠ 0) : Polynomial.support (C c * X ^ n) = singleton n := by rw [C_mul_X_pow_eq_monomial, support_monomial n h] #align polynomial.support_C_mul_X_pow Polynomial.support_C_mul_X_pow
Mathlib/Algebra/Polynomial/Basic.lean
902
903
theorem support_C_mul_X_pow' (n : ℕ) (c : R) : Polynomial.support (C c * X ^ n) ⊆ singleton n := by
simpa only [C_mul_X_pow_eq_monomial] using support_monomial' n c
/- 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 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] #align set.mk_preimage_prod_left_fn_eq_if Set.mk_preimage_prod_left_fn_eq_if theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) : (fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage] #align set.mk_preimage_prod_right_fn_eq_if Set.mk_preimage_prod_right_fn_eq_if @[simp] theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by ext ⟨x, y⟩ simp [and_comm] #align set.preimage_swap_prod Set.preimage_swap_prod @[simp] theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by rw [image_swap_eq_preimage_swap, preimage_swap_prod] #align set.image_swap_prod Set.image_swap_prod theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} : (m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t := ext <| by simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm] #align set.prod_image_image_eq Set.prod_image_image_eq theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} : range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_range_range_eq Set.prod_range_range_eq @[simp, mfld_simps] theorem range_prod_map {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ := prod_range_range_eq.symm #align set.range_prod_map Set.range_prod_map theorem prod_range_univ_eq {m₁ : α → γ} : range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) := ext <| by simp [range] #align set.prod_range_univ_eq Set.prod_range_univ_eq theorem prod_univ_range_eq {m₂ : β → δ} : (univ : Set α) ×ˢ range m₂ = range fun p : α × β => (p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_univ_range_eq Set.prod_univ_range_eq theorem range_pair_subset (f : α → β) (g : α → γ) : (range fun x => (f x, g x)) ⊆ range f ×ˢ range g := by have : (fun x => (f x, g x)) = Prod.map f g ∘ fun x => (x, x) := funext fun x => rfl rw [this, ← range_prod_map] apply range_comp_subset_range #align set.range_pair_subset Set.range_pair_subset theorem Nonempty.prod : s.Nonempty → t.Nonempty → (s ×ˢ t).Nonempty := fun ⟨x, hx⟩ ⟨y, hy⟩ => ⟨(x, y), ⟨hx, hy⟩⟩ #align set.nonempty.prod Set.Nonempty.prod theorem Nonempty.fst : (s ×ˢ t).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩ #align set.nonempty.fst Set.Nonempty.fst theorem Nonempty.snd : (s ×ˢ t).Nonempty → t.Nonempty := fun ⟨x, hx⟩ => ⟨x.2, hx.2⟩ #align set.nonempty.snd Set.Nonempty.snd @[simp] theorem prod_nonempty_iff : (s ×ˢ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod h.2⟩ #align set.prod_nonempty_iff Set.prod_nonempty_iff @[simp] theorem prod_eq_empty_iff : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ := by simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_or] #align set.prod_eq_empty_iff Set.prod_eq_empty_iff theorem prod_sub_preimage_iff {W : Set γ} {f : α × β → γ} : s ×ˢ t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W := by simp [subset_def] #align set.prod_sub_preimage_iff Set.prod_sub_preimage_iff theorem image_prod_mk_subset_prod {f : α → β} {g : α → γ} {s : Set α} : (fun x => (f x, g x)) '' s ⊆ (f '' s) ×ˢ (g '' s) := by rintro _ ⟨x, hx, rfl⟩ exact mk_mem_prod (mem_image_of_mem f hx) (mem_image_of_mem g hx) #align set.image_prod_mk_subset_prod Set.image_prod_mk_subset_prod theorem image_prod_mk_subset_prod_left (hb : b ∈ t) : (fun a => (a, b)) '' s ⊆ s ×ˢ t := by rintro _ ⟨a, ha, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_left Set.image_prod_mk_subset_prod_left theorem image_prod_mk_subset_prod_right (ha : a ∈ s) : Prod.mk a '' t ⊆ s ×ˢ t := by rintro _ ⟨b, hb, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_right Set.image_prod_mk_subset_prod_right theorem prod_subset_preimage_fst (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.fst ⁻¹' s := inter_subset_left #align set.prod_subset_preimage_fst Set.prod_subset_preimage_fst theorem fst_image_prod_subset (s : Set α) (t : Set β) : Prod.fst '' s ×ˢ t ⊆ s := image_subset_iff.2 <| prod_subset_preimage_fst s t #align set.fst_image_prod_subset Set.fst_image_prod_subset theorem fst_image_prod (s : Set β) {t : Set α} (ht : t.Nonempty) : Prod.fst '' s ×ˢ t = s := (fst_image_prod_subset _ _).antisymm fun y hy => let ⟨x, hx⟩ := ht ⟨(y, x), ⟨hy, hx⟩, rfl⟩ #align set.fst_image_prod Set.fst_image_prod theorem prod_subset_preimage_snd (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.snd ⁻¹' t := inter_subset_right #align set.prod_subset_preimage_snd Set.prod_subset_preimage_snd theorem snd_image_prod_subset (s : Set α) (t : Set β) : Prod.snd '' s ×ˢ t ⊆ t := image_subset_iff.2 <| prod_subset_preimage_snd s t #align set.snd_image_prod_subset Set.snd_image_prod_subset theorem snd_image_prod {s : Set α} (hs : s.Nonempty) (t : Set β) : Prod.snd '' s ×ˢ t = t := (snd_image_prod_subset _ _).antisymm fun y y_in => let ⟨x, x_in⟩ := hs ⟨(x, y), ⟨x_in, y_in⟩, rfl⟩ #align set.snd_image_prod Set.snd_image_prod theorem prod_diff_prod : s ×ˢ t \ s₁ ×ˢ t₁ = s ×ˢ (t \ t₁) ∪ (s \ s₁) ×ˢ t := by ext x by_cases h₁ : x.1 ∈ s₁ <;> by_cases h₂ : x.2 ∈ t₁ <;> simp [*] #align set.prod_diff_prod Set.prod_diff_prod /-- A product set is included in a product set if and only factors are included, or a factor of the first set is empty. -/ theorem prod_subset_prod_iff : s ×ˢ t ⊆ s₁ ×ˢ t₁ ↔ s ⊆ s₁ ∧ t ⊆ t₁ ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.1 h] have st : s.Nonempty ∧ t.Nonempty := by rwa [prod_nonempty_iff] at h refine ⟨fun H => Or.inl ⟨?_, ?_⟩, ?_⟩ · have := image_subset (Prod.fst : α × β → α) H rwa [fst_image_prod _ st.2, fst_image_prod _ (h.mono H).snd] at this · have := image_subset (Prod.snd : α × β → β) H rwa [snd_image_prod st.1, snd_image_prod (h.mono H).fst] at this · intro H simp only [st.1.ne_empty, st.2.ne_empty, or_false_iff] at H exact prod_mono H.1 H.2 #align set.prod_subset_prod_iff Set.prod_subset_prod_iff theorem prod_eq_prod_iff_of_nonempty (h : (s ×ˢ t).Nonempty) : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ := by constructor · intro heq have h₁ : (s₁ ×ˢ t₁ : Set _).Nonempty := by rwa [← heq] rw [prod_nonempty_iff] at h h₁ rw [← fst_image_prod s h.2, ← fst_image_prod s₁ h₁.2, heq, eq_self_iff_true, true_and_iff, ← snd_image_prod h.1 t, ← snd_image_prod h₁.1 t₁, heq] · rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_prod_iff_of_nonempty Set.prod_eq_prod_iff_of_nonempty theorem prod_eq_prod_iff : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ ∨ (s = ∅ ∨ t = ∅) ∧ (s₁ = ∅ ∨ t₁ = ∅) := by symm rcases eq_empty_or_nonempty (s ×ˢ t) with h | h · simp_rw [h, @eq_comm _ ∅, prod_eq_empty_iff, prod_eq_empty_iff.mp h, true_and_iff, or_iff_right_iff_imp] rintro ⟨rfl, rfl⟩ exact prod_eq_empty_iff.mp h rw [prod_eq_prod_iff_of_nonempty h] rw [nonempty_iff_ne_empty, Ne, prod_eq_empty_iff] at h simp_rw [h, false_and_iff, or_false_iff] #align set.prod_eq_prod_iff Set.prod_eq_prod_iff @[simp] theorem prod_eq_iff_eq (ht : t.Nonempty) : s ×ˢ t = s₁ ×ˢ t ↔ s = s₁ := by simp_rw [prod_eq_prod_iff, ht.ne_empty, and_true_iff, or_iff_left_iff_imp, or_false_iff] rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_iff_eq Set.prod_eq_iff_eq section Mono variable [Preorder α] {f : α → Set β} {g : α → Set γ} theorem _root_.Monotone.set_prod (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align monotone.set_prod Monotone.set_prod theorem _root_.Antitone.set_prod (hf : Antitone f) (hg : Antitone g) : Antitone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align antitone.set_prod Antitone.set_prod theorem _root_.MonotoneOn.set_prod (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align monotone_on.set_prod MonotoneOn.set_prod theorem _root_.AntitoneOn.set_prod (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align antitone_on.set_prod AntitoneOn.set_prod end Mono end Prod /-! ### Diagonal In this section we prove some lemmas about the diagonal set `{p | p.1 = p.2}` and the diagonal map `fun x ↦ (x, x)`. -/ section Diagonal variable {α : Type*} {s t : Set α} lemma diagonal_nonempty [Nonempty α] : (diagonal α).Nonempty := Nonempty.elim ‹_› fun x => ⟨_, mem_diagonal x⟩ #align set.diagonal_nonempty Set.diagonal_nonempty instance decidableMemDiagonal [h : DecidableEq α] (x : α × α) : Decidable (x ∈ diagonal α) := h x.1 x.2 #align set.decidable_mem_diagonal Set.decidableMemDiagonal theorem preimage_coe_coe_diagonal (s : Set α) : Prod.map (fun x : s => (x : α)) (fun x : s => (x : α)) ⁻¹' diagonal α = diagonal s := by ext ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ simp [Set.diagonal] #align set.preimage_coe_coe_diagonal Set.preimage_coe_coe_diagonal @[simp] theorem range_diag : (range fun x => (x, x)) = diagonal α := by ext ⟨x, y⟩ simp [diagonal, eq_comm] #align set.range_diag Set.range_diag theorem diagonal_subset_iff {s} : diagonal α ⊆ s ↔ ∀ x, (x, x) ∈ s := by rw [← range_diag, range_subset_iff] #align set.diagonal_subset_iff Set.diagonal_subset_iff @[simp] theorem prod_subset_compl_diagonal_iff_disjoint : s ×ˢ t ⊆ (diagonal α)ᶜ ↔ Disjoint s t := prod_subset_iff.trans disjoint_iff_forall_ne.symm #align set.prod_subset_compl_diagonal_iff_disjoint Set.prod_subset_compl_diagonal_iff_disjoint @[simp] theorem diag_preimage_prod (s t : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ t = s ∩ t := rfl #align set.diag_preimage_prod Set.diag_preimage_prod theorem diag_preimage_prod_self (s : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ s = s := inter_self s #align set.diag_preimage_prod_self Set.diag_preimage_prod_self theorem diag_image (s : Set α) : (fun x => (x, x)) '' s = diagonal α ∩ s ×ˢ s := by rw [← range_diag, ← image_preimage_eq_range_inter, diag_preimage_prod_self] #align set.diag_image Set.diag_image theorem diagonal_eq_univ_iff : diagonal α = univ ↔ Subsingleton α := by simp only [subsingleton_iff, eq_univ_iff_forall, Prod.forall, mem_diagonal_iff] theorem diagonal_eq_univ [Subsingleton α] : diagonal α = univ := diagonal_eq_univ_iff.2 ‹_› end Diagonal /-- A function is `Function.const α a` for some `a` if and only if `∀ x y, f x = f y`. -/
Mathlib/Data/Set/Prod.lean
519
524
theorem range_const_eq_diagonal {α β : Type*} [hβ : Nonempty β] : range (const α) = {f : α → β | ∀ x y, f x = f y} := by
refine (range_eq_iff _ _).mpr ⟨fun _ _ _ ↦ rfl, fun f hf ↦ ?_⟩ rcases isEmpty_or_nonempty α with h|⟨⟨a⟩⟩ · exact hβ.elim fun b ↦ ⟨b, Subsingleton.elim _ _⟩ · exact ⟨f a, funext fun x ↦ hf _ _⟩
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov, Neil Strickland, Aaron Anderson -/ import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Units #align_import algebra.divisibility.units from "leanprover-community/mathlib"@"e574b1a4e891376b0ef974b926da39e05da12a06" /-! # Divisibility and units ## Main definition * `IsRelPrime x y`: that `x` and `y` are relatively prime, defined to mean that the only common divisors of `x` and `y` are the units. -/ variable {α : Type*} namespace Units section Monoid variable [Monoid α] {a b : α} {u : αˣ} /-- Elements of the unit group of a monoid represented as elements of the monoid divide any element of the monoid. -/ theorem coe_dvd : ↑u ∣ a := ⟨↑u⁻¹ * a, by simp⟩ #align units.coe_dvd Units.coe_dvd /-- In a monoid, an element `a` divides an element `b` iff `a` divides all associates of `b`. -/ theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b := Iff.intro (fun ⟨c, Eq⟩ ↦ ⟨c * ↑u⁻¹, by rw [← mul_assoc, ← Eq, Units.mul_inv_cancel_right]⟩) fun ⟨c, Eq⟩ ↦ Eq.symm ▸ (_root_.dvd_mul_right _ _).mul_right _ #align units.dvd_mul_right Units.dvd_mul_right /-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/ theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b := Iff.intro (fun ⟨c, Eq⟩ => ⟨↑u * c, Eq.trans (mul_assoc _ _ _)⟩) fun h => dvd_trans (Dvd.intro (↑u⁻¹) (by rw [mul_assoc, u.mul_inv, mul_one])) h #align units.mul_right_dvd Units.mul_right_dvd end Monoid section CommMonoid variable [CommMonoid α] {a b : α} {u : αˣ} /-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left associates of `b`. -/ theorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by rw [mul_comm] apply dvd_mul_right #align units.dvd_mul_left Units.dvd_mul_left /-- In a commutative monoid, an element `a` divides an element `b` iff all left associates of `a` divide `b`. -/ theorem mul_left_dvd : ↑u * a ∣ b ↔ a ∣ b := by rw [mul_comm] apply mul_right_dvd #align units.mul_left_dvd Units.mul_left_dvd end CommMonoid end Units namespace IsUnit section Monoid variable [Monoid α] {a b u : α} (hu : IsUnit u) /-- Units of a monoid divide any element of the monoid. -/ @[simp] theorem dvd : u ∣ a := by rcases hu with ⟨u, rfl⟩ apply Units.coe_dvd #align is_unit.dvd IsUnit.dvd @[simp] theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.dvd_mul_right #align is_unit.dvd_mul_right IsUnit.dvd_mul_right /-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`. -/ @[simp] theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.mul_right_dvd #align is_unit.mul_right_dvd IsUnit.mul_right_dvd theorem isPrimal : IsPrimal u := fun _ _ _ ↦ ⟨u, 1, hu.dvd, one_dvd _, (mul_one u).symm⟩ end Monoid section CommMonoid variable [CommMonoid α] {a b u : α} (hu : IsUnit u) /-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left associates of `b`. -/ @[simp] theorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.dvd_mul_left #align is_unit.dvd_mul_left IsUnit.dvd_mul_left /-- In a commutative monoid, an element `a` divides an element `b` iff all left associates of `a` divide `b`. -/ @[simp] theorem mul_left_dvd : u * a ∣ b ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.mul_left_dvd #align is_unit.mul_left_dvd IsUnit.mul_left_dvd end CommMonoid end IsUnit section CommMonoid variable [CommMonoid α] theorem isUnit_iff_dvd_one {x : α} : IsUnit x ↔ x ∣ 1 := ⟨IsUnit.dvd, fun ⟨y, h⟩ => ⟨⟨x, y, h.symm, by rw [h, mul_comm]⟩, rfl⟩⟩ #align is_unit_iff_dvd_one isUnit_iff_dvd_one theorem isUnit_iff_forall_dvd {x : α} : IsUnit x ↔ ∀ y, x ∣ y := isUnit_iff_dvd_one.trans ⟨fun h _ => h.trans (one_dvd _), fun h => h _⟩ #align is_unit_iff_forall_dvd isUnit_iff_forall_dvd theorem isUnit_of_dvd_unit {x y : α} (xy : x ∣ y) (hu : IsUnit y) : IsUnit x := isUnit_iff_dvd_one.2 <| xy.trans <| isUnit_iff_dvd_one.1 hu #align is_unit_of_dvd_unit isUnit_of_dvd_unit theorem isUnit_of_dvd_one {a : α} (h : a ∣ 1) : IsUnit (a : α) := isUnit_iff_dvd_one.mpr h #align is_unit_of_dvd_one isUnit_of_dvd_one theorem not_isUnit_of_not_isUnit_dvd {a b : α} (ha : ¬IsUnit a) (hb : a ∣ b) : ¬IsUnit b := mt (isUnit_of_dvd_unit hb) ha #align not_is_unit_of_not_is_unit_dvd not_isUnit_of_not_isUnit_dvd end CommMonoid section RelPrime /-- `x` and `y` are relatively prime if every common divisor is a unit. -/ def IsRelPrime [Monoid α] (x y : α) : Prop := ∀ ⦃d⦄, d ∣ x → d ∣ y → IsUnit d variable [CommMonoid α] {x y z : α} @[symm] theorem IsRelPrime.symm (H : IsRelPrime x y) : IsRelPrime y x := fun _ hx hy ↦ H hy hx theorem isRelPrime_comm : IsRelPrime x y ↔ IsRelPrime y x := ⟨IsRelPrime.symm, IsRelPrime.symm⟩ theorem isRelPrime_self : IsRelPrime x x ↔ IsUnit x := ⟨(· dvd_rfl dvd_rfl), fun hu _ _ dvd ↦ isUnit_of_dvd_unit dvd hu⟩ theorem IsUnit.isRelPrime_left (h : IsUnit x) : IsRelPrime x y := fun _ hx _ ↦ isUnit_of_dvd_unit hx h theorem IsUnit.isRelPrime_right (h : IsUnit y) : IsRelPrime x y := h.isRelPrime_left.symm theorem isRelPrime_one_left : IsRelPrime 1 x := isUnit_one.isRelPrime_left theorem isRelPrime_one_right : IsRelPrime x 1 := isUnit_one.isRelPrime_right theorem IsRelPrime.of_mul_left_left (H : IsRelPrime (x * y) z) : IsRelPrime x z := fun _ hx ↦ H (dvd_mul_of_dvd_left hx _) theorem IsRelPrime.of_mul_left_right (H : IsRelPrime (x * y) z) : IsRelPrime y z := (mul_comm x y ▸ H).of_mul_left_left theorem IsRelPrime.of_mul_right_left (H : IsRelPrime x (y * z)) : IsRelPrime x y := by rw [isRelPrime_comm] at H ⊢ exact H.of_mul_left_left theorem IsRelPrime.of_mul_right_right (H : IsRelPrime x (y * z)) : IsRelPrime x z := (mul_comm y z ▸ H).of_mul_right_left theorem IsRelPrime.of_dvd_left (h : IsRelPrime y z) (dvd : x ∣ y) : IsRelPrime x z := by obtain ⟨d, rfl⟩ := dvd; exact IsRelPrime.of_mul_left_left h theorem IsRelPrime.of_dvd_right (h : IsRelPrime z y) (dvd : x ∣ y) : IsRelPrime z x := (h.symm.of_dvd_left dvd).symm theorem IsRelPrime.isUnit_of_dvd (H : IsRelPrime x y) (d : x ∣ y) : IsUnit x := H dvd_rfl d section IsUnit variable (hu : IsUnit x) theorem isRelPrime_mul_unit_left_left : IsRelPrime (x * y) z ↔ IsRelPrime y z := ⟨IsRelPrime.of_mul_left_right, fun H _ h ↦ H (hu.dvd_mul_left.mp h)⟩ theorem isRelPrime_mul_unit_left_right : IsRelPrime y (x * z) ↔ IsRelPrime y z := by rw [isRelPrime_comm, isRelPrime_mul_unit_left_left hu, isRelPrime_comm] theorem isRelPrime_mul_unit_left : IsRelPrime (x * y) (x * z) ↔ IsRelPrime y z := by rw [isRelPrime_mul_unit_left_left hu, isRelPrime_mul_unit_left_right hu] theorem isRelPrime_mul_unit_right_left : IsRelPrime (y * x) z ↔ IsRelPrime y z := by rw [mul_comm, isRelPrime_mul_unit_left_left hu] theorem isRelPrime_mul_unit_right_right : IsRelPrime y (z * x) ↔ IsRelPrime y z := by rw [mul_comm, isRelPrime_mul_unit_left_right hu] theorem isRelPrime_mul_unit_right : IsRelPrime (y * x) (z * x) ↔ IsRelPrime y z := by rw [isRelPrime_mul_unit_right_left hu, isRelPrime_mul_unit_right_right hu] end IsUnit theorem IsRelPrime.dvd_of_dvd_mul_right_of_isPrimal (H1 : IsRelPrime x z) (H2 : x ∣ y * z) (h : IsPrimal x) : x ∣ y := by obtain ⟨a, b, ha, hb, rfl⟩ := h H2 exact (H1.of_mul_left_right.isUnit_of_dvd hb).mul_right_dvd.mpr ha theorem IsRelPrime.dvd_of_dvd_mul_left_of_isPrimal (H1 : IsRelPrime x y) (H2 : x ∣ y * z) (h : IsPrimal x) : x ∣ z := H1.dvd_of_dvd_mul_right_of_isPrimal (mul_comm y z ▸ H2) h theorem IsRelPrime.mul_dvd_of_right_isPrimal (H : IsRelPrime x y) (H1 : x ∣ z) (H2 : y ∣ z) (hy : IsPrimal y) : x * y ∣ z := by obtain ⟨w, rfl⟩ := H1 exact mul_dvd_mul_left x (H.symm.dvd_of_dvd_mul_left_of_isPrimal H2 hy) theorem IsRelPrime.mul_dvd_of_left_isPrimal (H : IsRelPrime x y) (H1 : x ∣ z) (H2 : y ∣ z) (hx : IsPrimal x) : x * y ∣ z := by rw [mul_comm]; exact H.symm.mul_dvd_of_right_isPrimal H2 H1 hx /-! `IsRelPrime` enjoys desirable properties in a decomposition monoid. See Lemma 6.3 in *On properties of square-free elements in commutative cancellative monoids*, https://doi.org/10.1007/s00233-019-10022-3. -/ variable [DecompositionMonoid α] theorem IsRelPrime.dvd_of_dvd_mul_right (H1 : IsRelPrime x z) (H2 : x ∣ y * z) : x ∣ y := H1.dvd_of_dvd_mul_right_of_isPrimal H2 (DecompositionMonoid.primal x) theorem IsRelPrime.dvd_of_dvd_mul_left (H1 : IsRelPrime x y) (H2 : x ∣ y * z) : x ∣ z := H1.dvd_of_dvd_mul_right (mul_comm y z ▸ H2) theorem IsRelPrime.mul_left (H1 : IsRelPrime x z) (H2 : IsRelPrime y z) : IsRelPrime (x * y) z := fun _ h hz ↦ by obtain ⟨a, b, ha, hb, rfl⟩ := exists_dvd_and_dvd_of_dvd_mul h exact (H1 ha <| (dvd_mul_right a b).trans hz).mul (H2 hb <| (dvd_mul_left b a).trans hz)
Mathlib/Algebra/Divisibility/Units.lean
254
256
theorem IsRelPrime.mul_right (H1 : IsRelPrime x y) (H2 : IsRelPrime x z) : IsRelPrime x (y * z) := by
rw [isRelPrime_comm] at H1 H2 ⊢; exact H1.mul_left H2
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse #align_import analysis.special_functions.complex.arg from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # The argument of a complex number. We define `arg : ℂ → ℝ`, returning a real number in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, while `arg 0` defaults to `0` -/ open Filter Metric Set open scoped ComplexConjugate Real Topology namespace Complex variable {a x z : ℂ} /-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : ℂ) : ℝ := if 0 ≤ x.re then Real.arcsin (x.im / abs x) else if 0 ≤ x.im then Real.arcsin ((-x).im / abs x) + π else Real.arcsin ((-x).im / abs x) - π #align complex.arg Complex.arg theorem sin_arg (x : ℂ) : Real.sin (arg x) = x.im / abs x := by unfold arg; split_ifs <;> simp [sub_eq_add_neg, arg, Real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg] #align complex.sin_arg Complex.sin_arg theorem cos_arg {x : ℂ} (hx : x ≠ 0) : Real.cos (arg x) = x.re / abs x := by rw [arg] split_ifs with h₁ h₂ · rw [Real.cos_arcsin] field_simp [Real.sqrt_sq, (abs.pos hx).le, *] · rw [Real.cos_add_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] · rw [Real.cos_sub_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] #align complex.cos_arg Complex.cos_arg @[simp] theorem abs_mul_exp_arg_mul_I (x : ℂ) : ↑(abs x) * exp (arg x * I) = x := by rcases eq_or_ne x 0 with (rfl | hx) · simp · have : abs x ≠ 0 := abs.ne_zero hx apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm (abs x)] set_option linter.uppercaseLean3 false in #align complex.abs_mul_exp_arg_mul_I Complex.abs_mul_exp_arg_mul_I @[simp] theorem abs_mul_cos_add_sin_mul_I (x : ℂ) : (abs x * (cos (arg x) + sin (arg x) * I) : ℂ) = x := by rw [← exp_mul_I, abs_mul_exp_arg_mul_I] set_option linter.uppercaseLean3 false in #align complex.abs_mul_cos_add_sin_mul_I Complex.abs_mul_cos_add_sin_mul_I @[simp] lemma abs_mul_cos_arg (x : ℂ) : abs x * Real.cos (arg x) = x.re := by simpa [-abs_mul_cos_add_sin_mul_I] using congr_arg re (abs_mul_cos_add_sin_mul_I x) @[simp] lemma abs_mul_sin_arg (x : ℂ) : abs x * Real.sin (arg x) = x.im := by simpa [-abs_mul_cos_add_sin_mul_I] using congr_arg im (abs_mul_cos_add_sin_mul_I x) theorem abs_eq_one_iff (z : ℂ) : abs z = 1 ↔ ∃ θ : ℝ, exp (θ * I) = z := by refine ⟨fun hz => ⟨arg z, ?_⟩, ?_⟩ · calc exp (arg z * I) = abs z * exp (arg z * I) := by rw [hz, ofReal_one, one_mul] _ = z := abs_mul_exp_arg_mul_I z · rintro ⟨θ, rfl⟩ exact Complex.abs_exp_ofReal_mul_I θ #align complex.abs_eq_one_iff Complex.abs_eq_one_iff @[simp] theorem range_exp_mul_I : (Set.range fun x : ℝ => exp (x * I)) = Metric.sphere 0 1 := by ext x simp only [mem_sphere_zero_iff_norm, norm_eq_abs, abs_eq_one_iff, Set.mem_range] set_option linter.uppercaseLean3 false in #align complex.range_exp_mul_I Complex.range_exp_mul_I theorem arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (r * (cos θ + sin θ * I)) = θ := by simp only [arg, map_mul, abs_cos_add_sin_mul_I, abs_of_nonneg hr.le, mul_one] simp only [re_ofReal_mul, im_ofReal_mul, neg_im, ← ofReal_cos, ← ofReal_sin, ← mk_eq_add_mul_I, neg_div, mul_div_cancel_left₀ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr] by_cases h₁ : θ ∈ Set.Icc (-(π / 2)) (π / 2) · rw [if_pos] exacts [Real.arcsin_sin' h₁, Real.cos_nonneg_of_mem_Icc h₁] · rw [Set.mem_Icc, not_and_or, not_le, not_le] at h₁ cases' h₁ with h₁ h₁ · replace hθ := hθ.1 have hcos : Real.cos θ < 0 := by rw [← neg_pos, ← Real.cos_add_pi] refine Real.cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith have hsin : Real.sin θ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hθ rw [if_neg, if_neg, ← Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith; linarith; exact hsin.not_le; exact hcos.not_le] · replace hθ := hθ.2 have hcos : Real.cos θ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith) have hsin : 0 ≤ Real.sin θ := Real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩ rw [if_neg, if_pos, ← Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith; linarith; exact hsin; exact hcos.not_le] set_option linter.uppercaseLean3 false in #align complex.arg_mul_cos_add_sin_mul_I Complex.arg_mul_cos_add_sin_mul_I theorem arg_cos_add_sin_mul_I {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (cos θ + sin θ * I) = θ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hθ] set_option linter.uppercaseLean3 false in #align complex.arg_cos_add_sin_mul_I Complex.arg_cos_add_sin_mul_I lemma arg_exp_mul_I (θ : ℝ) : arg (exp (θ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ := by convert arg_cos_add_sin_mul_I (θ := toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ) _ using 2 · rw [← exp_mul_I, eq_sub_of_add_eq $ toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub, ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq] · convert toIocMod_mem_Ioc _ _ _ ring @[simp] theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl] #align complex.arg_zero Complex.arg_zero theorem ext_abs_arg {x y : ℂ} (h₁ : abs x = abs y) (h₂ : x.arg = y.arg) : x = y := by rw [← abs_mul_exp_arg_mul_I x, ← abs_mul_exp_arg_mul_I y, h₁, h₂] #align complex.ext_abs_arg Complex.ext_abs_arg theorem ext_abs_arg_iff {x y : ℂ} : x = y ↔ abs x = abs y ∧ arg x = arg y := ⟨fun h => h ▸ ⟨rfl, rfl⟩, and_imp.2 ext_abs_arg⟩ #align complex.ext_abs_arg_iff Complex.ext_abs_arg_iff theorem arg_mem_Ioc (z : ℂ) : arg z ∈ Set.Ioc (-π) π := by have hπ : 0 < π := Real.pi_pos rcases eq_or_ne z 0 with (rfl | hz) · simp [hπ, hπ.le] rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos (arg z) (-π) with ⟨N, hN, -⟩ rw [two_mul, neg_add_cancel_left, ← two_mul, zsmul_eq_mul] at hN rw [← abs_mul_cos_add_sin_mul_I z, ← cos_add_int_mul_two_pi _ N, ← sin_add_int_mul_two_pi _ N] have := arg_mul_cos_add_sin_mul_I (abs.pos hz) hN push_cast at this rwa [this] #align complex.arg_mem_Ioc Complex.arg_mem_Ioc @[simp] theorem range_arg : Set.range arg = Set.Ioc (-π) π := (Set.range_subset_iff.2 arg_mem_Ioc).antisymm fun _ hx => ⟨_, arg_cos_add_sin_mul_I hx⟩ #align complex.range_arg Complex.range_arg theorem arg_le_pi (x : ℂ) : arg x ≤ π := (arg_mem_Ioc x).2 #align complex.arg_le_pi Complex.arg_le_pi theorem neg_pi_lt_arg (x : ℂ) : -π < arg x := (arg_mem_Ioc x).1 #align complex.neg_pi_lt_arg Complex.neg_pi_lt_arg theorem abs_arg_le_pi (z : ℂ) : |arg z| ≤ π := abs_le.2 ⟨(neg_pi_lt_arg z).le, arg_le_pi z⟩ #align complex.abs_arg_le_pi Complex.abs_arg_le_pi @[simp] theorem arg_nonneg_iff {z : ℂ} : 0 ≤ arg z ↔ 0 ≤ z.im := by rcases eq_or_ne z 0 with (rfl | h₀); · simp calc 0 ≤ arg z ↔ 0 ≤ Real.sin (arg z) := ⟨fun h => Real.sin_nonneg_of_mem_Icc ⟨h, arg_le_pi z⟩, by contrapose! intro h exact Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _)⟩ _ ↔ _ := by rw [sin_arg, le_div_iff (abs.pos h₀), zero_mul] #align complex.arg_nonneg_iff Complex.arg_nonneg_iff @[simp] theorem arg_neg_iff {z : ℂ} : arg z < 0 ↔ z.im < 0 := lt_iff_lt_of_le_iff_le arg_nonneg_iff #align complex.arg_neg_iff Complex.arg_neg_iff theorem arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := by rcases eq_or_ne x 0 with (rfl | hx); · rw [mul_zero] conv_lhs => rw [← abs_mul_cos_add_sin_mul_I x, ← mul_assoc, ← ofReal_mul, arg_mul_cos_add_sin_mul_I (mul_pos hr (abs.pos hx)) x.arg_mem_Ioc] #align complex.arg_real_mul Complex.arg_real_mul theorem arg_mul_real {r : ℝ} (hr : 0 < r) (x : ℂ) : arg (x * r) = arg x := mul_comm x r ▸ arg_real_mul x hr theorem arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : arg x = arg y ↔ (abs y / abs x : ℂ) * x = y := by simp only [ext_abs_arg_iff, map_mul, map_div₀, abs_ofReal, abs_abs, div_mul_cancel₀ _ (abs.ne_zero hx), eq_self_iff_true, true_and_iff] rw [← ofReal_div, arg_real_mul] exact div_pos (abs.pos hy) (abs.pos hx) #align complex.arg_eq_arg_iff Complex.arg_eq_arg_iff @[simp] theorem arg_one : arg 1 = 0 := by simp [arg, zero_le_one] #align complex.arg_one Complex.arg_one @[simp] theorem arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (zero_lt_one' ℝ)] #align complex.arg_neg_one Complex.arg_neg_one @[simp] theorem arg_I : arg I = π / 2 := by simp [arg, le_refl] set_option linter.uppercaseLean3 false in #align complex.arg_I Complex.arg_I @[simp] theorem arg_neg_I : arg (-I) = -(π / 2) := by simp [arg, le_refl] set_option linter.uppercaseLean3 false in #align complex.arg_neg_I Complex.arg_neg_I @[simp] theorem tan_arg (x : ℂ) : Real.tan (arg x) = x.im / x.re := by by_cases h : x = 0 · simp only [h, zero_div, Complex.zero_im, Complex.arg_zero, Real.tan_zero, Complex.zero_re] rw [Real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_right _ (abs.ne_zero h)] #align complex.tan_arg Complex.tan_arg theorem arg_ofReal_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx] #align complex.arg_of_real_of_nonneg Complex.arg_ofReal_of_nonneg @[simp, norm_cast] lemma natCast_arg {n : ℕ} : arg n = 0 := ofReal_natCast n ▸ arg_ofReal_of_nonneg n.cast_nonneg @[simp] lemma ofNat_arg {n : ℕ} [n.AtLeastTwo] : arg (no_index (OfNat.ofNat n)) = 0 := natCast_arg theorem arg_eq_zero_iff {z : ℂ} : arg z = 0 ↔ 0 ≤ z.re ∧ z.im = 0 := by refine ⟨fun h => ?_, ?_⟩ · rw [← abs_mul_cos_add_sin_mul_I z, h] simp [abs.nonneg] · cases' z with x y rintro ⟨h, rfl : y = 0⟩ exact arg_ofReal_of_nonneg h #align complex.arg_eq_zero_iff Complex.arg_eq_zero_iff open ComplexOrder in lemma arg_eq_zero_iff_zero_le {z : ℂ} : arg z = 0 ↔ 0 ≤ z := by rw [arg_eq_zero_iff, eq_comm, nonneg_iff] theorem arg_eq_pi_iff {z : ℂ} : arg z = π ↔ z.re < 0 ∧ z.im = 0 := by by_cases h₀ : z = 0 · simp [h₀, lt_irrefl, Real.pi_ne_zero.symm] constructor · intro h rw [← abs_mul_cos_add_sin_mul_I z, h] simp [h₀] · cases' z with x y rintro ⟨h : x < 0, rfl : y = 0⟩ rw [← arg_neg_one, ← arg_real_mul (-1) (neg_pos.2 h)] simp [← ofReal_def] #align complex.arg_eq_pi_iff Complex.arg_eq_pi_iff open ComplexOrder in lemma arg_eq_pi_iff_lt_zero {z : ℂ} : arg z = π ↔ z < 0 := arg_eq_pi_iff theorem arg_lt_pi_iff {z : ℂ} : arg z < π ↔ 0 ≤ z.re ∨ z.im ≠ 0 := by rw [(arg_le_pi z).lt_iff_ne, not_iff_comm, not_or, not_le, Classical.not_not, arg_eq_pi_iff] #align complex.arg_lt_pi_iff Complex.arg_lt_pi_iff theorem arg_ofReal_of_neg {x : ℝ} (hx : x < 0) : arg x = π := arg_eq_pi_iff.2 ⟨hx, rfl⟩ #align complex.arg_of_real_of_neg Complex.arg_ofReal_of_neg theorem arg_eq_pi_div_two_iff {z : ℂ} : arg z = π / 2 ↔ z.re = 0 ∧ 0 < z.im := by by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_div_two_pos.ne] constructor · intro h rw [← abs_mul_cos_add_sin_mul_I z, h] simp [h₀] · cases' z with x y rintro ⟨rfl : x = 0, hy : 0 < y⟩ rw [← arg_I, ← arg_real_mul I hy, ofReal_mul', I_re, I_im, mul_zero, mul_one] #align complex.arg_eq_pi_div_two_iff Complex.arg_eq_pi_div_two_iff theorem arg_eq_neg_pi_div_two_iff {z : ℂ} : arg z = -(π / 2) ↔ z.re = 0 ∧ z.im < 0 := by by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_ne_zero] constructor · intro h rw [← abs_mul_cos_add_sin_mul_I z, h] simp [h₀] · cases' z with x y rintro ⟨rfl : x = 0, hy : y < 0⟩ rw [← arg_neg_I, ← arg_real_mul (-I) (neg_pos.2 hy), mk_eq_add_mul_I] simp #align complex.arg_eq_neg_pi_div_two_iff Complex.arg_eq_neg_pi_div_two_iff theorem arg_of_re_nonneg {x : ℂ} (hx : 0 ≤ x.re) : arg x = Real.arcsin (x.im / abs x) := if_pos hx #align complex.arg_of_re_nonneg Complex.arg_of_re_nonneg theorem arg_of_re_neg_of_im_nonneg {x : ℂ} (hx_re : x.re < 0) (hx_im : 0 ≤ x.im) : arg x = Real.arcsin ((-x).im / abs x) + π := by simp only [arg, hx_re.not_le, hx_im, if_true, if_false] #align complex.arg_of_re_neg_of_im_nonneg Complex.arg_of_re_neg_of_im_nonneg theorem arg_of_re_neg_of_im_neg {x : ℂ} (hx_re : x.re < 0) (hx_im : x.im < 0) : arg x = Real.arcsin ((-x).im / abs x) - π := by simp only [arg, hx_re.not_le, hx_im.not_le, if_false] #align complex.arg_of_re_neg_of_im_neg Complex.arg_of_re_neg_of_im_neg theorem arg_of_im_nonneg_of_ne_zero {z : ℂ} (h₁ : 0 ≤ z.im) (h₂ : z ≠ 0) : arg z = Real.arccos (z.re / abs z) := by rw [← cos_arg h₂, Real.arccos_cos (arg_nonneg_iff.2 h₁) (arg_le_pi _)] #align complex.arg_of_im_nonneg_of_ne_zero Complex.arg_of_im_nonneg_of_ne_zero theorem arg_of_im_pos {z : ℂ} (hz : 0 < z.im) : arg z = Real.arccos (z.re / abs z) := arg_of_im_nonneg_of_ne_zero hz.le fun h => hz.ne' <| h.symm ▸ rfl #align complex.arg_of_im_pos Complex.arg_of_im_pos theorem arg_of_im_neg {z : ℂ} (hz : z.im < 0) : arg z = -Real.arccos (z.re / abs z) := by have h₀ : z ≠ 0 := mt (congr_arg im) hz.ne rw [← cos_arg h₀, ← Real.cos_neg, Real.arccos_cos, neg_neg] exacts [neg_nonneg.2 (arg_neg_iff.2 hz).le, neg_le.2 (neg_pi_lt_arg z).le] #align complex.arg_of_im_neg Complex.arg_of_im_neg theorem arg_conj (x : ℂ) : arg (conj x) = if arg x = π then π else -arg x := by simp_rw [arg_eq_pi_iff, arg, neg_im, conj_im, conj_re, abs_conj, neg_div, neg_neg, Real.arcsin_neg] rcases lt_trichotomy x.re 0 with (hr | hr | hr) <;> rcases lt_trichotomy x.im 0 with (hi | hi | hi) · simp [hr, hr.not_le, hi.le, hi.ne, not_le.2 hi, add_comm] · simp [hr, hr.not_le, hi] · simp [hr, hr.not_le, hi.ne.symm, hi.le, not_le.2 hi, sub_eq_neg_add] · simp [hr] · simp [hr] · simp [hr] · simp [hr, hr.le, hi.ne] · simp [hr, hr.le, hr.le.not_lt] · simp [hr, hr.le, hr.le.not_lt] #align complex.arg_conj Complex.arg_conj
Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean
349
353
theorem arg_inv (x : ℂ) : arg x⁻¹ = if arg x = π then π else -arg x := by
rw [← arg_conj, inv_def, mul_comm] by_cases hx : x = 0 · simp [hx] · exact arg_real_mul (conj x) (by simp [hx])
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Simon Hudon -/ import Mathlib.Control.Functor.Multivariate import Mathlib.Data.PFunctor.Multivariate.Basic import Mathlib.Data.PFunctor.Multivariate.M import Mathlib.Data.QPF.Multivariate.Basic #align_import data.qpf.multivariate.constructions.cofix from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # The final co-algebra of a multivariate qpf is again a qpf. For a `(n+1)`-ary QPF `F (α₀,..,αₙ)`, we take the least fixed point of `F` with regards to its last argument `αₙ`. The result is an `n`-ary functor: `Fix F (α₀,..,αₙ₋₁)`. Making `Fix F` into a functor allows us to take the fixed point, compose with other functors and take a fixed point again. ## Main definitions * `Cofix.mk` - constructor * `Cofix.dest` - destructor * `Cofix.corec` - corecursor: useful for formulating infinite, productive computations * `Cofix.bisim` - bisimulation: proof technique to show the equality of possibly infinite values of `Cofix F α` ## Implementation notes For `F` a QPF, we define `Cofix F α` in terms of the M-type of the polynomial functor `P` of `F`. We define the relation `Mcongr` and take its quotient as the definition of `Cofix F α`. `Mcongr` is taken as the weakest bisimulation on M-type. See [avigad-carneiro-hudon2019] for more details. ## Reference * Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u open MvFunctor namespace MvQPF open TypeVec MvPFunctor open MvFunctor (LiftP LiftR) variable {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [mvf : MvFunctor F] [q : MvQPF F] /-- `corecF` is used as a basis for defining the corecursor of `Cofix F α`. `corecF` uses corecursion to construct the M-type generated by `q.P` and uses function on `F` as a corecursive step -/ def corecF {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) : β → q.P.M α := M.corec _ fun x => repr (g x) set_option linter.uppercaseLean3 false in #align mvqpf.corecF MvQPF.corecF theorem corecF_eq {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) (x : β) : M.dest q.P (corecF g x) = appendFun id (corecF g) <$$> repr (g x) := by rw [corecF, M.dest_corec] set_option linter.uppercaseLean3 false in #align mvqpf.corecF_eq MvQPF.corecF_eq /-- Characterization of desirable equivalence relations on M-types -/ def IsPrecongr {α : TypeVec n} (r : q.P.M α → q.P.M α → Prop) : Prop := ∀ ⦃x y⦄, r x y → abs (appendFun id (Quot.mk r) <$$> M.dest q.P x) = abs (appendFun id (Quot.mk r) <$$> M.dest q.P y) #align mvqpf.is_precongr MvQPF.IsPrecongr /-- Equivalence relation on M-types representing a value of type `Cofix F` -/ def Mcongr {α : TypeVec n} (x y : q.P.M α) : Prop := ∃ r, IsPrecongr r ∧ r x y set_option linter.uppercaseLean3 false in #align mvqpf.Mcongr MvQPF.Mcongr /-- Greatest fixed point of functor F. The result is a functor with one fewer parameters than the input. For `F a b c` a ternary functor, fix F is a binary functor such that ```lean Cofix F a b = F a b (Cofix F a b) ``` -/ def Cofix (F : TypeVec (n + 1) → Type u) [MvFunctor F] [q : MvQPF F] (α : TypeVec n) := Quot (@Mcongr _ F _ q α) #align mvqpf.cofix MvQPF.Cofix instance {α : TypeVec n} [Inhabited q.P.A] [∀ i : Fin2 n, Inhabited (α i)] : Inhabited (Cofix F α) := ⟨Quot.mk _ default⟩ /-- maps every element of the W type to a canonical representative -/ def mRepr {α : TypeVec n} : q.P.M α → q.P.M α := corecF (abs ∘ M.dest q.P) set_option linter.uppercaseLean3 false in #align mvqpf.Mrepr MvQPF.mRepr /-- the map function for the functor `Cofix F` -/ def Cofix.map {α β : TypeVec n} (g : α ⟹ β) : Cofix F α → Cofix F β := Quot.lift (fun x : q.P.M α => Quot.mk Mcongr (g <$$> x)) (by rintro aa₁ aa₂ ⟨r, pr, ra₁a₂⟩; apply Quot.sound let r' b₁ b₂ := ∃ a₁ a₂ : q.P.M α, r a₁ a₂ ∧ b₁ = g <$$> a₁ ∧ b₂ = g <$$> a₂ use r'; constructor · show IsPrecongr r' rintro b₁ b₂ ⟨a₁, a₂, ra₁a₂, b₁eq, b₂eq⟩ let u : Quot r → Quot r' := Quot.lift (fun x : q.P.M α => Quot.mk r' (g <$$> x)) (by intro a₁ a₂ ra₁a₂ apply Quot.sound exact ⟨a₁, a₂, ra₁a₂, rfl, rfl⟩) have hu : (Quot.mk r' ∘ fun x : q.P.M α => g <$$> x) = u ∘ Quot.mk r := by ext x rfl rw [b₁eq, b₂eq, M.dest_map, M.dest_map, ← q.P.comp_map, ← q.P.comp_map] rw [← appendFun_comp, id_comp, hu, ← comp_id g, appendFun_comp] rw [q.P.comp_map, q.P.comp_map, abs_map, pr ra₁a₂, ← abs_map] show r' (g <$$> aa₁) (g <$$> aa₂); exact ⟨aa₁, aa₂, ra₁a₂, rfl, rfl⟩) #align mvqpf.cofix.map MvQPF.Cofix.map instance Cofix.mvfunctor : MvFunctor (Cofix F) where map := @Cofix.map _ _ _ _ #align mvqpf.cofix.mvfunctor MvQPF.Cofix.mvfunctor /-- Corecursor for `Cofix F` -/ def Cofix.corec {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) : β → Cofix F α := fun x => Quot.mk _ (corecF g x) #align mvqpf.cofix.corec MvQPF.Cofix.corec /-- Destructor for `Cofix F` -/ def Cofix.dest {α : TypeVec n} : Cofix F α → F (α.append1 (Cofix F α)) := Quot.lift (fun x => appendFun id (Quot.mk Mcongr) <$$> abs (M.dest q.P x)) (by rintro x y ⟨r, pr, rxy⟩ dsimp have : ∀ x y, r x y → Mcongr x y := by intro x y h exact ⟨r, pr, h⟩ rw [← Quot.factor_mk_eq _ _ this] conv => lhs rw [appendFun_comp_id, comp_map, ← abs_map, pr rxy, abs_map, ← comp_map, ← appendFun_comp_id]) #align mvqpf.cofix.dest MvQPF.Cofix.dest /-- Abstraction function for `cofix F α` -/ def Cofix.abs {α} : q.P.M α → Cofix F α := Quot.mk _ #align mvqpf.cofix.abs MvQPF.Cofix.abs /-- Representation function for `Cofix F α` -/ def Cofix.repr {α} : Cofix F α → q.P.M α := M.corec _ <| q.repr ∘ Cofix.dest #align mvqpf.cofix.repr MvQPF.Cofix.repr /-- Corecursor for `Cofix F` -/ def Cofix.corec'₁ {α : TypeVec n} {β : Type u} (g : ∀ {X}, (β → X) → F (α.append1 X)) (x : β) : Cofix F α := Cofix.corec (fun _ => g id) x #align mvqpf.cofix.corec'₁ MvQPF.Cofix.corec'₁ /-- More flexible corecursor for `Cofix F`. Allows the return of a fully formed value instead of making a recursive call -/ def Cofix.corec' {α : TypeVec n} {β : Type u} (g : β → F (α.append1 (Cofix F α ⊕ β))) (x : β) : Cofix F α := let f : (α ::: Cofix F α) ⟹ (α ::: (Cofix F α ⊕ β)) := id ::: Sum.inl Cofix.corec (Sum.elim (MvFunctor.map f ∘ Cofix.dest) g) (Sum.inr x : Cofix F α ⊕ β) #align mvqpf.cofix.corec' MvQPF.Cofix.corec' /-- Corecursor for `Cofix F`. The shape allows recursive calls to look like recursive calls. -/ def Cofix.corec₁ {α : TypeVec n} {β : Type u} (g : ∀ {X}, (Cofix F α → X) → (β → X) → β → F (α ::: X)) (x : β) : Cofix F α := Cofix.corec' (fun x => g Sum.inl Sum.inr x) x #align mvqpf.cofix.corec₁ MvQPF.Cofix.corec₁ theorem Cofix.dest_corec {α : TypeVec n} {β : Type u} (g : β → F (α.append1 β)) (x : β) : Cofix.dest (Cofix.corec g x) = appendFun id (Cofix.corec g) <$$> g x := by conv => lhs rw [Cofix.dest, Cofix.corec]; dsimp rw [corecF_eq, abs_map, abs_repr, ← comp_map, ← appendFun_comp]; rfl #align mvqpf.cofix.dest_corec MvQPF.Cofix.dest_corec /-- constructor for `Cofix F` -/ def Cofix.mk {α : TypeVec n} : F (α.append1 <| Cofix F α) → Cofix F α := Cofix.corec fun x => (appendFun id fun i : Cofix F α => Cofix.dest.{u} i) <$$> x #align mvqpf.cofix.mk MvQPF.Cofix.mk /-! ## Bisimulation principles for `Cofix F` The following theorems are bisimulation principles. The general idea is to use a bisimulation relation to prove the equality between specific values of type `Cofix F α`. A bisimulation relation `R` for values `x y : Cofix F α`: * holds for `x y`: `R x y` * for any values `x y` that satisfy `R`, their root has the same shape and their children can be paired in such a way that they satisfy `R`. -/ private theorem Cofix.bisim_aux {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop) (h' : ∀ x, r x x) (h : ∀ x y, r x y → appendFun id (Quot.mk r) <$$> Cofix.dest x = appendFun id (Quot.mk r) <$$> Cofix.dest y) : ∀ x y, r x y → x = y := by intro x rcases x; clear x; rename M (P F) α => x; intro y rcases y; clear y; rename M (P F) α => y; intro rxy apply Quot.sound let r' := fun x y => r (Quot.mk _ x) (Quot.mk _ y) have hr' : r' = fun x y => r (Quot.mk _ x) (Quot.mk _ y) := rfl have : IsPrecongr r' := by intro a b r'ab have h₀ : appendFun id (Quot.mk r ∘ Quot.mk Mcongr) <$$> MvQPF.abs (M.dest q.P a) = appendFun id (Quot.mk r ∘ Quot.mk Mcongr) <$$> MvQPF.abs (M.dest q.P b) := by rw [appendFun_comp_id, comp_map, comp_map]; exact h _ _ r'ab have h₁ : ∀ u v : q.P.M α, Mcongr u v → Quot.mk r' u = Quot.mk r' v := by intro u v cuv apply Quot.sound dsimp [r', hr'] rw [Quot.sound cuv] apply h' let f : Quot r → Quot r' := Quot.lift (Quot.lift (Quot.mk r') h₁) (by intro c apply Quot.inductionOn (motive := fun c => ∀b, r c b → Quot.lift (Quot.mk r') h₁ c = Quot.lift (Quot.mk r') h₁ b) c clear c intro c d apply Quot.inductionOn (motive := fun d => r (Quot.mk Mcongr c) d → Quot.lift (Quot.mk r') h₁ (Quot.mk Mcongr c) = Quot.lift (Quot.mk r') h₁ d) d clear d intro d rcd; apply Quot.sound; apply rcd) have : f ∘ Quot.mk r ∘ Quot.mk Mcongr = Quot.mk r' := rfl rw [← this, appendFun_comp_id, q.P.comp_map, q.P.comp_map, abs_map, abs_map, abs_map, abs_map, h₀] exact ⟨r', this, rxy⟩ /-- Bisimulation principle using `map` and `Quot.mk` to match and relate children of two trees. -/ theorem Cofix.bisim_rel {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop) (h : ∀ x y, r x y → appendFun id (Quot.mk r) <$$> Cofix.dest x = appendFun id (Quot.mk r) <$$> Cofix.dest y) : ∀ x y, r x y → x = y := by let r' (x y) := x = y ∨ r x y intro x y rxy apply Cofix.bisim_aux r' · intro x left rfl · intro x y r'xy cases r'xy with | inl h => rw [h] | inr r'xy => have : ∀ x y, r x y → r' x y := fun x y h => Or.inr h rw [← Quot.factor_mk_eq _ _ this] dsimp [r'] rw [appendFun_comp_id] rw [@comp_map _ _ _ q _ _ _ (appendFun id (Quot.mk r)), @comp_map _ _ _ q _ _ _ (appendFun id (Quot.mk r))] rw [h _ _ r'xy] right; exact rxy #align mvqpf.cofix.bisim_rel MvQPF.Cofix.bisim_rel /-- Bisimulation principle using `LiftR` to match and relate children of two trees. -/ theorem Cofix.bisim {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop) (h : ∀ x y, r x y → LiftR (RelLast α r (i := _)) (Cofix.dest x) (Cofix.dest y)) : ∀ x y, r x y → x = y := by apply Cofix.bisim_rel intro x y rxy rcases (liftR_iff (fun a b => RelLast α r a b) (dest x) (dest y)).mp (h x y rxy) with ⟨a, f₀, f₁, dxeq, dyeq, h'⟩ rw [dxeq, dyeq, ← abs_map, ← abs_map, MvPFunctor.map_eq, MvPFunctor.map_eq] rw [← split_dropFun_lastFun f₀, ← split_dropFun_lastFun f₁] rw [appendFun_comp_splitFun, appendFun_comp_splitFun] rw [id_comp, id_comp] congr 2 with (i j); cases' i with _ i · apply Quot.sound apply h' _ j · change f₀ _ j = f₁ _ j apply h' _ j #align mvqpf.cofix.bisim MvQPF.Cofix.bisim open MvFunctor /-- Bisimulation principle using `LiftR'` to match and relate children of two trees. -/ theorem Cofix.bisim₂ {α : TypeVec n} (r : Cofix F α → Cofix F α → Prop) (h : ∀ x y, r x y → LiftR' (RelLast' α r) (Cofix.dest x) (Cofix.dest y)) : ∀ x y, r x y → x = y := Cofix.bisim r <| by intros; rw [← LiftR_RelLast_iff]; apply h; assumption #align mvqpf.cofix.bisim₂ MvQPF.Cofix.bisim₂ /-- Bisimulation principle the values `⟨a,f⟩` of the polynomial functor representing `Cofix F α` as well as an invariant `Q : β → Prop` and a state `β` generating the left-hand side and right-hand side of the equality through functions `u v : β → Cofix F α` -/ theorem Cofix.bisim' {α : TypeVec n} {β : Type*} (Q : β → Prop) (u v : β → Cofix F α) (h : ∀ x, Q x → ∃ a f' f₀ f₁, Cofix.dest (u x) = q.abs ⟨a, q.P.appendContents f' f₀⟩ ∧ Cofix.dest (v x) = q.abs ⟨a, q.P.appendContents f' f₁⟩ ∧ ∀ i, ∃ x', Q x' ∧ f₀ i = u x' ∧ f₁ i = v x') : ∀ x, Q x → u x = v x := fun x Qx => let R := fun w z : Cofix F α => ∃ x', Q x' ∧ w = u x' ∧ z = v x' Cofix.bisim R (fun x y ⟨x', Qx', xeq, yeq⟩ => by rcases h x' Qx' with ⟨a, f', f₀, f₁, ux'eq, vx'eq, h'⟩ rw [liftR_iff] refine ⟨a, q.P.appendContents f' f₀, q.P.appendContents f' f₁, xeq.symm ▸ ux'eq, yeq.symm ▸ vx'eq, ?_⟩ intro i; cases i · apply h' · intro j apply Eq.refl) _ _ ⟨x, Qx, rfl, rfl⟩ #align mvqpf.cofix.bisim' MvQPF.Cofix.bisim' theorem Cofix.mk_dest {α : TypeVec n} (x : Cofix F α) : Cofix.mk (Cofix.dest x) = x := by apply Cofix.bisim_rel (fun x y : Cofix F α => x = Cofix.mk (Cofix.dest y)) _ _ _ rfl; dsimp intro x y h rw [h] conv => lhs congr rfl rw [Cofix.mk] rw [Cofix.dest_corec] rw [← comp_map, ← appendFun_comp, id_comp] rw [← comp_map, ← appendFun_comp, id_comp, ← Cofix.mk] congr apply congrArg funext x apply Quot.sound; rfl #align mvqpf.cofix.mk_dest MvQPF.Cofix.mk_dest theorem Cofix.dest_mk {α : TypeVec n} (x : F (α.append1 <| Cofix F α)) : Cofix.dest (Cofix.mk x) = x := by have : Cofix.mk ∘ Cofix.dest = @_root_.id (Cofix F α) := funext Cofix.mk_dest rw [Cofix.mk, Cofix.dest_corec, ← comp_map, ← Cofix.mk, ← appendFun_comp, this, id_comp, appendFun_id_id, MvFunctor.id_map] #align mvqpf.cofix.dest_mk MvQPF.Cofix.dest_mk
Mathlib/Data/QPF/Multivariate/Constructions/Cofix.lean
362
363
theorem Cofix.ext {α : TypeVec n} (x y : Cofix F α) (h : x.dest = y.dest) : x = y := by
rw [← Cofix.mk_dest x, h, Cofix.mk_dest]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis -/ import Mathlib.Algebra.DirectSum.Module import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.Convex.Uniform import Mathlib.Analysis.NormedSpace.Completion import Mathlib.Analysis.NormedSpace.BoundedLinearMaps #align_import analysis.inner_product_space.basic from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Inner product space This file defines inner product spaces and proves the basic properties. We do not formally define Hilbert spaces, but they can be obtained using the set of assumptions `[NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E]`. An inner product space is a vector space endowed with an inner product. It generalizes the notion of dot product in `ℝ^n` and provides the means of defining the length of a vector and the angle between two vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero. We define both the real and complex cases at the same time using the `RCLike` typeclass. This file proves general results on inner product spaces. For the specific construction of an inner product structure on `n → 𝕜` for `𝕜 = ℝ` or `ℂ`, see `EuclideanSpace` in `Analysis.InnerProductSpace.PiL2`. ## Main results - We define the class `InnerProductSpace 𝕜 E` extending `NormedSpace 𝕜 E` with a number of basic properties, most notably the Cauchy-Schwarz inequality. Here `𝕜` is understood to be either `ℝ` or `ℂ`, through the `RCLike` typeclass. - We show that the inner product is continuous, `continuous_inner`, and bundle it as the continuous sesquilinear map `innerSL` (see also `innerₛₗ` for the non-continuous version). - We define `Orthonormal`, a predicate on a function `v : ι → E`, and prove the existence of a maximal orthonormal set, `exists_maximal_orthonormal`. Bessel's inequality, `Orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`, the sum of the norm-squares of the inner products `⟪v i, x⟫` is no more than the norm-square of `x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file `Analysis.InnerProductSpace.projection`. ## Notation We globally denote the real and complex inner products by `⟪·, ·⟫_ℝ` and `⟪·, ·⟫_ℂ` respectively. We also provide two notation namespaces: `RealInnerProductSpace`, `ComplexInnerProductSpace`, which respectively introduce the plain notation `⟪·, ·⟫` for the real and complex inner product. ## Implementation notes We choose the convention that inner products are conjugate linear in the first argument and linear in the second. ## Tags inner product space, Hilbert space, norm ## References * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open Topology ComplexConjugate open LinearMap (BilinForm) variable {𝕜 E F : Type*} [RCLike 𝕜] /-- Syntactic typeclass for types endowed with an inner product -/ class Inner (𝕜 E : Type*) where /-- The inner product function. -/ inner : E → E → 𝕜 #align has_inner Inner export Inner (inner) /-- The inner product with values in `𝕜`. -/ notation3:max "⟪" x ", " y "⟫_" 𝕜:max => @inner 𝕜 _ _ x y section Notations /-- The inner product with values in `ℝ`. -/ scoped[RealInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℝ _ _ x y /-- The inner product with values in `ℂ`. -/ scoped[ComplexInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℂ _ _ x y end Notations /-- An inner product space is a vector space with an additional operation called inner product. The norm could be derived from the inner product, instead we require the existence of a norm and the fact that `‖x‖^2 = re ⟪x, x⟫` to be able to put instances on `𝕂` or product spaces. To construct a norm from an inner product, see `InnerProductSpace.ofCore`. -/ class InnerProductSpace (𝕜 : Type*) (E : Type*) [RCLike 𝕜] [NormedAddCommGroup E] extends NormedSpace 𝕜 E, Inner 𝕜 E where /-- The inner product induces the norm. -/ norm_sq_eq_inner : ∀ x : E, ‖x‖ ^ 2 = re (inner x x) /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space InnerProductSpace /-! ### Constructing a normed space structure from an inner product In the definition of an inner product space, we require the existence of a norm, which is equal (but maybe not defeq) to the square root of the scalar product. This makes it possible to put an inner product space structure on spaces with a preexisting norm (for instance `ℝ`), with good properties. However, sometimes, one would like to define the norm starting only from a well-behaved scalar product. This is what we implement in this paragraph, starting from a structure `InnerProductSpace.Core` stating that we have a nice scalar product. Our goal here is not to develop a whole theory with all the supporting API, as this will be done below for `InnerProductSpace`. Instead, we implement the bare minimum to go as directly as possible to the construction of the norm and the proof of the triangular inequality. Warning: Do not use this `Core` structure if the space you are interested in already has a norm instance defined on it, otherwise this will create a second non-defeq norm instance! -/ /-- A structure requiring that a scalar product is positive definite and symmetric, from which one can construct an `InnerProductSpace` instance in `InnerProductSpace.ofCore`. -/ -- @[nolint HasNonemptyInstance] porting note: I don't think we have this linter anymore structure InnerProductSpace.Core (𝕜 : Type*) (F : Type*) [RCLike 𝕜] [AddCommGroup F] [Module 𝕜 F] extends Inner 𝕜 F where /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is positive (semi)definite. -/ nonneg_re : ∀ x, 0 ≤ re (inner x x) /-- The inner product is positive definite. -/ definite : ∀ x, inner x x = 0 → x = 0 /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space.core InnerProductSpace.Core /- We set `InnerProductSpace.Core` to be a class as we will use it as such in the construction of the normed space structure that it produces. However, all the instances we will use will be local to this proof. -/ attribute [class] InnerProductSpace.Core /-- Define `InnerProductSpace.Core` from `InnerProductSpace`. Defined to reuse lemmas about `InnerProductSpace.Core` for `InnerProductSpace`s. Note that the `Norm` instance provided by `InnerProductSpace.Core.norm` is propositionally but not definitionally equal to the original norm. -/ def InnerProductSpace.toCore [NormedAddCommGroup E] [c : InnerProductSpace 𝕜 E] : InnerProductSpace.Core 𝕜 E := { c with nonneg_re := fun x => by rw [← InnerProductSpace.norm_sq_eq_inner] apply sq_nonneg definite := fun x hx => norm_eq_zero.1 <| pow_eq_zero (n := 2) <| by rw [InnerProductSpace.norm_sq_eq_inner (𝕜 := 𝕜) x, hx, map_zero] } #align inner_product_space.to_core InnerProductSpace.toCore namespace InnerProductSpace.Core variable [AddCommGroup F] [Module 𝕜 F] [c : InnerProductSpace.Core 𝕜 F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 F _ x y local notation "normSqK" => @RCLike.normSq 𝕜 _ local notation "reK" => @RCLike.re 𝕜 _ local notation "ext_iff" => @RCLike.ext_iff 𝕜 _ local postfix:90 "†" => starRingEnd _ /-- Inner product defined by the `InnerProductSpace.Core` structure. We can't reuse `InnerProductSpace.Core.toInner` because it takes `InnerProductSpace.Core` as an explicit argument. -/ def toInner' : Inner 𝕜 F := c.toInner #align inner_product_space.core.to_has_inner' InnerProductSpace.Core.toInner' attribute [local instance] toInner' /-- The norm squared function for `InnerProductSpace.Core` structure. -/ def normSq (x : F) := reK ⟪x, x⟫ #align inner_product_space.core.norm_sq InnerProductSpace.Core.normSq local notation "normSqF" => @normSq 𝕜 F _ _ _ _ theorem inner_conj_symm (x y : F) : ⟪y, x⟫† = ⟪x, y⟫ := c.conj_symm x y #align inner_product_space.core.inner_conj_symm InnerProductSpace.Core.inner_conj_symm theorem inner_self_nonneg {x : F} : 0 ≤ re ⟪x, x⟫ := c.nonneg_re _ #align inner_product_space.core.inner_self_nonneg InnerProductSpace.Core.inner_self_nonneg theorem inner_self_im (x : F) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub] simp [inner_conj_symm] #align inner_product_space.core.inner_self_im InnerProductSpace.Core.inner_self_im theorem inner_add_left (x y z : F) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := c.add_left _ _ _ #align inner_product_space.core.inner_add_left InnerProductSpace.Core.inner_add_left theorem inner_add_right (x y z : F) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add]; simp only [inner_conj_symm] #align inner_product_space.core.inner_add_right InnerProductSpace.Core.inner_add_right theorem ofReal_normSq_eq_inner_self (x : F) : (normSqF x : 𝕜) = ⟪x, x⟫ := by rw [ext_iff] exact ⟨by simp only [ofReal_re]; rfl, by simp only [inner_self_im, ofReal_im]⟩ #align inner_product_space.core.coe_norm_sq_eq_inner_self InnerProductSpace.Core.ofReal_normSq_eq_inner_self theorem inner_re_symm (x y : F) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re] #align inner_product_space.core.inner_re_symm InnerProductSpace.Core.inner_re_symm theorem inner_im_symm (x y : F) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im] #align inner_product_space.core.inner_im_symm InnerProductSpace.Core.inner_im_symm theorem inner_smul_left (x y : F) {r : 𝕜} : ⟪r • x, y⟫ = r† * ⟪x, y⟫ := c.smul_left _ _ _ #align inner_product_space.core.inner_smul_left InnerProductSpace.Core.inner_smul_left theorem inner_smul_right (x y : F) {r : 𝕜} : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by rw [← inner_conj_symm, inner_smul_left]; simp only [conj_conj, inner_conj_symm, RingHom.map_mul] #align inner_product_space.core.inner_smul_right InnerProductSpace.Core.inner_smul_right theorem inner_zero_left (x : F) : ⟪0, x⟫ = 0 := by rw [← zero_smul 𝕜 (0 : F), inner_smul_left]; simp only [zero_mul, RingHom.map_zero] #align inner_product_space.core.inner_zero_left InnerProductSpace.Core.inner_zero_left theorem inner_zero_right (x : F) : ⟪x, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left]; simp only [RingHom.map_zero] #align inner_product_space.core.inner_zero_right InnerProductSpace.Core.inner_zero_right theorem inner_self_eq_zero {x : F} : ⟪x, x⟫ = 0 ↔ x = 0 := ⟨c.definite _, by rintro rfl exact inner_zero_left _⟩ #align inner_product_space.core.inner_self_eq_zero InnerProductSpace.Core.inner_self_eq_zero theorem normSq_eq_zero {x : F} : normSqF x = 0 ↔ x = 0 := Iff.trans (by simp only [normSq, ext_iff, map_zero, inner_self_im, eq_self_iff_true, and_true_iff]) (@inner_self_eq_zero 𝕜 _ _ _ _ _ x) #align inner_product_space.core.norm_sq_eq_zero InnerProductSpace.Core.normSq_eq_zero theorem inner_self_ne_zero {x : F} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 := inner_self_eq_zero.not #align inner_product_space.core.inner_self_ne_zero InnerProductSpace.Core.inner_self_ne_zero theorem inner_self_ofReal_re (x : F) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := by norm_num [ext_iff, inner_self_im] set_option linter.uppercaseLean3 false in #align inner_product_space.core.inner_self_re_to_K InnerProductSpace.Core.inner_self_ofReal_re theorem norm_inner_symm (x y : F) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj] #align inner_product_space.core.norm_inner_symm InnerProductSpace.Core.norm_inner_symm theorem inner_neg_left (x y : F) : ⟪-x, y⟫ = -⟪x, y⟫ := by rw [← neg_one_smul 𝕜 x, inner_smul_left] simp #align inner_product_space.core.inner_neg_left InnerProductSpace.Core.inner_neg_left theorem inner_neg_right (x y : F) : ⟪x, -y⟫ = -⟪x, y⟫ := by rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm] #align inner_product_space.core.inner_neg_right InnerProductSpace.Core.inner_neg_right theorem inner_sub_left (x y z : F) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by simp [sub_eq_add_neg, inner_add_left, inner_neg_left] #align inner_product_space.core.inner_sub_left InnerProductSpace.Core.inner_sub_left theorem inner_sub_right (x y z : F) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by simp [sub_eq_add_neg, inner_add_right, inner_neg_right] #align inner_product_space.core.inner_sub_right InnerProductSpace.Core.inner_sub_right theorem inner_mul_symm_re_eq_norm (x y : F) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by rw [← inner_conj_symm, mul_comm] exact re_eq_norm_of_mul_conj (inner y x) #align inner_product_space.core.inner_mul_symm_re_eq_norm InnerProductSpace.Core.inner_mul_symm_re_eq_norm /-- Expand `inner (x + y) (x + y)` -/ theorem inner_add_add_self (x y : F) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_add_left, inner_add_right]; ring #align inner_product_space.core.inner_add_add_self InnerProductSpace.Core.inner_add_add_self -- Expand `inner (x - y) (x - y)` theorem inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_sub_left, inner_sub_right]; ring #align inner_product_space.core.inner_sub_sub_self InnerProductSpace.Core.inner_sub_sub_self /-- An auxiliary equality useful to prove the **Cauchy–Schwarz inequality**: the square of the norm of `⟪x, y⟫ • x - ⟪x, x⟫ • y` is equal to `‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2 - ‖⟪x, y⟫‖ ^ 2)`. We use `InnerProductSpace.ofCore.normSq x` etc (defeq to `is_R_or_C.re ⟪x, x⟫`) instead of `‖x‖ ^ 2` etc to avoid extra rewrites when applying it to an `InnerProductSpace`. -/ theorem cauchy_schwarz_aux (x y : F) : normSqF (⟪x, y⟫ • x - ⟪x, x⟫ • y) = normSqF x * (normSqF x * normSqF y - ‖⟪x, y⟫‖ ^ 2) := by rw [← @ofReal_inj 𝕜, ofReal_normSq_eq_inner_self] simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, conj_ofReal, mul_sub, ← ofReal_normSq_eq_inner_self x, ← ofReal_normSq_eq_inner_self y] rw [← mul_assoc, mul_conj, RCLike.conj_mul, mul_left_comm, ← inner_conj_symm y, mul_conj] push_cast ring #align inner_product_space.core.cauchy_schwarz_aux InnerProductSpace.Core.cauchy_schwarz_aux /-- **Cauchy–Schwarz inequality**. We need this for the `Core` structure to prove the triangle inequality below when showing the core is a normed group. -/ theorem inner_mul_inner_self_le (x y : F) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := by rcases eq_or_ne x 0 with (rfl | hx) · simpa only [inner_zero_left, map_zero, zero_mul, norm_zero] using le_rfl · have hx' : 0 < normSqF x := inner_self_nonneg.lt_of_ne' (mt normSq_eq_zero.1 hx) rw [← sub_nonneg, ← mul_nonneg_iff_right_nonneg_of_pos hx', ← normSq, ← normSq, norm_inner_symm y, ← sq, ← cauchy_schwarz_aux] exact inner_self_nonneg #align inner_product_space.core.inner_mul_inner_self_le InnerProductSpace.Core.inner_mul_inner_self_le /-- Norm constructed from an `InnerProductSpace.Core` structure, defined to be the square root of the scalar product. -/ def toNorm : Norm F where norm x := √(re ⟪x, x⟫) #align inner_product_space.core.to_has_norm InnerProductSpace.Core.toNorm attribute [local instance] toNorm theorem norm_eq_sqrt_inner (x : F) : ‖x‖ = √(re ⟪x, x⟫) := rfl #align inner_product_space.core.norm_eq_sqrt_inner InnerProductSpace.Core.norm_eq_sqrt_inner theorem inner_self_eq_norm_mul_norm (x : F) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by rw [norm_eq_sqrt_inner, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg] #align inner_product_space.core.inner_self_eq_norm_mul_norm InnerProductSpace.Core.inner_self_eq_norm_mul_norm theorem sqrt_normSq_eq_norm (x : F) : √(normSqF x) = ‖x‖ := rfl #align inner_product_space.core.sqrt_norm_sq_eq_norm InnerProductSpace.Core.sqrt_normSq_eq_norm /-- Cauchy–Schwarz inequality with norm -/ theorem norm_inner_le_norm (x y : F) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := nonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) <| calc ‖⟪x, y⟫‖ * ‖⟪x, y⟫‖ = ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ := by rw [norm_inner_symm] _ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := inner_mul_inner_self_le x y _ = ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) := by simp only [inner_self_eq_norm_mul_norm]; ring #align inner_product_space.core.norm_inner_le_norm InnerProductSpace.Core.norm_inner_le_norm /-- Normed group structure constructed from an `InnerProductSpace.Core` structure -/ def toNormedAddCommGroup : NormedAddCommGroup F := AddGroupNorm.toNormedAddCommGroup { toFun := fun x => √(re ⟪x, x⟫) map_zero' := by simp only [sqrt_zero, inner_zero_right, map_zero] neg' := fun x => by simp only [inner_neg_left, neg_neg, inner_neg_right] add_le' := fun x y => by have h₁ : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := norm_inner_le_norm _ _ have h₂ : re ⟪x, y⟫ ≤ ‖⟪x, y⟫‖ := re_le_norm _ have h₃ : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := h₂.trans h₁ have h₄ : re ⟪y, x⟫ ≤ ‖x‖ * ‖y‖ := by rwa [← inner_conj_symm, conj_re] have : ‖x + y‖ * ‖x + y‖ ≤ (‖x‖ + ‖y‖) * (‖x‖ + ‖y‖) := by simp only [← inner_self_eq_norm_mul_norm, inner_add_add_self, mul_add, mul_comm, map_add] linarith exact nonneg_le_nonneg_of_sq_le_sq (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) this eq_zero_of_map_eq_zero' := fun x hx => normSq_eq_zero.1 <| (sqrt_eq_zero inner_self_nonneg).1 hx } #align inner_product_space.core.to_normed_add_comm_group InnerProductSpace.Core.toNormedAddCommGroup attribute [local instance] toNormedAddCommGroup /-- Normed space structure constructed from an `InnerProductSpace.Core` structure -/ def toNormedSpace : NormedSpace 𝕜 F where norm_smul_le r x := by rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, ← mul_assoc] rw [RCLike.conj_mul, ← ofReal_pow, re_ofReal_mul, sqrt_mul, ← ofReal_normSq_eq_inner_self, ofReal_re] · simp [sqrt_normSq_eq_norm, RCLike.sqrt_normSq_eq_norm] · positivity #align inner_product_space.core.to_normed_space InnerProductSpace.Core.toNormedSpace end InnerProductSpace.Core section attribute [local instance] InnerProductSpace.Core.toNormedAddCommGroup /-- Given an `InnerProductSpace.Core` structure on a space, one can use it to turn the space into an inner product space. The `NormedAddCommGroup` structure is expected to already be defined with `InnerProductSpace.ofCore.toNormedAddCommGroup`. -/ def InnerProductSpace.ofCore [AddCommGroup F] [Module 𝕜 F] (c : InnerProductSpace.Core 𝕜 F) : InnerProductSpace 𝕜 F := letI : NormedSpace 𝕜 F := @InnerProductSpace.Core.toNormedSpace 𝕜 F _ _ _ c { c with norm_sq_eq_inner := fun x => by have h₁ : ‖x‖ ^ 2 = √(re (c.inner x x)) ^ 2 := rfl have h₂ : 0 ≤ re (c.inner x x) := InnerProductSpace.Core.inner_self_nonneg simp [h₁, sq_sqrt, h₂] } #align inner_product_space.of_core InnerProductSpace.ofCore end /-! ### Properties of inner product spaces -/ variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "IK" => @RCLike.I 𝕜 _ local postfix:90 "†" => starRingEnd _ export InnerProductSpace (norm_sq_eq_inner) section BasicProperties @[simp] theorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ := InnerProductSpace.conj_symm _ _ #align inner_conj_symm inner_conj_symm theorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := @inner_conj_symm ℝ _ _ _ _ x y #align real_inner_comm real_inner_comm theorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 := by rw [← inner_conj_symm] exact star_eq_zero #align inner_eq_zero_symm inner_eq_zero_symm @[simp] theorem inner_self_im (x : E) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub]; simp #align inner_self_im inner_self_im theorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := InnerProductSpace.add_left _ _ _ #align inner_add_left inner_add_left theorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add] simp only [inner_conj_symm] #align inner_add_right inner_add_right theorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re] #align inner_re_symm inner_re_symm theorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im] #align inner_im_symm inner_im_symm theorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ := InnerProductSpace.smul_left _ _ _ #align inner_smul_left inner_smul_left theorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_left _ _ _ #align real_inner_smul_left real_inner_smul_left theorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ := by rw [inner_smul_left, conj_ofReal, Algebra.smul_def] rfl #align inner_smul_real_left inner_smul_real_left theorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by rw [← inner_conj_symm, inner_smul_left, RingHom.map_mul, conj_conj, inner_conj_symm] #align inner_smul_right inner_smul_right theorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_right _ _ _ #align real_inner_smul_right real_inner_smul_right theorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ := by rw [inner_smul_right, Algebra.smul_def] rfl #align inner_smul_real_right inner_smul_real_right /-- The inner product as a sesquilinear form. Note that in the case `𝕜 = ℝ` this is a bilinear form. -/ @[simps!] def sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 := LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫) (fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _) (fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _ #align sesq_form_of_inner sesqFormOfInner /-- The real inner product as a bilinear form. Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/ @[simps!] def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip #align bilin_form_of_real_inner bilinFormOfRealInner /-- An inner product with a sum on the left. -/ theorem sum_inner {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) : ⟪∑ i ∈ s, f i, x⟫ = ∑ i ∈ s, ⟪f i, x⟫ := map_sum (sesqFormOfInner (𝕜 := 𝕜) (E := E) x) _ _ #align sum_inner sum_inner /-- An inner product with a sum on the right. -/ theorem inner_sum {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) : ⟪x, ∑ i ∈ s, f i⟫ = ∑ i ∈ s, ⟪x, f i⟫ := map_sum (LinearMap.flip sesqFormOfInner x) _ _ #align inner_sum inner_sum /-- An inner product with a sum on the left, `Finsupp` version. -/ theorem Finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) : ⟪l.sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ := by convert _root_.sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x simp only [inner_smul_left, Finsupp.sum, smul_eq_mul] #align finsupp.sum_inner Finsupp.sum_inner /-- An inner product with a sum on the right, `Finsupp` version. -/ theorem Finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) : ⟪x, l.sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ := by convert _root_.inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x simp only [inner_smul_right, Finsupp.sum, smul_eq_mul] #align finsupp.inner_sum Finsupp.inner_sum theorem DFinsupp.sum_inner {ι : Type*} [DecidableEq ι] {α : ι → Type*} [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E) (l : Π₀ i, α i) (x : E) : ⟪l.sum f, x⟫ = l.sum fun i a => ⟪f i a, x⟫ := by simp (config := { contextual := true }) only [DFinsupp.sum, _root_.sum_inner, smul_eq_mul] #align dfinsupp.sum_inner DFinsupp.sum_inner theorem DFinsupp.inner_sum {ι : Type*} [DecidableEq ι] {α : ι → Type*} [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E) (l : Π₀ i, α i) (x : E) : ⟪x, l.sum f⟫ = l.sum fun i a => ⟪x, f i a⟫ := by simp (config := { contextual := true }) only [DFinsupp.sum, _root_.inner_sum, smul_eq_mul] #align dfinsupp.inner_sum DFinsupp.inner_sum @[simp] theorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul] #align inner_zero_left inner_zero_left theorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by simp only [inner_zero_left, AddMonoidHom.map_zero] #align inner_re_zero_left inner_re_zero_left @[simp] theorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero] #align inner_zero_right inner_zero_right theorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by simp only [inner_zero_right, AddMonoidHom.map_zero] #align inner_re_zero_right inner_re_zero_right theorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ := InnerProductSpace.toCore.nonneg_re x #align inner_self_nonneg inner_self_nonneg theorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ := @inner_self_nonneg ℝ F _ _ _ x #align real_inner_self_nonneg real_inner_self_nonneg @[simp] theorem inner_self_ofReal_re (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := ((RCLike.is_real_TFAE (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im _) set_option linter.uppercaseLean3 false in #align inner_self_re_to_K inner_self_ofReal_re theorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ : 𝕜) ^ 2 := by rw [← inner_self_ofReal_re, ← norm_sq_eq_inner, ofReal_pow] set_option linter.uppercaseLean3 false in #align inner_self_eq_norm_sq_to_K inner_self_eq_norm_sq_to_K theorem inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ := by conv_rhs => rw [← inner_self_ofReal_re] symm exact norm_of_nonneg inner_self_nonneg #align inner_self_re_eq_norm inner_self_re_eq_norm theorem inner_self_ofReal_norm (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ := by rw [← inner_self_re_eq_norm] exact inner_self_ofReal_re _ set_option linter.uppercaseLean3 false in #align inner_self_norm_to_K inner_self_ofReal_norm theorem real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ := @inner_self_ofReal_norm ℝ F _ _ _ x #align real_inner_self_abs real_inner_self_abs @[simp] theorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 := by rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero] #align inner_self_eq_zero inner_self_eq_zero theorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 := inner_self_eq_zero.not #align inner_self_ne_zero inner_self_ne_zero @[simp] theorem inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 := by rw [← norm_sq_eq_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero] #align inner_self_nonpos inner_self_nonpos theorem real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 := @inner_self_nonpos ℝ F _ _ _ x #align real_inner_self_nonpos real_inner_self_nonpos theorem norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj] #align norm_inner_symm norm_inner_symm @[simp] theorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ := by rw [← neg_one_smul 𝕜 x, inner_smul_left] simp #align inner_neg_left inner_neg_left @[simp] theorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm] #align inner_neg_right inner_neg_right theorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp #align inner_neg_neg inner_neg_neg -- Porting note: removed `simp` because it can prove it using `inner_conj_symm` theorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := inner_conj_symm _ _ #align inner_self_conj inner_self_conj theorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by simp [sub_eq_add_neg, inner_add_left] #align inner_sub_left inner_sub_left theorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by simp [sub_eq_add_neg, inner_add_right] #align inner_sub_right inner_sub_right theorem inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by rw [← inner_conj_symm, mul_comm] exact re_eq_norm_of_mul_conj (inner y x) #align inner_mul_symm_re_eq_norm inner_mul_symm_re_eq_norm /-- Expand `⟪x + y, x + y⟫` -/ theorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_add_left, inner_add_right]; ring #align inner_add_add_self inner_add_add_self /-- Expand `⟪x + y, x + y⟫_ℝ` -/ theorem real_inner_add_add_self (x y : F) : ⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_add_add_self, this, add_left_inj] ring #align real_inner_add_add_self real_inner_add_add_self -- Expand `⟪x - y, x - y⟫` theorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_sub_left, inner_sub_right]; ring #align inner_sub_sub_self inner_sub_sub_self /-- Expand `⟪x - y, x - y⟫_ℝ` -/ theorem real_inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_sub_sub_self, this, add_left_inj] ring #align real_inner_sub_sub_self real_inner_sub_sub_self variable (𝕜) theorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)] #align ext_inner_left ext_inner_left theorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)] #align ext_inner_right ext_inner_right variable {𝕜} /-- Parallelogram law -/ theorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by simp only [inner_add_add_self, inner_sub_sub_self] ring #align parallelogram_law parallelogram_law /-- **Cauchy–Schwarz inequality**. -/ theorem inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := letI c : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore InnerProductSpace.Core.inner_mul_inner_self_le x y #align inner_mul_inner_self_le inner_mul_inner_self_le /-- Cauchy–Schwarz inequality for real inner products. -/ theorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := calc ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ := by rw [real_inner_comm y, ← norm_mul] exact le_abs_self _ _ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y #align real_inner_mul_inner_self_le real_inner_mul_inner_self_le /-- A family of vectors is linearly independent if they are nonzero and orthogonal. -/ theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ι : Type*} {v : ι → E} (hz : ∀ i, v i ≠ 0) (ho : Pairwise fun i j => ⟪v i, v j⟫ = 0) : LinearIndependent 𝕜 v := by rw [linearIndependent_iff'] intro s g hg i hi have h' : g i * inner (v i) (v i) = inner (v i) (∑ j ∈ s, g j • v j) := by rw [inner_sum] symm convert Finset.sum_eq_single (β := 𝕜) i ?_ ?_ · rw [inner_smul_right] · intro j _hj hji rw [inner_smul_right, ho hji.symm, mul_zero] · exact fun h => False.elim (h hi) simpa [hg, hz] using h' #align linear_independent_of_ne_zero_of_inner_eq_zero linearIndependent_of_ne_zero_of_inner_eq_zero end BasicProperties section OrthonormalSets variable {ι : Type*} (𝕜) /-- An orthonormal set of vectors in an `InnerProductSpace` -/ def Orthonormal (v : ι → E) : Prop := (∀ i, ‖v i‖ = 1) ∧ Pairwise fun i j => ⟪v i, v j⟫ = 0 #align orthonormal Orthonormal variable {𝕜} /-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal. (Inner product equals Kronecker delta.) -/ theorem orthonormal_iff_ite [DecidableEq ι] {v : ι → E} : Orthonormal 𝕜 v ↔ ∀ i j, ⟪v i, v j⟫ = if i = j then (1 : 𝕜) else (0 : 𝕜) := by constructor · intro hv i j split_ifs with h · simp [h, inner_self_eq_norm_sq_to_K, hv.1] · exact hv.2 h · intro h constructor · intro i have h' : ‖v i‖ ^ 2 = 1 ^ 2 := by simp [@norm_sq_eq_inner 𝕜, h i i] have h₁ : 0 ≤ ‖v i‖ := norm_nonneg _ have h₂ : (0 : ℝ) ≤ 1 := zero_le_one rwa [sq_eq_sq h₁ h₂] at h' · intro i j hij simpa [hij] using h i j #align orthonormal_iff_ite orthonormal_iff_ite /-- `if ... then ... else` characterization of a set of vectors being orthonormal. (Inner product equals Kronecker delta.) -/ theorem orthonormal_subtype_iff_ite [DecidableEq E] {s : Set E} : Orthonormal 𝕜 (Subtype.val : s → E) ↔ ∀ v ∈ s, ∀ w ∈ s, ⟪v, w⟫ = if v = w then 1 else 0 := by rw [orthonormal_iff_ite] constructor · intro h v hv w hw convert h ⟨v, hv⟩ ⟨w, hw⟩ using 1 simp · rintro h ⟨v, hv⟩ ⟨w, hw⟩ convert h v hv w hw using 1 simp #align orthonormal_subtype_iff_ite orthonormal_subtype_iff_ite /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_right_finsupp {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) : ⟪v i, Finsupp.total ι E 𝕜 v l⟫ = l i := by classical simpa [Finsupp.total_apply, Finsupp.inner_sum, orthonormal_iff_ite.mp hv] using Eq.symm #align orthonormal.inner_right_finsupp Orthonormal.inner_right_finsupp /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_right_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) {s : Finset ι} {i : ι} (hi : i ∈ s) : ⟪v i, ∑ i ∈ s, l i • v i⟫ = l i := by classical simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv, hi] #align orthonormal.inner_right_sum Orthonormal.inner_right_sum /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_right_fintype [Fintype ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) : ⟪v i, ∑ i : ι, l i • v i⟫ = l i := hv.inner_right_sum l (Finset.mem_univ _) #align orthonormal.inner_right_fintype Orthonormal.inner_right_fintype /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_left_finsupp {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) : ⟪Finsupp.total ι E 𝕜 v l, v i⟫ = conj (l i) := by rw [← inner_conj_symm, hv.inner_right_finsupp] #align orthonormal.inner_left_finsupp Orthonormal.inner_left_finsupp /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_left_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) {s : Finset ι} {i : ι} (hi : i ∈ s) : ⟪∑ i ∈ s, l i • v i, v i⟫ = conj (l i) := by classical simp only [sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv, hi, mul_boole, Finset.sum_ite_eq', if_true] #align orthonormal.inner_left_sum Orthonormal.inner_left_sum /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_left_fintype [Fintype ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) : ⟪∑ i : ι, l i • v i, v i⟫ = conj (l i) := hv.inner_left_sum l (Finset.mem_univ _) #align orthonormal.inner_left_fintype Orthonormal.inner_left_fintype /-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as a sum over the first `Finsupp`. -/ theorem Orthonormal.inner_finsupp_eq_sum_left {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) : ⟪Finsupp.total ι E 𝕜 v l₁, Finsupp.total ι E 𝕜 v l₂⟫ = l₁.sum fun i y => conj y * l₂ i := by simp only [l₁.total_apply _, Finsupp.sum_inner, hv.inner_right_finsupp, smul_eq_mul] #align orthonormal.inner_finsupp_eq_sum_left Orthonormal.inner_finsupp_eq_sum_left /-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as a sum over the second `Finsupp`. -/ theorem Orthonormal.inner_finsupp_eq_sum_right {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) : ⟪Finsupp.total ι E 𝕜 v l₁, Finsupp.total ι E 𝕜 v l₂⟫ = l₂.sum fun i y => conj (l₁ i) * y := by simp only [l₂.total_apply _, Finsupp.inner_sum, hv.inner_left_finsupp, mul_comm, smul_eq_mul] #align orthonormal.inner_finsupp_eq_sum_right Orthonormal.inner_finsupp_eq_sum_right /-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as a sum. -/ theorem Orthonormal.inner_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι → 𝕜) (s : Finset ι) : ⟪∑ i ∈ s, l₁ i • v i, ∑ i ∈ s, l₂ i • v i⟫ = ∑ i ∈ s, conj (l₁ i) * l₂ i := by simp_rw [sum_inner, inner_smul_left] refine Finset.sum_congr rfl fun i hi => ?_ rw [hv.inner_right_sum l₂ hi] #align orthonormal.inner_sum Orthonormal.inner_sum /-- The double sum of weighted inner products of pairs of vectors from an orthonormal sequence is the sum of the weights. -/ theorem Orthonormal.inner_left_right_finset {s : Finset ι} {v : ι → E} (hv : Orthonormal 𝕜 v) {a : ι → ι → 𝕜} : (∑ i ∈ s, ∑ j ∈ s, a i j • ⟪v j, v i⟫) = ∑ k ∈ s, a k k := by classical simp [orthonormal_iff_ite.mp hv, Finset.sum_ite_of_true] #align orthonormal.inner_left_right_finset Orthonormal.inner_left_right_finset /-- An orthonormal set is linearly independent. -/ theorem Orthonormal.linearIndependent {v : ι → E} (hv : Orthonormal 𝕜 v) : LinearIndependent 𝕜 v := by rw [linearIndependent_iff] intro l hl ext i have key : ⟪v i, Finsupp.total ι E 𝕜 v l⟫ = ⟪v i, 0⟫ := by rw [hl] simpa only [hv.inner_right_finsupp, inner_zero_right] using key #align orthonormal.linear_independent Orthonormal.linearIndependent /-- A subfamily of an orthonormal family (i.e., a composition with an injective map) is an orthonormal family. -/ theorem Orthonormal.comp {ι' : Type*} {v : ι → E} (hv : Orthonormal 𝕜 v) (f : ι' → ι) (hf : Function.Injective f) : Orthonormal 𝕜 (v ∘ f) := by classical rw [orthonormal_iff_ite] at hv ⊢ intro i j convert hv (f i) (f j) using 1 simp [hf.eq_iff] #align orthonormal.comp Orthonormal.comp /-- An injective family `v : ι → E` is orthonormal if and only if `Subtype.val : (range v) → E` is orthonormal. -/ theorem orthonormal_subtype_range {v : ι → E} (hv : Function.Injective v) : Orthonormal 𝕜 (Subtype.val : Set.range v → E) ↔ Orthonormal 𝕜 v := by let f : ι ≃ Set.range v := Equiv.ofInjective v hv refine ⟨fun h => h.comp f f.injective, fun h => ?_⟩ rw [← Equiv.self_comp_ofInjective_symm hv] exact h.comp f.symm f.symm.injective #align orthonormal_subtype_range orthonormal_subtype_range /-- If `v : ι → E` is an orthonormal family, then `Subtype.val : (range v) → E` is an orthonormal family. -/ theorem Orthonormal.toSubtypeRange {v : ι → E} (hv : Orthonormal 𝕜 v) : Orthonormal 𝕜 (Subtype.val : Set.range v → E) := (orthonormal_subtype_range hv.linearIndependent.injective).2 hv #align orthonormal.to_subtype_range Orthonormal.toSubtypeRange /-- A linear combination of some subset of an orthonormal set is orthogonal to other members of the set. -/ theorem Orthonormal.inner_finsupp_eq_zero {v : ι → E} (hv : Orthonormal 𝕜 v) {s : Set ι} {i : ι} (hi : i ∉ s) {l : ι →₀ 𝕜} (hl : l ∈ Finsupp.supported 𝕜 𝕜 s) : ⟪Finsupp.total ι E 𝕜 v l, v i⟫ = 0 := by rw [Finsupp.mem_supported'] at hl simp only [hv.inner_left_finsupp, hl i hi, map_zero] #align orthonormal.inner_finsupp_eq_zero Orthonormal.inner_finsupp_eq_zero /-- Given an orthonormal family, a second family of vectors is orthonormal if every vector equals the corresponding vector in the original family or its negation. -/ theorem Orthonormal.orthonormal_of_forall_eq_or_eq_neg {v w : ι → E} (hv : Orthonormal 𝕜 v) (hw : ∀ i, w i = v i ∨ w i = -v i) : Orthonormal 𝕜 w := by classical rw [orthonormal_iff_ite] at * intro i j cases' hw i with hi hi <;> cases' hw j with hj hj <;> replace hv := hv i j <;> split_ifs at hv ⊢ with h <;> simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv #align orthonormal.orthonormal_of_forall_eq_or_eq_neg Orthonormal.orthonormal_of_forall_eq_or_eq_neg /- The material that follows, culminating in the existence of a maximal orthonormal subset, is adapted from the corresponding development of the theory of linearly independents sets. See `exists_linearIndependent` in particular. -/ variable (𝕜 E) theorem orthonormal_empty : Orthonormal 𝕜 (fun x => x : (∅ : Set E) → E) := by classical simp [orthonormal_subtype_iff_ite] #align orthonormal_empty orthonormal_empty variable {𝕜 E} theorem orthonormal_iUnion_of_directed {η : Type*} {s : η → Set E} (hs : Directed (· ⊆ ·) s) (h : ∀ i, Orthonormal 𝕜 (fun x => x : s i → E)) : Orthonormal 𝕜 (fun x => x : (⋃ i, s i) → E) := by classical rw [orthonormal_subtype_iff_ite] rintro x ⟨_, ⟨i, rfl⟩, hxi⟩ y ⟨_, ⟨j, rfl⟩, hyj⟩ obtain ⟨k, hik, hjk⟩ := hs i j have h_orth : Orthonormal 𝕜 (fun x => x : s k → E) := h k rw [orthonormal_subtype_iff_ite] at h_orth exact h_orth x (hik hxi) y (hjk hyj) #align orthonormal_Union_of_directed orthonormal_iUnion_of_directed theorem orthonormal_sUnion_of_directed {s : Set (Set E)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, Orthonormal 𝕜 (fun x => ((x : a) : E))) : Orthonormal 𝕜 (fun x => x : ⋃₀ s → E) := by rw [Set.sUnion_eq_iUnion]; exact orthonormal_iUnion_of_directed hs.directed_val (by simpa using h) #align orthonormal_sUnion_of_directed orthonormal_sUnion_of_directed /-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set containing it. -/ theorem exists_maximal_orthonormal {s : Set E} (hs : Orthonormal 𝕜 (Subtype.val : s → E)) : ∃ w ⊇ s, Orthonormal 𝕜 (Subtype.val : w → E) ∧ ∀ u ⊇ w, Orthonormal 𝕜 (Subtype.val : u → E) → u = w := by have := zorn_subset_nonempty { b | Orthonormal 𝕜 (Subtype.val : b → E) } ?_ _ hs · obtain ⟨b, bi, sb, h⟩ := this refine ⟨b, sb, bi, ?_⟩ exact fun u hus hu => h u hu hus · refine fun c hc cc _c0 => ⟨⋃₀ c, ?_, ?_⟩ · exact orthonormal_sUnion_of_directed cc.directedOn fun x xc => hc xc · exact fun _ => Set.subset_sUnion_of_mem #align exists_maximal_orthonormal exists_maximal_orthonormal theorem Orthonormal.ne_zero {v : ι → E} (hv : Orthonormal 𝕜 v) (i : ι) : v i ≠ 0 := by have : ‖v i‖ ≠ 0 := by rw [hv.1 i] norm_num simpa using this #align orthonormal.ne_zero Orthonormal.ne_zero open FiniteDimensional /-- A family of orthonormal vectors with the correct cardinality forms a basis. -/ def basisOfOrthonormalOfCardEqFinrank [Fintype ι] [Nonempty ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (card_eq : Fintype.card ι = finrank 𝕜 E) : Basis ι 𝕜 E := basisOfLinearIndependentOfCardEqFinrank hv.linearIndependent card_eq #align basis_of_orthonormal_of_card_eq_finrank basisOfOrthonormalOfCardEqFinrank @[simp] theorem coe_basisOfOrthonormalOfCardEqFinrank [Fintype ι] [Nonempty ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (card_eq : Fintype.card ι = finrank 𝕜 E) : (basisOfOrthonormalOfCardEqFinrank hv card_eq : ι → E) = v := coe_basisOfLinearIndependentOfCardEqFinrank _ _ #align coe_basis_of_orthonormal_of_card_eq_finrank coe_basisOfOrthonormalOfCardEqFinrank end OrthonormalSets section Norm theorem norm_eq_sqrt_inner (x : E) : ‖x‖ = √(re ⟪x, x⟫) := calc ‖x‖ = √(‖x‖ ^ 2) := (sqrt_sq (norm_nonneg _)).symm _ = √(re ⟪x, x⟫) := congr_arg _ (norm_sq_eq_inner _) #align norm_eq_sqrt_inner norm_eq_sqrt_inner theorem norm_eq_sqrt_real_inner (x : F) : ‖x‖ = √⟪x, x⟫_ℝ := @norm_eq_sqrt_inner ℝ _ _ _ _ x #align norm_eq_sqrt_real_inner norm_eq_sqrt_real_inner theorem inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by rw [@norm_eq_sqrt_inner 𝕜, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg] #align inner_self_eq_norm_mul_norm inner_self_eq_norm_mul_norm theorem inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ‖x‖ ^ 2 := by rw [pow_two, inner_self_eq_norm_mul_norm] #align inner_self_eq_norm_sq inner_self_eq_norm_sq theorem real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ‖x‖ * ‖x‖ := by have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x simpa using h #align real_inner_self_eq_norm_mul_norm real_inner_self_eq_norm_mul_norm theorem real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ‖x‖ ^ 2 := by rw [pow_two, real_inner_self_eq_norm_mul_norm] #align real_inner_self_eq_norm_sq real_inner_self_eq_norm_sq -- Porting note: this was present in mathlib3 but seemingly didn't do anything. -- variable (𝕜) /-- Expand the square -/ theorem norm_add_sq (x y : E) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by repeat' rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜] rw [inner_add_add_self, two_mul] simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add] rw [← inner_conj_symm, conj_re] #align norm_add_sq norm_add_sq alias norm_add_pow_two := norm_add_sq #align norm_add_pow_two norm_add_pow_two /-- Expand the square -/ theorem norm_add_sq_real (x y : F) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := by have h := @norm_add_sq ℝ _ _ _ _ x y simpa using h #align norm_add_sq_real norm_add_sq_real alias norm_add_pow_two_real := norm_add_sq_real #align norm_add_pow_two_real norm_add_pow_two_real /-- Expand the square -/ theorem norm_add_mul_self (x y : E) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by repeat' rw [← sq (M := ℝ)] exact norm_add_sq _ _ #align norm_add_mul_self norm_add_mul_self /-- Expand the square -/ theorem norm_add_mul_self_real (x y : F) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by have h := @norm_add_mul_self ℝ _ _ _ _ x y simpa using h #align norm_add_mul_self_real norm_add_mul_self_real /-- Expand the square -/ theorem norm_sub_sq (x y : E) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by rw [sub_eq_add_neg, @norm_add_sq 𝕜 _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg, sub_eq_add_neg] #align norm_sub_sq norm_sub_sq alias norm_sub_pow_two := norm_sub_sq #align norm_sub_pow_two norm_sub_pow_two /-- Expand the square -/ theorem norm_sub_sq_real (x y : F) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := @norm_sub_sq ℝ _ _ _ _ _ _ #align norm_sub_sq_real norm_sub_sq_real alias norm_sub_pow_two_real := norm_sub_sq_real #align norm_sub_pow_two_real norm_sub_pow_two_real /-- Expand the square -/ theorem norm_sub_mul_self (x y : E) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by repeat' rw [← sq (M := ℝ)] exact norm_sub_sq _ _ #align norm_sub_mul_self norm_sub_mul_self /-- Expand the square -/ theorem norm_sub_mul_self_real (x y : F) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by have h := @norm_sub_mul_self ℝ _ _ _ _ x y simpa using h #align norm_sub_mul_self_real norm_sub_mul_self_real /-- Cauchy–Schwarz inequality with norm -/ theorem norm_inner_le_norm (x y : E) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := by rw [norm_eq_sqrt_inner (𝕜 := 𝕜) x, norm_eq_sqrt_inner (𝕜 := 𝕜) y] letI : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore exact InnerProductSpace.Core.norm_inner_le_norm x y #align norm_inner_le_norm norm_inner_le_norm theorem nnnorm_inner_le_nnnorm (x y : E) : ‖⟪x, y⟫‖₊ ≤ ‖x‖₊ * ‖y‖₊ := norm_inner_le_norm x y #align nnnorm_inner_le_nnnorm nnnorm_inner_le_nnnorm theorem re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y) #align re_inner_le_norm re_inner_le_norm /-- Cauchy–Schwarz inequality with norm -/ theorem abs_real_inner_le_norm (x y : F) : |⟪x, y⟫_ℝ| ≤ ‖x‖ * ‖y‖ := (Real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y) #align abs_real_inner_le_norm abs_real_inner_le_norm /-- Cauchy–Schwarz inequality with norm -/ theorem real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ := le_trans (le_abs_self _) (abs_real_inner_le_norm _ _) #align real_inner_le_norm real_inner_le_norm variable (𝕜) theorem parallelogram_law_with_norm (x y : E) : ‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) := by simp only [← @inner_self_eq_norm_mul_norm 𝕜] rw [← re.map_add, parallelogram_law, two_mul, two_mul] simp only [re.map_add] #align parallelogram_law_with_norm parallelogram_law_with_norm theorem parallelogram_law_with_nnnorm (x y : E) : ‖x + y‖₊ * ‖x + y‖₊ + ‖x - y‖₊ * ‖x - y‖₊ = 2 * (‖x‖₊ * ‖x‖₊ + ‖y‖₊ * ‖y‖₊) := Subtype.ext <| parallelogram_law_with_norm 𝕜 x y #align parallelogram_law_with_nnnorm parallelogram_law_with_nnnorm variable {𝕜} /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) : re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 := by rw [@norm_add_mul_self 𝕜] ring #align re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) : re ⟪x, y⟫ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 := by rw [@norm_sub_mul_self 𝕜] ring #align re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) : re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4 := by rw [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜] ring #align re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four /-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/ theorem im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four (x y : E) : im ⟪x, y⟫ = (‖x - IK • y‖ * ‖x - IK • y‖ - ‖x + IK • y‖ * ‖x + IK • y‖) / 4 := by simp only [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜, inner_smul_right, I_mul_re] ring set_option linter.uppercaseLean3 false in #align im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four /-- Polarization identity: The inner product, in terms of the norm. -/ theorem inner_eq_sum_norm_sq_div_four (x y : E) : ⟪x, y⟫ = ((‖x + y‖ : 𝕜) ^ 2 - (‖x - y‖ : 𝕜) ^ 2 + ((‖x - IK • y‖ : 𝕜) ^ 2 - (‖x + IK • y‖ : 𝕜) ^ 2) * IK) / 4 := by rw [← re_add_im ⟪x, y⟫, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four, im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four] push_cast simp only [sq, ← mul_div_right_comm, ← add_div] #align inner_eq_sum_norm_sq_div_four inner_eq_sum_norm_sq_div_four /-- Formula for the distance between the images of two nonzero points under an inversion with center zero. See also `EuclideanGeometry.dist_inversion_inversion` for inversions around a general point. -/ theorem dist_div_norm_sq_smul {x y : F} (hx : x ≠ 0) (hy : y ≠ 0) (R : ℝ) : dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = R ^ 2 / (‖x‖ * ‖y‖) * dist x y := have hx' : ‖x‖ ≠ 0 := norm_ne_zero_iff.2 hx have hy' : ‖y‖ ≠ 0 := norm_ne_zero_iff.2 hy calc dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = √(‖(R / ‖x‖) ^ 2 • x - (R / ‖y‖) ^ 2 • y‖ ^ 2) := by rw [dist_eq_norm, sqrt_sq (norm_nonneg _)] _ = √((R ^ 2 / (‖x‖ * ‖y‖)) ^ 2 * ‖x - y‖ ^ 2) := congr_arg sqrt <| by field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left, inner_smul_right, Real.norm_of_nonneg (mul_self_nonneg _)] ring _ = R ^ 2 / (‖x‖ * ‖y‖) * dist x y := by rw [sqrt_mul, sqrt_sq, sqrt_sq, dist_eq_norm] <;> positivity #align dist_div_norm_sq_smul dist_div_norm_sq_smul -- See note [lower instance priority] instance (priority := 100) InnerProductSpace.toUniformConvexSpace : UniformConvexSpace F := ⟨fun ε hε => by refine ⟨2 - √(4 - ε ^ 2), sub_pos_of_lt <| (sqrt_lt' zero_lt_two).2 ?_, fun x hx y hy hxy => ?_⟩ · norm_num exact pow_pos hε _ rw [sub_sub_cancel] refine le_sqrt_of_sq_le ?_ rw [sq, eq_sub_iff_add_eq.2 (parallelogram_law_with_norm ℝ x y), ← sq ‖x - y‖, hx, hy] ring_nf exact sub_le_sub_left (pow_le_pow_left hε.le hxy _) 4⟩ #align inner_product_space.to_uniform_convex_space InnerProductSpace.toUniformConvexSpace section Complex variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] /-- A complex polarization identity, with a linear map -/
Mathlib/Analysis/InnerProductSpace/Basic.lean
1,198
1,207
theorem inner_map_polarization (T : V →ₗ[ℂ] V) (x y : V) : ⟪T y, x⟫_ℂ = (⟪T (x + y), x + y⟫_ℂ - ⟪T (x - y), x - y⟫_ℂ + Complex.I * ⟪T (x + Complex.I • y), x + Complex.I • y⟫_ℂ - Complex.I * ⟪T (x - Complex.I • y), x - Complex.I • y⟫_ℂ) / 4 := by
simp only [map_add, map_sub, inner_add_left, inner_add_right, LinearMap.map_smul, inner_smul_left, inner_smul_right, Complex.conj_I, ← pow_two, Complex.I_sq, inner_sub_left, inner_sub_right, mul_add, ← mul_assoc, mul_neg, neg_neg, sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub] ring
/- 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, Yury Kudryashov -/ import Mathlib.Order.Filter.Basic import Mathlib.Topology.Bases import Mathlib.Data.Set.Accumulate import Mathlib.Topology.Bornology.Basic import Mathlib.Topology.LocallyFinite /-! # Compact sets and compact spaces ## Main definitions We define the following properties for sets in a topological space: * `IsCompact`: a set such that each open cover has a finite subcover. This is defined in mathlib using filters. The main property of a compact set is `IsCompact.elim_finite_subcover`. * `CompactSpace`: typeclass stating that the whole space is a compact set. * `NoncompactSpace`: a space that is not a compact space. ## Main results * `isCompact_univ_pi`: **Tychonov's theorem** - an arbitrary product of compact sets is compact. -/ open Set Filter Topology TopologicalSpace Classical Function universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} -- compact sets section Compact lemma IsCompact.exists_clusterPt (hs : IsCompact s) {f : Filter X} [NeBot f] (hf : f ≤ 𝓟 s) : ∃ x ∈ s, ClusterPt x f := hs hf lemma IsCompact.exists_mapClusterPt {ι : Type*} (hs : IsCompact s) {f : Filter ι} [NeBot f] {u : ι → X} (hf : Filter.map u f ≤ 𝓟 s) : ∃ x ∈ s, MapClusterPt x f u := hs hf /-- The complement to a compact set belongs to a filter `f` if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsCompact.compl_mem_sets (hs : IsCompact s) {f : Filter X} (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 _ hf inf_le_right #align is_compact.compl_mem_sets IsCompact.compl_mem_sets /-- The complement to a compact set belongs to a filter `f` if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsCompact.compl_mem_sets_of_nhdsWithin (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx => ?_ rcases hf x hx with ⟨t, ht, hst⟩ replace ht := mem_inf_principal.1 ht apply mem_inf_of_inter ht hst rintro x ⟨h₁, h₂⟩ hs exact h₂ (h₁ hs) #align is_compact.compl_mem_sets_of_nhds_within IsCompact.compl_mem_sets_of_nhdsWithin /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsCompact.induction_on (hs : IsCompact s) {p : Set X → Prop} (he : p ∅) (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := comk p he (fun _t ht _s hsub ↦ hmono hsub ht) (fun _s hs _t ht ↦ hunion hs ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] #align is_compact.induction_on IsCompact.induction_on /-- The intersection of a compact set and a closed set is a compact set. -/ theorem IsCompact.inter_right (hs : IsCompact s) (ht : IsClosed t) : IsCompact (s ∩ t) := by intro f hnf hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs (le_trans hstf (le_principal_iff.2 inter_subset_left)) have : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono <| le_trans hstf (le_principal_iff.2 inter_subset_right) exact ⟨x, ⟨hsx, this⟩, hx⟩ #align is_compact.inter_right IsCompact.inter_right /-- The intersection of a closed set and a compact set is a compact set. -/ theorem IsCompact.inter_left (ht : IsCompact t) (hs : IsClosed s) : IsCompact (s ∩ t) := inter_comm t s ▸ ht.inter_right hs #align is_compact.inter_left IsCompact.inter_left /-- The set difference of a compact set and an open set is a compact set. -/ theorem IsCompact.diff (hs : IsCompact s) (ht : IsOpen t) : IsCompact (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) #align is_compact.diff IsCompact.diff /-- A closed subset of a compact set is a compact set. -/ theorem IsCompact.of_isClosed_subset (hs : IsCompact s) (ht : IsClosed t) (h : t ⊆ s) : IsCompact t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht #align is_compact_of_is_closed_subset IsCompact.of_isClosed_subset theorem IsCompact.image_of_continuousOn {f : X → Y} (hs : IsCompact s) (hf : ContinuousOn f s) : IsCompact (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 #align is_compact.image_of_continuous_on IsCompact.image_of_continuousOn theorem IsCompact.image {f : X → Y} (hs : IsCompact s) (hf : Continuous f) : IsCompact (f '' s) := hs.image_of_continuousOn hf.continuousOn #align is_compact.image IsCompact.image theorem IsCompact.adherence_nhdset {f : Filter X} (hs : IsCompact s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := Classical.by_cases mem_of_eq_bot fun (this : f ⊓ 𝓟 tᶜ ≠ ⊥) => let ⟨x, hx, (hfx : ClusterPt x <| f ⊓ 𝓟 tᶜ)⟩ := @hs _ ⟨this⟩ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (IsOpen.mem_nhds ht₁ 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 #align is_compact.adherence_nhdset IsCompact.adherence_nhdset theorem isCompact_iff_ultrafilter_le_nhds : IsCompact s ↔ ∀ f : Ultrafilter X, ↑f ≤ 𝓟 s → ∃ x ∈ s, ↑f ≤ 𝓝 x := by refine (forall_neBot_le_iff ?_).trans ?_ · rintro f g hle ⟨x, hxs, hxf⟩ exact ⟨x, hxs, hxf.mono hle⟩ · simp only [Ultrafilter.clusterPt_iff] #align is_compact_iff_ultrafilter_le_nhds isCompact_iff_ultrafilter_le_nhds alias ⟨IsCompact.ultrafilter_le_nhds, _⟩ := isCompact_iff_ultrafilter_le_nhds #align is_compact.ultrafilter_le_nhds IsCompact.ultrafilter_le_nhds theorem isCompact_iff_ultrafilter_le_nhds' : IsCompact s ↔ ∀ f : Ultrafilter X, s ∈ f → ∃ x ∈ s, ↑f ≤ 𝓝 x := by simp only [isCompact_iff_ultrafilter_le_nhds, le_principal_iff, Ultrafilter.mem_coe] alias ⟨IsCompact.ultrafilter_le_nhds', _⟩ := isCompact_iff_ultrafilter_le_nhds' /-- If a compact set belongs to a filter and this filter has a unique cluster point `y` in this set, then the filter is less than or equal to `𝓝 y`. -/ lemma IsCompact.le_nhds_of_unique_clusterPt (hs : IsCompact s) {l : Filter X} {y : X} (hmem : s ∈ l) (h : ∀ x ∈ s, ClusterPt x l → x = y) : l ≤ 𝓝 y := by refine le_iff_ultrafilter.2 fun f hf ↦ ?_ rcases hs.ultrafilter_le_nhds' f (hf hmem) with ⟨x, hxs, hx⟩ convert ← hx exact h x hxs (.mono (.of_le_nhds hx) hf) /-- If values of `f : Y → X` belong to a compact set `s` eventually along a filter `l` and `y` is a unique `MapClusterPt` for `f` along `l` in `s`, then `f` tends to `𝓝 y` along `l`. -/ lemma IsCompact.tendsto_nhds_of_unique_mapClusterPt {l : Filter Y} {y : X} {f : Y → X} (hs : IsCompact s) (hmem : ∀ᶠ x in l, f x ∈ s) (h : ∀ x ∈ s, MapClusterPt x l f → x = y) : Tendsto f l (𝓝 y) := hs.le_nhds_of_unique_clusterPt (mem_map.2 hmem) h /-- For every open directed cover of a compact set, there exists a single element of the cover which itself includes the set. -/ theorem IsCompact.elim_directed_cover {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : Directed (· ⊆ ·) U) : ∃ i, s ⊆ U i := hι.elim fun i₀ => IsCompact.induction_on hs ⟨i₀, empty_subset _⟩ (fun _ _ hs ⟨i, hi⟩ => ⟨i, hs.trans hi⟩) (fun _ _ ⟨i, hi⟩ ⟨j, hj⟩ => let ⟨k, hki, hkj⟩ := hdU i j ⟨k, union_subset (Subset.trans hi hki) (Subset.trans hj hkj)⟩) fun _x hx => let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) ⟨U i, mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds (hUo i) hi), i, Subset.refl _⟩ #align is_compact.elim_directed_cover IsCompact.elim_directed_cover /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover {ι : Type v} (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := hs.elim_directed_cover _ (fun _ => isOpen_biUnion fun i _ => hUo i) (iUnion_eq_iUnion_finset U ▸ hsU) (directed_of_isDirected_le fun _ _ h => biUnion_subset_biUnion_left h) #align is_compact.elim_finite_subcover IsCompact.elim_finite_subcover lemma IsCompact.elim_nhds_subcover_nhdsSet' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ t : Finset s, (⋃ x ∈ t, U x.1 x.2) ∈ 𝓝ˢ s := by rcases hs.elim_finite_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 _ _⟩ with ⟨t, hst⟩ refine ⟨t, mem_nhdsSet_iff_forall.2 fun x hx ↦ ?_⟩ rcases mem_iUnion₂.1 (hst hx) with ⟨y, hyt, hy⟩ refine mem_of_superset ?_ (subset_biUnion_of_mem hyt) exact mem_interior_iff_mem_nhds.1 hy lemma IsCompact.elim_nhds_subcover_nhdsSet (hs : IsCompact s) {U : X → Set X} (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ (⋃ x ∈ t, U x) ∈ 𝓝ˢ s := let ⟨t, ht⟩ := hs.elim_nhds_subcover_nhdsSet' (fun x _ => U x) hU ⟨t.image (↑), fun x hx => let ⟨y, _, hyx⟩ := Finset.mem_image.1 hx hyx ▸ y.2, by rwa [Finset.set_biUnion_finset_image]⟩ theorem IsCompact.elim_nhds_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 := (hs.elim_nhds_subcover_nhdsSet' U hU).imp fun _ ↦ subset_of_mem_nhdsSet #align is_compact.elim_nhds_subcover' IsCompact.elim_nhds_subcover' theorem IsCompact.elim_nhds_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := (hs.elim_nhds_subcover_nhdsSet hU).imp fun _ h ↦ h.imp_right subset_of_mem_nhdsSet #align is_compact.elim_nhds_subcover IsCompact.elim_nhds_subcover /-- The neighborhood filter of a compact set is disjoint with a filter `l` if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsCompact.disjoint_nhdsSet_left {l : Filter X} (hs : IsCompact 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, 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₂, biInter_finset_mem] exact fun x hx => hUl x (hts x hx) #align is_compact.disjoint_nhds_set_left IsCompact.disjoint_nhdsSet_left /-- A filter `l` is disjoint with the neighborhood filter of a compact set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsCompact.disjoint_nhdsSet_right {l : Filter X} (hs : IsCompact s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left #align is_compact.disjoint_nhds_set_right IsCompact.disjoint_nhdsSet_right -- Porting note (#11215): TODO: reformulate using `Disjoint` /-- For every directed family of closed sets whose intersection avoids a compact set, there exists a single element of the family which itself avoids this compact set. -/ theorem IsCompact.elim_directed_family_closed {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) (hdt : Directed (· ⊇ ·) t) : ∃ i : ι, s ∩ t i = ∅ := let ⟨t, ht⟩ := hs.elim_directed_cover (compl ∘ t) (fun i => (htc i).isOpen_compl) (by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, iff_self_iff, mem_iInter, mem_compl_iff] using hst) (hdt.mono_comp _ fun _ _ => compl_subset_compl.mpr) ⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, iff_self_iff, mem_iInter, mem_compl_iff] using ht⟩ #align is_compact.elim_directed_family_closed IsCompact.elim_directed_family_closed -- Porting note (#11215): TODO: reformulate using `Disjoint` /-- For every family of closed sets whose intersection avoids a compact set, there exists a finite subfamily whose intersection avoids this compact set. -/ theorem IsCompact.elim_finite_subfamily_closed {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) : ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := hs.elim_directed_family_closed _ (fun t ↦ isClosed_biInter fun _ _ ↦ htc _) (by rwa [← iInter_eq_iInter_finset]) (directed_of_isDirected_le fun _ _ h ↦ biInter_subset_biInter_left h) #align is_compact.elim_finite_subfamily_closed IsCompact.elim_finite_subfamily_closed /-- If `s` is a compact set in a topological space `X` and `f : ι → Set X` is a locally finite family of sets, then `f i ∩ s` is nonempty only for a finitely many `i`. -/ theorem LocallyFinite.finite_nonempty_inter_compact {f : ι → Set X} (hf : LocallyFinite f) (hs : IsCompact s) : { i | (f i ∩ s).Nonempty }.Finite := by choose U hxU hUf using hf rcases hs.elim_nhds_subcover U fun x _ => hxU x with ⟨t, -, hsU⟩ refine (t.finite_toSet.biUnion fun x _ => hUf x).subset ?_ rintro i ⟨x, hx⟩ rcases mem_iUnion₂.1 (hsU hx.2) with ⟨c, hct, hcx⟩ exact mem_biUnion hct ⟨x, hx.1, hcx⟩ #align locally_finite.finite_nonempty_inter_compact LocallyFinite.finite_nonempty_inter_compact /-- To show that a compact set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every finite subfamily. -/ theorem IsCompact.inter_iInter_nonempty {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Finset ι, (s ∩ ⋂ i ∈ u, t i).Nonempty) : (s ∩ ⋂ i, t i).Nonempty := by contrapose! hst exact hs.elim_finite_subfamily_closed t htc hst #align is_compact.inter_Inter_nonempty IsCompact.inter_iInter_nonempty /-- Cantor's intersection theorem for `iInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed {ι : Type v} [hι : Nonempty ι] (t : ι → Set X) (htd : Directed (· ⊇ ·) t) (htn : ∀ i, (t i).Nonempty) (htc : ∀ i, IsCompact (t i)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := by let i₀ := hι.some suffices (t i₀ ∩ ⋂ i, t i).Nonempty by rwa [inter_eq_right.mpr (iInter_subset _ i₀)] at this simp only [nonempty_iff_ne_empty] at htn ⊢ apply mt ((htc i₀).elim_directed_family_closed t htcl) push_neg simp only [← nonempty_iff_ne_empty] at htn ⊢ refine ⟨htd, fun i => ?_⟩ rcases htd i₀ i with ⟨j, hji₀, hji⟩ exact (htn j).mono (subset_inter hji₀ hji) #align is_compact.nonempty_Inter_of_directed_nonempty_compact_closed IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed @[deprecated (since := "2024-02-28")] alias IsCompact.nonempty_iInter_of_directed_nonempty_compact_closed := IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed /-- Cantor's intersection theorem for `sInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/
Mathlib/Topology/Compactness/Compact.lean
312
317
theorem IsCompact.nonempty_sInter_of_directed_nonempty_isCompact_isClosed {S : Set (Set X)} [hS : Nonempty S] (hSd : DirectedOn (· ⊇ ·) S) (hSn : ∀ U ∈ S, U.Nonempty) (hSc : ∀ U ∈ S, IsCompact U) (hScl : ∀ U ∈ S, IsClosed U) : (⋂₀ S).Nonempty := by
rw [sInter_eq_iInter] exact IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (DirectedOn.directed_val hSd) (fun i ↦ hSn i i.2) (fun i ↦ hSc i i.2) (fun i ↦ hScl i i.2)
/- 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
Mathlib/Data/Real/NNReal.lean
1,099
1,101
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 _) _
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov -/ import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Algebra.Group.Submonoid.MulOpposite import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Data.Finset.NoncommProd import Mathlib.Data.Int.Order.Lemmas #align_import group_theory.submonoid.membership from "leanprover-community/mathlib"@"e655e4ea5c6d02854696f97494997ba4c31be802" /-! # Submonoids: membership criteria In this file we prove various facts about membership in a submonoid: * `list_prod_mem`, `multiset_prod_mem`, `prod_mem`: if each element of a collection belongs to a multiplicative submonoid, then so does their product; * `list_sum_mem`, `multiset_sum_mem`, `sum_mem`: if each element of a collection belongs to an additive submonoid, then so does their sum; * `pow_mem`, `nsmul_mem`: if `x ∈ S` where `S` is a multiplicative (resp., additive) submonoid and `n` is a natural number, then `x^n` (resp., `n • x`) belongs to `S`; * `mem_iSup_of_directed`, `coe_iSup_of_directed`, `mem_sSup_of_directedOn`, `coe_sSup_of_directedOn`: the supremum of a directed collection of submonoid is their union. * `sup_eq_range`, `mem_sup`: supremum of two submonoids `S`, `T` of a commutative monoid is the set of products; * `closure_singleton_eq`, `mem_closure_singleton`, `mem_closure_pair`: the multiplicative (resp., additive) closure of `{x}` consists of powers (resp., natural multiples) of `x`, and a similar result holds for the closure of `{x, y}`. ## Tags submonoid, submonoids -/ variable {M A B : Type*} section Assoc variable [Monoid M] [SetLike B M] [SubmonoidClass B M] {S : B} namespace SubmonoidClass @[to_additive (attr := norm_cast, simp)] theorem coe_list_prod (l : List S) : (l.prod : M) = (l.map (↑)).prod := map_list_prod (SubmonoidClass.subtype S : _ →* M) l #align submonoid_class.coe_list_prod SubmonoidClass.coe_list_prod #align add_submonoid_class.coe_list_sum AddSubmonoidClass.coe_list_sum @[to_additive (attr := norm_cast, simp)] theorem coe_multiset_prod {M} [CommMonoid M] [SetLike B M] [SubmonoidClass B M] (m : Multiset S) : (m.prod : M) = (m.map (↑)).prod := (SubmonoidClass.subtype S : _ →* M).map_multiset_prod m #align submonoid_class.coe_multiset_prod SubmonoidClass.coe_multiset_prod #align add_submonoid_class.coe_multiset_sum AddSubmonoidClass.coe_multiset_sum @[to_additive (attr := norm_cast)] -- Porting note (#10618): removed `simp`, `simp` can prove it theorem coe_finset_prod {ι M} [CommMonoid M] [SetLike B M] [SubmonoidClass B M] (f : ι → S) (s : Finset ι) : ↑(∏ i ∈ s, f i) = (∏ i ∈ s, f i : M) := map_prod (SubmonoidClass.subtype S) f s #align submonoid_class.coe_finset_prod SubmonoidClass.coe_finset_prod #align add_submonoid_class.coe_finset_sum AddSubmonoidClass.coe_finset_sum end SubmonoidClass open SubmonoidClass /-- Product of a list of elements in a submonoid is in the submonoid. -/ @[to_additive "Sum of a list of elements in an `AddSubmonoid` is in the `AddSubmonoid`."] theorem list_prod_mem {l : List M} (hl : ∀ x ∈ l, x ∈ S) : l.prod ∈ S := by lift l to List S using hl rw [← coe_list_prod] exact l.prod.coe_prop #align list_prod_mem list_prod_mem #align list_sum_mem list_sum_mem /-- Product of a multiset of elements in a submonoid of a `CommMonoid` is in the submonoid. -/ @[to_additive "Sum of a multiset of elements in an `AddSubmonoid` of an `AddCommMonoid` is in the `AddSubmonoid`."] theorem multiset_prod_mem {M} [CommMonoid M] [SetLike B M] [SubmonoidClass B M] (m : Multiset M) (hm : ∀ a ∈ m, a ∈ S) : m.prod ∈ S := by lift m to Multiset S using hm rw [← coe_multiset_prod] exact m.prod.coe_prop #align multiset_prod_mem multiset_prod_mem #align multiset_sum_mem multiset_sum_mem /-- Product of elements of a submonoid of a `CommMonoid` indexed by a `Finset` is in the submonoid. -/ @[to_additive "Sum of elements in an `AddSubmonoid` of an `AddCommMonoid` indexed by a `Finset` is in the `AddSubmonoid`."] theorem prod_mem {M : Type*} [CommMonoid M] [SetLike B M] [SubmonoidClass B M] {ι : Type*} {t : Finset ι} {f : ι → M} (h : ∀ c ∈ t, f c ∈ S) : (∏ c ∈ t, f c) ∈ S := multiset_prod_mem (t.1.map f) fun _x hx => let ⟨i, hi, hix⟩ := Multiset.mem_map.1 hx hix ▸ h i hi #align prod_mem prod_mem #align sum_mem sum_mem namespace Submonoid variable (s : Submonoid M) @[to_additive (attr := norm_cast)] -- Porting note (#10618): removed `simp`, `simp` can prove it theorem coe_list_prod (l : List s) : (l.prod : M) = (l.map (↑)).prod := map_list_prod s.subtype l #align submonoid.coe_list_prod Submonoid.coe_list_prod #align add_submonoid.coe_list_sum AddSubmonoid.coe_list_sum @[to_additive (attr := norm_cast)] -- Porting note (#10618): removed `simp`, `simp` can prove it theorem coe_multiset_prod {M} [CommMonoid M] (S : Submonoid M) (m : Multiset S) : (m.prod : M) = (m.map (↑)).prod := S.subtype.map_multiset_prod m #align submonoid.coe_multiset_prod Submonoid.coe_multiset_prod #align add_submonoid.coe_multiset_sum AddSubmonoid.coe_multiset_sum @[to_additive (attr := norm_cast, simp)] theorem coe_finset_prod {ι M} [CommMonoid M] (S : Submonoid M) (f : ι → S) (s : Finset ι) : ↑(∏ i ∈ s, f i) = (∏ i ∈ s, f i : M) := map_prod S.subtype f s #align submonoid.coe_finset_prod Submonoid.coe_finset_prod #align add_submonoid.coe_finset_sum AddSubmonoid.coe_finset_sum /-- Product of a list of elements in a submonoid is in the submonoid. -/ @[to_additive "Sum of a list of elements in an `AddSubmonoid` is in the `AddSubmonoid`."] theorem list_prod_mem {l : List M} (hl : ∀ x ∈ l, x ∈ s) : l.prod ∈ s := by lift l to List s using hl rw [← coe_list_prod] exact l.prod.coe_prop #align submonoid.list_prod_mem Submonoid.list_prod_mem #align add_submonoid.list_sum_mem AddSubmonoid.list_sum_mem /-- Product of a multiset of elements in a submonoid of a `CommMonoid` is in the submonoid. -/ @[to_additive "Sum of a multiset of elements in an `AddSubmonoid` of an `AddCommMonoid` is in the `AddSubmonoid`."] theorem multiset_prod_mem {M} [CommMonoid M] (S : Submonoid M) (m : Multiset M) (hm : ∀ a ∈ m, a ∈ S) : m.prod ∈ S := by lift m to Multiset S using hm rw [← coe_multiset_prod] exact m.prod.coe_prop #align submonoid.multiset_prod_mem Submonoid.multiset_prod_mem #align add_submonoid.multiset_sum_mem AddSubmonoid.multiset_sum_mem @[to_additive] theorem multiset_noncommProd_mem (S : Submonoid M) (m : Multiset M) (comm) (h : ∀ x ∈ m, x ∈ S) : m.noncommProd comm ∈ S := by induction' m using Quotient.inductionOn with l simp only [Multiset.quot_mk_to_coe, Multiset.noncommProd_coe] exact Submonoid.list_prod_mem _ h #align submonoid.multiset_noncomm_prod_mem Submonoid.multiset_noncommProd_mem #align add_submonoid.multiset_noncomm_sum_mem AddSubmonoid.multiset_noncommSum_mem /-- Product of elements of a submonoid of a `CommMonoid` indexed by a `Finset` is in the submonoid. -/ @[to_additive "Sum of elements in an `AddSubmonoid` of an `AddCommMonoid` indexed by a `Finset` is in the `AddSubmonoid`."] theorem prod_mem {M : Type*} [CommMonoid M] (S : Submonoid M) {ι : Type*} {t : Finset ι} {f : ι → M} (h : ∀ c ∈ t, f c ∈ S) : (∏ c ∈ t, f c) ∈ S := S.multiset_prod_mem (t.1.map f) fun _ hx => let ⟨i, hi, hix⟩ := Multiset.mem_map.1 hx hix ▸ h i hi #align submonoid.prod_mem Submonoid.prod_mem #align add_submonoid.sum_mem AddSubmonoid.sum_mem @[to_additive] theorem noncommProd_mem (S : Submonoid M) {ι : Type*} (t : Finset ι) (f : ι → M) (comm) (h : ∀ c ∈ t, f c ∈ S) : t.noncommProd f comm ∈ S := by apply multiset_noncommProd_mem intro y rw [Multiset.mem_map] rintro ⟨x, ⟨hx, rfl⟩⟩ exact h x hx #align submonoid.noncomm_prod_mem Submonoid.noncommProd_mem #align add_submonoid.noncomm_sum_mem AddSubmonoid.noncommSum_mem end Submonoid end Assoc section NonAssoc variable [MulOneClass M] open Set namespace Submonoid -- TODO: this section can be generalized to `[SubmonoidClass B M] [CompleteLattice B]` -- such that `CompleteLattice.LE` coincides with `SetLike.LE` @[to_additive] theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Submonoid M} (hS : Directed (· ≤ ·) S) {x : M} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ suffices x ∈ closure (⋃ i, (S i : Set M)) → ∃ i, x ∈ S i by simpa only [closure_iUnion, closure_eq (S _)] using this refine fun hx ↦ closure_induction hx (fun _ ↦ mem_iUnion.1) ?_ ?_ · exact hι.elim fun i ↦ ⟨i, (S i).one_mem⟩ · rintro x y ⟨i, hi⟩ ⟨j, hj⟩ rcases hS i j with ⟨k, hki, hkj⟩ exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ #align submonoid.mem_supr_of_directed Submonoid.mem_iSup_of_directed #align add_submonoid.mem_supr_of_directed AddSubmonoid.mem_iSup_of_directed @[to_additive] theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → Submonoid M} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : Submonoid M) : Set M) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] #align submonoid.coe_supr_of_directed Submonoid.coe_iSup_of_directed #align add_submonoid.coe_supr_of_directed AddSubmonoid.coe_iSup_of_directed @[to_additive] theorem mem_sSup_of_directedOn {S : Set (Submonoid M)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) {x : M} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by haveI : Nonempty S := Sne.to_subtype simp [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk] #align submonoid.mem_Sup_of_directed_on Submonoid.mem_sSup_of_directedOn #align add_submonoid.mem_Sup_of_directed_on AddSubmonoid.mem_sSup_of_directedOn @[to_additive] theorem coe_sSup_of_directedOn {S : Set (Submonoid M)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set M) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS] #align submonoid.coe_Sup_of_directed_on Submonoid.coe_sSup_of_directedOn #align add_submonoid.coe_Sup_of_directed_on AddSubmonoid.coe_sSup_of_directedOn @[to_additive] theorem mem_sup_left {S T : Submonoid M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T := by rw [← SetLike.le_def] exact le_sup_left #align submonoid.mem_sup_left Submonoid.mem_sup_left #align add_submonoid.mem_sup_left AddSubmonoid.mem_sup_left @[to_additive] theorem mem_sup_right {S T : Submonoid M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T := by rw [← SetLike.le_def] exact le_sup_right #align submonoid.mem_sup_right Submonoid.mem_sup_right #align add_submonoid.mem_sup_right AddSubmonoid.mem_sup_right @[to_additive] theorem mul_mem_sup {S T : Submonoid M} {x y : M} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy) #align submonoid.mul_mem_sup Submonoid.mul_mem_sup #align add_submonoid.add_mem_sup AddSubmonoid.add_mem_sup @[to_additive] theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Submonoid M} (i : ι) : ∀ {x : M}, x ∈ S i → x ∈ iSup S := by rw [← SetLike.le_def] exact le_iSup _ _ #align submonoid.mem_supr_of_mem Submonoid.mem_iSup_of_mem #align add_submonoid.mem_supr_of_mem AddSubmonoid.mem_iSup_of_mem @[to_additive] theorem mem_sSup_of_mem {S : Set (Submonoid M)} {s : Submonoid M} (hs : s ∈ S) : ∀ {x : M}, x ∈ s → x ∈ sSup S := by rw [← SetLike.le_def] exact le_sSup hs #align submonoid.mem_Sup_of_mem Submonoid.mem_sSup_of_mem #align add_submonoid.mem_Sup_of_mem AddSubmonoid.mem_sSup_of_mem /-- An induction principle for elements of `⨆ i, S i`. If `C` holds for `1` and all elements of `S i` for all `i`, and is preserved under multiplication, then it holds for all elements of the supremum of `S`. -/ @[to_additive (attr := elab_as_elim) " An induction principle for elements of `⨆ i, S i`. If `C` holds for `0` and all elements of `S i` for all `i`, and is preserved under addition, then it holds for all elements of the supremum of `S`. "] theorem iSup_induction {ι : Sort*} (S : ι → Submonoid M) {C : M → Prop} {x : M} (hx : x ∈ ⨆ i, S i) (mem : ∀ (i), ∀ x ∈ S i, C x) (one : C 1) (mul : ∀ x y, C x → C y → C (x * y)) : C x := by rw [iSup_eq_closure] at hx refine closure_induction hx (fun x hx => ?_) one mul obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx exact mem _ _ hi #align submonoid.supr_induction Submonoid.iSup_induction #align add_submonoid.supr_induction AddSubmonoid.iSup_induction /-- A dependent version of `Submonoid.iSup_induction`. -/ @[to_additive (attr := elab_as_elim) "A dependent version of `AddSubmonoid.iSup_induction`. "] theorem iSup_induction' {ι : Sort*} (S : ι → Submonoid M) {C : ∀ x, (x ∈ ⨆ i, S i) → Prop} (mem : ∀ (i), ∀ (x) (hxS : x ∈ S i), C x (mem_iSup_of_mem i hxS)) (one : C 1 (one_mem _)) (mul : ∀ x y hx hy, C x hx → C y hy → C (x * y) (mul_mem ‹_› ‹_›)) {x : M} (hx : x ∈ ⨆ i, S i) : C x hx := by refine Exists.elim (?_ : ∃ Hx, C x Hx) fun (hx : x ∈ ⨆ i, S i) (hc : C x hx) => hc refine @iSup_induction _ _ ι S (fun m => ∃ hm, C m hm) _ hx (fun i x hx => ?_) ?_ fun x y => ?_ · exact ⟨_, mem _ _ hx⟩ · exact ⟨_, one⟩ · rintro ⟨_, Cx⟩ ⟨_, Cy⟩ exact ⟨_, mul _ _ _ _ Cx Cy⟩ #align submonoid.supr_induction' Submonoid.iSup_induction' #align add_submonoid.supr_induction' AddSubmonoid.iSup_induction' end Submonoid end NonAssoc namespace FreeMonoid variable {α : Type*} open Submonoid @[to_additive] theorem closure_range_of : closure (Set.range <| @of α) = ⊤ := eq_top_iff.2 fun x _ => FreeMonoid.recOn x (one_mem _) fun _x _xs hxs => mul_mem (subset_closure <| Set.mem_range_self _) hxs #align free_monoid.closure_range_of FreeMonoid.closure_range_of #align free_add_monoid.closure_range_of FreeAddMonoid.closure_range_of end FreeMonoid namespace Submonoid variable [Monoid M] {a : M} open MonoidHom theorem closure_singleton_eq (x : M) : closure ({x} : Set M) = mrange (powersHom M x) := closure_eq_of_le (Set.singleton_subset_iff.2 ⟨Multiplicative.ofAdd 1, pow_one x⟩) fun _ ⟨_, hn⟩ => hn ▸ pow_mem (subset_closure <| Set.mem_singleton _) _ #align submonoid.closure_singleton_eq Submonoid.closure_singleton_eq /-- The submonoid generated by an element of a monoid equals the set of natural number powers of the element. -/ theorem mem_closure_singleton {x y : M} : y ∈ closure ({x} : Set M) ↔ ∃ n : ℕ, x ^ n = y := by rw [closure_singleton_eq, mem_mrange]; rfl #align submonoid.mem_closure_singleton Submonoid.mem_closure_singleton theorem mem_closure_singleton_self {y : M} : y ∈ closure ({y} : Set M) := mem_closure_singleton.2 ⟨1, pow_one y⟩ #align submonoid.mem_closure_singleton_self Submonoid.mem_closure_singleton_self theorem closure_singleton_one : closure ({1} : Set M) = ⊥ := by simp [eq_bot_iff_forall, mem_closure_singleton] #align submonoid.closure_singleton_one Submonoid.closure_singleton_one section Submonoid variable {S : Submonoid M} [Fintype S] open Fintype /- curly brackets `{}` are used here instead of instance brackets `[]` because the instance in a goal is often not the same as the one inferred by type class inference. -/ @[to_additive] theorem card_bot {_ : Fintype (⊥ : Submonoid M)} : card (⊥ : Submonoid M) = 1 := card_eq_one_iff.2 ⟨⟨(1 : M), Set.mem_singleton 1⟩, fun ⟨_y, hy⟩ => Subtype.eq <| mem_bot.1 hy⟩ @[to_additive] theorem eq_bot_of_card_le (h : card S ≤ 1) : S = ⊥ := let _ := card_le_one_iff_subsingleton.mp h eq_bot_of_subsingleton S @[to_additive] theorem eq_bot_of_card_eq (h : card S = 1) : S = ⊥ := S.eq_bot_of_card_le (le_of_eq h) @[to_additive card_le_one_iff_eq_bot] theorem card_le_one_iff_eq_bot : card S ≤ 1 ↔ S = ⊥ := ⟨fun h => (eq_bot_iff_forall _).2 fun x hx => by simpa [Subtype.ext_iff] using card_le_one_iff.1 h ⟨x, hx⟩ 1, fun h => by simp [h]⟩ @[to_additive] lemma eq_bot_iff_card : S = ⊥ ↔ card S = 1 := ⟨by rintro rfl; exact card_bot, eq_bot_of_card_eq⟩ end Submonoid @[to_additive] theorem _root_.FreeMonoid.mrange_lift {α} (f : α → M) : mrange (FreeMonoid.lift f) = closure (Set.range f) := by rw [mrange_eq_map, ← FreeMonoid.closure_range_of, map_mclosure, ← Set.range_comp, FreeMonoid.lift_comp_of] #align free_monoid.mrange_lift FreeMonoid.mrange_lift #align free_add_monoid.mrange_lift FreeAddMonoid.mrange_lift @[to_additive] theorem closure_eq_mrange (s : Set M) : closure s = mrange (FreeMonoid.lift ((↑) : s → M)) := by rw [FreeMonoid.mrange_lift, Subtype.range_coe] #align submonoid.closure_eq_mrange Submonoid.closure_eq_mrange #align add_submonoid.closure_eq_mrange AddSubmonoid.closure_eq_mrange @[to_additive] theorem closure_eq_image_prod (s : Set M) : (closure s : Set M) = List.prod '' { l : List M | ∀ x ∈ l, x ∈ s } := by rw [closure_eq_mrange, coe_mrange, ← Set.range_list_map_coe, ← Set.range_comp] exact congrArg _ (funext <| FreeMonoid.lift_apply _) #align submonoid.closure_eq_image_prod Submonoid.closure_eq_image_prod #align add_submonoid.closure_eq_image_sum AddSubmonoid.closure_eq_image_sum @[to_additive] theorem exists_list_of_mem_closure {s : Set M} {x : M} (hx : x ∈ closure s) : ∃ l : List M, (∀ y ∈ l, y ∈ s) ∧ l.prod = x := by rwa [← SetLike.mem_coe, closure_eq_image_prod, Set.mem_image] at hx #align submonoid.exists_list_of_mem_closure Submonoid.exists_list_of_mem_closure #align add_submonoid.exists_list_of_mem_closure AddSubmonoid.exists_list_of_mem_closure @[to_additive] theorem exists_multiset_of_mem_closure {M : Type*} [CommMonoid M] {s : Set M} {x : M} (hx : x ∈ closure s) : ∃ l : Multiset M, (∀ y ∈ l, y ∈ s) ∧ l.prod = x := by obtain ⟨l, h1, h2⟩ := exists_list_of_mem_closure hx exact ⟨l, h1, (Multiset.prod_coe l).trans h2⟩ #align submonoid.exists_multiset_of_mem_closure Submonoid.exists_multiset_of_mem_closure #align add_submonoid.exists_multiset_of_mem_closure AddSubmonoid.exists_multiset_of_mem_closure @[to_additive (attr := elab_as_elim)] theorem closure_induction_left {s : Set M} {p : (m : M) → m ∈ closure s → Prop} (one : p 1 (one_mem _)) (mul_left : ∀ x (hx : x ∈ s), ∀ (y) hy, p y hy → p (x * y) (mul_mem (subset_closure hx) hy)) {x : M} (h : x ∈ closure s) : p x h := by simp_rw [closure_eq_mrange] at h obtain ⟨l, rfl⟩ := h induction' l using FreeMonoid.recOn with x y ih · exact one · simp only [map_mul, FreeMonoid.lift_eval_of] refine mul_left _ x.prop (FreeMonoid.lift Subtype.val y) _ (ih ?_) simp only [closure_eq_mrange, mem_mrange, exists_apply_eq_apply] #align submonoid.closure_induction_left Submonoid.closure_induction_left #align add_submonoid.closure_induction_left AddSubmonoid.closure_induction_left @[to_additive (attr := elab_as_elim)] theorem induction_of_closure_eq_top_left {s : Set M} {p : M → Prop} (hs : closure s = ⊤) (x : M) (one : p 1) (mul : ∀ x ∈ s, ∀ (y), p y → p (x * y)) : p x := by have : x ∈ closure s := by simp [hs] induction this using closure_induction_left with | one => exact one | mul_left x hx y _ ih => exact mul x hx y ih #align submonoid.induction_of_closure_eq_top_left Submonoid.induction_of_closure_eq_top_left #align add_submonoid.induction_of_closure_eq_top_left AddSubmonoid.induction_of_closure_eq_top_left @[to_additive (attr := elab_as_elim)] theorem closure_induction_right {s : Set M} {p : (m : M) → m ∈ closure s → Prop} (one : p 1 (one_mem _)) (mul_right : ∀ x hx, ∀ (y) (hy : y ∈ s), p x hx → p (x * y) (mul_mem hx (subset_closure hy))) {x : M} (h : x ∈ closure s) : p x h := closure_induction_left (s := MulOpposite.unop ⁻¹' s) (p := fun m hm => p m.unop <| by rwa [← op_closure] at hm) one (fun _x hx _y hy => mul_right _ _ _ hx) (by rwa [← op_closure]) #align submonoid.closure_induction_right Submonoid.closure_induction_right #align add_submonoid.closure_induction_right AddSubmonoid.closure_induction_right @[to_additive (attr := elab_as_elim)] theorem induction_of_closure_eq_top_right {s : Set M} {p : M → Prop} (hs : closure s = ⊤) (x : M) (H1 : p 1) (Hmul : ∀ (x), ∀ y ∈ s, p x → p (x * y)) : p x := by have : x ∈ closure s := by simp [hs] induction this using closure_induction_right with | one => exact H1 | mul_right x _ y hy ih => exact Hmul x y hy ih #align submonoid.induction_of_closure_eq_top_right Submonoid.induction_of_closure_eq_top_right #align add_submonoid.induction_of_closure_eq_top_right AddSubmonoid.induction_of_closure_eq_top_right /-- The submonoid generated by an element. -/ def powers (n : M) : Submonoid M := Submonoid.copy (mrange (powersHom M n)) (Set.range (n ^ · : ℕ → M)) <| Set.ext fun n => exists_congr fun i => by simp; rfl #align submonoid.powers Submonoid.powers theorem mem_powers (n : M) : n ∈ powers n := ⟨1, pow_one _⟩ #align submonoid.mem_powers Submonoid.mem_powers theorem coe_powers (x : M) : ↑(powers x) = Set.range fun n : ℕ => x ^ n := rfl #align submonoid.coe_powers Submonoid.coe_powers theorem mem_powers_iff (x z : M) : x ∈ powers z ↔ ∃ n : ℕ, z ^ n = x := Iff.rfl #align submonoid.mem_powers_iff Submonoid.mem_powers_iff noncomputable instance decidableMemPowers : DecidablePred (· ∈ Submonoid.powers a) := Classical.decPred _ #align decidable_powers Submonoid.decidableMemPowers -- Porting note (#11215): TODO the following instance should follow from a more general principle -- See also mathlib4#2417 noncomputable instance fintypePowers [Fintype M] : Fintype (powers a) := inferInstanceAs <| Fintype {y // y ∈ powers a} theorem powers_eq_closure (n : M) : powers n = closure {n} := by ext exact mem_closure_singleton.symm #align submonoid.powers_eq_closure Submonoid.powers_eq_closure lemma powers_le {n : M} {P : Submonoid M} : powers n ≤ P ↔ n ∈ P := by simp [powers_eq_closure] #align submonoid.powers_subset Submonoid.powers_le lemma powers_one : powers (1 : M) = ⊥ := bot_unique <| powers_le.2 <| one_mem _ #align submonoid.powers_one Submonoid.powers_one /-- The submonoid generated by an element is a group if that element has finite order. -/ abbrev groupPowers {x : M} {n : ℕ} (hpos : 0 < n) (hx : x ^ n = 1) : Group (powers x) where inv x := x ^ (n - 1) mul_left_inv y := Subtype.ext <| by obtain ⟨_, k, rfl⟩ := y simp only [coe_one, coe_mul, SubmonoidClass.coe_pow] rw [← pow_succ, Nat.sub_add_cancel hpos, ← pow_mul, mul_comm, pow_mul, hx, one_pow] zpow z x := x ^ z.natMod n zpow_zero' z := by simp only [Int.natMod, Int.zero_emod, Int.toNat_zero, pow_zero] zpow_neg' m x := Subtype.ext <| by obtain ⟨_, k, rfl⟩ := x simp only [← pow_mul, Int.natMod, SubmonoidClass.coe_pow] rw [Int.negSucc_coe, ← Int.add_mul_emod_self (b := (m + 1 : ℕ))] nth_rw 1 [← mul_one ((m + 1 : ℕ) : ℤ)] rw [← sub_eq_neg_add, ← mul_sub, ← Int.natCast_pred_of_pos hpos]; norm_cast simp only [Int.toNat_natCast] rw [mul_comm, pow_mul, ← pow_eq_pow_mod _ hx, mul_comm k, mul_assoc, pow_mul _ (_ % _), ← pow_eq_pow_mod _ hx, pow_mul, pow_mul] zpow_succ' m x := Subtype.ext <| by obtain ⟨_, k, rfl⟩ := x simp only [← pow_mul, Int.natMod, Int.ofNat_eq_coe, SubmonoidClass.coe_pow, coe_mul] norm_cast iterate 2 rw [Int.toNat_natCast, mul_comm, pow_mul, ← pow_eq_pow_mod _ hx] rw [← pow_mul _ m, mul_comm, pow_mul, ← pow_succ, ← pow_mul, mul_comm, pow_mul] /-- Exponentiation map from natural numbers to powers. -/ @[simps!] def pow (n : M) (m : ℕ) : powers n := (powersHom M n).mrangeRestrict (Multiplicative.ofAdd m) #align submonoid.pow Submonoid.pow #align submonoid.pow_coe Submonoid.pow_coe theorem pow_apply (n : M) (m : ℕ) : Submonoid.pow n m = ⟨n ^ m, m, rfl⟩ := rfl #align submonoid.pow_apply Submonoid.pow_apply /-- Logarithms from powers to natural numbers. -/ def log [DecidableEq M] {n : M} (p : powers n) : ℕ := Nat.find <| (mem_powers_iff p.val n).mp p.prop #align submonoid.log Submonoid.log @[simp] theorem pow_log_eq_self [DecidableEq M] {n : M} (p : powers n) : pow n (log p) = p := Subtype.ext <| Nat.find_spec p.prop #align submonoid.pow_log_eq_self Submonoid.pow_log_eq_self theorem pow_right_injective_iff_pow_injective {n : M} : (Function.Injective fun m : ℕ => n ^ m) ↔ Function.Injective (pow n) := Subtype.coe_injective.of_comp_iff (pow n) #align submonoid.pow_right_injective_iff_pow_injective Submonoid.pow_right_injective_iff_pow_injective @[simp] theorem log_pow_eq_self [DecidableEq M] {n : M} (h : Function.Injective fun m : ℕ => n ^ m) (m : ℕ) : log (pow n m) = m := pow_right_injective_iff_pow_injective.mp h <| pow_log_eq_self _ #align submonoid.log_pow_eq_self Submonoid.log_pow_eq_self /-- The exponentiation map is an isomorphism from the additive monoid on natural numbers to powers when it is injective. The inverse is given by the logarithms. -/ @[simps] def powLogEquiv [DecidableEq M] {n : M} (h : Function.Injective fun m : ℕ => n ^ m) : Multiplicative ℕ ≃* powers n where toFun m := pow n (Multiplicative.toAdd m) invFun m := Multiplicative.ofAdd (log m) left_inv := log_pow_eq_self h right_inv := pow_log_eq_self map_mul' _ _ := by simp only [pow, map_mul, ofAdd_add, toAdd_mul] #align submonoid.pow_log_equiv Submonoid.powLogEquiv #align submonoid.pow_log_equiv_symm_apply Submonoid.powLogEquiv_symm_apply #align submonoid.pow_log_equiv_apply Submonoid.powLogEquiv_apply theorem log_mul [DecidableEq M] {n : M} (h : Function.Injective fun m : ℕ => n ^ m) (x y : powers (n : M)) : log (x * y) = log x + log y := (powLogEquiv h).symm.map_mul x y #align submonoid.log_mul Submonoid.log_mul theorem log_pow_int_eq_self {x : ℤ} (h : 1 < x.natAbs) (m : ℕ) : log (pow x m) = m := (powLogEquiv (Int.pow_right_injective h)).symm_apply_apply _ #align submonoid.log_pow_int_eq_self Submonoid.log_pow_int_eq_self @[simp] theorem map_powers {N : Type*} {F : Type*} [Monoid N] [FunLike F M N] [MonoidHomClass F M N] (f : F) (m : M) : (powers m).map f = powers (f m) := by simp only [powers_eq_closure, map_mclosure f, Set.image_singleton] #align submonoid.map_powers Submonoid.map_powers /-- If all the elements of a set `s` commute, then `closure s` is a commutative monoid. -/ @[to_additive "If all the elements of a set `s` commute, then `closure s` forms an additive commutative monoid."] def closureCommMonoidOfComm {s : Set M} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : CommMonoid (closure s) := { (closure s).toMonoid with mul_comm := fun x y => by ext simp only [Submonoid.coe_mul] exact closure_induction₂ x.prop y.prop hcomm Commute.one_left Commute.one_right (fun x y z => Commute.mul_left) fun x y z => Commute.mul_right } #align submonoid.closure_comm_monoid_of_comm Submonoid.closureCommMonoidOfComm #align add_submonoid.closure_add_comm_monoid_of_comm AddSubmonoid.closureAddCommMonoidOfComm end Submonoid @[to_additive] theorem IsScalarTower.of_mclosure_eq_top {N α} [Monoid M] [MulAction M N] [SMul N α] [MulAction M α] {s : Set M} (htop : Submonoid.closure s = ⊤) (hs : ∀ x ∈ s, ∀ (y : N) (z : α), (x • y) • z = x • y • z) : IsScalarTower M N α := by refine ⟨fun x => Submonoid.induction_of_closure_eq_top_left htop x ?_ ?_⟩ · intro y z rw [one_smul, one_smul] · clear x intro x hx x' hx' y z rw [mul_smul, mul_smul, hs x hx, hx'] #align is_scalar_tower.of_mclosure_eq_top IsScalarTower.of_mclosure_eq_top #align vadd_assoc_class.of_mclosure_eq_top VAddAssocClass.of_mclosure_eq_top @[to_additive] theorem SMulCommClass.of_mclosure_eq_top {N α} [Monoid M] [SMul N α] [MulAction M α] {s : Set M} (htop : Submonoid.closure s = ⊤) (hs : ∀ x ∈ s, ∀ (y : N) (z : α), x • y • z = y • x • z) : SMulCommClass M N α := by refine ⟨fun x => Submonoid.induction_of_closure_eq_top_left htop x ?_ ?_⟩ · intro y z rw [one_smul, one_smul] · clear x intro x hx x' hx' y z rw [mul_smul, mul_smul, hx', hs x hx] #align smul_comm_class.of_mclosure_eq_top SMulCommClass.of_mclosure_eq_top #align vadd_comm_class.of_mclosure_eq_top VAddCommClass.of_mclosure_eq_top namespace Submonoid variable {N : Type*} [CommMonoid N] open MonoidHom @[to_additive] theorem sup_eq_range (s t : Submonoid N) : s ⊔ t = mrange (s.subtype.coprod t.subtype) := by rw [mrange_eq_map, ← mrange_inl_sup_mrange_inr, map_sup, map_mrange, coprod_comp_inl, map_mrange, coprod_comp_inr, range_subtype, range_subtype] #align submonoid.sup_eq_range Submonoid.sup_eq_range #align add_submonoid.sup_eq_range AddSubmonoid.sup_eq_range @[to_additive] theorem mem_sup {s t : Submonoid N} {x : N} : x ∈ s ⊔ t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x := by simp only [ge_iff_le, sup_eq_range, mem_mrange, coprod_apply, coe_subtype, Prod.exists, Subtype.exists, exists_prop] #align submonoid.mem_sup Submonoid.mem_sup #align add_submonoid.mem_sup AddSubmonoid.mem_sup end Submonoid namespace AddSubmonoid variable [AddMonoid A] open Set theorem closure_singleton_eq (x : A) : closure ({x} : Set A) = AddMonoidHom.mrange (multiplesHom A x) := closure_eq_of_le (Set.singleton_subset_iff.2 ⟨1, one_nsmul x⟩) fun _ ⟨_n, hn⟩ => hn ▸ nsmul_mem (subset_closure <| Set.mem_singleton _) _ #align add_submonoid.closure_singleton_eq AddSubmonoid.closure_singleton_eq /-- The `AddSubmonoid` generated by an element of an `AddMonoid` equals the set of natural number multiples of the element. -/ theorem mem_closure_singleton {x y : A} : y ∈ closure ({x} : Set A) ↔ ∃ n : ℕ, n • x = y := by rw [closure_singleton_eq, AddMonoidHom.mem_mrange]; rfl #align add_submonoid.mem_closure_singleton AddSubmonoid.mem_closure_singleton theorem closure_singleton_zero : closure ({0} : Set A) = ⊥ := by simp [eq_bot_iff_forall, mem_closure_singleton, nsmul_zero] #align add_submonoid.closure_singleton_zero AddSubmonoid.closure_singleton_zero /-- The additive submonoid generated by an element. -/ def multiples (x : A) : AddSubmonoid A := AddSubmonoid.copy (AddMonoidHom.mrange (multiplesHom A x)) (Set.range (fun i => i • x : ℕ → A)) <| Set.ext fun n => exists_congr fun i => by simp #align add_submonoid.multiples AddSubmonoid.multiples attribute [to_additive existing] Submonoid.powers attribute [to_additive (attr := simp)] Submonoid.mem_powers #align add_submonoid.mem_multiples AddSubmonoid.mem_multiples attribute [to_additive (attr := norm_cast)] Submonoid.coe_powers #align add_submonoid.coe_multiples AddSubmonoid.coe_multiples attribute [to_additive] Submonoid.mem_powers_iff #align add_submonoid.mem_multiples_iff AddSubmonoid.mem_multiples_iff attribute [to_additive] Submonoid.decidableMemPowers #align decidable_multiples AddSubmonoid.decidableMemMultiples attribute [to_additive] Submonoid.fintypePowers attribute [to_additive] Submonoid.powers_eq_closure #align add_submonoid.multiples_eq_closure AddSubmonoid.multiples_eq_closure attribute [to_additive] Submonoid.powers_le #align add_submonoid.multiples_subset AddSubmonoid.multiples_le attribute [to_additive (attr := simp)] Submonoid.powers_one #align add_submonoid.multiples_zero AddSubmonoid.multiples_zero attribute [to_additive "The additive submonoid generated by an element is an additive group if that element has finite order."] Submonoid.groupPowers end AddSubmonoid /-! Lemmas about additive closures of `Subsemigroup`. -/ namespace MulMemClass variable {R : Type*} [NonUnitalNonAssocSemiring R] [SetLike M R] [MulMemClass M R] {S : M} {a b : R} /-- The product of an element of the additive closure of a multiplicative subsemigroup `M` and an element of `M` is contained in the additive closure of `M`. -/ theorem mul_right_mem_add_closure (ha : a ∈ AddSubmonoid.closure (S : Set R)) (hb : b ∈ S) : a * b ∈ AddSubmonoid.closure (S : Set R) := by revert b apply @AddSubmonoid.closure_induction _ _ _ (fun z => ∀ (b : R), b ∈ S → z * b ∈ AddSubmonoid.closure S) _ ha <;> clear ha a · exact fun r hr b hb => AddSubmonoid.mem_closure.mpr fun y hy => hy (mul_mem hr hb) · exact fun b _ => by simp only [zero_mul, (AddSubmonoid.closure (S : Set R)).zero_mem] · simp_rw [add_mul] exact fun r s hr hs b hb => (AddSubmonoid.closure (S : Set R)).add_mem (hr _ hb) (hs _ hb) #align mul_mem_class.mul_right_mem_add_closure MulMemClass.mul_right_mem_add_closure /-- The product of two elements of the additive closure of a submonoid `M` is an element of the additive closure of `M`. -/ theorem mul_mem_add_closure (ha : a ∈ AddSubmonoid.closure (S : Set R)) (hb : b ∈ AddSubmonoid.closure (S : Set R)) : a * b ∈ AddSubmonoid.closure (S : Set R) := by revert a apply @AddSubmonoid.closure_induction _ _ _ (fun z => ∀ {a : R}, a ∈ AddSubmonoid.closure ↑S → a * z ∈ AddSubmonoid.closure ↑S) _ hb <;> clear hb b · exact fun r hr b hb => MulMemClass.mul_right_mem_add_closure hb hr · exact fun _ => by simp only [mul_zero, (AddSubmonoid.closure (S : Set R)).zero_mem] · simp_rw [mul_add] exact fun r s hr hs b hb => (AddSubmonoid.closure (S : Set R)).add_mem (hr hb) (hs hb) #align mul_mem_class.mul_mem_add_closure MulMemClass.mul_mem_add_closure /-- The product of an element of `S` and an element of the additive closure of a multiplicative submonoid `S` is contained in the additive closure of `S`. -/ theorem mul_left_mem_add_closure (ha : a ∈ S) (hb : b ∈ AddSubmonoid.closure (S : Set R)) : a * b ∈ AddSubmonoid.closure (S : Set R) := mul_mem_add_closure (AddSubmonoid.mem_closure.mpr fun _sT hT => hT ha) hb #align mul_mem_class.mul_left_mem_add_closure MulMemClass.mul_left_mem_add_closure end MulMemClass namespace Submonoid /-- An element is in the closure of a two-element set if it is a linear combination of those two elements. -/ @[to_additive "An element is in the closure of a two-element set if it is a linear combination of those two elements."] theorem mem_closure_pair {A : Type*} [CommMonoid A] (a b c : A) : c ∈ Submonoid.closure ({a, b} : Set A) ↔ ∃ m n : ℕ, a ^ m * b ^ n = c := by rw [← Set.singleton_union, Submonoid.closure_union, mem_sup] simp_rw [mem_closure_singleton, exists_exists_eq_and] #align submonoid.mem_closure_pair Submonoid.mem_closure_pair #align add_submonoid.mem_closure_pair AddSubmonoid.mem_closure_pair end Submonoid section mul_add theorem ofMul_image_powers_eq_multiples_ofMul [Monoid M] {x : M} : Additive.ofMul '' (Submonoid.powers x : Set M) = AddSubmonoid.multiples (Additive.ofMul x) := by ext constructor · rintro ⟨y, ⟨n, hy1⟩, hy2⟩ use n simpa [← ofMul_pow, hy1] · rintro ⟨n, hn⟩ refine ⟨x ^ n, ⟨n, rfl⟩, ?_⟩ rwa [ofMul_pow] #align of_mul_image_powers_eq_multiples_of_mul ofMul_image_powers_eq_multiples_ofMul
Mathlib/Algebra/Group/Submonoid/Membership.lean
786
791
theorem ofAdd_image_multiples_eq_powers_ofAdd [AddMonoid A] {x : A} : Multiplicative.ofAdd '' (AddSubmonoid.multiples x : Set A) = Submonoid.powers (Multiplicative.ofAdd x) := by
symm rw [Equiv.eq_image_iff_symm_image_eq] exact ofMul_image_powers_eq_multiples_ofMul
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.Supported import Mathlib.LinearAlgebra.LinearIndependent import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.Algebraic import Mathlib.RingTheory.MvPolynomial.Basic #align_import ring_theory.algebraic_independent from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Algebraic Independence This file defines algebraic independence of a family of element of an `R` algebra. ## Main definitions * `AlgebraicIndependent` - `AlgebraicIndependent R x` states the family of elements `x` is algebraically independent over `R`, meaning that the canonical map out of the multivariable polynomial ring is injective. * `AlgebraicIndependent.repr` - The canonical map from the subalgebra generated by an algebraic independent family into the polynomial ring. ## References * [Stacks: Transcendence](https://stacks.math.columbia.edu/tag/030D) ## TODO Define the transcendence degree and show it is independent of the choice of a transcendence basis. ## Tags transcendence basis, transcendence degree, transcendence -/ noncomputable section open Function Set Subalgebra MvPolynomial Algebra open scoped Classical universe x u v w variable {ι : Type*} {ι' : Type*} (R : Type*) {K : Type*} variable {A : Type*} {A' A'' : Type*} {V : Type u} {V' : Type*} variable (x : ι → A) variable [CommRing R] [CommRing A] [CommRing A'] [CommRing A''] variable [Algebra R A] [Algebra R A'] [Algebra R A''] variable {a b : R} /-- `AlgebraicIndependent R x` states the family of elements `x` is algebraically independent over `R`, meaning that the canonical map out of the multivariable polynomial ring is injective. -/ def AlgebraicIndependent : Prop := Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A) #align algebraic_independent AlgebraicIndependent variable {R} {x} theorem algebraicIndependent_iff_ker_eq_bot : AlgebraicIndependent R x ↔ RingHom.ker (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom = ⊥ := RingHom.injective_iff_ker_eq_bot _ #align algebraic_independent_iff_ker_eq_bot algebraicIndependent_iff_ker_eq_bot theorem algebraicIndependent_iff : AlgebraicIndependent R x ↔ ∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 := injective_iff_map_eq_zero _ #align algebraic_independent_iff algebraicIndependent_iff theorem AlgebraicIndependent.eq_zero_of_aeval_eq_zero (h : AlgebraicIndependent R x) : ∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 := algebraicIndependent_iff.1 h #align algebraic_independent.eq_zero_of_aeval_eq_zero AlgebraicIndependent.eq_zero_of_aeval_eq_zero theorem algebraicIndependent_iff_injective_aeval : AlgebraicIndependent R x ↔ Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A) := Iff.rfl #align algebraic_independent_iff_injective_aeval algebraicIndependent_iff_injective_aeval @[simp] theorem algebraicIndependent_empty_type_iff [IsEmpty ι] : AlgebraicIndependent R x ↔ Injective (algebraMap R A) := by have : aeval x = (Algebra.ofId R A).comp (@isEmptyAlgEquiv R ι _ _).toAlgHom := by ext i exact IsEmpty.elim' ‹IsEmpty ι› i rw [AlgebraicIndependent, this, ← Injective.of_comp_iff' _ (@isEmptyAlgEquiv R ι _ _).bijective] rfl #align algebraic_independent_empty_type_iff algebraicIndependent_empty_type_iff namespace AlgebraicIndependent variable (hx : AlgebraicIndependent R x) theorem algebraMap_injective : Injective (algebraMap R A) := by simpa [Function.comp] using (Injective.of_comp_iff (algebraicIndependent_iff_injective_aeval.1 hx) MvPolynomial.C).2 (MvPolynomial.C_injective _ _) #align algebraic_independent.algebra_map_injective AlgebraicIndependent.algebraMap_injective theorem linearIndependent : LinearIndependent R x := by rw [linearIndependent_iff_injective_total] have : Finsupp.total ι A R x = (MvPolynomial.aeval x).toLinearMap.comp (Finsupp.total ι _ R X) := by ext simp rw [this] refine hx.comp ?_ rw [← linearIndependent_iff_injective_total] exact linearIndependent_X _ _ #align algebraic_independent.linear_independent AlgebraicIndependent.linearIndependent protected theorem injective [Nontrivial R] : Injective x := hx.linearIndependent.injective #align algebraic_independent.injective AlgebraicIndependent.injective theorem ne_zero [Nontrivial R] (i : ι) : x i ≠ 0 := hx.linearIndependent.ne_zero i #align algebraic_independent.ne_zero AlgebraicIndependent.ne_zero theorem comp (f : ι' → ι) (hf : Function.Injective f) : AlgebraicIndependent R (x ∘ f) := by intro p q simpa [aeval_rename, (rename_injective f hf).eq_iff] using @hx (rename f p) (rename f q) #align algebraic_independent.comp AlgebraicIndependent.comp theorem coe_range : AlgebraicIndependent R ((↑) : range x → A) := by simpa using hx.comp _ (rangeSplitting_injective x) #align algebraic_independent.coe_range AlgebraicIndependent.coe_range theorem map {f : A →ₐ[R] A'} (hf_inj : Set.InjOn f (adjoin R (range x))) : AlgebraicIndependent R (f ∘ x) := by have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp have h : ∀ p : MvPolynomial ι R, aeval x p ∈ (@aeval R _ _ _ _ _ ((↑) : range x → A)).range := by intro p rw [AlgHom.mem_range] refine ⟨MvPolynomial.rename (codRestrict x (range x) mem_range_self) p, ?_⟩ simp [Function.comp, aeval_rename] intro x y hxy rw [this] at hxy rw [adjoin_eq_range] at hf_inj exact hx (hf_inj (h x) (h y) hxy) #align algebraic_independent.map AlgebraicIndependent.map theorem map' {f : A →ₐ[R] A'} (hf_inj : Injective f) : AlgebraicIndependent R (f ∘ x) := hx.map hf_inj.injOn #align algebraic_independent.map' AlgebraicIndependent.map' theorem of_comp (f : A →ₐ[R] A') (hfv : AlgebraicIndependent R (f ∘ x)) : AlgebraicIndependent R x := by have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp rw [AlgebraicIndependent, this, AlgHom.coe_comp] at hfv exact hfv.of_comp #align algebraic_independent.of_comp AlgebraicIndependent.of_comp end AlgebraicIndependent open AlgebraicIndependent theorem AlgHom.algebraicIndependent_iff (f : A →ₐ[R] A') (hf : Injective f) : AlgebraicIndependent R (f ∘ x) ↔ AlgebraicIndependent R x := ⟨fun h => h.of_comp f, fun h => h.map hf.injOn⟩ #align alg_hom.algebraic_independent_iff AlgHom.algebraicIndependent_iff @[nontriviality] theorem algebraicIndependent_of_subsingleton [Subsingleton R] : AlgebraicIndependent R x := algebraicIndependent_iff.2 fun _ _ => Subsingleton.elim _ _ #align algebraic_independent_of_subsingleton algebraicIndependent_of_subsingleton theorem algebraicIndependent_equiv (e : ι ≃ ι') {f : ι' → A} : AlgebraicIndependent R (f ∘ e) ↔ AlgebraicIndependent R f := ⟨fun h => Function.comp_id f ▸ e.self_comp_symm ▸ h.comp _ e.symm.injective, fun h => h.comp _ e.injective⟩ #align algebraic_independent_equiv algebraicIndependent_equiv theorem algebraicIndependent_equiv' (e : ι ≃ ι') {f : ι' → A} {g : ι → A} (h : f ∘ e = g) : AlgebraicIndependent R g ↔ AlgebraicIndependent R f := h ▸ algebraicIndependent_equiv e #align algebraic_independent_equiv' algebraicIndependent_equiv' theorem algebraicIndependent_subtype_range {ι} {f : ι → A} (hf : Injective f) : AlgebraicIndependent R ((↑) : range f → A) ↔ AlgebraicIndependent R f := Iff.symm <| algebraicIndependent_equiv' (Equiv.ofInjective f hf) rfl #align algebraic_independent_subtype_range algebraicIndependent_subtype_range alias ⟨AlgebraicIndependent.of_subtype_range, _⟩ := algebraicIndependent_subtype_range #align algebraic_independent.of_subtype_range AlgebraicIndependent.of_subtype_range theorem algebraicIndependent_image {ι} {s : Set ι} {f : ι → A} (hf : Set.InjOn f s) : (AlgebraicIndependent R fun x : s => f x) ↔ AlgebraicIndependent R fun x : f '' s => (x : A) := algebraicIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl #align algebraic_independent_image algebraicIndependent_image theorem algebraicIndependent_adjoin (hs : AlgebraicIndependent R x) : @AlgebraicIndependent ι R (adjoin R (range x)) (fun i : ι => ⟨x i, subset_adjoin (mem_range_self i)⟩) _ _ _ := AlgebraicIndependent.of_comp (adjoin R (range x)).val hs #align algebraic_independent_adjoin algebraicIndependent_adjoin /-- A set of algebraically independent elements in an algebra `A` over a ring `K` is also algebraically independent over a subring `R` of `K`. -/ theorem AlgebraicIndependent.restrictScalars {K : Type*} [CommRing K] [Algebra R K] [Algebra K A] [IsScalarTower R K A] (hinj : Function.Injective (algebraMap R K)) (ai : AlgebraicIndependent K x) : AlgebraicIndependent R x := by have : (aeval x : MvPolynomial ι K →ₐ[K] A).toRingHom.comp (MvPolynomial.map (algebraMap R K)) = (aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom := by ext <;> simp [algebraMap_eq_smul_one] show Injective (aeval x).toRingHom rw [← this, RingHom.coe_comp] exact Injective.comp ai (MvPolynomial.map_injective _ hinj) #align algebraic_independent.restrict_scalars AlgebraicIndependent.restrictScalars /-- Every finite subset of an algebraically independent set is algebraically independent. -/ theorem algebraicIndependent_finset_map_embedding_subtype (s : Set A) (li : AlgebraicIndependent R ((↑) : s → A)) (t : Finset s) : AlgebraicIndependent R ((↑) : Finset.map (Embedding.subtype s) t → A) := by let f : t.map (Embedding.subtype s) → s := fun x => ⟨x.1, by obtain ⟨x, h⟩ := x rw [Finset.mem_map] at h obtain ⟨a, _, rfl⟩ := h simp only [Subtype.coe_prop, Embedding.coe_subtype]⟩ convert AlgebraicIndependent.comp li f _ rintro ⟨x, hx⟩ ⟨y, hy⟩ rw [Finset.mem_map] at hx hy obtain ⟨a, _, rfl⟩ := hx obtain ⟨b, _, rfl⟩ := hy simp only [f, imp_self, Subtype.mk_eq_mk] #align algebraic_independent_finset_map_embedding_subtype algebraicIndependent_finset_map_embedding_subtype /-- If every finite set of algebraically independent element has cardinality at most `n`, then the same is true for arbitrary sets of algebraically independent elements. -/ theorem algebraicIndependent_bounded_of_finset_algebraicIndependent_bounded {n : ℕ} (H : ∀ s : Finset A, (AlgebraicIndependent R fun i : s => (i : A)) → s.card ≤ n) : ∀ s : Set A, AlgebraicIndependent R ((↑) : s → A) → Cardinal.mk s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply algebraicIndependent_finset_map_embedding_subtype _ li #align algebraic_independent_bounded_of_finset_algebraic_independent_bounded algebraicIndependent_bounded_of_finset_algebraicIndependent_bounded section Subtype theorem AlgebraicIndependent.restrict_of_comp_subtype {s : Set ι} (hs : AlgebraicIndependent R (x ∘ (↑) : s → A)) : AlgebraicIndependent R (s.restrict x) := hs #align algebraic_independent.restrict_of_comp_subtype AlgebraicIndependent.restrict_of_comp_subtype variable (R A) theorem algebraicIndependent_empty_iff : AlgebraicIndependent R ((↑) : (∅ : Set A) → A) ↔ Injective (algebraMap R A) := by simp #align algebraic_independent_empty_iff algebraicIndependent_empty_iff variable {R A} theorem AlgebraicIndependent.mono {t s : Set A} (h : t ⊆ s) (hx : AlgebraicIndependent R ((↑) : s → A)) : AlgebraicIndependent R ((↑) : t → A) := by simpa [Function.comp] using hx.comp (inclusion h) (inclusion_injective h) #align algebraic_independent.mono AlgebraicIndependent.mono end Subtype theorem AlgebraicIndependent.to_subtype_range {ι} {f : ι → A} (hf : AlgebraicIndependent R f) : AlgebraicIndependent R ((↑) : range f → A) := by nontriviality R rwa [algebraicIndependent_subtype_range hf.injective] #align algebraic_independent.to_subtype_range AlgebraicIndependent.to_subtype_range theorem AlgebraicIndependent.to_subtype_range' {ι} {f : ι → A} (hf : AlgebraicIndependent R f) {t} (ht : range f = t) : AlgebraicIndependent R ((↑) : t → A) := ht ▸ hf.to_subtype_range #align algebraic_independent.to_subtype_range' AlgebraicIndependent.to_subtype_range' theorem algebraicIndependent_comp_subtype {s : Set ι} : AlgebraicIndependent R (x ∘ (↑) : s → A) ↔ ∀ p ∈ MvPolynomial.supported R s, aeval x p = 0 → p = 0 := by have : (aeval (x ∘ (↑) : s → A) : _ →ₐ[R] _) = (aeval x).comp (rename (↑)) := by ext; simp have : ∀ p : MvPolynomial s R, rename ((↑) : s → ι) p = 0 ↔ p = 0 := (injective_iff_map_eq_zero' (rename ((↑) : s → ι) : MvPolynomial s R →ₐ[R] _).toRingHom).1 (rename_injective _ Subtype.val_injective) simp [algebraicIndependent_iff, supported_eq_range_rename, *] #align algebraic_independent_comp_subtype algebraicIndependent_comp_subtype theorem algebraicIndependent_subtype {s : Set A} : AlgebraicIndependent R ((↑) : s → A) ↔ ∀ p : MvPolynomial A R, p ∈ MvPolynomial.supported R s → aeval id p = 0 → p = 0 := by apply @algebraicIndependent_comp_subtype _ _ _ id #align algebraic_independent_subtype algebraicIndependent_subtype theorem algebraicIndependent_of_finite (s : Set A) (H : ∀ t ⊆ s, t.Finite → AlgebraicIndependent R ((↑) : t → A)) : AlgebraicIndependent R ((↑) : s → A) := algebraicIndependent_subtype.2 fun p hp => algebraicIndependent_subtype.1 (H _ (mem_supported.1 hp) (Finset.finite_toSet _)) _ (by simp) #align algebraic_independent_of_finite algebraicIndependent_of_finite theorem AlgebraicIndependent.image_of_comp {ι ι'} (s : Set ι) (f : ι → ι') (g : ι' → A) (hs : AlgebraicIndependent R fun x : s => g (f x)) : AlgebraicIndependent R fun x : f '' s => g x := by nontriviality R have : InjOn f s := injOn_iff_injective.2 hs.injective.of_comp exact (algebraicIndependent_equiv' (Equiv.Set.imageOfInjOn f s this) rfl).1 hs #align algebraic_independent.image_of_comp AlgebraicIndependent.image_of_comp theorem AlgebraicIndependent.image {ι} {s : Set ι} {f : ι → A} (hs : AlgebraicIndependent R fun x : s => f x) : AlgebraicIndependent R fun x : f '' s => (x : A) := by convert AlgebraicIndependent.image_of_comp s f id hs #align algebraic_independent.image AlgebraicIndependent.image theorem algebraicIndependent_iUnion_of_directed {η : Type*} [Nonempty η] {s : η → Set A} (hs : Directed (· ⊆ ·) s) (h : ∀ i, AlgebraicIndependent R ((↑) : s i → A)) : AlgebraicIndependent R ((↑) : (⋃ i, s i) → A) := by refine algebraicIndependent_of_finite (⋃ i, s i) fun t ht ft => ?_ rcases finite_subset_iUnion ft ht with ⟨I, fi, hI⟩ rcases hs.finset_le fi.toFinset with ⟨i, hi⟩ exact (h i).mono (Subset.trans hI <| iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj)) #align algebraic_independent_Union_of_directed algebraicIndependent_iUnion_of_directed theorem algebraicIndependent_sUnion_of_directed {s : Set (Set A)} (hsn : s.Nonempty) (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, AlgebraicIndependent R ((↑) : a → A)) : AlgebraicIndependent R ((↑) : ⋃₀ s → A) := by letI : Nonempty s := Nonempty.to_subtype hsn rw [sUnion_eq_iUnion] exact algebraicIndependent_iUnion_of_directed hs.directed_val (by simpa using h) #align algebraic_independent_sUnion_of_directed algebraicIndependent_sUnion_of_directed theorem exists_maximal_algebraicIndependent (s t : Set A) (hst : s ⊆ t) (hs : AlgebraicIndependent R ((↑) : s → A)) : ∃ u : Set A, AlgebraicIndependent R ((↑) : u → A) ∧ s ⊆ u ∧ u ⊆ t ∧ ∀ x : Set A, AlgebraicIndependent R ((↑) : x → A) → u ⊆ x → x ⊆ t → x = u := by rcases zorn_subset_nonempty { u : Set A | AlgebraicIndependent R ((↑) : u → A) ∧ s ⊆ u ∧ u ⊆ t } (fun c hc chainc hcn => ⟨⋃₀ c, by refine ⟨⟨algebraicIndependent_sUnion_of_directed hcn chainc.directedOn fun a ha => (hc ha).1, ?_, ?_⟩, ?_⟩ · cases' hcn with x hx exact subset_sUnion_of_subset _ x (hc hx).2.1 hx · exact sUnion_subset fun x hx => (hc hx).2.2 · intro s exact subset_sUnion_of_mem⟩) s ⟨hs, Set.Subset.refl s, hst⟩ with ⟨u, ⟨huai, _, hut⟩, hsu, hx⟩ use u, huai, hsu, hut intro x hxai huv hxt exact hx _ ⟨hxai, _root_.trans hsu huv, hxt⟩ huv #align exists_maximal_algebraic_independent exists_maximal_algebraicIndependent section repr variable (hx : AlgebraicIndependent R x) /-- Canonical isomorphism between polynomials and the subalgebra generated by algebraically independent elements. -/ @[simps!] def AlgebraicIndependent.aevalEquiv (hx : AlgebraicIndependent R x) : MvPolynomial ι R ≃ₐ[R] Algebra.adjoin R (range x) := by apply AlgEquiv.ofBijective (AlgHom.codRestrict (@aeval R A ι _ _ _ x) (Algebra.adjoin R (range x)) _) swap · intro x rw [adjoin_range_eq_range_aeval] exact AlgHom.mem_range_self _ _ · constructor · exact (AlgHom.injective_codRestrict _ _ _).2 hx · rintro ⟨x, hx⟩ rw [adjoin_range_eq_range_aeval] at hx rcases hx with ⟨y, rfl⟩ use y ext simp #align algebraic_independent.aeval_equiv AlgebraicIndependent.aevalEquiv --@[simp] Porting note: removing simp because the linter complains about deterministic timeout theorem AlgebraicIndependent.algebraMap_aevalEquiv (hx : AlgebraicIndependent R x) (p : MvPolynomial ι R) : algebraMap (Algebra.adjoin R (range x)) A (hx.aevalEquiv p) = aeval x p := rfl #align algebraic_independent.algebra_map_aeval_equiv AlgebraicIndependent.algebraMap_aevalEquiv /-- The canonical map from the subalgebra generated by an algebraic independent family into the polynomial ring. -/ def AlgebraicIndependent.repr (hx : AlgebraicIndependent R x) : Algebra.adjoin R (range x) →ₐ[R] MvPolynomial ι R := hx.aevalEquiv.symm #align algebraic_independent.repr AlgebraicIndependent.repr @[simp] theorem AlgebraicIndependent.aeval_repr (p) : aeval x (hx.repr p) = p := Subtype.ext_iff.1 (AlgEquiv.apply_symm_apply hx.aevalEquiv p) #align algebraic_independent.aeval_repr AlgebraicIndependent.aeval_repr theorem AlgebraicIndependent.aeval_comp_repr : (aeval x).comp hx.repr = Subalgebra.val _ := AlgHom.ext <| hx.aeval_repr #align algebraic_independent.aeval_comp_repr AlgebraicIndependent.aeval_comp_repr theorem AlgebraicIndependent.repr_ker : RingHom.ker (hx.repr : adjoin R (range x) →+* MvPolynomial ι R) = ⊥ := (RingHom.injective_iff_ker_eq_bot _).1 (AlgEquiv.injective _) #align algebraic_independent.repr_ker AlgebraicIndependent.repr_ker end repr -- TODO - make this an `AlgEquiv` /-- The isomorphism between `MvPolynomial (Option ι) R` and the polynomial ring over the algebra generated by an algebraically independent family. -/ def AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin (hx : AlgebraicIndependent R x) : MvPolynomial (Option ι) R ≃+* Polynomial (adjoin R (Set.range x)) := (MvPolynomial.optionEquivLeft _ _).toRingEquiv.trans (Polynomial.mapEquiv hx.aevalEquiv.toRingEquiv) #align algebraic_independent.mv_polynomial_option_equiv_polynomial_adjoin AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin @[simp] theorem AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_apply (hx : AlgebraicIndependent R x) (y) : hx.mvPolynomialOptionEquivPolynomialAdjoin y = Polynomial.map (hx.aevalEquiv : MvPolynomial ι R →+* adjoin R (range x)) (aeval (fun o : Option ι => o.elim Polynomial.X fun s : ι => Polynomial.C (X s)) y) := rfl #align algebraic_independent.mv_polynomial_option_equiv_polynomial_adjoin_apply AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_apply --@[simp] Porting note: removing simp because the linter complains about deterministic timeout theorem AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_C (hx : AlgebraicIndependent R x) (r) : hx.mvPolynomialOptionEquivPolynomialAdjoin (C r) = Polynomial.C (algebraMap _ _ r) := by rw [AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_apply, aeval_C, IsScalarTower.algebraMap_apply R (MvPolynomial ι R), ← Polynomial.C_eq_algebraMap, Polynomial.map_C, RingHom.coe_coe, AlgEquiv.commutes] set_option linter.uppercaseLean3 false in #align algebraic_independent.mv_polynomial_option_equiv_polynomial_adjoin_C AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_C --@[simp] Porting note (#10618): simp can prove it theorem AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_X_none (hx : AlgebraicIndependent R x) : hx.mvPolynomialOptionEquivPolynomialAdjoin (X none) = Polynomial.X := by rw [AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_apply, aeval_X, Option.elim, Polynomial.map_X] set_option linter.uppercaseLean3 false in #align algebraic_independent.mv_polynomial_option_equiv_polynomial_adjoin_X_none AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_X_none --@[simp] Porting note (#10618): simp can prove it theorem AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_X_some (hx : AlgebraicIndependent R x) (i) : hx.mvPolynomialOptionEquivPolynomialAdjoin (X (some i)) = Polynomial.C (hx.aevalEquiv (X i)) := by rw [AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_apply, aeval_X, Option.elim, Polynomial.map_C, RingHom.coe_coe] set_option linter.uppercaseLean3 false in #align algebraic_independent.mv_polynomial_option_equiv_polynomial_adjoin_X_some AlgebraicIndependent.mvPolynomialOptionEquivPolynomialAdjoin_X_some theorem AlgebraicIndependent.aeval_comp_mvPolynomialOptionEquivPolynomialAdjoin (hx : AlgebraicIndependent R x) (a : A) : RingHom.comp (↑(Polynomial.aeval a : Polynomial (adjoin R (Set.range x)) →ₐ[_] A) : Polynomial (adjoin R (Set.range x)) →+* A) hx.mvPolynomialOptionEquivPolynomialAdjoin.toRingHom = ↑(MvPolynomial.aeval fun o : Option ι => o.elim a x : MvPolynomial (Option ι) R →ₐ[R] A) := by refine MvPolynomial.ringHom_ext ?_ ?_ <;> simp only [RingHom.comp_apply, RingEquiv.toRingHom_eq_coe, RingEquiv.coe_toRingHom, AlgHom.coe_toRingHom, AlgHom.coe_toRingHom] · intro r rw [hx.mvPolynomialOptionEquivPolynomialAdjoin_C, aeval_C, Polynomial.aeval_C, IsScalarTower.algebraMap_apply R (adjoin R (range x)) A] · rintro (⟨⟩ | ⟨i⟩) · rw [hx.mvPolynomialOptionEquivPolynomialAdjoin_X_none, aeval_X, Polynomial.aeval_X, Option.elim] · rw [hx.mvPolynomialOptionEquivPolynomialAdjoin_X_some, Polynomial.aeval_C, hx.algebraMap_aevalEquiv, aeval_X, aeval_X, Option.elim] #align algebraic_independent.aeval_comp_mv_polynomial_option_equiv_polynomial_adjoin AlgebraicIndependent.aeval_comp_mvPolynomialOptionEquivPolynomialAdjoin theorem AlgebraicIndependent.option_iff (hx : AlgebraicIndependent R x) (a : A) : (AlgebraicIndependent R fun o : Option ι => o.elim a x) ↔ ¬IsAlgebraic (adjoin R (Set.range x)) a := by rw [algebraicIndependent_iff_injective_aeval, isAlgebraic_iff_not_injective, Classical.not_not, ← AlgHom.coe_toRingHom, ← hx.aeval_comp_mvPolynomialOptionEquivPolynomialAdjoin, RingHom.coe_comp] exact Injective.of_comp_iff' (Polynomial.aeval a) (mvPolynomialOptionEquivPolynomialAdjoin hx).bijective #align algebraic_independent.option_iff AlgebraicIndependent.option_iff variable (R) /-- A family is a transcendence basis if it is a maximal algebraically independent subset. -/ def IsTranscendenceBasis (x : ι → A) : Prop := AlgebraicIndependent R x ∧ ∀ (s : Set A) (_ : AlgebraicIndependent R ((↑) : s → A)) (_ : range x ≤ s), range x = s #align is_transcendence_basis IsTranscendenceBasis theorem exists_isTranscendenceBasis (h : Injective (algebraMap R A)) : ∃ s : Set A, IsTranscendenceBasis R ((↑) : s → A) := by cases' exists_maximal_algebraicIndependent (∅ : Set A) Set.univ (Set.subset_univ _) ((algebraicIndependent_empty_iff R A).2 h) with s hs use s, hs.1 intro t ht hr simp only [Subtype.range_coe_subtype, setOf_mem_eq] at * exact Eq.symm (hs.2.2.2 t ht hr (Set.subset_univ _)) #align exists_is_transcendence_basis exists_isTranscendenceBasis variable {R} theorem AlgebraicIndependent.isTranscendenceBasis_iff {ι : Type w} {R : Type u} [CommRing R] [Nontrivial R] {A : Type v} [CommRing A] [Algebra R A] {x : ι → A} (i : AlgebraicIndependent R x) : IsTranscendenceBasis R x ↔ ∀ (κ : Type v) (w : κ → A) (_ : AlgebraicIndependent R w) (j : ι → κ) (_ : w ∘ j = x), Surjective j := by fconstructor · rintro p κ w i' j rfl have p := p.2 (range w) i'.coe_range (range_comp_subset_range _ _) rw [range_comp, ← @image_univ _ _ w] at p exact range_iff_surjective.mp (image_injective.mpr i'.injective p) · intro p use i intro w i' h specialize p w ((↑) : w → A) i' (fun i => ⟨x i, range_subset_iff.mp h i⟩) (by ext; simp) have q := congr_arg (fun s => ((↑) : w → A) '' s) p.range_eq dsimp at q rw [← image_univ, image_image] at q simpa using q #align algebraic_independent.is_transcendence_basis_iff AlgebraicIndependent.isTranscendenceBasis_iff
Mathlib/RingTheory/AlgebraicIndependent.lean
533
551
theorem IsTranscendenceBasis.isAlgebraic [Nontrivial R] (hx : IsTranscendenceBasis R x) : Algebra.IsAlgebraic (adjoin R (range x)) A := by
constructor intro a rw [← not_iff_comm.1 (hx.1.option_iff _).symm] intro ai have h₁ : range x ⊆ range fun o : Option ι => o.elim a x := by rintro x ⟨y, rfl⟩ exact ⟨some y, rfl⟩ have h₂ : range x ≠ range fun o : Option ι => o.elim a x := by intro h have : a ∈ range x := by rw [h] exact ⟨none, rfl⟩ rcases this with ⟨b, rfl⟩ have : some b = none := ai.injective rfl simpa exact h₂ (hx.2 (Set.range fun o : Option ι => o.elim a x) ((algebraicIndependent_subtype_range ai.injective).2 ai) h₁)
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Adam Topaz, Johan Commelin, Jakob von Raumer -/ import Mathlib.CategoryTheory.Abelian.Opposite import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels import Mathlib.CategoryTheory.Preadditive.LeftExact import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.Algebra.Homology.Exact import Mathlib.Tactic.TFAE #align_import category_theory.abelian.exact from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Exact sequences in abelian categories In an abelian category, we get several interesting results related to exactness which are not true in more general settings. ## Main results * `(f, g)` is exact if and only if `f ≫ g = 0` and `kernel.ι g ≫ cokernel.π f = 0`. This characterisation tends to be less cumbersome to work with than the original definition involving the comparison map `image f ⟶ kernel g`. * If `(f, g)` is exact, then `image.ι f` has the universal property of the kernel of `g`. * `f` is a monomorphism iff `kernel.ι f = 0` iff `Exact 0 f`, and `f` is an epimorphism iff `cokernel.π = 0` iff `Exact f 0`. * A faithful functor between abelian categories that preserves zero morphisms reflects exact sequences. * `X ⟶ Y ⟶ Z ⟶ 0` is exact if and only if the second map is a cokernel of the first, and `0 ⟶ X ⟶ Y ⟶ Z` is exact if and only if the first map is a kernel of the second. * An exact functor preserves exactness, more specifically, `F` preserves finite colimits and finite limits, if and only if `Exact f g` implies `Exact (F.map f) (F.map g)`. -/ universe v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory Limits Preadditive variable {C : Type u₁} [Category.{v₁} C] [Abelian C] namespace CategoryTheory namespace Abelian variable {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) attribute [local instance] hasEqualizers_of_hasKernels /-- In an abelian category, a pair of morphisms `f : X ⟶ Y`, `g : Y ⟶ Z` is exact iff `imageSubobject f = kernelSubobject g`. -/ theorem exact_iff_image_eq_kernel : Exact f g ↔ imageSubobject f = kernelSubobject g := by constructor · intro h have : IsIso (imageToKernel f g h.w) := have := h.epi; isIso_of_mono_of_epi _ refine Subobject.eq_of_comm (asIso (imageToKernel _ _ h.w)) ?_ simp · apply exact_of_image_eq_kernel #align category_theory.abelian.exact_iff_image_eq_kernel CategoryTheory.Abelian.exact_iff_image_eq_kernel theorem exact_iff : Exact f g ↔ f ≫ g = 0 ∧ kernel.ι g ≫ cokernel.π f = 0 := by constructor · exact fun h ↦ ⟨h.1, kernel_comp_cokernel f g h⟩ · refine fun h ↦ ⟨h.1, ?_⟩ suffices hl : IsLimit (KernelFork.ofι (imageSubobject f).arrow (imageSubobject_arrow_comp_eq_zero h.1)) by have : imageToKernel f g h.1 = (hl.conePointUniqueUpToIso (limit.isLimit _)).hom ≫ (kernelSubobjectIso _).inv := by ext; simp rw [this] infer_instance refine KernelFork.IsLimit.ofι _ _ (fun u hu ↦ ?_) ?_ (fun _ _ _ h ↦ ?_) · refine kernel.lift (cokernel.π f) u ?_ ≫ (imageIsoImage f).hom ≫ (imageSubobjectIso _).inv rw [← kernel.lift_ι g u hu, Category.assoc, h.2, comp_zero] · aesop_cat · rw [← cancel_mono (imageSubobject f).arrow, h] simp #align category_theory.abelian.exact_iff CategoryTheory.Abelian.exact_iff theorem exact_iff' {cg : KernelFork g} (hg : IsLimit cg) {cf : CokernelCofork f} (hf : IsColimit cf) : Exact f g ↔ f ≫ g = 0 ∧ cg.ι ≫ cf.π = 0 := by constructor · intro h exact ⟨h.1, fork_ι_comp_cofork_π f g h cg cf⟩ · rw [exact_iff] refine fun h => ⟨h.1, ?_⟩ apply zero_of_epi_comp (IsLimit.conePointUniqueUpToIso hg (limit.isLimit _)).hom apply zero_of_comp_mono (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) hf).hom simp [h.2] #align category_theory.abelian.exact_iff' CategoryTheory.Abelian.exact_iff' open List in theorem exact_tfae : TFAE [Exact f g, f ≫ g = 0 ∧ kernel.ι g ≫ cokernel.π f = 0, imageSubobject f = kernelSubobject g] := by tfae_have 1 ↔ 2; · apply exact_iff tfae_have 1 ↔ 3; · apply exact_iff_image_eq_kernel tfae_finish #align category_theory.abelian.exact_tfae CategoryTheory.Abelian.exact_tfae nonrec theorem IsEquivalence.exact_iff {D : Type u₁} [Category.{v₁} D] [Abelian D] (F : C ⥤ D) [F.IsEquivalence] : Exact (F.map f) (F.map g) ↔ Exact f g := by simp only [exact_iff, ← F.map_eq_zero_iff, F.map_comp, Category.assoc, ← kernelComparison_comp_ι g F, ← π_comp_cokernelComparison f F] rw [IsIso.comp_left_eq_zero (kernelComparison g F), ← Category.assoc, IsIso.comp_right_eq_zero _ (cokernelComparison f F)] #align category_theory.abelian.is_equivalence.exact_iff CategoryTheory.Abelian.IsEquivalence.exact_iff /-- The dual result is true even in non-abelian categories, see `CategoryTheory.exact_comp_mono_iff`. -/ theorem exact_epi_comp_iff {W : C} (h : W ⟶ X) [Epi h] : Exact (h ≫ f) g ↔ Exact f g := by refine ⟨fun hfg => ?_, fun h => exact_epi_comp h⟩ let hc := isCokernelOfComp _ _ (colimit.isColimit (parallelPair (h ≫ f) 0)) (by rw [← cancel_epi h, ← Category.assoc, CokernelCofork.condition, comp_zero]) rfl refine (exact_iff' _ _ (limit.isLimit _) hc).2 ⟨?_, ((exact_iff _ _).1 hfg).2⟩ exact zero_of_epi_comp h (by rw [← hfg.1, Category.assoc]) #align category_theory.abelian.exact_epi_comp_iff CategoryTheory.Abelian.exact_epi_comp_iff /-- If `(f, g)` is exact, then `Abelian.image.ι f` is a kernel of `g`. -/ def isLimitImage (h : Exact f g) : IsLimit (KernelFork.ofι (Abelian.image.ι f) (image_ι_comp_eq_zero h.1) : KernelFork g) := by rw [exact_iff] at h exact KernelFork.IsLimit.ofι _ _ (fun u hu ↦ kernel.lift (cokernel.π f) u (by rw [← kernel.lift_ι g u hu, Category.assoc, h.2, comp_zero])) (by aesop_cat) (fun _ _ _ hm => by rw [← cancel_mono (image.ι f), hm, kernel.lift_ι]) #align category_theory.abelian.is_limit_image CategoryTheory.Abelian.isLimitImage /-- If `(f, g)` is exact, then `image.ι f` is a kernel of `g`. -/ def isLimitImage' (h : Exact f g) : IsLimit (KernelFork.ofι (Limits.image.ι f) (Limits.image_ι_comp_eq_zero h.1)) := IsKernel.isoKernel _ _ (isLimitImage f g h) (imageIsoImage f).symm <| IsImage.lift_fac _ _ #align category_theory.abelian.is_limit_image' CategoryTheory.Abelian.isLimitImage' /-- If `(f, g)` is exact, then `Abelian.coimage.π g` is a cokernel of `f`. -/ def isColimitCoimage (h : Exact f g) : IsColimit (CokernelCofork.ofπ (Abelian.coimage.π g) (Abelian.comp_coimage_π_eq_zero h.1) : CokernelCofork f) := by rw [exact_iff] at h refine CokernelCofork.IsColimit.ofπ _ _ (fun u hu => cokernel.desc (kernel.ι g) u (by rw [← cokernel.π_desc f u hu, ← Category.assoc, h.2, zero_comp])) (by aesop_cat) ?_ intros _ _ _ _ hm ext rw [hm, cokernel.π_desc] #align category_theory.abelian.is_colimit_coimage CategoryTheory.Abelian.isColimitCoimage /-- If `(f, g)` is exact, then `factorThruImage g` is a cokernel of `f`. -/ def isColimitImage (h : Exact f g) : IsColimit (CokernelCofork.ofπ (Limits.factorThruImage g) (comp_factorThruImage_eq_zero h.1)) := IsCokernel.cokernelIso _ _ (isColimitCoimage f g h) (coimageIsoImage' g) <| (cancel_mono (Limits.image.ι g)).1 <| by simp #align category_theory.abelian.is_colimit_image CategoryTheory.Abelian.isColimitImage theorem exact_cokernel : Exact f (cokernel.π f) := by rw [exact_iff] aesop_cat #align category_theory.abelian.exact_cokernel CategoryTheory.Abelian.exact_cokernel -- Porting note: this can no longer be an instance in Lean4 lemma mono_cokernel_desc_of_exact (h : Exact f g) : Mono (cokernel.desc f g h.w) := suffices h : cokernel.desc f g h.w = (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitImage f g h)).hom ≫ Limits.image.ι g from h.symm ▸ mono_comp _ _ (cancel_epi (cokernel.π f)).1 <| by simp -- Porting note: this can no longer be an instance in Lean4 /-- If `ex : Exact f g` and `epi g`, then `cokernel.desc _ _ ex.w` is an isomorphism. -/ lemma isIso_cokernel_desc_of_exact_of_epi (ex : Exact f g) [Epi g] : IsIso (cokernel.desc f g ex.w) := have := mono_cokernel_desc_of_exact _ _ ex isIso_of_mono_of_epi (Limits.cokernel.desc f g ex.w) -- Porting note: removed the simp attribute because the lemma may never apply automatically @[reassoc (attr := nolint unusedHavesSuffices)] theorem cokernel.desc.inv [Epi g] (ex : Exact f g) : have := isIso_cokernel_desc_of_exact_of_epi _ _ ex g ≫ inv (cokernel.desc _ _ ex.w) = cokernel.π _ := by have := isIso_cokernel_desc_of_exact_of_epi _ _ ex simp #align category_theory.abelian.cokernel.desc.inv CategoryTheory.Abelian.cokernel.desc.inv -- Porting note: this can no longer be an instance in Lean4 lemma isIso_kernel_lift_of_exact_of_mono (ex : Exact f g) [Mono f] : IsIso (kernel.lift g f ex.w) := have := ex.epi_kernel_lift isIso_of_mono_of_epi (Limits.kernel.lift g f ex.w) -- Porting note: removed the simp attribute because the lemma may never apply automatically @[reassoc (attr := nolint unusedHavesSuffices)] theorem kernel.lift.inv [Mono f] (ex : Exact f g) : have := isIso_kernel_lift_of_exact_of_mono _ _ ex inv (kernel.lift _ _ ex.w) ≫ f = kernel.ι g := by have := isIso_kernel_lift_of_exact_of_mono _ _ ex simp #align category_theory.abelian.kernel.lift.inv CategoryTheory.Abelian.kernel.lift.inv /-- If `X ⟶ Y ⟶ Z ⟶ 0` is exact, then the second map is a cokernel of the first. -/ def isColimitOfExactOfEpi [Epi g] (h : Exact f g) : IsColimit (CokernelCofork.ofπ _ h.w) := IsColimit.ofIsoColimit (colimit.isColimit _) <| Cocones.ext ⟨cokernel.desc _ _ h.w, epiDesc g (cokernel.π f) ((exact_iff _ _).1 h).2, (cancel_epi (cokernel.π f)).1 (by aesop_cat), (cancel_epi g).1 (by aesop_cat)⟩ (by rintro (_|_) <;> simp [h.w]) #align category_theory.abelian.is_colimit_of_exact_of_epi CategoryTheory.Abelian.isColimitOfExactOfEpi /-- If `0 ⟶ X ⟶ Y ⟶ Z` is exact, then the first map is a kernel of the second. -/ def isLimitOfExactOfMono [Mono f] (h : Exact f g) : IsLimit (KernelFork.ofι _ h.w) := IsLimit.ofIsoLimit (limit.isLimit _) <| Cones.ext ⟨monoLift f (kernel.ι g) ((exact_iff _ _).1 h).2, kernel.lift _ _ h.w, (cancel_mono (kernel.ι g)).1 (by aesop_cat), (cancel_mono f).1 (by aesop_cat)⟩ fun j => by cases j <;> simp #align category_theory.abelian.is_limit_of_exact_of_mono CategoryTheory.Abelian.isLimitOfExactOfMono theorem exact_of_is_cokernel (w : f ≫ g = 0) (h : IsColimit (CokernelCofork.ofπ _ w)) : Exact f g := by refine (exact_iff _ _).2 ⟨w, ?_⟩ have := h.fac (CokernelCofork.ofπ _ (cokernel.condition f)) WalkingParallelPair.one simp only [Cofork.ofπ_ι_app] at this rw [← this, ← Category.assoc, kernel.condition, zero_comp] #align category_theory.abelian.exact_of_is_cokernel CategoryTheory.Abelian.exact_of_is_cokernel theorem exact_of_is_kernel (w : f ≫ g = 0) (h : IsLimit (KernelFork.ofι _ w)) : Exact f g := by refine (exact_iff _ _).2 ⟨w, ?_⟩ have := h.fac (KernelFork.ofι _ (kernel.condition g)) WalkingParallelPair.zero simp only [Fork.ofι_π_app] at this rw [← this, Category.assoc, cokernel.condition, comp_zero] #align category_theory.abelian.exact_of_is_kernel CategoryTheory.Abelian.exact_of_is_kernel theorem exact_iff_exact_image_ι : Exact f g ↔ Exact (Abelian.image.ι f) g := by conv_lhs => rw [← Abelian.image.fac f] rw [exact_epi_comp_iff] #align category_theory.abelian.exact_iff_exact_image_ι CategoryTheory.Abelian.exact_iff_exact_image_ι theorem exact_iff_exact_coimage_π : Exact f g ↔ Exact f (coimage.π g) := by conv_lhs => rw [← Abelian.coimage.fac g] rw [exact_comp_mono_iff] #align category_theory.abelian.exact_iff_exact_coimage_π CategoryTheory.Abelian.exact_iff_exact_coimage_π section variable (Z) open List in
Mathlib/CategoryTheory/Abelian/Exact.lean
253
261
theorem tfae_mono : TFAE [Mono f, kernel.ι f = 0, Exact (0 : Z ⟶ X) f] := by
tfae_have 3 → 2 · exact kernel_ι_eq_zero_of_exact_zero_left Z tfae_have 1 → 3 · intros exact exact_zero_left_of_mono Z tfae_have 2 → 1 · exact mono_of_kernel_ι_eq_zero _ tfae_finish
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Logic.Relation import Mathlib.Data.Option.Basic import Mathlib.Data.Seq.Seq #align_import data.seq.wseq from "leanprover-community/mathlib"@"a7e36e48519ab281320c4d192da6a7b348ce40ad" /-! # Partially defined possibly infinite lists This file provides a `WSeq α` type representing partially defined possibly infinite lists (referred here as weak sequences). -/ namespace Stream' open Function universe u v w /- coinductive WSeq (α : Type u) : Type u | nil : WSeq α | cons : α → WSeq α → WSeq α | think : WSeq α → WSeq α -/ /-- Weak sequences. While the `Seq` structure allows for lists which may not be finite, a weak sequence also allows the computation of each element to involve an indeterminate amount of computation, including possibly an infinite loop. This is represented as a regular `Seq` interspersed with `none` elements to indicate that computation is ongoing. This model is appropriate for Haskell style lazy lists, and is closed under most interesting computation patterns on infinite lists, but conversely it is difficult to extract elements from it. -/ def WSeq (α) := Seq (Option α) #align stream.wseq Stream'.WSeq /- coinductive WSeq (α : Type u) : Type u | nil : WSeq α | cons : α → WSeq α → WSeq α | think : WSeq α → WSeq α -/ namespace WSeq variable {α : Type u} {β : Type v} {γ : Type w} /-- Turn a sequence into a weak sequence -/ @[coe] def ofSeq : Seq α → WSeq α := (· <$> ·) some #align stream.wseq.of_seq Stream'.WSeq.ofSeq /-- Turn a list into a weak sequence -/ @[coe] def ofList (l : List α) : WSeq α := ofSeq l #align stream.wseq.of_list Stream'.WSeq.ofList /-- Turn a stream into a weak sequence -/ @[coe] def ofStream (l : Stream' α) : WSeq α := ofSeq l #align stream.wseq.of_stream Stream'.WSeq.ofStream instance coeSeq : Coe (Seq α) (WSeq α) := ⟨ofSeq⟩ #align stream.wseq.coe_seq Stream'.WSeq.coeSeq instance coeList : Coe (List α) (WSeq α) := ⟨ofList⟩ #align stream.wseq.coe_list Stream'.WSeq.coeList instance coeStream : Coe (Stream' α) (WSeq α) := ⟨ofStream⟩ #align stream.wseq.coe_stream Stream'.WSeq.coeStream /-- The empty weak sequence -/ def nil : WSeq α := Seq.nil #align stream.wseq.nil Stream'.WSeq.nil instance inhabited : Inhabited (WSeq α) := ⟨nil⟩ #align stream.wseq.inhabited Stream'.WSeq.inhabited /-- Prepend an element to a weak sequence -/ def cons (a : α) : WSeq α → WSeq α := Seq.cons (some a) #align stream.wseq.cons Stream'.WSeq.cons /-- Compute for one tick, without producing any elements -/ def think : WSeq α → WSeq α := Seq.cons none #align stream.wseq.think Stream'.WSeq.think /-- Destruct a weak sequence, to (eventually possibly) produce either `none` for `nil` or `some (a, s)` if an element is produced. -/ def destruct : WSeq α → Computation (Option (α × WSeq α)) := Computation.corec fun s => match Seq.destruct s with | none => Sum.inl none | some (none, s') => Sum.inr s' | some (some a, s') => Sum.inl (some (a, s')) #align stream.wseq.destruct Stream'.WSeq.destruct /-- Recursion principle for weak sequences, compare with `List.recOn`. -/ def recOn {C : WSeq α → Sort v} (s : WSeq α) (h1 : C nil) (h2 : ∀ x s, C (cons x s)) (h3 : ∀ s, C (think s)) : C s := Seq.recOn s h1 fun o => Option.recOn o h3 h2 #align stream.wseq.rec_on Stream'.WSeq.recOn /-- membership for weak sequences-/ protected def Mem (a : α) (s : WSeq α) := Seq.Mem (some a) s #align stream.wseq.mem Stream'.WSeq.Mem instance membership : Membership α (WSeq α) := ⟨WSeq.Mem⟩ #align stream.wseq.has_mem Stream'.WSeq.membership theorem not_mem_nil (a : α) : a ∉ @nil α := Seq.not_mem_nil (some a) #align stream.wseq.not_mem_nil Stream'.WSeq.not_mem_nil /-- Get the head of a weak sequence. This involves a possibly infinite computation. -/ def head (s : WSeq α) : Computation (Option α) := Computation.map (Prod.fst <$> ·) (destruct s) #align stream.wseq.head Stream'.WSeq.head /-- Encode a computation yielding a weak sequence into additional `think` constructors in a weak sequence -/ def flatten : Computation (WSeq α) → WSeq α := Seq.corec fun c => match Computation.destruct c with | Sum.inl s => Seq.omap (return ·) (Seq.destruct s) | Sum.inr c' => some (none, c') #align stream.wseq.flatten Stream'.WSeq.flatten /-- Get the tail of a weak sequence. This doesn't need a `Computation` wrapper, unlike `head`, because `flatten` allows us to hide this in the construction of the weak sequence itself. -/ def tail (s : WSeq α) : WSeq α := flatten <| (fun o => Option.recOn o nil Prod.snd) <$> destruct s #align stream.wseq.tail Stream'.WSeq.tail /-- drop the first `n` elements from `s`. -/ def drop (s : WSeq α) : ℕ → WSeq α | 0 => s | n + 1 => tail (drop s n) #align stream.wseq.drop Stream'.WSeq.drop /-- Get the nth element of `s`. -/ def get? (s : WSeq α) (n : ℕ) : Computation (Option α) := head (drop s n) #align stream.wseq.nth Stream'.WSeq.get? /-- Convert `s` to a list (if it is finite and completes in finite time). -/ def toList (s : WSeq α) : Computation (List α) := @Computation.corec (List α) (List α × WSeq α) (fun ⟨l, s⟩ => match Seq.destruct s with | none => Sum.inl l.reverse | some (none, s') => Sum.inr (l, s') | some (some a, s') => Sum.inr (a::l, s')) ([], s) #align stream.wseq.to_list Stream'.WSeq.toList /-- Get the length of `s` (if it is finite and completes in finite time). -/ def length (s : WSeq α) : Computation ℕ := @Computation.corec ℕ (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s with | none => Sum.inl n | some (none, s') => Sum.inr (n, s') | some (some _, s') => Sum.inr (n + 1, s')) (0, s) #align stream.wseq.length Stream'.WSeq.length /-- A weak sequence is finite if `toList s` terminates. Equivalently, it is a finite number of `think` and `cons` applied to `nil`. -/ class IsFinite (s : WSeq α) : Prop where out : (toList s).Terminates #align stream.wseq.is_finite Stream'.WSeq.IsFinite instance toList_terminates (s : WSeq α) [h : IsFinite s] : (toList s).Terminates := h.out #align stream.wseq.to_list_terminates Stream'.WSeq.toList_terminates /-- Get the list corresponding to a finite weak sequence. -/ def get (s : WSeq α) [IsFinite s] : List α := (toList s).get #align stream.wseq.get Stream'.WSeq.get /-- A weak sequence is *productive* if it never stalls forever - there are always a finite number of `think`s between `cons` constructors. The sequence itself is allowed to be infinite though. -/ class Productive (s : WSeq α) : Prop where get?_terminates : ∀ n, (get? s n).Terminates #align stream.wseq.productive Stream'.WSeq.Productive #align stream.wseq.productive.nth_terminates Stream'.WSeq.Productive.get?_terminates theorem productive_iff (s : WSeq α) : Productive s ↔ ∀ n, (get? s n).Terminates := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align stream.wseq.productive_iff Stream'.WSeq.productive_iff instance get?_terminates (s : WSeq α) [h : Productive s] : ∀ n, (get? s n).Terminates := h.get?_terminates #align stream.wseq.nth_terminates Stream'.WSeq.get?_terminates instance head_terminates (s : WSeq α) [Productive s] : (head s).Terminates := s.get?_terminates 0 #align stream.wseq.head_terminates Stream'.WSeq.head_terminates /-- Replace the `n`th element of `s` with `a`. -/ def updateNth (s : WSeq α) (n : ℕ) (a : α) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s, n with | none, _ => none | some (none, s'), n => some (none, n, s') | some (some a', s'), 0 => some (some a', 0, s') | some (some _, s'), 1 => some (some a, 0, s') | some (some a', s'), n + 2 => some (some a', n + 1, s')) (n + 1, s) #align stream.wseq.update_nth Stream'.WSeq.updateNth /-- Remove the `n`th element of `s`. -/ def removeNth (s : WSeq α) (n : ℕ) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match Seq.destruct s, n with | none, _ => none | some (none, s'), n => some (none, n, s') | some (some a', s'), 0 => some (some a', 0, s') | some (some _, s'), 1 => some (none, 0, s') | some (some a', s'), n + 2 => some (some a', n + 1, s')) (n + 1, s) #align stream.wseq.remove_nth Stream'.WSeq.removeNth /-- Map the elements of `s` over `f`, removing any values that yield `none`. -/ def filterMap (f : α → Option β) : WSeq α → WSeq β := Seq.corec fun s => match Seq.destruct s with | none => none | some (none, s') => some (none, s') | some (some a, s') => some (f a, s') #align stream.wseq.filter_map Stream'.WSeq.filterMap /-- Select the elements of `s` that satisfy `p`. -/ def filter (p : α → Prop) [DecidablePred p] : WSeq α → WSeq α := filterMap fun a => if p a then some a else none #align stream.wseq.filter Stream'.WSeq.filter -- example of infinite list manipulations /-- Get the first element of `s` satisfying `p`. -/ def find (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation (Option α) := head <| filter p s #align stream.wseq.find Stream'.WSeq.find /-- Zip a function over two weak sequences -/ def zipWith (f : α → β → γ) (s1 : WSeq α) (s2 : WSeq β) : WSeq γ := @Seq.corec (Option γ) (WSeq α × WSeq β) (fun ⟨s1, s2⟩ => match Seq.destruct s1, Seq.destruct s2 with | some (none, s1'), some (none, s2') => some (none, s1', s2') | some (some _, _), some (none, s2') => some (none, s1, s2') | some (none, s1'), some (some _, _) => some (none, s1', s2) | some (some a1, s1'), some (some a2, s2') => some (some (f a1 a2), s1', s2') | _, _ => none) (s1, s2) #align stream.wseq.zip_with Stream'.WSeq.zipWith /-- Zip two weak sequences into a single sequence of pairs -/ def zip : WSeq α → WSeq β → WSeq (α × β) := zipWith Prod.mk #align stream.wseq.zip Stream'.WSeq.zip /-- Get the list of indexes of elements of `s` satisfying `p` -/ def findIndexes (p : α → Prop) [DecidablePred p] (s : WSeq α) : WSeq ℕ := (zip s (Stream'.nats : WSeq ℕ)).filterMap fun ⟨a, n⟩ => if p a then some n else none #align stream.wseq.find_indexes Stream'.WSeq.findIndexes /-- Get the index of the first element of `s` satisfying `p` -/ def findIndex (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation ℕ := (fun o => Option.getD o 0) <$> head (findIndexes p s) #align stream.wseq.find_index Stream'.WSeq.findIndex /-- Get the index of the first occurrence of `a` in `s` -/ def indexOf [DecidableEq α] (a : α) : WSeq α → Computation ℕ := findIndex (Eq a) #align stream.wseq.index_of Stream'.WSeq.indexOf /-- Get the indexes of occurrences of `a` in `s` -/ def indexesOf [DecidableEq α] (a : α) : WSeq α → WSeq ℕ := findIndexes (Eq a) #align stream.wseq.indexes_of Stream'.WSeq.indexesOf /-- `union s1 s2` is a weak sequence which interleaves `s1` and `s2` in some order (nondeterministically). -/ def union (s1 s2 : WSeq α) : WSeq α := @Seq.corec (Option α) (WSeq α × WSeq α) (fun ⟨s1, s2⟩ => match Seq.destruct s1, Seq.destruct s2 with | none, none => none | some (a1, s1'), none => some (a1, s1', nil) | none, some (a2, s2') => some (a2, nil, s2') | some (none, s1'), some (none, s2') => some (none, s1', s2') | some (some a1, s1'), some (none, s2') => some (some a1, s1', s2') | some (none, s1'), some (some a2, s2') => some (some a2, s1', s2') | some (some a1, s1'), some (some a2, s2') => some (some a1, cons a2 s1', s2')) (s1, s2) #align stream.wseq.union Stream'.WSeq.union /-- Returns `true` if `s` is `nil` and `false` if `s` has an element -/ def isEmpty (s : WSeq α) : Computation Bool := Computation.map Option.isNone <| head s #align stream.wseq.is_empty Stream'.WSeq.isEmpty /-- Calculate one step of computation -/ def compute (s : WSeq α) : WSeq α := match Seq.destruct s with | some (none, s') => s' | _ => s #align stream.wseq.compute Stream'.WSeq.compute /-- Get the first `n` elements of a weak sequence -/ def take (s : WSeq α) (n : ℕ) : WSeq α := @Seq.corec (Option α) (ℕ × WSeq α) (fun ⟨n, s⟩ => match n, Seq.destruct s with | 0, _ => none | _ + 1, none => none | m + 1, some (none, s') => some (none, m + 1, s') | m + 1, some (some a, s') => some (some a, m, s')) (n, s) #align stream.wseq.take Stream'.WSeq.take /-- Split the sequence at position `n` into a finite initial segment and the weak sequence tail -/ def splitAt (s : WSeq α) (n : ℕ) : Computation (List α × WSeq α) := @Computation.corec (List α × WSeq α) (ℕ × List α × WSeq α) (fun ⟨n, l, s⟩ => match n, Seq.destruct s with | 0, _ => Sum.inl (l.reverse, s) | _ + 1, none => Sum.inl (l.reverse, s) | _ + 1, some (none, s') => Sum.inr (n, l, s') | m + 1, some (some a, s') => Sum.inr (m, a::l, s')) (n, [], s) #align stream.wseq.split_at Stream'.WSeq.splitAt /-- Returns `true` if any element of `s` satisfies `p` -/ def any (s : WSeq α) (p : α → Bool) : Computation Bool := Computation.corec (fun s : WSeq α => match Seq.destruct s with | none => Sum.inl false | some (none, s') => Sum.inr s' | some (some a, s') => if p a then Sum.inl true else Sum.inr s') s #align stream.wseq.any Stream'.WSeq.any /-- Returns `true` if every element of `s` satisfies `p` -/ def all (s : WSeq α) (p : α → Bool) : Computation Bool := Computation.corec (fun s : WSeq α => match Seq.destruct s with | none => Sum.inl true | some (none, s') => Sum.inr s' | some (some a, s') => if p a then Sum.inr s' else Sum.inl false) s #align stream.wseq.all Stream'.WSeq.all /-- Apply a function to the elements of the sequence to produce a sequence of partial results. (There is no `scanr` because this would require working from the end of the sequence, which may not exist.) -/ def scanl (f : α → β → α) (a : α) (s : WSeq β) : WSeq α := cons a <| @Seq.corec (Option α) (α × WSeq β) (fun ⟨a, s⟩ => match Seq.destruct s with | none => none | some (none, s') => some (none, a, s') | some (some b, s') => let a' := f a b some (some a', a', s')) (a, s) #align stream.wseq.scanl Stream'.WSeq.scanl /-- Get the weak sequence of initial segments of the input sequence -/ def inits (s : WSeq α) : WSeq (List α) := cons [] <| @Seq.corec (Option (List α)) (Batteries.DList α × WSeq α) (fun ⟨l, s⟩ => match Seq.destruct s with | none => none | some (none, s') => some (none, l, s') | some (some a, s') => let l' := l.push a some (some l'.toList, l', s')) (Batteries.DList.empty, s) #align stream.wseq.inits Stream'.WSeq.inits /-- Like take, but does not wait for a result. Calculates `n` steps of computation and returns the sequence computed so far -/ def collect (s : WSeq α) (n : ℕ) : List α := (Seq.take n s).filterMap id #align stream.wseq.collect Stream'.WSeq.collect /-- Append two weak sequences. As with `Seq.append`, this may not use the second sequence if the first one takes forever to compute -/ def append : WSeq α → WSeq α → WSeq α := Seq.append #align stream.wseq.append Stream'.WSeq.append /-- Map a function over a weak sequence -/ def map (f : α → β) : WSeq α → WSeq β := Seq.map (Option.map f) #align stream.wseq.map Stream'.WSeq.map /-- Flatten a sequence of weak sequences. (Note that this allows empty sequences, unlike `Seq.join`.) -/ def join (S : WSeq (WSeq α)) : WSeq α := Seq.join ((fun o : Option (WSeq α) => match o with | none => Seq1.ret none | some s => (none, s)) <$> S) #align stream.wseq.join Stream'.WSeq.join /-- Monadic bind operator for weak sequences -/ def bind (s : WSeq α) (f : α → WSeq β) : WSeq β := join (map f s) #align stream.wseq.bind Stream'.WSeq.bind /-- lift a relation to a relation over weak sequences -/ @[simp] def LiftRelO (R : α → β → Prop) (C : WSeq α → WSeq β → Prop) : Option (α × WSeq α) → Option (β × WSeq β) → Prop | none, none => True | some (a, s), some (b, t) => R a b ∧ C s t | _, _ => False #align stream.wseq.lift_rel_o Stream'.WSeq.LiftRelO theorem LiftRelO.imp {R S : α → β → Prop} {C D : WSeq α → WSeq β → Prop} (H1 : ∀ a b, R a b → S a b) (H2 : ∀ s t, C s t → D s t) : ∀ {o p}, LiftRelO R C o p → LiftRelO S D o p | none, none, _ => trivial | some (_, _), some (_, _), h => And.imp (H1 _ _) (H2 _ _) h | none, some _, h => False.elim h | some (_, _), none, h => False.elim h #align stream.wseq.lift_rel_o.imp Stream'.WSeq.LiftRelO.imp theorem LiftRelO.imp_right (R : α → β → Prop) {C D : WSeq α → WSeq β → Prop} (H : ∀ s t, C s t → D s t) {o p} : LiftRelO R C o p → LiftRelO R D o p := LiftRelO.imp (fun _ _ => id) H #align stream.wseq.lift_rel_o.imp_right Stream'.WSeq.LiftRelO.imp_right /-- Definition of bisimilarity for weak sequences-/ @[simp] def BisimO (R : WSeq α → WSeq α → Prop) : Option (α × WSeq α) → Option (α × WSeq α) → Prop := LiftRelO (· = ·) R #align stream.wseq.bisim_o Stream'.WSeq.BisimO theorem BisimO.imp {R S : WSeq α → WSeq α → Prop} (H : ∀ s t, R s t → S s t) {o p} : BisimO R o p → BisimO S o p := LiftRelO.imp_right _ H #align stream.wseq.bisim_o.imp Stream'.WSeq.BisimO.imp /-- Two weak sequences are `LiftRel R` related if they are either both empty, or they are both nonempty and the heads are `R` related and the tails are `LiftRel R` related. (This is a coinductive definition.) -/ def LiftRel (R : α → β → Prop) (s : WSeq α) (t : WSeq β) : Prop := ∃ C : WSeq α → WSeq β → Prop, C s t ∧ ∀ {s t}, C s t → Computation.LiftRel (LiftRelO R C) (destruct s) (destruct t) #align stream.wseq.lift_rel Stream'.WSeq.LiftRel /-- If two sequences are equivalent, then they have the same values and the same computational behavior (i.e. if one loops forever then so does the other), although they may differ in the number of `think`s needed to arrive at the answer. -/ def Equiv : WSeq α → WSeq α → Prop := LiftRel (· = ·) #align stream.wseq.equiv Stream'.WSeq.Equiv theorem liftRel_destruct {R : α → β → Prop} {s : WSeq α} {t : WSeq β} : LiftRel R s t → Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) | ⟨R, h1, h2⟩ => by refine Computation.LiftRel.imp ?_ _ _ (h2 h1) apply LiftRelO.imp_right exact fun s' t' h' => ⟨R, h', @h2⟩ #align stream.wseq.lift_rel_destruct Stream'.WSeq.liftRel_destruct theorem liftRel_destruct_iff {R : α → β → Prop} {s : WSeq α} {t : WSeq β} : LiftRel R s t ↔ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := ⟨liftRel_destruct, fun h => ⟨fun s t => LiftRel R s t ∨ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t), Or.inr h, fun {s t} h => by have h : Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := by cases' h with h h · exact liftRel_destruct h · assumption apply Computation.LiftRel.imp _ _ _ h intro a b apply LiftRelO.imp_right intro s t apply Or.inl⟩⟩ #align stream.wseq.lift_rel_destruct_iff Stream'.WSeq.liftRel_destruct_iff -- Porting note: To avoid ambiguous notation, `~` became `~ʷ`. infixl:50 " ~ʷ " => Equiv theorem destruct_congr {s t : WSeq α} : s ~ʷ t → Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) := liftRel_destruct #align stream.wseq.destruct_congr Stream'.WSeq.destruct_congr theorem destruct_congr_iff {s t : WSeq α} : s ~ʷ t ↔ Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) := liftRel_destruct_iff #align stream.wseq.destruct_congr_iff Stream'.WSeq.destruct_congr_iff theorem LiftRel.refl (R : α → α → Prop) (H : Reflexive R) : Reflexive (LiftRel R) := fun s => by refine ⟨(· = ·), rfl, fun {s t} (h : s = t) => ?_⟩ rw [← h] apply Computation.LiftRel.refl intro a cases' a with a · simp · cases a simp only [LiftRelO, and_true] apply H #align stream.wseq.lift_rel.refl Stream'.WSeq.LiftRel.refl theorem LiftRelO.swap (R : α → β → Prop) (C) : swap (LiftRelO R C) = LiftRelO (swap R) (swap C) := by funext x y rcases x with ⟨⟩ | ⟨hx, jx⟩ <;> rcases y with ⟨⟩ | ⟨hy, jy⟩ <;> rfl #align stream.wseq.lift_rel_o.swap Stream'.WSeq.LiftRelO.swap theorem LiftRel.swap_lem {R : α → β → Prop} {s1 s2} (h : LiftRel R s1 s2) : LiftRel (swap R) s2 s1 := by refine ⟨swap (LiftRel R), h, fun {s t} (h : LiftRel R t s) => ?_⟩ rw [← LiftRelO.swap, Computation.LiftRel.swap] apply liftRel_destruct h #align stream.wseq.lift_rel.swap_lem Stream'.WSeq.LiftRel.swap_lem theorem LiftRel.swap (R : α → β → Prop) : swap (LiftRel R) = LiftRel (swap R) := funext fun _ => funext fun _ => propext ⟨LiftRel.swap_lem, LiftRel.swap_lem⟩ #align stream.wseq.lift_rel.swap Stream'.WSeq.LiftRel.swap theorem LiftRel.symm (R : α → α → Prop) (H : Symmetric R) : Symmetric (LiftRel R) := fun s1 s2 (h : Function.swap (LiftRel R) s2 s1) => by rwa [LiftRel.swap, H.swap_eq] at h #align stream.wseq.lift_rel.symm Stream'.WSeq.LiftRel.symm theorem LiftRel.trans (R : α → α → Prop) (H : Transitive R) : Transitive (LiftRel R) := fun s t u h1 h2 => by refine ⟨fun s u => ∃ t, LiftRel R s t ∧ LiftRel R t u, ⟨t, h1, h2⟩, fun {s u} h => ?_⟩ rcases h with ⟨t, h1, h2⟩ have h1 := liftRel_destruct h1 have h2 := liftRel_destruct h2 refine Computation.liftRel_def.2 ⟨(Computation.terminates_of_liftRel h1).trans (Computation.terminates_of_liftRel h2), fun {a c} ha hc => ?_⟩ rcases h1.left ha with ⟨b, hb, t1⟩ have t2 := Computation.rel_of_liftRel h2 hb hc cases' a with a <;> cases' c with c · trivial · cases b · cases t2 · cases t1 · cases a cases' b with b · cases t1 · cases b cases t2 · cases' a with a s cases' b with b · cases t1 cases' b with b t cases' c with c u cases' t1 with ab st cases' t2 with bc tu exact ⟨H ab bc, t, st, tu⟩ #align stream.wseq.lift_rel.trans Stream'.WSeq.LiftRel.trans theorem LiftRel.equiv (R : α → α → Prop) : Equivalence R → Equivalence (LiftRel R) | ⟨refl, symm, trans⟩ => ⟨LiftRel.refl R refl, @(LiftRel.symm R @symm), @(LiftRel.trans R @trans)⟩ #align stream.wseq.lift_rel.equiv Stream'.WSeq.LiftRel.equiv @[refl] theorem Equiv.refl : ∀ s : WSeq α, s ~ʷ s := LiftRel.refl (· = ·) Eq.refl #align stream.wseq.equiv.refl Stream'.WSeq.Equiv.refl @[symm] theorem Equiv.symm : ∀ {s t : WSeq α}, s ~ʷ t → t ~ʷ s := @(LiftRel.symm (· = ·) (@Eq.symm _)) #align stream.wseq.equiv.symm Stream'.WSeq.Equiv.symm @[trans] theorem Equiv.trans : ∀ {s t u : WSeq α}, s ~ʷ t → t ~ʷ u → s ~ʷ u := @(LiftRel.trans (· = ·) (@Eq.trans _)) #align stream.wseq.equiv.trans Stream'.WSeq.Equiv.trans theorem Equiv.equivalence : Equivalence (@Equiv α) := ⟨@Equiv.refl _, @Equiv.symm _, @Equiv.trans _⟩ #align stream.wseq.equiv.equivalence Stream'.WSeq.Equiv.equivalence open Computation @[simp] theorem destruct_nil : destruct (nil : WSeq α) = Computation.pure none := Computation.destruct_eq_pure rfl #align stream.wseq.destruct_nil Stream'.WSeq.destruct_nil @[simp] theorem destruct_cons (a : α) (s) : destruct (cons a s) = Computation.pure (some (a, s)) := Computation.destruct_eq_pure <| by simp [destruct, cons, Computation.rmap] #align stream.wseq.destruct_cons Stream'.WSeq.destruct_cons @[simp] theorem destruct_think (s : WSeq α) : destruct (think s) = (destruct s).think := Computation.destruct_eq_think <| by simp [destruct, think, Computation.rmap] #align stream.wseq.destruct_think Stream'.WSeq.destruct_think @[simp] theorem seq_destruct_nil : Seq.destruct (nil : WSeq α) = none := Seq.destruct_nil #align stream.wseq.seq_destruct_nil Stream'.WSeq.seq_destruct_nil @[simp] theorem seq_destruct_cons (a : α) (s) : Seq.destruct (cons a s) = some (some a, s) := Seq.destruct_cons _ _ #align stream.wseq.seq_destruct_cons Stream'.WSeq.seq_destruct_cons @[simp] theorem seq_destruct_think (s : WSeq α) : Seq.destruct (think s) = some (none, s) := Seq.destruct_cons _ _ #align stream.wseq.seq_destruct_think Stream'.WSeq.seq_destruct_think @[simp] theorem head_nil : head (nil : WSeq α) = Computation.pure none := by simp [head] #align stream.wseq.head_nil Stream'.WSeq.head_nil @[simp] theorem head_cons (a : α) (s) : head (cons a s) = Computation.pure (some a) := by simp [head] #align stream.wseq.head_cons Stream'.WSeq.head_cons @[simp] theorem head_think (s : WSeq α) : head (think s) = (head s).think := by simp [head] #align stream.wseq.head_think Stream'.WSeq.head_think @[simp] theorem flatten_pure (s : WSeq α) : flatten (Computation.pure s) = s := by refine Seq.eq_of_bisim (fun s1 s2 => flatten (Computation.pure s2) = s1) ?_ rfl intro s' s h rw [← h] simp only [Seq.BisimO, flatten, Seq.omap, pure_def, Seq.corec_eq, destruct_pure] cases Seq.destruct s with | none => simp | some val => cases' val with o s' simp #align stream.wseq.flatten_ret Stream'.WSeq.flatten_pure @[simp] theorem flatten_think (c : Computation (WSeq α)) : flatten c.think = think (flatten c) := Seq.destruct_eq_cons <| by simp [flatten, think] #align stream.wseq.flatten_think Stream'.WSeq.flatten_think @[simp]
Mathlib/Data/Seq/WSeq.lean
685
697
theorem destruct_flatten (c : Computation (WSeq α)) : destruct (flatten c) = c >>= destruct := by
refine Computation.eq_of_bisim (fun c1 c2 => c1 = c2 ∨ ∃ c, c1 = destruct (flatten c) ∧ c2 = Computation.bind c destruct) ?_ (Or.inr ⟨c, rfl, rfl⟩) intro c1 c2 h exact match c1, c2, h with | c, _, Or.inl rfl => by cases c.destruct <;> simp | _, _, Or.inr ⟨c, rfl, rfl⟩ => by induction' c using Computation.recOn with a c' <;> simp · cases (destruct a).destruct <;> simp · exact Or.inr ⟨c', rfl, rfl⟩
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.Orientation import Mathlib.Data.Complex.Orientation import Mathlib.Tactic.LinearCombination #align_import analysis.inner_product_space.two_dim from "leanprover-community/mathlib"@"cd8fafa2fac98e1a67097e8a91ad9901cfde48af" /-! # Oriented two-dimensional real inner product spaces This file defines constructions specific to the geometry of an oriented two-dimensional real inner product space `E`. ## Main declarations * `Orientation.areaForm`: an antisymmetric bilinear form `E →ₗ[ℝ] E →ₗ[ℝ] ℝ` (usual notation `ω`). Morally, when `ω` is evaluated on two vectors, it gives the oriented area of the parallelogram they span. (But mathlib does not yet have a construction of oriented area, and in fact the construction of oriented area should pass through `ω`.) * `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᵢ[ℝ] E` (usual notation `J`). This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined, in such a way that this automorphism is equal to rotation by 90 degrees. * `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]` for `E`. * `Orientation.kahler`: a complex-valued real-bilinear map `E →ₗ[ℝ] E →ₗ[ℝ] ℂ`. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`, the complex number `o.kahler x y` has modulus `‖x‖ * ‖y‖`. In a later file, oriented angles (`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the oriented angle from `x` to `y`. ## Main results * `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x` * `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if and only if `0 ≤ ⟪x, y⟫` and `ω x y = 0` * `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y` * `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner product space `ℂ` * `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`, `Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `ℂ`, expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete interpretations on `ℂ` ## Implementation notes Notation `ω` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be defined locally in each file which uses them, since otherwise one would need a more cumbersome notation which mentions the orientation explicitly (something like `ω[o]`). Write ``` local notation "ω" => o.areaForm local notation "J" => o.rightAngleRotation ``` -/ noncomputable section open scoped RealInnerProductSpace ComplexConjugate open FiniteDimensional lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V := .of_fact_finrank_eq_succ 1 attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two @[deprecated (since := "2024-02-02")] alias FiniteDimensional.finiteDimensional_of_fact_finrank_eq_two := FiniteDimensional.of_fact_finrank_eq_two variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)] (o : Orientation ℝ E (Fin 2)) namespace Orientation /-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual notation `ω`). When evaluated on two vectors, it gives the oriented area of the parallelogram they span. -/ irreducible_def areaForm : E →ₗ[ℝ] E →ₗ[ℝ] ℝ := by let z : E [⋀^Fin 0]→ₗ[ℝ] ℝ ≃ₗ[ℝ] ℝ := AlternatingMap.constLinearEquivOfIsEmpty.symm let y : E [⋀^Fin 1]→ₗ[ℝ] ℝ →ₗ[ℝ] E →ₗ[ℝ] ℝ := LinearMap.llcomp ℝ E (E [⋀^Fin 0]→ₗ[ℝ] ℝ) ℝ z ∘ₗ AlternatingMap.curryLeftLinearMap exact y ∘ₗ AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm #align orientation.area_form Orientation.areaForm local notation "ω" => o.areaForm theorem areaForm_to_volumeForm (x y : E) : ω x y = o.volumeForm ![x, y] := by simp [areaForm] #align orientation.area_form_to_volume_form Orientation.areaForm_to_volumeForm @[simp] theorem areaForm_apply_self (x : E) : ω x x = 0 := by rw [areaForm_to_volumeForm] refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) ≠ 1) · simp · norm_num #align orientation.area_form_apply_self Orientation.areaForm_apply_self theorem areaForm_swap (x y : E) : ω x y = -ω y x := by simp only [areaForm_to_volumeForm] convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) ≠ 1) · ext i fin_cases i <;> rfl · norm_num #align orientation.area_form_swap Orientation.areaForm_swap @[simp] theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by ext x y simp [areaForm_to_volumeForm] #align orientation.area_form_neg_orientation Orientation.areaForm_neg_orientation /-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/ def areaForm' : E →L[ℝ] E →L[ℝ] ℝ := LinearMap.toContinuousLinearMap (↑(LinearMap.toContinuousLinearMap : (E →ₗ[ℝ] ℝ) ≃ₗ[ℝ] E →L[ℝ] ℝ) ∘ₗ o.areaForm) #align orientation.area_form' Orientation.areaForm' @[simp] theorem areaForm'_apply (x : E) : o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) := rfl #align orientation.area_form'_apply Orientation.areaForm'_apply theorem abs_areaForm_le (x y : E) : |ω x y| ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y] #align orientation.abs_area_form_le Orientation.abs_areaForm_le theorem areaForm_le (x y : E) : ω x y ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y] #align orientation.area_form_le Orientation.areaForm_le theorem abs_areaForm_of_orthogonal {x y : E} (h : ⟪x, y⟫ = 0) : |ω x y| = ‖x‖ * ‖y‖ := by rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal] · simp [Fin.prod_univ_succ] intro i j hij fin_cases i <;> fin_cases j · simp_all · simpa using h · simpa [real_inner_comm] using h · simp_all #align orientation.abs_area_form_of_orthogonal Orientation.abs_areaForm_of_orthogonal theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).areaForm x y = o.areaForm (φ.symm x) (φ.symm y) := by have : φ.symm ∘ ![x, y] = ![φ.symm x, φ.symm y] := by ext i fin_cases i <;> rfl simp [areaForm_to_volumeForm, volumeForm_map, this] #align orientation.area_form_map Orientation.areaForm_map /-- The area form is invariant under pullback by a positively-oriented isometric automorphism. -/ theorem areaForm_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) : o.areaForm (φ x) (φ y) = o.areaForm x y := by convert o.areaForm_map φ (φ x) (φ y) · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] · simp · simp #align orientation.area_form_comp_linear_isometry_equiv Orientation.areaForm_comp_linearIsometryEquiv /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ irreducible_def rightAngleRotationAux₁ : E →ₗ[ℝ] E := let to_dual : E ≃ₗ[ℝ] E →ₗ[ℝ] ℝ := (InnerProductSpace.toDual ℝ E).toLinearEquiv ≪≫ₗ LinearMap.toContinuousLinearMap.symm ↑to_dual.symm ∘ₗ ω #align orientation.right_angle_rotation_aux₁ Orientation.rightAngleRotationAux₁ @[simp] theorem inner_rightAngleRotationAux₁_left (x y : E) : ⟪o.rightAngleRotationAux₁ x, y⟫ = ω x y := by -- Porting note: split `simp only` for greater proof control simp only [rightAngleRotationAux₁, LinearEquiv.trans_symm, LinearIsometryEquiv.toLinearEquiv_symm, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply, LinearIsometryEquiv.coe_toLinearEquiv] rw [InnerProductSpace.toDual_symm_apply] norm_cast #align orientation.inner_right_angle_rotation_aux₁_left Orientation.inner_rightAngleRotationAux₁_left @[simp] theorem inner_rightAngleRotationAux₁_right (x y : E) : ⟪x, o.rightAngleRotationAux₁ y⟫ = -ω x y := by rw [real_inner_comm] simp [o.areaForm_swap y x] #align orientation.inner_right_angle_rotation_aux₁_right Orientation.inner_rightAngleRotationAux₁_right /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ def rightAngleRotationAux₂ : E →ₗᵢ[ℝ] E := { o.rightAngleRotationAux₁ with norm_map' := fun x => by dsimp refine le_antisymm ?_ ?_ · cases' eq_or_lt_of_le (norm_nonneg (o.rightAngleRotationAux₁ x)) with h h · rw [← h] positivity refine le_of_mul_le_mul_right ?_ h rw [← real_inner_self_eq_norm_mul_norm, o.inner_rightAngleRotationAux₁_left] exact o.areaForm_le x (o.rightAngleRotationAux₁ x) · let K : Submodule ℝ E := ℝ ∙ x have : Nontrivial Kᗮ := by apply @FiniteDimensional.nontrivial_of_finrank_pos ℝ have : finrank ℝ K ≤ Finset.card {x} := by rw [← Set.toFinset_singleton] exact finrank_span_le_card ({x} : Set E) have : Finset.card {x} = 1 := Finset.card_singleton x have : finrank ℝ K + finrank ℝ Kᗮ = finrank ℝ E := K.finrank_add_finrank_orthogonal have : finrank ℝ E = 2 := Fact.out linarith obtain ⟨w, hw₀⟩ : ∃ w : Kᗮ, w ≠ 0 := exists_ne 0 have hw' : ⟪x, (w : E)⟫ = 0 := Submodule.mem_orthogonal_singleton_iff_inner_right.mp w.2 have hw : (w : E) ≠ 0 := fun h => hw₀ (Submodule.coe_eq_zero.mp h) refine le_of_mul_le_mul_right ?_ (by rwa [norm_pos_iff] : 0 < ‖(w : E)‖) rw [← o.abs_areaForm_of_orthogonal hw'] rw [← o.inner_rightAngleRotationAux₁_left x w] exact abs_real_inner_le_norm (o.rightAngleRotationAux₁ x) w } #align orientation.right_angle_rotation_aux₂ Orientation.rightAngleRotationAux₂ @[simp] theorem rightAngleRotationAux₁_rightAngleRotationAux₁ (x : E) : o.rightAngleRotationAux₁ (o.rightAngleRotationAux₁ x) = -x := by apply ext_inner_left ℝ intro y have : ⟪o.rightAngleRotationAux₁ y, o.rightAngleRotationAux₁ x⟫ = ⟪y, x⟫ := LinearIsometry.inner_map_map o.rightAngleRotationAux₂ y x rw [o.inner_rightAngleRotationAux₁_right, ← o.inner_rightAngleRotationAux₁_left, this, inner_neg_right] #align orientation.right_angle_rotation_aux₁_right_angle_rotation_aux₁ Orientation.rightAngleRotationAux₁_rightAngleRotationAux₁ /-- An isometric automorphism of an oriented real inner product space of dimension 2 (usual notation `J`). This automorphism squares to -1. We will define rotations in such a way that this automorphism is equal to rotation by 90 degrees. -/ irreducible_def rightAngleRotation : E ≃ₗᵢ[ℝ] E := LinearIsometryEquiv.ofLinearIsometry o.rightAngleRotationAux₂ (-o.rightAngleRotationAux₁) (by ext; simp [rightAngleRotationAux₂]) (by ext; simp [rightAngleRotationAux₂]) #align orientation.right_angle_rotation Orientation.rightAngleRotation local notation "J" => o.rightAngleRotation @[simp] theorem inner_rightAngleRotation_left (x y : E) : ⟪J x, y⟫ = ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_left x y #align orientation.inner_right_angle_rotation_left Orientation.inner_rightAngleRotation_left @[simp] theorem inner_rightAngleRotation_right (x y : E) : ⟪x, J y⟫ = -ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_right x y #align orientation.inner_right_angle_rotation_right Orientation.inner_rightAngleRotation_right @[simp] theorem rightAngleRotation_rightAngleRotation (x : E) : J (J x) = -x := by rw [rightAngleRotation] exact o.rightAngleRotationAux₁_rightAngleRotationAux₁ x #align orientation.right_angle_rotation_right_angle_rotation Orientation.rightAngleRotation_rightAngleRotation @[simp] theorem rightAngleRotation_symm : LinearIsometryEquiv.symm J = LinearIsometryEquiv.trans J (LinearIsometryEquiv.neg ℝ) := by rw [rightAngleRotation] exact LinearIsometryEquiv.toLinearIsometry_injective rfl #align orientation.right_angle_rotation_symm Orientation.rightAngleRotation_symm -- @[simp] -- Porting note (#10618): simp already proves this theorem inner_rightAngleRotation_self (x : E) : ⟪J x, x⟫ = 0 := by simp #align orientation.inner_right_angle_rotation_self Orientation.inner_rightAngleRotation_self theorem inner_rightAngleRotation_swap (x y : E) : ⟪x, J y⟫ = -⟪J x, y⟫ := by simp #align orientation.inner_right_angle_rotation_swap Orientation.inner_rightAngleRotation_swap theorem inner_rightAngleRotation_swap' (x y : E) : ⟪J x, y⟫ = -⟪x, J y⟫ := by simp [o.inner_rightAngleRotation_swap x y] #align orientation.inner_right_angle_rotation_swap' Orientation.inner_rightAngleRotation_swap' theorem inner_comp_rightAngleRotation (x y : E) : ⟪J x, J y⟫ = ⟪x, y⟫ := LinearIsometryEquiv.inner_map_map J x y #align orientation.inner_comp_right_angle_rotation Orientation.inner_comp_rightAngleRotation @[simp] theorem areaForm_rightAngleRotation_left (x y : E) : ω (J x) y = -⟪x, y⟫ := by rw [← o.inner_comp_rightAngleRotation, o.inner_rightAngleRotation_right, neg_neg] #align orientation.area_form_right_angle_rotation_left Orientation.areaForm_rightAngleRotation_left @[simp] theorem areaForm_rightAngleRotation_right (x y : E) : ω x (J y) = ⟪x, y⟫ := by rw [← o.inner_rightAngleRotation_left, o.inner_comp_rightAngleRotation] #align orientation.area_form_right_angle_rotation_right Orientation.areaForm_rightAngleRotation_right -- @[simp] -- Porting note (#10618): simp already proves this theorem areaForm_comp_rightAngleRotation (x y : E) : ω (J x) (J y) = ω x y := by simp #align orientation.area_form_comp_right_angle_rotation Orientation.areaForm_comp_rightAngleRotation @[simp] theorem rightAngleRotation_trans_rightAngleRotation : LinearIsometryEquiv.trans J J = LinearIsometryEquiv.neg ℝ := by ext; simp #align orientation.right_angle_rotation_trans_right_angle_rotation Orientation.rightAngleRotation_trans_rightAngleRotation theorem rightAngleRotation_neg_orientation (x : E) : (-o).rightAngleRotation x = -o.rightAngleRotation x := by apply ext_inner_right ℝ intro y rw [inner_rightAngleRotation_left] simp #align orientation.right_angle_rotation_neg_orientation Orientation.rightAngleRotation_neg_orientation @[simp] theorem rightAngleRotation_trans_neg_orientation : (-o).rightAngleRotation = o.rightAngleRotation.trans (LinearIsometryEquiv.neg ℝ) := LinearIsometryEquiv.ext <| o.rightAngleRotation_neg_orientation #align orientation.right_angle_rotation_trans_neg_orientation Orientation.rightAngleRotation_trans_neg_orientation theorem rightAngleRotation_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation x = φ (o.rightAngleRotation (φ.symm x)) := by apply ext_inner_right ℝ intro y rw [inner_rightAngleRotation_left] trans ⟪J (φ.symm x), φ.symm y⟫ · simp [o.areaForm_map] trans ⟪φ (J (φ.symm x)), φ (φ.symm y)⟫ · rw [φ.inner_map_map] · simp #align orientation.right_angle_rotation_map Orientation.rightAngleRotation_map /-- `J` commutes with any positively-oriented isometric automorphism. -/ theorem linearIsometryEquiv_comp_rightAngleRotation (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x : E) : φ (J x) = J (φ x) := by convert (o.rightAngleRotation_map φ (φ x)).symm · simp · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] #align orientation.linear_isometry_equiv_comp_right_angle_rotation Orientation.linearIsometryEquiv_comp_rightAngleRotation theorem rightAngleRotation_map' {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation = (φ.symm.trans o.rightAngleRotation).trans φ := LinearIsometryEquiv.ext <| o.rightAngleRotation_map φ #align orientation.right_angle_rotation_map' Orientation.rightAngleRotation_map' /-- `J` commutes with any positively-oriented isometric automorphism. -/ theorem linearIsometryEquiv_comp_rightAngleRotation' (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) : LinearIsometryEquiv.trans J φ = φ.trans J := LinearIsometryEquiv.ext <| o.linearIsometryEquiv_comp_rightAngleRotation φ hφ #align orientation.linear_isometry_equiv_comp_right_angle_rotation' Orientation.linearIsometryEquiv_comp_rightAngleRotation' /-- For a nonzero vector `x` in an oriented two-dimensional real inner product space `E`, `![x, J x]` forms an (orthogonal) basis for `E`. -/ def basisRightAngleRotation (x : E) (hx : x ≠ 0) : Basis (Fin 2) ℝ E := @basisOfLinearIndependentOfCardEqFinrank ℝ _ _ _ _ _ _ _ ![x, J x] (linearIndependent_of_ne_zero_of_inner_eq_zero (fun i => by fin_cases i <;> simp [hx]) (by intro i j hij fin_cases i <;> fin_cases j <;> simp_all)) (@Fact.out (finrank ℝ E = 2)).symm #align orientation.basis_right_angle_rotation Orientation.basisRightAngleRotation @[simp] theorem coe_basisRightAngleRotation (x : E) (hx : x ≠ 0) : ⇑(o.basisRightAngleRotation x hx) = ![x, J x] := coe_basisOfLinearIndependentOfCardEqFinrank _ _ #align orientation.coe_basis_right_angle_rotation Orientation.coe_basisRightAngleRotation /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. (See `Orientation.inner_mul_inner_add_areaForm_mul_areaForm` for the "applied" form.)-/ theorem inner_mul_inner_add_areaForm_mul_areaForm' (a x : E) : ⟪a, x⟫ • innerₛₗ ℝ a + ω a x • ω a = ‖a‖ ^ 2 • innerₛₗ ℝ x := by by_cases ha : a = 0 · simp [ha] apply (o.basisRightAngleRotation a ha).ext intro i fin_cases i · simp only [Fin.mk_zero, coe_basisRightAngleRotation, Matrix.cons_val_zero, LinearMap.add_apply, LinearMap.smul_apply, innerₛₗ_apply, real_inner_self_eq_norm_sq, smul_eq_mul, areaForm_apply_self, mul_zero, add_zero, Real.rpow_two, real_inner_comm] ring · simp only [Fin.mk_one, coe_basisRightAngleRotation, Matrix.cons_val_one, Matrix.head_cons, LinearMap.add_apply, LinearMap.smul_apply, innerₛₗ_apply, inner_rightAngleRotation_right, areaForm_apply_self, neg_zero, smul_eq_mul, mul_zero, areaForm_rightAngleRotation_right, real_inner_self_eq_norm_sq, zero_add, Real.rpow_two, mul_neg] rw [o.areaForm_swap] ring #align orientation.inner_mul_inner_add_area_form_mul_area_form' Orientation.inner_mul_inner_add_areaForm_mul_areaForm' /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. -/ theorem inner_mul_inner_add_areaForm_mul_areaForm (a x y : E) : ⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫ := congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_inner_add_areaForm_mul_areaForm' a x) #align orientation.inner_mul_inner_add_area_form_mul_area_form Orientation.inner_mul_inner_add_areaForm_mul_areaForm theorem inner_sq_add_areaForm_sq (a b : E) : ⟪a, b⟫ ^ 2 + ω a b ^ 2 = ‖a‖ ^ 2 * ‖b‖ ^ 2 := by simpa [sq, real_inner_self_eq_norm_sq] using o.inner_mul_inner_add_areaForm_mul_areaForm a b b #align orientation.inner_sq_add_area_form_sq Orientation.inner_sq_add_areaForm_sq /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. (See `Orientation.inner_mul_areaForm_sub` for the "applied" form.) -/ theorem inner_mul_areaForm_sub' (a x : E) : ⟪a, x⟫ • ω a - ω a x • innerₛₗ ℝ a = ‖a‖ ^ 2 • ω x := by by_cases ha : a = 0 · simp [ha] apply (o.basisRightAngleRotation a ha).ext intro i fin_cases i · simp only [o.areaForm_swap a x, neg_smul, sub_neg_eq_add, Fin.mk_zero, coe_basisRightAngleRotation, Matrix.cons_val_zero, LinearMap.add_apply, LinearMap.smul_apply, areaForm_apply_self, smul_eq_mul, mul_zero, innerₛₗ_apply, real_inner_self_eq_norm_sq, zero_add, Real.rpow_two] ring · simp only [Fin.mk_one, coe_basisRightAngleRotation, Matrix.cons_val_one, Matrix.head_cons, LinearMap.sub_apply, LinearMap.smul_apply, areaForm_rightAngleRotation_right, real_inner_self_eq_norm_sq, smul_eq_mul, innerₛₗ_apply, inner_rightAngleRotation_right, areaForm_apply_self, neg_zero, mul_zero, sub_zero, Real.rpow_two, real_inner_comm] ring #align orientation.inner_mul_area_form_sub' Orientation.inner_mul_areaForm_sub' /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. -/ theorem inner_mul_areaForm_sub (a x y : E) : ⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y := congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_areaForm_sub' a x) #align orientation.inner_mul_area_form_sub Orientation.inner_mul_areaForm_sub theorem nonneg_inner_and_areaForm_eq_zero_iff_sameRay (x y : E) : 0 ≤ ⟪x, y⟫ ∧ ω x y = 0 ↔ SameRay ℝ x y := by by_cases hx : x = 0 · simp [hx] constructor · let a : ℝ := (o.basisRightAngleRotation x hx).repr y 0 let b : ℝ := (o.basisRightAngleRotation x hx).repr y 1 suffices ↑0 ≤ a * ‖x‖ ^ 2 ∧ b * ‖x‖ ^ 2 = 0 → SameRay ℝ x (a • x + b • J x) by rw [← (o.basisRightAngleRotation x hx).sum_repr y] simp only [Fin.sum_univ_succ, coe_basisRightAngleRotation, Matrix.cons_val_zero, Fin.succ_zero_eq_one', Finset.univ_eq_empty, Finset.sum_empty, areaForm_apply_self, map_smul, map_add, real_inner_smul_right, inner_add_right, Matrix.cons_val_one, Matrix.head_cons, Algebra.id.smul_eq_mul, areaForm_rightAngleRotation_right, mul_zero, add_zero, zero_add, neg_zero, inner_rightAngleRotation_right, real_inner_self_eq_norm_sq, zero_smul, one_smul] exact this rintro ⟨ha, hb⟩ have hx' : 0 < ‖x‖ := by simpa using hx have ha' : 0 ≤ a := nonneg_of_mul_nonneg_left ha (by positivity) have hb' : b = 0 := eq_zero_of_ne_zero_of_mul_right_eq_zero (pow_ne_zero 2 hx'.ne') hb exact (SameRay.sameRay_nonneg_smul_right x ha').add_right $ by simp [hb'] · intro h obtain ⟨r, hr, rfl⟩ := h.exists_nonneg_left hx simp only [inner_smul_right, real_inner_self_eq_norm_sq, LinearMap.map_smulₛₗ, areaForm_apply_self, Algebra.id.smul_eq_mul, mul_zero, eq_self_iff_true, and_true_iff] positivity #align orientation.nonneg_inner_and_area_form_eq_zero_iff_same_ray Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay /-- A complex-valued real-bilinear map on an oriented real inner product space of dimension 2. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. On `ℂ` with the standard orientation, `kahler w z = conj w * z`; see `Complex.kahler`. -/ def kahler : E →ₗ[ℝ] E →ₗ[ℝ] ℂ := LinearMap.llcomp ℝ E ℝ ℂ Complex.ofRealCLM ∘ₗ innerₛₗ ℝ + LinearMap.llcomp ℝ E ℝ ℂ ((LinearMap.lsmul ℝ ℂ).flip Complex.I) ∘ₗ ω #align orientation.kahler Orientation.kahler theorem kahler_apply_apply (x y : E) : o.kahler x y = ⟪x, y⟫ + ω x y • Complex.I := rfl #align orientation.kahler_apply_apply Orientation.kahler_apply_apply theorem kahler_swap (x y : E) : o.kahler x y = conj (o.kahler y x) := by have : ∀ r : ℝ, Complex.ofReal' r = @RCLike.ofReal ℂ _ r := fun r => rfl simp only [kahler_apply_apply] rw [real_inner_comm, areaForm_swap] simp [this] #align orientation.kahler_swap Orientation.kahler_swap @[simp] theorem kahler_apply_self (x : E) : o.kahler x x = ‖x‖ ^ 2 := by simp [kahler_apply_apply, real_inner_self_eq_norm_sq] #align orientation.kahler_apply_self Orientation.kahler_apply_self @[simp] theorem kahler_rightAngleRotation_left (x y : E) : o.kahler (J x) y = -Complex.I * o.kahler x y := by simp only [o.areaForm_rightAngleRotation_left, o.inner_rightAngleRotation_left, o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul] linear_combination ω x y * Complex.I_sq #align orientation.kahler_right_angle_rotation_left Orientation.kahler_rightAngleRotation_left @[simp] theorem kahler_rightAngleRotation_right (x y : E) : o.kahler x (J y) = Complex.I * o.kahler x y := by simp only [o.areaForm_rightAngleRotation_right, o.inner_rightAngleRotation_right, o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul] linear_combination -ω x y * Complex.I_sq #align orientation.kahler_right_angle_rotation_right Orientation.kahler_rightAngleRotation_right -- @[simp] -- Porting note: simp normal form is `kahler_comp_rightAngleRotation'` theorem kahler_comp_rightAngleRotation (x y : E) : o.kahler (J x) (J y) = o.kahler x y := by simp only [kahler_rightAngleRotation_left, kahler_rightAngleRotation_right] linear_combination -o.kahler x y * Complex.I_sq #align orientation.kahler_comp_right_angle_rotation Orientation.kahler_comp_rightAngleRotation theorem kahler_comp_rightAngleRotation' (x y : E) : -(Complex.I * (Complex.I * o.kahler x y)) = o.kahler x y := by linear_combination -o.kahler x y * Complex.I_sq @[simp] theorem kahler_neg_orientation (x y : E) : (-o).kahler x y = conj (o.kahler x y) := by have : ∀ r : ℝ, Complex.ofReal' r = @RCLike.ofReal ℂ _ r := fun r => rfl simp [kahler_apply_apply, this] #align orientation.kahler_neg_orientation Orientation.kahler_neg_orientation theorem kahler_mul (a x y : E) : o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y := by trans ((‖a‖ ^ 2 :) : ℂ) * o.kahler x y · apply Complex.ext · simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re, Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul] rw [real_inner_comm a x, o.areaForm_swap x a] linear_combination o.inner_mul_inner_add_areaForm_mul_areaForm a x y · simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re, Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul] rw [real_inner_comm a x, o.areaForm_swap x a] linear_combination o.inner_mul_areaForm_sub a x y · norm_cast #align orientation.kahler_mul Orientation.kahler_mul theorem normSq_kahler (x y : E) : Complex.normSq (o.kahler x y) = ‖x‖ ^ 2 * ‖y‖ ^ 2 := by simpa [kahler_apply_apply, Complex.normSq, sq] using o.inner_sq_add_areaForm_sq x y #align orientation.norm_sq_kahler Orientation.normSq_kahler theorem abs_kahler (x y : E) : Complex.abs (o.kahler x y) = ‖x‖ * ‖y‖ := by rw [← sq_eq_sq, Complex.sq_abs] · linear_combination o.normSq_kahler x y · positivity · positivity #align orientation.abs_kahler Orientation.abs_kahler theorem norm_kahler (x y : E) : ‖o.kahler x y‖ = ‖x‖ * ‖y‖ := by simpa using o.abs_kahler x y #align orientation.norm_kahler Orientation.norm_kahler theorem eq_zero_or_eq_zero_of_kahler_eq_zero {x y : E} (hx : o.kahler x y = 0) : x = 0 ∨ y = 0 := by have : ‖x‖ * ‖y‖ = 0 := by simpa [hx] using (o.norm_kahler x y).symm cases' eq_zero_or_eq_zero_of_mul_eq_zero this with h h · left simpa using h · right simpa using h #align orientation.eq_zero_or_eq_zero_of_kahler_eq_zero Orientation.eq_zero_or_eq_zero_of_kahler_eq_zero
Mathlib/Analysis/InnerProductSpace/TwoDim.lean
568
570
theorem kahler_eq_zero_iff (x y : E) : o.kahler x y = 0 ↔ x = 0 ∨ y = 0 := by
refine ⟨o.eq_zero_or_eq_zero_of_kahler_eq_zero, ?_⟩ rintro (rfl | rfl) <;> simp
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Kernel.MeasurableIntegral #align_import probability.kernel.composition from "leanprover-community/mathlib"@"3b92d54a05ee592aa2c6181a4e76b1bb7cc45d0b" /-! # Product and composition of kernels We define * the composition-product `κ ⊗ₖ η` of two s-finite kernels `κ : kernel α β` and `η : kernel (α × β) γ`, a kernel from `α` to `β × γ`. * the map and comap of a kernel along a measurable function. * the composition `η ∘ₖ κ` of kernels `κ : kernel α β` and `η : kernel β γ`, kernel from `α` to `γ`. * the product `κ ×ₖ η` of s-finite kernels `κ : kernel α β` and `η : kernel α γ`, a kernel from `α` to `β × γ`. A note on names: The composition-product `kernel α β → kernel (α × β) γ → kernel α (β × γ)` is named composition in [kallenberg2021] and product on the wikipedia article on transition kernels. Most papers studying categories of kernels call composition the map we call composition. We adopt that convention because it fits better with the use of the name `comp` elsewhere in mathlib. ## Main definitions Kernels built from other kernels: * `compProd (κ : kernel α β) (η : kernel (α × β) γ) : kernel α (β × γ)`: composition-product of 2 s-finite kernels. We define a notation `κ ⊗ₖ η = compProd κ η`. `∫⁻ bc, f bc ∂((κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)` * `map (κ : kernel α β) (f : β → γ) (hf : Measurable f) : kernel α γ` `∫⁻ c, g c ∂(map κ f hf a) = ∫⁻ b, g (f b) ∂(κ a)` * `comap (κ : kernel α β) (f : γ → α) (hf : Measurable f) : kernel γ β` `∫⁻ b, g b ∂(comap κ f hf c) = ∫⁻ b, g b ∂(κ (f c))` * `comp (η : kernel β γ) (κ : kernel α β) : kernel α γ`: composition of 2 kernels. We define a notation `η ∘ₖ κ = comp η κ`. `∫⁻ c, g c ∂((η ∘ₖ κ) a) = ∫⁻ b, ∫⁻ c, g c ∂(η b) ∂(κ a)` * `prod (κ : kernel α β) (η : kernel α γ) : kernel α (β × γ)`: product of 2 s-finite kernels. `∫⁻ bc, f bc ∂((κ ×ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η a) ∂(κ a)` ## Main statements * `lintegral_compProd`, `lintegral_map`, `lintegral_comap`, `lintegral_comp`, `lintegral_prod`: Lebesgue integral of a function against a composition-product/map/comap/composition/product of kernels. * Instances of the form `<class>.<operation>` where class is one of `IsMarkovKernel`, `IsFiniteKernel`, `IsSFiniteKernel` and operation is one of `compProd`, `map`, `comap`, `comp`, `prod`. These instances state that the three classes are stable by the various operations. ## Notations * `κ ⊗ₖ η = ProbabilityTheory.kernel.compProd κ η` * `η ∘ₖ κ = ProbabilityTheory.kernel.comp η κ` * `κ ×ₖ η = ProbabilityTheory.kernel.prod κ η` -/ open MeasureTheory open scoped ENNReal namespace ProbabilityTheory namespace kernel variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} section CompositionProduct /-! ### Composition-Product of kernels We define a kernel composition-product `compProd : kernel α β → kernel (α × β) γ → kernel α (β × γ)`. -/ variable {γ : Type*} {mγ : MeasurableSpace γ} {s : Set (β × γ)} /-- Auxiliary function for the definition of the composition-product of two kernels. For all `a : α`, `compProdFun κ η a` is a countably additive function with value zero on the empty set, and the composition-product of kernels is defined in `kernel.compProd` through `Measure.ofMeasurable`. -/ noncomputable def compProdFun (κ : kernel α β) (η : kernel (α × β) γ) (a : α) (s : Set (β × γ)) : ℝ≥0∞ := ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a #align probability_theory.kernel.comp_prod_fun ProbabilityTheory.kernel.compProdFun theorem compProdFun_empty (κ : kernel α β) (η : kernel (α × β) γ) (a : α) : compProdFun κ η a ∅ = 0 := by simp only [compProdFun, Set.mem_empty_iff_false, Set.setOf_false, measure_empty, MeasureTheory.lintegral_const, zero_mul] #align probability_theory.kernel.comp_prod_fun_empty ProbabilityTheory.kernel.compProdFun_empty theorem compProdFun_iUnion (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (f : ℕ → Set (β × γ)) (hf_meas : ∀ i, MeasurableSet (f i)) (hf_disj : Pairwise (Disjoint on f)) : compProdFun κ η a (⋃ i, f i) = ∑' i, compProdFun κ η a (f i) := by have h_Union : (fun b => η (a, b) {c : γ | (b, c) ∈ ⋃ i, f i}) = fun b => η (a, b) (⋃ i, {c : γ | (b, c) ∈ f i}) := by ext1 b congr with c simp only [Set.mem_iUnion, Set.iSup_eq_iUnion, Set.mem_setOf_eq] rw [compProdFun, h_Union] have h_tsum : (fun b => η (a, b) (⋃ i, {c : γ | (b, c) ∈ f i})) = fun b => ∑' i, η (a, b) {c : γ | (b, c) ∈ f i} := by ext1 b rw [measure_iUnion] · intro i j hij s hsi hsj c hcs have hbci : {(b, c)} ⊆ f i := by rw [Set.singleton_subset_iff]; exact hsi hcs have hbcj : {(b, c)} ⊆ f j := by rw [Set.singleton_subset_iff]; exact hsj hcs simpa only [Set.bot_eq_empty, Set.le_eq_subset, Set.singleton_subset_iff, Set.mem_empty_iff_false] using hf_disj hij hbci hbcj · -- Porting note: behavior of `@` changed relative to lean 3, was -- exact fun i => (@measurable_prod_mk_left β γ _ _ b) _ (hf_meas i) exact fun i => (@measurable_prod_mk_left β γ _ _ b) (hf_meas i) rw [h_tsum, lintegral_tsum] · rfl · intro i have hm : MeasurableSet {p : (α × β) × γ | (p.1.2, p.2) ∈ f i} := measurable_fst.snd.prod_mk measurable_snd (hf_meas i) exact ((measurable_kernel_prod_mk_left hm).comp measurable_prod_mk_left).aemeasurable #align probability_theory.kernel.comp_prod_fun_Union ProbabilityTheory.kernel.compProdFun_iUnion theorem compProdFun_tsum_right (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : compProdFun κ η a s = ∑' n, compProdFun κ (seq η n) a s := by simp_rw [compProdFun, (measure_sum_seq η _).symm] have : ∫⁻ b, Measure.sum (fun n => seq η n (a, b)) {c : γ | (b, c) ∈ s} ∂κ a = ∫⁻ b, ∑' n, seq η n (a, b) {c : γ | (b, c) ∈ s} ∂κ a := by congr ext1 b rw [Measure.sum_apply] exact measurable_prod_mk_left hs rw [this, lintegral_tsum] exact fun n => ((measurable_kernel_prod_mk_left (κ := (seq η n)) ((measurable_fst.snd.prod_mk measurable_snd) hs)).comp measurable_prod_mk_left).aemeasurable #align probability_theory.kernel.comp_prod_fun_tsum_right ProbabilityTheory.kernel.compProdFun_tsum_right theorem compProdFun_tsum_left (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel κ] (a : α) (s : Set (β × γ)) : compProdFun κ η a s = ∑' n, compProdFun (seq κ n) η a s := by simp_rw [compProdFun, (measure_sum_seq κ _).symm, lintegral_sum_measure] #align probability_theory.kernel.comp_prod_fun_tsum_left ProbabilityTheory.kernel.compProdFun_tsum_left theorem compProdFun_eq_tsum (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : compProdFun κ η a s = ∑' (n) (m), compProdFun (seq κ n) (seq η m) a s := by simp_rw [compProdFun_tsum_left κ η a s, compProdFun_tsum_right _ η a hs] #align probability_theory.kernel.comp_prod_fun_eq_tsum ProbabilityTheory.kernel.compProdFun_eq_tsum /-- Auxiliary lemma for `measurable_compProdFun`. -/ theorem measurable_compProdFun_of_finite (κ : kernel α β) [IsFiniteKernel κ] (η : kernel (α × β) γ) [IsFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s := by simp only [compProdFun] have h_meas : Measurable (Function.uncurry fun a b => η (a, b) {c : γ | (b, c) ∈ s}) := by have : (Function.uncurry fun a b => η (a, b) {c : γ | (b, c) ∈ s}) = fun p => η p {c : γ | (p.2, c) ∈ s} := by ext1 p rw [Function.uncurry_apply_pair] rw [this] exact measurable_kernel_prod_mk_left (measurable_fst.snd.prod_mk measurable_snd hs) exact h_meas.lintegral_kernel_prod_right #align probability_theory.kernel.measurable_comp_prod_fun_of_finite ProbabilityTheory.kernel.measurable_compProdFun_of_finite theorem measurable_compProdFun (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s := by simp_rw [compProdFun_tsum_right κ η _ hs] refine Measurable.ennreal_tsum fun n => ?_ simp only [compProdFun] have h_meas : Measurable (Function.uncurry fun a b => seq η n (a, b) {c : γ | (b, c) ∈ s}) := by have : (Function.uncurry fun a b => seq η n (a, b) {c : γ | (b, c) ∈ s}) = fun p => seq η n p {c : γ | (p.2, c) ∈ s} := by ext1 p rw [Function.uncurry_apply_pair] rw [this] exact measurable_kernel_prod_mk_left (measurable_fst.snd.prod_mk measurable_snd hs) exact h_meas.lintegral_kernel_prod_right #align probability_theory.kernel.measurable_comp_prod_fun ProbabilityTheory.kernel.measurable_compProdFun open scoped Classical /-- Composition-Product of kernels. For s-finite kernels, it satisfies `∫⁻ bc, f bc ∂(compProd κ η a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)` (see `ProbabilityTheory.kernel.lintegral_compProd`). If either of the kernels is not s-finite, `compProd` is given the junk value 0. -/ noncomputable def compProd (κ : kernel α β) (η : kernel (α × β) γ) : kernel α (β × γ) := if h : IsSFiniteKernel κ ∧ IsSFiniteKernel η then { val := fun a ↦ Measure.ofMeasurable (fun s _ => compProdFun κ η a s) (compProdFun_empty κ η a) (@compProdFun_iUnion _ _ _ _ _ _ κ η h.2 a) property := by have : IsSFiniteKernel κ := h.1 have : IsSFiniteKernel η := h.2 refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ have : (fun a => Measure.ofMeasurable (fun s _ => compProdFun κ η a s) (compProdFun_empty κ η a) (compProdFun_iUnion κ η a) s) = fun a => compProdFun κ η a s := by ext1 a; rwa [Measure.ofMeasurable_apply] rw [this] exact measurable_compProdFun κ η hs } else 0 #align probability_theory.kernel.comp_prod ProbabilityTheory.kernel.compProd scoped[ProbabilityTheory] infixl:100 " ⊗ₖ " => ProbabilityTheory.kernel.compProd theorem compProd_apply_eq_compProdFun (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = compProdFun κ η a s := by rw [compProd, dif_pos] swap · constructor <;> infer_instance change Measure.ofMeasurable (fun s _ => compProdFun κ η a s) (compProdFun_empty κ η a) (compProdFun_iUnion κ η a) s = ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a rw [Measure.ofMeasurable_apply _ hs] rfl #align probability_theory.kernel.comp_prod_apply_eq_comp_prod_fun ProbabilityTheory.kernel.compProd_apply_eq_compProdFun
Mathlib/Probability/Kernel/Composition.lean
230
234
theorem compProd_of_not_isSFiniteKernel_left (κ : kernel α β) (η : kernel (α × β) γ) (h : ¬ IsSFiniteKernel κ) : κ ⊗ₖ η = 0 := by
rw [compProd, dif_neg] simp [h]
/- 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 -/ import Mathlib.Analysis.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.HahnBanach.Separation import Mathlib.LinearAlgebra.Dual import Mathlib.Analysis.NormedSpace.BoundedLinearMaps /-! # Spaces with separating dual We introduce a typeclass `SeparatingDual R V`, registering that the points of the topological module `V` over `R` can be separated by continuous linear forms. This property is satisfied for normed spaces over `ℝ` or `ℂ` (by the analytic Hahn-Banach theorem) and for locally convex topological spaces over `ℝ` (by the geometric Hahn-Banach theorem). Under the assumption `SeparatingDual R V`, we show in `SeparatingDual.exists_continuousLinearMap_apply_eq` that the group of continuous linear equivalences acts transitively on the set of nonzero vectors. -/ /-- When `E` is a topological module over a topological ring `R`, the class `SeparatingDual R E` registers that continuous linear forms on `E` separate points of `E`. -/ @[mk_iff separatingDual_def] class SeparatingDual (R V : Type*) [Ring R] [AddCommGroup V] [TopologicalSpace V] [TopologicalSpace R] [Module R V] : Prop := /-- Any nonzero vector can be mapped by a continuous linear map to a nonzero scalar. -/ exists_ne_zero' : ∀ (x : V), x ≠ 0 → ∃ f : V →L[R] R, f x ≠ 0 instance {E : Type*} [TopologicalSpace E] [AddCommGroup E] [TopologicalAddGroup E] [Module ℝ E] [ContinuousSMul ℝ E] [LocallyConvexSpace ℝ E] [T1Space E] : SeparatingDual ℝ E := ⟨fun x hx ↦ by rcases geometric_hahn_banach_point_point hx.symm with ⟨f, hf⟩ simp only [map_zero] at hf exact ⟨f, hf.ne'⟩⟩ instance {E 𝕜 : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] : SeparatingDual 𝕜 E := ⟨fun x hx ↦ by rcases exists_dual_vector 𝕜 x hx with ⟨f, -, hf⟩ refine ⟨f, ?_⟩ simpa [hf] using hx⟩ namespace SeparatingDual section Ring variable {R V : Type*} [Ring R] [AddCommGroup V] [TopologicalSpace V] [TopologicalSpace R] [Module R V] [SeparatingDual R V] lemma exists_ne_zero {x : V} (hx : x ≠ 0) : ∃ f : V →L[R] R, f x ≠ 0 := exists_ne_zero' x hx theorem exists_separating_of_ne {x y : V} (h : x ≠ y) : ∃ f : V →L[R] R, f x ≠ f y := by rcases exists_ne_zero (R := R) (sub_ne_zero_of_ne h) with ⟨f, hf⟩ exact ⟨f, by simpa [sub_ne_zero] using hf⟩ protected theorem t1Space [T1Space R] : T1Space V := by apply t1Space_iff_exists_open.2 (fun x y hxy ↦ ?_) rcases exists_separating_of_ne (R := R) hxy with ⟨f, hf⟩ exact ⟨f ⁻¹' {f y}ᶜ, isOpen_compl_singleton.preimage f.continuous, hf, by simp⟩ protected theorem t2Space [T2Space R] : T2Space V := by apply (t2Space_iff _).2 (fun {x} {y} hxy ↦ ?_) rcases exists_separating_of_ne (R := R) hxy with ⟨f, hf⟩ exact separated_by_continuous f.continuous hf end Ring section Field variable {R V : Type*} [Field R] [AddCommGroup V] [TopologicalSpace R] [TopologicalSpace V] [TopologicalRing R] [TopologicalAddGroup V] [Module R V] [SeparatingDual R V] -- TODO (@alreadydone): this could generalize to CommRing R if we were to add a section theorem _root_.separatingDual_iff_injective : SeparatingDual R V ↔ Function.Injective (ContinuousLinearMap.coeLM (R := R) R (M := V) (N₃ := R)).flip := by simp_rw [separatingDual_def, Ne, injective_iff_map_eq_zero] congrm ∀ v, ?_ rw [not_imp_comm, LinearMap.ext_iff] push_neg; rfl open Function in /-- Given a finite-dimensional subspace `W` of a space `V` with separating dual, any linear functional on `W` extends to a continuous linear functional on `V`. This is stated more generally for an injective linear map from `W` to `V`. -/ theorem dualMap_surjective_iff {W} [AddCommGroup W] [Module R W] [FiniteDimensional R W] {f : W →ₗ[R] V} : Surjective (f.dualMap ∘ ContinuousLinearMap.toLinearMap) ↔ Injective f := by constructor <;> intro hf · exact LinearMap.dualMap_surjective_iff.mp hf.of_comp have := (separatingDual_iff_injective.mp ‹_›).comp hf rw [← LinearMap.coe_comp] at this exact LinearMap.flip_surjective_iff₁.mpr this lemma exists_eq_one {x : V} (hx : x ≠ 0) : ∃ f : V →L[R] R, f x = 1 := by rcases exists_ne_zero (R := R) hx with ⟨f, hf⟩ exact ⟨(f x)⁻¹ • f, inv_mul_cancel hf⟩ theorem exists_eq_one_ne_zero_of_ne_zero_pair {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ∃ f : V →L[R] R, f x = 1 ∧ f y ≠ 0 := by obtain ⟨u, ux⟩ : ∃ u : V →L[R] R, u x = 1 := exists_eq_one hx rcases ne_or_eq (u y) 0 with uy|uy · exact ⟨u, ux, uy⟩ obtain ⟨v, vy⟩ : ∃ v : V →L[R] R, v y = 1 := exists_eq_one hy rcases ne_or_eq (v x) 0 with vx|vx · exact ⟨(v x)⁻¹ • v, inv_mul_cancel vx, show (v x)⁻¹ * v y ≠ 0 by simp [vx, vy]⟩ · exact ⟨u + v, by simp [ux, vx], by simp [uy, vy]⟩ /-- In a topological vector space with separating dual, the group of continuous linear equivalences acts transitively on the set of nonzero vectors: given two nonzero vectors `x` and `y`, there exists `A : V ≃L[R] V` mapping `x` to `y`. -/
Mathlib/Analysis/NormedSpace/HahnBanach/SeparatingDual.lean
117
144
theorem exists_continuousLinearEquiv_apply_eq [ContinuousSMul R V] {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : ∃ A : V ≃L[R] V, A x = y := by
obtain ⟨G, Gx, Gy⟩ : ∃ G : V →L[R] R, G x = 1 ∧ G y ≠ 0 := exists_eq_one_ne_zero_of_ne_zero_pair hx hy let A : V ≃L[R] V := { toFun := fun z ↦ z + G z • (y - x) invFun := fun z ↦ z + ((G y) ⁻¹ * G z) • (x - y) map_add' := fun a b ↦ by simp [add_smul]; abel map_smul' := by simp [smul_smul] left_inv := fun z ↦ by simp only [id_eq, eq_mpr_eq_cast, RingHom.id_apply, smul_eq_mul, AddHom.toFun_eq_coe, -- Note: #8386 had to change `map_smulₛₗ` into `map_smulₛₗ _` AddHom.coe_mk, map_add, map_smulₛₗ _, map_sub, Gx, mul_sub, mul_one, add_sub_cancel] rw [mul_comm (G z), ← mul_assoc, inv_mul_cancel Gy] simp only [smul_sub, one_mul] abel right_inv := fun z ↦ by -- Note: #8386 had to change `map_smulₛₗ` into `map_smulₛₗ _` simp only [map_add, map_smulₛₗ _, map_mul, map_inv₀, RingHom.id_apply, map_sub, Gx, smul_eq_mul, mul_sub, mul_one] rw [mul_comm _ (G y), ← mul_assoc, mul_inv_cancel Gy] simp only [smul_sub, one_mul, add_sub_cancel] abel continuous_toFun := continuous_id.add (G.continuous.smul continuous_const) continuous_invFun := continuous_id.add ((continuous_const.mul G.continuous).smul continuous_const) } exact ⟨A, show x + G x • (y - x) = y by simp [Gx]⟩
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.List.Infix #align_import data.list.rdrop from "leanprover-community/mathlib"@"26f081a2fb920140ed5bc5cc5344e84bcc7cb2b2" /-! # Dropping or taking from lists on the right Taking or removing element from the tail end of a list ## Main definitions - `rdrop n`: drop `n : ℕ` elements from the tail - `rtake n`: take `n : ℕ` elements from the tail - `rdropWhile p`: remove all the elements from the tail of a list until it finds the first element for which `p : α → Bool` returns false. This element and everything before is returned. - `rtakeWhile p`: Returns the longest terminal segment of a list for which `p : α → Bool` returns true. ## Implementation detail The two predicate-based methods operate by performing the regular "from-left" operation on `List.reverse`, followed by another `List.reverse`, so they are not the most performant. The other two rely on `List.length l` so they still traverse the list twice. One could construct another function that takes a `L : ℕ` and use `L - n`. Under a proof condition that `L = l.length`, the function would do the right thing. -/ -- Make sure we don't import algebra assert_not_exists Monoid variable {α : Type*} (p : α → Bool) (l : List α) (n : ℕ) namespace List /-- Drop `n` elements from the tail end of a list. -/ def rdrop : List α := l.take (l.length - n) #align list.rdrop List.rdrop @[simp] theorem rdrop_nil : rdrop ([] : List α) n = [] := by simp [rdrop] #align list.rdrop_nil List.rdrop_nil @[simp] theorem rdrop_zero : rdrop l 0 = l := by simp [rdrop] #align list.rdrop_zero List.rdrop_zero theorem rdrop_eq_reverse_drop_reverse : l.rdrop n = reverse (l.reverse.drop n) := by rw [rdrop] induction' l using List.reverseRecOn with xs x IH generalizing n · simp · cases n · simp [take_append] · simp [take_append_eq_append_take, IH] #align list.rdrop_eq_reverse_drop_reverse List.rdrop_eq_reverse_drop_reverse @[simp] theorem rdrop_concat_succ (x : α) : rdrop (l ++ [x]) (n + 1) = rdrop l n := by simp [rdrop_eq_reverse_drop_reverse] #align list.rdrop_concat_succ List.rdrop_concat_succ /-- Take `n` elements from the tail end of a list. -/ def rtake : List α := l.drop (l.length - n) #align list.rtake List.rtake @[simp] theorem rtake_nil : rtake ([] : List α) n = [] := by simp [rtake] #align list.rtake_nil List.rtake_nil @[simp] theorem rtake_zero : rtake l 0 = [] := by simp [rtake] #align list.rtake_zero List.rtake_zero theorem rtake_eq_reverse_take_reverse : l.rtake n = reverse (l.reverse.take n) := by rw [rtake] induction' l using List.reverseRecOn with xs x IH generalizing n · simp · cases n · exact drop_length _ · simp [drop_append_eq_append_drop, IH] #align list.rtake_eq_reverse_take_reverse List.rtake_eq_reverse_take_reverse @[simp] theorem rtake_concat_succ (x : α) : rtake (l ++ [x]) (n + 1) = rtake l n ++ [x] := by simp [rtake_eq_reverse_take_reverse] #align list.rtake_concat_succ List.rtake_concat_succ /-- Drop elements from the tail end of a list that satisfy `p : α → Bool`. Implemented naively via `List.reverse` -/ def rdropWhile : List α := reverse (l.reverse.dropWhile p) #align list.rdrop_while List.rdropWhile @[simp] theorem rdropWhile_nil : rdropWhile p ([] : List α) = [] := by simp [rdropWhile, dropWhile] #align list.rdrop_while_nil List.rdropWhile_nil theorem rdropWhile_concat (x : α) : rdropWhile p (l ++ [x]) = if p x then rdropWhile p l else l ++ [x] := by simp only [rdropWhile, dropWhile, reverse_append, reverse_singleton, singleton_append] split_ifs with h <;> simp [h] #align list.rdrop_while_concat List.rdropWhile_concat @[simp] theorem rdropWhile_concat_pos (x : α) (h : p x) : rdropWhile p (l ++ [x]) = rdropWhile p l := by rw [rdropWhile_concat, if_pos h] #align list.rdrop_while_concat_pos List.rdropWhile_concat_pos @[simp] theorem rdropWhile_concat_neg (x : α) (h : ¬p x) : rdropWhile p (l ++ [x]) = l ++ [x] := by rw [rdropWhile_concat, if_neg h] #align list.rdrop_while_concat_neg List.rdropWhile_concat_neg theorem rdropWhile_singleton (x : α) : rdropWhile p [x] = if p x then [] else [x] := by rw [← nil_append [x], rdropWhile_concat, rdropWhile_nil] #align list.rdrop_while_singleton List.rdropWhile_singleton theorem rdropWhile_last_not (hl : l.rdropWhile p ≠ []) : ¬p ((rdropWhile p l).getLast hl) := by simp_rw [rdropWhile] rw [getLast_reverse] exact dropWhile_nthLe_zero_not _ _ _ #align list.rdrop_while_last_not List.rdropWhile_last_not theorem rdropWhile_prefix : l.rdropWhile p <+: l := by rw [← reverse_suffix, rdropWhile, reverse_reverse] exact dropWhile_suffix _ #align list.rdrop_while_prefix List.rdropWhile_prefix variable {p} {l} @[simp] theorem rdropWhile_eq_nil_iff : rdropWhile p l = [] ↔ ∀ x ∈ l, p x := by simp [rdropWhile] #align list.rdrop_while_eq_nil_iff List.rdropWhile_eq_nil_iff -- it is in this file because it requires `List.Infix` @[simp] theorem dropWhile_eq_self_iff : dropWhile p l = l ↔ ∀ hl : 0 < l.length, ¬p (l.get ⟨0, hl⟩) := by cases' l with hd tl · simp only [dropWhile, true_iff] intro h by_contra rwa [length_nil, lt_self_iff_false] at h · rw [dropWhile] refine ⟨fun h => ?_, fun h => ?_⟩ · intro _ H rw [get] at H refine (cons_ne_self hd tl) (Sublist.antisymm ?_ (sublist_cons _ _)) rw [← h] simp only [H] exact List.IsSuffix.sublist (dropWhile_suffix p) · have := h (by simp only [length, Nat.succ_pos]) rw [get] at this simp_rw [this] #align list.drop_while_eq_self_iff List.dropWhile_eq_self_iff /- porting note: This proof is longer than it used to be because `simp` refuses to rewrite the `l ≠ []` condition if `hl` is not `intro`'d yet -/ @[simp] theorem rdropWhile_eq_self_iff : rdropWhile p l = l ↔ ∀ hl : l ≠ [], ¬p (l.getLast hl) := by simp only [rdropWhile, reverse_eq_iff, dropWhile_eq_self_iff, getLast_eq_get] refine ⟨fun h hl => ?_, fun h hl => ?_⟩ · rw [← length_pos, ← length_reverse] at hl have := h hl rwa [get_reverse'] at this · rw [length_reverse, length_pos] at hl have := h hl rwa [get_reverse'] #align list.rdrop_while_eq_self_iff List.rdropWhile_eq_self_iff variable (p) (l)
Mathlib/Data/List/DropRight.lean
179
181
theorem dropWhile_idempotent : dropWhile p (dropWhile p l) = dropWhile p l := by
simp only [dropWhile_eq_self_iff] exact fun h => dropWhile_nthLe_zero_not p l h
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.Order.Sub.WithTop import Mathlib.Data.Real.NNReal import Mathlib.Order.Interval.Set.WithBotTop #align_import data.real.ennreal from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Extended non-negative reals We define `ENNReal = ℝ≥0∞ := WithTop ℝ≥0` to be the type of extended nonnegative real numbers, i.e., the interval `[0, +∞]`. This type is used as the codomain of a `MeasureTheory.Measure`, and of the extended distance `edist` in an `EMetricSpace`. In this file we set up many of the instances on `ℝ≥0∞`, and provide relationships between `ℝ≥0∞` and `ℝ≥0`, and between `ℝ≥0∞` and `ℝ`. In particular, we provide a coercion from `ℝ≥0` to `ℝ≥0∞` as well as functions `ENNReal.toNNReal`, `ENNReal.ofReal` and `ENNReal.toReal`, all of which take the value zero wherever they cannot be the identity. Also included is the relationship between `ℝ≥0∞` and `ℕ`. The interaction of these functions, especially `ENNReal.ofReal` and `ENNReal.toReal`, with the algebraic and lattice structure can be found in `Data.ENNReal.Real`. This file proves many of the order properties of `ℝ≥0∞`, with the exception of the ways those relate to the algebraic structure, which are included in `Data.ENNReal.Operations`. This file also defines inversion and division: this includes `Inv` and `Div` instances on `ℝ≥0∞` making it into a `DivInvOneMonoid`. As a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation with integer exponent: this and other properties is shown in `Data.ENNReal.Inv`. ## Main definitions * `ℝ≥0∞`: the extended nonnegative real numbers `[0, ∞]`; defined as `WithTop ℝ≥0`; it is equipped with the following structures: - coercion from `ℝ≥0` defined in the natural way; - the natural structure of a complete dense linear order: `↑p ≤ ↑q ↔ p ≤ q` and `∀ a, a ≤ ∞`; - `a + b` is defined so that `↑p + ↑q = ↑(p + q)` for `(p q : ℝ≥0)` and `a + ∞ = ∞ + a = ∞`; - `a * b` is defined so that `↑p * ↑q = ↑(p * q)` for `(p q : ℝ≥0)`, `0 * ∞ = ∞ * 0 = 0`, and `a * ∞ = ∞ * a = ∞` for `a ≠ 0`; - `a - b` is defined as the minimal `d` such that `a ≤ d + b`; this way we have `↑p - ↑q = ↑(p - q)`, `∞ - ↑p = ∞`, `↑p - ∞ = ∞ - ∞ = 0`; note that there is no negation, only subtraction; The addition and multiplication defined this way together with `0 = ↑0` and `1 = ↑1` turn `ℝ≥0∞` into a canonically ordered commutative semiring of characteristic zero. - `a⁻¹` is defined as `Inf {b | 1 ≤ a * b}`. This way we have `(↑p)⁻¹ = ↑(p⁻¹)` for `p : ℝ≥0`, `p ≠ 0`, `0⁻¹ = ∞`, and `∞⁻¹ = 0`. - `a / b` is defined as `a * b⁻¹`. This inversion and division include `Inv` and `Div` instances on `ℝ≥0∞`, making it into a `DivInvOneMonoid`. Further properties of these are shown in `Data.ENNReal.Inv`. * Coercions to/from other types: - coercion `ℝ≥0 → ℝ≥0∞` is defined as `Coe`, so one can use `(p : ℝ≥0)` in a context that expects `a : ℝ≥0∞`, and Lean will apply `coe` automatically; - `ENNReal.toNNReal` sends `↑p` to `p` and `∞` to `0`; - `ENNReal.toReal := coe ∘ ENNReal.toNNReal` sends `↑p`, `p : ℝ≥0` to `(↑p : ℝ)` and `∞` to `0`; - `ENNReal.ofReal := coe ∘ Real.toNNReal` sends `x : ℝ` to `↑⟨max x 0, _⟩` - `ENNReal.neTopEquivNNReal` is an equivalence between `{a : ℝ≥0∞ // a ≠ 0}` and `ℝ≥0`. ## Implementation notes We define a `CanLift ℝ≥0∞ ℝ≥0` instance, so one of the ways to prove theorems about an `ℝ≥0∞` number `a` is to consider the cases `a = ∞` and `a ≠ ∞`, and use the tactic `lift a to ℝ≥0 using ha` in the second case. This instance is even more useful if one already has `ha : a ≠ ∞` in the context, or if we have `(f : α → ℝ≥0∞) (hf : ∀ x, f x ≠ ∞)`. ## Notations * `ℝ≥0∞`: the type of the extended nonnegative real numbers; * `ℝ≥0`: the type of nonnegative real numbers `[0, ∞)`; defined in `Data.Real.NNReal`; * `∞`: a localized notation in `ENNReal` for `⊤ : ℝ≥0∞`. -/ open Function Set NNReal variable {α : Type*} /-- The extended nonnegative real numbers. This is usually denoted [0, ∞], and is relevant as the codomain of a measure. -/ def ENNReal := WithTop ℝ≥0 deriving Zero, AddCommMonoidWithOne, SemilatticeSup, DistribLattice, Nontrivial #align ennreal ENNReal @[inherit_doc] scoped[ENNReal] notation "ℝ≥0∞" => ENNReal /-- Notation for infinity as an `ENNReal` number. -/ scoped[ENNReal] notation "∞" => (⊤ : ENNReal) namespace ENNReal instance : OrderBot ℝ≥0∞ := inferInstanceAs (OrderBot (WithTop ℝ≥0)) instance : BoundedOrder ℝ≥0∞ := inferInstanceAs (BoundedOrder (WithTop ℝ≥0)) instance : CharZero ℝ≥0∞ := inferInstanceAs (CharZero (WithTop ℝ≥0)) noncomputable instance : CanonicallyOrderedCommSemiring ℝ≥0∞ := inferInstanceAs (CanonicallyOrderedCommSemiring (WithTop ℝ≥0)) noncomputable instance : CompleteLinearOrder ℝ≥0∞ := inferInstanceAs (CompleteLinearOrder (WithTop ℝ≥0)) instance : DenselyOrdered ℝ≥0∞ := inferInstanceAs (DenselyOrdered (WithTop ℝ≥0)) noncomputable instance : CanonicallyLinearOrderedAddCommMonoid ℝ≥0∞ := inferInstanceAs (CanonicallyLinearOrderedAddCommMonoid (WithTop ℝ≥0)) noncomputable instance instSub : Sub ℝ≥0∞ := inferInstanceAs (Sub (WithTop ℝ≥0)) noncomputable instance : OrderedSub ℝ≥0∞ := inferInstanceAs (OrderedSub (WithTop ℝ≥0)) noncomputable instance : LinearOrderedAddCommMonoidWithTop ℝ≥0∞ := inferInstanceAs (LinearOrderedAddCommMonoidWithTop (WithTop ℝ≥0)) -- Porting note: rfc: redefine using pattern matching? noncomputable instance : Inv ℝ≥0∞ := ⟨fun a => sInf { b | 1 ≤ a * b }⟩ noncomputable instance : DivInvMonoid ℝ≥0∞ where variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} -- Porting note: are these 2 instances still required in Lean 4? instance covariantClass_mul_le : CovariantClass ℝ≥0∞ ℝ≥0∞ (· * ·) (· ≤ ·) := inferInstance #align ennreal.covariant_class_mul_le ENNReal.covariantClass_mul_le instance covariantClass_add_le : CovariantClass ℝ≥0∞ ℝ≥0∞ (· + ·) (· ≤ ·) := inferInstance #align ennreal.covariant_class_add_le ENNReal.covariantClass_add_le -- Porting note (#11215): TODO: add a `WithTop` instance and use it here noncomputable instance : LinearOrderedCommMonoidWithZero ℝ≥0∞ := { inferInstanceAs (LinearOrderedAddCommMonoidWithTop ℝ≥0∞), inferInstanceAs (CommSemiring ℝ≥0∞) with mul_le_mul_left := fun _ _ => mul_le_mul_left' zero_le_one := zero_le 1 } noncomputable instance : Unique (AddUnits ℝ≥0∞) where default := 0 uniq a := AddUnits.ext <| le_zero_iff.1 <| by rw [← a.add_neg]; exact le_self_add instance : Inhabited ℝ≥0∞ := ⟨0⟩ /-- Coercion from `ℝ≥0` to `ℝ≥0∞`. -/ @[coe, match_pattern] def ofNNReal : ℝ≥0 → ℝ≥0∞ := WithTop.some instance : Coe ℝ≥0 ℝ≥0∞ := ⟨ofNNReal⟩ /-- A version of `WithTop.recTopCoe` that uses `ENNReal.ofNNReal`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] def recTopCoe {C : ℝ≥0∞ → Sort*} (top : C ∞) (coe : ∀ x : ℝ≥0, C x) (x : ℝ≥0∞) : C x := WithTop.recTopCoe top coe x instance canLift : CanLift ℝ≥0∞ ℝ≥0 ofNNReal (· ≠ ∞) := WithTop.canLift #align ennreal.can_lift ENNReal.canLift @[simp] theorem none_eq_top : (none : ℝ≥0∞) = ∞ := rfl #align ennreal.none_eq_top ENNReal.none_eq_top @[simp] theorem some_eq_coe (a : ℝ≥0) : (Option.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl #align ennreal.some_eq_coe ENNReal.some_eq_coe @[simp] theorem some_eq_coe' (a : ℝ≥0) : (WithTop.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl lemma coe_injective : Injective ((↑) : ℝ≥0 → ℝ≥0∞) := WithTop.coe_injective @[simp, norm_cast] lemma coe_inj : (p : ℝ≥0∞) = q ↔ p = q := coe_injective.eq_iff #align ennreal.coe_eq_coe ENNReal.coe_inj lemma coe_ne_coe : (p : ℝ≥0∞) ≠ q ↔ p ≠ q := coe_inj.not theorem range_coe' : range ofNNReal = Iio ∞ := WithTop.range_coe theorem range_coe : range ofNNReal = {∞}ᶜ := (isCompl_range_some_none ℝ≥0).symm.compl_eq.symm /-- `toNNReal x` returns `x` if it is real, otherwise 0. -/ protected def toNNReal : ℝ≥0∞ → ℝ≥0 := WithTop.untop' 0 #align ennreal.to_nnreal ENNReal.toNNReal /-- `toReal x` returns `x` if it is real, `0` otherwise. -/ protected def toReal (a : ℝ≥0∞) : Real := a.toNNReal #align ennreal.to_real ENNReal.toReal /-- `ofReal x` returns `x` if it is nonnegative, `0` otherwise. -/ protected noncomputable def ofReal (r : Real) : ℝ≥0∞ := r.toNNReal #align ennreal.of_real ENNReal.ofReal @[simp, norm_cast] theorem toNNReal_coe : (r : ℝ≥0∞).toNNReal = r := rfl #align ennreal.to_nnreal_coe ENNReal.toNNReal_coe @[simp] theorem coe_toNNReal : ∀ {a : ℝ≥0∞}, a ≠ ∞ → ↑a.toNNReal = a | ofNNReal _, _ => rfl | ⊤, h => (h rfl).elim #align ennreal.coe_to_nnreal ENNReal.coe_toNNReal @[simp] theorem ofReal_toReal {a : ℝ≥0∞} (h : a ≠ ∞) : ENNReal.ofReal a.toReal = a := by simp [ENNReal.toReal, ENNReal.ofReal, h] #align ennreal.of_real_to_real ENNReal.ofReal_toReal @[simp] theorem toReal_ofReal {r : ℝ} (h : 0 ≤ r) : (ENNReal.ofReal r).toReal = r := max_eq_left h #align ennreal.to_real_of_real ENNReal.toReal_ofReal theorem toReal_ofReal' {r : ℝ} : (ENNReal.ofReal r).toReal = max r 0 := rfl #align ennreal.to_real_of_real' ENNReal.toReal_ofReal' theorem coe_toNNReal_le_self : ∀ {a : ℝ≥0∞}, ↑a.toNNReal ≤ a | ofNNReal r => by rw [toNNReal_coe] | ⊤ => le_top #align ennreal.coe_to_nnreal_le_self ENNReal.coe_toNNReal_le_self theorem coe_nnreal_eq (r : ℝ≥0) : (r : ℝ≥0∞) = ENNReal.ofReal r := by rw [ENNReal.ofReal, Real.toNNReal_coe] #align ennreal.coe_nnreal_eq ENNReal.coe_nnreal_eq theorem ofReal_eq_coe_nnreal {x : ℝ} (h : 0 ≤ x) : ENNReal.ofReal x = ofNNReal ⟨x, h⟩ := (coe_nnreal_eq ⟨x, h⟩).symm #align ennreal.of_real_eq_coe_nnreal ENNReal.ofReal_eq_coe_nnreal @[simp] theorem ofReal_coe_nnreal : ENNReal.ofReal p = p := (coe_nnreal_eq p).symm #align ennreal.of_real_coe_nnreal ENNReal.ofReal_coe_nnreal @[simp, norm_cast] theorem coe_zero : ↑(0 : ℝ≥0) = (0 : ℝ≥0∞) := rfl #align ennreal.coe_zero ENNReal.coe_zero @[simp, norm_cast] theorem coe_one : ↑(1 : ℝ≥0) = (1 : ℝ≥0∞) := rfl #align ennreal.coe_one ENNReal.coe_one @[simp] theorem toReal_nonneg {a : ℝ≥0∞} : 0 ≤ a.toReal := a.toNNReal.2 #align ennreal.to_real_nonneg ENNReal.toReal_nonneg @[simp] theorem top_toNNReal : ∞.toNNReal = 0 := rfl #align ennreal.top_to_nnreal ENNReal.top_toNNReal @[simp] theorem top_toReal : ∞.toReal = 0 := rfl #align ennreal.top_to_real ENNReal.top_toReal @[simp] theorem one_toReal : (1 : ℝ≥0∞).toReal = 1 := rfl #align ennreal.one_to_real ENNReal.one_toReal @[simp] theorem one_toNNReal : (1 : ℝ≥0∞).toNNReal = 1 := rfl #align ennreal.one_to_nnreal ENNReal.one_toNNReal @[simp] theorem coe_toReal (r : ℝ≥0) : (r : ℝ≥0∞).toReal = r := rfl #align ennreal.coe_to_real ENNReal.coe_toReal @[simp] theorem zero_toNNReal : (0 : ℝ≥0∞).toNNReal = 0 := rfl #align ennreal.zero_to_nnreal ENNReal.zero_toNNReal @[simp] theorem zero_toReal : (0 : ℝ≥0∞).toReal = 0 := rfl #align ennreal.zero_to_real ENNReal.zero_toReal @[simp] theorem ofReal_zero : ENNReal.ofReal (0 : ℝ) = 0 := by simp [ENNReal.ofReal] #align ennreal.of_real_zero ENNReal.ofReal_zero @[simp] theorem ofReal_one : ENNReal.ofReal (1 : ℝ) = (1 : ℝ≥0∞) := by simp [ENNReal.ofReal] #align ennreal.of_real_one ENNReal.ofReal_one theorem ofReal_toReal_le {a : ℝ≥0∞} : ENNReal.ofReal a.toReal ≤ a := if ha : a = ∞ then ha.symm ▸ le_top else le_of_eq (ofReal_toReal ha) #align ennreal.of_real_to_real_le ENNReal.ofReal_toReal_le theorem forall_ennreal {p : ℝ≥0∞ → Prop} : (∀ a, p a) ↔ (∀ r : ℝ≥0, p r) ∧ p ∞ := Option.forall.trans and_comm #align ennreal.forall_ennreal ENNReal.forall_ennreal theorem forall_ne_top {p : ℝ≥0∞ → Prop} : (∀ a, a ≠ ∞ → p a) ↔ ∀ r : ℝ≥0, p r := Option.ball_ne_none #align ennreal.forall_ne_top ENNReal.forall_ne_top theorem exists_ne_top {p : ℝ≥0∞ → Prop} : (∃ a ≠ ∞, p a) ↔ ∃ r : ℝ≥0, p r := Option.exists_ne_none #align ennreal.exists_ne_top ENNReal.exists_ne_top theorem toNNReal_eq_zero_iff (x : ℝ≥0∞) : x.toNNReal = 0 ↔ x = 0 ∨ x = ∞ := WithTop.untop'_eq_self_iff #align ennreal.to_nnreal_eq_zero_iff ENNReal.toNNReal_eq_zero_iff theorem toReal_eq_zero_iff (x : ℝ≥0∞) : x.toReal = 0 ↔ x = 0 ∨ x = ∞ := by simp [ENNReal.toReal, toNNReal_eq_zero_iff] #align ennreal.to_real_eq_zero_iff ENNReal.toReal_eq_zero_iff theorem toNNReal_ne_zero : a.toNNReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toNNReal_eq_zero_iff.not.trans not_or #align ennreal.to_nnreal_ne_zero ENNReal.toNNReal_ne_zero theorem toReal_ne_zero : a.toReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toReal_eq_zero_iff.not.trans not_or #align ennreal.to_real_ne_zero ENNReal.toReal_ne_zero theorem toNNReal_eq_one_iff (x : ℝ≥0∞) : x.toNNReal = 1 ↔ x = 1 := WithTop.untop'_eq_iff.trans <| by simp #align ennreal.to_nnreal_eq_one_iff ENNReal.toNNReal_eq_one_iff theorem toReal_eq_one_iff (x : ℝ≥0∞) : x.toReal = 1 ↔ x = 1 := by rw [ENNReal.toReal, NNReal.coe_eq_one, ENNReal.toNNReal_eq_one_iff] #align ennreal.to_real_eq_one_iff ENNReal.toReal_eq_one_iff theorem toNNReal_ne_one : a.toNNReal ≠ 1 ↔ a ≠ 1 := a.toNNReal_eq_one_iff.not #align ennreal.to_nnreal_ne_one ENNReal.toNNReal_ne_one theorem toReal_ne_one : a.toReal ≠ 1 ↔ a ≠ 1 := a.toReal_eq_one_iff.not #align ennreal.to_real_ne_one ENNReal.toReal_ne_one @[simp] theorem coe_ne_top : (r : ℝ≥0∞) ≠ ∞ := WithTop.coe_ne_top #align ennreal.coe_ne_top ENNReal.coe_ne_top @[simp] theorem top_ne_coe : ∞ ≠ (r : ℝ≥0∞) := WithTop.top_ne_coe #align ennreal.top_ne_coe ENNReal.top_ne_coe @[simp] theorem coe_lt_top : (r : ℝ≥0∞) < ∞ := WithTop.coe_lt_top r #align ennreal.coe_lt_top ENNReal.coe_lt_top @[simp] theorem ofReal_ne_top {r : ℝ} : ENNReal.ofReal r ≠ ∞ := coe_ne_top #align ennreal.of_real_ne_top ENNReal.ofReal_ne_top @[simp] theorem ofReal_lt_top {r : ℝ} : ENNReal.ofReal r < ∞ := coe_lt_top #align ennreal.of_real_lt_top ENNReal.ofReal_lt_top @[simp] theorem top_ne_ofReal {r : ℝ} : ∞ ≠ ENNReal.ofReal r := top_ne_coe #align ennreal.top_ne_of_real ENNReal.top_ne_ofReal @[simp] theorem ofReal_toReal_eq_iff : ENNReal.ofReal a.toReal = a ↔ a ≠ ⊤ := ⟨fun h => by rw [← h] exact ofReal_ne_top, ofReal_toReal⟩ #align ennreal.of_real_to_real_eq_iff ENNReal.ofReal_toReal_eq_iff @[simp] theorem toReal_ofReal_eq_iff {a : ℝ} : (ENNReal.ofReal a).toReal = a ↔ 0 ≤ a := ⟨fun h => by rw [← h] exact toReal_nonneg, toReal_ofReal⟩ #align ennreal.to_real_of_real_eq_iff ENNReal.toReal_ofReal_eq_iff @[simp] theorem zero_ne_top : 0 ≠ ∞ := coe_ne_top #align ennreal.zero_ne_top ENNReal.zero_ne_top @[simp] theorem top_ne_zero : ∞ ≠ 0 := top_ne_coe #align ennreal.top_ne_zero ENNReal.top_ne_zero @[simp] theorem one_ne_top : 1 ≠ ∞ := coe_ne_top #align ennreal.one_ne_top ENNReal.one_ne_top @[simp] theorem top_ne_one : ∞ ≠ 1 := top_ne_coe #align ennreal.top_ne_one ENNReal.top_ne_one @[simp] theorem zero_lt_top : 0 < ∞ := coe_lt_top @[simp, norm_cast] theorem coe_le_coe : (↑r : ℝ≥0∞) ≤ ↑q ↔ r ≤ q := WithTop.coe_le_coe #align ennreal.coe_le_coe ENNReal.coe_le_coe @[simp, norm_cast] theorem coe_lt_coe : (↑r : ℝ≥0∞) < ↑q ↔ r < q := WithTop.coe_lt_coe #align ennreal.coe_lt_coe ENNReal.coe_lt_coe -- Needed until `@[gcongr]` accepts iff statements alias ⟨_, coe_le_coe_of_le⟩ := coe_le_coe attribute [gcongr] ENNReal.coe_le_coe_of_le -- Needed until `@[gcongr]` accepts iff statements alias ⟨_, coe_lt_coe_of_lt⟩ := coe_lt_coe attribute [gcongr] ENNReal.coe_lt_coe_of_lt theorem coe_mono : Monotone ofNNReal := fun _ _ => coe_le_coe.2 #align ennreal.coe_mono ENNReal.coe_mono theorem coe_strictMono : StrictMono ofNNReal := fun _ _ => coe_lt_coe.2 @[simp, norm_cast] theorem coe_eq_zero : (↑r : ℝ≥0∞) = 0 ↔ r = 0 := coe_inj #align ennreal.coe_eq_zero ENNReal.coe_eq_zero @[simp, norm_cast] theorem zero_eq_coe : 0 = (↑r : ℝ≥0∞) ↔ 0 = r := coe_inj #align ennreal.zero_eq_coe ENNReal.zero_eq_coe @[simp, norm_cast] theorem coe_eq_one : (↑r : ℝ≥0∞) = 1 ↔ r = 1 := coe_inj #align ennreal.coe_eq_one ENNReal.coe_eq_one @[simp, norm_cast] theorem one_eq_coe : 1 = (↑r : ℝ≥0∞) ↔ 1 = r := coe_inj #align ennreal.one_eq_coe ENNReal.one_eq_coe @[simp, norm_cast] theorem coe_pos : 0 < (r : ℝ≥0∞) ↔ 0 < r := coe_lt_coe #align ennreal.coe_pos ENNReal.coe_pos theorem coe_ne_zero : (r : ℝ≥0∞) ≠ 0 ↔ r ≠ 0 := coe_eq_zero.not #align ennreal.coe_ne_zero ENNReal.coe_ne_zero lemma coe_ne_one : (r : ℝ≥0∞) ≠ 1 ↔ r ≠ 1 := coe_eq_one.not @[simp, norm_cast] lemma coe_add (x y : ℝ≥0) : (↑(x + y) : ℝ≥0∞) = x + y := rfl #align ennreal.coe_add ENNReal.coe_add @[simp, norm_cast] lemma coe_mul (x y : ℝ≥0) : (↑(x * y) : ℝ≥0∞) = x * y := rfl #align ennreal.coe_mul ENNReal.coe_mul @[norm_cast] lemma coe_nsmul (n : ℕ) (x : ℝ≥0) : (↑(n • x) : ℝ≥0∞) = n • x := rfl @[simp, norm_cast] lemma coe_pow (x : ℝ≥0) (n : ℕ) : (↑(x ^ n) : ℝ≥0∞) = x ^ n := rfl #noalign ennreal.coe_bit0 #noalign ennreal.coe_bit1 -- See note [no_index around OfNat.ofNat] @[simp, norm_cast] -- Porting note (#10756): new theorem theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] : ((no_index (OfNat.ofNat n) : ℝ≥0) : ℝ≥0∞) = OfNat.ofNat n := rfl -- Porting note (#11215): TODO: add lemmas about `OfNat.ofNat` and `<`/`≤` theorem coe_two : ((2 : ℝ≥0) : ℝ≥0∞) = 2 := rfl #align ennreal.coe_two ENNReal.coe_two theorem toNNReal_eq_toNNReal_iff (x y : ℝ≥0∞) : x.toNNReal = y.toNNReal ↔ x = y ∨ x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0 := WithTop.untop'_eq_untop'_iff #align ennreal.to_nnreal_eq_to_nnreal_iff ENNReal.toNNReal_eq_toNNReal_iff theorem toReal_eq_toReal_iff (x y : ℝ≥0∞) : x.toReal = y.toReal ↔ x = y ∨ x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0 := by simp only [ENNReal.toReal, NNReal.coe_inj, toNNReal_eq_toNNReal_iff] #align ennreal.to_real_eq_to_real_iff ENNReal.toReal_eq_toReal_iff theorem toNNReal_eq_toNNReal_iff' {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) : x.toNNReal = y.toNNReal ↔ x = y := by simp only [ENNReal.toNNReal_eq_toNNReal_iff x y, hx, hy, and_false, false_and, or_false] #align ennreal.to_nnreal_eq_to_nnreal_iff' ENNReal.toNNReal_eq_toNNReal_iff'
Mathlib/Data/ENNReal/Basic.lean
448
450
theorem toReal_eq_toReal_iff' {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) : x.toReal = y.toReal ↔ x = y := by
simp only [ENNReal.toReal, NNReal.coe_inj, toNNReal_eq_toNNReal_iff' hx hy]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Analysis.SpecialFunctions.Sqrt import Mathlib.Analysis.NormedSpace.HomeomorphBall #align_import analysis.inner_product_space.calculus from "leanprover-community/mathlib"@"f9dd3204df14a0749cd456fac1e6849dfe7d2b88" /-! # Calculus in inner product spaces In this file we prove that the inner product and square of the norm in an inner space are infinitely `ℝ`-smooth. In order to state these results, we need a `NormedSpace ℝ E` instance. Though we can deduce this structure from `InnerProductSpace 𝕜 E`, this instance may be not definitionally equal to some other “natural” instance. So, we assume `[NormedSpace ℝ E]`. We also prove that functions to a `EuclideanSpace` are (higher) differentiable if and only if their components are. This follows from the corresponding fact for finite product of normed spaces, and from the equivalence of norms in finite dimensions. ## TODO The last part of the file should be generalized to `PiLp`. -/ noncomputable section open RCLike Real Filter open scoped Classical Topology section DerivInner variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y variable (𝕜) [NormedSpace ℝ E] /-- Derivative of the inner product. -/ def fderivInnerCLM (p : E × E) : E × E →L[ℝ] 𝕜 := isBoundedBilinearMap_inner.deriv p #align fderiv_inner_clm fderivInnerCLM @[simp] theorem fderivInnerCLM_apply (p x : E × E) : fderivInnerCLM 𝕜 p x = ⟪p.1, x.2⟫ + ⟪x.1, p.2⟫ := rfl #align fderiv_inner_clm_apply fderivInnerCLM_apply variable {𝕜} -- Porting note: Lean 3 magically switches back to `{𝕜}` here theorem contDiff_inner {n} : ContDiff ℝ n fun p : E × E => ⟪p.1, p.2⟫ := isBoundedBilinearMap_inner.contDiff #align cont_diff_inner contDiff_inner theorem contDiffAt_inner {p : E × E} {n} : ContDiffAt ℝ n (fun p : E × E => ⟪p.1, p.2⟫) p := ContDiff.contDiffAt contDiff_inner #align cont_diff_at_inner contDiffAt_inner theorem differentiable_inner : Differentiable ℝ fun p : E × E => ⟪p.1, p.2⟫ := isBoundedBilinearMap_inner.differentiableAt #align differentiable_inner differentiable_inner variable (𝕜) variable {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] {f g : G → E} {f' g' : G →L[ℝ] E} {s : Set G} {x : G} {n : ℕ∞} theorem ContDiffWithinAt.inner (hf : ContDiffWithinAt ℝ n f s x) (hg : ContDiffWithinAt ℝ n g s x) : ContDiffWithinAt ℝ n (fun x => ⟪f x, g x⟫) s x := contDiffAt_inner.comp_contDiffWithinAt x (hf.prod hg) #align cont_diff_within_at.inner ContDiffWithinAt.inner nonrec theorem ContDiffAt.inner (hf : ContDiffAt ℝ n f x) (hg : ContDiffAt ℝ n g x) : ContDiffAt ℝ n (fun x => ⟪f x, g x⟫) x := hf.inner 𝕜 hg #align cont_diff_at.inner ContDiffAt.inner theorem ContDiffOn.inner (hf : ContDiffOn ℝ n f s) (hg : ContDiffOn ℝ n g s) : ContDiffOn ℝ n (fun x => ⟪f x, g x⟫) s := fun x hx => (hf x hx).inner 𝕜 (hg x hx) #align cont_diff_on.inner ContDiffOn.inner theorem ContDiff.inner (hf : ContDiff ℝ n f) (hg : ContDiff ℝ n g) : ContDiff ℝ n fun x => ⟪f x, g x⟫ := contDiff_inner.comp (hf.prod hg) #align cont_diff.inner ContDiff.inner theorem HasFDerivWithinAt.inner (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') s x := (isBoundedBilinearMap_inner.hasFDerivAt (f x, g x)).comp_hasFDerivWithinAt x (hf.prod hg) #align has_fderiv_within_at.inner HasFDerivWithinAt.inner theorem HasStrictFDerivAt.inner (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') x := (isBoundedBilinearMap_inner.hasStrictFDerivAt (f x, g x)).comp x (hf.prod hg) #align has_strict_fderiv_at.inner HasStrictFDerivAt.inner theorem HasFDerivAt.inner (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun t => ⟪f t, g t⟫) ((fderivInnerCLM 𝕜 (f x, g x)).comp <| f'.prod g') x := (isBoundedBilinearMap_inner.hasFDerivAt (f x, g x)).comp x (hf.prod hg) #align has_fderiv_at.inner HasFDerivAt.inner theorem HasDerivWithinAt.inner {f g : ℝ → E} {f' g' : E} {s : Set ℝ} {x : ℝ} (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun t => ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) s x := by simpa using (hf.hasFDerivWithinAt.inner 𝕜 hg.hasFDerivWithinAt).hasDerivWithinAt #align has_deriv_within_at.inner HasDerivWithinAt.inner theorem HasDerivAt.inner {f g : ℝ → E} {f' g' : E} {x : ℝ} : HasDerivAt f f' x → HasDerivAt g g' x → HasDerivAt (fun t => ⟪f t, g t⟫) (⟪f x, g'⟫ + ⟪f', g x⟫) x := by simpa only [← hasDerivWithinAt_univ] using HasDerivWithinAt.inner 𝕜 #align has_deriv_at.inner HasDerivAt.inner theorem DifferentiableWithinAt.inner (hf : DifferentiableWithinAt ℝ f s x) (hg : DifferentiableWithinAt ℝ g s x) : DifferentiableWithinAt ℝ (fun x => ⟪f x, g x⟫) s x := ((differentiable_inner _).hasFDerivAt.comp_hasFDerivWithinAt x (hf.prod hg).hasFDerivWithinAt).differentiableWithinAt #align differentiable_within_at.inner DifferentiableWithinAt.inner theorem DifferentiableAt.inner (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) : DifferentiableAt ℝ (fun x => ⟪f x, g x⟫) x := (differentiable_inner _).comp x (hf.prod hg) #align differentiable_at.inner DifferentiableAt.inner theorem DifferentiableOn.inner (hf : DifferentiableOn ℝ f s) (hg : DifferentiableOn ℝ g s) : DifferentiableOn ℝ (fun x => ⟪f x, g x⟫) s := fun x hx => (hf x hx).inner 𝕜 (hg x hx) #align differentiable_on.inner DifferentiableOn.inner theorem Differentiable.inner (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) : Differentiable ℝ fun x => ⟪f x, g x⟫ := fun x => (hf x).inner 𝕜 (hg x) #align differentiable.inner Differentiable.inner theorem fderiv_inner_apply (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) (y : G) : fderiv ℝ (fun t => ⟪f t, g t⟫) x y = ⟪f x, fderiv ℝ g x y⟫ + ⟪fderiv ℝ f x y, g x⟫ := by rw [(hf.hasFDerivAt.inner 𝕜 hg.hasFDerivAt).fderiv]; rfl #align fderiv_inner_apply fderiv_inner_apply theorem deriv_inner_apply {f g : ℝ → E} {x : ℝ} (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) : deriv (fun t => ⟪f t, g t⟫) x = ⟪f x, deriv g x⟫ + ⟪deriv f x, g x⟫ := (hf.hasDerivAt.inner 𝕜 hg.hasDerivAt).deriv #align deriv_inner_apply deriv_inner_apply theorem contDiff_norm_sq : ContDiff ℝ n fun x : E => ‖x‖ ^ 2 := by convert (reCLM : 𝕜 →L[ℝ] ℝ).contDiff.comp ((contDiff_id (E := E)).inner 𝕜 (contDiff_id (E := E))) exact (inner_self_eq_norm_sq _).symm #align cont_diff_norm_sq contDiff_norm_sq theorem ContDiff.norm_sq (hf : ContDiff ℝ n f) : ContDiff ℝ n fun x => ‖f x‖ ^ 2 := (contDiff_norm_sq 𝕜).comp hf #align cont_diff.norm_sq ContDiff.norm_sq theorem ContDiffWithinAt.norm_sq (hf : ContDiffWithinAt ℝ n f s x) : ContDiffWithinAt ℝ n (fun y => ‖f y‖ ^ 2) s x := (contDiff_norm_sq 𝕜).contDiffAt.comp_contDiffWithinAt x hf #align cont_diff_within_at.norm_sq ContDiffWithinAt.norm_sq nonrec theorem ContDiffAt.norm_sq (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (‖f ·‖ ^ 2) x := hf.norm_sq 𝕜 #align cont_diff_at.norm_sq ContDiffAt.norm_sq theorem contDiffAt_norm {x : E} (hx : x ≠ 0) : ContDiffAt ℝ n norm x := by have : ‖id x‖ ^ 2 ≠ 0 := pow_ne_zero 2 (norm_pos_iff.2 hx).ne' simpa only [id, sqrt_sq, norm_nonneg] using (contDiffAt_id.norm_sq 𝕜).sqrt this #align cont_diff_at_norm contDiffAt_norm theorem ContDiffAt.norm (hf : ContDiffAt ℝ n f x) (h0 : f x ≠ 0) : ContDiffAt ℝ n (fun y => ‖f y‖) x := (contDiffAt_norm 𝕜 h0).comp x hf #align cont_diff_at.norm ContDiffAt.norm theorem ContDiffAt.dist (hf : ContDiffAt ℝ n f x) (hg : ContDiffAt ℝ n g x) (hne : f x ≠ g x) : ContDiffAt ℝ n (fun y => dist (f y) (g y)) x := by simp only [dist_eq_norm] exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) #align cont_diff_at.dist ContDiffAt.dist theorem ContDiffWithinAt.norm (hf : ContDiffWithinAt ℝ n f s x) (h0 : f x ≠ 0) : ContDiffWithinAt ℝ n (fun y => ‖f y‖) s x := (contDiffAt_norm 𝕜 h0).comp_contDiffWithinAt x hf #align cont_diff_within_at.norm ContDiffWithinAt.norm theorem ContDiffWithinAt.dist (hf : ContDiffWithinAt ℝ n f s x) (hg : ContDiffWithinAt ℝ n g s x) (hne : f x ≠ g x) : ContDiffWithinAt ℝ n (fun y => dist (f y) (g y)) s x := by simp only [dist_eq_norm]; exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) #align cont_diff_within_at.dist ContDiffWithinAt.dist theorem ContDiffOn.norm_sq (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun y => ‖f y‖ ^ 2) s := fun x hx => (hf x hx).norm_sq 𝕜 #align cont_diff_on.norm_sq ContDiffOn.norm_sq theorem ContDiffOn.norm (hf : ContDiffOn ℝ n f s) (h0 : ∀ x ∈ s, f x ≠ 0) : ContDiffOn ℝ n (fun y => ‖f y‖) s := fun x hx => (hf x hx).norm 𝕜 (h0 x hx) #align cont_diff_on.norm ContDiffOn.norm theorem ContDiffOn.dist (hf : ContDiffOn ℝ n f s) (hg : ContDiffOn ℝ n g s) (hne : ∀ x ∈ s, f x ≠ g x) : ContDiffOn ℝ n (fun y => dist (f y) (g y)) s := fun x hx => (hf x hx).dist 𝕜 (hg x hx) (hne x hx) #align cont_diff_on.dist ContDiffOn.dist theorem ContDiff.norm (hf : ContDiff ℝ n f) (h0 : ∀ x, f x ≠ 0) : ContDiff ℝ n fun y => ‖f y‖ := contDiff_iff_contDiffAt.2 fun x => hf.contDiffAt.norm 𝕜 (h0 x) #align cont_diff.norm ContDiff.norm theorem ContDiff.dist (hf : ContDiff ℝ n f) (hg : ContDiff ℝ n g) (hne : ∀ x, f x ≠ g x) : ContDiff ℝ n fun y => dist (f y) (g y) := contDiff_iff_contDiffAt.2 fun x => hf.contDiffAt.dist 𝕜 hg.contDiffAt (hne x) #align cont_diff.dist ContDiff.dist -- Porting note: use `2 •` instead of `bit0` theorem hasStrictFDerivAt_norm_sq (x : F) : HasStrictFDerivAt (fun x => ‖x‖ ^ 2) (2 • (innerSL ℝ x)) x := by simp only [sq, ← @inner_self_eq_norm_mul_norm ℝ] convert (hasStrictFDerivAt_id x).inner ℝ (hasStrictFDerivAt_id x) ext y simp [two_smul, real_inner_comm] #align has_strict_fderiv_at_norm_sq hasStrictFDerivAt_norm_sqₓ theorem HasFDerivAt.norm_sq {f : G → F} {f' : G →L[ℝ] F} (hf : HasFDerivAt f f' x) : HasFDerivAt (‖f ·‖ ^ 2) (2 • (innerSL ℝ (f x)).comp f') x := (hasStrictFDerivAt_norm_sq _).hasFDerivAt.comp x hf theorem HasDerivAt.norm_sq {f : ℝ → F} {f' : F} {x : ℝ} (hf : HasDerivAt f f' x) : HasDerivAt (‖f ·‖ ^ 2) (2 * Inner.inner (f x) f') x := by simpa using hf.hasFDerivAt.norm_sq.hasDerivAt theorem HasFDerivWithinAt.norm_sq {f : G → F} {f' : G →L[ℝ] F} (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (‖f ·‖ ^ 2) (2 • (innerSL ℝ (f x)).comp f') s x := (hasStrictFDerivAt_norm_sq _).hasFDerivAt.comp_hasFDerivWithinAt x hf theorem HasDerivWithinAt.norm_sq {f : ℝ → F} {f' : F} {s : Set ℝ} {x : ℝ} (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (‖f ·‖ ^ 2) (2 * Inner.inner (f x) f') s x := by simpa using hf.hasFDerivWithinAt.norm_sq.hasDerivWithinAt theorem DifferentiableAt.norm_sq (hf : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (fun y => ‖f y‖ ^ 2) x := ((contDiffAt_id.norm_sq 𝕜).differentiableAt le_rfl).comp x hf #align differentiable_at.norm_sq DifferentiableAt.norm_sq theorem DifferentiableAt.norm (hf : DifferentiableAt ℝ f x) (h0 : f x ≠ 0) : DifferentiableAt ℝ (fun y => ‖f y‖) x := ((contDiffAt_norm 𝕜 h0).differentiableAt le_rfl).comp x hf #align differentiable_at.norm DifferentiableAt.norm theorem DifferentiableAt.dist (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) (hne : f x ≠ g x) : DifferentiableAt ℝ (fun y => dist (f y) (g y)) x := by simp only [dist_eq_norm]; exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) #align differentiable_at.dist DifferentiableAt.dist theorem Differentiable.norm_sq (hf : Differentiable ℝ f) : Differentiable ℝ fun y => ‖f y‖ ^ 2 := fun x => (hf x).norm_sq 𝕜 #align differentiable.norm_sq Differentiable.norm_sq theorem Differentiable.norm (hf : Differentiable ℝ f) (h0 : ∀ x, f x ≠ 0) : Differentiable ℝ fun y => ‖f y‖ := fun x => (hf x).norm 𝕜 (h0 x) #align differentiable.norm Differentiable.norm theorem Differentiable.dist (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) (hne : ∀ x, f x ≠ g x) : Differentiable ℝ fun y => dist (f y) (g y) := fun x => (hf x).dist 𝕜 (hg x) (hne x) #align differentiable.dist Differentiable.dist theorem DifferentiableWithinAt.norm_sq (hf : DifferentiableWithinAt ℝ f s x) : DifferentiableWithinAt ℝ (fun y => ‖f y‖ ^ 2) s x := ((contDiffAt_id.norm_sq 𝕜).differentiableAt le_rfl).comp_differentiableWithinAt x hf #align differentiable_within_at.norm_sq DifferentiableWithinAt.norm_sq theorem DifferentiableWithinAt.norm (hf : DifferentiableWithinAt ℝ f s x) (h0 : f x ≠ 0) : DifferentiableWithinAt ℝ (fun y => ‖f y‖) s x := ((contDiffAt_id.norm 𝕜 h0).differentiableAt le_rfl).comp_differentiableWithinAt x hf #align differentiable_within_at.norm DifferentiableWithinAt.norm theorem DifferentiableWithinAt.dist (hf : DifferentiableWithinAt ℝ f s x) (hg : DifferentiableWithinAt ℝ g s x) (hne : f x ≠ g x) : DifferentiableWithinAt ℝ (fun y => dist (f y) (g y)) s x := by simp only [dist_eq_norm] exact (hf.sub hg).norm 𝕜 (sub_ne_zero.2 hne) #align differentiable_within_at.dist DifferentiableWithinAt.dist theorem DifferentiableOn.norm_sq (hf : DifferentiableOn ℝ f s) : DifferentiableOn ℝ (fun y => ‖f y‖ ^ 2) s := fun x hx => (hf x hx).norm_sq 𝕜 #align differentiable_on.norm_sq DifferentiableOn.norm_sq theorem DifferentiableOn.norm (hf : DifferentiableOn ℝ f s) (h0 : ∀ x ∈ s, f x ≠ 0) : DifferentiableOn ℝ (fun y => ‖f y‖) s := fun x hx => (hf x hx).norm 𝕜 (h0 x hx) #align differentiable_on.norm DifferentiableOn.norm theorem DifferentiableOn.dist (hf : DifferentiableOn ℝ f s) (hg : DifferentiableOn ℝ g s) (hne : ∀ x ∈ s, f x ≠ g x) : DifferentiableOn ℝ (fun y => dist (f y) (g y)) s := fun x hx => (hf x hx).dist 𝕜 (hg x hx) (hne x hx) #align differentiable_on.dist DifferentiableOn.dist end DerivInner section PiLike open ContinuousLinearMap variable {𝕜 ι H : Type*} [RCLike 𝕜] [NormedAddCommGroup H] [NormedSpace 𝕜 H] [Fintype ι] {f : H → EuclideanSpace 𝕜 ι} {f' : H →L[𝕜] EuclideanSpace 𝕜 ι} {t : Set H} {y : H} theorem differentiableWithinAt_euclidean : DifferentiableWithinAt 𝕜 f t y ↔ ∀ i, DifferentiableWithinAt 𝕜 (fun x => f x i) t y := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_differentiableWithinAt_iff, differentiableWithinAt_pi] rfl #align differentiable_within_at_euclidean differentiableWithinAt_euclidean theorem differentiableAt_euclidean : DifferentiableAt 𝕜 f y ↔ ∀ i, DifferentiableAt 𝕜 (fun x => f x i) y := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_differentiableAt_iff, differentiableAt_pi] rfl #align differentiable_at_euclidean differentiableAt_euclidean theorem differentiableOn_euclidean : DifferentiableOn 𝕜 f t ↔ ∀ i, DifferentiableOn 𝕜 (fun x => f x i) t := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_differentiableOn_iff, differentiableOn_pi] rfl #align differentiable_on_euclidean differentiableOn_euclidean theorem differentiable_euclidean : Differentiable 𝕜 f ↔ ∀ i, Differentiable 𝕜 fun x => f x i := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_differentiable_iff, differentiable_pi] rfl #align differentiable_euclidean differentiable_euclidean theorem hasStrictFDerivAt_euclidean : HasStrictFDerivAt f f' y ↔ ∀ i, HasStrictFDerivAt (fun x => f x i) (EuclideanSpace.proj i ∘L f') y := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_hasStrictFDerivAt_iff, hasStrictFDerivAt_pi'] rfl #align has_strict_fderiv_at_euclidean hasStrictFDerivAt_euclidean theorem hasFDerivWithinAt_euclidean : HasFDerivWithinAt f f' t y ↔ ∀ i, HasFDerivWithinAt (fun x => f x i) (EuclideanSpace.proj i ∘L f') t y := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_hasFDerivWithinAt_iff, hasFDerivWithinAt_pi'] rfl #align has_fderiv_within_at_euclidean hasFDerivWithinAt_euclidean theorem contDiffWithinAt_euclidean {n : ℕ∞} : ContDiffWithinAt 𝕜 n f t y ↔ ∀ i, ContDiffWithinAt 𝕜 n (fun x => f x i) t y := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_contDiffWithinAt_iff, contDiffWithinAt_pi] rfl #align cont_diff_within_at_euclidean contDiffWithinAt_euclidean theorem contDiffAt_euclidean {n : ℕ∞} : ContDiffAt 𝕜 n f y ↔ ∀ i, ContDiffAt 𝕜 n (fun x => f x i) y := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_contDiffAt_iff, contDiffAt_pi] rfl #align cont_diff_at_euclidean contDiffAt_euclidean theorem contDiffOn_euclidean {n : ℕ∞} : ContDiffOn 𝕜 n f t ↔ ∀ i, ContDiffOn 𝕜 n (fun x => f x i) t := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_contDiffOn_iff, contDiffOn_pi] rfl #align cont_diff_on_euclidean contDiffOn_euclidean theorem contDiff_euclidean {n : ℕ∞} : ContDiff 𝕜 n f ↔ ∀ i, ContDiff 𝕜 n fun x => f x i := by rw [← (EuclideanSpace.equiv ι 𝕜).comp_contDiff_iff, contDiff_pi] rfl #align cont_diff_euclidean contDiff_euclidean end PiLike section DiffeomorphUnitBall open Metric hiding mem_nhds_iff variable {n : ℕ∞} {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] theorem PartialHomeomorph.contDiff_univUnitBall : ContDiff ℝ n (univUnitBall : E → E) := by suffices ContDiff ℝ n fun x : E => (√(1 + ‖x‖ ^ 2 : ℝ))⁻¹ from this.smul contDiff_id have h : ∀ x : E, (0 : ℝ) < (1 : ℝ) + ‖x‖ ^ 2 := fun x => by positivity refine ContDiff.inv ?_ fun x => Real.sqrt_ne_zero'.mpr (h x) exact (contDiff_const.add <| contDiff_norm_sq ℝ).sqrt fun x => (h x).ne' theorem PartialHomeomorph.contDiffOn_univUnitBall_symm : ContDiffOn ℝ n univUnitBall.symm (ball (0 : E) 1) := fun y hy ↦ by apply ContDiffAt.contDiffWithinAt suffices ContDiffAt ℝ n (fun y : E => (√(1 - ‖y‖ ^ 2 : ℝ))⁻¹) y from this.smul contDiffAt_id have h : (0 : ℝ) < (1 : ℝ) - ‖(y : E)‖ ^ 2 := by rwa [mem_ball_zero_iff, ← _root_.abs_one, ← abs_norm, ← sq_lt_sq, one_pow, ← sub_pos] at hy refine ContDiffAt.inv ?_ (Real.sqrt_ne_zero'.mpr h) refine (contDiffAt_sqrt h.ne').comp y ?_ exact contDiffAt_const.sub (contDiff_norm_sq ℝ).contDiffAt theorem Homeomorph.contDiff_unitBall : ContDiff ℝ n fun x : E => (unitBall x : E) := PartialHomeomorph.contDiff_univUnitBall #align cont_diff_homeomorph_unit_ball Homeomorph.contDiff_unitBall @[deprecated PartialHomeomorph.contDiffOn_univUnitBall_symm] theorem Homeomorph.contDiffOn_unitBall_symm {f : E → E} (h : ∀ (y) (hy : y ∈ ball (0 : E) 1), f y = Homeomorph.unitBall.symm ⟨y, hy⟩) : ContDiffOn ℝ n f <| ball 0 1 := PartialHomeomorph.contDiffOn_univUnitBall_symm.congr h #align cont_diff_on_homeomorph_unit_ball_symm Homeomorph.contDiffOn_unitBall_symm namespace PartialHomeomorph variable {c : E} {r : ℝ} theorem contDiff_unitBallBall (hr : 0 < r) : ContDiff ℝ n (unitBallBall c r hr) := (contDiff_id.const_smul _).add contDiff_const theorem contDiff_unitBallBall_symm (hr : 0 < r) : ContDiff ℝ n (unitBallBall c r hr).symm := (contDiff_id.sub contDiff_const).const_smul _ theorem contDiff_univBall : ContDiff ℝ n (univBall c r) := by unfold univBall; split_ifs with h · exact (contDiff_unitBallBall h).comp contDiff_univUnitBall · exact contDiff_id.add contDiff_const
Mathlib/Analysis/InnerProductSpace/Calculus.lean
420
426
theorem contDiffOn_univBall_symm : ContDiffOn ℝ n (univBall c r).symm (ball c r) := by
unfold univBall; split_ifs with h · refine contDiffOn_univUnitBall_symm.comp (contDiff_unitBallBall_symm h).contDiffOn ?_ rw [← unitBallBall_source c r h, ← unitBallBall_target c r h] apply PartialHomeomorph.symm_mapsTo · exact contDiffOn_id.sub contDiffOn_const
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.LinearAlgebra.Matrix.BilinearForm import Mathlib.LinearAlgebra.Matrix.Charpoly.Minpoly import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.Vandermonde import Mathlib.LinearAlgebra.Trace import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.PrimitiveElement import Mathlib.FieldTheory.Galois import Mathlib.RingTheory.PowerBasis import Mathlib.FieldTheory.Minpoly.MinpolyDiv #align_import ring_theory.trace from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1" /-! # Trace for (finite) ring extensions. Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`, the trace of the linear map given by multiplying by `s` gives information about the roots of the minimal polynomial of `s` over `R`. ## Main definitions * `Algebra.trace R S x`: the trace of an element `s` of an `R`-algebra `S` * `Algebra.traceForm R S`: bilinear form sending `x`, `y` to the trace of `x * y` * `Algebra.traceMatrix R b`: the matrix whose `(i j)`-th element is the trace of `b i * b j`. * `Algebra.embeddingsMatrix A C b : Matrix κ (B →ₐ[A] C) C` is the matrix whose `(i, σ)` coefficient is `σ (b i)`. * `Algebra.embeddingsMatrixReindex A C b e : Matrix κ κ C` is the matrix whose `(i, j)` coefficient is `σⱼ (b i)`, where `σⱼ : B →ₐ[A] C` is the embedding corresponding to `j : κ` given by a bijection `e : κ ≃ (B →ₐ[A] C)`. ## Main results * `trace_algebraMap_of_basis`, `trace_algebraMap`: if `x : K`, then `Tr_{L/K} x = [L : K] x` * `trace_trace_of_basis`, `trace_trace`: `Tr_{L/K} (Tr_{F/L} x) = Tr_{F/K} x` * `trace_eq_sum_roots`: the trace of `x : K(x)` is the sum of all conjugate roots of `x` * `trace_eq_sum_embeddings`: the trace of `x : K(x)` is the sum of all embeddings of `x` into an algebraically closed field * `traceForm_nondegenerate`: the trace form over a separable extension is a nondegenerate bilinear form * `traceForm_dualBasis_powerBasis_eq`: The dual basis of a powerbasis `{1, x, x²...}` under the trace form is `aᵢ / f'(x)`, with `f` being the minpoly of `x` and `f / (X - x) = ∑ aᵢxⁱ`. ## Implementation notes Typically, the trace is defined specifically for finite field extensions. The definition is as general as possible and the assumption that we have fields or that the extension is finite is added to the lemmas as needed. We only define the trace for left multiplication (`Algebra.leftMulMatrix`, i.e. `LinearMap.mulLeft`). For now, the definitions assume `S` is commutative, so the choice doesn't matter anyway. ## References * https://en.wikipedia.org/wiki/Field_trace -/ universe u v w z variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] variable [Algebra R S] [Algebra R T] variable {K L : Type*} [Field K] [Field L] [Algebra K L] variable {ι κ : Type w} [Fintype ι] open FiniteDimensional open LinearMap (BilinForm) open LinearMap open Matrix open scoped Matrix namespace Algebra variable (b : Basis ι R S) variable (R S) /-- The trace of an element `s` of an `R`-algebra is the trace of `(s * ·)`, as an `R`-linear map. -/ noncomputable def trace : S →ₗ[R] R := (LinearMap.trace R S).comp (lmul R S).toLinearMap #align algebra.trace Algebra.trace variable {S} -- Not a `simp` lemma since there are more interesting ways to rewrite `trace R S x`, -- for example `trace_trace` theorem trace_apply (x) : trace R S x = LinearMap.trace R S (lmul R S x) := rfl #align algebra.trace_apply Algebra.trace_apply theorem trace_eq_zero_of_not_exists_basis (h : ¬∃ s : Finset S, Nonempty (Basis s R S)) : trace R S = 0 := by ext s; simp [trace_apply, LinearMap.trace, h] #align algebra.trace_eq_zero_of_not_exists_basis Algebra.trace_eq_zero_of_not_exists_basis variable {R} -- Can't be a `simp` lemma because it depends on a choice of basis theorem trace_eq_matrix_trace [DecidableEq ι] (b : Basis ι R S) (s : S) : trace R S s = Matrix.trace (Algebra.leftMulMatrix b s) := by rw [trace_apply, LinearMap.trace_eq_matrix_trace _ b, ← toMatrix_lmul_eq]; rfl #align algebra.trace_eq_matrix_trace Algebra.trace_eq_matrix_trace /-- If `x` is in the base field `K`, then the trace is `[L : K] * x`. -/ theorem trace_algebraMap_of_basis (x : R) : trace R S (algebraMap R S x) = Fintype.card ι • x := by haveI := Classical.decEq ι rw [trace_apply, LinearMap.trace_eq_matrix_trace R b, Matrix.trace] convert Finset.sum_const x simp [-coe_lmul_eq_mul] #align algebra.trace_algebra_map_of_basis Algebra.trace_algebraMap_of_basis /-- If `x` is in the base field `K`, then the trace is `[L : K] * x`. (If `L` is not finite-dimensional over `K`, then `trace` and `finrank` return `0`.) -/ @[simp] theorem trace_algebraMap (x : K) : trace K L (algebraMap K L x) = finrank K L • x := by by_cases H : ∃ s : Finset L, Nonempty (Basis s K L) · rw [trace_algebraMap_of_basis H.choose_spec.some, finrank_eq_card_basis H.choose_spec.some] · simp [trace_eq_zero_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis_finset H] #align algebra.trace_algebra_map Algebra.trace_algebraMap theorem trace_trace_of_basis [Algebra S T] [IsScalarTower R S T] {ι κ : Type*} [Finite ι] [Finite κ] (b : Basis ι R S) (c : Basis κ S T) (x : T) : trace R S (trace S T x) = trace R T x := by haveI := Classical.decEq ι haveI := Classical.decEq κ cases nonempty_fintype ι cases nonempty_fintype κ rw [trace_eq_matrix_trace (b.smul c), trace_eq_matrix_trace b, trace_eq_matrix_trace c, Matrix.trace, Matrix.trace, Matrix.trace, ← Finset.univ_product_univ, Finset.sum_product] refine Finset.sum_congr rfl fun i _ ↦ ?_ simp only [AlgHom.map_sum, smul_leftMulMatrix, Finset.sum_apply, Matrix.diag, Finset.sum_apply i (Finset.univ : Finset κ) fun y => leftMulMatrix b (leftMulMatrix c x y y)] #align algebra.trace_trace_of_basis Algebra.trace_trace_of_basis theorem trace_comp_trace_of_basis [Algebra S T] [IsScalarTower R S T] {ι κ : Type*} [Finite ι] [Finite κ] (b : Basis ι R S) (c : Basis κ S T) : (trace R S).comp ((trace S T).restrictScalars R) = trace R T := by ext rw [LinearMap.comp_apply, LinearMap.restrictScalars_apply, trace_trace_of_basis b c] #align algebra.trace_comp_trace_of_basis Algebra.trace_comp_trace_of_basis @[simp] theorem trace_trace [Algebra K T] [Algebra L T] [IsScalarTower K L T] [FiniteDimensional K L] [FiniteDimensional L T] (x : T) : trace K L (trace L T x) = trace K T x := trace_trace_of_basis (Basis.ofVectorSpace K L) (Basis.ofVectorSpace L T) x #align algebra.trace_trace Algebra.trace_trace @[simp] theorem trace_comp_trace [Algebra K T] [Algebra L T] [IsScalarTower K L T] [FiniteDimensional K L] [FiniteDimensional L T] : (trace K L).comp ((trace L T).restrictScalars K) = trace K T := by ext; rw [LinearMap.comp_apply, LinearMap.restrictScalars_apply, trace_trace] #align algebra.trace_comp_trace Algebra.trace_comp_trace @[simp] theorem trace_prod_apply [Module.Free R S] [Module.Free R T] [Module.Finite R S] [Module.Finite R T] (x : S × T) : trace R (S × T) x = trace R S x.fst + trace R T x.snd := by nontriviality R let f := (lmul R S).toLinearMap.prodMap (lmul R T).toLinearMap have : (lmul R (S × T)).toLinearMap = (prodMapLinear R S T S T R).comp f := LinearMap.ext₂ Prod.mul_def simp_rw [trace, this] exact trace_prodMap' _ _ #align algebra.trace_prod_apply Algebra.trace_prod_apply theorem trace_prod [Module.Free R S] [Module.Free R T] [Module.Finite R S] [Module.Finite R T] : trace R (S × T) = (trace R S).coprod (trace R T) := LinearMap.ext fun p => by rw [coprod_apply, trace_prod_apply] #align algebra.trace_prod Algebra.trace_prod section TraceForm variable (R S) /-- The `traceForm` maps `x y : S` to the trace of `x * y`. It is a symmetric bilinear form and is nondegenerate if the extension is separable. -/ noncomputable def traceForm : BilinForm R S := LinearMap.compr₂ (lmul R S).toLinearMap (trace R S) #align algebra.trace_form Algebra.traceForm variable {S} -- This is a nicer lemma than the one produced by `@[simps] def traceForm`. @[simp] theorem traceForm_apply (x y : S) : traceForm R S x y = trace R S (x * y) := rfl #align algebra.trace_form_apply Algebra.traceForm_apply theorem traceForm_isSymm : (traceForm R S).IsSymm := fun _ _ => congr_arg (trace R S) (mul_comm _ _) #align algebra.trace_form_is_symm Algebra.traceForm_isSymm theorem traceForm_toMatrix [DecidableEq ι] (i j) : BilinForm.toMatrix b (traceForm R S) i j = trace R S (b i * b j) := by rw [BilinForm.toMatrix_apply, traceForm_apply] #align algebra.trace_form_to_matrix Algebra.traceForm_toMatrix theorem traceForm_toMatrix_powerBasis (h : PowerBasis R S) : BilinForm.toMatrix h.basis (traceForm R S) = of fun i j => trace R S (h.gen ^ (i.1 + j.1)) := by ext; rw [traceForm_toMatrix, of_apply, pow_add, h.basis_eq_pow, h.basis_eq_pow] #align algebra.trace_form_to_matrix_power_basis Algebra.traceForm_toMatrix_powerBasis end TraceForm end Algebra section EqSumRoots open Algebra Polynomial variable {F : Type*} [Field F] variable [Algebra K S] [Algebra K F] /-- Given `pb : PowerBasis K S`, the trace of `pb.gen` is `-(minpoly K pb.gen).nextCoeff`. -/ theorem PowerBasis.trace_gen_eq_nextCoeff_minpoly [Nontrivial S] (pb : PowerBasis K S) : Algebra.trace K S pb.gen = -(minpoly K pb.gen).nextCoeff := by have d_pos : 0 < pb.dim := PowerBasis.dim_pos pb have d_pos' : 0 < (minpoly K pb.gen).natDegree := by simpa haveI : Nonempty (Fin pb.dim) := ⟨⟨0, d_pos⟩⟩ rw [trace_eq_matrix_trace pb.basis, trace_eq_neg_charpoly_coeff, charpoly_leftMulMatrix, ← pb.natDegree_minpoly, Fintype.card_fin, ← nextCoeff_of_natDegree_pos d_pos'] #align power_basis.trace_gen_eq_next_coeff_minpoly PowerBasis.trace_gen_eq_nextCoeff_minpoly /-- Given `pb : PowerBasis K S`, then the trace of `pb.gen` is `((minpoly K pb.gen).aroots F).sum`. -/ theorem PowerBasis.trace_gen_eq_sum_roots [Nontrivial S] (pb : PowerBasis K S) (hf : (minpoly K pb.gen).Splits (algebraMap K F)) : algebraMap K F (trace K S pb.gen) = ((minpoly K pb.gen).aroots F).sum := by rw [PowerBasis.trace_gen_eq_nextCoeff_minpoly, RingHom.map_neg, ← nextCoeff_map (algebraMap K F).injective, sum_roots_eq_nextCoeff_of_monic_of_split ((minpoly.monic (PowerBasis.isIntegral_gen _)).map _) ((splits_id_iff_splits _).2 hf), neg_neg] #align power_basis.trace_gen_eq_sum_roots PowerBasis.trace_gen_eq_sum_roots namespace IntermediateField.AdjoinSimple open IntermediateField theorem trace_gen_eq_zero {x : L} (hx : ¬IsIntegral K x) : Algebra.trace K K⟮x⟯ (AdjoinSimple.gen K x) = 0 := by rw [trace_eq_zero_of_not_exists_basis, LinearMap.zero_apply] contrapose! hx obtain ⟨s, ⟨b⟩⟩ := hx refine .of_mem_of_fg K⟮x⟯.toSubalgebra ?_ x ?_ · exact (Submodule.fg_iff_finiteDimensional _).mpr (FiniteDimensional.of_fintype_basis b) · exact subset_adjoin K _ (Set.mem_singleton x) #align intermediate_field.adjoin_simple.trace_gen_eq_zero IntermediateField.AdjoinSimple.trace_gen_eq_zero theorem trace_gen_eq_sum_roots (x : L) (hf : (minpoly K x).Splits (algebraMap K F)) : algebraMap K F (trace K K⟮x⟯ (AdjoinSimple.gen K x)) = ((minpoly K x).aroots F).sum := by have injKxL := (algebraMap K⟮x⟯ L).injective by_cases hx : IsIntegral K x; swap · simp [minpoly.eq_zero hx, trace_gen_eq_zero hx, aroots_def] rw [← adjoin.powerBasis_gen hx, (adjoin.powerBasis hx).trace_gen_eq_sum_roots] <;> rw [adjoin.powerBasis_gen hx, ← minpoly.algebraMap_eq injKxL] <;> try simp only [AdjoinSimple.algebraMap_gen _ _] exact hf #align intermediate_field.adjoin_simple.trace_gen_eq_sum_roots IntermediateField.AdjoinSimple.trace_gen_eq_sum_roots end IntermediateField.AdjoinSimple open IntermediateField variable (K) theorem trace_eq_trace_adjoin [FiniteDimensional K L] (x : L) : Algebra.trace K L x = finrank K⟮x⟯ L • trace K K⟮x⟯ (AdjoinSimple.gen K x) := by -- Porting note: `conv` was -- `conv in x => rw [← IntermediateField.AdjoinSimple.algebraMap_gen K x]` -- and it was after the first `rw`. conv => lhs rw [← IntermediateField.AdjoinSimple.algebraMap_gen K x] rw [← trace_trace (L := K⟮x⟯), trace_algebraMap, LinearMap.map_smul_of_tower] #align trace_eq_trace_adjoin trace_eq_trace_adjoin variable {K} theorem trace_eq_sum_roots [FiniteDimensional K L] {x : L} (hF : (minpoly K x).Splits (algebraMap K F)) : algebraMap K F (Algebra.trace K L x) = finrank K⟮x⟯ L • ((minpoly K x).aroots F).sum := by rw [trace_eq_trace_adjoin K x, Algebra.smul_def, RingHom.map_mul, ← Algebra.smul_def, IntermediateField.AdjoinSimple.trace_gen_eq_sum_roots _ hF, IsScalarTower.algebraMap_smul] #align trace_eq_sum_roots trace_eq_sum_roots end EqSumRoots variable {F : Type*} [Field F] variable [Algebra R L] [Algebra L F] [Algebra R F] [IsScalarTower R L F] open Polynomial attribute [-instance] Field.toEuclideanDomain theorem Algebra.isIntegral_trace [FiniteDimensional L F] {x : F} (hx : IsIntegral R x) : IsIntegral R (Algebra.trace L F x) := by have hx' : IsIntegral L x := hx.tower_top rw [← isIntegral_algebraMap_iff (algebraMap L (AlgebraicClosure F)).injective, trace_eq_sum_roots] · refine (IsIntegral.multiset_sum ?_).nsmul _ intro y hy rw [mem_roots_map (minpoly.ne_zero hx')] at hy use minpoly R x, minpoly.monic hx rw [← aeval_def] at hy ⊢ exact minpoly.aeval_of_isScalarTower R x y hy · apply IsAlgClosed.splits_codomain #align algebra.is_integral_trace Algebra.isIntegral_trace lemma Algebra.trace_eq_of_algEquiv {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] [Algebra A B] [Algebra A C] (e : B ≃ₐ[A] C) (x) : Algebra.trace A C (e x) = Algebra.trace A B x := by simp_rw [Algebra.trace_apply, ← LinearMap.trace_conj' _ e.toLinearEquiv] congr; ext; simp [LinearEquiv.conj_apply] lemma Algebra.trace_eq_of_ringEquiv {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] [Algebra A C] [Algebra B C] (e : A ≃+* B) (he : (algebraMap B C).comp e = algebraMap A C) (x) : e (Algebra.trace A C x) = Algebra.trace B C x := by classical by_cases h : ∃ s : Finset C, Nonempty (Basis s B C) · obtain ⟨s, ⟨b⟩⟩ := h letI : Algebra A B := RingHom.toAlgebra e letI : IsScalarTower A B C := IsScalarTower.of_algebraMap_eq' he.symm rw [Algebra.trace_eq_matrix_trace b, Algebra.trace_eq_matrix_trace (b.mapCoeffs e.symm (by simp [Algebra.smul_def, ← he]))] show e.toAddMonoidHom _ = _ rw [AddMonoidHom.map_trace] congr ext i j simp [leftMulMatrix_apply, LinearMap.toMatrix_apply] rw [trace_eq_zero_of_not_exists_basis _ h, trace_eq_zero_of_not_exists_basis, LinearMap.zero_apply, LinearMap.zero_apply, map_zero] intro ⟨s, ⟨b⟩⟩ exact h ⟨s, ⟨b.mapCoeffs e (by simp [Algebra.smul_def, ← he])⟩⟩ lemma Algebra.trace_eq_of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [CommRing A₁] [CommRing B₁] [CommRing A₂] [CommRing B₂] [Algebra A₁ B₁] [Algebra A₂ B₂] (e₁ : A₁ ≃+* A₂) (e₂ : B₁ ≃+* B₂) (he : RingHom.comp (algebraMap A₂ B₂) ↑e₁ = RingHom.comp ↑e₂ (algebraMap A₁ B₁)) (x) : Algebra.trace A₁ B₁ x = e₁.symm (Algebra.trace A₂ B₂ (e₂ x)) := by letI := (RingHom.comp (e₂ : B₁ →+* B₂) (algebraMap A₁ B₁)).toAlgebra let e' : B₁ ≃ₐ[A₁] B₂ := { e₂ with commutes' := fun _ ↦ rfl } rw [← Algebra.trace_eq_of_ringEquiv e₁ he, ← Algebra.trace_eq_of_algEquiv e', RingEquiv.symm_apply_apply] rfl section EqSumEmbeddings variable [Algebra K F] [IsScalarTower K L F] open Algebra IntermediateField variable (F) (E : Type*) [Field E] [Algebra K E] theorem trace_eq_sum_embeddings_gen (pb : PowerBasis K L) (hE : (minpoly K pb.gen).Splits (algebraMap K E)) (hfx : (minpoly K pb.gen).Separable) : algebraMap K E (Algebra.trace K L pb.gen) = (@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).sum fun σ => σ pb.gen := by letI := Classical.decEq E -- Porting note: the following `letI` was not needed. letI : Fintype (L →ₐ[K] E) := PowerBasis.AlgHom.fintype pb rw [pb.trace_gen_eq_sum_roots hE, Fintype.sum_equiv pb.liftEquiv', Finset.sum_mem_multiset, Finset.sum_eq_multiset_sum, Multiset.toFinset_val, Multiset.dedup_eq_self.mpr _, Multiset.map_id] · exact nodup_roots ((separable_map _).mpr hfx) -- Porting note: the following goal does not exist in mathlib3. · exact (fun x => x.1) · intro x; rfl · intro σ rw [PowerBasis.liftEquiv'_apply_coe] #align trace_eq_sum_embeddings_gen trace_eq_sum_embeddings_gen variable [IsAlgClosed E] theorem sum_embeddings_eq_finrank_mul [FiniteDimensional K F] [IsSeparable K F] (pb : PowerBasis K L) : ∑ σ : F →ₐ[K] E, σ (algebraMap L F pb.gen) = finrank L F • (@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).sum fun σ : L →ₐ[K] E => σ pb.gen := by haveI : FiniteDimensional L F := FiniteDimensional.right K L F haveI : IsSeparable L F := isSeparable_tower_top_of_isSeparable K L F letI : Fintype (L →ₐ[K] E) := PowerBasis.AlgHom.fintype pb letI : ∀ f : L →ₐ[K] E, Fintype (haveI := f.toRingHom.toAlgebra; AlgHom L F E) := ?_ · rw [Fintype.sum_equiv algHomEquivSigma (fun σ : F →ₐ[K] E => _) fun σ => σ.1 pb.gen, ← Finset.univ_sigma_univ, Finset.sum_sigma, ← Finset.sum_nsmul] · refine Finset.sum_congr rfl fun σ _ => ?_ letI : Algebra L E := σ.toRingHom.toAlgebra -- Porting note: `Finset.card_univ` was inside `simp only`. simp only [Finset.sum_const] congr rw [← AlgHom.card L F E] exact Finset.card_univ (α := F →ₐ[L] E) · intro σ simp only [algHomEquivSigma, Equiv.coe_fn_mk, AlgHom.restrictDomain, AlgHom.comp_apply, IsScalarTower.coe_toAlgHom'] #align sum_embeddings_eq_finrank_mul sum_embeddings_eq_finrank_mul theorem trace_eq_sum_embeddings [FiniteDimensional K L] [IsSeparable K L] {x : L} : algebraMap K E (Algebra.trace K L x) = ∑ σ : L →ₐ[K] E, σ x := by have hx := IsSeparable.isIntegral K x let pb := adjoin.powerBasis hx rw [trace_eq_trace_adjoin K x, Algebra.smul_def, RingHom.map_mul, ← adjoin.powerBasis_gen hx, trace_eq_sum_embeddings_gen E pb (IsAlgClosed.splits_codomain _)] -- Porting note: the following `convert` was `exact`, with `← algebra.smul_def, algebra_map_smul` -- in the previous `rw`. · convert (sum_embeddings_eq_finrank_mul L E pb).symm ext simp · haveI := isSeparable_tower_bot_of_isSeparable K K⟮x⟯ L exact IsSeparable.separable K _ #align trace_eq_sum_embeddings trace_eq_sum_embeddings theorem trace_eq_sum_automorphisms (x : L) [FiniteDimensional K L] [IsGalois K L] : algebraMap K L (Algebra.trace K L x) = ∑ σ : L ≃ₐ[K] L, σ x := by apply NoZeroSMulDivisors.algebraMap_injective L (AlgebraicClosure L) rw [_root_.map_sum (algebraMap L (AlgebraicClosure L))] rw [← Fintype.sum_equiv (Normal.algHomEquivAut K (AlgebraicClosure L) L)] · rw [← trace_eq_sum_embeddings (AlgebraicClosure L)] · simp only [algebraMap_eq_smul_one] -- Porting note: `smul_one_smul` was in the `simp only`. apply smul_one_smul · intro σ simp only [Normal.algHomEquivAut, AlgHom.restrictNormal', Equiv.coe_fn_mk, AlgEquiv.coe_ofBijective, AlgHom.restrictNormal_commutes, id.map_eq_id, RingHom.id_apply] #align trace_eq_sum_automorphisms trace_eq_sum_automorphisms end EqSumEmbeddings section DetNeZero namespace Algebra variable (A : Type u) {B : Type v} (C : Type z) variable [CommRing A] [CommRing B] [Algebra A B] [CommRing C] [Algebra A C] open Finset /-- Given an `A`-algebra `B` and `b`, a `κ`-indexed family of elements of `B`, we define `traceMatrix A b` as the matrix whose `(i j)`-th element is the trace of `b i * b j`. -/ noncomputable def traceMatrix (b : κ → B) : Matrix κ κ A := of fun i j => traceForm A B (b i) (b j) #align algebra.trace_matrix Algebra.traceMatrix -- TODO: set as an equation lemma for `traceMatrix`, see mathlib4#3024 @[simp] theorem traceMatrix_apply (b : κ → B) (i j) : traceMatrix A b i j = traceForm A B (b i) (b j) := rfl #align algebra.trace_matrix_apply Algebra.traceMatrix_apply
Mathlib/RingTheory/Trace.lean
462
463
theorem traceMatrix_reindex {κ' : Type*} (b : Basis κ A B) (f : κ ≃ κ') : traceMatrix A (b.reindex f) = reindex f f (traceMatrix A b) := by
ext (x y); simp
/- 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 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 #align measure_theory.finite_measure.test_against_nn_smul MeasureTheory.FiniteMeasure.testAgainstNN_smul theorem testAgainstNN_lipschitz_estimate (μ : FiniteMeasure Ω) (f g : Ω →ᵇ ℝ≥0) : μ.testAgainstNN f ≤ μ.testAgainstNN g + nndist f g * μ.mass := by simp only [← μ.testAgainstNN_const (nndist f g), ← testAgainstNN_add, ← ENNReal.coe_le_coe, BoundedContinuousFunction.coe_add, const_apply, ENNReal.coe_add, Pi.add_apply, coe_nnreal_ennreal_nndist, testAgainstNN_coe_eq] apply lintegral_mono have le_dist : ∀ ω, dist (f ω) (g ω) ≤ nndist f g := BoundedContinuousFunction.dist_coe_le_dist intro ω have le' : f ω ≤ g ω + nndist f g := by apply (NNReal.le_add_nndist (f ω) (g ω)).trans rw [add_le_add_iff_left] exact dist_le_coe.mp (le_dist ω) have le : (f ω : ℝ≥0∞) ≤ (g ω : ℝ≥0∞) + nndist f g := by rw [← ENNReal.coe_add]; exact ENNReal.coe_mono le' rwa [coe_nnreal_ennreal_nndist] at le #align measure_theory.finite_measure.test_against_nn_lipschitz_estimate MeasureTheory.FiniteMeasure.testAgainstNN_lipschitz_estimate theorem testAgainstNN_lipschitz (μ : FiniteMeasure Ω) : LipschitzWith μ.mass fun f : Ω →ᵇ ℝ≥0 => μ.testAgainstNN f := by rw [lipschitzWith_iff_dist_le_mul] intro f₁ f₂ suffices abs (μ.testAgainstNN f₁ - μ.testAgainstNN f₂ : ℝ) ≤ μ.mass * dist f₁ f₂ by rwa [NNReal.dist_eq] apply abs_le.mpr constructor · have key' := μ.testAgainstNN_lipschitz_estimate f₂ f₁ rw [mul_comm] at key' suffices ↑(μ.testAgainstNN f₂) ≤ ↑(μ.testAgainstNN f₁) + ↑μ.mass * dist f₁ f₂ by linarith have key := NNReal.coe_mono key' rwa [NNReal.coe_add, NNReal.coe_mul, nndist_comm] at key · have key' := μ.testAgainstNN_lipschitz_estimate f₁ f₂ rw [mul_comm] at key' suffices ↑(μ.testAgainstNN f₁) ≤ ↑(μ.testAgainstNN f₂) + ↑μ.mass * dist f₁ f₂ by linarith have key := NNReal.coe_mono key' rwa [NNReal.coe_add, NNReal.coe_mul] at key #align measure_theory.finite_measure.test_against_nn_lipschitz MeasureTheory.FiniteMeasure.testAgainstNN_lipschitz /-- Finite measures yield elements of the `WeakDual` of bounded continuous nonnegative functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/ def toWeakDualBCNN (μ : FiniteMeasure Ω) : WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) where toFun f := μ.testAgainstNN f map_add' := testAgainstNN_add μ map_smul' := testAgainstNN_smul μ cont := μ.testAgainstNN_lipschitz.continuous #align measure_theory.finite_measure.to_weak_dual_bcnn MeasureTheory.FiniteMeasure.toWeakDualBCNN @[simp] theorem coe_toWeakDualBCNN (μ : FiniteMeasure Ω) : ⇑μ.toWeakDualBCNN = μ.testAgainstNN := rfl #align measure_theory.finite_measure.coe_to_weak_dual_bcnn MeasureTheory.FiniteMeasure.coe_toWeakDualBCNN @[simp] theorem toWeakDualBCNN_apply (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) : μ.toWeakDualBCNN f = (∫⁻ x, f x ∂(μ : Measure Ω)).toNNReal := rfl #align measure_theory.finite_measure.to_weak_dual_bcnn_apply MeasureTheory.FiniteMeasure.toWeakDualBCNN_apply /-- The topology of weak convergence on `MeasureTheory.FiniteMeasure Ω` is inherited (induced) from the weak-* topology on `WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)` via the function `MeasureTheory.FiniteMeasure.toWeakDualBCNN`. -/ instance instTopologicalSpace : TopologicalSpace (FiniteMeasure Ω) := TopologicalSpace.induced toWeakDualBCNN inferInstance theorem toWeakDualBCNN_continuous : Continuous (@toWeakDualBCNN Ω _ _ _) := continuous_induced_dom #align measure_theory.finite_measure.to_weak_dual_bcnn_continuous MeasureTheory.FiniteMeasure.toWeakDualBCNN_continuous /-- Integration of (nonnegative bounded continuous) test functions against finite Borel measures depends continuously on the measure. -/ theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) : Continuous fun μ : FiniteMeasure Ω => μ.testAgainstNN f := by show Continuous ((fun φ : WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) => φ f) ∘ toWeakDualBCNN) refine Continuous.comp ?_ (toWeakDualBCNN_continuous (Ω := Ω)) exact WeakBilin.eval_continuous (𝕜 := ℝ≥0) (E := (Ω →ᵇ ℝ≥0) →L[ℝ≥0] ℝ≥0) _ _ /- porting note: without explicitly providing `𝕜` and `E` TC synthesis times out trying to find `Module ℝ≥0 ((Ω →ᵇ ℝ≥0) →L[ℝ≥0] ℝ≥0)`, but it can find it with enough time: `set_option synthInstance.maxHeartbeats 47000` was sufficient. -/ #align measure_theory.finite_measure.continuous_test_against_nn_eval MeasureTheory.FiniteMeasure.continuous_testAgainstNN_eval /-- The total mass of a finite measure depends continuously on the measure. -/ theorem continuous_mass : Continuous fun μ : FiniteMeasure Ω => μ.mass := by simp_rw [← testAgainstNN_one]; exact continuous_testAgainstNN_eval 1 #align measure_theory.finite_measure.continuous_mass MeasureTheory.FiniteMeasure.continuous_mass /-- Convergence of finite measures implies the convergence of their total masses. -/ theorem _root_.Filter.Tendsto.mass {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} (h : Tendsto μs F (𝓝 μ)) : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass) := (continuous_mass.tendsto μ).comp h #align filter.tendsto.mass Filter.Tendsto.mass theorem tendsto_iff_weak_star_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ Tendsto (fun i => (μs i).toWeakDualBCNN) F (𝓝 μ.toWeakDualBCNN) := Inducing.tendsto_nhds_iff ⟨rfl⟩ #align measure_theory.finite_measure.tendsto_iff_weak_star_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_weak_star_tendsto theorem tendsto_iff_forall_toWeakDualBCNN_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => (μs i).toWeakDualBCNN f) F (𝓝 (μ.toWeakDualBCNN f)) := by rw [tendsto_iff_weak_star_tendsto, tendsto_iff_forall_eval_tendsto_topDualPairing]; rfl #align measure_theory.finite_measure.tendsto_iff_forall_to_weak_dual_bcnn_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_forall_toWeakDualBCNN_tendsto theorem tendsto_iff_forall_testAgainstNN_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by rw [FiniteMeasure.tendsto_iff_forall_toWeakDualBCNN_tendsto]; rfl #align measure_theory.finite_measure.tendsto_iff_forall_test_against_nn_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_forall_testAgainstNN_tendsto /-- If the total masses of finite measures tend to zero, then the measures tend to zero. This formulation concerns the associated functionals on bounded continuous nonnegative test functions. See `MeasureTheory.FiniteMeasure.tendsto_zero_of_tendsto_zero_mass` for a formulation stating the weak convergence of measures. -/ theorem tendsto_zero_testAgainstNN_of_tendsto_zero_mass {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 0)) (f : Ω →ᵇ ℝ≥0) : Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 0) := by apply tendsto_iff_dist_tendsto_zero.mpr have obs := fun i => (μs i).testAgainstNN_lipschitz_estimate f 0 simp_rw [testAgainstNN_zero, zero_add] at obs simp_rw [show ∀ i, dist ((μs i).testAgainstNN f) 0 = (μs i).testAgainstNN f by simp only [dist_nndist, NNReal.nndist_zero_eq_val', eq_self_iff_true, imp_true_iff]] refine squeeze_zero (fun i => NNReal.coe_nonneg _) obs ?_ have lim_pair : Tendsto (fun i => (⟨nndist f 0, (μs i).mass⟩ : ℝ × ℝ)) F (𝓝 ⟨nndist f 0, 0⟩) := by refine (Prod.tendsto_iff _ _).mpr ⟨tendsto_const_nhds, ?_⟩ exact (NNReal.continuous_coe.tendsto 0).comp mass_lim have key := tendsto_mul.comp lim_pair rwa [mul_zero] at key #align measure_theory.finite_measure.tendsto_zero_test_against_nn_of_tendsto_zero_mass MeasureTheory.FiniteMeasure.tendsto_zero_testAgainstNN_of_tendsto_zero_mass /-- If the total masses of finite measures tend to zero, then the measures tend to zero. -/ theorem tendsto_zero_of_tendsto_zero_mass {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 0)) : Tendsto μs F (𝓝 0) := by rw [tendsto_iff_forall_testAgainstNN_tendsto] intro f convert tendsto_zero_testAgainstNN_of_tendsto_zero_mass mass_lim f rw [zero_testAgainstNN_apply] #align measure_theory.finite_measure.tendsto_zero_of_tendsto_zero_mass MeasureTheory.FiniteMeasure.tendsto_zero_of_tendsto_zero_mass /-- A characterization of weak convergence in terms of integrals of bounded continuous nonnegative functions. -/ theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => ∫⁻ x, f x ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ x, f x ∂(μ : Measure Ω))) := by rw [tendsto_iff_forall_toWeakDualBCNN_tendsto] simp_rw [toWeakDualBCNN_apply _ _, ← testAgainstNN_coe_eq, ENNReal.tendsto_coe, ENNReal.toNNReal_coe] #align measure_theory.finite_measure.tendsto_iff_forall_lintegral_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_forall_lintegral_tendsto end weak_convergence -- section section Hausdorff variable [HasOuterApproxClosed Ω] [BorelSpace Ω] open Function /-- The mapping `toWeakDualBCNN` from finite Borel measures to the weak dual of `Ω →ᵇ ℝ≥0` is injective, if in the underlying space `Ω`, indicator functions of closed sets have decreasing approximations by sequences of continuous functions (in particular if `Ω` is pseudometrizable). -/ lemma injective_toWeakDualBCNN : Injective (toWeakDualBCNN : FiniteMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)) := by intro μ ν hμν apply ext_of_forall_lintegral_eq intro f have key := congr_fun (congrArg DFunLike.coe hμν) f apply (ENNReal.toNNReal_eq_toNNReal_iff' ?_ ?_).mp key · exact (lintegral_lt_top_of_nnreal μ f).ne · exact (lintegral_lt_top_of_nnreal ν f).ne variable (Ω) lemma embedding_toWeakDualBCNN : Embedding (toWeakDualBCNN : FiniteMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)) where induced := rfl inj := injective_toWeakDualBCNN /-- On topological spaces where indicators of closed sets have decreasing approximating sequences of continuous functions (`HasOuterApproxClosed`), the topology of weak convergence of finite Borel measures is Hausdorff (`T2Space`). -/ instance t2Space : T2Space (FiniteMeasure Ω) := Embedding.t2Space (embedding_toWeakDualBCNN Ω) end Hausdorff -- section end FiniteMeasure -- section section FiniteMeasureBoundedConvergence /-! ### Bounded convergence results for finite measures This section is about bounded convergence theorems for finite measures. -/ variable {Ω : Type*} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] /-- A bounded convergence theorem for a finite measure: If a sequence of bounded continuous non-negative functions are uniformly bounded by a constant and tend pointwise to a limit, then their integrals (`MeasureTheory.lintegral`) against the finite measure tend to the integral of the limit. A related result with more general assumptions is `MeasureTheory.tendsto_lintegral_nn_filter_of_le_const`. -/ theorem tendsto_lintegral_nn_of_le_const (μ : FiniteMeasure Ω) {fs : ℕ → Ω →ᵇ ℝ≥0} {c : ℝ≥0} (fs_le_const : ∀ n ω, fs n ω ≤ c) {f : Ω → ℝ≥0} (fs_lim : ∀ ω, Tendsto (fun n => fs n ω) atTop (𝓝 (f ω))) : Tendsto (fun n => ∫⁻ ω, fs n ω ∂(μ : Measure Ω)) atTop (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) := tendsto_lintegral_nn_filter_of_le_const μ (eventually_of_forall fun n => eventually_of_forall (fs_le_const n)) (eventually_of_forall fs_lim) #align measure_theory.finite_measure.tendsto_lintegral_nn_of_le_const MeasureTheory.FiniteMeasure.tendsto_lintegral_nn_of_le_const /-- A bounded convergence theorem for a finite measure: If bounded continuous non-negative functions are uniformly bounded by a constant and tend to a limit, then their integrals against the finite measure tend to the integral of the limit. This formulation assumes: * the functions tend to a limit along a countably generated filter; * the limit is in the almost everywhere sense; * boundedness holds almost everywhere; * integration is the pairing against non-negative continuous test functions (`MeasureTheory.FiniteMeasure.testAgainstNN`). A related result using `MeasureTheory.lintegral` for integration is `MeasureTheory.FiniteMeasure.tendsto_lintegral_nn_filter_of_le_const`. -/ theorem tendsto_testAgainstNN_filter_of_le_const {ι : Type*} {L : Filter ι} [L.IsCountablyGenerated] {μ : FiniteMeasure Ω} {fs : ι → Ω →ᵇ ℝ≥0} {c : ℝ≥0} (fs_le_const : ∀ᶠ i in L, ∀ᵐ ω : Ω ∂(μ : Measure Ω), fs i ω ≤ c) {f : Ω →ᵇ ℝ≥0} (fs_lim : ∀ᵐ ω : Ω ∂(μ : Measure Ω), Tendsto (fun i => fs i ω) L (𝓝 (f ω))) : Tendsto (fun i => μ.testAgainstNN (fs i)) L (𝓝 (μ.testAgainstNN f)) := by apply (ENNReal.tendsto_toNNReal (f.lintegral_lt_top_of_nnreal (μ : Measure Ω)).ne).comp exact tendsto_lintegral_nn_filter_of_le_const μ fs_le_const fs_lim #align measure_theory.finite_measure.tendsto_test_against_nn_filter_of_le_const MeasureTheory.FiniteMeasure.tendsto_testAgainstNN_filter_of_le_const /-- A bounded convergence theorem for a finite measure: If a sequence of bounded continuous non-negative functions are uniformly bounded by a constant and tend pointwise to a limit, then their integrals (`MeasureTheory.FiniteMeasure.testAgainstNN`) against the finite measure tend to the integral of the limit. Related results: * `MeasureTheory.FiniteMeasure.tendsto_testAgainstNN_filter_of_le_const`: more general assumptions * `MeasureTheory.FiniteMeasure.tendsto_lintegral_nn_of_le_const`: using `MeasureTheory.lintegral` for integration. -/ theorem tendsto_testAgainstNN_of_le_const {μ : FiniteMeasure Ω} {fs : ℕ → Ω →ᵇ ℝ≥0} {c : ℝ≥0} (fs_le_const : ∀ n ω, fs n ω ≤ c) {f : Ω →ᵇ ℝ≥0} (fs_lim : ∀ ω, Tendsto (fun n => fs n ω) atTop (𝓝 (f ω))) : Tendsto (fun n => μ.testAgainstNN (fs n)) atTop (𝓝 (μ.testAgainstNN f)) := tendsto_testAgainstNN_filter_of_le_const (eventually_of_forall fun n => eventually_of_forall (fs_le_const n)) (eventually_of_forall fs_lim) #align measure_theory.finite_measure.tendsto_test_against_nn_of_le_const MeasureTheory.FiniteMeasure.tendsto_testAgainstNN_of_le_const end FiniteMeasureBoundedConvergence -- section section FiniteMeasureConvergenceByBoundedContinuousFunctions /-! ### Weak convergence of finite measures with bounded continuous real-valued functions In this section we characterize the weak convergence of finite measures by the usual (defining) condition that the integrals of all bounded continuous real-valued functions converge. -/ variable {Ω : Type*} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] theorem tendsto_of_forall_integral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} (h : ∀ f : Ω →ᵇ ℝ, Tendsto (fun i => ∫ x, f x ∂(μs i : Measure Ω)) F (𝓝 (∫ x, f x ∂(μ : Measure Ω)))) : Tendsto μs F (𝓝 μ) := by apply (@tendsto_iff_forall_lintegral_tendsto Ω _ _ _ γ F μs μ).mpr intro f have key := @ENNReal.tendsto_toReal_iff _ F _ (fun i => (f.lintegral_lt_top_of_nnreal (μs i)).ne) _ (f.lintegral_lt_top_of_nnreal μ).ne simp only [ENNReal.ofReal_coe_nnreal] at key apply key.mp have lip : LipschitzWith 1 ((↑) : ℝ≥0 → ℝ) := isometry_subtype_coe.lipschitz set f₀ := BoundedContinuousFunction.comp _ lip f with _def_f₀ have f₀_eq : ⇑f₀ = ((↑) : ℝ≥0 → ℝ) ∘ ⇑f := rfl have f₀_nn : 0 ≤ ⇑f₀ := fun _ => by simp only [f₀_eq, Pi.zero_apply, Function.comp_apply, NNReal.zero_le_coe] have f₀_ae_nn : 0 ≤ᵐ[(μ : Measure Ω)] ⇑f₀ := eventually_of_forall f₀_nn have f₀_ae_nns : ∀ i, 0 ≤ᵐ[(μs i : Measure Ω)] ⇑f₀ := fun i => eventually_of_forall f₀_nn have aux := integral_eq_lintegral_of_nonneg_ae f₀_ae_nn f₀.continuous.measurable.aestronglyMeasurable have auxs := fun i => integral_eq_lintegral_of_nonneg_ae (f₀_ae_nns i) f₀.continuous.measurable.aestronglyMeasurable simp_rw [f₀_eq, Function.comp_apply, ENNReal.ofReal_coe_nnreal] at aux auxs simpa only [← aux, ← auxs] using h f₀ #align measure_theory.finite_measure.tendsto_of_forall_integral_tendsto MeasureTheory.FiniteMeasure.tendsto_of_forall_integral_tendsto /-- A characterization of weak convergence in terms of integrals of bounded continuous real-valued functions. -/
Mathlib/MeasureTheory/Measure/FiniteMeasure.lean
711
730
theorem tendsto_iff_forall_integral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ, Tendsto (fun i => ∫ x, f x ∂(μs i : Measure Ω)) F (𝓝 (∫ x, f x ∂(μ : Measure Ω))) := by
refine ⟨?_, tendsto_of_forall_integral_tendsto⟩ rw [tendsto_iff_forall_lintegral_tendsto] intro h f simp_rw [BoundedContinuousFunction.integral_eq_integral_nnrealPart_sub] set f_pos := f.nnrealPart with _def_f_pos set f_neg := (-f).nnrealPart with _def_f_neg have tends_pos := (ENNReal.tendsto_toReal (f_pos.lintegral_lt_top_of_nnreal μ).ne).comp (h f_pos) have tends_neg := (ENNReal.tendsto_toReal (f_neg.lintegral_lt_top_of_nnreal μ).ne).comp (h f_neg) have aux : ∀ g : Ω →ᵇ ℝ≥0, (ENNReal.toReal ∘ fun i : γ => ∫⁻ x : Ω, ↑(g x) ∂(μs i : Measure Ω)) = fun i : γ => (∫⁻ x : Ω, ↑(g x) ∂(μs i : Measure Ω)).toReal := fun _ => rfl simp_rw [aux, BoundedContinuousFunction.toReal_lintegral_coe_eq_integral] at tends_pos tends_neg exact Tendsto.sub tends_pos tends_neg
/- Copyright (c) 2019 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign #align_import analysis.special_functions.trigonometric.angle from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real -- Porting note: can't derive `NormedAddCommGroup, Inhabited` /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) #align real.angle Real.Angle namespace Angle -- Porting note (#10754): added due to missing instances due to no deriving instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) -- Porting note (#10754): added due to missing instances due to no deriving instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) -- Porting note (#10754): added due to missing instances due to no deriving -- also, without this, a plain `QuotientAddGroup.mk` -- causes coerced terms to be of type `ℝ ⧸ AddSubgroup.zmultiples (2 * π)` /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ → Angle) := continuous_quotient_mk' #align real.angle.continuous_coe Real.Angle.continuous_coe /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ #align real.angle.coe_hom Real.Angle.coeHom @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl #align real.angle.coe_coe_hom Real.Angle.coe_coeHom /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction θ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ := Quotient.inductionOn' θ h #align real.angle.induction_on Real.Angle.induction_on @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl #align real.angle.coe_zero Real.Angle.coe_zero @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl #align real.angle.coe_add Real.Angle.coe_add @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl #align real.angle.coe_neg Real.Angle.coe_neg @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl #align real.angle.coe_sub Real.Angle.coe_sub theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl #align real.angle.coe_nsmul Real.Angle.coe_nsmul theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl #align real.angle.coe_zsmul Real.Angle.coe_zsmul @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n #align real.angle.coe_nat_mul_eq_nsmul Real.Angle.natCast_mul_eq_nsmul @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n #align real.angle.coe_int_mul_eq_zsmul Real.Angle.intCast_mul_eq_zsmul @[deprecated (since := "2024-05-25")] alias coe_nat_mul_eq_nsmul := natCast_mul_eq_nsmul @[deprecated (since := "2024-05-25")] alias coe_int_mul_eq_zsmul := intCast_mul_eq_zsmul theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] -- Porting note: added `rw`, `simp [Angle.coe, QuotientAddGroup.eq]` doesn't fire otherwise rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] #align real.angle.angle_eq_iff_two_pi_dvd_sub Real.Angle.angle_eq_iff_two_pi_dvd_sub @[simp] theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ #align real.angle.coe_two_pi Real.Angle.coe_two_pi @[simp] theorem neg_coe_pi : -(π : Angle) = π := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] #align real.angle.neg_coe_pi Real.Angle.neg_coe_pi @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] #align real.angle.two_nsmul_coe_div_two Real.Angle.two_nsmul_coe_div_two @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] #align real.angle.two_zsmul_coe_div_two Real.Angle.two_zsmul_coe_div_two -- Porting note (#10618): @[simp] can prove it theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] #align real.angle.two_nsmul_neg_pi_div_two Real.Angle.two_nsmul_neg_pi_div_two -- Porting note (#10618): @[simp] can prove it theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] #align real.angle.two_zsmul_neg_pi_div_two Real.Angle.two_zsmul_neg_pi_div_two theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] #align real.angle.sub_coe_pi_eq_add_coe_pi Real.Angle.sub_coe_pi_eq_add_coe_pi @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] #align real.angle.two_nsmul_coe_pi Real.Angle.two_nsmul_coe_pi @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] #align real.angle.two_zsmul_coe_pi Real.Angle.two_zsmul_coe_pi @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] #align real.angle.coe_pi_add_coe_pi Real.Angle.coe_pi_add_coe_pi theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) : z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz #align real.angle.zsmul_eq_iff Real.Angle.zsmul_eq_iff theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz #align real.angle.nsmul_eq_iff Real.Angle.nsmul_eq_iff theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by -- Porting note: no `Int.natAbs_bit0` anymore have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_left₀ (_ : ℝ) two_ne_zero] #align real.angle.two_zsmul_eq_iff Real.Angle.two_zsmul_eq_iff theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] #align real.angle.two_nsmul_eq_iff Real.Angle.two_nsmul_eq_iff theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp #align real.angle.two_nsmul_eq_zero_iff Real.Angle.two_nsmul_eq_zero_iff theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] #align real.angle.two_nsmul_ne_zero_iff Real.Angle.two_nsmul_ne_zero_iff theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] #align real.angle.two_zsmul_eq_zero_iff Real.Angle.two_zsmul_eq_zero_iff theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_zsmul_eq_zero_iff] #align real.angle.two_zsmul_ne_zero_iff Real.Angle.two_zsmul_ne_zero_iff theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] #align real.angle.eq_neg_self_iff Real.Angle.eq_neg_self_iff theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← eq_neg_self_iff.not] #align real.angle.ne_neg_self_iff Real.Angle.ne_neg_self_iff theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff] #align real.angle.neg_eq_self_iff Real.Angle.neg_eq_self_iff theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← neg_eq_self_iff.not] #align real.angle.neg_ne_self_iff Real.Angle.neg_ne_self_iff theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ) :) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] #align real.angle.two_nsmul_eq_pi_iff Real.Angle.two_nsmul_eq_pi_iff theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] #align real.angle.two_zsmul_eq_pi_iff Real.Angle.two_zsmul_eq_pi_iff theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by constructor · intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or_iff, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) · right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] · left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] · rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] #align real.angle.cos_eq_iff_coe_eq_or_eq_neg Real.Angle.cos_eq_iff_coe_eq_or_eq_neg theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by constructor · intro Hsin rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h h · left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm · rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] have H' : θ + ψ = 2 * k * π + π := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] #align real.angle.sin_eq_iff_coe_eq_or_add_eq_pi Real.Angle.sin_eq_iff_coe_eq_or_add_eq_pi theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc hc; · exact hc cases' sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs hs; · exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false_iff, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn rw [add_comm, Int.add_mul_emod_self] at this exact absurd this one_ne_zero #align real.angle.cos_sin_inj Real.Angle.cos_sin_inj /-- The sine of a `Real.Angle`. -/ def sin (θ : Angle) : ℝ := sin_periodic.lift θ #align real.angle.sin Real.Angle.sin @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl #align real.angle.sin_coe Real.Angle.sin_coe @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ #align real.angle.continuous_sin Real.Angle.continuous_sin /-- The cosine of a `Real.Angle`. -/ def cos (θ : Angle) : ℝ := cos_periodic.lift θ #align real.angle.cos Real.Angle.cos @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl #align real.angle.cos_coe Real.Angle.cos_coe @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ #align real.angle.continuous_cos Real.Angle.continuous_cos theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} : cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction θ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg #align real.angle.cos_eq_real_cos_iff_eq_or_eq_neg Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg #align real.angle.cos_eq_iff_eq_or_eq_neg Real.Angle.cos_eq_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} : sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction θ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi #align real.angle.sin_eq_real_sin_iff_eq_or_add_eq_pi Real.Angle.sin_eq_real_sin_iff_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi #align real.angle.sin_eq_iff_eq_or_add_eq_pi Real.Angle.sin_eq_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] #align real.angle.sin_zero Real.Angle.sin_zero -- Porting note (#10618): @[simp] can prove it theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi] #align real.angle.sin_coe_pi Real.Angle.sin_coe_pi theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp #align real.angle.sin_eq_zero_iff Real.Angle.sin_eq_zero_iff theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← sin_eq_zero_iff] #align real.angle.sin_ne_zero_iff Real.Angle.sin_ne_zero_iff @[simp] theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.sin_neg _ #align real.angle.sin_neg Real.Angle.sin_neg theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.sin_antiperiodic _ #align real.angle.sin_antiperiodic Real.Angle.sin_antiperiodic @[simp] theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ := sin_antiperiodic θ #align real.angle.sin_add_pi Real.Angle.sin_add_pi @[simp] theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ := sin_antiperiodic.sub_eq θ #align real.angle.sin_sub_pi Real.Angle.sin_sub_pi @[simp] theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero] #align real.angle.cos_zero Real.Angle.cos_zero -- Porting note (#10618): @[simp] can prove it theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi] #align real.angle.cos_coe_pi Real.Angle.cos_coe_pi @[simp] theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.cos_neg _ #align real.angle.cos_neg Real.Angle.cos_neg theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.cos_antiperiodic _ #align real.angle.cos_antiperiodic Real.Angle.cos_antiperiodic @[simp] theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ := cos_antiperiodic θ #align real.angle.cos_add_pi Real.Angle.cos_add_pi @[simp] theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ := cos_antiperiodic.sub_eq θ #align real.angle.cos_sub_pi Real.Angle.cos_sub_pi theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div] #align real.angle.cos_eq_zero_iff Real.Angle.cos_eq_zero_iff theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by induction θ₁ using Real.Angle.induction_on induction θ₂ using Real.Angle.induction_on exact Real.sin_add _ _ #align real.angle.sin_add Real.Angle.sin_add theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by induction θ₂ using Real.Angle.induction_on induction θ₁ using Real.Angle.induction_on exact Real.cos_add _ _ #align real.angle.cos_add Real.Angle.cos_add @[simp] theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by induction θ using Real.Angle.induction_on exact Real.cos_sq_add_sin_sq _ #align real.angle.cos_sq_add_sin_sq Real.Angle.cos_sq_add_sin_sq theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_add_pi_div_two _ #align real.angle.sin_add_pi_div_two Real.Angle.sin_add_pi_div_two theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_sub_pi_div_two _ #align real.angle.sin_sub_pi_div_two Real.Angle.sin_sub_pi_div_two theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_pi_div_two_sub _ #align real.angle.sin_pi_div_two_sub Real.Angle.sin_pi_div_two_sub theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_add_pi_div_two _ #align real.angle.cos_add_pi_div_two Real.Angle.cos_add_pi_div_two theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_sub_pi_div_two _ #align real.angle.cos_sub_pi_div_two Real.Angle.cos_sub_pi_div_two theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_pi_div_two_sub _ #align real.angle.cos_pi_div_two_sub Real.Angle.cos_pi_div_two_sub theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |sin θ| = |sin ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [sin_add_pi, abs_neg] #align real.angle.abs_sin_eq_of_two_nsmul_eq Real.Angle.abs_sin_eq_of_two_nsmul_eq theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |sin θ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_sin_eq_of_two_nsmul_eq h #align real.angle.abs_sin_eq_of_two_zsmul_eq Real.Angle.abs_sin_eq_of_two_zsmul_eq theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |cos θ| = |cos ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [cos_add_pi, abs_neg] #align real.angle.abs_cos_eq_of_two_nsmul_eq Real.Angle.abs_cos_eq_of_two_nsmul_eq theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |cos θ| = |cos ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_of_two_nsmul_eq h #align real.angle.abs_cos_eq_of_two_zsmul_eq Real.Angle.abs_cos_eq_of_two_zsmul_eq @[simp] theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩ rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm] #align real.angle.coe_to_Ico_mod Real.Angle.coe_toIcoMod @[simp] theorem coe_toIocMod (θ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIocDiv two_pi_pos ψ θ, ?_⟩ rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm] #align real.angle.coe_to_Ioc_mod Real.Angle.coe_toIocMod /-- Convert a `Real.Angle` to a real number in the interval `Ioc (-π) π`. -/ def toReal (θ : Angle) : ℝ := (toIocMod_periodic two_pi_pos (-π)).lift θ #align real.angle.to_real Real.Angle.toReal theorem toReal_coe (θ : ℝ) : (θ : Angle).toReal = toIocMod two_pi_pos (-π) θ := rfl #align real.angle.to_real_coe Real.Angle.toReal_coe theorem toReal_coe_eq_self_iff {θ : ℝ} : (θ : Angle).toReal = θ ↔ -π < θ ∧ θ ≤ π := by rw [toReal_coe, toIocMod_eq_self two_pi_pos] ring_nf rfl #align real.angle.to_real_coe_eq_self_iff Real.Angle.toReal_coe_eq_self_iff theorem toReal_coe_eq_self_iff_mem_Ioc {θ : ℝ} : (θ : Angle).toReal = θ ↔ θ ∈ Set.Ioc (-π) π := by rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc] #align real.angle.to_real_coe_eq_self_iff_mem_Ioc Real.Angle.toReal_coe_eq_self_iff_mem_Ioc theorem toReal_injective : Function.Injective toReal := by intro θ ψ h induction θ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * π), ← angle_eq_iff_two_pi_dvd_sub, eq_comm] using h #align real.angle.to_real_injective Real.Angle.toReal_injective @[simp] theorem toReal_inj {θ ψ : Angle} : θ.toReal = ψ.toReal ↔ θ = ψ := toReal_injective.eq_iff #align real.angle.to_real_inj Real.Angle.toReal_inj @[simp] theorem coe_toReal (θ : Angle) : (θ.toReal : Angle) = θ := by induction θ using Real.Angle.induction_on exact coe_toIocMod _ _ #align real.angle.coe_to_real Real.Angle.coe_toReal theorem neg_pi_lt_toReal (θ : Angle) : -π < θ.toReal := by induction θ using Real.Angle.induction_on exact left_lt_toIocMod _ _ _ #align real.angle.neg_pi_lt_to_real Real.Angle.neg_pi_lt_toReal theorem toReal_le_pi (θ : Angle) : θ.toReal ≤ π := by induction θ using Real.Angle.induction_on convert toIocMod_le_right two_pi_pos _ _ ring #align real.angle.to_real_le_pi Real.Angle.toReal_le_pi theorem abs_toReal_le_pi (θ : Angle) : |θ.toReal| ≤ π := abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩ #align real.angle.abs_to_real_le_pi Real.Angle.abs_toReal_le_pi theorem toReal_mem_Ioc (θ : Angle) : θ.toReal ∈ Set.Ioc (-π) π := ⟨neg_pi_lt_toReal _, toReal_le_pi _⟩ #align real.angle.to_real_mem_Ioc Real.Angle.toReal_mem_Ioc @[simp] theorem toIocMod_toReal (θ : Angle) : toIocMod two_pi_pos (-π) θ.toReal = θ.toReal := by induction θ using Real.Angle.induction_on rw [toReal_coe] exact toIocMod_toIocMod _ _ _ _ #align real.angle.to_Ioc_mod_to_real Real.Angle.toIocMod_toReal @[simp] theorem toReal_zero : (0 : Angle).toReal = 0 := by rw [← coe_zero, toReal_coe_eq_self_iff] exact ⟨Left.neg_neg_iff.2 Real.pi_pos, Real.pi_pos.le⟩ #align real.angle.to_real_zero Real.Angle.toReal_zero @[simp] theorem toReal_eq_zero_iff {θ : Angle} : θ.toReal = 0 ↔ θ = 0 := by nth_rw 1 [← toReal_zero] exact toReal_inj #align real.angle.to_real_eq_zero_iff Real.Angle.toReal_eq_zero_iff @[simp]
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
598
600
theorem toReal_pi : (π : Angle).toReal = π := by
rw [toReal_coe_eq_self_iff] exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker, Aaron Anderson -/ import Mathlib.Algebra.BigOperators.Associated import Mathlib.Algebra.GCDMonoid.Basic import Mathlib.Data.Finsupp.Multiset import Mathlib.Data.Nat.Factors import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.Multiplicity #align_import ring_theory.unique_factorization_domain from "leanprover-community/mathlib"@"570e9f4877079b3a923135b3027ac3be8695ab8c" /-! # Unique factorization ## Main Definitions * `WfDvdMonoid` holds for `Monoid`s for which a strict divisibility relation is well-founded. * `UniqueFactorizationMonoid` holds for `WfDvdMonoid`s where `Irreducible` is equivalent to `Prime` ## To do * set up the complete lattice structure on `FactorSet`. -/ variable {α : Type*} local infixl:50 " ~ᵤ " => Associated /-- Well-foundedness of the strict version of |, which is equivalent to the descending chain condition on divisibility and to the ascending chain condition on principal ideals in an integral domain. -/ class WfDvdMonoid (α : Type*) [CommMonoidWithZero α] : Prop where wellFounded_dvdNotUnit : WellFounded (@DvdNotUnit α _) #align wf_dvd_monoid WfDvdMonoid export WfDvdMonoid (wellFounded_dvdNotUnit) -- see Note [lower instance priority] instance (priority := 100) IsNoetherianRing.wfDvdMonoid [CommRing α] [IsDomain α] [IsNoetherianRing α] : WfDvdMonoid α := ⟨by convert InvImage.wf (fun a => Ideal.span ({a} : Set α)) (wellFounded_submodule_gt _ _) ext exact Ideal.span_singleton_lt_span_singleton.symm⟩ #align is_noetherian_ring.wf_dvd_monoid IsNoetherianRing.wfDvdMonoid namespace WfDvdMonoid variable [CommMonoidWithZero α] open Associates Nat theorem of_wfDvdMonoid_associates (_ : WfDvdMonoid (Associates α)) : WfDvdMonoid α := ⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).2 wellFounded_dvdNotUnit⟩ #align wf_dvd_monoid.of_wf_dvd_monoid_associates WfDvdMonoid.of_wfDvdMonoid_associates variable [WfDvdMonoid α] instance wfDvdMonoid_associates : WfDvdMonoid (Associates α) := ⟨(mk_surjective.wellFounded_iff mk_dvdNotUnit_mk_iff.symm).1 wellFounded_dvdNotUnit⟩ #align wf_dvd_monoid.wf_dvd_monoid_associates WfDvdMonoid.wfDvdMonoid_associates theorem wellFounded_associates : WellFounded ((· < ·) : Associates α → Associates α → Prop) := Subrelation.wf dvdNotUnit_of_lt wellFounded_dvdNotUnit #align wf_dvd_monoid.well_founded_associates WfDvdMonoid.wellFounded_associates -- Porting note: elab_as_elim can only be global and cannot be changed on an imported decl -- attribute [local elab_as_elim] WellFounded.fix theorem exists_irreducible_factor {a : α} (ha : ¬IsUnit a) (ha0 : a ≠ 0) : ∃ i, Irreducible i ∧ i ∣ a := let ⟨b, hs, hr⟩ := wellFounded_dvdNotUnit.has_min { b | b ∣ a ∧ ¬IsUnit b } ⟨a, dvd_rfl, ha⟩ ⟨b, ⟨hs.2, fun c d he => let h := dvd_trans ⟨d, he⟩ hs.1 or_iff_not_imp_left.2 fun hc => of_not_not fun hd => hr c ⟨h, hc⟩ ⟨ne_zero_of_dvd_ne_zero ha0 h, d, hd, he⟩⟩, hs.1⟩ #align wf_dvd_monoid.exists_irreducible_factor WfDvdMonoid.exists_irreducible_factor @[elab_as_elim] theorem induction_on_irreducible {P : α → Prop} (a : α) (h0 : P 0) (hu : ∀ u : α, IsUnit u → P u) (hi : ∀ a i : α, a ≠ 0 → Irreducible i → P a → P (i * a)) : P a := haveI := Classical.dec wellFounded_dvdNotUnit.fix (fun a ih => if ha0 : a = 0 then ha0.substr h0 else if hau : IsUnit a then hu a hau else let ⟨i, hii, b, hb⟩ := exists_irreducible_factor hau ha0 let hb0 : b ≠ 0 := ne_zero_of_dvd_ne_zero ha0 ⟨i, mul_comm i b ▸ hb⟩ hb.symm ▸ hi b i hb0 hii <| ih b ⟨hb0, i, hii.1, mul_comm i b ▸ hb⟩) a #align wf_dvd_monoid.induction_on_irreducible WfDvdMonoid.induction_on_irreducible theorem exists_factors (a : α) : a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ Associated f.prod a := induction_on_irreducible a (fun h => (h rfl).elim) (fun u hu _ => ⟨0, fun _ h => False.elim (Multiset.not_mem_zero _ h), hu.unit, one_mul _⟩) fun a i ha0 hi ih _ => let ⟨s, hs⟩ := ih ha0 ⟨i ::ₘ s, fun b H => (Multiset.mem_cons.1 H).elim (fun h => h.symm ▸ hi) (hs.1 b), by rw [s.prod_cons i] exact hs.2.mul_left i⟩ #align wf_dvd_monoid.exists_factors WfDvdMonoid.exists_factors theorem not_unit_iff_exists_factors_eq (a : α) (hn0 : a ≠ 0) : ¬IsUnit a ↔ ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod = a ∧ f ≠ ∅ := ⟨fun hnu => by obtain ⟨f, hi, u, rfl⟩ := exists_factors a hn0 obtain ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero fun h : f = 0 => hnu <| by simp [h] classical refine ⟨(f.erase b).cons (b * u), fun a ha => ?_, ?_, Multiset.cons_ne_zero⟩ · obtain rfl | ha := Multiset.mem_cons.1 ha exacts [Associated.irreducible ⟨u, rfl⟩ (hi b h), hi a (Multiset.mem_of_mem_erase ha)] · rw [Multiset.prod_cons, mul_comm b, mul_assoc, Multiset.prod_erase h, mul_comm], fun ⟨f, hi, he, hne⟩ => let ⟨b, h⟩ := Multiset.exists_mem_of_ne_zero hne not_isUnit_of_not_isUnit_dvd (hi b h).not_unit <| he ▸ Multiset.dvd_prod h⟩ #align wf_dvd_monoid.not_unit_iff_exists_factors_eq WfDvdMonoid.not_unit_iff_exists_factors_eq theorem isRelPrime_of_no_irreducible_factors {x y : α} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z : α, Irreducible z → z ∣ x → ¬z ∣ y) : IsRelPrime x y := isRelPrime_of_no_nonunits_factors nonzero fun _z znu znz zx zy ↦ have ⟨i, h1, h2⟩ := exists_irreducible_factor znu znz H i h1 (h2.trans zx) (h2.trans zy) end WfDvdMonoid theorem WfDvdMonoid.of_wellFounded_associates [CancelCommMonoidWithZero α] (h : WellFounded ((· < ·) : Associates α → Associates α → Prop)) : WfDvdMonoid α := WfDvdMonoid.of_wfDvdMonoid_associates ⟨by convert h ext exact Associates.dvdNotUnit_iff_lt⟩ #align wf_dvd_monoid.of_well_founded_associates WfDvdMonoid.of_wellFounded_associates theorem WfDvdMonoid.iff_wellFounded_associates [CancelCommMonoidWithZero α] : WfDvdMonoid α ↔ WellFounded ((· < ·) : Associates α → Associates α → Prop) := ⟨by apply WfDvdMonoid.wellFounded_associates, WfDvdMonoid.of_wellFounded_associates⟩ #align wf_dvd_monoid.iff_well_founded_associates WfDvdMonoid.iff_wellFounded_associates theorem WfDvdMonoid.max_power_factor' [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α} (h : a₀ ≠ 0) (hx : ¬IsUnit x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a := by obtain ⟨a, ⟨n, rfl⟩, hm⟩ := wellFounded_dvdNotUnit.has_min {a | ∃ n, x ^ n * a = a₀} ⟨a₀, 0, by rw [pow_zero, one_mul]⟩ refine ⟨n, a, ?_, rfl⟩; rintro ⟨d, rfl⟩ exact hm d ⟨n + 1, by rw [pow_succ, mul_assoc]⟩ ⟨(right_ne_zero_of_mul <| right_ne_zero_of_mul h), x, hx, mul_comm _ _⟩ theorem WfDvdMonoid.max_power_factor [CommMonoidWithZero α] [WfDvdMonoid α] {a₀ x : α} (h : a₀ ≠ 0) (hx : Irreducible x) : ∃ (n : ℕ) (a : α), ¬x ∣ a ∧ a₀ = x ^ n * a := max_power_factor' h hx.not_unit theorem multiplicity.finite_of_not_isUnit [CancelCommMonoidWithZero α] [WfDvdMonoid α] {a b : α} (ha : ¬IsUnit a) (hb : b ≠ 0) : multiplicity.Finite a b := by obtain ⟨n, c, ndvd, rfl⟩ := WfDvdMonoid.max_power_factor' hb ha exact ⟨n, by rwa [pow_succ, mul_dvd_mul_iff_left (left_ne_zero_of_mul hb)]⟩ section Prio -- set_option default_priority 100 -- see Note [default priority] /-- unique factorization monoids. These are defined as `CancelCommMonoidWithZero`s with well-founded strict divisibility relations, but this is equivalent to more familiar definitions: Each element (except zero) is uniquely represented as a multiset of irreducible factors. Uniqueness is only up to associated elements. Each element (except zero) is non-uniquely represented as a multiset of prime factors. To define a UFD using the definition in terms of multisets of irreducible factors, use the definition `of_exists_unique_irreducible_factors` To define a UFD using the definition in terms of multisets of prime factors, use the definition `of_exists_prime_factors` -/ class UniqueFactorizationMonoid (α : Type*) [CancelCommMonoidWithZero α] extends WfDvdMonoid α : Prop where protected irreducible_iff_prime : ∀ {a : α}, Irreducible a ↔ Prime a #align unique_factorization_monoid UniqueFactorizationMonoid /-- Can't be an instance because it would cause a loop `ufm → WfDvdMonoid → ufm → ...`. -/ theorem ufm_of_decomposition_of_wfDvdMonoid [CancelCommMonoidWithZero α] [WfDvdMonoid α] [DecompositionMonoid α] : UniqueFactorizationMonoid α := { ‹WfDvdMonoid α› with irreducible_iff_prime := irreducible_iff_prime } #align ufm_of_gcd_of_wf_dvd_monoid ufm_of_decomposition_of_wfDvdMonoid @[deprecated] alias ufm_of_gcd_of_wfDvdMonoid := ufm_of_decomposition_of_wfDvdMonoid instance Associates.ufm [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] : UniqueFactorizationMonoid (Associates α) := { (WfDvdMonoid.wfDvdMonoid_associates : WfDvdMonoid (Associates α)) with irreducible_iff_prime := by rw [← Associates.irreducible_iff_prime_iff] apply UniqueFactorizationMonoid.irreducible_iff_prime } #align associates.ufm Associates.ufm end Prio namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] theorem exists_prime_factors (a : α) : a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a := by simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime] apply WfDvdMonoid.exists_factors a #align unique_factorization_monoid.exists_prime_factors UniqueFactorizationMonoid.exists_prime_factors instance : DecompositionMonoid α where primal a := by obtain rfl | ha := eq_or_ne a 0; · exact isPrimal_zero obtain ⟨f, hf, u, rfl⟩ := exists_prime_factors a ha exact ((Submonoid.isPrimal α).multiset_prod_mem f (hf · ·|>.isPrimal)).mul u.isUnit.isPrimal lemma exists_prime_iff : (∃ (p : α), Prime p) ↔ ∃ (x : α), x ≠ 0 ∧ ¬ IsUnit x := by refine ⟨fun ⟨p, hp⟩ ↦ ⟨p, hp.ne_zero, hp.not_unit⟩, fun ⟨x, hx₀, hxu⟩ ↦ ?_⟩ obtain ⟨f, hf, -⟩ := WfDvdMonoid.exists_irreducible_factor hxu hx₀ exact ⟨f, UniqueFactorizationMonoid.irreducible_iff_prime.mp hf⟩ @[elab_as_elim] theorem induction_on_prime {P : α → Prop} (a : α) (h₁ : P 0) (h₂ : ∀ x : α, IsUnit x → P x) (h₃ : ∀ a p : α, a ≠ 0 → Prime p → P a → P (p * a)) : P a := by simp_rw [← UniqueFactorizationMonoid.irreducible_iff_prime] at h₃ exact WfDvdMonoid.induction_on_irreducible a h₁ h₂ h₃ #align unique_factorization_monoid.induction_on_prime UniqueFactorizationMonoid.induction_on_prime end UniqueFactorizationMonoid theorem prime_factors_unique [CancelCommMonoidWithZero α] : ∀ {f g : Multiset α}, (∀ x ∈ f, Prime x) → (∀ x ∈ g, Prime x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g := by classical intro f induction' f using Multiset.induction_on with p f ih · intros g _ hg h exact Multiset.rel_zero_left.2 <| Multiset.eq_zero_of_forall_not_mem fun x hx => have : IsUnit g.prod := by simpa [associated_one_iff_isUnit] using h.symm (hg x hx).not_unit <| isUnit_iff_dvd_one.2 <| (Multiset.dvd_prod hx).trans (isUnit_iff_dvd_one.1 this) · intros g hf hg hfg let ⟨b, hbg, hb⟩ := (exists_associated_mem_of_dvd_prod (hf p (by simp)) fun q hq => hg _ hq) <| hfg.dvd_iff_dvd_right.1 (show p ∣ (p ::ₘ f).prod by simp) haveI := Classical.decEq α rw [← Multiset.cons_erase hbg] exact Multiset.Rel.cons hb (ih (fun q hq => hf _ (by simp [hq])) (fun {q} (hq : q ∈ g.erase b) => hg q (Multiset.mem_of_mem_erase hq)) (Associated.of_mul_left (by rwa [← Multiset.prod_cons, ← Multiset.prod_cons, Multiset.cons_erase hbg]) hb (hf p (by simp)).ne_zero)) #align prime_factors_unique prime_factors_unique namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] theorem factors_unique {f g : Multiset α} (hf : ∀ x ∈ f, Irreducible x) (hg : ∀ x ∈ g, Irreducible x) (h : f.prod ~ᵤ g.prod) : Multiset.Rel Associated f g := prime_factors_unique (fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hf x hx)) (fun x hx => UniqueFactorizationMonoid.irreducible_iff_prime.mp (hg x hx)) h #align unique_factorization_monoid.factors_unique UniqueFactorizationMonoid.factors_unique end UniqueFactorizationMonoid /-- If an irreducible has a prime factorization, then it is an associate of one of its prime factors. -/ theorem prime_factors_irreducible [CancelCommMonoidWithZero α] {a : α} {f : Multiset α} (ha : Irreducible a) (pfa : (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a) : ∃ p, a ~ᵤ p ∧ f = {p} := by haveI := Classical.decEq α refine @Multiset.induction_on _ (fun g => (g.prod ~ᵤ a) → (∀ b ∈ g, Prime b) → ∃ p, a ~ᵤ p ∧ g = {p}) f ?_ ?_ pfa.2 pfa.1 · intro h; exact (ha.not_unit (associated_one_iff_isUnit.1 (Associated.symm h))).elim · rintro p s _ ⟨u, hu⟩ hs use p have hs0 : s = 0 := by by_contra hs0 obtain ⟨q, hq⟩ := Multiset.exists_mem_of_ne_zero hs0 apply (hs q (by simp [hq])).2.1 refine (ha.isUnit_or_isUnit (?_ : _ = p * ↑u * (s.erase q).prod * _)).resolve_left ?_ · rw [mul_right_comm _ _ q, mul_assoc, ← Multiset.prod_cons, Multiset.cons_erase hq, ← hu, mul_comm, mul_comm p _, mul_assoc] simp apply mt isUnit_of_mul_isUnit_left (mt isUnit_of_mul_isUnit_left _) apply (hs p (Multiset.mem_cons_self _ _)).2.1 simp only [mul_one, Multiset.prod_cons, Multiset.prod_zero, hs0] at * exact ⟨Associated.symm ⟨u, hu⟩, rfl⟩ #align prime_factors_irreducible prime_factors_irreducible section ExistsPrimeFactors variable [CancelCommMonoidWithZero α] variable (pf : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a) theorem WfDvdMonoid.of_exists_prime_factors : WfDvdMonoid α := ⟨by classical refine RelHomClass.wellFounded (RelHom.mk ?_ ?_ : (DvdNotUnit : α → α → Prop) →r ((· < ·) : ℕ∞ → ℕ∞ → Prop)) wellFounded_lt · intro a by_cases h : a = 0 · exact ⊤ exact ↑(Multiset.card (Classical.choose (pf a h))) rintro a b ⟨ane0, ⟨c, hc, b_eq⟩⟩ rw [dif_neg ane0] by_cases h : b = 0 · simp [h, lt_top_iff_ne_top] · rw [dif_neg h] erw [WithTop.coe_lt_coe] have cne0 : c ≠ 0 := by refine mt (fun con => ?_) h rw [b_eq, con, mul_zero] calc Multiset.card (Classical.choose (pf a ane0)) < _ + Multiset.card (Classical.choose (pf c cne0)) := lt_add_of_pos_right _ (Multiset.card_pos.mpr fun con => hc (associated_one_iff_isUnit.mp ?_)) _ = Multiset.card (Classical.choose (pf a ane0) + Classical.choose (pf c cne0)) := (Multiset.card_add _ _).symm _ = Multiset.card (Classical.choose (pf b h)) := Multiset.card_eq_card_of_rel (prime_factors_unique ?_ (Classical.choose_spec (pf _ h)).1 ?_) · convert (Classical.choose_spec (pf c cne0)).2.symm rw [con, Multiset.prod_zero] · intro x hadd rw [Multiset.mem_add] at hadd cases' hadd with h h <;> apply (Classical.choose_spec (pf _ _)).1 _ h <;> assumption · rw [Multiset.prod_add] trans a * c · apply Associated.mul_mul <;> apply (Classical.choose_spec (pf _ _)).2 <;> assumption · rw [← b_eq] apply (Classical.choose_spec (pf _ _)).2.symm; assumption⟩ #align wf_dvd_monoid.of_exists_prime_factors WfDvdMonoid.of_exists_prime_factors theorem irreducible_iff_prime_of_exists_prime_factors {p : α} : Irreducible p ↔ Prime p := by by_cases hp0 : p = 0 · simp [hp0] refine ⟨fun h => ?_, Prime.irreducible⟩ obtain ⟨f, hf⟩ := pf p hp0 obtain ⟨q, hq, rfl⟩ := prime_factors_irreducible h hf rw [hq.prime_iff] exact hf.1 q (Multiset.mem_singleton_self _) #align irreducible_iff_prime_of_exists_prime_factors irreducible_iff_prime_of_exists_prime_factors theorem UniqueFactorizationMonoid.of_exists_prime_factors : UniqueFactorizationMonoid α := { WfDvdMonoid.of_exists_prime_factors pf with irreducible_iff_prime := irreducible_iff_prime_of_exists_prime_factors pf } #align unique_factorization_monoid.of_exists_prime_factors UniqueFactorizationMonoid.of_exists_prime_factors end ExistsPrimeFactors theorem UniqueFactorizationMonoid.iff_exists_prime_factors [CancelCommMonoidWithZero α] : UniqueFactorizationMonoid α ↔ ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Prime b) ∧ f.prod ~ᵤ a := ⟨fun h => @UniqueFactorizationMonoid.exists_prime_factors _ _ h, UniqueFactorizationMonoid.of_exists_prime_factors⟩ #align unique_factorization_monoid.iff_exists_prime_factors UniqueFactorizationMonoid.iff_exists_prime_factors section variable {β : Type*} [CancelCommMonoidWithZero α] [CancelCommMonoidWithZero β] theorem MulEquiv.uniqueFactorizationMonoid (e : α ≃* β) (hα : UniqueFactorizationMonoid α) : UniqueFactorizationMonoid β := by rw [UniqueFactorizationMonoid.iff_exists_prime_factors] at hα ⊢ intro a ha obtain ⟨w, hp, u, h⟩ := hα (e.symm a) fun h => ha <| by convert← map_zero e simp [← h] exact ⟨w.map e, fun b hb => let ⟨c, hc, he⟩ := Multiset.mem_map.1 hb he ▸ e.prime_iff.1 (hp c hc), Units.map e.toMonoidHom u, by erw [Multiset.prod_hom, ← e.map_mul, h] simp⟩ #align mul_equiv.unique_factorization_monoid MulEquiv.uniqueFactorizationMonoid theorem MulEquiv.uniqueFactorizationMonoid_iff (e : α ≃* β) : UniqueFactorizationMonoid α ↔ UniqueFactorizationMonoid β := ⟨e.uniqueFactorizationMonoid, e.symm.uniqueFactorizationMonoid⟩ #align mul_equiv.unique_factorization_monoid_iff MulEquiv.uniqueFactorizationMonoid_iff end theorem irreducible_iff_prime_of_exists_unique_irreducible_factors [CancelCommMonoidWithZero α] (eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a) (uif : ∀ f g : Multiset α, (∀ x ∈ f, Irreducible x) → (∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g) (p : α) : Irreducible p ↔ Prime p := letI := Classical.decEq α ⟨ fun hpi => ⟨hpi.ne_zero, hpi.1, fun a b ⟨x, hx⟩ => if hab0 : a * b = 0 then (eq_zero_or_eq_zero_of_mul_eq_zero hab0).elim (fun ha0 => by simp [ha0]) fun hb0 => by simp [hb0] else by have hx0 : x ≠ 0 := fun hx0 => by simp_all have ha0 : a ≠ 0 := left_ne_zero_of_mul hab0 have hb0 : b ≠ 0 := right_ne_zero_of_mul hab0 cases' eif x hx0 with fx hfx cases' eif a ha0 with fa hfa cases' eif b hb0 with fb hfb have h : Multiset.Rel Associated (p ::ₘ fx) (fa + fb) := by apply uif · exact fun i hi => (Multiset.mem_cons.1 hi).elim (fun hip => hip.symm ▸ hpi) (hfx.1 _) · exact fun i hi => (Multiset.mem_add.1 hi).elim (hfa.1 _) (hfb.1 _) calc Multiset.prod (p ::ₘ fx) ~ᵤ a * b := by rw [hx, Multiset.prod_cons]; exact hfx.2.mul_left _ _ ~ᵤ fa.prod * fb.prod := hfa.2.symm.mul_mul hfb.2.symm _ = _ := by rw [Multiset.prod_add] exact let ⟨q, hqf, hq⟩ := Multiset.exists_mem_of_rel_of_mem h (Multiset.mem_cons_self p _) (Multiset.mem_add.1 hqf).elim (fun hqa => Or.inl <| hq.dvd_iff_dvd_left.2 <| hfa.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqa)) fun hqb => Or.inr <| hq.dvd_iff_dvd_left.2 <| hfb.2.dvd_iff_dvd_right.1 (Multiset.dvd_prod hqb)⟩, Prime.irreducible⟩ #align irreducible_iff_prime_of_exists_unique_irreducible_factors irreducible_iff_prime_of_exists_unique_irreducible_factors theorem UniqueFactorizationMonoid.of_exists_unique_irreducible_factors [CancelCommMonoidWithZero α] (eif : ∀ a : α, a ≠ 0 → ∃ f : Multiset α, (∀ b ∈ f, Irreducible b) ∧ f.prod ~ᵤ a) (uif : ∀ f g : Multiset α, (∀ x ∈ f, Irreducible x) → (∀ x ∈ g, Irreducible x) → f.prod ~ᵤ g.prod → Multiset.Rel Associated f g) : UniqueFactorizationMonoid α := UniqueFactorizationMonoid.of_exists_prime_factors (by convert eif using 7 simp_rw [irreducible_iff_prime_of_exists_unique_irreducible_factors eif uif]) #align unique_factorization_monoid.of_exists_unique_irreducible_factors UniqueFactorizationMonoid.of_exists_unique_irreducible_factors namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] variable [UniqueFactorizationMonoid α] open Classical in /-- Noncomputably determines the multiset of prime factors. -/ noncomputable def factors (a : α) : Multiset α := if h : a = 0 then 0 else Classical.choose (UniqueFactorizationMonoid.exists_prime_factors a h) #align unique_factorization_monoid.factors UniqueFactorizationMonoid.factors theorem factors_prod {a : α} (ane0 : a ≠ 0) : Associated (factors a).prod a := by rw [factors, dif_neg ane0] exact (Classical.choose_spec (exists_prime_factors a ane0)).2 #align unique_factorization_monoid.factors_prod UniqueFactorizationMonoid.factors_prod @[simp] theorem factors_zero : factors (0 : α) = 0 := by simp [factors] #align unique_factorization_monoid.factors_zero UniqueFactorizationMonoid.factors_zero theorem ne_zero_of_mem_factors {p a : α} (h : p ∈ factors a) : a ≠ 0 := by rintro rfl simp at h #align unique_factorization_monoid.ne_zero_of_mem_factors UniqueFactorizationMonoid.ne_zero_of_mem_factors theorem dvd_of_mem_factors {p a : α} (h : p ∈ factors a) : p ∣ a := dvd_trans (Multiset.dvd_prod h) (Associated.dvd (factors_prod (ne_zero_of_mem_factors h))) #align unique_factorization_monoid.dvd_of_mem_factors UniqueFactorizationMonoid.dvd_of_mem_factors theorem prime_of_factor {a : α} (x : α) (hx : x ∈ factors a) : Prime x := by have ane0 := ne_zero_of_mem_factors hx rw [factors, dif_neg ane0] at hx exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 x hx #align unique_factorization_monoid.prime_of_factor UniqueFactorizationMonoid.prime_of_factor theorem irreducible_of_factor {a : α} : ∀ x : α, x ∈ factors a → Irreducible x := fun x h => (prime_of_factor x h).irreducible #align unique_factorization_monoid.irreducible_of_factor UniqueFactorizationMonoid.irreducible_of_factor @[simp] theorem factors_one : factors (1 : α) = 0 := by nontriviality α using factors rw [← Multiset.rel_zero_right] refine factors_unique irreducible_of_factor (fun x hx => (Multiset.not_mem_zero x hx).elim) ?_ rw [Multiset.prod_zero] exact factors_prod one_ne_zero #align unique_factorization_monoid.factors_one UniqueFactorizationMonoid.factors_one theorem exists_mem_factors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : p ∣ a → ∃ q ∈ factors a, p ~ᵤ q := fun ⟨b, hb⟩ => have hb0 : b ≠ 0 := fun hb0 => by simp_all have : Multiset.Rel Associated (p ::ₘ factors b) (factors a) := factors_unique (fun x hx => (Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_factor _)) irreducible_of_factor (Associated.symm <| calc Multiset.prod (factors a) ~ᵤ a := factors_prod ha0 _ = p * b := hb _ ~ᵤ Multiset.prod (p ::ₘ factors b) := by rw [Multiset.prod_cons]; exact (factors_prod hb0).symm.mul_left _ ) Multiset.exists_mem_of_rel_of_mem this (by simp) #align unique_factorization_monoid.exists_mem_factors_of_dvd UniqueFactorizationMonoid.exists_mem_factors_of_dvd theorem exists_mem_factors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) : ∃ p, p ∈ factors x := by obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx obtain ⟨p, hp, _⟩ := exists_mem_factors_of_dvd hx hp' hp'x exact ⟨p, hp⟩ #align unique_factorization_monoid.exists_mem_factors UniqueFactorizationMonoid.exists_mem_factors open Classical in theorem factors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : Multiset.Rel Associated (factors (x * y)) (factors x + factors y) := by refine factors_unique irreducible_of_factor (fun a ha => (Multiset.mem_add.mp ha).by_cases (irreducible_of_factor _) (irreducible_of_factor _)) ((factors_prod (mul_ne_zero hx hy)).trans ?_) rw [Multiset.prod_add] exact (Associated.mul_mul (factors_prod hx) (factors_prod hy)).symm #align unique_factorization_monoid.factors_mul UniqueFactorizationMonoid.factors_mul theorem factors_pow {x : α} (n : ℕ) : Multiset.Rel Associated (factors (x ^ n)) (n • factors x) := by match n with | 0 => rw [zero_smul, pow_zero, factors_one, Multiset.rel_zero_right] | n+1 => by_cases h0 : x = 0 · simp [h0, zero_pow n.succ_ne_zero, smul_zero] · rw [pow_succ', succ_nsmul'] refine Multiset.Rel.trans _ (factors_mul h0 (pow_ne_zero n h0)) ?_ refine Multiset.Rel.add ?_ <| factors_pow n exact Multiset.rel_refl_of_refl_on fun y _ => Associated.refl _ #align unique_factorization_monoid.factors_pow UniqueFactorizationMonoid.factors_pow @[simp] theorem factors_pos (x : α) (hx : x ≠ 0) : 0 < factors x ↔ ¬IsUnit x := by constructor · intro h hx obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne' exact (prime_of_factor _ hp).not_unit (isUnit_of_dvd_unit (dvd_of_mem_factors hp) hx) · intro h obtain ⟨p, hp⟩ := exists_mem_factors hx h exact bot_lt_iff_ne_bot.mpr (mt Multiset.eq_zero_iff_forall_not_mem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩)) #align unique_factorization_monoid.factors_pos UniqueFactorizationMonoid.factors_pos open Multiset in theorem factors_pow_count_prod [DecidableEq α] {x : α} (hx : x ≠ 0) : (∏ p ∈ (factors x).toFinset, p ^ (factors x).count p) ~ᵤ x := calc _ = prod (∑ a ∈ toFinset (factors x), count a (factors x) • {a}) := by simp only [prod_sum, prod_nsmul, prod_singleton] _ = prod (factors x) := by rw [toFinset_sum_count_nsmul_eq (factors x)] _ ~ᵤ x := factors_prod hx end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] variable [UniqueFactorizationMonoid α] /-- Noncomputably determines the multiset of prime factors. -/ noncomputable def normalizedFactors (a : α) : Multiset α := Multiset.map normalize <| factors a #align unique_factorization_monoid.normalized_factors UniqueFactorizationMonoid.normalizedFactors /-- An arbitrary choice of factors of `x : M` is exactly the (unique) normalized set of factors, if `M` has a trivial group of units. -/ @[simp] theorem factors_eq_normalizedFactors {M : Type*} [CancelCommMonoidWithZero M] [UniqueFactorizationMonoid M] [Unique Mˣ] (x : M) : factors x = normalizedFactors x := by unfold normalizedFactors convert (Multiset.map_id (factors x)).symm ext p exact normalize_eq p #align unique_factorization_monoid.factors_eq_normalized_factors UniqueFactorizationMonoid.factors_eq_normalizedFactors theorem normalizedFactors_prod {a : α} (ane0 : a ≠ 0) : Associated (normalizedFactors a).prod a := by rw [normalizedFactors, factors, dif_neg ane0] refine Associated.trans ?_ (Classical.choose_spec (exists_prime_factors a ane0)).2 rw [← Associates.mk_eq_mk_iff_associated, ← Associates.prod_mk, ← Associates.prod_mk, Multiset.map_map] congr 2 ext rw [Function.comp_apply, Associates.mk_normalize] #align unique_factorization_monoid.normalized_factors_prod UniqueFactorizationMonoid.normalizedFactors_prod theorem prime_of_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → Prime x := by rw [normalizedFactors, factors] split_ifs with ane0; · simp intro x hx; rcases Multiset.mem_map.1 hx with ⟨y, ⟨hy, rfl⟩⟩ rw [(normalize_associated _).prime_iff] exact (Classical.choose_spec (UniqueFactorizationMonoid.exists_prime_factors a ane0)).1 y hy #align unique_factorization_monoid.prime_of_normalized_factor UniqueFactorizationMonoid.prime_of_normalized_factor theorem irreducible_of_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → Irreducible x := fun x h => (prime_of_normalized_factor x h).irreducible #align unique_factorization_monoid.irreducible_of_normalized_factor UniqueFactorizationMonoid.irreducible_of_normalized_factor theorem normalize_normalized_factor {a : α} : ∀ x : α, x ∈ normalizedFactors a → normalize x = x := by rw [normalizedFactors, factors] split_ifs with h; · simp intro x hx obtain ⟨y, _, rfl⟩ := Multiset.mem_map.1 hx apply normalize_idem #align unique_factorization_monoid.normalize_normalized_factor UniqueFactorizationMonoid.normalize_normalized_factor theorem normalizedFactors_irreducible {a : α} (ha : Irreducible a) : normalizedFactors a = {normalize a} := by obtain ⟨p, a_assoc, hp⟩ := prime_factors_irreducible ha ⟨prime_of_normalized_factor, normalizedFactors_prod ha.ne_zero⟩ have p_mem : p ∈ normalizedFactors a := by rw [hp] exact Multiset.mem_singleton_self _ convert hp rwa [← normalize_normalized_factor p p_mem, normalize_eq_normalize_iff, dvd_dvd_iff_associated] #align unique_factorization_monoid.normalized_factors_irreducible UniqueFactorizationMonoid.normalizedFactors_irreducible theorem normalizedFactors_eq_of_dvd (a : α) : ∀ᵉ (p ∈ normalizedFactors a) (q ∈ normalizedFactors a), p ∣ q → p = q := by intro p hp q hq hdvd convert normalize_eq_normalize hdvd ((prime_of_normalized_factor _ hp).irreducible.dvd_symm (prime_of_normalized_factor _ hq).irreducible hdvd) <;> apply (normalize_normalized_factor _ ‹_›).symm #align unique_factorization_monoid.normalized_factors_eq_of_dvd UniqueFactorizationMonoid.normalizedFactors_eq_of_dvd theorem exists_mem_normalizedFactors_of_dvd {a p : α} (ha0 : a ≠ 0) (hp : Irreducible p) : p ∣ a → ∃ q ∈ normalizedFactors a, p ~ᵤ q := fun ⟨b, hb⟩ => have hb0 : b ≠ 0 := fun hb0 => by simp_all have : Multiset.Rel Associated (p ::ₘ normalizedFactors b) (normalizedFactors a) := factors_unique (fun x hx => (Multiset.mem_cons.1 hx).elim (fun h => h.symm ▸ hp) (irreducible_of_normalized_factor _)) irreducible_of_normalized_factor (Associated.symm <| calc Multiset.prod (normalizedFactors a) ~ᵤ a := normalizedFactors_prod ha0 _ = p * b := hb _ ~ᵤ Multiset.prod (p ::ₘ normalizedFactors b) := by rw [Multiset.prod_cons] exact (normalizedFactors_prod hb0).symm.mul_left _ ) Multiset.exists_mem_of_rel_of_mem this (by simp) #align unique_factorization_monoid.exists_mem_normalized_factors_of_dvd UniqueFactorizationMonoid.exists_mem_normalizedFactors_of_dvd theorem exists_mem_normalizedFactors {x : α} (hx : x ≠ 0) (h : ¬IsUnit x) : ∃ p, p ∈ normalizedFactors x := by obtain ⟨p', hp', hp'x⟩ := WfDvdMonoid.exists_irreducible_factor h hx obtain ⟨p, hp, _⟩ := exists_mem_normalizedFactors_of_dvd hx hp' hp'x exact ⟨p, hp⟩ #align unique_factorization_monoid.exists_mem_normalized_factors UniqueFactorizationMonoid.exists_mem_normalizedFactors @[simp] theorem normalizedFactors_zero : normalizedFactors (0 : α) = 0 := by simp [normalizedFactors, factors] #align unique_factorization_monoid.normalized_factors_zero UniqueFactorizationMonoid.normalizedFactors_zero @[simp] theorem normalizedFactors_one : normalizedFactors (1 : α) = 0 := by cases' subsingleton_or_nontrivial α with h h · dsimp [normalizedFactors, factors] simp [Subsingleton.elim (1:α) 0] · rw [← Multiset.rel_zero_right] apply factors_unique irreducible_of_normalized_factor · intro x hx exfalso apply Multiset.not_mem_zero x hx · apply normalizedFactors_prod one_ne_zero #align unique_factorization_monoid.normalized_factors_one UniqueFactorizationMonoid.normalizedFactors_one @[simp] theorem normalizedFactors_mul {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : normalizedFactors (x * y) = normalizedFactors x + normalizedFactors y := by have h : (normalize : α → α) = Associates.out ∘ Associates.mk := by ext rw [Function.comp_apply, Associates.out_mk] rw [← Multiset.map_id' (normalizedFactors (x * y)), ← Multiset.map_id' (normalizedFactors x), ← Multiset.map_id' (normalizedFactors y), ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_congr rfl normalize_normalized_factor, ← Multiset.map_add, h, ← Multiset.map_map Associates.out, eq_comm, ← Multiset.map_map Associates.out] refine congr rfl ?_ apply Multiset.map_mk_eq_map_mk_of_rel apply factors_unique · intro x hx rcases Multiset.mem_add.1 hx with (hx | hx) <;> exact irreducible_of_normalized_factor x hx · exact irreducible_of_normalized_factor · rw [Multiset.prod_add] exact ((normalizedFactors_prod hx).mul_mul (normalizedFactors_prod hy)).trans (normalizedFactors_prod (mul_ne_zero hx hy)).symm #align unique_factorization_monoid.normalized_factors_mul UniqueFactorizationMonoid.normalizedFactors_mul @[simp] theorem normalizedFactors_pow {x : α} (n : ℕ) : normalizedFactors (x ^ n) = n • normalizedFactors x := by induction' n with n ih · simp by_cases h0 : x = 0 · simp [h0, zero_pow n.succ_ne_zero, smul_zero] rw [pow_succ', succ_nsmul', normalizedFactors_mul h0 (pow_ne_zero _ h0), ih] #align unique_factorization_monoid.normalized_factors_pow UniqueFactorizationMonoid.normalizedFactors_pow theorem _root_.Irreducible.normalizedFactors_pow {p : α} (hp : Irreducible p) (k : ℕ) : normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by rw [UniqueFactorizationMonoid.normalizedFactors_pow, normalizedFactors_irreducible hp, Multiset.nsmul_singleton] #align irreducible.normalized_factors_pow Irreducible.normalizedFactors_pow theorem normalizedFactors_prod_eq (s : Multiset α) (hs : ∀ a ∈ s, Irreducible a) : normalizedFactors s.prod = s.map normalize := by induction' s using Multiset.induction with a s ih · rw [Multiset.prod_zero, normalizedFactors_one, Multiset.map_zero] · have ia := hs a (Multiset.mem_cons_self a _) have ib := fun b h => hs b (Multiset.mem_cons_of_mem h) obtain rfl | ⟨b, hb⟩ := s.empty_or_exists_mem · rw [Multiset.cons_zero, Multiset.prod_singleton, Multiset.map_singleton, normalizedFactors_irreducible ia] haveI := nontrivial_of_ne b 0 (ib b hb).ne_zero rw [Multiset.prod_cons, Multiset.map_cons, normalizedFactors_mul ia.ne_zero (Multiset.prod_ne_zero fun h => (ib 0 h).ne_zero rfl), normalizedFactors_irreducible ia, ih ib, Multiset.singleton_add] #align unique_factorization_monoid.normalized_factors_prod_eq UniqueFactorizationMonoid.normalizedFactors_prod_eq theorem dvd_iff_normalizedFactors_le_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : x ∣ y ↔ normalizedFactors x ≤ normalizedFactors y := by constructor · rintro ⟨c, rfl⟩ simp [hx, right_ne_zero_of_mul hy] · rw [← (normalizedFactors_prod hx).dvd_iff_dvd_left, ← (normalizedFactors_prod hy).dvd_iff_dvd_right] apply Multiset.prod_dvd_prod_of_le #align unique_factorization_monoid.dvd_iff_normalized_factors_le_normalized_factors UniqueFactorizationMonoid.dvd_iff_normalizedFactors_le_normalizedFactors theorem associated_iff_normalizedFactors_eq_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : x ~ᵤ y ↔ normalizedFactors x = normalizedFactors y := by refine ⟨fun h => ?_, fun h => (normalizedFactors_prod hx).symm.trans (_root_.trans (by rw [h]) (normalizedFactors_prod hy))⟩ apply le_antisymm <;> rw [← dvd_iff_normalizedFactors_le_normalizedFactors] all_goals simp [*, h.dvd, h.symm.dvd] #align unique_factorization_monoid.associated_iff_normalized_factors_eq_normalized_factors UniqueFactorizationMonoid.associated_iff_normalizedFactors_eq_normalizedFactors theorem normalizedFactors_of_irreducible_pow {p : α} (hp : Irreducible p) (k : ℕ) : normalizedFactors (p ^ k) = Multiset.replicate k (normalize p) := by rw [normalizedFactors_pow, normalizedFactors_irreducible hp, Multiset.nsmul_singleton] #align unique_factorization_monoid.normalized_factors_of_irreducible_pow UniqueFactorizationMonoid.normalizedFactors_of_irreducible_pow theorem zero_not_mem_normalizedFactors (x : α) : (0 : α) ∉ normalizedFactors x := fun h => Prime.ne_zero (prime_of_normalized_factor _ h) rfl #align unique_factorization_monoid.zero_not_mem_normalized_factors UniqueFactorizationMonoid.zero_not_mem_normalizedFactors theorem dvd_of_mem_normalizedFactors {a p : α} (H : p ∈ normalizedFactors a) : p ∣ a := by by_cases hcases : a = 0 · rw [hcases] exact dvd_zero p · exact dvd_trans (Multiset.dvd_prod H) (Associated.dvd (normalizedFactors_prod hcases)) #align unique_factorization_monoid.dvd_of_mem_normalized_factors UniqueFactorizationMonoid.dvd_of_mem_normalizedFactors theorem mem_normalizedFactors_iff [Unique αˣ] {p x : α} (hx : x ≠ 0) : p ∈ normalizedFactors x ↔ Prime p ∧ p ∣ x := by constructor · intro h exact ⟨prime_of_normalized_factor p h, dvd_of_mem_normalizedFactors h⟩ · rintro ⟨hprime, hdvd⟩ obtain ⟨q, hqmem, hqeq⟩ := exists_mem_normalizedFactors_of_dvd hx hprime.irreducible hdvd rw [associated_iff_eq] at hqeq exact hqeq ▸ hqmem theorem exists_associated_prime_pow_of_unique_normalized_factor {p r : α} (h : ∀ {m}, m ∈ normalizedFactors r → m = p) (hr : r ≠ 0) : ∃ i : ℕ, Associated (p ^ i) r := by use Multiset.card.toFun (normalizedFactors r) have := UniqueFactorizationMonoid.normalizedFactors_prod hr rwa [Multiset.eq_replicate_of_mem fun b => h, Multiset.prod_replicate] at this #align unique_factorization_monoid.exists_associated_prime_pow_of_unique_normalized_factor UniqueFactorizationMonoid.exists_associated_prime_pow_of_unique_normalized_factor theorem normalizedFactors_prod_of_prime [Nontrivial α] [Unique αˣ] {m : Multiset α} (h : ∀ p ∈ m, Prime p) : normalizedFactors m.prod = m := by simpa only [← Multiset.rel_eq, ← associated_eq_eq] using prime_factors_unique prime_of_normalized_factor h (normalizedFactors_prod (m.prod_ne_zero_of_prime h)) #align unique_factorization_monoid.normalized_factors_prod_of_prime UniqueFactorizationMonoid.normalizedFactors_prod_of_prime theorem mem_normalizedFactors_eq_of_associated {a b c : α} (ha : a ∈ normalizedFactors c) (hb : b ∈ normalizedFactors c) (h : Associated a b) : a = b := by rw [← normalize_normalized_factor a ha, ← normalize_normalized_factor b hb, normalize_eq_normalize_iff] exact Associated.dvd_dvd h #align unique_factorization_monoid.mem_normalized_factors_eq_of_associated UniqueFactorizationMonoid.mem_normalizedFactors_eq_of_associated @[simp] theorem normalizedFactors_pos (x : α) (hx : x ≠ 0) : 0 < normalizedFactors x ↔ ¬IsUnit x := by constructor · intro h hx obtain ⟨p, hp⟩ := Multiset.exists_mem_of_ne_zero h.ne' exact (prime_of_normalized_factor _ hp).not_unit (isUnit_of_dvd_unit (dvd_of_mem_normalizedFactors hp) hx) · intro h obtain ⟨p, hp⟩ := exists_mem_normalizedFactors hx h exact bot_lt_iff_ne_bot.mpr (mt Multiset.eq_zero_iff_forall_not_mem.mp (not_forall.mpr ⟨p, not_not.mpr hp⟩)) #align unique_factorization_monoid.normalized_factors_pos UniqueFactorizationMonoid.normalizedFactors_pos theorem dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors {x y : α} (hx : x ≠ 0) (hy : y ≠ 0) : DvdNotUnit x y ↔ normalizedFactors x < normalizedFactors y := by constructor · rintro ⟨_, c, hc, rfl⟩ simp only [hx, right_ne_zero_of_mul hy, normalizedFactors_mul, Ne, not_false_iff, lt_add_iff_pos_right, normalizedFactors_pos, hc] · intro h exact dvdNotUnit_of_dvd_of_not_dvd ((dvd_iff_normalizedFactors_le_normalizedFactors hx hy).mpr h.le) (mt (dvd_iff_normalizedFactors_le_normalizedFactors hy hx).mp h.not_le) #align unique_factorization_monoid.dvd_not_unit_iff_normalized_factors_lt_normalized_factors UniqueFactorizationMonoid.dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors theorem normalizedFactors_multiset_prod (s : Multiset α) (hs : 0 ∉ s) : normalizedFactors (s.prod) = (s.map normalizedFactors).sum := by cases subsingleton_or_nontrivial α · obtain rfl : s = 0 := by apply Multiset.eq_zero_of_forall_not_mem intro _ convert hs simp induction s using Multiset.induction with | empty => simp | cons _ _ IH => rw [Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons, normalizedFactors_mul, IH] · exact fun h ↦ hs (Multiset.mem_cons_of_mem h) · exact fun h ↦ hs (h ▸ Multiset.mem_cons_self _ _) · apply Multiset.prod_ne_zero exact fun h ↦ hs (Multiset.mem_cons_of_mem h) end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid open scoped Classical open Multiset Associates variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] /-- Noncomputably defines a `normalizationMonoid` structure on a `UniqueFactorizationMonoid`. -/ protected noncomputable def normalizationMonoid : NormalizationMonoid α := normalizationMonoidOfMonoidHomRightInverse { toFun := fun a : Associates α => if a = 0 then 0 else ((normalizedFactors a).map (Classical.choose mk_surjective.hasRightInverse : Associates α → α)).prod map_one' := by nontriviality α; simp map_mul' := fun x y => by by_cases hx : x = 0 · simp [hx] by_cases hy : y = 0 · simp [hy] simp [hx, hy] } (by intro x dsimp by_cases hx : x = 0 · simp [hx] have h : Associates.mkMonoidHom ∘ Classical.choose mk_surjective.hasRightInverse = (id : Associates α → Associates α) := by ext x rw [Function.comp_apply, mkMonoidHom_apply, Classical.choose_spec mk_surjective.hasRightInverse x] rfl rw [if_neg hx, ← mkMonoidHom_apply, MonoidHom.map_multiset_prod, map_map, h, map_id, ← associated_iff_eq] apply normalizedFactors_prod hx) #align unique_factorization_monoid.normalization_monoid UniqueFactorizationMonoid.normalizationMonoid end UniqueFactorizationMonoid namespace UniqueFactorizationMonoid variable {R : Type*} [CancelCommMonoidWithZero R] [UniqueFactorizationMonoid R] theorem isRelPrime_iff_no_prime_factors {a b : R} (ha : a ≠ 0) : IsRelPrime a b ↔ ∀ ⦃d⦄, d ∣ a → d ∣ b → ¬Prime d := ⟨fun h _ ha hb ↦ (·.not_unit <| h ha hb), fun h ↦ WfDvdMonoid.isRelPrime_of_no_irreducible_factors (ha ·.1) fun _ irr ha hb ↦ h ha hb (UniqueFactorizationMonoid.irreducible_iff_prime.mp irr)⟩ #align unique_factorization_monoid.no_factors_of_no_prime_factors UniqueFactorizationMonoid.isRelPrime_iff_no_prime_factors /-- Euclid's lemma: if `a ∣ b * c` and `a` and `c` have no common prime factors, `a ∣ b`. Compare `IsCoprime.dvd_of_dvd_mul_left`. -/ theorem dvd_of_dvd_mul_left_of_no_prime_factors {a b c : R} (ha : a ≠ 0) (h : ∀ ⦃d⦄, d ∣ a → d ∣ c → ¬Prime d) : a ∣ b * c → a ∣ b := ((isRelPrime_iff_no_prime_factors ha).mpr h).dvd_of_dvd_mul_right #align unique_factorization_monoid.dvd_of_dvd_mul_left_of_no_prime_factors UniqueFactorizationMonoid.dvd_of_dvd_mul_left_of_no_prime_factors /-- Euclid's lemma: if `a ∣ b * c` and `a` and `b` have no common prime factors, `a ∣ c`. Compare `IsCoprime.dvd_of_dvd_mul_right`. -/ theorem dvd_of_dvd_mul_right_of_no_prime_factors {a b c : R} (ha : a ≠ 0) (no_factors : ∀ {d}, d ∣ a → d ∣ b → ¬Prime d) : a ∣ b * c → a ∣ c := by simpa [mul_comm b c] using dvd_of_dvd_mul_left_of_no_prime_factors ha @no_factors #align unique_factorization_monoid.dvd_of_dvd_mul_right_of_no_prime_factors UniqueFactorizationMonoid.dvd_of_dvd_mul_right_of_no_prime_factors /-- If `a ≠ 0, b` are elements of a unique factorization domain, then dividing out their common factor `c'` gives `a'` and `b'` with no factors in common. -/ theorem exists_reduced_factors : ∀ a ≠ (0 : R), ∀ b, ∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b := by intro a refine induction_on_prime a ?_ ?_ ?_ · intros contradiction · intro a a_unit _ b use a, b, 1 constructor · intro p p_dvd_a _ exact isUnit_of_dvd_unit p_dvd_a a_unit · simp · intro a p a_ne_zero p_prime ih_a pa_ne_zero b by_cases h : p ∣ b · rcases h with ⟨b, rfl⟩ obtain ⟨a', b', c', no_factor, ha', hb'⟩ := ih_a a_ne_zero b refine ⟨a', b', p * c', @no_factor, ?_, ?_⟩ · rw [mul_assoc, ha'] · rw [mul_assoc, hb'] · obtain ⟨a', b', c', coprime, rfl, rfl⟩ := ih_a a_ne_zero b refine ⟨p * a', b', c', ?_, mul_left_comm _ _ _, rfl⟩ intro q q_dvd_pa' q_dvd_b' cases' p_prime.left_dvd_or_dvd_right_of_dvd_mul q_dvd_pa' with p_dvd_q q_dvd_a' · have : p ∣ c' * b' := dvd_mul_of_dvd_right (p_dvd_q.trans q_dvd_b') _ contradiction exact coprime q_dvd_a' q_dvd_b' #align unique_factorization_monoid.exists_reduced_factors UniqueFactorizationMonoid.exists_reduced_factors theorem exists_reduced_factors' (a b : R) (hb : b ≠ 0) : ∃ a' b' c', IsRelPrime a' b' ∧ c' * a' = a ∧ c' * b' = b := let ⟨b', a', c', no_factor, hb, ha⟩ := exists_reduced_factors b hb a ⟨a', b', c', fun _ hpb hpa => no_factor hpa hpb, ha, hb⟩ #align unique_factorization_monoid.exists_reduced_factors' UniqueFactorizationMonoid.exists_reduced_factors' theorem pow_right_injective {a : R} (ha0 : a ≠ 0) (ha1 : ¬IsUnit a) : Function.Injective (a ^ · : ℕ → R) := by letI := Classical.decEq R intro i j hij letI : Nontrivial R := ⟨⟨a, 0, ha0⟩⟩ letI : NormalizationMonoid R := UniqueFactorizationMonoid.normalizationMonoid obtain ⟨p', hp', dvd'⟩ := WfDvdMonoid.exists_irreducible_factor ha1 ha0 obtain ⟨p, mem, _⟩ := exists_mem_normalizedFactors_of_dvd ha0 hp' dvd' have := congr_arg (fun x => Multiset.count p (normalizedFactors x)) hij simp only [normalizedFactors_pow, Multiset.count_nsmul] at this exact mul_right_cancel₀ (Multiset.count_ne_zero.mpr mem) this #align unique_factorization_monoid.pow_right_injective UniqueFactorizationMonoid.pow_right_injective theorem pow_eq_pow_iff {a : R} (ha0 : a ≠ 0) (ha1 : ¬IsUnit a) {i j : ℕ} : a ^ i = a ^ j ↔ i = j := (pow_right_injective ha0 ha1).eq_iff #align unique_factorization_monoid.pow_eq_pow_iff UniqueFactorizationMonoid.pow_eq_pow_iff section multiplicity variable [NormalizationMonoid R] variable [DecidableRel (Dvd.dvd : R → R → Prop)] open multiplicity Multiset theorem le_multiplicity_iff_replicate_le_normalizedFactors {a b : R} {n : ℕ} (ha : Irreducible a) (hb : b ≠ 0) : ↑n ≤ multiplicity a b ↔ replicate n (normalize a) ≤ normalizedFactors b := by rw [← pow_dvd_iff_le_multiplicity] revert b induction' n with n ih; · simp intro b hb constructor · rintro ⟨c, rfl⟩ rw [Ne, pow_succ', mul_assoc, mul_eq_zero, not_or] at hb rw [pow_succ', mul_assoc, normalizedFactors_mul hb.1 hb.2, replicate_succ, normalizedFactors_irreducible ha, singleton_add, cons_le_cons_iff, ← ih hb.2] apply Dvd.intro _ rfl · rw [Multiset.le_iff_exists_add] rintro ⟨u, hu⟩ rw [← (normalizedFactors_prod hb).dvd_iff_dvd_right, hu, prod_add, prod_replicate] exact (Associated.pow_pow <| associated_normalize a).dvd.trans (Dvd.intro u.prod rfl) #align unique_factorization_monoid.le_multiplicity_iff_replicate_le_normalized_factors UniqueFactorizationMonoid.le_multiplicity_iff_replicate_le_normalizedFactors /-- The multiplicity of an irreducible factor of a nonzero element is exactly the number of times the normalized factor occurs in the `normalizedFactors`. See also `count_normalizedFactors_eq` which expands the definition of `multiplicity` to produce a specification for `count (normalizedFactors _) _`.. -/ theorem multiplicity_eq_count_normalizedFactors [DecidableEq R] {a b : R} (ha : Irreducible a) (hb : b ≠ 0) : multiplicity a b = (normalizedFactors b).count (normalize a) := by apply le_antisymm · apply PartENat.le_of_lt_add_one rw [← Nat.cast_one, ← Nat.cast_add, lt_iff_not_ge, ge_iff_le, le_multiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le] simp rw [le_multiplicity_iff_replicate_le_normalizedFactors ha hb, ← le_count_iff_replicate_le] #align unique_factorization_monoid.multiplicity_eq_count_normalized_factors UniqueFactorizationMonoid.multiplicity_eq_count_normalizedFactors /-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by the number of times it divides `x`. See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`. -/ theorem count_normalizedFactors_eq [DecidableEq R] {p x : R} (hp : Irreducible p) (hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) : (normalizedFactors x).count p = n := by letI : DecidableRel ((· ∣ ·) : R → R → Prop) := fun _ _ => Classical.propDecidable _ by_cases hx0 : x = 0 · simp [hx0] at hlt rw [← PartENat.natCast_inj] convert (multiplicity_eq_count_normalizedFactors hp hx0).symm · exact hnorm.symm exact (multiplicity.eq_coe_iff.mpr ⟨hle, hlt⟩).symm #align unique_factorization_monoid.count_normalized_factors_eq UniqueFactorizationMonoid.count_normalizedFactors_eq /-- The number of times an irreducible factor `p` appears in `normalizedFactors x` is defined by the number of times it divides `x`. This is a slightly more general version of `UniqueFactorizationMonoid.count_normalizedFactors_eq` that allows `p = 0`. See also `multiplicity_eq_count_normalizedFactors` if `n` is given by `multiplicity p x`. -/ theorem count_normalizedFactors_eq' [DecidableEq R] {p x : R} (hp : p = 0 ∨ Irreducible p) (hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) : (normalizedFactors x).count p = n := by rcases hp with (rfl | hp) · cases n · exact count_eq_zero.2 (zero_not_mem_normalizedFactors _) · rw [zero_pow (Nat.succ_ne_zero _)] at hle hlt exact absurd hle hlt · exact count_normalizedFactors_eq hp hnorm hle hlt #align unique_factorization_monoid.count_normalized_factors_eq' UniqueFactorizationMonoid.count_normalizedFactors_eq' /-- Deprecated. Use `WfDvdMonoid.max_power_factor` instead. -/ @[deprecated WfDvdMonoid.max_power_factor] theorem max_power_factor {a₀ x : R} (h : a₀ ≠ 0) (hx : Irreducible x) : ∃ n : ℕ, ∃ a : R, ¬x ∣ a ∧ a₀ = x ^ n * a := WfDvdMonoid.max_power_factor h hx #align unique_factorization_monoid.max_power_factor UniqueFactorizationMonoid.max_power_factor end multiplicity section Multiplicative variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] variable {β : Type*} [CancelCommMonoidWithZero β] theorem prime_pow_coprime_prod_of_coprime_insert [DecidableEq α] {s : Finset α} (i : α → ℕ) (p : α) (hps : p ∉ s) (is_prime : ∀ q ∈ insert p s, Prime q) (is_coprime : ∀ᵉ (q ∈ insert p s) (q' ∈ insert p s), q ∣ q' → q = q') : IsRelPrime (p ^ i p) (∏ p' ∈ s, p' ^ i p') := by have hp := is_prime _ (Finset.mem_insert_self _ _) refine (isRelPrime_iff_no_prime_factors <| pow_ne_zero _ hp.ne_zero).mpr ?_ intro d hdp hdprod hd apply hps replace hdp := hd.dvd_of_dvd_pow hdp obtain ⟨q, q_mem', hdq⟩ := hd.exists_mem_multiset_dvd hdprod obtain ⟨q, q_mem, rfl⟩ := Multiset.mem_map.mp q_mem' replace hdq := hd.dvd_of_dvd_pow hdq have : p ∣ q := dvd_trans (hd.irreducible.dvd_symm hp.irreducible hdp) hdq convert q_mem rw [Finset.mem_val, is_coprime _ (Finset.mem_insert_self p s) _ (Finset.mem_insert_of_mem q_mem) this] #align unique_factorization_monoid.prime_pow_coprime_prod_of_coprime_insert UniqueFactorizationMonoid.prime_pow_coprime_prod_of_coprime_insert /-- If `P` holds for units and powers of primes, and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`, then `P` holds on a product of powers of distinct primes. -/ -- @[elab_as_elim] Porting note: commented out theorem induction_on_prime_power {P : α → Prop} (s : Finset α) (i : α → ℕ) (is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q) (h1 : ∀ {x}, IsUnit x → P x) (hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i)) (hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) : P (∏ p ∈ s, p ^ i p) := by letI := Classical.decEq α induction' s using Finset.induction_on with p f' hpf' ih · simpa using h1 isUnit_one rw [Finset.prod_insert hpf'] exact hcp (prime_pow_coprime_prod_of_coprime_insert i p hpf' is_prime is_coprime) (hpr (i p) (is_prime _ (Finset.mem_insert_self _ _))) (ih (fun q hq => is_prime _ (Finset.mem_insert_of_mem hq)) fun q hq q' hq' => is_coprime _ (Finset.mem_insert_of_mem hq) _ (Finset.mem_insert_of_mem hq')) #align unique_factorization_monoid.induction_on_prime_power UniqueFactorizationMonoid.induction_on_prime_power /-- If `P` holds for `0`, units and powers of primes, and `P x ∧ P y` for coprime `x, y` implies `P (x * y)`, then `P` holds on all `a : α`. -/ @[elab_as_elim] theorem induction_on_coprime {P : α → Prop} (a : α) (h0 : P 0) (h1 : ∀ {x}, IsUnit x → P x) (hpr : ∀ {p} (i : ℕ), Prime p → P (p ^ i)) (hcp : ∀ {x y}, IsRelPrime x y → P x → P y → P (x * y)) : P a := by letI := Classical.decEq α have P_of_associated : ∀ {x y}, Associated x y → P x → P y := by rintro x y ⟨u, rfl⟩ hx exact hcp (fun p _ hpx => isUnit_of_dvd_unit hpx u.isUnit) hx (h1 u.isUnit) by_cases ha0 : a = 0 · rwa [ha0] haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩ letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid refine P_of_associated (normalizedFactors_prod ha0) ?_ rw [← (normalizedFactors a).map_id, Finset.prod_multiset_map_count] refine induction_on_prime_power _ _ ?_ ?_ @h1 @hpr @hcp <;> simp only [Multiset.mem_toFinset] · apply prime_of_normalized_factor · apply normalizedFactors_eq_of_dvd #align unique_factorization_monoid.induction_on_coprime UniqueFactorizationMonoid.induction_on_coprime /-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f` is multiplicative on coprime elements, then `f` is multiplicative on all products of primes. -/ -- @[elab_as_elim] Porting note: commented out theorem multiplicative_prime_power {f : α → β} (s : Finset α) (i j : α → ℕ) (is_prime : ∀ p ∈ s, Prime p) (is_coprime : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q) (h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y) (hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i) (hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) : f (∏ p ∈ s, p ^ (i p + j p)) = f (∏ p ∈ s, p ^ i p) * f (∏ p ∈ s, p ^ j p) := by letI := Classical.decEq α induction' s using Finset.induction_on with p s hps ih · simpa using h1 isUnit_one have hpr_p := is_prime _ (Finset.mem_insert_self _ _) have hpr_s : ∀ p ∈ s, Prime p := fun p hp => is_prime _ (Finset.mem_insert_of_mem hp) have hcp_p := fun i => prime_pow_coprime_prod_of_coprime_insert i p hps is_prime is_coprime have hcp_s : ∀ᵉ (p ∈ s) (q ∈ s), p ∣ q → p = q := fun p hp q hq => is_coprime p (Finset.mem_insert_of_mem hp) q (Finset.mem_insert_of_mem hq) rw [Finset.prod_insert hps, Finset.prod_insert hps, Finset.prod_insert hps, hcp (hcp_p _), hpr _ hpr_p, hcp (hcp_p _), hpr _ hpr_p, hcp (hcp_p (fun p => i p + j p)), hpr _ hpr_p, ih hpr_s hcp_s, pow_add, mul_assoc, mul_left_comm (f p ^ j p), mul_assoc] #align unique_factorization_monoid.multiplicative_prime_power UniqueFactorizationMonoid.multiplicative_prime_power /-- If `f` maps `p ^ i` to `(f p) ^ i` for primes `p`, and `f` is multiplicative on coprime elements, then `f` is multiplicative everywhere. -/ theorem multiplicative_of_coprime (f : α → β) (a b : α) (h0 : f 0 = 0) (h1 : ∀ {x y}, IsUnit y → f (x * y) = f x * f y) (hpr : ∀ {p} (i : ℕ), Prime p → f (p ^ i) = f p ^ i) (hcp : ∀ {x y}, IsRelPrime x y → f (x * y) = f x * f y) : f (a * b) = f a * f b := by letI := Classical.decEq α by_cases ha0 : a = 0 · rw [ha0, zero_mul, h0, zero_mul] by_cases hb0 : b = 0 · rw [hb0, mul_zero, h0, mul_zero] by_cases hf1 : f 1 = 0 · calc f (a * b) = f (a * b * 1) := by rw [mul_one] _ = 0 := by simp only [h1 isUnit_one, hf1, mul_zero] _ = f a * f (b * 1) := by simp only [h1 isUnit_one, hf1, mul_zero] _ = f a * f b := by rw [mul_one] haveI : Nontrivial α := ⟨⟨_, _, ha0⟩⟩ letI : NormalizationMonoid α := UniqueFactorizationMonoid.normalizationMonoid suffices f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ ((normalizedFactors a).count p + (normalizedFactors b).count p)) = f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ (normalizedFactors a).count p) * f (∏ p ∈ (normalizedFactors a).toFinset ∪ (normalizedFactors b).toFinset, p ^ (normalizedFactors b).count p) by obtain ⟨ua, a_eq⟩ := normalizedFactors_prod ha0 obtain ⟨ub, b_eq⟩ := normalizedFactors_prod hb0 rw [← a_eq, ← b_eq, mul_right_comm (Multiset.prod (normalizedFactors a)) ua (Multiset.prod (normalizedFactors b) * ub), h1 ua.isUnit, h1 ub.isUnit, h1 ua.isUnit, ← mul_assoc, h1 ub.isUnit, mul_right_comm _ (f ua), ← mul_assoc] congr rw [← (normalizedFactors a).map_id, ← (normalizedFactors b).map_id, Finset.prod_multiset_map_count, Finset.prod_multiset_map_count, Finset.prod_subset (Finset.subset_union_left (s₂:=(normalizedFactors b).toFinset)), Finset.prod_subset (Finset.subset_union_right (s₂:=(normalizedFactors b).toFinset)), ← Finset.prod_mul_distrib] · simp_rw [id, ← pow_add, this] all_goals simp only [Multiset.mem_toFinset] · intro p _ hpb simp [hpb] · intro p _ hpa simp [hpa] refine multiplicative_prime_power _ _ _ ?_ ?_ @h1 @hpr @hcp all_goals simp only [Multiset.mem_toFinset, Finset.mem_union] · rintro p (hpa | hpb) <;> apply prime_of_normalized_factor <;> assumption · rintro p (hp | hp) q (hq | hq) hdvd <;> rw [← normalize_normalized_factor _ hp, ← normalize_normalized_factor _ hq] <;> exact normalize_eq_normalize hdvd ((prime_of_normalized_factor _ hp).irreducible.dvd_symm (prime_of_normalized_factor _ hq).irreducible hdvd) #align unique_factorization_monoid.multiplicative_of_coprime UniqueFactorizationMonoid.multiplicative_of_coprime end Multiplicative end UniqueFactorizationMonoid namespace Associates open UniqueFactorizationMonoid Associated Multiset variable [CancelCommMonoidWithZero α] /-- `FactorSet α` representation elements of unique factorization domain as multisets. `Multiset α` produced by `normalizedFactors` are only unique up to associated elements, while the multisets in `FactorSet α` are unique by equality and restricted to irreducible elements. This gives us a representation of each element as a unique multisets (or the added ⊤ for 0), which has a complete lattice structure. Infimum is the greatest common divisor and supremum is the least common multiple. -/ abbrev FactorSet.{u} (α : Type u) [CancelCommMonoidWithZero α] : Type u := WithTop (Multiset { a : Associates α // Irreducible a }) #align associates.factor_set Associates.FactorSet attribute [local instance] Associated.setoid theorem FactorSet.coe_add {a b : Multiset { a : Associates α // Irreducible a }} : (↑(a + b) : FactorSet α) = a + b := by norm_cast #align associates.factor_set.coe_add Associates.FactorSet.coe_add theorem FactorSet.sup_add_inf_eq_add [DecidableEq (Associates α)] : ∀ a b : FactorSet α, a ⊔ b + a ⊓ b = a + b | ⊤, b => show ⊤ ⊔ b + ⊤ ⊓ b = ⊤ + b by simp | a, ⊤ => show a ⊔ ⊤ + a ⊓ ⊤ = a + ⊤ by simp | WithTop.some a, WithTop.some b => show (a : FactorSet α) ⊔ b + (a : FactorSet α) ⊓ b = a + b by rw [← WithTop.coe_sup, ← WithTop.coe_inf, ← WithTop.coe_add, ← WithTop.coe_add, WithTop.coe_eq_coe] exact Multiset.union_add_inter _ _ #align associates.factor_set.sup_add_inf_eq_add Associates.FactorSet.sup_add_inf_eq_add /-- Evaluates the product of a `FactorSet` to be the product of the corresponding multiset, or `0` if there is none. -/ def FactorSet.prod : FactorSet α → Associates α | ⊤ => 0 | WithTop.some s => (s.map (↑)).prod #align associates.factor_set.prod Associates.FactorSet.prod @[simp] theorem prod_top : (⊤ : FactorSet α).prod = 0 := rfl #align associates.prod_top Associates.prod_top @[simp] theorem prod_coe {s : Multiset { a : Associates α // Irreducible a }} : FactorSet.prod (s : FactorSet α) = (s.map (↑)).prod := rfl #align associates.prod_coe Associates.prod_coe @[simp] theorem prod_add : ∀ a b : FactorSet α, (a + b).prod = a.prod * b.prod | ⊤, b => show (⊤ + b).prod = (⊤ : FactorSet α).prod * b.prod by simp | a, ⊤ => show (a + ⊤).prod = a.prod * (⊤ : FactorSet α).prod by simp | WithTop.some a, WithTop.some b => by rw [← FactorSet.coe_add, prod_coe, prod_coe, prod_coe, Multiset.map_add, Multiset.prod_add] #align associates.prod_add Associates.prod_add @[gcongr] theorem prod_mono : ∀ {a b : FactorSet α}, a ≤ b → a.prod ≤ b.prod | ⊤, b, h => by have : b = ⊤ := top_unique h rw [this, prod_top] | a, ⊤, _ => show a.prod ≤ (⊤ : FactorSet α).prod by simp | WithTop.some a, WithTop.some b, h => prod_le_prod <| Multiset.map_le_map <| WithTop.coe_le_coe.1 <| h #align associates.prod_mono Associates.prod_mono theorem FactorSet.prod_eq_zero_iff [Nontrivial α] (p : FactorSet α) : p.prod = 0 ↔ p = ⊤ := by unfold FactorSet at p induction p -- TODO: `induction_eliminator` doesn't work with `abbrev` · simp only [iff_self_iff, eq_self_iff_true, Associates.prod_top] · rw [prod_coe, Multiset.prod_eq_zero_iff, Multiset.mem_map, eq_false WithTop.coe_ne_top, iff_false_iff, not_exists] exact fun a => not_and_of_not_right _ a.prop.ne_zero #align associates.factor_set.prod_eq_zero_iff Associates.FactorSet.prod_eq_zero_iff section count variable [DecidableEq (Associates α)] /-- `bcount p s` is the multiplicity of `p` in the FactorSet `s` (with bundled `p`)-/ def bcount (p : { a : Associates α // Irreducible a }) : FactorSet α → ℕ | ⊤ => 0 | WithTop.some s => s.count p #align associates.bcount Associates.bcount variable [∀ p : Associates α, Decidable (Irreducible p)] {p : Associates α} /-- `count p s` is the multiplicity of the irreducible `p` in the FactorSet `s`. If `p` is not irreducible, `count p s` is defined to be `0`. -/ def count (p : Associates α) : FactorSet α → ℕ := if hp : Irreducible p then bcount ⟨p, hp⟩ else 0 #align associates.count Associates.count @[simp] theorem count_some (hp : Irreducible p) (s : Multiset _) : count p (WithTop.some s) = s.count ⟨p, hp⟩ := by simp only [count, dif_pos hp, bcount] #align associates.count_some Associates.count_some @[simp] theorem count_zero (hp : Irreducible p) : count p (0 : FactorSet α) = 0 := by simp only [count, dif_pos hp, bcount, Multiset.count_zero] #align associates.count_zero Associates.count_zero theorem count_reducible (hp : ¬Irreducible p) : count p = 0 := dif_neg hp #align associates.count_reducible Associates.count_reducible end count section Mem /-- membership in a FactorSet (bundled version) -/ def BfactorSetMem : { a : Associates α // Irreducible a } → FactorSet α → Prop | _, ⊤ => True | p, some l => p ∈ l #align associates.bfactor_set_mem Associates.BfactorSetMem /-- `FactorSetMem p s` is the predicate that the irreducible `p` is a member of `s : FactorSet α`. If `p` is not irreducible, `p` is not a member of any `FactorSet`. -/ def FactorSetMem (p : Associates α) (s : FactorSet α) : Prop := letI : Decidable (Irreducible p) := Classical.dec _ if hp : Irreducible p then BfactorSetMem ⟨p, hp⟩ s else False #align associates.factor_set_mem Associates.FactorSetMem instance : Membership (Associates α) (FactorSet α) := ⟨FactorSetMem⟩ @[simp] theorem factorSetMem_eq_mem (p : Associates α) (s : FactorSet α) : FactorSetMem p s = (p ∈ s) := rfl #align associates.factor_set_mem_eq_mem Associates.factorSetMem_eq_mem theorem mem_factorSet_top {p : Associates α} {hp : Irreducible p} : p ∈ (⊤ : FactorSet α) := by dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; exact trivial #align associates.mem_factor_set_top Associates.mem_factorSet_top theorem mem_factorSet_some {p : Associates α} {hp : Irreducible p} {l : Multiset { a : Associates α // Irreducible a }} : p ∈ (l : FactorSet α) ↔ Subtype.mk p hp ∈ l := by dsimp only [Membership.mem]; dsimp only [FactorSetMem]; split_ifs; rfl #align associates.mem_factor_set_some Associates.mem_factorSet_some theorem reducible_not_mem_factorSet {p : Associates α} (hp : ¬Irreducible p) (s : FactorSet α) : ¬p ∈ s := fun h ↦ by rwa [← factorSetMem_eq_mem, FactorSetMem, dif_neg hp] at h #align associates.reducible_not_mem_factor_set Associates.reducible_not_mem_factorSet theorem irreducible_of_mem_factorSet {p : Associates α} {s : FactorSet α} (h : p ∈ s) : Irreducible p := by_contra fun hp ↦ reducible_not_mem_factorSet hp s h end Mem variable [UniqueFactorizationMonoid α] theorem unique' {p q : Multiset (Associates α)} : (∀ a ∈ p, Irreducible a) → (∀ a ∈ q, Irreducible a) → p.prod = q.prod → p = q := by apply Multiset.induction_on_multiset_quot p apply Multiset.induction_on_multiset_quot q intro s t hs ht eq refine Multiset.map_mk_eq_map_mk_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ ?_) · exact fun a ha => irreducible_mk.1 <| hs _ <| Multiset.mem_map_of_mem _ ha · exact fun a ha => irreducible_mk.1 <| ht _ <| Multiset.mem_map_of_mem _ ha have eq' : (Quot.mk Setoid.r : α → Associates α) = Associates.mk := funext quot_mk_eq_mk rwa [eq', prod_mk, prod_mk, mk_eq_mk_iff_associated] at eq #align associates.unique' Associates.unique' theorem FactorSet.unique [Nontrivial α] {p q : FactorSet α} (h : p.prod = q.prod) : p = q := by -- TODO: `induction_eliminator` doesn't work with `abbrev` unfold FactorSet at p q induction p <;> induction q · rfl · rw [eq_comm, ← FactorSet.prod_eq_zero_iff, ← h, Associates.prod_top] · rw [← FactorSet.prod_eq_zero_iff, h, Associates.prod_top] · congr 1 rw [← Multiset.map_eq_map Subtype.coe_injective] apply unique' _ _ h <;> · intro a ha obtain ⟨⟨a', irred⟩, -, rfl⟩ := Multiset.mem_map.mp ha rwa [Subtype.coe_mk] #align associates.factor_set.unique Associates.FactorSet.unique theorem prod_le_prod_iff_le [Nontrivial α] {p q : Multiset (Associates α)} (hp : ∀ a ∈ p, Irreducible a) (hq : ∀ a ∈ q, Irreducible a) : p.prod ≤ q.prod ↔ p ≤ q := by refine ⟨?_, prod_le_prod⟩ rintro ⟨c, eqc⟩ refine Multiset.le_iff_exists_add.2 ⟨factors c, unique' hq (fun x hx ↦ ?_) ?_⟩ · obtain h | h := Multiset.mem_add.1 hx · exact hp x h · exact irreducible_of_factor _ h · rw [eqc, Multiset.prod_add] congr refine associated_iff_eq.mp (factors_prod fun hc => ?_).symm refine not_irreducible_zero (hq _ ?_) rw [← prod_eq_zero_iff, eqc, hc, mul_zero] #align associates.prod_le_prod_iff_le Associates.prod_le_prod_iff_le /-- This returns the multiset of irreducible factors as a `FactorSet`, a multiset of irreducible associates `WithTop`. -/ noncomputable def factors' (a : α) : Multiset { a : Associates α // Irreducible a } := (factors a).pmap (fun a ha => ⟨Associates.mk a, irreducible_mk.2 ha⟩) irreducible_of_factor #align associates.factors' Associates.factors' @[simp] theorem map_subtype_coe_factors' {a : α} : (factors' a).map (↑) = (factors a).map Associates.mk := by simp [factors', Multiset.map_pmap, Multiset.pmap_eq_map] #align associates.map_subtype_coe_factors' Associates.map_subtype_coe_factors' theorem factors'_cong {a b : α} (h : a ~ᵤ b) : factors' a = factors' b := by obtain rfl | hb := eq_or_ne b 0 · rw [associated_zero_iff_eq_zero] at h rw [h] have ha : a ≠ 0 := by contrapose! hb with ha rw [← associated_zero_iff_eq_zero, ← ha] exact h.symm rw [← Multiset.map_eq_map Subtype.coe_injective, map_subtype_coe_factors', map_subtype_coe_factors', ← rel_associated_iff_map_eq_map] exact factors_unique irreducible_of_factor irreducible_of_factor ((factors_prod ha).trans <| h.trans <| (factors_prod hb).symm) #align associates.factors'_cong Associates.factors'_cong /-- This returns the multiset of irreducible factors of an associate as a `FactorSet`, a multiset of irreducible associates `WithTop`. -/ noncomputable def factors (a : Associates α) : FactorSet α := by classical refine if h : a = 0 then ⊤ else Quotient.hrecOn a (fun x _ => factors' x) ?_ h intro a b hab apply Function.hfunext · have : a ~ᵤ 0 ↔ b ~ᵤ 0 := Iff.intro (fun ha0 => hab.symm.trans ha0) fun hb0 => hab.trans hb0 simp only [associated_zero_iff_eq_zero] at this simp only [quotient_mk_eq_mk, this, mk_eq_zero] exact fun ha hb _ => heq_of_eq <| congr_arg some <| factors'_cong hab #align associates.factors Associates.factors @[simp] theorem factors_zero : (0 : Associates α).factors = ⊤ := dif_pos rfl #align associates.factors_0 Associates.factors_zero @[deprecated (since := "2024-03-16")] alias factors_0 := factors_zero @[simp] theorem factors_mk (a : α) (h : a ≠ 0) : (Associates.mk a).factors = factors' a := by classical apply dif_neg apply mt mk_eq_zero.1 h #align associates.factors_mk Associates.factors_mk @[simp] theorem factors_prod (a : Associates α) : a.factors.prod = a := by rcases Associates.mk_surjective a with ⟨a, rfl⟩ rcases eq_or_ne a 0 with rfl | ha · simp · simp [ha, prod_mk, mk_eq_mk_iff_associated, UniqueFactorizationMonoid.factors_prod, -Quotient.eq] #align associates.factors_prod Associates.factors_prod @[simp] theorem prod_factors [Nontrivial α] (s : FactorSet α) : s.prod.factors = s := FactorSet.unique <| factors_prod _ #align associates.prod_factors Associates.prod_factors @[nontriviality] theorem factors_subsingleton [Subsingleton α] {a : Associates α} : a.factors = ⊤ := by have : Subsingleton (Associates α) := inferInstance convert factors_zero #align associates.factors_subsingleton Associates.factors_subsingleton theorem factors_eq_top_iff_zero {a : Associates α} : a.factors = ⊤ ↔ a = 0 := by nontriviality α exact ⟨fun h ↦ by rwa [← factors_prod a, FactorSet.prod_eq_zero_iff], fun h ↦ h ▸ factors_zero⟩ #align associates.factors_eq_none_iff_zero Associates.factors_eq_top_iff_zero @[deprecated] alias factors_eq_none_iff_zero := factors_eq_top_iff_zero theorem factors_eq_some_iff_ne_zero {a : Associates α} : (∃ s : Multiset { p : Associates α // Irreducible p }, a.factors = s) ↔ a ≠ 0 := by simp_rw [@eq_comm _ a.factors, ← WithTop.ne_top_iff_exists] exact factors_eq_top_iff_zero.not #align associates.factors_eq_some_iff_ne_zero Associates.factors_eq_some_iff_ne_zero theorem eq_of_factors_eq_factors {a b : Associates α} (h : a.factors = b.factors) : a = b := by have : a.factors.prod = b.factors.prod := by rw [h] rwa [factors_prod, factors_prod] at this #align associates.eq_of_factors_eq_factors Associates.eq_of_factors_eq_factors theorem eq_of_prod_eq_prod [Nontrivial α] {a b : FactorSet α} (h : a.prod = b.prod) : a = b := by have : a.prod.factors = b.prod.factors := by rw [h] rwa [prod_factors, prod_factors] at this #align associates.eq_of_prod_eq_prod Associates.eq_of_prod_eq_prod @[simp] theorem factors_mul (a b : Associates α) : (a * b).factors = a.factors + b.factors := by nontriviality α refine eq_of_prod_eq_prod <| eq_of_factors_eq_factors ?_ rw [prod_add, factors_prod, factors_prod, factors_prod] #align associates.factors_mul Associates.factors_mul @[gcongr] theorem factors_mono : ∀ {a b : Associates α}, a ≤ b → a.factors ≤ b.factors | s, t, ⟨d, eq⟩ => by rw [eq, factors_mul]; exact le_add_of_nonneg_right bot_le #align associates.factors_mono Associates.factors_mono @[simp] theorem factors_le {a b : Associates α} : a.factors ≤ b.factors ↔ a ≤ b := by refine ⟨fun h ↦ ?_, factors_mono⟩ have : a.factors.prod ≤ b.factors.prod := prod_mono h rwa [factors_prod, factors_prod] at this #align associates.factors_le Associates.factors_le section count variable [DecidableEq (Associates α)] [∀ p : Associates α, Decidable (Irreducible p)]
Mathlib/RingTheory/UniqueFactorizationDomain.lean
1,540
1,553
theorem eq_factors_of_eq_counts {a b : Associates α} (ha : a ≠ 0) (hb : b ≠ 0) (h : ∀ p : Associates α, Irreducible p → p.count a.factors = p.count b.factors) : a.factors = b.factors := by
obtain ⟨sa, h_sa⟩ := factors_eq_some_iff_ne_zero.mpr ha obtain ⟨sb, h_sb⟩ := factors_eq_some_iff_ne_zero.mpr hb rw [h_sa, h_sb] at h ⊢ rw [WithTop.coe_eq_coe] have h_count : ∀ (p : Associates α) (hp : Irreducible p), sa.count ⟨p, hp⟩ = sb.count ⟨p, hp⟩ := by intro p hp rw [← count_some, ← count_some, h p hp] apply Multiset.toFinsupp.injective ext ⟨p, hp⟩ rw [Multiset.toFinsupp_apply, Multiset.toFinsupp_apply, h_count p hp]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro, Yaël Dillies -/ import Mathlib.Logic.Function.Iterate import Mathlib.Init.Data.Int.Order import Mathlib.Order.Compare import Mathlib.Order.Max import Mathlib.Order.RelClasses import Mathlib.Tactic.Choose #align_import order.monotone.basic from "leanprover-community/mathlib"@"554bb38de8ded0dafe93b7f18f0bfee6ef77dc5d" /-! # Monotonicity This file defines (strictly) monotone/antitone functions. Contrary to standard mathematical usage, "monotone"/"mono" here means "increasing", not "increasing or decreasing". We use "antitone"/"anti" to mean "decreasing". ## Definitions * `Monotone f`: A function `f` between two preorders is monotone if `a ≤ b` implies `f a ≤ f b`. * `Antitone f`: A function `f` between two preorders is antitone if `a ≤ b` implies `f b ≤ f a`. * `MonotoneOn f s`: Same as `Monotone f`, but for all `a, b ∈ s`. * `AntitoneOn f s`: Same as `Antitone f`, but for all `a, b ∈ s`. * `StrictMono f` : A function `f` between two preorders is strictly monotone if `a < b` implies `f a < f b`. * `StrictAnti f` : A function `f` between two preorders is strictly antitone if `a < b` implies `f b < f a`. * `StrictMonoOn f s`: Same as `StrictMono f`, but for all `a, b ∈ s`. * `StrictAntiOn f s`: Same as `StrictAnti f`, but for all `a, b ∈ s`. ## Main theorems * `monotone_nat_of_le_succ`, `monotone_int_of_le_succ`: If `f : ℕ → α` or `f : ℤ → α` and `f n ≤ f (n + 1)` for all `n`, then `f` is monotone. * `antitone_nat_of_succ_le`, `antitone_int_of_succ_le`: If `f : ℕ → α` or `f : ℤ → α` and `f (n + 1) ≤ f n` for all `n`, then `f` is antitone. * `strictMono_nat_of_lt_succ`, `strictMono_int_of_lt_succ`: If `f : ℕ → α` or `f : ℤ → α` and `f n < f (n + 1)` for all `n`, then `f` is strictly monotone. * `strictAnti_nat_of_succ_lt`, `strictAnti_int_of_succ_lt`: If `f : ℕ → α` or `f : ℤ → α` and `f (n + 1) < f n` for all `n`, then `f` is strictly antitone. ## Implementation notes Some of these definitions used to only require `LE α` or `LT α`. The advantage of this is unclear and it led to slight elaboration issues. Now, everything requires `Preorder α` and seems to work fine. Related Zulip discussion: https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Order.20diamond/near/254353352. ## TODO The above theorems are also true in `ℕ+`, `Fin n`... To make that work, we need `SuccOrder α` and `IsSuccArchimedean α`. ## Tags monotone, strictly monotone, antitone, strictly antitone, increasing, strictly increasing, decreasing, strictly decreasing -/ open Function OrderDual universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {π : ι → Type*} {r : α → α → Prop} section MonotoneDef variable [Preorder α] [Preorder β] /-- A function `f` is monotone if `a ≤ b` implies `f a ≤ f b`. -/ def Monotone (f : α → β) : Prop := ∀ ⦃a b⦄, a ≤ b → f a ≤ f b #align monotone Monotone /-- A function `f` is antitone if `a ≤ b` implies `f b ≤ f a`. -/ def Antitone (f : α → β) : Prop := ∀ ⦃a b⦄, a ≤ b → f b ≤ f a #align antitone Antitone /-- A function `f` is monotone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f a ≤ f b`. -/ def MonotoneOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a ≤ b → f a ≤ f b #align monotone_on MonotoneOn /-- A function `f` is antitone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f b ≤ f a`. -/ def AntitoneOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a ≤ b → f b ≤ f a #align antitone_on AntitoneOn /-- A function `f` is strictly monotone if `a < b` implies `f a < f b`. -/ def StrictMono (f : α → β) : Prop := ∀ ⦃a b⦄, a < b → f a < f b #align strict_mono StrictMono /-- A function `f` is strictly antitone if `a < b` implies `f b < f a`. -/ def StrictAnti (f : α → β) : Prop := ∀ ⦃a b⦄, a < b → f b < f a #align strict_anti StrictAnti /-- A function `f` is strictly monotone on `s` if, for all `a, b ∈ s`, `a < b` implies `f a < f b`. -/ def StrictMonoOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f a < f b #align strict_mono_on StrictMonoOn /-- A function `f` is strictly antitone on `s` if, for all `a, b ∈ s`, `a < b` implies `f b < f a`. -/ def StrictAntiOn (f : α → β) (s : Set α) : Prop := ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f b < f a #align strict_anti_on StrictAntiOn end MonotoneDef section Decidable variable [Preorder α] [Preorder β] {f : α → β} {s : Set α} instance [i : Decidable (∀ a b, a ≤ b → f a ≤ f b)] : Decidable (Monotone f) := i instance [i : Decidable (∀ a b, a ≤ b → f b ≤ f a)] : Decidable (Antitone f) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f a ≤ f b)] : Decidable (MonotoneOn f s) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f b ≤ f a)] : Decidable (AntitoneOn f s) := i instance [i : Decidable (∀ a b, a < b → f a < f b)] : Decidable (StrictMono f) := i instance [i : Decidable (∀ a b, a < b → f b < f a)] : Decidable (StrictAnti f) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f a < f b)] : Decidable (StrictMonoOn f s) := i instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f b < f a)] : Decidable (StrictAntiOn f s) := i end Decidable /-! ### Monotonicity on the dual order Strictly, many of the `*On.dual` lemmas in this section should use `ofDual ⁻¹' s` instead of `s`, but right now this is not possible as `Set.preimage` is not defined yet, and importing it creates an import cycle. Often, you should not need the rewriting lemmas. Instead, you probably want to add `.dual`, `.dual_left` or `.dual_right` to your `Monotone`/`Antitone` hypothesis. -/ section OrderDual variable [Preorder α] [Preorder β] {f : α → β} {s : Set α} @[simp] theorem monotone_comp_ofDual_iff : Monotone (f ∘ ofDual) ↔ Antitone f := forall_swap #align monotone_comp_of_dual_iff monotone_comp_ofDual_iff @[simp] theorem antitone_comp_ofDual_iff : Antitone (f ∘ ofDual) ↔ Monotone f := forall_swap #align antitone_comp_of_dual_iff antitone_comp_ofDual_iff -- Porting note: -- Here (and below) without the type ascription, Lean is seeing through the -- defeq `βᵒᵈ = β` and picking up the wrong `Preorder` instance. -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/logic.2Eequiv.2Ebasic.20mathlib4.23631/near/311744939 @[simp] theorem monotone_toDual_comp_iff : Monotone (toDual ∘ f : α → βᵒᵈ) ↔ Antitone f := Iff.rfl #align monotone_to_dual_comp_iff monotone_toDual_comp_iff @[simp] theorem antitone_toDual_comp_iff : Antitone (toDual ∘ f : α → βᵒᵈ) ↔ Monotone f := Iff.rfl #align antitone_to_dual_comp_iff antitone_toDual_comp_iff @[simp] theorem monotoneOn_comp_ofDual_iff : MonotoneOn (f ∘ ofDual) s ↔ AntitoneOn f s := forall₂_swap #align monotone_on_comp_of_dual_iff monotoneOn_comp_ofDual_iff @[simp] theorem antitoneOn_comp_ofDual_iff : AntitoneOn (f ∘ ofDual) s ↔ MonotoneOn f s := forall₂_swap #align antitone_on_comp_of_dual_iff antitoneOn_comp_ofDual_iff @[simp] theorem monotoneOn_toDual_comp_iff : MonotoneOn (toDual ∘ f : α → βᵒᵈ) s ↔ AntitoneOn f s := Iff.rfl #align monotone_on_to_dual_comp_iff monotoneOn_toDual_comp_iff @[simp] theorem antitoneOn_toDual_comp_iff : AntitoneOn (toDual ∘ f : α → βᵒᵈ) s ↔ MonotoneOn f s := Iff.rfl #align antitone_on_to_dual_comp_iff antitoneOn_toDual_comp_iff @[simp] theorem strictMono_comp_ofDual_iff : StrictMono (f ∘ ofDual) ↔ StrictAnti f := forall_swap #align strict_mono_comp_of_dual_iff strictMono_comp_ofDual_iff @[simp] theorem strictAnti_comp_ofDual_iff : StrictAnti (f ∘ ofDual) ↔ StrictMono f := forall_swap #align strict_anti_comp_of_dual_iff strictAnti_comp_ofDual_iff @[simp] theorem strictMono_toDual_comp_iff : StrictMono (toDual ∘ f : α → βᵒᵈ) ↔ StrictAnti f := Iff.rfl #align strict_mono_to_dual_comp_iff strictMono_toDual_comp_iff @[simp] theorem strictAnti_toDual_comp_iff : StrictAnti (toDual ∘ f : α → βᵒᵈ) ↔ StrictMono f := Iff.rfl #align strict_anti_to_dual_comp_iff strictAnti_toDual_comp_iff @[simp] theorem strictMonoOn_comp_ofDual_iff : StrictMonoOn (f ∘ ofDual) s ↔ StrictAntiOn f s := forall₂_swap #align strict_mono_on_comp_of_dual_iff strictMonoOn_comp_ofDual_iff @[simp] theorem strictAntiOn_comp_ofDual_iff : StrictAntiOn (f ∘ ofDual) s ↔ StrictMonoOn f s := forall₂_swap #align strict_anti_on_comp_of_dual_iff strictAntiOn_comp_ofDual_iff @[simp] theorem strictMonoOn_toDual_comp_iff : StrictMonoOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictAntiOn f s := Iff.rfl #align strict_mono_on_to_dual_comp_iff strictMonoOn_toDual_comp_iff @[simp] theorem strictAntiOn_toDual_comp_iff : StrictAntiOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictMonoOn f s := Iff.rfl #align strict_anti_on_to_dual_comp_iff strictAntiOn_toDual_comp_iff theorem monotone_dual_iff : Monotone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Monotone f := by rw [monotone_toDual_comp_iff, antitone_comp_ofDual_iff] theorem antitone_dual_iff : Antitone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Antitone f := by rw [antitone_toDual_comp_iff, monotone_comp_ofDual_iff] theorem monotoneOn_dual_iff : MonotoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ MonotoneOn f s := by rw [monotoneOn_toDual_comp_iff, antitoneOn_comp_ofDual_iff] theorem antitoneOn_dual_iff : AntitoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ AntitoneOn f s := by rw [antitoneOn_toDual_comp_iff, monotoneOn_comp_ofDual_iff] theorem strictMono_dual_iff : StrictMono (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictMono f := by rw [strictMono_toDual_comp_iff, strictAnti_comp_ofDual_iff] theorem strictAnti_dual_iff : StrictAnti (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictAnti f := by rw [strictAnti_toDual_comp_iff, strictMono_comp_ofDual_iff] theorem strictMonoOn_dual_iff : StrictMonoOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictMonoOn f s := by rw [strictMonoOn_toDual_comp_iff, strictAntiOn_comp_ofDual_iff] theorem strictAntiOn_dual_iff : StrictAntiOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictAntiOn f s := by rw [strictAntiOn_toDual_comp_iff, strictMonoOn_comp_ofDual_iff] alias ⟨_, Monotone.dual_left⟩ := antitone_comp_ofDual_iff #align monotone.dual_left Monotone.dual_left alias ⟨_, Antitone.dual_left⟩ := monotone_comp_ofDual_iff #align antitone.dual_left Antitone.dual_left alias ⟨_, Monotone.dual_right⟩ := antitone_toDual_comp_iff #align monotone.dual_right Monotone.dual_right alias ⟨_, Antitone.dual_right⟩ := monotone_toDual_comp_iff #align antitone.dual_right Antitone.dual_right alias ⟨_, MonotoneOn.dual_left⟩ := antitoneOn_comp_ofDual_iff #align monotone_on.dual_left MonotoneOn.dual_left alias ⟨_, AntitoneOn.dual_left⟩ := monotoneOn_comp_ofDual_iff #align antitone_on.dual_left AntitoneOn.dual_left alias ⟨_, MonotoneOn.dual_right⟩ := antitoneOn_toDual_comp_iff #align monotone_on.dual_right MonotoneOn.dual_right alias ⟨_, AntitoneOn.dual_right⟩ := monotoneOn_toDual_comp_iff #align antitone_on.dual_right AntitoneOn.dual_right alias ⟨_, StrictMono.dual_left⟩ := strictAnti_comp_ofDual_iff #align strict_mono.dual_left StrictMono.dual_left alias ⟨_, StrictAnti.dual_left⟩ := strictMono_comp_ofDual_iff #align strict_anti.dual_left StrictAnti.dual_left alias ⟨_, StrictMono.dual_right⟩ := strictAnti_toDual_comp_iff #align strict_mono.dual_right StrictMono.dual_right alias ⟨_, StrictAnti.dual_right⟩ := strictMono_toDual_comp_iff #align strict_anti.dual_right StrictAnti.dual_right alias ⟨_, StrictMonoOn.dual_left⟩ := strictAntiOn_comp_ofDual_iff #align strict_mono_on.dual_left StrictMonoOn.dual_left alias ⟨_, StrictAntiOn.dual_left⟩ := strictMonoOn_comp_ofDual_iff #align strict_anti_on.dual_left StrictAntiOn.dual_left alias ⟨_, StrictMonoOn.dual_right⟩ := strictAntiOn_toDual_comp_iff #align strict_mono_on.dual_right StrictMonoOn.dual_right alias ⟨_, StrictAntiOn.dual_right⟩ := strictMonoOn_toDual_comp_iff #align strict_anti_on.dual_right StrictAntiOn.dual_right alias ⟨_, Monotone.dual⟩ := monotone_dual_iff #align monotone.dual Monotone.dual alias ⟨_, Antitone.dual⟩ := antitone_dual_iff #align antitone.dual Antitone.dual alias ⟨_, MonotoneOn.dual⟩ := monotoneOn_dual_iff #align monotone_on.dual MonotoneOn.dual alias ⟨_, AntitoneOn.dual⟩ := antitoneOn_dual_iff #align antitone_on.dual AntitoneOn.dual alias ⟨_, StrictMono.dual⟩ := strictMono_dual_iff #align strict_mono.dual StrictMono.dual alias ⟨_, StrictAnti.dual⟩ := strictAnti_dual_iff #align strict_anti.dual StrictAnti.dual alias ⟨_, StrictMonoOn.dual⟩ := strictMonoOn_dual_iff #align strict_mono_on.dual StrictMonoOn.dual alias ⟨_, StrictAntiOn.dual⟩ := strictAntiOn_dual_iff #align strict_anti_on.dual StrictAntiOn.dual end OrderDual /-! ### Monotonicity in function spaces -/ section Preorder variable [Preorder α] theorem Monotone.comp_le_comp_left [Preorder β] {f : β → α} {g h : γ → β} (hf : Monotone f) (le_gh : g ≤ h) : LE.le.{max w u} (f ∘ g) (f ∘ h) := fun x ↦ hf (le_gh x) #align monotone.comp_le_comp_left Monotone.comp_le_comp_left variable [Preorder γ] theorem monotone_lam {f : α → β → γ} (hf : ∀ b, Monotone fun a ↦ f a b) : Monotone f := fun _ _ h b ↦ hf b h #align monotone_lam monotone_lam theorem monotone_app (f : β → α → γ) (b : β) (hf : Monotone fun a b ↦ f b a) : Monotone (f b) := fun _ _ h ↦ hf h b #align monotone_app monotone_app theorem antitone_lam {f : α → β → γ} (hf : ∀ b, Antitone fun a ↦ f a b) : Antitone f := fun _ _ h b ↦ hf b h #align antitone_lam antitone_lam theorem antitone_app (f : β → α → γ) (b : β) (hf : Antitone fun a b ↦ f b a) : Antitone (f b) := fun _ _ h ↦ hf h b #align antitone_app antitone_app end Preorder theorem Function.monotone_eval {ι : Type u} {α : ι → Type v} [∀ i, Preorder (α i)] (i : ι) : Monotone (Function.eval i : (∀ i, α i) → α i) := fun _ _ H ↦ H i #align function.monotone_eval Function.monotone_eval /-! ### Monotonicity hierarchy -/ section Preorder variable [Preorder α] section Preorder variable [Preorder β] {f : α → β} {a b : α} /-! These four lemmas are there to strip off the semi-implicit arguments `⦃a b : α⦄`. This is useful when you do not want to apply a `Monotone` assumption (i.e. your goal is `a ≤ b → f a ≤ f b`). However if you find yourself writing `hf.imp h`, then you should have written `hf h` instead. -/ theorem Monotone.imp (hf : Monotone f) (h : a ≤ b) : f a ≤ f b := hf h #align monotone.imp Monotone.imp theorem Antitone.imp (hf : Antitone f) (h : a ≤ b) : f b ≤ f a := hf h #align antitone.imp Antitone.imp theorem StrictMono.imp (hf : StrictMono f) (h : a < b) : f a < f b := hf h #align strict_mono.imp StrictMono.imp theorem StrictAnti.imp (hf : StrictAnti f) (h : a < b) : f b < f a := hf h #align strict_anti.imp StrictAnti.imp protected theorem Monotone.monotoneOn (hf : Monotone f) (s : Set α) : MonotoneOn f s := fun _ _ _ _ ↦ hf.imp #align monotone.monotone_on Monotone.monotoneOn protected theorem Antitone.antitoneOn (hf : Antitone f) (s : Set α) : AntitoneOn f s := fun _ _ _ _ ↦ hf.imp #align antitone.antitone_on Antitone.antitoneOn @[simp] theorem monotoneOn_univ : MonotoneOn f Set.univ ↔ Monotone f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.monotoneOn _⟩ #align monotone_on_univ monotoneOn_univ @[simp] theorem antitoneOn_univ : AntitoneOn f Set.univ ↔ Antitone f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.antitoneOn _⟩ #align antitone_on_univ antitoneOn_univ protected theorem StrictMono.strictMonoOn (hf : StrictMono f) (s : Set α) : StrictMonoOn f s := fun _ _ _ _ ↦ hf.imp #align strict_mono.strict_mono_on StrictMono.strictMonoOn protected theorem StrictAnti.strictAntiOn (hf : StrictAnti f) (s : Set α) : StrictAntiOn f s := fun _ _ _ _ ↦ hf.imp #align strict_anti.strict_anti_on StrictAnti.strictAntiOn @[simp] theorem strictMonoOn_univ : StrictMonoOn f Set.univ ↔ StrictMono f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.strictMonoOn _⟩ #align strict_mono_on_univ strictMonoOn_univ @[simp] theorem strictAntiOn_univ : StrictAntiOn f Set.univ ↔ StrictAnti f := ⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.strictAntiOn _⟩ #align strict_anti_on_univ strictAntiOn_univ end Preorder section PartialOrder variable [PartialOrder β] {f : α → β} theorem Monotone.strictMono_of_injective (h₁ : Monotone f) (h₂ : Injective f) : StrictMono f := fun _ _ h ↦ (h₁ h.le).lt_of_ne fun H ↦ h.ne <| h₂ H #align monotone.strict_mono_of_injective Monotone.strictMono_of_injective theorem Antitone.strictAnti_of_injective (h₁ : Antitone f) (h₂ : Injective f) : StrictAnti f := fun _ _ h ↦ (h₁ h.le).lt_of_ne fun H ↦ h.ne <| h₂ H.symm #align antitone.strict_anti_of_injective Antitone.strictAnti_of_injective end PartialOrder end Preorder section PartialOrder variable [PartialOrder α] [Preorder β] {f : α → β} {s : Set α} theorem monotone_iff_forall_lt : Monotone f ↔ ∀ ⦃a b⦄, a < b → f a ≤ f b := forall₂_congr fun _ _ ↦ ⟨fun hf h ↦ hf h.le, fun hf h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).le) hf⟩ #align monotone_iff_forall_lt monotone_iff_forall_lt theorem antitone_iff_forall_lt : Antitone f ↔ ∀ ⦃a b⦄, a < b → f b ≤ f a := forall₂_congr fun _ _ ↦ ⟨fun hf h ↦ hf h.le, fun hf h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).ge) hf⟩ #align antitone_iff_forall_lt antitone_iff_forall_lt theorem monotoneOn_iff_forall_lt : MonotoneOn f s ↔ ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f a ≤ f b := ⟨fun hf _ ha _ hb h ↦ hf ha hb h.le, fun hf _ ha _ hb h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).le) (hf ha hb)⟩ #align monotone_on_iff_forall_lt monotoneOn_iff_forall_lt theorem antitoneOn_iff_forall_lt : AntitoneOn f s ↔ ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f b ≤ f a := ⟨fun hf _ ha _ hb h ↦ hf ha hb h.le, fun hf _ ha _ hb h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).ge) (hf ha hb)⟩ #align antitone_on_iff_forall_lt antitoneOn_iff_forall_lt -- `Preorder α` isn't strong enough: if the preorder on `α` is an equivalence relation, -- then `StrictMono f` is vacuously true. protected theorem StrictMonoOn.monotoneOn (hf : StrictMonoOn f s) : MonotoneOn f s := monotoneOn_iff_forall_lt.2 fun _ ha _ hb h ↦ (hf ha hb h).le #align strict_mono_on.monotone_on StrictMonoOn.monotoneOn protected theorem StrictAntiOn.antitoneOn (hf : StrictAntiOn f s) : AntitoneOn f s := antitoneOn_iff_forall_lt.2 fun _ ha _ hb h ↦ (hf ha hb h).le #align strict_anti_on.antitone_on StrictAntiOn.antitoneOn protected theorem StrictMono.monotone (hf : StrictMono f) : Monotone f := monotone_iff_forall_lt.2 fun _ _ h ↦ (hf h).le #align strict_mono.monotone StrictMono.monotone protected theorem StrictAnti.antitone (hf : StrictAnti f) : Antitone f := antitone_iff_forall_lt.2 fun _ _ h ↦ (hf h).le #align strict_anti.antitone StrictAnti.antitone end PartialOrder /-! ### Monotonicity from and to subsingletons -/ namespace Subsingleton variable [Preorder α] [Preorder β] protected theorem monotone [Subsingleton α] (f : α → β) : Monotone f := fun _ _ _ ↦ (congr_arg _ <| Subsingleton.elim _ _).le #align subsingleton.monotone Subsingleton.monotone protected theorem antitone [Subsingleton α] (f : α → β) : Antitone f := fun _ _ _ ↦ (congr_arg _ <| Subsingleton.elim _ _).le #align subsingleton.antitone Subsingleton.antitone theorem monotone' [Subsingleton β] (f : α → β) : Monotone f := fun _ _ _ ↦ (Subsingleton.elim _ _).le #align subsingleton.monotone' Subsingleton.monotone' theorem antitone' [Subsingleton β] (f : α → β) : Antitone f := fun _ _ _ ↦ (Subsingleton.elim _ _).le #align subsingleton.antitone' Subsingleton.antitone' protected theorem strictMono [Subsingleton α] (f : α → β) : StrictMono f := fun _ _ h ↦ (h.ne <| Subsingleton.elim _ _).elim #align subsingleton.strict_mono Subsingleton.strictMono protected theorem strictAnti [Subsingleton α] (f : α → β) : StrictAnti f := fun _ _ h ↦ (h.ne <| Subsingleton.elim _ _).elim #align subsingleton.strict_anti Subsingleton.strictAnti end Subsingleton /-! ### Miscellaneous monotonicity results -/ theorem monotone_id [Preorder α] : Monotone (id : α → α) := fun _ _ ↦ id #align monotone_id monotone_id theorem monotoneOn_id [Preorder α] {s : Set α} : MonotoneOn id s := fun _ _ _ _ ↦ id #align monotone_on_id monotoneOn_id theorem strictMono_id [Preorder α] : StrictMono (id : α → α) := fun _ _ ↦ id #align strict_mono_id strictMono_id theorem strictMonoOn_id [Preorder α] {s : Set α} : StrictMonoOn id s := fun _ _ _ _ ↦ id #align strict_mono_on_id strictMonoOn_id theorem monotone_const [Preorder α] [Preorder β] {c : β} : Monotone fun _ : α ↦ c := fun _ _ _ ↦ le_rfl #align monotone_const monotone_const theorem monotoneOn_const [Preorder α] [Preorder β] {c : β} {s : Set α} : MonotoneOn (fun _ : α ↦ c) s := fun _ _ _ _ _ ↦ le_rfl #align monotone_on_const monotoneOn_const theorem antitone_const [Preorder α] [Preorder β] {c : β} : Antitone fun _ : α ↦ c := fun _ _ _ ↦ le_refl c #align antitone_const antitone_const theorem antitoneOn_const [Preorder α] [Preorder β] {c : β} {s : Set α} : AntitoneOn (fun _ : α ↦ c) s := fun _ _ _ _ _ ↦ le_rfl #align antitone_on_const antitoneOn_const theorem strictMono_of_le_iff_le [Preorder α] [Preorder β] {f : α → β} (h : ∀ x y, x ≤ y ↔ f x ≤ f y) : StrictMono f := fun _ _ ↦ (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1 #align strict_mono_of_le_iff_le strictMono_of_le_iff_le theorem strictAnti_of_le_iff_le [Preorder α] [Preorder β] {f : α → β} (h : ∀ x y, x ≤ y ↔ f y ≤ f x) : StrictAnti f := fun _ _ ↦ (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1 #align strict_anti_of_le_iff_le strictAnti_of_le_iff_le -- Porting note: mathlib3 proof uses `contrapose` tactic theorem injective_of_lt_imp_ne [LinearOrder α] {f : α → β} (h : ∀ x y, x < y → f x ≠ f y) : Injective f := by intro x y hf rcases lt_trichotomy x y with (hxy | rfl | hxy) · exact absurd hf <| h _ _ hxy · rfl · exact absurd hf.symm <| h _ _ hxy #align injective_of_lt_imp_ne injective_of_lt_imp_ne theorem injective_of_le_imp_le [PartialOrder α] [Preorder β] (f : α → β) (h : ∀ {x y}, f x ≤ f y → x ≤ y) : Injective f := fun _ _ hxy ↦ (h hxy.le).antisymm (h hxy.ge) #align injective_of_le_imp_le injective_of_le_imp_le section Preorder variable [Preorder α] [Preorder β] {f g : α → β} {a : α} theorem StrictMono.isMax_of_apply (hf : StrictMono f) (ha : IsMax (f a)) : IsMax a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMax_iff.1 h (hf hb).not_isMax ha #align strict_mono.is_max_of_apply StrictMono.isMax_of_apply theorem StrictMono.isMin_of_apply (hf : StrictMono f) (ha : IsMin (f a)) : IsMin a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMin_iff.1 h (hf hb).not_isMin ha #align strict_mono.is_min_of_apply StrictMono.isMin_of_apply theorem StrictAnti.isMax_of_apply (hf : StrictAnti f) (ha : IsMin (f a)) : IsMax a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMax_iff.1 h (hf hb).not_isMin ha #align strict_anti.is_max_of_apply StrictAnti.isMax_of_apply theorem StrictAnti.isMin_of_apply (hf : StrictAnti f) (ha : IsMax (f a)) : IsMin a := of_not_not fun h ↦ let ⟨_, hb⟩ := not_isMin_iff.1 h (hf hb).not_isMax ha #align strict_anti.is_min_of_apply StrictAnti.isMin_of_apply protected theorem StrictMono.ite' (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → f x < g y) : StrictMono fun x ↦ if p x then f x else g x := by intro x y h by_cases hy:p y · have hx : p x := hp h hy simpa [hx, hy] using hf h by_cases hx:p x · simpa [hx, hy] using hfg hx hy h · simpa [hx, hy] using hg h #align strict_mono.ite' StrictMono.ite' protected theorem StrictMono.ite (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, f x ≤ g x) : StrictMono fun x ↦ if p x then f x else g x := (hf.ite' hg hp) fun _ y _ _ h ↦ (hf h).trans_le (hfg y) #align strict_mono.ite StrictMono.ite -- Porting note: `Strict*.dual_right` dot notation is not working here for some reason protected theorem StrictAnti.ite' (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → g y < f x) : StrictAnti fun x ↦ if p x then f x else g x := StrictMono.ite' (StrictAnti.dual_right hf) (StrictAnti.dual_right hg) hp hfg #align strict_anti.ite' StrictAnti.ite' protected theorem StrictAnti.ite (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop} [DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, g x ≤ f x) : StrictAnti fun x ↦ if p x then f x else g x := (hf.ite' hg hp) fun _ y _ _ h ↦ (hfg y).trans_lt (hf h) #align strict_anti.ite StrictAnti.ite end Preorder /-! ### Monotonicity under composition -/ section Composition variable [Preorder α] [Preorder β] [Preorder γ] {g : β → γ} {f : α → β} {s : Set α} protected theorem Monotone.comp (hg : Monotone g) (hf : Monotone f) : Monotone (g ∘ f) := fun _ _ h ↦ hg (hf h) #align monotone.comp Monotone.comp theorem Monotone.comp_antitone (hg : Monotone g) (hf : Antitone f) : Antitone (g ∘ f) := fun _ _ h ↦ hg (hf h) #align monotone.comp_antitone Monotone.comp_antitone protected theorem Antitone.comp (hg : Antitone g) (hf : Antitone f) : Monotone (g ∘ f) := fun _ _ h ↦ hg (hf h) #align antitone.comp Antitone.comp theorem Antitone.comp_monotone (hg : Antitone g) (hf : Monotone f) : Antitone (g ∘ f) := fun _ _ h ↦ hg (hf h) #align antitone.comp_monotone Antitone.comp_monotone protected theorem Monotone.iterate {f : α → α} (hf : Monotone f) (n : ℕ) : Monotone f^[n] := Nat.recOn n monotone_id fun _ h ↦ h.comp hf #align monotone.iterate Monotone.iterate protected theorem Monotone.comp_monotoneOn (hg : Monotone g) (hf : MonotoneOn f s) : MonotoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align monotone.comp_monotone_on Monotone.comp_monotoneOn theorem Monotone.comp_antitoneOn (hg : Monotone g) (hf : AntitoneOn f s) : AntitoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align monotone.comp_antitone_on Monotone.comp_antitoneOn protected theorem Antitone.comp_antitoneOn (hg : Antitone g) (hf : AntitoneOn f s) : MonotoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align antitone.comp_antitone_on Antitone.comp_antitoneOn theorem Antitone.comp_monotoneOn (hg : Antitone g) (hf : MonotoneOn f s) : AntitoneOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align antitone.comp_monotone_on Antitone.comp_monotoneOn protected theorem StrictMono.comp (hg : StrictMono g) (hf : StrictMono f) : StrictMono (g ∘ f) := fun _ _ h ↦ hg (hf h) #align strict_mono.comp StrictMono.comp theorem StrictMono.comp_strictAnti (hg : StrictMono g) (hf : StrictAnti f) : StrictAnti (g ∘ f) := fun _ _ h ↦ hg (hf h) #align strict_mono.comp_strict_anti StrictMono.comp_strictAnti protected theorem StrictAnti.comp (hg : StrictAnti g) (hf : StrictAnti f) : StrictMono (g ∘ f) := fun _ _ h ↦ hg (hf h) #align strict_anti.comp StrictAnti.comp theorem StrictAnti.comp_strictMono (hg : StrictAnti g) (hf : StrictMono f) : StrictAnti (g ∘ f) := fun _ _ h ↦ hg (hf h) #align strict_anti.comp_strict_mono StrictAnti.comp_strictMono protected theorem StrictMono.iterate {f : α → α} (hf : StrictMono f) (n : ℕ) : StrictMono f^[n] := Nat.recOn n strictMono_id fun _ h ↦ h.comp hf #align strict_mono.iterate StrictMono.iterate protected theorem StrictMono.comp_strictMonoOn (hg : StrictMono g) (hf : StrictMonoOn f s) : StrictMonoOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align strict_mono.comp_strict_mono_on StrictMono.comp_strictMonoOn theorem StrictMono.comp_strictAntiOn (hg : StrictMono g) (hf : StrictAntiOn f s) : StrictAntiOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align strict_mono.comp_strict_anti_on StrictMono.comp_strictAntiOn protected theorem StrictAnti.comp_strictAntiOn (hg : StrictAnti g) (hf : StrictAntiOn f s) : StrictMonoOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align strict_anti.comp_strict_anti_on StrictAnti.comp_strictAntiOn theorem StrictAnti.comp_strictMonoOn (hg : StrictAnti g) (hf : StrictMonoOn f s) : StrictAntiOn (g ∘ f) s := fun _ ha _ hb h ↦ hg (hf ha hb h) #align strict_anti.comp_strict_mono_on StrictAnti.comp_strictMonoOn end Composition namespace List section Fold theorem foldl_monotone [Preorder α] {f : α → β → α} (H : ∀ b, Monotone fun a ↦ f a b) (l : List β) : Monotone fun a ↦ l.foldl f a := List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h) #align list.foldl_monotone List.foldl_monotone theorem foldr_monotone [Preorder β] {f : α → β → β} (H : ∀ a, Monotone (f a)) (l : List α) : Monotone fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl #align list.foldr_monotone List.foldr_monotone theorem foldl_strictMono [Preorder α] {f : α → β → α} (H : ∀ b, StrictMono fun a ↦ f a b) (l : List β) : StrictMono fun a ↦ l.foldl f a := List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h) #align list.foldl_strict_mono List.foldl_strictMono theorem foldr_strictMono [Preorder β] {f : α → β → β} (H : ∀ a, StrictMono (f a)) (l : List α) : StrictMono fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl #align list.foldr_strict_mono List.foldr_strictMono end Fold end List /-! ### Monotonicity in linear orders -/ section LinearOrder variable [LinearOrder α] section Preorder variable [Preorder β] {f : α → β} {s : Set α} open Ordering theorem Monotone.reflect_lt (hf : Monotone f) {a b : α} (h : f a < f b) : a < b := lt_of_not_ge fun h' ↦ h.not_le (hf h') #align monotone.reflect_lt Monotone.reflect_lt theorem Antitone.reflect_lt (hf : Antitone f) {a b : α} (h : f a < f b) : b < a := lt_of_not_ge fun h' ↦ h.not_le (hf h') #align antitone.reflect_lt Antitone.reflect_lt theorem MonotoneOn.reflect_lt (hf : MonotoneOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (h : f a < f b) : a < b := lt_of_not_ge fun h' ↦ h.not_le <| hf hb ha h' #align monotone_on.reflect_lt MonotoneOn.reflect_lt theorem AntitoneOn.reflect_lt (hf : AntitoneOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (h : f a < f b) : b < a := lt_of_not_ge fun h' ↦ h.not_le <| hf ha hb h' #align antitone_on.reflect_lt AntitoneOn.reflect_lt theorem StrictMonoOn.le_iff_le (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a ≤ f b ↔ a ≤ b := ⟨fun h ↦ le_of_not_gt fun h' ↦ (hf hb ha h').not_le h, fun h ↦ h.lt_or_eq_dec.elim (fun h' ↦ (hf ha hb h').le) fun h' ↦ h' ▸ le_rfl⟩ #align strict_mono_on.le_iff_le StrictMonoOn.le_iff_le theorem StrictAntiOn.le_iff_le (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a ≤ f b ↔ b ≤ a := hf.dual_right.le_iff_le hb ha #align strict_anti_on.le_iff_le StrictAntiOn.le_iff_le theorem StrictMonoOn.eq_iff_eq (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a = f b ↔ a = b := ⟨fun h ↦ le_antisymm ((hf.le_iff_le ha hb).mp h.le) ((hf.le_iff_le hb ha).mp h.ge), by rintro rfl rfl⟩ #align strict_mono_on.eq_iff_eq StrictMonoOn.eq_iff_eq theorem StrictAntiOn.eq_iff_eq (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a = f b ↔ b = a := (hf.dual_right.eq_iff_eq ha hb).trans eq_comm #align strict_anti_on.eq_iff_eq StrictAntiOn.eq_iff_eq theorem StrictMonoOn.lt_iff_lt (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a < f b ↔ a < b := by rw [lt_iff_le_not_le, lt_iff_le_not_le, hf.le_iff_le ha hb, hf.le_iff_le hb ha] #align strict_mono_on.lt_iff_lt StrictMonoOn.lt_iff_lt theorem StrictAntiOn.lt_iff_lt (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : f a < f b ↔ b < a := hf.dual_right.lt_iff_lt hb ha #align strict_anti_on.lt_iff_lt StrictAntiOn.lt_iff_lt theorem StrictMono.le_iff_le (hf : StrictMono f) {a b : α} : f a ≤ f b ↔ a ≤ b := (hf.strictMonoOn Set.univ).le_iff_le trivial trivial #align strict_mono.le_iff_le StrictMono.le_iff_le theorem StrictAnti.le_iff_le (hf : StrictAnti f) {a b : α} : f a ≤ f b ↔ b ≤ a := (hf.strictAntiOn Set.univ).le_iff_le trivial trivial #align strict_anti.le_iff_le StrictAnti.le_iff_le theorem StrictMono.lt_iff_lt (hf : StrictMono f) {a b : α} : f a < f b ↔ a < b := (hf.strictMonoOn Set.univ).lt_iff_lt trivial trivial #align strict_mono.lt_iff_lt StrictMono.lt_iff_lt theorem StrictAnti.lt_iff_lt (hf : StrictAnti f) {a b : α} : f a < f b ↔ b < a := (hf.strictAntiOn Set.univ).lt_iff_lt trivial trivial #align strict_anti.lt_iff_lt StrictAnti.lt_iff_lt protected theorem StrictMonoOn.compares (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : ∀ {o : Ordering}, o.Compares (f a) (f b) ↔ o.Compares a b | Ordering.lt => hf.lt_iff_lt ha hb | Ordering.eq => ⟨fun h ↦ ((hf.le_iff_le ha hb).1 h.le).antisymm ((hf.le_iff_le hb ha).1 h.symm.le), congr_arg _⟩ | Ordering.gt => hf.lt_iff_lt hb ha #align strict_mono_on.compares StrictMonoOn.compares protected theorem StrictAntiOn.compares (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares b a := toDual_compares_toDual.trans <| hf.dual_right.compares hb ha #align strict_anti_on.compares StrictAntiOn.compares protected theorem StrictMono.compares (hf : StrictMono f) {a b : α} {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares a b := (hf.strictMonoOn Set.univ).compares trivial trivial #align strict_mono.compares StrictMono.compares protected theorem StrictAnti.compares (hf : StrictAnti f) {a b : α} {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares b a := (hf.strictAntiOn Set.univ).compares trivial trivial #align strict_anti.compares StrictAnti.compares theorem StrictMono.injective (hf : StrictMono f) : Injective f := fun x y h ↦ show Compares eq x y from hf.compares.1 h #align strict_mono.injective StrictMono.injective theorem StrictAnti.injective (hf : StrictAnti f) : Injective f := fun x y h ↦ show Compares eq x y from hf.compares.1 h.symm #align strict_anti.injective StrictAnti.injective theorem StrictMono.maximal_of_maximal_image (hf : StrictMono f) {a} (hmax : ∀ p, p ≤ f a) (x : α) : x ≤ a := hf.le_iff_le.mp (hmax (f x)) #align strict_mono.maximal_of_maximal_image StrictMono.maximal_of_maximal_image theorem StrictMono.minimal_of_minimal_image (hf : StrictMono f) {a} (hmin : ∀ p, f a ≤ p) (x : α) : a ≤ x := hf.le_iff_le.mp (hmin (f x)) #align strict_mono.minimal_of_minimal_image StrictMono.minimal_of_minimal_image theorem StrictAnti.minimal_of_maximal_image (hf : StrictAnti f) {a} (hmax : ∀ p, p ≤ f a) (x : α) : a ≤ x := hf.le_iff_le.mp (hmax (f x)) #align strict_anti.minimal_of_maximal_image StrictAnti.minimal_of_maximal_image theorem StrictAnti.maximal_of_minimal_image (hf : StrictAnti f) {a} (hmin : ∀ p, f a ≤ p) (x : α) : x ≤ a := hf.le_iff_le.mp (hmin (f x)) #align strict_anti.maximal_of_minimal_image StrictAnti.maximal_of_minimal_image end Preorder section PartialOrder variable [PartialOrder β] {f : α → β} theorem Monotone.strictMono_iff_injective (hf : Monotone f) : StrictMono f ↔ Injective f := ⟨fun h ↦ h.injective, hf.strictMono_of_injective⟩ #align monotone.strict_mono_iff_injective Monotone.strictMono_iff_injective theorem Antitone.strictAnti_iff_injective (hf : Antitone f) : StrictAnti f ↔ Injective f := ⟨fun h ↦ h.injective, hf.strictAnti_of_injective⟩ #align antitone.strict_anti_iff_injective Antitone.strictAnti_iff_injective /-- If a monotone function is equal at two points, it is equal between all of them -/
Mathlib/Order/Monotone/Basic.lean
923
927
theorem Monotone.eq_of_le_of_le {a₁ a₂ : α} (h_mon : Monotone f) (h_fa : f a₁ = f a₂) {i : α} (h₁ : a₁ ≤ i) (h₂ : i ≤ a₂) : f i = f a₁ := by
apply le_antisymm · rw [h_fa]; exact h_mon h₂ · exact h_mon h₁
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Data.Set.Basic /-! # Subsingleton Defines the predicate `Subsingleton s : Prop`, saying that `s` has at most one element. Also defines `Nontrivial s : Prop` : the predicate saying that `s` has at least two distinct elements. -/ open Function universe u v namespace Set /-! ### Subsingleton -/ section Subsingleton variable {α : Type u} {a : α} {s t : Set α} /-- A set `s` is a `Subsingleton` if it has at most one element. -/ protected def Subsingleton (s : Set α) : Prop := ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), x = y #align set.subsingleton Set.Subsingleton theorem Subsingleton.anti (ht : t.Subsingleton) (hst : s ⊆ t) : s.Subsingleton := fun _ hx _ hy => ht (hst hx) (hst hy) #align set.subsingleton.anti Set.Subsingleton.anti theorem Subsingleton.eq_singleton_of_mem (hs : s.Subsingleton) {x : α} (hx : x ∈ s) : s = {x} := ext fun _ => ⟨fun hy => hs hx hy ▸ mem_singleton _, fun hy => (eq_of_mem_singleton hy).symm ▸ hx⟩ #align set.subsingleton.eq_singleton_of_mem Set.Subsingleton.eq_singleton_of_mem @[simp] theorem subsingleton_empty : (∅ : Set α).Subsingleton := fun _ => False.elim #align set.subsingleton_empty Set.subsingleton_empty @[simp] theorem subsingleton_singleton {a} : ({a} : Set α).Subsingleton := fun _ hx _ hy => (eq_of_mem_singleton hx).symm ▸ (eq_of_mem_singleton hy).symm ▸ rfl #align set.subsingleton_singleton Set.subsingleton_singleton theorem subsingleton_of_subset_singleton (h : s ⊆ {a}) : s.Subsingleton := subsingleton_singleton.anti h #align set.subsingleton_of_subset_singleton Set.subsingleton_of_subset_singleton theorem subsingleton_of_forall_eq (a : α) (h : ∀ b ∈ s, b = a) : s.Subsingleton := fun _ hb _ hc => (h _ hb).trans (h _ hc).symm #align set.subsingleton_of_forall_eq Set.subsingleton_of_forall_eq theorem subsingleton_iff_singleton {x} (hx : x ∈ s) : s.Subsingleton ↔ s = {x} := ⟨fun h => h.eq_singleton_of_mem hx, fun h => h.symm ▸ subsingleton_singleton⟩ #align set.subsingleton_iff_singleton Set.subsingleton_iff_singleton theorem Subsingleton.eq_empty_or_singleton (hs : s.Subsingleton) : s = ∅ ∨ ∃ x, s = {x} := s.eq_empty_or_nonempty.elim Or.inl fun ⟨x, hx⟩ => Or.inr ⟨x, hs.eq_singleton_of_mem hx⟩ #align set.subsingleton.eq_empty_or_singleton Set.Subsingleton.eq_empty_or_singleton theorem Subsingleton.induction_on {p : Set α → Prop} (hs : s.Subsingleton) (he : p ∅) (h₁ : ∀ x, p {x}) : p s := by rcases hs.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) exacts [he, h₁ _] #align set.subsingleton.induction_on Set.Subsingleton.induction_on theorem subsingleton_univ [Subsingleton α] : (univ : Set α).Subsingleton := fun x _ y _ => Subsingleton.elim x y #align set.subsingleton_univ Set.subsingleton_univ theorem subsingleton_of_univ_subsingleton (h : (univ : Set α).Subsingleton) : Subsingleton α := ⟨fun a b => h (mem_univ a) (mem_univ b)⟩ #align set.subsingleton_of_univ_subsingleton Set.subsingleton_of_univ_subsingleton @[simp] theorem subsingleton_univ_iff : (univ : Set α).Subsingleton ↔ Subsingleton α := ⟨subsingleton_of_univ_subsingleton, fun h => @subsingleton_univ _ h⟩ #align set.subsingleton_univ_iff Set.subsingleton_univ_iff theorem subsingleton_of_subsingleton [Subsingleton α] {s : Set α} : Set.Subsingleton s := subsingleton_univ.anti (subset_univ s) #align set.subsingleton_of_subsingleton Set.subsingleton_of_subsingleton theorem subsingleton_isTop (α : Type*) [PartialOrder α] : Set.Subsingleton { x : α | IsTop x } := fun x hx _ hy => hx.isMax.eq_of_le (hy x) #align set.subsingleton_is_top Set.subsingleton_isTop theorem subsingleton_isBot (α : Type*) [PartialOrder α] : Set.Subsingleton { x : α | IsBot x } := fun x hx _ hy => hx.isMin.eq_of_ge (hy x) #align set.subsingleton_is_bot Set.subsingleton_isBot theorem exists_eq_singleton_iff_nonempty_subsingleton : (∃ a : α, s = {a}) ↔ s.Nonempty ∧ s.Subsingleton := by refine ⟨?_, fun h => ?_⟩ · rintro ⟨a, rfl⟩ exact ⟨singleton_nonempty a, subsingleton_singleton⟩ · exact h.2.eq_empty_or_singleton.resolve_left h.1.ne_empty #align set.exists_eq_singleton_iff_nonempty_subsingleton Set.exists_eq_singleton_iff_nonempty_subsingleton /-- `s`, coerced to a type, is a subsingleton type if and only if `s` is a subsingleton set. -/ @[simp, norm_cast] theorem subsingleton_coe (s : Set α) : Subsingleton s ↔ s.Subsingleton := by constructor · refine fun h => fun a ha b hb => ?_ exact SetCoe.ext_iff.2 (@Subsingleton.elim s h ⟨a, ha⟩ ⟨b, hb⟩) · exact fun h => Subsingleton.intro fun a b => SetCoe.ext (h a.property b.property) #align set.subsingleton_coe Set.subsingleton_coe theorem Subsingleton.coe_sort {s : Set α} : s.Subsingleton → Subsingleton s := s.subsingleton_coe.2 #align set.subsingleton.coe_sort Set.Subsingleton.coe_sort /-- The `coe_sort` of a set `s` in a subsingleton type is a subsingleton. For the corresponding result for `Subtype`, see `subtype.subsingleton`. -/ instance subsingleton_coe_of_subsingleton [Subsingleton α] {s : Set α} : Subsingleton s := by rw [s.subsingleton_coe] exact subsingleton_of_subsingleton #align set.subsingleton_coe_of_subsingleton Set.subsingleton_coe_of_subsingleton end Subsingleton /-! ### Nontrivial -/ section Nontrivial variable {α : Type u} {a : α} {s t : Set α} /-- A set `s` is `Set.Nontrivial` if it has at least two distinct elements. -/ protected def Nontrivial (s : Set α) : Prop := ∃ x ∈ s, ∃ y ∈ s, x ≠ y #align set.nontrivial Set.Nontrivial theorem nontrivial_of_mem_mem_ne {x y} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) : s.Nontrivial := ⟨x, hx, y, hy, hxy⟩ #align set.nontrivial_of_mem_mem_ne Set.nontrivial_of_mem_mem_ne -- Porting note: following the pattern for `Exists`, we have renamed `some` to `choose`. /-- Extract witnesses from s.nontrivial. This function might be used instead of case analysis on the argument. Note that it makes a proof depend on the classical.choice axiom. -/ protected noncomputable def Nontrivial.choose (hs : s.Nontrivial) : α × α := (Exists.choose hs, hs.choose_spec.right.choose) #align set.nontrivial.some Set.Nontrivial.choose protected theorem Nontrivial.choose_fst_mem (hs : s.Nontrivial) : hs.choose.fst ∈ s := hs.choose_spec.left #align set.nontrivial.some_fst_mem Set.Nontrivial.choose_fst_mem protected theorem Nontrivial.choose_snd_mem (hs : s.Nontrivial) : hs.choose.snd ∈ s := hs.choose_spec.right.choose_spec.left #align set.nontrivial.some_snd_mem Set.Nontrivial.choose_snd_mem protected theorem Nontrivial.choose_fst_ne_choose_snd (hs : s.Nontrivial) : hs.choose.fst ≠ hs.choose.snd := hs.choose_spec.right.choose_spec.right #align set.nontrivial.some_fst_ne_some_snd Set.Nontrivial.choose_fst_ne_choose_snd theorem Nontrivial.mono (hs : s.Nontrivial) (hst : s ⊆ t) : t.Nontrivial := let ⟨x, hx, y, hy, hxy⟩ := hs ⟨x, hst hx, y, hst hy, hxy⟩ #align set.nontrivial.mono Set.Nontrivial.mono theorem nontrivial_pair {x y} (hxy : x ≠ y) : ({x, y} : Set α).Nontrivial := ⟨x, mem_insert _ _, y, mem_insert_of_mem _ (mem_singleton _), hxy⟩ #align set.nontrivial_pair Set.nontrivial_pair theorem nontrivial_of_pair_subset {x y} (hxy : x ≠ y) (h : {x, y} ⊆ s) : s.Nontrivial := (nontrivial_pair hxy).mono h #align set.nontrivial_of_pair_subset Set.nontrivial_of_pair_subset theorem Nontrivial.pair_subset (hs : s.Nontrivial) : ∃ x y, x ≠ y ∧ {x, y} ⊆ s := let ⟨x, hx, y, hy, hxy⟩ := hs ⟨x, y, hxy, insert_subset hx <| singleton_subset_iff.2 hy⟩ #align set.nontrivial.pair_subset Set.Nontrivial.pair_subset theorem nontrivial_iff_pair_subset : s.Nontrivial ↔ ∃ x y, x ≠ y ∧ {x, y} ⊆ s := ⟨Nontrivial.pair_subset, fun H => let ⟨_, _, hxy, h⟩ := H nontrivial_of_pair_subset hxy h⟩ #align set.nontrivial_iff_pair_subset Set.nontrivial_iff_pair_subset theorem nontrivial_of_exists_ne {x} (hx : x ∈ s) (h : ∃ y ∈ s, y ≠ x) : s.Nontrivial := let ⟨y, hy, hyx⟩ := h ⟨y, hy, x, hx, hyx⟩ #align set.nontrivial_of_exists_ne Set.nontrivial_of_exists_ne theorem Nontrivial.exists_ne (hs : s.Nontrivial) (z) : ∃ x ∈ s, x ≠ z := by by_contra! H rcases hs with ⟨x, hx, y, hy, hxy⟩ rw [H x hx, H y hy] at hxy exact hxy rfl #align set.nontrivial.exists_ne Set.Nontrivial.exists_ne theorem nontrivial_iff_exists_ne {x} (hx : x ∈ s) : s.Nontrivial ↔ ∃ y ∈ s, y ≠ x := ⟨fun H => H.exists_ne _, nontrivial_of_exists_ne hx⟩ #align set.nontrivial_iff_exists_ne Set.nontrivial_iff_exists_ne theorem nontrivial_of_lt [Preorder α] {x y} (hx : x ∈ s) (hy : y ∈ s) (hxy : x < y) : s.Nontrivial := ⟨x, hx, y, hy, ne_of_lt hxy⟩ #align set.nontrivial_of_lt Set.nontrivial_of_lt theorem nontrivial_of_exists_lt [Preorder α] (H : ∃ᵉ (x ∈ s) (y ∈ s), x < y) : s.Nontrivial := let ⟨_, hx, _, hy, hxy⟩ := H nontrivial_of_lt hx hy hxy #align set.nontrivial_of_exists_lt Set.nontrivial_of_exists_lt theorem Nontrivial.exists_lt [LinearOrder α] (hs : s.Nontrivial) : ∃ᵉ (x ∈ s) (y ∈ s), x < y := let ⟨x, hx, y, hy, hxy⟩ := hs Or.elim (lt_or_gt_of_ne hxy) (fun H => ⟨x, hx, y, hy, H⟩) fun H => ⟨y, hy, x, hx, H⟩ #align set.nontrivial.exists_lt Set.Nontrivial.exists_lt theorem nontrivial_iff_exists_lt [LinearOrder α] : s.Nontrivial ↔ ∃ᵉ (x ∈ s) (y ∈ s), x < y := ⟨Nontrivial.exists_lt, nontrivial_of_exists_lt⟩ #align set.nontrivial_iff_exists_lt Set.nontrivial_iff_exists_lt protected theorem Nontrivial.nonempty (hs : s.Nontrivial) : s.Nonempty := let ⟨x, hx, _⟩ := hs ⟨x, hx⟩ #align set.nontrivial.nonempty Set.Nontrivial.nonempty protected theorem Nontrivial.ne_empty (hs : s.Nontrivial) : s ≠ ∅ := hs.nonempty.ne_empty #align set.nontrivial.ne_empty Set.Nontrivial.ne_empty theorem Nontrivial.not_subset_empty (hs : s.Nontrivial) : ¬s ⊆ ∅ := hs.nonempty.not_subset_empty #align set.nontrivial.not_subset_empty Set.Nontrivial.not_subset_empty @[simp] theorem not_nontrivial_empty : ¬(∅ : Set α).Nontrivial := fun h => h.ne_empty rfl #align set.not_nontrivial_empty Set.not_nontrivial_empty @[simp] theorem not_nontrivial_singleton {x} : ¬({x} : Set α).Nontrivial := fun H => by rw [nontrivial_iff_exists_ne (mem_singleton x)] at H let ⟨y, hy, hya⟩ := H exact hya (mem_singleton_iff.1 hy) #align set.not_nontrivial_singleton Set.not_nontrivial_singleton theorem Nontrivial.ne_singleton {x} (hs : s.Nontrivial) : s ≠ {x} := fun H => by rw [H] at hs exact not_nontrivial_singleton hs #align set.nontrivial.ne_singleton Set.Nontrivial.ne_singleton theorem Nontrivial.not_subset_singleton {x} (hs : s.Nontrivial) : ¬s ⊆ {x} := (not_congr subset_singleton_iff_eq).2 (not_or_of_not hs.ne_empty hs.ne_singleton) #align set.nontrivial.not_subset_singleton Set.Nontrivial.not_subset_singleton theorem nontrivial_univ [Nontrivial α] : (univ : Set α).Nontrivial := let ⟨x, y, hxy⟩ := exists_pair_ne α ⟨x, mem_univ _, y, mem_univ _, hxy⟩ #align set.nontrivial_univ Set.nontrivial_univ theorem nontrivial_of_univ_nontrivial (h : (univ : Set α).Nontrivial) : Nontrivial α := let ⟨x, _, y, _, hxy⟩ := h ⟨⟨x, y, hxy⟩⟩ #align set.nontrivial_of_univ_nontrivial Set.nontrivial_of_univ_nontrivial @[simp] theorem nontrivial_univ_iff : (univ : Set α).Nontrivial ↔ Nontrivial α := ⟨nontrivial_of_univ_nontrivial, fun h => @nontrivial_univ _ h⟩ #align set.nontrivial_univ_iff Set.nontrivial_univ_iff theorem nontrivial_of_nontrivial (hs : s.Nontrivial) : Nontrivial α := let ⟨x, _, y, _, hxy⟩ := hs ⟨⟨x, y, hxy⟩⟩ #align set.nontrivial_of_nontrivial Set.nontrivial_of_nontrivial -- Porting note: simp_rw broken here -- Perhaps review after https://github.com/leanprover/lean4/issues/1937? /-- `s`, coerced to a type, is a nontrivial type if and only if `s` is a nontrivial set. -/ @[simp, norm_cast]
Mathlib/Data/Set/Subsingleton.lean
283
291
theorem nontrivial_coe_sort {s : Set α} : Nontrivial s ↔ s.Nontrivial := by
-- simp_rw [← nontrivial_univ_iff, Set.Nontrivial, mem_univ, exists_true_left, SetCoe.exists, -- Subtype.mk_eq_mk] rw [← nontrivial_univ_iff, Set.Nontrivial, Set.Nontrivial] apply Iff.intro · rintro ⟨x, _, y, _, hxy⟩ exact ⟨x, Subtype.prop x, y, Subtype.prop y, fun h => hxy (Subtype.coe_injective h)⟩ · rintro ⟨x, hx, y, hy, hxy⟩ exact ⟨⟨x, hx⟩, mem_univ _, ⟨y, hy⟩, mem_univ _, Subtype.mk_eq_mk.not.mpr hxy⟩
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.AlgebraicTopology.SplitSimplicialObject import Mathlib.AlgebraicTopology.DoldKan.PInfty #align_import algebraic_topology.dold_kan.functor_gamma from "leanprover-community/mathlib"@"32a7e535287f9c73f2e4d2aef306a39190f0b504" /-! # Construction of the inverse functor of the Dold-Kan equivalence In this file, we construct the functor `Γ₀ : ChainComplex C ℕ ⥤ SimplicialObject C` which shall be the inverse functor of the Dold-Kan equivalence in the case of abelian categories, and more generally pseudoabelian categories. By definition, when `K` is a chain_complex, `Γ₀.obj K` is a simplicial object which sends `Δ : SimplexCategoryᵒᵖ` to a certain coproduct indexed by the set `Splitting.IndexSet Δ` whose elements consists of epimorphisms `e : Δ.unop ⟶ Δ'.unop` (with `Δ' : SimplexCategoryᵒᵖ`); the summand attached to such an `e` is `K.X Δ'.unop.len`. By construction, `Γ₀.obj K` is a split simplicial object whose splitting is `Γ₀.splitting K`. We also construct `Γ₂ : Karoubi (ChainComplex C ℕ) ⥤ Karoubi (SimplicialObject C)` which shall be an equivalence for any additive category `C`. (See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Limits SimplexCategory SimplicialObject Opposite CategoryTheory.Idempotents Simplicial DoldKan namespace AlgebraicTopology namespace DoldKan variable {C : Type*} [Category C] [Preadditive C] (K K' : ChainComplex C ℕ) (f : K ⟶ K') {Δ Δ' Δ'' : SimplexCategory} /-- `Isδ₀ i` is a simple condition used to check whether a monomorphism `i` in `SimplexCategory` identifies to the coface map `δ 0`. -/ @[nolint unusedArguments] def Isδ₀ {Δ Δ' : SimplexCategory} (i : Δ' ⟶ Δ) [Mono i] : Prop := Δ.len = Δ'.len + 1 ∧ i.toOrderHom 0 ≠ 0 #align algebraic_topology.dold_kan.is_δ₀ AlgebraicTopology.DoldKan.Isδ₀ namespace Isδ₀ theorem iff {j : ℕ} {i : Fin (j + 2)} : Isδ₀ (SimplexCategory.δ i) ↔ i = 0 := by constructor · rintro ⟨_, h₂⟩ by_contra h exact h₂ (Fin.succAbove_ne_zero_zero h) · rintro rfl exact ⟨rfl, by dsimp; exact Fin.succ_ne_zero (0 : Fin (j + 1))⟩ #align algebraic_topology.dold_kan.is_δ₀.iff AlgebraicTopology.DoldKan.Isδ₀.iff theorem eq_δ₀ {n : ℕ} {i : ([n] : SimplexCategory) ⟶ [n + 1]} [Mono i] (hi : Isδ₀ i) : i = SimplexCategory.δ 0 := by obtain ⟨j, rfl⟩ := SimplexCategory.eq_δ_of_mono i rw [iff] at hi rw [hi] #align algebraic_topology.dold_kan.is_δ₀.eq_δ₀ AlgebraicTopology.DoldKan.Isδ₀.eq_δ₀ end Isδ₀ namespace Γ₀ namespace Obj /-- In the definition of `(Γ₀.obj K).obj Δ` as a direct sum indexed by `A : Splitting.IndexSet Δ`, the summand `summand K Δ A` is `K.X A.1.len`. -/ def summand (Δ : SimplexCategoryᵒᵖ) (A : Splitting.IndexSet Δ) : C := K.X A.1.unop.len #align algebraic_topology.dold_kan.Γ₀.obj.summand AlgebraicTopology.DoldKan.Γ₀.Obj.summand /-- The functor `Γ₀` sends a chain complex `K` to the simplicial object which sends `Δ` to the direct sum of the objects `summand K Δ A` for all `A : Splitting.IndexSet Δ` -/ def obj₂ (K : ChainComplex C ℕ) (Δ : SimplexCategoryᵒᵖ) [HasFiniteCoproducts C] : C := ∐ fun A : Splitting.IndexSet Δ => summand K Δ A #align algebraic_topology.dold_kan.Γ₀.obj.obj₂ AlgebraicTopology.DoldKan.Γ₀.Obj.obj₂ namespace Termwise /-- A monomorphism `i : Δ' ⟶ Δ` induces a morphism `K.X Δ.len ⟶ K.X Δ'.len` which is the identity if `Δ = Δ'`, the differential on the complex `K` if `i = δ 0`, and zero otherwise. -/ def mapMono (K : ChainComplex C ℕ) {Δ' Δ : SimplexCategory} (i : Δ' ⟶ Δ) [Mono i] : K.X Δ.len ⟶ K.X Δ'.len := by by_cases Δ = Δ' · exact eqToHom (by congr) · by_cases Isδ₀ i · exact K.d Δ.len Δ'.len · exact 0 #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono variable (Δ) theorem mapMono_id : mapMono K (𝟙 Δ) = 𝟙 _ := by unfold mapMono simp only [eq_self_iff_true, eqToHom_refl, dite_eq_ite, if_true] #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono_id AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono_id variable {Δ} theorem mapMono_δ₀' (i : Δ' ⟶ Δ) [Mono i] (hi : Isδ₀ i) : mapMono K i = K.d Δ.len Δ'.len := by unfold mapMono suffices Δ ≠ Δ' by simp only [dif_neg this, dif_pos hi] rintro rfl simpa only [self_eq_add_right, Nat.one_ne_zero] using hi.1 #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono_δ₀' AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono_δ₀' @[simp] theorem mapMono_δ₀ {n : ℕ} : mapMono K (δ (0 : Fin (n + 2))) = K.d (n + 1) n := mapMono_δ₀' K _ (by rw [Isδ₀.iff]) #align algebraic_topology.dold_kan.Γ₀.obj.termwise.map_mono_δ₀ AlgebraicTopology.DoldKan.Γ₀.Obj.Termwise.mapMono_δ₀
Mathlib/AlgebraicTopology/DoldKan/FunctorGamma.lean
125
129
theorem mapMono_eq_zero (i : Δ' ⟶ Δ) [Mono i] (h₁ : Δ ≠ Δ') (h₂ : ¬Isδ₀ i) : mapMono K i = 0 := by
unfold mapMono rw [Ne] at h₁ split_ifs rfl
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Kernel.MeasurableIntegral #align_import probability.kernel.composition from "leanprover-community/mathlib"@"3b92d54a05ee592aa2c6181a4e76b1bb7cc45d0b" /-! # Product and composition of kernels We define * the composition-product `κ ⊗ₖ η` of two s-finite kernels `κ : kernel α β` and `η : kernel (α × β) γ`, a kernel from `α` to `β × γ`. * the map and comap of a kernel along a measurable function. * the composition `η ∘ₖ κ` of kernels `κ : kernel α β` and `η : kernel β γ`, kernel from `α` to `γ`. * the product `κ ×ₖ η` of s-finite kernels `κ : kernel α β` and `η : kernel α γ`, a kernel from `α` to `β × γ`. A note on names: The composition-product `kernel α β → kernel (α × β) γ → kernel α (β × γ)` is named composition in [kallenberg2021] and product on the wikipedia article on transition kernels. Most papers studying categories of kernels call composition the map we call composition. We adopt that convention because it fits better with the use of the name `comp` elsewhere in mathlib. ## Main definitions Kernels built from other kernels: * `compProd (κ : kernel α β) (η : kernel (α × β) γ) : kernel α (β × γ)`: composition-product of 2 s-finite kernels. We define a notation `κ ⊗ₖ η = compProd κ η`. `∫⁻ bc, f bc ∂((κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)` * `map (κ : kernel α β) (f : β → γ) (hf : Measurable f) : kernel α γ` `∫⁻ c, g c ∂(map κ f hf a) = ∫⁻ b, g (f b) ∂(κ a)` * `comap (κ : kernel α β) (f : γ → α) (hf : Measurable f) : kernel γ β` `∫⁻ b, g b ∂(comap κ f hf c) = ∫⁻ b, g b ∂(κ (f c))` * `comp (η : kernel β γ) (κ : kernel α β) : kernel α γ`: composition of 2 kernels. We define a notation `η ∘ₖ κ = comp η κ`. `∫⁻ c, g c ∂((η ∘ₖ κ) a) = ∫⁻ b, ∫⁻ c, g c ∂(η b) ∂(κ a)` * `prod (κ : kernel α β) (η : kernel α γ) : kernel α (β × γ)`: product of 2 s-finite kernels. `∫⁻ bc, f bc ∂((κ ×ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η a) ∂(κ a)` ## Main statements * `lintegral_compProd`, `lintegral_map`, `lintegral_comap`, `lintegral_comp`, `lintegral_prod`: Lebesgue integral of a function against a composition-product/map/comap/composition/product of kernels. * Instances of the form `<class>.<operation>` where class is one of `IsMarkovKernel`, `IsFiniteKernel`, `IsSFiniteKernel` and operation is one of `compProd`, `map`, `comap`, `comp`, `prod`. These instances state that the three classes are stable by the various operations. ## Notations * `κ ⊗ₖ η = ProbabilityTheory.kernel.compProd κ η` * `η ∘ₖ κ = ProbabilityTheory.kernel.comp η κ` * `κ ×ₖ η = ProbabilityTheory.kernel.prod κ η` -/ open MeasureTheory open scoped ENNReal namespace ProbabilityTheory namespace kernel variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} section CompositionProduct /-! ### Composition-Product of kernels We define a kernel composition-product `compProd : kernel α β → kernel (α × β) γ → kernel α (β × γ)`. -/ variable {γ : Type*} {mγ : MeasurableSpace γ} {s : Set (β × γ)} /-- Auxiliary function for the definition of the composition-product of two kernels. For all `a : α`, `compProdFun κ η a` is a countably additive function with value zero on the empty set, and the composition-product of kernels is defined in `kernel.compProd` through `Measure.ofMeasurable`. -/ noncomputable def compProdFun (κ : kernel α β) (η : kernel (α × β) γ) (a : α) (s : Set (β × γ)) : ℝ≥0∞ := ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a #align probability_theory.kernel.comp_prod_fun ProbabilityTheory.kernel.compProdFun theorem compProdFun_empty (κ : kernel α β) (η : kernel (α × β) γ) (a : α) : compProdFun κ η a ∅ = 0 := by simp only [compProdFun, Set.mem_empty_iff_false, Set.setOf_false, measure_empty, MeasureTheory.lintegral_const, zero_mul] #align probability_theory.kernel.comp_prod_fun_empty ProbabilityTheory.kernel.compProdFun_empty theorem compProdFun_iUnion (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (f : ℕ → Set (β × γ)) (hf_meas : ∀ i, MeasurableSet (f i)) (hf_disj : Pairwise (Disjoint on f)) : compProdFun κ η a (⋃ i, f i) = ∑' i, compProdFun κ η a (f i) := by have h_Union : (fun b => η (a, b) {c : γ | (b, c) ∈ ⋃ i, f i}) = fun b => η (a, b) (⋃ i, {c : γ | (b, c) ∈ f i}) := by ext1 b congr with c simp only [Set.mem_iUnion, Set.iSup_eq_iUnion, Set.mem_setOf_eq] rw [compProdFun, h_Union] have h_tsum : (fun b => η (a, b) (⋃ i, {c : γ | (b, c) ∈ f i})) = fun b => ∑' i, η (a, b) {c : γ | (b, c) ∈ f i} := by ext1 b rw [measure_iUnion] · intro i j hij s hsi hsj c hcs have hbci : {(b, c)} ⊆ f i := by rw [Set.singleton_subset_iff]; exact hsi hcs have hbcj : {(b, c)} ⊆ f j := by rw [Set.singleton_subset_iff]; exact hsj hcs simpa only [Set.bot_eq_empty, Set.le_eq_subset, Set.singleton_subset_iff, Set.mem_empty_iff_false] using hf_disj hij hbci hbcj · -- Porting note: behavior of `@` changed relative to lean 3, was -- exact fun i => (@measurable_prod_mk_left β γ _ _ b) _ (hf_meas i) exact fun i => (@measurable_prod_mk_left β γ _ _ b) (hf_meas i) rw [h_tsum, lintegral_tsum] · rfl · intro i have hm : MeasurableSet {p : (α × β) × γ | (p.1.2, p.2) ∈ f i} := measurable_fst.snd.prod_mk measurable_snd (hf_meas i) exact ((measurable_kernel_prod_mk_left hm).comp measurable_prod_mk_left).aemeasurable #align probability_theory.kernel.comp_prod_fun_Union ProbabilityTheory.kernel.compProdFun_iUnion theorem compProdFun_tsum_right (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : compProdFun κ η a s = ∑' n, compProdFun κ (seq η n) a s := by simp_rw [compProdFun, (measure_sum_seq η _).symm] have : ∫⁻ b, Measure.sum (fun n => seq η n (a, b)) {c : γ | (b, c) ∈ s} ∂κ a = ∫⁻ b, ∑' n, seq η n (a, b) {c : γ | (b, c) ∈ s} ∂κ a := by congr ext1 b rw [Measure.sum_apply] exact measurable_prod_mk_left hs rw [this, lintegral_tsum] exact fun n => ((measurable_kernel_prod_mk_left (κ := (seq η n)) ((measurable_fst.snd.prod_mk measurable_snd) hs)).comp measurable_prod_mk_left).aemeasurable #align probability_theory.kernel.comp_prod_fun_tsum_right ProbabilityTheory.kernel.compProdFun_tsum_right theorem compProdFun_tsum_left (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel κ] (a : α) (s : Set (β × γ)) : compProdFun κ η a s = ∑' n, compProdFun (seq κ n) η a s := by simp_rw [compProdFun, (measure_sum_seq κ _).symm, lintegral_sum_measure] #align probability_theory.kernel.comp_prod_fun_tsum_left ProbabilityTheory.kernel.compProdFun_tsum_left theorem compProdFun_eq_tsum (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : compProdFun κ η a s = ∑' (n) (m), compProdFun (seq κ n) (seq η m) a s := by simp_rw [compProdFun_tsum_left κ η a s, compProdFun_tsum_right _ η a hs] #align probability_theory.kernel.comp_prod_fun_eq_tsum ProbabilityTheory.kernel.compProdFun_eq_tsum /-- Auxiliary lemma for `measurable_compProdFun`. -/ theorem measurable_compProdFun_of_finite (κ : kernel α β) [IsFiniteKernel κ] (η : kernel (α × β) γ) [IsFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s := by simp only [compProdFun] have h_meas : Measurable (Function.uncurry fun a b => η (a, b) {c : γ | (b, c) ∈ s}) := by have : (Function.uncurry fun a b => η (a, b) {c : γ | (b, c) ∈ s}) = fun p => η p {c : γ | (p.2, c) ∈ s} := by ext1 p rw [Function.uncurry_apply_pair] rw [this] exact measurable_kernel_prod_mk_left (measurable_fst.snd.prod_mk measurable_snd hs) exact h_meas.lintegral_kernel_prod_right #align probability_theory.kernel.measurable_comp_prod_fun_of_finite ProbabilityTheory.kernel.measurable_compProdFun_of_finite theorem measurable_compProdFun (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s := by simp_rw [compProdFun_tsum_right κ η _ hs] refine Measurable.ennreal_tsum fun n => ?_ simp only [compProdFun] have h_meas : Measurable (Function.uncurry fun a b => seq η n (a, b) {c : γ | (b, c) ∈ s}) := by have : (Function.uncurry fun a b => seq η n (a, b) {c : γ | (b, c) ∈ s}) = fun p => seq η n p {c : γ | (p.2, c) ∈ s} := by ext1 p rw [Function.uncurry_apply_pair] rw [this] exact measurable_kernel_prod_mk_left (measurable_fst.snd.prod_mk measurable_snd hs) exact h_meas.lintegral_kernel_prod_right #align probability_theory.kernel.measurable_comp_prod_fun ProbabilityTheory.kernel.measurable_compProdFun open scoped Classical /-- Composition-Product of kernels. For s-finite kernels, it satisfies `∫⁻ bc, f bc ∂(compProd κ η a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)` (see `ProbabilityTheory.kernel.lintegral_compProd`). If either of the kernels is not s-finite, `compProd` is given the junk value 0. -/ noncomputable def compProd (κ : kernel α β) (η : kernel (α × β) γ) : kernel α (β × γ) := if h : IsSFiniteKernel κ ∧ IsSFiniteKernel η then { val := fun a ↦ Measure.ofMeasurable (fun s _ => compProdFun κ η a s) (compProdFun_empty κ η a) (@compProdFun_iUnion _ _ _ _ _ _ κ η h.2 a) property := by have : IsSFiniteKernel κ := h.1 have : IsSFiniteKernel η := h.2 refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ have : (fun a => Measure.ofMeasurable (fun s _ => compProdFun κ η a s) (compProdFun_empty κ η a) (compProdFun_iUnion κ η a) s) = fun a => compProdFun κ η a s := by ext1 a; rwa [Measure.ofMeasurable_apply] rw [this] exact measurable_compProdFun κ η hs } else 0 #align probability_theory.kernel.comp_prod ProbabilityTheory.kernel.compProd scoped[ProbabilityTheory] infixl:100 " ⊗ₖ " => ProbabilityTheory.kernel.compProd theorem compProd_apply_eq_compProdFun (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = compProdFun κ η a s := by rw [compProd, dif_pos] swap · constructor <;> infer_instance change Measure.ofMeasurable (fun s _ => compProdFun κ η a s) (compProdFun_empty κ η a) (compProdFun_iUnion κ η a) s = ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a rw [Measure.ofMeasurable_apply _ hs] rfl #align probability_theory.kernel.comp_prod_apply_eq_comp_prod_fun ProbabilityTheory.kernel.compProd_apply_eq_compProdFun theorem compProd_of_not_isSFiniteKernel_left (κ : kernel α β) (η : kernel (α × β) γ) (h : ¬ IsSFiniteKernel κ) : κ ⊗ₖ η = 0 := by rw [compProd, dif_neg] simp [h] theorem compProd_of_not_isSFiniteKernel_right (κ : kernel α β) (η : kernel (α × β) γ) (h : ¬ IsSFiniteKernel η) : κ ⊗ₖ η = 0 := by rw [compProd, dif_neg] simp [h] theorem compProd_apply (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a := compProd_apply_eq_compProdFun κ η a hs #align probability_theory.kernel.comp_prod_apply ProbabilityTheory.kernel.compProd_apply theorem le_compProd_apply (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (s : Set (β × γ)) : ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a ≤ (κ ⊗ₖ η) a s := calc ∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a ≤ ∫⁻ b, η (a, b) {c | (b, c) ∈ toMeasurable ((κ ⊗ₖ η) a) s} ∂κ a := lintegral_mono fun _ => measure_mono fun _ h_mem => subset_toMeasurable _ _ h_mem _ = (κ ⊗ₖ η) a (toMeasurable ((κ ⊗ₖ η) a) s) := (kernel.compProd_apply_eq_compProdFun κ η a (measurableSet_toMeasurable _ _)).symm _ = (κ ⊗ₖ η) a s := measure_toMeasurable s #align probability_theory.kernel.le_comp_prod_apply ProbabilityTheory.kernel.le_compProd_apply @[simp] lemma compProd_zero_left (κ : kernel (α × β) γ) : (0 : kernel α β) ⊗ₖ κ = 0 := by by_cases h : IsSFiniteKernel κ · ext a s hs rw [kernel.compProd_apply _ _ _ hs] simp · rw [kernel.compProd_of_not_isSFiniteKernel_right _ _ h] @[simp] lemma compProd_zero_right (κ : kernel α β) (γ : Type*) [MeasurableSpace γ] : κ ⊗ₖ (0 : kernel (α × β) γ) = 0 := by by_cases h : IsSFiniteKernel κ · ext a s hs rw [kernel.compProd_apply _ _ _ hs] simp · rw [kernel.compProd_of_not_isSFiniteKernel_left _ _ h] section Ae /-! ### `ae` filter of the composition-product -/ variable {κ : kernel α β} [IsSFiniteKernel κ] {η : kernel (α × β) γ} [IsSFiniteKernel η] {a : α} theorem ae_kernel_lt_top (a : α) (h2s : (κ ⊗ₖ η) a s ≠ ∞) : ∀ᵐ b ∂κ a, η (a, b) (Prod.mk b ⁻¹' s) < ∞ := by let t := toMeasurable ((κ ⊗ₖ η) a) s have : ∀ b : β, η (a, b) (Prod.mk b ⁻¹' s) ≤ η (a, b) (Prod.mk b ⁻¹' t) := fun b => measure_mono (Set.preimage_mono (subset_toMeasurable _ _)) have ht : MeasurableSet t := measurableSet_toMeasurable _ _ have h2t : (κ ⊗ₖ η) a t ≠ ∞ := by rwa [measure_toMeasurable] have ht_lt_top : ∀ᵐ b ∂κ a, η (a, b) (Prod.mk b ⁻¹' t) < ∞ := by rw [kernel.compProd_apply _ _ _ ht] at h2t exact ae_lt_top (kernel.measurable_kernel_prod_mk_left' ht a) h2t filter_upwards [ht_lt_top] with b hb exact (this b).trans_lt hb #align probability_theory.kernel.ae_kernel_lt_top ProbabilityTheory.kernel.ae_kernel_lt_top theorem compProd_null (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = 0 ↔ (fun b => η (a, b) (Prod.mk b ⁻¹' s)) =ᵐ[κ a] 0 := by rw [kernel.compProd_apply _ _ _ hs, lintegral_eq_zero_iff] · rfl · exact kernel.measurable_kernel_prod_mk_left' hs a #align probability_theory.kernel.comp_prod_null ProbabilityTheory.kernel.compProd_null theorem ae_null_of_compProd_null (h : (κ ⊗ₖ η) a s = 0) : (fun b => η (a, b) (Prod.mk b ⁻¹' s)) =ᵐ[κ a] 0 := by obtain ⟨t, hst, mt, ht⟩ := exists_measurable_superset_of_null h simp_rw [compProd_null a mt] at ht rw [Filter.eventuallyLE_antisymm_iff] exact ⟨Filter.EventuallyLE.trans_eq (Filter.eventually_of_forall fun x => (measure_mono (Set.preimage_mono hst) : _)) ht, Filter.eventually_of_forall fun x => zero_le _⟩ #align probability_theory.kernel.ae_null_of_comp_prod_null ProbabilityTheory.kernel.ae_null_of_compProd_null theorem ae_ae_of_ae_compProd {p : β × γ → Prop} (h : ∀ᵐ bc ∂(κ ⊗ₖ η) a, p bc) : ∀ᵐ b ∂κ a, ∀ᵐ c ∂η (a, b), p (b, c) := ae_null_of_compProd_null h #align probability_theory.kernel.ae_ae_of_ae_comp_prod ProbabilityTheory.kernel.ae_ae_of_ae_compProd lemma ae_compProd_of_ae_ae {p : β × γ → Prop} (hp : MeasurableSet {x | p x}) (h : ∀ᵐ b ∂κ a, ∀ᵐ c ∂η (a, b), p (b, c)) : ∀ᵐ bc ∂(κ ⊗ₖ η) a, p bc := by simp_rw [ae_iff] at h ⊢ rw [compProd_null] · exact h · exact hp.compl lemma ae_compProd_iff {p : β × γ → Prop} (hp : MeasurableSet {x | p x}) : (∀ᵐ bc ∂(κ ⊗ₖ η) a, p bc) ↔ ∀ᵐ b ∂κ a, ∀ᵐ c ∂η (a, b), p (b, c) := ⟨fun h ↦ ae_ae_of_ae_compProd h, fun h ↦ ae_compProd_of_ae_ae hp h⟩ end Ae section Restrict variable {κ : kernel α β} [IsSFiniteKernel κ] {η : kernel (α × β) γ} [IsSFiniteKernel η] {a : α} theorem compProd_restrict {s : Set β} {t : Set γ} (hs : MeasurableSet s) (ht : MeasurableSet t) : kernel.restrict κ hs ⊗ₖ kernel.restrict η ht = kernel.restrict (κ ⊗ₖ η) (hs.prod ht) := by ext a u hu rw [compProd_apply _ _ _ hu, restrict_apply' _ _ _ hu, compProd_apply _ _ _ (hu.inter (hs.prod ht))] simp only [kernel.restrict_apply, Measure.restrict_apply' ht, Set.mem_inter_iff, Set.prod_mk_mem_set_prod_eq] have : ∀ b, η (a, b) {c : γ | (b, c) ∈ u ∧ b ∈ s ∧ c ∈ t} = s.indicator (fun b => η (a, b) ({c : γ | (b, c) ∈ u} ∩ t)) b := by intro b classical rw [Set.indicator_apply] split_ifs with h · simp only [h, true_and_iff] rfl · simp only [h, false_and_iff, and_false_iff, Set.setOf_false, measure_empty] simp_rw [this] rw [lintegral_indicator _ hs] #align probability_theory.kernel.comp_prod_restrict ProbabilityTheory.kernel.compProd_restrict theorem compProd_restrict_left {s : Set β} (hs : MeasurableSet s) : kernel.restrict κ hs ⊗ₖ η = kernel.restrict (κ ⊗ₖ η) (hs.prod MeasurableSet.univ) := by rw [← compProd_restrict] · congr; exact kernel.restrict_univ.symm #align probability_theory.kernel.comp_prod_restrict_left ProbabilityTheory.kernel.compProd_restrict_left theorem compProd_restrict_right {t : Set γ} (ht : MeasurableSet t) : κ ⊗ₖ kernel.restrict η ht = kernel.restrict (κ ⊗ₖ η) (MeasurableSet.univ.prod ht) := by rw [← compProd_restrict] · congr; exact kernel.restrict_univ.symm #align probability_theory.kernel.comp_prod_restrict_right ProbabilityTheory.kernel.compProd_restrict_right end Restrict section Lintegral /-! ### Lebesgue integral -/ /-- Lebesgue integral against the composition-product of two kernels. -/ theorem lintegral_compProd' (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β → γ → ℝ≥0∞} (hf : Measurable (Function.uncurry f)) : ∫⁻ bc, f bc.1 bc.2 ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c, f b c ∂η (a, b) ∂κ a := by let F : ℕ → SimpleFunc (β × γ) ℝ≥0∞ := SimpleFunc.eapprox (Function.uncurry f) have h : ∀ a, ⨆ n, F n a = Function.uncurry f a := SimpleFunc.iSup_eapprox_apply (Function.uncurry f) hf simp only [Prod.forall, Function.uncurry_apply_pair] at h simp_rw [← h] have h_mono : Monotone F := fun i j hij b => SimpleFunc.monotone_eapprox (Function.uncurry f) hij _ rw [lintegral_iSup (fun n => (F n).measurable) h_mono] have : ∀ b, ∫⁻ c, ⨆ n, F n (b, c) ∂η (a, b) = ⨆ n, ∫⁻ c, F n (b, c) ∂η (a, b) := by intro a rw [lintegral_iSup] · exact fun n => (F n).measurable.comp measurable_prod_mk_left · exact fun i j hij b => h_mono hij _ simp_rw [this] have h_some_meas_integral : ∀ f' : SimpleFunc (β × γ) ℝ≥0∞, Measurable fun b => ∫⁻ c, f' (b, c) ∂η (a, b) := by intro f' have : (fun b => ∫⁻ c, f' (b, c) ∂η (a, b)) = (fun ab => ∫⁻ c, f' (ab.2, c) ∂η ab) ∘ fun b => (a, b) := by ext1 ab; rfl rw [this] apply Measurable.comp _ (measurable_prod_mk_left (m := mα)) exact Measurable.lintegral_kernel_prod_right ((SimpleFunc.measurable _).comp (measurable_fst.snd.prod_mk measurable_snd)) rw [lintegral_iSup] rotate_left · exact fun n => h_some_meas_integral (F n) · exact fun i j hij b => lintegral_mono fun c => h_mono hij _ congr ext1 n -- Porting note: Added `(P := _)` refine SimpleFunc.induction (P := fun f => (∫⁻ (a : β × γ), f a ∂(κ ⊗ₖ η) a = ∫⁻ (a_1 : β), ∫⁻ (c : γ), f (a_1, c) ∂η (a, a_1) ∂κ a)) ?_ ?_ (F n) · intro c s hs classical -- Porting note: Added `classical` for `Set.piecewise_eq_indicator` simp (config := { unfoldPartialApp := true }) only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_const, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, Function.const, lintegral_indicator_const hs] rw [compProd_apply κ η _ hs, ← lintegral_const_mul c _] swap · exact (measurable_kernel_prod_mk_left ((measurable_fst.snd.prod_mk measurable_snd) hs)).comp measurable_prod_mk_left congr ext1 b rw [lintegral_indicator_const_comp measurable_prod_mk_left hs] rfl · intro f f' _ hf_eq hf'_eq simp_rw [SimpleFunc.coe_add, Pi.add_apply] change ∫⁻ x, (f : β × γ → ℝ≥0∞) x + f' x ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c : γ, f (b, c) + f' (b, c) ∂η (a, b) ∂κ a rw [lintegral_add_left (SimpleFunc.measurable _), hf_eq, hf'_eq, ← lintegral_add_left] swap · exact h_some_meas_integral f congr with b rw [lintegral_add_left] exact (SimpleFunc.measurable _).comp measurable_prod_mk_left #align probability_theory.kernel.lintegral_comp_prod' ProbabilityTheory.kernel.lintegral_compProd' /-- Lebesgue integral against the composition-product of two kernels. -/ theorem lintegral_compProd (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) : ∫⁻ bc, f bc ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c, f (b, c) ∂η (a, b) ∂κ a := by let g := Function.curry f change ∫⁻ bc, f bc ∂(κ ⊗ₖ η) a = ∫⁻ b, ∫⁻ c, g b c ∂η (a, b) ∂κ a rw [← lintegral_compProd'] · simp_rw [g, Function.curry_apply] · simp_rw [g, Function.uncurry_curry]; exact hf #align probability_theory.kernel.lintegral_comp_prod ProbabilityTheory.kernel.lintegral_compProd /-- Lebesgue integral against the composition-product of two kernels. -/ theorem lintegral_compProd₀ (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : AEMeasurable f ((κ ⊗ₖ η) a)) : ∫⁻ z, f z ∂(κ ⊗ₖ η) a = ∫⁻ x, ∫⁻ y, f (x, y) ∂η (a, x) ∂κ a := by have A : ∫⁻ z, f z ∂(κ ⊗ₖ η) a = ∫⁻ z, hf.mk f z ∂(κ ⊗ₖ η) a := lintegral_congr_ae hf.ae_eq_mk have B : ∫⁻ x, ∫⁻ y, f (x, y) ∂η (a, x) ∂κ a = ∫⁻ x, ∫⁻ y, hf.mk f (x, y) ∂η (a, x) ∂κ a := by apply lintegral_congr_ae filter_upwards [ae_ae_of_ae_compProd hf.ae_eq_mk] with _ ha using lintegral_congr_ae ha rw [A, B, lintegral_compProd] exact hf.measurable_mk #align probability_theory.kernel.lintegral_comp_prod₀ ProbabilityTheory.kernel.lintegral_compProd₀ theorem set_lintegral_compProd (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) {s : Set β} {t : Set γ} (hs : MeasurableSet s) (ht : MeasurableSet t) : ∫⁻ z in s ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫⁻ x in s, ∫⁻ y in t, f (x, y) ∂η (a, x) ∂κ a := by simp_rw [← kernel.restrict_apply (κ ⊗ₖ η) (hs.prod ht), ← compProd_restrict hs ht, lintegral_compProd _ _ _ hf, kernel.restrict_apply] #align probability_theory.kernel.set_lintegral_comp_prod ProbabilityTheory.kernel.set_lintegral_compProd theorem set_lintegral_compProd_univ_right (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : ∫⁻ z in s ×ˢ Set.univ, f z ∂(κ ⊗ₖ η) a = ∫⁻ x in s, ∫⁻ y, f (x, y) ∂η (a, x) ∂κ a := by simp_rw [set_lintegral_compProd κ η a hf hs MeasurableSet.univ, Measure.restrict_univ] #align probability_theory.kernel.set_lintegral_comp_prod_univ_right ProbabilityTheory.kernel.set_lintegral_compProd_univ_right theorem set_lintegral_compProd_univ_left (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) {f : β × γ → ℝ≥0∞} (hf : Measurable f) {t : Set γ} (ht : MeasurableSet t) : ∫⁻ z in Set.univ ×ˢ t, f z ∂(κ ⊗ₖ η) a = ∫⁻ x, ∫⁻ y in t, f (x, y) ∂η (a, x) ∂κ a := by simp_rw [set_lintegral_compProd κ η a hf MeasurableSet.univ ht, Measure.restrict_univ] #align probability_theory.kernel.set_lintegral_comp_prod_univ_left ProbabilityTheory.kernel.set_lintegral_compProd_univ_left end Lintegral theorem compProd_eq_tsum_compProd (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) : (κ ⊗ₖ η) a s = ∑' (n : ℕ) (m : ℕ), (seq κ n ⊗ₖ seq η m) a s := by simp_rw [compProd_apply_eq_compProdFun _ _ _ hs]; exact compProdFun_eq_tsum κ η a hs #align probability_theory.kernel.comp_prod_eq_tsum_comp_prod ProbabilityTheory.kernel.compProd_eq_tsum_compProd theorem compProd_eq_sum_compProd (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] : κ ⊗ₖ η = kernel.sum fun n => kernel.sum fun m => seq κ n ⊗ₖ seq η m := by ext a s hs; simp_rw [kernel.sum_apply' _ a hs]; rw [compProd_eq_tsum_compProd κ η a hs] #align probability_theory.kernel.comp_prod_eq_sum_comp_prod ProbabilityTheory.kernel.compProd_eq_sum_compProd theorem compProd_eq_sum_compProd_left (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) : κ ⊗ₖ η = kernel.sum fun n => seq κ n ⊗ₖ η := by by_cases h : IsSFiniteKernel η swap · simp_rw [compProd_of_not_isSFiniteKernel_right _ _ h] simp rw [compProd_eq_sum_compProd] congr with n a s hs simp_rw [kernel.sum_apply' _ _ hs, compProd_apply_eq_compProdFun _ _ _ hs, compProdFun_tsum_right _ η a hs] #align probability_theory.kernel.comp_prod_eq_sum_comp_prod_left ProbabilityTheory.kernel.compProd_eq_sum_compProd_left theorem compProd_eq_sum_compProd_right (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel η] : κ ⊗ₖ η = kernel.sum fun n => κ ⊗ₖ seq η n := by by_cases hκ : IsSFiniteKernel κ swap · simp_rw [compProd_of_not_isSFiniteKernel_left _ _ hκ] simp rw [compProd_eq_sum_compProd] simp_rw [compProd_eq_sum_compProd_left κ _] rw [kernel.sum_comm] #align probability_theory.kernel.comp_prod_eq_sum_comp_prod_right ProbabilityTheory.kernel.compProd_eq_sum_compProd_right instance IsMarkovKernel.compProd (κ : kernel α β) [IsMarkovKernel κ] (η : kernel (α × β) γ) [IsMarkovKernel η] : IsMarkovKernel (κ ⊗ₖ η) := ⟨fun a => ⟨by rw [compProd_apply κ η a MeasurableSet.univ] simp only [Set.mem_univ, Set.setOf_true, measure_univ, lintegral_one]⟩⟩ #align probability_theory.kernel.is_markov_kernel.comp_prod ProbabilityTheory.kernel.IsMarkovKernel.compProd theorem compProd_apply_univ_le (κ : kernel α β) (η : kernel (α × β) γ) [IsFiniteKernel η] (a : α) : (κ ⊗ₖ η) a Set.univ ≤ κ a Set.univ * IsFiniteKernel.bound η := by by_cases hκ : IsSFiniteKernel κ swap · rw [compProd_of_not_isSFiniteKernel_left _ _ hκ] simp rw [compProd_apply κ η a MeasurableSet.univ] simp only [Set.mem_univ, Set.setOf_true] let Cη := IsFiniteKernel.bound η calc ∫⁻ b, η (a, b) Set.univ ∂κ a ≤ ∫⁻ _, Cη ∂κ a := lintegral_mono fun b => measure_le_bound η (a, b) Set.univ _ = Cη * κ a Set.univ := MeasureTheory.lintegral_const Cη _ = κ a Set.univ * Cη := mul_comm _ _ #align probability_theory.kernel.comp_prod_apply_univ_le ProbabilityTheory.kernel.compProd_apply_univ_le instance IsFiniteKernel.compProd (κ : kernel α β) [IsFiniteKernel κ] (η : kernel (α × β) γ) [IsFiniteKernel η] : IsFiniteKernel (κ ⊗ₖ η) := ⟨⟨IsFiniteKernel.bound κ * IsFiniteKernel.bound η, ENNReal.mul_lt_top (IsFiniteKernel.bound_ne_top κ) (IsFiniteKernel.bound_ne_top η), fun a => calc (κ ⊗ₖ η) a Set.univ ≤ κ a Set.univ * IsFiniteKernel.bound η := compProd_apply_univ_le κ η a _ ≤ IsFiniteKernel.bound κ * IsFiniteKernel.bound η := mul_le_mul (measure_le_bound κ a Set.univ) le_rfl (zero_le _) (zero_le _)⟩⟩ #align probability_theory.kernel.is_finite_kernel.comp_prod ProbabilityTheory.kernel.IsFiniteKernel.compProd instance IsSFiniteKernel.compProd (κ : kernel α β) (η : kernel (α × β) γ) : IsSFiniteKernel (κ ⊗ₖ η) := by by_cases h : IsSFiniteKernel κ swap · rw [compProd_of_not_isSFiniteKernel_left _ _ h] infer_instance by_cases h : IsSFiniteKernel η swap · rw [compProd_of_not_isSFiniteKernel_right _ _ h] infer_instance rw [compProd_eq_sum_compProd] exact kernel.isSFiniteKernel_sum fun n => kernel.isSFiniteKernel_sum inferInstance #align probability_theory.kernel.is_s_finite_kernel.comp_prod ProbabilityTheory.kernel.IsSFiniteKernel.compProd lemma compProd_add_left (μ κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel μ] [IsSFiniteKernel κ] [IsSFiniteKernel η] : (μ + κ) ⊗ₖ η = μ ⊗ₖ η + κ ⊗ₖ η := by ext _ _ hs; simp [compProd_apply _ _ _ hs] lemma compProd_add_right (μ : kernel α β) (κ η : kernel (α × β) γ) [IsSFiniteKernel μ] [IsSFiniteKernel κ] [IsSFiniteKernel η] : μ ⊗ₖ (κ + η) = μ ⊗ₖ κ + μ ⊗ₖ η := by ext a s hs simp only [compProd_apply _ _ _ hs, coeFn_add, Pi.add_apply, Measure.coe_add] rw [lintegral_add_left] exact measurable_kernel_prod_mk_left' hs a lemma comapRight_compProd_id_prod {δ : Type*} {mδ : MeasurableSpace δ} (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ) [IsSFiniteKernel η] {f : δ → γ} (hf : MeasurableEmbedding f) : comapRight (κ ⊗ₖ η) (MeasurableEmbedding.id.prod_mk hf) = κ ⊗ₖ (comapRight η hf) := by ext a t ht rw [comapRight_apply' _ _ _ ht, compProd_apply, compProd_apply _ _ _ ht] swap; · exact (MeasurableEmbedding.id.prod_mk hf).measurableSet_image.mpr ht refine lintegral_congr (fun b ↦ ?_) simp only [id_eq, Set.mem_image, Prod.mk.injEq, Prod.exists] rw [comapRight_apply'] swap; · exact measurable_prod_mk_left ht congr with x simp only [Set.mem_setOf_eq, Set.mem_image] constructor · rintro ⟨b', c, h, rfl, rfl⟩ exact ⟨c, h, rfl⟩ · rintro ⟨c, h, rfl⟩ exact ⟨b, c, h, rfl, rfl⟩ end CompositionProduct section MapComap /-! ### map, comap -/ variable {γ δ : Type*} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ} {f : β → γ} {g : γ → α} /-- The pushforward of a kernel along a measurable function. We include measurability in the assumptions instead of using junk values to make sure that typeclass inference can infer that the `map` of a Markov kernel is again a Markov kernel. -/ noncomputable def map (κ : kernel α β) (f : β → γ) (hf : Measurable f) : kernel α γ where val a := (κ a).map f property := (Measure.measurable_map _ hf).comp (kernel.measurable κ) #align probability_theory.kernel.map ProbabilityTheory.kernel.map theorem map_apply (κ : kernel α β) (hf : Measurable f) (a : α) : map κ f hf a = (κ a).map f := rfl #align probability_theory.kernel.map_apply ProbabilityTheory.kernel.map_apply theorem map_apply' (κ : kernel α β) (hf : Measurable f) (a : α) {s : Set γ} (hs : MeasurableSet s) : map κ f hf a s = κ a (f ⁻¹' s) := by rw [map_apply, Measure.map_apply hf hs] #align probability_theory.kernel.map_apply' ProbabilityTheory.kernel.map_apply' @[simp] lemma map_zero (hf : Measurable f) : kernel.map (0 : kernel α β) f hf = 0 := by ext; rw [kernel.map_apply]; simp @[simp] lemma map_id (κ : kernel α β) : map κ id measurable_id = κ := by ext a; rw [map_apply]; simp @[simp] lemma map_id' (κ : kernel α β) : map κ (fun a ↦ a) measurable_id = κ := map_id κ nonrec theorem lintegral_map (κ : kernel α β) (hf : Measurable f) (a : α) {g' : γ → ℝ≥0∞} (hg : Measurable g') : ∫⁻ b, g' b ∂map κ f hf a = ∫⁻ a, g' (f a) ∂κ a := by rw [map_apply _ hf, lintegral_map hg hf] #align probability_theory.kernel.lintegral_map ProbabilityTheory.kernel.lintegral_map theorem sum_map_seq (κ : kernel α β) [IsSFiniteKernel κ] (hf : Measurable f) : (kernel.sum fun n => map (seq κ n) f hf) = map κ f hf := by ext a s hs rw [kernel.sum_apply, map_apply' κ hf a hs, Measure.sum_apply _ hs, ← measure_sum_seq κ, Measure.sum_apply _ (hf hs)] simp_rw [map_apply' _ hf _ hs] #align probability_theory.kernel.sum_map_seq ProbabilityTheory.kernel.sum_map_seq instance IsMarkovKernel.map (κ : kernel α β) [IsMarkovKernel κ] (hf : Measurable f) : IsMarkovKernel (map κ f hf) := ⟨fun a => ⟨by rw [map_apply' κ hf a MeasurableSet.univ, Set.preimage_univ, measure_univ]⟩⟩ #align probability_theory.kernel.is_markov_kernel.map ProbabilityTheory.kernel.IsMarkovKernel.map instance IsFiniteKernel.map (κ : kernel α β) [IsFiniteKernel κ] (hf : Measurable f) : IsFiniteKernel (map κ f hf) := by refine ⟨⟨IsFiniteKernel.bound κ, IsFiniteKernel.bound_lt_top κ, fun a => ?_⟩⟩ rw [map_apply' κ hf a MeasurableSet.univ] exact measure_le_bound κ a _ #align probability_theory.kernel.is_finite_kernel.map ProbabilityTheory.kernel.IsFiniteKernel.map instance IsSFiniteKernel.map (κ : kernel α β) [IsSFiniteKernel κ] (hf : Measurable f) : IsSFiniteKernel (map κ f hf) := ⟨⟨fun n => kernel.map (seq κ n) f hf, inferInstance, (sum_map_seq κ hf).symm⟩⟩ #align probability_theory.kernel.is_s_finite_kernel.map ProbabilityTheory.kernel.IsSFiniteKernel.map @[simp] lemma map_const (μ : Measure α) {f : α → β} (hf : Measurable f) : map (const γ μ) f hf = const γ (μ.map f) := by ext x s hs rw [map_apply' _ _ _ hs, const_apply, const_apply, Measure.map_apply hf hs] /-- Pullback of a kernel, such that for each set s `comap κ g hg c s = κ (g c) s`. We include measurability in the assumptions instead of using junk values to make sure that typeclass inference can infer that the `comap` of a Markov kernel is again a Markov kernel. -/ def comap (κ : kernel α β) (g : γ → α) (hg : Measurable g) : kernel γ β where val a := κ (g a) property := (kernel.measurable κ).comp hg #align probability_theory.kernel.comap ProbabilityTheory.kernel.comap theorem comap_apply (κ : kernel α β) (hg : Measurable g) (c : γ) : comap κ g hg c = κ (g c) := rfl #align probability_theory.kernel.comap_apply ProbabilityTheory.kernel.comap_apply theorem comap_apply' (κ : kernel α β) (hg : Measurable g) (c : γ) (s : Set β) : comap κ g hg c s = κ (g c) s := rfl #align probability_theory.kernel.comap_apply' ProbabilityTheory.kernel.comap_apply' @[simp] lemma comap_zero (hg : Measurable g) : kernel.comap (0 : kernel α β) g hg = 0 := by ext; rw [kernel.comap_apply]; simp @[simp] lemma comap_id (κ : kernel α β) : comap κ id measurable_id = κ := by ext a; rw [comap_apply]; simp @[simp] lemma comap_id' (κ : kernel α β) : comap κ (fun a ↦ a) measurable_id = κ := comap_id κ theorem lintegral_comap (κ : kernel α β) (hg : Measurable g) (c : γ) (g' : β → ℝ≥0∞) : ∫⁻ b, g' b ∂comap κ g hg c = ∫⁻ b, g' b ∂κ (g c) := rfl #align probability_theory.kernel.lintegral_comap ProbabilityTheory.kernel.lintegral_comap theorem sum_comap_seq (κ : kernel α β) [IsSFiniteKernel κ] (hg : Measurable g) : (kernel.sum fun n => comap (seq κ n) g hg) = comap κ g hg := by ext a s hs rw [kernel.sum_apply, comap_apply' κ hg a s, Measure.sum_apply _ hs, ← measure_sum_seq κ, Measure.sum_apply _ hs] simp_rw [comap_apply' _ hg _ s] #align probability_theory.kernel.sum_comap_seq ProbabilityTheory.kernel.sum_comap_seq instance IsMarkovKernel.comap (κ : kernel α β) [IsMarkovKernel κ] (hg : Measurable g) : IsMarkovKernel (comap κ g hg) := ⟨fun a => ⟨by rw [comap_apply' κ hg a Set.univ, measure_univ]⟩⟩ #align probability_theory.kernel.is_markov_kernel.comap ProbabilityTheory.kernel.IsMarkovKernel.comap instance IsFiniteKernel.comap (κ : kernel α β) [IsFiniteKernel κ] (hg : Measurable g) : IsFiniteKernel (comap κ g hg) := by refine ⟨⟨IsFiniteKernel.bound κ, IsFiniteKernel.bound_lt_top κ, fun a => ?_⟩⟩ rw [comap_apply' κ hg a Set.univ] exact measure_le_bound κ _ _ #align probability_theory.kernel.is_finite_kernel.comap ProbabilityTheory.kernel.IsFiniteKernel.comap instance IsSFiniteKernel.comap (κ : kernel α β) [IsSFiniteKernel κ] (hg : Measurable g) : IsSFiniteKernel (comap κ g hg) := ⟨⟨fun n => kernel.comap (seq κ n) g hg, inferInstance, (sum_comap_seq κ hg).symm⟩⟩ #align probability_theory.kernel.is_s_finite_kernel.comap ProbabilityTheory.kernel.IsSFiniteKernel.comap lemma comap_map_comm (κ : kernel β γ) {f : α → β} {g : γ → δ} (hf : Measurable f) (hg : Measurable g) : comap (map κ g hg) f hf = map (comap κ f hf) g hg := by ext x s _ rw [comap_apply, map_apply, map_apply, comap_apply] end MapComap open scoped ProbabilityTheory section FstSnd variable {δ : Type*} {mδ : MeasurableSpace δ} /-- Define a `kernel (γ × α) β` from a `kernel α β` by taking the comap of the projection. -/ def prodMkLeft (γ : Type*) [MeasurableSpace γ] (κ : kernel α β) : kernel (γ × α) β := comap κ Prod.snd measurable_snd #align probability_theory.kernel.prod_mk_left ProbabilityTheory.kernel.prodMkLeft /-- Define a `kernel (α × γ) β` from a `kernel α β` by taking the comap of the projection. -/ def prodMkRight (γ : Type*) [MeasurableSpace γ] (κ : kernel α β) : kernel (α × γ) β := comap κ Prod.fst measurable_fst variable {γ : Type*} {mγ : MeasurableSpace γ} {f : β → γ} {g : γ → α} @[simp] theorem prodMkLeft_apply (κ : kernel α β) (ca : γ × α) : prodMkLeft γ κ ca = κ ca.snd := rfl #align probability_theory.kernel.prod_mk_left_apply ProbabilityTheory.kernel.prodMkLeft_apply @[simp] theorem prodMkRight_apply (κ : kernel α β) (ca : α × γ) : prodMkRight γ κ ca = κ ca.fst := rfl theorem prodMkLeft_apply' (κ : kernel α β) (ca : γ × α) (s : Set β) : prodMkLeft γ κ ca s = κ ca.snd s := rfl #align probability_theory.kernel.prod_mk_left_apply' ProbabilityTheory.kernel.prodMkLeft_apply' theorem prodMkRight_apply' (κ : kernel α β) (ca : α × γ) (s : Set β) : prodMkRight γ κ ca s = κ ca.fst s := rfl @[simp] lemma prodMkLeft_zero : kernel.prodMkLeft α (0 : kernel β γ) = 0 := by ext x s _; simp @[simp] lemma prodMkRight_zero : kernel.prodMkRight α (0 : kernel β γ) = 0 := by ext x s _; simp @[simp] lemma prodMkLeft_add (κ η : kernel α β) : prodMkLeft γ (κ + η) = prodMkLeft γ κ + prodMkLeft γ η := by ext; simp @[simp] lemma prodMkRight_add (κ η : kernel α β) : prodMkRight γ (κ + η) = prodMkRight γ κ + prodMkRight γ η := by ext; simp theorem lintegral_prodMkLeft (κ : kernel α β) (ca : γ × α) (g : β → ℝ≥0∞) : ∫⁻ b, g b ∂prodMkLeft γ κ ca = ∫⁻ b, g b ∂κ ca.snd := rfl #align probability_theory.kernel.lintegral_prod_mk_left ProbabilityTheory.kernel.lintegral_prodMkLeft theorem lintegral_prodMkRight (κ : kernel α β) (ca : α × γ) (g : β → ℝ≥0∞) : ∫⁻ b, g b ∂prodMkRight γ κ ca = ∫⁻ b, g b ∂κ ca.fst := rfl instance IsMarkovKernel.prodMkLeft (κ : kernel α β) [IsMarkovKernel κ] : IsMarkovKernel (prodMkLeft γ κ) := by rw [kernel.prodMkLeft]; infer_instance #align probability_theory.kernel.is_markov_kernel.prod_mk_left ProbabilityTheory.kernel.IsMarkovKernel.prodMkLeft instance IsMarkovKernel.prodMkRight (κ : kernel α β) [IsMarkovKernel κ] : IsMarkovKernel (prodMkRight γ κ) := by rw [kernel.prodMkRight]; infer_instance instance IsFiniteKernel.prodMkLeft (κ : kernel α β) [IsFiniteKernel κ] : IsFiniteKernel (prodMkLeft γ κ) := by rw [kernel.prodMkLeft]; infer_instance #align probability_theory.kernel.is_finite_kernel.prod_mk_left ProbabilityTheory.kernel.IsFiniteKernel.prodMkLeft instance IsFiniteKernel.prodMkRight (κ : kernel α β) [IsFiniteKernel κ] : IsFiniteKernel (prodMkRight γ κ) := by rw [kernel.prodMkRight]; infer_instance instance IsSFiniteKernel.prodMkLeft (κ : kernel α β) [IsSFiniteKernel κ] : IsSFiniteKernel (prodMkLeft γ κ) := by rw [kernel.prodMkLeft]; infer_instance #align probability_theory.kernel.is_s_finite_kernel.prod_mk_left ProbabilityTheory.kernel.IsSFiniteKernel.prodMkLeft instance IsSFiniteKernel.prodMkRight (κ : kernel α β) [IsSFiniteKernel κ] : IsSFiniteKernel (prodMkRight γ κ) := by rw [kernel.prodMkRight]; infer_instance lemma map_prodMkLeft (γ : Type*) [MeasurableSpace γ] (κ : kernel α β) {f : β → δ} (hf : Measurable f) : map (prodMkLeft γ κ) f hf = prodMkLeft γ (map κ f hf) := rfl lemma map_prodMkRight (κ : kernel α β) (γ : Type*) [MeasurableSpace γ] {f : β → δ} (hf : Measurable f) : map (prodMkRight γ κ) f hf = prodMkRight γ (map κ f hf) := rfl /-- Define a `kernel (β × α) γ` from a `kernel (α × β) γ` by taking the comap of `Prod.swap`. -/ def swapLeft (κ : kernel (α × β) γ) : kernel (β × α) γ := comap κ Prod.swap measurable_swap #align probability_theory.kernel.swap_left ProbabilityTheory.kernel.swapLeft @[simp] theorem swapLeft_apply (κ : kernel (α × β) γ) (a : β × α) : swapLeft κ a = κ a.swap := rfl #align probability_theory.kernel.swap_left_apply ProbabilityTheory.kernel.swapLeft_apply theorem swapLeft_apply' (κ : kernel (α × β) γ) (a : β × α) (s : Set γ) : swapLeft κ a s = κ a.swap s := rfl #align probability_theory.kernel.swap_left_apply' ProbabilityTheory.kernel.swapLeft_apply' theorem lintegral_swapLeft (κ : kernel (α × β) γ) (a : β × α) (g : γ → ℝ≥0∞) : ∫⁻ c, g c ∂swapLeft κ a = ∫⁻ c, g c ∂κ a.swap := by rw [swapLeft_apply] #align probability_theory.kernel.lintegral_swap_left ProbabilityTheory.kernel.lintegral_swapLeft instance IsMarkovKernel.swapLeft (κ : kernel (α × β) γ) [IsMarkovKernel κ] : IsMarkovKernel (swapLeft κ) := by rw [kernel.swapLeft]; infer_instance #align probability_theory.kernel.is_markov_kernel.swap_left ProbabilityTheory.kernel.IsMarkovKernel.swapLeft instance IsFiniteKernel.swapLeft (κ : kernel (α × β) γ) [IsFiniteKernel κ] : IsFiniteKernel (swapLeft κ) := by rw [kernel.swapLeft]; infer_instance #align probability_theory.kernel.is_finite_kernel.swap_left ProbabilityTheory.kernel.IsFiniteKernel.swapLeft instance IsSFiniteKernel.swapLeft (κ : kernel (α × β) γ) [IsSFiniteKernel κ] : IsSFiniteKernel (swapLeft κ) := by rw [kernel.swapLeft]; infer_instance #align probability_theory.kernel.is_s_finite_kernel.swap_left ProbabilityTheory.kernel.IsSFiniteKernel.swapLeft @[simp] lemma swapLeft_prodMkLeft (κ : kernel α β) (γ : Type*) [MeasurableSpace γ] : swapLeft (prodMkLeft γ κ) = prodMkRight γ κ := rfl @[simp] lemma swapLeft_prodMkRight (κ : kernel α β) (γ : Type*) [MeasurableSpace γ] : swapLeft (prodMkRight γ κ) = prodMkLeft γ κ := rfl /-- Define a `kernel α (γ × β)` from a `kernel α (β × γ)` by taking the map of `Prod.swap`. -/ noncomputable def swapRight (κ : kernel α (β × γ)) : kernel α (γ × β) := map κ Prod.swap measurable_swap #align probability_theory.kernel.swap_right ProbabilityTheory.kernel.swapRight theorem swapRight_apply (κ : kernel α (β × γ)) (a : α) : swapRight κ a = (κ a).map Prod.swap := rfl #align probability_theory.kernel.swap_right_apply ProbabilityTheory.kernel.swapRight_apply theorem swapRight_apply' (κ : kernel α (β × γ)) (a : α) {s : Set (γ × β)} (hs : MeasurableSet s) : swapRight κ a s = κ a {p | p.swap ∈ s} := by rw [swapRight_apply, Measure.map_apply measurable_swap hs]; rfl #align probability_theory.kernel.swap_right_apply' ProbabilityTheory.kernel.swapRight_apply' theorem lintegral_swapRight (κ : kernel α (β × γ)) (a : α) {g : γ × β → ℝ≥0∞} (hg : Measurable g) : ∫⁻ c, g c ∂swapRight κ a = ∫⁻ bc : β × γ, g bc.swap ∂κ a := by rw [swapRight, lintegral_map _ measurable_swap a hg] #align probability_theory.kernel.lintegral_swap_right ProbabilityTheory.kernel.lintegral_swapRight instance IsMarkovKernel.swapRight (κ : kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (swapRight κ) := by rw [kernel.swapRight]; infer_instance #align probability_theory.kernel.is_markov_kernel.swap_right ProbabilityTheory.kernel.IsMarkovKernel.swapRight instance IsFiniteKernel.swapRight (κ : kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (swapRight κ) := by rw [kernel.swapRight]; infer_instance #align probability_theory.kernel.is_finite_kernel.swap_right ProbabilityTheory.kernel.IsFiniteKernel.swapRight instance IsSFiniteKernel.swapRight (κ : kernel α (β × γ)) [IsSFiniteKernel κ] : IsSFiniteKernel (swapRight κ) := by rw [kernel.swapRight]; infer_instance #align probability_theory.kernel.is_s_finite_kernel.swap_right ProbabilityTheory.kernel.IsSFiniteKernel.swapRight /-- Define a `kernel α β` from a `kernel α (β × γ)` by taking the map of the first projection. -/ noncomputable def fst (κ : kernel α (β × γ)) : kernel α β := map κ Prod.fst measurable_fst #align probability_theory.kernel.fst ProbabilityTheory.kernel.fst theorem fst_apply (κ : kernel α (β × γ)) (a : α) : fst κ a = (κ a).map Prod.fst := rfl #align probability_theory.kernel.fst_apply ProbabilityTheory.kernel.fst_apply theorem fst_apply' (κ : kernel α (β × γ)) (a : α) {s : Set β} (hs : MeasurableSet s) : fst κ a s = κ a {p | p.1 ∈ s} := by rw [fst_apply, Measure.map_apply measurable_fst hs]; rfl #align probability_theory.kernel.fst_apply' ProbabilityTheory.kernel.fst_apply' @[simp] lemma fst_zero : fst (0 : kernel α (β × γ)) = 0 := by simp [fst] theorem lintegral_fst (κ : kernel α (β × γ)) (a : α) {g : β → ℝ≥0∞} (hg : Measurable g) : ∫⁻ c, g c ∂fst κ a = ∫⁻ bc : β × γ, g bc.fst ∂κ a := by rw [fst, lintegral_map _ measurable_fst a hg] #align probability_theory.kernel.lintegral_fst ProbabilityTheory.kernel.lintegral_fst instance IsMarkovKernel.fst (κ : kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (fst κ) := by rw [kernel.fst]; infer_instance #align probability_theory.kernel.is_markov_kernel.fst ProbabilityTheory.kernel.IsMarkovKernel.fst instance IsFiniteKernel.fst (κ : kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (fst κ) := by rw [kernel.fst]; infer_instance #align probability_theory.kernel.is_finite_kernel.fst ProbabilityTheory.kernel.IsFiniteKernel.fst instance IsSFiniteKernel.fst (κ : kernel α (β × γ)) [IsSFiniteKernel κ] : IsSFiniteKernel (fst κ) := by rw [kernel.fst]; infer_instance #align probability_theory.kernel.is_s_finite_kernel.fst ProbabilityTheory.kernel.IsSFiniteKernel.fst instance (priority := 100) isFiniteKernel_of_isFiniteKernel_fst {κ : kernel α (β × γ)} [h : IsFiniteKernel (fst κ)] : IsFiniteKernel κ := by refine ⟨h.bound, h.bound_lt_top, fun a ↦ le_trans ?_ (measure_le_bound (fst κ) a Set.univ)⟩ rw [fst_apply' _ _ MeasurableSet.univ] simp lemma fst_map_prod (κ : kernel α β) {f : β → γ} {g : β → δ} (hf : Measurable f) (hg : Measurable g) : fst (map κ (fun x ↦ (f x, g x)) (hf.prod_mk hg)) = map κ f hf := by ext x s hs rw [fst_apply' _ _ hs, map_apply', map_apply' _ _ _ hs] · rfl · exact measurable_fst hs lemma fst_map_id_prod (κ : kernel α β) {γ : Type*} {mγ : MeasurableSpace γ} {f : β → γ} (hf : Measurable f) : fst (map κ (fun a ↦ (a, f a)) (measurable_id.prod_mk hf)) = κ := by rw [fst_map_prod _ measurable_id' hf, kernel.map_id'] @[simp] lemma fst_compProd (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel κ] [IsMarkovKernel η] : fst (κ ⊗ₖ η) = κ := by ext x s hs rw [fst_apply' _ _ hs, compProd_apply] swap; · exact measurable_fst hs simp only [Set.mem_setOf_eq] classical have : ∀ b : β, η (x, b) {_c | b ∈ s} = s.indicator (fun _ ↦ 1) b := by intro b by_cases hb : b ∈ s <;> simp [hb] simp_rw [this] rw [lintegral_indicator_const hs, one_mul] lemma fst_prodMkLeft (δ : Type*) [MeasurableSpace δ] (κ : kernel α (β × γ)) : fst (prodMkLeft δ κ) = prodMkLeft δ (fst κ) := rfl lemma fst_prodMkRight (κ : kernel α (β × γ)) (δ : Type*) [MeasurableSpace δ] : fst (prodMkRight δ κ) = prodMkRight δ (fst κ) := rfl /-- Define a `kernel α γ` from a `kernel α (β × γ)` by taking the map of the second projection. -/ noncomputable def snd (κ : kernel α (β × γ)) : kernel α γ := map κ Prod.snd measurable_snd #align probability_theory.kernel.snd ProbabilityTheory.kernel.snd theorem snd_apply (κ : kernel α (β × γ)) (a : α) : snd κ a = (κ a).map Prod.snd := rfl #align probability_theory.kernel.snd_apply ProbabilityTheory.kernel.snd_apply theorem snd_apply' (κ : kernel α (β × γ)) (a : α) {s : Set γ} (hs : MeasurableSet s) : snd κ a s = κ a {p | p.2 ∈ s} := by rw [snd_apply, Measure.map_apply measurable_snd hs]; rfl #align probability_theory.kernel.snd_apply' ProbabilityTheory.kernel.snd_apply' @[simp] lemma snd_zero : snd (0 : kernel α (β × γ)) = 0 := by simp [snd] theorem lintegral_snd (κ : kernel α (β × γ)) (a : α) {g : γ → ℝ≥0∞} (hg : Measurable g) : ∫⁻ c, g c ∂snd κ a = ∫⁻ bc : β × γ, g bc.snd ∂κ a := by rw [snd, lintegral_map _ measurable_snd a hg] #align probability_theory.kernel.lintegral_snd ProbabilityTheory.kernel.lintegral_snd instance IsMarkovKernel.snd (κ : kernel α (β × γ)) [IsMarkovKernel κ] : IsMarkovKernel (snd κ) := by rw [kernel.snd]; infer_instance #align probability_theory.kernel.is_markov_kernel.snd ProbabilityTheory.kernel.IsMarkovKernel.snd instance IsFiniteKernel.snd (κ : kernel α (β × γ)) [IsFiniteKernel κ] : IsFiniteKernel (snd κ) := by rw [kernel.snd]; infer_instance #align probability_theory.kernel.is_finite_kernel.snd ProbabilityTheory.kernel.IsFiniteKernel.snd instance IsSFiniteKernel.snd (κ : kernel α (β × γ)) [IsSFiniteKernel κ] : IsSFiniteKernel (snd κ) := by rw [kernel.snd]; infer_instance #align probability_theory.kernel.is_s_finite_kernel.snd ProbabilityTheory.kernel.IsSFiniteKernel.snd instance (priority := 100) isFiniteKernel_of_isFiniteKernel_snd {κ : kernel α (β × γ)} [h : IsFiniteKernel (snd κ)] : IsFiniteKernel κ := by refine ⟨h.bound, h.bound_lt_top, fun a ↦ le_trans ?_ (measure_le_bound (snd κ) a Set.univ)⟩ rw [snd_apply' _ _ MeasurableSet.univ] simp lemma snd_map_prod (κ : kernel α β) {f : β → γ} {g : β → δ} (hf : Measurable f) (hg : Measurable g) : snd (map κ (fun x ↦ (f x, g x)) (hf.prod_mk hg)) = map κ g hg := by ext x s hs rw [snd_apply' _ _ hs, map_apply', map_apply' _ _ _ hs] · rfl · exact measurable_snd hs lemma snd_map_prod_id (κ : kernel α β) {γ : Type*} {mγ : MeasurableSpace γ} {f : β → γ} (hf : Measurable f) : snd (map κ (fun a ↦ (f a, a)) (hf.prod_mk measurable_id)) = κ := by rw [snd_map_prod _ hf measurable_id', kernel.map_id'] lemma snd_prodMkLeft (δ : Type*) [MeasurableSpace δ] (κ : kernel α (β × γ)) : snd (prodMkLeft δ κ) = prodMkLeft δ (snd κ) := rfl lemma snd_prodMkRight (κ : kernel α (β × γ)) (δ : Type*) [MeasurableSpace δ] : snd (prodMkRight δ κ) = prodMkRight δ (snd κ) := rfl @[simp] lemma fst_swapRight (κ : kernel α (β × γ)) : fst (swapRight κ) = snd κ := by ext a s hs rw [fst_apply' _ _ hs, swapRight_apply', snd_apply' _ _ hs] · rfl · exact measurable_fst hs @[simp] lemma snd_swapRight (κ : kernel α (β × γ)) : snd (swapRight κ) = fst κ := by ext a s hs rw [snd_apply' _ _ hs, swapRight_apply', fst_apply' _ _ hs] · rfl · exact measurable_snd hs end FstSnd section Comp /-! ### Composition of two kernels -/ variable {γ : Type*} {mγ : MeasurableSpace γ} {f : β → γ} {g : γ → α} /-- Composition of two kernels. -/ noncomputable def comp (η : kernel β γ) (κ : kernel α β) : kernel α γ where val a := (κ a).bind η property := (Measure.measurable_bind' (kernel.measurable _)).comp (kernel.measurable _) #align probability_theory.kernel.comp ProbabilityTheory.kernel.comp scoped[ProbabilityTheory] infixl:100 " ∘ₖ " => ProbabilityTheory.kernel.comp theorem comp_apply (η : kernel β γ) (κ : kernel α β) (a : α) : (η ∘ₖ κ) a = (κ a).bind η := rfl #align probability_theory.kernel.comp_apply ProbabilityTheory.kernel.comp_apply theorem comp_apply' (η : kernel β γ) (κ : kernel α β) (a : α) {s : Set γ} (hs : MeasurableSet s) : (η ∘ₖ κ) a s = ∫⁻ b, η b s ∂κ a := by rw [comp_apply, Measure.bind_apply hs (kernel.measurable _)] #align probability_theory.kernel.comp_apply' ProbabilityTheory.kernel.comp_apply' theorem comp_eq_snd_compProd (η : kernel β γ) [IsSFiniteKernel η] (κ : kernel α β) [IsSFiniteKernel κ] : η ∘ₖ κ = snd (κ ⊗ₖ prodMkLeft α η) := by ext a s hs rw [comp_apply' _ _ _ hs, snd_apply' _ _ hs, compProd_apply] swap · exact measurable_snd hs simp only [Set.mem_setOf_eq, Set.setOf_mem_eq, prodMkLeft_apply' _ _ s] #align probability_theory.kernel.comp_eq_snd_comp_prod ProbabilityTheory.kernel.comp_eq_snd_compProd theorem lintegral_comp (η : kernel β γ) (κ : kernel α β) (a : α) {g : γ → ℝ≥0∞} (hg : Measurable g) : ∫⁻ c, g c ∂(η ∘ₖ κ) a = ∫⁻ b, ∫⁻ c, g c ∂η b ∂κ a := by rw [comp_apply, Measure.lintegral_bind (kernel.measurable _) hg] #align probability_theory.kernel.lintegral_comp ProbabilityTheory.kernel.lintegral_comp instance IsMarkovKernel.comp (η : kernel β γ) [IsMarkovKernel η] (κ : kernel α β) [IsMarkovKernel κ] : IsMarkovKernel (η ∘ₖ κ) := by rw [comp_eq_snd_compProd]; infer_instance #align probability_theory.kernel.is_markov_kernel.comp ProbabilityTheory.kernel.IsMarkovKernel.comp instance IsFiniteKernel.comp (η : kernel β γ) [IsFiniteKernel η] (κ : kernel α β) [IsFiniteKernel κ] : IsFiniteKernel (η ∘ₖ κ) := by rw [comp_eq_snd_compProd]; infer_instance #align probability_theory.kernel.is_finite_kernel.comp ProbabilityTheory.kernel.IsFiniteKernel.comp instance IsSFiniteKernel.comp (η : kernel β γ) [IsSFiniteKernel η] (κ : kernel α β) [IsSFiniteKernel κ] : IsSFiniteKernel (η ∘ₖ κ) := by rw [comp_eq_snd_compProd]; infer_instance #align probability_theory.kernel.is_s_finite_kernel.comp ProbabilityTheory.kernel.IsSFiniteKernel.comp /-- Composition of kernels is associative. -/
Mathlib/Probability/Kernel/Composition.lean
1,094
1,097
theorem comp_assoc {δ : Type*} {mδ : MeasurableSpace δ} (ξ : kernel γ δ) [IsSFiniteKernel ξ] (η : kernel β γ) (κ : kernel α β) : ξ ∘ₖ η ∘ₖ κ = ξ ∘ₖ (η ∘ₖ κ) := by
refine ext_fun fun a f hf => ?_ simp_rw [lintegral_comp _ _ _ hf, lintegral_comp _ _ _ hf.lintegral_kernel]
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca, Johan Commelin -/ import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.FieldTheory.Minpoly.Basic import Mathlib.RingTheory.Algebraic #align_import field_theory.minpoly.field from "leanprover-community/mathlib"@"cbdf7b565832144d024caa5a550117c6df0204a5" /-! # Minimal polynomials on an algebra over a field This file specializes the theory of minpoly to the setting of field extensions and derives some well-known properties, amongst which the fact that minimal polynomials are irreducible, and uniquely determined by their defining property. -/ open scoped Classical open Polynomial Set Function minpoly namespace minpoly variable {A B : Type*} variable (A) [Field A] section Ring variable [Ring B] [Algebra A B] (x : B) /-- If an element `x` is a root of a nonzero polynomial `p`, then the degree of `p` is at least the degree of the minimal polynomial of `x`. See also `minpoly.IsIntegrallyClosed.degree_le_of_ne_zero` which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/ theorem degree_le_of_ne_zero {p : A[X]} (pnz : p ≠ 0) (hp : Polynomial.aeval x p = 0) : degree (minpoly A x) ≤ degree p := calc degree (minpoly A x) ≤ degree (p * C (leadingCoeff p)⁻¹) := min A x (monic_mul_leadingCoeff_inv pnz) (by simp [hp]) _ = degree p := degree_mul_leadingCoeff_inv p pnz #align minpoly.degree_le_of_ne_zero minpoly.degree_le_of_ne_zero theorem ne_zero_of_finite (e : B) [FiniteDimensional A B] : minpoly A e ≠ 0 := minpoly.ne_zero <| .of_finite A _ #align minpoly.ne_zero_of_finite_field_extension minpoly.ne_zero_of_finite /-- The minimal polynomial of an element `x` is uniquely characterized by its defining property: if there is another monic polynomial of minimal degree that has `x` as a root, then this polynomial is equal to the minimal polynomial of `x`. See also `minpoly.IsIntegrallyClosed.Minpoly.unique` which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/ theorem unique {p : A[X]} (pmonic : p.Monic) (hp : Polynomial.aeval x p = 0) (pmin : ∀ q : A[X], q.Monic → Polynomial.aeval x q = 0 → degree p ≤ degree q) : p = minpoly A x := by have hx : IsIntegral A x := ⟨p, pmonic, hp⟩ symm; apply eq_of_sub_eq_zero by_contra hnz apply degree_le_of_ne_zero A x hnz (by simp [hp]) |>.not_lt apply degree_sub_lt _ (minpoly.ne_zero hx) · rw [(monic hx).leadingCoeff, pmonic.leadingCoeff] · exact le_antisymm (min A x pmonic hp) (pmin (minpoly A x) (monic hx) (aeval A x)) #align minpoly.unique minpoly.unique /-- If an element `x` is a root of a polynomial `p`, then the minimal polynomial of `x` divides `p`. See also `minpoly.isIntegrallyClosed_dvd` which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/ theorem dvd {p : A[X]} (hp : Polynomial.aeval x p = 0) : minpoly A x ∣ p := by by_cases hp0 : p = 0 · simp only [hp0, dvd_zero] have hx : IsIntegral A x := IsAlgebraic.isIntegral ⟨p, hp0, hp⟩ rw [← modByMonic_eq_zero_iff_dvd (monic hx)] by_contra hnz apply degree_le_of_ne_zero A x hnz ((aeval_modByMonic_eq_self_of_root (monic hx) (aeval _ _)).trans hp) |>.not_lt exact degree_modByMonic_lt _ (monic hx) #align minpoly.dvd minpoly.dvd variable {A x} in lemma dvd_iff {p : A[X]} : minpoly A x ∣ p ↔ Polynomial.aeval x p = 0 := ⟨fun ⟨q, hq⟩ ↦ by rw [hq, map_mul, aeval, zero_mul], minpoly.dvd A x⟩ theorem isRadical [IsReduced B] : IsRadical (minpoly A x) := fun n p dvd ↦ by rw [dvd_iff] at dvd ⊢; rw [map_pow] at dvd; exact IsReduced.eq_zero _ ⟨n, dvd⟩
Mathlib/FieldTheory/Minpoly/Field.lean
86
90
theorem dvd_map_of_isScalarTower (A K : Type*) {R : Type*} [CommRing A] [Field K] [CommRing R] [Algebra A K] [Algebra A R] [Algebra K R] [IsScalarTower A K R] (x : R) : minpoly K x ∣ (minpoly A x).map (algebraMap A K) := by
refine minpoly.dvd K x ?_ rw [aeval_map_algebraMap, minpoly.aeval]
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.ModelTheory.Ultraproducts import Mathlib.ModelTheory.Bundled import Mathlib.ModelTheory.Skolem #align_import model_theory.satisfiability from "leanprover-community/mathlib"@"d565b3df44619c1498326936be16f1a935df0728" /-! # First-Order Satisfiability This file deals with the satisfiability of first-order theories, as well as equivalence over them. ## Main Definitions * `FirstOrder.Language.Theory.IsSatisfiable`: `T.IsSatisfiable` indicates that `T` has a nonempty model. * `FirstOrder.Language.Theory.IsFinitelySatisfiable`: `T.IsFinitelySatisfiable` indicates that every finite subset of `T` is satisfiable. * `FirstOrder.Language.Theory.IsComplete`: `T.IsComplete` indicates that `T` is satisfiable and models each sentence or its negation. * `FirstOrder.Language.Theory.SemanticallyEquivalent`: `T.SemanticallyEquivalent φ ψ` indicates that `φ` and `ψ` are equivalent formulas or sentences in models of `T`. * `Cardinal.Categorical`: A theory is `κ`-categorical if all models of size `κ` are isomorphic. ## Main Results * The Compactness Theorem, `FirstOrder.Language.Theory.isSatisfiable_iff_isFinitelySatisfiable`, shows that a theory is satisfiable iff it is finitely satisfiable. * `FirstOrder.Language.completeTheory.isComplete`: The complete theory of a structure is complete. * `FirstOrder.Language.Theory.exists_large_model_of_infinite_model` shows that any theory with an infinite model has arbitrarily large models. * `FirstOrder.Language.Theory.exists_elementaryEmbedding_card_eq`: The Upward Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. ## Implementation Details * Satisfiability of an `L.Theory` `T` is defined in the minimal universe containing all the symbols of `L`. By Löwenheim-Skolem, this is equivalent to satisfiability in any universe. -/ set_option linter.uppercaseLean3 false universe u v w w' open Cardinal CategoryTheory open Cardinal FirstOrder namespace FirstOrder namespace Language variable {L : Language.{u, v}} {T : L.Theory} {α : Type w} {n : ℕ} namespace Theory variable (T) /-- A theory is satisfiable if a structure models it. -/ def IsSatisfiable : Prop := Nonempty (ModelType.{u, v, max u v} T) #align first_order.language.Theory.is_satisfiable FirstOrder.Language.Theory.IsSatisfiable /-- A theory is finitely satisfiable if all of its finite subtheories are satisfiable. -/ def IsFinitelySatisfiable : Prop := ∀ T0 : Finset L.Sentence, (T0 : L.Theory) ⊆ T → IsSatisfiable (T0 : L.Theory) #align first_order.language.Theory.is_finitely_satisfiable FirstOrder.Language.Theory.IsFinitelySatisfiable variable {T} {T' : L.Theory} theorem Model.isSatisfiable (M : Type w) [Nonempty M] [L.Structure M] [M ⊨ T] : T.IsSatisfiable := ⟨((⊥ : Substructure _ (ModelType.of T M)).elementarySkolem₁Reduct.toModel T).shrink⟩ #align first_order.language.Theory.model.is_satisfiable FirstOrder.Language.Theory.Model.isSatisfiable theorem IsSatisfiable.mono (h : T'.IsSatisfiable) (hs : T ⊆ T') : T.IsSatisfiable := ⟨(Theory.Model.mono (ModelType.is_model h.some) hs).bundled⟩ #align first_order.language.Theory.is_satisfiable.mono FirstOrder.Language.Theory.IsSatisfiable.mono theorem isSatisfiable_empty (L : Language.{u, v}) : IsSatisfiable (∅ : L.Theory) := ⟨default⟩ #align first_order.language.Theory.is_satisfiable_empty FirstOrder.Language.Theory.isSatisfiable_empty theorem isSatisfiable_of_isSatisfiable_onTheory {L' : Language.{w, w'}} (φ : L →ᴸ L') (h : (φ.onTheory T).IsSatisfiable) : T.IsSatisfiable := Model.isSatisfiable (h.some.reduct φ) #align first_order.language.Theory.is_satisfiable_of_is_satisfiable_on_Theory FirstOrder.Language.Theory.isSatisfiable_of_isSatisfiable_onTheory theorem isSatisfiable_onTheory_iff {L' : Language.{w, w'}} {φ : L →ᴸ L'} (h : φ.Injective) : (φ.onTheory T).IsSatisfiable ↔ T.IsSatisfiable := by classical refine ⟨isSatisfiable_of_isSatisfiable_onTheory φ, fun h' => ?_⟩ haveI : Inhabited h'.some := Classical.inhabited_of_nonempty' exact Model.isSatisfiable (h'.some.defaultExpansion h) #align first_order.language.Theory.is_satisfiable_on_Theory_iff FirstOrder.Language.Theory.isSatisfiable_onTheory_iff theorem IsSatisfiable.isFinitelySatisfiable (h : T.IsSatisfiable) : T.IsFinitelySatisfiable := fun _ => h.mono #align first_order.language.Theory.is_satisfiable.is_finitely_satisfiable FirstOrder.Language.Theory.IsSatisfiable.isFinitelySatisfiable /-- The **Compactness Theorem of first-order logic**: A theory is satisfiable if and only if it is finitely satisfiable. -/ theorem isSatisfiable_iff_isFinitelySatisfiable {T : L.Theory} : T.IsSatisfiable ↔ T.IsFinitelySatisfiable := ⟨Theory.IsSatisfiable.isFinitelySatisfiable, fun h => by classical set M : Finset T → Type max u v := fun T0 : Finset T => (h (T0.map (Function.Embedding.subtype fun x => x ∈ T)) T0.map_subtype_subset).some.Carrier let M' := Filter.Product (Ultrafilter.of (Filter.atTop : Filter (Finset T))) M have h' : M' ⊨ T := by refine ⟨fun φ hφ => ?_⟩ rw [Ultraproduct.sentence_realize] refine Filter.Eventually.filter_mono (Ultrafilter.of_le _) (Filter.eventually_atTop.2 ⟨{⟨φ, hφ⟩}, fun s h' => Theory.realize_sentence_of_mem (s.map (Function.Embedding.subtype fun x => x ∈ T)) ?_⟩) simp only [Finset.coe_map, Function.Embedding.coe_subtype, Set.mem_image, Finset.mem_coe, Subtype.exists, Subtype.coe_mk, exists_and_right, exists_eq_right] exact ⟨hφ, h' (Finset.mem_singleton_self _)⟩ exact ⟨ModelType.of T M'⟩⟩ #align first_order.language.Theory.is_satisfiable_iff_is_finitely_satisfiable FirstOrder.Language.Theory.isSatisfiable_iff_isFinitelySatisfiable theorem isSatisfiable_directed_union_iff {ι : Type*} [Nonempty ι] {T : ι → L.Theory} (h : Directed (· ⊆ ·) T) : Theory.IsSatisfiable (⋃ i, T i) ↔ ∀ i, (T i).IsSatisfiable := by refine ⟨fun h' i => h'.mono (Set.subset_iUnion _ _), fun h' => ?_⟩ rw [isSatisfiable_iff_isFinitelySatisfiable, IsFinitelySatisfiable] intro T0 hT0 obtain ⟨i, hi⟩ := h.exists_mem_subset_of_finset_subset_biUnion hT0 exact (h' i).mono hi #align first_order.language.Theory.is_satisfiable_directed_union_iff FirstOrder.Language.Theory.isSatisfiable_directed_union_iff theorem isSatisfiable_union_distinctConstantsTheory_of_card_le (T : L.Theory) (s : Set α) (M : Type w') [Nonempty M] [L.Structure M] [M ⊨ T] (h : Cardinal.lift.{w'} #s ≤ Cardinal.lift.{w} #M) : ((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by haveI : Inhabited M := Classical.inhabited_of_nonempty inferInstance rw [Cardinal.lift_mk_le'] at h letI : (constantsOn α).Structure M := constantsOn.structure (Function.extend (↑) h.some default) have : M ⊨ (L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s := by refine ((LHom.onTheory_model _ _).2 inferInstance).union ?_ rw [model_distinctConstantsTheory] refine fun a as b bs ab => ?_ rw [← Subtype.coe_mk a as, ← Subtype.coe_mk b bs, ← Subtype.ext_iff] exact h.some.injective ((Subtype.coe_injective.extend_apply h.some default ⟨a, as⟩).symm.trans (ab.trans (Subtype.coe_injective.extend_apply h.some default ⟨b, bs⟩))) exact Model.isSatisfiable M #align first_order.language.Theory.is_satisfiable_union_distinct_constants_theory_of_card_le FirstOrder.Language.Theory.isSatisfiable_union_distinctConstantsTheory_of_card_le theorem isSatisfiable_union_distinctConstantsTheory_of_infinite (T : L.Theory) (s : Set α) (M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] : ((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by classical rw [distinctConstantsTheory_eq_iUnion, Set.union_iUnion, isSatisfiable_directed_union_iff] · exact fun t => isSatisfiable_union_distinctConstantsTheory_of_card_le T _ M ((lift_le_aleph0.2 (finset_card_lt_aleph0 _).le).trans (aleph0_le_lift.2 (aleph0_le_mk M))) · apply Monotone.directed_le refine monotone_const.union (monotone_distinctConstantsTheory.comp ?_) simp only [Finset.coe_map, Function.Embedding.coe_subtype] exact Monotone.comp (g := Set.image ((↑) : s → α)) (f := ((↑) : Finset s → Set s)) Set.monotone_image fun _ _ => Finset.coe_subset.2 #align first_order.language.Theory.is_satisfiable_union_distinct_constants_theory_of_infinite FirstOrder.Language.Theory.isSatisfiable_union_distinctConstantsTheory_of_infinite /-- Any theory with an infinite model has arbitrarily large models. -/ theorem exists_large_model_of_infinite_model (T : L.Theory) (κ : Cardinal.{w}) (M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] : ∃ N : ModelType.{_, _, max u v w} T, Cardinal.lift.{max u v w} κ ≤ #N := by obtain ⟨N⟩ := isSatisfiable_union_distinctConstantsTheory_of_infinite T (Set.univ : Set κ.out) M refine ⟨(N.is_model.mono Set.subset_union_left).bundled.reduct _, ?_⟩ haveI : N ⊨ distinctConstantsTheory _ _ := N.is_model.mono Set.subset_union_right rw [ModelType.reduct_Carrier, coe_of] refine _root_.trans (lift_le.2 (le_of_eq (Cardinal.mk_out κ).symm)) ?_ rw [← mk_univ] refine (card_le_of_model_distinctConstantsTheory L Set.univ N).trans (lift_le.{max u v w}.1 ?_) rw [lift_lift] #align first_order.language.Theory.exists_large_model_of_infinite_model FirstOrder.Language.Theory.exists_large_model_of_infinite_model theorem isSatisfiable_iUnion_iff_isSatisfiable_iUnion_finset {ι : Type*} (T : ι → L.Theory) : IsSatisfiable (⋃ i, T i) ↔ ∀ s : Finset ι, IsSatisfiable (⋃ i ∈ s, T i) := by classical refine ⟨fun h s => h.mono (Set.iUnion_mono fun _ => Set.iUnion_subset_iff.2 fun _ => refl _), fun h => ?_⟩ rw [isSatisfiable_iff_isFinitelySatisfiable] intro s hs rw [Set.iUnion_eq_iUnion_finset] at hs obtain ⟨t, ht⟩ := Directed.exists_mem_subset_of_finset_subset_biUnion (by exact Monotone.directed_le fun t1 t2 (h : ∀ ⦃x⦄, x ∈ t1 → x ∈ t2) => Set.iUnion_mono fun _ => Set.iUnion_mono' fun h1 => ⟨h h1, refl _⟩) hs exact (h t).mono ht #align first_order.language.Theory.is_satisfiable_Union_iff_is_satisfiable_Union_finset FirstOrder.Language.Theory.isSatisfiable_iUnion_iff_isSatisfiable_iUnion_finset end Theory variable (L) /-- A version of The Downward Löwenheim–Skolem theorem where the structure `N` elementarily embeds into `M`, but is not by type a substructure of `M`, and thus can be chosen to belong to the universe of the cardinal `κ`. -/ theorem exists_elementaryEmbedding_card_eq_of_le (M : Type w') [L.Structure M] [Nonempty M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (h3 : lift.{w'} κ ≤ Cardinal.lift.{w} #M) : ∃ N : Bundled L.Structure, Nonempty (N ↪ₑ[L] M) ∧ #N = κ := by obtain ⟨S, _, hS⟩ := exists_elementarySubstructure_card_eq L ∅ κ h1 (by simp) h2 h3 have : Small.{w} S := by rw [← lift_inj.{_, w + 1}, lift_lift, lift_lift] at hS exact small_iff_lift_mk_lt_univ.2 (lt_of_eq_of_lt hS κ.lift_lt_univ') refine ⟨(equivShrink S).bundledInduced L, ⟨S.subtype.comp (Equiv.bundledInducedEquiv L _).symm.toElementaryEmbedding⟩, lift_inj.1 (_root_.trans ?_ hS)⟩ simp only [Equiv.bundledInduced_α, lift_mk_shrink'] #align first_order.language.exists_elementary_embedding_card_eq_of_le FirstOrder.Language.exists_elementaryEmbedding_card_eq_of_le section -- Porting note: This instance interrupts synthesizing instances. attribute [-instance] FirstOrder.Language.withConstants_expansion /-- The **Upward Löwenheim–Skolem Theorem**: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. -/ theorem exists_elementaryEmbedding_card_eq_of_ge (M : Type w') [L.Structure M] [iM : Infinite M] (κ : Cardinal.{w}) (h1 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (h2 : Cardinal.lift.{w} #M ≤ Cardinal.lift.{w'} κ) : ∃ N : Bundled L.Structure, Nonempty (M ↪ₑ[L] N) ∧ #N = κ := by obtain ⟨N0, hN0⟩ := (L.elementaryDiagram M).exists_large_model_of_infinite_model κ M rw [← lift_le.{max u v}, lift_lift, lift_lift] at h2 obtain ⟨N, ⟨NN0⟩, hN⟩ := exists_elementaryEmbedding_card_eq_of_le (L[[M]]) N0 κ (aleph0_le_lift.1 ((aleph0_le_lift.2 (aleph0_le_mk M)).trans h2)) (by simp only [card_withConstants, lift_add, lift_lift] rw [add_comm, add_eq_max (aleph0_le_lift.2 (infinite_iff.1 iM)), max_le_iff] rw [← lift_le.{w'}, lift_lift, lift_lift] at h1 exact ⟨h2, h1⟩) (hN0.trans (by rw [← lift_umax', lift_id])) letI := (lhomWithConstants L M).reduct N haveI h : N ⊨ L.elementaryDiagram M := (NN0.theory_model_iff (L.elementaryDiagram M)).2 inferInstance refine ⟨Bundled.of N, ⟨?_⟩, hN⟩ apply ElementaryEmbedding.ofModelsElementaryDiagram L M N #align first_order.language.exists_elementary_embedding_card_eq_of_ge FirstOrder.Language.exists_elementaryEmbedding_card_eq_of_ge end /-- The Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then there is an elementary embedding in the appropriate direction between then `M` and a structure of cardinality `κ`. -/ theorem exists_elementaryEmbedding_card_eq (M : Type w') [L.Structure M] [iM : Infinite M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : Bundled L.Structure, (Nonempty (N ↪ₑ[L] M) ∨ Nonempty (M ↪ₑ[L] N)) ∧ #N = κ := by cases le_or_gt (lift.{w'} κ) (Cardinal.lift.{w} #M) with | inl h => obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_le L M κ h1 h2 h exact ⟨N, Or.inl hN1, hN2⟩ | inr h => obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_ge L M κ h2 (le_of_lt h) exact ⟨N, Or.inr hN1, hN2⟩ #align first_order.language.exists_elementary_embedding_card_eq FirstOrder.Language.exists_elementaryEmbedding_card_eq /-- A consequence of the Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then there is a structure of cardinality `κ` elementarily equivalent to `M`. -/ theorem exists_elementarilyEquivalent_card_eq (M : Type w') [L.Structure M] [Infinite M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : CategoryTheory.Bundled L.Structure, (M ≅[L] N) ∧ #N = κ := by obtain ⟨N, NM | MN, hNκ⟩ := exists_elementaryEmbedding_card_eq L M κ h1 h2 · exact ⟨N, NM.some.elementarilyEquivalent.symm, hNκ⟩ · exact ⟨N, MN.some.elementarilyEquivalent, hNκ⟩ #align first_order.language.exists_elementarily_equivalent_card_eq FirstOrder.Language.exists_elementarilyEquivalent_card_eq variable {L} namespace Theory theorem exists_model_card_eq (h : ∃ M : ModelType.{u, v, max u v} T, Infinite M) (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : ModelType.{u, v, w} T, #N = κ := by cases h with | intro M MI => haveI := MI obtain ⟨N, hN, rfl⟩ := exists_elementarilyEquivalent_card_eq L M κ h1 h2 haveI : Nonempty N := hN.nonempty exact ⟨hN.theory_model.bundled, rfl⟩ #align first_order.language.Theory.exists_model_card_eq FirstOrder.Language.Theory.exists_model_card_eq variable (T) /-- A theory models a (bounded) formula when any of its nonempty models realizes that formula on all inputs. -/ def ModelsBoundedFormula (φ : L.BoundedFormula α n) : Prop := ∀ (M : ModelType.{u, v, max u v} T) (v : α → M) (xs : Fin n → M), φ.Realize v xs #align first_order.language.Theory.models_bounded_formula FirstOrder.Language.Theory.ModelsBoundedFormula -- Porting note: In Lean3 it was `⊨` but ambiguous. @[inherit_doc FirstOrder.Language.Theory.ModelsBoundedFormula] infixl:51 " ⊨ᵇ " => ModelsBoundedFormula -- input using \|= or \vDash, but not using \models variable {T} theorem models_formula_iff {φ : L.Formula α} : T ⊨ᵇ φ ↔ ∀ (M : ModelType.{u, v, max u v} T) (v : α → M), φ.Realize v := forall_congr' fun _ => forall_congr' fun _ => Unique.forall_iff #align first_order.language.Theory.models_formula_iff FirstOrder.Language.Theory.models_formula_iff theorem models_sentence_iff {φ : L.Sentence} : T ⊨ᵇ φ ↔ ∀ M : ModelType.{u, v, max u v} T, M ⊨ φ := models_formula_iff.trans (forall_congr' fun _ => Unique.forall_iff) #align first_order.language.Theory.models_sentence_iff FirstOrder.Language.Theory.models_sentence_iff theorem models_sentence_of_mem {φ : L.Sentence} (h : φ ∈ T) : T ⊨ᵇ φ := models_sentence_iff.2 fun _ => realize_sentence_of_mem T h #align first_order.language.Theory.models_sentence_of_mem FirstOrder.Language.Theory.models_sentence_of_mem theorem models_iff_not_satisfiable (φ : L.Sentence) : T ⊨ᵇ φ ↔ ¬IsSatisfiable (T ∪ {φ.not}) := by rw [models_sentence_iff, IsSatisfiable] refine ⟨fun h1 h2 => (Sentence.realize_not _).1 (realize_sentence_of_mem (T ∪ {Formula.not φ}) (Set.subset_union_right (Set.mem_singleton _))) (h1 (h2.some.subtheoryModel Set.subset_union_left)), fun h M => ?_⟩ contrapose! h rw [← Sentence.realize_not] at h refine ⟨{ Carrier := M is_model := ⟨fun ψ hψ => hψ.elim (realize_sentence_of_mem _) fun h' => ?_⟩ }⟩ rw [Set.mem_singleton_iff.1 h'] exact h #align first_order.language.Theory.models_iff_not_satisfiable FirstOrder.Language.Theory.models_iff_not_satisfiable theorem ModelsBoundedFormula.realize_sentence {φ : L.Sentence} (h : T ⊨ᵇ φ) (M : Type*) [L.Structure M] [M ⊨ T] [Nonempty M] : M ⊨ φ := by rw [models_iff_not_satisfiable] at h contrapose! h have : M ⊨ T ∪ {Formula.not φ} := by simp only [Set.union_singleton, model_iff, Set.mem_insert_iff, forall_eq_or_imp, Sentence.realize_not] rw [← model_iff] exact ⟨h, inferInstance⟩ exact Model.isSatisfiable M #align first_order.language.Theory.models_bounded_formula.realize_sentence FirstOrder.Language.Theory.ModelsBoundedFormula.realize_sentence
Mathlib/ModelTheory/Satisfiability.lean
355
362
theorem models_of_models_theory {T' : L.Theory} (h : ∀ φ : L.Sentence, φ ∈ T' → T ⊨ᵇ φ) {φ : L.Formula α} (hφ : T' ⊨ᵇ φ) : T ⊨ᵇ φ := by
simp only [models_sentence_iff] at h intro M have hM : M ⊨ T' := T'.model_iff.2 (fun ψ hψ => h ψ hψ M) let M' : ModelType T' := ⟨M⟩ exact hφ M'
/- Copyright (c) 2024 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Matroid.Restrict /-! # Some constructions of matroids This file defines some very elementary examples of matroids, namely those with at most one base. ## Main definitions * `emptyOn α` is the matroid on `α` with empty ground set. For `E : Set α`, ... * `loopyOn E` is the matroid on `E` whose elements are all loops, or equivalently in which `∅` is the only base. * `freeOn E` is the 'free matroid' whose ground set `E` is the only base. * For `I ⊆ E`, `uniqueBaseOn I E` is the matroid with ground set `E` in which `I` is the only base. ## Implementation details To avoid the tedious process of certifying the matroid axioms for each of these easy examples, we bootstrap the definitions starting with `emptyOn α` (which `simp` can prove is a matroid) and then construct the other examples using duality and restriction. -/ variable {α : Type*} {M : Matroid α} {E B I X R J : Set α} namespace Matroid open Set section EmptyOn /-- The `Matroid α` with empty ground set. -/ def emptyOn (α : Type*) : Matroid α where E := ∅ Base := (· = ∅) Indep := (· = ∅) indep_iff' := by simp [subset_empty_iff] exists_base := ⟨∅, rfl⟩ base_exchange := by rintro _ _ rfl; simp maximality := by rintro _ _ _ rfl -; exact ⟨∅, by simp [mem_maximals_iff]⟩ subset_ground := by simp @[simp] theorem emptyOn_ground : (emptyOn α).E = ∅ := rfl @[simp] theorem emptyOn_base_iff : (emptyOn α).Base B ↔ B = ∅ := Iff.rfl @[simp] theorem emptyOn_indep_iff : (emptyOn α).Indep I ↔ I = ∅ := Iff.rfl theorem ground_eq_empty_iff : (M.E = ∅) ↔ M = emptyOn α := by simp only [emptyOn, eq_iff_indep_iff_indep_forall, iff_self_and] exact fun h ↦ by simp [h, subset_empty_iff] @[simp] theorem emptyOn_dual_eq : (emptyOn α)✶ = emptyOn α := by rw [← ground_eq_empty_iff]; rfl @[simp] theorem restrict_empty (M : Matroid α) : M ↾ (∅ : Set α) = emptyOn α := by simp [← ground_eq_empty_iff] theorem eq_emptyOn_or_nonempty (M : Matroid α) : M = emptyOn α ∨ Matroid.Nonempty M := by rw [← ground_eq_empty_iff] exact M.E.eq_empty_or_nonempty.elim Or.inl (fun h ↦ Or.inr ⟨h⟩) theorem eq_emptyOn [IsEmpty α] (M : Matroid α) : M = emptyOn α := by rw [← ground_eq_empty_iff] exact M.E.eq_empty_of_isEmpty instance finite_emptyOn (α : Type*) : (emptyOn α).Finite := ⟨finite_empty⟩ end EmptyOn section LoopyOn /-- The `Matroid α` with ground set `E` whose only base is `∅` -/ def loopyOn (E : Set α) : Matroid α := emptyOn α ↾ E @[simp] theorem loopyOn_ground (E : Set α) : (loopyOn E).E = E := rfl @[simp] theorem loopyOn_empty (α : Type*) : loopyOn (∅ : Set α) = emptyOn α := by rw [← ground_eq_empty_iff, loopyOn_ground] @[simp] theorem loopyOn_indep_iff : (loopyOn E).Indep I ↔ I = ∅ := by simp only [loopyOn, restrict_indep_iff, emptyOn_indep_iff, and_iff_left_iff_imp] rintro rfl; apply empty_subset theorem eq_loopyOn_iff : M = loopyOn E ↔ M.E = E ∧ ∀ X ⊆ M.E, M.Indep X → X = ∅ := by simp only [eq_iff_indep_iff_indep_forall, loopyOn_ground, loopyOn_indep_iff, and_congr_right_iff] rintro rfl refine ⟨fun h I hI ↦ (h I hI).1, fun h I hIE ↦ ⟨h I hIE, by rintro rfl; simp⟩⟩ @[simp] theorem loopyOn_base_iff : (loopyOn E).Base B ↔ B = ∅ := by simp only [base_iff_maximal_indep, loopyOn_indep_iff, forall_eq, and_iff_left_iff_imp] exact fun h _ ↦ h @[simp] theorem loopyOn_basis_iff : (loopyOn E).Basis I X ↔ I = ∅ ∧ X ⊆ E := ⟨fun h ↦ ⟨loopyOn_indep_iff.mp h.indep, h.subset_ground⟩, by rintro ⟨rfl, hX⟩; rw [basis_iff]; simp⟩ instance : FiniteRk (loopyOn E) := ⟨⟨∅, loopyOn_base_iff.2 rfl, finite_empty⟩⟩ theorem Finite.loopyOn_finite (hE : E.Finite) : Matroid.Finite (loopyOn E) := ⟨hE⟩ @[simp] theorem loopyOn_restrict (E R : Set α) : (loopyOn E) ↾ R = loopyOn R := by refine eq_of_indep_iff_indep_forall rfl ?_ simp only [restrict_ground_eq, restrict_indep_iff, loopyOn_indep_iff, and_iff_left_iff_imp] exact fun _ h _ ↦ h theorem empty_base_iff : M.Base ∅ ↔ M = loopyOn M.E := by simp only [base_iff_maximal_indep, empty_indep, empty_subset, eq_comm (a := ∅), true_implies, true_and, eq_iff_indep_iff_indep_forall, loopyOn_ground, loopyOn_indep_iff] exact ⟨fun h I _ ↦ ⟨h I, by rintro rfl; simp⟩, fun h I hI ↦ (h I hI.subset_ground).1 hI⟩ theorem eq_loopyOn_or_rkPos (M : Matroid α) : M = loopyOn M.E ∨ RkPos M := by rw [← empty_base_iff, rkPos_iff_empty_not_base]; apply em theorem not_rkPos_iff : ¬RkPos M ↔ M = loopyOn M.E := by rw [rkPos_iff_empty_not_base, not_iff_comm, empty_base_iff] end LoopyOn section FreeOn /-- The `Matroid α` with ground set `E` whose only base is `E`. -/ def freeOn (E : Set α) : Matroid α := (loopyOn E)✶ @[simp] theorem freeOn_ground : (freeOn E).E = E := rfl @[simp] theorem freeOn_dual_eq : (freeOn E)✶ = loopyOn E := by rw [freeOn, dual_dual] @[simp] theorem loopyOn_dual_eq : (loopyOn E)✶ = freeOn E := rfl @[simp] theorem freeOn_empty (α : Type*) : freeOn (∅ : Set α) = emptyOn α := by simp [freeOn] @[simp] theorem freeOn_base_iff : (freeOn E).Base B ↔ B = E := by simp only [freeOn, loopyOn_ground, dual_base_iff', loopyOn_base_iff, diff_eq_empty, ← subset_antisymm_iff, eq_comm (a := E)] @[simp] theorem freeOn_indep_iff : (freeOn E).Indep I ↔ I ⊆ E := by simp [indep_iff] theorem freeOn_indep (hIE : I ⊆ E) : (freeOn E).Indep I := freeOn_indep_iff.2 hIE @[simp] theorem freeOn_basis_iff : (freeOn E).Basis I X ↔ I = X ∧ X ⊆ E := by use fun h ↦ ⟨(freeOn_indep h.subset_ground).eq_of_basis h ,h.subset_ground⟩ rintro ⟨rfl, hIE⟩ exact (freeOn_indep hIE).basis_self @[simp] theorem freeOn_basis'_iff : (freeOn E).Basis' I X ↔ I = X ∩ E := by rw [basis'_iff_basis_inter_ground, freeOn_basis_iff, freeOn_ground, and_iff_left inter_subset_right] theorem eq_freeOn_iff : M = freeOn E ↔ M.E = E ∧ M.Indep E := by refine ⟨?_, fun h ↦ ?_⟩ · rintro rfl; simp [Subset.rfl] simp only [eq_iff_indep_iff_indep_forall, freeOn_ground, freeOn_indep_iff, h.1, true_and] exact fun I hIX ↦ iff_of_true (h.2.subset hIX) hIX theorem ground_indep_iff_eq_freeOn : M.Indep M.E ↔ M = freeOn M.E := by simp [eq_freeOn_iff] theorem freeOn_restrict (h : R ⊆ E) : (freeOn E) ↾ R = freeOn R := by simp [h, eq_freeOn_iff, Subset.rfl] theorem restrict_eq_freeOn_iff : M ↾ I = freeOn I ↔ M.Indep I := by rw [eq_freeOn_iff, and_iff_right M.restrict_ground_eq, restrict_indep_iff, and_iff_left Subset.rfl] theorem Indep.restrict_eq_freeOn (hI : M.Indep I) : M ↾ I = freeOn I := by rwa [restrict_eq_freeOn_iff] end FreeOn section uniqueBaseOn /-- The matroid on `E` whose unique base is the subset `I` of `E`. Intended for use when `I ⊆ E`; if this not not the case, then the base is `I ∩ E`. -/ def uniqueBaseOn (I E : Set α) : Matroid α := freeOn I ↾ E @[simp] theorem uniqueBaseOn_ground : (uniqueBaseOn I E).E = E := rfl theorem uniqueBaseOn_base_iff (hIE : I ⊆ E) : (uniqueBaseOn I E).Base B ↔ B = I := by rw [uniqueBaseOn, base_restrict_iff', freeOn_basis'_iff, inter_eq_self_of_subset_right hIE] theorem uniqueBaseOn_inter_ground_eq (I E : Set α) : uniqueBaseOn (I ∩ E) E = uniqueBaseOn I E := by simp only [uniqueBaseOn, restrict_eq_restrict_iff, freeOn_indep_iff, subset_inter_iff, iff_self_and] tauto @[simp] theorem uniqueBaseOn_indep_iff' : (uniqueBaseOn I E).Indep J ↔ J ⊆ I ∩ E := by rw [uniqueBaseOn, restrict_indep_iff, freeOn_indep_iff, subset_inter_iff] theorem uniqueBaseOn_indep_iff (hIE : I ⊆ E) : (uniqueBaseOn I E).Indep J ↔ J ⊆ I := by rw [uniqueBaseOn, restrict_indep_iff, freeOn_indep_iff, and_iff_left_iff_imp] exact fun h ↦ h.trans hIE theorem uniqueBaseOn_basis_iff (hI : I ⊆ E) (hX : X ⊆ E) : (uniqueBaseOn I E).Basis J X ↔ J = X ∩ I := by rw [basis_iff_mem_maximals] simp_rw [uniqueBaseOn_indep_iff', ← subset_inter_iff, ← le_eq_subset, Iic_def, maximals_Iic, mem_singleton_iff, inter_eq_self_of_subset_left hI, inter_comm I] theorem uniqueBaseOn_inter_basis (hI : I ⊆ E) (hX : X ⊆ E) : (uniqueBaseOn I E).Basis (X ∩ I) X := by rw [uniqueBaseOn_basis_iff hI hX] @[simp] theorem uniqueBaseOn_dual_eq (I E : Set α) : (uniqueBaseOn I E)✶ = uniqueBaseOn (E \ I) E := by rw [← uniqueBaseOn_inter_ground_eq] refine eq_of_base_iff_base_forall rfl (fun B (hB : B ⊆ E) ↦ ?_) rw [dual_base_iff, uniqueBaseOn_base_iff inter_subset_right, uniqueBaseOn_base_iff diff_subset, uniqueBaseOn_ground] exact ⟨fun h ↦ by rw [← diff_diff_cancel_left hB, h, diff_inter_self_eq_diff], fun h ↦ by rw [h, inter_comm I]; simp⟩ @[simp] theorem uniqueBaseOn_self (I : Set α) : uniqueBaseOn I I = freeOn I := by rw [uniqueBaseOn, freeOn_restrict rfl.subset] @[simp] theorem uniqueBaseOn_empty (I : Set α) : uniqueBaseOn ∅ I = loopyOn I := by rw [← dual_inj, uniqueBaseOn_dual_eq, diff_empty, uniqueBaseOn_self, loopyOn_dual_eq]
Mathlib/Data/Matroid/Constructions.lean
236
240
theorem uniqueBaseOn_restrict' (I E R : Set α) : (uniqueBaseOn I E) ↾ R = uniqueBaseOn (I ∩ R ∩ E) R := by
simp_rw [eq_iff_indep_iff_indep_forall, restrict_ground_eq, uniqueBaseOn_ground, true_and, restrict_indep_iff, uniqueBaseOn_indep_iff', subset_inter_iff] tauto
/- 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] theorem type_out (o : Ordinal) : Ordinal.type o.out.r = o := by rw [Ordinal.type, WellOrder.eta, Quotient.out_eq] #align ordinal.type_out Ordinal.type_out theorem type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] : type r = type s ↔ Nonempty (r ≃r s) := Quotient.eq' #align ordinal.type_eq Ordinal.type_eq theorem _root_.RelIso.ordinal_type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (h : r ≃r s) : type r = type s := type_eq.2 ⟨h⟩ #align rel_iso.ordinal_type_eq RelIso.ordinal_type_eq @[simp] theorem type_lt (o : Ordinal) : type ((· < ·) : o.out.α → o.out.α → Prop) = o := (type_def' _).symm.trans <| Quotient.out_eq o #align ordinal.type_lt Ordinal.type_lt theorem type_eq_zero_of_empty (r) [IsWellOrder α r] [IsEmpty α] : type r = 0 := (RelIso.relIsoOfIsEmpty r _).ordinal_type_eq #align ordinal.type_eq_zero_of_empty Ordinal.type_eq_zero_of_empty @[simp] theorem type_eq_zero_iff_isEmpty [IsWellOrder α r] : type r = 0 ↔ IsEmpty α := ⟨fun h => let ⟨s⟩ := type_eq.1 h s.toEquiv.isEmpty, @type_eq_zero_of_empty α r _⟩ #align ordinal.type_eq_zero_iff_is_empty Ordinal.type_eq_zero_iff_isEmpty theorem type_ne_zero_iff_nonempty [IsWellOrder α r] : type r ≠ 0 ↔ Nonempty α := by simp #align ordinal.type_ne_zero_iff_nonempty Ordinal.type_ne_zero_iff_nonempty theorem type_ne_zero_of_nonempty (r) [IsWellOrder α r] [h : Nonempty α] : type r ≠ 0 := type_ne_zero_iff_nonempty.2 h #align ordinal.type_ne_zero_of_nonempty Ordinal.type_ne_zero_of_nonempty theorem type_pEmpty : type (@EmptyRelation PEmpty) = 0 := rfl #align ordinal.type_pempty Ordinal.type_pEmpty theorem type_empty : type (@EmptyRelation Empty) = 0 := type_eq_zero_of_empty _ #align ordinal.type_empty Ordinal.type_empty theorem type_eq_one_of_unique (r) [IsWellOrder α r] [Unique α] : type r = 1 := (RelIso.relIsoOfUniqueOfIrrefl r _).ordinal_type_eq #align ordinal.type_eq_one_of_unique Ordinal.type_eq_one_of_unique @[simp] theorem type_eq_one_iff_unique [IsWellOrder α r] : type r = 1 ↔ Nonempty (Unique α) := ⟨fun h => let ⟨s⟩ := type_eq.1 h ⟨s.toEquiv.unique⟩, fun ⟨h⟩ => @type_eq_one_of_unique α r _ h⟩ #align ordinal.type_eq_one_iff_unique Ordinal.type_eq_one_iff_unique theorem type_pUnit : type (@EmptyRelation PUnit) = 1 := rfl #align ordinal.type_punit Ordinal.type_pUnit theorem type_unit : type (@EmptyRelation Unit) = 1 := rfl #align ordinal.type_unit Ordinal.type_unit @[simp] theorem out_empty_iff_eq_zero {o : Ordinal} : IsEmpty o.out.α ↔ o = 0 := by rw [← @type_eq_zero_iff_isEmpty o.out.α (· < ·), type_lt] #align ordinal.out_empty_iff_eq_zero Ordinal.out_empty_iff_eq_zero theorem eq_zero_of_out_empty (o : Ordinal) [h : IsEmpty o.out.α] : o = 0 := out_empty_iff_eq_zero.1 h #align ordinal.eq_zero_of_out_empty Ordinal.eq_zero_of_out_empty instance isEmpty_out_zero : IsEmpty (0 : Ordinal).out.α := out_empty_iff_eq_zero.2 rfl #align ordinal.is_empty_out_zero Ordinal.isEmpty_out_zero @[simp] theorem out_nonempty_iff_ne_zero {o : Ordinal} : Nonempty o.out.α ↔ o ≠ 0 := by rw [← @type_ne_zero_iff_nonempty o.out.α (· < ·), type_lt] #align ordinal.out_nonempty_iff_ne_zero Ordinal.out_nonempty_iff_ne_zero theorem ne_zero_of_out_nonempty (o : Ordinal) [h : Nonempty o.out.α] : o ≠ 0 := out_nonempty_iff_ne_zero.1 h #align ordinal.ne_zero_of_out_nonempty Ordinal.ne_zero_of_out_nonempty protected theorem one_ne_zero : (1 : Ordinal) ≠ 0 := type_ne_zero_of_nonempty _ #align ordinal.one_ne_zero Ordinal.one_ne_zero instance nontrivial : Nontrivial Ordinal.{u} := ⟨⟨1, 0, Ordinal.one_ne_zero⟩⟩ --@[simp] -- Porting note: not in simp nf, added aux lemma below theorem type_preimage {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) : type (f ⁻¹'o r) = type r := (RelIso.preimage f r).ordinal_type_eq #align ordinal.type_preimage Ordinal.type_preimage @[simp, nolint simpNF] -- `simpNF` incorrectly complains the LHS doesn't simplify. theorem type_preimage_aux {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) : @type _ (fun x y => r (f x) (f y)) (inferInstanceAs (IsWellOrder β (↑f ⁻¹'o r))) = type r := by convert (RelIso.preimage f r).ordinal_type_eq @[elab_as_elim] theorem inductionOn {C : Ordinal → Prop} (o : Ordinal) (H : ∀ (α r) [IsWellOrder α r], C (type r)) : C o := Quot.inductionOn o fun ⟨α, r, wo⟩ => @H α r wo #align ordinal.induction_on Ordinal.inductionOn /-! ### The order on ordinals -/ /-- For `Ordinal`: * less-equal is defined such that well orders `r` and `s` satisfy `type r ≤ type s` if there exists a function embedding `r` as an *initial* segment of `s`. * less-than is defined such that well orders `r` and `s` satisfy `type r < type s` if there exists a function embedding `r` as a *principal* segment of `s`. -/ instance partialOrder : PartialOrder Ordinal where le a b := Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≼i s)) fun _ _ _ _ ⟨f⟩ ⟨g⟩ => propext ⟨fun ⟨h⟩ => ⟨(InitialSeg.ofIso f.symm).trans <| h.trans (InitialSeg.ofIso g)⟩, fun ⟨h⟩ => ⟨(InitialSeg.ofIso f).trans <| h.trans (InitialSeg.ofIso g.symm)⟩⟩ lt a b := Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≺i s)) fun _ _ _ _ ⟨f⟩ ⟨g⟩ => propext ⟨fun ⟨h⟩ => ⟨PrincipalSeg.equivLT f.symm <| h.ltLe (InitialSeg.ofIso g)⟩, fun ⟨h⟩ => ⟨PrincipalSeg.equivLT f <| h.ltLe (InitialSeg.ofIso g.symm)⟩⟩ le_refl := Quot.ind fun ⟨_, _, _⟩ => ⟨InitialSeg.refl _⟩ le_trans a b c := Quotient.inductionOn₃ a b c fun _ _ _ ⟨f⟩ ⟨g⟩ => ⟨f.trans g⟩ lt_iff_le_not_le a b := Quotient.inductionOn₂ a b fun _ _ => ⟨fun ⟨f⟩ => ⟨⟨f⟩, fun ⟨g⟩ => (f.ltLe g).irrefl⟩, fun ⟨⟨f⟩, h⟩ => Sum.recOn f.ltOrEq (fun g => ⟨g⟩) fun g => (h ⟨InitialSeg.ofIso g.symm⟩).elim⟩ le_antisymm a b := Quotient.inductionOn₂ a b fun _ _ ⟨h₁⟩ ⟨h₂⟩ => Quot.sound ⟨InitialSeg.antisymm h₁ h₂⟩ theorem type_le_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ≼i s) := Iff.rfl #align ordinal.type_le_iff Ordinal.type_le_iff theorem type_le_iff' {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ↪r s) := ⟨fun ⟨f⟩ => ⟨f⟩, fun ⟨f⟩ => ⟨f.collapse⟩⟩ #align ordinal.type_le_iff' Ordinal.type_le_iff' theorem _root_.InitialSeg.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (h : r ≼i s) : type r ≤ type s := ⟨h⟩ #align initial_seg.ordinal_type_le InitialSeg.ordinal_type_le theorem _root_.RelEmbedding.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (h : r ↪r s) : type r ≤ type s := ⟨h.collapse⟩ #align rel_embedding.ordinal_type_le RelEmbedding.ordinal_type_le @[simp] theorem type_lt_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] : type r < type s ↔ Nonempty (r ≺i s) := Iff.rfl #align ordinal.type_lt_iff Ordinal.type_lt_iff theorem _root_.PrincipalSeg.ordinal_type_lt {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (h : r ≺i s) : type r < type s := ⟨h⟩ #align principal_seg.ordinal_type_lt PrincipalSeg.ordinal_type_lt @[simp] protected theorem zero_le (o : Ordinal) : 0 ≤ o := inductionOn o fun _ r _ => (InitialSeg.ofIsEmpty _ r).ordinal_type_le #align ordinal.zero_le Ordinal.zero_le instance orderBot : OrderBot Ordinal where bot := 0 bot_le := Ordinal.zero_le @[simp] theorem bot_eq_zero : (⊥ : Ordinal) = 0 := rfl #align ordinal.bot_eq_zero Ordinal.bot_eq_zero @[simp] protected theorem le_zero {o : Ordinal} : o ≤ 0 ↔ o = 0 := le_bot_iff #align ordinal.le_zero Ordinal.le_zero protected theorem pos_iff_ne_zero {o : Ordinal} : 0 < o ↔ o ≠ 0 := bot_lt_iff_ne_bot #align ordinal.pos_iff_ne_zero Ordinal.pos_iff_ne_zero protected theorem not_lt_zero (o : Ordinal) : ¬o < 0 := not_lt_bot #align ordinal.not_lt_zero Ordinal.not_lt_zero theorem eq_zero_or_pos : ∀ a : Ordinal, a = 0 ∨ 0 < a := eq_bot_or_bot_lt #align ordinal.eq_zero_or_pos Ordinal.eq_zero_or_pos instance zeroLEOneClass : ZeroLEOneClass Ordinal := ⟨Ordinal.zero_le _⟩ instance NeZero.one : NeZero (1 : Ordinal) := ⟨Ordinal.one_ne_zero⟩ #align ordinal.ne_zero.one Ordinal.NeZero.one /-- Given two ordinals `α ≤ β`, then `initialSegOut α β` is the initial segment embedding of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/ def initialSegOut {α β : Ordinal} (h : α ≤ β) : InitialSeg ((· < ·) : α.out.α → α.out.α → Prop) ((· < ·) : β.out.α → β.out.α → Prop) := by change α.out.r ≼i β.out.r rw [← Quotient.out_eq α, ← Quotient.out_eq β] at h; revert h cases Quotient.out α; cases Quotient.out β; exact Classical.choice #align ordinal.initial_seg_out Ordinal.initialSegOut /-- Given two ordinals `α < β`, then `principalSegOut α β` is the principal segment embedding of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/ def principalSegOut {α β : Ordinal} (h : α < β) : PrincipalSeg ((· < ·) : α.out.α → α.out.α → Prop) ((· < ·) : β.out.α → β.out.α → Prop) := by change α.out.r ≺i β.out.r rw [← Quotient.out_eq α, ← Quotient.out_eq β] at h; revert h cases Quotient.out α; cases Quotient.out β; exact Classical.choice #align ordinal.principal_seg_out Ordinal.principalSegOut theorem typein_lt_type (r : α → α → Prop) [IsWellOrder α r] (a : α) : typein r a < type r := ⟨PrincipalSeg.ofElement _ _⟩ #align ordinal.typein_lt_type Ordinal.typein_lt_type theorem typein_lt_self {o : Ordinal} (i : o.out.α) : @typein _ (· < ·) (isWellOrder_out_lt _) i < o := by simp_rw [← type_lt o] apply typein_lt_type #align ordinal.typein_lt_self Ordinal.typein_lt_self @[simp] theorem typein_top {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≺i s) : typein s f.top = type r := Eq.symm <| Quot.sound ⟨RelIso.ofSurjective (RelEmbedding.codRestrict _ f f.lt_top) fun ⟨a, h⟩ => by rcases f.down.1 h with ⟨b, rfl⟩; exact ⟨b, rfl⟩⟩ #align ordinal.typein_top Ordinal.typein_top @[simp] theorem typein_apply {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≼i s) (a : α) : Ordinal.typein s (f a) = Ordinal.typein r a := Eq.symm <| Quotient.sound ⟨RelIso.ofSurjective (RelEmbedding.codRestrict _ ((Subrel.relEmbedding _ _).trans f) fun ⟨x, h⟩ => by rw [RelEmbedding.trans_apply]; exact f.toRelEmbedding.map_rel_iff.2 h) fun ⟨y, h⟩ => by rcases f.init h with ⟨a, rfl⟩ exact ⟨⟨a, f.toRelEmbedding.map_rel_iff.1 h⟩, Subtype.eq <| RelEmbedding.trans_apply _ _ _⟩⟩ #align ordinal.typein_apply Ordinal.typein_apply @[simp] theorem typein_lt_typein (r : α → α → Prop) [IsWellOrder α r] {a b : α} : typein r a < typein r b ↔ r a b := ⟨fun ⟨f⟩ => by have : f.top.1 = a := by let f' := PrincipalSeg.ofElement r a let g' := f.trans (PrincipalSeg.ofElement r b) have : g'.top = f'.top := by rw [Subsingleton.elim f' g'] exact this rw [← this] exact f.top.2, fun h => ⟨PrincipalSeg.codRestrict _ (PrincipalSeg.ofElement r a) (fun x => @trans _ r _ _ _ _ x.2 h) h⟩⟩ #align ordinal.typein_lt_typein Ordinal.typein_lt_typein theorem typein_surj (r : α → α → Prop) [IsWellOrder α r] {o} (h : o < type r) : ∃ a, typein r a = o := inductionOn o (fun _ _ _ ⟨f⟩ => ⟨f.top, typein_top _⟩) h #align ordinal.typein_surj Ordinal.typein_surj theorem typein_injective (r : α → α → Prop) [IsWellOrder α r] : Injective (typein r) := injective_of_increasing r (· < ·) (typein r) (typein_lt_typein r).2 #align ordinal.typein_injective Ordinal.typein_injective @[simp] theorem typein_inj (r : α → α → Prop) [IsWellOrder α r] {a b} : typein r a = typein r b ↔ a = b := (typein_injective r).eq_iff #align ordinal.typein_inj Ordinal.typein_inj /-- Principal segment version of the `typein` function, embedding a well order into ordinals as a principal segment. -/ def typein.principalSeg {α : Type u} (r : α → α → Prop) [IsWellOrder α r] : @PrincipalSeg α Ordinal.{u} r (· < ·) := ⟨⟨⟨typein r, typein_injective r⟩, typein_lt_typein r⟩, type r, fun _ ↦ ⟨typein_surj r, fun ⟨a, h⟩ ↦ h ▸ typein_lt_type r a⟩⟩ #align ordinal.typein.principal_seg Ordinal.typein.principalSeg @[simp] theorem typein.principalSeg_coe (r : α → α → Prop) [IsWellOrder α r] : (typein.principalSeg r : α → Ordinal) = typein r := rfl #align ordinal.typein.principal_seg_coe Ordinal.typein.principalSeg_coe /-! ### Enumerating elements in a well-order with ordinals. -/ /-- `enum r o h` is the `o`-th element of `α` ordered by `r`. That is, `enum` maps an initial segment of the ordinals, those less than the order type of `r`, to the elements of `α`. -/ def enum (r : α → α → Prop) [IsWellOrder α r] (o) (h : o < type r) : α := (typein.principalSeg r).subrelIso ⟨o, h⟩ @[simp] theorem typein_enum (r : α → α → Prop) [IsWellOrder α r] {o} (h : o < type r) : typein r (enum r o h) = o := (typein.principalSeg r).apply_subrelIso _ #align ordinal.typein_enum Ordinal.typein_enum theorem enum_type {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : s ≺i r) {h : type s < type r} : enum r (type s) h = f.top := (typein.principalSeg r).injective <| (typein_enum _ _).trans (typein_top _).symm #align ordinal.enum_type Ordinal.enum_type @[simp] theorem enum_typein (r : α → α → Prop) [IsWellOrder α r] (a : α) : enum r (typein r a) (typein_lt_type r a) = a := enum_type (PrincipalSeg.ofElement r a) #align ordinal.enum_typein Ordinal.enum_typein theorem enum_lt_enum {r : α → α → Prop} [IsWellOrder α r] {o₁ o₂ : Ordinal} (h₁ : o₁ < type r) (h₂ : o₂ < type r) : r (enum r o₁ h₁) (enum r o₂ h₂) ↔ o₁ < o₂ := by rw [← typein_lt_typein r, typein_enum, typein_enum] #align ordinal.enum_lt_enum Ordinal.enum_lt_enum theorem relIso_enum' {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≃r s) (o : Ordinal) : ∀ (hr : o < type r) (hs : o < type s), f (enum r o hr) = enum s o hs := by refine inductionOn o ?_; rintro γ t wo ⟨g⟩ ⟨h⟩ rw [enum_type g, enum_type (PrincipalSeg.ltEquiv g f)]; rfl #align ordinal.rel_iso_enum' Ordinal.relIso_enum' theorem relIso_enum {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≃r s) (o : Ordinal) (hr : o < type r) : f (enum r o hr) = enum s o (by convert hr using 1 apply Quotient.sound exact ⟨f.symm⟩) := relIso_enum' _ _ _ _ #align ordinal.rel_iso_enum Ordinal.relIso_enum theorem lt_wf : @WellFounded Ordinal (· < ·) := /- wellFounded_iff_wellFounded_subrel.mpr (·.induction_on fun ⟨_, r, wo⟩ ↦ RelHomClass.wellFounded (typein.principalSeg r).subrelIso wo.wf) -/ ⟨fun a => inductionOn a fun α r wo => suffices ∀ a, Acc (· < ·) (typein r a) from ⟨_, fun o h => let ⟨a, e⟩ := typein_surj r h e ▸ this a⟩ fun a => Acc.recOn (wo.wf.apply a) fun x _ IH => ⟨_, fun o h => by rcases typein_surj r (lt_trans h (typein_lt_type r _)) with ⟨b, rfl⟩ exact IH _ ((typein_lt_typein r).1 h)⟩⟩ #align ordinal.lt_wf Ordinal.lt_wf instance wellFoundedRelation : WellFoundedRelation Ordinal := ⟨(· < ·), lt_wf⟩ /-- Reformulation of well founded induction on ordinals as a lemma that works with the `induction` tactic, as in `induction i using Ordinal.induction with | h i IH => ?_`. -/ theorem induction {p : Ordinal.{u} → Prop} (i : Ordinal.{u}) (h : ∀ j, (∀ k, k < j → p k) → p j) : p i := lt_wf.induction i h #align ordinal.induction Ordinal.induction /-! ### Cardinality of ordinals -/ /-- The cardinal of an ordinal is the cardinality of any type on which a relation with that order type is defined. -/ def card : Ordinal → Cardinal := Quotient.map WellOrder.α fun _ _ ⟨e⟩ => ⟨e.toEquiv⟩ #align ordinal.card Ordinal.card @[simp] theorem card_type (r : α → α → Prop) [IsWellOrder α r] : card (type r) = #α := rfl #align ordinal.card_type Ordinal.card_type -- Porting note: nolint, simpNF linter falsely claims the lemma never applies @[simp, nolint simpNF] theorem card_typein {r : α → α → Prop} [IsWellOrder α r] (x : α) : #{ y // r y x } = (typein r x).card := rfl #align ordinal.card_typein Ordinal.card_typein theorem card_le_card {o₁ o₂ : Ordinal} : o₁ ≤ o₂ → card o₁ ≤ card o₂ := inductionOn o₁ fun _ _ _ => inductionOn o₂ fun _ _ _ ⟨⟨⟨f, _⟩, _⟩⟩ => ⟨f⟩ #align ordinal.card_le_card Ordinal.card_le_card @[simp] theorem card_zero : card 0 = 0 := mk_eq_zero _ #align ordinal.card_zero Ordinal.card_zero @[simp] theorem card_one : card 1 = 1 := mk_eq_one _ #align ordinal.card_one Ordinal.card_one /-! ### Lifting ordinals to a higher universe -/ -- Porting note: Needed to add universe hint .{u} below /-- The universe lift operation for ordinals, which embeds `Ordinal.{u}` as a proper initial segment of `Ordinal.{v}` for `v > u`. For the initial segment version, see `lift.initialSeg`. -/ @[pp_with_univ] def lift (o : Ordinal.{v}) : Ordinal.{max v u} := Quotient.liftOn o (fun w => type <| ULift.down.{u} ⁻¹'o w.r) fun ⟨_, r, _⟩ ⟨_, s, _⟩ ⟨f⟩ => Quot.sound ⟨(RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm⟩ #align ordinal.lift Ordinal.lift -- Porting note: Needed to add universe hints ULift.down.{v,u} below -- @[simp] -- Porting note: Not in simpnf, added aux lemma below theorem type_uLift (r : α → α → Prop) [IsWellOrder α r] : type (ULift.down.{v,u} ⁻¹'o r) = lift.{v} (type r) := by simp (config := { unfoldPartialApp := true }) rfl #align ordinal.type_ulift Ordinal.type_uLift -- Porting note: simpNF linter falsely claims that this never applies @[simp, nolint simpNF] theorem type_uLift_aux (r : α → α → Prop) [IsWellOrder α r] : @type.{max v u} _ (fun x y => r (ULift.down.{v,u} x) (ULift.down.{v,u} y)) (inferInstanceAs (IsWellOrder (ULift α) (ULift.down ⁻¹'o r))) = lift.{v} (type r) := rfl theorem _root_.RelIso.ordinal_lift_type_eq {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≃r s) : lift.{v} (type r) = lift.{u} (type s) := ((RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm).ordinal_type_eq #align rel_iso.ordinal_lift_type_eq RelIso.ordinal_lift_type_eq -- @[simp] theorem type_lift_preimage {α : Type u} {β : Type v} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) : lift.{u} (type (f ⁻¹'o r)) = lift.{v} (type r) := (RelIso.preimage f r).ordinal_lift_type_eq #align ordinal.type_lift_preimage Ordinal.type_lift_preimage @[simp, nolint simpNF] theorem type_lift_preimage_aux {α : Type u} {β : Type v} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) : lift.{u} (@type _ (fun x y => r (f x) (f y)) (inferInstanceAs (IsWellOrder β (f ⁻¹'o r)))) = lift.{v} (type r) := (RelIso.preimage f r).ordinal_lift_type_eq /-- `lift.{max u v, u}` equals `lift.{v, u}`. -/ -- @[simp] -- Porting note: simp lemma never applies, tested theorem lift_umax : lift.{max u v, u} = lift.{v, u} := funext fun a => inductionOn a fun _ r _ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift r).trans (RelIso.preimage Equiv.ulift r).symm⟩ #align ordinal.lift_umax Ordinal.lift_umax /-- `lift.{max v u, u}` equals `lift.{v, u}`. -/ -- @[simp] -- Porting note: simp lemma never applies, tested theorem lift_umax' : lift.{max v u, u} = lift.{v, u} := lift_umax #align ordinal.lift_umax' Ordinal.lift_umax' /-- An ordinal lifted to a lower or equal universe equals itself. -/ -- @[simp] -- Porting note: simp lemma never applies, tested theorem lift_id' (a : Ordinal) : lift a = a := inductionOn a fun _ r _ => Quotient.sound ⟨RelIso.preimage Equiv.ulift r⟩ #align ordinal.lift_id' Ordinal.lift_id' /-- An ordinal lifted to the same universe equals itself. -/ @[simp] theorem lift_id : ∀ a, lift.{u, u} a = a := lift_id'.{u, u} #align ordinal.lift_id Ordinal.lift_id /-- An ordinal lifted to the zero universe equals itself. -/ @[simp] theorem lift_uzero (a : Ordinal.{u}) : lift.{0} a = a := lift_id' a #align ordinal.lift_uzero Ordinal.lift_uzero @[simp] theorem lift_lift (a : Ordinal) : lift.{w} (lift.{v} a) = lift.{max v w} a := inductionOn a fun _ _ _ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans <| (RelIso.preimage Equiv.ulift _).trans (RelIso.preimage Equiv.ulift _).symm⟩ #align ordinal.lift_lift Ordinal.lift_lift theorem lift_type_le {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] : lift.{max v w} (type r) ≤ lift.{max u w} (type s) ↔ Nonempty (r ≼i s) := ⟨fun ⟨f⟩ => ⟨(InitialSeg.ofIso (RelIso.preimage Equiv.ulift r).symm).trans <| f.trans (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s))⟩, fun ⟨f⟩ => ⟨(InitialSeg.ofIso (RelIso.preimage Equiv.ulift r)).trans <| f.trans (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s).symm)⟩⟩ #align ordinal.lift_type_le Ordinal.lift_type_le theorem lift_type_eq {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] : lift.{max v w} (type r) = lift.{max u w} (type s) ↔ Nonempty (r ≃r s) := Quotient.eq'.trans ⟨fun ⟨f⟩ => ⟨(RelIso.preimage Equiv.ulift r).symm.trans <| f.trans (RelIso.preimage Equiv.ulift s)⟩, fun ⟨f⟩ => ⟨(RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm⟩⟩ #align ordinal.lift_type_eq Ordinal.lift_type_eq theorem lift_type_lt {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] : lift.{max v w} (type r) < lift.{max u w} (type s) ↔ Nonempty (r ≺i s) := by haveI := @RelEmbedding.isWellOrder _ _ (@Equiv.ulift.{max v w} α ⁻¹'o r) r (RelIso.preimage Equiv.ulift.{max v w} r) _ haveI := @RelEmbedding.isWellOrder _ _ (@Equiv.ulift.{max u w} β ⁻¹'o s) s (RelIso.preimage Equiv.ulift.{max u w} s) _ exact ⟨fun ⟨f⟩ => ⟨(f.equivLT (RelIso.preimage Equiv.ulift r).symm).ltLe (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s))⟩, fun ⟨f⟩ => ⟨(f.equivLT (RelIso.preimage Equiv.ulift r)).ltLe (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s).symm)⟩⟩ #align ordinal.lift_type_lt Ordinal.lift_type_lt @[simp] theorem lift_le {a b : Ordinal} : lift.{u,v} a ≤ lift.{u,v} b ↔ a ≤ b := inductionOn a fun α r _ => inductionOn b fun β s _ => by rw [← lift_umax] exact lift_type_le.{_,_,u} #align ordinal.lift_le Ordinal.lift_le @[simp] theorem lift_inj {a b : Ordinal} : lift.{u,v} a = lift.{u,v} b ↔ a = b := by simp only [le_antisymm_iff, lift_le] #align ordinal.lift_inj Ordinal.lift_inj @[simp] theorem lift_lt {a b : Ordinal} : lift.{u,v} a < lift.{u,v} b ↔ a < b := by simp only [lt_iff_le_not_le, lift_le] #align ordinal.lift_lt Ordinal.lift_lt @[simp] theorem lift_zero : lift 0 = 0 := type_eq_zero_of_empty _ #align ordinal.lift_zero Ordinal.lift_zero @[simp] theorem lift_one : lift 1 = 1 := type_eq_one_of_unique _ #align ordinal.lift_one Ordinal.lift_one @[simp] theorem lift_card (a) : Cardinal.lift.{u,v} (card a)= card (lift.{u,v} a) := inductionOn a fun _ _ _ => rfl #align ordinal.lift_card Ordinal.lift_card theorem lift_down' {a : Cardinal.{u}} {b : Ordinal.{max u v}} (h : card.{max u v} b ≤ Cardinal.lift.{v,u} a) : ∃ a', lift.{v,u} a' = b := let ⟨c, e⟩ := Cardinal.lift_down h Cardinal.inductionOn c (fun α => inductionOn b fun β s _ e' => by rw [card_type, ← Cardinal.lift_id'.{max u v, u} #β, ← Cardinal.lift_umax.{u, v}, lift_mk_eq.{u, max u v, max u v}] at e' cases' e' with f have g := RelIso.preimage f s haveI := (g : f ⁻¹'o s ↪r s).isWellOrder have := lift_type_eq.{u, max u v, max u v}.2 ⟨g⟩ rw [lift_id, lift_umax.{u, v}] at this exact ⟨_, this⟩) e #align ordinal.lift_down' Ordinal.lift_down' theorem lift_down {a : Ordinal.{u}} {b : Ordinal.{max u v}} (h : b ≤ lift.{v,u} a) : ∃ a', lift.{v,u} a' = b := @lift_down' (card a) _ (by rw [lift_card]; exact card_le_card h) #align ordinal.lift_down Ordinal.lift_down theorem le_lift_iff {a : Ordinal.{u}} {b : Ordinal.{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 ordinal.le_lift_iff Ordinal.le_lift_iff theorem lt_lift_iff {a : Ordinal.{u}} {b : Ordinal.{max u v}} : b < lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' < a := ⟨fun h => let ⟨a', e⟩ := lift_down (le_of_lt h) ⟨a', e, lift_lt.1 <| e.symm ▸ h⟩, fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩ #align ordinal.lt_lift_iff Ordinal.lt_lift_iff /-- Initial segment version of the lift operation on ordinals, embedding `ordinal.{u}` in `ordinal.{v}` as an initial segment when `u ≤ v`. -/ def lift.initialSeg : @InitialSeg Ordinal.{u} Ordinal.{max u v} (· < ·) (· < ·) := ⟨⟨⟨lift.{v}, fun _ _ => lift_inj.1⟩, lift_lt⟩, fun _ _ h => lift_down (le_of_lt h)⟩ #align ordinal.lift.initial_seg Ordinal.lift.initialSeg @[simp] theorem lift.initialSeg_coe : (lift.initialSeg.{u,v} : Ordinal → Ordinal) = lift.{v,u} := rfl #align ordinal.lift.initial_seg_coe Ordinal.lift.initialSeg_coe /-! ### The first infinite ordinal `omega` -/ /-- `ω` is the first infinite ordinal, defined as the order type of `ℕ`. -/ def omega : Ordinal.{u} := lift <| @type ℕ (· < ·) _ #align ordinal.omega Ordinal.omega @[inherit_doc] scoped notation "ω" => Ordinal.omega /-- Note that the presence of this lemma makes `simp [omega]` form a loop. -/ @[simp] theorem type_nat_lt : @type ℕ (· < ·) _ = ω := (lift_id _).symm #align ordinal.type_nat_lt Ordinal.type_nat_lt @[simp] theorem card_omega : card ω = ℵ₀ := rfl #align ordinal.card_omega Ordinal.card_omega @[simp] theorem lift_omega : lift ω = ω := lift_lift _ #align ordinal.lift_omega Ordinal.lift_omega /-! ### Definition and first properties of addition on ordinals In this paragraph, we introduce the addition on ordinals, and prove just enough properties to deduce that the order on ordinals is total (and therefore well-founded). Further properties of the addition, together with properties of the other operations, are proved in `Mathlib/SetTheory/Ordinal/Arithmetic.lean`. -/ /-- `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₂`. -/ instance add : Add Ordinal.{u} := ⟨fun o₁ o₂ => Quotient.liftOn₂ o₁ o₂ (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => type (Sum.Lex r s)) fun _ _ _ _ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.sumLexCongr f g⟩⟩ instance addMonoidWithOne : AddMonoidWithOne Ordinal.{u} where add := (· + ·) zero := 0 one := 1 zero_add o := inductionOn o fun α r _ => Eq.symm <| Quotient.sound ⟨⟨(emptySum PEmpty α).symm, Sum.lex_inr_inr⟩⟩ add_zero o := inductionOn o fun α r _ => Eq.symm <| Quotient.sound ⟨⟨(sumEmpty α PEmpty).symm, Sum.lex_inl_inl⟩⟩ add_assoc o₁ o₂ o₃ := Quotient.inductionOn₃ o₁ o₂ o₃ fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Quot.sound ⟨⟨sumAssoc _ _ _, by intros a b rcases a with (⟨a | a⟩ | a) <;> rcases b with (⟨b | b⟩ | b) <;> simp only [sumAssoc_apply_inl_inl, sumAssoc_apply_inl_inr, sumAssoc_apply_inr, Sum.lex_inl_inl, Sum.lex_inr_inr, Sum.Lex.sep, Sum.lex_inr_inl]⟩⟩ nsmul := nsmulRec @[simp] theorem card_add (o₁ o₂ : Ordinal) : card (o₁ + o₂) = card o₁ + card o₂ := inductionOn o₁ fun _ __ => inductionOn o₂ fun _ _ _ => rfl #align ordinal.card_add Ordinal.card_add @[simp] theorem type_sum_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r] [IsWellOrder β s] : type (Sum.Lex r s) = type r + type s := rfl #align ordinal.type_sum_lex Ordinal.type_sum_lex @[simp] theorem card_nat (n : ℕ) : card.{u} n = n := by induction n <;> [simp; simp only [card_add, card_one, Nat.cast_succ, *]] #align ordinal.card_nat Ordinal.card_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem card_ofNat (n : ℕ) [n.AtLeastTwo] : card.{u} (no_index (OfNat.ofNat n)) = OfNat.ofNat n := card_nat n -- Porting note: Rewritten proof of elim, previous version was difficult to debug instance add_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) where elim := fun c a b h => by revert h c refine inductionOn a (fun α₁ r₁ _ ↦ ?_) refine inductionOn b (fun α₂ r₂ _ ↦ ?_) rintro c ⟨⟨⟨f, fo⟩, fi⟩⟩ refine inductionOn c (fun β s _ ↦ ?_) refine ⟨⟨⟨(Embedding.refl.{u+1} _).sumMap f, ?_⟩, ?_⟩⟩ · intros a b match a, b with | Sum.inl a, Sum.inl b => exact Sum.lex_inl_inl.trans Sum.lex_inl_inl.symm | Sum.inl a, Sum.inr b => apply iff_of_true <;> apply Sum.Lex.sep | Sum.inr a, Sum.inl b => apply iff_of_false <;> exact Sum.lex_inr_inl | Sum.inr a, Sum.inr b => exact Sum.lex_inr_inr.trans <| fo.trans Sum.lex_inr_inr.symm · intros a b H match a, b, H with | _, Sum.inl b, _ => exact ⟨Sum.inl b, rfl⟩ | Sum.inl a, Sum.inr b, H => exact (Sum.lex_inr_inl H).elim | Sum.inr a, Sum.inr b, H => let ⟨w, h⟩ := fi _ _ (Sum.lex_inr_inr.1 H) exact ⟨Sum.inr w, congr_arg Sum.inr h⟩ #align ordinal.add_covariant_class_le Ordinal.add_covariantClass_le -- Porting note: Rewritten proof of elim, previous version was difficult to debug instance add_swap_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· ≤ ·) where elim := fun c a b h => by revert h c refine inductionOn a (fun α₁ r₁ _ ↦ ?_) refine inductionOn b (fun α₂ r₂ _ ↦ ?_) rintro c ⟨⟨⟨f, fo⟩, fi⟩⟩ refine inductionOn c (fun β s _ ↦ ?_) exact @RelEmbedding.ordinal_type_le _ _ (Sum.Lex r₁ s) (Sum.Lex r₂ s) _ _ ⟨f.sumMap (Embedding.refl _), by intro a b constructor <;> intro H · cases' a with a a <;> cases' b with b b <;> cases H <;> constructor <;> [rwa [← fo]; assumption] · cases H <;> constructor <;> [rwa [fo]; assumption]⟩ #align ordinal.add_swap_covariant_class_le Ordinal.add_swap_covariantClass_le theorem le_add_right (a b : Ordinal) : a ≤ a + b := by simpa only [add_zero] using add_le_add_left (Ordinal.zero_le b) a #align ordinal.le_add_right Ordinal.le_add_right theorem le_add_left (a b : Ordinal) : a ≤ b + a := by simpa only [zero_add] using add_le_add_right (Ordinal.zero_le b) a #align ordinal.le_add_left Ordinal.le_add_left instance linearOrder : LinearOrder Ordinal := {inferInstanceAs (PartialOrder Ordinal) with le_total := fun a b => match lt_or_eq_of_le (le_add_left b a), lt_or_eq_of_le (le_add_right a b) with | Or.inr h, _ => by rw [h]; exact Or.inl (le_add_right _ _) | _, Or.inr h => by rw [h]; exact Or.inr (le_add_left _ _) | Or.inl h₁, Or.inl h₂ => by revert h₁ h₂ refine inductionOn a ?_ intro α₁ r₁ _ refine inductionOn b ?_ intro α₂ r₂ _ ⟨f⟩ ⟨g⟩ rw [← typein_top f, ← typein_top g, le_iff_lt_or_eq, le_iff_lt_or_eq, typein_lt_typein, typein_lt_typein] rcases trichotomous_of (Sum.Lex r₁ r₂) g.top f.top with (h | h | h) <;> [exact Or.inl (Or.inl h); (left; right; rw [h]); exact Or.inr (Or.inl h)] decidableLE := Classical.decRel _ } instance wellFoundedLT : WellFoundedLT Ordinal := ⟨lt_wf⟩ instance isWellOrder : IsWellOrder Ordinal (· < ·) where instance : ConditionallyCompleteLinearOrderBot Ordinal := IsWellOrder.conditionallyCompleteLinearOrderBot _ theorem max_zero_left : ∀ a : Ordinal, max 0 a = a := max_bot_left #align ordinal.max_zero_left Ordinal.max_zero_left theorem max_zero_right : ∀ a : Ordinal, max a 0 = a := max_bot_right #align ordinal.max_zero_right Ordinal.max_zero_right @[simp] theorem max_eq_zero {a b : Ordinal} : max a b = 0 ↔ a = 0 ∧ b = 0 := max_eq_bot #align ordinal.max_eq_zero Ordinal.max_eq_zero @[simp] theorem sInf_empty : sInf (∅ : Set Ordinal) = 0 := dif_neg Set.not_nonempty_empty #align ordinal.Inf_empty Ordinal.sInf_empty /-! ### Successor order properties -/ private theorem succ_le_iff' {a b : Ordinal} : a + 1 ≤ b ↔ a < b := ⟨lt_of_lt_of_le (inductionOn a fun α r _ => ⟨⟨⟨⟨fun x => Sum.inl x, fun _ _ => Sum.inl.inj⟩, Sum.lex_inl_inl⟩, Sum.inr PUnit.unit, fun b => Sum.recOn b (fun x => ⟨fun _ => ⟨x, rfl⟩, fun _ => Sum.Lex.sep _ _⟩) fun x => Sum.lex_inr_inr.trans ⟨False.elim, fun ⟨x, H⟩ => Sum.inl_ne_inr H⟩⟩⟩), inductionOn a fun α r hr => inductionOn b fun β s hs ⟨⟨f, t, hf⟩⟩ => by haveI := hs refine ⟨⟨RelEmbedding.ofMonotone (Sum.rec f fun _ => t) (fun a b ↦ ?_), fun a b ↦ ?_⟩⟩ · rcases a with (a | _) <;> rcases b with (b | _) · simpa only [Sum.lex_inl_inl] using f.map_rel_iff.2 · intro rw [hf] exact ⟨_, rfl⟩ · exact False.elim ∘ Sum.lex_inr_inl · exact False.elim ∘ Sum.lex_inr_inr.1 · rcases a with (a | _) · intro h have := @PrincipalSeg.init _ _ _ _ _ ⟨f, t, hf⟩ _ _ h cases' this with w h exact ⟨Sum.inl w, h⟩ · intro h cases' (hf b).1 h with w h exact ⟨Sum.inl w, h⟩⟩ instance noMaxOrder : NoMaxOrder Ordinal := ⟨fun _ => ⟨_, succ_le_iff'.1 le_rfl⟩⟩ instance succOrder : SuccOrder Ordinal.{u} := SuccOrder.ofSuccLeIff (fun o => o + 1) succ_le_iff' @[simp] theorem add_one_eq_succ (o : Ordinal) : o + 1 = succ o := rfl #align ordinal.add_one_eq_succ Ordinal.add_one_eq_succ @[simp] theorem succ_zero : succ (0 : Ordinal) = 1 := zero_add 1 #align ordinal.succ_zero Ordinal.succ_zero -- Porting note: Proof used to be rfl @[simp] theorem succ_one : succ (1 : Ordinal) = 2 := by congr; simp only [Nat.unaryCast, zero_add] #align ordinal.succ_one Ordinal.succ_one theorem add_succ (o₁ o₂ : Ordinal) : o₁ + succ o₂ = succ (o₁ + o₂) := (add_assoc _ _ _).symm #align ordinal.add_succ Ordinal.add_succ theorem one_le_iff_pos {o : Ordinal} : 1 ≤ o ↔ 0 < o := by rw [← succ_zero, succ_le_iff] #align ordinal.one_le_iff_pos Ordinal.one_le_iff_pos theorem one_le_iff_ne_zero {o : Ordinal} : 1 ≤ o ↔ o ≠ 0 := by rw [one_le_iff_pos, Ordinal.pos_iff_ne_zero] #align ordinal.one_le_iff_ne_zero Ordinal.one_le_iff_ne_zero theorem succ_pos (o : Ordinal) : 0 < succ o := bot_lt_succ o #align ordinal.succ_pos Ordinal.succ_pos theorem succ_ne_zero (o : Ordinal) : succ o ≠ 0 := ne_of_gt <| succ_pos o #align ordinal.succ_ne_zero Ordinal.succ_ne_zero @[simp] theorem lt_one_iff_zero {a : Ordinal} : a < 1 ↔ a = 0 := by simpa using @lt_succ_bot_iff _ _ _ a _ _ #align ordinal.lt_one_iff_zero Ordinal.lt_one_iff_zero theorem le_one_iff {a : Ordinal} : a ≤ 1 ↔ a = 0 ∨ a = 1 := by simpa using @le_succ_bot_iff _ _ _ a _ #align ordinal.le_one_iff Ordinal.le_one_iff @[simp] theorem card_succ (o : Ordinal) : card (succ o) = card o + 1 := by simp only [← add_one_eq_succ, card_add, card_one] #align ordinal.card_succ Ordinal.card_succ theorem natCast_succ (n : ℕ) : ↑n.succ = succ (n : Ordinal) := rfl #align ordinal.nat_cast_succ Ordinal.natCast_succ @[deprecated (since := "2024-04-17")] alias nat_cast_succ := natCast_succ instance uniqueIioOne : Unique (Iio (1 : Ordinal)) where default := ⟨0, by simp⟩ uniq a := Subtype.ext <| lt_one_iff_zero.1 a.2 #align ordinal.unique_Iio_one Ordinal.uniqueIioOne instance uniqueOutOne : Unique (1 : Ordinal).out.α where default := enum (· < ·) 0 (by simp) uniq a := by unfold default rw [← @enum_typein _ (· < ·) (isWellOrder_out_lt _) a] congr rw [← lt_one_iff_zero] apply typein_lt_self #align ordinal.unique_out_one Ordinal.uniqueOutOne theorem one_out_eq (x : (1 : Ordinal).out.α) : x = enum (· < ·) 0 (by simp) := Unique.eq_default x #align ordinal.one_out_eq Ordinal.one_out_eq /-! ### Extra properties of typein and enum -/ @[simp] theorem typein_one_out (x : (1 : Ordinal).out.α) : @typein _ (· < ·) (isWellOrder_out_lt _) x = 0 := by rw [one_out_eq x, typein_enum] #align ordinal.typein_one_out Ordinal.typein_one_out @[simp] theorem typein_le_typein (r : α → α → Prop) [IsWellOrder α r] {x x' : α} : typein r x ≤ typein r x' ↔ ¬r x' x := by rw [← not_lt, typein_lt_typein] #align ordinal.typein_le_typein Ordinal.typein_le_typein -- @[simp] -- Porting note (#10618): simp can prove this theorem typein_le_typein' (o : Ordinal) {x x' : o.out.α} : @typein _ (· < ·) (isWellOrder_out_lt _) x ≤ @typein _ (· < ·) (isWellOrder_out_lt _) x' ↔ x ≤ x' := by rw [typein_le_typein] exact not_lt #align ordinal.typein_le_typein' Ordinal.typein_le_typein' -- Porting note: added nolint, simpnf linter falsely claims it never applies @[simp, nolint simpNF] theorem enum_le_enum (r : α → α → Prop) [IsWellOrder α r] {o o' : Ordinal} (ho : o < type r) (ho' : o' < type r) : ¬r (enum r o' ho') (enum r o ho) ↔ o ≤ o' := by rw [← @not_lt _ _ o' o, enum_lt_enum ho'] #align ordinal.enum_le_enum Ordinal.enum_le_enum @[simp] theorem enum_le_enum' (a : Ordinal) {o o' : Ordinal} (ho : o < type (· < ·)) (ho' : o' < type (· < ·)) : enum (· < ·) o ho ≤ @enum a.out.α (· < ·) _ o' ho' ↔ o ≤ o' := by rw [← @enum_le_enum _ (· < ·) (isWellOrder_out_lt _), ← not_lt] #align ordinal.enum_le_enum' Ordinal.enum_le_enum' theorem enum_zero_le {r : α → α → Prop} [IsWellOrder α r] (h0 : 0 < type r) (a : α) : ¬r a (enum r 0 h0) := by rw [← enum_typein r a, enum_le_enum r] apply Ordinal.zero_le #align ordinal.enum_zero_le Ordinal.enum_zero_le theorem enum_zero_le' {o : Ordinal} (h0 : 0 < o) (a : o.out.α) : @enum o.out.α (· < ·) _ 0 (by rwa [type_lt]) ≤ a := by rw [← not_lt] apply enum_zero_le #align ordinal.enum_zero_le' Ordinal.enum_zero_le' theorem le_enum_succ {o : Ordinal} (a : (succ o).out.α) : a ≤ @enum (succ o).out.α (· < ·) _ o (by rw [type_lt] exact lt_succ o) := by rw [← @enum_typein _ (· < ·) (isWellOrder_out_lt _) a, enum_le_enum', ← lt_succ_iff] apply typein_lt_self #align ordinal.le_enum_succ Ordinal.le_enum_succ @[simp] theorem enum_inj {r : α → α → Prop} [IsWellOrder α r] {o₁ o₂ : Ordinal} (h₁ : o₁ < type r) (h₂ : o₂ < type r) : enum r o₁ h₁ = enum r o₂ h₂ ↔ o₁ = o₂ := (typein.principalSeg r).subrelIso.injective.eq_iff.trans Subtype.mk_eq_mk #align ordinal.enum_inj Ordinal.enum_inj -- TODO: Can we remove this definition and just use `(typein.principalSeg r).subrelIso` directly? /-- A well order `r` is order isomorphic to the set of ordinals smaller than `type r`. -/ @[simps] def enumIso (r : α → α → Prop) [IsWellOrder α r] : Subrel (· < ·) (· < type r) ≃r r := { (typein.principalSeg r).subrelIso with toFun := fun x ↦ enum r x.1 x.2 invFun := fun x ↦ ⟨typein r x, typein_lt_type r x⟩ } #align ordinal.enum_iso Ordinal.enumIso /-- The order isomorphism between ordinals less than `o` and `o.out.α`. -/ @[simps!] noncomputable def enumIsoOut (o : Ordinal) : Set.Iio o ≃o o.out.α where toFun x := enum (· < ·) x.1 <| by rw [type_lt] exact x.2 invFun x := ⟨@typein _ (· < ·) (isWellOrder_out_lt _) x, typein_lt_self x⟩ left_inv := fun ⟨o', h⟩ => Subtype.ext_val (typein_enum _ _) right_inv h := enum_typein _ _ map_rel_iff' := by rintro ⟨a, _⟩ ⟨b, _⟩ apply enum_le_enum' #align ordinal.enum_iso_out Ordinal.enumIsoOut /-- `o.out.α` is an `OrderBot` whenever `0 < o`. -/ def outOrderBotOfPos {o : Ordinal} (ho : 0 < o) : OrderBot o.out.α where bot_le := enum_zero_le' ho #align ordinal.out_order_bot_of_pos Ordinal.outOrderBotOfPos theorem enum_zero_eq_bot {o : Ordinal} (ho : 0 < o) : enum (· < ·) 0 (by rwa [type_lt]) = haveI H := outOrderBotOfPos ho ⊥ := rfl #align ordinal.enum_zero_eq_bot Ordinal.enum_zero_eq_bot /-! ### Universal ordinal -/ -- intended to be used with explicit universe parameters /-- `univ.{u v}` is the order type of the ordinals of `Type u` as a member of `Ordinal.{v}` (when `u < v`). It is an inaccessible cardinal. -/ @[pp_with_univ, nolint checkUnivs] def univ : Ordinal.{max (u + 1) v} := lift.{v, u + 1} (@type Ordinal (· < ·) _) #align ordinal.univ Ordinal.univ theorem univ_id : univ.{u, u + 1} = @type Ordinal (· < ·) _ := lift_id _ #align ordinal.univ_id Ordinal.univ_id @[simp] theorem lift_univ : lift.{w} univ.{u, v} = univ.{u, max v w} := lift_lift _ #align ordinal.lift_univ Ordinal.lift_univ theorem univ_umax : univ.{u, max (u + 1) v} = univ.{u, v} := congr_fun lift_umax _ #align ordinal.univ_umax Ordinal.univ_umax /-- Principal segment version of the lift operation on ordinals, embedding `ordinal.{u}` in `ordinal.{v}` as a principal segment when `u < v`. -/ def lift.principalSeg : @PrincipalSeg Ordinal.{u} Ordinal.{max (u + 1) v} (· < ·) (· < ·) := ⟨↑lift.initialSeg.{u, max (u + 1) v}, univ.{u, v}, by refine fun b => inductionOn b ?_; intro β s _ rw [univ, ← lift_umax]; constructor <;> intro h · rw [← lift_id (type s)] at h ⊢ cases' lift_type_lt.{_,_,v}.1 h with f cases' f with f a hf exists a revert hf -- Porting note: apply inductionOn does not work, refine does refine inductionOn a ?_ intro α r _ hf refine lift_type_eq.{u, max (u + 1) v, max (u + 1) v}.2 ⟨(RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ ?_) ?_).symm⟩ · exact fun b => enum r (f b) ((hf _).2 ⟨_, rfl⟩) · refine fun a b h => (typein_lt_typein r).1 ?_ rw [typein_enum, typein_enum] exact f.map_rel_iff.2 h · intro a' cases' (hf _).1 (typein_lt_type _ a') with b e exists b simp only [RelEmbedding.ofMonotone_coe] simp [e] · cases' h with a e rw [← e] refine inductionOn a ?_ intro α r _ exact lift_type_lt.{u, u + 1, max (u + 1) v}.2 ⟨typein.principalSeg r⟩⟩ #align ordinal.lift.principal_seg Ordinal.lift.principalSeg @[simp] theorem lift.principalSeg_coe : (lift.principalSeg.{u, v} : Ordinal → Ordinal) = lift.{max (u + 1) v} := rfl #align ordinal.lift.principal_seg_coe Ordinal.lift.principalSeg_coe -- Porting note: Added universe hints below @[simp] theorem lift.principalSeg_top : (lift.principalSeg.{u,v}).top = univ.{u,v} := rfl #align ordinal.lift.principal_seg_top Ordinal.lift.principalSeg_top
Mathlib/SetTheory/Ordinal/Basic.lean
1,285
1,286
theorem lift.principalSeg_top' : lift.principalSeg.{u, u + 1}.top = @type Ordinal (· < ·) _ := by
simp only [lift.principalSeg_top, univ_id]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.RingTheory.Ideal.Operations import Mathlib.RingTheory.JacobsonIdeal import Mathlib.Logic.Equiv.TransferInstance import Mathlib.Tactic.TFAE #align_import ring_theory.ideal.local_ring from "leanprover-community/mathlib"@"ec1c7d810034d4202b0dd239112d1792be9f6fdc" /-! # Local rings Define local rings as commutative rings having a unique maximal ideal. ## Main definitions * `LocalRing`: A predicate on commutative semirings, stating that for any pair of elements that adds up to `1`, one of them is a unit. This is shown to be equivalent to the condition that there exists a unique maximal ideal. * `LocalRing.maximalIdeal`: The unique maximal ideal for a local rings. Its carrier set is the set of non units. * `IsLocalRingHom`: A predicate on semiring homomorphisms, requiring that it maps nonunits to nonunits. For local rings, this means that the image of the unique maximal ideal is again contained in the unique maximal ideal. * `LocalRing.ResidueField`: The quotient of a local ring by its maximal ideal. -/ universe u v w u' variable {R : Type u} {S : Type v} {T : Type w} {K : Type u'} /-- A semiring is local if it is nontrivial and `a` or `b` is a unit whenever `a + b = 1`. Note that `LocalRing` is a predicate. -/ class LocalRing (R : Type u) [Semiring R] extends Nontrivial R : Prop where of_is_unit_or_is_unit_of_add_one :: /-- in a local ring `R`, if `a + b = 1`, then either `a` is a unit or `b` is a unit. In another word, for every `a : R`, either `a` is a unit or `1 - a` is a unit. -/ isUnit_or_isUnit_of_add_one {a b : R} (h : a + b = 1) : IsUnit a ∨ IsUnit b #align local_ring LocalRing section CommSemiring variable [CommSemiring R] namespace LocalRing theorem of_isUnit_or_isUnit_of_isUnit_add [Nontrivial R] (h : ∀ a b : R, IsUnit (a + b) → IsUnit a ∨ IsUnit b) : LocalRing R := ⟨fun {a b} hab => h a b <| hab.symm ▸ isUnit_one⟩ #align local_ring.of_is_unit_or_is_unit_of_is_unit_add LocalRing.of_isUnit_or_isUnit_of_isUnit_add /-- A semiring is local if it is nontrivial and the set of nonunits is closed under the addition. -/ theorem of_nonunits_add [Nontrivial R] (h : ∀ a b : R, a ∈ nonunits R → b ∈ nonunits R → a + b ∈ nonunits R) : LocalRing R := ⟨fun {a b} hab => or_iff_not_and_not.2 fun H => h a b H.1 H.2 <| hab.symm ▸ isUnit_one⟩ #align local_ring.of_nonunits_add LocalRing.of_nonunits_add /-- A semiring is local if it has a unique maximal ideal. -/ theorem of_unique_max_ideal (h : ∃! I : Ideal R, I.IsMaximal) : LocalRing R := @of_nonunits_add _ _ (nontrivial_of_ne (0 : R) 1 <| let ⟨I, Imax, _⟩ := h fun H : 0 = 1 => Imax.1.1 <| I.eq_top_iff_one.2 <| H ▸ I.zero_mem) fun x y hx hy H => let ⟨I, Imax, Iuniq⟩ := h let ⟨Ix, Ixmax, Hx⟩ := exists_max_ideal_of_mem_nonunits hx let ⟨Iy, Iymax, Hy⟩ := exists_max_ideal_of_mem_nonunits hy have xmemI : x ∈ I := Iuniq Ix Ixmax ▸ Hx have ymemI : y ∈ I := Iuniq Iy Iymax ▸ Hy Imax.1.1 <| I.eq_top_of_isUnit_mem (I.add_mem xmemI ymemI) H #align local_ring.of_unique_max_ideal LocalRing.of_unique_max_ideal theorem of_unique_nonzero_prime (h : ∃! P : Ideal R, P ≠ ⊥ ∧ Ideal.IsPrime P) : LocalRing R := of_unique_max_ideal (by rcases h with ⟨P, ⟨hPnonzero, hPnot_top, _⟩, hPunique⟩ refine ⟨P, ⟨⟨hPnot_top, ?_⟩⟩, fun M hM => hPunique _ ⟨?_, Ideal.IsMaximal.isPrime hM⟩⟩ · refine Ideal.maximal_of_no_maximal fun M hPM hM => ne_of_lt hPM ?_ exact (hPunique _ ⟨ne_bot_of_gt hPM, Ideal.IsMaximal.isPrime hM⟩).symm · rintro rfl exact hPnot_top (hM.1.2 P (bot_lt_iff_ne_bot.2 hPnonzero))) #align local_ring.of_unique_nonzero_prime LocalRing.of_unique_nonzero_prime variable [LocalRing R] theorem isUnit_or_isUnit_of_isUnit_add {a b : R} (h : IsUnit (a + b)) : IsUnit a ∨ IsUnit b := by rcases h with ⟨u, hu⟩ rw [← Units.inv_mul_eq_one, mul_add] at hu apply Or.imp _ _ (isUnit_or_isUnit_of_add_one hu) <;> exact isUnit_of_mul_isUnit_right #align local_ring.is_unit_or_is_unit_of_is_unit_add LocalRing.isUnit_or_isUnit_of_isUnit_add theorem nonunits_add {a b : R} (ha : a ∈ nonunits R) (hb : b ∈ nonunits R) : a + b ∈ nonunits R := fun H => not_or_of_not ha hb (isUnit_or_isUnit_of_isUnit_add H) #align local_ring.nonunits_add LocalRing.nonunits_add variable (R) /-- The ideal of elements that are not units. -/ def maximalIdeal : Ideal R where carrier := nonunits R zero_mem' := zero_mem_nonunits.2 <| zero_ne_one add_mem' {_ _} hx hy := nonunits_add hx hy smul_mem' _ _ := mul_mem_nonunits_right #align local_ring.maximal_ideal LocalRing.maximalIdeal instance maximalIdeal.isMaximal : (maximalIdeal R).IsMaximal := by rw [Ideal.isMaximal_iff] constructor · intro h apply h exact isUnit_one · intro I x _ hx H erw [Classical.not_not] at hx rcases hx with ⟨u, rfl⟩ simpa using I.mul_mem_left (↑u⁻¹) H #align local_ring.maximal_ideal.is_maximal LocalRing.maximalIdeal.isMaximal theorem maximal_ideal_unique : ∃! I : Ideal R, I.IsMaximal := ⟨maximalIdeal R, maximalIdeal.isMaximal R, fun I hI => hI.eq_of_le (maximalIdeal.isMaximal R).1.1 fun _ hx => hI.1.1 ∘ I.eq_top_of_isUnit_mem hx⟩ #align local_ring.maximal_ideal_unique LocalRing.maximal_ideal_unique variable {R} theorem eq_maximalIdeal {I : Ideal R} (hI : I.IsMaximal) : I = maximalIdeal R := ExistsUnique.unique (maximal_ideal_unique R) hI <| maximalIdeal.isMaximal R #align local_ring.eq_maximal_ideal LocalRing.eq_maximalIdeal theorem le_maximalIdeal {J : Ideal R} (hJ : J ≠ ⊤) : J ≤ maximalIdeal R := by rcases Ideal.exists_le_maximal J hJ with ⟨M, hM1, hM2⟩ rwa [← eq_maximalIdeal hM1] #align local_ring.le_maximal_ideal LocalRing.le_maximalIdeal @[simp] theorem mem_maximalIdeal (x) : x ∈ maximalIdeal R ↔ x ∈ nonunits R := Iff.rfl #align local_ring.mem_maximal_ideal LocalRing.mem_maximalIdeal theorem isField_iff_maximalIdeal_eq : IsField R ↔ maximalIdeal R = ⊥ := not_iff_not.mp ⟨Ring.ne_bot_of_isMaximal_of_not_isField inferInstance, fun h => Ring.not_isField_iff_exists_prime.mpr ⟨_, h, Ideal.IsMaximal.isPrime' _⟩⟩ #align local_ring.is_field_iff_maximal_ideal_eq LocalRing.isField_iff_maximalIdeal_eq end LocalRing end CommSemiring section CommRing variable [CommRing R] namespace LocalRing theorem of_isUnit_or_isUnit_one_sub_self [Nontrivial R] (h : ∀ a : R, IsUnit a ∨ IsUnit (1 - a)) : LocalRing R := ⟨fun {a b} hab => add_sub_cancel_left a b ▸ hab.symm ▸ h a⟩ #align local_ring.of_is_unit_or_is_unit_one_sub_self LocalRing.of_isUnit_or_isUnit_one_sub_self variable [LocalRing R] theorem isUnit_or_isUnit_one_sub_self (a : R) : IsUnit a ∨ IsUnit (1 - a) := isUnit_or_isUnit_of_isUnit_add <| (add_sub_cancel a 1).symm ▸ isUnit_one #align local_ring.is_unit_or_is_unit_one_sub_self LocalRing.isUnit_or_isUnit_one_sub_self theorem isUnit_of_mem_nonunits_one_sub_self (a : R) (h : 1 - a ∈ nonunits R) : IsUnit a := or_iff_not_imp_right.1 (isUnit_or_isUnit_one_sub_self a) h #align local_ring.is_unit_of_mem_nonunits_one_sub_self LocalRing.isUnit_of_mem_nonunits_one_sub_self theorem isUnit_one_sub_self_of_mem_nonunits (a : R) (h : a ∈ nonunits R) : IsUnit (1 - a) := or_iff_not_imp_left.1 (isUnit_or_isUnit_one_sub_self a) h #align local_ring.is_unit_one_sub_self_of_mem_nonunits LocalRing.isUnit_one_sub_self_of_mem_nonunits theorem of_surjective' [CommRing S] [Nontrivial S] (f : R →+* S) (hf : Function.Surjective f) : LocalRing S := of_isUnit_or_isUnit_one_sub_self (by intro b obtain ⟨a, rfl⟩ := hf b apply (isUnit_or_isUnit_one_sub_self a).imp <| RingHom.isUnit_map _ rw [← f.map_one, ← f.map_sub] apply f.isUnit_map) #align local_ring.of_surjective' LocalRing.of_surjective' theorem maximalIdeal_le_jacobson (I : Ideal R) : LocalRing.maximalIdeal R ≤ I.jacobson := le_sInf fun _ ⟨_, h⟩ => le_of_eq (LocalRing.eq_maximalIdeal h).symm theorem jacobson_eq_maximalIdeal (I : Ideal R) (h : I ≠ ⊤) : I.jacobson = LocalRing.maximalIdeal R := le_antisymm (sInf_le ⟨le_maximalIdeal h, maximalIdeal.isMaximal R⟩) (maximalIdeal_le_jacobson I) #align local_ring.jacobson_eq_maximal_ideal LocalRing.jacobson_eq_maximalIdeal end LocalRing end CommRing /-- A local ring homomorphism is a homomorphism `f` between local rings such that `a` in the domain is a unit if `f a` is a unit for any `a`. See `LocalRing.local_hom_TFAE` for other equivalent definitions. -/ class IsLocalRingHom [Semiring R] [Semiring S] (f : R →+* S) : Prop where /-- A local ring homomorphism `f : R ⟶ S` will send nonunits of `R` to nonunits of `S`. -/ map_nonunit : ∀ a, IsUnit (f a) → IsUnit a #align is_local_ring_hom IsLocalRingHom section variable [Semiring R] [Semiring S] [Semiring T] instance isLocalRingHom_id (R : Type*) [Semiring R] : IsLocalRingHom (RingHom.id R) where map_nonunit _ := id #align is_local_ring_hom_id isLocalRingHom_id @[simp] theorem isUnit_map_iff (f : R →+* S) [IsLocalRingHom f] (a) : IsUnit (f a) ↔ IsUnit a := ⟨IsLocalRingHom.map_nonunit a, f.isUnit_map⟩ #align is_unit_map_iff isUnit_map_iff -- Porting note: as this can be proved by other `simp` lemmas, this is marked as high priority. @[simp (high)] theorem map_mem_nonunits_iff (f : R →+* S) [IsLocalRingHom f] (a) : f a ∈ nonunits S ↔ a ∈ nonunits R := ⟨fun h ha => h <| (isUnit_map_iff f a).mpr ha, fun h ha => h <| (isUnit_map_iff f a).mp ha⟩ #align map_mem_nonunits_iff map_mem_nonunits_iff instance isLocalRingHom_comp (g : S →+* T) (f : R →+* S) [IsLocalRingHom g] [IsLocalRingHom f] : IsLocalRingHom (g.comp f) where map_nonunit a := IsLocalRingHom.map_nonunit a ∘ IsLocalRingHom.map_nonunit (f a) #align is_local_ring_hom_comp isLocalRingHom_comp instance isLocalRingHom_equiv (f : R ≃+* S) : IsLocalRingHom (f : R →+* S) where map_nonunit a ha := by convert RingHom.isUnit_map (f.symm : S →+* R) ha exact (RingEquiv.symm_apply_apply f a).symm #align is_local_ring_hom_equiv isLocalRingHom_equiv @[simp] theorem isUnit_of_map_unit (f : R →+* S) [IsLocalRingHom f] (a) (h : IsUnit (f a)) : IsUnit a := IsLocalRingHom.map_nonunit a h #align is_unit_of_map_unit isUnit_of_map_unit theorem of_irreducible_map (f : R →+* S) [h : IsLocalRingHom f] {x} (hfx : Irreducible (f x)) : Irreducible x := ⟨fun h => hfx.not_unit <| IsUnit.map f h, fun p q hx => let ⟨H⟩ := h Or.imp (H p) (H q) <| hfx.isUnit_or_isUnit <| f.map_mul p q ▸ congr_arg f hx⟩ #align of_irreducible_map of_irreducible_map theorem isLocalRingHom_of_comp (f : R →+* S) (g : S →+* T) [IsLocalRingHom (g.comp f)] : IsLocalRingHom f := ⟨fun _ ha => (isUnit_map_iff (g.comp f) _).mp (g.isUnit_map ha)⟩ #align is_local_ring_hom_of_comp isLocalRingHom_of_comp /-- If `f : R →+* S` is a local ring hom, then `R` is a local ring if `S` is. -/ theorem RingHom.domain_localRing {R S : Type*} [CommSemiring R] [CommSemiring S] [H : LocalRing S] (f : R →+* S) [IsLocalRingHom f] : LocalRing R := by haveI : Nontrivial R := pullback_nonzero f f.map_zero f.map_one apply LocalRing.of_nonunits_add intro a b simp_rw [← map_mem_nonunits_iff f, f.map_add] exact LocalRing.nonunits_add #align ring_hom.domain_local_ring RingHom.domain_localRing end section open LocalRing variable [CommSemiring R] [LocalRing R] [CommSemiring S] [LocalRing S] /-- The image of the maximal ideal of the source is contained within the maximal ideal of the target. -/ theorem map_nonunit (f : R →+* S) [IsLocalRingHom f] (a : R) (h : a ∈ maximalIdeal R) : f a ∈ maximalIdeal S := fun H => h <| isUnit_of_map_unit f a H #align map_nonunit map_nonunit end namespace LocalRing section variable [CommSemiring R] [LocalRing R] [CommSemiring S] [LocalRing S] /-- A ring homomorphism between local rings is a local ring hom iff it reflects units, i.e. any preimage of a unit is still a unit. https://stacks.math.columbia.edu/tag/07BJ -/ theorem local_hom_TFAE (f : R →+* S) : List.TFAE [IsLocalRingHom f, f '' (maximalIdeal R).1 ⊆ maximalIdeal S, (maximalIdeal R).map f ≤ maximalIdeal S, maximalIdeal R ≤ (maximalIdeal S).comap f, (maximalIdeal S).comap f = maximalIdeal R] := by tfae_have 1 → 2 · rintro _ _ ⟨a, ha, rfl⟩ exact map_nonunit f a ha tfae_have 2 → 4 · exact Set.image_subset_iff.1 tfae_have 3 ↔ 4 · exact Ideal.map_le_iff_le_comap tfae_have 4 → 1 · intro h constructor exact fun x => not_imp_not.1 (@h x) tfae_have 1 → 5 · intro ext exact not_iff_not.2 (isUnit_map_iff f _) tfae_have 5 → 4 · exact fun h => le_of_eq h.symm tfae_finish #align local_ring.local_hom_tfae LocalRing.local_hom_TFAE end theorem of_surjective [CommSemiring R] [LocalRing R] [CommSemiring S] [Nontrivial S] (f : R →+* S) [IsLocalRingHom f] (hf : Function.Surjective f) : LocalRing S := of_isUnit_or_isUnit_of_isUnit_add (by intro a b hab obtain ⟨a, rfl⟩ := hf a obtain ⟨b, rfl⟩ := hf b rw [← map_add] at hab exact (isUnit_or_isUnit_of_isUnit_add <| IsLocalRingHom.map_nonunit _ hab).imp f.isUnit_map f.isUnit_map) #align local_ring.of_surjective LocalRing.of_surjective /-- If `f : R →+* S` is a surjective local ring hom, then the induced units map is surjective. -/ theorem surjective_units_map_of_local_ringHom [CommRing R] [CommRing S] (f : R →+* S) (hf : Function.Surjective f) (h : IsLocalRingHom f) : Function.Surjective (Units.map <| f.toMonoidHom) := by intro a obtain ⟨b, hb⟩ := hf (a : S) use (isUnit_of_map_unit f b (by rw [hb]; exact Units.isUnit _)).unit ext exact hb #align local_ring.surjective_units_map_of_local_ring_hom LocalRing.surjective_units_map_of_local_ringHom section variable (R) [CommRing R] [LocalRing R] [CommRing S] [LocalRing S] [CommRing T] [LocalRing T] /-- The residue field of a local ring is the quotient of the ring by its maximal ideal. -/ def ResidueField := R ⧸ maximalIdeal R #align local_ring.residue_field LocalRing.ResidueField -- Porting note: failed at `deriving` instances automatically instance ResidueFieldCommRing : CommRing (ResidueField R) := show CommRing (R ⧸ maximalIdeal R) from inferInstance instance ResidueFieldInhabited : Inhabited (ResidueField R) := show Inhabited (R ⧸ maximalIdeal R) from inferInstance noncomputable instance ResidueField.field : Field (ResidueField R) := Ideal.Quotient.field (maximalIdeal R) #align local_ring.residue_field.field LocalRing.ResidueField.field /-- The quotient map from a local ring to its residue field. -/ def residue : R →+* ResidueField R := Ideal.Quotient.mk _ #align local_ring.residue LocalRing.residue instance ResidueField.algebra : Algebra R (ResidueField R) := Ideal.Quotient.algebra _ #align local_ring.residue_field.algebra LocalRing.ResidueField.algebra theorem ResidueField.algebraMap_eq : algebraMap R (ResidueField R) = residue R := rfl #align local_ring.residue_field.algebra_map_eq LocalRing.ResidueField.algebraMap_eq instance : IsLocalRingHom (LocalRing.residue R) := ⟨fun _ ha => Classical.not_not.mp (Ideal.Quotient.eq_zero_iff_mem.not.mp (isUnit_iff_ne_zero.mp ha))⟩ variable {R} namespace ResidueField /-- A local ring homomorphism into a field can be descended onto the residue field. -/ def lift {R S : Type*} [CommRing R] [LocalRing R] [Field S] (f : R →+* S) [IsLocalRingHom f] : LocalRing.ResidueField R →+* S := Ideal.Quotient.lift _ f fun a ha => by_contradiction fun h => ha (isUnit_of_map_unit f a (isUnit_iff_ne_zero.mpr h)) #align local_ring.residue_field.lift LocalRing.ResidueField.lift theorem lift_comp_residue {R S : Type*} [CommRing R] [LocalRing R] [Field S] (f : R →+* S) [IsLocalRingHom f] : (lift f).comp (residue R) = f := RingHom.ext fun _ => rfl #align local_ring.residue_field.lift_comp_residue LocalRing.ResidueField.lift_comp_residue @[simp] theorem lift_residue_apply {R S : Type*} [CommRing R] [LocalRing R] [Field S] (f : R →+* S) [IsLocalRingHom f] (x) : lift f (residue R x) = f x := rfl #align local_ring.residue_field.lift_residue_apply LocalRing.ResidueField.lift_residue_apply /-- The map on residue fields induced by a local homomorphism between local rings -/ def map (f : R →+* S) [IsLocalRingHom f] : ResidueField R →+* ResidueField S := Ideal.Quotient.lift (maximalIdeal R) ((Ideal.Quotient.mk _).comp f) fun a ha => by erw [Ideal.Quotient.eq_zero_iff_mem] exact map_nonunit f a ha #align local_ring.residue_field.map LocalRing.ResidueField.map /-- Applying `LocalRing.ResidueField.map` to the identity ring homomorphism gives the identity ring homomorphism. -/ @[simp] theorem map_id : LocalRing.ResidueField.map (RingHom.id R) = RingHom.id (LocalRing.ResidueField R) := Ideal.Quotient.ringHom_ext <| RingHom.ext fun _ => rfl #align local_ring.residue_field.map_id LocalRing.ResidueField.map_id /-- The composite of two `LocalRing.ResidueField.map`s is the `LocalRing.ResidueField.map` of the composite. -/ theorem map_comp (f : T →+* R) (g : R →+* S) [IsLocalRingHom f] [IsLocalRingHom g] : LocalRing.ResidueField.map (g.comp f) = (LocalRing.ResidueField.map g).comp (LocalRing.ResidueField.map f) := Ideal.Quotient.ringHom_ext <| RingHom.ext fun _ => rfl #align local_ring.residue_field.map_comp LocalRing.ResidueField.map_comp theorem map_comp_residue (f : R →+* S) [IsLocalRingHom f] : (ResidueField.map f).comp (residue R) = (residue S).comp f := rfl #align local_ring.residue_field.map_comp_residue LocalRing.ResidueField.map_comp_residue theorem map_residue (f : R →+* S) [IsLocalRingHom f] (r : R) : ResidueField.map f (residue R r) = residue S (f r) := rfl #align local_ring.residue_field.map_residue LocalRing.ResidueField.map_residue theorem map_id_apply (x : ResidueField R) : map (RingHom.id R) x = x := DFunLike.congr_fun map_id x #align local_ring.residue_field.map_id_apply LocalRing.ResidueField.map_id_apply @[simp] theorem map_map (f : R →+* S) (g : S →+* T) (x : ResidueField R) [IsLocalRingHom f] [IsLocalRingHom g] : map g (map f x) = map (g.comp f) x := DFunLike.congr_fun (map_comp f g).symm x #align local_ring.residue_field.map_map LocalRing.ResidueField.map_map /-- A ring isomorphism defines an isomorphism of residue fields. -/ @[simps apply] def mapEquiv (f : R ≃+* S) : LocalRing.ResidueField R ≃+* LocalRing.ResidueField S where toFun := map (f : R →+* S) invFun := map (f.symm : S →+* R) left_inv x := by simp only [map_map, RingEquiv.symm_comp, map_id, RingHom.id_apply] right_inv x := by simp only [map_map, RingEquiv.comp_symm, map_id, RingHom.id_apply] map_mul' := RingHom.map_mul _ map_add' := RingHom.map_add _ #align local_ring.residue_field.map_equiv LocalRing.ResidueField.mapEquiv @[simp] theorem mapEquiv.symm (f : R ≃+* S) : (mapEquiv f).symm = mapEquiv f.symm := rfl #align local_ring.residue_field.map_equiv.symm LocalRing.ResidueField.mapEquiv.symm @[simp] theorem mapEquiv_trans (e₁ : R ≃+* S) (e₂ : S ≃+* T) : mapEquiv (e₁.trans e₂) = (mapEquiv e₁).trans (mapEquiv e₂) := RingEquiv.toRingHom_injective <| map_comp (e₁ : R →+* S) (e₂ : S →+* T) #align local_ring.residue_field.map_equiv_trans LocalRing.ResidueField.mapEquiv_trans @[simp] theorem mapEquiv_refl : mapEquiv (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.toRingHom_injective map_id #align local_ring.residue_field.map_equiv_refl LocalRing.ResidueField.mapEquiv_refl /-- The group homomorphism from `RingAut R` to `RingAut k` where `k` is the residue field of `R`. -/ @[simps] def mapAut : RingAut R →* RingAut (LocalRing.ResidueField R) where toFun := mapEquiv map_mul' e₁ e₂ := mapEquiv_trans e₂ e₁ map_one' := mapEquiv_refl #align local_ring.residue_field.map_aut LocalRing.ResidueField.mapAut section MulSemiringAction variable (G : Type*) [Group G] [MulSemiringAction G R] /-- If `G` acts on `R` as a `MulSemiringAction`, then it also acts on `LocalRing.ResidueField R`. -/ instance : MulSemiringAction G (LocalRing.ResidueField R) := MulSemiringAction.compHom _ <| mapAut.comp (MulSemiringAction.toRingAut G R) @[simp] theorem residue_smul (g : G) (r : R) : residue R (g • r) = g • residue R r := rfl #align local_ring.residue_field.residue_smul LocalRing.ResidueField.residue_smul end MulSemiringAction end ResidueField theorem ker_eq_maximalIdeal [Field K] (φ : R →+* K) (hφ : Function.Surjective φ) : RingHom.ker φ = maximalIdeal R := LocalRing.eq_maximalIdeal <| (RingHom.ker_isMaximal_of_surjective φ) hφ #align local_ring.ker_eq_maximal_ideal LocalRing.ker_eq_maximalIdeal
Mathlib/RingTheory/Ideal/LocalRing.lean
507
512
theorem isLocalRingHom_residue : IsLocalRingHom (LocalRing.residue R) := by
constructor intro a ha by_contra h erw [Ideal.Quotient.eq_zero_iff_mem.mpr ((LocalRing.mem_maximalIdeal _).mpr h)] at ha exact ha.ne_zero rfl
/- 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.Perfect import Mathlib.Topology.MetricSpace.Polish import Mathlib.Topology.MetricSpace.CantorScheme #align_import topology.perfect from "leanprover-community/mathlib"@"3905fa80e62c0898131285baab35559fbc4e5cda" /-! # Perfect Sets In this file we define properties of `Perfect` subsets of a metric space, including a version of the Cantor-Bendixson Theorem. ## Main Statements * `Perfect.exists_nat_bool_injection`: A perfect nonempty set in a complete metric space admits an embedding from the Cantor space. ## References * [kechris1995] (Chapters 6-7) ## Tags accumulation point, perfect set, cantor-bendixson. --/ open Set Filter section CantorInjMetric open Function ENNReal variable {α : Type*} [MetricSpace α] {C : Set α} (hC : Perfect C) {ε : ℝ≥0∞} private theorem Perfect.small_diam_aux (ε_pos : 0 < ε) {x : α} (xC : x ∈ C) : let D := closure (EMetric.ball x (ε / 2) ∩ C) Perfect D ∧ D.Nonempty ∧ D ⊆ C ∧ EMetric.diam D ≤ ε := by have : x ∈ EMetric.ball x (ε / 2) := by apply EMetric.mem_ball_self rw [ENNReal.div_pos_iff] exact ⟨ne_of_gt ε_pos, by norm_num⟩ have := hC.closure_nhds_inter x xC this EMetric.isOpen_ball refine ⟨this.1, this.2, ?_, ?_⟩ · rw [IsClosed.closure_subset_iff hC.closed] apply inter_subset_right rw [EMetric.diam_closure] apply le_trans (EMetric.diam_mono inter_subset_left) convert EMetric.diam_ball (x := x) rw [mul_comm, ENNReal.div_mul_cancel] <;> norm_num variable (hnonempty : C.Nonempty) /-- A refinement of `Perfect.splitting` for metric spaces, where we also control the diameter of the new perfect sets. -/ theorem Perfect.small_diam_splitting (ε_pos : 0 < ε) : ∃ C₀ C₁ : Set α, (Perfect C₀ ∧ C₀.Nonempty ∧ C₀ ⊆ C ∧ EMetric.diam C₀ ≤ ε) ∧ (Perfect C₁ ∧ C₁.Nonempty ∧ C₁ ⊆ C ∧ EMetric.diam C₁ ≤ ε) ∧ Disjoint C₀ C₁ := by rcases hC.splitting hnonempty with ⟨D₀, D₁, ⟨perf0, non0, sub0⟩, ⟨perf1, non1, sub1⟩, hdisj⟩ cases' non0 with x₀ hx₀ cases' non1 with x₁ hx₁ rcases perf0.small_diam_aux ε_pos hx₀ with ⟨perf0', non0', sub0', diam0⟩ rcases perf1.small_diam_aux ε_pos hx₁ with ⟨perf1', non1', sub1', diam1⟩ refine ⟨closure (EMetric.ball x₀ (ε / 2) ∩ D₀), closure (EMetric.ball x₁ (ε / 2) ∩ D₁), ⟨perf0', non0', sub0'.trans sub0, diam0⟩, ⟨perf1', non1', sub1'.trans sub1, diam1⟩, ?_⟩ apply Disjoint.mono _ _ hdisj <;> assumption #align perfect.small_diam_splitting Perfect.small_diam_splitting open CantorScheme /-- Any nonempty perfect set in a complete metric space admits a continuous injection from the Cantor space, `ℕ → Bool`. -/ theorem Perfect.exists_nat_bool_injection [CompleteSpace α] : ∃ f : (ℕ → Bool) → α, range f ⊆ C ∧ Continuous f ∧ Injective f := by obtain ⟨u, -, upos', hu⟩ := exists_seq_strictAnti_tendsto' (zero_lt_one' ℝ≥0∞) have upos := fun n => (upos' n).1 let P := Subtype fun E : Set α => Perfect E ∧ E.Nonempty choose C0 C1 h0 h1 hdisj using fun {C : Set α} (hC : Perfect C) (hnonempty : C.Nonempty) {ε : ℝ≥0∞} (hε : 0 < ε) => hC.small_diam_splitting hnonempty hε let DP : List Bool → P := fun l => by induction' l with a l ih; · exact ⟨C, ⟨hC, hnonempty⟩⟩ cases a · use C0 ih.property.1 ih.property.2 (upos (l.length + 1)) exact ⟨(h0 _ _ _).1, (h0 _ _ _).2.1⟩ use C1 ih.property.1 ih.property.2 (upos (l.length + 1)) exact ⟨(h1 _ _ _).1, (h1 _ _ _).2.1⟩ let D : List Bool → Set α := fun l => (DP l).val have hanti : ClosureAntitone D := by refine Antitone.closureAntitone ?_ fun l => (DP l).property.1.closed intro l a cases a · exact (h0 _ _ _).2.2.1 exact (h1 _ _ _).2.2.1 have hdiam : VanishingDiam D := by intro x apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hu · simp rw [eventually_atTop] refine ⟨1, fun m (hm : 1 ≤ m) => ?_⟩ rw [Nat.one_le_iff_ne_zero] at hm rcases Nat.exists_eq_succ_of_ne_zero hm with ⟨n, rfl⟩ dsimp cases x n · convert (h0 _ _ _).2.2.2 rw [PiNat.res_length] convert (h1 _ _ _).2.2.2 rw [PiNat.res_length] have hdisj' : CantorScheme.Disjoint D := by rintro l (a | a) (b | b) hab <;> try contradiction · exact hdisj _ _ _ exact (hdisj _ _ _).symm have hdom : ∀ {x : ℕ → Bool}, x ∈ (inducedMap D).1 := fun {x} => by rw [hanti.map_of_vanishingDiam hdiam fun l => (DP l).property.2] apply mem_univ refine ⟨fun x => (inducedMap D).2 ⟨x, hdom⟩, ?_, ?_, ?_⟩ · rintro y ⟨x, rfl⟩ exact map_mem ⟨_, hdom⟩ 0 · apply hdiam.map_continuous.comp continuity intro x y hxy simpa only [← Subtype.val_inj] using hdisj'.map_injective hxy #align perfect.exists_nat_bool_injection Perfect.exists_nat_bool_injection end CantorInjMetric /-- Any closed uncountable subset of a Polish space admits a continuous injection from the Cantor space `ℕ → Bool`. -/
Mathlib/Topology/MetricSpace/Perfect.lean
136
142
theorem IsClosed.exists_nat_bool_injection_of_not_countable {α : Type*} [TopologicalSpace α] [PolishSpace α] {C : Set α} (hC : IsClosed C) (hunc : ¬C.Countable) : ∃ f : (ℕ → Bool) → α, range f ⊆ C ∧ Continuous f ∧ Function.Injective f := by
letI := upgradePolishSpace α obtain ⟨D, hD, Dnonempty, hDC⟩ := exists_perfect_nonempty_of_isClosed_of_not_countable hC hunc obtain ⟨f, hfD, hf⟩ := hD.exists_nat_bool_injection Dnonempty exact ⟨f, hfD.trans hDC, hf⟩
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Choose.Basic import Mathlib.Data.List.Perm import Mathlib.Data.List.Range #align_import data.list.sublists from "leanprover-community/mathlib"@"ccad6d5093bd2f5c6ca621fc74674cce51355af6" /-! # sublists `List.Sublists` gives a list of all (not necessarily contiguous) sublists of a list. This file contains basic results on this function. -/ /- Porting note: various auxiliary definitions such as `sublists'_aux` were left out of the port because they were only used to prove properties of `sublists`, and these proofs have changed. -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} open Nat namespace List /-! ### sublists -/ @[simp] theorem sublists'_nil : sublists' (@nil α) = [[]] := rfl #align list.sublists'_nil List.sublists'_nil @[simp] theorem sublists'_singleton (a : α) : sublists' [a] = [[], [a]] := rfl #align list.sublists'_singleton List.sublists'_singleton #noalign list.map_sublists'_aux #noalign list.sublists'_aux_append #noalign list.sublists'_aux_eq_sublists' -- Porting note: Not the same as `sublists'_aux` from Lean3 /-- Auxiliary helper definition for `sublists'` -/ def sublists'Aux (a : α) (r₁ r₂ : List (List α)) : List (List α) := r₁.foldl (init := r₂) fun r l => r ++ [a :: l] #align list.sublists'_aux List.sublists'Aux theorem sublists'Aux_eq_array_foldl (a : α) : ∀ (r₁ r₂ : List (List α)), sublists'Aux a r₁ r₂ = ((r₁.toArray).foldl (init := r₂.toArray) (fun r l => r.push (a :: l))).toList := by intro r₁ r₂ rw [sublists'Aux, Array.foldl_eq_foldl_data] have := List.foldl_hom Array.toList (fun r l => r.push (a :: l)) (fun r l => r ++ [a :: l]) r₁ r₂.toArray (by simp) simpa using this theorem sublists'_eq_sublists'Aux (l : List α) : sublists' l = l.foldr (fun a r => sublists'Aux a r r) [[]] := by simp only [sublists', sublists'Aux_eq_array_foldl] rw [← List.foldr_hom Array.toList] · rfl · intros _ _; congr <;> simp theorem sublists'Aux_eq_map (a : α) (r₁ : List (List α)) : ∀ (r₂ : List (List α)), sublists'Aux a r₁ r₂ = r₂ ++ map (cons a) r₁ := List.reverseRecOn r₁ (fun _ => by simp [sublists'Aux]) fun r₁ l ih r₂ => by rw [map_append, map_singleton, ← append_assoc, ← ih, sublists'Aux, foldl_append, foldl] simp [sublists'Aux] -- Porting note: simp can prove `sublists'_singleton` @[simp 900] theorem sublists'_cons (a : α) (l : List α) : sublists' (a :: l) = sublists' l ++ map (cons a) (sublists' l) := by simp [sublists'_eq_sublists'Aux, foldr_cons, sublists'Aux_eq_map] #align list.sublists'_cons List.sublists'_cons @[simp] theorem mem_sublists' {s t : List α} : s ∈ sublists' t ↔ s <+ t := by induction' t with a t IH generalizing s · simp only [sublists'_nil, mem_singleton] exact ⟨fun h => by rw [h], eq_nil_of_sublist_nil⟩ simp only [sublists'_cons, mem_append, IH, mem_map] constructor <;> intro h · rcases h with (h | ⟨s, h, rfl⟩) · exact sublist_cons_of_sublist _ h · exact h.cons_cons _ · cases' h with _ _ _ h s _ _ h · exact Or.inl h · exact Or.inr ⟨s, h, rfl⟩ #align list.mem_sublists' List.mem_sublists' @[simp] theorem length_sublists' : ∀ l : List α, length (sublists' l) = 2 ^ length l | [] => rfl | a :: l => by simp_arith only [sublists'_cons, length_append, length_sublists' l, length_map, length, Nat.pow_succ'] #align list.length_sublists' List.length_sublists' @[simp] theorem sublists_nil : sublists (@nil α) = [[]] := rfl #align list.sublists_nil List.sublists_nil @[simp] theorem sublists_singleton (a : α) : sublists [a] = [[], [a]] := rfl #align list.sublists_singleton List.sublists_singleton -- Porting note: Not the same as `sublists_aux` from Lean3 /-- Auxiliary helper function for `sublists` -/ def sublistsAux (a : α) (r : List (List α)) : List (List α) := r.foldl (init := []) fun r l => r ++ [l, a :: l] #align list.sublists_aux List.sublistsAux theorem sublistsAux_eq_array_foldl : sublistsAux = fun (a : α) (r : List (List α)) => (r.toArray.foldl (init := #[]) fun r l => (r.push l).push (a :: l)).toList := by funext a r simp only [sublistsAux, Array.foldl_eq_foldl_data, Array.mkEmpty] have := foldl_hom Array.toList (fun r l => (r.push l).push (a :: l)) (fun (r : List (List α)) l => r ++ [l, a :: l]) r #[] (by simp) simpa using this theorem sublistsAux_eq_bind : sublistsAux = fun (a : α) (r : List (List α)) => r.bind fun l => [l, a :: l] := funext fun a => funext fun r => List.reverseRecOn r (by simp [sublistsAux]) (fun r l ih => by rw [append_bind, ← ih, bind_singleton, sublistsAux, foldl_append] simp [sublistsAux]) @[csimp] theorem sublists_eq_sublistsFast : @sublists = @sublistsFast := by ext α l : 2 trans l.foldr sublistsAux [[]] · rw [sublistsAux_eq_bind, sublists] · simp only [sublistsFast, sublistsAux_eq_array_foldl, Array.foldr_eq_foldr_data] rw [← foldr_hom Array.toList] · rfl · intros _ _; congr <;> simp #noalign list.sublists_aux₁_eq_sublists_aux #noalign list.sublists_aux_cons_eq_sublists_aux₁ #noalign list.sublists_aux_eq_foldr.aux #noalign list.sublists_aux_eq_foldr #noalign list.sublists_aux_cons_cons #noalign list.sublists_aux₁_append #noalign list.sublists_aux₁_concat #noalign list.sublists_aux₁_bind #noalign list.sublists_aux_cons_append theorem sublists_append (l₁ l₂ : List α) : sublists (l₁ ++ l₂) = (sublists l₂) >>= (fun x => (sublists l₁).map (· ++ x)) := by simp only [sublists, foldr_append] induction l₁ with | nil => simp | cons a l₁ ih => rw [foldr_cons, ih] simp [List.bind, join_join, Function.comp] #align list.sublists_append List.sublists_append -- Porting note (#10756): new theorem theorem sublists_cons (a : α) (l : List α) : sublists (a :: l) = sublists l >>= (fun x => [x, a :: x]) := show sublists ([a] ++ l) = _ by rw [sublists_append] simp only [sublists_singleton, map_cons, bind_eq_bind, nil_append, cons_append, map_nil] @[simp] theorem sublists_concat (l : List α) (a : α) : sublists (l ++ [a]) = sublists l ++ map (fun x => x ++ [a]) (sublists l) := by rw [sublists_append, sublists_singleton, bind_eq_bind, cons_bind, cons_bind, nil_bind, map_id'' append_nil, append_nil] #align list.sublists_concat List.sublists_concat theorem sublists_reverse (l : List α) : sublists (reverse l) = map reverse (sublists' l) := by induction' l with hd tl ih <;> [rfl; simp only [reverse_cons, sublists_append, sublists'_cons, map_append, ih, sublists_singleton, map_eq_map, bind_eq_bind, map_map, cons_bind, append_nil, nil_bind, (· ∘ ·)]] #align list.sublists_reverse List.sublists_reverse theorem sublists_eq_sublists' (l : List α) : sublists l = map reverse (sublists' (reverse l)) := by rw [← sublists_reverse, reverse_reverse] #align list.sublists_eq_sublists' List.sublists_eq_sublists' theorem sublists'_reverse (l : List α) : sublists' (reverse l) = map reverse (sublists l) := by simp only [sublists_eq_sublists', map_map, map_id'' reverse_reverse, Function.comp] #align list.sublists'_reverse List.sublists'_reverse theorem sublists'_eq_sublists (l : List α) : sublists' l = map reverse (sublists (reverse l)) := by rw [← sublists'_reverse, reverse_reverse] #align list.sublists'_eq_sublists List.sublists'_eq_sublists #noalign list.sublists_aux_ne_nil @[simp] theorem mem_sublists {s t : List α} : s ∈ sublists t ↔ s <+ t := by rw [← reverse_sublist, ← mem_sublists', sublists'_reverse, mem_map_of_injective reverse_injective] #align list.mem_sublists List.mem_sublists @[simp] theorem length_sublists (l : List α) : length (sublists l) = 2 ^ length l := by simp only [sublists_eq_sublists', length_map, length_sublists', length_reverse] #align list.length_sublists List.length_sublists theorem map_pure_sublist_sublists (l : List α) : map pure l <+ sublists l := by induction' l using reverseRecOn with l a ih <;> simp only [map, map_append, sublists_concat] · simp only [sublists_nil, sublist_cons] exact ((append_sublist_append_left _).2 <| singleton_sublist.2 <| mem_map.2 ⟨[], mem_sublists.2 (nil_sublist _), by rfl⟩).trans ((append_sublist_append_right _).2 ih) #align list.map_ret_sublist_sublists List.map_pure_sublist_sublists set_option linter.deprecated false in @[deprecated map_pure_sublist_sublists (since := "2024-03-24")] theorem map_ret_sublist_sublists (l : List α) : map List.ret l <+ sublists l := map_pure_sublist_sublists l /-! ### sublistsLen -/ /-- Auxiliary function to construct the list of all sublists of a given length. Given an integer `n`, a list `l`, a function `f` and an auxiliary list `L`, it returns the list made of `f` applied to all sublists of `l` of length `n`, concatenated with `L`. -/ def sublistsLenAux : ℕ → List α → (List α → β) → List β → List β | 0, _, f, r => f [] :: r | _ + 1, [], _, r => r | n + 1, a :: l, f, r => sublistsLenAux (n + 1) l f (sublistsLenAux n l (f ∘ List.cons a) r) #align list.sublists_len_aux List.sublistsLenAux /-- The list of all sublists of a list `l` that are of length `n`. For instance, for `l = [0, 1, 2, 3]` and `n = 2`, one gets `[[2, 3], [1, 3], [1, 2], [0, 3], [0, 2], [0, 1]]`. -/ def sublistsLen (n : ℕ) (l : List α) : List (List α) := sublistsLenAux n l id [] #align list.sublists_len List.sublistsLen theorem sublistsLenAux_append : ∀ (n : ℕ) (l : List α) (f : List α → β) (g : β → γ) (r : List β) (s : List γ), sublistsLenAux n l (g ∘ f) (r.map g ++ s) = (sublistsLenAux n l f r).map g ++ s | 0, l, f, g, r, s => by unfold sublistsLenAux; simp | n + 1, [], f, g, r, s => rfl | n + 1, a :: l, f, g, r, s => by unfold sublistsLenAux simp only [show (g ∘ f) ∘ List.cons a = g ∘ f ∘ List.cons a by rfl, sublistsLenAux_append, sublistsLenAux_append] #align list.sublists_len_aux_append List.sublistsLenAux_append theorem sublistsLenAux_eq (l : List α) (n) (f : List α → β) (r) : sublistsLenAux n l f r = (sublistsLen n l).map f ++ r := by rw [sublistsLen, ← sublistsLenAux_append]; rfl #align list.sublists_len_aux_eq List.sublistsLenAux_eq theorem sublistsLenAux_zero (l : List α) (f : List α → β) (r) : sublistsLenAux 0 l f r = f [] :: r := by cases l <;> rfl #align list.sublists_len_aux_zero List.sublistsLenAux_zero @[simp] theorem sublistsLen_zero (l : List α) : sublistsLen 0 l = [[]] := sublistsLenAux_zero _ _ _ #align list.sublists_len_zero List.sublistsLen_zero @[simp] theorem sublistsLen_succ_nil (n) : sublistsLen (n + 1) (@nil α) = [] := rfl #align list.sublists_len_succ_nil List.sublistsLen_succ_nil @[simp]
Mathlib/Data/List/Sublists.lean
276
279
theorem sublistsLen_succ_cons (n) (a : α) (l) : sublistsLen (n + 1) (a :: l) = sublistsLen (n + 1) l ++ (sublistsLen n l).map (cons a) := by
rw [sublistsLen, sublistsLenAux, sublistsLenAux_eq, sublistsLenAux_eq, map_id, append_nil]; rfl
/- 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.MeasureTheory.Integral.Lebesgue /-! # Measure with a given density with respect to another measure For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`. On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`. An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures `μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to `ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that `μ = ν.withDensity f`. See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`. -/ open Set hiding restrict restrict_apply open Filter ENNReal NNReal MeasureTheory.Measure namespace MeasureTheory variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α} /-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/ noncomputable def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α := Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun s hs hd => lintegral_iUnion hs hd _ #align measure_theory.measure.with_density MeasureTheory.Measure.withDensity @[simp] theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := Measure.ofMeasurable_apply s hs #align measure_theory.with_density_apply MeasureTheory.withDensity_apply theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by let t := toMeasurable (μ.withDensity f) s calc ∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ := lintegral_mono_set (subset_toMeasurable (withDensity μ f) s) _ = μ.withDensity f t := (withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm _ = μ.withDensity f s := measure_toMeasurable s /-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then * `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then `∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim. * `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets `t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then `μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`. One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not containing `x₀`, and infinite mass to those that contain it. -/ theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by apply le_antisymm ?_ (withDensity_apply_le f s) let t := toMeasurable μ s calc μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s) _ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s) _ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s @[simp] lemma withDensity_zero_left (f : α → ℝ≥0∞) : (0 : Measure α).withDensity f = 0 := by ext s hs rw [withDensity_apply _ hs] simp theorem withDensity_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : μ.withDensity f = μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] exact lintegral_congr_ae (ae_restrict_of_ae h) #align measure_theory.with_density_congr_ae MeasureTheory.withDensity_congr_ae lemma withDensity_mono {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) : μ.withDensity f ≤ μ.withDensity g := by refine le_iff.2 fun s hs ↦ ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] refine set_lintegral_mono_ae' hs ?_ filter_upwards [hfg] with x h_le using fun _ ↦ h_le theorem withDensity_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.add_apply, withDensity_apply _ hs, withDensity_apply _ hs, ← lintegral_add_left hf] simp only [Pi.add_apply] #align measure_theory.with_density_add_left MeasureTheory.withDensity_add_left theorem withDensity_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by simpa only [add_comm] using withDensity_add_left hg f #align measure_theory.with_density_add_right MeasureTheory.withDensity_add_right theorem withDensity_add_measure {m : MeasurableSpace α} (μ ν : Measure α) (f : α → ℝ≥0∞) : (μ + ν).withDensity f = μ.withDensity f + ν.withDensity f := by ext1 s hs simp only [withDensity_apply f hs, restrict_add, lintegral_add_measure, Measure.add_apply] #align measure_theory.with_density_add_measure MeasureTheory.withDensity_add_measure theorem withDensity_sum {ι : Type*} {m : MeasurableSpace α} (μ : ι → Measure α) (f : α → ℝ≥0∞) : (sum μ).withDensity f = sum fun n => (μ n).withDensity f := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply f hs, restrict_sum μ hs, lintegral_sum_measure] #align measure_theory.with_density_sum MeasureTheory.withDensity_sum theorem withDensity_smul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul r hf] simp only [Pi.smul_apply, smul_eq_mul] #align measure_theory.with_density_smul MeasureTheory.withDensity_smul theorem withDensity_smul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul' r f hr] simp only [Pi.smul_apply, smul_eq_mul] #align measure_theory.with_density_smul' MeasureTheory.withDensity_smul' theorem withDensity_smul_measure (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (r • μ).withDensity f = r • μ.withDensity f := by ext s hs rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, set_lintegral_smul_measure] theorem isFiniteMeasure_withDensity {f : α → ℝ≥0∞} (hf : ∫⁻ a, f a ∂μ ≠ ∞) : IsFiniteMeasure (μ.withDensity f) := { measure_univ_lt_top := by rwa [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, lt_top_iff_ne_top] } #align measure_theory.is_finite_measure_with_density MeasureTheory.isFiniteMeasure_withDensity theorem withDensity_absolutelyContinuous {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : μ.withDensity f ≪ μ := by refine AbsolutelyContinuous.mk fun s hs₁ hs₂ => ?_ rw [withDensity_apply _ hs₁] exact set_lintegral_measure_zero _ _ hs₂ #align measure_theory.with_density_absolutely_continuous MeasureTheory.withDensity_absolutelyContinuous @[simp] theorem withDensity_zero : μ.withDensity 0 = 0 := by ext1 s hs simp [withDensity_apply _ hs] #align measure_theory.with_density_zero MeasureTheory.withDensity_zero @[simp] theorem withDensity_one : μ.withDensity 1 = μ := by ext1 s hs simp [withDensity_apply _ hs] #align measure_theory.with_density_one MeasureTheory.withDensity_one @[simp] theorem withDensity_const (c : ℝ≥0∞) : μ.withDensity (fun _ ↦ c) = c • μ := by ext1 s hs simp [withDensity_apply _ hs] theorem withDensity_tsum {f : ℕ → α → ℝ≥0∞} (h : ∀ i, Measurable (f i)) : μ.withDensity (∑' n, f n) = sum fun n => μ.withDensity (f n) := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply _ hs] change ∫⁻ x in s, (∑' n, f n) x ∂μ = ∑' i : ℕ, ∫⁻ x, f i x ∂μ.restrict s rw [← lintegral_tsum fun i => (h i).aemeasurable] exact lintegral_congr fun x => tsum_apply (Pi.summable.2 fun _ => ENNReal.summable) #align measure_theory.with_density_tsum MeasureTheory.withDensity_tsum theorem withDensity_indicator {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : μ.withDensity (s.indicator f) = (μ.restrict s).withDensity f := by ext1 t ht rw [withDensity_apply _ ht, lintegral_indicator _ hs, restrict_comm hs, ← withDensity_apply _ ht] #align measure_theory.with_density_indicator MeasureTheory.withDensity_indicator theorem withDensity_indicator_one {s : Set α} (hs : MeasurableSet s) : μ.withDensity (s.indicator 1) = μ.restrict s := by rw [withDensity_indicator hs, withDensity_one] #align measure_theory.with_density_indicator_one MeasureTheory.withDensity_indicator_one theorem withDensity_ofReal_mutuallySingular {f : α → ℝ} (hf : Measurable f) : (μ.withDensity fun x => ENNReal.ofReal <| f x) ⟂ₘ μ.withDensity fun x => ENNReal.ofReal <| -f x := by set S : Set α := { x | f x < 0 } have hS : MeasurableSet S := measurableSet_lt hf measurable_const refine ⟨S, hS, ?_, ?_⟩ · rw [withDensity_apply _ hS, lintegral_eq_zero_iff hf.ennreal_ofReal, EventuallyEq] exact (ae_restrict_mem hS).mono fun x hx => ENNReal.ofReal_eq_zero.2 (le_of_lt hx) · rw [withDensity_apply _ hS.compl, lintegral_eq_zero_iff hf.neg.ennreal_ofReal, EventuallyEq] exact (ae_restrict_mem hS.compl).mono fun x hx => ENNReal.ofReal_eq_zero.2 (not_lt.1 <| mt neg_pos.1 hx) #align measure_theory.with_density_of_real_mutually_singular MeasureTheory.withDensity_ofReal_mutuallySingular theorem restrict_withDensity {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : (μ.withDensity f).restrict s = (μ.restrict s).withDensity f := by ext1 t ht rw [restrict_apply ht, withDensity_apply _ ht, withDensity_apply _ (ht.inter hs), restrict_restrict ht] #align measure_theory.restrict_with_density MeasureTheory.restrict_withDensity theorem restrict_withDensity' [SFinite μ] (s : Set α) (f : α → ℝ≥0∞) : (μ.withDensity f).restrict s = (μ.restrict s).withDensity f := by ext1 t ht rw [restrict_apply ht, withDensity_apply _ ht, withDensity_apply' _ (t ∩ s), restrict_restrict ht] lemma trim_withDensity {m m0 : MeasurableSpace α} {μ : Measure α} (hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : Measurable[m] f) : (μ.withDensity f).trim hm = (μ.trim hm).withDensity f := by refine @Measure.ext _ m _ _ (fun s hs ↦ ?_) rw [withDensity_apply _ hs, restrict_trim _ _ hs, lintegral_trim _ hf, trim_measurableSet_eq _ hs, withDensity_apply _ (hm s hs)] lemma Measure.MutuallySingular.withDensity {ν : Measure α} {f : α → ℝ≥0∞} (h : μ ⟂ₘ ν) : μ.withDensity f ⟂ₘ ν := MutuallySingular.mono_ac h (withDensity_absolutelyContinuous _ _) AbsolutelyContinuous.rfl theorem withDensity_eq_zero {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (h : μ.withDensity f = 0) : f =ᵐ[μ] 0 := by rw [← lintegral_eq_zero_iff' hf, ← set_lintegral_univ, ← withDensity_apply _ MeasurableSet.univ, h, Measure.coe_zero, Pi.zero_apply] #align measure_theory.with_density_eq_zero MeasureTheory.withDensity_eq_zero @[simp] theorem withDensity_eq_zero_iff {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : μ.withDensity f = 0 ↔ f =ᵐ[μ] 0 := ⟨withDensity_eq_zero hf, fun h => withDensity_zero (μ := μ) ▸ withDensity_congr_ae h⟩ theorem withDensity_apply_eq_zero' {f : α → ℝ≥0∞} {s : Set α} (hf : AEMeasurable f μ) : μ.withDensity f s = 0 ↔ μ ({ x | f x ≠ 0 } ∩ s) = 0 := by constructor · intro hs let t := toMeasurable (μ.withDensity f) s apply measure_mono_null (inter_subset_inter_right _ (subset_toMeasurable (μ.withDensity f) s)) have A : μ.withDensity f t = 0 := by rw [measure_toMeasurable, hs] rw [withDensity_apply f (measurableSet_toMeasurable _ s), lintegral_eq_zero_iff' (AEMeasurable.restrict hf), EventuallyEq, ae_restrict_iff'₀, ae_iff] at A swap · simp only [measurableSet_toMeasurable, MeasurableSet.nullMeasurableSet] simp only [Pi.zero_apply, mem_setOf_eq, Filter.mem_mk] at A convert A using 2 ext x simp only [and_comm, exists_prop, mem_inter_iff, iff_self_iff, mem_setOf_eq, mem_compl_iff, not_forall] · intro hs let t := toMeasurable μ ({ x | f x ≠ 0 } ∩ s) have A : s ⊆ t ∪ { x | f x = 0 } := by intro x hx rcases eq_or_ne (f x) 0 with (fx | fx) · simp only [fx, mem_union, mem_setOf_eq, eq_self_iff_true, or_true_iff] · left apply subset_toMeasurable _ _ exact ⟨fx, hx⟩ apply measure_mono_null A (measure_union_null _ _) · apply withDensity_absolutelyContinuous rwa [measure_toMeasurable] rcases hf with ⟨g, hg, hfg⟩ have t : {x | f x = 0} =ᵐ[μ.withDensity f] {x | g x = 0} := by apply withDensity_absolutelyContinuous filter_upwards [hfg] with a ha rw [eq_iff_iff] exact ⟨fun h ↦ by rw [h] at ha; exact ha.symm, fun h ↦ by rw [h] at ha; exact ha⟩ rw [measure_congr t, withDensity_congr_ae hfg] have M : MeasurableSet { x : α | g x = 0 } := hg (measurableSet_singleton _) rw [withDensity_apply _ M, lintegral_eq_zero_iff hg] filter_upwards [ae_restrict_mem M] simp only [imp_self, Pi.zero_apply, imp_true_iff] theorem withDensity_apply_eq_zero {f : α → ℝ≥0∞} {s : Set α} (hf : Measurable f) : μ.withDensity f s = 0 ↔ μ ({ x | f x ≠ 0 } ∩ s) = 0 := withDensity_apply_eq_zero' <| hf.aemeasurable #align measure_theory.with_density_apply_eq_zero MeasureTheory.withDensity_apply_eq_zero theorem ae_withDensity_iff' {p : α → Prop} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ, f x ≠ 0 → p x := by rw [ae_iff, ae_iff, withDensity_apply_eq_zero' hf, iff_iff_eq] congr ext x simp only [exists_prop, mem_inter_iff, iff_self_iff, mem_setOf_eq, not_forall] theorem ae_withDensity_iff {p : α → Prop} {f : α → ℝ≥0∞} (hf : Measurable f) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ, f x ≠ 0 → p x := ae_withDensity_iff' <| hf.aemeasurable #align measure_theory.ae_with_density_iff MeasureTheory.ae_withDensity_iff theorem ae_withDensity_iff_ae_restrict' {p : α → Prop} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ.restrict { x | f x ≠ 0 }, p x := by rw [ae_withDensity_iff' hf, ae_restrict_iff'₀] · simp only [mem_setOf] · rcases hf with ⟨g, hg, hfg⟩ have nonneg_eq_ae : {x | g x ≠ 0} =ᵐ[μ] {x | f x ≠ 0} := by filter_upwards [hfg] with a ha simp only [eq_iff_iff] exact ⟨fun (h : g a ≠ 0) ↦ by rwa [← ha] at h, fun (h : f a ≠ 0) ↦ by rwa [ha] at h⟩ exact NullMeasurableSet.congr (MeasurableSet.nullMeasurableSet <| hg (measurableSet_singleton _)).compl nonneg_eq_ae theorem ae_withDensity_iff_ae_restrict {p : α → Prop} {f : α → ℝ≥0∞} (hf : Measurable f) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ.restrict { x | f x ≠ 0 }, p x := ae_withDensity_iff_ae_restrict' <| hf.aemeasurable #align measure_theory.ae_with_density_iff_ae_restrict MeasureTheory.ae_withDensity_iff_ae_restrict theorem aemeasurable_withDensity_ennreal_iff' {f : α → ℝ≥0} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} : AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔ AEMeasurable (fun x => (f x : ℝ≥0∞) * g x) μ := by have t : ∃ f', Measurable f' ∧ f =ᵐ[μ] f' := hf rcases t with ⟨f', hf'_m, hf'_ae⟩ constructor · rintro ⟨g', g'meas, hg'⟩ have A : MeasurableSet {x | f' x ≠ 0} := hf'_m (measurableSet_singleton _).compl refine ⟨fun x => f' x * g' x, hf'_m.coe_nnreal_ennreal.smul g'meas, ?_⟩ apply ae_of_ae_restrict_of_ae_restrict_compl { x | f' x ≠ 0 } · rw [EventuallyEq, ae_withDensity_iff' hf.coe_nnreal_ennreal] at hg' rw [ae_restrict_iff' A] filter_upwards [hg', hf'_ae] with a ha h'a h_a_nonneg have : (f' a : ℝ≥0∞) ≠ 0 := by simpa only [Ne, ENNReal.coe_eq_zero] using h_a_nonneg rw [← h'a] at this ⊢ rw [ha this] · rw [ae_restrict_iff' A.compl] filter_upwards [hf'_ae] with a ha ha_null have ha_null : f' a = 0 := Function.nmem_support.mp ha_null rw [ha_null] at ha ⊢ rw [ha] simp only [ENNReal.coe_zero, zero_mul] · rintro ⟨g', g'meas, hg'⟩ refine ⟨fun x => ((f' x)⁻¹ : ℝ≥0∞) * g' x, hf'_m.coe_nnreal_ennreal.inv.smul g'meas, ?_⟩ rw [EventuallyEq, ae_withDensity_iff' hf.coe_nnreal_ennreal] filter_upwards [hg', hf'_ae] with a hfga hff'a h'a rw [hff'a] at hfga h'a rw [← hfga, ← mul_assoc, ENNReal.inv_mul_cancel h'a ENNReal.coe_ne_top, one_mul] theorem aemeasurable_withDensity_ennreal_iff {f : α → ℝ≥0} (hf : Measurable f) {g : α → ℝ≥0∞} : AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔ AEMeasurable (fun x => (f x : ℝ≥0∞) * g x) μ := aemeasurable_withDensity_ennreal_iff' <| hf.aemeasurable #align measure_theory.ae_measurable_with_density_ennreal_iff MeasureTheory.aemeasurable_withDensity_ennreal_iff open MeasureTheory.SimpleFunc /-- This is Exercise 1.2.1 from [tao2010]. It allows you to express integration of a measurable function with respect to `(μ.withDensity f)` as an integral with respect to `μ`, called the base measure. `μ` is often the Lebesgue measure, and in this circumstance `f` is the probability density function, and `(μ.withDensity f)` represents any continuous random variable as a probability measure, such as the uniform distribution between 0 and 1, the Gaussian distribution, the exponential distribution, the Beta distribution, or the Cauchy distribution (see Section 2.4 of [wasserman2004]). Thus, this method shows how to one can calculate expectations, variances, and other moments as a function of the probability density function. -/ theorem lintegral_withDensity_eq_lintegral_mul (μ : Measure α) {f : α → ℝ≥0∞} (h_mf : Measurable f) : ∀ {g : α → ℝ≥0∞}, Measurable g → ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by apply Measurable.ennreal_induction · intro c s h_ms simp [*, mul_comm _ c, ← indicator_mul_right] · intro g h _ h_mea_g _ h_ind_g h_ind_h simp [mul_add, *, Measurable.mul] · intro g h_mea_g h_mono_g h_ind have : Monotone fun n a => f a * g n a := fun m n hmn x => mul_le_mul_left' (h_mono_g hmn x) _ simp [lintegral_iSup, ENNReal.mul_iSup, h_mf.mul (h_mea_g _), *] #align measure_theory.lintegral_with_density_eq_lintegral_mul MeasureTheory.lintegral_withDensity_eq_lintegral_mul
Mathlib/MeasureTheory/Measure/WithDensity.lean
384
387
theorem set_lintegral_withDensity_eq_set_lintegral_mul (μ : Measure α) {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) {s : Set α} (hs : MeasurableSet s) : ∫⁻ x in s, g x ∂μ.withDensity f = ∫⁻ x in s, (f * g) x ∂μ := by
rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul _ hf hg]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attr import Mathlib.Data.Multiset.FinsetOps import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Basic #align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib.Data.Fintype.Basic`. There is also `univ'`, the noncomputable partner to `univ`, which is defined to be `α` as a finset if `α` is finite, and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`. `Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`. This is then used to define `Fintype.card`, the size of a type. ## Main declarations ### Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. * `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`, then it holds for the finset obtained by inserting a new element. * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Finset constructions * `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element. * `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements. * `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`. This convention is consistent with other languages and normalizes `card (range n) = n`. Beware, `n` is not in `range n`. * `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype `{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set. ### Finsets from functions * `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is the finset consisting of those elements in `s` satisfying the predicate `p`. ### The lattice structure on subsets of finsets There is a natural lattice structure on the subsets of a set. In Lean, we use lattice notation to talk about things involving unions and intersections. See `Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is called `top` with `⊤ = univ`. * `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect. * `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`. See `Finset.sup`/`Finset.biUnion` for finite unions. * `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`. See `Finset.inf` for finite intersections. ### Operations on two or more finsets * `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h` returns the same except that it requires a hypothesis stating that `a` is not already in `s`. This does not require decidable equality on the type `α`. * `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets" * `Finset.instInterFinset`: see "The lattice structure on subsets of finsets" * `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed. * `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`. * `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`. For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`. ### Predicates on finsets * `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their intersection is empty. * `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`. ### Equivalences between finsets * The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen assert_not_exists Multiset.Powerset assert_not_exists CompleteLattice open Multiset Subtype Nat Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val #align finset Finset instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ #align multiset.can_lift_finset Multiset.canLiftFinset namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl #align finset.eq_of_veq Finset.eq_of_veq theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq #align finset.val_injective Finset.val_injective @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff #align finset.val_inj Finset.val_inj @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup #align finset.dedup_eq_self Finset.dedup_eq_self instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj #align finset.has_decidable_eq Finset.decidableEq /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun a s => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl #align finset.mem_def Finset.mem_def @[simp] theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s := Iff.rfl #align finset.mem_val Finset.mem_val @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl #align finset.mem_mk Finset.mem_mk instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ #align finset.decidable_mem Finset.decidableMem @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ -- Porting note (#11445): new definition /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl #align finset.mem_coe Finset.mem_coe @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl #align finset.set_of_mem Finset.setOf_mem @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 #align finset.coe_mem Finset.coe_mem -- Porting note (#10618): @[simp] can prove this theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ #align finset.mk_coe Finset.mk_coe instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ #align finset.decidable_mem' Finset.decidableMem' /-! ### extensionality -/ theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans <| s₁.nodup.ext s₂.nodup #align finset.ext_iff Finset.ext_iff @[ext] theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext_iff.2 #align finset.ext Finset.ext @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans ext_iff.symm #align finset.coe_inj Finset.coe_inj theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 #align finset.coe_injective Finset.coe_injective /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ -- Porting note (#10618): @[simp] can prove this protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align finset.forall_coe Finset.forall_coe -- Porting note (#10618): @[simp] can prove this protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align finset.exists_coe Finset.exists_coe instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) #align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s #align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift' instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ #align finset.finset_coe.can_lift Finset.FinsetCoe.canLift @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl #align finset.coe_sort_coe Finset.coe_sort_coe /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl s a := id le_trans s t u hst htu a ha := htu <| hst ha le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩ instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl #align finset.subset_def Finset.subset_def theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl #align finset.ssubset_def Finset.ssubset_def @[simp] theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ #align finset.subset.refl Finset.Subset.refl protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ #align finset.subset.rfl Finset.Subset.rfl protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ #align finset.subset_of_eq Finset.subset_of_eq theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans #align finset.subset.trans Finset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' #align finset.superset.trans Finset.Superset.trans theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset #align finset.mem_of_subset Finset.mem_of_subset theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ #align finset.not_mem_mono Finset.not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ #align finset.subset.antisymm Finset.Subset.antisymm theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl #align finset.subset_iff Finset.subset_iff @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.coe_subset Finset.coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 #align finset.val_le_iff Finset.val_le_iff theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff #align finset.subset.antisymm_iff Finset.Subset.antisymm_iff theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe] #align finset.not_subset Finset.not_subset @[simp] theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) := rfl #align finset.le_eq_subset Finset.le_eq_subset @[simp] theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) := rfl #align finset.lt_eq_subset Finset.lt_eq_subset theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.le_iff_subset Finset.le_iff_subset theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := Iff.rfl #align finset.lt_iff_ssubset Finset.lt_iff_ssubset @[simp, norm_cast] theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ := show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset] #align finset.coe_ssubset Finset.coe_ssubset @[simp] theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff <| not_congr val_le_iff #align finset.val_lt_iff Finset.val_lt_iff lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2 theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne _ _ s t #align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ := Set.ssubset_iff_of_subset h #align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃ #align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃ #align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ := Set.exists_of_ssubset h #align finset.exists_of_ssubset Finset.exists_of_ssubset instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) := Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2 #align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset instance wellFoundedLT : WellFoundedLT (Finset α) := Finset.isWellFounded_ssubset #align finset.is_well_founded_lt Finset.wellFoundedLT end Subset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans /-! ### Order embedding from `Finset α` to `Set α` -/ /-- Coercion to `Set α` as an `OrderEmbedding`. -/ def coeEmb : Finset α ↪o Set α := ⟨⟨(↑), coe_injective⟩, coe_subset⟩ #align finset.coe_emb Finset.coeEmb @[simp] theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) := rfl #align finset.coe_coe_emb Finset.coe_coeEmb /-! ### Nonempty -/ /-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s #align finset.nonempty Finset.Nonempty -- Porting note: Much longer than in Lean3 instance decidableNonempty {s : Finset α} : Decidable s.Nonempty := Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1 (fun l : List α => match l with | [] => isFalse <| by simp | a::l => isTrue ⟨a, by simp⟩) #align finset.decidable_nonempty Finset.decidableNonempty @[simp, norm_cast] theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty := Iff.rfl #align finset.coe_nonempty Finset.coe_nonempty -- Porting note: Left-hand side simplifies @[simp] theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty := nonempty_subtype #align finset.nonempty_coe_sort Finset.nonempty_coe_sort alias ⟨_, Nonempty.to_set⟩ := coe_nonempty #align finset.nonempty.to_set Finset.Nonempty.to_set alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align finset.nonempty.coe_sort Finset.Nonempty.coe_sort theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s := h #align finset.nonempty.bex Finset.Nonempty.exists_mem @[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := Set.Nonempty.mono hst hs #align finset.nonempty.mono Finset.Nonempty.mono theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p := let ⟨x, hx⟩ := h ⟨fun h => h x hx, fun h _ _ => h⟩ #align finset.nonempty.forall_const Finset.Nonempty.forall_const theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s := nonempty_coe_sort.2 #align finset.nonempty.to_subtype Finset.Nonempty.to_subtype theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩ #align finset.nonempty.to_type Finset.Nonempty.to_type /-! ### empty -/ section Empty variable {s : Finset α} /-- The empty finset -/ protected def empty : Finset α := ⟨0, nodup_zero⟩ #align finset.empty Finset.empty instance : EmptyCollection (Finset α) := ⟨Finset.empty⟩ instance inhabitedFinset : Inhabited (Finset α) := ⟨∅⟩ #align finset.inhabited_finset Finset.inhabitedFinset @[simp] theorem empty_val : (∅ : Finset α).1 = 0 := rfl #align finset.empty_val Finset.empty_val @[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by -- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False` simp only [mem_def, empty_val, not_mem_zero, not_false_iff] #align finset.not_mem_empty Finset.not_mem_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx #align finset.not_nonempty_empty Finset.not_nonempty_empty @[simp] theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ := rfl #align finset.mk_zero Finset.mk_zero theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e => not_mem_empty a <| e ▸ h #align finset.ne_empty_of_mem Finset.ne_empty_of_mem theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ := (Exists.elim h) fun _a => ne_empty_of_mem #align finset.nonempty.ne_empty Finset.Nonempty.ne_empty @[simp] theorem empty_subset (s : Finset α) : ∅ ⊆ s := zero_subset _ #align finset.empty_subset Finset.empty_subset theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ := eq_of_veq (eq_zero_of_forall_not_mem H) #align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s := -- Porting note: used `id` ⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩ #align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem @[simp] theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅ #align finset.val_eq_zero Finset.val_eq_zero theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero #align finset.subset_empty Finset.subset_empty @[simp] theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h => let ⟨_, he, _⟩ := exists_of_ssubset h -- Porting note: was `he` not_mem_empty _ he #align finset.not_ssubset_empty Finset.not_ssubset_empty theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty := exists_mem_of_ne_zero (mt val_eq_zero.1 h) #align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ := ⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩ #align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty @[simp] theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ := nonempty_iff_ne_empty.not.trans not_not #align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty := by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h) #align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty @[simp, norm_cast] theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ := Set.ext <| by simp #align finset.coe_empty Finset.coe_empty @[simp, norm_cast] theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj] #align finset.coe_eq_empty Finset.coe_eq_empty -- Porting note: Left-hand side simplifies @[simp] theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by simpa using @Set.isEmpty_coe_sort α s #align finset.is_empty_coe_sort Finset.isEmpty_coe_sort instance instIsEmpty : IsEmpty (∅ : Finset α) := isEmpty_coe_sort.2 rfl /-- A `Finset` for an empty type is empty. -/ theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ := Finset.eq_empty_of_forall_not_mem isEmptyElim #align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty instance : OrderBot (Finset α) where bot := ∅ bot_le := empty_subset @[simp] theorem bot_eq_empty : (⊥ : Finset α) = ∅ := rfl #align finset.bot_eq_empty Finset.bot_eq_empty @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm #align finset.empty_ssubset Finset.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset end Empty /-! ### singleton -/ section Singleton variable {s : Finset α} {a b : α} /-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else. This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`. -/ instance : Singleton α (Finset α) := ⟨fun a => ⟨{a}, nodup_singleton a⟩⟩ @[simp] theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} := rfl #align finset.singleton_val Finset.singleton_val @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a := Multiset.mem_singleton #align finset.mem_singleton Finset.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y := mem_singleton.1 h #align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b := not_congr mem_singleton #align finset.not_mem_singleton Finset.not_mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) := -- Porting note: was `Or.inl rfl` mem_singleton.mpr rfl #align finset.mem_singleton_self Finset.mem_singleton_self @[simp] theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by rw [← val_inj] rfl #align finset.val_eq_singleton_iff Finset.val_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Finset α) := fun _a _b h => mem_singleton.1 (h ▸ mem_singleton_self _) #align finset.singleton_injective Finset.singleton_injective @[simp] theorem singleton_inj : ({a} : Finset α) = {b} ↔ a = b := singleton_injective.eq_iff #align finset.singleton_inj Finset.singleton_inj @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem singleton_nonempty (a : α) : ({a} : Finset α).Nonempty := ⟨a, mem_singleton_self a⟩ #align finset.singleton_nonempty Finset.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Finset α) ≠ ∅ := (singleton_nonempty a).ne_empty #align finset.singleton_ne_empty Finset.singleton_ne_empty theorem empty_ssubset_singleton : (∅ : Finset α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align finset.empty_ssubset_singleton Finset.empty_ssubset_singleton @[simp, norm_cast] theorem coe_singleton (a : α) : (({a} : Finset α) : Set α) = {a} := by ext simp #align finset.coe_singleton Finset.coe_singleton @[simp, norm_cast] theorem coe_eq_singleton {s : Finset α} {a : α} : (s : Set α) = {a} ↔ s = {a} := by rw [← coe_singleton, coe_inj] #align finset.coe_eq_singleton Finset.coe_eq_singleton @[norm_cast] lemma coe_subset_singleton : (s : Set α) ⊆ {a} ↔ s ⊆ {a} := by rw [← coe_subset, coe_singleton] @[norm_cast] lemma singleton_subset_coe : {a} ⊆ (s : Set α) ↔ {a} ⊆ s := by rw [← coe_subset, coe_singleton] theorem eq_singleton_iff_unique_mem {s : Finset α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := by constructor <;> intro t · rw [t] exact ⟨Finset.mem_singleton_self _, fun _ => Finset.mem_singleton.1⟩ · ext rw [Finset.mem_singleton] exact ⟨t.right _, fun r => r.symm ▸ t.left⟩ #align finset.eq_singleton_iff_unique_mem Finset.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem {s : Finset α} {a : α} : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := by constructor · rintro rfl simp · rintro ⟨hne, h_uniq⟩ rw [eq_singleton_iff_unique_mem] refine ⟨?_, h_uniq⟩ rw [← h_uniq hne.choose hne.choose_spec] exact hne.choose_spec #align finset.eq_singleton_iff_nonempty_unique_mem Finset.eq_singleton_iff_nonempty_unique_mem theorem nonempty_iff_eq_singleton_default [Unique α] {s : Finset α} : s.Nonempty ↔ s = {default} := by simp [eq_singleton_iff_nonempty_unique_mem, eq_iff_true_of_subsingleton] #align finset.nonempty_iff_eq_singleton_default Finset.nonempty_iff_eq_singleton_default alias ⟨Nonempty.eq_singleton_default, _⟩ := nonempty_iff_eq_singleton_default #align finset.nonempty.eq_singleton_default Finset.Nonempty.eq_singleton_default theorem singleton_iff_unique_mem (s : Finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s := by simp only [eq_singleton_iff_unique_mem, ExistsUnique] #align finset.singleton_iff_unique_mem Finset.singleton_iff_unique_mem theorem singleton_subset_set_iff {s : Set α} {a : α} : ↑({a} : Finset α) ⊆ s ↔ a ∈ s := by rw [coe_singleton, Set.singleton_subset_iff] #align finset.singleton_subset_set_iff Finset.singleton_subset_set_iff @[simp] theorem singleton_subset_iff {s : Finset α} {a : α} : {a} ⊆ s ↔ a ∈ s := singleton_subset_set_iff #align finset.singleton_subset_iff Finset.singleton_subset_iff @[simp] theorem subset_singleton_iff {s : Finset α} {a : α} : s ⊆ {a} ↔ s = ∅ ∨ s = {a} := by rw [← coe_subset, coe_singleton, Set.subset_singleton_iff_eq, coe_eq_empty, coe_eq_singleton] #align finset.subset_singleton_iff Finset.subset_singleton_iff theorem singleton_subset_singleton : ({a} : Finset α) ⊆ {b} ↔ a = b := by simp #align finset.singleton_subset_singleton Finset.singleton_subset_singleton protected theorem Nonempty.subset_singleton_iff {s : Finset α} {a : α} (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} := subset_singleton_iff.trans <| or_iff_right h.ne_empty #align finset.nonempty.subset_singleton_iff Finset.Nonempty.subset_singleton_iff theorem subset_singleton_iff' {s : Finset α} {a : α} : s ⊆ {a} ↔ ∀ b ∈ s, b = a := forall₂_congr fun _ _ => mem_singleton #align finset.subset_singleton_iff' Finset.subset_singleton_iff' @[simp] theorem ssubset_singleton_iff {s : Finset α} {a : α} : s ⊂ {a} ↔ s = ∅ := by rw [← coe_ssubset, coe_singleton, Set.ssubset_singleton_iff, coe_eq_empty] #align finset.ssubset_singleton_iff Finset.ssubset_singleton_iff theorem eq_empty_of_ssubset_singleton {s : Finset α} {x : α} (hs : s ⊂ {x}) : s = ∅ := ssubset_singleton_iff.1 hs #align finset.eq_empty_of_ssubset_singleton Finset.eq_empty_of_ssubset_singleton /-- A finset is nontrivial if it has at least two elements. -/ protected abbrev Nontrivial (s : Finset α) : Prop := (s : Set α).Nontrivial #align finset.nontrivial Finset.Nontrivial @[simp] theorem not_nontrivial_empty : ¬ (∅ : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_empty Finset.not_nontrivial_empty @[simp] theorem not_nontrivial_singleton : ¬ ({a} : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_singleton Finset.not_nontrivial_singleton theorem Nontrivial.ne_singleton (hs : s.Nontrivial) : s ≠ {a} := by rintro rfl; exact not_nontrivial_singleton hs #align finset.nontrivial.ne_singleton Finset.Nontrivial.ne_singleton nonrec lemma Nontrivial.exists_ne (hs : s.Nontrivial) (a : α) : ∃ b ∈ s, b ≠ a := hs.exists_ne _ theorem eq_singleton_or_nontrivial (ha : a ∈ s) : s = {a} ∨ s.Nontrivial := by rw [← coe_eq_singleton]; exact Set.eq_singleton_or_nontrivial ha #align finset.eq_singleton_or_nontrivial Finset.eq_singleton_or_nontrivial theorem nontrivial_iff_ne_singleton (ha : a ∈ s) : s.Nontrivial ↔ s ≠ {a} := ⟨Nontrivial.ne_singleton, (eq_singleton_or_nontrivial ha).resolve_left⟩ #align finset.nontrivial_iff_ne_singleton Finset.nontrivial_iff_ne_singleton theorem Nonempty.exists_eq_singleton_or_nontrivial : s.Nonempty → (∃ a, s = {a}) ∨ s.Nontrivial := fun ⟨a, ha⟩ => (eq_singleton_or_nontrivial ha).imp_left <| Exists.intro a #align finset.nonempty.exists_eq_singleton_or_nontrivial Finset.Nonempty.exists_eq_singleton_or_nontrivial instance instNontrivial [Nonempty α] : Nontrivial (Finset α) := ‹Nonempty α›.elim fun a => ⟨⟨{a}, ∅, singleton_ne_empty _⟩⟩ #align finset.nontrivial' Finset.instNontrivial instance [IsEmpty α] : Unique (Finset α) where default := ∅ uniq _ := eq_empty_of_forall_not_mem isEmptyElim instance (i : α) : Unique ({i} : Finset α) where default := ⟨i, mem_singleton_self i⟩ uniq j := Subtype.ext <| mem_singleton.mp j.2 @[simp] lemma default_singleton (i : α) : ((default : ({i} : Finset α)) : α) = i := rfl end Singleton /-! ### cons -/ section Cons variable {s t : Finset α} {a b : α} /-- `cons a s h` is the set `{a} ∪ s` containing `a` and the elements of `s`. It is the same as `insert a s` when it is defined, but unlike `insert a s` it does not require `DecidableEq α`, and the union is guaranteed to be disjoint. -/ def cons (a : α) (s : Finset α) (h : a ∉ s) : Finset α := ⟨a ::ₘ s.1, nodup_cons.2 ⟨h, s.2⟩⟩ #align finset.cons Finset.cons @[simp] theorem mem_cons {h} : b ∈ s.cons a h ↔ b = a ∨ b ∈ s := Multiset.mem_cons #align finset.mem_cons Finset.mem_cons theorem mem_cons_of_mem {a b : α} {s : Finset α} {hb : b ∉ s} (ha : a ∈ s) : a ∈ cons b s hb := Multiset.mem_cons_of_mem ha -- Porting note (#10618): @[simp] can prove this theorem mem_cons_self (a : α) (s : Finset α) {h} : a ∈ cons a s h := Multiset.mem_cons_self _ _ #align finset.mem_cons_self Finset.mem_cons_self @[simp] theorem cons_val (h : a ∉ s) : (cons a s h).1 = a ::ₘ s.1 := rfl #align finset.cons_val Finset.cons_val theorem forall_mem_cons (h : a ∉ s) (p : α → Prop) : (∀ x, x ∈ cons a s h → p x) ↔ p a ∧ ∀ x, x ∈ s → p x := by simp only [mem_cons, or_imp, forall_and, forall_eq] #align finset.forall_mem_cons Finset.forall_mem_cons /-- Useful in proofs by induction. -/ theorem forall_of_forall_cons {p : α → Prop} {h : a ∉ s} (H : ∀ x, x ∈ cons a s h → p x) (x) (h : x ∈ s) : p x := H _ <| mem_cons.2 <| Or.inr h #align finset.forall_of_forall_cons Finset.forall_of_forall_cons @[simp] theorem mk_cons {s : Multiset α} (h : (a ::ₘ s).Nodup) : (⟨a ::ₘ s, h⟩ : Finset α) = cons a ⟨s, (nodup_cons.1 h).2⟩ (nodup_cons.1 h).1 := rfl #align finset.mk_cons Finset.mk_cons @[simp] theorem cons_empty (a : α) : cons a ∅ (not_mem_empty _) = {a} := rfl #align finset.cons_empty Finset.cons_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_cons (h : a ∉ s) : (cons a s h).Nonempty := ⟨a, mem_cons.2 <| Or.inl rfl⟩ #align finset.nonempty_cons Finset.nonempty_cons @[simp] theorem nonempty_mk {m : Multiset α} {hm} : (⟨m, hm⟩ : Finset α).Nonempty ↔ m ≠ 0 := by induction m using Multiset.induction_on <;> simp #align finset.nonempty_mk Finset.nonempty_mk @[simp] theorem coe_cons {a s h} : (@cons α a s h : Set α) = insert a (s : Set α) := by ext simp #align finset.coe_cons Finset.coe_cons theorem subset_cons (h : a ∉ s) : s ⊆ s.cons a h := Multiset.subset_cons _ _ #align finset.subset_cons Finset.subset_cons theorem ssubset_cons (h : a ∉ s) : s ⊂ s.cons a h := Multiset.ssubset_cons h #align finset.ssubset_cons Finset.ssubset_cons theorem cons_subset {h : a ∉ s} : s.cons a h ⊆ t ↔ a ∈ t ∧ s ⊆ t := Multiset.cons_subset #align finset.cons_subset Finset.cons_subset @[simp] theorem cons_subset_cons {hs ht} : s.cons a hs ⊆ t.cons a ht ↔ s ⊆ t := by rwa [← coe_subset, coe_cons, coe_cons, Set.insert_subset_insert_iff, coe_subset] #align finset.cons_subset_cons Finset.cons_subset_cons theorem ssubset_iff_exists_cons_subset : s ⊂ t ↔ ∃ (a : _) (h : a ∉ s), s.cons a h ⊆ t := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_ssubset_of_subset (ssubset_cons _) h⟩ obtain ⟨a, hs, ht⟩ := not_subset.1 h.2 exact ⟨a, ht, cons_subset.2 ⟨hs, h.subset⟩⟩ #align finset.ssubset_iff_exists_cons_subset Finset.ssubset_iff_exists_cons_subset end Cons /-! ### disjoint -/ section Disjoint variable {f : α → β} {s t u : Finset α} {a b : α} theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t := ⟨fun h a hs ht => not_mem_empty a <| singleton_subset_iff.mp (h (singleton_subset_iff.mpr hs) (singleton_subset_iff.mpr ht)), fun h _ hs ht _ ha => (h (hs ha) (ht ha)).elim⟩ #align finset.disjoint_left Finset.disjoint_left theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [_root_.disjoint_comm, disjoint_left] #align finset.disjoint_right Finset.disjoint_right theorem disjoint_iff_ne : Disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b := by simp only [disjoint_left, imp_not_comm, forall_eq'] #align finset.disjoint_iff_ne Finset.disjoint_iff_ne @[simp] theorem disjoint_val : s.1.Disjoint t.1 ↔ Disjoint s t := disjoint_left.symm #align finset.disjoint_val Finset.disjoint_val theorem _root_.Disjoint.forall_ne_finset (h : Disjoint s t) (ha : a ∈ s) (hb : b ∈ t) : a ≠ b := disjoint_iff_ne.1 h _ ha _ hb #align disjoint.forall_ne_finset Disjoint.forall_ne_finset theorem not_disjoint_iff : ¬Disjoint s t ↔ ∃ a, a ∈ s ∧ a ∈ t := disjoint_left.not.trans <| not_forall.trans <| exists_congr fun _ => by rw [Classical.not_imp, not_not] #align finset.not_disjoint_iff Finset.not_disjoint_iff theorem disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := disjoint_left.2 fun _x m₁ => (disjoint_left.1 d) (h m₁) #align finset.disjoint_of_subset_left Finset.disjoint_of_subset_left theorem disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := disjoint_right.2 fun _x m₁ => (disjoint_right.1 d) (h m₁) #align finset.disjoint_of_subset_right Finset.disjoint_of_subset_right @[simp] theorem disjoint_empty_left (s : Finset α) : Disjoint ∅ s := disjoint_bot_left #align finset.disjoint_empty_left Finset.disjoint_empty_left @[simp] theorem disjoint_empty_right (s : Finset α) : Disjoint s ∅ := disjoint_bot_right #align finset.disjoint_empty_right Finset.disjoint_empty_right @[simp] theorem disjoint_singleton_left : Disjoint (singleton a) s ↔ a ∉ s := by simp only [disjoint_left, mem_singleton, forall_eq] #align finset.disjoint_singleton_left Finset.disjoint_singleton_left @[simp] theorem disjoint_singleton_right : Disjoint s (singleton a) ↔ a ∉ s := disjoint_comm.trans disjoint_singleton_left #align finset.disjoint_singleton_right Finset.disjoint_singleton_right -- Porting note: Left-hand side simplifies @[simp] theorem disjoint_singleton : Disjoint ({a} : Finset α) {b} ↔ a ≠ b := by rw [disjoint_singleton_left, mem_singleton] #align finset.disjoint_singleton Finset.disjoint_singleton theorem disjoint_self_iff_empty (s : Finset α) : Disjoint s s ↔ s = ∅ := disjoint_self #align finset.disjoint_self_iff_empty Finset.disjoint_self_iff_empty @[simp, norm_cast] theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by simp only [Finset.disjoint_left, Set.disjoint_left, mem_coe] #align finset.disjoint_coe Finset.disjoint_coe @[simp, norm_cast] theorem pairwiseDisjoint_coe {ι : Type*} {s : Set ι} {f : ι → Finset α} : s.PairwiseDisjoint (fun i => f i : ι → Set α) ↔ s.PairwiseDisjoint f := forall₅_congr fun _ _ _ _ _ => disjoint_coe #align finset.pairwise_disjoint_coe Finset.pairwiseDisjoint_coe end Disjoint /-! ### disjoint union -/ /-- `disjUnion s t h` is the set such that `a ∈ disjUnion s t h` iff `a ∈ s` or `a ∈ t`. It is the same as `s ∪ t`, but it does not require decidable equality on the type. The hypothesis ensures that the sets are disjoint. -/ def disjUnion (s t : Finset α) (h : Disjoint s t) : Finset α := ⟨s.1 + t.1, Multiset.nodup_add.2 ⟨s.2, t.2, disjoint_val.2 h⟩⟩ #align finset.disj_union Finset.disjUnion @[simp] theorem mem_disjUnion {α s t h a} : a ∈ @disjUnion α s t h ↔ a ∈ s ∨ a ∈ t := by rcases s with ⟨⟨s⟩⟩; rcases t with ⟨⟨t⟩⟩; apply List.mem_append #align finset.mem_disj_union Finset.mem_disjUnion @[simp, norm_cast] theorem coe_disjUnion {s t : Finset α} (h : Disjoint s t) : (disjUnion s t h : Set α) = (s : Set α) ∪ t := Set.ext <| by simp theorem disjUnion_comm (s t : Finset α) (h : Disjoint s t) : disjUnion s t h = disjUnion t s h.symm := eq_of_veq <| add_comm _ _ #align finset.disj_union_comm Finset.disjUnion_comm @[simp] theorem empty_disjUnion (t : Finset α) (h : Disjoint ∅ t := disjoint_bot_left) : disjUnion ∅ t h = t := eq_of_veq <| zero_add _ #align finset.empty_disj_union Finset.empty_disjUnion @[simp] theorem disjUnion_empty (s : Finset α) (h : Disjoint s ∅ := disjoint_bot_right) : disjUnion s ∅ h = s := eq_of_veq <| add_zero _ #align finset.disj_union_empty Finset.disjUnion_empty theorem singleton_disjUnion (a : α) (t : Finset α) (h : Disjoint {a} t) : disjUnion {a} t h = cons a t (disjoint_singleton_left.mp h) := eq_of_veq <| Multiset.singleton_add _ _ #align finset.singleton_disj_union Finset.singleton_disjUnion theorem disjUnion_singleton (s : Finset α) (a : α) (h : Disjoint s {a}) : disjUnion s {a} h = cons a s (disjoint_singleton_right.mp h) := by rw [disjUnion_comm, singleton_disjUnion] #align finset.disj_union_singleton Finset.disjUnion_singleton /-! ### insert -/ section Insert variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `insert a s` is the set `{a} ∪ s` containing `a` and the elements of `s`. -/ instance : Insert α (Finset α) := ⟨fun a s => ⟨_, s.2.ndinsert a⟩⟩ theorem insert_def (a : α) (s : Finset α) : insert a s = ⟨_, s.2.ndinsert a⟩ := rfl #align finset.insert_def Finset.insert_def @[simp] theorem insert_val (a : α) (s : Finset α) : (insert a s).1 = ndinsert a s.1 := rfl #align finset.insert_val Finset.insert_val theorem insert_val' (a : α) (s : Finset α) : (insert a s).1 = dedup (a ::ₘ s.1) := by rw [dedup_cons, dedup_eq_self]; rfl #align finset.insert_val' Finset.insert_val' theorem insert_val_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : (insert a s).1 = a ::ₘ s.1 := by rw [insert_val, ndinsert_of_not_mem h] #align finset.insert_val_of_not_mem Finset.insert_val_of_not_mem @[simp] theorem mem_insert : a ∈ insert b s ↔ a = b ∨ a ∈ s := mem_ndinsert #align finset.mem_insert Finset.mem_insert theorem mem_insert_self (a : α) (s : Finset α) : a ∈ insert a s := mem_ndinsert_self a s.1 #align finset.mem_insert_self Finset.mem_insert_self theorem mem_insert_of_mem (h : a ∈ s) : a ∈ insert b s := mem_ndinsert_of_mem h #align finset.mem_insert_of_mem Finset.mem_insert_of_mem theorem mem_of_mem_insert_of_ne (h : b ∈ insert a s) : b ≠ a → b ∈ s := (mem_insert.1 h).resolve_left #align finset.mem_of_mem_insert_of_ne Finset.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert (ha : b ∈ insert a s) (hb : b ∉ s) : b = a := (mem_insert.1 ha).resolve_right hb #align finset.eq_of_not_mem_of_mem_insert Finset.eq_of_not_mem_of_mem_insert /-- A version of `LawfulSingleton.insert_emptyc_eq` that works with `dsimp`. -/ @[simp, nolint simpNF] lemma insert_empty : insert a (∅ : Finset α) = {a} := rfl @[simp] theorem cons_eq_insert (a s h) : @cons α a s h = insert a s := ext fun a => by simp #align finset.cons_eq_insert Finset.cons_eq_insert @[simp, norm_cast] theorem coe_insert (a : α) (s : Finset α) : ↑(insert a s) = (insert a s : Set α) := Set.ext fun x => by simp only [mem_coe, mem_insert, Set.mem_insert_iff] #align finset.coe_insert Finset.coe_insert theorem mem_insert_coe {s : Finset α} {x y : α} : x ∈ insert y s ↔ x ∈ insert y (s : Set α) := by simp #align finset.mem_insert_coe Finset.mem_insert_coe instance : LawfulSingleton α (Finset α) := ⟨fun a => by ext; simp⟩ @[simp] theorem insert_eq_of_mem (h : a ∈ s) : insert a s = s := eq_of_veq <| ndinsert_of_mem h #align finset.insert_eq_of_mem Finset.insert_eq_of_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert_self _ _, insert_eq_of_mem⟩ #align finset.insert_eq_self Finset.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align finset.insert_ne_self Finset.insert_ne_self -- Porting note (#10618): @[simp] can prove this theorem pair_eq_singleton (a : α) : ({a, a} : Finset α) = {a} := insert_eq_of_mem <| mem_singleton_self _ #align finset.pair_eq_singleton Finset.pair_eq_singleton theorem Insert.comm (a b : α) (s : Finset α) : insert a (insert b s) = insert b (insert a s) := ext fun x => by simp only [mem_insert, or_left_comm] #align finset.insert.comm Finset.Insert.comm -- Porting note (#10618): @[simp] can prove this @[norm_cast] theorem coe_pair {a b : α} : (({a, b} : Finset α) : Set α) = {a, b} := by ext simp #align finset.coe_pair Finset.coe_pair @[simp, norm_cast] theorem coe_eq_pair {s : Finset α} {a b : α} : (s : Set α) = {a, b} ↔ s = {a, b} := by rw [← coe_pair, coe_inj] #align finset.coe_eq_pair Finset.coe_eq_pair theorem pair_comm (a b : α) : ({a, b} : Finset α) = {b, a} := Insert.comm a b ∅ #align finset.pair_comm Finset.pair_comm -- Porting note (#10618): @[simp] can prove this theorem insert_idem (a : α) (s : Finset α) : insert a (insert a s) = insert a s := ext fun x => by simp only [mem_insert, ← or_assoc, or_self_iff] #align finset.insert_idem Finset.insert_idem @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem insert_nonempty (a : α) (s : Finset α) : (insert a s).Nonempty := ⟨a, mem_insert_self a s⟩ #align finset.insert_nonempty Finset.insert_nonempty @[simp] theorem insert_ne_empty (a : α) (s : Finset α) : insert a s ≠ ∅ := (insert_nonempty a s).ne_empty #align finset.insert_ne_empty Finset.insert_ne_empty -- Porting note: explicit universe annotation is no longer required. instance (i : α) (s : Finset α) : Nonempty ((insert i s : Finset α) : Set α) := (Finset.coe_nonempty.mpr (s.insert_nonempty i)).to_subtype theorem ne_insert_of_not_mem (s t : Finset α) {a : α} (h : a ∉ s) : s ≠ insert a t := by contrapose! h simp [h] #align finset.ne_insert_of_not_mem Finset.ne_insert_of_not_mem theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_iff, mem_insert, forall_eq, or_imp, forall_and] #align finset.insert_subset Finset.insert_subset_iff theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t := insert_subset_iff.mpr ⟨ha,hs⟩ @[simp] theorem subset_insert (a : α) (s : Finset α) : s ⊆ insert a s := fun _b => mem_insert_of_mem #align finset.subset_insert Finset.subset_insert @[gcongr] theorem insert_subset_insert (a : α) {s t : Finset α} (h : s ⊆ t) : insert a s ⊆ insert a t := insert_subset_iff.2 ⟨mem_insert_self _ _, Subset.trans h (subset_insert _ _)⟩ #align finset.insert_subset_insert Finset.insert_subset_insert @[simp] lemma insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by simp_rw [← coe_subset]; simp [-coe_subset, ha] theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b := ⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert_self _ _) ha, congr_arg (insert · s)⟩ #align finset.insert_inj Finset.insert_inj theorem insert_inj_on (s : Finset α) : Set.InjOn (fun a => insert a s) sᶜ := fun _ h _ _ => (insert_inj h).1 #align finset.insert_inj_on Finset.insert_inj_on theorem ssubset_iff : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := mod_cast @Set.ssubset_iff_insert α s t #align finset.ssubset_iff Finset.ssubset_iff theorem ssubset_insert (h : a ∉ s) : s ⊂ insert a s := ssubset_iff.mpr ⟨a, h, Subset.rfl⟩ #align finset.ssubset_insert Finset.ssubset_insert @[elab_as_elim] theorem cons_induction {α : Type*} {p : Finset α → Prop} (empty : p ∅) (cons : ∀ (a : α) (s : Finset α) (h : a ∉ s), p s → p (cons a s h)) : ∀ s, p s | ⟨s, nd⟩ => by induction s using Multiset.induction with | empty => exact empty | cons a s IH => rw [mk_cons nd] exact cons a _ _ (IH _) #align finset.cons_induction Finset.cons_induction @[elab_as_elim] theorem cons_induction_on {α : Type*} {p : Finset α → Prop} (s : Finset α) (h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : Finset α} (h : a ∉ s), p s → p (cons a s h)) : p s := cons_induction h₁ h₂ s #align finset.cons_induction_on Finset.cons_induction_on @[elab_as_elim] protected theorem induction {α : Type*} {p : Finset α → Prop} [DecidableEq α] (empty : p ∅) (insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s := cons_induction empty fun a s ha => (s.cons_eq_insert a ha).symm ▸ insert ha #align finset.induction Finset.induction /-- To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty `Finset`, and to show that if it holds for some `Finset α`, then it holds for the `Finset` obtained by inserting a new element. -/ @[elab_as_elim] protected theorem induction_on {α : Type*} {p : Finset α → Prop} [DecidableEq α] (s : Finset α) (empty : p ∅) (insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : p s := Finset.induction empty insert s #align finset.induction_on Finset.induction_on /-- To prove a proposition about `S : Finset α`, it suffices to prove it for the empty `Finset`, and to show that if it holds for some `Finset α ⊆ S`, then it holds for the `Finset` obtained by inserting a new element of `S`. -/ @[elab_as_elim] theorem induction_on' {α : Type*} {p : Finset α → Prop} [DecidableEq α] (S : Finset α) (h₁ : p ∅) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → p s → p (insert a s)) : p S := @Finset.induction_on α (fun T => T ⊆ S → p T) _ S (fun _ => h₁) (fun _ _ has hqs hs => let ⟨hS, sS⟩ := Finset.insert_subset_iff.1 hs h₂ hS sS has (hqs sS)) (Finset.Subset.refl S) #align finset.induction_on' Finset.induction_on' /-- To prove a proposition about a nonempty `s : Finset α`, it suffices to show it holds for all singletons and that if it holds for nonempty `t : Finset α`, then it also holds for the `Finset` obtained by inserting an element in `t`. -/ @[elab_as_elim] theorem Nonempty.cons_induction {α : Type*} {p : ∀ s : Finset α, s.Nonempty → Prop} (singleton : ∀ a, p {a} (singleton_nonempty _)) (cons : ∀ a s (h : a ∉ s) (hs), p s hs → p (Finset.cons a s h) (nonempty_cons h)) {s : Finset α} (hs : s.Nonempty) : p s hs := by induction s using Finset.cons_induction with | empty => exact (not_nonempty_empty hs).elim | cons a t ha h => obtain rfl | ht := t.eq_empty_or_nonempty · exact singleton a · exact cons a t ha ht (h ht) #align finset.nonempty.cons_induction Finset.Nonempty.cons_induction lemma Nonempty.exists_cons_eq (hs : s.Nonempty) : ∃ t a ha, cons a t ha = s := hs.cons_induction (fun a ↦ ⟨∅, a, _, cons_empty _⟩) fun _ _ _ _ _ ↦ ⟨_, _, _, rfl⟩ /-- Inserting an element to a finite set is equivalent to the option type. -/ def subtypeInsertEquivOption {t : Finset α} {x : α} (h : x ∉ t) : { i // i ∈ insert x t } ≃ Option { i // i ∈ t } where toFun y := if h : ↑y = x then none else some ⟨y, (mem_insert.mp y.2).resolve_left h⟩ invFun y := (y.elim ⟨x, mem_insert_self _ _⟩) fun z => ⟨z, mem_insert_of_mem z.2⟩ left_inv y := by by_cases h : ↑y = x · simp only [Subtype.ext_iff, h, Option.elim, dif_pos, Subtype.coe_mk] · simp only [h, Option.elim, dif_neg, not_false_iff, Subtype.coe_eta, Subtype.coe_mk] right_inv := by rintro (_ | y) · simp only [Option.elim, dif_pos] · have : ↑y ≠ x := by rintro ⟨⟩ exact h y.2 simp only [this, Option.elim, Subtype.eta, dif_neg, not_false_iff, Subtype.coe_mk] #align finset.subtype_insert_equiv_option Finset.subtypeInsertEquivOption @[simp] theorem disjoint_insert_left : Disjoint (insert a s) t ↔ a ∉ t ∧ Disjoint s t := by simp only [disjoint_left, mem_insert, or_imp, forall_and, forall_eq] #align finset.disjoint_insert_left Finset.disjoint_insert_left @[simp] theorem disjoint_insert_right : Disjoint s (insert a t) ↔ a ∉ s ∧ Disjoint s t := disjoint_comm.trans <| by rw [disjoint_insert_left, _root_.disjoint_comm] #align finset.disjoint_insert_right Finset.disjoint_insert_right end Insert /-! ### Lattice structure -/ section Lattice variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α} /-- `s ∪ t` is the set such that `a ∈ s ∪ t` iff `a ∈ s` or `a ∈ t`. -/ instance : Union (Finset α) := ⟨fun s t => ⟨_, t.2.ndunion s.1⟩⟩ /-- `s ∩ t` is the set such that `a ∈ s ∩ t` iff `a ∈ s` and `a ∈ t`. -/ instance : Inter (Finset α) := ⟨fun s t => ⟨_, s.2.ndinter t.1⟩⟩ instance : Lattice (Finset α) := { Finset.partialOrder with sup := (· ∪ ·) sup_le := fun _ _ _ hs ht _ ha => (mem_ndunion.1 ha).elim (fun h => hs h) fun h => ht h le_sup_left := fun _ _ _ h => mem_ndunion.2 <| Or.inl h le_sup_right := fun _ _ _ h => mem_ndunion.2 <| Or.inr h inf := (· ∩ ·) le_inf := fun _ _ _ ht hu _ h => mem_ndinter.2 ⟨ht h, hu h⟩ inf_le_left := fun _ _ _ h => (mem_ndinter.1 h).1 inf_le_right := fun _ _ _ h => (mem_ndinter.1 h).2 } @[simp] theorem sup_eq_union : (Sup.sup : Finset α → Finset α → Finset α) = Union.union := rfl #align finset.sup_eq_union Finset.sup_eq_union @[simp] theorem inf_eq_inter : (Inf.inf : Finset α → Finset α → Finset α) = Inter.inter := rfl #align finset.inf_eq_inter Finset.inf_eq_inter theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ := disjoint_iff #align finset.disjoint_iff_inter_eq_empty Finset.disjoint_iff_inter_eq_empty instance decidableDisjoint (U V : Finset α) : Decidable (Disjoint U V) := decidable_of_iff _ disjoint_left.symm #align finset.decidable_disjoint Finset.decidableDisjoint /-! #### union -/ theorem union_val_nd (s t : Finset α) : (s ∪ t).1 = ndunion s.1 t.1 := rfl #align finset.union_val_nd Finset.union_val_nd @[simp] theorem union_val (s t : Finset α) : (s ∪ t).1 = s.1 ∪ t.1 := ndunion_eq_union s.2 #align finset.union_val Finset.union_val @[simp] theorem mem_union : a ∈ s ∪ t ↔ a ∈ s ∨ a ∈ t := mem_ndunion #align finset.mem_union Finset.mem_union @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t := ext fun a => by simp #align finset.disj_union_eq_union Finset.disjUnion_eq_union theorem mem_union_left (t : Finset α) (h : a ∈ s) : a ∈ s ∪ t := mem_union.2 <| Or.inl h #align finset.mem_union_left Finset.mem_union_left theorem mem_union_right (s : Finset α) (h : a ∈ t) : a ∈ s ∪ t := mem_union.2 <| Or.inr h #align finset.mem_union_right Finset.mem_union_right theorem forall_mem_union {p : α → Prop} : (∀ a ∈ s ∪ t, p a) ↔ (∀ a ∈ s, p a) ∧ ∀ a ∈ t, p a := ⟨fun h => ⟨fun a => h a ∘ mem_union_left _, fun b => h b ∘ mem_union_right _⟩, fun h _ab hab => (mem_union.mp hab).elim (h.1 _) (h.2 _)⟩ #align finset.forall_mem_union Finset.forall_mem_union theorem not_mem_union : a ∉ s ∪ t ↔ a ∉ s ∧ a ∉ t := by rw [mem_union, not_or] #align finset.not_mem_union Finset.not_mem_union @[simp, norm_cast] theorem coe_union (s₁ s₂ : Finset α) : ↑(s₁ ∪ s₂) = (s₁ ∪ s₂ : Set α) := Set.ext fun _ => mem_union #align finset.coe_union Finset.coe_union theorem union_subset (hs : s ⊆ u) : t ⊆ u → s ∪ t ⊆ u := sup_le <| le_iff_subset.2 hs #align finset.union_subset Finset.union_subset theorem subset_union_left {s₁ s₂ : Finset α} : s₁ ⊆ s₁ ∪ s₂ := fun _x => mem_union_left _ #align finset.subset_union_left Finset.subset_union_left theorem subset_union_right {s₁ s₂ : Finset α} : s₂ ⊆ s₁ ∪ s₂ := fun _x => mem_union_right _ #align finset.subset_union_right Finset.subset_union_right @[gcongr] theorem union_subset_union (hsu : s ⊆ u) (htv : t ⊆ v) : s ∪ t ⊆ u ∪ v := sup_le_sup (le_iff_subset.2 hsu) htv #align finset.union_subset_union Finset.union_subset_union @[gcongr] theorem union_subset_union_left (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl #align finset.union_subset_union_left Finset.union_subset_union_left @[gcongr] theorem union_subset_union_right (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h #align finset.union_subset_union_right Finset.union_subset_union_right theorem union_comm (s₁ s₂ : Finset α) : s₁ ∪ s₂ = s₂ ∪ s₁ := sup_comm _ _ #align finset.union_comm Finset.union_comm instance : Std.Commutative (α := Finset α) (· ∪ ·) := ⟨union_comm⟩ @[simp] theorem union_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ (s₂ ∪ s₃) := sup_assoc _ _ _ #align finset.union_assoc Finset.union_assoc instance : Std.Associative (α := Finset α) (· ∪ ·) := ⟨union_assoc⟩ @[simp] theorem union_idempotent (s : Finset α) : s ∪ s = s := sup_idem _ #align finset.union_idempotent Finset.union_idempotent instance : Std.IdempotentOp (α := Finset α) (· ∪ ·) := ⟨union_idempotent⟩ theorem union_subset_left (h : s ∪ t ⊆ u) : s ⊆ u := subset_union_left.trans h #align finset.union_subset_left Finset.union_subset_left theorem union_subset_right {s t u : Finset α} (h : s ∪ t ⊆ u) : t ⊆ u := Subset.trans subset_union_right h #align finset.union_subset_right Finset.union_subset_right theorem union_left_comm (s t u : Finset α) : s ∪ (t ∪ u) = t ∪ (s ∪ u) := ext fun _ => by simp only [mem_union, or_left_comm] #align finset.union_left_comm Finset.union_left_comm theorem union_right_comm (s t u : Finset α) : s ∪ t ∪ u = s ∪ u ∪ t := ext fun x => by simp only [mem_union, or_assoc, @or_comm (x ∈ t)] #align finset.union_right_comm Finset.union_right_comm theorem union_self (s : Finset α) : s ∪ s = s := union_idempotent s #align finset.union_self Finset.union_self @[simp] theorem union_empty (s : Finset α) : s ∪ ∅ = s := ext fun x => mem_union.trans <| by simp #align finset.union_empty Finset.union_empty @[simp] theorem empty_union (s : Finset α) : ∅ ∪ s = s := ext fun x => mem_union.trans <| by simp #align finset.empty_union Finset.empty_union @[aesop unsafe apply (rule_sets := [finsetNonempty])] theorem Nonempty.inl {s t : Finset α} (h : s.Nonempty) : (s ∪ t).Nonempty := h.mono subset_union_left @[aesop unsafe apply (rule_sets := [finsetNonempty])] theorem Nonempty.inr {s t : Finset α} (h : t.Nonempty) : (s ∪ t).Nonempty := h.mono subset_union_right theorem insert_eq (a : α) (s : Finset α) : insert a s = {a} ∪ s := rfl #align finset.insert_eq Finset.insert_eq @[simp] theorem insert_union (a : α) (s t : Finset α) : insert a s ∪ t = insert a (s ∪ t) := by simp only [insert_eq, union_assoc] #align finset.insert_union Finset.insert_union @[simp] theorem union_insert (a : α) (s t : Finset α) : s ∪ insert a t = insert a (s ∪ t) := by simp only [insert_eq, union_left_comm] #align finset.union_insert Finset.union_insert theorem insert_union_distrib (a : α) (s t : Finset α) : insert a (s ∪ t) = insert a s ∪ insert a t := by simp only [insert_union, union_insert, insert_idem] #align finset.insert_union_distrib Finset.insert_union_distrib @[simp] lemma union_eq_left : s ∪ t = s ↔ t ⊆ s := sup_eq_left #align finset.union_eq_left_iff_subset Finset.union_eq_left @[simp] lemma left_eq_union : s = s ∪ t ↔ t ⊆ s := by rw [eq_comm, union_eq_left] #align finset.left_eq_union_iff_subset Finset.left_eq_union @[simp] lemma union_eq_right : s ∪ t = t ↔ s ⊆ t := sup_eq_right #align finset.union_eq_right_iff_subset Finset.union_eq_right @[simp] lemma right_eq_union : s = t ∪ s ↔ t ⊆ s := by rw [eq_comm, union_eq_right] #align finset.right_eq_union_iff_subset Finset.right_eq_union -- Porting note: replaced `⊔` in RHS theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu #align finset.union_congr_left Finset.union_congr_left theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht #align finset.union_congr_right Finset.union_congr_right theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left #align finset.union_eq_union_iff_left Finset.union_eq_union_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right #align finset.union_eq_union_iff_right Finset.union_eq_union_iff_right @[simp] theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by simp only [disjoint_left, mem_union, or_imp, forall_and] #align finset.disjoint_union_left Finset.disjoint_union_left @[simp] theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by simp only [disjoint_right, mem_union, or_imp, forall_and] #align finset.disjoint_union_right Finset.disjoint_union_right /-- To prove a relation on pairs of `Finset X`, it suffices to show that it is * symmetric, * it holds when one of the `Finset`s is empty, * it holds for pairs of singletons, * if it holds for `[a, c]` and for `[b, c]`, then it holds for `[a ∪ b, c]`. -/ theorem induction_on_union (P : Finset α → Finset α → Prop) (symm : ∀ {a b}, P a b → P b a) (empty_right : ∀ {a}, P a ∅) (singletons : ∀ {a b}, P {a} {b}) (union_of : ∀ {a b c}, P a c → P b c → P (a ∪ b) c) : ∀ a b, P a b := by intro a b refine Finset.induction_on b empty_right fun x s _xs hi => symm ?_ rw [Finset.insert_eq] apply union_of _ (symm hi) refine Finset.induction_on a empty_right fun a t _ta hi => symm ?_ rw [Finset.insert_eq] exact union_of singletons (symm hi) #align finset.induction_on_union Finset.induction_on_union /-! #### inter -/ theorem inter_val_nd (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = ndinter s₁.1 s₂.1 := rfl #align finset.inter_val_nd Finset.inter_val_nd @[simp] theorem inter_val (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = s₁.1 ∩ s₂.1 := ndinter_eq_inter s₁.2 #align finset.inter_val Finset.inter_val @[simp] theorem mem_inter {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ ∩ s₂ ↔ a ∈ s₁ ∧ a ∈ s₂ := mem_ndinter #align finset.mem_inter Finset.mem_inter theorem mem_of_mem_inter_left {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₁ := (mem_inter.1 h).1 #align finset.mem_of_mem_inter_left Finset.mem_of_mem_inter_left theorem mem_of_mem_inter_right {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₂ := (mem_inter.1 h).2 #align finset.mem_of_mem_inter_right Finset.mem_of_mem_inter_right theorem mem_inter_of_mem {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ → a ∈ s₂ → a ∈ s₁ ∩ s₂ := and_imp.1 mem_inter.2 #align finset.mem_inter_of_mem Finset.mem_inter_of_mem theorem inter_subset_left {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₁ := fun _a => mem_of_mem_inter_left #align finset.inter_subset_left Finset.inter_subset_left theorem inter_subset_right {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₂ := fun _a => mem_of_mem_inter_right #align finset.inter_subset_right Finset.inter_subset_right theorem subset_inter {s₁ s₂ u : Finset α} : s₁ ⊆ s₂ → s₁ ⊆ u → s₁ ⊆ s₂ ∩ u := by simp (config := { contextual := true }) [subset_iff, mem_inter] #align finset.subset_inter Finset.subset_inter @[simp, norm_cast] theorem coe_inter (s₁ s₂ : Finset α) : ↑(s₁ ∩ s₂) = (s₁ ∩ s₂ : Set α) := Set.ext fun _ => mem_inter #align finset.coe_inter Finset.coe_inter @[simp] theorem union_inter_cancel_left {s t : Finset α} : (s ∪ t) ∩ s = s := by rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_left] #align finset.union_inter_cancel_left Finset.union_inter_cancel_left @[simp] theorem union_inter_cancel_right {s t : Finset α} : (s ∪ t) ∩ t = t := by rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_right] #align finset.union_inter_cancel_right Finset.union_inter_cancel_right theorem inter_comm (s₁ s₂ : Finset α) : s₁ ∩ s₂ = s₂ ∩ s₁ := ext fun _ => by simp only [mem_inter, and_comm] #align finset.inter_comm Finset.inter_comm @[simp] theorem inter_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ (s₂ ∩ s₃) := ext fun _ => by simp only [mem_inter, and_assoc] #align finset.inter_assoc Finset.inter_assoc theorem inter_left_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => by simp only [mem_inter, and_left_comm] #align finset.inter_left_comm Finset.inter_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => by simp only [mem_inter, and_right_comm] #align finset.inter_right_comm Finset.inter_right_comm @[simp] theorem inter_self (s : Finset α) : s ∩ s = s := ext fun _ => mem_inter.trans <| and_self_iff #align finset.inter_self Finset.inter_self @[simp] theorem inter_empty (s : Finset α) : s ∩ ∅ = ∅ := ext fun _ => mem_inter.trans <| by simp #align finset.inter_empty Finset.inter_empty @[simp] theorem empty_inter (s : Finset α) : ∅ ∩ s = ∅ := ext fun _ => mem_inter.trans <| by simp #align finset.empty_inter Finset.empty_inter @[simp] theorem inter_union_self (s t : Finset α) : s ∩ (t ∪ s) = s := by rw [inter_comm, union_inter_cancel_right] #align finset.inter_union_self Finset.inter_union_self @[simp] theorem insert_inter_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₂) : insert a s₁ ∩ s₂ = insert a (s₁ ∩ s₂) := ext fun x => by have : x = a ∨ x ∈ s₂ ↔ x ∈ s₂ := or_iff_right_of_imp <| by rintro rfl; exact h simp only [mem_inter, mem_insert, or_and_left, this] #align finset.insert_inter_of_mem Finset.insert_inter_of_mem @[simp] theorem inter_insert_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₁) : s₁ ∩ insert a s₂ = insert a (s₁ ∩ s₂) := by rw [inter_comm, insert_inter_of_mem h, inter_comm] #align finset.inter_insert_of_mem Finset.inter_insert_of_mem @[simp] theorem insert_inter_of_not_mem {s₁ s₂ : Finset α} {a : α} (h : a ∉ s₂) : insert a s₁ ∩ s₂ = s₁ ∩ s₂ := ext fun x => by have : ¬(x = a ∧ x ∈ s₂) := by rintro ⟨rfl, H⟩; exact h H simp only [mem_inter, mem_insert, or_and_right, this, false_or_iff] #align finset.insert_inter_of_not_mem Finset.insert_inter_of_not_mem @[simp] theorem inter_insert_of_not_mem {s₁ s₂ : Finset α} {a : α} (h : a ∉ s₁) : s₁ ∩ insert a s₂ = s₁ ∩ s₂ := by rw [inter_comm, insert_inter_of_not_mem h, inter_comm] #align finset.inter_insert_of_not_mem Finset.inter_insert_of_not_mem @[simp] theorem singleton_inter_of_mem {a : α} {s : Finset α} (H : a ∈ s) : {a} ∩ s = {a} := show insert a ∅ ∩ s = insert a ∅ by rw [insert_inter_of_mem H, empty_inter] #align finset.singleton_inter_of_mem Finset.singleton_inter_of_mem @[simp] theorem singleton_inter_of_not_mem {a : α} {s : Finset α} (H : a ∉ s) : {a} ∩ s = ∅ := eq_empty_of_forall_not_mem <| by simp only [mem_inter, mem_singleton]; rintro x ⟨rfl, h⟩; exact H h #align finset.singleton_inter_of_not_mem Finset.singleton_inter_of_not_mem @[simp] theorem inter_singleton_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ∩ {a} = {a} := by rw [inter_comm, singleton_inter_of_mem h] #align finset.inter_singleton_of_mem Finset.inter_singleton_of_mem @[simp] theorem inter_singleton_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : s ∩ {a} = ∅ := by rw [inter_comm, singleton_inter_of_not_mem h] #align finset.inter_singleton_of_not_mem Finset.inter_singleton_of_not_mem @[mono, gcongr] theorem inter_subset_inter {x y s t : Finset α} (h : x ⊆ y) (h' : s ⊆ t) : x ∩ s ⊆ y ∩ t := by intro a a_in rw [Finset.mem_inter] at a_in ⊢ exact ⟨h a_in.1, h' a_in.2⟩ #align finset.inter_subset_inter Finset.inter_subset_inter @[gcongr] theorem inter_subset_inter_left (h : t ⊆ u) : s ∩ t ⊆ s ∩ u := inter_subset_inter Subset.rfl h #align finset.inter_subset_inter_left Finset.inter_subset_inter_left @[gcongr] theorem inter_subset_inter_right (h : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter h Subset.rfl #align finset.inter_subset_inter_right Finset.inter_subset_inter_right theorem inter_subset_union : s ∩ t ⊆ s ∪ t := le_iff_subset.1 inf_le_sup #align finset.inter_subset_union Finset.inter_subset_union instance : DistribLattice (Finset α) := { le_sup_inf := fun a b c => by simp (config := { contextual := true }) only [sup_eq_union, inf_eq_inter, le_eq_subset, subset_iff, mem_inter, mem_union, and_imp, or_imp, true_or_iff, imp_true_iff, true_and_iff, or_true_iff] } @[simp] theorem union_left_idem (s t : Finset α) : s ∪ (s ∪ t) = s ∪ t := sup_left_idem _ _ #align finset.union_left_idem Finset.union_left_idem -- Porting note (#10618): @[simp] can prove this theorem union_right_idem (s t : Finset α) : s ∪ t ∪ t = s ∪ t := sup_right_idem _ _ #align finset.union_right_idem Finset.union_right_idem @[simp] theorem inter_left_idem (s t : Finset α) : s ∩ (s ∩ t) = s ∩ t := inf_left_idem _ _ #align finset.inter_left_idem Finset.inter_left_idem -- Porting note (#10618): @[simp] can prove this theorem inter_right_idem (s t : Finset α) : s ∩ t ∩ t = s ∩ t := inf_right_idem _ _ #align finset.inter_right_idem Finset.inter_right_idem theorem inter_union_distrib_left (s t u : Finset α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ #align finset.inter_distrib_left Finset.inter_union_distrib_left theorem union_inter_distrib_right (s t u : Finset α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ #align finset.inter_distrib_right Finset.union_inter_distrib_right theorem union_inter_distrib_left (s t u : Finset α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ #align finset.union_distrib_left Finset.union_inter_distrib_left theorem inter_union_distrib_right (s t u : Finset α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ #align finset.union_distrib_right Finset.inter_union_distrib_right -- 2024-03-22 @[deprecated] alias inter_distrib_left := inter_union_distrib_left @[deprecated] alias inter_distrib_right := union_inter_distrib_right @[deprecated] alias union_distrib_left := union_inter_distrib_left @[deprecated] alias union_distrib_right := inter_union_distrib_right theorem union_union_distrib_left (s t u : Finset α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ #align finset.union_union_distrib_left Finset.union_union_distrib_left theorem union_union_distrib_right (s t u : Finset α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ #align finset.union_union_distrib_right Finset.union_union_distrib_right theorem inter_inter_distrib_left (s t u : Finset α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ #align finset.inter_inter_distrib_left Finset.inter_inter_distrib_left theorem inter_inter_distrib_right (s t u : Finset α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ #align finset.inter_inter_distrib_right Finset.inter_inter_distrib_right theorem union_union_union_comm (s t u v : Finset α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ #align finset.union_union_union_comm Finset.union_union_union_comm theorem inter_inter_inter_comm (s t u v : Finset α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ #align finset.inter_inter_inter_comm Finset.inter_inter_inter_comm lemma union_eq_empty : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := sup_eq_bot_iff #align finset.union_eq_empty_iff Finset.union_eq_empty theorem union_subset_iff : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (sup_le_iff : s ⊔ t ≤ u ↔ s ≤ u ∧ t ≤ u) #align finset.union_subset_iff Finset.union_subset_iff theorem subset_inter_iff : s ⊆ t ∩ u ↔ s ⊆ t ∧ s ⊆ u := (le_inf_iff : s ≤ t ⊓ u ↔ s ≤ t ∧ s ≤ u) #align finset.subset_inter_iff Finset.subset_inter_iff @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left #align finset.inter_eq_left_iff_subset_iff_subset Finset.inter_eq_left @[simp] lemma inter_eq_right : t ∩ s = s ↔ s ⊆ t := inf_eq_right #align finset.inter_eq_right_iff_subset Finset.inter_eq_right theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu #align finset.inter_congr_left Finset.inter_congr_left theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht #align finset.inter_congr_right Finset.inter_congr_right theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left #align finset.inter_eq_inter_iff_left Finset.inter_eq_inter_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right #align finset.inter_eq_inter_iff_right Finset.inter_eq_inter_iff_right theorem ite_subset_union (s s' : Finset α) (P : Prop) [Decidable P] : ite P s s' ⊆ s ∪ s' := ite_le_sup s s' P #align finset.ite_subset_union Finset.ite_subset_union theorem inter_subset_ite (s s' : Finset α) (P : Prop) [Decidable P] : s ∩ s' ⊆ ite P s s' := inf_le_ite s s' P #align finset.inter_subset_ite Finset.inter_subset_ite theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] #align finset.not_disjoint_iff_nonempty_inter Finset.not_disjoint_iff_nonempty_inter alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter #align finset.nonempty.not_disjoint Finset.Nonempty.not_disjoint theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ #align finset.disjoint_or_nonempty_inter Finset.disjoint_or_nonempty_inter end Lattice instance isDirected_le : IsDirected (Finset α) (· ≤ ·) := by classical infer_instance instance isDirected_subset : IsDirected (Finset α) (· ⊆ ·) := isDirected_le /-! ### erase -/ section Erase variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `erase s a` is the set `s - {a}`, that is, the elements of `s` which are not equal to `a`. -/ def erase (s : Finset α) (a : α) : Finset α := ⟨_, s.2.erase a⟩ #align finset.erase Finset.erase @[simp] theorem erase_val (s : Finset α) (a : α) : (erase s a).1 = s.1.erase a := rfl #align finset.erase_val Finset.erase_val @[simp] theorem mem_erase {a b : α} {s : Finset α} : a ∈ erase s b ↔ a ≠ b ∧ a ∈ s := s.2.mem_erase_iff #align finset.mem_erase Finset.mem_erase theorem not_mem_erase (a : α) (s : Finset α) : a ∉ erase s a := s.2.not_mem_erase #align finset.not_mem_erase Finset.not_mem_erase -- While this can be solved by `simp`, this lemma is eligible for `dsimp` @[nolint simpNF, simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl #align finset.erase_empty Finset.erase_empty protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty := (hs.exists_ne a).imp $ by aesop @[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)] refine ⟨?_, fun hs ↦ hs.exists_ne a⟩ rintro ⟨b, hb, hba⟩ exact ⟨_, hb, _, ha, hba⟩ @[simp] theorem erase_singleton (a : α) : ({a} : Finset α).erase a = ∅ := by ext x simp #align finset.erase_singleton Finset.erase_singleton theorem ne_of_mem_erase : b ∈ erase s a → b ≠ a := fun h => (mem_erase.1 h).1 #align finset.ne_of_mem_erase Finset.ne_of_mem_erase theorem mem_of_mem_erase : b ∈ erase s a → b ∈ s := Multiset.mem_of_mem_erase #align finset.mem_of_mem_erase Finset.mem_of_mem_erase theorem mem_erase_of_ne_of_mem : a ≠ b → a ∈ s → a ∈ erase s b := by simp only [mem_erase]; exact And.intro #align finset.mem_erase_of_ne_of_mem Finset.mem_erase_of_ne_of_mem /-- An element of `s` that is not an element of `erase s a` must be`a`. -/ theorem eq_of_mem_of_not_mem_erase (hs : b ∈ s) (hsa : b ∉ s.erase a) : b = a := by rw [mem_erase, not_and] at hsa exact not_imp_not.mp hsa hs #align finset.eq_of_mem_of_not_mem_erase Finset.eq_of_mem_of_not_mem_erase @[simp] theorem erase_eq_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : erase s a = s := eq_of_veq <| erase_of_not_mem h #align finset.erase_eq_of_not_mem Finset.erase_eq_of_not_mem @[simp] theorem erase_eq_self : s.erase a = s ↔ a ∉ s := ⟨fun h => h ▸ not_mem_erase _ _, erase_eq_of_not_mem⟩ #align finset.erase_eq_self Finset.erase_eq_self @[simp] theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a := ext fun x => by simp (config := { contextual := true }) only [mem_erase, mem_insert, and_congr_right_iff, false_or_iff, iff_self_iff, imp_true_iff] #align finset.erase_insert_eq_erase Finset.erase_insert_eq_erase theorem erase_insert {a : α} {s : Finset α} (h : a ∉ s) : erase (insert a s) a = s := by rw [erase_insert_eq_erase, erase_eq_of_not_mem h] #align finset.erase_insert Finset.erase_insert theorem erase_insert_of_ne {a b : α} {s : Finset α} (h : a ≠ b) : erase (insert a s) b = insert a (erase s b) := ext fun x => by have : x ≠ b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm ▸ h simp only [mem_erase, mem_insert, and_or_left, this] #align finset.erase_insert_of_ne Finset.erase_insert_of_ne theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b) : erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by simp only [cons_eq_insert, erase_insert_of_ne hb] #align finset.erase_cons_of_ne Finset.erase_cons_of_ne @[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s := ext fun x => by simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and_iff] apply or_iff_right_of_imp rintro rfl exact h #align finset.insert_erase Finset.insert_erase lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by aesop lemma insert_erase_invOn : Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} := ⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩ theorem erase_subset_erase (a : α) {s t : Finset α} (h : s ⊆ t) : erase s a ⊆ erase t a := val_le_iff.1 <| erase_le_erase _ <| val_le_iff.2 h #align finset.erase_subset_erase Finset.erase_subset_erase theorem erase_subset (a : α) (s : Finset α) : erase s a ⊆ s := Multiset.erase_subset _ _ #align finset.erase_subset Finset.erase_subset theorem subset_erase {a : α} {s t : Finset α} : s ⊆ t.erase a ↔ s ⊆ t ∧ a ∉ s := ⟨fun h => ⟨h.trans (erase_subset _ _), fun ha => not_mem_erase _ _ (h ha)⟩, fun h _b hb => mem_erase.2 ⟨ne_of_mem_of_not_mem hb h.2, h.1 hb⟩⟩ #align finset.subset_erase Finset.subset_erase @[simp, norm_cast] theorem coe_erase (a : α) (s : Finset α) : ↑(erase s a) = (s \ {a} : Set α) := Set.ext fun _ => mem_erase.trans <| by rw [and_comm, Set.mem_diff, Set.mem_singleton_iff, mem_coe] #align finset.coe_erase Finset.coe_erase theorem erase_ssubset {a : α} {s : Finset α} (h : a ∈ s) : s.erase a ⊂ s := calc s.erase a ⊂ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _ _ = _ := insert_erase h #align finset.erase_ssubset Finset.erase_ssubset theorem ssubset_iff_exists_subset_erase {s t : Finset α} : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t.erase a := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩ obtain ⟨a, ht, hs⟩ := not_subset.1 h.2 exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩ #align finset.ssubset_iff_exists_subset_erase Finset.ssubset_iff_exists_subset_erase theorem erase_ssubset_insert (s : Finset α) (a : α) : s.erase a ⊂ insert a s := ssubset_iff_exists_subset_erase.2 ⟨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _⟩ #align finset.erase_ssubset_insert Finset.erase_ssubset_insert theorem erase_ne_self : s.erase a ≠ s ↔ a ∈ s := erase_eq_self.not_left #align finset.erase_ne_self Finset.erase_ne_self theorem erase_cons {s : Finset α} {a : α} (h : a ∉ s) : (s.cons a h).erase a = s := by rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h] #align finset.erase_cons Finset.erase_cons theorem erase_idem {a : α} {s : Finset α} : erase (erase s a) a = erase s a := by simp #align finset.erase_idem Finset.erase_idem theorem erase_right_comm {a b : α} {s : Finset α} : erase (erase s a) b = erase (erase s b) a := by ext x simp only [mem_erase, ← and_assoc] rw [@and_comm (x ≠ a)] #align finset.erase_right_comm Finset.erase_right_comm theorem subset_insert_iff {a : α} {s t : Finset α} : s ⊆ insert a t ↔ erase s a ⊆ t := by simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp] exact forall_congr' fun x => forall_swap #align finset.subset_insert_iff Finset.subset_insert_iff theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s := subset_insert_iff.1 <| Subset.rfl #align finset.erase_insert_subset Finset.erase_insert_subset theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) := subset_insert_iff.2 <| Subset.rfl #align finset.insert_erase_subset Finset.insert_erase_subset theorem subset_insert_iff_of_not_mem (h : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := by rw [subset_insert_iff, erase_eq_of_not_mem h] #align finset.subset_insert_iff_of_not_mem Finset.subset_insert_iff_of_not_mem theorem erase_subset_iff_of_mem (h : a ∈ t) : s.erase a ⊆ t ↔ s ⊆ t := by rw [← subset_insert_iff, insert_eq_of_mem h] #align finset.erase_subset_iff_of_mem Finset.erase_subset_iff_of_mem theorem erase_inj {x y : α} (s : Finset α) (hx : x ∈ s) : s.erase x = s.erase y ↔ x = y := by refine ⟨fun h => eq_of_mem_of_not_mem_erase hx ?_, congr_arg _⟩ rw [← h] simp #align finset.erase_inj Finset.erase_inj theorem erase_injOn (s : Finset α) : Set.InjOn s.erase s := fun _ _ _ _ => (erase_inj s ‹_›).mp #align finset.erase_inj_on Finset.erase_injOn theorem erase_injOn' (a : α) : { s : Finset α | a ∈ s }.InjOn fun s => erase s a := fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h] #align finset.erase_inj_on' Finset.erase_injOn' end Erase lemma Nontrivial.exists_cons_eq {s : Finset α} (hs : s.Nontrivial) : ∃ t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by classical obtain ⟨a, ha, b, hb, hab⟩ := hs have : b ∈ s.erase a := mem_erase.2 ⟨hab.symm, hb⟩ refine ⟨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_⟩ <;> simp [insert_erase this, insert_erase ha, *] /-! ### sdiff -/ section Sdiff variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `s \ t` is the set consisting of the elements of `s` that are not in `t`. -/ instance : SDiff (Finset α) := ⟨fun s₁ s₂ => ⟨s₁.1 - s₂.1, nodup_of_le tsub_le_self s₁.2⟩⟩ @[simp] theorem sdiff_val (s₁ s₂ : Finset α) : (s₁ \ s₂).val = s₁.val - s₂.val := rfl #align finset.sdiff_val Finset.sdiff_val @[simp] theorem mem_sdiff : a ∈ s \ t ↔ a ∈ s ∧ a ∉ t := mem_sub_of_nodup s.2 #align finset.mem_sdiff Finset.mem_sdiff @[simp] theorem inter_sdiff_self (s₁ s₂ : Finset α) : s₁ ∩ (s₂ \ s₁) = ∅ := eq_empty_of_forall_not_mem <| by simp only [mem_inter, mem_sdiff]; rintro x ⟨h, _, hn⟩; exact hn h #align finset.inter_sdiff_self Finset.inter_sdiff_self instance : GeneralizedBooleanAlgebra (Finset α) := { sup_inf_sdiff := fun x y => by simp only [ext_iff, mem_union, mem_sdiff, inf_eq_inter, sup_eq_union, mem_inter, ← and_or_left, em, and_true, implies_true] inf_inf_sdiff := fun x y => by simp only [ext_iff, inter_sdiff_self, inter_empty, inter_assoc, false_iff_iff, inf_eq_inter, not_mem_empty, bot_eq_empty, not_false_iff, implies_true] } theorem not_mem_sdiff_of_mem_right (h : a ∈ t) : a ∉ s \ t := by simp only [mem_sdiff, h, not_true, not_false_iff, and_false_iff] #align finset.not_mem_sdiff_of_mem_right Finset.not_mem_sdiff_of_mem_right theorem not_mem_sdiff_of_not_mem_left (h : a ∉ s) : a ∉ s \ t := by simp [h] #align finset.not_mem_sdiff_of_not_mem_left Finset.not_mem_sdiff_of_not_mem_left theorem union_sdiff_of_subset (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h #align finset.union_sdiff_of_subset Finset.union_sdiff_of_subset theorem sdiff_union_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₂ \ s₁ ∪ s₁ = s₂ := (union_comm _ _).trans (union_sdiff_of_subset h) #align finset.sdiff_union_of_subset Finset.sdiff_union_of_subset lemma inter_sdiff_assoc (s t u : Finset α) : (s ∩ t) \ u = s ∩ (t \ u) := by ext x; simp [and_assoc] @[deprecated inter_sdiff_assoc (since := "2024-05-01")] theorem inter_sdiff (s t u : Finset α) : s ∩ (t \ u) = (s ∩ t) \ u := (inter_sdiff_assoc _ _ _).symm #align finset.inter_sdiff Finset.inter_sdiff @[simp] theorem sdiff_inter_self (s₁ s₂ : Finset α) : s₂ \ s₁ ∩ s₁ = ∅ := inf_sdiff_self_left #align finset.sdiff_inter_self Finset.sdiff_inter_self -- Porting note (#10618): @[simp] can prove this protected theorem sdiff_self (s₁ : Finset α) : s₁ \ s₁ = ∅ := _root_.sdiff_self #align finset.sdiff_self Finset.sdiff_self theorem sdiff_inter_distrib_right (s t u : Finset α) : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf #align finset.sdiff_inter_distrib_right Finset.sdiff_inter_distrib_right @[simp] theorem sdiff_inter_self_left (s t : Finset α) : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ #align finset.sdiff_inter_self_left Finset.sdiff_inter_self_left @[simp] theorem sdiff_inter_self_right (s t : Finset α) : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ #align finset.sdiff_inter_self_right Finset.sdiff_inter_self_right @[simp] theorem sdiff_empty : s \ ∅ = s := sdiff_bot #align finset.sdiff_empty Finset.sdiff_empty @[mono, gcongr] theorem sdiff_subset_sdiff (hst : s ⊆ t) (hvu : v ⊆ u) : s \ u ⊆ t \ v := sdiff_le_sdiff hst hvu #align finset.sdiff_subset_sdiff Finset.sdiff_subset_sdiff @[simp, norm_cast] theorem coe_sdiff (s₁ s₂ : Finset α) : ↑(s₁ \ s₂) = (s₁ \ s₂ : Set α) := Set.ext fun _ => mem_sdiff #align finset.coe_sdiff Finset.coe_sdiff @[simp] theorem union_sdiff_self_eq_union : s ∪ t \ s = s ∪ t := sup_sdiff_self_right _ _ #align finset.union_sdiff_self_eq_union Finset.union_sdiff_self_eq_union @[simp] theorem sdiff_union_self_eq_union : s \ t ∪ t = s ∪ t := sup_sdiff_self_left _ _ #align finset.sdiff_union_self_eq_union Finset.sdiff_union_self_eq_union theorem union_sdiff_left (s t : Finset α) : (s ∪ t) \ s = t \ s := sup_sdiff_left_self #align finset.union_sdiff_left Finset.union_sdiff_left theorem union_sdiff_right (s t : Finset α) : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align finset.union_sdiff_right Finset.union_sdiff_right theorem union_sdiff_cancel_left (h : Disjoint s t) : (s ∪ t) \ s = t := h.sup_sdiff_cancel_left #align finset.union_sdiff_cancel_left Finset.union_sdiff_cancel_left theorem union_sdiff_cancel_right (h : Disjoint s t) : (s ∪ t) \ t = s := h.sup_sdiff_cancel_right #align finset.union_sdiff_cancel_right Finset.union_sdiff_cancel_right theorem union_sdiff_symm : s ∪ t \ s = t ∪ s \ t := by simp [union_comm] #align finset.union_sdiff_symm Finset.union_sdiff_symm theorem sdiff_union_inter (s t : Finset α) : s \ t ∪ s ∩ t = s := sup_sdiff_inf _ _ #align finset.sdiff_union_inter Finset.sdiff_union_inter -- Porting note (#10618): @[simp] can prove this theorem sdiff_idem (s t : Finset α) : (s \ t) \ t = s \ t := _root_.sdiff_idem #align finset.sdiff_idem Finset.sdiff_idem theorem subset_sdiff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u := le_iff_subset.symm.trans le_sdiff #align finset.subset_sdiff Finset.subset_sdiff @[simp] theorem sdiff_eq_empty_iff_subset : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff #align finset.sdiff_eq_empty_iff_subset Finset.sdiff_eq_empty_iff_subset theorem sdiff_nonempty : (s \ t).Nonempty ↔ ¬s ⊆ t := nonempty_iff_ne_empty.trans sdiff_eq_empty_iff_subset.not #align finset.sdiff_nonempty Finset.sdiff_nonempty @[simp] theorem empty_sdiff (s : Finset α) : ∅ \ s = ∅ := bot_sdiff #align finset.empty_sdiff Finset.empty_sdiff theorem insert_sdiff_of_not_mem (s : Finset α) {t : Finset α} {x : α} (h : x ∉ t) : insert x s \ t = insert x (s \ t) := by rw [← coe_inj, coe_insert, coe_sdiff, coe_sdiff, coe_insert] exact Set.insert_diff_of_not_mem _ h #align finset.insert_sdiff_of_not_mem Finset.insert_sdiff_of_not_mem theorem insert_sdiff_of_mem (s : Finset α) {x : α} (h : x ∈ t) : insert x s \ t = s \ t := by rw [← coe_inj, coe_sdiff, coe_sdiff, coe_insert] exact Set.insert_diff_of_mem _ h #align finset.insert_sdiff_of_mem Finset.insert_sdiff_of_mem @[simp] lemma insert_sdiff_cancel (ha : a ∉ s) : insert a s \ s = {a} := by rw [insert_sdiff_of_not_mem _ ha, Finset.sdiff_self, insert_emptyc_eq] @[simp] theorem insert_sdiff_insert (s t : Finset α) (x : α) : insert x s \ insert x t = s \ insert x t := insert_sdiff_of_mem _ (mem_insert_self _ _) #align finset.insert_sdiff_insert Finset.insert_sdiff_insert lemma insert_sdiff_insert' (hab : a ≠ b) (ha : a ∉ s) : insert a s \ insert b s = {a} := by ext; aesop lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by ext; aesop lemma cons_sdiff_cons (hab : a ≠ b) (ha hb) : s.cons a ha \ s.cons b hb = {a} := by rw [cons_eq_insert, cons_eq_insert, insert_sdiff_insert' hab ha] theorem sdiff_insert_of_not_mem {x : α} (h : x ∉ s) (t : Finset α) : s \ insert x t = s \ t := by refine Subset.antisymm (sdiff_subset_sdiff (Subset.refl _) (subset_insert _ _)) fun y hy => ?_ simp only [mem_sdiff, mem_insert, not_or] at hy ⊢ exact ⟨hy.1, fun hxy => h <| hxy ▸ hy.1, hy.2⟩ #align finset.sdiff_insert_of_not_mem Finset.sdiff_insert_of_not_mem @[simp] theorem sdiff_subset {s t : Finset α} : s \ t ⊆ s := le_iff_subset.mp sdiff_le #align finset.sdiff_subset Finset.sdiff_subset theorem sdiff_ssubset (h : t ⊆ s) (ht : t.Nonempty) : s \ t ⊂ s := sdiff_lt (le_iff_subset.mpr h) ht.ne_empty #align finset.sdiff_ssubset Finset.sdiff_ssubset theorem union_sdiff_distrib (s₁ s₂ t : Finset α) : (s₁ ∪ s₂) \ t = s₁ \ t ∪ s₂ \ t := sup_sdiff #align finset.union_sdiff_distrib Finset.union_sdiff_distrib theorem sdiff_union_distrib (s t₁ t₂ : Finset α) : s \ (t₁ ∪ t₂) = s \ t₁ ∩ (s \ t₂) := sdiff_sup #align finset.sdiff_union_distrib Finset.sdiff_union_distrib theorem union_sdiff_self (s t : Finset α) : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align finset.union_sdiff_self Finset.union_sdiff_self -- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`, -- or instead add `Finset.union_singleton`/`Finset.singleton_union`? theorem sdiff_singleton_eq_erase (a : α) (s : Finset α) : s \ singleton a = erase s a := by ext rw [mem_erase, mem_sdiff, mem_singleton, and_comm] #align finset.sdiff_singleton_eq_erase Finset.sdiff_singleton_eq_erase -- This lemma matches `Finset.insert_eq` in functionality. theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} := (sdiff_singleton_eq_erase _ _).symm #align finset.erase_eq Finset.erase_eq theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by simp_rw [erase_eq, disjoint_sdiff_comm] #align finset.disjoint_erase_comm Finset.disjoint_erase_comm lemma disjoint_insert_erase (ha : a ∉ t) : Disjoint (s.erase a) (insert a t) ↔ Disjoint s t := by rw [disjoint_erase_comm, erase_insert ha] lemma disjoint_erase_insert (ha : a ∉ s) : Disjoint (insert a s) (t.erase a) ↔ Disjoint s t := by rw [← disjoint_erase_comm, erase_insert ha] theorem disjoint_of_erase_left (ha : a ∉ t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by rw [← erase_insert ha, ← disjoint_erase_comm, disjoint_insert_right] exact ⟨not_mem_erase _ _, hst⟩ #align finset.disjoint_of_erase_left Finset.disjoint_of_erase_left theorem disjoint_of_erase_right (ha : a ∉ s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by rw [← erase_insert ha, disjoint_erase_comm, disjoint_insert_left] exact ⟨not_mem_erase _ _, hst⟩ #align finset.disjoint_of_erase_right Finset.disjoint_of_erase_right theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by simp only [erase_eq, inter_sdiff_assoc] #align finset.inter_erase Finset.inter_erase @[simp] theorem erase_inter (a : α) (s t : Finset α) : s.erase a ∩ t = (s ∩ t).erase a := by simpa only [inter_comm t] using inter_erase a t s #align finset.erase_inter Finset.erase_inter theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by simp_rw [erase_eq, sdiff_right_comm] #align finset.erase_sdiff_comm Finset.erase_sdiff_comm theorem insert_union_comm (s t : Finset α) (a : α) : insert a s ∪ t = s ∪ insert a t := by rw [insert_union, union_insert] #align finset.insert_union_comm Finset.insert_union_comm theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by rw [erase_inter, inter_erase] #align finset.erase_inter_comm Finset.erase_inter_comm theorem erase_union_distrib (s t : Finset α) (a : α) : (s ∪ t).erase a = s.erase a ∪ t.erase a := by simp_rw [erase_eq, union_sdiff_distrib] #align finset.erase_union_distrib Finset.erase_union_distrib theorem insert_inter_distrib (s t : Finset α) (a : α) : insert a (s ∩ t) = insert a s ∩ insert a t := by simp_rw [insert_eq, union_inter_distrib_left] #align finset.insert_inter_distrib Finset.insert_inter_distrib theorem erase_sdiff_distrib (s t : Finset α) (a : α) : (s \ t).erase a = s.erase a \ t.erase a := by simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm] #align finset.erase_sdiff_distrib Finset.erase_sdiff_distrib theorem erase_union_of_mem (ha : a ∈ t) (s : Finset α) : s.erase a ∪ t = s ∪ t := by rw [← insert_erase (mem_union_right s ha), erase_union_distrib, ← union_insert, insert_erase ha] #align finset.erase_union_of_mem Finset.erase_union_of_mem theorem union_erase_of_mem (ha : a ∈ s) (t : Finset α) : s ∪ t.erase a = s ∪ t := by rw [← insert_erase (mem_union_left t ha), erase_union_distrib, ← insert_union, insert_erase ha] #align finset.union_erase_of_mem Finset.union_erase_of_mem @[simp] theorem sdiff_singleton_eq_self (ha : a ∉ s) : s \ {a} = s := sdiff_eq_self_iff_disjoint.2 <| by simp [ha] #align finset.sdiff_singleton_eq_self Finset.sdiff_singleton_eq_self theorem Nontrivial.sdiff_singleton_nonempty {c : α} {s : Finset α} (hS : s.Nontrivial) : (s \ {c}).Nonempty := by rw [Finset.sdiff_nonempty, Finset.subset_singleton_iff] push_neg exact ⟨by rintro rfl; exact Finset.not_nontrivial_empty hS, hS.ne_singleton⟩ theorem sdiff_sdiff_left' (s t u : Finset α) : (s \ t) \ u = s \ t ∩ (s \ u) := _root_.sdiff_sdiff_left' #align finset.sdiff_sdiff_left' Finset.sdiff_sdiff_left' theorem sdiff_union_sdiff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut #align finset.sdiff_union_sdiff_cancel Finset.sdiff_union_sdiff_cancel theorem sdiff_union_erase_cancel (hts : t ⊆ s) (ha : a ∈ t) : s \ t ∪ t.erase a = s.erase a := by simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)] #align finset.sdiff_union_erase_cancel Finset.sdiff_union_erase_cancel theorem sdiff_sdiff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h #align finset.sdiff_sdiff_eq_sdiff_union Finset.sdiff_sdiff_eq_sdiff_union theorem sdiff_insert (s t : Finset α) (x : α) : s \ insert x t = (s \ t).erase x := by simp_rw [← sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib, inter_comm] #align finset.sdiff_insert Finset.sdiff_insert theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset α} {x : α} (hxs : x ∈ s) (hxt : x ∉ t) : insert x (s \ insert x t) = s \ t := by rw [sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hxs, hxt⟩)] #align finset.sdiff_insert_insert_of_mem_of_not_mem Finset.sdiff_insert_insert_of_mem_of_not_mem theorem sdiff_erase (h : a ∈ s) : s \ t.erase a = insert a (s \ t) := by rw [← sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq, union_comm] #align finset.sdiff_erase Finset.sdiff_erase theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by rw [sdiff_erase ha, Finset.sdiff_self, insert_emptyc_eq] #align finset.sdiff_erase_self Finset.sdiff_erase_self theorem sdiff_sdiff_self_left (s t : Finset α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self #align finset.sdiff_sdiff_self_left Finset.sdiff_sdiff_self_left theorem sdiff_sdiff_eq_self (h : t ⊆ s) : s \ (s \ t) = t := _root_.sdiff_sdiff_eq_self h #align finset.sdiff_sdiff_eq_self Finset.sdiff_sdiff_eq_self theorem sdiff_eq_sdiff_iff_inter_eq_inter {s t₁ t₂ : Finset α} : s \ t₁ = s \ t₂ ↔ s ∩ t₁ = s ∩ t₂ := sdiff_eq_sdiff_iff_inf_eq_inf #align finset.sdiff_eq_sdiff_iff_inter_eq_inter Finset.sdiff_eq_sdiff_iff_inter_eq_inter theorem union_eq_sdiff_union_sdiff_union_inter (s t : Finset α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf #align finset.union_eq_sdiff_union_sdiff_union_inter Finset.union_eq_sdiff_union_sdiff_union_inter theorem erase_eq_empty_iff (s : Finset α) (a : α) : s.erase a = ∅ ↔ s = ∅ ∨ s = {a} := by rw [← sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff] #align finset.erase_eq_empty_iff Finset.erase_eq_empty_iff --TODO@Yaël: Kill lemmas duplicate with `BooleanAlgebra` theorem sdiff_disjoint : Disjoint (t \ s) s := disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2 #align finset.sdiff_disjoint Finset.sdiff_disjoint theorem disjoint_sdiff : Disjoint s (t \ s) := sdiff_disjoint.symm #align finset.disjoint_sdiff Finset.disjoint_sdiff theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right sdiff_disjoint #align finset.disjoint_sdiff_inter Finset.disjoint_sdiff_inter theorem sdiff_eq_self_iff_disjoint : s \ t = s ↔ Disjoint s t := sdiff_eq_self_iff_disjoint' #align finset.sdiff_eq_self_iff_disjoint Finset.sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_of_disjoint (h : Disjoint s t) : s \ t = s := sdiff_eq_self_iff_disjoint.2 h #align finset.sdiff_eq_self_of_disjoint Finset.sdiff_eq_self_of_disjoint end Sdiff /-! ### Symmetric difference -/ section SymmDiff open scoped symmDiff variable [DecidableEq α] {s t : Finset α} {a b : α} theorem mem_symmDiff : a ∈ s ∆ t ↔ a ∈ s ∧ a ∉ t ∨ a ∈ t ∧ a ∉ s := by simp_rw [symmDiff, sup_eq_union, mem_union, mem_sdiff] #align finset.mem_symm_diff Finset.mem_symmDiff @[simp, norm_cast] theorem coe_symmDiff : (↑(s ∆ t) : Set α) = (s : Set α) ∆ t := Set.ext fun x => by simp [mem_symmDiff, Set.mem_symmDiff] #align finset.coe_symm_diff Finset.coe_symmDiff @[simp] lemma symmDiff_eq_empty : s ∆ t = ∅ ↔ s = t := symmDiff_eq_bot @[simp] lemma symmDiff_nonempty : (s ∆ t).Nonempty ↔ s ≠ t := nonempty_iff_ne_empty.trans symmDiff_eq_empty.not end SymmDiff /-! ### attach -/ /-- `attach s` takes the elements of `s` and forms a new set of elements of the subtype `{x // x ∈ s}`. -/ def attach (s : Finset α) : Finset { x // x ∈ s } := ⟨Multiset.attach s.1, nodup_attach.2 s.2⟩ #align finset.attach Finset.attach theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Finset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by cases s dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf] rw [add_comm] refine lt_trans ?_ (Nat.lt_succ_self _) exact Multiset.sizeOf_lt_sizeOf_of_mem hx #align finset.sizeof_lt_sizeof_of_mem Finset.sizeOf_lt_sizeOf_of_mem @[simp] theorem attach_val (s : Finset α) : s.attach.1 = s.1.attach := rfl #align finset.attach_val Finset.attach_val @[simp] theorem mem_attach (s : Finset α) : ∀ x, x ∈ s.attach := Multiset.mem_attach _ #align finset.mem_attach Finset.mem_attach @[simp] theorem attach_empty : attach (∅ : Finset α) = ∅ := rfl #align finset.attach_empty Finset.attach_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by simp [Finset.Nonempty] #align finset.attach_nonempty_iff Finset.attach_nonempty_iff protected alias ⟨_, Nonempty.attach⟩ := attach_nonempty_iff @[simp] theorem attach_eq_empty_iff {s : Finset α} : s.attach = ∅ ↔ s = ∅ := by simp [eq_empty_iff_forall_not_mem] #align finset.attach_eq_empty_iff Finset.attach_eq_empty_iff section DecidablePiExists variable {s : Finset α} instance decidableDforallFinset {p : ∀ a ∈ s, Prop} [_hp : ∀ (a) (h : a ∈ s), Decidable (p a h)] : Decidable (∀ (a) (h : a ∈ s), p a h) := Multiset.decidableDforallMultiset #align finset.decidable_dforall_finset Finset.decidableDforallFinset -- Porting note: In lean3, `decidableDforallFinset` was picked up when decidability of `s ⊆ t` was -- needed. In lean4 it seems this is not the case. instance instDecidableRelSubset [DecidableEq α] : @DecidableRel (Finset α) (· ⊆ ·) := fun _ _ ↦ decidableDforallFinset instance instDecidableRelSSubset [DecidableEq α] : @DecidableRel (Finset α) (· ⊂ ·) := fun _ _ ↦ instDecidableAnd instance instDecidableLE [DecidableEq α] : @DecidableRel (Finset α) (· ≤ ·) := instDecidableRelSubset instance instDecidableLT [DecidableEq α] : @DecidableRel (Finset α) (· < ·) := instDecidableRelSSubset instance decidableDExistsFinset {p : ∀ a ∈ s, Prop} [_hp : ∀ (a) (h : a ∈ s), Decidable (p a h)] : Decidable (∃ (a : _) (h : a ∈ s), p a h) := Multiset.decidableDexistsMultiset #align finset.decidable_dexists_finset Finset.decidableDExistsFinset instance decidableExistsAndFinset {p : α → Prop} [_hp : ∀ (a), Decidable (p a)] : Decidable (∃ a ∈ s, p a) := decidable_of_iff (∃ (a : _) (_ : a ∈ s), p a) (by simp) instance decidableExistsAndFinsetCoe {p : α → Prop} [DecidablePred p] : Decidable (∃ a ∈ (s : Set α), p a) := decidableExistsAndFinset /-- decidable equality for functions whose domain is bounded by finsets -/ instance decidableEqPiFinset {β : α → Type*} [_h : ∀ a, DecidableEq (β a)] : DecidableEq (∀ a ∈ s, β a) := Multiset.decidableEqPiMultiset #align finset.decidable_eq_pi_finset Finset.decidableEqPiFinset end DecidablePiExists /-! ### filter -/ section Filter variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s : Finset α} /-- `Finset.filter p s` is the set of elements of `s` that satisfy `p`. For example, one can use `s.filter (· ∈ t)` to get the intersection of `s` with `t : Set α` as a `Finset α` (when a `DecidablePred (· ∈ t)` instance is available). -/ def filter (s : Finset α) : Finset α := ⟨_, s.2.filter p⟩ #align finset.filter Finset.filter @[simp] theorem filter_val (s : Finset α) : (filter p s).1 = s.1.filter p := rfl #align finset.filter_val Finset.filter_val @[simp] theorem filter_subset (s : Finset α) : s.filter p ⊆ s := Multiset.filter_subset _ _ #align finset.filter_subset Finset.filter_subset variable {p} @[simp] theorem mem_filter {s : Finset α} {a : α} : a ∈ s.filter p ↔ a ∈ s ∧ p a := Multiset.mem_filter #align finset.mem_filter Finset.mem_filter theorem mem_of_mem_filter {s : Finset α} (x : α) (h : x ∈ s.filter p) : x ∈ s := Multiset.mem_of_mem_filter h #align finset.mem_of_mem_filter Finset.mem_of_mem_filter theorem filter_ssubset {s : Finset α} : s.filter p ⊂ s ↔ ∃ x ∈ s, ¬p x := ⟨fun h => let ⟨x, hs, hp⟩ := Set.exists_of_ssubset h ⟨x, hs, mt (fun hp => mem_filter.2 ⟨hs, hp⟩) hp⟩, fun ⟨_, hs, hp⟩ => ⟨s.filter_subset _, fun h => hp (mem_filter.1 (h hs)).2⟩⟩ #align finset.filter_ssubset Finset.filter_ssubset variable (p) theorem filter_filter (s : Finset α) : (s.filter p).filter q = s.filter fun a => p a ∧ q a := ext fun a => by simp only [mem_filter, and_assoc, Bool.decide_and, Bool.decide_coe, Bool.and_eq_true] #align finset.filter_filter Finset.filter_filter theorem filter_comm (s : Finset α) : (s.filter p).filter q = (s.filter q).filter p := by simp_rw [filter_filter, and_comm] #align finset.filter_comm Finset.filter_comm -- We can replace an application of filter where the decidability is inferred in "the wrong way". theorem filter_congr_decidable (s : Finset α) (p : α → Prop) (h : DecidablePred p) [DecidablePred p] : @filter α p h s = s.filter p := by congr #align finset.filter_congr_decidable Finset.filter_congr_decidable @[simp] theorem filter_True {h} (s : Finset α) : @filter _ (fun _ => True) h s = s := by ext; simp #align finset.filter_true Finset.filter_True @[simp] theorem filter_False {h} (s : Finset α) : @filter _ (fun _ => False) h s = ∅ := by ext; simp #align finset.filter_false Finset.filter_False variable {p q} lemma filter_eq_self : s.filter p = s ↔ ∀ x ∈ s, p x := by simp [Finset.ext_iff] #align finset.filter_eq_self Finset.filter_eq_self theorem filter_eq_empty_iff : s.filter p = ∅ ↔ ∀ ⦃x⦄, x ∈ s → ¬p x := by simp [Finset.ext_iff] #align finset.filter_eq_empty_iff Finset.filter_eq_empty_iff theorem filter_nonempty_iff : (s.filter p).Nonempty ↔ ∃ a ∈ s, p a := by simp only [nonempty_iff_ne_empty, Ne, filter_eq_empty_iff, Classical.not_not, not_forall, exists_prop] #align finset.filter_nonempty_iff Finset.filter_nonempty_iff /-- If all elements of a `Finset` satisfy the predicate `p`, `s.filter p` is `s`. -/ theorem filter_true_of_mem (h : ∀ x ∈ s, p x) : s.filter p = s := filter_eq_self.2 h #align finset.filter_true_of_mem Finset.filter_true_of_mem /-- If all elements of a `Finset` fail to satisfy the predicate `p`, `s.filter p` is `∅`. -/ theorem filter_false_of_mem (h : ∀ x ∈ s, ¬p x) : s.filter p = ∅ := filter_eq_empty_iff.2 h #align finset.filter_false_of_mem Finset.filter_false_of_mem @[simp] theorem filter_const (p : Prop) [Decidable p] (s : Finset α) : (s.filter fun _a => p) = if p then s else ∅ := by split_ifs <;> simp [*] #align finset.filter_const Finset.filter_const theorem filter_congr {s : Finset α} (H : ∀ x ∈ s, p x ↔ q x) : filter p s = filter q s := eq_of_veq <| Multiset.filter_congr H #align finset.filter_congr Finset.filter_congr variable (p q) @[simp] theorem filter_empty : filter p ∅ = ∅ := subset_empty.1 <| filter_subset _ _ #align finset.filter_empty Finset.filter_empty @[gcongr] theorem filter_subset_filter {s t : Finset α} (h : s ⊆ t) : s.filter p ⊆ t.filter p := fun _a ha => mem_filter.2 ⟨h (mem_filter.1 ha).1, (mem_filter.1 ha).2⟩ #align finset.filter_subset_filter Finset.filter_subset_filter theorem monotone_filter_left : Monotone (filter p) := fun _ _ => filter_subset_filter p #align finset.monotone_filter_left Finset.monotone_filter_left -- TODO: `@[gcongr]` doesn't accept this lemma because of the `DecidablePred` arguments theorem monotone_filter_right (s : Finset α) ⦃p q : α → Prop⦄ [DecidablePred p] [DecidablePred q] (h : p ≤ q) : s.filter p ⊆ s.filter q := Multiset.subset_of_le (Multiset.monotone_filter_right s.val h) #align finset.monotone_filter_right Finset.monotone_filter_right @[simp, norm_cast] theorem coe_filter (s : Finset α) : ↑(s.filter p) = ({ x ∈ ↑s | p x } : Set α) := Set.ext fun _ => mem_filter #align finset.coe_filter Finset.coe_filter theorem subset_coe_filter_of_subset_forall (s : Finset α) {t : Set α} (h₁ : t ⊆ s) (h₂ : ∀ x ∈ t, p x) : t ⊆ s.filter p := fun x hx => (s.coe_filter p).symm ▸ ⟨h₁ hx, h₂ x hx⟩ #align finset.subset_coe_filter_of_subset_forall Finset.subset_coe_filter_of_subset_forall theorem filter_singleton (a : α) : filter p {a} = if p a then {a} else ∅ := by classical ext x simp only [mem_singleton, forall_eq, mem_filter] split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] #align finset.filter_singleton Finset.filter_singleton theorem filter_cons_of_pos (a : α) (s : Finset α) (ha : a ∉ s) (hp : p a) : filter p (cons a s ha) = cons a (filter p s) (mem_filter.not.mpr <| mt And.left ha) := eq_of_veq <| Multiset.filter_cons_of_pos s.val hp #align finset.filter_cons_of_pos Finset.filter_cons_of_pos theorem filter_cons_of_neg (a : α) (s : Finset α) (ha : a ∉ s) (hp : ¬p a) : filter p (cons a s ha) = filter p s := eq_of_veq <| Multiset.filter_cons_of_neg s.val hp #align finset.filter_cons_of_neg Finset.filter_cons_of_neg theorem disjoint_filter {s : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] : Disjoint (s.filter p) (s.filter q) ↔ ∀ x ∈ s, p x → ¬q x := by constructor <;> simp (config := { contextual := true }) [disjoint_left] #align finset.disjoint_filter Finset.disjoint_filter theorem disjoint_filter_filter {s t : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] : Disjoint s t → Disjoint (s.filter p) (t.filter q) := Disjoint.mono (filter_subset _ _) (filter_subset _ _) #align finset.disjoint_filter_filter Finset.disjoint_filter_filter theorem disjoint_filter_filter' (s t : Finset α) {p q : α → Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) : Disjoint (s.filter p) (t.filter q) := by simp_rw [disjoint_left, mem_filter] rintro a ⟨_, hp⟩ ⟨_, hq⟩ rw [Pi.disjoint_iff] at h simpa [hp, hq] using h a #align finset.disjoint_filter_filter' Finset.disjoint_filter_filter' theorem disjoint_filter_filter_neg (s t : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] : Disjoint (s.filter p) (t.filter fun a => ¬p a) := disjoint_filter_filter' s t disjoint_compl_right #align finset.disjoint_filter_filter_neg Finset.disjoint_filter_filter_neg theorem filter_disj_union (s : Finset α) (t : Finset α) (h : Disjoint s t) : filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) := eq_of_veq <| Multiset.filter_add _ _ _ #align finset.filter_disj_union Finset.filter_disj_union lemma _root_.Set.pairwiseDisjoint_filter [DecidableEq β] (f : α → β) (s : Set β) (t : Finset α) : s.PairwiseDisjoint fun x ↦ t.filter (f · = x) := by rintro i - j - h u hi hj x hx obtain ⟨-, rfl⟩ : x ∈ t ∧ f x = i := by simpa using hi hx obtain ⟨-, rfl⟩ : x ∈ t ∧ f x = j := by simpa using hj hx contradiction theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) : filter p (cons a s ha) = (if p a then {a} else ∅ : Finset α).disjUnion (filter p s) (by split_ifs · rw [disjoint_singleton_left] exact mem_filter.not.mpr <| mt And.left ha · exact disjoint_empty_left _) := by split_ifs with h · rw [filter_cons_of_pos _ _ _ ha h, singleton_disjUnion] · rw [filter_cons_of_neg _ _ _ ha h, empty_disjUnion] #align finset.filter_cons Finset.filter_cons variable [DecidableEq α] theorem filter_union (s₁ s₂ : Finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p := ext fun _ => by simp only [mem_filter, mem_union, or_and_right] #align finset.filter_union Finset.filter_union theorem filter_union_right (s : Finset α) : s.filter p ∪ s.filter q = s.filter fun x => p x ∨ q x := ext fun x => by simp [mem_filter, mem_union, ← and_or_left] #align finset.filter_union_right Finset.filter_union_right theorem filter_mem_eq_inter {s t : Finset α} [∀ i, Decidable (i ∈ t)] : (s.filter fun i => i ∈ t) = s ∩ t := ext fun i => by simp [mem_filter, mem_inter] #align finset.filter_mem_eq_inter Finset.filter_mem_eq_inter theorem filter_inter_distrib (s t : Finset α) : (s ∩ t).filter p = s.filter p ∩ t.filter p := by ext simp [mem_filter, mem_inter, and_assoc] #align finset.filter_inter_distrib Finset.filter_inter_distrib theorem filter_inter (s t : Finset α) : filter p s ∩ t = filter p (s ∩ t) := by ext simp only [mem_inter, mem_filter, and_right_comm] #align finset.filter_inter Finset.filter_inter theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by rw [inter_comm, filter_inter, inter_comm] #align finset.inter_filter Finset.inter_filter theorem filter_insert (a : α) (s : Finset α) : filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by ext x split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] #align finset.filter_insert Finset.filter_insert theorem filter_erase (a : α) (s : Finset α) : filter p (erase s a) = erase (filter p s) a := by ext x simp only [and_assoc, mem_filter, iff_self_iff, mem_erase] #align finset.filter_erase Finset.filter_erase theorem filter_or (s : Finset α) : (s.filter fun a => p a ∨ q a) = s.filter p ∪ s.filter q := ext fun _ => by simp [mem_filter, mem_union, and_or_left] #align finset.filter_or Finset.filter_or theorem filter_and (s : Finset α) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q := ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc] #align finset.filter_and Finset.filter_and theorem filter_not (s : Finset α) : (s.filter fun a => ¬p a) = s \ s.filter p := ext fun a => by simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or, Bool.not_eq_true, and_or_left, and_not_self, or_false] #align finset.filter_not Finset.filter_not lemma filter_and_not (s : Finset α) (p q : α → Prop) [DecidablePred p] [DecidablePred q] : s.filter (fun a ↦ p a ∧ ¬ q a) = s.filter p \ s.filter q := by rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)] theorem sdiff_eq_filter (s₁ s₂ : Finset α) : s₁ \ s₂ = filter (· ∉ s₂) s₁ := ext fun _ => by simp [mem_sdiff, mem_filter] #align finset.sdiff_eq_filter Finset.sdiff_eq_filter theorem sdiff_eq_self (s₁ s₂ : Finset α) : s₁ \ s₂ = s₁ ↔ s₁ ∩ s₂ ⊆ ∅ := by simp [Subset.antisymm_iff, disjoint_iff_inter_eq_empty] #align finset.sdiff_eq_self Finset.sdiff_eq_self theorem subset_union_elim {s : Finset α} {t₁ t₂ : Set α} (h : ↑s ⊆ t₁ ∪ t₂) : ∃ s₁ s₂ : Finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := by classical refine ⟨s.filter (· ∈ t₁), s.filter (· ∉ t₁), ?_, ?_, ?_⟩ · simp [filter_union_right, em] · intro x simp · intro x simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp] intro hx hx₂ exact ⟨Or.resolve_left (h hx) hx₂, hx₂⟩ #align finset.subset_union_elim Finset.subset_union_elim section Classical open scoped Classical -- Porting note: The notation `{ x ∈ s | p x }` in Lean 4 is hardcoded to be about `Set`. -- So at the moment the whole `Sep`-class is useless, as it doesn't have notation. -- /-- The following instance allows us to write `{x ∈ s | p x}` for `Finset.filter p s`. -- We don't want to redo all lemmas of `Finset.filter` for `Sep.sep`, so we make sure that `simp` -- unfolds the notation `{x ∈ s | p x}` to `Finset.filter p s`. -- -/ -- noncomputable instance {α : Type*} : Sep α (Finset α) := -- ⟨fun p x => x.filter p⟩ -- -- @[simp] -- Porting note: not a simp-lemma until `Sep`-notation is fixed. -- theorem sep_def {α : Type*} (s : Finset α) (p : α → Prop) : { x ∈ s | p x } = s.filter p := by -- ext -- simp -- #align finset.sep_def Finset.sep_def end Classical -- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing -- on, e.g. `x ∈ s.filter (Eq b)`. /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq'` with the equality the other way. -/ theorem filter_eq [DecidableEq β] (s : Finset β) (b : β) : s.filter (Eq b) = ite (b ∈ s) {b} ∅ := by split_ifs with h · ext simp only [mem_filter, mem_singleton, decide_eq_true_eq] refine ⟨fun h => h.2.symm, ?_⟩ rintro rfl exact ⟨h, rfl⟩ · ext simp only [mem_filter, not_and, iff_false_iff, not_mem_empty, decide_eq_true_eq] rintro m rfl exact h m #align finset.filter_eq Finset.filter_eq /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq` with the equality the other way. -/ theorem filter_eq' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a = b) = ite (b ∈ s) {b} ∅ := _root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b) #align finset.filter_eq' Finset.filter_eq' theorem filter_ne [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => b ≠ a) = s.erase b := by ext simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not] tauto #align finset.filter_ne Finset.filter_ne theorem filter_ne' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a ≠ b) = s.erase b := _root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b) #align finset.filter_ne' Finset.filter_ne' theorem filter_inter_filter_neg_eq (s t : Finset α) : (s.filter p ∩ t.filter fun a => ¬p a) = ∅ := by simpa using (disjoint_filter_filter_neg s t p).eq_bot #align finset.filter_inter_filter_neg_eq Finset.filter_inter_filter_neg_eq theorem filter_union_filter_of_codisjoint (s : Finset α) (h : Codisjoint p q) : s.filter p ∪ s.filter q = s := (filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial #align finset.filter_union_filter_of_codisjoint Finset.filter_union_filter_of_codisjoint theorem filter_union_filter_neg_eq [∀ x, Decidable (¬p x)] (s : Finset α) : (s.filter p ∪ s.filter fun a => ¬p a) = s := filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p #align finset.filter_union_filter_neg_eq Finset.filter_union_filter_neg_eq end Filter /-! ### range -/ section Range variable {n m l : ℕ} /-- `range n` is the set of natural numbers less than `n`. -/ def range (n : ℕ) : Finset ℕ := ⟨_, nodup_range n⟩ #align finset.range Finset.range @[simp] theorem range_val (n : ℕ) : (range n).1 = Multiset.range n := rfl #align finset.range_val Finset.range_val @[simp] theorem mem_range : m ∈ range n ↔ m < n := Multiset.mem_range #align finset.mem_range Finset.mem_range @[simp, norm_cast] theorem coe_range (n : ℕ) : (range n : Set ℕ) = Set.Iio n := Set.ext fun _ => mem_range #align finset.coe_range Finset.coe_range @[simp] theorem range_zero : range 0 = ∅ := rfl #align finset.range_zero Finset.range_zero @[simp] theorem range_one : range 1 = {0} := rfl #align finset.range_one Finset.range_one theorem range_succ : range (succ n) = insert n (range n) := eq_of_veq <| (Multiset.range_succ n).trans <| (ndinsert_of_not_mem not_mem_range_self).symm #align finset.range_succ Finset.range_succ theorem range_add_one : range (n + 1) = insert n (range n) := range_succ #align finset.range_add_one Finset.range_add_one -- Porting note (#10618): @[simp] can prove this theorem not_mem_range_self : n ∉ range n := Multiset.not_mem_range_self #align finset.not_mem_range_self Finset.not_mem_range_self -- Porting note (#10618): @[simp] can prove this theorem self_mem_range_succ (n : ℕ) : n ∈ range (n + 1) := Multiset.self_mem_range_succ n #align finset.self_mem_range_succ Finset.self_mem_range_succ @[simp] theorem range_subset {n m} : range n ⊆ range m ↔ n ≤ m := Multiset.range_subset #align finset.range_subset Finset.range_subset theorem range_mono : Monotone range := fun _ _ => range_subset.2 #align finset.range_mono Finset.range_mono @[gcongr] alias ⟨_, _root_.GCongr.finset_range_subset_of_le⟩ := range_subset theorem mem_range_succ_iff {a b : ℕ} : a ∈ Finset.range b.succ ↔ a ≤ b := Finset.mem_range.trans Nat.lt_succ_iff #align finset.mem_range_succ_iff Finset.mem_range_succ_iff theorem mem_range_le {n x : ℕ} (hx : x ∈ range n) : x ≤ n := (mem_range.1 hx).le #align finset.mem_range_le Finset.mem_range_le theorem mem_range_sub_ne_zero {n x : ℕ} (hx : x ∈ range n) : n - x ≠ 0 := _root_.ne_of_gt <| Nat.sub_pos_of_lt <| mem_range.1 hx #align finset.mem_range_sub_ne_zero Finset.mem_range_sub_ne_zero @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_range_iff : (range n).Nonempty ↔ n ≠ 0 := ⟨fun ⟨k, hk⟩ => (k.zero_le.trans_lt <| mem_range.1 hk).ne', fun h => ⟨0, mem_range.2 <| Nat.pos_iff_ne_zero.2 h⟩⟩ #align finset.nonempty_range_iff Finset.nonempty_range_iff @[simp] theorem range_eq_empty_iff : range n = ∅ ↔ n = 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_range_iff, not_not] #align finset.range_eq_empty_iff Finset.range_eq_empty_iff theorem nonempty_range_succ : (range <| n + 1).Nonempty := nonempty_range_iff.2 n.succ_ne_zero #align finset.nonempty_range_succ Finset.nonempty_range_succ @[simp] theorem range_filter_eq {n m : ℕ} : (range n).filter (· = m) = if m < n then {m} else ∅ := by convert filter_eq (range n) m using 2 · ext rw [eq_comm] · simp #align finset.range_filter_eq Finset.range_filter_eq lemma range_nontrivial {n : ℕ} (hn : 1 < n) : (Finset.range n).Nontrivial := by rw [Finset.Nontrivial, Finset.coe_range] exact ⟨0, Nat.zero_lt_one.trans hn, 1, hn, zero_ne_one⟩ end Range -- useful rules for calculations with quantifiers theorem exists_mem_empty_iff (p : α → Prop) : (∃ x, x ∈ (∅ : Finset α) ∧ p x) ↔ False := by simp only [not_mem_empty, false_and_iff, exists_false] #align finset.exists_mem_empty_iff Finset.exists_mem_empty_iff theorem exists_mem_insert [DecidableEq α] (a : α) (s : Finset α) (p : α → Prop) : (∃ x, x ∈ insert a s ∧ p x) ↔ p a ∨ ∃ x, x ∈ s ∧ p x := by simp only [mem_insert, or_and_right, exists_or, exists_eq_left] #align finset.exists_mem_insert Finset.exists_mem_insert theorem forall_mem_empty_iff (p : α → Prop) : (∀ x, x ∈ (∅ : Finset α) → p x) ↔ True := iff_true_intro fun _ h => False.elim <| not_mem_empty _ h #align finset.forall_mem_empty_iff Finset.forall_mem_empty_iff theorem forall_mem_insert [DecidableEq α] (a : α) (s : Finset α) (p : α → Prop) : (∀ x, x ∈ insert a s → p x) ↔ p a ∧ ∀ x, x ∈ s → p x := by simp only [mem_insert, or_imp, forall_and, forall_eq] #align finset.forall_mem_insert Finset.forall_mem_insert /-- Useful in proofs by induction. -/ theorem forall_of_forall_insert [DecidableEq α] {p : α → Prop} {a : α} {s : Finset α} (H : ∀ x, x ∈ insert a s → p x) (x) (h : x ∈ s) : p x := H _ <| mem_insert_of_mem h #align finset.forall_of_forall_insert Finset.forall_of_forall_insert end Finset /-- Equivalence between the set of natural numbers which are `≥ k` and `ℕ`, given by `n → n - k`. -/ def notMemRangeEquiv (k : ℕ) : { n // n ∉ range k } ≃ ℕ where toFun i := i.1 - k invFun j := ⟨j + k, by simp⟩ left_inv j := by rw [Subtype.ext_iff_val] apply Nat.sub_add_cancel simpa using j.2 right_inv j := Nat.add_sub_cancel_right _ _ #align not_mem_range_equiv notMemRangeEquiv @[simp] theorem coe_notMemRangeEquiv (k : ℕ) : (notMemRangeEquiv k : { n // n ∉ range k } → ℕ) = fun (i : { n // n ∉ range k }) => i - k := rfl #align coe_not_mem_range_equiv coe_notMemRangeEquiv @[simp] theorem coe_notMemRangeEquiv_symm (k : ℕ) : ((notMemRangeEquiv k).symm : ℕ → { n // n ∉ range k }) = fun j => ⟨j + k, by simp⟩ := rfl #align coe_not_mem_range_equiv_symm coe_notMemRangeEquiv_symm /-! ### dedup on list and multiset -/ namespace Multiset variable [DecidableEq α] {s t : Multiset α} /-- `toFinset s` removes duplicates from the multiset `s` to produce a finset. -/ def toFinset (s : Multiset α) : Finset α := ⟨_, nodup_dedup s⟩ #align multiset.to_finset Multiset.toFinset @[simp] theorem toFinset_val (s : Multiset α) : s.toFinset.1 = s.dedup := rfl #align multiset.to_finset_val Multiset.toFinset_val theorem toFinset_eq {s : Multiset α} (n : Nodup s) : Finset.mk s n = s.toFinset := Finset.val_inj.1 n.dedup.symm #align multiset.to_finset_eq Multiset.toFinset_eq theorem Nodup.toFinset_inj {l l' : Multiset α} (hl : Nodup l) (hl' : Nodup l') (h : l.toFinset = l'.toFinset) : l = l' := by simpa [← toFinset_eq hl, ← toFinset_eq hl'] using h #align multiset.nodup.to_finset_inj Multiset.Nodup.toFinset_inj @[simp] theorem mem_toFinset {a : α} {s : Multiset α} : a ∈ s.toFinset ↔ a ∈ s := mem_dedup #align multiset.mem_to_finset Multiset.mem_toFinset @[simp] theorem toFinset_zero : toFinset (0 : Multiset α) = ∅ := rfl #align multiset.to_finset_zero Multiset.toFinset_zero @[simp] theorem toFinset_cons (a : α) (s : Multiset α) : toFinset (a ::ₘ s) = insert a (toFinset s) := Finset.eq_of_veq dedup_cons #align multiset.to_finset_cons Multiset.toFinset_cons @[simp] theorem toFinset_singleton (a : α) : toFinset ({a} : Multiset α) = {a} := by rw [← cons_zero, toFinset_cons, toFinset_zero, LawfulSingleton.insert_emptyc_eq] #align multiset.to_finset_singleton Multiset.toFinset_singleton @[simp] theorem toFinset_add (s t : Multiset α) : toFinset (s + t) = toFinset s ∪ toFinset t := Finset.ext <| by simp #align multiset.to_finset_add Multiset.toFinset_add @[simp] theorem toFinset_nsmul (s : Multiset α) : ∀ n ≠ 0, (n • s).toFinset = s.toFinset | 0, h => by contradiction | n + 1, _ => by by_cases h : n = 0 · rw [h, zero_add, one_nsmul] · rw [add_nsmul, toFinset_add, one_nsmul, toFinset_nsmul s n h, Finset.union_idempotent] #align multiset.to_finset_nsmul Multiset.toFinset_nsmul theorem toFinset_eq_singleton_iff (s : Multiset α) (a : α) : s.toFinset = {a} ↔ card s ≠ 0 ∧ s = card s • {a} := by refine ⟨fun H ↦ ⟨fun h ↦ ?_, ext' fun x ↦ ?_⟩, fun H ↦ ?_⟩ · rw [card_eq_zero.1 h, toFinset_zero] at H exact Finset.singleton_ne_empty _ H.symm · rw [count_nsmul, count_singleton] by_cases hx : x = a · simp_rw [hx, ite_true, mul_one, count_eq_card] intro y hy rw [← mem_toFinset, H, Finset.mem_singleton] at hy exact hy.symm have hx' : x ∉ s := fun h' ↦ hx <| by rwa [← mem_toFinset, H, Finset.mem_singleton] at h' simp_rw [count_eq_zero_of_not_mem hx', hx, ite_false, Nat.mul_zero] simpa only [toFinset_nsmul _ _ H.1, toFinset_singleton] using congr($(H.2).toFinset) @[simp] theorem toFinset_inter (s t : Multiset α) : toFinset (s ∩ t) = toFinset s ∩ toFinset t := Finset.ext <| by simp #align multiset.to_finset_inter Multiset.toFinset_inter @[simp] theorem toFinset_union (s t : Multiset α) : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset := by ext; simp #align multiset.to_finset_union Multiset.toFinset_union @[simp] theorem toFinset_eq_empty {m : Multiset α} : m.toFinset = ∅ ↔ m = 0 := Finset.val_inj.symm.trans Multiset.dedup_eq_zero #align multiset.to_finset_eq_empty Multiset.toFinset_eq_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s ≠ 0 := by simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty] #align multiset.to_finset_nonempty Multiset.toFinset_nonempty @[simp] theorem toFinset_subset : s.toFinset ⊆ t.toFinset ↔ s ⊆ t := by simp only [Finset.subset_iff, Multiset.subset_iff, Multiset.mem_toFinset] #align multiset.to_finset_subset Multiset.toFinset_subset @[simp] theorem toFinset_ssubset : s.toFinset ⊂ t.toFinset ↔ s ⊂ t := by simp_rw [Finset.ssubset_def, toFinset_subset] rfl #align multiset.to_finset_ssubset Multiset.toFinset_ssubset @[simp] theorem toFinset_dedup (m : Multiset α) : m.dedup.toFinset = m.toFinset := by simp_rw [toFinset, dedup_idem] #align multiset.to_finset_dedup Multiset.toFinset_dedup -- @[simp] -- theorem toFinset_bind_dedup [DecidableEq β] (m : Multiset α) (f : α → Multiset β) : -- (m.dedup.bind f).toFinset = (m.bind f).toFinset := by simp_rw [toFinset, dedup_bind_dedup] -- #align multiset.to_finset_bind_dedup Multiset.toFinset_bind_dedup @[simp] theorem toFinset_filter (s : Multiset α) (p : α → Prop) [DecidablePred p] : Multiset.toFinset (s.filter p) = s.toFinset.filter p := by ext; simp instance isWellFounded_ssubset : IsWellFounded (Multiset β) (· ⊂ ·) := by classical exact Subrelation.isWellFounded (InvImage _ toFinset) toFinset_ssubset.2 #align multiset.is_well_founded_ssubset Multiset.isWellFounded_ssubset end Multiset namespace Finset @[simp] theorem val_toFinset [DecidableEq α] (s : Finset α) : s.val.toFinset = s := by ext rw [Multiset.mem_toFinset, ← mem_def] #align finset.val_to_finset Finset.val_toFinset theorem val_le_iff_val_subset {a : Finset α} {b : Multiset α} : a.val ≤ b ↔ a.val ⊆ b := Multiset.le_iff_subset a.nodup #align finset.val_le_iff_val_subset Finset.val_le_iff_val_subset end Finset namespace List variable [DecidableEq α] {l l' : List α} {a : α} /-- `toFinset l` removes duplicates from the list `l` to produce a finset. -/ def toFinset (l : List α) : Finset α := Multiset.toFinset l #align list.to_finset List.toFinset @[simp] theorem toFinset_val (l : List α) : l.toFinset.1 = (l.dedup : Multiset α) := rfl #align list.to_finset_val List.toFinset_val @[simp] theorem toFinset_coe (l : List α) : (l : Multiset α).toFinset = l.toFinset := rfl #align list.to_finset_coe List.toFinset_coe theorem toFinset_eq (n : Nodup l) : @Finset.mk α l n = l.toFinset := Multiset.toFinset_eq <| by rwa [Multiset.coe_nodup] #align list.to_finset_eq List.toFinset_eq @[simp] theorem mem_toFinset : a ∈ l.toFinset ↔ a ∈ l := mem_dedup #align list.mem_to_finset List.mem_toFinset @[simp, norm_cast] theorem coe_toFinset (l : List α) : (l.toFinset : Set α) = { a | a ∈ l } := Set.ext fun _ => List.mem_toFinset #align list.coe_to_finset List.coe_toFinset @[simp] theorem toFinset_nil : toFinset (@nil α) = ∅ := rfl #align list.to_finset_nil List.toFinset_nil @[simp] theorem toFinset_cons : toFinset (a :: l) = insert a (toFinset l) := Finset.eq_of_veq <| by by_cases h : a ∈ l <;> simp [Finset.insert_val', Multiset.dedup_cons, h] #align list.to_finset_cons List.toFinset_cons theorem toFinset_surj_on : Set.SurjOn toFinset { l : List α | l.Nodup } Set.univ := by rintro ⟨⟨l⟩, hl⟩ _ exact ⟨l, hl, (toFinset_eq hl).symm⟩ #align list.to_finset_surj_on List.toFinset_surj_on theorem toFinset_surjective : Surjective (toFinset : List α → Finset α) := fun s => let ⟨l, _, hls⟩ := toFinset_surj_on (Set.mem_univ s) ⟨l, hls⟩ #align list.to_finset_surjective List.toFinset_surjective theorem toFinset_eq_iff_perm_dedup : l.toFinset = l'.toFinset ↔ l.dedup ~ l'.dedup := by simp [Finset.ext_iff, perm_ext_iff_of_nodup (nodup_dedup _) (nodup_dedup _)] #align list.to_finset_eq_iff_perm_dedup List.toFinset_eq_iff_perm_dedup theorem toFinset.ext_iff {a b : List α} : a.toFinset = b.toFinset ↔ ∀ x, x ∈ a ↔ x ∈ b := by simp only [Finset.ext_iff, mem_toFinset] #align list.to_finset.ext_iff List.toFinset.ext_iff theorem toFinset.ext : (∀ x, x ∈ l ↔ x ∈ l') → l.toFinset = l'.toFinset := toFinset.ext_iff.mpr #align list.to_finset.ext List.toFinset.ext theorem toFinset_eq_of_perm (l l' : List α) (h : l ~ l') : l.toFinset = l'.toFinset := toFinset_eq_iff_perm_dedup.mpr h.dedup #align list.to_finset_eq_of_perm List.toFinset_eq_of_perm theorem perm_of_nodup_nodup_toFinset_eq (hl : Nodup l) (hl' : Nodup l') (h : l.toFinset = l'.toFinset) : l ~ l' := by rw [← Multiset.coe_eq_coe] exact Multiset.Nodup.toFinset_inj hl hl' h #align list.perm_of_nodup_nodup_to_finset_eq List.perm_of_nodup_nodup_toFinset_eq @[simp] theorem toFinset_append : toFinset (l ++ l') = l.toFinset ∪ l'.toFinset := by induction' l with hd tl hl · simp · simp [hl] #align list.to_finset_append List.toFinset_append @[simp] theorem toFinset_reverse {l : List α} : toFinset l.reverse = l.toFinset := toFinset_eq_of_perm _ _ (reverse_perm l) #align list.to_finset_reverse List.toFinset_reverse theorem toFinset_replicate_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (List.replicate n a).toFinset = {a} := by ext x simp [hn, List.mem_replicate] #align list.to_finset_replicate_of_ne_zero List.toFinset_replicate_of_ne_zero @[simp] theorem toFinset_union (l l' : List α) : (l ∪ l').toFinset = l.toFinset ∪ l'.toFinset := by ext simp #align list.to_finset_union List.toFinset_union @[simp] theorem toFinset_inter (l l' : List α) : (l ∩ l').toFinset = l.toFinset ∩ l'.toFinset := by ext simp #align list.to_finset_inter List.toFinset_inter @[simp]
Mathlib/Data/Finset/Basic.lean
3,322
3,323
theorem toFinset_eq_empty_iff (l : List α) : l.toFinset = ∅ ↔ l = nil := by
cases l <;> simp
/- Copyright (c) 2020 Fox Thomson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Fox Thomson -/ import Mathlib.SetTheory.Game.Basic import Mathlib.Tactic.NthRewrite #align_import set_theory.game.impartial from "leanprover-community/mathlib"@"2e0975f6a25dd3fbfb9e41556a77f075f6269748" /-! # Basic definitions about impartial (pre-)games We will define an impartial game, one in which left and right can make exactly the same moves. Our definition differs slightly by saying that the game is always equivalent to its negative, no matter what moves are played. This allows for games such as poker-nim to be classified as impartial. -/ universe u namespace SetTheory open scoped PGame namespace PGame /-- The definition for an impartial game, defined using Conway induction. -/ def ImpartialAux : PGame → Prop | G => (G ≈ -G) ∧ (∀ i, ImpartialAux (G.moveLeft i)) ∧ ∀ j, ImpartialAux (G.moveRight j) termination_by G => G -- Porting note: Added `termination_by` #align pgame.impartial_aux SetTheory.PGame.ImpartialAux
Mathlib/SetTheory/Game/Impartial.lean
35
38
theorem impartialAux_def {G : PGame} : G.ImpartialAux ↔ (G ≈ -G) ∧ (∀ i, ImpartialAux (G.moveLeft i)) ∧ ∀ j, ImpartialAux (G.moveRight j) := by
rw [ImpartialAux]
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Analytic.Composition #align_import analysis.analytic.inverse from "leanprover-community/mathlib"@"284fdd2962e67d2932fa3a79ce19fcf92d38e228" /-! # Inverse of analytic functions We construct the left and right inverse of a formal multilinear series with invertible linear term, we prove that they coincide and study their properties (notably convergence). ## Main statements * `p.leftInv i`: the formal left inverse of the formal multilinear series `p`, for `i : E ≃L[𝕜] F` which coincides with `p₁`. * `p.rightInv i`: the formal right inverse of the formal multilinear series `p`, for `i : E ≃L[𝕜] F` which coincides with `p₁`. * `p.leftInv_comp` says that `p.leftInv i` is indeed a left inverse to `p` when `p₁ = i`. * `p.rightInv_comp` says that `p.rightInv i` is indeed a right inverse to `p` when `p₁ = i`. * `p.leftInv_eq_rightInv`: the two inverses coincide. * `p.radius_rightInv_pos_of_radius_pos`: if a power series has a positive radius of convergence, then so does its inverse. -/ open scoped Classical Topology open Finset Filter namespace FormalMultilinearSeries variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] /-! ### The left inverse of a formal multilinear series -/ /-- The left inverse of a formal multilinear series, where the `n`-th term is defined inductively in terms of the previous ones to make sure that `(leftInv p i) ∘ p = id`. For this, the linear term `p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should coincide with `p₁`, so that one can use its inverse in the construction. The definition does not use that `i = p₁`, but proofs that the definition is well-behaved do. The `n`-th term in `q ∘ p` is `∑ qₖ (p_{j₁}, ..., p_{jₖ})` over `j₁ + ... + jₖ = n`. In this expression, `qₙ` appears only once, in `qₙ (p₁, ..., p₁)`. We adjust the definition so that this term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`. These formulas only make sense when the constant term `p₀` vanishes. The definition we give is general, but it ignores the value of `p₀`. -/ noncomputable def leftInv (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) : FormalMultilinearSeries 𝕜 F E | 0 => 0 | 1 => (continuousMultilinearCurryFin1 𝕜 F E).symm i.symm | n + 2 => -∑ c : { c : Composition (n + 2) // c.length < n + 2 }, (leftInv p i (c : Composition (n + 2)).length).compAlongComposition (p.compContinuousLinearMap i.symm) c #align formal_multilinear_series.left_inv FormalMultilinearSeries.leftInv @[simp] theorem leftInv_coeff_zero (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) : p.leftInv i 0 = 0 := by rw [leftInv] #align formal_multilinear_series.left_inv_coeff_zero FormalMultilinearSeries.leftInv_coeff_zero @[simp] theorem leftInv_coeff_one (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) : p.leftInv i 1 = (continuousMultilinearCurryFin1 𝕜 F E).symm i.symm := by rw [leftInv] #align formal_multilinear_series.left_inv_coeff_one FormalMultilinearSeries.leftInv_coeff_one /-- The left inverse does not depend on the zeroth coefficient of a formal multilinear series. -/ theorem leftInv_removeZero (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) : p.removeZero.leftInv i = p.leftInv i := by ext1 n induction' n using Nat.strongRec' with n IH match n with | 0 => simp -- if one replaces `simp` with `refl`, the proof times out in the kernel. | 1 => simp -- TODO: why? | n + 2 => simp only [leftInv, neg_inj] refine Finset.sum_congr rfl fun c cuniv => ?_ rcases c with ⟨c, hc⟩ ext v dsimp simp [IH _ hc] #align formal_multilinear_series.left_inv_remove_zero FormalMultilinearSeries.leftInv_removeZero /-- The left inverse to a formal multilinear series is indeed a left inverse, provided its linear term is invertible. -/ theorem leftInv_comp (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) (h : p 1 = (continuousMultilinearCurryFin1 𝕜 E F).symm i) : (leftInv p i).comp p = id 𝕜 E := by ext (n v) match n with | 0 => simp only [leftInv_coeff_zero, ContinuousMultilinearMap.zero_apply, id_apply_ne_one, Ne, not_false_iff, zero_ne_one, comp_coeff_zero'] | 1 => simp only [leftInv_coeff_one, comp_coeff_one, h, id_apply_one, ContinuousLinearEquiv.coe_apply, ContinuousLinearEquiv.symm_apply_apply, continuousMultilinearCurryFin1_symm_apply] | n + 2 => have A : (Finset.univ : Finset (Composition (n + 2))) = {c | Composition.length c < n + 2}.toFinset ∪ {Composition.ones (n + 2)} := by refine Subset.antisymm (fun c _ => ?_) (subset_univ _) by_cases h : c.length < n + 2 · simp [h, Set.mem_toFinset (s := {c | Composition.length c < n + 2})] · simp [Composition.eq_ones_iff_le_length.2 (not_lt.1 h)] have B : Disjoint ({c | Composition.length c < n + 2} : Set (Composition (n + 2))).toFinset {Composition.ones (n + 2)} := by simp [Set.mem_toFinset (s := {c | Composition.length c < n + 2})] have C : ((p.leftInv i (Composition.ones (n + 2)).length) fun j : Fin (Composition.ones n.succ.succ).length => p 1 fun _ => v ((Fin.castLE (Composition.length_le _)) j)) = p.leftInv i (n + 2) fun j : Fin (n + 2) => p 1 fun _ => v j := by apply FormalMultilinearSeries.congr _ (Composition.ones_length _) fun j hj1 hj2 => ?_ exact FormalMultilinearSeries.congr _ rfl fun k _ _ => by congr have D : (p.leftInv i (n + 2) fun j : Fin (n + 2) => p 1 fun _ => v j) = -∑ c ∈ {c : Composition (n + 2) | c.length < n + 2}.toFinset, (p.leftInv i c.length) (p.applyComposition c v) := by simp only [leftInv, ContinuousMultilinearMap.neg_apply, neg_inj, ContinuousMultilinearMap.sum_apply] convert (sum_toFinset_eq_subtype (fun c : Composition (n + 2) => c.length < n + 2) (fun c : Composition (n + 2) => (ContinuousMultilinearMap.compAlongComposition (p.compContinuousLinearMap (i.symm : F →L[𝕜] E)) c (p.leftInv i c.length)) fun j : Fin (n + 2) => p 1 fun _ : Fin 1 => v j)).symm.trans _ simp only [compContinuousLinearMap_applyComposition, ContinuousMultilinearMap.compAlongComposition_apply] congr ext c congr ext k simp [h, Function.comp] simp [FormalMultilinearSeries.comp, show n + 2 ≠ 1 by omega, A, Finset.sum_union B, applyComposition_ones, C, D, -Set.toFinset_setOf] #align formal_multilinear_series.left_inv_comp FormalMultilinearSeries.leftInv_comp /-! ### The right inverse of a formal multilinear series -/ /-- The right inverse of a formal multilinear series, where the `n`-th term is defined inductively in terms of the previous ones to make sure that `p ∘ (rightInv p i) = id`. For this, the linear term `p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should coincide with `p₁`, so that one can use its inverse in the construction. The definition does not use that `i = p₁`, but proofs that the definition is well-behaved do. The `n`-th term in `p ∘ q` is `∑ pₖ (q_{j₁}, ..., q_{jₖ})` over `j₁ + ... + jₖ = n`. In this expression, `qₙ` appears only once, in `p₁ (qₙ)`. We adjust the definition of `qₙ` so that this term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`. These formulas only make sense when the constant term `p₀` vanishes. The definition we give is general, but it ignores the value of `p₀`. -/ noncomputable def rightInv (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) : FormalMultilinearSeries 𝕜 F E | 0 => 0 | 1 => (continuousMultilinearCurryFin1 𝕜 F E).symm i.symm | n + 2 => let q : FormalMultilinearSeries 𝕜 F E := fun k => if k < n + 2 then rightInv p i k else 0; -(i.symm : F →L[𝕜] E).compContinuousMultilinearMap ((p.comp q) (n + 2)) #align formal_multilinear_series.right_inv FormalMultilinearSeries.rightInv @[simp] theorem rightInv_coeff_zero (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) : p.rightInv i 0 = 0 := by rw [rightInv] #align formal_multilinear_series.right_inv_coeff_zero FormalMultilinearSeries.rightInv_coeff_zero @[simp] theorem rightInv_coeff_one (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) : p.rightInv i 1 = (continuousMultilinearCurryFin1 𝕜 F E).symm i.symm := by rw [rightInv] #align formal_multilinear_series.right_inv_coeff_one FormalMultilinearSeries.rightInv_coeff_one /-- The right inverse does not depend on the zeroth coefficient of a formal multilinear series. -/ theorem rightInv_removeZero (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) : p.removeZero.rightInv i = p.rightInv i := by ext1 n induction' n using Nat.strongRec' with n IH match n with | 0 => simp only [rightInv_coeff_zero] | 1 => simp only [rightInv_coeff_one] | n + 2 => simp only [rightInv, neg_inj] rw [removeZero_comp_of_pos _ _ (add_pos_of_nonneg_of_pos n.zero_le zero_lt_two)] congr (config := { closePost := false }) 2 with k by_cases hk : k < n + 2 <;> simp [hk, IH] #align formal_multilinear_series.right_inv_remove_zero FormalMultilinearSeries.rightInv_removeZero theorem comp_rightInv_aux1 {n : ℕ} (hn : 0 < n) (p : FormalMultilinearSeries 𝕜 E F) (q : FormalMultilinearSeries 𝕜 F E) (v : Fin n → F) : p.comp q n v = ∑ c ∈ {c : Composition n | 1 < c.length}.toFinset, p c.length (q.applyComposition c v) + p 1 fun _ => q n v := by have A : (Finset.univ : Finset (Composition n)) = {c | 1 < Composition.length c}.toFinset ∪ {Composition.single n hn} := by refine Subset.antisymm (fun c _ => ?_) (subset_univ _) by_cases h : 1 < c.length · simp [h, Set.mem_toFinset (s := {c | 1 < Composition.length c})] · have : c.length = 1 := by refine (eq_iff_le_not_lt.2 ⟨?_, h⟩).symm; exact c.length_pos_of_pos hn rw [← Composition.eq_single_iff_length hn] at this simp [this] have B : Disjoint ({c | 1 < Composition.length c} : Set (Composition n)).toFinset {Composition.single n hn} := by simp [Set.mem_toFinset (s := {c | 1 < Composition.length c})] have C : p (Composition.single n hn).length (q.applyComposition (Composition.single n hn) v) = p 1 fun _ : Fin 1 => q n v := by apply p.congr (Composition.single_length hn) fun j hj1 _ => ?_ simp [applyComposition_single] simp [FormalMultilinearSeries.comp, A, Finset.sum_union B, C, -Set.toFinset_setOf, -add_right_inj, -Composition.single_length] #align formal_multilinear_series.comp_right_inv_aux1 FormalMultilinearSeries.comp_rightInv_aux1 theorem comp_rightInv_aux2 (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) (n : ℕ) (v : Fin (n + 2) → F) : ∑ c ∈ {c : Composition (n + 2) | 1 < c.length}.toFinset, p c.length (applyComposition (fun k : ℕ => ite (k < n + 2) (p.rightInv i k) 0) c v) = ∑ c ∈ {c : Composition (n + 2) | 1 < c.length}.toFinset, p c.length ((p.rightInv i).applyComposition c v) := by have N : 0 < n + 2 := by norm_num refine sum_congr rfl fun c hc => p.congr rfl fun j hj1 hj2 => ?_ have : ∀ k, c.blocksFun k < n + 2 := by simp only [Set.mem_toFinset (s := {c : Composition (n + 2) | 1 < c.length}), Set.mem_setOf_eq] at hc simp [← Composition.ne_single_iff N, Composition.eq_single_iff_length, ne_of_gt hc] simp [applyComposition, this] #align formal_multilinear_series.comp_right_inv_aux2 FormalMultilinearSeries.comp_rightInv_aux2 /-- The right inverse to a formal multilinear series is indeed a right inverse, provided its linear term is invertible and its constant term vanishes. -/ theorem comp_rightInv (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) (h : p 1 = (continuousMultilinearCurryFin1 𝕜 E F).symm i) (h0 : p 0 = 0) : p.comp (rightInv p i) = id 𝕜 F := by ext (n v) match n with | 0 => simp only [h0, ContinuousMultilinearMap.zero_apply, id_apply_ne_one, Ne, not_false_iff, zero_ne_one, comp_coeff_zero'] | 1 => simp only [comp_coeff_one, h, rightInv_coeff_one, ContinuousLinearEquiv.apply_symm_apply, id_apply_one, ContinuousLinearEquiv.coe_apply, continuousMultilinearCurryFin1_symm_apply] | n + 2 => have N : 0 < n + 2 := by norm_num simp [comp_rightInv_aux1 N, h, rightInv, lt_irrefl n, show n + 2 ≠ 1 by omega, ← sub_eq_add_neg, sub_eq_zero, comp_rightInv_aux2, -Set.toFinset_setOf] #align formal_multilinear_series.comp_right_inv FormalMultilinearSeries.comp_rightInv
Mathlib/Analysis/Analytic/Inverse.lean
265
279
theorem rightInv_coeff (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) (n : ℕ) (hn : 2 ≤ n) : p.rightInv i n = -(i.symm : F →L[𝕜] E).compContinuousMultilinearMap (∑ c ∈ ({c | 1 < Composition.length c}.toFinset : Finset (Composition n)), p.compAlongComposition (p.rightInv i) c) := by
match n with | 0 => exact False.elim (zero_lt_two.not_le hn) | 1 => exact False.elim (one_lt_two.not_le hn) | n + 2 => simp only [rightInv, neg_inj] congr (config := { closePost := false }) 1 ext v have N : 0 < n + 2 := by norm_num have : ((p 1) fun i : Fin 1 => 0) = 0 := ContinuousMultilinearMap.map_zero _ simp [comp_rightInv_aux1 N, lt_irrefl n, this, comp_rightInv_aux2, -Set.toFinset_setOf]
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Fintype.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineMap import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace import Mathlib.LinearAlgebra.Finsupp import Mathlib.Tactic.FinCases #align_import linear_algebra.affine_space.combination from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0" /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp #align finset.univ_fin2 Finset.univ_fin2 variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) #align finset.weighted_vsub_of_point Finset.weightedVSubOfPoint @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] #align finset.weighted_vsub_of_point_apply Finset.weightedVSubOfPoint_apply /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] #align finset.weighted_vsub_of_point_apply_const Finset.weightedVSubOfPoint_apply_const /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] #align finset.weighted_vsub_of_point_congr Finset.weightedVSubOfPoint_congr /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] #align finset.weighted_vsub_of_point_eq_of_weights_eq Finset.weightedVSubOfPoint_eq_of_weights_eq /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] #align finset.weighted_vsub_of_point_eq_of_sum_eq_zero Finset.weightedVSubOfPoint_eq_of_sum_eq_zero /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w +ᵥ b₁ = s.weightedVSubOfPoint p b₂ w +ᵥ b₂ := by erw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr · skip · congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] #align finset.weighted_vsub_of_point_vadd_eq_of_sum_eq_one Finset.weightedVSubOfPoint_vadd_eq_of_sum_eq_one /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_erase [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero] #align finset.weighted_vsub_of_point_erase Finset.weightedVSubOfPoint_erase /-- The weighted sum is unaffected by adding the base point, whether or not present, to the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_insert [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (insert i s).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_insert_zero rw [vsub_self, smul_zero] #align finset.weighted_vsub_of_point_insert Finset.weightedVSubOfPoint_insert /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSubOfPoint_indicator_subset (w : ι → k) (p : ι → P) (b : P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint p b (Set.indicator (↑s₁) w) := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] exact Eq.symm <| sum_indicator_subset_of_eq_zero w (fun i wi => wi • (p i -ᵥ b : V)) h fun i => zero_smul k _ #align finset.weighted_vsub_of_point_indicator_subset Finset.weightedVSubOfPoint_indicator_subset /-- A weighted sum, over the image of an embedding, equals a weighted sum with the same points and weights over the original `Finset`. -/ theorem weightedVSubOfPoint_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) (b : P) : (s₂.map e).weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint (p ∘ e) b (w ∘ e) := by simp_rw [weightedVSubOfPoint_apply] exact Finset.sum_map _ _ _ #align finset.weighted_vsub_of_point_map Finset.weightedVSubOfPoint_map /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSubOfPoint` expressions. -/ theorem sum_smul_vsub_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ p₂ : ι → P) (b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSubOfPoint p₁ b w - s.weightedVSubOfPoint p₂ b w := by simp_rw [weightedVSubOfPoint_apply, ← sum_sub_distrib, ← smul_sub, vsub_sub_vsub_cancel_right] #align finset.sum_smul_vsub_eq_weighted_vsub_of_point_sub Finset.sum_smul_vsub_eq_weightedVSubOfPoint_sub /-- A weighted sum of pairwise subtractions, where the point on the right is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_vsub_const_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ : ι → P) (p₂ b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSubOfPoint p₁ b w - (∑ i ∈ s, w i) • (p₂ -ᵥ b) := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] #align finset.sum_smul_vsub_const_eq_weighted_vsub_of_point_sub Finset.sum_smul_vsub_const_eq_weightedVSubOfPoint_sub /-- A weighted sum of pairwise subtractions, where the point on the left is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_const_vsub_eq_sub_weightedVSubOfPoint (w : ι → k) (p₂ : ι → P) (p₁ b : P) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = (∑ i ∈ s, w i) • (p₁ -ᵥ b) - s.weightedVSubOfPoint p₂ b w := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] #align finset.sum_smul_const_vsub_eq_sub_weighted_vsub_of_point Finset.sum_smul_const_vsub_eq_sub_weightedVSubOfPoint /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w + s₂.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, sum_sdiff h] #align finset.weighted_vsub_of_point_sdiff Finset.weightedVSubOfPoint_sdiff /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w - s₂.weightedVSubOfPoint p b (-w) = s.weightedVSubOfPoint p b w := by rw [map_neg, sub_neg_eq_add, s.weightedVSubOfPoint_sdiff h] #align finset.weighted_vsub_of_point_sdiff_sub Finset.weightedVSubOfPoint_sdiff_sub /-- A weighted sum over `s.subtype pred` equals one over `s.filter pred`. -/ theorem weightedVSubOfPoint_subtype_eq_filter (w : ι → k) (p : ι → P) (b : P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSubOfPoint (fun i => p i) b fun i => w i) = (s.filter pred).weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] #align finset.weighted_vsub_of_point_subtype_eq_filter Finset.weightedVSubOfPoint_subtype_eq_filter /-- A weighted sum over `s.filter pred` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSubOfPoint_filter_of_ne (w : ι → k) (p : ι → P) (b : P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : (s.filter pred).weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, sum_filter_of_ne] intro i hi hne refine h i hi ?_ intro hw simp [hw] at hne #align finset.weighted_vsub_of_point_filter_of_ne Finset.weightedVSubOfPoint_filter_of_ne /-- A constant multiplier of the weights in `weightedVSubOfPoint` may be moved outside the sum. -/ theorem weightedVSubOfPoint_const_smul (w : ι → k) (p : ι → P) (b : P) (c : k) : s.weightedVSubOfPoint p b (c • w) = c • s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, smul_sum, Pi.smul_apply, smul_smul, smul_eq_mul] #align finset.weighted_vsub_of_point_const_smul Finset.weightedVSubOfPoint_const_smul /-- A weighted sum of the results of subtracting a default base point from the given points, as a linear map on the weights. This is intended to be used when the sum of the weights is 0; that condition is specified as a hypothesis on those lemmas that require it. -/ def weightedVSub (p : ι → P) : (ι → k) →ₗ[k] V := s.weightedVSubOfPoint p (Classical.choice S.nonempty) #align finset.weighted_vsub Finset.weightedVSub /-- Applying `weightedVSub` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `weightedVSub` would involve selecting a preferred base point with `weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero` and then using `weightedVSubOfPoint_apply`. -/ theorem weightedVSub_apply (w : ι → k) (p : ι → P) : s.weightedVSub p w = ∑ i ∈ s, w i • (p i -ᵥ Classical.choice S.nonempty) := by simp [weightedVSub, LinearMap.sum_apply] #align finset.weighted_vsub_apply Finset.weightedVSub_apply /-- `weightedVSub` gives the sum of the results of subtracting any base point, when the sum of the weights is 0. -/ theorem weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b : P) : s.weightedVSub p w = s.weightedVSubOfPoint p b w := s.weightedVSubOfPoint_eq_of_sum_eq_zero w p h _ _ #align finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero /-- The value of `weightedVSub`, where the given points are equal and the sum of the weights is 0. -/ @[simp] theorem weightedVSub_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 0) : s.weightedVSub (fun _ => p) w = 0 := by rw [weightedVSub, weightedVSubOfPoint_apply_const, h, zero_smul] #align finset.weighted_vsub_apply_const Finset.weightedVSub_apply_const /-- The `weightedVSub` for an empty set is 0. -/ @[simp] theorem weightedVSub_empty (w : ι → k) (p : ι → P) : (∅ : Finset ι).weightedVSub p w = (0 : V) := by simp [weightedVSub_apply] #align finset.weighted_vsub_empty Finset.weightedVSub_empty /-- `weightedVSub` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSub_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.weightedVSub p₁ w₁ = s.weightedVSub p₂ w₂ := s.weightedVSubOfPoint_congr hw hp _ #align finset.weighted_vsub_congr Finset.weightedVSub_congr /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSub_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSub p w = s₂.weightedVSub p (Set.indicator (↑s₁) w) := weightedVSubOfPoint_indicator_subset _ _ _ h #align finset.weighted_vsub_indicator_subset Finset.weightedVSub_indicator_subset /-- A weighted subtraction, over the image of an embedding, equals a weighted subtraction with the same points and weights over the original `Finset`. -/ theorem weightedVSub_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).weightedVSub p w = s₂.weightedVSub (p ∘ e) (w ∘ e) := s₂.weightedVSubOfPoint_map _ _ _ _ #align finset.weighted_vsub_map Finset.weightedVSub_map /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSub` expressions. -/ theorem sum_smul_vsub_eq_weightedVSub_sub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSub p₁ w - s.weightedVSub p₂ w := s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ #align finset.sum_smul_vsub_eq_weighted_vsub_sub Finset.sum_smul_vsub_eq_weightedVSub_sub /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 0. -/ theorem sum_smul_vsub_const_eq_weightedVSub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSub p₁ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, sub_zero] #align finset.sum_smul_vsub_const_eq_weighted_vsub Finset.sum_smul_vsub_const_eq_weightedVSub /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 0. -/ theorem sum_smul_const_vsub_eq_neg_weightedVSub (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = -s.weightedVSub p₂ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, zero_sub] #align finset.sum_smul_const_vsub_eq_neg_weighted_vsub Finset.sum_smul_const_vsub_eq_neg_weightedVSub /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSub_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w + s₂.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff h _ _ _ #align finset.weighted_vsub_sdiff Finset.weightedVSub_sdiff /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSub_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w - s₂.weightedVSub p (-w) = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff_sub h _ _ _ #align finset.weighted_vsub_sdiff_sub Finset.weightedVSub_sdiff_sub /-- A weighted sum over `s.subtype pred` equals one over `s.filter pred`. -/ theorem weightedVSub_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSub (fun i => p i) fun i => w i) = (s.filter pred).weightedVSub p w := s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _ #align finset.weighted_vsub_subtype_eq_filter Finset.weightedVSub_subtype_eq_filter /-- A weighted sum over `s.filter pred` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSub_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : (s.filter pred).weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_filter_of_ne _ _ _ h #align finset.weighted_vsub_filter_of_ne Finset.weightedVSub_filter_of_ne /-- A constant multiplier of the weights in `weightedVSub_of` may be moved outside the sum. -/ theorem weightedVSub_const_smul (w : ι → k) (p : ι → P) (c : k) : s.weightedVSub p (c • w) = c • s.weightedVSub p w := s.weightedVSubOfPoint_const_smul _ _ _ _ #align finset.weighted_vsub_const_smul Finset.weightedVSub_const_smul instance : AffineSpace (ι → k) (ι → k) := Pi.instAddTorsor variable (k) /-- A weighted sum of the results of subtracting a default base point from the given points, added to that base point, as an affine map on the weights. This is intended to be used when the sum of the weights is 1, in which case it is an affine combination (barycenter) of the points with the given weights; that condition is specified as a hypothesis on those lemmas that require it. -/ def affineCombination (p : ι → P) : (ι → k) →ᵃ[k] P where toFun w := s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty linear := s.weightedVSub p map_vadd' w₁ w₂ := by simp_rw [vadd_vadd, weightedVSub, vadd_eq_add, LinearMap.map_add] #align finset.affine_combination Finset.affineCombination /-- The linear map corresponding to `affineCombination` is `weightedVSub`. -/ @[simp] theorem affineCombination_linear (p : ι → P) : (s.affineCombination k p).linear = s.weightedVSub p := rfl #align finset.affine_combination_linear Finset.affineCombination_linear variable {k} /-- Applying `affineCombination` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `affineCombination` would involve selecting a preferred base point with `affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one` and then using `weightedVSubOfPoint_apply`. -/ theorem affineCombination_apply (w : ι → k) (p : ι → P) : (s.affineCombination k p) w = s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty := rfl #align finset.affine_combination_apply Finset.affineCombination_apply /-- The value of `affineCombination`, where the given points are equal. -/ @[simp] theorem affineCombination_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 1) : s.affineCombination k (fun _ => p) w = p := by rw [affineCombination_apply, s.weightedVSubOfPoint_apply_const, h, one_smul, vsub_vadd] #align finset.affine_combination_apply_const Finset.affineCombination_apply_const /-- `affineCombination` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem affineCombination_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.affineCombination k p₁ w₁ = s.affineCombination k p₂ w₂ := by simp_rw [affineCombination_apply, s.weightedVSubOfPoint_congr hw hp] #align finset.affine_combination_congr Finset.affineCombination_congr /-- `affineCombination` gives the sum with any base point, when the sum of the weights is 1. -/ theorem affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b : P) : s.affineCombination k p w = s.weightedVSubOfPoint p b w +ᵥ b := s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w p h _ _ #align finset.affine_combination_eq_weighted_vsub_of_point_vadd_of_sum_eq_one Finset.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one /-- Adding a `weightedVSub` to an `affineCombination`. -/ theorem weightedVSub_vadd_affineCombination (w₁ w₂ : ι → k) (p : ι → P) : s.weightedVSub p w₁ +ᵥ s.affineCombination k p w₂ = s.affineCombination k p (w₁ + w₂) := by rw [← vadd_eq_add, AffineMap.map_vadd, affineCombination_linear] #align finset.weighted_vsub_vadd_affine_combination Finset.weightedVSub_vadd_affineCombination /-- Subtracting two `affineCombination`s. -/ theorem affineCombination_vsub (w₁ w₂ : ι → k) (p : ι → P) : s.affineCombination k p w₁ -ᵥ s.affineCombination k p w₂ = s.weightedVSub p (w₁ - w₂) := by rw [← AffineMap.linearMap_vsub, affineCombination_linear, vsub_eq_sub] #align finset.affine_combination_vsub Finset.affineCombination_vsub theorem attach_affineCombination_of_injective [DecidableEq P] (s : Finset P) (w : P → k) (f : s → P) (hf : Function.Injective f) : s.attach.affineCombination k f (w ∘ f) = (image f univ).affineCombination k id w := by simp only [affineCombination, weightedVSubOfPoint_apply, id, vadd_right_cancel_iff, Function.comp_apply, AffineMap.coe_mk] let g₁ : s → V := fun i => w (f i) • (f i -ᵥ Classical.choice S.nonempty) let g₂ : P → V := fun i => w i • (i -ᵥ Classical.choice S.nonempty) change univ.sum g₁ = (image f univ).sum g₂ have hgf : g₁ = g₂ ∘ f := by ext simp rw [hgf, sum_image] · simp only [Function.comp_apply] · exact fun _ _ _ _ hxy => hf hxy #align finset.attach_affine_combination_of_injective Finset.attach_affineCombination_of_injective theorem attach_affineCombination_coe (s : Finset P) (w : P → k) : s.attach.affineCombination k ((↑) : s → P) (w ∘ (↑)) = s.affineCombination k id w := by classical rw [attach_affineCombination_of_injective s w ((↑) : s → P) Subtype.coe_injective, univ_eq_attach, attach_image_val] #align finset.attach_affine_combination_coe Finset.attach_affineCombination_coe /-- Viewing a module as an affine space modelled on itself, a `weightedVSub` is just a linear combination. -/ @[simp] theorem weightedVSub_eq_linear_combination {ι} (s : Finset ι) {w : ι → k} {p : ι → V} (hw : s.sum w = 0) : s.weightedVSub p w = ∑ i ∈ s, w i • p i := by simp [s.weightedVSub_apply, vsub_eq_sub, smul_sub, ← Finset.sum_smul, hw] #align finset.weighted_vsub_eq_linear_combination Finset.weightedVSub_eq_linear_combination /-- Viewing a module as an affine space modelled on itself, affine combinations are just linear combinations. -/ @[simp] theorem affineCombination_eq_linear_combination (s : Finset ι) (p : ι → V) (w : ι → k) (hw : ∑ i ∈ s, w i = 1) : s.affineCombination k p w = ∑ i ∈ s, w i • p i := by simp [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw 0] #align finset.affine_combination_eq_linear_combination Finset.affineCombination_eq_linear_combination /-- An `affineCombination` equals a point if that point is in the set and has weight 1 and the other points in the set have weight 0. -/ @[simp] theorem affineCombination_of_eq_one_of_eq_zero (w : ι → k) (p : ι → P) {i : ι} (his : i ∈ s) (hwi : w i = 1) (hw0 : ∀ i2 ∈ s, i2 ≠ i → w i2 = 0) : s.affineCombination k p w = p i := by have h1 : ∑ i ∈ s, w i = 1 := hwi ▸ sum_eq_single i hw0 fun h => False.elim (h his) rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h1 (p i), weightedVSubOfPoint_apply] convert zero_vadd V (p i) refine sum_eq_zero ?_ intro i2 hi2 by_cases h : i2 = i · simp [h] · simp [hw0 i2 hi2 h] #align finset.affine_combination_of_eq_one_of_eq_zero Finset.affineCombination_of_eq_one_of_eq_zero /-- An affine combination is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem affineCombination_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.affineCombination k p w = s₂.affineCombination k p (Set.indicator (↑s₁) w) := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_indicator_subset _ _ _ h] #align finset.affine_combination_indicator_subset Finset.affineCombination_indicator_subset /-- An affine combination, over the image of an embedding, equals an affine combination with the same points and weights over the original `Finset`. -/ theorem affineCombination_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).affineCombination k p w = s₂.affineCombination k (p ∘ e) (w ∘ e) := by simp_rw [affineCombination_apply, weightedVSubOfPoint_map] #align finset.affine_combination_map Finset.affineCombination_map /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `affineCombination` expressions. -/ theorem sum_smul_vsub_eq_affineCombination_vsub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.affineCombination k p₁ w -ᵥ s.affineCombination k p₂ w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ #align finset.sum_smul_vsub_eq_affine_combination_vsub Finset.sum_smul_vsub_eq_affineCombination_vsub /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 1. -/ theorem sum_smul_vsub_const_eq_affineCombination_vsub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.affineCombination k p₁ w -ᵥ p₂ := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] #align finset.sum_smul_vsub_const_eq_affine_combination_vsub Finset.sum_smul_vsub_const_eq_affineCombination_vsub /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 1. -/ theorem sum_smul_const_vsub_eq_vsub_affineCombination (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = p₁ -ᵥ s.affineCombination k p₂ w := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] #align finset.sum_smul_const_vsub_eq_vsub_affine_combination Finset.sum_smul_const_vsub_eq_vsub_affineCombination /-- A weighted sum may be split into a subtraction of affine combinations over two subsets. -/
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
526
530
theorem affineCombination_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).affineCombination k p w -ᵥ s₂.affineCombination k p (-w) = s.weightedVSub p w := by
simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.weightedVSub_sdiff_sub h _ _
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.Finsupp import Mathlib.Algebra.MonoidAlgebra.Support import Mathlib.Algebra.DirectSum.Internal import Mathlib.RingTheory.GradedAlgebra.Basic #align_import algebra.monoid_algebra.grading from "leanprover-community/mathlib"@"feb99064803fd3108e37c18b0f77d0a8344677a3" /-! # Internal grading of an `AddMonoidAlgebra` In this file, we show that an `AddMonoidAlgebra` has an internal direct sum structure. ## Main results * `AddMonoidAlgebra.gradeBy R f i`: the `i`th grade of an `R[M]` given by the degree function `f`. * `AddMonoidAlgebra.grade R i`: the `i`th grade of an `R[M]` when the degree function is the identity. * `AddMonoidAlgebra.gradeBy.gradedAlgebra`: `AddMonoidAlgebra` is an algebra graded by `AddMonoidAlgebra.gradeBy`. * `AddMonoidAlgebra.grade.gradedAlgebra`: `AddMonoidAlgebra` is an algebra graded by `AddMonoidAlgebra.grade`. * `AddMonoidAlgebra.gradeBy.isInternal`: propositionally, the statement that `AddMonoidAlgebra.gradeBy` defines an internal graded structure. * `AddMonoidAlgebra.grade.isInternal`: propositionally, the statement that `AddMonoidAlgebra.grade` defines an internal graded structure when the degree function is the identity. -/ noncomputable section namespace AddMonoidAlgebra variable {M : Type*} {ι : Type*} {R : Type*} section variable (R) [CommSemiring R] /-- The submodule corresponding to each grade given by the degree function `f`. -/ abbrev gradeBy (f : M → ι) (i : ι) : Submodule R R[M] where carrier := { a | ∀ m, m ∈ a.support → f m = i } zero_mem' m h := by cases h add_mem' {a b} ha hb m h := by classical exact (Finset.mem_union.mp (Finsupp.support_add h)).elim (ha m) (hb m) smul_mem' a m h := Set.Subset.trans Finsupp.support_smul h #align add_monoid_algebra.grade_by AddMonoidAlgebra.gradeBy /-- The submodule corresponding to each grade. -/ abbrev grade (m : M) : Submodule R R[M] := gradeBy R id m #align add_monoid_algebra.grade AddMonoidAlgebra.grade theorem gradeBy_id : gradeBy R (id : M → M) = grade R := rfl #align add_monoid_algebra.grade_by_id AddMonoidAlgebra.gradeBy_id theorem mem_gradeBy_iff (f : M → ι) (i : ι) (a : R[M]) : a ∈ gradeBy R f i ↔ (a.support : Set M) ⊆ f ⁻¹' {i} := by rfl #align add_monoid_algebra.mem_grade_by_iff AddMonoidAlgebra.mem_gradeBy_iff theorem mem_grade_iff (m : M) (a : R[M]) : a ∈ grade R m ↔ a.support ⊆ {m} := by rw [← Finset.coe_subset, Finset.coe_singleton] rfl #align add_monoid_algebra.mem_grade_iff AddMonoidAlgebra.mem_grade_iff theorem mem_grade_iff' (m : M) (a : R[M]) : a ∈ grade R m ↔ a ∈ (LinearMap.range (Finsupp.lsingle m : R →ₗ[R] M →₀ R) : Submodule R R[M]) := by rw [mem_grade_iff, Finsupp.support_subset_singleton'] apply exists_congr intro r constructor <;> exact Eq.symm #align add_monoid_algebra.mem_grade_iff' AddMonoidAlgebra.mem_grade_iff' theorem grade_eq_lsingle_range (m : M) : grade R m = LinearMap.range (Finsupp.lsingle m : R →ₗ[R] M →₀ R) := Submodule.ext (mem_grade_iff' R m) #align add_monoid_algebra.grade_eq_lsingle_range AddMonoidAlgebra.grade_eq_lsingle_range theorem single_mem_gradeBy {R} [CommSemiring R] (f : M → ι) (m : M) (r : R) : Finsupp.single m r ∈ gradeBy R f (f m) := by intro x hx rw [Finset.mem_singleton.mp (Finsupp.support_single_subset hx)] #align add_monoid_algebra.single_mem_grade_by AddMonoidAlgebra.single_mem_gradeBy theorem single_mem_grade {R} [CommSemiring R] (i : M) (r : R) : Finsupp.single i r ∈ grade R i := single_mem_gradeBy _ _ _ #align add_monoid_algebra.single_mem_grade AddMonoidAlgebra.single_mem_grade end open DirectSum instance gradeBy.gradedMonoid [AddMonoid M] [AddMonoid ι] [CommSemiring R] (f : M →+ ι) : SetLike.GradedMonoid (gradeBy R f : ι → Submodule R R[M]) where one_mem m h := by rw [one_def] at h obtain rfl : m = 0 := Finset.mem_singleton.1 <| Finsupp.support_single_subset h apply map_zero mul_mem i j a b ha hb c hc := by classical obtain ⟨ma, hma, mb, hmb, rfl⟩ : ∃ y ∈ a.support, ∃ z ∈ b.support, y + z = c := Finset.mem_add.1 <| support_mul a b hc rw [map_add, ha ma hma, hb mb hmb] #align add_monoid_algebra.grade_by.graded_monoid AddMonoidAlgebra.gradeBy.gradedMonoid instance grade.gradedMonoid [AddMonoid M] [CommSemiring R] : SetLike.GradedMonoid (grade R : M → Submodule R R[M]) := by apply gradeBy.gradedMonoid (AddMonoidHom.id _) #align add_monoid_algebra.grade.graded_monoid AddMonoidAlgebra.grade.gradedMonoid variable [AddMonoid M] [DecidableEq ι] [AddMonoid ι] [CommSemiring R] (f : M →+ ι) /-- Auxiliary definition; the canonical grade decomposition, used to provide `DirectSum.decompose`. -/ def decomposeAux : R[M] →ₐ[R] ⨁ i : ι, gradeBy R f i := AddMonoidAlgebra.lift R M _ { toFun := fun m => DirectSum.of (fun i : ι => gradeBy R f i) (f (Multiplicative.toAdd m)) ⟨Finsupp.single (Multiplicative.toAdd m) 1, single_mem_gradeBy _ _ _⟩ map_one' := DirectSum.of_eq_of_gradedMonoid_eq (by congr 2 <;> simp) map_mul' := fun i j => by symm dsimp only [toAdd_one, Eq.ndrec, Set.mem_setOf_eq, ne_eq, OneHom.toFun_eq_coe, OneHom.coe_mk, toAdd_mul] convert DirectSum.of_mul_of (A := (fun i : ι => gradeBy R f i)) _ _ repeat { rw [ AddMonoidHom.map_add] } simp only [SetLike.coe_gMul] exact Eq.trans (by rw [one_mul]) single_mul_single.symm } #align add_monoid_algebra.decompose_aux AddMonoidAlgebra.decomposeAux theorem decomposeAux_single (m : M) (r : R) : decomposeAux f (Finsupp.single m r) = DirectSum.of (fun i : ι => gradeBy R f i) (f m) ⟨Finsupp.single m r, single_mem_gradeBy _ _ _⟩ := by refine (lift_single _ _ _).trans ?_ refine (DirectSum.of_smul R _ _ _).symm.trans ?_ apply DirectSum.of_eq_of_gradedMonoid_eq refine Sigma.subtype_ext rfl ?_ refine (Finsupp.smul_single' _ _ _).trans ?_ rw [mul_one] rfl #align add_monoid_algebra.decompose_aux_single AddMonoidAlgebra.decomposeAux_single
Mathlib/Algebra/MonoidAlgebra/Grading.lean
153
177
theorem decomposeAux_coe {i : ι} (x : gradeBy R f i) : decomposeAux f ↑x = DirectSum.of (fun i => gradeBy R f i) i x := by
classical obtain ⟨x, hx⟩ := x revert hx refine Finsupp.induction x ?_ ?_ · intro hx symm exact AddMonoidHom.map_zero _ · intro m b y hmy hb ih hmby have : Disjoint (Finsupp.single m b).support y.support := by simpa only [Finsupp.support_single_ne_zero _ hb, Finset.disjoint_singleton_left] rw [mem_gradeBy_iff, Finsupp.support_add_eq this, Finset.coe_union, Set.union_subset_iff] at hmby cases' hmby with h1 h2 have : f m = i := by rwa [Finsupp.support_single_ne_zero _ hb, Finset.coe_singleton, Set.singleton_subset_iff] at h1 subst this simp only [AlgHom.map_add, Submodule.coe_mk, decomposeAux_single f m] let ih' := ih h2 dsimp at ih' rw [ih', ← AddMonoidHom.map_add] apply DirectSum.of_eq_of_gradedMonoid_eq congr 2
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Finset.Pointwise #align_import combinatorics.additive.e_transform from "leanprover-community/mathlib"@"207c92594599a06e7c134f8d00a030a83e6c7259" /-! # e-transforms e-transforms are a family of transformations of pairs of finite sets that aim to reduce the size of the sumset while keeping some invariant the same. This file defines a few of them, to be used as internals of other proofs. ## Main declarations * `Finset.mulDysonETransform`: The Dyson e-transform. Replaces `(s, t)` by `(s ∪ e • t, t ∩ e⁻¹ • s)`. The additive version preserves `|s ∩ [1, m]| + |t ∩ [1, m - e]|`. * `Finset.mulETransformLeft`/`Finset.mulETransformRight`: Replace `(s, t)` by `(s ∩ s • e, t ∪ e⁻¹ • t)` and `(s ∪ s • e, t ∩ e⁻¹ • t)`. Preserve (together) the sum of the cardinalities (see `Finset.MulETransform.card`). In particular, one of the two transforms increases the sum of the cardinalities and the other one decreases it. See `le_or_lt_of_add_le_add` and around. ## TODO Prove the invariance property of the Dyson e-transform. -/ open MulOpposite open Pointwise variable {α : Type*} [DecidableEq α] namespace Finset /-! ### Dyson e-transform -/ section CommGroup variable [CommGroup α] (e : α) (x : Finset α × Finset α) /-- The **Dyson e-transform**. Turns `(s, t)` into `(s ∪ e • t, t ∩ e⁻¹ • s)`. This reduces the product of the two sets. -/ @[to_additive (attr := simps) "The **Dyson e-transform**. Turns `(s, t)` into `(s ∪ e +ᵥ t, t ∩ -e +ᵥ s)`. This reduces the sum of the two sets."] def mulDysonETransform : Finset α × Finset α := (x.1 ∪ e • x.2, x.2 ∩ e⁻¹ • x.1) #align finset.mul_dyson_e_transform Finset.mulDysonETransform #align finset.add_dyson_e_transform Finset.addDysonETransform @[to_additive] theorem mulDysonETransform.subset : (mulDysonETransform e x).1 * (mulDysonETransform e x).2 ⊆ x.1 * x.2 := by refine union_mul_inter_subset_union.trans (union_subset Subset.rfl ?_) rw [mul_smul_comm, smul_mul_assoc, inv_smul_smul, mul_comm] #align finset.mul_dyson_e_transform.subset Finset.mulDysonETransform.subset #align finset.add_dyson_e_transform.subset Finset.addDysonETransform.subset @[to_additive] theorem mulDysonETransform.card : (mulDysonETransform e x).1.card + (mulDysonETransform e x).2.card = x.1.card + x.2.card := by dsimp rw [← card_smul_finset e (_ ∩ _), smul_finset_inter, smul_inv_smul, inter_comm, card_union_add_card_inter, card_smul_finset] #align finset.mul_dyson_e_transform.card Finset.mulDysonETransform.card #align finset.add_dyson_e_transform.card Finset.addDysonETransform.card @[to_additive (attr := simp)] theorem mulDysonETransform_idem : mulDysonETransform e (mulDysonETransform e x) = mulDysonETransform e x := by ext : 1 <;> dsimp · rw [smul_finset_inter, smul_inv_smul, inter_comm, union_eq_left] exact inter_subset_union · rw [smul_finset_union, inv_smul_smul, union_comm, inter_eq_left] exact inter_subset_union #align finset.mul_dyson_e_transform_idem Finset.mulDysonETransform_idem #align finset.add_dyson_e_transform_idem Finset.addDysonETransform_idem variable {e x} @[to_additive] theorem mulDysonETransform.smul_finset_snd_subset_fst : e • (mulDysonETransform e x).2 ⊆ (mulDysonETransform e x).1 := by dsimp rw [smul_finset_inter, smul_inv_smul, inter_comm] exact inter_subset_union #align finset.mul_dyson_e_transform.smul_finset_snd_subset_fst Finset.mulDysonETransform.smul_finset_snd_subset_fst #align finset.add_dyson_e_transform.vadd_finset_snd_subset_fst Finset.addDysonETransform.vadd_finset_snd_subset_fst end CommGroup /-! ### Two unnamed e-transforms The following two transforms both reduce the product/sum of the two sets. Further, one of them must decrease the sum of the size of the sets (and then the other increases it). This pair of transforms doesn't seem to be named in the literature. It is used by Sanders in his bound on Roth numbers, and by DeVos in his proof of Cauchy-Davenport. -/ section Group variable [Group α] (e : α) (x : Finset α × Finset α) /-- An **e-transform**. Turns `(s, t)` into `(s ∩ s • e, t ∪ e⁻¹ • t)`. This reduces the product of the two sets. -/ @[to_additive (attr := simps) "An **e-transform**. Turns `(s, t)` into `(s ∩ s +ᵥ e, t ∪ -e +ᵥ t)`. This reduces the sum of the two sets."] def mulETransformLeft : Finset α × Finset α := (x.1 ∩ op e • x.1, x.2 ∪ e⁻¹ • x.2) #align finset.mul_e_transform_left Finset.mulETransformLeft #align finset.add_e_transform_left Finset.addETransformLeft /-- An **e-transform**. Turns `(s, t)` into `(s ∪ s • e, t ∩ e⁻¹ • t)`. This reduces the product of the two sets. -/ @[to_additive (attr := simps) "An **e-transform**. Turns `(s, t)` into `(s ∪ s +ᵥ e, t ∩ -e +ᵥ t)`. This reduces the sum of the two sets."] def mulETransformRight : Finset α × Finset α := (x.1 ∪ op e • x.1, x.2 ∩ e⁻¹ • x.2) #align finset.mul_e_transform_right Finset.mulETransformRight #align finset.add_e_transform_right Finset.addETransformRight @[to_additive (attr := simp)] theorem mulETransformLeft_one : mulETransformLeft 1 x = x := by simp [mulETransformLeft] #align finset.mul_e_transform_left_one Finset.mulETransformLeft_one #align finset.add_e_transform_left_zero Finset.addETransformLeft_zero @[to_additive (attr := simp)] theorem mulETransformRight_one : mulETransformRight 1 x = x := by simp [mulETransformRight] #align finset.mul_e_transform_right_one Finset.mulETransformRight_one #align finset.add_e_transform_right_zero Finset.addETransformRight_zero @[to_additive]
Mathlib/Combinatorics/Additive/ETransform.lean
142
145
theorem mulETransformLeft.fst_mul_snd_subset : (mulETransformLeft e x).1 * (mulETransformLeft e x).2 ⊆ x.1 * x.2 := by
refine inter_mul_union_subset_union.trans (union_subset Subset.rfl ?_) rw [op_smul_finset_mul_eq_mul_smul_finset, smul_inv_smul]
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.RingTheory.IntegralClosure import Mathlib.RingTheory.FractionalIdeal.Basic #align_import ring_theory.fractional_ideal from "leanprover-community/mathlib"@"ed90a7d327c3a5caf65a6faf7e8a0d63c4605df7" /-! # More operations on fractional ideals ## Main definitions * `map` is the pushforward of a fractional ideal along an algebra morphism Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions). * `FractionalIdeal R⁰ K` is the type of fractional ideals in the field of fractions * `Div (FractionalIdeal R⁰ K)` instance: the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined) ## Main statement * `isNoetherian` states that every fractional ideal of a noetherian integral domain is noetherian ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] [loc : IsLocalization S P] section variable {P' : Type*} [CommRing P'] [Algebra R P'] [loc' : IsLocalization S P'] variable {P'' : Type*} [CommRing P''] [Algebra R P''] [loc'' : IsLocalization S P''] theorem _root_.IsFractional.map (g : P →ₐ[R] P') {I : Submodule R P} : IsFractional S I → IsFractional S (Submodule.map g.toLinearMap I) | ⟨a, a_nonzero, hI⟩ => ⟨a, a_nonzero, fun b hb => by obtain ⟨b', b'_mem, hb'⟩ := Submodule.mem_map.mp hb rw [AlgHom.toLinearMap_apply] at hb' obtain ⟨x, hx⟩ := hI b' b'_mem use x rw [← g.commutes, hx, g.map_smul, hb']⟩ #align is_fractional.map IsFractional.map /-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/ def map (g : P →ₐ[R] P') : FractionalIdeal S P → FractionalIdeal S P' := fun I => ⟨Submodule.map g.toLinearMap I, I.isFractional.map g⟩ #align fractional_ideal.map FractionalIdeal.map @[simp, norm_cast] theorem coe_map (g : P →ₐ[R] P') (I : FractionalIdeal S P) : ↑(map g I) = Submodule.map g.toLinearMap I := rfl #align fractional_ideal.coe_map FractionalIdeal.coe_map @[simp] theorem mem_map {I : FractionalIdeal S P} {g : P →ₐ[R] P'} {y : P'} : y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y := Submodule.mem_map #align fractional_ideal.mem_map FractionalIdeal.mem_map variable (I J : FractionalIdeal S P) (g : P →ₐ[R] P') @[simp] theorem map_id : I.map (AlgHom.id _ _) = I := coeToSubmodule_injective (Submodule.map_id (I : Submodule R P)) #align fractional_ideal.map_id FractionalIdeal.map_id @[simp] theorem map_comp (g' : P' →ₐ[R] P'') : I.map (g'.comp g) = (I.map g).map g' := coeToSubmodule_injective (Submodule.map_comp g.toLinearMap g'.toLinearMap I) #align fractional_ideal.map_comp FractionalIdeal.map_comp @[simp, norm_cast] theorem map_coeIdeal (I : Ideal R) : (I : FractionalIdeal S P).map g = I := by ext x simp only [mem_coeIdeal] constructor · rintro ⟨_, ⟨y, hy, rfl⟩, rfl⟩ exact ⟨y, hy, (g.commutes y).symm⟩ · rintro ⟨y, hy, rfl⟩ exact ⟨_, ⟨y, hy, rfl⟩, g.commutes y⟩ #align fractional_ideal.map_coe_ideal FractionalIdeal.map_coeIdeal @[simp] theorem map_one : (1 : FractionalIdeal S P).map g = 1 := map_coeIdeal g ⊤ #align fractional_ideal.map_one FractionalIdeal.map_one @[simp] theorem map_zero : (0 : FractionalIdeal S P).map g = 0 := map_coeIdeal g 0 #align fractional_ideal.map_zero FractionalIdeal.map_zero @[simp] theorem map_add : (I + J).map g = I.map g + J.map g := coeToSubmodule_injective (Submodule.map_sup _ _ _) #align fractional_ideal.map_add FractionalIdeal.map_add @[simp] theorem map_mul : (I * J).map g = I.map g * J.map g := by simp only [mul_def] exact coeToSubmodule_injective (Submodule.map_mul _ _ _) #align fractional_ideal.map_mul FractionalIdeal.map_mul @[simp] theorem map_map_symm (g : P ≃ₐ[R] P') : (I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I := by rw [← map_comp, g.symm_comp, map_id] #align fractional_ideal.map_map_symm FractionalIdeal.map_map_symm @[simp] theorem map_symm_map (I : FractionalIdeal S P') (g : P ≃ₐ[R] P') : (I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I := by rw [← map_comp, g.comp_symm, map_id] #align fractional_ideal.map_symm_map FractionalIdeal.map_symm_map theorem map_mem_map {f : P →ₐ[R] P'} (h : Function.Injective f) {x : P} {I : FractionalIdeal S P} : f x ∈ map f I ↔ x ∈ I := mem_map.trans ⟨fun ⟨_, hx', x'_eq⟩ => h x'_eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ #align fractional_ideal.map_mem_map FractionalIdeal.map_mem_map theorem map_injective (f : P →ₐ[R] P') (h : Function.Injective f) : Function.Injective (map f : FractionalIdeal S P → FractionalIdeal S P') := fun _ _ hIJ => ext fun _ => (map_mem_map h).symm.trans (hIJ.symm ▸ map_mem_map h) #align fractional_ideal.map_injective FractionalIdeal.map_injective /-- If `g` is an equivalence, `map g` is an isomorphism -/ def mapEquiv (g : P ≃ₐ[R] P') : FractionalIdeal S P ≃+* FractionalIdeal S P' where toFun := map g invFun := map g.symm map_add' I J := map_add I J _ map_mul' I J := map_mul I J _ left_inv I := by rw [← map_comp, AlgEquiv.symm_comp, map_id] right_inv I := by rw [← map_comp, AlgEquiv.comp_symm, map_id] #align fractional_ideal.map_equiv FractionalIdeal.mapEquiv @[simp] theorem coeFun_mapEquiv (g : P ≃ₐ[R] P') : (mapEquiv g : FractionalIdeal S P → FractionalIdeal S P') = map g := rfl #align fractional_ideal.coe_fun_map_equiv FractionalIdeal.coeFun_mapEquiv @[simp] theorem mapEquiv_apply (g : P ≃ₐ[R] P') (I : FractionalIdeal S P) : mapEquiv g I = map (↑g) I := rfl #align fractional_ideal.map_equiv_apply FractionalIdeal.mapEquiv_apply @[simp] theorem mapEquiv_symm (g : P ≃ₐ[R] P') : ((mapEquiv g).symm : FractionalIdeal S P' ≃+* _) = mapEquiv g.symm := rfl #align fractional_ideal.map_equiv_symm FractionalIdeal.mapEquiv_symm @[simp] theorem mapEquiv_refl : mapEquiv AlgEquiv.refl = RingEquiv.refl (FractionalIdeal S P) := RingEquiv.ext fun x => by simp #align fractional_ideal.map_equiv_refl FractionalIdeal.mapEquiv_refl theorem isFractional_span_iff {s : Set P} : IsFractional S (span R s) ↔ ∃ a ∈ S, ∀ b : P, b ∈ s → IsInteger R (a • b) := ⟨fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => h b (subset_span hb)⟩, fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => span_induction hb h (by rw [smul_zero] exact isInteger_zero) (fun x y hx hy => by rw [smul_add] exact isInteger_add hx hy) fun s x hx => by rw [smul_comm] exact isInteger_smul hx⟩⟩ #align fractional_ideal.is_fractional_span_iff FractionalIdeal.isFractional_span_iff theorem isFractional_of_fg {I : Submodule R P} (hI : I.FG) : IsFractional S I := by rcases hI with ⟨I, rfl⟩ rcases exist_integer_multiples_of_finset S I with ⟨⟨s, hs1⟩, hs⟩ rw [isFractional_span_iff] exact ⟨s, hs1, hs⟩ #align fractional_ideal.is_fractional_of_fg FractionalIdeal.isFractional_of_fg theorem mem_span_mul_finite_of_mem_mul {I J : FractionalIdeal S P} {x : P} (hx : x ∈ I * J) : ∃ T T' : Finset P, (T : Set P) ⊆ I ∧ (T' : Set P) ⊆ J ∧ x ∈ span R (T * T' : Set P) := Submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx) #align fractional_ideal.mem_span_mul_finite_of_mem_mul FractionalIdeal.mem_span_mul_finite_of_mem_mul variable (S) theorem coeIdeal_fg (inj : Function.Injective (algebraMap R P)) (I : Ideal R) : FG ((I : FractionalIdeal S P) : Submodule R P) ↔ I.FG := coeSubmodule_fg _ inj _ #align fractional_ideal.coe_ideal_fg FractionalIdeal.coeIdeal_fg variable {S} theorem fg_unit (I : (FractionalIdeal S P)ˣ) : FG (I : Submodule R P) := Submodule.fg_unit <| Units.map (coeSubmoduleHom S P).toMonoidHom I #align fractional_ideal.fg_unit FractionalIdeal.fg_unit theorem fg_of_isUnit (I : FractionalIdeal S P) (h : IsUnit I) : FG (I : Submodule R P) := fg_unit h.unit #align fractional_ideal.fg_of_is_unit FractionalIdeal.fg_of_isUnit theorem _root_.Ideal.fg_of_isUnit (inj : Function.Injective (algebraMap R P)) (I : Ideal R) (h : IsUnit (I : FractionalIdeal S P)) : I.FG := by rw [← coeIdeal_fg S inj I] exact FractionalIdeal.fg_of_isUnit I h #align ideal.fg_of_is_unit Ideal.fg_of_isUnit variable (S P P') /-- `canonicalEquiv f f'` is the canonical equivalence between the fractional ideals in `P` and in `P'`, which are both localizations of `R` at `S`. -/ noncomputable irreducible_def canonicalEquiv : FractionalIdeal S P ≃+* FractionalIdeal S P' := mapEquiv { ringEquivOfRingEquiv P P' (RingEquiv.refl R) (show S.map _ = S by rw [RingEquiv.toMonoidHom_refl, Submonoid.map_id]) with commutes' := fun r => ringEquivOfRingEquiv_eq _ _ } #align fractional_ideal.canonical_equiv FractionalIdeal.canonicalEquiv @[simp] theorem mem_canonicalEquiv_apply {I : FractionalIdeal S P} {x : P'} : x ∈ canonicalEquiv S P P' I ↔ ∃ y ∈ I, IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) (y : P) = x := by rw [canonicalEquiv, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ #align fractional_ideal.mem_canonical_equiv_apply FractionalIdeal.mem_canonicalEquiv_apply @[simp] theorem canonicalEquiv_symm : (canonicalEquiv S P P').symm = canonicalEquiv S P' P := RingEquiv.ext fun I => SetLike.ext_iff.mpr fun x => by rw [mem_canonicalEquiv_apply, canonicalEquiv, mapEquiv_symm, mapEquiv_apply, mem_map] exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩ #align fractional_ideal.canonical_equiv_symm FractionalIdeal.canonicalEquiv_symm theorem canonicalEquiv_flip (I) : canonicalEquiv S P P' (canonicalEquiv S P' P I) = I := by rw [← canonicalEquiv_symm]; erw [RingEquiv.apply_symm_apply] #align fractional_ideal.canonical_equiv_flip FractionalIdeal.canonicalEquiv_flip @[simp] theorem canonicalEquiv_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] (I : FractionalIdeal S P) : canonicalEquiv S P' P'' (canonicalEquiv S P P' I) = canonicalEquiv S P P'' I := by ext simp only [IsLocalization.map_map, RingHomInvPair.comp_eq₂, mem_canonicalEquiv_apply, exists_prop, exists_exists_and_eq_and] #align fractional_ideal.canonical_equiv_canonical_equiv FractionalIdeal.canonicalEquiv_canonicalEquiv theorem canonicalEquiv_trans_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] : (canonicalEquiv S P P').trans (canonicalEquiv S P' P'') = canonicalEquiv S P P'' := RingEquiv.ext (canonicalEquiv_canonicalEquiv S P P' P'') #align fractional_ideal.canonical_equiv_trans_canonical_equiv FractionalIdeal.canonicalEquiv_trans_canonicalEquiv @[simp] theorem canonicalEquiv_coeIdeal (I : Ideal R) : canonicalEquiv S P P' I = I := by ext simp [IsLocalization.map_eq] #align fractional_ideal.canonical_equiv_coe_ideal FractionalIdeal.canonicalEquiv_coeIdeal @[simp] theorem canonicalEquiv_self : canonicalEquiv S P P = RingEquiv.refl _ := by rw [← canonicalEquiv_trans_canonicalEquiv S P P] convert (canonicalEquiv S P P).symm_trans_self exact (canonicalEquiv_symm S P P).symm #align fractional_ideal.canonical_equiv_self FractionalIdeal.canonicalEquiv_self end section IsFractionRing /-! ### `IsFractionRing` section This section concerns fractional ideals in the field of fractions, i.e. the type `FractionalIdeal R⁰ K` where `IsFractionRing R K`. -/ variable {K K' : Type*} [Field K] [Field K'] variable [Algebra R K] [IsFractionRing R K] [Algebra R K'] [IsFractionRing R K'] variable {I J : FractionalIdeal R⁰ K} (h : K →ₐ[R] K') /-- Nonzero fractional ideals contain a nonzero integer. -/ theorem exists_ne_zero_mem_isInteger [Nontrivial R] (hI : I ≠ 0) : ∃ x, x ≠ 0 ∧ algebraMap R K x ∈ I := by obtain ⟨y : K, y_mem, y_not_mem⟩ := SetLike.exists_of_lt (by simpa only using bot_lt_iff_ne_bot.mpr hI) have y_ne_zero : y ≠ 0 := by simpa using y_not_mem obtain ⟨z, ⟨x, hx⟩⟩ := exists_integer_multiple R⁰ y refine ⟨x, ?_, ?_⟩ · rw [Ne, ← @IsFractionRing.to_map_eq_zero_iff R _ K, hx, Algebra.smul_def] exact mul_ne_zero (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors z.2) y_ne_zero · rw [hx] exact smul_mem _ _ y_mem #align fractional_ideal.exists_ne_zero_mem_is_integer FractionalIdeal.exists_ne_zero_mem_isInteger theorem map_ne_zero [Nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 := by obtain ⟨x, x_ne_zero, hx⟩ := exists_ne_zero_mem_isInteger hI contrapose! x_ne_zero with map_eq_zero refine IsFractionRing.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr ?_)) exact ⟨algebraMap R K x, hx, h.commutes x⟩ #align fractional_ideal.map_ne_zero FractionalIdeal.map_ne_zero @[simp] theorem map_eq_zero_iff [Nontrivial R] : I.map h = 0 ↔ I = 0 := ⟨not_imp_not.mp (map_ne_zero _), fun hI => hI.symm ▸ map_zero h⟩ #align fractional_ideal.map_eq_zero_iff FractionalIdeal.map_eq_zero_iff theorem coeIdeal_injective : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal R⁰ K)) := coeIdeal_injective' le_rfl #align fractional_ideal.coe_ideal_injective FractionalIdeal.coeIdeal_injective theorem coeIdeal_inj {I J : Ideal R} : (I : FractionalIdeal R⁰ K) = (J : FractionalIdeal R⁰ K) ↔ I = J := coeIdeal_inj' le_rfl #align fractional_ideal.coe_ideal_inj FractionalIdeal.coeIdeal_inj @[simp] theorem coeIdeal_eq_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 0 ↔ I = ⊥ := coeIdeal_eq_zero' le_rfl #align fractional_ideal.coe_ideal_eq_zero FractionalIdeal.coeIdeal_eq_zero theorem coeIdeal_ne_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 0 ↔ I ≠ ⊥ := coeIdeal_ne_zero' le_rfl #align fractional_ideal.coe_ideal_ne_zero FractionalIdeal.coeIdeal_ne_zero @[simp] theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by simpa only [Ideal.one_eq_top] using coeIdeal_inj #align fractional_ideal.coe_ideal_eq_one FractionalIdeal.coeIdeal_eq_one theorem coeIdeal_ne_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 1 ↔ I ≠ 1 := not_iff_not.mpr coeIdeal_eq_one #align fractional_ideal.coe_ideal_ne_one FractionalIdeal.coeIdeal_ne_one theorem num_eq_zero_iff [Nontrivial R] {I : FractionalIdeal R⁰ K} : I.num = 0 ↔ I = 0 := ⟨fun h ↦ zero_of_num_eq_bot zero_not_mem_nonZeroDivisors h, fun h ↦ h ▸ num_zero_eq (IsFractionRing.injective R K)⟩ end IsFractionRing section Quotient /-! ### `quotient` section This section defines the ideal quotient of fractional ideals. In this section we need that each non-zero `y : R` has an inverse in the localization, i.e. that the localization is a field. We satisfy this assumption by taking `S = nonZeroDivisors R`, `R`'s localization at which is a field because `R` is a domain. -/ open scoped Classical variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] [frac : IsFractionRing R₁ K] instance : Nontrivial (FractionalIdeal R₁⁰ K) := ⟨⟨0, 1, fun h => have this : (1 : K) ∈ (0 : FractionalIdeal R₁⁰ K) := by rw [← (algebraMap R₁ K).map_one] simpa only [h] using coe_mem_one R₁⁰ 1 one_ne_zero ((mem_zero_iff _).mp this)⟩⟩ theorem ne_zero_of_mul_eq_one (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : I ≠ 0 := fun hI => zero_ne_one' (FractionalIdeal R₁⁰ K) (by convert h simp [hI]) #align fractional_ideal.ne_zero_of_mul_eq_one FractionalIdeal.ne_zero_of_mul_eq_one variable [IsDomain R₁] theorem _root_.IsFractional.div_of_nonzero {I J : Submodule R₁ K} : IsFractional R₁⁰ I → IsFractional R₁⁰ J → J ≠ 0 → IsFractional R₁⁰ (I / J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩, h => by obtain ⟨y, mem_J, not_mem_zero⟩ := SetLike.exists_of_lt (show 0 < J by simpa only using bot_lt_iff_ne_bot.mpr h) obtain ⟨y', hy'⟩ := hJ y mem_J use aI * y' constructor · apply (nonZeroDivisors R₁).mul_mem haI (mem_nonZeroDivisors_iff_ne_zero.mpr _) intro y'_eq_zero have : algebraMap R₁ K aJ * y = 0 := by rw [← Algebra.smul_def, ← hy', y'_eq_zero, RingHom.map_zero] have y_zero := (mul_eq_zero.mp this).resolve_left (mt ((injective_iff_map_eq_zero (algebraMap R₁ K)).1 (IsFractionRing.injective _ _) _) (mem_nonZeroDivisors_iff_ne_zero.mp haJ)) apply not_mem_zero simpa intro b hb convert hI _ (hb _ (Submodule.smul_mem _ aJ mem_J)) using 1 rw [← hy', mul_comm b, ← Algebra.smul_def, mul_smul] #align is_fractional.div_of_nonzero IsFractional.div_of_nonzero theorem fractional_div_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : IsFractional R₁⁰ (I / J : Submodule R₁ K) := I.isFractional.div_of_nonzero J.isFractional fun H => h <| coeToSubmodule_injective <| H.trans coe_zero.symm #align fractional_ideal.fractional_div_of_nonzero FractionalIdeal.fractional_div_of_nonzero noncomputable instance : Div (FractionalIdeal R₁⁰ K) := ⟨fun I J => if h : J = 0 then 0 else ⟨I / J, fractional_div_of_nonzero h⟩⟩ variable {I J : FractionalIdeal R₁⁰ K} @[simp] theorem div_zero {I : FractionalIdeal R₁⁰ K} : I / 0 = 0 := dif_pos rfl #align fractional_ideal.div_zero FractionalIdeal.div_zero theorem div_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) : I / J = ⟨I / J, fractional_div_of_nonzero h⟩ := dif_neg h #align fractional_ideal.div_nonzero FractionalIdeal.div_nonzero @[simp] theorem coe_div {I J : FractionalIdeal R₁⁰ K} (hJ : J ≠ 0) : (↑(I / J) : Submodule R₁ K) = ↑I / (↑J : Submodule R₁ K) := congr_arg _ (dif_neg hJ) #align fractional_ideal.coe_div FractionalIdeal.coe_div theorem mem_div_iff_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) {x} : x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I := by rw [div_nonzero h] exact Submodule.mem_div_iff_forall_mul_mem #align fractional_ideal.mem_div_iff_of_nonzero FractionalIdeal.mem_div_iff_of_nonzero theorem mul_one_div_le_one {I : FractionalIdeal R₁⁰ K} : I * (1 / I) ≤ 1 := by by_cases hI : I = 0 · rw [hI, div_zero, mul_zero] exact zero_le 1 · rw [← coe_le_coe, coe_mul, coe_div hI, coe_one] apply Submodule.mul_one_div_le_one #align fractional_ideal.mul_one_div_le_one FractionalIdeal.mul_one_div_le_one theorem le_self_mul_one_div {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) : I ≤ I * (1 / I) := by by_cases hI_nz : I = 0 · rw [hI_nz, div_zero, mul_zero] · rw [← coe_le_coe, coe_mul, coe_div hI_nz, coe_one] rw [← coe_le_coe, coe_one] at hI exact Submodule.le_self_mul_one_div hI #align fractional_ideal.le_self_mul_one_div FractionalIdeal.le_self_mul_one_div theorem le_div_iff_of_nonzero {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ ∀ x ∈ I, ∀ y ∈ J', x * y ∈ J := ⟨fun h _ hx => (mem_div_iff_of_nonzero hJ').mp (h hx), fun h x hx => (mem_div_iff_of_nonzero hJ').mpr (h x hx)⟩ #align fractional_ideal.le_div_iff_of_nonzero FractionalIdeal.le_div_iff_of_nonzero theorem le_div_iff_mul_le {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) : I ≤ J / J' ↔ I * J' ≤ J := by rw [div_nonzero hJ'] -- Porting note: this used to be { convert; rw }, flipped the order. rw [← coe_le_coe (I := I * J') (J := J), coe_mul] exact Submodule.le_div_iff_mul_le #align fractional_ideal.le_div_iff_mul_le FractionalIdeal.le_div_iff_mul_le @[simp] theorem div_one {I : FractionalIdeal R₁⁰ K} : I / 1 = I := by rw [div_nonzero (one_ne_zero' (FractionalIdeal R₁⁰ K))] ext constructor <;> intro h · simpa using mem_div_iff_forall_mul_mem.mp h 1 ((algebraMap R₁ K).map_one ▸ coe_mem_one R₁⁰ 1) · apply mem_div_iff_forall_mul_mem.mpr rintro y ⟨y', _, rfl⟩ -- Porting note: this used to be { convert; rw }, flipped the order. rw [mul_comm, Algebra.linearMap_apply, ← Algebra.smul_def] exact Submodule.smul_mem _ y' h #align fractional_ideal.div_one FractionalIdeal.div_one theorem eq_one_div_of_mul_eq_one_right (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = 1 / 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.eq_one_div_of_mul_eq_one_right FractionalIdeal.eq_one_div_of_mul_eq_one_right theorem mul_div_self_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * (1 / I) = 1 ↔ ∃ J, I * J = 1 := ⟨fun h => ⟨1 / I, h⟩, fun ⟨J, hJ⟩ => by rwa [← eq_one_div_of_mul_eq_one_right I J hJ]⟩ #align fractional_ideal.mul_div_self_cancel_iff FractionalIdeal.mul_div_self_cancel_iff variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K'] @[simp] theorem map_div (I J : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (I / J).map (h : K →ₐ[R₁] K') = I.map h / J.map h := by by_cases H : J = 0 · rw [H, div_zero, map_zero, div_zero] · -- Porting note: `simp` wouldn't apply these lemmas so do them manually using `rw` rw [← coeToSubmodule_inj, div_nonzero H, div_nonzero (map_ne_zero _ H)] simp [Submodule.map_div] #align fractional_ideal.map_div FractionalIdeal.map_div -- Porting note: doesn't need to be @[simp] because this follows from `map_one` and `map_div` theorem map_one_div (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') : (1 / I).map (h : K →ₐ[R₁] K') = 1 / I.map h := by rw [map_div, map_one] #align fractional_ideal.map_one_div FractionalIdeal.map_one_div end Quotient section Field variable {R₁ K L : Type*} [CommRing R₁] [Field K] [Field L] variable [Algebra R₁ K] [IsFractionRing R₁ K] [Algebra K L] [IsFractionRing K L] theorem eq_zero_or_one (I : FractionalIdeal K⁰ L) : I = 0 ∨ I = 1 := by rw [or_iff_not_imp_left] intro hI simp_rw [@SetLike.ext_iff _ _ _ I 1, mem_one_iff] intro x constructor · intro x_mem obtain ⟨n, d, rfl⟩ := IsLocalization.mk'_surjective K⁰ x refine ⟨n / d, ?_⟩ rw [map_div₀, IsFractionRing.mk'_eq_div] · rintro ⟨x, rfl⟩ obtain ⟨y, y_ne, y_mem⟩ := exists_ne_zero_mem_isInteger hI rw [← div_mul_cancel₀ x y_ne, RingHom.map_mul, ← Algebra.smul_def] exact smul_mem (M := L) I (x / y) y_mem #align fractional_ideal.eq_zero_or_one FractionalIdeal.eq_zero_or_one theorem eq_zero_or_one_of_isField (hF : IsField R₁) (I : FractionalIdeal R₁⁰ K) : I = 0 ∨ I = 1 := letI : Field R₁ := hF.toField eq_zero_or_one I #align fractional_ideal.eq_zero_or_one_of_is_field FractionalIdeal.eq_zero_or_one_of_isField end Field section PrincipalIdeal variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K] variable [Algebra R₁ K] [IsFractionRing R₁ K] open scoped Classical variable (R₁) /-- `FractionalIdeal.span_finset R₁ s f` is the fractional ideal of `R₁` generated by `f '' s`. -/ -- Porting note: `@[simps]` generated a `Subtype.val` coercion instead of a -- `FractionalIdeal.coeToSubmodule` coercion def spanFinset {ι : Type*} (s : Finset ι) (f : ι → K) : FractionalIdeal R₁⁰ K := ⟨Submodule.span R₁ (f '' s), by obtain ⟨a', ha'⟩ := IsLocalization.exist_integer_multiples R₁⁰ s f refine ⟨a', a'.2, fun x hx => Submodule.span_induction hx ?_ ?_ ?_ ?_⟩ · rintro _ ⟨i, hi, rfl⟩ exact ha' i hi · rw [smul_zero] exact IsLocalization.isInteger_zero · intro x y hx hy rw [smul_add] exact IsLocalization.isInteger_add hx hy · intro c x hx rw [smul_comm] exact IsLocalization.isInteger_smul hx⟩ #align fractional_ideal.span_finset FractionalIdeal.spanFinset @[simp] lemma spanFinset_coe {ι : Type*} (s : Finset ι) (f : ι → K) : (spanFinset R₁ s f : Submodule R₁ K) = Submodule.span R₁ (f '' s) := rfl variable {R₁} @[simp] theorem spanFinset_eq_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f = 0 ↔ ∀ j ∈ s, f j = 0 := by simp only [← coeToSubmodule_inj, spanFinset_coe, coe_zero, Submodule.span_eq_bot, Set.mem_image, Finset.mem_coe, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] #align fractional_ideal.span_finset_eq_zero FractionalIdeal.spanFinset_eq_zero theorem spanFinset_ne_zero {ι : Type*} {s : Finset ι} {f : ι → K} : spanFinset R₁ s f ≠ 0 ↔ ∃ j ∈ s, f j ≠ 0 := by simp #align fractional_ideal.span_finset_ne_zero FractionalIdeal.spanFinset_ne_zero open Submodule.IsPrincipal theorem isFractional_span_singleton (x : P) : IsFractional S (span R {x} : Submodule R P) := let ⟨a, ha⟩ := exists_integer_multiple S x isFractional_span_iff.mpr ⟨a, a.2, fun _ hx' => (Set.mem_singleton_iff.mp hx').symm ▸ ha⟩ #align fractional_ideal.is_fractional_span_singleton FractionalIdeal.isFractional_span_singleton variable (S) /-- `spanSingleton x` is the fractional ideal generated by `x` if `0 ∉ S` -/ irreducible_def spanSingleton (x : P) : FractionalIdeal S P := ⟨span R {x}, isFractional_span_singleton x⟩ #align fractional_ideal.span_singleton FractionalIdeal.spanSingleton -- local attribute [semireducible] span_singleton @[simp] theorem coe_spanSingleton (x : P) : (spanSingleton S x : Submodule R P) = span R {x} := by rw [spanSingleton] rfl #align fractional_ideal.coe_span_singleton FractionalIdeal.coe_spanSingleton @[simp]
Mathlib/RingTheory/FractionalIdeal/Operations.lean
635
637
theorem mem_spanSingleton {x y : P} : x ∈ spanSingleton S y ↔ ∃ z : R, z • y = x := by
rw [spanSingleton] exact Submodule.mem_span_singleton
/- Copyright (c) 2024 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Topology.ContinuousFunction.ZeroAtInfty /-! # ZeroAtInftyContinuousMapClass in normed additive groups In this file we give a characterization of the predicate `zero_at_infty` from `ZeroAtInftyContinuousMapClass`. A continuous map `f` is zero at infinity if and only if for every `ε > 0` there exists a `r : ℝ` such that for all `x : E` with `r < ‖x‖` it holds that `‖f x‖ < ε`. -/ open Topology Filter variable {E F 𝓕 : Type*} variable [SeminormedAddGroup E] [SeminormedAddCommGroup F] variable [FunLike 𝓕 E F] [ZeroAtInftyContinuousMapClass 𝓕 E F]
Mathlib/Analysis/Normed/Group/ZeroAtInfty.lean
24
34
theorem ZeroAtInftyContinuousMapClass.norm_le (f : 𝓕) (ε : ℝ) (hε : 0 < ε) : ∃ (r : ℝ), ∀ (x : E) (_hx : r < ‖x‖), ‖f x‖ < ε := by
have h := zero_at_infty f rw [tendsto_zero_iff_norm_tendsto_zero, tendsto_def] at h specialize h (Metric.ball 0 ε) (Metric.ball_mem_nhds 0 hε) rcases Metric.closedBall_compl_subset_of_mem_cocompact h 0 with ⟨r, hr⟩ use r intro x hr' suffices x ∈ (fun x ↦ ‖f x‖) ⁻¹' Metric.ball 0 ε by aesop apply hr aesop
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attr import Mathlib.Data.Multiset.FinsetOps import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Basic #align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib.Data.Fintype.Basic`. There is also `univ'`, the noncomputable partner to `univ`, which is defined to be `α` as a finset if `α` is finite, and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`. `Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`. This is then used to define `Fintype.card`, the size of a type. ## Main declarations ### Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. * `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`, then it holds for the finset obtained by inserting a new element. * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Finset constructions * `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element. * `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements. * `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`. This convention is consistent with other languages and normalizes `card (range n) = n`. Beware, `n` is not in `range n`. * `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype `{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set. ### Finsets from functions * `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is the finset consisting of those elements in `s` satisfying the predicate `p`. ### The lattice structure on subsets of finsets There is a natural lattice structure on the subsets of a set. In Lean, we use lattice notation to talk about things involving unions and intersections. See `Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is called `top` with `⊤ = univ`. * `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect. * `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`. See `Finset.sup`/`Finset.biUnion` for finite unions. * `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`. See `Finset.inf` for finite intersections. ### Operations on two or more finsets * `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h` returns the same except that it requires a hypothesis stating that `a` is not already in `s`. This does not require decidable equality on the type `α`. * `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets" * `Finset.instInterFinset`: see "The lattice structure on subsets of finsets" * `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed. * `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`. * `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`. For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`. ### Predicates on finsets * `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their intersection is empty. * `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`. ### Equivalences between finsets * The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen assert_not_exists Multiset.Powerset assert_not_exists CompleteLattice open Multiset Subtype Nat Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val #align finset Finset instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ #align multiset.can_lift_finset Multiset.canLiftFinset namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl #align finset.eq_of_veq Finset.eq_of_veq theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq #align finset.val_injective Finset.val_injective @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff #align finset.val_inj Finset.val_inj @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup #align finset.dedup_eq_self Finset.dedup_eq_self instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj #align finset.has_decidable_eq Finset.decidableEq /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun a s => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl #align finset.mem_def Finset.mem_def @[simp] theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s := Iff.rfl #align finset.mem_val Finset.mem_val @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl #align finset.mem_mk Finset.mem_mk instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ #align finset.decidable_mem Finset.decidableMem @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ -- Porting note (#11445): new definition /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl #align finset.mem_coe Finset.mem_coe @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl #align finset.set_of_mem Finset.setOf_mem @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 #align finset.coe_mem Finset.coe_mem -- Porting note (#10618): @[simp] can prove this theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ #align finset.mk_coe Finset.mk_coe instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ #align finset.decidable_mem' Finset.decidableMem' /-! ### extensionality -/ theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans <| s₁.nodup.ext s₂.nodup #align finset.ext_iff Finset.ext_iff @[ext] theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext_iff.2 #align finset.ext Finset.ext @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans ext_iff.symm #align finset.coe_inj Finset.coe_inj theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 #align finset.coe_injective Finset.coe_injective /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ -- Porting note (#10618): @[simp] can prove this protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align finset.forall_coe Finset.forall_coe -- Porting note (#10618): @[simp] can prove this protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align finset.exists_coe Finset.exists_coe instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) #align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s #align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift' instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ #align finset.finset_coe.can_lift Finset.FinsetCoe.canLift @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl #align finset.coe_sort_coe Finset.coe_sort_coe /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl s a := id le_trans s t u hst htu a ha := htu <| hst ha le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩ instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl #align finset.subset_def Finset.subset_def theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl #align finset.ssubset_def Finset.ssubset_def @[simp] theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ #align finset.subset.refl Finset.Subset.refl protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ #align finset.subset.rfl Finset.Subset.rfl protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ #align finset.subset_of_eq Finset.subset_of_eq theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans #align finset.subset.trans Finset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' #align finset.superset.trans Finset.Superset.trans theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset #align finset.mem_of_subset Finset.mem_of_subset theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ #align finset.not_mem_mono Finset.not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ #align finset.subset.antisymm Finset.Subset.antisymm theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl #align finset.subset_iff Finset.subset_iff @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.coe_subset Finset.coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 #align finset.val_le_iff Finset.val_le_iff theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff #align finset.subset.antisymm_iff Finset.Subset.antisymm_iff theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe] #align finset.not_subset Finset.not_subset @[simp] theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) := rfl #align finset.le_eq_subset Finset.le_eq_subset @[simp] theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) := rfl #align finset.lt_eq_subset Finset.lt_eq_subset theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.le_iff_subset Finset.le_iff_subset theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := Iff.rfl #align finset.lt_iff_ssubset Finset.lt_iff_ssubset @[simp, norm_cast] theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ := show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset] #align finset.coe_ssubset Finset.coe_ssubset @[simp] theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff <| not_congr val_le_iff #align finset.val_lt_iff Finset.val_lt_iff lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2 theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne _ _ s t #align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ := Set.ssubset_iff_of_subset h #align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃ #align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃ #align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ := Set.exists_of_ssubset h #align finset.exists_of_ssubset Finset.exists_of_ssubset instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) := Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2 #align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset instance wellFoundedLT : WellFoundedLT (Finset α) := Finset.isWellFounded_ssubset #align finset.is_well_founded_lt Finset.wellFoundedLT end Subset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans /-! ### Order embedding from `Finset α` to `Set α` -/ /-- Coercion to `Set α` as an `OrderEmbedding`. -/ def coeEmb : Finset α ↪o Set α := ⟨⟨(↑), coe_injective⟩, coe_subset⟩ #align finset.coe_emb Finset.coeEmb @[simp] theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) := rfl #align finset.coe_coe_emb Finset.coe_coeEmb /-! ### Nonempty -/ /-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s #align finset.nonempty Finset.Nonempty -- Porting note: Much longer than in Lean3 instance decidableNonempty {s : Finset α} : Decidable s.Nonempty := Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1 (fun l : List α => match l with | [] => isFalse <| by simp | a::l => isTrue ⟨a, by simp⟩) #align finset.decidable_nonempty Finset.decidableNonempty @[simp, norm_cast] theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty := Iff.rfl #align finset.coe_nonempty Finset.coe_nonempty -- Porting note: Left-hand side simplifies @[simp] theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty := nonempty_subtype #align finset.nonempty_coe_sort Finset.nonempty_coe_sort alias ⟨_, Nonempty.to_set⟩ := coe_nonempty #align finset.nonempty.to_set Finset.Nonempty.to_set alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align finset.nonempty.coe_sort Finset.Nonempty.coe_sort theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s := h #align finset.nonempty.bex Finset.Nonempty.exists_mem @[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := Set.Nonempty.mono hst hs #align finset.nonempty.mono Finset.Nonempty.mono theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p := let ⟨x, hx⟩ := h ⟨fun h => h x hx, fun h _ _ => h⟩ #align finset.nonempty.forall_const Finset.Nonempty.forall_const theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s := nonempty_coe_sort.2 #align finset.nonempty.to_subtype Finset.Nonempty.to_subtype theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩ #align finset.nonempty.to_type Finset.Nonempty.to_type /-! ### empty -/ section Empty variable {s : Finset α} /-- The empty finset -/ protected def empty : Finset α := ⟨0, nodup_zero⟩ #align finset.empty Finset.empty instance : EmptyCollection (Finset α) := ⟨Finset.empty⟩ instance inhabitedFinset : Inhabited (Finset α) := ⟨∅⟩ #align finset.inhabited_finset Finset.inhabitedFinset @[simp] theorem empty_val : (∅ : Finset α).1 = 0 := rfl #align finset.empty_val Finset.empty_val @[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by -- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False` simp only [mem_def, empty_val, not_mem_zero, not_false_iff] #align finset.not_mem_empty Finset.not_mem_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx #align finset.not_nonempty_empty Finset.not_nonempty_empty @[simp] theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ := rfl #align finset.mk_zero Finset.mk_zero theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e => not_mem_empty a <| e ▸ h #align finset.ne_empty_of_mem Finset.ne_empty_of_mem theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ := (Exists.elim h) fun _a => ne_empty_of_mem #align finset.nonempty.ne_empty Finset.Nonempty.ne_empty @[simp] theorem empty_subset (s : Finset α) : ∅ ⊆ s := zero_subset _ #align finset.empty_subset Finset.empty_subset theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ := eq_of_veq (eq_zero_of_forall_not_mem H) #align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s := -- Porting note: used `id` ⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩ #align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem @[simp] theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅ #align finset.val_eq_zero Finset.val_eq_zero theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero #align finset.subset_empty Finset.subset_empty @[simp] theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h => let ⟨_, he, _⟩ := exists_of_ssubset h -- Porting note: was `he` not_mem_empty _ he #align finset.not_ssubset_empty Finset.not_ssubset_empty theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty := exists_mem_of_ne_zero (mt val_eq_zero.1 h) #align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ := ⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩ #align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty @[simp] theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ := nonempty_iff_ne_empty.not.trans not_not #align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty := by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h) #align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty @[simp, norm_cast] theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ := Set.ext <| by simp #align finset.coe_empty Finset.coe_empty @[simp, norm_cast] theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj] #align finset.coe_eq_empty Finset.coe_eq_empty -- Porting note: Left-hand side simplifies @[simp] theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by simpa using @Set.isEmpty_coe_sort α s #align finset.is_empty_coe_sort Finset.isEmpty_coe_sort instance instIsEmpty : IsEmpty (∅ : Finset α) := isEmpty_coe_sort.2 rfl /-- A `Finset` for an empty type is empty. -/ theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ := Finset.eq_empty_of_forall_not_mem isEmptyElim #align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty instance : OrderBot (Finset α) where bot := ∅ bot_le := empty_subset @[simp] theorem bot_eq_empty : (⊥ : Finset α) = ∅ := rfl #align finset.bot_eq_empty Finset.bot_eq_empty @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm #align finset.empty_ssubset Finset.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset end Empty /-! ### singleton -/ section Singleton variable {s : Finset α} {a b : α} /-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else. This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`. -/ instance : Singleton α (Finset α) := ⟨fun a => ⟨{a}, nodup_singleton a⟩⟩ @[simp] theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} := rfl #align finset.singleton_val Finset.singleton_val @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a := Multiset.mem_singleton #align finset.mem_singleton Finset.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y := mem_singleton.1 h #align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b := not_congr mem_singleton #align finset.not_mem_singleton Finset.not_mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) := -- Porting note: was `Or.inl rfl` mem_singleton.mpr rfl #align finset.mem_singleton_self Finset.mem_singleton_self @[simp] theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by rw [← val_inj] rfl #align finset.val_eq_singleton_iff Finset.val_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Finset α) := fun _a _b h => mem_singleton.1 (h ▸ mem_singleton_self _) #align finset.singleton_injective Finset.singleton_injective @[simp] theorem singleton_inj : ({a} : Finset α) = {b} ↔ a = b := singleton_injective.eq_iff #align finset.singleton_inj Finset.singleton_inj @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem singleton_nonempty (a : α) : ({a} : Finset α).Nonempty := ⟨a, mem_singleton_self a⟩ #align finset.singleton_nonempty Finset.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Finset α) ≠ ∅ := (singleton_nonempty a).ne_empty #align finset.singleton_ne_empty Finset.singleton_ne_empty theorem empty_ssubset_singleton : (∅ : Finset α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align finset.empty_ssubset_singleton Finset.empty_ssubset_singleton @[simp, norm_cast] theorem coe_singleton (a : α) : (({a} : Finset α) : Set α) = {a} := by ext simp #align finset.coe_singleton Finset.coe_singleton @[simp, norm_cast] theorem coe_eq_singleton {s : Finset α} {a : α} : (s : Set α) = {a} ↔ s = {a} := by rw [← coe_singleton, coe_inj] #align finset.coe_eq_singleton Finset.coe_eq_singleton @[norm_cast] lemma coe_subset_singleton : (s : Set α) ⊆ {a} ↔ s ⊆ {a} := by rw [← coe_subset, coe_singleton] @[norm_cast] lemma singleton_subset_coe : {a} ⊆ (s : Set α) ↔ {a} ⊆ s := by rw [← coe_subset, coe_singleton] theorem eq_singleton_iff_unique_mem {s : Finset α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := by constructor <;> intro t · rw [t] exact ⟨Finset.mem_singleton_self _, fun _ => Finset.mem_singleton.1⟩ · ext rw [Finset.mem_singleton] exact ⟨t.right _, fun r => r.symm ▸ t.left⟩ #align finset.eq_singleton_iff_unique_mem Finset.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem {s : Finset α} {a : α} : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := by constructor · rintro rfl simp · rintro ⟨hne, h_uniq⟩ rw [eq_singleton_iff_unique_mem] refine ⟨?_, h_uniq⟩ rw [← h_uniq hne.choose hne.choose_spec] exact hne.choose_spec #align finset.eq_singleton_iff_nonempty_unique_mem Finset.eq_singleton_iff_nonempty_unique_mem theorem nonempty_iff_eq_singleton_default [Unique α] {s : Finset α} : s.Nonempty ↔ s = {default} := by simp [eq_singleton_iff_nonempty_unique_mem, eq_iff_true_of_subsingleton] #align finset.nonempty_iff_eq_singleton_default Finset.nonempty_iff_eq_singleton_default alias ⟨Nonempty.eq_singleton_default, _⟩ := nonempty_iff_eq_singleton_default #align finset.nonempty.eq_singleton_default Finset.Nonempty.eq_singleton_default theorem singleton_iff_unique_mem (s : Finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s := by simp only [eq_singleton_iff_unique_mem, ExistsUnique] #align finset.singleton_iff_unique_mem Finset.singleton_iff_unique_mem theorem singleton_subset_set_iff {s : Set α} {a : α} : ↑({a} : Finset α) ⊆ s ↔ a ∈ s := by rw [coe_singleton, Set.singleton_subset_iff] #align finset.singleton_subset_set_iff Finset.singleton_subset_set_iff @[simp] theorem singleton_subset_iff {s : Finset α} {a : α} : {a} ⊆ s ↔ a ∈ s := singleton_subset_set_iff #align finset.singleton_subset_iff Finset.singleton_subset_iff @[simp] theorem subset_singleton_iff {s : Finset α} {a : α} : s ⊆ {a} ↔ s = ∅ ∨ s = {a} := by rw [← coe_subset, coe_singleton, Set.subset_singleton_iff_eq, coe_eq_empty, coe_eq_singleton] #align finset.subset_singleton_iff Finset.subset_singleton_iff theorem singleton_subset_singleton : ({a} : Finset α) ⊆ {b} ↔ a = b := by simp #align finset.singleton_subset_singleton Finset.singleton_subset_singleton protected theorem Nonempty.subset_singleton_iff {s : Finset α} {a : α} (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} := subset_singleton_iff.trans <| or_iff_right h.ne_empty #align finset.nonempty.subset_singleton_iff Finset.Nonempty.subset_singleton_iff theorem subset_singleton_iff' {s : Finset α} {a : α} : s ⊆ {a} ↔ ∀ b ∈ s, b = a := forall₂_congr fun _ _ => mem_singleton #align finset.subset_singleton_iff' Finset.subset_singleton_iff' @[simp] theorem ssubset_singleton_iff {s : Finset α} {a : α} : s ⊂ {a} ↔ s = ∅ := by rw [← coe_ssubset, coe_singleton, Set.ssubset_singleton_iff, coe_eq_empty] #align finset.ssubset_singleton_iff Finset.ssubset_singleton_iff theorem eq_empty_of_ssubset_singleton {s : Finset α} {x : α} (hs : s ⊂ {x}) : s = ∅ := ssubset_singleton_iff.1 hs #align finset.eq_empty_of_ssubset_singleton Finset.eq_empty_of_ssubset_singleton /-- A finset is nontrivial if it has at least two elements. -/ protected abbrev Nontrivial (s : Finset α) : Prop := (s : Set α).Nontrivial #align finset.nontrivial Finset.Nontrivial @[simp] theorem not_nontrivial_empty : ¬ (∅ : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_empty Finset.not_nontrivial_empty @[simp] theorem not_nontrivial_singleton : ¬ ({a} : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_singleton Finset.not_nontrivial_singleton theorem Nontrivial.ne_singleton (hs : s.Nontrivial) : s ≠ {a} := by rintro rfl; exact not_nontrivial_singleton hs #align finset.nontrivial.ne_singleton Finset.Nontrivial.ne_singleton nonrec lemma Nontrivial.exists_ne (hs : s.Nontrivial) (a : α) : ∃ b ∈ s, b ≠ a := hs.exists_ne _ theorem eq_singleton_or_nontrivial (ha : a ∈ s) : s = {a} ∨ s.Nontrivial := by rw [← coe_eq_singleton]; exact Set.eq_singleton_or_nontrivial ha #align finset.eq_singleton_or_nontrivial Finset.eq_singleton_or_nontrivial theorem nontrivial_iff_ne_singleton (ha : a ∈ s) : s.Nontrivial ↔ s ≠ {a} := ⟨Nontrivial.ne_singleton, (eq_singleton_or_nontrivial ha).resolve_left⟩ #align finset.nontrivial_iff_ne_singleton Finset.nontrivial_iff_ne_singleton theorem Nonempty.exists_eq_singleton_or_nontrivial : s.Nonempty → (∃ a, s = {a}) ∨ s.Nontrivial := fun ⟨a, ha⟩ => (eq_singleton_or_nontrivial ha).imp_left <| Exists.intro a #align finset.nonempty.exists_eq_singleton_or_nontrivial Finset.Nonempty.exists_eq_singleton_or_nontrivial instance instNontrivial [Nonempty α] : Nontrivial (Finset α) := ‹Nonempty α›.elim fun a => ⟨⟨{a}, ∅, singleton_ne_empty _⟩⟩ #align finset.nontrivial' Finset.instNontrivial instance [IsEmpty α] : Unique (Finset α) where default := ∅ uniq _ := eq_empty_of_forall_not_mem isEmptyElim instance (i : α) : Unique ({i} : Finset α) where default := ⟨i, mem_singleton_self i⟩ uniq j := Subtype.ext <| mem_singleton.mp j.2 @[simp] lemma default_singleton (i : α) : ((default : ({i} : Finset α)) : α) = i := rfl end Singleton /-! ### cons -/ section Cons variable {s t : Finset α} {a b : α} /-- `cons a s h` is the set `{a} ∪ s` containing `a` and the elements of `s`. It is the same as `insert a s` when it is defined, but unlike `insert a s` it does not require `DecidableEq α`, and the union is guaranteed to be disjoint. -/ def cons (a : α) (s : Finset α) (h : a ∉ s) : Finset α := ⟨a ::ₘ s.1, nodup_cons.2 ⟨h, s.2⟩⟩ #align finset.cons Finset.cons @[simp] theorem mem_cons {h} : b ∈ s.cons a h ↔ b = a ∨ b ∈ s := Multiset.mem_cons #align finset.mem_cons Finset.mem_cons theorem mem_cons_of_mem {a b : α} {s : Finset α} {hb : b ∉ s} (ha : a ∈ s) : a ∈ cons b s hb := Multiset.mem_cons_of_mem ha -- Porting note (#10618): @[simp] can prove this theorem mem_cons_self (a : α) (s : Finset α) {h} : a ∈ cons a s h := Multiset.mem_cons_self _ _ #align finset.mem_cons_self Finset.mem_cons_self @[simp] theorem cons_val (h : a ∉ s) : (cons a s h).1 = a ::ₘ s.1 := rfl #align finset.cons_val Finset.cons_val theorem forall_mem_cons (h : a ∉ s) (p : α → Prop) : (∀ x, x ∈ cons a s h → p x) ↔ p a ∧ ∀ x, x ∈ s → p x := by simp only [mem_cons, or_imp, forall_and, forall_eq] #align finset.forall_mem_cons Finset.forall_mem_cons /-- Useful in proofs by induction. -/ theorem forall_of_forall_cons {p : α → Prop} {h : a ∉ s} (H : ∀ x, x ∈ cons a s h → p x) (x) (h : x ∈ s) : p x := H _ <| mem_cons.2 <| Or.inr h #align finset.forall_of_forall_cons Finset.forall_of_forall_cons @[simp] theorem mk_cons {s : Multiset α} (h : (a ::ₘ s).Nodup) : (⟨a ::ₘ s, h⟩ : Finset α) = cons a ⟨s, (nodup_cons.1 h).2⟩ (nodup_cons.1 h).1 := rfl #align finset.mk_cons Finset.mk_cons @[simp] theorem cons_empty (a : α) : cons a ∅ (not_mem_empty _) = {a} := rfl #align finset.cons_empty Finset.cons_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_cons (h : a ∉ s) : (cons a s h).Nonempty := ⟨a, mem_cons.2 <| Or.inl rfl⟩ #align finset.nonempty_cons Finset.nonempty_cons @[simp] theorem nonempty_mk {m : Multiset α} {hm} : (⟨m, hm⟩ : Finset α).Nonempty ↔ m ≠ 0 := by induction m using Multiset.induction_on <;> simp #align finset.nonempty_mk Finset.nonempty_mk @[simp] theorem coe_cons {a s h} : (@cons α a s h : Set α) = insert a (s : Set α) := by ext simp #align finset.coe_cons Finset.coe_cons theorem subset_cons (h : a ∉ s) : s ⊆ s.cons a h := Multiset.subset_cons _ _ #align finset.subset_cons Finset.subset_cons theorem ssubset_cons (h : a ∉ s) : s ⊂ s.cons a h := Multiset.ssubset_cons h #align finset.ssubset_cons Finset.ssubset_cons theorem cons_subset {h : a ∉ s} : s.cons a h ⊆ t ↔ a ∈ t ∧ s ⊆ t := Multiset.cons_subset #align finset.cons_subset Finset.cons_subset @[simp] theorem cons_subset_cons {hs ht} : s.cons a hs ⊆ t.cons a ht ↔ s ⊆ t := by rwa [← coe_subset, coe_cons, coe_cons, Set.insert_subset_insert_iff, coe_subset] #align finset.cons_subset_cons Finset.cons_subset_cons theorem ssubset_iff_exists_cons_subset : s ⊂ t ↔ ∃ (a : _) (h : a ∉ s), s.cons a h ⊆ t := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_ssubset_of_subset (ssubset_cons _) h⟩ obtain ⟨a, hs, ht⟩ := not_subset.1 h.2 exact ⟨a, ht, cons_subset.2 ⟨hs, h.subset⟩⟩ #align finset.ssubset_iff_exists_cons_subset Finset.ssubset_iff_exists_cons_subset end Cons /-! ### disjoint -/ section Disjoint variable {f : α → β} {s t u : Finset α} {a b : α} theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t := ⟨fun h a hs ht => not_mem_empty a <| singleton_subset_iff.mp (h (singleton_subset_iff.mpr hs) (singleton_subset_iff.mpr ht)), fun h _ hs ht _ ha => (h (hs ha) (ht ha)).elim⟩ #align finset.disjoint_left Finset.disjoint_left theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [_root_.disjoint_comm, disjoint_left] #align finset.disjoint_right Finset.disjoint_right theorem disjoint_iff_ne : Disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b := by simp only [disjoint_left, imp_not_comm, forall_eq'] #align finset.disjoint_iff_ne Finset.disjoint_iff_ne @[simp] theorem disjoint_val : s.1.Disjoint t.1 ↔ Disjoint s t := disjoint_left.symm #align finset.disjoint_val Finset.disjoint_val theorem _root_.Disjoint.forall_ne_finset (h : Disjoint s t) (ha : a ∈ s) (hb : b ∈ t) : a ≠ b := disjoint_iff_ne.1 h _ ha _ hb #align disjoint.forall_ne_finset Disjoint.forall_ne_finset theorem not_disjoint_iff : ¬Disjoint s t ↔ ∃ a, a ∈ s ∧ a ∈ t := disjoint_left.not.trans <| not_forall.trans <| exists_congr fun _ => by rw [Classical.not_imp, not_not] #align finset.not_disjoint_iff Finset.not_disjoint_iff theorem disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := disjoint_left.2 fun _x m₁ => (disjoint_left.1 d) (h m₁) #align finset.disjoint_of_subset_left Finset.disjoint_of_subset_left theorem disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := disjoint_right.2 fun _x m₁ => (disjoint_right.1 d) (h m₁) #align finset.disjoint_of_subset_right Finset.disjoint_of_subset_right @[simp] theorem disjoint_empty_left (s : Finset α) : Disjoint ∅ s := disjoint_bot_left #align finset.disjoint_empty_left Finset.disjoint_empty_left @[simp] theorem disjoint_empty_right (s : Finset α) : Disjoint s ∅ := disjoint_bot_right #align finset.disjoint_empty_right Finset.disjoint_empty_right @[simp] theorem disjoint_singleton_left : Disjoint (singleton a) s ↔ a ∉ s := by simp only [disjoint_left, mem_singleton, forall_eq] #align finset.disjoint_singleton_left Finset.disjoint_singleton_left @[simp] theorem disjoint_singleton_right : Disjoint s (singleton a) ↔ a ∉ s := disjoint_comm.trans disjoint_singleton_left #align finset.disjoint_singleton_right Finset.disjoint_singleton_right -- Porting note: Left-hand side simplifies @[simp] theorem disjoint_singleton : Disjoint ({a} : Finset α) {b} ↔ a ≠ b := by rw [disjoint_singleton_left, mem_singleton] #align finset.disjoint_singleton Finset.disjoint_singleton theorem disjoint_self_iff_empty (s : Finset α) : Disjoint s s ↔ s = ∅ := disjoint_self #align finset.disjoint_self_iff_empty Finset.disjoint_self_iff_empty @[simp, norm_cast] theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by simp only [Finset.disjoint_left, Set.disjoint_left, mem_coe] #align finset.disjoint_coe Finset.disjoint_coe @[simp, norm_cast] theorem pairwiseDisjoint_coe {ι : Type*} {s : Set ι} {f : ι → Finset α} : s.PairwiseDisjoint (fun i => f i : ι → Set α) ↔ s.PairwiseDisjoint f := forall₅_congr fun _ _ _ _ _ => disjoint_coe #align finset.pairwise_disjoint_coe Finset.pairwiseDisjoint_coe end Disjoint /-! ### disjoint union -/ /-- `disjUnion s t h` is the set such that `a ∈ disjUnion s t h` iff `a ∈ s` or `a ∈ t`. It is the same as `s ∪ t`, but it does not require decidable equality on the type. The hypothesis ensures that the sets are disjoint. -/ def disjUnion (s t : Finset α) (h : Disjoint s t) : Finset α := ⟨s.1 + t.1, Multiset.nodup_add.2 ⟨s.2, t.2, disjoint_val.2 h⟩⟩ #align finset.disj_union Finset.disjUnion @[simp] theorem mem_disjUnion {α s t h a} : a ∈ @disjUnion α s t h ↔ a ∈ s ∨ a ∈ t := by rcases s with ⟨⟨s⟩⟩; rcases t with ⟨⟨t⟩⟩; apply List.mem_append #align finset.mem_disj_union Finset.mem_disjUnion @[simp, norm_cast] theorem coe_disjUnion {s t : Finset α} (h : Disjoint s t) : (disjUnion s t h : Set α) = (s : Set α) ∪ t := Set.ext <| by simp theorem disjUnion_comm (s t : Finset α) (h : Disjoint s t) : disjUnion s t h = disjUnion t s h.symm := eq_of_veq <| add_comm _ _ #align finset.disj_union_comm Finset.disjUnion_comm @[simp] theorem empty_disjUnion (t : Finset α) (h : Disjoint ∅ t := disjoint_bot_left) : disjUnion ∅ t h = t := eq_of_veq <| zero_add _ #align finset.empty_disj_union Finset.empty_disjUnion @[simp] theorem disjUnion_empty (s : Finset α) (h : Disjoint s ∅ := disjoint_bot_right) : disjUnion s ∅ h = s := eq_of_veq <| add_zero _ #align finset.disj_union_empty Finset.disjUnion_empty theorem singleton_disjUnion (a : α) (t : Finset α) (h : Disjoint {a} t) : disjUnion {a} t h = cons a t (disjoint_singleton_left.mp h) := eq_of_veq <| Multiset.singleton_add _ _ #align finset.singleton_disj_union Finset.singleton_disjUnion theorem disjUnion_singleton (s : Finset α) (a : α) (h : Disjoint s {a}) : disjUnion s {a} h = cons a s (disjoint_singleton_right.mp h) := by rw [disjUnion_comm, singleton_disjUnion] #align finset.disj_union_singleton Finset.disjUnion_singleton /-! ### insert -/ section Insert variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `insert a s` is the set `{a} ∪ s` containing `a` and the elements of `s`. -/ instance : Insert α (Finset α) := ⟨fun a s => ⟨_, s.2.ndinsert a⟩⟩ theorem insert_def (a : α) (s : Finset α) : insert a s = ⟨_, s.2.ndinsert a⟩ := rfl #align finset.insert_def Finset.insert_def @[simp] theorem insert_val (a : α) (s : Finset α) : (insert a s).1 = ndinsert a s.1 := rfl #align finset.insert_val Finset.insert_val theorem insert_val' (a : α) (s : Finset α) : (insert a s).1 = dedup (a ::ₘ s.1) := by rw [dedup_cons, dedup_eq_self]; rfl #align finset.insert_val' Finset.insert_val' theorem insert_val_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : (insert a s).1 = a ::ₘ s.1 := by rw [insert_val, ndinsert_of_not_mem h] #align finset.insert_val_of_not_mem Finset.insert_val_of_not_mem @[simp] theorem mem_insert : a ∈ insert b s ↔ a = b ∨ a ∈ s := mem_ndinsert #align finset.mem_insert Finset.mem_insert theorem mem_insert_self (a : α) (s : Finset α) : a ∈ insert a s := mem_ndinsert_self a s.1 #align finset.mem_insert_self Finset.mem_insert_self theorem mem_insert_of_mem (h : a ∈ s) : a ∈ insert b s := mem_ndinsert_of_mem h #align finset.mem_insert_of_mem Finset.mem_insert_of_mem theorem mem_of_mem_insert_of_ne (h : b ∈ insert a s) : b ≠ a → b ∈ s := (mem_insert.1 h).resolve_left #align finset.mem_of_mem_insert_of_ne Finset.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert (ha : b ∈ insert a s) (hb : b ∉ s) : b = a := (mem_insert.1 ha).resolve_right hb #align finset.eq_of_not_mem_of_mem_insert Finset.eq_of_not_mem_of_mem_insert /-- A version of `LawfulSingleton.insert_emptyc_eq` that works with `dsimp`. -/ @[simp, nolint simpNF] lemma insert_empty : insert a (∅ : Finset α) = {a} := rfl @[simp] theorem cons_eq_insert (a s h) : @cons α a s h = insert a s := ext fun a => by simp #align finset.cons_eq_insert Finset.cons_eq_insert @[simp, norm_cast] theorem coe_insert (a : α) (s : Finset α) : ↑(insert a s) = (insert a s : Set α) := Set.ext fun x => by simp only [mem_coe, mem_insert, Set.mem_insert_iff] #align finset.coe_insert Finset.coe_insert theorem mem_insert_coe {s : Finset α} {x y : α} : x ∈ insert y s ↔ x ∈ insert y (s : Set α) := by simp #align finset.mem_insert_coe Finset.mem_insert_coe instance : LawfulSingleton α (Finset α) := ⟨fun a => by ext; simp⟩ @[simp] theorem insert_eq_of_mem (h : a ∈ s) : insert a s = s := eq_of_veq <| ndinsert_of_mem h #align finset.insert_eq_of_mem Finset.insert_eq_of_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert_self _ _, insert_eq_of_mem⟩ #align finset.insert_eq_self Finset.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align finset.insert_ne_self Finset.insert_ne_self -- Porting note (#10618): @[simp] can prove this theorem pair_eq_singleton (a : α) : ({a, a} : Finset α) = {a} := insert_eq_of_mem <| mem_singleton_self _ #align finset.pair_eq_singleton Finset.pair_eq_singleton theorem Insert.comm (a b : α) (s : Finset α) : insert a (insert b s) = insert b (insert a s) := ext fun x => by simp only [mem_insert, or_left_comm] #align finset.insert.comm Finset.Insert.comm -- Porting note (#10618): @[simp] can prove this @[norm_cast] theorem coe_pair {a b : α} : (({a, b} : Finset α) : Set α) = {a, b} := by ext simp #align finset.coe_pair Finset.coe_pair @[simp, norm_cast] theorem coe_eq_pair {s : Finset α} {a b : α} : (s : Set α) = {a, b} ↔ s = {a, b} := by rw [← coe_pair, coe_inj] #align finset.coe_eq_pair Finset.coe_eq_pair theorem pair_comm (a b : α) : ({a, b} : Finset α) = {b, a} := Insert.comm a b ∅ #align finset.pair_comm Finset.pair_comm -- Porting note (#10618): @[simp] can prove this theorem insert_idem (a : α) (s : Finset α) : insert a (insert a s) = insert a s := ext fun x => by simp only [mem_insert, ← or_assoc, or_self_iff] #align finset.insert_idem Finset.insert_idem @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem insert_nonempty (a : α) (s : Finset α) : (insert a s).Nonempty := ⟨a, mem_insert_self a s⟩ #align finset.insert_nonempty Finset.insert_nonempty @[simp] theorem insert_ne_empty (a : α) (s : Finset α) : insert a s ≠ ∅ := (insert_nonempty a s).ne_empty #align finset.insert_ne_empty Finset.insert_ne_empty -- Porting note: explicit universe annotation is no longer required. instance (i : α) (s : Finset α) : Nonempty ((insert i s : Finset α) : Set α) := (Finset.coe_nonempty.mpr (s.insert_nonempty i)).to_subtype theorem ne_insert_of_not_mem (s t : Finset α) {a : α} (h : a ∉ s) : s ≠ insert a t := by contrapose! h simp [h] #align finset.ne_insert_of_not_mem Finset.ne_insert_of_not_mem theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_iff, mem_insert, forall_eq, or_imp, forall_and] #align finset.insert_subset Finset.insert_subset_iff theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t := insert_subset_iff.mpr ⟨ha,hs⟩ @[simp] theorem subset_insert (a : α) (s : Finset α) : s ⊆ insert a s := fun _b => mem_insert_of_mem #align finset.subset_insert Finset.subset_insert @[gcongr] theorem insert_subset_insert (a : α) {s t : Finset α} (h : s ⊆ t) : insert a s ⊆ insert a t := insert_subset_iff.2 ⟨mem_insert_self _ _, Subset.trans h (subset_insert _ _)⟩ #align finset.insert_subset_insert Finset.insert_subset_insert @[simp] lemma insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by simp_rw [← coe_subset]; simp [-coe_subset, ha] theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b := ⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert_self _ _) ha, congr_arg (insert · s)⟩ #align finset.insert_inj Finset.insert_inj theorem insert_inj_on (s : Finset α) : Set.InjOn (fun a => insert a s) sᶜ := fun _ h _ _ => (insert_inj h).1 #align finset.insert_inj_on Finset.insert_inj_on theorem ssubset_iff : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := mod_cast @Set.ssubset_iff_insert α s t #align finset.ssubset_iff Finset.ssubset_iff theorem ssubset_insert (h : a ∉ s) : s ⊂ insert a s := ssubset_iff.mpr ⟨a, h, Subset.rfl⟩ #align finset.ssubset_insert Finset.ssubset_insert @[elab_as_elim] theorem cons_induction {α : Type*} {p : Finset α → Prop} (empty : p ∅) (cons : ∀ (a : α) (s : Finset α) (h : a ∉ s), p s → p (cons a s h)) : ∀ s, p s | ⟨s, nd⟩ => by induction s using Multiset.induction with | empty => exact empty | cons a s IH => rw [mk_cons nd] exact cons a _ _ (IH _) #align finset.cons_induction Finset.cons_induction @[elab_as_elim] theorem cons_induction_on {α : Type*} {p : Finset α → Prop} (s : Finset α) (h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : Finset α} (h : a ∉ s), p s → p (cons a s h)) : p s := cons_induction h₁ h₂ s #align finset.cons_induction_on Finset.cons_induction_on @[elab_as_elim] protected theorem induction {α : Type*} {p : Finset α → Prop} [DecidableEq α] (empty : p ∅) (insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s := cons_induction empty fun a s ha => (s.cons_eq_insert a ha).symm ▸ insert ha #align finset.induction Finset.induction /-- To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty `Finset`, and to show that if it holds for some `Finset α`, then it holds for the `Finset` obtained by inserting a new element. -/ @[elab_as_elim] protected theorem induction_on {α : Type*} {p : Finset α → Prop} [DecidableEq α] (s : Finset α) (empty : p ∅) (insert : ∀ ⦃a : α⦄ {s : Finset α}, a ∉ s → p s → p (insert a s)) : p s := Finset.induction empty insert s #align finset.induction_on Finset.induction_on /-- To prove a proposition about `S : Finset α`, it suffices to prove it for the empty `Finset`, and to show that if it holds for some `Finset α ⊆ S`, then it holds for the `Finset` obtained by inserting a new element of `S`. -/ @[elab_as_elim] theorem induction_on' {α : Type*} {p : Finset α → Prop} [DecidableEq α] (S : Finset α) (h₁ : p ∅) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → p s → p (insert a s)) : p S := @Finset.induction_on α (fun T => T ⊆ S → p T) _ S (fun _ => h₁) (fun _ _ has hqs hs => let ⟨hS, sS⟩ := Finset.insert_subset_iff.1 hs h₂ hS sS has (hqs sS)) (Finset.Subset.refl S) #align finset.induction_on' Finset.induction_on' /-- To prove a proposition about a nonempty `s : Finset α`, it suffices to show it holds for all singletons and that if it holds for nonempty `t : Finset α`, then it also holds for the `Finset` obtained by inserting an element in `t`. -/ @[elab_as_elim] theorem Nonempty.cons_induction {α : Type*} {p : ∀ s : Finset α, s.Nonempty → Prop} (singleton : ∀ a, p {a} (singleton_nonempty _)) (cons : ∀ a s (h : a ∉ s) (hs), p s hs → p (Finset.cons a s h) (nonempty_cons h)) {s : Finset α} (hs : s.Nonempty) : p s hs := by induction s using Finset.cons_induction with | empty => exact (not_nonempty_empty hs).elim | cons a t ha h => obtain rfl | ht := t.eq_empty_or_nonempty · exact singleton a · exact cons a t ha ht (h ht) #align finset.nonempty.cons_induction Finset.Nonempty.cons_induction lemma Nonempty.exists_cons_eq (hs : s.Nonempty) : ∃ t a ha, cons a t ha = s := hs.cons_induction (fun a ↦ ⟨∅, a, _, cons_empty _⟩) fun _ _ _ _ _ ↦ ⟨_, _, _, rfl⟩ /-- Inserting an element to a finite set is equivalent to the option type. -/ def subtypeInsertEquivOption {t : Finset α} {x : α} (h : x ∉ t) : { i // i ∈ insert x t } ≃ Option { i // i ∈ t } where toFun y := if h : ↑y = x then none else some ⟨y, (mem_insert.mp y.2).resolve_left h⟩ invFun y := (y.elim ⟨x, mem_insert_self _ _⟩) fun z => ⟨z, mem_insert_of_mem z.2⟩ left_inv y := by by_cases h : ↑y = x · simp only [Subtype.ext_iff, h, Option.elim, dif_pos, Subtype.coe_mk] · simp only [h, Option.elim, dif_neg, not_false_iff, Subtype.coe_eta, Subtype.coe_mk] right_inv := by rintro (_ | y) · simp only [Option.elim, dif_pos] · have : ↑y ≠ x := by rintro ⟨⟩ exact h y.2 simp only [this, Option.elim, Subtype.eta, dif_neg, not_false_iff, Subtype.coe_mk] #align finset.subtype_insert_equiv_option Finset.subtypeInsertEquivOption @[simp] theorem disjoint_insert_left : Disjoint (insert a s) t ↔ a ∉ t ∧ Disjoint s t := by simp only [disjoint_left, mem_insert, or_imp, forall_and, forall_eq] #align finset.disjoint_insert_left Finset.disjoint_insert_left @[simp] theorem disjoint_insert_right : Disjoint s (insert a t) ↔ a ∉ s ∧ Disjoint s t := disjoint_comm.trans <| by rw [disjoint_insert_left, _root_.disjoint_comm] #align finset.disjoint_insert_right Finset.disjoint_insert_right end Insert /-! ### Lattice structure -/ section Lattice variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α} /-- `s ∪ t` is the set such that `a ∈ s ∪ t` iff `a ∈ s` or `a ∈ t`. -/ instance : Union (Finset α) := ⟨fun s t => ⟨_, t.2.ndunion s.1⟩⟩ /-- `s ∩ t` is the set such that `a ∈ s ∩ t` iff `a ∈ s` and `a ∈ t`. -/ instance : Inter (Finset α) := ⟨fun s t => ⟨_, s.2.ndinter t.1⟩⟩ instance : Lattice (Finset α) := { Finset.partialOrder with sup := (· ∪ ·) sup_le := fun _ _ _ hs ht _ ha => (mem_ndunion.1 ha).elim (fun h => hs h) fun h => ht h le_sup_left := fun _ _ _ h => mem_ndunion.2 <| Or.inl h le_sup_right := fun _ _ _ h => mem_ndunion.2 <| Or.inr h inf := (· ∩ ·) le_inf := fun _ _ _ ht hu _ h => mem_ndinter.2 ⟨ht h, hu h⟩ inf_le_left := fun _ _ _ h => (mem_ndinter.1 h).1 inf_le_right := fun _ _ _ h => (mem_ndinter.1 h).2 } @[simp] theorem sup_eq_union : (Sup.sup : Finset α → Finset α → Finset α) = Union.union := rfl #align finset.sup_eq_union Finset.sup_eq_union @[simp] theorem inf_eq_inter : (Inf.inf : Finset α → Finset α → Finset α) = Inter.inter := rfl #align finset.inf_eq_inter Finset.inf_eq_inter theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ := disjoint_iff #align finset.disjoint_iff_inter_eq_empty Finset.disjoint_iff_inter_eq_empty instance decidableDisjoint (U V : Finset α) : Decidable (Disjoint U V) := decidable_of_iff _ disjoint_left.symm #align finset.decidable_disjoint Finset.decidableDisjoint /-! #### union -/ theorem union_val_nd (s t : Finset α) : (s ∪ t).1 = ndunion s.1 t.1 := rfl #align finset.union_val_nd Finset.union_val_nd @[simp] theorem union_val (s t : Finset α) : (s ∪ t).1 = s.1 ∪ t.1 := ndunion_eq_union s.2 #align finset.union_val Finset.union_val @[simp] theorem mem_union : a ∈ s ∪ t ↔ a ∈ s ∨ a ∈ t := mem_ndunion #align finset.mem_union Finset.mem_union @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t := ext fun a => by simp #align finset.disj_union_eq_union Finset.disjUnion_eq_union theorem mem_union_left (t : Finset α) (h : a ∈ s) : a ∈ s ∪ t := mem_union.2 <| Or.inl h #align finset.mem_union_left Finset.mem_union_left theorem mem_union_right (s : Finset α) (h : a ∈ t) : a ∈ s ∪ t := mem_union.2 <| Or.inr h #align finset.mem_union_right Finset.mem_union_right theorem forall_mem_union {p : α → Prop} : (∀ a ∈ s ∪ t, p a) ↔ (∀ a ∈ s, p a) ∧ ∀ a ∈ t, p a := ⟨fun h => ⟨fun a => h a ∘ mem_union_left _, fun b => h b ∘ mem_union_right _⟩, fun h _ab hab => (mem_union.mp hab).elim (h.1 _) (h.2 _)⟩ #align finset.forall_mem_union Finset.forall_mem_union theorem not_mem_union : a ∉ s ∪ t ↔ a ∉ s ∧ a ∉ t := by rw [mem_union, not_or] #align finset.not_mem_union Finset.not_mem_union @[simp, norm_cast] theorem coe_union (s₁ s₂ : Finset α) : ↑(s₁ ∪ s₂) = (s₁ ∪ s₂ : Set α) := Set.ext fun _ => mem_union #align finset.coe_union Finset.coe_union theorem union_subset (hs : s ⊆ u) : t ⊆ u → s ∪ t ⊆ u := sup_le <| le_iff_subset.2 hs #align finset.union_subset Finset.union_subset theorem subset_union_left {s₁ s₂ : Finset α} : s₁ ⊆ s₁ ∪ s₂ := fun _x => mem_union_left _ #align finset.subset_union_left Finset.subset_union_left theorem subset_union_right {s₁ s₂ : Finset α} : s₂ ⊆ s₁ ∪ s₂ := fun _x => mem_union_right _ #align finset.subset_union_right Finset.subset_union_right @[gcongr] theorem union_subset_union (hsu : s ⊆ u) (htv : t ⊆ v) : s ∪ t ⊆ u ∪ v := sup_le_sup (le_iff_subset.2 hsu) htv #align finset.union_subset_union Finset.union_subset_union @[gcongr] theorem union_subset_union_left (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl #align finset.union_subset_union_left Finset.union_subset_union_left @[gcongr] theorem union_subset_union_right (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h #align finset.union_subset_union_right Finset.union_subset_union_right theorem union_comm (s₁ s₂ : Finset α) : s₁ ∪ s₂ = s₂ ∪ s₁ := sup_comm _ _ #align finset.union_comm Finset.union_comm instance : Std.Commutative (α := Finset α) (· ∪ ·) := ⟨union_comm⟩ @[simp] theorem union_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ (s₂ ∪ s₃) := sup_assoc _ _ _ #align finset.union_assoc Finset.union_assoc instance : Std.Associative (α := Finset α) (· ∪ ·) := ⟨union_assoc⟩ @[simp] theorem union_idempotent (s : Finset α) : s ∪ s = s := sup_idem _ #align finset.union_idempotent Finset.union_idempotent instance : Std.IdempotentOp (α := Finset α) (· ∪ ·) := ⟨union_idempotent⟩ theorem union_subset_left (h : s ∪ t ⊆ u) : s ⊆ u := subset_union_left.trans h #align finset.union_subset_left Finset.union_subset_left theorem union_subset_right {s t u : Finset α} (h : s ∪ t ⊆ u) : t ⊆ u := Subset.trans subset_union_right h #align finset.union_subset_right Finset.union_subset_right theorem union_left_comm (s t u : Finset α) : s ∪ (t ∪ u) = t ∪ (s ∪ u) := ext fun _ => by simp only [mem_union, or_left_comm] #align finset.union_left_comm Finset.union_left_comm theorem union_right_comm (s t u : Finset α) : s ∪ t ∪ u = s ∪ u ∪ t := ext fun x => by simp only [mem_union, or_assoc, @or_comm (x ∈ t)] #align finset.union_right_comm Finset.union_right_comm theorem union_self (s : Finset α) : s ∪ s = s := union_idempotent s #align finset.union_self Finset.union_self @[simp] theorem union_empty (s : Finset α) : s ∪ ∅ = s := ext fun x => mem_union.trans <| by simp #align finset.union_empty Finset.union_empty @[simp] theorem empty_union (s : Finset α) : ∅ ∪ s = s := ext fun x => mem_union.trans <| by simp #align finset.empty_union Finset.empty_union @[aesop unsafe apply (rule_sets := [finsetNonempty])] theorem Nonempty.inl {s t : Finset α} (h : s.Nonempty) : (s ∪ t).Nonempty := h.mono subset_union_left @[aesop unsafe apply (rule_sets := [finsetNonempty])] theorem Nonempty.inr {s t : Finset α} (h : t.Nonempty) : (s ∪ t).Nonempty := h.mono subset_union_right theorem insert_eq (a : α) (s : Finset α) : insert a s = {a} ∪ s := rfl #align finset.insert_eq Finset.insert_eq @[simp] theorem insert_union (a : α) (s t : Finset α) : insert a s ∪ t = insert a (s ∪ t) := by simp only [insert_eq, union_assoc] #align finset.insert_union Finset.insert_union @[simp] theorem union_insert (a : α) (s t : Finset α) : s ∪ insert a t = insert a (s ∪ t) := by simp only [insert_eq, union_left_comm] #align finset.union_insert Finset.union_insert theorem insert_union_distrib (a : α) (s t : Finset α) : insert a (s ∪ t) = insert a s ∪ insert a t := by simp only [insert_union, union_insert, insert_idem] #align finset.insert_union_distrib Finset.insert_union_distrib @[simp] lemma union_eq_left : s ∪ t = s ↔ t ⊆ s := sup_eq_left #align finset.union_eq_left_iff_subset Finset.union_eq_left @[simp] lemma left_eq_union : s = s ∪ t ↔ t ⊆ s := by rw [eq_comm, union_eq_left] #align finset.left_eq_union_iff_subset Finset.left_eq_union @[simp] lemma union_eq_right : s ∪ t = t ↔ s ⊆ t := sup_eq_right #align finset.union_eq_right_iff_subset Finset.union_eq_right @[simp] lemma right_eq_union : s = t ∪ s ↔ t ⊆ s := by rw [eq_comm, union_eq_right] #align finset.right_eq_union_iff_subset Finset.right_eq_union -- Porting note: replaced `⊔` in RHS theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu #align finset.union_congr_left Finset.union_congr_left theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht #align finset.union_congr_right Finset.union_congr_right theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left #align finset.union_eq_union_iff_left Finset.union_eq_union_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right #align finset.union_eq_union_iff_right Finset.union_eq_union_iff_right @[simp] theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by simp only [disjoint_left, mem_union, or_imp, forall_and] #align finset.disjoint_union_left Finset.disjoint_union_left @[simp] theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by simp only [disjoint_right, mem_union, or_imp, forall_and] #align finset.disjoint_union_right Finset.disjoint_union_right /-- To prove a relation on pairs of `Finset X`, it suffices to show that it is * symmetric, * it holds when one of the `Finset`s is empty, * it holds for pairs of singletons, * if it holds for `[a, c]` and for `[b, c]`, then it holds for `[a ∪ b, c]`. -/ theorem induction_on_union (P : Finset α → Finset α → Prop) (symm : ∀ {a b}, P a b → P b a) (empty_right : ∀ {a}, P a ∅) (singletons : ∀ {a b}, P {a} {b}) (union_of : ∀ {a b c}, P a c → P b c → P (a ∪ b) c) : ∀ a b, P a b := by intro a b refine Finset.induction_on b empty_right fun x s _xs hi => symm ?_ rw [Finset.insert_eq] apply union_of _ (symm hi) refine Finset.induction_on a empty_right fun a t _ta hi => symm ?_ rw [Finset.insert_eq] exact union_of singletons (symm hi) #align finset.induction_on_union Finset.induction_on_union /-! #### inter -/ theorem inter_val_nd (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = ndinter s₁.1 s₂.1 := rfl #align finset.inter_val_nd Finset.inter_val_nd @[simp] theorem inter_val (s₁ s₂ : Finset α) : (s₁ ∩ s₂).1 = s₁.1 ∩ s₂.1 := ndinter_eq_inter s₁.2 #align finset.inter_val Finset.inter_val @[simp] theorem mem_inter {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ ∩ s₂ ↔ a ∈ s₁ ∧ a ∈ s₂ := mem_ndinter #align finset.mem_inter Finset.mem_inter theorem mem_of_mem_inter_left {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₁ := (mem_inter.1 h).1 #align finset.mem_of_mem_inter_left Finset.mem_of_mem_inter_left theorem mem_of_mem_inter_right {a : α} {s₁ s₂ : Finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₂ := (mem_inter.1 h).2 #align finset.mem_of_mem_inter_right Finset.mem_of_mem_inter_right theorem mem_inter_of_mem {a : α} {s₁ s₂ : Finset α} : a ∈ s₁ → a ∈ s₂ → a ∈ s₁ ∩ s₂ := and_imp.1 mem_inter.2 #align finset.mem_inter_of_mem Finset.mem_inter_of_mem theorem inter_subset_left {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₁ := fun _a => mem_of_mem_inter_left #align finset.inter_subset_left Finset.inter_subset_left theorem inter_subset_right {s₁ s₂ : Finset α} : s₁ ∩ s₂ ⊆ s₂ := fun _a => mem_of_mem_inter_right #align finset.inter_subset_right Finset.inter_subset_right theorem subset_inter {s₁ s₂ u : Finset α} : s₁ ⊆ s₂ → s₁ ⊆ u → s₁ ⊆ s₂ ∩ u := by simp (config := { contextual := true }) [subset_iff, mem_inter] #align finset.subset_inter Finset.subset_inter @[simp, norm_cast] theorem coe_inter (s₁ s₂ : Finset α) : ↑(s₁ ∩ s₂) = (s₁ ∩ s₂ : Set α) := Set.ext fun _ => mem_inter #align finset.coe_inter Finset.coe_inter @[simp] theorem union_inter_cancel_left {s t : Finset α} : (s ∪ t) ∩ s = s := by rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_left] #align finset.union_inter_cancel_left Finset.union_inter_cancel_left @[simp] theorem union_inter_cancel_right {s t : Finset α} : (s ∪ t) ∩ t = t := by rw [← coe_inj, coe_inter, coe_union, Set.union_inter_cancel_right] #align finset.union_inter_cancel_right Finset.union_inter_cancel_right theorem inter_comm (s₁ s₂ : Finset α) : s₁ ∩ s₂ = s₂ ∩ s₁ := ext fun _ => by simp only [mem_inter, and_comm] #align finset.inter_comm Finset.inter_comm @[simp] theorem inter_assoc (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ (s₂ ∩ s₃) := ext fun _ => by simp only [mem_inter, and_assoc] #align finset.inter_assoc Finset.inter_assoc theorem inter_left_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => by simp only [mem_inter, and_left_comm] #align finset.inter_left_comm Finset.inter_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Finset α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => by simp only [mem_inter, and_right_comm] #align finset.inter_right_comm Finset.inter_right_comm @[simp] theorem inter_self (s : Finset α) : s ∩ s = s := ext fun _ => mem_inter.trans <| and_self_iff #align finset.inter_self Finset.inter_self @[simp] theorem inter_empty (s : Finset α) : s ∩ ∅ = ∅ := ext fun _ => mem_inter.trans <| by simp #align finset.inter_empty Finset.inter_empty @[simp] theorem empty_inter (s : Finset α) : ∅ ∩ s = ∅ := ext fun _ => mem_inter.trans <| by simp #align finset.empty_inter Finset.empty_inter @[simp] theorem inter_union_self (s t : Finset α) : s ∩ (t ∪ s) = s := by rw [inter_comm, union_inter_cancel_right] #align finset.inter_union_self Finset.inter_union_self @[simp] theorem insert_inter_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₂) : insert a s₁ ∩ s₂ = insert a (s₁ ∩ s₂) := ext fun x => by have : x = a ∨ x ∈ s₂ ↔ x ∈ s₂ := or_iff_right_of_imp <| by rintro rfl; exact h simp only [mem_inter, mem_insert, or_and_left, this] #align finset.insert_inter_of_mem Finset.insert_inter_of_mem @[simp] theorem inter_insert_of_mem {s₁ s₂ : Finset α} {a : α} (h : a ∈ s₁) : s₁ ∩ insert a s₂ = insert a (s₁ ∩ s₂) := by rw [inter_comm, insert_inter_of_mem h, inter_comm] #align finset.inter_insert_of_mem Finset.inter_insert_of_mem @[simp] theorem insert_inter_of_not_mem {s₁ s₂ : Finset α} {a : α} (h : a ∉ s₂) : insert a s₁ ∩ s₂ = s₁ ∩ s₂ := ext fun x => by have : ¬(x = a ∧ x ∈ s₂) := by rintro ⟨rfl, H⟩; exact h H simp only [mem_inter, mem_insert, or_and_right, this, false_or_iff] #align finset.insert_inter_of_not_mem Finset.insert_inter_of_not_mem @[simp] theorem inter_insert_of_not_mem {s₁ s₂ : Finset α} {a : α} (h : a ∉ s₁) : s₁ ∩ insert a s₂ = s₁ ∩ s₂ := by rw [inter_comm, insert_inter_of_not_mem h, inter_comm] #align finset.inter_insert_of_not_mem Finset.inter_insert_of_not_mem @[simp] theorem singleton_inter_of_mem {a : α} {s : Finset α} (H : a ∈ s) : {a} ∩ s = {a} := show insert a ∅ ∩ s = insert a ∅ by rw [insert_inter_of_mem H, empty_inter] #align finset.singleton_inter_of_mem Finset.singleton_inter_of_mem @[simp] theorem singleton_inter_of_not_mem {a : α} {s : Finset α} (H : a ∉ s) : {a} ∩ s = ∅ := eq_empty_of_forall_not_mem <| by simp only [mem_inter, mem_singleton]; rintro x ⟨rfl, h⟩; exact H h #align finset.singleton_inter_of_not_mem Finset.singleton_inter_of_not_mem @[simp] theorem inter_singleton_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ∩ {a} = {a} := by rw [inter_comm, singleton_inter_of_mem h] #align finset.inter_singleton_of_mem Finset.inter_singleton_of_mem @[simp] theorem inter_singleton_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : s ∩ {a} = ∅ := by rw [inter_comm, singleton_inter_of_not_mem h] #align finset.inter_singleton_of_not_mem Finset.inter_singleton_of_not_mem @[mono, gcongr] theorem inter_subset_inter {x y s t : Finset α} (h : x ⊆ y) (h' : s ⊆ t) : x ∩ s ⊆ y ∩ t := by intro a a_in rw [Finset.mem_inter] at a_in ⊢ exact ⟨h a_in.1, h' a_in.2⟩ #align finset.inter_subset_inter Finset.inter_subset_inter @[gcongr] theorem inter_subset_inter_left (h : t ⊆ u) : s ∩ t ⊆ s ∩ u := inter_subset_inter Subset.rfl h #align finset.inter_subset_inter_left Finset.inter_subset_inter_left @[gcongr] theorem inter_subset_inter_right (h : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter h Subset.rfl #align finset.inter_subset_inter_right Finset.inter_subset_inter_right theorem inter_subset_union : s ∩ t ⊆ s ∪ t := le_iff_subset.1 inf_le_sup #align finset.inter_subset_union Finset.inter_subset_union instance : DistribLattice (Finset α) := { le_sup_inf := fun a b c => by simp (config := { contextual := true }) only [sup_eq_union, inf_eq_inter, le_eq_subset, subset_iff, mem_inter, mem_union, and_imp, or_imp, true_or_iff, imp_true_iff, true_and_iff, or_true_iff] } @[simp] theorem union_left_idem (s t : Finset α) : s ∪ (s ∪ t) = s ∪ t := sup_left_idem _ _ #align finset.union_left_idem Finset.union_left_idem -- Porting note (#10618): @[simp] can prove this theorem union_right_idem (s t : Finset α) : s ∪ t ∪ t = s ∪ t := sup_right_idem _ _ #align finset.union_right_idem Finset.union_right_idem @[simp] theorem inter_left_idem (s t : Finset α) : s ∩ (s ∩ t) = s ∩ t := inf_left_idem _ _ #align finset.inter_left_idem Finset.inter_left_idem -- Porting note (#10618): @[simp] can prove this theorem inter_right_idem (s t : Finset α) : s ∩ t ∩ t = s ∩ t := inf_right_idem _ _ #align finset.inter_right_idem Finset.inter_right_idem theorem inter_union_distrib_left (s t u : Finset α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ #align finset.inter_distrib_left Finset.inter_union_distrib_left theorem union_inter_distrib_right (s t u : Finset α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ #align finset.inter_distrib_right Finset.union_inter_distrib_right theorem union_inter_distrib_left (s t u : Finset α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ #align finset.union_distrib_left Finset.union_inter_distrib_left theorem inter_union_distrib_right (s t u : Finset α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ #align finset.union_distrib_right Finset.inter_union_distrib_right -- 2024-03-22 @[deprecated] alias inter_distrib_left := inter_union_distrib_left @[deprecated] alias inter_distrib_right := union_inter_distrib_right @[deprecated] alias union_distrib_left := union_inter_distrib_left @[deprecated] alias union_distrib_right := inter_union_distrib_right theorem union_union_distrib_left (s t u : Finset α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ #align finset.union_union_distrib_left Finset.union_union_distrib_left theorem union_union_distrib_right (s t u : Finset α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ #align finset.union_union_distrib_right Finset.union_union_distrib_right theorem inter_inter_distrib_left (s t u : Finset α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ #align finset.inter_inter_distrib_left Finset.inter_inter_distrib_left theorem inter_inter_distrib_right (s t u : Finset α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ #align finset.inter_inter_distrib_right Finset.inter_inter_distrib_right theorem union_union_union_comm (s t u v : Finset α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ #align finset.union_union_union_comm Finset.union_union_union_comm theorem inter_inter_inter_comm (s t u v : Finset α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ #align finset.inter_inter_inter_comm Finset.inter_inter_inter_comm lemma union_eq_empty : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := sup_eq_bot_iff #align finset.union_eq_empty_iff Finset.union_eq_empty theorem union_subset_iff : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (sup_le_iff : s ⊔ t ≤ u ↔ s ≤ u ∧ t ≤ u) #align finset.union_subset_iff Finset.union_subset_iff theorem subset_inter_iff : s ⊆ t ∩ u ↔ s ⊆ t ∧ s ⊆ u := (le_inf_iff : s ≤ t ⊓ u ↔ s ≤ t ∧ s ≤ u) #align finset.subset_inter_iff Finset.subset_inter_iff @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left #align finset.inter_eq_left_iff_subset_iff_subset Finset.inter_eq_left @[simp] lemma inter_eq_right : t ∩ s = s ↔ s ⊆ t := inf_eq_right #align finset.inter_eq_right_iff_subset Finset.inter_eq_right theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu #align finset.inter_congr_left Finset.inter_congr_left theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht #align finset.inter_congr_right Finset.inter_congr_right theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left #align finset.inter_eq_inter_iff_left Finset.inter_eq_inter_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right #align finset.inter_eq_inter_iff_right Finset.inter_eq_inter_iff_right theorem ite_subset_union (s s' : Finset α) (P : Prop) [Decidable P] : ite P s s' ⊆ s ∪ s' := ite_le_sup s s' P #align finset.ite_subset_union Finset.ite_subset_union theorem inter_subset_ite (s s' : Finset α) (P : Prop) [Decidable P] : s ∩ s' ⊆ ite P s s' := inf_le_ite s s' P #align finset.inter_subset_ite Finset.inter_subset_ite theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] #align finset.not_disjoint_iff_nonempty_inter Finset.not_disjoint_iff_nonempty_inter alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter #align finset.nonempty.not_disjoint Finset.Nonempty.not_disjoint theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ #align finset.disjoint_or_nonempty_inter Finset.disjoint_or_nonempty_inter end Lattice instance isDirected_le : IsDirected (Finset α) (· ≤ ·) := by classical infer_instance instance isDirected_subset : IsDirected (Finset α) (· ⊆ ·) := isDirected_le /-! ### erase -/ section Erase variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `erase s a` is the set `s - {a}`, that is, the elements of `s` which are not equal to `a`. -/ def erase (s : Finset α) (a : α) : Finset α := ⟨_, s.2.erase a⟩ #align finset.erase Finset.erase @[simp] theorem erase_val (s : Finset α) (a : α) : (erase s a).1 = s.1.erase a := rfl #align finset.erase_val Finset.erase_val @[simp] theorem mem_erase {a b : α} {s : Finset α} : a ∈ erase s b ↔ a ≠ b ∧ a ∈ s := s.2.mem_erase_iff #align finset.mem_erase Finset.mem_erase theorem not_mem_erase (a : α) (s : Finset α) : a ∉ erase s a := s.2.not_mem_erase #align finset.not_mem_erase Finset.not_mem_erase -- While this can be solved by `simp`, this lemma is eligible for `dsimp` @[nolint simpNF, simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl #align finset.erase_empty Finset.erase_empty protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty := (hs.exists_ne a).imp $ by aesop @[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)] refine ⟨?_, fun hs ↦ hs.exists_ne a⟩ rintro ⟨b, hb, hba⟩ exact ⟨_, hb, _, ha, hba⟩ @[simp] theorem erase_singleton (a : α) : ({a} : Finset α).erase a = ∅ := by ext x simp #align finset.erase_singleton Finset.erase_singleton theorem ne_of_mem_erase : b ∈ erase s a → b ≠ a := fun h => (mem_erase.1 h).1 #align finset.ne_of_mem_erase Finset.ne_of_mem_erase theorem mem_of_mem_erase : b ∈ erase s a → b ∈ s := Multiset.mem_of_mem_erase #align finset.mem_of_mem_erase Finset.mem_of_mem_erase theorem mem_erase_of_ne_of_mem : a ≠ b → a ∈ s → a ∈ erase s b := by simp only [mem_erase]; exact And.intro #align finset.mem_erase_of_ne_of_mem Finset.mem_erase_of_ne_of_mem /-- An element of `s` that is not an element of `erase s a` must be`a`. -/ theorem eq_of_mem_of_not_mem_erase (hs : b ∈ s) (hsa : b ∉ s.erase a) : b = a := by rw [mem_erase, not_and] at hsa exact not_imp_not.mp hsa hs #align finset.eq_of_mem_of_not_mem_erase Finset.eq_of_mem_of_not_mem_erase @[simp] theorem erase_eq_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : erase s a = s := eq_of_veq <| erase_of_not_mem h #align finset.erase_eq_of_not_mem Finset.erase_eq_of_not_mem @[simp] theorem erase_eq_self : s.erase a = s ↔ a ∉ s := ⟨fun h => h ▸ not_mem_erase _ _, erase_eq_of_not_mem⟩ #align finset.erase_eq_self Finset.erase_eq_self @[simp] theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a := ext fun x => by simp (config := { contextual := true }) only [mem_erase, mem_insert, and_congr_right_iff, false_or_iff, iff_self_iff, imp_true_iff] #align finset.erase_insert_eq_erase Finset.erase_insert_eq_erase theorem erase_insert {a : α} {s : Finset α} (h : a ∉ s) : erase (insert a s) a = s := by rw [erase_insert_eq_erase, erase_eq_of_not_mem h] #align finset.erase_insert Finset.erase_insert theorem erase_insert_of_ne {a b : α} {s : Finset α} (h : a ≠ b) : erase (insert a s) b = insert a (erase s b) := ext fun x => by have : x ≠ b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm ▸ h simp only [mem_erase, mem_insert, and_or_left, this] #align finset.erase_insert_of_ne Finset.erase_insert_of_ne theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b) : erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by simp only [cons_eq_insert, erase_insert_of_ne hb] #align finset.erase_cons_of_ne Finset.erase_cons_of_ne @[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s := ext fun x => by simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and_iff] apply or_iff_right_of_imp rintro rfl exact h #align finset.insert_erase Finset.insert_erase lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by aesop lemma insert_erase_invOn : Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} := ⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩ theorem erase_subset_erase (a : α) {s t : Finset α} (h : s ⊆ t) : erase s a ⊆ erase t a := val_le_iff.1 <| erase_le_erase _ <| val_le_iff.2 h #align finset.erase_subset_erase Finset.erase_subset_erase theorem erase_subset (a : α) (s : Finset α) : erase s a ⊆ s := Multiset.erase_subset _ _ #align finset.erase_subset Finset.erase_subset theorem subset_erase {a : α} {s t : Finset α} : s ⊆ t.erase a ↔ s ⊆ t ∧ a ∉ s := ⟨fun h => ⟨h.trans (erase_subset _ _), fun ha => not_mem_erase _ _ (h ha)⟩, fun h _b hb => mem_erase.2 ⟨ne_of_mem_of_not_mem hb h.2, h.1 hb⟩⟩ #align finset.subset_erase Finset.subset_erase @[simp, norm_cast] theorem coe_erase (a : α) (s : Finset α) : ↑(erase s a) = (s \ {a} : Set α) := Set.ext fun _ => mem_erase.trans <| by rw [and_comm, Set.mem_diff, Set.mem_singleton_iff, mem_coe] #align finset.coe_erase Finset.coe_erase theorem erase_ssubset {a : α} {s : Finset α} (h : a ∈ s) : s.erase a ⊂ s := calc s.erase a ⊂ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _ _ = _ := insert_erase h #align finset.erase_ssubset Finset.erase_ssubset
Mathlib/Data/Finset/Basic.lean
2,014
2,017
theorem ssubset_iff_exists_subset_erase {s t : Finset α} : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t.erase a := by
refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩ obtain ⟨a, ht, hs⟩ := not_subset.1 h.2 exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩
/- 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.Finsupp.Multiset import Mathlib.Order.Bounded import Mathlib.SetTheory.Cardinal.PartENat import Mathlib.SetTheory.Ordinal.Principal import Mathlib.Tactic.Linarith #align_import set_theory.cardinal.ordinal from "leanprover-community/mathlib"@"7c2ce0c2da15516b4e65d0c9e254bb6dc93abd1f" /-! # Cardinals and ordinals Relationships between cardinals and ordinals, properties of cardinals that are proved using ordinals. ## Main definitions * The function `Cardinal.aleph'` gives the cardinals listed by their ordinal index, and is the inverse of `Cardinal.aleph/idx`. `aleph' n = n`, `aleph' ω = ℵ₀`, `aleph' (ω + 1) = succ ℵ₀`, etc. It is an order isomorphism between ordinals and cardinals. * The function `Cardinal.aleph` gives the infinite cardinals listed by their ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first uncountable cardinal, and so on. The notation `ω_` combines the latter with `Cardinal.ord`, giving an enumeration of (infinite) initial ordinals. Thus `ω_ 0 = ω` and `ω₁ = ω_ 1` is the first uncountable ordinal. * The function `Cardinal.beth` enumerates the Beth cardinals. `beth 0 = ℵ₀`, `beth (succ o) = 2 ^ beth o`, and for a limit ordinal `o`, `beth o` is the supremum of `beth a` for `a < o`. ## Main Statements * `Cardinal.mul_eq_max` and `Cardinal.add_eq_max` state that the product (resp. sum) of two infinite cardinals is just their maximum. Several variations around this fact are also given. * `Cardinal.mk_list_eq_mk` : when `α` is infinite, `α` and `List α` have the same cardinality. * simp lemmas for inequalities between `bit0 a` and `bit1 b` are registered, making `simp` able to prove inequalities about numeral cardinals. ## Tags cardinal arithmetic (for infinite cardinals) -/ noncomputable section open Function Set Cardinal Equiv Order Ordinal open scoped Classical universe u v w namespace Cardinal section UsingOrdinals theorem ord_isLimit {c} (co : ℵ₀ ≤ c) : (ord c).IsLimit := by refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩ · rw [← Ordinal.le_zero, ord_le] at h simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h · rw [ord_le] at h ⊢ rwa [← @add_one_of_aleph0_le (card a), ← card_succ] rw [← ord_le, ← le_succ_of_isLimit, ord_le] · exact co.trans h · rw [ord_aleph0] exact omega_isLimit #align cardinal.ord_is_limit Cardinal.ord_isLimit theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.out.α := Ordinal.out_no_max_of_succ_lt (ord_isLimit h).2 /-! ### Aleph cardinals -/ section aleph /-- The `aleph'` index function, which gives the ordinal index of a cardinal. (The `aleph'` part is because unlike `aleph` this counts also the finite stages. So `alephIdx n = n`, `alephIdx ω = ω`, `alephIdx ℵ₁ = ω + 1` and so on.) In this definition, we register additionally that this function is an initial segment, i.e., it is order preserving and its range is an initial segment of the ordinals. For the basic function version, see `alephIdx`. For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/ def alephIdx.initialSeg : @InitialSeg Cardinal Ordinal (· < ·) (· < ·) := @RelEmbedding.collapse Cardinal Ordinal (· < ·) (· < ·) _ Cardinal.ord.orderEmbedding.ltEmbedding #align cardinal.aleph_idx.initial_seg Cardinal.alephIdx.initialSeg /-- The `aleph'` index function, which gives the ordinal index of a cardinal. (The `aleph'` part is because unlike `aleph` this counts also the finite stages. So `alephIdx n = n`, `alephIdx ω = ω`, `alephIdx ℵ₁ = ω + 1` and so on.) For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/ def alephIdx : Cardinal → Ordinal := alephIdx.initialSeg #align cardinal.aleph_idx Cardinal.alephIdx @[simp] theorem alephIdx.initialSeg_coe : (alephIdx.initialSeg : Cardinal → Ordinal) = alephIdx := rfl #align cardinal.aleph_idx.initial_seg_coe Cardinal.alephIdx.initialSeg_coe @[simp] theorem alephIdx_lt {a b} : alephIdx a < alephIdx b ↔ a < b := alephIdx.initialSeg.toRelEmbedding.map_rel_iff #align cardinal.aleph_idx_lt Cardinal.alephIdx_lt @[simp] theorem alephIdx_le {a b} : alephIdx a ≤ alephIdx b ↔ a ≤ b := by rw [← not_lt, ← not_lt, alephIdx_lt] #align cardinal.aleph_idx_le Cardinal.alephIdx_le theorem alephIdx.init {a b} : b < alephIdx a → ∃ c, alephIdx c = b := alephIdx.initialSeg.init #align cardinal.aleph_idx.init Cardinal.alephIdx.init /-- The `aleph'` index function, which gives the ordinal index of a cardinal. (The `aleph'` part is because unlike `aleph` this counts also the finite stages. So `alephIdx n = n`, `alephIdx ℵ₀ = ω`, `alephIdx ℵ₁ = ω + 1` and so on.) In this version, we register additionally that this function is an order isomorphism between cardinals and ordinals. For the basic function version, see `alephIdx`. -/ def alephIdx.relIso : @RelIso Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) := @RelIso.ofSurjective Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) alephIdx.initialSeg.{u} <| (InitialSeg.eq_or_principal alephIdx.initialSeg.{u}).resolve_right fun ⟨o, e⟩ => by have : ∀ c, alephIdx c < o := fun c => (e _).2 ⟨_, rfl⟩ refine Ordinal.inductionOn o ?_ this; intro α r _ h let s := ⨆ a, invFun alephIdx (Ordinal.typein r a) apply (lt_succ s).not_le have I : Injective.{u+2, u+2} alephIdx := alephIdx.initialSeg.toEmbedding.injective simpa only [typein_enum, leftInverse_invFun I (succ s)] using le_ciSup (Cardinal.bddAbove_range.{u, u} fun a : α => invFun alephIdx (Ordinal.typein r a)) (Ordinal.enum r _ (h (succ s))) #align cardinal.aleph_idx.rel_iso Cardinal.alephIdx.relIso @[simp] theorem alephIdx.relIso_coe : (alephIdx.relIso : Cardinal → Ordinal) = alephIdx := rfl #align cardinal.aleph_idx.rel_iso_coe Cardinal.alephIdx.relIso_coe @[simp] theorem type_cardinal : @type Cardinal (· < ·) _ = Ordinal.univ.{u, u + 1} := by rw [Ordinal.univ_id]; exact Quotient.sound ⟨alephIdx.relIso⟩ #align cardinal.type_cardinal Cardinal.type_cardinal @[simp] theorem mk_cardinal : #Cardinal = univ.{u, u + 1} := by simpa only [card_type, card_univ] using congr_arg card type_cardinal #align cardinal.mk_cardinal Cardinal.mk_cardinal /-- The `aleph'` function gives the cardinals listed by their ordinal index, and is the inverse of `aleph_idx`. `aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. In this version, we register additionally that this function is an order isomorphism between ordinals and cardinals. For the basic function version, see `aleph'`. -/ def Aleph'.relIso := Cardinal.alephIdx.relIso.symm #align cardinal.aleph'.rel_iso Cardinal.Aleph'.relIso /-- The `aleph'` function gives the cardinals listed by their ordinal index, and is the inverse of `aleph_idx`. `aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. -/ def aleph' : Ordinal → Cardinal := Aleph'.relIso #align cardinal.aleph' Cardinal.aleph' @[simp] theorem aleph'.relIso_coe : (Aleph'.relIso : Ordinal → Cardinal) = aleph' := rfl #align cardinal.aleph'.rel_iso_coe Cardinal.aleph'.relIso_coe @[simp] theorem aleph'_lt {o₁ o₂ : Ordinal} : aleph' o₁ < aleph' o₂ ↔ o₁ < o₂ := Aleph'.relIso.map_rel_iff #align cardinal.aleph'_lt Cardinal.aleph'_lt @[simp] theorem aleph'_le {o₁ o₂ : Ordinal} : aleph' o₁ ≤ aleph' o₂ ↔ o₁ ≤ o₂ := le_iff_le_iff_lt_iff_lt.2 aleph'_lt #align cardinal.aleph'_le Cardinal.aleph'_le @[simp] theorem aleph'_alephIdx (c : Cardinal) : aleph' c.alephIdx = c := Cardinal.alephIdx.relIso.toEquiv.symm_apply_apply c #align cardinal.aleph'_aleph_idx Cardinal.aleph'_alephIdx @[simp] theorem alephIdx_aleph' (o : Ordinal) : (aleph' o).alephIdx = o := Cardinal.alephIdx.relIso.toEquiv.apply_symm_apply o #align cardinal.aleph_idx_aleph' Cardinal.alephIdx_aleph' @[simp] theorem aleph'_zero : aleph' 0 = 0 := by rw [← nonpos_iff_eq_zero, ← aleph'_alephIdx 0, aleph'_le] apply Ordinal.zero_le #align cardinal.aleph'_zero Cardinal.aleph'_zero @[simp] theorem aleph'_succ {o : Ordinal} : aleph' (succ o) = succ (aleph' o) := by apply (succ_le_of_lt <| aleph'_lt.2 <| lt_succ o).antisymm' (Cardinal.alephIdx_le.1 <| _) rw [alephIdx_aleph', succ_le_iff, ← aleph'_lt, aleph'_alephIdx] apply lt_succ #align cardinal.aleph'_succ Cardinal.aleph'_succ @[simp] theorem aleph'_nat : ∀ n : ℕ, aleph' n = n | 0 => aleph'_zero | n + 1 => show aleph' (succ n) = n.succ by rw [aleph'_succ, aleph'_nat n, nat_succ] #align cardinal.aleph'_nat Cardinal.aleph'_nat theorem aleph'_le_of_limit {o : Ordinal} (l : o.IsLimit) {c} : aleph' o ≤ c ↔ ∀ o' < o, aleph' o' ≤ c := ⟨fun h o' h' => (aleph'_le.2 <| h'.le).trans h, fun h => by rw [← aleph'_alephIdx c, aleph'_le, limit_le l] intro x h' rw [← aleph'_le, aleph'_alephIdx] exact h _ h'⟩ #align cardinal.aleph'_le_of_limit Cardinal.aleph'_le_of_limit theorem aleph'_limit {o : Ordinal} (ho : o.IsLimit) : aleph' o = ⨆ a : Iio o, aleph' a := by refine le_antisymm ?_ (ciSup_le' fun i => aleph'_le.2 (le_of_lt i.2)) rw [aleph'_le_of_limit ho] exact fun a ha => le_ciSup (bddAbove_of_small _) (⟨a, ha⟩ : Iio o) #align cardinal.aleph'_limit Cardinal.aleph'_limit @[simp] theorem aleph'_omega : aleph' ω = ℵ₀ := eq_of_forall_ge_iff fun c => by simp only [aleph'_le_of_limit omega_isLimit, lt_omega, exists_imp, aleph0_le] exact forall_swap.trans (forall_congr' fun n => by simp only [forall_eq, aleph'_nat]) #align cardinal.aleph'_omega Cardinal.aleph'_omega /-- `aleph'` and `aleph_idx` form an equivalence between `Ordinal` and `Cardinal` -/ @[simp] def aleph'Equiv : Ordinal ≃ Cardinal := ⟨aleph', alephIdx, alephIdx_aleph', aleph'_alephIdx⟩ #align cardinal.aleph'_equiv Cardinal.aleph'Equiv /-- The `aleph` function gives the infinite cardinals listed by their ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first uncountable cardinal, and so on. -/ def aleph (o : Ordinal) : Cardinal := aleph' (ω + o) #align cardinal.aleph Cardinal.aleph @[simp] theorem aleph_lt {o₁ o₂ : Ordinal} : aleph o₁ < aleph o₂ ↔ o₁ < o₂ := aleph'_lt.trans (add_lt_add_iff_left _) #align cardinal.aleph_lt Cardinal.aleph_lt @[simp] theorem aleph_le {o₁ o₂ : Ordinal} : aleph o₁ ≤ aleph o₂ ↔ o₁ ≤ o₂ := le_iff_le_iff_lt_iff_lt.2 aleph_lt #align cardinal.aleph_le Cardinal.aleph_le @[simp] theorem max_aleph_eq (o₁ o₂ : Ordinal) : max (aleph o₁) (aleph o₂) = aleph (max o₁ o₂) := by rcases le_total (aleph o₁) (aleph o₂) with h | h · rw [max_eq_right h, max_eq_right (aleph_le.1 h)] · rw [max_eq_left h, max_eq_left (aleph_le.1 h)] #align cardinal.max_aleph_eq Cardinal.max_aleph_eq @[simp] theorem aleph_succ {o : Ordinal} : aleph (succ o) = succ (aleph o) := by rw [aleph, add_succ, aleph'_succ, aleph] #align cardinal.aleph_succ Cardinal.aleph_succ @[simp] theorem aleph_zero : aleph 0 = ℵ₀ := by rw [aleph, add_zero, aleph'_omega] #align cardinal.aleph_zero Cardinal.aleph_zero theorem aleph_limit {o : Ordinal} (ho : o.IsLimit) : aleph o = ⨆ a : Iio o, aleph a := by apply le_antisymm _ (ciSup_le' _) · rw [aleph, aleph'_limit (ho.add _)] refine ciSup_mono' (bddAbove_of_small _) ?_ rintro ⟨i, hi⟩ cases' lt_or_le i ω with h h · rcases lt_omega.1 h with ⟨n, rfl⟩ use ⟨0, ho.pos⟩ simpa using (nat_lt_aleph0 n).le · exact ⟨⟨_, (sub_lt_of_le h).2 hi⟩, aleph'_le.2 (le_add_sub _ _)⟩ · exact fun i => aleph_le.2 (le_of_lt i.2) #align cardinal.aleph_limit Cardinal.aleph_limit theorem aleph0_le_aleph' {o : Ordinal} : ℵ₀ ≤ aleph' o ↔ ω ≤ o := by rw [← aleph'_omega, aleph'_le] #align cardinal.aleph_0_le_aleph' Cardinal.aleph0_le_aleph' theorem aleph0_le_aleph (o : Ordinal) : ℵ₀ ≤ aleph o := by rw [aleph, aleph0_le_aleph'] apply Ordinal.le_add_right #align cardinal.aleph_0_le_aleph Cardinal.aleph0_le_aleph theorem aleph'_pos {o : Ordinal} (ho : 0 < o) : 0 < aleph' o := by rwa [← aleph'_zero, aleph'_lt] #align cardinal.aleph'_pos Cardinal.aleph'_pos theorem aleph_pos (o : Ordinal) : 0 < aleph o := aleph0_pos.trans_le (aleph0_le_aleph o) #align cardinal.aleph_pos Cardinal.aleph_pos @[simp] theorem aleph_toNat (o : Ordinal) : toNat (aleph o) = 0 := toNat_apply_of_aleph0_le <| aleph0_le_aleph o #align cardinal.aleph_to_nat Cardinal.aleph_toNat @[simp] theorem aleph_toPartENat (o : Ordinal) : toPartENat (aleph o) = ⊤ := toPartENat_apply_of_aleph0_le <| aleph0_le_aleph o #align cardinal.aleph_to_part_enat Cardinal.aleph_toPartENat instance nonempty_out_aleph (o : Ordinal) : Nonempty (aleph o).ord.out.α := by rw [out_nonempty_iff_ne_zero, ← ord_zero] exact fun h => (ord_injective h).not_gt (aleph_pos o) #align cardinal.nonempty_out_aleph Cardinal.nonempty_out_aleph theorem ord_aleph_isLimit (o : Ordinal) : (aleph o).ord.IsLimit := ord_isLimit <| aleph0_le_aleph _ #align cardinal.ord_aleph_is_limit Cardinal.ord_aleph_isLimit instance (o : Ordinal) : NoMaxOrder (aleph o).ord.out.α := out_no_max_of_succ_lt (ord_aleph_isLimit o).2 theorem exists_aleph {c : Cardinal} : ℵ₀ ≤ c ↔ ∃ o, c = aleph o := ⟨fun h => ⟨alephIdx c - ω, by rw [aleph, Ordinal.add_sub_cancel_of_le, aleph'_alephIdx] rwa [← aleph0_le_aleph', aleph'_alephIdx]⟩, fun ⟨o, e⟩ => e.symm ▸ aleph0_le_aleph _⟩ #align cardinal.exists_aleph Cardinal.exists_aleph theorem aleph'_isNormal : IsNormal (ord ∘ aleph') := ⟨fun o => ord_lt_ord.2 <| aleph'_lt.2 <| lt_succ o, fun o l a => by simp [ord_le, aleph'_le_of_limit l]⟩ #align cardinal.aleph'_is_normal Cardinal.aleph'_isNormal theorem aleph_isNormal : IsNormal (ord ∘ aleph) := aleph'_isNormal.trans <| add_isNormal ω #align cardinal.aleph_is_normal Cardinal.aleph_isNormal theorem succ_aleph0 : succ ℵ₀ = aleph 1 := by rw [← aleph_zero, ← aleph_succ, Ordinal.succ_zero] #align cardinal.succ_aleph_0 Cardinal.succ_aleph0 theorem aleph0_lt_aleph_one : ℵ₀ < aleph 1 := by rw [← succ_aleph0] apply lt_succ #align cardinal.aleph_0_lt_aleph_one Cardinal.aleph0_lt_aleph_one theorem countable_iff_lt_aleph_one {α : Type*} (s : Set α) : s.Countable ↔ #s < aleph 1 := by rw [← succ_aleph0, lt_succ_iff, le_aleph0_iff_set_countable] #align cardinal.countable_iff_lt_aleph_one Cardinal.countable_iff_lt_aleph_one /-- Ordinals that are cardinals are unbounded. -/ theorem ord_card_unbounded : Unbounded (· < ·) { b : Ordinal | b.card.ord = b } := unbounded_lt_iff.2 fun a => ⟨_, ⟨by dsimp rw [card_ord], (lt_ord_succ_card a).le⟩⟩ #align cardinal.ord_card_unbounded Cardinal.ord_card_unbounded theorem eq_aleph'_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) : ∃ a, (aleph' a).ord = o := ⟨Cardinal.alephIdx.relIso o.card, by simpa using ho⟩ #align cardinal.eq_aleph'_of_eq_card_ord Cardinal.eq_aleph'_of_eq_card_ord /-- `ord ∘ aleph'` enumerates the ordinals that are cardinals. -/
Mathlib/SetTheory/Cardinal/Ordinal.lean
370
376
theorem ord_aleph'_eq_enum_card : ord ∘ aleph' = enumOrd { b : Ordinal | b.card.ord = b } := by
rw [← eq_enumOrd _ ord_card_unbounded, range_eq_iff] exact ⟨aleph'_isNormal.strictMono, ⟨fun a => by dsimp rw [card_ord], fun b hb => eq_aleph'_of_eq_card_ord hb⟩⟩
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Algebra.NeZero import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.Lifts import Mathlib.Algebra.Polynomial.Splits import Mathlib.RingTheory.RootsOfUnity.Complex import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.RingTheory.RootsOfUnity.Basic import Mathlib.FieldTheory.RatFunc.AsPolynomial #align_import ring_theory.polynomial.cyclotomic.basic from "leanprover-community/mathlib"@"7fdeecc0d03cd40f7a165e6cf00a4d2286db599f" /-! # Cyclotomic polynomials. For `n : ℕ` and an integral domain `R`, we define a modified version of the `n`-th cyclotomic polynomial with coefficients in `R`, denoted `cyclotomic' n R`, as `∏ (X - μ)`, where `μ` varies over the primitive `n`th roots of unity. If there is a primitive `n`th root of unity in `R` then this the standard definition. We then define the standard cyclotomic polynomial `cyclotomic n R` with coefficients in any ring `R`. ## Main definition * `cyclotomic n R` : the `n`-th cyclotomic polynomial with coefficients in `R`. ## Main results * `Polynomial.degree_cyclotomic` : The degree of `cyclotomic n` is `totient n`. * `Polynomial.prod_cyclotomic_eq_X_pow_sub_one` : `X ^ n - 1 = ∏ (cyclotomic i)`, where `i` divides `n`. * `Polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius` : The Möbius inversion formula for `cyclotomic n R` over an abstract fraction field for `R[X]`. ## Implementation details Our definition of `cyclotomic' n R` makes sense in any integral domain `R`, but the interesting results hold if there is a primitive `n`-th root of unity in `R`. In particular, our definition is not the standard one unless there is a primitive `n`th root of unity in `R`. For example, `cyclotomic' 3 ℤ = 1`, since there are no primitive cube roots of unity in `ℤ`. The main example is `R = ℂ`, we decided to work in general since the difficulties are essentially the same. To get the standard cyclotomic polynomials, we use `unique_int_coeff_of_cycl`, with `R = ℂ`, to get a polynomial with integer coefficients and then we map it to `R[X]`, for any ring `R`. -/ open scoped Polynomial noncomputable section universe u namespace Polynomial section Cyclotomic' section IsDomain variable {R : Type*} [CommRing R] [IsDomain R] /-- The modified `n`-th cyclotomic polynomial with coefficients in `R`, it is the usual cyclotomic polynomial if there is a primitive `n`-th root of unity in `R`. -/ def cyclotomic' (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : R[X] := ∏ μ ∈ primitiveRoots n R, (X - C μ) #align polynomial.cyclotomic' Polynomial.cyclotomic' /-- The zeroth modified cyclotomic polyomial is `1`. -/ @[simp] theorem cyclotomic'_zero (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 0 R = 1 := by simp only [cyclotomic', Finset.prod_empty, primitiveRoots_zero] #align polynomial.cyclotomic'_zero Polynomial.cyclotomic'_zero /-- The first modified cyclotomic polyomial is `X - 1`. -/ @[simp] theorem cyclotomic'_one (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 1 R = X - 1 := by simp only [cyclotomic', Finset.prod_singleton, RingHom.map_one, IsPrimitiveRoot.primitiveRoots_one] #align polynomial.cyclotomic'_one Polynomial.cyclotomic'_one /-- The second modified cyclotomic polyomial is `X + 1` if the characteristic of `R` is not `2`. -/ @[simp] theorem cyclotomic'_two (R : Type*) [CommRing R] [IsDomain R] (p : ℕ) [CharP R p] (hp : p ≠ 2) : cyclotomic' 2 R = X + 1 := by rw [cyclotomic'] have prim_root_two : primitiveRoots 2 R = {(-1 : R)} := by simp only [Finset.eq_singleton_iff_unique_mem, mem_primitiveRoots two_pos] exact ⟨IsPrimitiveRoot.neg_one p hp, fun x => IsPrimitiveRoot.eq_neg_one_of_two_right⟩ simp only [prim_root_two, Finset.prod_singleton, RingHom.map_neg, RingHom.map_one, sub_neg_eq_add] #align polynomial.cyclotomic'_two Polynomial.cyclotomic'_two /-- `cyclotomic' n R` is monic. -/ theorem cyclotomic'.monic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).Monic := monic_prod_of_monic _ _ fun _ _ => monic_X_sub_C _ #align polynomial.cyclotomic'.monic Polynomial.cyclotomic'.monic /-- `cyclotomic' n R` is different from `0`. -/ theorem cyclotomic'_ne_zero (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' n R ≠ 0 := (cyclotomic'.monic n R).ne_zero #align polynomial.cyclotomic'_ne_zero Polynomial.cyclotomic'_ne_zero /-- The natural degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem natDegree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).natDegree = Nat.totient n := by rw [cyclotomic'] rw [natDegree_prod (primitiveRoots n R) fun z : R => X - C z] · simp only [IsPrimitiveRoot.card_primitiveRoots h, mul_one, natDegree_X_sub_C, Nat.cast_id, Finset.sum_const, nsmul_eq_mul] intro z _ exact X_sub_C_ne_zero z #align polynomial.nat_degree_cyclotomic' Polynomial.natDegree_cyclotomic' /-- The degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem degree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).degree = Nat.totient n := by simp only [degree_eq_natDegree (cyclotomic'_ne_zero n R), natDegree_cyclotomic' h] #align polynomial.degree_cyclotomic' Polynomial.degree_cyclotomic' /-- The roots of `cyclotomic' n R` are the primitive `n`-th roots of unity. -/ theorem roots_of_cyclotomic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).roots = (primitiveRoots n R).val := by rw [cyclotomic']; exact roots_prod_X_sub_C (primitiveRoots n R) #align polynomial.roots_of_cyclotomic Polynomial.roots_of_cyclotomic /-- If there is a primitive `n`th root of unity in `K`, then `X ^ n - 1 = ∏ (X - μ)`, where `μ` varies over the `n`-th roots of unity. -/ theorem X_pow_sub_one_eq_prod {ζ : R} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : X ^ n - 1 = ∏ ζ ∈ nthRootsFinset n R, (X - C ζ) := by classical rw [nthRootsFinset, ← Multiset.toFinset_eq (IsPrimitiveRoot.nthRoots_one_nodup h)] simp only [Finset.prod_mk, RingHom.map_one] rw [nthRoots] have hmonic : (X ^ n - C (1 : R)).Monic := monic_X_pow_sub_C (1 : R) (ne_of_lt hpos).symm symm apply prod_multiset_X_sub_C_of_monic_of_roots_card_eq hmonic rw [@natDegree_X_pow_sub_C R _ _ n 1, ← nthRoots] exact IsPrimitiveRoot.card_nthRoots_one h set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_eq_prod Polynomial.X_pow_sub_one_eq_prod end IsDomain section Field variable {K : Type*} [Field K] /-- `cyclotomic' n K` splits. -/ theorem cyclotomic'_splits (n : ℕ) : Splits (RingHom.id K) (cyclotomic' n K) := by apply splits_prod (RingHom.id K) intro z _ simp only [splits_X_sub_C (RingHom.id K)] #align polynomial.cyclotomic'_splits Polynomial.cyclotomic'_splits /-- If there is a primitive `n`-th root of unity in `K`, then `X ^ n - 1` splits. -/ theorem X_pow_sub_one_splits {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : Splits (RingHom.id K) (X ^ n - C (1 : K)) := by rw [splits_iff_card_roots, ← nthRoots, IsPrimitiveRoot.card_nthRoots_one h, natDegree_X_pow_sub_C] set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_splits Polynomial.X_pow_sub_one_splits /-- If there is a primitive `n`-th root of unity in `K`, then `∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1`. -/ theorem prod_cyclotomic'_eq_X_pow_sub_one {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : ∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1 := by classical have hd : (n.divisors : Set ℕ).PairwiseDisjoint fun k => primitiveRoots k K := fun x _ y _ hne => IsPrimitiveRoot.disjoint hne simp only [X_pow_sub_one_eq_prod hpos h, cyclotomic', ← Finset.prod_biUnion hd, h.nthRoots_one_eq_biUnion_primitiveRoots] set_option linter.uppercaseLean3 false in #align polynomial.prod_cyclotomic'_eq_X_pow_sub_one Polynomial.prod_cyclotomic'_eq_X_pow_sub_one /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K = (X ^ k - 1) /ₘ (∏ i ∈ Nat.properDivisors k, cyclotomic' i K)`. -/ theorem cyclotomic'_eq_X_pow_sub_one_div {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : cyclotomic' n K = (X ^ n - 1) /ₘ ∏ i ∈ Nat.properDivisors n, cyclotomic' i K := by rw [← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic' i K).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K rw [(div_modByMonic_unique (cyclotomic' n K) 0 prod_monic _).1] simp only [degree_zero, zero_add] refine ⟨by rw [mul_comm], ?_⟩ rw [bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic'_eq_X_pow_sub_one_div Polynomial.cyclotomic'_eq_X_pow_sub_one_div /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K` comes from a monic polynomial with integer coefficients. -/ theorem int_coeff_of_cyclotomic' {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : ∃ P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K ∧ P.degree = (cyclotomic' n K).degree ∧ P.Monic := by refine lifts_and_degree_eq_and_monic ?_ (cyclotomic'.monic n K) induction' n using Nat.strong_induction_on with k ihk generalizing ζ rcases k.eq_zero_or_pos with (rfl | hpos) · use 1 simp only [cyclotomic'_zero, coe_mapRingHom, Polynomial.map_one] let B : K[X] := ∏ i ∈ Nat.properDivisors k, cyclotomic' i K have Bmo : B.Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K have Bint : B ∈ lifts (Int.castRingHom K) := by refine Subsemiring.prod_mem (lifts (Int.castRingHom K)) ?_ intro x hx have xsmall := (Nat.mem_properDivisors.1 hx).2 obtain ⟨d, hd⟩ := (Nat.mem_properDivisors.1 hx).1 rw [mul_comm] at hd exact ihk x xsmall (h.pow hpos hd) replace Bint := lifts_and_degree_eq_and_monic Bint Bmo obtain ⟨B₁, hB₁, _, hB₁mo⟩ := Bint let Q₁ : ℤ[X] := (X ^ k - 1) /ₘ B₁ have huniq : 0 + B * cyclotomic' k K = X ^ k - 1 ∧ (0 : K[X]).degree < B.degree := by constructor · rw [zero_add, mul_comm, ← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] · simpa only [degree_zero, bot_lt_iff_ne_bot, Ne, degree_eq_bot] using Bmo.ne_zero replace huniq := div_modByMonic_unique (cyclotomic' k K) (0 : K[X]) Bmo huniq simp only [lifts, RingHom.mem_rangeS] use Q₁ rw [coe_mapRingHom, map_divByMonic (Int.castRingHom K) hB₁mo, hB₁, ← huniq.1] simp #align polynomial.int_coeff_of_cyclotomic' Polynomial.int_coeff_of_cyclotomic' /-- If `K` is of characteristic `0` and there is a primitive `n`-th root of unity in `K`, then `cyclotomic n K` comes from a unique polynomial with integer coefficients. -/ theorem unique_int_coeff_of_cycl {K : Type*} [CommRing K] [IsDomain K] [CharZero K] {ζ : K} {n : ℕ+} (h : IsPrimitiveRoot ζ n) : ∃! P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K := by obtain ⟨P, hP⟩ := int_coeff_of_cyclotomic' h refine ⟨P, hP.1, fun Q hQ => ?_⟩ apply map_injective (Int.castRingHom K) Int.cast_injective rw [hP.1, hQ] #align polynomial.unique_int_coeff_of_cycl Polynomial.unique_int_coeff_of_cycl end Field end Cyclotomic' section Cyclotomic /-- The `n`-th cyclotomic polynomial with coefficients in `R`. -/ def cyclotomic (n : ℕ) (R : Type*) [Ring R] : R[X] := if h : n = 0 then 1 else map (Int.castRingHom R) (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose #align polynomial.cyclotomic Polynomial.cyclotomic theorem int_cyclotomic_rw {n : ℕ} (h : n ≠ 0) : cyclotomic n ℤ = (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose := by simp only [cyclotomic, h, dif_neg, not_false_iff] ext i simp only [coeff_map, Int.cast_id, eq_intCast] #align polynomial.int_cyclotomic_rw Polynomial.int_cyclotomic_rw /-- `cyclotomic n R` comes from `cyclotomic n ℤ`. -/ theorem map_cyclotomic_int (n : ℕ) (R : Type*) [Ring R] : map (Int.castRingHom R) (cyclotomic n ℤ) = cyclotomic n R := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, dif_pos, Polynomial.map_one] simp [cyclotomic, hzero] #align polynomial.map_cyclotomic_int Polynomial.map_cyclotomic_int theorem int_cyclotomic_spec (n : ℕ) : map (Int.castRingHom ℂ) (cyclotomic n ℤ) = cyclotomic' n ℂ ∧ (cyclotomic n ℤ).degree = (cyclotomic' n ℂ).degree ∧ (cyclotomic n ℤ).Monic := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, degree_one, monic_one, cyclotomic'_zero, dif_pos, eq_self_iff_true, Polynomial.map_one, and_self_iff] rw [int_cyclotomic_rw hzero] exact (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n hzero)).choose_spec #align polynomial.int_cyclotomic_spec Polynomial.int_cyclotomic_spec theorem int_cyclotomic_unique {n : ℕ} {P : ℤ[X]} (h : map (Int.castRingHom ℂ) P = cyclotomic' n ℂ) : P = cyclotomic n ℤ := by apply map_injective (Int.castRingHom ℂ) Int.cast_injective rw [h, (int_cyclotomic_spec n).1] #align polynomial.int_cyclotomic_unique Polynomial.int_cyclotomic_unique /-- The definition of `cyclotomic n R` commutes with any ring homomorphism. -/ @[simp] theorem map_cyclotomic (n : ℕ) {R S : Type*} [Ring R] [Ring S] (f : R →+* S) : map f (cyclotomic n R) = cyclotomic n S := by rw [← map_cyclotomic_int n R, ← map_cyclotomic_int n S, map_map] have : Subsingleton (ℤ →+* S) := inferInstance congr! #align polynomial.map_cyclotomic Polynomial.map_cyclotomic theorem cyclotomic.eval_apply {R S : Type*} (q : R) (n : ℕ) [Ring R] [Ring S] (f : R →+* S) : eval (f q) (cyclotomic n S) = f (eval q (cyclotomic n R)) := by rw [← map_cyclotomic n f, eval_map, eval₂_at_apply] #align polynomial.cyclotomic.eval_apply Polynomial.cyclotomic.eval_apply /-- The zeroth cyclotomic polyomial is `1`. -/ @[simp] theorem cyclotomic_zero (R : Type*) [Ring R] : cyclotomic 0 R = 1 := by simp only [cyclotomic, dif_pos] #align polynomial.cyclotomic_zero Polynomial.cyclotomic_zero /-- The first cyclotomic polyomial is `X - 1`. -/ @[simp] theorem cyclotomic_one (R : Type*) [Ring R] : cyclotomic 1 R = X - 1 := by have hspec : map (Int.castRingHom ℂ) (X - 1) = cyclotomic' 1 ℂ := by simp only [cyclotomic'_one, PNat.one_coe, map_X, Polynomial.map_one, Polynomial.map_sub] symm rw [← map_cyclotomic_int, ← int_cyclotomic_unique hspec] simp only [map_X, Polynomial.map_one, Polynomial.map_sub] #align polynomial.cyclotomic_one Polynomial.cyclotomic_one /-- `cyclotomic n` is monic. -/ theorem cyclotomic.monic (n : ℕ) (R : Type*) [Ring R] : (cyclotomic n R).Monic := by rw [← map_cyclotomic_int] exact (int_cyclotomic_spec n).2.2.map _ #align polynomial.cyclotomic.monic Polynomial.cyclotomic.monic /-- `cyclotomic n` is primitive. -/ theorem cyclotomic.isPrimitive (n : ℕ) (R : Type*) [CommRing R] : (cyclotomic n R).IsPrimitive := (cyclotomic.monic n R).isPrimitive #align polynomial.cyclotomic.is_primitive Polynomial.cyclotomic.isPrimitive /-- `cyclotomic n R` is different from `0`. -/ theorem cyclotomic_ne_zero (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : cyclotomic n R ≠ 0 := (cyclotomic.monic n R).ne_zero #align polynomial.cyclotomic_ne_zero Polynomial.cyclotomic_ne_zero /-- The degree of `cyclotomic n` is `totient n`. -/ theorem degree_cyclotomic (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : (cyclotomic n R).degree = Nat.totient n := by rw [← map_cyclotomic_int] rw [degree_map_eq_of_leadingCoeff_ne_zero (Int.castRingHom R) _] · cases' n with k · simp only [cyclotomic, degree_one, dif_pos, Nat.totient_zero, CharP.cast_eq_zero] rw [← degree_cyclotomic' (Complex.isPrimitiveRoot_exp k.succ (Nat.succ_ne_zero k))] exact (int_cyclotomic_spec k.succ).2.1 simp only [(int_cyclotomic_spec n).right.right, eq_intCast, Monic.leadingCoeff, Int.cast_one, Ne, not_false_iff, one_ne_zero] #align polynomial.degree_cyclotomic Polynomial.degree_cyclotomic /-- The natural degree of `cyclotomic n` is `totient n`. -/ theorem natDegree_cyclotomic (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : (cyclotomic n R).natDegree = Nat.totient n := by rw [natDegree, degree_cyclotomic]; norm_cast #align polynomial.nat_degree_cyclotomic Polynomial.natDegree_cyclotomic /-- The degree of `cyclotomic n R` is positive. -/ theorem degree_cyclotomic_pos (n : ℕ) (R : Type*) (hpos : 0 < n) [Ring R] [Nontrivial R] : 0 < (cyclotomic n R).degree := by rwa [degree_cyclotomic n R, Nat.cast_pos, Nat.totient_pos] #align polynomial.degree_cyclotomic_pos Polynomial.degree_cyclotomic_pos open Finset /-- `∏ i ∈ Nat.divisors n, cyclotomic i R = X ^ n - 1`. -/ theorem prod_cyclotomic_eq_X_pow_sub_one {n : ℕ} (hpos : 0 < n) (R : Type*) [CommRing R] : ∏ i ∈ Nat.divisors n, cyclotomic i R = X ^ n - 1 := by have integer : ∏ i ∈ Nat.divisors n, cyclotomic i ℤ = X ^ n - 1 := by apply map_injective (Int.castRingHom ℂ) Int.cast_injective simp only [Polynomial.map_prod, int_cyclotomic_spec, Polynomial.map_pow, map_X, Polynomial.map_one, Polynomial.map_sub] exact prod_cyclotomic'_eq_X_pow_sub_one hpos (Complex.isPrimitiveRoot_exp n hpos.ne') simpa only [Polynomial.map_prod, map_cyclotomic_int, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) integer set_option linter.uppercaseLean3 false in #align polynomial.prod_cyclotomic_eq_X_pow_sub_one Polynomial.prod_cyclotomic_eq_X_pow_sub_one theorem cyclotomic.dvd_X_pow_sub_one (n : ℕ) (R : Type*) [Ring R] : cyclotomic n R ∣ X ^ n - 1 := by suffices cyclotomic n ℤ ∣ X ^ n - 1 by simpa only [map_cyclotomic_int, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow, Polynomial.map_X] using map_dvd (Int.castRingHom R) this rcases n.eq_zero_or_pos with (rfl | hn) · simp rw [← prod_cyclotomic_eq_X_pow_sub_one hn] exact Finset.dvd_prod_of_mem _ (n.mem_divisors_self hn.ne') set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic.dvd_X_pow_sub_one Polynomial.cyclotomic.dvd_X_pow_sub_one theorem prod_cyclotomic_eq_geom_sum {n : ℕ} (h : 0 < n) (R) [CommRing R] : ∏ i ∈ n.divisors.erase 1, cyclotomic i R = ∑ i ∈ Finset.range n, X ^ i := by suffices (∏ i ∈ n.divisors.erase 1, cyclotomic i ℤ) = ∑ i ∈ Finset.range n, X ^ i by simpa only [Polynomial.map_prod, map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) this rw [← mul_left_inj' (cyclotomic_ne_zero 1 ℤ), prod_erase_mul _ _ (Nat.one_mem_divisors.2 h.ne'), cyclotomic_one, geom_sum_mul, prod_cyclotomic_eq_X_pow_sub_one h] #align polynomial.prod_cyclotomic_eq_geom_sum Polynomial.prod_cyclotomic_eq_geom_sum /-- If `p` is prime, then `cyclotomic p R = ∑ i ∈ range p, X ^ i`. -/ theorem cyclotomic_prime (R : Type*) [Ring R] (p : ℕ) [hp : Fact p.Prime] : cyclotomic p R = ∑ i ∈ Finset.range p, X ^ i := by suffices cyclotomic p ℤ = ∑ i ∈ range p, X ^ i by simpa only [map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) this rw [← prod_cyclotomic_eq_geom_sum hp.out.pos, hp.out.divisors, erase_insert (mem_singleton.not.2 hp.out.ne_one.symm), prod_singleton] #align polynomial.cyclotomic_prime Polynomial.cyclotomic_prime theorem cyclotomic_prime_mul_X_sub_one (R : Type*) [Ring R] (p : ℕ) [hn : Fact (Nat.Prime p)] : cyclotomic p R * (X - 1) = X ^ p - 1 := by rw [cyclotomic_prime, geom_sum_mul] set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic_prime_mul_X_sub_one Polynomial.cyclotomic_prime_mul_X_sub_one @[simp] theorem cyclotomic_two (R : Type*) [Ring R] : cyclotomic 2 R = X + 1 := by simp [cyclotomic_prime] #align polynomial.cyclotomic_two Polynomial.cyclotomic_two @[simp] theorem cyclotomic_three (R : Type*) [Ring R] : cyclotomic 3 R = X ^ 2 + X + 1 := by simp [cyclotomic_prime, sum_range_succ'] #align polynomial.cyclotomic_three Polynomial.cyclotomic_three theorem cyclotomic_dvd_geom_sum_of_dvd (R) [Ring R] {d n : ℕ} (hdn : d ∣ n) (hd : d ≠ 1) : cyclotomic d R ∣ ∑ i ∈ Finset.range n, X ^ i := by suffices cyclotomic d ℤ ∣ ∑ i ∈ Finset.range n, X ^ i by simpa only [map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using map_dvd (Int.castRingHom R) this rcases n.eq_zero_or_pos with (rfl | hn) · simp rw [← prod_cyclotomic_eq_geom_sum hn] apply Finset.dvd_prod_of_mem simp [hd, hdn, hn.ne'] #align polynomial.cyclotomic_dvd_geom_sum_of_dvd Polynomial.cyclotomic_dvd_geom_sum_of_dvd theorem X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd (R) [CommRing R] {d n : ℕ} (h : d ∈ n.properDivisors) : ((X ^ d - 1) * ∏ x ∈ n.divisors \ d.divisors, cyclotomic x R) = X ^ n - 1 := by obtain ⟨hd, hdn⟩ := Nat.mem_properDivisors.mp h have h0n : 0 < n := pos_of_gt hdn have h0d : 0 < d := Nat.pos_of_dvd_of_pos hd h0n rw [← prod_cyclotomic_eq_X_pow_sub_one h0d, ← prod_cyclotomic_eq_X_pow_sub_one h0n, mul_comm, Finset.prod_sdiff (Nat.divisors_subset_of_dvd h0n.ne' hd)] set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd Polynomial.X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd theorem X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd (R) [CommRing R] {d n : ℕ} (h : d ∈ n.properDivisors) : (X ^ d - 1) * cyclotomic n R ∣ X ^ n - 1 := by have hdn := (Nat.mem_properDivisors.mp h).2 use ∏ x ∈ n.properDivisors \ d.divisors, cyclotomic x R symm convert X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd R h using 1 rw [mul_assoc] congr 1 rw [← Nat.insert_self_properDivisors hdn.ne_bot, insert_sdiff_of_not_mem, prod_insert] · exact Finset.not_mem_sdiff_of_not_mem_left Nat.properDivisors.not_self_mem · exact fun hk => hdn.not_le <| Nat.divisor_le hk set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd Polynomial.X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd section ArithmeticFunction open ArithmeticFunction open scoped ArithmeticFunction /-- `cyclotomic n R` can be expressed as a product in a fraction field of `R[X]` using Möbius inversion. -/ theorem cyclotomic_eq_prod_X_pow_sub_one_pow_moebius {n : ℕ} (R : Type*) [CommRing R] [IsDomain R] : algebraMap _ (RatFunc R) (cyclotomic n R) = ∏ i ∈ n.divisorsAntidiagonal, algebraMap R[X] _ (X ^ i.snd - 1) ^ μ i.fst := by rcases n.eq_zero_or_pos with (rfl | hpos) · simp have h : ∀ n : ℕ, 0 < n → (∏ i ∈ Nat.divisors n, algebraMap _ (RatFunc R) (cyclotomic i R)) = algebraMap _ _ (X ^ n - 1 : R[X]) := by intro n hn rw [← prod_cyclotomic_eq_X_pow_sub_one hn R, map_prod] rw [(prod_eq_iff_prod_pow_moebius_eq_of_nonzero (fun n hn => _) fun n hn => _).1 h n hpos] <;> simp_rw [Ne, IsFractionRing.to_map_eq_zero_iff] · simp [cyclotomic_ne_zero] · intro n hn apply Monic.ne_zero apply monic_X_pow_sub_C _ (ne_of_gt hn) set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius Polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius end ArithmeticFunction /-- We have `cyclotomic n R = (X ^ k - 1) /ₘ (∏ i ∈ Nat.properDivisors k, cyclotomic i K)`. -/ theorem cyclotomic_eq_X_pow_sub_one_div {R : Type*} [CommRing R] {n : ℕ} (hpos : 0 < n) : cyclotomic n R = (X ^ n - 1) /ₘ ∏ i ∈ Nat.properDivisors n, cyclotomic i R := by nontriviality R rw [← prod_cyclotomic_eq_X_pow_sub_one hpos, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic i R).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic.monic i R rw [(div_modByMonic_unique (cyclotomic n R) 0 prod_monic _).1] simp only [degree_zero, zero_add] constructor · rw [mul_comm] rw [bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic_eq_X_pow_sub_one_div Polynomial.cyclotomic_eq_X_pow_sub_one_div /-- If `m` is a proper divisor of `n`, then `X ^ m - 1` divides `∏ i ∈ Nat.properDivisors n, cyclotomic i R`. -/ theorem X_pow_sub_one_dvd_prod_cyclotomic (R : Type*) [CommRing R] {n m : ℕ} (hpos : 0 < n) (hm : m ∣ n) (hdiff : m ≠ n) : X ^ m - 1 ∣ ∏ i ∈ Nat.properDivisors n, cyclotomic i R := by replace hm := Nat.mem_properDivisors.2 ⟨hm, lt_of_le_of_ne (Nat.divisor_le (Nat.mem_divisors.2 ⟨hm, hpos.ne'⟩)) hdiff⟩ rw [← Finset.sdiff_union_of_subset (Nat.divisors_subset_properDivisors (ne_of_lt hpos).symm (Nat.mem_properDivisors.1 hm).1 (ne_of_lt (Nat.mem_properDivisors.1 hm).2)), Finset.prod_union Finset.sdiff_disjoint, prod_cyclotomic_eq_X_pow_sub_one (Nat.pos_of_mem_properDivisors hm)] exact ⟨∏ x ∈ n.properDivisors \ m.divisors, cyclotomic x R, by rw [mul_comm]⟩ set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_dvd_prod_cyclotomic Polynomial.X_pow_sub_one_dvd_prod_cyclotomic /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic n K = ∏ μ ∈ primitiveRoots n K, (X - C μ)`. ∈ particular, `cyclotomic n K = cyclotomic' n K` -/
Mathlib/RingTheory/Polynomial/Cyclotomic/Basic.lean
523
535
theorem cyclotomic_eq_prod_X_sub_primitiveRoots {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hz : IsPrimitiveRoot ζ n) : cyclotomic n K = ∏ μ ∈ primitiveRoots n K, (X - C μ) := by
rw [← cyclotomic'] induction' n using Nat.strong_induction_on with k hk generalizing ζ obtain hzero | hpos := k.eq_zero_or_pos · simp only [hzero, cyclotomic'_zero, cyclotomic_zero] have h : ∀ i ∈ k.properDivisors, cyclotomic i K = cyclotomic' i K := by intro i hi obtain ⟨d, hd⟩ := (Nat.mem_properDivisors.1 hi).1 rw [mul_comm] at hd exact hk i (Nat.mem_properDivisors.1 hi).2 (IsPrimitiveRoot.pow hpos hz hd) rw [@cyclotomic_eq_X_pow_sub_one_div _ _ _ hpos, cyclotomic'_eq_X_pow_sub_one_div hpos hz, Finset.prod_congr (refl k.properDivisors) h]
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.GroupTheory.Perm.Cycle.Type import Mathlib.GroupTheory.Perm.Option import Mathlib.Logic.Equiv.Fin import Mathlib.Logic.Equiv.Fintype #align_import group_theory.perm.fin from "leanprover-community/mathlib"@"7e1c1263b6a25eb90bf16e80d8f47a657e403c4c" /-! # Permutations of `Fin n` -/ open Equiv /-- Permutations of `Fin (n + 1)` are equivalent to fixing a single `Fin (n + 1)` and permuting the remaining with a `Perm (Fin n)`. The fixed `Fin (n + 1)` is swapped with `0`. -/ def Equiv.Perm.decomposeFin {n : ℕ} : Perm (Fin n.succ) ≃ Fin n.succ × Perm (Fin n) := ((Equiv.permCongr <| finSuccEquiv n).trans Equiv.Perm.decomposeOption).trans (Equiv.prodCongr (finSuccEquiv n).symm (Equiv.refl _)) #align equiv.perm.decompose_fin Equiv.Perm.decomposeFin @[simp] theorem Equiv.Perm.decomposeFin_symm_of_refl {n : ℕ} (p : Fin (n + 1)) : Equiv.Perm.decomposeFin.symm (p, Equiv.refl _) = swap 0 p := by simp [Equiv.Perm.decomposeFin, Equiv.permCongr_def] #align equiv.perm.decompose_fin_symm_of_refl Equiv.Perm.decomposeFin_symm_of_refl @[simp] theorem Equiv.Perm.decomposeFin_symm_of_one {n : ℕ} (p : Fin (n + 1)) : Equiv.Perm.decomposeFin.symm (p, 1) = swap 0 p := Equiv.Perm.decomposeFin_symm_of_refl p #align equiv.perm.decompose_fin_symm_of_one Equiv.Perm.decomposeFin_symm_of_one #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. See https://github.com/leanprover-community/mathlib4/issues/12232 -/ @[simp, nolint simpNF] theorem Equiv.Perm.decomposeFin_symm_apply_zero {n : ℕ} (p : Fin (n + 1)) (e : Perm (Fin n)) : Equiv.Perm.decomposeFin.symm (p, e) 0 = p := by simp [Equiv.Perm.decomposeFin] #align equiv.perm.decompose_fin_symm_apply_zero Equiv.Perm.decomposeFin_symm_apply_zero @[simp] theorem Equiv.Perm.decomposeFin_symm_apply_succ {n : ℕ} (e : Perm (Fin n)) (p : Fin (n + 1)) (x : Fin n) : Equiv.Perm.decomposeFin.symm (p, e) x.succ = swap 0 p (e x).succ := by refine Fin.cases ?_ ?_ p · simp [Equiv.Perm.decomposeFin, EquivFunctor.map] · intro i by_cases h : i = e x · simp [h, Equiv.Perm.decomposeFin, EquivFunctor.map] · simp [h, Fin.succ_ne_zero, Equiv.Perm.decomposeFin, EquivFunctor.map, swap_apply_def, Ne.symm h] #align equiv.perm.decompose_fin_symm_apply_succ Equiv.Perm.decomposeFin_symm_apply_succ #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. See https://github.com/leanprover-community/mathlib4/issues/12232 -/ @[simp, nolint simpNF] theorem Equiv.Perm.decomposeFin_symm_apply_one {n : ℕ} (e : Perm (Fin (n + 1))) (p : Fin (n + 2)) : Equiv.Perm.decomposeFin.symm (p, e) 1 = swap 0 p (e 0).succ := by rw [← Fin.succ_zero_eq_one, Equiv.Perm.decomposeFin_symm_apply_succ e p 0] #align equiv.perm.decompose_fin_symm_apply_one Equiv.Perm.decomposeFin_symm_apply_one @[simp] theorem Equiv.Perm.decomposeFin.symm_sign {n : ℕ} (p : Fin (n + 1)) (e : Perm (Fin n)) : Perm.sign (Equiv.Perm.decomposeFin.symm (p, e)) = ite (p = 0) 1 (-1) * Perm.sign e := by refine Fin.cases ?_ ?_ p <;> simp [Equiv.Perm.decomposeFin, Fin.succ_ne_zero] #align equiv.perm.decompose_fin.symm_sign Equiv.Perm.decomposeFin.symm_sign /-- The set of all permutations of `Fin (n + 1)` can be constructed by augmenting the set of permutations of `Fin n` by each element of `Fin (n + 1)` in turn. -/ theorem Finset.univ_perm_fin_succ {n : ℕ} : @Finset.univ (Perm <| Fin n.succ) _ = (Finset.univ : Finset <| Fin n.succ × Perm (Fin n)).map Equiv.Perm.decomposeFin.symm.toEmbedding := (Finset.univ_map_equiv_to_embedding _).symm #align finset.univ_perm_fin_succ Finset.univ_perm_fin_succ section CycleRange /-! ### `cycleRange` section Define the permutations `Fin.cycleRange i`, the cycle `(0 1 2 ... i)`. -/ open Equiv.Perm -- Porting note: renamed from finRotate_succ because there is already a theorem with that name theorem finRotate_succ_eq_decomposeFin {n : ℕ} : finRotate n.succ = decomposeFin.symm (1, finRotate n) := by ext i cases n; · simp refine Fin.cases ?_ (fun i => ?_) i · simp rw [coe_finRotate, decomposeFin_symm_apply_succ, if_congr i.succ_eq_last_succ rfl rfl] split_ifs with h · simp [h] · rw [Fin.val_succ, Function.Injective.map_swap Fin.val_injective, Fin.val_succ, coe_finRotate, if_neg h, Fin.val_zero, Fin.val_one, swap_apply_of_ne_of_ne (Nat.succ_ne_zero _) (Nat.succ_succ_ne_one _)] #align fin_rotate_succ finRotate_succ_eq_decomposeFin @[simp] theorem sign_finRotate (n : ℕ) : Perm.sign (finRotate (n + 1)) = (-1) ^ n := by induction' n with n ih · simp · rw [finRotate_succ_eq_decomposeFin] simp [ih, pow_succ] #align sign_fin_rotate sign_finRotate @[simp] theorem support_finRotate {n : ℕ} : support (finRotate (n + 2)) = Finset.univ := by ext simp #align support_fin_rotate support_finRotate theorem support_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : support (finRotate n) = Finset.univ := by obtain ⟨m, rfl⟩ := exists_add_of_le h rw [add_comm, support_finRotate] #align support_fin_rotate_of_le support_finRotate_of_le theorem isCycle_finRotate {n : ℕ} : IsCycle (finRotate (n + 2)) := by refine ⟨0, by simp, fun x hx' => ⟨x, ?_⟩⟩ clear hx' cases' x with x hx rw [zpow_natCast, Fin.ext_iff, Fin.val_mk] induction' x with x ih; · rfl rw [pow_succ', Perm.mul_apply, coe_finRotate_of_ne_last, ih (lt_trans x.lt_succ_self hx)] rw [Ne, Fin.ext_iff, ih (lt_trans x.lt_succ_self hx), Fin.val_last] exact ne_of_lt (Nat.lt_of_succ_lt_succ hx) #align is_cycle_fin_rotate isCycle_finRotate theorem isCycle_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : IsCycle (finRotate n) := by obtain ⟨m, rfl⟩ := exists_add_of_le h rw [add_comm] exact isCycle_finRotate #align is_cycle_fin_rotate_of_le isCycle_finRotate_of_le @[simp] theorem cycleType_finRotate {n : ℕ} : cycleType (finRotate (n + 2)) = {n + 2} := by rw [isCycle_finRotate.cycleType, support_finRotate, ← Fintype.card, Fintype.card_fin] rfl #align cycle_type_fin_rotate cycleType_finRotate theorem cycleType_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : cycleType (finRotate n) = {n} := by obtain ⟨m, rfl⟩ := exists_add_of_le h rw [add_comm, cycleType_finRotate] #align cycle_type_fin_rotate_of_le cycleType_finRotate_of_le namespace Fin /-- `Fin.cycleRange i` is the cycle `(0 1 2 ... i)` leaving `(i+1 ... (n-1))` unchanged. -/ def cycleRange {n : ℕ} (i : Fin n) : Perm (Fin n) := (finRotate (i + 1)).extendDomain (Equiv.ofLeftInverse' (Fin.castLEEmb (Nat.succ_le_of_lt i.is_lt)) (↑) (by intro x ext simp)) #align fin.cycle_range Fin.cycleRange theorem cycleRange_of_gt {n : ℕ} {i j : Fin n.succ} (h : i < j) : cycleRange i j = j := by rw [cycleRange, ofLeftInverse'_eq_ofInjective, ← Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding, viaFintypeEmbedding_apply_not_mem_range] simpa #align fin.cycle_range_of_gt Fin.cycleRange_of_gt
Mathlib/GroupTheory/Perm/Fin.lean
175
190
theorem cycleRange_of_le {n : ℕ} {i j : Fin n.succ} (h : j ≤ i) : cycleRange i j = if j = i then 0 else j + 1 := by
cases n · exact Subsingleton.elim (α := Fin 1) _ _ --Porting note; was `simp` have : j = (Fin.castLE (Nat.succ_le_of_lt i.is_lt)) ⟨j, lt_of_le_of_lt h (Nat.lt_succ_self i)⟩ := by simp ext erw [this, cycleRange, ofLeftInverse'_eq_ofInjective, ← Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding, viaFintypeEmbedding_apply_image, Function.Embedding.coeFn_mk, coe_castLE, coe_finRotate] simp only [Fin.ext_iff, val_last, val_mk, val_zero, Fin.eta, castLE_mk] split_ifs with heq · rfl · rw [Fin.val_add_one_of_lt] exact lt_of_lt_of_le (lt_of_le_of_ne h (mt (congr_arg _) heq)) (le_last i)
/- Copyright (c) 2020 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import Mathlib.Analysis.NormedSpace.IndicatorFunction import Mathlib.MeasureTheory.Function.EssSup import Mathlib.MeasureTheory.Function.AEEqFun import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic #align_import measure_theory.function.lp_seminorm from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9" /-! # ℒp space This file describes properties of almost everywhere strongly measurable functions with finite `p`-seminorm, denoted by `snorm f p μ` and defined for `p:ℝ≥0∞` as `0` if `p=0`, `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `0 < p < ∞` and `essSup ‖f‖ μ` for `p=∞`. The Prop-valued `Memℒp f p μ` states that a function `f : α → E` has finite `p`-seminorm and is almost everywhere strongly measurable. ## Main definitions * `snorm' f p μ` : `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `f : α → F` and `p : ℝ`, where `α` is a measurable space and `F` is a normed group. * `snormEssSup f μ` : seminorm in `ℒ∞`, equal to the essential supremum `ess_sup ‖f‖ μ`. * `snorm f p μ` : for `p : ℝ≥0∞`, seminorm in `ℒp`, equal to `0` for `p=0`, to `snorm' f p μ` for `0 < p < ∞` and to `snormEssSup f μ` for `p = ∞`. * `Memℒp f p μ` : property that the function `f` is almost everywhere strongly measurable and has finite `p`-seminorm for the measure `μ` (`snorm f p μ < ∞`) -/ noncomputable section set_option linter.uppercaseLean3 false open TopologicalSpace MeasureTheory Filter open scoped NNReal ENNReal Topology variable {α E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] namespace MeasureTheory section ℒp /-! ### ℒp seminorm We define the ℒp seminorm, denoted by `snorm f p μ`. For real `p`, it is given by an integral formula (for which we use the notation `snorm' f p μ`), and for `p = ∞` it is the essential supremum (for which we use the notation `snormEssSup f μ`). We also define a predicate `Memℒp f p μ`, requesting that a function is almost everywhere measurable and has finite `snorm f p μ`. This paragraph is devoted to the basic properties of these definitions. It is constructed as follows: for a given property, we prove it for `snorm'` and `snormEssSup` when it makes sense, deduce it for `snorm`, and translate it in terms of `Memℒp`. -/ section ℒpSpaceDefinition /-- `(∫ ‖f a‖^q ∂μ) ^ (1/q)`, which is a seminorm on the space of measurable functions for which this quantity is finite -/ def snorm' {_ : MeasurableSpace α} (f : α → F) (q : ℝ) (μ : Measure α) : ℝ≥0∞ := (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) #align measure_theory.snorm' MeasureTheory.snorm' /-- seminorm for `ℒ∞`, equal to the essential supremum of `‖f‖`. -/ def snormEssSup {_ : MeasurableSpace α} (f : α → F) (μ : Measure α) := essSup (fun x => (‖f x‖₊ : ℝ≥0∞)) μ #align measure_theory.snorm_ess_sup MeasureTheory.snormEssSup /-- `ℒp` seminorm, equal to `0` for `p=0`, to `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `0 < p < ∞` and to `essSup ‖f‖ μ` for `p = ∞`. -/ def snorm {_ : MeasurableSpace α} (f : α → F) (p : ℝ≥0∞) (μ : Measure α) : ℝ≥0∞ := if p = 0 then 0 else if p = ∞ then snormEssSup f μ else snorm' f (ENNReal.toReal p) μ #align measure_theory.snorm MeasureTheory.snorm theorem snorm_eq_snorm' (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} : snorm f p μ = snorm' f (ENNReal.toReal p) μ := by simp [snorm, hp_ne_zero, hp_ne_top] #align measure_theory.snorm_eq_snorm' MeasureTheory.snorm_eq_snorm' theorem snorm_eq_lintegral_rpow_nnnorm (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} : snorm f p μ = (∫⁻ x, (‖f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) ^ (1 / p.toReal) := by rw [snorm_eq_snorm' hp_ne_zero hp_ne_top, snorm'] #align measure_theory.snorm_eq_lintegral_rpow_nnnorm MeasureTheory.snorm_eq_lintegral_rpow_nnnorm theorem snorm_one_eq_lintegral_nnnorm {f : α → F} : snorm f 1 μ = ∫⁻ x, ‖f x‖₊ ∂μ := by simp_rw [snorm_eq_lintegral_rpow_nnnorm one_ne_zero ENNReal.coe_ne_top, ENNReal.one_toReal, one_div_one, ENNReal.rpow_one] #align measure_theory.snorm_one_eq_lintegral_nnnorm MeasureTheory.snorm_one_eq_lintegral_nnnorm @[simp] theorem snorm_exponent_top {f : α → F} : snorm f ∞ μ = snormEssSup f μ := by simp [snorm] #align measure_theory.snorm_exponent_top MeasureTheory.snorm_exponent_top /-- The property that `f:α→E` is ae strongly measurable and `(∫ ‖f a‖^p ∂μ)^(1/p)` is finite if `p < ∞`, or `essSup f < ∞` if `p = ∞`. -/ def Memℒp {α} {_ : MeasurableSpace α} (f : α → E) (p : ℝ≥0∞) (μ : Measure α := by volume_tac) : Prop := AEStronglyMeasurable f μ ∧ snorm f p μ < ∞ #align measure_theory.mem_ℒp MeasureTheory.Memℒp theorem Memℒp.aestronglyMeasurable {f : α → E} {p : ℝ≥0∞} (h : Memℒp f p μ) : AEStronglyMeasurable f μ := h.1 #align measure_theory.mem_ℒp.ae_strongly_measurable MeasureTheory.Memℒp.aestronglyMeasurable theorem lintegral_rpow_nnnorm_eq_rpow_snorm' {f : α → F} (hq0_lt : 0 < q) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) = snorm' f q μ ^ q := by rw [snorm', ← ENNReal.rpow_mul, one_div, inv_mul_cancel, ENNReal.rpow_one] exact (ne_of_lt hq0_lt).symm #align measure_theory.lintegral_rpow_nnnorm_eq_rpow_snorm' MeasureTheory.lintegral_rpow_nnnorm_eq_rpow_snorm' end ℒpSpaceDefinition section Top theorem Memℒp.snorm_lt_top {f : α → E} (hfp : Memℒp f p μ) : snorm f p μ < ∞ := hfp.2 #align measure_theory.mem_ℒp.snorm_lt_top MeasureTheory.Memℒp.snorm_lt_top theorem Memℒp.snorm_ne_top {f : α → E} (hfp : Memℒp f p μ) : snorm f p μ ≠ ∞ := ne_of_lt hfp.2 #align measure_theory.mem_ℒp.snorm_ne_top MeasureTheory.Memℒp.snorm_ne_top theorem lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top {f : α → F} (hq0_lt : 0 < q) (hfq : snorm' f q μ < ∞) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) < ∞ := by rw [lintegral_rpow_nnnorm_eq_rpow_snorm' hq0_lt] exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq) #align measure_theory.lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top MeasureTheory.lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top
Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean
141
145
theorem lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) (hfp : snorm f p μ < ∞) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) < ∞ := by
apply lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top · exact ENNReal.toReal_pos hp_ne_zero hp_ne_top · simpa [snorm_eq_snorm' hp_ne_zero hp_ne_top] using hfp
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Reid Barton -/ import Mathlib.Data.TypeMax import Mathlib.Logic.UnivLE import Mathlib.CategoryTheory.Limits.Shapes.Images #align_import category_theory.limits.types from "leanprover-community/mathlib"@"4aa2a2e17940311e47007f087c9df229e7f12942" /-! # Limits in the category of types. We show that the category of types has all (co)limits, by providing the usual concrete models. Next, we prove the category of types has categorical images, and that these agree with the range of a function. Finally, we give the natural isomorphism between cones on `F` with cone point `X` and the type `lim Hom(X, F·)`, and similarly the natural isomorphism between cocones on `F` with cocone point `X` and the type `lim Hom(F·, X)`. -/ open CategoryTheory CategoryTheory.Limits universe v u w namespace CategoryTheory.Limits namespace Types section limit_characterization variable {J : Type v} [Category.{w} J] {F : J ⥤ Type u} /-- Given a section of a functor F into `Type*`, construct a cone over F with `PUnit` as the cone point. -/ def coneOfSection {s} (hs : s ∈ F.sections) : Cone F where pt := PUnit π := { app := fun j _ ↦ s j, naturality := fun i j f ↦ by ext; exact (hs f).symm } /-- Given a cone over a functor F into `Type*` and an element in the cone point, construct a section of F. -/ def sectionOfCone (c : Cone F) (x : c.pt) : F.sections := ⟨fun j ↦ c.π.app j x, fun f ↦ congr_fun (c.π.naturality f).symm x⟩ theorem isLimit_iff (c : Cone F) : Nonempty (IsLimit c) ↔ ∀ s ∈ F.sections, ∃! x : c.pt, ∀ j, c.π.app j x = s j := by refine ⟨fun ⟨t⟩ s hs ↦ ?_, fun h ↦ ⟨?_⟩⟩ · let cs := coneOfSection hs exact ⟨t.lift cs ⟨⟩, fun j ↦ congr_fun (t.fac cs j) ⟨⟩, fun x hx ↦ congr_fun (t.uniq cs (fun _ ↦ x) fun j ↦ funext fun _ ↦ hx j) ⟨⟩⟩ · choose x hx using fun c y ↦ h _ (sectionOfCone c y).2 exact ⟨x, fun c j ↦ funext fun y ↦ (hx c y).1 j, fun c f hf ↦ funext fun y ↦ (hx c y).2 (f y) (fun j ↦ congr_fun (hf j) y)⟩ theorem isLimit_iff_bijective_sectionOfCone (c : Cone F) : Nonempty (IsLimit c) ↔ (Types.sectionOfCone c).Bijective := by simp_rw [isLimit_iff, Function.bijective_iff_existsUnique, Subtype.forall, F.sections_ext_iff, sectionOfCone] /-- The equivalence between a limiting cone of `F` in `Type u` and the "concrete" definition as the sections of `F`. -/ noncomputable def isLimitEquivSections {c : Cone F} (t : IsLimit c) : c.pt ≃ F.sections where toFun := sectionOfCone c invFun s := t.lift (coneOfSection s.2) ⟨⟩ left_inv x := (congr_fun (t.uniq (coneOfSection _) (fun _ ↦ x) fun _ ↦ rfl) ⟨⟩).symm right_inv s := Subtype.ext (funext fun j ↦ congr_fun (t.fac (coneOfSection s.2) j) ⟨⟩) #align category_theory.limits.types.is_limit_equiv_sections CategoryTheory.Limits.Types.isLimitEquivSections @[simp] theorem isLimitEquivSections_apply {c : Cone F} (t : IsLimit c) (j : J) (x : c.pt) : (isLimitEquivSections t x : ∀ j, F.obj j) j = c.π.app j x := rfl #align category_theory.limits.types.is_limit_equiv_sections_apply CategoryTheory.Limits.Types.isLimitEquivSections_apply @[simp] theorem isLimitEquivSections_symm_apply {c : Cone F} (t : IsLimit c) (x : F.sections) (j : J) : c.π.app j ((isLimitEquivSections t).symm x) = (x : ∀ j, F.obj j) j := by conv_rhs => rw [← (isLimitEquivSections t).right_inv x] rfl #align category_theory.limits.types.is_limit_equiv_sections_symm_apply CategoryTheory.Limits.Types.isLimitEquivSections_symm_apply end limit_characterization variable {J : Type v} [Category.{w} J] /-! We now provide two distinct implementations in the category of types. The first, in the `CategoryTheory.Limits.Types.Small` namespace, assumes `Small.{u} J` and constructs `J`-indexed limits in `Type u`. The second, in the `CategoryTheory.Limits.Types.TypeMax` namespace constructs limits for functors `F : J ⥤ TypeMax.{v, u}`, for `J : Type v`. This construction is slightly nicer, as the limit is definitionally just `F.sections`, rather than `Shrink F.sections`, which makes an arbitrary choice of `u`-small representative. Hopefully we might be able to entirely remove the `TypeMax` constructions, but for now they are useful glue for the later parts of the library. -/ namespace Small variable (F : J ⥤ Type u) section variable [Small.{u} F.sections] /-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/ @[simps] noncomputable def limitCone : Cone F where pt := Shrink F.sections π := { app := fun j u => ((equivShrink F.sections).symm u).val j naturality := fun j j' f => by funext x simp } @[ext] lemma limitCone_pt_ext {x y : (limitCone F).pt} (w : (equivShrink F.sections).symm x = (equivShrink F.sections).symm y) : x = y := by aesop /-- (internal implementation) the fact that the proposed limit cone is the limit -/ @[simps] noncomputable def limitConeIsLimit : IsLimit (limitCone.{v, u} F) where lift s v := equivShrink F.sections { val := fun j => s.π.app j v property := fun f => congr_fun (Cone.w s f) _ } uniq := fun _ _ w => by ext x j simpa using congr_fun (w j) x end end Small theorem hasLimit_iff_small_sections (F : J ⥤ Type u): HasLimit F ↔ Small.{u} F.sections := ⟨fun _ => .mk ⟨_, ⟨(Equiv.ofBijective _ ((isLimit_iff_bijective_sectionOfCone (limit.cone F)).mp ⟨limit.isLimit _⟩)).symm⟩⟩, fun _ => ⟨_, Small.limitConeIsLimit F⟩⟩ -- TODO: If `UnivLE` works out well, we will eventually want to deprecate these -- definitions, and probably as a first step put them in namespace or otherwise rename them. section TypeMax /-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/ @[simps] noncomputable def limitCone (F : J ⥤ TypeMax.{v, u}) : Cone F where pt := F.sections π := { app := fun j u => u.val j naturality := fun j j' f => by funext x simp } #align category_theory.limits.types.limit_cone CategoryTheory.Limits.Types.limitCone /-- (internal implementation) the fact that the proposed limit cone is the limit -/ @[simps] noncomputable def limitConeIsLimit (F : J ⥤ TypeMax.{v, u}) : IsLimit (limitCone F) where lift s v := { val := fun j => s.π.app j v property := fun f => congr_fun (Cone.w s f) _ } uniq := fun _ _ w => by funext x apply Subtype.ext funext j exact congr_fun (w j) x #align category_theory.limits.types.limit_cone_is_limit CategoryTheory.Limits.Types.limitConeIsLimit end TypeMax /-! The results in this section have a `UnivLE.{v, u}` hypothesis, but as they only use the constructions from the `CategoryTheory.Limits.Types.UnivLE` namespace in their definitions (rather than their statements), we leave them in the main `CategoryTheory.Limits.Types` namespace. -/ section UnivLE open UnivLE instance hasLimit [Small.{u} J] (F : J ⥤ Type u) : HasLimit F := (hasLimit_iff_small_sections F).mpr inferInstance instance hasLimitsOfShape [Small.{u} J] : HasLimitsOfShape J (Type u) where /-- The category of types has all limits. More specifically, when `UnivLE.{v, u}`, the category `Type u` has all `v`-small limits. See <https://stacks.math.columbia.edu/tag/002U>. -/ instance (priority := 1300) hasLimitsOfSize [UnivLE.{v, u}] : HasLimitsOfSize.{w, v} (Type u) where has_limits_of_shape _ := { } #align category_theory.limits.types.has_limits_of_size CategoryTheory.Limits.Types.hasLimitsOfSize variable (F : J ⥤ Type u) [HasLimit F] /-- The equivalence between the abstract limit of `F` in `TypeMax.{v, u}` and the "concrete" definition as the sections of `F`. -/ noncomputable def limitEquivSections : limit F ≃ F.sections := isLimitEquivSections (limit.isLimit F) #align category_theory.limits.types.limit_equiv_sections CategoryTheory.Limits.Types.limitEquivSections @[simp] theorem limitEquivSections_apply (x : limit F) (j : J) : ((limitEquivSections F) x : ∀ j, F.obj j) j = limit.π F j x := isLimitEquivSections_apply _ _ _ #align category_theory.limits.types.limit_equiv_sections_apply CategoryTheory.Limits.Types.limitEquivSections_apply @[simp] theorem limitEquivSections_symm_apply (x : F.sections) (j : J) : limit.π F j ((limitEquivSections F).symm x) = (x : ∀ j, F.obj j) j := isLimitEquivSections_symm_apply _ _ _ #align category_theory.limits.types.limit_equiv_sections_symm_apply CategoryTheory.Limits.Types.limitEquivSections_symm_apply -- Porting note: `limitEquivSections_symm_apply'` was removed because the linter -- complains it is unnecessary --@[simp] --theorem limitEquivSections_symm_apply' (F : J ⥤ Type v) (x : F.sections) (j : J) : -- limit.π F j ((limitEquivSections.{v, v} F).symm x) = (x : ∀ j, F.obj j) j := -- isLimitEquivSections_symm_apply _ _ _ --#align category_theory.limits.types.limit_equiv_sections_symm_apply' CategoryTheory.Limits.Types.limitEquivSections_symm_apply' -- Porting note (#11182): removed @[ext] /-- Construct a term of `limit F : Type u` from a family of terms `x : Π j, F.obj j` which are "coherent": `∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j'`. -/ noncomputable def Limit.mk (x : ∀ j, F.obj j) (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') : limit F := (limitEquivSections F).symm ⟨x, h _ _⟩ #align category_theory.limits.types.limit.mk CategoryTheory.Limits.Types.Limit.mk @[simp] theorem Limit.π_mk (x : ∀ j, F.obj j) (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') (j) : limit.π F j (Limit.mk F x h) = x j := by dsimp [Limit.mk] simp #align category_theory.limits.types.limit.π_mk CategoryTheory.Limits.Types.Limit.π_mk -- Porting note: `Limit.π_mk'` was removed because the linter complains it is unnecessary --@[simp] --theorem Limit.π_mk' (F : J ⥤ Type v) (x : ∀ j, F.obj j) -- (h : ∀ (j j') (f : j ⟶ j'), F.map f (x j) = x j') (j) : -- limit.π F j (Limit.mk.{v, v} F x h) = x j := by -- dsimp [Limit.mk] -- simp --#align category_theory.limits.types.limit.π_mk' CategoryTheory.Limits.Types.Limit.π_mk' -- PROJECT: prove this for concrete categories where the forgetful functor preserves limits @[ext]
Mathlib/CategoryTheory/Limits/Types.lean
267
270
theorem limit_ext (x y : limit F) (w : ∀ j, limit.π F j x = limit.π F j y) : x = y := by
apply (limitEquivSections F).injective ext j simp [w j]
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Init.Core import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots import Mathlib.NumberTheory.NumberField.Basic import Mathlib.FieldTheory.Galois #align_import number_theory.cyclotomic.basic from "leanprover-community/mathlib"@"4b05d3f4f0601dca8abf99c4ec99187682ed0bba" /-! # Cyclotomic extensions Let `A` and `B` be commutative rings with `Algebra A B`. For `S : Set ℕ+`, we define a class `IsCyclotomicExtension S A B` expressing the fact that `B` is obtained from `A` by adding `n`-th primitive roots of unity, for all `n ∈ S`. ## Main definitions * `IsCyclotomicExtension S A B` : means that `B` is obtained from `A` by adding `n`-th primitive roots of unity, for all `n ∈ S`. * `CyclotomicField`: given `n : ℕ+` and a field `K`, we define `CyclotomicField n K` as the splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has the instance `IsCyclotomicExtension {n} K (CyclotomicField n K)`. * `CyclotomicRing` : if `A` is a domain with fraction field `K` and `n : ℕ+`, we define `CyclotomicRing n A K` as the `A`-subalgebra of `CyclotomicField n K` generated by the roots of `X ^ n - 1`. If `n` is nonzero in `A`, it has the instance `IsCyclotomicExtension {n} A (CyclotomicRing n A K)`. ## Main results * `IsCyclotomicExtension.trans` : if `IsCyclotomicExtension S A B` and `IsCyclotomicExtension T B C`, then `IsCyclotomicExtension (S ∪ T) A C` if `Function.Injective (algebraMap B C)`. * `IsCyclotomicExtension.union_right` : given `IsCyclotomicExtension (S ∪ T) A B`, then `IsCyclotomicExtension T (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }) B`. * `IsCyclotomicExtension.union_left` : given `IsCyclotomicExtension T A B` and `S ⊆ T`, then `IsCyclotomicExtension S A (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 })`. * `IsCyclotomicExtension.finite` : if `S` is finite and `IsCyclotomicExtension S A B`, then `B` is a finite `A`-algebra. * `IsCyclotomicExtension.numberField` : a finite cyclotomic extension of a number field is a number field. * `IsCyclotomicExtension.isSplittingField_X_pow_sub_one` : if `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `X ^ n - 1`. * `IsCyclotomicExtension.splitting_field_cyclotomic` : if `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `cyclotomic n K`. ## Implementation details Our definition of `IsCyclotomicExtension` is very general, to allow rings of any characteristic and infinite extensions, but it will mainly be used in the case `S = {n}` and for integral domains. All results are in the `IsCyclotomicExtension` namespace. Note that some results, for example `IsCyclotomicExtension.trans`, `IsCyclotomicExtension.finite`, `IsCyclotomicExtension.numberField`, `IsCyclotomicExtension.finiteDimensional`, `IsCyclotomicExtension.isGalois` and `CyclotomicField.algebraBase` are lemmas, but they can be made local instances. Some of them are included in the `Cyclotomic` locale. -/ open Polynomial Algebra FiniteDimensional Set universe u v w z variable (n : ℕ+) (S T : Set ℕ+) (A : Type u) (B : Type v) (K : Type w) (L : Type z) variable [CommRing A] [CommRing B] [Algebra A B] variable [Field K] [Field L] [Algebra K L] noncomputable section /-- Given an `A`-algebra `B` and `S : Set ℕ+`, we define `IsCyclotomicExtension S A B` requiring that there is an `n`-th primitive root of unity in `B` for all `n ∈ S` and that `B` is generated over `A` by the roots of `X ^ n - 1`. -/ @[mk_iff] class IsCyclotomicExtension : Prop where /-- For all `n ∈ S`, there exists a primitive `n`-th root of unity in `B`. -/ exists_prim_root {n : ℕ+} (ha : n ∈ S) : ∃ r : B, IsPrimitiveRoot r n /-- The `n`-th roots of unity, for `n ∈ S`, generate `B` as an `A`-algebra. -/ adjoin_roots : ∀ x : B, x ∈ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} #align is_cyclotomic_extension IsCyclotomicExtension namespace IsCyclotomicExtension section Basic /-- A reformulation of `IsCyclotomicExtension` that uses `⊤`. -/ theorem iff_adjoin_eq_top : IsCyclotomicExtension S A B ↔ (∀ n : ℕ+, n ∈ S → ∃ r : B, IsPrimitiveRoot r n) ∧ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} = ⊤ := ⟨fun h => ⟨fun _ => h.exists_prim_root, Algebra.eq_top_iff.2 h.adjoin_roots⟩, fun h => ⟨h.1 _, Algebra.eq_top_iff.1 h.2⟩⟩ #align is_cyclotomic_extension.iff_adjoin_eq_top IsCyclotomicExtension.iff_adjoin_eq_top /-- A reformulation of `IsCyclotomicExtension` in the case `S` is a singleton. -/ theorem iff_singleton : IsCyclotomicExtension {n} A B ↔ (∃ r : B, IsPrimitiveRoot r n) ∧ ∀ x, x ∈ adjoin A {b : B | b ^ (n : ℕ) = 1} := by simp [isCyclotomicExtension_iff] #align is_cyclotomic_extension.iff_singleton IsCyclotomicExtension.iff_singleton /-- If `IsCyclotomicExtension ∅ A B`, then the image of `A` in `B` equals `B`. -/ theorem empty [h : IsCyclotomicExtension ∅ A B] : (⊥ : Subalgebra A B) = ⊤ := by simpa [Algebra.eq_top_iff, isCyclotomicExtension_iff] using h #align is_cyclotomic_extension.empty IsCyclotomicExtension.empty /-- If `IsCyclotomicExtension {1} A B`, then the image of `A` in `B` equals `B`. -/ theorem singleton_one [h : IsCyclotomicExtension {1} A B] : (⊥ : Subalgebra A B) = ⊤ := Algebra.eq_top_iff.2 fun x => by simpa [adjoin_singleton_one] using ((isCyclotomicExtension_iff _ _ _).1 h).2 x #align is_cyclotomic_extension.singleton_one IsCyclotomicExtension.singleton_one variable {A B} /-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension ∅ A B`. -/ theorem singleton_zero_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) : IsCyclotomicExtension ∅ A B := by -- Porting note: Lean3 is able to infer `A`. refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => by simp at hs, _root_.eq_top_iff.2 fun x hx => ?_⟩ rw [← h] at hx simpa using hx #align is_cyclotomic_extension.singleton_zero_of_bot_eq_top IsCyclotomicExtension.singleton_zero_of_bot_eq_top variable (A B) /-- Transitivity of cyclotomic extensions. -/ theorem trans (C : Type w) [CommRing C] [Algebra A C] [Algebra B C] [IsScalarTower A B C] [hS : IsCyclotomicExtension S A B] [hT : IsCyclotomicExtension T B C] (h : Function.Injective (algebraMap B C)) : IsCyclotomicExtension (S ∪ T) A C := by refine ⟨fun hn => ?_, fun x => ?_⟩ · cases' hn with hn hn · obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 hS).1 hn refine ⟨algebraMap B C b, ?_⟩ exact hb.map_of_injective h · exact ((isCyclotomicExtension_iff _ _ _).1 hT).1 hn · refine adjoin_induction (((isCyclotomicExtension_iff T B _).1 hT).2 x) (fun c ⟨n, hn⟩ => subset_adjoin ⟨n, Or.inr hn.1, hn.2⟩) (fun b => ?_) (fun x y hx hy => Subalgebra.add_mem _ hx hy) fun x y hx hy => Subalgebra.mul_mem _ hx hy let f := IsScalarTower.toAlgHom A B C have hb : f b ∈ (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}).map f := ⟨b, ((isCyclotomicExtension_iff _ _ _).1 hS).2 b, rfl⟩ rw [IsScalarTower.toAlgHom_apply, ← adjoin_image] at hb refine adjoin_mono (fun y hy => ?_) hb obtain ⟨b₁, ⟨⟨n, hn⟩, h₁⟩⟩ := hy exact ⟨n, ⟨mem_union_left T hn.1, by rw [← h₁, ← AlgHom.map_pow, hn.2, AlgHom.map_one]⟩⟩ #align is_cyclotomic_extension.trans IsCyclotomicExtension.trans @[nontriviality] theorem subsingleton_iff [Subsingleton B] : IsCyclotomicExtension S A B ↔ S = { } ∨ S = {1} := by have : Subsingleton (Subalgebra A B) := inferInstance constructor · rintro ⟨hprim, -⟩ rw [← subset_singleton_iff_eq] intro t ht obtain ⟨ζ, hζ⟩ := hprim ht rw [mem_singleton_iff, ← PNat.coe_eq_one_iff] exact mod_cast hζ.unique (IsPrimitiveRoot.of_subsingleton ζ) · rintro (rfl | rfl) -- Porting note: `R := A` was not needed. · exact ⟨fun h => h.elim, fun x => by convert (mem_top (R := A) : x ∈ ⊤)⟩ · rw [iff_singleton] exact ⟨⟨0, IsPrimitiveRoot.of_subsingleton 0⟩, fun x => by convert (mem_top (R := A) : x ∈ ⊤)⟩ #align is_cyclotomic_extension.subsingleton_iff IsCyclotomicExtension.subsingleton_iff /-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `S ∪ T`, then `B` is a cyclotomic extension of `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }` given by roots of unity of order in `T`. -/ theorem union_right [h : IsCyclotomicExtension (S ∪ T) A B] : IsCyclotomicExtension T (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}) B := by have : {b : B | ∃ n : ℕ+, n ∈ S ∪ T ∧ b ^ (n : ℕ) = 1} = {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} ∪ {b : B | ∃ n : ℕ+, n ∈ T ∧ b ^ (n : ℕ) = 1} := by refine le_antisymm ?_ ?_ · rintro x ⟨n, hn₁ | hn₂, hnpow⟩ · left; exact ⟨n, hn₁, hnpow⟩ · right; exact ⟨n, hn₂, hnpow⟩ · rintro x (⟨n, hn⟩ | ⟨n, hn⟩) · exact ⟨n, Or.inl hn.1, hn.2⟩ · exact ⟨n, Or.inr hn.1, hn.2⟩ refine ⟨fun hn => ((isCyclotomicExtension_iff _ A _).1 h).1 (mem_union_right S hn), fun b => ?_⟩ replace h := ((isCyclotomicExtension_iff _ _ _).1 h).2 b rwa [this, adjoin_union_eq_adjoin_adjoin, Subalgebra.mem_restrictScalars] at h #align is_cyclotomic_extension.union_right IsCyclotomicExtension.union_right /-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `T` and `S ⊆ T`, then `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }` is a cyclotomic extension of `B` given by roots of unity of order in `S`. -/ theorem union_left [h : IsCyclotomicExtension T A B] (hS : S ⊆ T) : IsCyclotomicExtension S A (adjoin A {b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1}) := by refine ⟨@fun n hn => ?_, fun b => ?_⟩ · obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 h).1 (hS hn) refine ⟨⟨b, subset_adjoin ⟨n, hn, hb.pow_eq_one⟩⟩, ?_⟩ rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk] · convert mem_top (R := A) (x := b) rw [← adjoin_adjoin_coe_preimage, preimage_setOf_eq] norm_cast #align is_cyclotomic_extension.union_left IsCyclotomicExtension.union_left variable {n S} /-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` implies `IsCyclotomicExtension (S ∪ {n}) A B`. -/ theorem of_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) [H : IsCyclotomicExtension S A B] : IsCyclotomicExtension (S ∪ {n}) A B := by refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩ · rw [mem_union, mem_singleton_iff] at hs obtain hs | rfl := hs · exact H.exists_prim_root hs · obtain ⟨m, hm⟩ := hS obtain ⟨x, rfl⟩ := h m hm obtain ⟨ζ, hζ⟩ := H.exists_prim_root hm refine ⟨ζ ^ (x : ℕ), ?_⟩ convert hζ.pow_of_dvd x.ne_zero (dvd_mul_left (x : ℕ) s) simp only [PNat.mul_coe, Nat.mul_div_left, PNat.pos] · refine _root_.eq_top_iff.2 ?_ rw [← ((iff_adjoin_eq_top S A B).1 H).2] refine adjoin_mono fun x hx => ?_ simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢ obtain ⟨m, hm⟩ := hx exact ⟨m, ⟨Or.inr hm.1, hm.2⟩⟩ #align is_cyclotomic_extension.of_union_of_dvd IsCyclotomicExtension.of_union_of_dvd /-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `IsCyclotomicExtension S A B` if and only if `IsCyclotomicExtension (S ∪ {n}) A B`. -/ theorem iff_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.Nonempty) : IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {n}) A B := by refine ⟨fun H => of_union_of_dvd A B h hS, fun H => (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ?_, ?_⟩⟩ · exact H.exists_prim_root (subset_union_left hs) · rw [_root_.eq_top_iff, ← ((iff_adjoin_eq_top _ A B).1 H).2] refine adjoin_mono fun x hx => ?_ simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢ obtain ⟨m, rfl | hm, hxpow⟩ := hx · obtain ⟨y, hy⟩ := hS refine ⟨y, ⟨hy, ?_⟩⟩ obtain ⟨z, rfl⟩ := h y hy simp only [PNat.mul_coe, pow_mul, hxpow, one_pow] · exact ⟨m, ⟨hm, hxpow⟩⟩ #align is_cyclotomic_extension.iff_union_of_dvd IsCyclotomicExtension.iff_union_of_dvd variable (n S) /-- `IsCyclotomicExtension S A B` is equivalent to `IsCyclotomicExtension (S ∪ {1}) A B`. -/ theorem iff_union_singleton_one : IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {1}) A B := by obtain hS | rfl := S.eq_empty_or_nonempty.symm · exact iff_union_of_dvd _ _ (fun s _ => one_dvd _) hS rw [empty_union] refine ⟨fun H => ?_, fun H => ?_⟩ · refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => ⟨1, by simp [mem_singleton_iff.1 hs]⟩, ?_⟩ simp [adjoin_singleton_one, empty] · refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs => (not_mem_empty s hs).elim, ?_⟩ simp [@singleton_one A B _ _ _ H] #align is_cyclotomic_extension.iff_union_singleton_one IsCyclotomicExtension.iff_union_singleton_one variable {A B} /-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension {1} A B`. -/ theorem singleton_one_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) : IsCyclotomicExtension {1} A B := by convert (iff_union_singleton_one _ A _).1 (singleton_zero_of_bot_eq_top h) simp #align is_cyclotomic_extension.singleton_one_of_bot_eq_top IsCyclotomicExtension.singleton_one_of_bot_eq_top /-- If `Function.Surjective (algebraMap A B)`, then `IsCyclotomicExtension {1} A B`. -/ theorem singleton_one_of_algebraMap_bijective (h : Function.Surjective (algebraMap A B)) : IsCyclotomicExtension {1} A B := singleton_one_of_bot_eq_top (surjective_algebraMap_iff.1 h).symm #align is_cyclotomic_extension.singleton_one_of_algebra_map_bijective IsCyclotomicExtension.singleton_one_of_algebraMap_bijective variable (A B) /-- Given `(f : B ≃ₐ[A] C)`, if `IsCyclotomicExtension S A B` then `IsCyclotomicExtension S A C`. -/ protected theorem equiv {C : Type*} [CommRing C] [Algebra A C] [h : IsCyclotomicExtension S A B] (f : B ≃ₐ[A] C) : IsCyclotomicExtension S A C := by letI : Algebra B C := f.toAlgHom.toRingHom.toAlgebra haveI : IsCyclotomicExtension {1} B C := singleton_one_of_algebraMap_bijective f.surjective haveI : IsScalarTower A B C := IsScalarTower.of_algHom f.toAlgHom exact (iff_union_singleton_one _ _ _).2 (trans S {1} A B C f.injective) #align is_cyclotomic_extension.equiv IsCyclotomicExtension.equiv protected theorem neZero [h : IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero ((n : ℕ) : B) := by obtain ⟨⟨r, hr⟩, -⟩ := (iff_singleton n A B).1 h exact hr.neZero' #align is_cyclotomic_extension.ne_zero IsCyclotomicExtension.neZero protected theorem neZero' [IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero ((n : ℕ) : A) := by haveI := IsCyclotomicExtension.neZero n A B exact NeZero.nat_of_neZero (algebraMap A B) #align is_cyclotomic_extension.ne_zero' IsCyclotomicExtension.neZero' end Basic section Fintype theorem finite_of_singleton [IsDomain B] [h : IsCyclotomicExtension {n} A B] : Module.Finite A B := by classical rw [Module.finite_def, ← top_toSubmodule, ← ((iff_adjoin_eq_top _ _ _).1 h).2] refine fg_adjoin_of_finite ?_ fun b hb => ?_ · simp only [mem_singleton_iff, exists_eq_left] have : {b : B | b ^ (n : ℕ) = 1} = (nthRoots n (1 : B)).toFinset := Set.ext fun x => ⟨fun h => by simpa using h, fun h => by simpa using h⟩ rw [this] exact (nthRoots (↑n) 1).toFinset.finite_toSet · simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] at hb exact ⟨X ^ (n : ℕ) - 1, ⟨monic_X_pow_sub_C _ n.pos.ne.symm, by simp [hb]⟩⟩ #align is_cyclotomic_extension.finite_of_singleton IsCyclotomicExtension.finite_of_singleton /-- If `S` is finite and `IsCyclotomicExtension S A B`, then `B` is a finite `A`-algebra. -/ protected theorem finite [IsDomain B] [h₁ : Finite S] [h₂ : IsCyclotomicExtension S A B] : Module.Finite A B := by cases' nonempty_fintype S with h revert h₂ A B refine Set.Finite.induction_on h₁ (fun A B => ?_) @fun n S _ _ H A B => ?_ · intro _ _ _ _ _ refine Module.finite_def.2 ⟨({1} : Finset B), ?_⟩ simp [← top_toSubmodule, ← empty, toSubmodule_bot, Submodule.one_eq_span] · intro _ _ _ _ h haveI : IsCyclotomicExtension S A (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) := union_left _ (insert n S) _ _ (subset_insert n S) haveI := H A (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) have : Module.Finite (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) B := by rw [← union_singleton] at h letI := @union_right S {n} A B _ _ _ h exact finite_of_singleton n _ _ exact Module.Finite.trans (adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}) _ #align is_cyclotomic_extension.finite IsCyclotomicExtension.finite /-- A cyclotomic finite extension of a number field is a number field. -/ theorem numberField [h : NumberField K] [Finite S] [IsCyclotomicExtension S K L] : NumberField L := { to_charZero := charZero_of_injective_algebraMap (algebraMap K L).injective to_finiteDimensional := by haveI := charZero_of_injective_algebraMap (algebraMap K L).injective haveI := IsCyclotomicExtension.finite S K L exact Module.Finite.trans K _ } #align is_cyclotomic_extension.number_field IsCyclotomicExtension.numberField /-- A finite cyclotomic extension of an integral noetherian domain is integral -/ theorem integral [IsDomain B] [IsNoetherianRing A] [Finite S] [IsCyclotomicExtension S A B] : Algebra.IsIntegral A B := have := IsCyclotomicExtension.finite S A B ⟨isIntegral_of_noetherian inferInstance⟩ #align is_cyclotomic_extension.integral IsCyclotomicExtension.integral /-- If `S` is finite and `IsCyclotomicExtension S K A`, then `finiteDimensional K A`. -/ theorem finiteDimensional (C : Type z) [Finite S] [CommRing C] [Algebra K C] [IsDomain C] [IsCyclotomicExtension S K C] : FiniteDimensional K C := IsCyclotomicExtension.finite S K C #align is_cyclotomic_extension.finite_dimensional IsCyclotomicExtension.finiteDimensional end Fintype section variable {A B} theorem adjoin_roots_cyclotomic_eq_adjoin_nth_roots [IsDomain B] {ζ : B} {n : ℕ+} (hζ : IsPrimitiveRoot ζ n) : adjoin A ((cyclotomic n A).rootSet B) = adjoin A {b : B | ∃ a : ℕ+, a ∈ ({n} : Set ℕ+) ∧ b ^ (a : ℕ) = 1} := by simp only [mem_singleton_iff, exists_eq_left, map_cyclotomic] refine le_antisymm (adjoin_mono fun x hx => ?_) (adjoin_le fun x hx => ?_) · rw [mem_rootSet'] at hx simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] rw [isRoot_of_unity_iff n.pos] refine ⟨n, Nat.mem_divisors_self n n.ne_zero, ?_⟩ rw [IsRoot.def, ← map_cyclotomic n (algebraMap A B), eval_map, ← aeval_def] exact hx.2 · simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] at hx obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx n.pos refine SetLike.mem_coe.2 (Subalgebra.pow_mem _ (subset_adjoin ?_) _) rw [mem_rootSet', map_cyclotomic, aeval_def, ← eval_map, map_cyclotomic, ← IsRoot] exact ⟨cyclotomic_ne_zero n B, hζ.isRoot_cyclotomic n.pos⟩ #align is_cyclotomic_extension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots theorem adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic {n : ℕ+} [IsDomain B] {ζ : B} (hζ : IsPrimitiveRoot ζ n) : adjoin A ((cyclotomic n A).rootSet B) = adjoin A {ζ} := by refine le_antisymm (adjoin_le fun x hx => ?_) (adjoin_mono fun x hx => ?_) · suffices hx : x ^ n.1 = 1 by obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx n.pos exact SetLike.mem_coe.2 (Subalgebra.pow_mem _ (subset_adjoin <| mem_singleton ζ) _) refine (isRoot_of_unity_iff n.pos B).2 ?_ refine ⟨n, Nat.mem_divisors_self n n.ne_zero, ?_⟩ rw [mem_rootSet', aeval_def, ← eval_map, map_cyclotomic, ← IsRoot] at hx exact hx.2 · simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq] at hx simpa only [hx, mem_rootSet', map_cyclotomic, aeval_def, ← eval_map, IsRoot] using And.intro (cyclotomic_ne_zero n B) (hζ.isRoot_cyclotomic n.pos) #align is_cyclotomic_extension.adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic theorem adjoin_primitive_root_eq_top {n : ℕ+} [IsDomain B] [h : IsCyclotomicExtension {n} A B] {ζ : B} (hζ : IsPrimitiveRoot ζ n) : adjoin A ({ζ} : Set B) = ⊤ := by classical rw [← adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic hζ] rw [adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ] exact ((iff_adjoin_eq_top {n} A B).mp h).2 #align is_cyclotomic_extension.adjoin_primitive_root_eq_top IsCyclotomicExtension.adjoin_primitive_root_eq_top variable (A) theorem _root_.IsPrimitiveRoot.adjoin_isCyclotomicExtension {ζ : B} {n : ℕ+} (h : IsPrimitiveRoot ζ n) : IsCyclotomicExtension {n} A (adjoin A ({ζ} : Set B)) := { exists_prim_root := fun hi => by rw [Set.mem_singleton_iff] at hi refine ⟨⟨ζ, subset_adjoin <| Set.mem_singleton ζ⟩, ?_⟩ rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk, hi] adjoin_roots := fun x => by refine adjoin_induction' (x := x) (fun b hb => ?_) (fun a => ?_) (fun b₁ b₂ hb₁ hb₂ => ?_) (fun b₁ b₂ hb₁ hb₂ => ?_) · rw [Set.mem_singleton_iff] at hb refine subset_adjoin ?_ simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq, hb] rw [← Subalgebra.coe_eq_one, Subalgebra.coe_pow, Subtype.coe_mk] exact ((IsPrimitiveRoot.iff_def ζ n).1 h).1 · exact Subalgebra.algebraMap_mem _ _ · exact Subalgebra.add_mem _ hb₁ hb₂ · exact Subalgebra.mul_mem _ hb₁ hb₂ } #align is_primitive_root.adjoin_is_cyclotomic_extension IsPrimitiveRoot.adjoin_isCyclotomicExtension end section Field variable {n S} /-- A cyclotomic extension splits `X ^ n - 1` if `n ∈ S`. -/ theorem splits_X_pow_sub_one [H : IsCyclotomicExtension S K L] (hS : n ∈ S) : Splits (algebraMap K L) (X ^ (n : ℕ) - 1) := by rw [← splits_id_iff_splits, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow, Polynomial.map_X] obtain ⟨z, hz⟩ := ((isCyclotomicExtension_iff _ _ _).1 H).1 hS exact X_pow_sub_one_splits hz set_option linter.uppercaseLean3 false in #align is_cyclotomic_extension.splits_X_pow_sub_one IsCyclotomicExtension.splits_X_pow_sub_one /-- A cyclotomic extension splits `cyclotomic n K` if `n ∈ S` and `ne_zero (n : K)`. -/ theorem splits_cyclotomic [IsCyclotomicExtension S K L] (hS : n ∈ S) : Splits (algebraMap K L) (cyclotomic n K) := by refine splits_of_splits_of_dvd _ (X_pow_sub_C_ne_zero n.pos _) (splits_X_pow_sub_one K L hS) ?_ use ∏ i ∈ (n : ℕ).properDivisors, Polynomial.cyclotomic i K rw [(eq_cyclotomic_iff n.pos _).1 rfl, RingHom.map_one] #align is_cyclotomic_extension.splits_cyclotomic IsCyclotomicExtension.splits_cyclotomic variable (n S) section Singleton variable [IsCyclotomicExtension {n} K L] /-- If `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `X ^ n - 1`. -/
Mathlib/NumberTheory/Cyclotomic/Basic.lean
464
474
theorem isSplittingField_X_pow_sub_one : IsSplittingField K L (X ^ (n : ℕ) - 1) := { splits' := splits_X_pow_sub_one K L (mem_singleton n) adjoin_rootSet' := by
rw [← ((iff_adjoin_eq_top {n} K L).1 inferInstance).2] congr refine Set.ext fun x => ?_ simp only [Polynomial.map_pow, mem_singleton_iff, Multiset.mem_toFinset, exists_eq_left, mem_setOf_eq, Polynomial.map_X, Polynomial.map_one, Finset.mem_coe, Polynomial.map_sub] simp only [mem_rootSet', map_sub, map_pow, aeval_one, aeval_X, sub_eq_zero, map_X, and_iff_right_iff_imp, Polynomial.map_sub, Polynomial.map_pow, Polynomial.map_one] exact fun _ => X_pow_sub_C_ne_zero n.pos (1 : L) }
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Probability.Martingale.Convergence import Mathlib.Probability.Martingale.OptionalStopping import Mathlib.Probability.Martingale.Centering #align_import probability.martingale.borel_cantelli from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # Generalized Borel-Cantelli lemma This file proves Lévy's generalized Borel-Cantelli lemma which is a generalization of the Borel-Cantelli lemmas. With this generalization, one can easily deduce the Borel-Cantelli lemmas by choosing appropriate filtrations. This file also contains the one sided martingale bound which is required to prove the generalized Borel-Cantelli. **Note**: the usual Borel-Cantelli lemmas are not in this file. See `MeasureTheory.measure_limsup_eq_zero` for the first (which does not depend on the results here), and `ProbabilityTheory.measure_limsup_eq_one` for the second (which does). ## Main results - `MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto`: the one sided martingale bound: given a submartingale `f` with uniformly bounded differences, the set for which `f` converges is almost everywhere equal to the set for which it is bounded. - `MeasureTheory.ae_mem_limsup_atTop_iff`: Lévy's generalized Borel-Cantelli: given a filtration `ℱ` and a sequence of sets `s` such that `s n ∈ ℱ n` for all `n`, `limsup atTop s` is almost everywhere equal to the set for which `∑ ℙ[s (n + 1)∣ℱ n] = ∞`. -/ open Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory BigOperators Topology namespace MeasureTheory variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {ℱ : Filtration ℕ m0} {f : ℕ → Ω → ℝ} {ω : Ω} /-! ### One sided martingale bound -/ -- TODO: `leastGE` should be defined taking values in `WithTop ℕ` once the `stoppedProcess` -- refactor is complete /-- `leastGE f r n` is the stopping time corresponding to the first time `f ≥ r`. -/ noncomputable def leastGE (f : ℕ → Ω → ℝ) (r : ℝ) (n : ℕ) := hitting f (Set.Ici r) 0 n #align measure_theory.least_ge MeasureTheory.leastGE theorem Adapted.isStoppingTime_leastGE (r : ℝ) (n : ℕ) (hf : Adapted ℱ f) : IsStoppingTime ℱ (leastGE f r n) := hitting_isStoppingTime hf measurableSet_Ici #align measure_theory.adapted.is_stopping_time_least_ge MeasureTheory.Adapted.isStoppingTime_leastGE theorem leastGE_le {i : ℕ} {r : ℝ} (ω : Ω) : leastGE f r i ω ≤ i := hitting_le ω #align measure_theory.least_ge_le MeasureTheory.leastGE_le -- The following four lemmas shows `leastGE` behaves like a stopped process. Ideally we should -- define `leastGE` as a stopping time and take its stopped process. However, we can't do that -- with our current definition since a stopping time takes only finite indicies. An upcomming -- refactor should hopefully make it possible to have stopping times taking infinity as a value theorem leastGE_mono {n m : ℕ} (hnm : n ≤ m) (r : ℝ) (ω : Ω) : leastGE f r n ω ≤ leastGE f r m ω := hitting_mono hnm #align measure_theory.least_ge_mono MeasureTheory.leastGE_mono theorem leastGE_eq_min (π : Ω → ℕ) (r : ℝ) (ω : Ω) {n : ℕ} (hπn : ∀ ω, π ω ≤ n) : leastGE f r (π ω) ω = min (π ω) (leastGE f r n ω) := by classical refine le_antisymm (le_min (leastGE_le _) (leastGE_mono (hπn ω) r ω)) ?_ by_cases hle : π ω ≤ leastGE f r n ω · rw [min_eq_left hle, leastGE] by_cases h : ∃ j ∈ Set.Icc 0 (π ω), f j ω ∈ Set.Ici r · refine hle.trans (Eq.le ?_) rw [leastGE, ← hitting_eq_hitting_of_exists (hπn ω) h] · simp only [hitting, if_neg h, le_rfl] · rw [min_eq_right (not_le.1 hle).le, leastGE, leastGE, ← hitting_eq_hitting_of_exists (hπn ω) _] rw [not_le, leastGE, hitting_lt_iff _ (hπn ω)] at hle exact let ⟨j, hj₁, hj₂⟩ := hle ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ #align measure_theory.least_ge_eq_min MeasureTheory.leastGE_eq_min theorem stoppedValue_stoppedValue_leastGE (f : ℕ → Ω → ℝ) (π : Ω → ℕ) (r : ℝ) {n : ℕ} (hπn : ∀ ω, π ω ≤ n) : stoppedValue (fun i => stoppedValue f (leastGE f r i)) π = stoppedValue (stoppedProcess f (leastGE f r n)) π := by ext1 ω simp (config := { unfoldPartialApp := true }) only [stoppedProcess, stoppedValue] rw [leastGE_eq_min _ _ _ hπn] #align measure_theory.stopped_value_stopped_value_least_ge MeasureTheory.stoppedValue_stoppedValue_leastGE theorem Submartingale.stoppedValue_leastGE [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (r : ℝ) : Submartingale (fun i => stoppedValue f (leastGE f r i)) ℱ μ := by rw [submartingale_iff_expected_stoppedValue_mono] · intro σ π hσ hπ hσ_le_π hπ_bdd obtain ⟨n, hπ_le_n⟩ := hπ_bdd simp_rw [stoppedValue_stoppedValue_leastGE f σ r fun i => (hσ_le_π i).trans (hπ_le_n i)] simp_rw [stoppedValue_stoppedValue_leastGE f π r hπ_le_n] refine hf.expected_stoppedValue_mono ?_ ?_ ?_ fun ω => (min_le_left _ _).trans (hπ_le_n ω) · exact hσ.min (hf.adapted.isStoppingTime_leastGE _ _) · exact hπ.min (hf.adapted.isStoppingTime_leastGE _ _) · exact fun ω => min_le_min (hσ_le_π ω) le_rfl · exact fun i => stronglyMeasurable_stoppedValue_of_le hf.adapted.progMeasurable_of_discrete (hf.adapted.isStoppingTime_leastGE _ _) leastGE_le · exact fun i => integrable_stoppedValue _ (hf.adapted.isStoppingTime_leastGE _ _) hf.integrable leastGE_le #align measure_theory.submartingale.stopped_value_least_ge MeasureTheory.Submartingale.stoppedValue_leastGE variable {r : ℝ} {R : ℝ≥0} theorem norm_stoppedValue_leastGE_le (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : ∀ᵐ ω ∂μ, stoppedValue f (leastGE f r i) ω ≤ r + R := by filter_upwards [hbdd] with ω hbddω change f (leastGE f r i ω) ω ≤ r + R by_cases heq : leastGE f r i ω = 0 · rw [heq, hf0, Pi.zero_apply] exact add_nonneg hr R.coe_nonneg · obtain ⟨k, hk⟩ := Nat.exists_eq_succ_of_ne_zero heq rw [hk, add_comm, ← sub_le_iff_le_add] have := not_mem_of_lt_hitting (hk.symm ▸ k.lt_succ_self : k < leastGE f r i ω) (zero_le _) simp only [Set.mem_union, Set.mem_Iic, Set.mem_Ici, not_or, not_le] at this exact (sub_lt_sub_left this _).le.trans ((le_abs_self _).trans (hbddω _)) #align measure_theory.norm_stopped_value_least_ge_le MeasureTheory.norm_stoppedValue_leastGE_le theorem Submartingale.stoppedValue_leastGE_snorm_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : snorm (stoppedValue f (leastGE f r i)) 1 μ ≤ 2 * μ Set.univ * ENNReal.ofReal (r + R) := by refine snorm_one_le_of_le' ((hf.stoppedValue_leastGE r).integrable _) ?_ (norm_stoppedValue_leastGE_le hr hf0 hbdd i) rw [← integral_univ] refine le_trans ?_ ((hf.stoppedValue_leastGE r).setIntegral_le (zero_le _) MeasurableSet.univ) simp_rw [stoppedValue, leastGE, hitting_of_le le_rfl, hf0, integral_zero', le_rfl] #align measure_theory.submartingale.stopped_value_least_ge_snorm_le MeasureTheory.Submartingale.stoppedValue_leastGE_snorm_le theorem Submartingale.stoppedValue_leastGE_snorm_le' [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hr : 0 ≤ r) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) (i : ℕ) : snorm (stoppedValue f (leastGE f r i)) 1 μ ≤ ENNReal.toNNReal (2 * μ Set.univ * ENNReal.ofReal (r + R)) := by refine (hf.stoppedValue_leastGE_snorm_le hr hf0 hbdd i).trans ?_ simp [ENNReal.coe_toNNReal (measure_ne_top μ _), ENNReal.coe_toNNReal] #align measure_theory.submartingale.stopped_value_least_ge_snorm_le' MeasureTheory.Submartingale.stoppedValue_leastGE_snorm_le' /-- This lemma is superseded by `Submartingale.bddAbove_iff_exists_tendsto`. -/ theorem Submartingale.exists_tendsto_of_abs_bddAbove_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) → ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by have ht : ∀ᵐ ω ∂μ, ∀ i : ℕ, ∃ c, Tendsto (fun n => stoppedValue f (leastGE f i n) ω) atTop (𝓝 c) := by rw [ae_all_iff] exact fun i => Submartingale.exists_ae_tendsto_of_bdd (hf.stoppedValue_leastGE i) (hf.stoppedValue_leastGE_snorm_le' i.cast_nonneg hf0 hbdd) filter_upwards [ht] with ω hω hωb rw [BddAbove] at hωb obtain ⟨i, hi⟩ := exists_nat_gt hωb.some have hib : ∀ n, f n ω < i := by intro n exact lt_of_le_of_lt ((mem_upperBounds.1 hωb.some_mem) _ ⟨n, rfl⟩) hi have heq : ∀ n, stoppedValue f (leastGE f i n) ω = f n ω := by intro n rw [leastGE]; unfold hitting; rw [stoppedValue] rw [if_neg] simp only [Set.mem_Icc, Set.mem_union, Set.mem_Ici] push_neg exact fun j _ => hib j simp only [← heq, hω i] #align measure_theory.submartingale.exists_tendsto_of_abs_bdd_above_aux MeasureTheory.Submartingale.exists_tendsto_of_abs_bddAbove_aux theorem Submartingale.bddAbove_iff_exists_tendsto_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hf0 : f 0 = 0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by filter_upwards [hf.exists_tendsto_of_abs_bddAbove_aux hf0 hbdd] with ω hω using ⟨hω, fun ⟨c, hc⟩ => hc.bddAbove_range⟩ #align measure_theory.submartingale.bdd_above_iff_exists_tendsto_aux MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto_aux /-- One sided martingale bound: If `f` is a submartingale which has uniformly bounded differences, then for almost every `ω`, `f n ω` is bounded above (in `n`) if and only if it converges. -/ theorem Submartingale.bddAbove_iff_exists_tendsto [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ ∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c) := by set g : ℕ → Ω → ℝ := fun n ω => f n ω - f 0 ω have hg : Submartingale g ℱ μ := hf.sub_martingale (martingale_const_fun _ _ (hf.adapted 0) (hf.integrable 0)) have hg0 : g 0 = 0 := by ext ω simp only [g, sub_self, Pi.zero_apply] have hgbdd : ∀ᵐ ω ∂μ, ∀ i : ℕ, |g (i + 1) ω - g i ω| ≤ ↑R := by simpa only [g, sub_sub_sub_cancel_right] filter_upwards [hg.bddAbove_iff_exists_tendsto_aux hg0 hgbdd] with ω hω convert hω using 1 · refine ⟨fun h => ?_, fun h => ?_⟩ <;> obtain ⟨b, hb⟩ := h <;> refine ⟨b + |f 0 ω|, fun y hy => ?_⟩ <;> obtain ⟨n, rfl⟩ := hy · simp_rw [g, sub_eq_add_neg] exact add_le_add (hb ⟨n, rfl⟩) (neg_le_abs _) · exact sub_le_iff_le_add.1 (le_trans (sub_le_sub_left (le_abs_self _) _) (hb ⟨n, rfl⟩)) · refine ⟨fun h => ?_, fun h => ?_⟩ <;> obtain ⟨c, hc⟩ := h · exact ⟨c - f 0 ω, hc.sub_const _⟩ · refine ⟨c + f 0 ω, ?_⟩ have := hc.add_const (f 0 ω) simpa only [g, sub_add_cancel] #align measure_theory.submartingale.bdd_above_iff_exists_tendsto MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto /-! ### Lévy's generalization of the Borel-Cantelli lemma Lévy's generalization of the Borel-Cantelli lemma states that: given a natural number indexed filtration $(\mathcal{F}_n)$, and a sequence of sets $(s_n)$ such that for all $n$, $s_n \in \mathcal{F}_n$, $limsup_n s_n$ is almost everywhere equal to the set for which $\sum_n \mathbb{P}[s_n \mid \mathcal{F}_n] = \infty$. The proof strategy follows by constructing a martingale satisfying the one sided martingale bound. In particular, we define $$ f_n := \sum_{k < n} \mathbf{1}_{s_{n + 1}} - \mathbb{P}[s_{n + 1} \mid \mathcal{F}_n]. $$ Then, as a martingale is both a sub and a super-martingale, the set for which it is unbounded from above must agree with the set for which it is unbounded from below almost everywhere. Thus, it can only converge to $\pm \infty$ with probability 0. Thus, by considering $$ \limsup_n s_n = \{\sum_n \mathbf{1}_{s_n} = \infty\} $$ almost everywhere, the result follows. -/ theorem Martingale.bddAbove_range_iff_bddBelow_range [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, BddAbove (Set.range fun n => f n ω) ↔ BddBelow (Set.range fun n => f n ω) := by have hbdd' : ∀ᵐ ω ∂μ, ∀ i, |(-f) (i + 1) ω - (-f) i ω| ≤ R := by filter_upwards [hbdd] with ω hω i erw [← abs_neg, neg_sub, sub_neg_eq_add, neg_add_eq_sub] exact hω i have hup := hf.submartingale.bddAbove_iff_exists_tendsto hbdd have hdown := hf.neg.submartingale.bddAbove_iff_exists_tendsto hbdd' filter_upwards [hup, hdown] with ω hω₁ hω₂ have : (∃ c, Tendsto (fun n => f n ω) atTop (𝓝 c)) ↔ ∃ c, Tendsto (fun n => (-f) n ω) atTop (𝓝 c) := by constructor <;> rintro ⟨c, hc⟩ · exact ⟨-c, hc.neg⟩ · refine ⟨-c, ?_⟩ convert hc.neg simp only [neg_neg, Pi.neg_apply] rw [hω₁, this, ← hω₂] constructor <;> rintro ⟨c, hc⟩ <;> refine ⟨-c, fun ω hω => ?_⟩ · rw [mem_upperBounds] at hc refine neg_le.2 (hc _ ?_) simpa only [Pi.neg_apply, Set.mem_range, neg_inj] · rw [mem_lowerBounds] at hc simp_rw [Set.mem_range, Pi.neg_apply, neg_eq_iff_eq_neg] at hω refine le_neg.1 (hc _ ?_) simpa only [Set.mem_range] #align measure_theory.martingale.bdd_above_range_iff_bdd_below_range MeasureTheory.Martingale.bddAbove_range_iff_bddBelow_range theorem Martingale.ae_not_tendsto_atTop_atTop [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atTop := by filter_upwards [hf.bddAbove_range_iff_bddBelow_range hbdd] with ω hω htop using unbounded_of_tendsto_atTop htop (hω.2 <| bddBelow_range_of_tendsto_atTop_atTop htop) #align measure_theory.martingale.ae_not_tendsto_at_top_at_top MeasureTheory.Martingale.ae_not_tendsto_atTop_atTop theorem Martingale.ae_not_tendsto_atTop_atBot [IsFiniteMeasure μ] (hf : Martingale f ℱ μ) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ¬Tendsto (fun n => f n ω) atTop atBot := by filter_upwards [hf.bddAbove_range_iff_bddBelow_range hbdd] with ω hω htop using unbounded_of_tendsto_atBot htop (hω.1 <| bddAbove_range_of_tendsto_atTop_atBot htop) #align measure_theory.martingale.ae_not_tendsto_at_top_at_bot MeasureTheory.Martingale.ae_not_tendsto_atTop_atBot namespace BorelCantelli /-- Auxiliary definition required to prove Lévy's generalization of the Borel-Cantelli lemmas for which we will take the martingale part. -/ noncomputable def process (s : ℕ → Set Ω) (n : ℕ) : Ω → ℝ := ∑ k ∈ Finset.range n, (s (k + 1)).indicator 1 #align measure_theory.borel_cantelli.process MeasureTheory.BorelCantelli.process variable {s : ℕ → Set Ω} theorem process_zero : process s 0 = 0 := by rw [process, Finset.range_zero, Finset.sum_empty] #align measure_theory.borel_cantelli.process_zero MeasureTheory.BorelCantelli.process_zero theorem adapted_process (hs : ∀ n, MeasurableSet[ℱ n] (s n)) : Adapted ℱ (process s) := fun _ => Finset.stronglyMeasurable_sum' _ fun _ hk => stronglyMeasurable_one.indicator <| ℱ.mono (Finset.mem_range.1 hk) _ <| hs _ #align measure_theory.borel_cantelli.adapted_process MeasureTheory.BorelCantelli.adapted_process theorem martingalePart_process_ae_eq (ℱ : Filtration ℕ m0) (μ : Measure Ω) (s : ℕ → Set Ω) (n : ℕ) : martingalePart (process s) ℱ μ n = ∑ k ∈ Finset.range n, ((s (k + 1)).indicator 1 - μ[(s (k + 1)).indicator 1|ℱ k]) := by simp only [martingalePart_eq_sum, process_zero, zero_add] refine Finset.sum_congr rfl fun k _ => ?_ simp only [process, Finset.sum_range_succ_sub_sum] #align measure_theory.borel_cantelli.martingale_part_process_ae_eq MeasureTheory.BorelCantelli.martingalePart_process_ae_eq theorem predictablePart_process_ae_eq (ℱ : Filtration ℕ m0) (μ : Measure Ω) (s : ℕ → Set Ω) (n : ℕ) : predictablePart (process s) ℱ μ n = ∑ k ∈ Finset.range n, μ[(s (k + 1)).indicator (1 : Ω → ℝ)|ℱ k] := by have := martingalePart_process_ae_eq ℱ μ s n simp_rw [martingalePart, process, Finset.sum_sub_distrib] at this exact sub_right_injective this #align measure_theory.borel_cantelli.predictable_part_process_ae_eq MeasureTheory.BorelCantelli.predictablePart_process_ae_eq theorem process_difference_le (s : ℕ → Set Ω) (ω : Ω) (n : ℕ) : |process s (n + 1) ω - process s n ω| ≤ (1 : ℝ≥0) := by norm_cast rw [process, process, Finset.sum_apply, Finset.sum_apply, Finset.sum_range_succ_sub_sum, ← Real.norm_eq_abs, norm_indicator_eq_indicator_norm] refine Set.indicator_le' (fun _ _ => ?_) (fun _ _ => zero_le_one) _ rw [Pi.one_apply, norm_one] #align measure_theory.borel_cantelli.process_difference_le MeasureTheory.BorelCantelli.process_difference_le theorem integrable_process (μ : Measure Ω) [IsFiniteMeasure μ] (hs : ∀ n, MeasurableSet[ℱ n] (s n)) (n : ℕ) : Integrable (process s n) μ := integrable_finset_sum' _ fun _ _ => IntegrableOn.integrable_indicator (integrable_const 1) <| ℱ.le _ _ <| hs _ #align measure_theory.borel_cantelli.integrable_process MeasureTheory.BorelCantelli.integrable_process end BorelCantelli open BorelCantelli /-- An a.e. monotone adapted process `f` with uniformly bounded differences converges to `+∞` if and only if its predictable part also converges to `+∞`. -/
Mathlib/Probability/Martingale/BorelCantelli.lean
332
358
theorem tendsto_sum_indicator_atTop_iff [IsFiniteMeasure μ] (hfmono : ∀ᵐ ω ∂μ, ∀ n, f n ω ≤ f (n + 1) ω) (hf : Adapted ℱ f) (hint : ∀ n, Integrable (f n) μ) (hbdd : ∀ᵐ ω ∂μ, ∀ n, |f (n + 1) ω - f n ω| ≤ R) : ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop atTop ↔ Tendsto (fun n => predictablePart f ℱ μ n ω) atTop atTop := by
have h₁ := (martingale_martingalePart hf hint).ae_not_tendsto_atTop_atTop (martingalePart_bdd_difference ℱ hbdd) have h₂ := (martingale_martingalePart hf hint).ae_not_tendsto_atTop_atBot (martingalePart_bdd_difference ℱ hbdd) have h₃ : ∀ᵐ ω ∂μ, ∀ n, 0 ≤ (μ[f (n + 1) - f n|ℱ n]) ω := by refine ae_all_iff.2 fun n => condexp_nonneg ?_ filter_upwards [ae_all_iff.1 hfmono n] with ω hω using sub_nonneg.2 hω filter_upwards [h₁, h₂, h₃, hfmono] with ω hω₁ hω₂ hω₃ hω₄ constructor <;> intro ht · refine tendsto_atTop_atTop_of_monotone' ?_ ?_ · intro n m hnm simp only [predictablePart, Finset.sum_apply] exact Finset.sum_mono_set_of_nonneg hω₃ (Finset.range_mono hnm) rintro ⟨b, hbdd⟩ rw [← tendsto_neg_atBot_iff] at ht simp only [martingalePart, sub_eq_add_neg] at hω₁ exact hω₁ (tendsto_atTop_add_right_of_le _ (-b) (tendsto_neg_atBot_iff.1 ht) fun n => neg_le_neg (hbdd ⟨n, rfl⟩)) · refine tendsto_atTop_atTop_of_monotone' (monotone_nat_of_le_succ hω₄) ?_ rintro ⟨b, hbdd⟩ exact hω₂ ((tendsto_atBot_add_left_of_ge _ b fun n => hbdd ⟨n, rfl⟩) <| tendsto_neg_atBot_iff.2 ht)
/- 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.Fintype.Card import Mathlib.Data.List.MinMax import Mathlib.Data.Nat.Order.Lemmas import Mathlib.Logic.Encodable.Basic #align_import logic.denumerable from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226" /-! # Denumerable types This file defines denumerable (countably infinite) types as a typeclass extending `Encodable`. This is used to provide explicit encode/decode functions from and to `ℕ`, with the information that those functions are inverses of each other. ## Implementation notes This property already has a name, namely `α ≃ ℕ`, but here we are interested in using it as a typeclass. -/ variable {α β : Type*} /-- A denumerable type is (constructively) bijective with `ℕ`. Typeclass equivalent of `α ≃ ℕ`. -/ class Denumerable (α : Type*) extends Encodable α where /-- `decode` and `encode` are inverses. -/ decode_inv : ∀ n, ∃ a ∈ decode n, encode a = n #align denumerable Denumerable open Nat namespace Denumerable section variable [Denumerable α] [Denumerable β] open Encodable theorem decode_isSome (α) [Denumerable α] (n : ℕ) : (decode (α := α) n).isSome := Option.isSome_iff_exists.2 <| (decode_inv n).imp fun _ => And.left #align denumerable.decode_is_some Denumerable.decode_isSome /-- Returns the `n`-th element of `α` indexed by the decoding. -/ def ofNat (α) [Denumerable α] (n : ℕ) : α := Option.get _ (decode_isSome α n) #align denumerable.of_nat Denumerable.ofNat @[simp] theorem decode_eq_ofNat (α) [Denumerable α] (n : ℕ) : decode (α := α) n = some (ofNat α n) := Option.eq_some_of_isSome _ #align denumerable.decode_eq_of_nat Denumerable.decode_eq_ofNat @[simp] theorem ofNat_of_decode {n b} (h : decode (α := α) n = some b) : ofNat (α := α) n = b := Option.some.inj <| (decode_eq_ofNat _ _).symm.trans h #align denumerable.of_nat_of_decode Denumerable.ofNat_of_decode @[simp] theorem encode_ofNat (n) : encode (ofNat α n) = n := by obtain ⟨a, h, e⟩ := decode_inv (α := α) n rwa [ofNat_of_decode h] #align denumerable.encode_of_nat Denumerable.encode_ofNat @[simp] theorem ofNat_encode (a) : ofNat α (encode a) = a := ofNat_of_decode (encodek _) #align denumerable.of_nat_encode Denumerable.ofNat_encode /-- A denumerable type is equivalent to `ℕ`. -/ def eqv (α) [Denumerable α] : α ≃ ℕ := ⟨encode, ofNat α, ofNat_encode, encode_ofNat⟩ #align denumerable.eqv Denumerable.eqv -- See Note [lower instance priority] instance (priority := 100) : Infinite α := Infinite.of_surjective _ (eqv α).surjective /-- A type equivalent to `ℕ` is denumerable. -/ def mk' {α} (e : α ≃ ℕ) : Denumerable α where encode := e decode := some ∘ e.symm encodek _ := congr_arg some (e.symm_apply_apply _) decode_inv _ := ⟨_, rfl, e.apply_symm_apply _⟩ #align denumerable.mk' Denumerable.mk' /-- Denumerability is conserved by equivalences. This is transitivity of equivalence the denumerable way. -/ def ofEquiv (α) {β} [Denumerable α] (e : β ≃ α) : Denumerable β := { Encodable.ofEquiv _ e with decode_inv := fun n => by -- Porting note: replaced `simp` simp_rw [Option.mem_def, decode_ofEquiv e, encode_ofEquiv e, decode_eq_ofNat, Option.map_some', Option.some_inj, exists_eq_left', Equiv.apply_symm_apply, Denumerable.encode_ofNat] } #align denumerable.of_equiv Denumerable.ofEquiv @[simp] theorem ofEquiv_ofNat (α) {β} [Denumerable α] (e : β ≃ α) (n) : @ofNat β (ofEquiv _ e) n = e.symm (ofNat α n) := by -- Porting note: added `letI` letI := ofEquiv _ e refine ofNat_of_decode ?_ rw [decode_ofEquiv e] simp #align denumerable.of_equiv_of_nat Denumerable.ofEquiv_ofNat /-- All denumerable types are equivalent. -/ def equiv₂ (α β) [Denumerable α] [Denumerable β] : α ≃ β := (eqv α).trans (eqv β).symm #align denumerable.equiv₂ Denumerable.equiv₂ instance nat : Denumerable ℕ := ⟨fun _ => ⟨_, rfl, rfl⟩⟩ #align denumerable.nat Denumerable.nat @[simp] theorem ofNat_nat (n) : ofNat ℕ n = n := rfl #align denumerable.of_nat_nat Denumerable.ofNat_nat /-- If `α` is denumerable, then so is `Option α`. -/ instance option : Denumerable (Option α) := ⟨fun n => by cases n with | zero => refine ⟨none, ?_, encode_none⟩ rw [decode_option_zero, Option.mem_def] | succ n => refine ⟨some (ofNat α n), ?_, ?_⟩ · rw [decode_option_succ, decode_eq_ofNat, Option.map_some', Option.mem_def] rw [encode_some, encode_ofNat]⟩ #align denumerable.option Denumerable.option set_option linter.deprecated false in /-- If `α` and `β` are denumerable, then so is their sum. -/ instance sum : Denumerable (Sum α β) := ⟨fun n => by suffices ∃ a ∈ @decodeSum α β _ _ n, encodeSum a = bit (bodd n) (div2 n) by simpa [bit_decomp] simp only [decodeSum, boddDiv2_eq, decode_eq_ofNat, Option.some.injEq, Option.map_some', Option.mem_def, Sum.exists] cases bodd n <;> simp [decodeSum, bit, encodeSum, bit0_eq_two_mul, bit1]⟩ #align denumerable.sum Denumerable.sum section Sigma variable {γ : α → Type*} [∀ a, Denumerable (γ a)] /-- A denumerable collection of denumerable types is denumerable. -/ instance sigma : Denumerable (Sigma γ) := ⟨fun n => by simp [decodeSigma]⟩ #align denumerable.sigma Denumerable.sigma @[simp] theorem sigma_ofNat_val (n : ℕ) : ofNat (Sigma γ) n = ⟨ofNat α (unpair n).1, ofNat (γ _) (unpair n).2⟩ := Option.some.inj <| by rw [← decode_eq_ofNat, decode_sigma_val]; simp #align denumerable.sigma_of_nat_val Denumerable.sigma_ofNat_val end Sigma /-- If `α` and `β` are denumerable, then so is their product. -/ instance prod : Denumerable (α × β) := ofEquiv _ (Equiv.sigmaEquivProd α β).symm #align denumerable.prod Denumerable.prod -- Porting note: removed @[simp] - simp can prove it
Mathlib/Logic/Denumerable.lean
173
174
theorem prod_ofNat_val (n : ℕ) : ofNat (α × β) n = (ofNat α (unpair n).1, ofNat β (unpair n).2) := by
simp
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Analysis.Convex.Hull #align_import analysis.convex.join from "leanprover-community/mathlib"@"951bf1d9e98a2042979ced62c0620bcfb3587cf8" /-! # Convex join This file defines the convex join of two sets. The convex join of `s` and `t` is the union of the segments with one end in `s` and the other in `t`. This is notably a useful gadget to deal with convex hulls of finite sets. -/ open Set variable {ι : Sort*} {𝕜 E : Type*} section OrderedSemiring variable (𝕜) [OrderedSemiring 𝕜] [AddCommMonoid E] [Module 𝕜 E] {s t s₁ s₂ t₁ t₂ u : Set E} {x y : E} /-- The join of two sets is the union of the segments joining them. This can be interpreted as the topological join, but within the original space. -/ def convexJoin (s t : Set E) : Set E := ⋃ (x ∈ s) (y ∈ t), segment 𝕜 x y #align convex_join convexJoin variable {𝕜} theorem mem_convexJoin : x ∈ convexJoin 𝕜 s t ↔ ∃ a ∈ s, ∃ b ∈ t, x ∈ segment 𝕜 a b := by simp [convexJoin] #align mem_convex_join mem_convexJoin theorem convexJoin_comm (s t : Set E) : convexJoin 𝕜 s t = convexJoin 𝕜 t s := (iUnion₂_comm _).trans <| by simp_rw [convexJoin, segment_symm] #align convex_join_comm convexJoin_comm theorem convexJoin_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : convexJoin 𝕜 s₁ t₁ ⊆ convexJoin 𝕜 s₂ t₂ := biUnion_mono hs fun _ _ => biUnion_subset_biUnion_left ht #align convex_join_mono convexJoin_mono theorem convexJoin_mono_left (hs : s₁ ⊆ s₂) : convexJoin 𝕜 s₁ t ⊆ convexJoin 𝕜 s₂ t := convexJoin_mono hs Subset.rfl #align convex_join_mono_left convexJoin_mono_left theorem convexJoin_mono_right (ht : t₁ ⊆ t₂) : convexJoin 𝕜 s t₁ ⊆ convexJoin 𝕜 s t₂ := convexJoin_mono Subset.rfl ht #align convex_join_mono_right convexJoin_mono_right @[simp] theorem convexJoin_empty_left (t : Set E) : convexJoin 𝕜 ∅ t = ∅ := by simp [convexJoin] #align convex_join_empty_left convexJoin_empty_left @[simp] theorem convexJoin_empty_right (s : Set E) : convexJoin 𝕜 s ∅ = ∅ := by simp [convexJoin] #align convex_join_empty_right convexJoin_empty_right @[simp] theorem convexJoin_singleton_left (t : Set E) (x : E) : convexJoin 𝕜 {x} t = ⋃ y ∈ t, segment 𝕜 x y := by simp [convexJoin] #align convex_join_singleton_left convexJoin_singleton_left @[simp] theorem convexJoin_singleton_right (s : Set E) (y : E) : convexJoin 𝕜 s {y} = ⋃ x ∈ s, segment 𝕜 x y := by simp [convexJoin] #align convex_join_singleton_right convexJoin_singleton_right -- Porting note (#10618): simp can prove it theorem convexJoin_singletons (x : E) : convexJoin 𝕜 {x} {y} = segment 𝕜 x y := by simp #align convex_join_singletons convexJoin_singletons @[simp] theorem convexJoin_union_left (s₁ s₂ t : Set E) : convexJoin 𝕜 (s₁ ∪ s₂) t = convexJoin 𝕜 s₁ t ∪ convexJoin 𝕜 s₂ t := by simp_rw [convexJoin, mem_union, iUnion_or, iUnion_union_distrib] #align convex_join_union_left convexJoin_union_left @[simp] theorem convexJoin_union_right (s t₁ t₂ : Set E) : convexJoin 𝕜 s (t₁ ∪ t₂) = convexJoin 𝕜 s t₁ ∪ convexJoin 𝕜 s t₂ := by simp_rw [convexJoin_comm s, convexJoin_union_left] #align convex_join_union_right convexJoin_union_right @[simp] theorem convexJoin_iUnion_left (s : ι → Set E) (t : Set E) : convexJoin 𝕜 (⋃ i, s i) t = ⋃ i, convexJoin 𝕜 (s i) t := by simp_rw [convexJoin, mem_iUnion, iUnion_exists] exact iUnion_comm _ #align convex_join_Union_left convexJoin_iUnion_left @[simp] theorem convexJoin_iUnion_right (s : Set E) (t : ι → Set E) : convexJoin 𝕜 s (⋃ i, t i) = ⋃ i, convexJoin 𝕜 s (t i) := by simp_rw [convexJoin_comm s, convexJoin_iUnion_left] #align convex_join_Union_right convexJoin_iUnion_right theorem segment_subset_convexJoin (hx : x ∈ s) (hy : y ∈ t) : segment 𝕜 x y ⊆ convexJoin 𝕜 s t := subset_iUnion₂_of_subset x hx <| subset_iUnion₂ (s := fun y _ ↦ segment 𝕜 x y) y hy #align segment_subset_convex_join segment_subset_convexJoin theorem subset_convexJoin_left (h : t.Nonempty) : s ⊆ convexJoin 𝕜 s t := fun _x hx => let ⟨_y, hy⟩ := h segment_subset_convexJoin hx hy <| left_mem_segment _ _ _ #align subset_convex_join_left subset_convexJoin_left theorem subset_convexJoin_right (h : s.Nonempty) : t ⊆ convexJoin 𝕜 s t := convexJoin_comm (𝕜 := 𝕜) t s ▸ subset_convexJoin_left h #align subset_convex_join_right subset_convexJoin_right theorem convexJoin_subset (hs : s ⊆ u) (ht : t ⊆ u) (hu : Convex 𝕜 u) : convexJoin 𝕜 s t ⊆ u := iUnion₂_subset fun _x hx => iUnion₂_subset fun _y hy => hu.segment_subset (hs hx) (ht hy) #align convex_join_subset convexJoin_subset theorem convexJoin_subset_convexHull (s t : Set E) : convexJoin 𝕜 s t ⊆ convexHull 𝕜 (s ∪ t) := convexJoin_subset (subset_union_left.trans <| subset_convexHull _ _) (subset_union_right.trans <| subset_convexHull _ _) <| convex_convexHull _ _ #align convex_join_subset_convex_hull convexJoin_subset_convexHull end OrderedSemiring section LinearOrderedField variable [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {s t u : Set E} {x y : E} theorem convexJoin_assoc_aux (s t u : Set E) : convexJoin 𝕜 (convexJoin 𝕜 s t) u ⊆ convexJoin 𝕜 s (convexJoin 𝕜 t u) := by simp_rw [subset_def, mem_convexJoin] rintro _ ⟨z, ⟨x, hx, y, hy, a₁, b₁, ha₁, hb₁, hab₁, rfl⟩, z, hz, a₂, b₂, ha₂, hb₂, hab₂, rfl⟩ obtain rfl | hb₂ := hb₂.eq_or_lt · refine ⟨x, hx, y, ⟨y, hy, z, hz, left_mem_segment 𝕜 _ _⟩, a₁, b₁, ha₁, hb₁, hab₁, ?_⟩ rw [add_zero] at hab₂ rw [hab₂, one_smul, zero_smul, add_zero] have ha₂b₁ : 0 ≤ a₂ * b₁ := mul_nonneg ha₂ hb₁ have hab : 0 < a₂ * b₁ + b₂ := add_pos_of_nonneg_of_pos ha₂b₁ hb₂ refine ⟨x, hx, (a₂ * b₁ / (a₂ * b₁ + b₂)) • y + (b₂ / (a₂ * b₁ + b₂)) • z, ⟨y, hy, z, hz, _, _, ?_, ?_, ?_, rfl⟩, a₂ * a₁, a₂ * b₁ + b₂, mul_nonneg ha₂ ha₁, hab.le, ?_, ?_⟩ · exact div_nonneg ha₂b₁ hab.le · exact div_nonneg hb₂.le hab.le · rw [← add_div, div_self hab.ne'] · rw [← add_assoc, ← mul_add, hab₁, mul_one, hab₂] · simp_rw [smul_add, ← mul_smul, mul_div_cancel₀ _ hab.ne', add_assoc] #align convex_join_assoc_aux convexJoin_assoc_aux theorem convexJoin_assoc (s t u : Set E) : convexJoin 𝕜 (convexJoin 𝕜 s t) u = convexJoin 𝕜 s (convexJoin 𝕜 t u) := by refine (convexJoin_assoc_aux _ _ _).antisymm ?_ simp_rw [convexJoin_comm s, convexJoin_comm _ u] exact convexJoin_assoc_aux _ _ _ #align convex_join_assoc convexJoin_assoc theorem convexJoin_left_comm (s t u : Set E) : convexJoin 𝕜 s (convexJoin 𝕜 t u) = convexJoin 𝕜 t (convexJoin 𝕜 s u) := by simp_rw [← convexJoin_assoc, convexJoin_comm] #align convex_join_left_comm convexJoin_left_comm theorem convexJoin_right_comm (s t u : Set E) : convexJoin 𝕜 (convexJoin 𝕜 s t) u = convexJoin 𝕜 (convexJoin 𝕜 s u) t := by simp_rw [convexJoin_assoc, convexJoin_comm] #align convex_join_right_comm convexJoin_right_comm theorem convexJoin_convexJoin_convexJoin_comm (s t u v : Set E) : convexJoin 𝕜 (convexJoin 𝕜 s t) (convexJoin 𝕜 u v) = convexJoin 𝕜 (convexJoin 𝕜 s u) (convexJoin 𝕜 t v) := by simp_rw [← convexJoin_assoc, convexJoin_right_comm] #align convex_join_convex_join_convex_join_comm convexJoin_convexJoin_convexJoin_comm -- Porting note: moved 3 lemmas from below to golf protected theorem Convex.convexJoin (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (convexJoin 𝕜 s t) := by simp only [Convex, StarConvex, convexJoin, mem_iUnion] rintro _ ⟨x₁, hx₁, y₁, hy₁, a₁, b₁, ha₁, hb₁, hab₁, rfl⟩ _ ⟨x₂, hx₂, y₂, hy₂, a₂, b₂, ha₂, hb₂, hab₂, rfl⟩ p q hp hq hpq rcases hs.exists_mem_add_smul_eq hx₁ hx₂ (mul_nonneg hp ha₁) (mul_nonneg hq ha₂) with ⟨x, hxs, hx⟩ rcases ht.exists_mem_add_smul_eq hy₁ hy₂ (mul_nonneg hp hb₁) (mul_nonneg hq hb₂) with ⟨y, hyt, hy⟩ refine ⟨_, hxs, _, hyt, p * a₁ + q * a₂, p * b₁ + q * b₂, ?_, ?_, ?_, ?_⟩ <;> try positivity · rwa [add_add_add_comm, ← mul_add, ← mul_add, hab₁, hab₂, mul_one, mul_one] · rw [hx, hy, add_add_add_comm] simp only [smul_add, smul_smul] #align convex.convex_join Convex.convexJoin protected theorem Convex.convexHull_union (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) (hs₀ : s.Nonempty) (ht₀ : t.Nonempty) : convexHull 𝕜 (s ∪ t) = convexJoin 𝕜 s t := (convexHull_min (union_subset (subset_convexJoin_left ht₀) <| subset_convexJoin_right hs₀) <| hs.convexJoin ht).antisymm <| convexJoin_subset_convexHull _ _ #align convex.convex_hull_union Convex.convexHull_union theorem convexHull_union (hs : s.Nonempty) (ht : t.Nonempty) : convexHull 𝕜 (s ∪ t) = convexJoin 𝕜 (convexHull 𝕜 s) (convexHull 𝕜 t) := by rw [← convexHull_convexHull_union_left, ← convexHull_convexHull_union_right] exact (convex_convexHull 𝕜 s).convexHull_union (convex_convexHull 𝕜 t) hs.convexHull ht.convexHull #align convex_hull_union convexHull_union
Mathlib/Analysis/Convex/Join.lean
203
205
theorem convexHull_insert (hs : s.Nonempty) : convexHull 𝕜 (insert x s) = convexJoin 𝕜 {x} (convexHull 𝕜 s) := by
rw [insert_eq, convexHull_union (singleton_nonempty _) hs, convexHull_singleton]
/- 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 -/ import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SumOverResidueClass #align_import analysis.p_series from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8" /-! # Convergence of `p`-series In this file we prove that the series `∑' k in ℕ, 1 / k ^ p` converges if and only if `p > 1`. The proof is based on the [Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `∑ k, f k` converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. We prove this test in `NNReal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove `summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series. ## Tags p-series, Cauchy condensation test -/ /-! ### Schlömilch's generalization of the Cauchy condensation test In this section we prove the Schlömilch's generalization of the Cauchy condensation test: for a strictly increasing `u : ℕ → ℕ` with ratio of successive differences bounded and an antitone `f : ℕ → ℝ≥0` or `f : ℕ → ℝ`, `∑ k, f k` converges if and only if so does `∑ k, (u (k + 1) - u k) * f (u k)`. Instead of giving a monolithic proof, we split it into a series of lemmas with explicit estimates of partial sums of each series in terms of the partial sums of the other series. -/ /-- A sequence `u` has the property that its ratio of successive differences is bounded when there is a positive real number `C` such that, for all n ∈ ℕ, (u (n + 2) - u (n + 1)) ≤ C * (u (n + 1) - u n) -/ def SuccDiffBounded (C : ℕ) (u : ℕ → ℕ) : Prop := ∀ n : ℕ, u (n + 2) - u (n + 1) ≤ C • (u (n + 1) - u n) namespace Finset variable {M : Type*} [OrderedAddCommMonoid M] {f : ℕ → M} {u : ℕ → ℕ} theorem le_sum_schlomilch' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : Monotone u) (n : ℕ) : (∑ k ∈ Ico (u 0) (u n), f k) ≤ ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by induction' n with n ihn · simp suffices (∑ k ∈ Ico (u n) (u (n + 1)), f k) ≤ (u (n + 1) - u n) • f (u n) by rw [sum_range_succ, ← sum_Ico_consecutive] · exact add_le_add ihn this exacts [hu n.zero_le, hu n.le_succ] have : ∀ k ∈ Ico (u n) (u (n + 1)), f k ≤ f (u n) := fun k hk => hf (Nat.succ_le_of_lt (h_pos n)) (mem_Ico.mp hk).1 convert sum_le_sum this simp [pow_succ, mul_two] theorem le_sum_condensed' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ Ico 1 (2 ^ n), f k) ≤ ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by convert le_sum_schlomilch' hf (fun n => pow_pos zero_lt_two n) (fun m n hm => pow_le_pow_right one_le_two hm) n using 2 simp [pow_succ, mul_two, two_mul] #align finset.le_sum_condensed' Finset.le_sum_condensed' theorem le_sum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : Monotone u) (n : ℕ) : (∑ k ∈ range (u n), f k) ≤ ∑ k ∈ range (u 0), f k + ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by convert add_le_add_left (le_sum_schlomilch' hf h_pos hu n) (∑ k ∈ range (u 0), f k) rw [← sum_range_add_sum_Ico _ (hu n.zero_le)] theorem le_sum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ range (2 ^ n), f k) ≤ f 0 + ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by convert add_le_add_left (le_sum_condensed' hf n) (f 0) rw [← sum_range_add_sum_Ico _ n.one_le_two_pow, sum_range_succ, sum_range_zero, zero_add] #align finset.le_sum_condensed Finset.le_sum_condensed theorem sum_schlomilch_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : Monotone u) (n : ℕ) : (∑ k ∈ range n, (u (k + 1) - u k) • f (u (k + 1))) ≤ ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by induction' n with n ihn · simp suffices (u (n + 1) - u n) • f (u (n + 1)) ≤ ∑ k ∈ Ico (u n + 1) (u (n + 1) + 1), f k by rw [sum_range_succ, ← sum_Ico_consecutive] exacts [add_le_add ihn this, (add_le_add_right (hu n.zero_le) _ : u 0 + 1 ≤ u n + 1), add_le_add_right (hu n.le_succ) _] have : ∀ k ∈ Ico (u n + 1) (u (n + 1) + 1), f (u (n + 1)) ≤ f k := fun k hk => hf (Nat.lt_of_le_of_lt (Nat.succ_le_of_lt (h_pos n)) <| (Nat.lt_succ_of_le le_rfl).trans_le (mem_Ico.mp hk).1) (Nat.le_of_lt_succ <| (mem_Ico.mp hk).2) convert sum_le_sum this simp [pow_succ, mul_two] theorem sum_condensed_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ range n, 2 ^ k • f (2 ^ (k + 1))) ≤ ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by convert sum_schlomilch_le' hf (fun n => pow_pos zero_lt_two n) (fun m n hm => pow_le_pow_right one_le_two hm) n using 2 simp [pow_succ, mul_two, two_mul] #align finset.sum_condensed_le' Finset.sum_condensed_le' theorem sum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) (n : ℕ) : ∑ k ∈ range (n + 1), (u (k + 1) - u k) • f (u k) ≤ (u 1 - u 0) • f (u 0) + C • ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by rw [sum_range_succ', add_comm] gcongr suffices ∑ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤ C • ∑ k ∈ range n, ((u (k + 1) - u k) • f (u (k + 1))) by refine this.trans (nsmul_le_nsmul_right ?_ _) exact sum_schlomilch_le' hf h_pos hu n have : ∀ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤ C • ((u (k + 1) - u k) • f (u (k + 1))) := by intro k _ rw [smul_smul] gcongr · exact h_nonneg (u (k + 1)) exact mod_cast h_succ_diff k convert sum_le_sum this simp [smul_sum] theorem sum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) : (∑ k ∈ range (n + 1), 2 ^ k • f (2 ^ k)) ≤ f 1 + 2 • ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by convert add_le_add_left (nsmul_le_nsmul_right (sum_condensed_le' hf n) 2) (f 1) simp [sum_range_succ', add_comm, pow_succ', mul_nsmul', sum_nsmul] #align finset.sum_condensed_le Finset.sum_condensed_le end Finset namespace ENNReal open Filter Finset variable {u : ℕ → ℕ} {f : ℕ → ℝ≥0∞} open NNReal in theorem le_tsum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu : StrictMono u) : ∑' k , f k ≤ ∑ k ∈ range (u 0), f k + ∑' k : ℕ, (u (k + 1) - u k) * f (u k) := by rw [ENNReal.tsum_eq_iSup_nat' hu.tendsto_atTop] refine iSup_le fun n => (Finset.le_sum_schlomilch hf h_pos hu.monotone n).trans (add_le_add_left ?_ _) have (k : ℕ) : (u (k + 1) - u k : ℝ≥0∞) = (u (k + 1) - (u k : ℕ) : ℕ) := by simp [NNReal.coe_sub (Nat.cast_le (α := ℝ≥0).mpr <| (hu k.lt_succ_self).le)] simp only [nsmul_eq_mul, this] apply ENNReal.sum_le_tsum theorem le_tsum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) : ∑' k, f k ≤ f 0 + ∑' k : ℕ, 2 ^ k * f (2 ^ k) := by rw [ENNReal.tsum_eq_iSup_nat' (Nat.tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two)] refine iSup_le fun n => (Finset.le_sum_condensed hf n).trans (add_le_add_left ?_ _) simp only [nsmul_eq_mul, Nat.cast_pow, Nat.cast_two] apply ENNReal.sum_le_tsum #align ennreal.le_tsum_condensed ENNReal.le_tsum_condensed theorem tsum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) : ∑' k : ℕ, (u (k + 1) - u k) * f (u k) ≤ (u 1 - u 0) * f (u 0) + C * ∑' k, f k := by rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id)] refine iSup_le fun n => le_trans ?_ (add_le_add_left (mul_le_mul_of_nonneg_left (ENNReal.sum_le_tsum <| Finset.Ico (u 0 + 1) (u n + 1)) ?_) _) simpa using Finset.sum_schlomilch_le hf h_pos h_nonneg hu h_succ_diff n exact zero_le _ theorem tsum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) : (∑' k : ℕ, 2 ^ k * f (2 ^ k)) ≤ f 1 + 2 * ∑' k, f k := by rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id), two_mul, ← two_nsmul] refine iSup_le fun n => le_trans ?_ (add_le_add_left (nsmul_le_nsmul_right (ENNReal.sum_le_tsum <| Finset.Ico 2 (2 ^ n + 1)) _) _) simpa using Finset.sum_condensed_le hf n #align ennreal.tsum_condensed_le ENNReal.tsum_condensed_le end ENNReal namespace NNReal open Finset open ENNReal in /-- for a series of `NNReal` version. -/ theorem summable_schlomilch_iff {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ≥0} (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu_strict : StrictMono u) (hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) : (Summable fun k : ℕ => (u (k + 1) - (u k : ℝ≥0)) * f (u k)) ↔ Summable f := by simp only [← tsum_coe_ne_top_iff_summable, Ne, not_iff_not, ENNReal.coe_mul] constructor <;> intro h · replace hf : ∀ m n, 1 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn => ENNReal.coe_le_coe.2 (hf (zero_lt_one.trans hm) hmn) have h_nonneg : ∀ n, 0 ≤ (f n : ℝ≥0∞) := fun n => ENNReal.coe_le_coe.2 (f n).2 obtain hC := tsum_schlomilch_le hf h_pos h_nonneg hu_strict.monotone h_succ_diff simpa [add_eq_top, mul_ne_top, mul_eq_top, hC_nonzero] using eq_top_mono hC h · replace hf : ∀ m n, 0 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn => ENNReal.coe_le_coe.2 (hf hm hmn) have : ∑ k ∈ range (u 0), (f k : ℝ≥0∞) ≠ ∞ := (sum_lt_top fun a _ => coe_ne_top).ne simpa [h, add_eq_top, this] using le_tsum_schlomilch hf h_pos hu_strict open ENNReal in theorem summable_condensed_iff {f : ℕ → ℝ≥0} (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) : (Summable fun k : ℕ => (2 : ℝ≥0) ^ k * f (2 ^ k)) ↔ Summable f := by have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by intro n simp [pow_succ, mul_two, two_mul] convert summable_schlomilch_iff hf (pow_pos zero_lt_two) (pow_right_strictMono _root_.one_lt_two) two_ne_zero h_succ_diff simp [pow_succ, mul_two, two_mul] #align nnreal.summable_condensed_iff NNReal.summable_condensed_iff end NNReal open NNReal in /-- for series of nonnegative real numbers. -/ theorem summable_schlomilch_iff_of_nonneg {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n) (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n) (hu_strict : StrictMono u) (hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) : (Summable fun k : ℕ => (u (k + 1) - (u k : ℝ)) * f (u k)) ↔ Summable f := by lift f to ℕ → ℝ≥0 using h_nonneg simp only [NNReal.coe_le_coe] at * have (k : ℕ) : (u (k + 1) - (u k : ℝ)) = ((u (k + 1) : ℝ≥0) - (u k : ℝ≥0) : ℝ≥0) := by have := Nat.cast_le (α := ℝ≥0).mpr <| (hu_strict k.lt_succ_self).le simp [NNReal.coe_sub this] simp_rw [this] exact_mod_cast NNReal.summable_schlomilch_iff hf h_pos hu_strict hC_nonzero h_succ_diff /-- Cauchy condensation test for antitone series of nonnegative real numbers. -/ theorem summable_condensed_iff_of_nonneg {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n) (h_mono : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) : (Summable fun k : ℕ => (2 : ℝ) ^ k * f (2 ^ k)) ↔ Summable f := by have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by intro n simp [pow_succ, mul_two, two_mul] convert summable_schlomilch_iff_of_nonneg h_nonneg h_mono (pow_pos zero_lt_two) (pow_right_strictMono one_lt_two) two_ne_zero h_succ_diff simp [pow_succ, mul_two, two_mul] #align summable_condensed_iff_of_nonneg summable_condensed_iff_of_nonneg section p_series /-! ### Convergence of the `p`-series In this section we prove that for a real number `p`, the series `∑' n : ℕ, 1 / (n ^ p)` converges if and only if `1 < p`. There are many different proofs of this fact. The proof in this file uses the Cauchy condensation test we formalized above. This test implies that `∑ n, 1 / (n ^ p)` converges if and only if `∑ n, 2 ^ n / ((2 ^ n) ^ p)` converges, and the latter series is a geometric series with common ratio `2 ^ {1 - p}`. -/ namespace Real open Filter /-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges if and only if `1 < p`. -/ @[simp] theorem summable_nat_rpow_inv {p : ℝ} : Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by rcases le_or_lt 0 p with hp | hp /- Cauchy condensation test applies only to antitone sequences, so we consider the cases `0 ≤ p` and `p < 0` separately. -/ · rw [← summable_condensed_iff_of_nonneg] · simp_rw [Nat.cast_pow, Nat.cast_two, ← rpow_natCast, ← rpow_mul zero_lt_two.le, mul_comm _ p, rpow_mul zero_lt_two.le, rpow_natCast, ← inv_pow, ← mul_pow, summable_geometric_iff_norm_lt_one] nth_rw 1 [← rpow_one 2] rw [← division_def, ← rpow_sub zero_lt_two, norm_eq_abs, abs_of_pos (rpow_pos_of_pos zero_lt_two _), rpow_lt_one_iff zero_lt_two.le] norm_num · intro n positivity · intro m n hm hmn gcongr -- If `p < 0`, then `1 / n ^ p` tends to infinity, thus the series diverges. · suffices ¬Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) by have : ¬1 < p := fun hp₁ => hp.not_le (zero_le_one.trans hp₁.le) simpa only [this, iff_false] intro h obtain ⟨k : ℕ, hk₁ : ((k : ℝ) ^ p)⁻¹ < 1, hk₀ : k ≠ 0⟩ := ((h.tendsto_cofinite_zero.eventually (gt_mem_nhds zero_lt_one)).and (eventually_cofinite_ne 0)).exists apply hk₀ rw [← pos_iff_ne_zero, ← @Nat.cast_pos ℝ] at hk₀ simpa [inv_lt_one_iff_of_pos (rpow_pos_of_pos hk₀ _), one_lt_rpow_iff_of_pos hk₀, hp, hp.not_lt, hk₀] using hk₁ #align real.summable_nat_rpow_inv Real.summable_nat_rpow_inv @[simp] theorem summable_nat_rpow {p : ℝ} : Summable (fun n => (n : ℝ) ^ p : ℕ → ℝ) ↔ p < -1 := by rcases neg_surjective p with ⟨p, rfl⟩ simp [rpow_neg] #align real.summable_nat_rpow Real.summable_nat_rpow /-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges if and only if `1 < p`. -/ theorem summable_one_div_nat_rpow {p : ℝ} : Summable (fun n => 1 / (n : ℝ) ^ p : ℕ → ℝ) ↔ 1 < p := by simp #align real.summable_one_div_nat_rpow Real.summable_one_div_nat_rpow /-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges if and only if `1 < p`. -/ @[simp] theorem summable_nat_pow_inv {p : ℕ} : Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by simp only [← rpow_natCast, summable_nat_rpow_inv, Nat.one_lt_cast] #align real.summable_nat_pow_inv Real.summable_nat_pow_inv /-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges if and only if `1 < p`. -/ theorem summable_one_div_nat_pow {p : ℕ} : Summable (fun n => 1 / (n : ℝ) ^ p : ℕ → ℝ) ↔ 1 < p := by simp only [one_div, Real.summable_nat_pow_inv] #align real.summable_one_div_nat_pow Real.summable_one_div_nat_pow /-- Summability of the `p`-series over `ℤ`. -/
Mathlib/Analysis/PSeries.lean
327
332
theorem summable_one_div_int_pow {p : ℕ} : (Summable fun n : ℤ ↦ 1 / (n : ℝ) ^ p) ↔ 1 < p := by
refine ⟨fun h ↦ summable_one_div_nat_pow.mp (h.comp_injective Nat.cast_injective), fun h ↦ .of_nat_of_neg (summable_one_div_nat_pow.mpr h) (((summable_one_div_nat_pow.mpr h).mul_left <| 1 / (-1 : ℝ) ^ p).congr fun n ↦ ?_)⟩ rw [Int.cast_neg, Int.cast_natCast, neg_eq_neg_one_mul (n : ℝ), mul_pow, mul_one_div, div_div]
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Adjunction.Basic import Mathlib.CategoryTheory.Conj #align_import category_theory.adjunction.mates from "leanprover-community/mathlib"@"cea27692b3fdeb328a2ddba6aabf181754543184" /-! # Mate of natural transformations This file establishes the bijection between the 2-cells L₁ R₁ C --→ D C ←-- D G ↓ ↗ ↓ H G ↓ ↘ ↓ H E --→ F E ←-- F L₂ R₂ where `L₁ ⊣ R₁` and `L₂ ⊣ R₂`, and shows that in the special case where `G,H` are identity then the bijection preserves and reflects isomorphisms (i.e. we have bijections `(L₂ ⟶ L₁) ≃ (R₁ ⟶ R₂)`, and if either side is an iso then the other side is as well). On its own, this bijection is not particularly useful but it includes a number of interesting cases as specializations. For instance, this generalises the fact that adjunctions are unique (since if `L₁ ≅ L₂` then we deduce `R₁ ≅ R₂`). Another example arises from considering the square representing that a functor `H` preserves products, in particular the morphism `HA ⨯ H- ⟶ H(A ⨯ -)`. Then provided `(A ⨯ -)` and `HA ⨯ -` have left adjoints (for instance if the relevant categories are cartesian closed), the transferred natural transformation is the exponential comparison morphism: `H(A ^ -) ⟶ HA ^ H-`. Furthermore if `H` has a left adjoint `L`, this morphism is an isomorphism iff its mate `L(HA ⨯ -) ⟶ A ⨯ L-` is an isomorphism, see https://ncatlab.org/nlab/show/Frobenius+reciprocity#InCategoryTheory. This also relates to Grothendieck's yoga of six operations, though this is not spelled out in mathlib: https://ncatlab.org/nlab/show/six+operations. -/ universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ namespace CategoryTheory open Category variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] section Square variable {E : Type u₃} {F : Type u₄} [Category.{v₃} E] [Category.{v₄} F] variable {G : C ⥤ E} {H : D ⥤ F} {L₁ : C ⥤ D} {R₁ : D ⥤ C} {L₂ : E ⥤ F} {R₂ : F ⥤ E} variable (adj₁ : L₁ ⊣ R₁) (adj₂ : L₂ ⊣ R₂) /-- Suppose we have a square of functors (where the top and bottom are adjunctions `L₁ ⊣ R₁` and `L₂ ⊣ R₂` respectively). C ↔ D G ↓ ↓ H E ↔ F Then we have a bijection between natural transformations `G ⋙ L₂ ⟶ L₁ ⋙ H` and `R₁ ⋙ G ⟶ H ⋙ R₂`. This can be seen as a bijection of the 2-cells: L₁ R₁ C --→ D C ←-- D G ↓ ↗ ↓ H G ↓ ↘ ↓ H E --→ F E ←-- F L₂ R₂ Note that if one of the transformations is an iso, it does not imply the other is an iso. -/ def transferNatTrans : (G ⋙ L₂ ⟶ L₁ ⋙ H) ≃ (R₁ ⋙ G ⟶ H ⋙ R₂) where toFun h := { app := fun X => adj₂.unit.app _ ≫ R₂.map (h.app _ ≫ H.map (adj₁.counit.app _)) naturality := fun X Y f => by dsimp rw [assoc, ← R₂.map_comp, assoc, ← H.map_comp, ← adj₁.counit_naturality, H.map_comp, ← Functor.comp_map L₁, ← h.naturality_assoc] simp } invFun h := { app := fun X => L₂.map (G.map (adj₁.unit.app _) ≫ h.app _) ≫ adj₂.counit.app _ naturality := fun X Y f => by dsimp rw [← L₂.map_comp_assoc, ← G.map_comp_assoc, ← adj₁.unit_naturality, G.map_comp_assoc, ← Functor.comp_map, h.naturality] simp } left_inv h := by ext X dsimp simp only [L₂.map_comp, assoc, adj₂.counit_naturality, adj₂.left_triangle_components_assoc, ← Functor.comp_map G L₂, h.naturality_assoc, Functor.comp_map L₁, ← H.map_comp, adj₁.left_triangle_components] dsimp simp only [id_comp, ← Functor.comp_map, ← Functor.comp_obj, NatTrans.naturality_assoc] simp only [Functor.comp_obj, Functor.comp_map, ← Functor.map_comp] have : Prefunctor.map L₁.toPrefunctor (NatTrans.app adj₁.unit X) ≫ NatTrans.app adj₁.counit (Prefunctor.obj L₁.toPrefunctor X) = 𝟙 _ := by simp simp [this] -- See library note [dsimp, simp]. right_inv h := by ext X dsimp simp [-Functor.comp_map, ← Functor.comp_map H, Functor.comp_map R₁, -NatTrans.naturality, ← h.naturality, -Functor.map_comp, ← Functor.map_comp_assoc G, R₂.map_comp] #align category_theory.transfer_nat_trans CategoryTheory.transferNatTrans theorem transferNatTrans_counit (f : G ⋙ L₂ ⟶ L₁ ⋙ H) (Y : D) : L₂.map ((transferNatTrans adj₁ adj₂ f).app _) ≫ adj₂.counit.app _ = f.app _ ≫ H.map (adj₁.counit.app Y) := by erw [Functor.map_comp] simp #align category_theory.transfer_nat_trans_counit CategoryTheory.transferNatTrans_counit theorem unit_transferNatTrans (f : G ⋙ L₂ ⟶ L₁ ⋙ H) (X : C) : G.map (adj₁.unit.app X) ≫ (transferNatTrans adj₁ adj₂ f).app _ = adj₂.unit.app _ ≫ R₂.map (f.app _) := by dsimp [transferNatTrans] rw [← adj₂.unit_naturality_assoc, ← R₂.map_comp, ← Functor.comp_map G L₂, f.naturality_assoc, Functor.comp_map, ← H.map_comp] dsimp; simp #align category_theory.unit_transfer_nat_trans CategoryTheory.unit_transferNatTrans -- See library note [dsimp, simp] end Square section Self variable {L₁ L₂ L₃ : C ⥤ D} {R₁ R₂ R₃ : D ⥤ C} variable (adj₁ : L₁ ⊣ R₁) (adj₂ : L₂ ⊣ R₂) (adj₃ : L₃ ⊣ R₃) /-- Given two adjunctions `L₁ ⊣ R₁` and `L₂ ⊣ R₂` both between categories `C`, `D`, there is a bijection between natural transformations `L₂ ⟶ L₁` and natural transformations `R₁ ⟶ R₂`. This is defined as a special case of `transferNatTrans`, where the two "vertical" functors are identity. TODO: Generalise to when the two vertical functors are equivalences rather than being exactly `𝟭`. Furthermore, this bijection preserves (and reflects) isomorphisms, i.e. a transformation is an iso iff its image under the bijection is an iso, see eg `CategoryTheory.transferNatTransSelf_iso`. This is in contrast to the general case `transferNatTrans` which does not in general have this property. -/ def transferNatTransSelf : (L₂ ⟶ L₁) ≃ (R₁ ⟶ R₂) := calc (L₂ ⟶ L₁) ≃ _ := (Iso.homCongr L₂.leftUnitor L₁.rightUnitor).symm _ ≃ _ := transferNatTrans adj₁ adj₂ _ ≃ (R₁ ⟶ R₂) := R₁.rightUnitor.homCongr R₂.leftUnitor #align category_theory.transfer_nat_trans_self CategoryTheory.transferNatTransSelf theorem transferNatTransSelf_counit (f : L₂ ⟶ L₁) (X) : L₂.map ((transferNatTransSelf adj₁ adj₂ f).app _) ≫ adj₂.counit.app X = f.app _ ≫ adj₁.counit.app X := by dsimp [transferNatTransSelf] rw [id_comp, comp_id] have := transferNatTrans_counit adj₁ adj₂ (L₂.leftUnitor.hom ≫ f ≫ L₁.rightUnitor.inv) X dsimp at this rw [this] simp #align category_theory.transfer_nat_trans_self_counit CategoryTheory.transferNatTransSelf_counit theorem unit_transferNatTransSelf (f : L₂ ⟶ L₁) (X) : adj₁.unit.app _ ≫ (transferNatTransSelf adj₁ adj₂ f).app _ = adj₂.unit.app X ≫ R₂.map (f.app _) := by dsimp [transferNatTransSelf] rw [id_comp, comp_id] have := unit_transferNatTrans adj₁ adj₂ (L₂.leftUnitor.hom ≫ f ≫ L₁.rightUnitor.inv) X dsimp at this rw [this] simp #align category_theory.unit_transfer_nat_trans_self CategoryTheory.unit_transferNatTransSelf @[simp]
Mathlib/CategoryTheory/Adjunction/Mates.lean
176
179
theorem transferNatTransSelf_id : transferNatTransSelf adj₁ adj₁ (𝟙 _) = 𝟙 _ := by
ext dsimp [transferNatTransSelf, transferNatTrans] simp
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Data.Finset.Sort import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Sign import Mathlib.LinearAlgebra.AffineSpace.Combination import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv import Mathlib.LinearAlgebra.Basis.VectorSpace #align_import linear_algebra.affine_space.independent from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0" /-! # Affine independence This file defines affinely independent families of points. ## Main definitions * `AffineIndependent` defines affinely independent families of points as those where no nontrivial weighted subtraction is `0`. This is proved equivalent to two other formulations: linear independence of the results of subtracting a base point in the family from the other points in the family, or any equal affine combinations having the same weights. A bundled type `Simplex` is provided for finite affinely independent families of points, with an abbreviation `Triangle` for the case of three points. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Finset Function open scoped Affine section AffineIndependent variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} /-- An indexed family is said to be affinely independent if no nontrivial weighted subtractions (where the sum of weights is 0) are 0. -/ def AffineIndependent (p : ι → P) : Prop := ∀ (s : Finset ι) (w : ι → k), ∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0 #align affine_independent AffineIndependent /-- The definition of `AffineIndependent`. -/ theorem affineIndependent_def (p : ι → P) : AffineIndependent k p ↔ ∀ (s : Finset ι) (w : ι → k), ∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0 := Iff.rfl #align affine_independent_def affineIndependent_def /-- A family with at most one point is affinely independent. -/ theorem affineIndependent_of_subsingleton [Subsingleton ι] (p : ι → P) : AffineIndependent k p := fun _ _ h _ i hi => Fintype.eq_of_subsingleton_of_sum_eq h i hi #align affine_independent_of_subsingleton affineIndependent_of_subsingleton /-- A family indexed by a `Fintype` is affinely independent if and only if no nontrivial weighted subtractions over `Finset.univ` (where the sum of the weights is 0) are 0. -/ theorem affineIndependent_iff_of_fintype [Fintype ι] (p : ι → P) : AffineIndependent k p ↔ ∀ w : ι → k, ∑ i, w i = 0 → Finset.univ.weightedVSub p w = (0 : V) → ∀ i, w i = 0 := by constructor · exact fun h w hw hs i => h Finset.univ w hw hs i (Finset.mem_univ _) · intro h s w hw hs i hi rw [Finset.weightedVSub_indicator_subset _ _ (Finset.subset_univ s)] at hs rw [← Finset.sum_indicator_subset _ (Finset.subset_univ s)] at hw replace h := h ((↑s : Set ι).indicator w) hw hs i simpa [hi] using h #align affine_independent_iff_of_fintype affineIndependent_iff_of_fintype /-- A family is affinely independent if and only if the differences from a base point in that family are linearly independent. -/ theorem affineIndependent_iff_linearIndependent_vsub (p : ι → P) (i1 : ι) : AffineIndependent k p ↔ LinearIndependent k fun i : { x // x ≠ i1 } => (p i -ᵥ p i1 : V) := by classical constructor · intro h rw [linearIndependent_iff'] intro s g hg i hi set f : ι → k := fun x => if hx : x = i1 then -∑ y ∈ s, g y else g ⟨x, hx⟩ with hfdef let s2 : Finset ι := insert i1 (s.map (Embedding.subtype _)) have hfg : ∀ x : { x // x ≠ i1 }, g x = f x := by intro x rw [hfdef] dsimp only erw [dif_neg x.property, Subtype.coe_eta] rw [hfg] have hf : ∑ ι ∈ s2, f ι = 0 := by rw [Finset.sum_insert (Finset.not_mem_map_subtype_of_not_property s (Classical.not_not.2 rfl)), Finset.sum_subtype_map_embedding fun x _ => (hfg x).symm] rw [hfdef] dsimp only rw [dif_pos rfl] exact neg_add_self _ have hs2 : s2.weightedVSub p f = (0 : V) := by set f2 : ι → V := fun x => f x • (p x -ᵥ p i1) with hf2def set g2 : { x // x ≠ i1 } → V := fun x => g x • (p x -ᵥ p i1) have hf2g2 : ∀ x : { x // x ≠ i1 }, f2 x = g2 x := by simp only [g2, hf2def] refine fun x => ?_ rw [hfg] rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s2 f p hf (p i1), Finset.weightedVSubOfPoint_insert, Finset.weightedVSubOfPoint_apply, Finset.sum_subtype_map_embedding fun x _ => hf2g2 x] exact hg exact h s2 f hf hs2 i (Finset.mem_insert_of_mem (Finset.mem_map.2 ⟨i, hi, rfl⟩)) · intro h rw [linearIndependent_iff'] at h intro s w hw hs i hi rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s w p hw (p i1), ← s.weightedVSubOfPoint_erase w p i1, Finset.weightedVSubOfPoint_apply] at hs let f : ι → V := fun i => w i • (p i -ᵥ p i1) have hs2 : (∑ i ∈ (s.erase i1).subtype fun i => i ≠ i1, f i) = 0 := by rw [← hs] convert Finset.sum_subtype_of_mem f fun x => Finset.ne_of_mem_erase have h2 := h ((s.erase i1).subtype fun i => i ≠ i1) (fun x => w x) hs2 simp_rw [Finset.mem_subtype] at h2 have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := fun i his hi => h2 ⟨i, hi⟩ (Finset.mem_erase_of_ne_of_mem hi his) exact Finset.eq_zero_of_sum_eq_zero hw h2b i hi #align affine_independent_iff_linear_independent_vsub affineIndependent_iff_linearIndependent_vsub /-- A set is affinely independent if and only if the differences from a base point in that set are linearly independent. -/ theorem affineIndependent_set_iff_linearIndependent_vsub {s : Set P} {p₁ : P} (hp₁ : p₁ ∈ s) : AffineIndependent k (fun p => p : s → P) ↔ LinearIndependent k (fun v => v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → V) := by rw [affineIndependent_iff_linearIndependent_vsub k (fun p => p : s → P) ⟨p₁, hp₁⟩] constructor · intro h have hv : ∀ v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}), (v : V) +ᵥ p₁ ∈ s \ {p₁} := fun v => (vsub_left_injective p₁).mem_set_image.1 ((vadd_vsub (v : V) p₁).symm ▸ v.property) let f : (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → { x : s // x ≠ ⟨p₁, hp₁⟩ } := fun x => ⟨⟨(x : V) +ᵥ p₁, Set.mem_of_mem_diff (hv x)⟩, fun hx => Set.not_mem_of_mem_diff (hv x) (Subtype.ext_iff.1 hx)⟩ convert h.comp f fun x1 x2 hx => Subtype.ext (vadd_right_cancel p₁ (Subtype.ext_iff.1 (Subtype.ext_iff.1 hx))) ext v exact (vadd_vsub (v : V) p₁).symm · intro h let f : { x : s // x ≠ ⟨p₁, hp₁⟩ } → (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) := fun x => ⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, fun hx => x.property (Subtype.ext hx)⟩, rfl⟩⟩⟩ convert h.comp f fun x1 x2 hx => Subtype.ext (Subtype.ext (vsub_left_cancel (Subtype.ext_iff.1 hx))) #align affine_independent_set_iff_linear_independent_vsub affineIndependent_set_iff_linearIndependent_vsub /-- A set of nonzero vectors is linearly independent if and only if, given a point `p₁`, the vectors added to `p₁` and `p₁` itself are affinely independent. -/ theorem linearIndependent_set_iff_affineIndependent_vadd_union_singleton {s : Set V} (hs : ∀ v ∈ s, v ≠ (0 : V)) (p₁ : P) : LinearIndependent k (fun v => v : s → V) ↔ AffineIndependent k (fun p => p : ({p₁} ∪ (fun v => v +ᵥ p₁) '' s : Set P) → P) := by rw [affineIndependent_set_iff_linearIndependent_vsub k (Set.mem_union_left _ (Set.mem_singleton p₁))] have h : (fun p => (p -ᵥ p₁ : V)) '' (({p₁} ∪ (fun v => v +ᵥ p₁) '' s) \ {p₁}) = s := by simp_rw [Set.union_diff_left, Set.image_diff (vsub_left_injective p₁), Set.image_image, Set.image_singleton, vsub_self, vadd_vsub, Set.image_id'] exact Set.diff_singleton_eq_self fun h => hs 0 h rfl rw [h] #align linear_independent_set_iff_affine_independent_vadd_union_singleton linearIndependent_set_iff_affineIndependent_vadd_union_singleton /-- A family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point have equal `Set.indicator`. -/ theorem affineIndependent_iff_indicator_eq_of_affineCombination_eq (p : ι → P) : AffineIndependent k p ↔ ∀ (s1 s2 : Finset ι) (w1 w2 : ι → k), ∑ i ∈ s1, w1 i = 1 → ∑ i ∈ s2, w2 i = 1 → s1.affineCombination k p w1 = s2.affineCombination k p w2 → Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2 := by classical constructor · intro ha s1 s2 w1 w2 hw1 hw2 heq ext i by_cases hi : i ∈ s1 ∪ s2 · rw [← sub_eq_zero] rw [← Finset.sum_indicator_subset w1 (s1.subset_union_left (s₂:=s2))] at hw1 rw [← Finset.sum_indicator_subset w2 (s1.subset_union_right)] at hw2 have hws : (∑ i ∈ s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i) = 0 := by simp [hw1, hw2] rw [Finset.affineCombination_indicator_subset w1 p (s1.subset_union_left (s₂:=s2)), Finset.affineCombination_indicator_subset w2 p s1.subset_union_right, ← @vsub_eq_zero_iff_eq V, Finset.affineCombination_vsub] at heq exact ha (s1 ∪ s2) (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) hws heq i hi · rw [← Finset.mem_coe, Finset.coe_union] at hi have h₁ : Set.indicator (↑s1) w1 i = 0 := by simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff] intro h by_contra exact (mt (@Set.mem_union_left _ i ↑s1 ↑s2) hi) h have h₂ : Set.indicator (↑s2) w2 i = 0 := by simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff] intro h by_contra exact (mt (@Set.mem_union_right _ i ↑s2 ↑s1) hi) h simp [h₁, h₂] · intro ha s w hw hs i0 hi0 let w1 : ι → k := Function.update (Function.const ι 0) i0 1 have hw1 : ∑ i ∈ s, w1 i = 1 := by rw [Finset.sum_update_of_mem hi0] simp only [Finset.sum_const_zero, add_zero, const_apply] have hw1s : s.affineCombination k p w1 = p i0 := s.affineCombination_of_eq_one_of_eq_zero w1 p hi0 (Function.update_same _ _ _) fun _ _ hne => Function.update_noteq hne _ _ let w2 := w + w1 have hw2 : ∑ i ∈ s, w2 i = 1 := by simp_all only [w2, Pi.add_apply, Finset.sum_add_distrib, zero_add] have hw2s : s.affineCombination k p w2 = p i0 := by simp_all only [w2, ← Finset.weightedVSub_vadd_affineCombination, zero_vadd] replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s) have hws : w2 i0 - w1 i0 = 0 := by rw [← Finset.mem_coe] at hi0 rw [← Set.indicator_of_mem hi0 w2, ← Set.indicator_of_mem hi0 w1, ha, sub_self] simpa [w2] using hws #align affine_independent_iff_indicator_eq_of_affine_combination_eq affineIndependent_iff_indicator_eq_of_affineCombination_eq /-- A finite family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point are equal. -/ theorem affineIndependent_iff_eq_of_fintype_affineCombination_eq [Fintype ι] (p : ι → P) : AffineIndependent k p ↔ ∀ w1 w2 : ι → k, ∑ i, w1 i = 1 → ∑ i, w2 i = 1 → Finset.univ.affineCombination k p w1 = Finset.univ.affineCombination k p w2 → w1 = w2 := by rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] constructor · intro h w1 w2 hw1 hw2 hweq simpa only [Set.indicator_univ, Finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq · intro h s1 s2 w1 w2 hw1 hw2 hweq have hw1' : (∑ i, (s1 : Set ι).indicator w1 i) = 1 := by rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s1)] have hw2' : (∑ i, (s2 : Set ι).indicator w2 i) = 1 := by rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s2)] rw [Finset.affineCombination_indicator_subset w1 p (Finset.subset_univ s1), Finset.affineCombination_indicator_subset w2 p (Finset.subset_univ s2)] at hweq exact h _ _ hw1' hw2' hweq #align affine_independent_iff_eq_of_fintype_affine_combination_eq affineIndependent_iff_eq_of_fintype_affineCombination_eq variable {k} /-- If we single out one member of an affine-independent family of points and affinely transport all others along the line joining them to this member, the resulting new family of points is affine- independent. This is the affine version of `LinearIndependent.units_smul`. -/ theorem AffineIndependent.units_lineMap {p : ι → P} (hp : AffineIndependent k p) (j : ι) (w : ι → Units k) : AffineIndependent k fun i => AffineMap.lineMap (p j) (p i) (w i : k) := by rw [affineIndependent_iff_linearIndependent_vsub k _ j] at hp ⊢ simp only [AffineMap.lineMap_vsub_left, AffineMap.coe_const, AffineMap.lineMap_same, const_apply] exact hp.units_smul fun i => w i #align affine_independent.units_line_map AffineIndependent.units_lineMap theorem AffineIndependent.indicator_eq_of_affineCombination_eq {p : ι → P} (ha : AffineIndependent k p) (s₁ s₂ : Finset ι) (w₁ w₂ : ι → k) (hw₁ : ∑ i ∈ s₁, w₁ i = 1) (hw₂ : ∑ i ∈ s₂, w₂ i = 1) (h : s₁.affineCombination k p w₁ = s₂.affineCombination k p w₂) : Set.indicator (↑s₁) w₁ = Set.indicator (↑s₂) w₂ := (affineIndependent_iff_indicator_eq_of_affineCombination_eq k p).1 ha s₁ s₂ w₁ w₂ hw₁ hw₂ h #align affine_independent.indicator_eq_of_affine_combination_eq AffineIndependent.indicator_eq_of_affineCombination_eq /-- An affinely independent family is injective, if the underlying ring is nontrivial. -/ protected theorem AffineIndependent.injective [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) : Function.Injective p := by intro i j hij rw [affineIndependent_iff_linearIndependent_vsub _ _ j] at ha by_contra hij' refine ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr ?_) simp_all only [ne_eq] #align affine_independent.injective AffineIndependent.injective /-- If a family is affinely independent, so is any subfamily given by composition of an embedding into index type with the original family. -/ theorem AffineIndependent.comp_embedding {ι2 : Type*} (f : ι2 ↪ ι) {p : ι → P} (ha : AffineIndependent k p) : AffineIndependent k (p ∘ f) := by classical intro fs w hw hs i0 hi0 let fs' := fs.map f let w' i := if h : ∃ i2, f i2 = i then w h.choose else 0 have hw' : ∀ i2 : ι2, w' (f i2) = w i2 := by intro i2 have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩ have hs : h.choose = i2 := f.injective h.choose_spec simp_rw [w', dif_pos h, hs] have hw's : ∑ i ∈ fs', w' i = 0 := by rw [← hw, Finset.sum_map] simp [hw'] have hs' : fs'.weightedVSub p w' = (0 : V) := by rw [← hs, Finset.weightedVSub_map] congr with i simp_all only [comp_apply, EmbeddingLike.apply_eq_iff_eq, exists_eq, dite_true] rw [← ha fs' w' hw's hs' (f i0) ((Finset.mem_map' _).2 hi0), hw'] #align affine_independent.comp_embedding AffineIndependent.comp_embedding /-- If a family is affinely independent, so is any subfamily indexed by a subtype of the index type. -/ protected theorem AffineIndependent.subtype {p : ι → P} (ha : AffineIndependent k p) (s : Set ι) : AffineIndependent k fun i : s => p i := ha.comp_embedding (Embedding.subtype _) #align affine_independent.subtype AffineIndependent.subtype /-- If an indexed family of points is affinely independent, so is the corresponding set of points. -/ protected theorem AffineIndependent.range {p : ι → P} (ha : AffineIndependent k p) : AffineIndependent k (fun x => x : Set.range p → P) := by let f : Set.range p → ι := fun x => x.property.choose have hf : ∀ x, p (f x) = x := fun x => x.property.choose_spec let fe : Set.range p ↪ ι := ⟨f, fun x₁ x₂ he => Subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩ convert ha.comp_embedding fe ext simp [fe, hf] #align affine_independent.range AffineIndependent.range theorem affineIndependent_equiv {ι' : Type*} (e : ι ≃ ι') {p : ι' → P} : AffineIndependent k (p ∘ e) ↔ AffineIndependent k p := by refine ⟨?_, AffineIndependent.comp_embedding e.toEmbedding⟩ intro h have : p = p ∘ e ∘ e.symm.toEmbedding := by ext simp rw [this] exact h.comp_embedding e.symm.toEmbedding #align affine_independent_equiv affineIndependent_equiv /-- If a set of points is affinely independent, so is any subset. -/ protected theorem AffineIndependent.mono {s t : Set P} (ha : AffineIndependent k (fun x => x : t → P)) (hs : s ⊆ t) : AffineIndependent k (fun x => x : s → P) := ha.comp_embedding (s.embeddingOfSubset t hs) #align affine_independent.mono AffineIndependent.mono /-- If the range of an injective indexed family of points is affinely independent, so is that family. -/ theorem AffineIndependent.of_set_of_injective {p : ι → P} (ha : AffineIndependent k (fun x => x : Set.range p → P)) (hi : Function.Injective p) : AffineIndependent k p := ha.comp_embedding (⟨fun i => ⟨p i, Set.mem_range_self _⟩, fun _ _ h => hi (Subtype.mk_eq_mk.1 h)⟩ : ι ↪ Set.range p) #align affine_independent.of_set_of_injective AffineIndependent.of_set_of_injective section Composition variable {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AffineSpace V₂ P₂] /-- If the image of a family of points in affine space under an affine transformation is affine- independent, then the original family of points is also affine-independent. -/ theorem AffineIndependent.of_comp {p : ι → P} (f : P →ᵃ[k] P₂) (hai : AffineIndependent k (f ∘ p)) : AffineIndependent k p := by cases' isEmpty_or_nonempty ι with h h; · haveI := h apply affineIndependent_of_subsingleton obtain ⟨i⟩ := h rw [affineIndependent_iff_linearIndependent_vsub k p i] simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ← f.linearMap_vsub] at hai exact LinearIndependent.of_comp f.linear hai #align affine_independent.of_comp AffineIndependent.of_comp /-- The image of a family of points in affine space, under an injective affine transformation, is affine-independent. -/ theorem AffineIndependent.map' {p : ι → P} (hai : AffineIndependent k p) (f : P →ᵃ[k] P₂) (hf : Function.Injective f) : AffineIndependent k (f ∘ p) := by cases' isEmpty_or_nonempty ι with h h · haveI := h apply affineIndependent_of_subsingleton obtain ⟨i⟩ := h rw [affineIndependent_iff_linearIndependent_vsub k p i] at hai simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ← f.linearMap_vsub] have hf' : LinearMap.ker f.linear = ⊥ := by rwa [LinearMap.ker_eq_bot, f.linear_injective_iff] exact LinearIndependent.map' hai f.linear hf' #align affine_independent.map' AffineIndependent.map' /-- Injective affine maps preserve affine independence. -/ theorem AffineMap.affineIndependent_iff {p : ι → P} (f : P →ᵃ[k] P₂) (hf : Function.Injective f) : AffineIndependent k (f ∘ p) ↔ AffineIndependent k p := ⟨AffineIndependent.of_comp f, fun hai => AffineIndependent.map' hai f hf⟩ #align affine_map.affine_independent_iff AffineMap.affineIndependent_iff /-- Affine equivalences preserve affine independence of families of points. -/ theorem AffineEquiv.affineIndependent_iff {p : ι → P} (e : P ≃ᵃ[k] P₂) : AffineIndependent k (e ∘ p) ↔ AffineIndependent k p := e.toAffineMap.affineIndependent_iff e.toEquiv.injective #align affine_equiv.affine_independent_iff AffineEquiv.affineIndependent_iff /-- Affine equivalences preserve affine independence of subsets. -/ theorem AffineEquiv.affineIndependent_set_of_eq_iff {s : Set P} (e : P ≃ᵃ[k] P₂) : AffineIndependent k ((↑) : e '' s → P₂) ↔ AffineIndependent k ((↑) : s → P) := by have : e ∘ ((↑) : s → P) = ((↑) : e '' s → P₂) ∘ (e : P ≃ P₂).image s := rfl -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [← e.affineIndependent_iff, this, affineIndependent_equiv] #align affine_equiv.affine_independent_set_of_eq_iff AffineEquiv.affineIndependent_set_of_eq_iff end Composition /-- If a family is affinely independent, and the spans of points indexed by two subsets of the index type have a point in common, those subsets of the index type have an element in common, if the underlying ring is nontrivial. -/ theorem AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) {s1 s2 : Set ι} {p0 : P} (hp0s1 : p0 ∈ affineSpan k (p '' s1)) (hp0s2 : p0 ∈ affineSpan k (p '' s2)) : ∃ i : ι, i ∈ s1 ∩ s2 := by rw [Set.image_eq_range] at hp0s1 hp0s2 rw [mem_affineSpan_iff_eq_affineCombination, ← Finset.eq_affineCombination_subset_iff_eq_affineCombination_subtype] at hp0s1 hp0s2 rcases hp0s1 with ⟨fs1, hfs1, w1, hw1, hp0s1⟩ rcases hp0s2 with ⟨fs2, hfs2, w2, hw2, hp0s2⟩ rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] at ha replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 ▸ hp0s2) have hnz : ∑ i ∈ fs1, w1 i ≠ 0 := hw1.symm ▸ one_ne_zero rcases Finset.exists_ne_zero_of_sum_ne_zero hnz with ⟨i, hifs1, hinz⟩ simp_rw [← Set.indicator_of_mem (Finset.mem_coe.2 hifs1) w1, ha] at hinz use i, hfs1 hifs1 exact hfs2 (Set.mem_of_indicator_ne_zero hinz) #align affine_independent.exists_mem_inter_of_exists_mem_inter_affine_span AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan /-- If a family is affinely independent, the spans of points indexed by disjoint subsets of the index type are disjoint, if the underlying ring is nontrivial. -/ theorem AffineIndependent.affineSpan_disjoint_of_disjoint [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) {s1 s2 : Set ι} (hd : Disjoint s1 s2) : Disjoint (affineSpan k (p '' s1) : Set P) (affineSpan k (p '' s2)) := by refine Set.disjoint_left.2 fun p0 hp0s1 hp0s2 => ?_ cases' ha.exists_mem_inter_of_exists_mem_inter_affineSpan hp0s1 hp0s2 with i hi exact Set.disjoint_iff.1 hd hi #align affine_independent.affine_span_disjoint_of_disjoint AffineIndependent.affineSpan_disjoint_of_disjoint /-- If a family is affinely independent, a point in the family is in the span of some of the points given by a subset of the index type if and only if that point's index is in the subset, if the underlying ring is nontrivial. -/ @[simp] protected theorem AffineIndependent.mem_affineSpan_iff [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) (i : ι) (s : Set ι) : p i ∈ affineSpan k (p '' s) ↔ i ∈ s := by constructor · intro hs have h := AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan ha hs (mem_affineSpan k (Set.mem_image_of_mem _ (Set.mem_singleton _))) rwa [← Set.nonempty_def, Set.inter_singleton_nonempty] at h · exact fun h => mem_affineSpan k (Set.mem_image_of_mem p h) #align affine_independent.mem_affine_span_iff AffineIndependent.mem_affineSpan_iff /-- If a family is affinely independent, a point in the family is not in the affine span of the other points, if the underlying ring is nontrivial. -/ theorem AffineIndependent.not_mem_affineSpan_diff [Nontrivial k] {p : ι → P} (ha : AffineIndependent k p) (i : ι) (s : Set ι) : p i ∉ affineSpan k (p '' (s \ {i})) := by simp [ha] #align affine_independent.not_mem_affine_span_diff AffineIndependent.not_mem_affineSpan_diff theorem exists_nontrivial_relation_sum_zero_of_not_affine_ind {t : Finset V} (h : ¬AffineIndependent k ((↑) : t → V)) : ∃ f : V → k, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by classical rw [affineIndependent_iff_of_fintype] at h simp only [exists_prop, not_forall] at h obtain ⟨w, hw, hwt, i, hi⟩ := h simp only [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ w ((↑) : t → V) hw 0, vsub_eq_sub, Finset.weightedVSubOfPoint_apply, sub_zero] at hwt let f : ∀ x : V, x ∈ t → k := fun x hx => w ⟨x, hx⟩ refine ⟨fun x => if hx : x ∈ t then f x hx else (0 : k), ?_, ?_, by use i; simp [hi]⟩ on_goal 1 => suffices (∑ e ∈ t, dite (e ∈ t) (fun hx => f e hx • e) fun _ => 0) = 0 by convert this rename V => x by_cases hx : x ∈ t <;> simp [hx] all_goals simp only [Finset.sum_dite_of_true fun _ h => h, Finset.mk_coe, hwt, hw] #align exists_nontrivial_relation_sum_zero_of_not_affine_ind exists_nontrivial_relation_sum_zero_of_not_affine_ind variable {s : Finset ι} {w w₁ w₂ : ι → k} {p : ι → V} /-- Viewing a module as an affine space modelled on itself, we can characterise affine independence in terms of linear combinations. -/ theorem affineIndependent_iff {ι} {p : ι → V} : AffineIndependent k p ↔ ∀ (s : Finset ι) (w : ι → k), s.sum w = 0 → ∑ e ∈ s, w e • p e = 0 → ∀ e ∈ s, w e = 0 := forall₃_congr fun s w hw => by simp [s.weightedVSub_eq_linear_combination hw] #align affine_independent_iff affineIndependent_iff lemma AffineIndependent.eq_zero_of_sum_eq_zero (hp : AffineIndependent k p) (hw₀ : ∑ i ∈ s, w i = 0) (hw₁ : ∑ i ∈ s, w i • p i = 0) : ∀ i ∈ s, w i = 0 := affineIndependent_iff.1 hp _ _ hw₀ hw₁ lemma AffineIndependent.eq_of_sum_eq_sum (hp : AffineIndependent k p) (hw : ∑ i ∈ s, w₁ i = ∑ i ∈ s, w₂ i) (hwp : ∑ i ∈ s, w₁ i • p i = ∑ i ∈ s, w₂ i • p i) : ∀ i ∈ s, w₁ i = w₂ i := by refine fun i hi ↦ sub_eq_zero.1 (hp.eq_zero_of_sum_eq_zero (w := w₁ - w₂) ?_ ?_ _ hi) <;> simpa [sub_mul, sub_smul, sub_eq_zero] lemma AffineIndependent.eq_zero_of_sum_eq_zero_subtype {s : Finset V} (hp : AffineIndependent k ((↑) : s → V)) {w : V → k} (hw₀ : ∑ x ∈ s, w x = 0) (hw₁ : ∑ x ∈ s, w x • x = 0) : ∀ x ∈ s, w x = 0 := by rw [← sum_attach] at hw₀ hw₁ exact fun x hx ↦ hp.eq_zero_of_sum_eq_zero hw₀ hw₁ ⟨x, hx⟩ (mem_univ _) lemma AffineIndependent.eq_of_sum_eq_sum_subtype {s : Finset V} (hp : AffineIndependent k ((↑) : s → V)) {w₁ w₂ : V → k} (hw : ∑ i ∈ s, w₁ i = ∑ i ∈ s, w₂ i) (hwp : ∑ i ∈ s, w₁ i • i = ∑ i ∈ s, w₂ i • i) : ∀ i ∈ s, w₁ i = w₂ i := by refine fun i hi => sub_eq_zero.1 (hp.eq_zero_of_sum_eq_zero_subtype (w := w₁ - w₂) ?_ ?_ _ hi) <;> simpa [sub_mul, sub_smul, sub_eq_zero] /-- Given an affinely independent family of points, a weighted subtraction lies in the `vectorSpan` of two points given as affine combinations if and only if it is a weighted subtraction with weights a multiple of the difference between the weights of the two points. -/ theorem weightedVSub_mem_vectorSpan_pair {p : ι → P} (h : AffineIndependent k p) {w w₁ w₂ : ι → k} {s : Finset ι} (hw : ∑ i ∈ s, w i = 0) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) : s.weightedVSub p w ∈ vectorSpan k ({s.affineCombination k p w₁, s.affineCombination k p w₂} : Set P) ↔ ∃ r : k, ∀ i ∈ s, w i = r * (w₁ i - w₂ i) := by rw [mem_vectorSpan_pair] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ⟨r, hr⟩ refine ⟨r, fun i hi => ?_⟩ rw [s.affineCombination_vsub, ← s.weightedVSub_const_smul, ← sub_eq_zero, ← map_sub] at hr have hw' : (∑ j ∈ s, (r • (w₁ - w₂) - w) j) = 0 := by simp_rw [Pi.sub_apply, Pi.smul_apply, Pi.sub_apply, smul_sub, Finset.sum_sub_distrib, ← Finset.smul_sum, hw, hw₁, hw₂, sub_self] have hr' := h s _ hw' hr i hi rw [eq_comm, ← sub_eq_zero, ← smul_eq_mul] exact hr' · rcases h with ⟨r, hr⟩ refine ⟨r, ?_⟩ let w' i := r * (w₁ i - w₂ i) change ∀ i ∈ s, w i = w' i at hr rw [s.weightedVSub_congr hr fun _ _ => rfl, s.affineCombination_vsub, ← s.weightedVSub_const_smul] congr #align weighted_vsub_mem_vector_span_pair weightedVSub_mem_vectorSpan_pair /-- Given an affinely independent family of points, an affine combination lies in the span of two points given as affine combinations if and only if it is an affine combination with weights those of one point plus a multiple of the difference between the weights of the two points. -/ theorem affineCombination_mem_affineSpan_pair {p : ι → P} (h : AffineIndependent k p) {w w₁ w₂ : ι → k} {s : Finset ι} (_ : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) : s.affineCombination k p w ∈ line[k, s.affineCombination k p w₁, s.affineCombination k p w₂] ↔ ∃ r : k, ∀ i ∈ s, w i = r * (w₂ i - w₁ i) + w₁ i := by rw [← vsub_vadd (s.affineCombination k p w) (s.affineCombination k p w₁), AffineSubspace.vadd_mem_iff_mem_direction _ (left_mem_affineSpan_pair _ _ _), direction_affineSpan, s.affineCombination_vsub, Set.pair_comm, weightedVSub_mem_vectorSpan_pair h _ hw₂ hw₁] · simp only [Pi.sub_apply, sub_eq_iff_eq_add] · simp_all only [Pi.sub_apply, Finset.sum_sub_distrib, sub_self] #align affine_combination_mem_affine_span_pair affineCombination_mem_affineSpan_pair end AffineIndependent section DivisionRing variable {k : Type*} {V : Type*} {P : Type*} [DivisionRing k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} /-- An affinely independent set of points can be extended to such a set that spans the whole space. -/ theorem exists_subset_affineIndependent_affineSpan_eq_top {s : Set P} (h : AffineIndependent k (fun p => p : s → P)) : ∃ t : Set P, s ⊆ t ∧ AffineIndependent k (fun p => p : t → P) ∧ affineSpan k t = ⊤ := by rcases s.eq_empty_or_nonempty with (rfl | ⟨p₁, hp₁⟩) · have p₁ : P := AddTorsor.nonempty.some let hsv := Basis.ofVectorSpace k V have hsvi := hsv.linearIndependent have hsvt := hsv.span_eq rw [Basis.coe_ofVectorSpace] at hsvi hsvt have h0 : ∀ v : V, v ∈ Basis.ofVectorSpaceIndex k V → v ≠ 0 := by intro v hv simpa [hsv] using hsv.ne_zero ⟨v, hv⟩ rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi exact ⟨{p₁} ∪ (fun v => v +ᵥ p₁) '' _, Set.empty_subset _, hsvi, affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt⟩ · rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁] at h let bsv := Basis.extend h have hsvi := bsv.linearIndependent have hsvt := bsv.span_eq rw [Basis.coe_extend] at hsvi hsvt have hsv := h.subset_extend (Set.subset_univ _) have h0 : ∀ v : V, v ∈ h.extend (Set.subset_univ _) → v ≠ 0 := by intro v hv simpa [bsv] using bsv.ne_zero ⟨v, hv⟩ rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi refine ⟨{p₁} ∪ (fun v => v +ᵥ p₁) '' h.extend (Set.subset_univ _), ?_, ?_⟩ · refine Set.Subset.trans ?_ (Set.union_subset_union_right _ (Set.image_subset _ hsv)) simp [Set.image_image] · use hsvi exact affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt #align exists_subset_affine_independent_affine_span_eq_top exists_subset_affineIndependent_affineSpan_eq_top variable (k V)
Mathlib/LinearAlgebra/AffineSpace/Independent.lean
607
628
theorem exists_affineIndependent (s : Set P) : ∃ t ⊆ s, affineSpan k t = affineSpan k s ∧ AffineIndependent k ((↑) : t → P) := by
rcases s.eq_empty_or_nonempty with (rfl | ⟨p, hp⟩) · exact ⟨∅, Set.empty_subset ∅, rfl, affineIndependent_of_subsingleton k _⟩ obtain ⟨b, hb₁, hb₂, hb₃⟩ := exists_linearIndependent k ((Equiv.vaddConst p).symm '' s) have hb₀ : ∀ v : V, v ∈ b → v ≠ 0 := fun v hv => hb₃.ne_zero (⟨v, hv⟩ : b) rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k hb₀ p] at hb₃ refine ⟨{p} ∪ Equiv.vaddConst p '' b, ?_, ?_, hb₃⟩ · apply Set.union_subset (Set.singleton_subset_iff.mpr hp) rwa [← (Equiv.vaddConst p).subset_symm_image b s] · rw [Equiv.coe_vaddConst_symm, ← vectorSpan_eq_span_vsub_set_right k hp] at hb₂ apply AffineSubspace.ext_of_direction_eq · have : Submodule.span k b = Submodule.span k (insert 0 b) := by simp simp only [direction_affineSpan, ← hb₂, Equiv.coe_vaddConst, Set.singleton_union, vectorSpan_eq_span_vsub_set_right k (Set.mem_insert p _), this] congr change (Equiv.vaddConst p).symm '' insert p (Equiv.vaddConst p '' b) = _ rw [Set.image_insert_eq, ← Set.image_comp] simp · use p simp only [Equiv.coe_vaddConst, Set.singleton_union, Set.mem_inter_iff, coe_affineSpan] exact ⟨mem_spanPoints k _ _ (Set.mem_insert p _), mem_spanPoints k _ _ hp⟩
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax import Mathlib.Algebra.Order.Monoid.WithTop import Mathlib.Data.Finset.Image import Mathlib.Data.Multiset.Fold #align_import data.finset.fold from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # The fold operation for a commutative associative operation over a finset. -/ -- TODO: -- assert_not_exists OrderedCommMonoid assert_not_exists MonoidWithZero namespace Finset open Multiset variable {α β γ : Type*} /-! ### fold -/ section Fold variable (op : β → β → β) [hc : Std.Commutative op] [ha : Std.Associative op] local notation a " * " b => op a b /-- `fold op b f s` folds the commutative associative operation `op` over the `f`-image of `s`, i.e. `fold (+) b f {1,2,3} = f 1 + f 2 + f 3 + b`. -/ def fold (b : β) (f : α → β) (s : Finset α) : β := (s.1.map f).fold op b #align finset.fold Finset.fold variable {op} {f : α → β} {b : β} {s : Finset α} {a : α} @[simp] theorem fold_empty : (∅ : Finset α).fold op b f = b := rfl #align finset.fold_empty Finset.fold_empty @[simp] theorem fold_cons (h : a ∉ s) : (cons a s h).fold op b f = f a * s.fold op b f := by dsimp only [fold] rw [cons_val, Multiset.map_cons, fold_cons_left] #align finset.fold_cons Finset.fold_cons @[simp] theorem fold_insert [DecidableEq α] (h : a ∉ s) : (insert a s).fold op b f = f a * s.fold op b f := by unfold fold rw [insert_val, ndinsert_of_not_mem h, Multiset.map_cons, fold_cons_left] #align finset.fold_insert Finset.fold_insert @[simp] theorem fold_singleton : ({a} : Finset α).fold op b f = f a * b := rfl #align finset.fold_singleton Finset.fold_singleton @[simp] theorem fold_map {g : γ ↪ α} {s : Finset γ} : (s.map g).fold op b f = s.fold op b (f ∘ g) := by simp only [fold, map, Multiset.map_map] #align finset.fold_map Finset.fold_map @[simp] theorem fold_image [DecidableEq α] {g : γ → α} {s : Finset γ} (H : ∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) : (s.image g).fold op b f = s.fold op b (f ∘ g) := by simp only [fold, image_val_of_injOn H, Multiset.map_map] #align finset.fold_image Finset.fold_image @[congr] theorem fold_congr {g : α → β} (H : ∀ x ∈ s, f x = g x) : s.fold op b f = s.fold op b g := by rw [fold, fold, map_congr rfl H] #align finset.fold_congr Finset.fold_congr
Mathlib/Data/Finset/Fold.lean
83
85
theorem fold_op_distrib {f g : α → β} {b₁ b₂ : β} : (s.fold op (b₁ * b₂) fun x => f x * g x) = s.fold op b₁ f * s.fold op b₂ g := by
simp only [fold, fold_distrib]
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Fintype.Basic import Mathlib.Data.Finset.Card import Mathlib.Data.List.NodupEquivFin import Mathlib.Data.Set.Image #align_import data.fintype.card from "leanprover-community/mathlib"@"bf2428c9486c407ca38b5b3fb10b87dad0bc99fa" /-! # Cardinalities of finite types ## Main declarations * `Fintype.card α`: Cardinality of a fintype. Equal to `Finset.univ.card`. * `Fintype.truncEquivFin`: A fintype `α` is computably equivalent to `Fin (card α)`. The `Trunc`-free, noncomputable version is `Fintype.equivFin`. * `Fintype.truncEquivOfCardEq` `Fintype.equivOfCardEq`: Two fintypes of same cardinality are equivalent. See above. * `Fin.equiv_iff_eq`: `Fin m ≃ Fin n` iff `m = n`. * `Infinite.natEmbedding`: An embedding of `ℕ` into an infinite type. We also provide the following versions of the pigeonholes principle. * `Fintype.exists_ne_map_eq_of_card_lt` and `isEmpty_of_card_lt`: Finitely many pigeons and pigeonholes. Weak formulation. * `Finite.exists_ne_map_eq_of_infinite`: Infinitely many pigeons in finitely many pigeonholes. Weak formulation. * `Finite.exists_infinite_fiber`: Infinitely many pigeons in finitely many pigeonholes. Strong formulation. Some more pigeonhole-like statements can be found in `Data.Fintype.CardEmbedding`. Types which have an injection from/a surjection to an `Infinite` type are themselves `Infinite`. See `Infinite.of_injective` and `Infinite.of_surjective`. ## Instances We provide `Infinite` instances for * specific types: `ℕ`, `ℤ`, `String` * type constructors: `Multiset α`, `List α` -/ assert_not_exists MonoidWithZero assert_not_exists MulAction open Function open Nat universe u v variable {α β γ : Type*} open Finset Function namespace Fintype /-- `card α` is the number of elements in `α`, defined when `α` is a fintype. -/ def card (α) [Fintype α] : ℕ := (@univ α _).card #align fintype.card Fintype.card /-- There is (computably) an equivalence between `α` and `Fin (card α)`. Since it is not unique and depends on which permutation of the universe list is used, the equivalence is wrapped in `Trunc` to preserve computability. See `Fintype.equivFin` for the noncomputable version, and `Fintype.truncEquivFinOfCardEq` and `Fintype.equivFinOfCardEq` for an equiv `α ≃ Fin n` given `Fintype.card α = n`. See `Fintype.truncFinBijection` for a version without `[DecidableEq α]`. -/ def truncEquivFin (α) [DecidableEq α] [Fintype α] : Trunc (α ≃ Fin (card α)) := by unfold card Finset.card exact Quot.recOnSubsingleton' (motive := fun s : Multiset α => (∀ x : α, x ∈ s) → s.Nodup → Trunc (α ≃ Fin (Multiset.card s))) univ.val (fun l (h : ∀ x : α, x ∈ l) (nd : l.Nodup) => Trunc.mk (nd.getEquivOfForallMemList _ h).symm) mem_univ_val univ.2 #align fintype.trunc_equiv_fin Fintype.truncEquivFin /-- There is (noncomputably) an equivalence between `α` and `Fin (card α)`. See `Fintype.truncEquivFin` for the computable version, and `Fintype.truncEquivFinOfCardEq` and `Fintype.equivFinOfCardEq` for an equiv `α ≃ Fin n` given `Fintype.card α = n`. -/ noncomputable def equivFin (α) [Fintype α] : α ≃ Fin (card α) := letI := Classical.decEq α (truncEquivFin α).out #align fintype.equiv_fin Fintype.equivFin /-- There is (computably) a bijection between `Fin (card α)` and `α`. Since it is not unique and depends on which permutation of the universe list is used, the bijection is wrapped in `Trunc` to preserve computability. See `Fintype.truncEquivFin` for a version that gives an equivalence given `[DecidableEq α]`. -/ def truncFinBijection (α) [Fintype α] : Trunc { f : Fin (card α) → α // Bijective f } := by unfold card Finset.card refine Quot.recOnSubsingleton' (motive := fun s : Multiset α => (∀ x : α, x ∈ s) → s.Nodup → Trunc {f : Fin (Multiset.card s) → α // Bijective f}) univ.val (fun l (h : ∀ x : α, x ∈ l) (nd : l.Nodup) => Trunc.mk (nd.getBijectionOfForallMemList _ h)) mem_univ_val univ.2 #align fintype.trunc_fin_bijection Fintype.truncFinBijection theorem subtype_card {p : α → Prop} (s : Finset α) (H : ∀ x : α, x ∈ s ↔ p x) : @card { x // p x } (Fintype.subtype s H) = s.card := Multiset.card_pmap _ _ _ #align fintype.subtype_card Fintype.subtype_card theorem card_of_subtype {p : α → Prop} (s : Finset α) (H : ∀ x : α, x ∈ s ↔ p x) [Fintype { x // p x }] : card { x // p x } = s.card := by rw [← subtype_card s H] congr apply Subsingleton.elim #align fintype.card_of_subtype Fintype.card_of_subtype @[simp] theorem card_ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : @Fintype.card p (ofFinset s H) = s.card := Fintype.subtype_card s H #align fintype.card_of_finset Fintype.card_ofFinset theorem card_of_finset' {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) [Fintype p] : Fintype.card p = s.card := by rw [← card_ofFinset s H]; congr; apply Subsingleton.elim #align fintype.card_of_finset' Fintype.card_of_finset' end Fintype namespace Fintype theorem ofEquiv_card [Fintype α] (f : α ≃ β) : @card β (ofEquiv α f) = card α := Multiset.card_map _ _ #align fintype.of_equiv_card Fintype.ofEquiv_card theorem card_congr {α β} [Fintype α] [Fintype β] (f : α ≃ β) : card α = card β := by rw [← ofEquiv_card f]; congr; apply Subsingleton.elim #align fintype.card_congr Fintype.card_congr @[congr] theorem card_congr' {α β} [Fintype α] [Fintype β] (h : α = β) : card α = card β := card_congr (by rw [h]) #align fintype.card_congr' Fintype.card_congr' section variable [Fintype α] [Fintype β] /-- If the cardinality of `α` is `n`, there is computably a bijection between `α` and `Fin n`. See `Fintype.equivFinOfCardEq` for the noncomputable definition, and `Fintype.truncEquivFin` and `Fintype.equivFin` for the bijection `α ≃ Fin (card α)`. -/ def truncEquivFinOfCardEq [DecidableEq α] {n : ℕ} (h : Fintype.card α = n) : Trunc (α ≃ Fin n) := (truncEquivFin α).map fun e => e.trans (finCongr h) #align fintype.trunc_equiv_fin_of_card_eq Fintype.truncEquivFinOfCardEq /-- If the cardinality of `α` is `n`, there is noncomputably a bijection between `α` and `Fin n`. See `Fintype.truncEquivFinOfCardEq` for the computable definition, and `Fintype.truncEquivFin` and `Fintype.equivFin` for the bijection `α ≃ Fin (card α)`. -/ noncomputable def equivFinOfCardEq {n : ℕ} (h : Fintype.card α = n) : α ≃ Fin n := letI := Classical.decEq α (truncEquivFinOfCardEq h).out #align fintype.equiv_fin_of_card_eq Fintype.equivFinOfCardEq /-- Two `Fintype`s with the same cardinality are (computably) in bijection. See `Fintype.equivOfCardEq` for the noncomputable version, and `Fintype.truncEquivFinOfCardEq` and `Fintype.equivFinOfCardEq` for the specialization to `Fin`. -/ def truncEquivOfCardEq [DecidableEq α] [DecidableEq β] (h : card α = card β) : Trunc (α ≃ β) := (truncEquivFinOfCardEq h).bind fun e => (truncEquivFin β).map fun e' => e.trans e'.symm #align fintype.trunc_equiv_of_card_eq Fintype.truncEquivOfCardEq /-- Two `Fintype`s with the same cardinality are (noncomputably) in bijection. See `Fintype.truncEquivOfCardEq` for the computable version, and `Fintype.truncEquivFinOfCardEq` and `Fintype.equivFinOfCardEq` for the specialization to `Fin`. -/ noncomputable def equivOfCardEq (h : card α = card β) : α ≃ β := by letI := Classical.decEq α letI := Classical.decEq β exact (truncEquivOfCardEq h).out #align fintype.equiv_of_card_eq Fintype.equivOfCardEq end theorem card_eq {α β} [_F : Fintype α] [_G : Fintype β] : card α = card β ↔ Nonempty (α ≃ β) := ⟨fun h => haveI := Classical.propDecidable (truncEquivOfCardEq h).nonempty, fun ⟨f⟩ => card_congr f⟩ #align fintype.card_eq Fintype.card_eq /-- Note: this lemma is specifically about `Fintype.ofSubsingleton`. For a statement about arbitrary `Fintype` instances, use either `Fintype.card_le_one_iff_subsingleton` or `Fintype.card_unique`. -/ @[simp] theorem card_ofSubsingleton (a : α) [Subsingleton α] : @Fintype.card _ (ofSubsingleton a) = 1 := rfl #align fintype.card_of_subsingleton Fintype.card_ofSubsingleton @[simp] theorem card_unique [Unique α] [h : Fintype α] : Fintype.card α = 1 := Subsingleton.elim (ofSubsingleton default) h ▸ card_ofSubsingleton _ #align fintype.card_unique Fintype.card_unique /-- Note: this lemma is specifically about `Fintype.ofIsEmpty`. For a statement about arbitrary `Fintype` instances, use `Fintype.card_eq_zero`. -/ @[simp] theorem card_ofIsEmpty [IsEmpty α] : @Fintype.card α Fintype.ofIsEmpty = 0 := rfl #align fintype.card_of_is_empty Fintype.card_ofIsEmpty end Fintype namespace Set variable {s t : Set α} -- We use an arbitrary `[Fintype s]` instance here, -- not necessarily coming from a `[Fintype α]`. @[simp] theorem toFinset_card {α : Type*} (s : Set α) [Fintype s] : s.toFinset.card = Fintype.card s := Multiset.card_map Subtype.val Finset.univ.val #align set.to_finset_card Set.toFinset_card end Set @[simp] theorem Finset.card_univ [Fintype α] : (Finset.univ : Finset α).card = Fintype.card α := rfl #align finset.card_univ Finset.card_univ theorem Finset.eq_univ_of_card [Fintype α] (s : Finset α) (hs : s.card = Fintype.card α) : s = univ := eq_of_subset_of_card_le (subset_univ _) <| by rw [hs, Finset.card_univ] #align finset.eq_univ_of_card Finset.eq_univ_of_card theorem Finset.card_eq_iff_eq_univ [Fintype α] (s : Finset α) : s.card = Fintype.card α ↔ s = Finset.univ := ⟨s.eq_univ_of_card, by rintro rfl exact Finset.card_univ⟩ #align finset.card_eq_iff_eq_univ Finset.card_eq_iff_eq_univ theorem Finset.card_le_univ [Fintype α] (s : Finset α) : s.card ≤ Fintype.card α := card_le_card (subset_univ s) #align finset.card_le_univ Finset.card_le_univ theorem Finset.card_lt_univ_of_not_mem [Fintype α] {s : Finset α} {x : α} (hx : x ∉ s) : s.card < Fintype.card α := card_lt_card ⟨subset_univ s, not_forall.2 ⟨x, fun hx' => hx (hx' <| mem_univ x)⟩⟩ #align finset.card_lt_univ_of_not_mem Finset.card_lt_univ_of_not_mem theorem Finset.card_lt_iff_ne_univ [Fintype α] (s : Finset α) : s.card < Fintype.card α ↔ s ≠ Finset.univ := s.card_le_univ.lt_iff_ne.trans (not_congr s.card_eq_iff_eq_univ) #align finset.card_lt_iff_ne_univ Finset.card_lt_iff_ne_univ theorem Finset.card_compl_lt_iff_nonempty [Fintype α] [DecidableEq α] (s : Finset α) : sᶜ.card < Fintype.card α ↔ s.Nonempty := sᶜ.card_lt_iff_ne_univ.trans s.compl_ne_univ_iff_nonempty #align finset.card_compl_lt_iff_nonempty Finset.card_compl_lt_iff_nonempty theorem Finset.card_univ_diff [DecidableEq α] [Fintype α] (s : Finset α) : (Finset.univ \ s).card = Fintype.card α - s.card := Finset.card_sdiff (subset_univ s) #align finset.card_univ_diff Finset.card_univ_diff theorem Finset.card_compl [DecidableEq α] [Fintype α] (s : Finset α) : sᶜ.card = Fintype.card α - s.card := Finset.card_univ_diff s #align finset.card_compl Finset.card_compl @[simp] theorem Finset.card_add_card_compl [DecidableEq α] [Fintype α] (s : Finset α) : s.card + sᶜ.card = Fintype.card α := by rw [Finset.card_compl, ← Nat.add_sub_assoc (card_le_univ s), Nat.add_sub_cancel_left] @[simp] theorem Finset.card_compl_add_card [DecidableEq α] [Fintype α] (s : Finset α) : sᶜ.card + s.card = Fintype.card α := by rw [add_comm, card_add_card_compl] theorem Fintype.card_compl_set [Fintype α] (s : Set α) [Fintype s] [Fintype (↥sᶜ : Sort _)] : Fintype.card (↥sᶜ : Sort _) = Fintype.card α - Fintype.card s := by classical rw [← Set.toFinset_card, ← Set.toFinset_card, ← Finset.card_compl, Set.toFinset_compl] #align fintype.card_compl_set Fintype.card_compl_set @[simp] theorem Fintype.card_fin (n : ℕ) : Fintype.card (Fin n) = n := List.length_finRange n #align fintype.card_fin Fintype.card_fin theorem Fintype.card_fin_lt_of_le {m n : ℕ} (h : m ≤ n) : Fintype.card {i : Fin n // i < m} = m := by conv_rhs => rw [← Fintype.card_fin m] apply Fintype.card_congr exact { toFun := fun ⟨⟨i, _⟩, hi⟩ ↦ ⟨i, hi⟩ invFun := fun ⟨i, hi⟩ ↦ ⟨⟨i, lt_of_lt_of_le hi h⟩, hi⟩ left_inv := fun i ↦ rfl right_inv := fun i ↦ rfl } theorem Finset.card_fin (n : ℕ) : Finset.card (Finset.univ : Finset (Fin n)) = n := by simp #align finset.card_fin Finset.card_fin /-- `Fin` as a map from `ℕ` to `Type` is injective. Note that since this is a statement about equality of types, using it should be avoided if possible. -/ theorem fin_injective : Function.Injective Fin := fun m n h => (Fintype.card_fin m).symm.trans <| (Fintype.card_congr <| Equiv.cast h).trans (Fintype.card_fin n) #align fin_injective fin_injective /-- A reversed version of `Fin.cast_eq_cast` that is easier to rewrite with. -/ theorem Fin.cast_eq_cast' {n m : ℕ} (h : Fin n = Fin m) : _root_.cast h = Fin.cast (fin_injective h) := by cases fin_injective h rfl #align fin.cast_eq_cast' Fin.cast_eq_cast' theorem card_finset_fin_le {n : ℕ} (s : Finset (Fin n)) : s.card ≤ n := by simpa only [Fintype.card_fin] using s.card_le_univ #align card_finset_fin_le card_finset_fin_le --@[simp] Porting note (#10618): simp can prove it theorem Fintype.card_subtype_eq (y : α) [Fintype { x // x = y }] : Fintype.card { x // x = y } = 1 := Fintype.card_unique #align fintype.card_subtype_eq Fintype.card_subtype_eq --@[simp] Porting note (#10618): simp can prove it theorem Fintype.card_subtype_eq' (y : α) [Fintype { x // y = x }] : Fintype.card { x // y = x } = 1 := Fintype.card_unique #align fintype.card_subtype_eq' Fintype.card_subtype_eq' theorem Fintype.card_empty : Fintype.card Empty = 0 := rfl #align fintype.card_empty Fintype.card_empty theorem Fintype.card_pempty : Fintype.card PEmpty = 0 := rfl #align fintype.card_pempty Fintype.card_pempty theorem Fintype.card_unit : Fintype.card Unit = 1 := rfl #align fintype.card_unit Fintype.card_unit @[simp] theorem Fintype.card_punit : Fintype.card PUnit = 1 := rfl #align fintype.card_punit Fintype.card_punit @[simp] theorem Fintype.card_bool : Fintype.card Bool = 2 := rfl #align fintype.card_bool Fintype.card_bool @[simp] theorem Fintype.card_ulift (α : Type*) [Fintype α] : Fintype.card (ULift α) = Fintype.card α := Fintype.ofEquiv_card _ #align fintype.card_ulift Fintype.card_ulift @[simp] theorem Fintype.card_plift (α : Type*) [Fintype α] : Fintype.card (PLift α) = Fintype.card α := Fintype.ofEquiv_card _ #align fintype.card_plift Fintype.card_plift @[simp] theorem Fintype.card_orderDual (α : Type*) [Fintype α] : Fintype.card αᵒᵈ = Fintype.card α := rfl #align fintype.card_order_dual Fintype.card_orderDual @[simp] theorem Fintype.card_lex (α : Type*) [Fintype α] : Fintype.card (Lex α) = Fintype.card α := rfl #align fintype.card_lex Fintype.card_lex @[simp] lemma Fintype.card_multiplicative (α : Type*) [Fintype α] : card (Multiplicative α) = card α := Finset.card_map _ @[simp] lemma Fintype.card_additive (α : Type*) [Fintype α] : card (Additive α) = card α := Finset.card_map _ /-- Given that `α ⊕ β` is a fintype, `α` is also a fintype. This is non-computable as it uses that `Sum.inl` is an injection, but there's no clear inverse if `α` is empty. -/ noncomputable def Fintype.sumLeft {α β} [Fintype (Sum α β)] : Fintype α := Fintype.ofInjective (Sum.inl : α → Sum α β) Sum.inl_injective #align fintype.sum_left Fintype.sumLeft /-- Given that `α ⊕ β` is a fintype, `β` is also a fintype. This is non-computable as it uses that `Sum.inr` is an injection, but there's no clear inverse if `β` is empty. -/ noncomputable def Fintype.sumRight {α β} [Fintype (Sum α β)] : Fintype β := Fintype.ofInjective (Sum.inr : β → Sum α β) Sum.inr_injective #align fintype.sum_right Fintype.sumRight /-! ### Relation to `Finite` In this section we prove that `α : Type*` is `Finite` if and only if `Fintype α` is nonempty. -/ -- @[nolint fintype_finite] -- Porting note: do we need this protected theorem Fintype.finite {α : Type*} (_inst : Fintype α) : Finite α := ⟨Fintype.equivFin α⟩ #align fintype.finite Fintype.finite /-- For efficiency reasons, we want `Finite` instances to have higher priority than ones coming from `Fintype` instances. -/ -- @[nolint fintype_finite] -- Porting note: do we need this instance (priority := 900) Finite.of_fintype (α : Type*) [Fintype α] : Finite α := Fintype.finite ‹_› #align finite.of_fintype Finite.of_fintype theorem finite_iff_nonempty_fintype (α : Type*) : Finite α ↔ Nonempty (Fintype α) := ⟨fun h => let ⟨_k, ⟨e⟩⟩ := @Finite.exists_equiv_fin α h ⟨Fintype.ofEquiv _ e.symm⟩, fun ⟨_⟩ => inferInstance⟩ #align finite_iff_nonempty_fintype finite_iff_nonempty_fintype /-- See also `nonempty_encodable`, `nonempty_denumerable`. -/ theorem nonempty_fintype (α : Type*) [Finite α] : Nonempty (Fintype α) := (finite_iff_nonempty_fintype α).mp ‹_› #align nonempty_fintype nonempty_fintype /-- Noncomputably get a `Fintype` instance from a `Finite` instance. This is not an instance because we want `Fintype` instances to be useful for computations. -/ noncomputable def Fintype.ofFinite (α : Type*) [Finite α] : Fintype α := (nonempty_fintype α).some #align fintype.of_finite Fintype.ofFinite theorem Finite.of_injective {α β : Sort*} [Finite β] (f : α → β) (H : Injective f) : Finite α := by rcases Finite.exists_equiv_fin β with ⟨n, ⟨e⟩⟩ classical exact .of_equiv (Set.range (e ∘ f)) (Equiv.ofInjective _ (e.injective.comp H)).symm #align finite.of_injective Finite.of_injective /-- This instance also provides `[Finite s]` for `s : Set α`. -/ instance Subtype.finite {α : Sort*} [Finite α] {p : α → Prop} : Finite { x // p x } := Finite.of_injective (↑) Subtype.coe_injective #align subtype.finite Subtype.finite theorem Finite.of_surjective {α β : Sort*} [Finite α] (f : α → β) (H : Surjective f) : Finite β := Finite.of_injective _ <| injective_surjInv H #align finite.of_surjective Finite.of_surjective theorem Finite.exists_univ_list (α) [Finite α] : ∃ l : List α, l.Nodup ∧ ∀ x : α, x ∈ l := by cases nonempty_fintype α obtain ⟨l, e⟩ := Quotient.exists_rep (@univ α _).1 have := And.intro (@univ α _).2 (@mem_univ_val α _) exact ⟨_, by rwa [← e] at this⟩ #align finite.exists_univ_list Finite.exists_univ_list theorem List.Nodup.length_le_card {α : Type*} [Fintype α] {l : List α} (h : l.Nodup) : l.length ≤ Fintype.card α := by classical exact List.toFinset_card_of_nodup h ▸ l.toFinset.card_le_univ #align list.nodup.length_le_card List.Nodup.length_le_card namespace Fintype variable [Fintype α] [Fintype β] theorem card_le_of_injective (f : α → β) (hf : Function.Injective f) : card α ≤ card β := Finset.card_le_card_of_inj_on f (fun _ _ => Finset.mem_univ _) fun _ _ _ _ h => hf h #align fintype.card_le_of_injective Fintype.card_le_of_injective theorem card_le_of_embedding (f : α ↪ β) : card α ≤ card β := card_le_of_injective f f.2 #align fintype.card_le_of_embedding Fintype.card_le_of_embedding theorem card_lt_of_injective_of_not_mem (f : α → β) (h : Function.Injective f) {b : β} (w : b ∉ Set.range f) : card α < card β := calc card α = (univ.map ⟨f, h⟩).card := (card_map _).symm _ < card β := Finset.card_lt_univ_of_not_mem <| by rwa [← mem_coe, coe_map, coe_univ, Set.image_univ] #align fintype.card_lt_of_injective_of_not_mem Fintype.card_lt_of_injective_of_not_mem theorem card_lt_of_injective_not_surjective (f : α → β) (h : Function.Injective f) (h' : ¬Function.Surjective f) : card α < card β := let ⟨_y, hy⟩ := not_forall.1 h' card_lt_of_injective_of_not_mem f h hy #align fintype.card_lt_of_injective_not_surjective Fintype.card_lt_of_injective_not_surjective theorem card_le_of_surjective (f : α → β) (h : Function.Surjective f) : card β ≤ card α := card_le_of_injective _ (Function.injective_surjInv h) #align fintype.card_le_of_surjective Fintype.card_le_of_surjective theorem card_range_le {α β : Type*} (f : α → β) [Fintype α] [Fintype (Set.range f)] : Fintype.card (Set.range f) ≤ Fintype.card α := Fintype.card_le_of_surjective (fun a => ⟨f a, by simp⟩) fun ⟨_, a, ha⟩ => ⟨a, by simpa using ha⟩ #align fintype.card_range_le Fintype.card_range_le theorem card_range {α β F : Type*} [FunLike F α β] [EmbeddingLike F α β] (f : F) [Fintype α] [Fintype (Set.range f)] : Fintype.card (Set.range f) = Fintype.card α := Eq.symm <| Fintype.card_congr <| Equiv.ofInjective _ <| EmbeddingLike.injective f #align fintype.card_range Fintype.card_range /-- The pigeonhole principle for finitely many pigeons and pigeonholes. This is the `Fintype` version of `Finset.exists_ne_map_eq_of_card_lt_of_maps_to`. -/ theorem exists_ne_map_eq_of_card_lt (f : α → β) (h : Fintype.card β < Fintype.card α) : ∃ x y, x ≠ y ∧ f x = f y := let ⟨x, _, y, _, h⟩ := Finset.exists_ne_map_eq_of_card_lt_of_maps_to h fun x _ => mem_univ (f x) ⟨x, y, h⟩ #align fintype.exists_ne_map_eq_of_card_lt Fintype.exists_ne_map_eq_of_card_lt theorem card_eq_one_iff : card α = 1 ↔ ∃ x : α, ∀ y, y = x := by rw [← card_unit, card_eq] exact ⟨fun ⟨a⟩ => ⟨a.symm (), fun y => a.injective (Subsingleton.elim _ _)⟩, fun ⟨x, hx⟩ => ⟨⟨fun _ => (), fun _ => x, fun _ => (hx _).trans (hx _).symm, fun _ => Subsingleton.elim _ _⟩⟩⟩ #align fintype.card_eq_one_iff Fintype.card_eq_one_iff theorem card_eq_zero_iff : card α = 0 ↔ IsEmpty α := by rw [card, Finset.card_eq_zero, univ_eq_empty_iff] #align fintype.card_eq_zero_iff Fintype.card_eq_zero_iff @[simp] theorem card_eq_zero [IsEmpty α] : card α = 0 := card_eq_zero_iff.2 ‹_› #align fintype.card_eq_zero Fintype.card_eq_zero alias card_of_isEmpty := card_eq_zero theorem card_eq_one_iff_nonempty_unique : card α = 1 ↔ Nonempty (Unique α) := ⟨fun h => let ⟨d, h⟩ := Fintype.card_eq_one_iff.mp h ⟨{ default := d uniq := h }⟩, fun ⟨_h⟩ => Fintype.card_unique⟩ #align fintype.card_eq_one_iff_nonempty_unique Fintype.card_eq_one_iff_nonempty_unique /-- A `Fintype` with cardinality zero is equivalent to `Empty`. -/ def cardEqZeroEquivEquivEmpty : card α = 0 ≃ (α ≃ Empty) := (Equiv.ofIff card_eq_zero_iff).trans (Equiv.equivEmptyEquiv α).symm #align fintype.card_eq_zero_equiv_equiv_empty Fintype.cardEqZeroEquivEquivEmpty theorem card_pos_iff : 0 < card α ↔ Nonempty α := Nat.pos_iff_ne_zero.trans <| not_iff_comm.mp <| not_nonempty_iff.trans card_eq_zero_iff.symm #align fintype.card_pos_iff Fintype.card_pos_iff theorem card_pos [h : Nonempty α] : 0 < card α := card_pos_iff.mpr h #align fintype.card_pos Fintype.card_pos @[simp] theorem card_ne_zero [Nonempty α] : card α ≠ 0 := _root_.ne_of_gt card_pos #align fintype.card_ne_zero Fintype.card_ne_zero instance [Nonempty α] : NeZero (card α) := ⟨card_ne_zero⟩ theorem card_le_one_iff : card α ≤ 1 ↔ ∀ a b : α, a = b := let n := card α have hn : n = card α := rfl match n, hn with | 0, ha => ⟨fun _h => fun a => (card_eq_zero_iff.1 ha.symm).elim a, fun _ => ha ▸ Nat.le_succ _⟩ | 1, ha => ⟨fun _h => fun a b => by let ⟨x, hx⟩ := card_eq_one_iff.1 ha.symm rw [hx a, hx b], fun _ => ha ▸ le_rfl⟩ | n + 2, ha => ⟨fun h => False.elim <| by rw [← ha] at h; cases h with | step h => cases h; , fun h => card_unit ▸ card_le_of_injective (fun _ => ()) fun _ _ _ => h _ _⟩ #align fintype.card_le_one_iff Fintype.card_le_one_iff theorem card_le_one_iff_subsingleton : card α ≤ 1 ↔ Subsingleton α := card_le_one_iff.trans subsingleton_iff.symm #align fintype.card_le_one_iff_subsingleton Fintype.card_le_one_iff_subsingleton theorem one_lt_card_iff_nontrivial : 1 < card α ↔ Nontrivial α := by rw [← not_iff_not, not_lt, not_nontrivial_iff_subsingleton, card_le_one_iff_subsingleton] #align fintype.one_lt_card_iff_nontrivial Fintype.one_lt_card_iff_nontrivial theorem exists_ne_of_one_lt_card (h : 1 < card α) (a : α) : ∃ b : α, b ≠ a := haveI : Nontrivial α := one_lt_card_iff_nontrivial.1 h exists_ne a #align fintype.exists_ne_of_one_lt_card Fintype.exists_ne_of_one_lt_card theorem exists_pair_of_one_lt_card (h : 1 < card α) : ∃ a b : α, a ≠ b := haveI : Nontrivial α := one_lt_card_iff_nontrivial.1 h exists_pair_ne α #align fintype.exists_pair_of_one_lt_card Fintype.exists_pair_of_one_lt_card theorem card_eq_one_of_forall_eq {i : α} (h : ∀ j, j = i) : card α = 1 := Fintype.card_eq_one_iff.2 ⟨i, h⟩ #align fintype.card_eq_one_of_forall_eq Fintype.card_eq_one_of_forall_eq
Mathlib/Data/Fintype/Card.lean
612
617
theorem exists_unique_iff_card_one {α} [Fintype α] (p : α → Prop) [DecidablePred p] : (∃! a : α, p a) ↔ (Finset.univ.filter p).card = 1 := by
rw [Finset.card_eq_one] refine exists_congr fun x => ?_ simp only [forall_true_left, Subset.antisymm_iff, subset_singleton_iff', singleton_subset_iff, true_and, and_comm, mem_univ, mem_filter]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attr import Mathlib.Data.Multiset.FinsetOps import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Basic #align_import data.finset.basic from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Finite sets Terms of type `Finset α` are one way of talking about finite subsets of `α` in mathlib. Below, `Finset α` is defined as a structure with 2 fields: 1. `val` is a `Multiset α` of elements; 2. `nodup` is a proof that `val` has no duplicates. Finsets in Lean are constructive in that they have an underlying `List` that enumerates their elements. In particular, any function that uses the data of the underlying list cannot depend on its ordering. This is handled on the `Multiset` level by multiset API, so in most cases one needn't worry about it explicitly. Finsets give a basic foundation for defining finite sums and products over types: 1. `∑ i ∈ (s : Finset α), f i`; 2. `∏ i ∈ (s : Finset α), f i`. Lean refers to these operations as big operators. More information can be found in `Mathlib.Algebra.BigOperators.Group.Finset`. Finsets are directly used to define fintypes in Lean. A `Fintype α` instance for a type `α` consists of a universal `Finset α` containing every term of `α`, called `univ`. See `Mathlib.Data.Fintype.Basic`. There is also `univ'`, the noncomputable partner to `univ`, which is defined to be `α` as a finset if `α` is finite, and the empty finset otherwise. See `Mathlib.Data.Fintype.Basic`. `Finset.card`, the size of a finset is defined in `Mathlib.Data.Finset.Card`. This is then used to define `Fintype.card`, the size of a type. ## Main declarations ### Main definitions * `Finset`: Defines a type for the finite subsets of `α`. Constructing a `Finset` requires two pieces of data: `val`, a `Multiset α` of elements, and `nodup`, a proof that `val` has no duplicates. * `Finset.instMembershipFinset`: Defines membership `a ∈ (s : Finset α)`. * `Finset.instCoeTCFinsetSet`: Provides a coercion `s : Finset α` to `s : Set α`. * `Finset.instCoeSortFinsetType`: Coerce `s : Finset α` to the type of all `x ∈ s`. * `Finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `Finset α`, it suffices to prove it for the empty finset, and to show that if it holds for some `Finset α`, then it holds for the finset obtained by inserting a new element. * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Finset constructions * `Finset.instSingletonFinset`: Denoted by `{a}`; the finset consisting of one element. * `Finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements. * `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`. This convention is consistent with other languages and normalizes `card (range n) = n`. Beware, `n` is not in `range n`. * `Finset.attach`: Given `s : Finset α`, `attach s` forms a finset of elements of the subtype `{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set. ### Finsets from functions * `Finset.filter`: Given a decidable predicate `p : α → Prop`, `s.filter p` is the finset consisting of those elements in `s` satisfying the predicate `p`. ### The lattice structure on subsets of finsets There is a natural lattice structure on the subsets of a set. In Lean, we use lattice notation to talk about things involving unions and intersections. See `Mathlib.Order.Lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is called `top` with `⊤ = univ`. * `Finset.instHasSubsetFinset`: Lots of API about lattices, otherwise behaves as one would expect. * `Finset.instUnionFinset`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`. See `Finset.sup`/`Finset.biUnion` for finite unions. * `Finset.instInterFinset`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`. See `Finset.inf` for finite intersections. ### Operations on two or more finsets * `insert` and `Finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h` returns the same except that it requires a hypothesis stating that `a` is not already in `s`. This does not require decidable equality on the type `α`. * `Finset.instUnionFinset`: see "The lattice structure on subsets of finsets" * `Finset.instInterFinset`: see "The lattice structure on subsets of finsets" * `Finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed. * `Finset.instSDiffFinset`: Defines the set difference `s \ t` for finsets `s` and `t`. * `Finset.product`: Given finsets of `α` and `β`, defines finsets of `α × β`. For arbitrary dependent products, see `Mathlib.Data.Finset.Pi`. ### Predicates on finsets * `Disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their intersection is empty. * `Finset.Nonempty`: A finset is nonempty if it has elements. This is equivalent to saying `s ≠ ∅`. ### Equivalences between finsets * The `Mathlib.Data.Equiv` files describe a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen assert_not_exists Multiset.Powerset assert_not_exists CompleteLattice open Multiset Subtype Nat Function universe u variable {α : Type*} {β : Type*} {γ : Type*} /-- `Finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure Finset (α : Type*) where /-- The underlying multiset -/ val : Multiset α /-- `val` contains no duplicates -/ nodup : Nodup val #align finset Finset instance Multiset.canLiftFinset {α} : CanLift (Multiset α) (Finset α) Finset.val Multiset.Nodup := ⟨fun m hm => ⟨⟨m, hm⟩, rfl⟩⟩ #align multiset.can_lift_finset Multiset.canLiftFinset namespace Finset theorem eq_of_veq : ∀ {s t : Finset α}, s.1 = t.1 → s = t | ⟨s, _⟩, ⟨t, _⟩, h => by cases h; rfl #align finset.eq_of_veq Finset.eq_of_veq theorem val_injective : Injective (val : Finset α → Multiset α) := fun _ _ => eq_of_veq #align finset.val_injective Finset.val_injective @[simp] theorem val_inj {s t : Finset α} : s.1 = t.1 ↔ s = t := val_injective.eq_iff #align finset.val_inj Finset.val_inj @[simp] theorem dedup_eq_self [DecidableEq α] (s : Finset α) : dedup s.1 = s.1 := s.2.dedup #align finset.dedup_eq_self Finset.dedup_eq_self instance decidableEq [DecidableEq α] : DecidableEq (Finset α) | _, _ => decidable_of_iff _ val_inj #align finset.has_decidable_eq Finset.decidableEq /-! ### membership -/ instance : Membership α (Finset α) := ⟨fun a s => a ∈ s.1⟩ theorem mem_def {a : α} {s : Finset α} : a ∈ s ↔ a ∈ s.1 := Iff.rfl #align finset.mem_def Finset.mem_def @[simp] theorem mem_val {a : α} {s : Finset α} : a ∈ s.1 ↔ a ∈ s := Iff.rfl #align finset.mem_val Finset.mem_val @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @Finset.mk α s nd ↔ a ∈ s := Iff.rfl #align finset.mem_mk Finset.mem_mk instance decidableMem [_h : DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ s) := Multiset.decidableMem _ _ #align finset.decidable_mem Finset.decidableMem @[simp] lemma forall_mem_not_eq {s : Finset α} {a : α} : (∀ b ∈ s, ¬ a = b) ↔ a ∉ s := by aesop @[simp] lemma forall_mem_not_eq' {s : Finset α} {a : α} : (∀ b ∈ s, ¬ b = a) ↔ a ∉ s := by aesop /-! ### set coercion -/ -- Porting note (#11445): new definition /-- Convert a finset to a set in the natural way. -/ @[coe] def toSet (s : Finset α) : Set α := { a | a ∈ s } /-- Convert a finset to a set in the natural way. -/ instance : CoeTC (Finset α) (Set α) := ⟨toSet⟩ @[simp, norm_cast] theorem mem_coe {a : α} {s : Finset α} : a ∈ (s : Set α) ↔ a ∈ (s : Finset α) := Iff.rfl #align finset.mem_coe Finset.mem_coe @[simp] theorem setOf_mem {α} {s : Finset α} : { a | a ∈ s } = s := rfl #align finset.set_of_mem Finset.setOf_mem @[simp] theorem coe_mem {s : Finset α} (x : (s : Set α)) : ↑x ∈ s := x.2 #align finset.coe_mem Finset.coe_mem -- Porting note (#10618): @[simp] can prove this theorem mk_coe {s : Finset α} (x : (s : Set α)) {h} : (⟨x, h⟩ : (s : Set α)) = x := Subtype.coe_eta _ _ #align finset.mk_coe Finset.mk_coe instance decidableMem' [DecidableEq α] (a : α) (s : Finset α) : Decidable (a ∈ (s : Set α)) := s.decidableMem _ #align finset.decidable_mem' Finset.decidableMem' /-! ### extensionality -/ theorem ext_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans <| s₁.nodup.ext s₂.nodup #align finset.ext_iff Finset.ext_iff @[ext] theorem ext {s₁ s₂ : Finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext_iff.2 #align finset.ext Finset.ext @[simp, norm_cast] theorem coe_inj {s₁ s₂ : Finset α} : (s₁ : Set α) = s₂ ↔ s₁ = s₂ := Set.ext_iff.trans ext_iff.symm #align finset.coe_inj Finset.coe_inj theorem coe_injective {α} : Injective ((↑) : Finset α → Set α) := fun _s _t => coe_inj.1 #align finset.coe_injective Finset.coe_injective /-! ### type coercion -/ /-- Coercion from a finset to the corresponding subtype. -/ instance {α : Type u} : CoeSort (Finset α) (Type u) := ⟨fun s => { x // x ∈ s }⟩ -- Porting note (#10618): @[simp] can prove this protected theorem forall_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∀ x : s, p x) ↔ ∀ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align finset.forall_coe Finset.forall_coe -- Porting note (#10618): @[simp] can prove this protected theorem exists_coe {α : Type*} (s : Finset α) (p : s → Prop) : (∃ x : s, p x) ↔ ∃ (x : α) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align finset.exists_coe Finset.exists_coe instance PiFinsetCoe.canLift (ι : Type*) (α : ι → Type*) [_ne : ∀ i, Nonempty (α i)] (s : Finset ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α (· ∈ s) #align finset.pi_finset_coe.can_lift Finset.PiFinsetCoe.canLift instance PiFinsetCoe.canLift' (ι α : Type*) [_ne : Nonempty α] (s : Finset ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiFinsetCoe.canLift ι (fun _ => α) s #align finset.pi_finset_coe.can_lift' Finset.PiFinsetCoe.canLift' instance FinsetCoe.canLift (s : Finset α) : CanLift α s (↑) fun a => a ∈ s where prf a ha := ⟨⟨a, ha⟩, rfl⟩ #align finset.finset_coe.can_lift Finset.FinsetCoe.canLift @[simp, norm_cast] theorem coe_sort_coe (s : Finset α) : ((s : Set α) : Sort _) = s := rfl #align finset.coe_sort_coe Finset.coe_sort_coe /-! ### Subset and strict subset relations -/ section Subset variable {s t : Finset α} instance : HasSubset (Finset α) := ⟨fun s t => ∀ ⦃a⦄, a ∈ s → a ∈ t⟩ instance : HasSSubset (Finset α) := ⟨fun s t => s ⊆ t ∧ ¬t ⊆ s⟩ instance partialOrder : PartialOrder (Finset α) where le := (· ⊆ ·) lt := (· ⊂ ·) le_refl s a := id le_trans s t u hst htu a ha := htu <| hst ha le_antisymm s t hst hts := ext fun a => ⟨@hst _, @hts _⟩ instance : IsRefl (Finset α) (· ⊆ ·) := show IsRefl (Finset α) (· ≤ ·) by infer_instance instance : IsTrans (Finset α) (· ⊆ ·) := show IsTrans (Finset α) (· ≤ ·) by infer_instance instance : IsAntisymm (Finset α) (· ⊆ ·) := show IsAntisymm (Finset α) (· ≤ ·) by infer_instance instance : IsIrrefl (Finset α) (· ⊂ ·) := show IsIrrefl (Finset α) (· < ·) by infer_instance instance : IsTrans (Finset α) (· ⊂ ·) := show IsTrans (Finset α) (· < ·) by infer_instance instance : IsAsymm (Finset α) (· ⊂ ·) := show IsAsymm (Finset α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Finset α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ theorem subset_def : s ⊆ t ↔ s.1 ⊆ t.1 := Iff.rfl #align finset.subset_def Finset.subset_def theorem ssubset_def : s ⊂ t ↔ s ⊆ t ∧ ¬t ⊆ s := Iff.rfl #align finset.ssubset_def Finset.ssubset_def @[simp] theorem Subset.refl (s : Finset α) : s ⊆ s := Multiset.Subset.refl _ #align finset.subset.refl Finset.Subset.refl protected theorem Subset.rfl {s : Finset α} : s ⊆ s := Subset.refl _ #align finset.subset.rfl Finset.Subset.rfl protected theorem subset_of_eq {s t : Finset α} (h : s = t) : s ⊆ t := h ▸ Subset.refl _ #align finset.subset_of_eq Finset.subset_of_eq theorem Subset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := Multiset.Subset.trans #align finset.subset.trans Finset.Subset.trans theorem Superset.trans {s₁ s₂ s₃ : Finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := fun h' h => Subset.trans h h' #align finset.superset.trans Finset.Superset.trans theorem mem_of_subset {s₁ s₂ : Finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := Multiset.mem_of_subset #align finset.mem_of_subset Finset.mem_of_subset theorem not_mem_mono {s t : Finset α} (h : s ⊆ t) {a : α} : a ∉ t → a ∉ s := mt <| @h _ #align finset.not_mem_mono Finset.not_mem_mono theorem Subset.antisymm {s₁ s₂ : Finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext fun a => ⟨@H₁ a, @H₂ a⟩ #align finset.subset.antisymm Finset.Subset.antisymm theorem subset_iff {s₁ s₂ : Finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := Iff.rfl #align finset.subset_iff Finset.subset_iff @[simp, norm_cast] theorem coe_subset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.coe_subset Finset.coe_subset @[simp] theorem val_le_iff {s₁ s₂ : Finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 #align finset.val_le_iff Finset.val_le_iff theorem Subset.antisymm_iff {s₁ s₂ : Finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff #align finset.subset.antisymm_iff Finset.Subset.antisymm_iff theorem not_subset : ¬s ⊆ t ↔ ∃ x ∈ s, x ∉ t := by simp only [← coe_subset, Set.not_subset, mem_coe] #align finset.not_subset Finset.not_subset @[simp] theorem le_eq_subset : ((· ≤ ·) : Finset α → Finset α → Prop) = (· ⊆ ·) := rfl #align finset.le_eq_subset Finset.le_eq_subset @[simp] theorem lt_eq_subset : ((· < ·) : Finset α → Finset α → Prop) = (· ⊂ ·) := rfl #align finset.lt_eq_subset Finset.lt_eq_subset theorem le_iff_subset {s₁ s₂ : Finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := Iff.rfl #align finset.le_iff_subset Finset.le_iff_subset theorem lt_iff_ssubset {s₁ s₂ : Finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := Iff.rfl #align finset.lt_iff_ssubset Finset.lt_iff_ssubset @[simp, norm_cast] theorem coe_ssubset {s₁ s₂ : Finset α} : (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊂ s₂ := show (s₁ : Set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁ by simp only [Set.ssubset_def, Finset.coe_subset] #align finset.coe_ssubset Finset.coe_ssubset @[simp] theorem val_lt_iff {s₁ s₂ : Finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff <| not_congr val_le_iff #align finset.val_lt_iff Finset.val_lt_iff lemma val_strictMono : StrictMono (val : Finset α → Multiset α) := fun _ _ ↦ val_lt_iff.2 theorem ssubset_iff_subset_ne {s t : Finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne _ _ s t #align finset.ssubset_iff_subset_ne Finset.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ := Set.ssubset_iff_of_subset h #align finset.ssubset_iff_of_subset Finset.ssubset_iff_of_subset theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃ #align finset.ssubset_of_ssubset_of_subset Finset.ssubset_of_ssubset_of_subset theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := Set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃ #align finset.ssubset_of_subset_of_ssubset Finset.ssubset_of_subset_of_ssubset theorem exists_of_ssubset {s₁ s₂ : Finset α} (h : s₁ ⊂ s₂) : ∃ x ∈ s₂, x ∉ s₁ := Set.exists_of_ssubset h #align finset.exists_of_ssubset Finset.exists_of_ssubset instance isWellFounded_ssubset : IsWellFounded (Finset α) (· ⊂ ·) := Subrelation.isWellFounded (InvImage _ _) val_lt_iff.2 #align finset.is_well_founded_ssubset Finset.isWellFounded_ssubset instance wellFoundedLT : WellFoundedLT (Finset α) := Finset.isWellFounded_ssubset #align finset.is_well_founded_lt Finset.wellFoundedLT end Subset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans /-! ### Order embedding from `Finset α` to `Set α` -/ /-- Coercion to `Set α` as an `OrderEmbedding`. -/ def coeEmb : Finset α ↪o Set α := ⟨⟨(↑), coe_injective⟩, coe_subset⟩ #align finset.coe_emb Finset.coeEmb @[simp] theorem coe_coeEmb : ⇑(coeEmb : Finset α ↪o Set α) = ((↑) : Finset α → Set α) := rfl #align finset.coe_coe_emb Finset.coe_coeEmb /-! ### Nonempty -/ /-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s #align finset.nonempty Finset.Nonempty -- Porting note: Much longer than in Lean3 instance decidableNonempty {s : Finset α} : Decidable s.Nonempty := Quotient.recOnSubsingleton (motive := fun s : Multiset α => Decidable (∃ a, a ∈ s)) s.1 (fun l : List α => match l with | [] => isFalse <| by simp | a::l => isTrue ⟨a, by simp⟩) #align finset.decidable_nonempty Finset.decidableNonempty @[simp, norm_cast] theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty := Iff.rfl #align finset.coe_nonempty Finset.coe_nonempty -- Porting note: Left-hand side simplifies @[simp] theorem nonempty_coe_sort {s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty := nonempty_subtype #align finset.nonempty_coe_sort Finset.nonempty_coe_sort alias ⟨_, Nonempty.to_set⟩ := coe_nonempty #align finset.nonempty.to_set Finset.Nonempty.to_set alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align finset.nonempty.coe_sort Finset.Nonempty.coe_sort theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s := h #align finset.nonempty.bex Finset.Nonempty.exists_mem @[deprecated (since := "2024-03-23")] alias Nonempty.bex := Nonempty.exists_mem theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := Set.Nonempty.mono hst hs #align finset.nonempty.mono Finset.Nonempty.mono theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p := let ⟨x, hx⟩ := h ⟨fun h => h x hx, fun h _ _ => h⟩ #align finset.nonempty.forall_const Finset.Nonempty.forall_const theorem Nonempty.to_subtype {s : Finset α} : s.Nonempty → Nonempty s := nonempty_coe_sort.2 #align finset.nonempty.to_subtype Finset.Nonempty.to_subtype theorem Nonempty.to_type {s : Finset α} : s.Nonempty → Nonempty α := fun ⟨x, _hx⟩ => ⟨x⟩ #align finset.nonempty.to_type Finset.Nonempty.to_type /-! ### empty -/ section Empty variable {s : Finset α} /-- The empty finset -/ protected def empty : Finset α := ⟨0, nodup_zero⟩ #align finset.empty Finset.empty instance : EmptyCollection (Finset α) := ⟨Finset.empty⟩ instance inhabitedFinset : Inhabited (Finset α) := ⟨∅⟩ #align finset.inhabited_finset Finset.inhabitedFinset @[simp] theorem empty_val : (∅ : Finset α).1 = 0 := rfl #align finset.empty_val Finset.empty_val @[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : Finset α) := by -- Porting note: was `id`. `a ∈ List.nil` is no longer definitionally equal to `False` simp only [mem_def, empty_val, not_mem_zero, not_false_iff] #align finset.not_mem_empty Finset.not_mem_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx #align finset.not_nonempty_empty Finset.not_nonempty_empty @[simp] theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) = ∅ := rfl #align finset.mk_zero Finset.mk_zero theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e => not_mem_empty a <| e ▸ h #align finset.ne_empty_of_mem Finset.ne_empty_of_mem theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ := (Exists.elim h) fun _a => ne_empty_of_mem #align finset.nonempty.ne_empty Finset.Nonempty.ne_empty @[simp] theorem empty_subset (s : Finset α) : ∅ ⊆ s := zero_subset _ #align finset.empty_subset Finset.empty_subset theorem eq_empty_of_forall_not_mem {s : Finset α} (H : ∀ x, x ∉ s) : s = ∅ := eq_of_veq (eq_zero_of_forall_not_mem H) #align finset.eq_empty_of_forall_not_mem Finset.eq_empty_of_forall_not_mem theorem eq_empty_iff_forall_not_mem {s : Finset α} : s = ∅ ↔ ∀ x, x ∉ s := -- Porting note: used `id` ⟨by rintro rfl x; apply not_mem_empty, fun h => eq_empty_of_forall_not_mem h⟩ #align finset.eq_empty_iff_forall_not_mem Finset.eq_empty_iff_forall_not_mem @[simp] theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅ #align finset.val_eq_zero Finset.val_eq_zero theorem subset_empty {s : Finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero #align finset.subset_empty Finset.subset_empty @[simp] theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h => let ⟨_, he, _⟩ := exists_of_ssubset h -- Porting note: was `he` not_mem_empty _ he #align finset.not_ssubset_empty Finset.not_ssubset_empty theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty := exists_mem_of_ne_zero (mt val_eq_zero.1 h) #align finset.nonempty_of_ne_empty Finset.nonempty_of_ne_empty theorem nonempty_iff_ne_empty {s : Finset α} : s.Nonempty ↔ s ≠ ∅ := ⟨Nonempty.ne_empty, nonempty_of_ne_empty⟩ #align finset.nonempty_iff_ne_empty Finset.nonempty_iff_ne_empty @[simp] theorem not_nonempty_iff_eq_empty {s : Finset α} : ¬s.Nonempty ↔ s = ∅ := nonempty_iff_ne_empty.not.trans not_not #align finset.not_nonempty_iff_eq_empty Finset.not_nonempty_iff_eq_empty theorem eq_empty_or_nonempty (s : Finset α) : s = ∅ ∨ s.Nonempty := by_cases Or.inl fun h => Or.inr (nonempty_of_ne_empty h) #align finset.eq_empty_or_nonempty Finset.eq_empty_or_nonempty @[simp, norm_cast] theorem coe_empty : ((∅ : Finset α) : Set α) = ∅ := Set.ext <| by simp #align finset.coe_empty Finset.coe_empty @[simp, norm_cast] theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj] #align finset.coe_eq_empty Finset.coe_eq_empty -- Porting note: Left-hand side simplifies @[simp] theorem isEmpty_coe_sort {s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅ := by simpa using @Set.isEmpty_coe_sort α s #align finset.is_empty_coe_sort Finset.isEmpty_coe_sort instance instIsEmpty : IsEmpty (∅ : Finset α) := isEmpty_coe_sort.2 rfl /-- A `Finset` for an empty type is empty. -/ theorem eq_empty_of_isEmpty [IsEmpty α] (s : Finset α) : s = ∅ := Finset.eq_empty_of_forall_not_mem isEmptyElim #align finset.eq_empty_of_is_empty Finset.eq_empty_of_isEmpty instance : OrderBot (Finset α) where bot := ∅ bot_le := empty_subset @[simp] theorem bot_eq_empty : (⊥ : Finset α) = ∅ := rfl #align finset.bot_eq_empty Finset.bot_eq_empty @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Finset α) _ _ _).trans nonempty_iff_ne_empty.symm #align finset.empty_ssubset Finset.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align finset.nonempty.empty_ssubset Finset.Nonempty.empty_ssubset end Empty /-! ### singleton -/ section Singleton variable {s : Finset α} {a b : α} /-- `{a} : Finset a` is the set `{a}` containing `a` and nothing else. This differs from `insert a ∅` in that it does not require a `DecidableEq` instance for `α`. -/ instance : Singleton α (Finset α) := ⟨fun a => ⟨{a}, nodup_singleton a⟩⟩ @[simp] theorem singleton_val (a : α) : ({a} : Finset α).1 = {a} := rfl #align finset.singleton_val Finset.singleton_val @[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : Finset α) ↔ b = a := Multiset.mem_singleton #align finset.mem_singleton Finset.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Finset α)) : x = y := mem_singleton.1 h #align finset.eq_of_mem_singleton Finset.eq_of_mem_singleton theorem not_mem_singleton {a b : α} : a ∉ ({b} : Finset α) ↔ a ≠ b := not_congr mem_singleton #align finset.not_mem_singleton Finset.not_mem_singleton theorem mem_singleton_self (a : α) : a ∈ ({a} : Finset α) := -- Porting note: was `Or.inl rfl` mem_singleton.mpr rfl #align finset.mem_singleton_self Finset.mem_singleton_self @[simp] theorem val_eq_singleton_iff {a : α} {s : Finset α} : s.val = {a} ↔ s = {a} := by rw [← val_inj] rfl #align finset.val_eq_singleton_iff Finset.val_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Finset α) := fun _a _b h => mem_singleton.1 (h ▸ mem_singleton_self _) #align finset.singleton_injective Finset.singleton_injective @[simp] theorem singleton_inj : ({a} : Finset α) = {b} ↔ a = b := singleton_injective.eq_iff #align finset.singleton_inj Finset.singleton_inj @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem singleton_nonempty (a : α) : ({a} : Finset α).Nonempty := ⟨a, mem_singleton_self a⟩ #align finset.singleton_nonempty Finset.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Finset α) ≠ ∅ := (singleton_nonempty a).ne_empty #align finset.singleton_ne_empty Finset.singleton_ne_empty theorem empty_ssubset_singleton : (∅ : Finset α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align finset.empty_ssubset_singleton Finset.empty_ssubset_singleton @[simp, norm_cast] theorem coe_singleton (a : α) : (({a} : Finset α) : Set α) = {a} := by ext simp #align finset.coe_singleton Finset.coe_singleton @[simp, norm_cast] theorem coe_eq_singleton {s : Finset α} {a : α} : (s : Set α) = {a} ↔ s = {a} := by rw [← coe_singleton, coe_inj] #align finset.coe_eq_singleton Finset.coe_eq_singleton @[norm_cast] lemma coe_subset_singleton : (s : Set α) ⊆ {a} ↔ s ⊆ {a} := by rw [← coe_subset, coe_singleton] @[norm_cast] lemma singleton_subset_coe : {a} ⊆ (s : Set α) ↔ {a} ⊆ s := by rw [← coe_subset, coe_singleton] theorem eq_singleton_iff_unique_mem {s : Finset α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := by constructor <;> intro t · rw [t] exact ⟨Finset.mem_singleton_self _, fun _ => Finset.mem_singleton.1⟩ · ext rw [Finset.mem_singleton] exact ⟨t.right _, fun r => r.symm ▸ t.left⟩ #align finset.eq_singleton_iff_unique_mem Finset.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem {s : Finset α} {a : α} : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := by constructor · rintro rfl simp · rintro ⟨hne, h_uniq⟩ rw [eq_singleton_iff_unique_mem] refine ⟨?_, h_uniq⟩ rw [← h_uniq hne.choose hne.choose_spec] exact hne.choose_spec #align finset.eq_singleton_iff_nonempty_unique_mem Finset.eq_singleton_iff_nonempty_unique_mem theorem nonempty_iff_eq_singleton_default [Unique α] {s : Finset α} : s.Nonempty ↔ s = {default} := by simp [eq_singleton_iff_nonempty_unique_mem, eq_iff_true_of_subsingleton] #align finset.nonempty_iff_eq_singleton_default Finset.nonempty_iff_eq_singleton_default alias ⟨Nonempty.eq_singleton_default, _⟩ := nonempty_iff_eq_singleton_default #align finset.nonempty.eq_singleton_default Finset.Nonempty.eq_singleton_default theorem singleton_iff_unique_mem (s : Finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s := by simp only [eq_singleton_iff_unique_mem, ExistsUnique] #align finset.singleton_iff_unique_mem Finset.singleton_iff_unique_mem theorem singleton_subset_set_iff {s : Set α} {a : α} : ↑({a} : Finset α) ⊆ s ↔ a ∈ s := by rw [coe_singleton, Set.singleton_subset_iff] #align finset.singleton_subset_set_iff Finset.singleton_subset_set_iff @[simp] theorem singleton_subset_iff {s : Finset α} {a : α} : {a} ⊆ s ↔ a ∈ s := singleton_subset_set_iff #align finset.singleton_subset_iff Finset.singleton_subset_iff @[simp] theorem subset_singleton_iff {s : Finset α} {a : α} : s ⊆ {a} ↔ s = ∅ ∨ s = {a} := by rw [← coe_subset, coe_singleton, Set.subset_singleton_iff_eq, coe_eq_empty, coe_eq_singleton] #align finset.subset_singleton_iff Finset.subset_singleton_iff theorem singleton_subset_singleton : ({a} : Finset α) ⊆ {b} ↔ a = b := by simp #align finset.singleton_subset_singleton Finset.singleton_subset_singleton protected theorem Nonempty.subset_singleton_iff {s : Finset α} {a : α} (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} := subset_singleton_iff.trans <| or_iff_right h.ne_empty #align finset.nonempty.subset_singleton_iff Finset.Nonempty.subset_singleton_iff theorem subset_singleton_iff' {s : Finset α} {a : α} : s ⊆ {a} ↔ ∀ b ∈ s, b = a := forall₂_congr fun _ _ => mem_singleton #align finset.subset_singleton_iff' Finset.subset_singleton_iff' @[simp] theorem ssubset_singleton_iff {s : Finset α} {a : α} : s ⊂ {a} ↔ s = ∅ := by rw [← coe_ssubset, coe_singleton, Set.ssubset_singleton_iff, coe_eq_empty] #align finset.ssubset_singleton_iff Finset.ssubset_singleton_iff theorem eq_empty_of_ssubset_singleton {s : Finset α} {x : α} (hs : s ⊂ {x}) : s = ∅ := ssubset_singleton_iff.1 hs #align finset.eq_empty_of_ssubset_singleton Finset.eq_empty_of_ssubset_singleton /-- A finset is nontrivial if it has at least two elements. -/ protected abbrev Nontrivial (s : Finset α) : Prop := (s : Set α).Nontrivial #align finset.nontrivial Finset.Nontrivial @[simp] theorem not_nontrivial_empty : ¬ (∅ : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_empty Finset.not_nontrivial_empty @[simp] theorem not_nontrivial_singleton : ¬ ({a} : Finset α).Nontrivial := by simp [Finset.Nontrivial] #align finset.not_nontrivial_singleton Finset.not_nontrivial_singleton theorem Nontrivial.ne_singleton (hs : s.Nontrivial) : s ≠ {a} := by rintro rfl; exact not_nontrivial_singleton hs #align finset.nontrivial.ne_singleton Finset.Nontrivial.ne_singleton nonrec lemma Nontrivial.exists_ne (hs : s.Nontrivial) (a : α) : ∃ b ∈ s, b ≠ a := hs.exists_ne _ theorem eq_singleton_or_nontrivial (ha : a ∈ s) : s = {a} ∨ s.Nontrivial := by rw [← coe_eq_singleton]; exact Set.eq_singleton_or_nontrivial ha #align finset.eq_singleton_or_nontrivial Finset.eq_singleton_or_nontrivial theorem nontrivial_iff_ne_singleton (ha : a ∈ s) : s.Nontrivial ↔ s ≠ {a} := ⟨Nontrivial.ne_singleton, (eq_singleton_or_nontrivial ha).resolve_left⟩ #align finset.nontrivial_iff_ne_singleton Finset.nontrivial_iff_ne_singleton theorem Nonempty.exists_eq_singleton_or_nontrivial : s.Nonempty → (∃ a, s = {a}) ∨ s.Nontrivial := fun ⟨a, ha⟩ => (eq_singleton_or_nontrivial ha).imp_left <| Exists.intro a #align finset.nonempty.exists_eq_singleton_or_nontrivial Finset.Nonempty.exists_eq_singleton_or_nontrivial instance instNontrivial [Nonempty α] : Nontrivial (Finset α) := ‹Nonempty α›.elim fun a => ⟨⟨{a}, ∅, singleton_ne_empty _⟩⟩ #align finset.nontrivial' Finset.instNontrivial instance [IsEmpty α] : Unique (Finset α) where default := ∅ uniq _ := eq_empty_of_forall_not_mem isEmptyElim instance (i : α) : Unique ({i} : Finset α) where default := ⟨i, mem_singleton_self i⟩ uniq j := Subtype.ext <| mem_singleton.mp j.2 @[simp] lemma default_singleton (i : α) : ((default : ({i} : Finset α)) : α) = i := rfl end Singleton /-! ### cons -/ section Cons variable {s t : Finset α} {a b : α} /-- `cons a s h` is the set `{a} ∪ s` containing `a` and the elements of `s`. It is the same as `insert a s` when it is defined, but unlike `insert a s` it does not require `DecidableEq α`, and the union is guaranteed to be disjoint. -/ def cons (a : α) (s : Finset α) (h : a ∉ s) : Finset α := ⟨a ::ₘ s.1, nodup_cons.2 ⟨h, s.2⟩⟩ #align finset.cons Finset.cons @[simp] theorem mem_cons {h} : b ∈ s.cons a h ↔ b = a ∨ b ∈ s := Multiset.mem_cons #align finset.mem_cons Finset.mem_cons theorem mem_cons_of_mem {a b : α} {s : Finset α} {hb : b ∉ s} (ha : a ∈ s) : a ∈ cons b s hb := Multiset.mem_cons_of_mem ha -- Porting note (#10618): @[simp] can prove this theorem mem_cons_self (a : α) (s : Finset α) {h} : a ∈ cons a s h := Multiset.mem_cons_self _ _ #align finset.mem_cons_self Finset.mem_cons_self @[simp] theorem cons_val (h : a ∉ s) : (cons a s h).1 = a ::ₘ s.1 := rfl #align finset.cons_val Finset.cons_val theorem forall_mem_cons (h : a ∉ s) (p : α → Prop) : (∀ x, x ∈ cons a s h → p x) ↔ p a ∧ ∀ x, x ∈ s → p x := by simp only [mem_cons, or_imp, forall_and, forall_eq] #align finset.forall_mem_cons Finset.forall_mem_cons /-- Useful in proofs by induction. -/ theorem forall_of_forall_cons {p : α → Prop} {h : a ∉ s} (H : ∀ x, x ∈ cons a s h → p x) (x) (h : x ∈ s) : p x := H _ <| mem_cons.2 <| Or.inr h #align finset.forall_of_forall_cons Finset.forall_of_forall_cons @[simp] theorem mk_cons {s : Multiset α} (h : (a ::ₘ s).Nodup) : (⟨a ::ₘ s, h⟩ : Finset α) = cons a ⟨s, (nodup_cons.1 h).2⟩ (nodup_cons.1 h).1 := rfl #align finset.mk_cons Finset.mk_cons @[simp] theorem cons_empty (a : α) : cons a ∅ (not_mem_empty _) = {a} := rfl #align finset.cons_empty Finset.cons_empty @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_cons (h : a ∉ s) : (cons a s h).Nonempty := ⟨a, mem_cons.2 <| Or.inl rfl⟩ #align finset.nonempty_cons Finset.nonempty_cons @[simp] theorem nonempty_mk {m : Multiset α} {hm} : (⟨m, hm⟩ : Finset α).Nonempty ↔ m ≠ 0 := by induction m using Multiset.induction_on <;> simp #align finset.nonempty_mk Finset.nonempty_mk @[simp] theorem coe_cons {a s h} : (@cons α a s h : Set α) = insert a (s : Set α) := by ext simp #align finset.coe_cons Finset.coe_cons theorem subset_cons (h : a ∉ s) : s ⊆ s.cons a h := Multiset.subset_cons _ _ #align finset.subset_cons Finset.subset_cons theorem ssubset_cons (h : a ∉ s) : s ⊂ s.cons a h := Multiset.ssubset_cons h #align finset.ssubset_cons Finset.ssubset_cons theorem cons_subset {h : a ∉ s} : s.cons a h ⊆ t ↔ a ∈ t ∧ s ⊆ t := Multiset.cons_subset #align finset.cons_subset Finset.cons_subset @[simp] theorem cons_subset_cons {hs ht} : s.cons a hs ⊆ t.cons a ht ↔ s ⊆ t := by rwa [← coe_subset, coe_cons, coe_cons, Set.insert_subset_insert_iff, coe_subset] #align finset.cons_subset_cons Finset.cons_subset_cons theorem ssubset_iff_exists_cons_subset : s ⊂ t ↔ ∃ (a : _) (h : a ∉ s), s.cons a h ⊆ t := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_ssubset_of_subset (ssubset_cons _) h⟩ obtain ⟨a, hs, ht⟩ := not_subset.1 h.2 exact ⟨a, ht, cons_subset.2 ⟨hs, h.subset⟩⟩ #align finset.ssubset_iff_exists_cons_subset Finset.ssubset_iff_exists_cons_subset end Cons /-! ### disjoint -/ section Disjoint variable {f : α → β} {s t u : Finset α} {a b : α} theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t := ⟨fun h a hs ht => not_mem_empty a <| singleton_subset_iff.mp (h (singleton_subset_iff.mpr hs) (singleton_subset_iff.mpr ht)), fun h _ hs ht _ ha => (h (hs ha) (ht ha)).elim⟩ #align finset.disjoint_left Finset.disjoint_left theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [_root_.disjoint_comm, disjoint_left] #align finset.disjoint_right Finset.disjoint_right theorem disjoint_iff_ne : Disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b := by simp only [disjoint_left, imp_not_comm, forall_eq'] #align finset.disjoint_iff_ne Finset.disjoint_iff_ne @[simp] theorem disjoint_val : s.1.Disjoint t.1 ↔ Disjoint s t := disjoint_left.symm #align finset.disjoint_val Finset.disjoint_val theorem _root_.Disjoint.forall_ne_finset (h : Disjoint s t) (ha : a ∈ s) (hb : b ∈ t) : a ≠ b := disjoint_iff_ne.1 h _ ha _ hb #align disjoint.forall_ne_finset Disjoint.forall_ne_finset theorem not_disjoint_iff : ¬Disjoint s t ↔ ∃ a, a ∈ s ∧ a ∈ t := disjoint_left.not.trans <| not_forall.trans <| exists_congr fun _ => by rw [Classical.not_imp, not_not] #align finset.not_disjoint_iff Finset.not_disjoint_iff theorem disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := disjoint_left.2 fun _x m₁ => (disjoint_left.1 d) (h m₁) #align finset.disjoint_of_subset_left Finset.disjoint_of_subset_left theorem disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := disjoint_right.2 fun _x m₁ => (disjoint_right.1 d) (h m₁) #align finset.disjoint_of_subset_right Finset.disjoint_of_subset_right @[simp] theorem disjoint_empty_left (s : Finset α) : Disjoint ∅ s := disjoint_bot_left #align finset.disjoint_empty_left Finset.disjoint_empty_left @[simp] theorem disjoint_empty_right (s : Finset α) : Disjoint s ∅ := disjoint_bot_right #align finset.disjoint_empty_right Finset.disjoint_empty_right @[simp] theorem disjoint_singleton_left : Disjoint (singleton a) s ↔ a ∉ s := by simp only [disjoint_left, mem_singleton, forall_eq] #align finset.disjoint_singleton_left Finset.disjoint_singleton_left @[simp] theorem disjoint_singleton_right : Disjoint s (singleton a) ↔ a ∉ s := disjoint_comm.trans disjoint_singleton_left #align finset.disjoint_singleton_right Finset.disjoint_singleton_right -- Porting note: Left-hand side simplifies @[simp] theorem disjoint_singleton : Disjoint ({a} : Finset α) {b} ↔ a ≠ b := by rw [disjoint_singleton_left, mem_singleton] #align finset.disjoint_singleton Finset.disjoint_singleton theorem disjoint_self_iff_empty (s : Finset α) : Disjoint s s ↔ s = ∅ := disjoint_self #align finset.disjoint_self_iff_empty Finset.disjoint_self_iff_empty @[simp, norm_cast] theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by simp only [Finset.disjoint_left, Set.disjoint_left, mem_coe] #align finset.disjoint_coe Finset.disjoint_coe @[simp, norm_cast] theorem pairwiseDisjoint_coe {ι : Type*} {s : Set ι} {f : ι → Finset α} : s.PairwiseDisjoint (fun i => f i : ι → Set α) ↔ s.PairwiseDisjoint f := forall₅_congr fun _ _ _ _ _ => disjoint_coe #align finset.pairwise_disjoint_coe Finset.pairwiseDisjoint_coe end Disjoint /-! ### disjoint union -/ /-- `disjUnion s t h` is the set such that `a ∈ disjUnion s t h` iff `a ∈ s` or `a ∈ t`. It is the same as `s ∪ t`, but it does not require decidable equality on the type. The hypothesis ensures that the sets are disjoint. -/ def disjUnion (s t : Finset α) (h : Disjoint s t) : Finset α := ⟨s.1 + t.1, Multiset.nodup_add.2 ⟨s.2, t.2, disjoint_val.2 h⟩⟩ #align finset.disj_union Finset.disjUnion @[simp] theorem mem_disjUnion {α s t h a} : a ∈ @disjUnion α s t h ↔ a ∈ s ∨ a ∈ t := by rcases s with ⟨⟨s⟩⟩; rcases t with ⟨⟨t⟩⟩; apply List.mem_append #align finset.mem_disj_union Finset.mem_disjUnion @[simp, norm_cast] theorem coe_disjUnion {s t : Finset α} (h : Disjoint s t) : (disjUnion s t h : Set α) = (s : Set α) ∪ t := Set.ext <| by simp theorem disjUnion_comm (s t : Finset α) (h : Disjoint s t) : disjUnion s t h = disjUnion t s h.symm := eq_of_veq <| add_comm _ _ #align finset.disj_union_comm Finset.disjUnion_comm @[simp] theorem empty_disjUnion (t : Finset α) (h : Disjoint ∅ t := disjoint_bot_left) : disjUnion ∅ t h = t := eq_of_veq <| zero_add _ #align finset.empty_disj_union Finset.empty_disjUnion @[simp] theorem disjUnion_empty (s : Finset α) (h : Disjoint s ∅ := disjoint_bot_right) : disjUnion s ∅ h = s := eq_of_veq <| add_zero _ #align finset.disj_union_empty Finset.disjUnion_empty theorem singleton_disjUnion (a : α) (t : Finset α) (h : Disjoint {a} t) : disjUnion {a} t h = cons a t (disjoint_singleton_left.mp h) := eq_of_veq <| Multiset.singleton_add _ _ #align finset.singleton_disj_union Finset.singleton_disjUnion theorem disjUnion_singleton (s : Finset α) (a : α) (h : Disjoint s {a}) : disjUnion s {a} h = cons a s (disjoint_singleton_right.mp h) := by rw [disjUnion_comm, singleton_disjUnion] #align finset.disj_union_singleton Finset.disjUnion_singleton /-! ### insert -/ section Insert variable [DecidableEq α] {s t u v : Finset α} {a b : α} /-- `insert a s` is the set `{a} ∪ s` containing `a` and the elements of `s`. -/ instance : Insert α (Finset α) := ⟨fun a s => ⟨_, s.2.ndinsert a⟩⟩ theorem insert_def (a : α) (s : Finset α) : insert a s = ⟨_, s.2.ndinsert a⟩ := rfl #align finset.insert_def Finset.insert_def @[simp] theorem insert_val (a : α) (s : Finset α) : (insert a s).1 = ndinsert a s.1 := rfl #align finset.insert_val Finset.insert_val theorem insert_val' (a : α) (s : Finset α) : (insert a s).1 = dedup (a ::ₘ s.1) := by rw [dedup_cons, dedup_eq_self]; rfl #align finset.insert_val' Finset.insert_val' theorem insert_val_of_not_mem {a : α} {s : Finset α} (h : a ∉ s) : (insert a s).1 = a ::ₘ s.1 := by rw [insert_val, ndinsert_of_not_mem h] #align finset.insert_val_of_not_mem Finset.insert_val_of_not_mem @[simp] theorem mem_insert : a ∈ insert b s ↔ a = b ∨ a ∈ s := mem_ndinsert #align finset.mem_insert Finset.mem_insert theorem mem_insert_self (a : α) (s : Finset α) : a ∈ insert a s := mem_ndinsert_self a s.1 #align finset.mem_insert_self Finset.mem_insert_self theorem mem_insert_of_mem (h : a ∈ s) : a ∈ insert b s := mem_ndinsert_of_mem h #align finset.mem_insert_of_mem Finset.mem_insert_of_mem theorem mem_of_mem_insert_of_ne (h : b ∈ insert a s) : b ≠ a → b ∈ s := (mem_insert.1 h).resolve_left #align finset.mem_of_mem_insert_of_ne Finset.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert (ha : b ∈ insert a s) (hb : b ∉ s) : b = a := (mem_insert.1 ha).resolve_right hb #align finset.eq_of_not_mem_of_mem_insert Finset.eq_of_not_mem_of_mem_insert /-- A version of `LawfulSingleton.insert_emptyc_eq` that works with `dsimp`. -/ @[simp, nolint simpNF] lemma insert_empty : insert a (∅ : Finset α) = {a} := rfl @[simp] theorem cons_eq_insert (a s h) : @cons α a s h = insert a s := ext fun a => by simp #align finset.cons_eq_insert Finset.cons_eq_insert @[simp, norm_cast] theorem coe_insert (a : α) (s : Finset α) : ↑(insert a s) = (insert a s : Set α) := Set.ext fun x => by simp only [mem_coe, mem_insert, Set.mem_insert_iff] #align finset.coe_insert Finset.coe_insert theorem mem_insert_coe {s : Finset α} {x y : α} : x ∈ insert y s ↔ x ∈ insert y (s : Set α) := by simp #align finset.mem_insert_coe Finset.mem_insert_coe instance : LawfulSingleton α (Finset α) := ⟨fun a => by ext; simp⟩ @[simp] theorem insert_eq_of_mem (h : a ∈ s) : insert a s = s := eq_of_veq <| ndinsert_of_mem h #align finset.insert_eq_of_mem Finset.insert_eq_of_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert_self _ _, insert_eq_of_mem⟩ #align finset.insert_eq_self Finset.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align finset.insert_ne_self Finset.insert_ne_self -- Porting note (#10618): @[simp] can prove this theorem pair_eq_singleton (a : α) : ({a, a} : Finset α) = {a} := insert_eq_of_mem <| mem_singleton_self _ #align finset.pair_eq_singleton Finset.pair_eq_singleton theorem Insert.comm (a b : α) (s : Finset α) : insert a (insert b s) = insert b (insert a s) := ext fun x => by simp only [mem_insert, or_left_comm] #align finset.insert.comm Finset.Insert.comm -- Porting note (#10618): @[simp] can prove this @[norm_cast] theorem coe_pair {a b : α} : (({a, b} : Finset α) : Set α) = {a, b} := by ext simp #align finset.coe_pair Finset.coe_pair @[simp, norm_cast] theorem coe_eq_pair {s : Finset α} {a b : α} : (s : Set α) = {a, b} ↔ s = {a, b} := by rw [← coe_pair, coe_inj] #align finset.coe_eq_pair Finset.coe_eq_pair theorem pair_comm (a b : α) : ({a, b} : Finset α) = {b, a} := Insert.comm a b ∅ #align finset.pair_comm Finset.pair_comm -- Porting note (#10618): @[simp] can prove this theorem insert_idem (a : α) (s : Finset α) : insert a (insert a s) = insert a s := ext fun x => by simp only [mem_insert, ← or_assoc, or_self_iff] #align finset.insert_idem Finset.insert_idem @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem insert_nonempty (a : α) (s : Finset α) : (insert a s).Nonempty := ⟨a, mem_insert_self a s⟩ #align finset.insert_nonempty Finset.insert_nonempty @[simp] theorem insert_ne_empty (a : α) (s : Finset α) : insert a s ≠ ∅ := (insert_nonempty a s).ne_empty #align finset.insert_ne_empty Finset.insert_ne_empty -- Porting note: explicit universe annotation is no longer required. instance (i : α) (s : Finset α) : Nonempty ((insert i s : Finset α) : Set α) := (Finset.coe_nonempty.mpr (s.insert_nonempty i)).to_subtype theorem ne_insert_of_not_mem (s t : Finset α) {a : α} (h : a ∉ s) : s ≠ insert a t := by contrapose! h simp [h] #align finset.ne_insert_of_not_mem Finset.ne_insert_of_not_mem
Mathlib/Data/Finset/Basic.lean
1,216
1,217
theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by
simp only [subset_iff, mem_insert, forall_eq, or_imp, forall_and]
/- Copyright (c) 2021 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn, Joachim Breitner -/ import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.GroupTheory.Congruence.Basic import Mathlib.GroupTheory.FreeGroup.IsFreeGroup import Mathlib.Data.List.Chain import Mathlib.SetTheory.Cardinal.Basic import Mathlib.Data.Set.Pointwise.SMul #align_import group_theory.free_product from "leanprover-community/mathlib"@"9114ddffa023340c9ec86965e00cdd6fe26fcdf6" /-! # The coproduct (a.k.a. the free product) of groups or monoids Given an `ι`-indexed family `M` of monoids, we define their coproduct (a.k.a. free product) `Monoid.CoprodI M`. As usual, we use the suffix `I` for an indexed (co)product, leaving `Coprod` for the coproduct of two monoids. When `ι` and all `M i` have decidable equality, the free product bijects with the type `Monoid.CoprodI.Word M` of reduced words. This bijection is constructed by defining an action of `Monoid.CoprodI M` on `Monoid.CoprodI.Word M`. When `M i` are all groups, `Monoid.CoprodI M` is also a group (and the coproduct in the category of groups). ## Main definitions - `Monoid.CoprodI M`: the free product, defined as a quotient of a free monoid. - `Monoid.CoprodI.of {i} : M i →* Monoid.CoprodI M`. - `Monoid.CoprodI.lift : (∀ {i}, M i →* N) ≃ (Monoid.CoprodI M →* N)`: the universal property. - `Monoid.CoprodI.Word M`: the type of reduced words. - `Monoid.CoprodI.Word.equiv M : Monoid.CoprodI M ≃ word M`. - `Monoid.CoprodI.NeWord M i j`: an inductive description of non-empty words with first letter from `M i` and last letter from `M j`, together with an API (`singleton`, `append`, `head`, `tail`, `to_word`, `Prod`, `inv`). Used in the proof of the Ping-Pong-lemma. - `Monoid.CoprodI.lift_injective_of_ping_pong`: The Ping-Pong-lemma, proving injectivity of the `lift`. See the documentation of that theorem for more information. ## Remarks There are many answers to the question "what is the coproduct of a family `M` of monoids?", and they are all equivalent but not obviously equivalent. We provide two answers. The first, almost tautological answer is given by `Monoid.CoprodI M`, which is a quotient of the type of words in the alphabet `Σ i, M i`. It's straightforward to define and easy to prove its universal property. But this answer is not completely satisfactory, because it's difficult to tell when two elements `x y : Monoid.CoprodI M` are distinct since `Monoid.CoprodI M` is defined as a quotient. The second, maximally efficient answer is given by `Monoid.CoprodI.Word M`. An element of `Monoid.CoprodI.Word M` is a word in the alphabet `Σ i, M i`, where the letter `⟨i, 1⟩` doesn't occur and no adjacent letters share an index `i`. Since we only work with reduced words, there is no need for quotienting, and it is easy to tell when two elements are distinct. However it's not obvious that this is even a monoid! We prove that every element of `Monoid.CoprodI M` can be represented by a unique reduced word, i.e. `Monoid.CoprodI M` and `Monoid.CoprodI.Word M` are equivalent types. This means that `Monoid.CoprodI.Word M` can be given a monoid structure, and it lets us tell when two elements of `Monoid.CoprodI M` are distinct. There is also a completely tautological, maximally inefficient answer given by `MonCat.Colimits.ColimitType`. Whereas `Monoid.CoprodI M` at least ensures that (any instance of) associativity holds by reflexivity, in this answer associativity holds because of quotienting. Yet another answer, which is constructively more satisfying, could be obtained by showing that `Monoid.CoprodI.Rel` is confluent. ## References [van der Waerden, *Free products of groups*][MR25465] -/ open Set variable {ι : Type*} (M : ι → Type*) [∀ i, Monoid (M i)] /-- A relation on the free monoid on alphabet `Σ i, M i`, relating `⟨i, 1⟩` with `1` and `⟨i, x⟩ * ⟨i, y⟩` with `⟨i, x * y⟩`. -/ inductive Monoid.CoprodI.Rel : FreeMonoid (Σi, M i) → FreeMonoid (Σi, M i) → Prop | of_one (i : ι) : Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, 1⟩) 1 | of_mul {i : ι} (x y : M i) : Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, x⟩ * FreeMonoid.of ⟨i, y⟩) (FreeMonoid.of ⟨i, x * y⟩) #align free_product.rel Monoid.CoprodI.Rel /-- The free product (categorical coproduct) of an indexed family of monoids. -/ def Monoid.CoprodI : Type _ := (conGen (Monoid.CoprodI.Rel M)).Quotient #align free_product Monoid.CoprodI -- Porting note: could not de derived instance : Monoid (Monoid.CoprodI M) := by delta Monoid.CoprodI; infer_instance instance : Inhabited (Monoid.CoprodI M) := ⟨1⟩ namespace Monoid.CoprodI /-- The type of reduced words. A reduced word cannot contain a letter `1`, and no two adjacent letters can come from the same summand. -/ @[ext] structure Word where /-- A `Word` is a `List (Σ i, M i)`, such that `1` is not in the list, and no two adjacent letters are from the same summand -/ toList : List (Σi, M i) /-- A reduced word does not contain `1` -/ ne_one : ∀ l ∈ toList, Sigma.snd l ≠ 1 /-- Adjacent letters are not from the same summand. -/ chain_ne : toList.Chain' fun l l' => Sigma.fst l ≠ Sigma.fst l' #align free_product.word Monoid.CoprodI.Word variable {M} /-- The inclusion of a summand into the free product. -/ def of {i : ι} : M i →* CoprodI M where toFun x := Con.mk' _ (FreeMonoid.of <| Sigma.mk i x) map_one' := (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_one i)) map_mul' x y := Eq.symm <| (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_mul x y)) #align free_product.of Monoid.CoprodI.of theorem of_apply {i} (m : M i) : of m = Con.mk' _ (FreeMonoid.of <| Sigma.mk i m) := rfl #align free_product.of_apply Monoid.CoprodI.of_apply variable {N : Type*} [Monoid N] /-- See note [partially-applied ext lemmas]. -/ -- Porting note: higher `ext` priority @[ext 1100] theorem ext_hom (f g : CoprodI M →* N) (h : ∀ i, f.comp (of : M i →* _) = g.comp of) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| FreeMonoid.hom_eq fun ⟨i, x⟩ => by -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [MonoidHom.comp_apply, MonoidHom.comp_apply, ← of_apply, ← MonoidHom.comp_apply, ← MonoidHom.comp_apply, h]; rfl #align free_product.ext_hom Monoid.CoprodI.ext_hom /-- A map out of the free product corresponds to a family of maps out of the summands. This is the universal property of the free product, characterizing it as a categorical coproduct. -/ @[simps symm_apply] def lift : (∀ i, M i →* N) ≃ (CoprodI M →* N) where toFun fi := Con.lift _ (FreeMonoid.lift fun p : Σi, M i => fi p.fst p.snd) <| Con.conGen_le <| by simp_rw [Con.ker_rel] rintro _ _ (i | ⟨x, y⟩) · change FreeMonoid.lift _ (FreeMonoid.of _) = FreeMonoid.lift _ 1 simp only [MonoidHom.map_one, FreeMonoid.lift_eval_of] · change FreeMonoid.lift _ (FreeMonoid.of _ * FreeMonoid.of _) = FreeMonoid.lift _ (FreeMonoid.of _) simp only [MonoidHom.map_mul, FreeMonoid.lift_eval_of] invFun f i := f.comp of left_inv := by intro fi ext i x -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [MonoidHom.comp_apply, of_apply, Con.lift_mk', FreeMonoid.lift_eval_of] right_inv := by intro f ext i x rfl #align free_product.lift Monoid.CoprodI.lift @[simp] theorem lift_comp_of {N} [Monoid N] (fi : ∀ i, M i →* N) i : (lift fi).comp of = fi i := congr_fun (lift.symm_apply_apply fi) i @[simp] theorem lift_of {N} [Monoid N] (fi : ∀ i, M i →* N) {i} (m : M i) : lift fi (of m) = fi i m := DFunLike.congr_fun (lift_comp_of ..) m #align free_product.lift_of Monoid.CoprodI.lift_of @[simp] theorem lift_comp_of' {N} [Monoid N] (f : CoprodI M →* N) : lift (fun i ↦ f.comp (of (i := i))) = f := lift.apply_symm_apply f @[simp] theorem lift_of' : lift (fun i ↦ (of : M i →* CoprodI M)) = .id (CoprodI M) := lift_comp_of' (.id _) theorem of_leftInverse [DecidableEq ι] (i : ι) : Function.LeftInverse (lift <| Pi.mulSingle i (MonoidHom.id (M i))) of := fun x => by simp only [lift_of, Pi.mulSingle_eq_same, MonoidHom.id_apply] #align free_product.of_left_inverse Monoid.CoprodI.of_leftInverse theorem of_injective (i : ι) : Function.Injective (of : M i →* _) := by classical exact (of_leftInverse i).injective #align free_product.of_injective Monoid.CoprodI.of_injective theorem mrange_eq_iSup {N} [Monoid N] (f : ∀ i, M i →* N) : MonoidHom.mrange (lift f) = ⨆ i, MonoidHom.mrange (f i) := by rw [lift, Equiv.coe_fn_mk, Con.lift_range, FreeMonoid.mrange_lift, range_sigma_eq_iUnion_range, Submonoid.closure_iUnion] simp only [MonoidHom.mclosure_range] #align free_product.mrange_eq_supr Monoid.CoprodI.mrange_eq_iSup theorem lift_mrange_le {N} [Monoid N] (f : ∀ i, M i →* N) {s : Submonoid N} : MonoidHom.mrange (lift f) ≤ s ↔ ∀ i, MonoidHom.mrange (f i) ≤ s := by simp [mrange_eq_iSup] #align free_product.lift_mrange_le Monoid.CoprodI.lift_mrange_le @[simp] theorem iSup_mrange_of : ⨆ i, MonoidHom.mrange (of : M i →* CoprodI M) = ⊤ := by simp [← mrange_eq_iSup] @[simp] theorem mclosure_iUnion_range_of : Submonoid.closure (⋃ i, Set.range (of : M i →* CoprodI M)) = ⊤ := by simp [Submonoid.closure_iUnion] @[elab_as_elim] theorem induction_left {C : CoprodI M → Prop} (m : CoprodI M) (one : C 1) (mul : ∀ {i} (m : M i) x, C x → C (of m * x)) : C m := by induction m using Submonoid.induction_of_closure_eq_top_left mclosure_iUnion_range_of with | one => exact one | mul x hx y ihy => obtain ⟨i, m, rfl⟩ : ∃ (i : ι) (m : M i), of m = x := by simpa using hx exact mul m y ihy @[elab_as_elim] theorem induction_on {C : CoprodI M → Prop} (m : CoprodI M) (h_one : C 1) (h_of : ∀ (i) (m : M i), C (of m)) (h_mul : ∀ x y, C x → C y → C (x * y)) : C m := by induction m using CoprodI.induction_left with | one => exact h_one | mul m x hx => exact h_mul _ _ (h_of _ _) hx #align free_product.induction_on Monoid.CoprodI.induction_on section Group variable (G : ι → Type*) [∀ i, Group (G i)] instance : Inv (CoprodI G) where inv := MulOpposite.unop ∘ lift fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom theorem inv_def (x : CoprodI G) : x⁻¹ = MulOpposite.unop (lift (fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom) x) := rfl #align free_product.inv_def Monoid.CoprodI.inv_def instance : Group (CoprodI G) := { mul_left_inv := by intro m rw [inv_def] induction m using CoprodI.induction_on with | h_one => rw [MonoidHom.map_one, MulOpposite.unop_one, one_mul] | h_of m ih => change of _⁻¹ * of _ = 1 rw [← of.map_mul, mul_left_inv, of.map_one] | h_mul x y ihx ihy => rw [MonoidHom.map_mul, MulOpposite.unop_mul, mul_assoc, ← mul_assoc _ x y, ihx, one_mul, ihy] } theorem lift_range_le {N} [Group N] (f : ∀ i, G i →* N) {s : Subgroup N} (h : ∀ i, (f i).range ≤ s) : (lift f).range ≤ s := by rintro _ ⟨x, rfl⟩ induction' x using CoprodI.induction_on with i x x y hx hy · exact s.one_mem · simp only [lift_of, SetLike.mem_coe] exact h i (Set.mem_range_self x) · simp only [map_mul, SetLike.mem_coe] exact s.mul_mem hx hy #align free_product.lift_range_le Monoid.CoprodI.lift_range_le theorem range_eq_iSup {N} [Group N] (f : ∀ i, G i →* N) : (lift f).range = ⨆ i, (f i).range := by apply le_antisymm (lift_range_le _ f fun i => le_iSup (fun i => MonoidHom.range (f i)) i) apply iSup_le _ rintro i _ ⟨x, rfl⟩ exact ⟨of x, by simp only [lift_of]⟩ #align free_product.range_eq_supr Monoid.CoprodI.range_eq_iSup end Group namespace Word /-- The empty reduced word. -/ @[simps] def empty : Word M where toList := [] ne_one := by simp chain_ne := List.chain'_nil #align free_product.word.empty Monoid.CoprodI.Word.empty instance : Inhabited (Word M) := ⟨empty⟩ /-- A reduced word determines an element of the free product, given by multiplication. -/ def prod (w : Word M) : CoprodI M := List.prod (w.toList.map fun l => of l.snd) #align free_product.word.prod Monoid.CoprodI.Word.prod @[simp] theorem prod_empty : prod (empty : Word M) = 1 := rfl #align free_product.word.prod_empty Monoid.CoprodI.Word.prod_empty /-- `fstIdx w` is `some i` if the first letter of `w` is `⟨i, m⟩` with `m : M i`. If `w` is empty then it's `none`. -/ def fstIdx (w : Word M) : Option ι := w.toList.head?.map Sigma.fst #align free_product.word.fst_idx Monoid.CoprodI.Word.fstIdx theorem fstIdx_ne_iff {w : Word M} {i} : fstIdx w ≠ some i ↔ ∀ l ∈ w.toList.head?, i ≠ Sigma.fst l := not_iff_not.mp <| by simp [fstIdx] #align free_product.word.fst_idx_ne_iff Monoid.CoprodI.Word.fstIdx_ne_iff variable (M) /-- Given an index `i : ι`, `Pair M i` is the type of pairs `(head, tail)` where `head : M i` and `tail : Word M`, subject to the constraint that first letter of `tail` can't be `⟨i, m⟩`. By prepending `head` to `tail`, one obtains a new word. We'll show that any word can be uniquely obtained in this way. -/ @[ext] structure Pair (i : ι) where /-- An element of `M i`, the first letter of the word. -/ head : M i /-- The remaining letters of the word, excluding the first letter -/ tail : Word M /-- The index first letter of tail of a `Pair M i` is not equal to `i` -/ fstIdx_ne : fstIdx tail ≠ some i #align free_product.word.pair Monoid.CoprodI.Word.Pair instance (i : ι) : Inhabited (Pair M i) := ⟨⟨1, empty, by tauto⟩⟩ variable {M} variable [∀ i, DecidableEq (M i)] /-- Construct a new `Word` without any reduction. The underlying list of `cons m w _ _` is `⟨_, m⟩::w` -/ @[simps] def cons {i} (m : M i) (w : Word M) (hmw : w.fstIdx ≠ some i) (h1 : m ≠ 1) : Word M := { toList := ⟨i, m⟩ :: w.toList, ne_one := by simp only [List.mem_cons] rintro l (rfl | hl) · exact h1 · exact w.ne_one l hl chain_ne := w.chain_ne.cons' (fstIdx_ne_iff.mp hmw) } /-- Given a pair `(head, tail)`, we can form a word by prepending `head` to `tail`, except if `head` is `1 : M i` then we have to just return `Word` since we need the result to be reduced. -/ def rcons {i} (p : Pair M i) : Word M := if h : p.head = 1 then p.tail else cons p.head p.tail p.fstIdx_ne h #align free_product.word.rcons Monoid.CoprodI.Word.rcons #noalign free_product.word.cons_eq_rcons @[simp] theorem prod_rcons {i} (p : Pair M i) : prod (rcons p) = of p.head * prod p.tail := if hm : p.head = 1 then by rw [rcons, dif_pos hm, hm, MonoidHom.map_one, one_mul] else by rw [rcons, dif_neg hm, cons, prod, List.map_cons, List.prod_cons, prod] #align free_product.word.prod_rcons Monoid.CoprodI.Word.prod_rcons theorem rcons_inj {i} : Function.Injective (rcons : Pair M i → Word M) := by rintro ⟨m, w, h⟩ ⟨m', w', h'⟩ he by_cases hm : m = 1 <;> by_cases hm' : m' = 1 · simp only [rcons, dif_pos hm, dif_pos hm'] at he aesop · exfalso simp only [rcons, dif_pos hm, dif_neg hm'] at he rw [he] at h exact h rfl · exfalso simp only [rcons, dif_pos hm', dif_neg hm] at he rw [← he] at h' exact h' rfl · have : m = m' ∧ w.toList = w'.toList := by simpa [cons, rcons, dif_neg hm, dif_neg hm', true_and_iff, eq_self_iff_true, Subtype.mk_eq_mk, heq_iff_eq, ← Subtype.ext_iff_val] using he rcases this with ⟨rfl, h⟩ congr exact Word.ext _ _ h #align free_product.word.rcons_inj Monoid.CoprodI.Word.rcons_inj theorem mem_rcons_iff {i j : ι} (p : Pair M i) (m : M j) : ⟨_, m⟩ ∈ (rcons p).toList ↔ ⟨_, m⟩ ∈ p.tail.toList ∨ m ≠ 1 ∧ (∃ h : i = j, m = h ▸ p.head) := by simp only [rcons, cons, ne_eq] by_cases hij : i = j · subst i by_cases hm : m = p.head · subst m split_ifs <;> simp_all · split_ifs <;> simp_all · split_ifs <;> simp_all [Ne.symm hij] @[simp]
Mathlib/GroupTheory/CoprodI.lean
406
407
theorem fstIdx_cons {i} (m : M i) (w : Word M) (hmw : w.fstIdx ≠ some i) (h1 : m ≠ 1) : fstIdx (cons m w hmw h1) = some i := by
simp [cons, fstIdx]
/- Copyright (c) 2020 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Yury Kudryashov -/ import Mathlib.Algebra.Star.Order import Mathlib.Topology.Instances.NNReal import Mathlib.Topology.Order.MonotoneContinuity #align_import data.real.sqrt from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004" /-! # Square root of a real number In this file we define * `NNReal.sqrt` to be the square root of a nonnegative real number. * `Real.sqrt` to be the square root of a real number, defined to be zero on negative numbers. Then we prove some basic properties of these functions. ## Implementation notes We define `NNReal.sqrt` as the noncomputable inverse to the function `x ↦ x * x`. We use general theory of inverses of strictly monotone functions to prove that `NNReal.sqrt x` exists. As a side effect, `NNReal.sqrt` is a bundled `OrderIso`, so for `NNReal` numbers we get continuity as well as theorems like `NNReal.sqrt x ≤ y ↔ x ≤ y * y` for free. Then we define `Real.sqrt x` to be `NNReal.sqrt (Real.toNNReal x)`. ## Tags square root -/ open Set Filter open scoped Filter NNReal Topology namespace NNReal variable {x y : ℝ≥0} /-- Square root of a nonnegative real number. -/ -- Porting note: was @[pp_nodot] noncomputable def sqrt : ℝ≥0 ≃o ℝ≥0 := OrderIso.symm <| powOrderIso 2 two_ne_zero #align nnreal.sqrt NNReal.sqrt @[simp] lemma sq_sqrt (x : ℝ≥0) : sqrt x ^ 2 = x := sqrt.symm_apply_apply _ #align nnreal.sq_sqrt NNReal.sq_sqrt @[simp] lemma sqrt_sq (x : ℝ≥0) : sqrt (x ^ 2) = x := sqrt.apply_symm_apply _ #align nnreal.sqrt_sq NNReal.sqrt_sq @[simp] lemma mul_self_sqrt (x : ℝ≥0) : sqrt x * sqrt x = x := by rw [← sq, sq_sqrt] #align nnreal.mul_self_sqrt NNReal.mul_self_sqrt @[simp] lemma sqrt_mul_self (x : ℝ≥0) : sqrt (x * x) = x := by rw [← sq, sqrt_sq] #align nnreal.sqrt_mul_self NNReal.sqrt_mul_self lemma sqrt_le_sqrt : sqrt x ≤ sqrt y ↔ x ≤ y := sqrt.le_iff_le #align nnreal.sqrt_le_sqrt_iff NNReal.sqrt_le_sqrt lemma sqrt_lt_sqrt : sqrt x < sqrt y ↔ x < y := sqrt.lt_iff_lt #align nnreal.sqrt_lt_sqrt_iff NNReal.sqrt_lt_sqrt lemma sqrt_eq_iff_eq_sq : sqrt x = y ↔ x = y ^ 2 := sqrt.toEquiv.apply_eq_iff_eq_symm_apply #align nnreal.sqrt_eq_iff_sq_eq NNReal.sqrt_eq_iff_eq_sq lemma sqrt_le_iff_le_sq : sqrt x ≤ y ↔ x ≤ y ^ 2 := sqrt.to_galoisConnection _ _ #align nnreal.sqrt_le_iff NNReal.sqrt_le_iff_le_sq lemma le_sqrt_iff_sq_le : x ≤ sqrt y ↔ x ^ 2 ≤ y := (sqrt.symm.to_galoisConnection _ _).symm #align nnreal.le_sqrt_iff NNReal.le_sqrt_iff_sq_le -- 2024-02-14 @[deprecated] alias sqrt_le_sqrt_iff := sqrt_le_sqrt @[deprecated] alias sqrt_lt_sqrt_iff := sqrt_lt_sqrt @[deprecated] alias sqrt_le_iff := sqrt_le_iff_le_sq @[deprecated] alias le_sqrt_iff := le_sqrt_iff_sq_le @[deprecated] alias sqrt_eq_iff_sq_eq := sqrt_eq_iff_eq_sq @[simp] lemma sqrt_eq_zero : sqrt x = 0 ↔ x = 0 := by simp [sqrt_eq_iff_eq_sq] #align nnreal.sqrt_eq_zero NNReal.sqrt_eq_zero @[simp] lemma sqrt_eq_one : sqrt x = 1 ↔ x = 1 := by simp [sqrt_eq_iff_eq_sq] @[simp] lemma sqrt_zero : sqrt 0 = 0 := by simp #align nnreal.sqrt_zero NNReal.sqrt_zero @[simp] lemma sqrt_one : sqrt 1 = 1 := by simp #align nnreal.sqrt_one NNReal.sqrt_one @[simp] lemma sqrt_le_one : sqrt x ≤ 1 ↔ x ≤ 1 := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one] @[simp] lemma one_le_sqrt : 1 ≤ sqrt x ↔ 1 ≤ x := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one] theorem sqrt_mul (x y : ℝ≥0) : sqrt (x * y) = sqrt x * sqrt y := by rw [sqrt_eq_iff_eq_sq, mul_pow, sq_sqrt, sq_sqrt] #align nnreal.sqrt_mul NNReal.sqrt_mul /-- `NNReal.sqrt` as a `MonoidWithZeroHom`. -/ noncomputable def sqrtHom : ℝ≥0 →*₀ ℝ≥0 := ⟨⟨sqrt, sqrt_zero⟩, sqrt_one, sqrt_mul⟩ #align nnreal.sqrt_hom NNReal.sqrtHom theorem sqrt_inv (x : ℝ≥0) : sqrt x⁻¹ = (sqrt x)⁻¹ := map_inv₀ sqrtHom x #align nnreal.sqrt_inv NNReal.sqrt_inv theorem sqrt_div (x y : ℝ≥0) : sqrt (x / y) = sqrt x / sqrt y := map_div₀ sqrtHom x y #align nnreal.sqrt_div NNReal.sqrt_div @[continuity, fun_prop] theorem continuous_sqrt : Continuous sqrt := sqrt.continuous #align nnreal.continuous_sqrt NNReal.continuous_sqrt @[simp] theorem sqrt_pos : 0 < sqrt x ↔ 0 < x := by simp [pos_iff_ne_zero] alias ⟨_, sqrt_pos_of_pos⟩ := sqrt_pos end NNReal namespace Real /-- The square root of a real number. This returns 0 for negative inputs. This has notation `√x`. Note that `√x⁻¹` is parsed as `√(x⁻¹)`. -/ noncomputable def sqrt (x : ℝ) : ℝ := NNReal.sqrt (Real.toNNReal x) #align real.sqrt Real.sqrt -- TODO: replace this with a typeclass @[inherit_doc] prefix:max "√" => Real.sqrt /- quotient.lift_on x (λ f, mk ⟨sqrt_aux f, (sqrt_aux_converges f).fst⟩) (λ f g e, begin rcases sqrt_aux_converges f with ⟨hf, x, x0, xf, xs⟩, rcases sqrt_aux_converges g with ⟨hg, y, y0, yg, ys⟩, refine xs.trans (eq.trans _ ys.symm), rw [← @mul_self_inj_of_nonneg ℝ _ x y x0 y0, xf, yg], congr' 1, exact quotient.sound e end)-/ variable {x y : ℝ} @[simp, norm_cast] theorem coe_sqrt {x : ℝ≥0} : (NNReal.sqrt x : ℝ) = √(x : ℝ) := by rw [Real.sqrt, Real.toNNReal_coe] #align real.coe_sqrt Real.coe_sqrt @[continuity] theorem continuous_sqrt : Continuous (√· : ℝ → ℝ) := NNReal.continuous_coe.comp <| NNReal.continuous_sqrt.comp continuous_real_toNNReal #align real.continuous_sqrt Real.continuous_sqrt theorem sqrt_eq_zero_of_nonpos (h : x ≤ 0) : sqrt x = 0 := by simp [sqrt, Real.toNNReal_eq_zero.2 h] #align real.sqrt_eq_zero_of_nonpos Real.sqrt_eq_zero_of_nonpos theorem sqrt_nonneg (x : ℝ) : 0 ≤ √x := NNReal.coe_nonneg _ #align real.sqrt_nonneg Real.sqrt_nonneg @[simp] theorem mul_self_sqrt (h : 0 ≤ x) : √x * √x = x := by rw [Real.sqrt, ← NNReal.coe_mul, NNReal.mul_self_sqrt, Real.coe_toNNReal _ h] #align real.mul_self_sqrt Real.mul_self_sqrt @[simp] theorem sqrt_mul_self (h : 0 ≤ x) : √(x * x) = x := (mul_self_inj_of_nonneg (sqrt_nonneg _) h).1 (mul_self_sqrt (mul_self_nonneg _)) #align real.sqrt_mul_self Real.sqrt_mul_self theorem sqrt_eq_cases : √x = y ↔ y * y = x ∧ 0 ≤ y ∨ x < 0 ∧ y = 0 := by constructor · rintro rfl rcases le_or_lt 0 x with hle | hlt · exact Or.inl ⟨mul_self_sqrt hle, sqrt_nonneg x⟩ · exact Or.inr ⟨hlt, sqrt_eq_zero_of_nonpos hlt.le⟩ · rintro (⟨rfl, hy⟩ | ⟨hx, rfl⟩) exacts [sqrt_mul_self hy, sqrt_eq_zero_of_nonpos hx.le] #align real.sqrt_eq_cases Real.sqrt_eq_cases theorem sqrt_eq_iff_mul_self_eq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ y * y = x := ⟨fun h => by rw [← h, mul_self_sqrt hx], fun h => by rw [← h, sqrt_mul_self hy]⟩ #align real.sqrt_eq_iff_mul_self_eq Real.sqrt_eq_iff_mul_self_eq theorem sqrt_eq_iff_mul_self_eq_of_pos (h : 0 < y) : √x = y ↔ y * y = x := by simp [sqrt_eq_cases, h.ne', h.le] #align real.sqrt_eq_iff_mul_self_eq_of_pos Real.sqrt_eq_iff_mul_self_eq_of_pos @[simp] theorem sqrt_eq_one : √x = 1 ↔ x = 1 := calc √x = 1 ↔ 1 * 1 = x := sqrt_eq_iff_mul_self_eq_of_pos zero_lt_one _ ↔ x = 1 := by rw [eq_comm, mul_one] #align real.sqrt_eq_one Real.sqrt_eq_one @[simp] theorem sq_sqrt (h : 0 ≤ x) : √x ^ 2 = x := by rw [sq, mul_self_sqrt h] #align real.sq_sqrt Real.sq_sqrt @[simp] theorem sqrt_sq (h : 0 ≤ x) : √(x ^ 2) = x := by rw [sq, sqrt_mul_self h] #align real.sqrt_sq Real.sqrt_sq theorem sqrt_eq_iff_sq_eq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ y ^ 2 = x := by rw [sq, sqrt_eq_iff_mul_self_eq hx hy] #align real.sqrt_eq_iff_sq_eq Real.sqrt_eq_iff_sq_eq theorem sqrt_mul_self_eq_abs (x : ℝ) : √(x * x) = |x| := by rw [← abs_mul_abs_self x, sqrt_mul_self (abs_nonneg _)] #align real.sqrt_mul_self_eq_abs Real.sqrt_mul_self_eq_abs theorem sqrt_sq_eq_abs (x : ℝ) : √(x ^ 2) = |x| := by rw [sq, sqrt_mul_self_eq_abs] #align real.sqrt_sq_eq_abs Real.sqrt_sq_eq_abs @[simp] theorem sqrt_zero : √0 = 0 := by simp [Real.sqrt] #align real.sqrt_zero Real.sqrt_zero @[simp] theorem sqrt_one : √1 = 1 := by simp [Real.sqrt] #align real.sqrt_one Real.sqrt_one @[simp]
Mathlib/Data/Real/Sqrt.lean
228
229
theorem sqrt_le_sqrt_iff (hy : 0 ≤ y) : √x ≤ √y ↔ x ≤ y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_le_coe, NNReal.sqrt_le_sqrt, toNNReal_le_toNNReal_iff hy]
/- 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 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' _) set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model.union FirstOrder.Language.Theory.Model.union @[simp] theorem model_union_iff {T' : L.Theory} : M ⊨ T ∪ T' ↔ M ⊨ T ∧ M ⊨ T' := ⟨fun h => ⟨h.mono Set.subset_union_left, h.mono Set.subset_union_right⟩, fun h => h.1.union h.2⟩ set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model_union_iff FirstOrder.Language.Theory.model_union_iff theorem model_singleton_iff {φ : L.Sentence} : M ⊨ ({φ} : L.Theory) ↔ M ⊨ φ := by simp set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model_singleton_iff FirstOrder.Language.Theory.model_singleton_iff theorem model_iff_subset_completeTheory : M ⊨ T ↔ T ⊆ L.completeTheory M := T.model_iff set_option linter.uppercaseLean3 false in #align first_order.language.Theory.model_iff_subset_complete_theory FirstOrder.Language.Theory.model_iff_subset_completeTheory theorem completeTheory.subset [MT : M ⊨ T] : T ⊆ L.completeTheory M := model_iff_subset_completeTheory.1 MT set_option linter.uppercaseLean3 false in #align first_order.language.Theory.complete_theory.subset FirstOrder.Language.Theory.completeTheory.subset end Theory instance model_completeTheory : M ⊨ L.completeTheory M := Theory.model_iff_subset_completeTheory.2 (subset_refl _) #align first_order.language.model_complete_theory FirstOrder.Language.model_completeTheory variable (M N) theorem realize_iff_of_model_completeTheory [N ⊨ L.completeTheory M] (φ : L.Sentence) : N ⊨ φ ↔ M ⊨ φ := by refine ⟨fun h => ?_, (L.completeTheory M).realize_sentence_of_mem⟩ contrapose! h rw [← Sentence.realize_not] at * exact (L.completeTheory M).realize_sentence_of_mem (mem_completeTheory.2 h) #align first_order.language.realize_iff_of_model_complete_theory FirstOrder.Language.realize_iff_of_model_completeTheory variable {M N} namespace BoundedFormula @[simp] theorem realize_alls {φ : L.BoundedFormula α n} {v : α → M} : φ.alls.Realize v ↔ ∀ xs : Fin n → M, φ.Realize v xs := by induction' n with n ih · exact Unique.forall_iff.symm · simp only [alls, ih, Realize] exact ⟨fun h xs => Fin.snoc_init_self xs ▸ h _ _, fun h xs x => h (Fin.snoc xs x)⟩ #align first_order.language.bounded_formula.realize_alls FirstOrder.Language.BoundedFormula.realize_alls @[simp] theorem realize_exs {φ : L.BoundedFormula α n} {v : α → M} : φ.exs.Realize v ↔ ∃ xs : Fin n → M, φ.Realize v xs := by induction' n with n ih · exact Unique.exists_iff.symm · simp only [BoundedFormula.exs, ih, realize_ex] constructor · rintro ⟨xs, x, h⟩ exact ⟨_, h⟩ · rintro ⟨xs, h⟩ rw [← Fin.snoc_init_self xs] at h exact ⟨_, _, h⟩ #align first_order.language.bounded_formula.realize_exs FirstOrder.Language.BoundedFormula.realize_exs @[simp] theorem _root_.FirstOrder.Language.Formula.realize_iAlls [Finite γ] {f : α → β ⊕ γ} {φ : L.Formula α} {v : β → M} : (φ.iAlls f).Realize v ↔ ∀ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin γ)) rw [Formula.iAlls] simp only [Nat.add_zero, realize_alls, realize_relabel, Function.comp, castAdd_zero, finCongr_refl, OrderIso.refl_apply, Sum.elim_map, id_eq] refine Equiv.forall_congr ?_ ?_ · exact ⟨fun v => v ∘ e, fun v => v ∘ e.symm, fun _ => by simp [Function.comp], fun _ => by simp [Function.comp]⟩ · intro x rw [Formula.Realize, iff_iff_eq] congr funext i exact i.elim0 @[simp] theorem realize_iAlls [Finite γ] {f : α → β ⊕ γ} {φ : L.Formula α} {v : β → M} {v' : Fin 0 → M} : BoundedFormula.Realize (φ.iAlls f) v v' ↔ ∀ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by rw [← Formula.realize_iAlls, iff_iff_eq]; congr; simp [eq_iff_true_of_subsingleton] @[simp]
Mathlib/ModelTheory/Semantics.lean
937
954
theorem _root_.FirstOrder.Language.Formula.realize_iExs [Finite γ] {f : α → β ⊕ γ} {φ : L.Formula α} {v : β → M} : (φ.iExs f).Realize v ↔ ∃ (i : γ → M), φ.Realize (fun a => Sum.elim v i (f a)) := by
let e := Classical.choice (Classical.choose_spec (Finite.exists_equiv_fin γ)) rw [Formula.iExs] simp only [Nat.add_zero, realize_exs, realize_relabel, Function.comp, castAdd_zero, finCongr_refl, OrderIso.refl_apply, Sum.elim_map, id_eq] rw [← not_iff_not, not_exists, not_exists] refine Equiv.forall_congr ?_ ?_ · exact ⟨fun v => v ∘ e, fun v => v ∘ e.symm, fun _ => by simp [Function.comp], fun _ => by simp [Function.comp]⟩ · intro x rw [Formula.Realize, iff_iff_eq] congr funext i exact i.elim0
/- 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]] 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] #align ratfunc.mk_smul RatFunc.mk_smul instance : IsScalarTower R K[X] (RatFunc K) := ⟨fun c p q => q.induction_on' fun q r _ => by rw [← mk_smul, smul_assoc, mk_smul, mk_smul]⟩ end IsDomain end SMul variable (K) instance [Subsingleton K] : Subsingleton (RatFunc K) := toFractionRing_injective.subsingleton instance : Inhabited (RatFunc K) := ⟨0⟩ instance instNontrivial [Nontrivial K] : Nontrivial (RatFunc K) := ofFractionRing_injective.nontrivial #align ratfunc.nontrivial RatFunc.instNontrivial /-- `RatFunc K` is isomorphic to the field of fractions of `K[X]`, as rings. This is an auxiliary definition; `simp`-normal form is `IsLocalization.algEquiv`. -/ @[simps apply] def toFractionRingRingEquiv : RatFunc K ≃+* FractionRing K[X] where toFun := toFractionRing invFun := ofFractionRing left_inv := fun ⟨_⟩ => rfl right_inv _ := rfl map_add' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_add] map_mul' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_mul] #align ratfunc.to_fraction_ring_ring_equiv RatFunc.toFractionRingRingEquiv end Field section TacticInterlude -- Porting note: reimplemented the `frac_tac` and `smul_tac` as close to the originals as I could /-- Solve equations for `RatFunc K` by working in `FractionRing K[X]`. -/ macro "frac_tac" : tactic => `(tactic| repeat (rintro (⟨⟩ : RatFunc _)) <;> try simp only [← ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_sub, ← ofFractionRing_neg, ← ofFractionRing_one, ← ofFractionRing_mul, ← ofFractionRing_div, ← ofFractionRing_inv, add_assoc, zero_add, add_zero, mul_assoc, mul_zero, mul_one, mul_add, inv_zero, add_comm, add_left_comm, mul_comm, mul_left_comm, sub_eq_add_neg, div_eq_mul_inv, add_mul, zero_mul, one_mul, neg_mul, mul_neg, add_right_neg]) /-- Solve equations for `RatFunc K` by applying `RatFunc.induction_on`. -/ macro "smul_tac" : tactic => `(tactic| repeat (first | rintro (⟨⟩ : RatFunc _) | intro) <;> simp_rw [← ofFractionRing_smul] <;> simp only [add_comm, mul_comm, zero_smul, succ_nsmul, zsmul_eq_mul, mul_add, mul_one, mul_zero, neg_add, mul_neg, Int.ofNat_eq_coe, Int.cast_zero, Int.cast_add, Int.cast_one, Int.cast_negSucc, Int.cast_natCast, Nat.cast_succ, Localization.mk_zero, Localization.add_mk_self, Localization.neg_mk, ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_neg]) end TacticInterlude section CommRing variable (K) [CommRing K] -- Porting note: split the CommRing instance up into multiple defs because it was hard to see -- if the big instance declaration made any progress. /-- `RatFunc K` is a commutative monoid. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instCommMonoid : CommMonoid (RatFunc K) where mul := (· * ·) mul_assoc := by frac_tac mul_comm := by frac_tac one := 1 one_mul := by frac_tac mul_one := by frac_tac npow := npowRec /-- `RatFunc K` is an additive commutative group. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instAddCommGroup : AddCommGroup (RatFunc K) where add := (· + ·) add_assoc := by frac_tac -- Porting note: `by frac_tac` didn't work: add_comm := by repeat rintro (⟨⟩ : RatFunc _) <;> simp only [← ofFractionRing_add, add_comm] zero := 0 zero_add := by frac_tac add_zero := by frac_tac neg := Neg.neg add_left_neg := by frac_tac sub := Sub.sub sub_eq_add_neg := by frac_tac nsmul := (· • ·) nsmul_zero := by smul_tac nsmul_succ _ := by smul_tac zsmul := (· • ·) zsmul_zero' := by smul_tac zsmul_succ' _ := by smul_tac zsmul_neg' _ := by smul_tac instance instCommRing : CommRing (RatFunc K) := { instCommMonoid K, instAddCommGroup K with zero := 0 sub := Sub.sub zero_mul := by frac_tac mul_zero := by frac_tac left_distrib := by frac_tac right_distrib := by frac_tac one := 1 nsmul := (· • ·) zsmul := (· • ·) npow := npowRec } #align ratfunc.comm_ring RatFunc.instCommRing variable {K} section LiftHom open RatFunc variable {G₀ L R S F : Type*} [CommGroupWithZero G₀] [Field L] [CommRing R] [CommRing S] variable [FunLike F R[X] S[X]] /-- Lift a monoid homomorphism that maps polynomials `φ : R[X] →* S[X]` to a `RatFunc R →* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def map [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →* RatFunc S where toFun f := RatFunc.liftOn f (fun n d => if h : φ d ∈ S[X]⁰ then ofFractionRing (Localization.mk (φ n) ⟨φ d, h⟩) else 0) fun {p q p' q'} hq hq' h => by beta_reduce -- Porting note(#12129): force the function to be applied rw [dif_pos, dif_pos] on_goal 1 => congr 1 -- Porting note: this was a `rw [ofFractionRing.inj_eq]` which was overkill anyway rw [Localization.mk_eq_mk_iff] rotate_left · exact hφ hq · exact hφ hq' refine Localization.r_of_eq ?_ simpa only [map_mul] using congr_arg φ h map_one' := by beta_reduce -- Porting note(#12129): force the function to be applied rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, dif_pos] · simpa using ofFractionRing_one · simpa using Submonoid.one_mem _ map_mul' x y := by beta_reduce -- Porting note(#12129): force the function to be applied cases' x with x; cases' y with y -- Porting note: added `using Localization.rec` (`Localization.induction_on` didn't work) induction' x using Localization.rec with p q · induction' y using Localization.rec with p' q' · have hq : φ q ∈ S[X]⁰ := hφ q.prop have hq' : φ q' ∈ S[X]⁰ := hφ q'.prop have hqq' : φ ↑(q * q') ∈ S[X]⁰ := by simpa using Submonoid.mul_mem _ hq hq' simp_rw [← ofFractionRing_mul, Localization.mk_mul, liftOn_ofFractionRing_mk, dif_pos hq, dif_pos hq', dif_pos hqq', ← ofFractionRing_mul, Submonoid.coe_mul, map_mul, Localization.mk_mul, Submonoid.mk_mul_mk] · rfl · rfl #align ratfunc.map RatFunc.map theorem map_apply_ofFractionRing_mk [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (n : R[X]) (d : R[X]⁰) : map φ hφ (ofFractionRing (Localization.mk n d)) = ofFractionRing (Localization.mk (φ n) ⟨φ d, hφ d.prop⟩) := by -- Porting note: replaced `convert` with `refine Eq.trans` refine (liftOn_ofFractionRing_mk n _ _ _).trans ?_ rw [dif_pos] #align ratfunc.map_apply_of_fraction_ring_mk RatFunc.map_apply_ofFractionRing_mk theorem map_injective [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (hf : Function.Injective φ) : Function.Injective (map φ hφ) := by rintro ⟨x⟩ ⟨y⟩ h -- Porting note: had to hint `induction` which induction principle to use induction x using Localization.induction_on induction y using Localization.induction_on simpa only [map_apply_ofFractionRing_mk, ofFractionRing_injective.eq_iff, Localization.mk_eq_mk_iff, Localization.r_iff_exists, mul_cancel_left_coe_nonZeroDivisors, exists_const, ← map_mul, hf.eq_iff] using h #align ratfunc.map_injective RatFunc.map_injective /-- Lift a ring homomorphism that maps polynomials `φ : R[X] →+* S[X]` to a `RatFunc R →+* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapRingHom [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →+* RatFunc S := { map φ hφ with map_zero' := by simp_rw [MonoidHom.toFun_eq_coe, ← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), ← Localization.mk_zero (1 : S[X]⁰), map_apply_ofFractionRing_mk, map_zero, Localization.mk_eq_mk', IsLocalization.mk'_zero] map_add' := by rintro ⟨x⟩ ⟨y⟩ -- Porting note: had to hint `induction` which induction principle to use induction x using Localization.rec induction y using Localization.rec · simp only [← ofFractionRing_add, Localization.add_mk, map_add, map_mul, MonoidHom.toFun_eq_coe, map_apply_ofFractionRing_mk, Submonoid.coe_mul] -- Porting note: `Submonoid.mk_mul_mk` couldn't be applied: motive incorrect, -- even though it is a rfl lemma. rfl · rfl · rfl } #align ratfunc.map_ring_hom RatFunc.mapRingHom theorem coe_mapRingHom_eq_coe_map [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : (mapRingHom φ hφ : RatFunc R → RatFunc S) = map φ hφ := rfl #align ratfunc.coe_map_ring_hom_eq_coe_map RatFunc.coe_mapRingHom_eq_coe_map -- TODO: Generalize to `FunLike` classes, /-- Lift a monoid with zero homomorphism `R[X] →*₀ G₀` to a `RatFunc R →*₀ G₀` on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def liftMonoidWithZeroHom (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) : RatFunc R →*₀ G₀ where toFun f := RatFunc.liftOn f (fun p q => φ p / φ q) fun {p q p' q'} hq hq' h => by cases subsingleton_or_nontrivial R · rw [Subsingleton.elim p q, Subsingleton.elim p' q, Subsingleton.elim q' q] rw [div_eq_div_iff, ← map_mul, mul_comm p, h, map_mul, mul_comm] <;> exact nonZeroDivisors.ne_zero (hφ ‹_›) map_one' := by dsimp only -- Porting note: force the function to be applied (not just beta reduction!) rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk] simp only [map_one, OneMemClass.coe_one, div_one] map_mul' x y := by cases' x with x cases' y with y induction' x using Localization.rec with p q · induction' y using Localization.rec with p' q' · rw [← ofFractionRing_mul, Localization.mk_mul] simp only [liftOn_ofFractionRing_mk, div_mul_div_comm, map_mul, Submonoid.coe_mul] · rfl · rfl map_zero' := by beta_reduce -- Porting note(#12129): force the function to be applied rw [← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), liftOn_ofFractionRing_mk] simp only [map_zero, zero_div] #align ratfunc.lift_monoid_with_zero_hom RatFunc.liftMonoidWithZeroHom theorem liftMonoidWithZeroHom_apply_ofFractionRing_mk (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftMonoidWithZeroHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftOn_ofFractionRing_mk _ _ _ _ #align ratfunc.lift_monoid_with_zero_hom_apply_of_fraction_ring_mk RatFunc.liftMonoidWithZeroHom_apply_ofFractionRing_mk theorem liftMonoidWithZeroHom_injective [Nontrivial R] (φ : R[X] →*₀ G₀) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ G₀⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftMonoidWithZeroHom φ hφ') := by rintro ⟨x⟩ ⟨y⟩ induction' x using Localization.induction_on with a induction' y using Localization.induction_on with a' simp_rw [liftMonoidWithZeroHom_apply_ofFractionRing_mk] intro h congr 1 refine Localization.mk_eq_mk_iff.mpr (Localization.r_of_eq (M := R[X]) ?_) have := mul_eq_mul_of_div_eq_div _ _ ?_ ?_ h · rwa [← map_mul, ← map_mul, hφ.eq_iff, mul_comm, mul_comm a'.fst] at this all_goals exact map_ne_zero_of_mem_nonZeroDivisors _ hφ (SetLike.coe_mem _) #align ratfunc.lift_monoid_with_zero_hom_injective RatFunc.liftMonoidWithZeroHom_injective /-- Lift an injective ring homomorphism `R[X] →+* L` to a `RatFunc R →+* L` by mapping both the numerator and denominator and quotienting them. -/ def liftRingHom (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) : RatFunc R →+* L := { liftMonoidWithZeroHom φ.toMonoidWithZeroHom hφ with map_add' := fun x y => by -- Porting note: used to invoke `MonoidWithZeroHom.toFun_eq_coe` simp only [ZeroHom.toFun_eq_coe, MonoidWithZeroHom.toZeroHom_coe] cases subsingleton_or_nontrivial R · rw [Subsingleton.elim (x + y) y, Subsingleton.elim x 0, map_zero, zero_add] cases' x with x cases' y with y -- Porting note: had to add the recursor explicitly below induction' x using Localization.rec with p q · induction' y using Localization.rec with p' q' · rw [← ofFractionRing_add, Localization.add_mk] simp only [RingHom.toMonoidWithZeroHom_eq_coe, liftMonoidWithZeroHom_apply_ofFractionRing_mk] rw [div_add_div, div_eq_div_iff] · rw [mul_comm _ p, mul_comm _ p', mul_comm _ (φ p'), add_comm] simp only [map_add, map_mul, Submonoid.coe_mul] all_goals try simp only [← map_mul, ← Submonoid.coe_mul] exact nonZeroDivisors.ne_zero (hφ (SetLike.coe_mem _)) · rfl · rfl } #align ratfunc.lift_ring_hom RatFunc.liftRingHom theorem liftRingHom_apply_ofFractionRing_mk (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftRingHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ #align ratfunc.lift_ring_hom_apply_of_fraction_ring_mk RatFunc.liftRingHom_apply_ofFractionRing_mk theorem liftRingHom_injective [Nontrivial R] (φ : R[X] →+* L) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftRingHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ #align ratfunc.lift_ring_hom_injective RatFunc.liftRingHom_injective end LiftHom variable (K) instance instField [IsDomain K] : Field (RatFunc K) where -- Porting note: used to be `by frac_tac` inv_zero := by rw [← ofFractionRing_zero, ← ofFractionRing_inv, inv_zero] div := (· / ·) div_eq_mul_inv := by frac_tac mul_inv_cancel _ := mul_inv_cancel zpow := zpowRec nnqsmul := _ qsmul := _ section IsFractionRing /-! ### `RatFunc` as field of fractions of `Polynomial` -/ section IsDomain variable [IsDomain K] instance (R : Type*) [CommSemiring R] [Algebra R K[X]] : Algebra R (RatFunc K) where toFun x := RatFunc.mk (algebraMap _ _ x) 1 map_add' x y := by simp only [mk_one', RingHom.map_add, ofFractionRing_add] map_mul' x y := by simp only [mk_one', RingHom.map_mul, ofFractionRing_mul] map_one' := by simp only [mk_one', RingHom.map_one, ofFractionRing_one] map_zero' := by simp only [mk_one', RingHom.map_zero, ofFractionRing_zero] smul := (· • ·) smul_def' c x := by induction' x using RatFunc.induction_on' with p q hq -- Porting note: the first `rw [...]` was not needed rw [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk] rw [mk_one', ← mk_smul, mk_def_of_ne (c • p) hq, mk_def_of_ne p hq, ← ofFractionRing_mul, IsLocalization.mul_mk'_eq_mk'_of_mul, Algebra.smul_def] commutes' c x := mul_comm _ _ variable {K} /-- The coercion from polynomials to rational functions, implemented as the algebra map from a domain to its field of fractions -/ @[coe] def coePolynomial (P : Polynomial K) : RatFunc K := algebraMap _ _ P instance : Coe (Polynomial K) (RatFunc K) := ⟨coePolynomial⟩ theorem mk_one (x : K[X]) : RatFunc.mk x 1 = algebraMap _ _ x := rfl #align ratfunc.mk_one RatFunc.mk_one theorem ofFractionRing_algebraMap (x : K[X]) : ofFractionRing (algebraMap _ (FractionRing K[X]) x) = algebraMap _ _ x := by rw [← mk_one, mk_one'] #align ratfunc.of_fraction_ring_algebra_map RatFunc.ofFractionRing_algebraMap @[simp] theorem mk_eq_div (p q : K[X]) : RatFunc.mk p q = algebraMap _ _ p / algebraMap _ _ q := by simp only [mk_eq_div', ofFractionRing_div, ofFractionRing_algebraMap] #align ratfunc.mk_eq_div RatFunc.mk_eq_div @[simp] theorem div_smul {R} [Monoid R] [DistribMulAction R K[X]] [IsScalarTower R K[X] K[X]] (c : R) (p q : K[X]) : algebraMap _ (RatFunc K) (c • p) / algebraMap _ _ q = c • (algebraMap _ _ p / algebraMap _ _ q) := by rw [← mk_eq_div, mk_smul, mk_eq_div] #align ratfunc.div_smul RatFunc.div_smul theorem algebraMap_apply {R : Type*} [CommSemiring R] [Algebra R K[X]] (x : R) : algebraMap R (RatFunc K) x = algebraMap _ _ (algebraMap R K[X] x) / algebraMap K[X] _ 1 := by rw [← mk_eq_div] rfl #align ratfunc.algebra_map_apply RatFunc.algebraMap_apply theorem map_apply_div_ne_zero {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) (hq : q ≠ 0) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by have hq' : φ q ≠ 0 := nonZeroDivisors.ne_zero (hφ (mem_nonZeroDivisors_iff_ne_zero.mpr hq)) simp only [← mk_eq_div, mk_eq_localization_mk _ hq, map_apply_ofFractionRing_mk, mk_eq_localization_mk _ hq'] #align ratfunc.map_apply_div_ne_zero RatFunc.map_apply_div_ne_zero @[simp] theorem map_apply_div {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidWithZeroHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by rcases eq_or_ne q 0 with (rfl | hq) · have : (0 : RatFunc K) = algebraMap K[X] _ 0 / algebraMap K[X] _ 1 := by simp rw [map_zero, map_zero, map_zero, div_zero, div_zero, this, map_apply_div_ne_zero, map_one, map_one, div_one, map_zero, map_zero] exact one_ne_zero exact map_apply_div_ne_zero _ _ _ _ hq #align ratfunc.map_apply_div RatFunc.map_apply_div theorem liftMonoidWithZeroHom_apply_div {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := by rcases eq_or_ne q 0 with (rfl | hq) · simp only [div_zero, map_zero] simp only [← mk_eq_div, mk_eq_localization_mk _ hq, liftMonoidWithZeroHom_apply_ofFractionRing_mk] #align ratfunc.lift_monoid_with_zero_hom_apply_div RatFunc.liftMonoidWithZeroHom_apply_div @[simp] theorem liftMonoidWithZeroHom_apply_div' {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p) / liftMonoidWithZeroHom φ hφ (algebraMap _ _ q) = φ p / φ q := by rw [← map_div₀, liftMonoidWithZeroHom_apply_div] theorem liftRingHom_apply_div {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ -- Porting note: gave explicitly the `hφ` #align ratfunc.lift_ring_hom_apply_div RatFunc.liftRingHom_apply_div @[simp] theorem liftRingHom_apply_div' {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p) / liftRingHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ -- Porting note: gave explicitly the `hφ` variable (K) theorem ofFractionRing_comp_algebraMap : ofFractionRing ∘ algebraMap K[X] (FractionRing K[X]) = algebraMap _ _ := funext ofFractionRing_algebraMap #align ratfunc.of_fraction_ring_comp_algebra_map RatFunc.ofFractionRing_comp_algebraMap theorem algebraMap_injective : Function.Injective (algebraMap K[X] (RatFunc K)) := by rw [← ofFractionRing_comp_algebraMap] exact ofFractionRing_injective.comp (IsFractionRing.injective _ _) #align ratfunc.algebra_map_injective RatFunc.algebraMap_injective @[simp] theorem algebraMap_eq_zero_iff {x : K[X]} : algebraMap K[X] (RatFunc K) x = 0 ↔ x = 0 := ⟨(injective_iff_map_eq_zero _).mp (algebraMap_injective K) _, fun hx => by rw [hx, RingHom.map_zero]⟩ #align ratfunc.algebra_map_eq_zero_iff RatFunc.algebraMap_eq_zero_iff variable {K} theorem algebraMap_ne_zero {x : K[X]} (hx : x ≠ 0) : algebraMap K[X] (RatFunc K) x ≠ 0 := mt (algebraMap_eq_zero_iff K).mp hx #align ratfunc.algebra_map_ne_zero RatFunc.algebraMap_ne_zero section LiftAlgHom variable {L R S : Type*} [Field L] [CommRing R] [IsDomain R] [CommSemiring S] [Algebra S K[X]] [Algebra S L] [Algebra S R[X]] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) /-- Lift an algebra homomorphism that maps polynomials `φ : K[X] →ₐ[S] R[X]` to a `RatFunc K →ₐ[S] RatFunc R`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapAlgHom (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : RatFunc K →ₐ[S] RatFunc R := { mapRingHom φ hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, coe_mapRingHom_eq_coe_map, algebraMap_apply r, map_apply_div, map_one, AlgHom.commutes] } #align ratfunc.map_alg_hom RatFunc.mapAlgHom theorem coe_mapAlgHom_eq_coe_map (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : (mapAlgHom φ hφ : RatFunc K → RatFunc R) = map φ hφ := rfl #align ratfunc.coe_map_alg_hom_eq_coe_map RatFunc.coe_mapAlgHom_eq_coe_map /-- Lift an injective algebra homomorphism `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L` by mapping both the numerator and denominator and quotienting them. -/ def liftAlgHom : RatFunc K →ₐ[S] L := { liftRingHom φ.toRingHom hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, AlgHom.toRingHom_eq_coe, algebraMap_apply r, liftRingHom_apply_div, AlgHom.coe_toRingHom, map_one, div_one, AlgHom.commutes] } #align ratfunc.lift_alg_hom RatFunc.liftAlgHom theorem liftAlgHom_apply_ofFractionRing_mk (n : K[X]) (d : K[X]⁰) : liftAlgHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ -- Porting note: gave explicitly the `hφ` #align ratfunc.lift_alg_hom_apply_of_fraction_ring_mk RatFunc.liftAlgHom_apply_ofFractionRing_mk theorem liftAlgHom_injective (φ : K[X] →ₐ[S] L) (hφ : Function.Injective φ) (hφ' : K[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftAlgHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ #align ratfunc.lift_alg_hom_injective RatFunc.liftAlgHom_injective @[simp] theorem liftAlgHom_apply_div' (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p) / liftAlgHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ -- Porting note: gave explicitly the `hφ` theorem liftAlgHom_apply_div (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ -- Porting note: gave explicitly the `hφ` #align ratfunc.lift_alg_hom_apply_div RatFunc.liftAlgHom_apply_div end LiftAlgHom variable (K) /-- `RatFunc K` is the field of fractions of the polynomials over `K`. -/ instance : IsFractionRing K[X] (RatFunc K) where map_units' y := by rw [← ofFractionRing_algebraMap] exact (toFractionRingRingEquiv K).symm.toRingHom.isUnit_map (IsLocalization.map_units _ y) exists_of_eq {x y} := by rw [← ofFractionRing_algebraMap, ← ofFractionRing_algebraMap] exact fun h ↦ IsLocalization.exists_of_eq ((toFractionRingRingEquiv K).symm.injective h) surj' := by rintro ⟨z⟩ convert IsLocalization.surj K[X]⁰ z -- Porting note: `ext ⟨x, y⟩` no longer necessary simp only [← ofFractionRing_algebraMap, Function.comp_apply, ← ofFractionRing_mul] rw [ofFractionRing.injEq] -- Porting note: added variable {K} @[simp] theorem liftOn_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H' : ∀ {p q p' q'} (_hq : q ≠ 0) (_hq' : q' ≠ 0), q' * p = q * p' → f p q = f p' q') (H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q' := fun {p q p' q'} hq hq' h => H' (nonZeroDivisors.ne_zero hq) (nonZeroDivisors.ne_zero hq') h) : (RatFunc.liftOn (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [← mk_eq_div, liftOn_mk _ _ f f0 @H'] #align ratfunc.lift_on_div RatFunc.liftOn_div @[simp] theorem liftOn'_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H) : (RatFunc.liftOn' (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [RatFunc.liftOn', liftOn_div _ _ _ f0] apply liftOn_condition_of_liftOn'_condition H -- Porting note: `exact` did not work. Also, -- was `@H` that still works, but is not needed. #align ratfunc.lift_on'_div RatFunc.liftOn'_div /-- Induction principle for `RatFunc K`: if `f p q : P (p / q)` for all `p q : K[X]`, then `P` holds on all elements of `RatFunc K`. See also `induction_on'`, which is a recursion principle defined in terms of `RatFunc.mk`. -/ protected theorem induction_on {P : RatFunc K → Prop} (x : RatFunc K) (f : ∀ (p q : K[X]) (hq : q ≠ 0), P (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) : P x := x.induction_on' fun p q hq => by simpa using f p q hq #align ratfunc.induction_on RatFunc.induction_on theorem ofFractionRing_mk' (x : K[X]) (y : K[X]⁰) : -- Porting note: I gave explicitly the argument `(FractionRing K[X])` ofFractionRing (IsLocalization.mk' (FractionRing K[X]) x y) = IsLocalization.mk' (RatFunc K) x y := by rw [IsFractionRing.mk'_eq_div, IsFractionRing.mk'_eq_div, ← mk_eq_div', ← mk_eq_div] #align ratfunc.of_fraction_ring_mk' RatFunc.ofFractionRing_mk' @[simp] theorem ofFractionRing_eq : (ofFractionRing : FractionRing K[X] → RatFunc K) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun x => Localization.induction_on x fun x => by simp only [IsLocalization.algEquiv_apply, IsLocalization.ringEquivOfRingEquiv_apply, Localization.mk_eq_mk'_apply, IsLocalization.map_mk', ofFractionRing_mk', RingEquiv.coe_toRingHom, RingEquiv.refl_apply, SetLike.eta] -- Porting note: added following `simp`. The previous one can be squeezed. simp only [IsFractionRing.mk'_eq_div, RingHom.id_apply, Subtype.coe_eta] #align ratfunc.of_fraction_ring_eq RatFunc.ofFractionRing_eq @[simp] theorem toFractionRing_eq : (toFractionRing : RatFunc K → FractionRing K[X]) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun ⟨x⟩ => Localization.induction_on x fun x => by simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply, IsLocalization.ringEquivOfRingEquiv_apply, IsLocalization.map_mk', RingEquiv.coe_toRingHom, RingEquiv.refl_apply, SetLike.eta] -- Porting note: added following `simp`. The previous one can be squeezed. simp only [IsFractionRing.mk'_eq_div, RingHom.id_apply, Subtype.coe_eta] #align ratfunc.to_fraction_ring_eq RatFunc.toFractionRing_eq @[simp] theorem toFractionRingRingEquiv_symm_eq : (toFractionRingRingEquiv K).symm = (IsLocalization.algEquiv K[X]⁰ _ _).toRingEquiv := by ext x simp [toFractionRingRingEquiv, ofFractionRing_eq, AlgEquiv.coe_ringEquiv'] #align ratfunc.to_fraction_ring_ring_equiv_symm_eq RatFunc.toFractionRingRingEquiv_symm_eq end IsDomain end IsFractionRing end CommRing section NumDenom /-! ### Numerator and denominator -/ open GCDMonoid Polynomial variable [Field K] set_option tactic.skipAssignedInstances false in /-- `RatFunc.numDenom` are numerator and denominator of a rational function over a field, normalized such that the denominator is monic. -/ def numDenom (x : RatFunc K) : K[X] × K[X] := x.liftOn' (fun p q => if q = 0 then ⟨0, 1⟩ else let r := gcd p q ⟨Polynomial.C (q / r).leadingCoeff⁻¹ * (p / r), Polynomial.C (q / r).leadingCoeff⁻¹ * (q / r)⟩) (by intros p q a hq ha dsimp rw [if_neg hq, if_neg (mul_ne_zero ha hq)] have ha' : a.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr ha have hainv : a.leadingCoeff⁻¹ ≠ 0 := inv_ne_zero ha' simp only [Prod.ext_iff, gcd_mul_left, normalize_apply, Polynomial.coe_normUnit, mul_assoc, CommGroupWithZero.coe_normUnit _ ha'] have hdeg : (gcd p q).degree ≤ q.degree := degree_gcd_le_right _ hq have hdeg' : (Polynomial.C a.leadingCoeff⁻¹ * gcd p q).degree ≤ q.degree := by rw [Polynomial.degree_mul, Polynomial.degree_C hainv, zero_add] exact hdeg have hdivp : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ p := (C_mul_dvd hainv).mpr (gcd_dvd_left p q) have hdivq : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ q := (C_mul_dvd hainv).mpr (gcd_dvd_right p q) -- Porting note: added `simp only [...]` and `rw [mul_assoc]` -- Porting note: note the unfolding of `normalize` and `normUnit`! simp only [normalize, normUnit, coe_normUnit, leadingCoeff_eq_zero, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, ha, dite_false, Units.val_inv_eq_inv_val, Units.val_mk0] rw [mul_assoc] rw [EuclideanDomain.mul_div_mul_cancel ha hdivp, EuclideanDomain.mul_div_mul_cancel ha hdivq, leadingCoeff_div hdeg, leadingCoeff_div hdeg', Polynomial.leadingCoeff_mul, Polynomial.leadingCoeff_C, div_C_mul, div_C_mul, ← mul_assoc, ← Polynomial.C_mul, ← mul_assoc, ← Polynomial.C_mul] constructor <;> congr <;> rw [inv_div, mul_comm, mul_div_assoc, ← mul_assoc, inv_inv, _root_.mul_inv_cancel ha', one_mul, inv_div]) #align ratfunc.num_denom RatFunc.numDenom @[simp] theorem numDenom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : numDenom (algebraMap _ _ p / algebraMap _ _ q) = (Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q), Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q)) := by rw [numDenom, liftOn'_div, if_neg hq] intro p rw [if_pos rfl, if_neg (one_ne_zero' K[X])] simp #align ratfunc.num_denom_div RatFunc.numDenom_div /-- `RatFunc.num` is the numerator of a rational function, normalized such that the denominator is monic. -/ def num (x : RatFunc K) : K[X] := x.numDenom.1 #align ratfunc.num RatFunc.num private theorem num_div' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by rw [num, numDenom_div _ hq] @[simp] theorem num_zero : num (0 : RatFunc K) = 0 := by convert num_div' (0 : K[X]) one_ne_zero <;> simp #align ratfunc.num_zero RatFunc.num_zero @[simp] theorem num_div (p q : K[X]) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by by_cases hq : q = 0 · simp [hq] · exact num_div' p hq #align ratfunc.num_div RatFunc.num_div @[simp] theorem num_one : num (1 : RatFunc K) = 1 := by convert num_div (1 : K[X]) 1 <;> simp #align ratfunc.num_one RatFunc.num_one @[simp] theorem num_algebraMap (p : K[X]) : num (algebraMap _ _ p) = p := by convert num_div p 1 <;> simp #align ratfunc.num_algebra_map RatFunc.num_algebraMap theorem num_div_dvd (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) ∣ p := by rw [num_div _ q, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_left p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq #align ratfunc.num_div_dvd RatFunc.num_div_dvd /-- A version of `num_div_dvd` with the LHS in simp normal form -/ @[simp] theorem num_div_dvd' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) ∣ p := by simpa using num_div_dvd p hq #align ratfunc.num_div_dvd' RatFunc.num_div_dvd' /-- `RatFunc.denom` is the denominator of a rational function, normalized such that it is monic. -/ def denom (x : RatFunc K) : K[X] := x.numDenom.2 #align ratfunc.denom RatFunc.denom @[simp] theorem denom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : denom (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q) := by rw [denom, numDenom_div _ hq] #align ratfunc.denom_div RatFunc.denom_div theorem monic_denom (x : RatFunc K) : (denom x).Monic := by induction x using RatFunc.induction_on with | f p q hq => rw [denom_div p hq, mul_comm] exact Polynomial.monic_mul_leadingCoeff_inv (right_div_gcd_ne_zero hq) #align ratfunc.monic_denom RatFunc.monic_denom theorem denom_ne_zero (x : RatFunc K) : denom x ≠ 0 := (monic_denom x).ne_zero #align ratfunc.denom_ne_zero RatFunc.denom_ne_zero @[simp] theorem denom_zero : denom (0 : RatFunc K) = 1 := by convert denom_div (0 : K[X]) one_ne_zero <;> simp #align ratfunc.denom_zero RatFunc.denom_zero @[simp] theorem denom_one : denom (1 : RatFunc K) = 1 := by convert denom_div (1 : K[X]) one_ne_zero <;> simp #align ratfunc.denom_one RatFunc.denom_one @[simp] theorem denom_algebraMap (p : K[X]) : denom (algebraMap _ (RatFunc K) p) = 1 := by convert denom_div p one_ne_zero <;> simp #align ratfunc.denom_algebra_map RatFunc.denom_algebraMap @[simp] theorem denom_div_dvd (p q : K[X]) : denom (algebraMap _ _ p / algebraMap _ _ q) ∣ q := by by_cases hq : q = 0 · simp [hq] rw [denom_div _ hq, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_right p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq #align ratfunc.denom_div_dvd RatFunc.denom_div_dvd @[simp] theorem num_div_denom (x : RatFunc K) : algebraMap _ _ (num x) / algebraMap _ _ (denom x) = x := by induction' x using RatFunc.induction_on with p q hq -- Porting note: had to hint the type of this `have` have q_div_ne_zero : q / gcd p q ≠ 0 := right_div_gcd_ne_zero hq rw [num_div p q, denom_div p hq, RingHom.map_mul, RingHom.map_mul, mul_div_mul_left, div_eq_div_iff, ← RingHom.map_mul, ← RingHom.map_mul, mul_comm _ q, ← EuclideanDomain.mul_div_assoc, ← EuclideanDomain.mul_div_assoc, mul_comm] · apply gcd_dvd_right · apply gcd_dvd_left · exact algebraMap_ne_zero q_div_ne_zero · exact algebraMap_ne_zero hq · refine algebraMap_ne_zero (mt Polynomial.C_eq_zero.mp ?_) exact inv_ne_zero (Polynomial.leadingCoeff_ne_zero.mpr q_div_ne_zero) #align ratfunc.num_div_denom RatFunc.num_div_denom theorem isCoprime_num_denom (x : RatFunc K) : IsCoprime x.num x.denom := by induction' x using RatFunc.induction_on with p q hq rw [num_div, denom_div _ hq] exact (isCoprime_mul_unit_left ((leadingCoeff_ne_zero.2 <| right_div_gcd_ne_zero hq).isUnit.inv.map C) _ _).2 (isCoprime_div_gcd_div_gcd hq) #align ratfunc.is_coprime_num_denom RatFunc.isCoprime_num_denom @[simp] theorem num_eq_zero_iff {x : RatFunc K} : num x = 0 ↔ x = 0 := ⟨fun h => by rw [← num_div_denom x, h, RingHom.map_zero, zero_div], fun h => h.symm ▸ num_zero⟩ #align ratfunc.num_eq_zero_iff RatFunc.num_eq_zero_iff theorem num_ne_zero {x : RatFunc K} (hx : x ≠ 0) : num x ≠ 0 := mt num_eq_zero_iff.mp hx #align ratfunc.num_ne_zero RatFunc.num_ne_zero theorem num_mul_eq_mul_denom_iff {x : RatFunc K} {p q : K[X]} (hq : q ≠ 0) : x.num * q = p * x.denom ↔ x = algebraMap _ _ p / algebraMap _ _ q := by rw [← (algebraMap_injective K).eq_iff, eq_div_iff (algebraMap_ne_zero hq)] conv_rhs => rw [← num_div_denom x] rw [RingHom.map_mul, RingHom.map_mul, div_eq_mul_inv, mul_assoc, mul_comm (Inv.inv _), ← mul_assoc, ← div_eq_mul_inv, div_eq_iff] exact algebraMap_ne_zero (denom_ne_zero x) #align ratfunc.num_mul_eq_mul_denom_iff RatFunc.num_mul_eq_mul_denom_iff theorem num_denom_add (x y : RatFunc K) : (x + y).num * (x.denom * y.denom) = (x.num * y.denom + x.denom * y.num) * (x + y).denom := (num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by conv_lhs => rw [← num_div_denom x, ← num_div_denom y] rw [div_add_div, RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul] · exact algebraMap_ne_zero (denom_ne_zero x) · exact algebraMap_ne_zero (denom_ne_zero y) #align ratfunc.num_denom_add RatFunc.num_denom_add theorem num_denom_neg (x : RatFunc K) : (-x).num * x.denom = -x.num * (-x).denom := by rw [num_mul_eq_mul_denom_iff (denom_ne_zero x), _root_.map_neg, neg_div, num_div_denom] #align ratfunc.num_denom_neg RatFunc.num_denom_neg theorem num_denom_mul (x y : RatFunc K) : (x * y).num * (x.denom * y.denom) = x.num * y.num * (x * y).denom := (num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by conv_lhs => rw [← num_div_denom x, ← num_div_denom y, div_mul_div_comm, ← RingHom.map_mul, ← RingHom.map_mul] #align ratfunc.num_denom_mul RatFunc.num_denom_mul theorem num_dvd {x : RatFunc K} {p : K[X]} (hp : p ≠ 0) : num x ∣ p ↔ ∃ q : K[X], q ≠ 0 ∧ x = algebraMap _ _ p / algebraMap _ _ q := by constructor · rintro ⟨q, rfl⟩ obtain ⟨_hx, hq⟩ := mul_ne_zero_iff.mp hp use denom x * q rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom] · exact ⟨mul_ne_zero (denom_ne_zero x) hq, rfl⟩ · exact algebraMap_ne_zero hq · rintro ⟨q, hq, rfl⟩ exact num_div_dvd p hq #align ratfunc.num_dvd RatFunc.num_dvd theorem denom_dvd {x : RatFunc K} {q : K[X]} (hq : q ≠ 0) : denom x ∣ q ↔ ∃ p : K[X], x = algebraMap _ _ p / algebraMap _ _ q := by constructor · rintro ⟨p, rfl⟩ obtain ⟨_hx, hp⟩ := mul_ne_zero_iff.mp hq use num x * p rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom] exact algebraMap_ne_zero hp · rintro ⟨p, rfl⟩ exact denom_div_dvd p q #align ratfunc.denom_dvd RatFunc.denom_dvd theorem num_mul_dvd (x y : RatFunc K) : num (x * y) ∣ num x * num y := by by_cases hx : x = 0 · simp [hx] by_cases hy : y = 0 · simp [hy] rw [num_dvd (mul_ne_zero (num_ne_zero hx) (num_ne_zero hy))] refine ⟨x.denom * y.denom, mul_ne_zero (denom_ne_zero x) (denom_ne_zero y), ?_⟩ rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom] #align ratfunc.num_mul_dvd RatFunc.num_mul_dvd theorem denom_mul_dvd (x y : RatFunc K) : denom (x * y) ∣ denom x * denom y := by rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))] refine ⟨x.num * y.num, ?_⟩ rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom] #align ratfunc.denom_mul_dvd RatFunc.denom_mul_dvd
Mathlib/FieldTheory/RatFunc/Basic.lean
1,101
1,107
theorem denom_add_dvd (x y : RatFunc K) : denom (x + y) ∣ denom x * denom y := by
rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))] refine ⟨x.num * y.denom + x.denom * y.num, ?_⟩ rw [RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul, ← div_add_div, num_div_denom, num_div_denom] · exact algebraMap_ne_zero (denom_ne_zero x) · exact algebraMap_ne_zero (denom_ne_zero y)
/- 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.MetricSpace.HausdorffDistance #align_import topology.metric_space.hausdorff_distance from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Thickenings in pseudo-metric spaces ## Main definitions * `Metric.thickening δ s`, the open thickening by radius `δ` of a set `s` in a pseudo emetric space. * `Metric.cthickening δ s`, the closed thickening by radius `δ` of a set `s` in a pseudo emetric space. ## Main results * `Disjoint.exists_thickenings`: two disjoint sets admit disjoint thickenings * `Disjoint.exists_cthickenings`: two disjoint sets admit disjoint closed thickenings * `IsCompact.exists_cthickening_subset_open`: if `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. * `Metric.hasBasis_nhdsSet_cthickening`: the `cthickening`s of a compact set `K` form a basis of the neighbourhoods of `K` * `Metric.closure_eq_iInter_cthickening'`: the closure of a set equals the intersection of its closed thickenings of positive radii accumulating at zero. The same holds for open thickenings. * `IsCompact.cthickening_eq_biUnion_closedBall`: if `s` is compact, `cthickening δ s` is the union of `closedBall`s of radius `δ` around `x : E`. -/ noncomputable section open NNReal ENNReal Topology Set Filter Bornology universe u v w variable {ι : Sort*} {α : Type u} {β : Type v} namespace Metric section Thickening variable [PseudoEMetricSpace α] {δ : ℝ} {s : Set α} {x : α} open EMetric /-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a pseudo emetric space consists of those points that are at distance less than `δ` from some point of `E`. -/ def thickening (δ : ℝ) (E : Set α) : Set α := { x : α | infEdist x E < ENNReal.ofReal δ } #align metric.thickening Metric.thickening theorem mem_thickening_iff_infEdist_lt : x ∈ thickening δ s ↔ infEdist x s < ENNReal.ofReal δ := Iff.rfl #align metric.mem_thickening_iff_inf_edist_lt Metric.mem_thickening_iff_infEdist_lt /-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the (open) `δ`-thickening of `E` for small enough positive `δ`. -/ lemma eventually_not_mem_thickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) : ∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.thickening δ E := by obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h filter_upwards [eventually_lt_nhds ε_pos] with δ hδ simp only [thickening, mem_setOf_eq, not_lt] exact (ENNReal.ofReal_le_ofReal hδ.le).trans ε_lt.le /-- The (open) thickening equals the preimage of an open interval under `EMetric.infEdist`. -/ theorem thickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) : thickening δ E = (infEdist · E) ⁻¹' Iio (ENNReal.ofReal δ) := rfl #align metric.thickening_eq_preimage_inf_edist Metric.thickening_eq_preimage_infEdist /-- The (open) thickening is an open set. -/ theorem isOpen_thickening {δ : ℝ} {E : Set α} : IsOpen (thickening δ E) := Continuous.isOpen_preimage continuous_infEdist _ isOpen_Iio #align metric.is_open_thickening Metric.isOpen_thickening /-- The (open) thickening of the empty set is empty. -/ @[simp] theorem thickening_empty (δ : ℝ) : thickening δ (∅ : Set α) = ∅ := by simp only [thickening, setOf_false, infEdist_empty, not_top_lt] #align metric.thickening_empty Metric.thickening_empty theorem thickening_of_nonpos (hδ : δ ≤ 0) (s : Set α) : thickening δ s = ∅ := eq_empty_of_forall_not_mem fun _ => ((ENNReal.ofReal_of_nonpos hδ).trans_le bot_le).not_lt #align metric.thickening_of_nonpos Metric.thickening_of_nonpos /-- The (open) thickening `Metric.thickening δ E` of a fixed subset `E` is an increasing function of the thickening radius `δ`. -/ theorem thickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : thickening δ₁ E ⊆ thickening δ₂ E := preimage_mono (Iio_subset_Iio (ENNReal.ofReal_le_ofReal hle)) #align metric.thickening_mono Metric.thickening_mono /-- The (open) thickening `Metric.thickening δ E` with a fixed thickening radius `δ` is an increasing function of the subset `E`. -/ theorem thickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) : thickening δ E₁ ⊆ thickening δ E₂ := fun _ hx => lt_of_le_of_lt (infEdist_anti h) hx #align metric.thickening_subset_of_subset Metric.thickening_subset_of_subset theorem mem_thickening_iff_exists_edist_lt {δ : ℝ} (E : Set α) (x : α) : x ∈ thickening δ E ↔ ∃ z ∈ E, edist x z < ENNReal.ofReal δ := infEdist_lt_iff #align metric.mem_thickening_iff_exists_edist_lt Metric.mem_thickening_iff_exists_edist_lt /-- The frontier of the (open) thickening of a set is contained in an `EMetric.infEdist` level set. -/ theorem frontier_thickening_subset (E : Set α) {δ : ℝ} : frontier (thickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } := frontier_lt_subset_eq continuous_infEdist continuous_const #align metric.frontier_thickening_subset Metric.frontier_thickening_subset theorem frontier_thickening_disjoint (A : Set α) : Pairwise (Disjoint on fun r : ℝ => frontier (thickening r A)) := by refine (pairwise_disjoint_on _).2 fun r₁ r₂ hr => ?_ rcases le_total r₁ 0 with h₁ | h₁ · simp [thickening_of_nonpos h₁] refine ((disjoint_singleton.2 fun h => hr.ne ?_).preimage _).mono (frontier_thickening_subset _) (frontier_thickening_subset _) apply_fun ENNReal.toReal at h rwa [ENNReal.toReal_ofReal h₁, ENNReal.toReal_ofReal (h₁.trans hr.le)] at h #align metric.frontier_thickening_disjoint Metric.frontier_thickening_disjoint /-- Any set is contained in the complement of the δ-thickening of the complement of its δ-thickening. -/ lemma subset_compl_thickening_compl_thickening_self (δ : ℝ) (E : Set α) : E ⊆ (thickening δ (thickening δ E)ᶜ)ᶜ := by intro x x_in_E simp only [thickening, mem_compl_iff, mem_setOf_eq, not_lt] apply EMetric.le_infEdist.mpr fun y hy ↦ ?_ simp only [mem_compl_iff, mem_setOf_eq, not_lt] at hy simpa only [edist_comm] using le_trans hy <| EMetric.infEdist_le_edist_of_mem x_in_E /-- The δ-thickening of the complement of the δ-thickening of a set is contained in the complement of the set. -/ lemma thickening_compl_thickening_self_subset_compl (δ : ℝ) (E : Set α) : thickening δ (thickening δ E)ᶜ ⊆ Eᶜ := by apply compl_subset_compl.mp simpa only [compl_compl] using subset_compl_thickening_compl_thickening_self δ E variable {X : Type u} [PseudoMetricSpace X] -- Porting note (#10756): new lemma theorem mem_thickening_iff_infDist_lt {E : Set X} {x : X} (h : E.Nonempty) : x ∈ thickening δ E ↔ infDist x E < δ := lt_ofReal_iff_toReal_lt (infEdist_ne_top h) /-- A point in a metric space belongs to the (open) `δ`-thickening of a subset `E` if and only if it is at distance less than `δ` from some point of `E`. -/ theorem mem_thickening_iff {E : Set X} {x : X} : x ∈ thickening δ E ↔ ∃ z ∈ E, dist x z < δ := by have key_iff : ∀ z : X, edist x z < ENNReal.ofReal δ ↔ dist x z < δ := fun z ↦ by rw [dist_edist, lt_ofReal_iff_toReal_lt (edist_ne_top _ _)] simp_rw [mem_thickening_iff_exists_edist_lt, key_iff] #align metric.mem_thickening_iff Metric.mem_thickening_iff @[simp] theorem thickening_singleton (δ : ℝ) (x : X) : thickening δ ({x} : Set X) = ball x δ := by ext simp [mem_thickening_iff] #align metric.thickening_singleton Metric.thickening_singleton theorem ball_subset_thickening {x : X} {E : Set X} (hx : x ∈ E) (δ : ℝ) : ball x δ ⊆ thickening δ E := Subset.trans (by simp [Subset.rfl]) (thickening_subset_of_subset δ <| singleton_subset_iff.mpr hx) #align metric.ball_subset_thickening Metric.ball_subset_thickening /-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a metric space equals the union of balls of radius `δ` centered at points of `E`. -/ theorem thickening_eq_biUnion_ball {δ : ℝ} {E : Set X} : thickening δ E = ⋃ x ∈ E, ball x δ := by ext x simp only [mem_iUnion₂, exists_prop] exact mem_thickening_iff #align metric.thickening_eq_bUnion_ball Metric.thickening_eq_biUnion_ball protected theorem _root_.Bornology.IsBounded.thickening {δ : ℝ} {E : Set X} (h : IsBounded E) : IsBounded (thickening δ E) := by rcases E.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · simp · refine (isBounded_iff_subset_closedBall x).2 ⟨δ + diam E, fun y hy ↦ ?_⟩ calc dist y x ≤ infDist y E + diam E := dist_le_infDist_add_diam (x := y) h hx _ ≤ δ + diam E := add_le_add_right ((mem_thickening_iff_infDist_lt ⟨x, hx⟩).1 hy).le _ #align metric.bounded.thickening Bornology.IsBounded.thickening end Thickening section Cthickening variable [PseudoEMetricSpace α] {δ ε : ℝ} {s t : Set α} {x : α} open EMetric /-- The closed `δ`-thickening `Metric.cthickening δ E` of a subset `E` in a pseudo emetric space consists of those points that are at infimum distance at most `δ` from `E`. -/ def cthickening (δ : ℝ) (E : Set α) : Set α := { x : α | infEdist x E ≤ ENNReal.ofReal δ } #align metric.cthickening Metric.cthickening @[simp] theorem mem_cthickening_iff : x ∈ cthickening δ s ↔ infEdist x s ≤ ENNReal.ofReal δ := Iff.rfl #align metric.mem_cthickening_iff Metric.mem_cthickening_iff /-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the closed `δ`-thickening of `E` for small enough positive `δ`. -/ lemma eventually_not_mem_cthickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) : ∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.cthickening δ E := by obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h filter_upwards [eventually_lt_nhds ε_pos] with δ hδ simp only [cthickening, mem_setOf_eq, not_le] exact ((ofReal_lt_ofReal_iff ε_pos).mpr hδ).trans ε_lt theorem mem_cthickening_of_edist_le (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E) (h' : edist x y ≤ ENNReal.ofReal δ) : x ∈ cthickening δ E := (infEdist_le_edist_of_mem h).trans h' #align metric.mem_cthickening_of_edist_le Metric.mem_cthickening_of_edist_le theorem mem_cthickening_of_dist_le {α : Type*} [PseudoMetricSpace α] (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E) (h' : dist x y ≤ δ) : x ∈ cthickening δ E := by apply mem_cthickening_of_edist_le x y δ E h rw [edist_dist] exact ENNReal.ofReal_le_ofReal h' #align metric.mem_cthickening_of_dist_le Metric.mem_cthickening_of_dist_le theorem cthickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) : cthickening δ E = (fun x => infEdist x E) ⁻¹' Iic (ENNReal.ofReal δ) := rfl #align metric.cthickening_eq_preimage_inf_edist Metric.cthickening_eq_preimage_infEdist /-- The closed thickening is a closed set. -/ theorem isClosed_cthickening {δ : ℝ} {E : Set α} : IsClosed (cthickening δ E) := IsClosed.preimage continuous_infEdist isClosed_Iic #align metric.is_closed_cthickening Metric.isClosed_cthickening /-- The closed thickening of the empty set is empty. -/ @[simp] theorem cthickening_empty (δ : ℝ) : cthickening δ (∅ : Set α) = ∅ := by simp only [cthickening, ENNReal.ofReal_ne_top, setOf_false, infEdist_empty, top_le_iff] #align metric.cthickening_empty Metric.cthickening_empty theorem cthickening_of_nonpos {δ : ℝ} (hδ : δ ≤ 0) (E : Set α) : cthickening δ E = closure E := by ext x simp [mem_closure_iff_infEdist_zero, cthickening, ENNReal.ofReal_eq_zero.2 hδ] #align metric.cthickening_of_nonpos Metric.cthickening_of_nonpos /-- The closed thickening with radius zero is the closure of the set. -/ @[simp] theorem cthickening_zero (E : Set α) : cthickening 0 E = closure E := cthickening_of_nonpos le_rfl E #align metric.cthickening_zero Metric.cthickening_zero theorem cthickening_max_zero (δ : ℝ) (E : Set α) : cthickening (max 0 δ) E = cthickening δ E := by cases le_total δ 0 <;> simp [cthickening_of_nonpos, *] #align metric.cthickening_max_zero Metric.cthickening_max_zero /-- The closed thickening `Metric.cthickening δ E` of a fixed subset `E` is an increasing function of the thickening radius `δ`. -/ theorem cthickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : cthickening δ₁ E ⊆ cthickening δ₂ E := preimage_mono (Iic_subset_Iic.mpr (ENNReal.ofReal_le_ofReal hle)) #align metric.cthickening_mono Metric.cthickening_mono @[simp] theorem cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) {δ : ℝ} (hδ : 0 ≤ δ) : cthickening δ ({x} : Set α) = closedBall x δ := by ext y simp [cthickening, edist_dist, ENNReal.ofReal_le_ofReal_iff hδ] #align metric.cthickening_singleton Metric.cthickening_singleton theorem closedBall_subset_cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) (δ : ℝ) : closedBall x δ ⊆ cthickening δ ({x} : Set α) := by rcases lt_or_le δ 0 with (hδ | hδ) · simp only [closedBall_eq_empty.mpr hδ, empty_subset] · simp only [cthickening_singleton x hδ, Subset.rfl] #align metric.closed_ball_subset_cthickening_singleton Metric.closedBall_subset_cthickening_singleton /-- The closed thickening `Metric.cthickening δ E` with a fixed thickening radius `δ` is an increasing function of the subset `E`. -/ theorem cthickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) : cthickening δ E₁ ⊆ cthickening δ E₂ := fun _ hx => le_trans (infEdist_anti h) hx #align metric.cthickening_subset_of_subset Metric.cthickening_subset_of_subset theorem cthickening_subset_thickening {δ₁ : ℝ≥0} {δ₂ : ℝ} (hlt : (δ₁ : ℝ) < δ₂) (E : Set α) : cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx => hx.out.trans_lt ((ENNReal.ofReal_lt_ofReal_iff (lt_of_le_of_lt δ₁.prop hlt)).mpr hlt) #align metric.cthickening_subset_thickening Metric.cthickening_subset_thickening /-- The closed thickening `Metric.cthickening δ₁ E` is contained in the open thickening `Metric.thickening δ₂ E` if the radius of the latter is positive and larger. -/ theorem cthickening_subset_thickening' {δ₁ δ₂ : ℝ} (δ₂_pos : 0 < δ₂) (hlt : δ₁ < δ₂) (E : Set α) : cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx => lt_of_le_of_lt hx.out ((ENNReal.ofReal_lt_ofReal_iff δ₂_pos).mpr hlt) #align metric.cthickening_subset_thickening' Metric.cthickening_subset_thickening' /-- The open thickening `Metric.thickening δ E` is contained in the closed thickening `Metric.cthickening δ E` with the same radius. -/ theorem thickening_subset_cthickening (δ : ℝ) (E : Set α) : thickening δ E ⊆ cthickening δ E := by intro x hx rw [thickening, mem_setOf_eq] at hx exact hx.le #align metric.thickening_subset_cthickening Metric.thickening_subset_cthickening theorem thickening_subset_cthickening_of_le {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : thickening δ₁ E ⊆ cthickening δ₂ E := (thickening_subset_cthickening δ₁ E).trans (cthickening_mono hle E) #align metric.thickening_subset_cthickening_of_le Metric.thickening_subset_cthickening_of_le theorem _root_.Bornology.IsBounded.cthickening {α : Type*} [PseudoMetricSpace α] {δ : ℝ} {E : Set α} (h : IsBounded E) : IsBounded (cthickening δ E) := by have : IsBounded (thickening (max (δ + 1) 1) E) := h.thickening apply this.subset exact cthickening_subset_thickening' (zero_lt_one.trans_le (le_max_right _ _)) ((lt_add_one _).trans_le (le_max_left _ _)) _ #align metric.bounded.cthickening Bornology.IsBounded.cthickening protected theorem _root_.IsCompact.cthickening {α : Type*} [PseudoMetricSpace α] [ProperSpace α] {s : Set α} (hs : IsCompact s) {r : ℝ} : IsCompact (cthickening r s) := isCompact_of_isClosed_isBounded isClosed_cthickening hs.isBounded.cthickening theorem thickening_subset_interior_cthickening (δ : ℝ) (E : Set α) : thickening δ E ⊆ interior (cthickening δ E) := (subset_interior_iff_isOpen.mpr isOpen_thickening).trans (interior_mono (thickening_subset_cthickening δ E)) #align metric.thickening_subset_interior_cthickening Metric.thickening_subset_interior_cthickening theorem closure_thickening_subset_cthickening (δ : ℝ) (E : Set α) : closure (thickening δ E) ⊆ cthickening δ E := (closure_mono (thickening_subset_cthickening δ E)).trans isClosed_cthickening.closure_subset #align metric.closure_thickening_subset_cthickening Metric.closure_thickening_subset_cthickening /-- The closed thickening of a set contains the closure of the set. -/ theorem closure_subset_cthickening (δ : ℝ) (E : Set α) : closure E ⊆ cthickening δ E := by rw [← cthickening_of_nonpos (min_le_right δ 0)] exact cthickening_mono (min_le_left δ 0) E #align metric.closure_subset_cthickening Metric.closure_subset_cthickening /-- The (open) thickening of a set contains the closure of the set. -/ theorem closure_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : closure E ⊆ thickening δ E := by rw [← cthickening_zero] exact cthickening_subset_thickening' δ_pos δ_pos E #align metric.closure_subset_thickening Metric.closure_subset_thickening /-- A set is contained in its own (open) thickening. -/ theorem self_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : E ⊆ thickening δ E := (@subset_closure _ E).trans (closure_subset_thickening δ_pos E) #align metric.self_subset_thickening Metric.self_subset_thickening /-- A set is contained in its own closed thickening. -/ theorem self_subset_cthickening {δ : ℝ} (E : Set α) : E ⊆ cthickening δ E := subset_closure.trans (closure_subset_cthickening δ E) #align metric.self_subset_cthickening Metric.self_subset_cthickening theorem thickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : thickening δ E ∈ 𝓝ˢ E := isOpen_thickening.mem_nhdsSet.2 <| self_subset_thickening hδ E #align metric.thickening_mem_nhds_set Metric.thickening_mem_nhdsSet theorem cthickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : cthickening δ E ∈ 𝓝ˢ E := mem_of_superset (thickening_mem_nhdsSet E hδ) (thickening_subset_cthickening _ _) #align metric.cthickening_mem_nhds_set Metric.cthickening_mem_nhdsSet @[simp] theorem thickening_union (δ : ℝ) (s t : Set α) : thickening δ (s ∪ t) = thickening δ s ∪ thickening δ t := by simp_rw [thickening, infEdist_union, inf_eq_min, min_lt_iff, setOf_or] #align metric.thickening_union Metric.thickening_union @[simp] theorem cthickening_union (δ : ℝ) (s t : Set α) : cthickening δ (s ∪ t) = cthickening δ s ∪ cthickening δ t := by simp_rw [cthickening, infEdist_union, inf_eq_min, min_le_iff, setOf_or] #align metric.cthickening_union Metric.cthickening_union @[simp] theorem thickening_iUnion (δ : ℝ) (f : ι → Set α) : thickening δ (⋃ i, f i) = ⋃ i, thickening δ (f i) := by simp_rw [thickening, infEdist_iUnion, iInf_lt_iff, setOf_exists] #align metric.thickening_Union Metric.thickening_iUnion lemma thickening_biUnion {ι : Type*} (δ : ℝ) (f : ι → Set α) (I : Set ι) : thickening δ (⋃ i ∈ I, f i) = ⋃ i ∈ I, thickening δ (f i) := by simp only [thickening_iUnion] theorem ediam_cthickening_le (ε : ℝ≥0) : EMetric.diam (cthickening ε s) ≤ EMetric.diam s + 2 * ε := by refine diam_le fun x hx y hy => ENNReal.le_of_forall_pos_le_add fun δ hδ _ => ?_ rw [mem_cthickening_iff, ENNReal.ofReal_coe_nnreal] at hx hy have hε : (ε : ℝ≥0∞) < ε + δ := ENNReal.coe_lt_coe.2 (lt_add_of_pos_right _ hδ) replace hx := hx.trans_lt hε obtain ⟨x', hx', hxx'⟩ := infEdist_lt_iff.mp hx calc edist x y ≤ edist x x' + edist y x' := edist_triangle_right _ _ _ _ ≤ ε + δ + (infEdist y s + EMetric.diam s) := add_le_add hxx'.le (edist_le_infEdist_add_ediam hx') _ ≤ ε + δ + (ε + EMetric.diam s) := add_le_add_left (add_le_add_right hy _) _ _ = _ := by rw [two_mul]; ac_rfl #align metric.ediam_cthickening_le Metric.ediam_cthickening_le theorem ediam_thickening_le (ε : ℝ≥0) : EMetric.diam (thickening ε s) ≤ EMetric.diam s + 2 * ε := (EMetric.diam_mono <| thickening_subset_cthickening _ _).trans <| ediam_cthickening_le _ #align metric.ediam_thickening_le Metric.ediam_thickening_le theorem diam_cthickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) : diam (cthickening ε s) ≤ diam s + 2 * ε := by lift ε to ℝ≥0 using hε refine (toReal_le_add' (ediam_cthickening_le _) ?_ ?_).trans_eq ?_ · exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono (self_subset_cthickening _) · simp [mul_eq_top] · simp [diam] #align metric.diam_cthickening_le Metric.diam_cthickening_le theorem diam_thickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) : diam (thickening ε s) ≤ diam s + 2 * ε := by by_cases hs : IsBounded s · exact (diam_mono (thickening_subset_cthickening _ _) hs.cthickening).trans (diam_cthickening_le _ hε) obtain rfl | hε := hε.eq_or_lt · simp [thickening_of_nonpos, diam_nonneg] · rw [diam_eq_zero_of_unbounded (mt (IsBounded.subset · <| self_subset_thickening hε _) hs)] positivity #align metric.diam_thickening_le Metric.diam_thickening_le @[simp] theorem thickening_closure : thickening δ (closure s) = thickening δ s := by simp_rw [thickening, infEdist_closure] #align metric.thickening_closure Metric.thickening_closure @[simp] theorem cthickening_closure : cthickening δ (closure s) = cthickening δ s := by simp_rw [cthickening, infEdist_closure] #align metric.cthickening_closure Metric.cthickening_closure open ENNReal theorem _root_.Disjoint.exists_thickenings (hst : Disjoint s t) (hs : IsCompact s) (ht : IsClosed t) : ∃ δ, 0 < δ ∧ Disjoint (thickening δ s) (thickening δ t) := by obtain ⟨r, hr, h⟩ := exists_pos_forall_lt_edist hs ht hst refine ⟨r / 2, half_pos (NNReal.coe_pos.2 hr), ?_⟩ rw [disjoint_iff_inf_le] rintro z ⟨hzs, hzt⟩ rw [mem_thickening_iff_exists_edist_lt] at hzs hzt rw [← NNReal.coe_two, ← NNReal.coe_div, ENNReal.ofReal_coe_nnreal] at hzs hzt obtain ⟨x, hx, hzx⟩ := hzs obtain ⟨y, hy, hzy⟩ := hzt refine (h x hx y hy).not_le ?_ calc edist x y ≤ edist z x + edist z y := edist_triangle_left _ _ _ _ ≤ ↑(r / 2) + ↑(r / 2) := add_le_add hzx.le hzy.le _ = r := by rw [← ENNReal.coe_add, add_halves] #align disjoint.exists_thickenings Disjoint.exists_thickenings theorem _root_.Disjoint.exists_cthickenings (hst : Disjoint s t) (hs : IsCompact s) (ht : IsClosed t) : ∃ δ, 0 < δ ∧ Disjoint (cthickening δ s) (cthickening δ t) := by obtain ⟨δ, hδ, h⟩ := hst.exists_thickenings hs ht refine ⟨δ / 2, half_pos hδ, h.mono ?_ ?_⟩ <;> exact cthickening_subset_thickening' hδ (half_lt_self hδ) _ #align disjoint.exists_cthickenings Disjoint.exists_cthickenings /-- If `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. -/ theorem _root_.IsCompact.exists_cthickening_subset_open (hs : IsCompact s) (ht : IsOpen t) (hst : s ⊆ t) : ∃ δ, 0 < δ ∧ cthickening δ s ⊆ t := (hst.disjoint_compl_right.exists_cthickenings hs ht.isClosed_compl).imp fun _ h => ⟨h.1, disjoint_compl_right_iff_subset.1 <| h.2.mono_right <| self_subset_cthickening _⟩ #align is_compact.exists_cthickening_subset_open IsCompact.exists_cthickening_subset_open theorem _root_.IsCompact.exists_isCompact_cthickening [LocallyCompactSpace α] (hs : IsCompact s) : ∃ δ, 0 < δ ∧ IsCompact (cthickening δ s) := by rcases exists_compact_superset hs with ⟨K, K_compact, hK⟩ rcases hs.exists_cthickening_subset_open isOpen_interior hK with ⟨δ, δpos, hδ⟩ refine ⟨δ, δpos, ?_⟩ exact K_compact.of_isClosed_subset isClosed_cthickening (hδ.trans interior_subset) theorem _root_.IsCompact.exists_thickening_subset_open (hs : IsCompact s) (ht : IsOpen t) (hst : s ⊆ t) : ∃ δ, 0 < δ ∧ thickening δ s ⊆ t := let ⟨δ, h₀, hδ⟩ := hs.exists_cthickening_subset_open ht hst ⟨δ, h₀, (thickening_subset_cthickening _ _).trans hδ⟩ #align is_compact.exists_thickening_subset_open IsCompact.exists_thickening_subset_open theorem hasBasis_nhdsSet_thickening {K : Set α} (hK : IsCompact K) : (𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => thickening δ K := (hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_thickening_subset_open hU.1 hU.2) fun _ => thickening_mem_nhdsSet K #align metric.has_basis_nhds_set_thickening Metric.hasBasis_nhdsSet_thickening theorem hasBasis_nhdsSet_cthickening {K : Set α} (hK : IsCompact K) : (𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => cthickening δ K := (hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_cthickening_subset_open hU.1 hU.2) fun _ => cthickening_mem_nhdsSet K #align metric.has_basis_nhds_set_cthickening Metric.hasBasis_nhdsSet_cthickening theorem cthickening_eq_iInter_cthickening' {δ : ℝ} (s : Set ℝ) (hsδ : s ⊆ Ioi δ) (hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) : cthickening δ E = ⋂ ε ∈ s, cthickening ε E := by apply Subset.antisymm · exact subset_iInter₂ fun _ hε => cthickening_mono (le_of_lt (hsδ hε)) E · unfold cthickening intro x hx simp only [mem_iInter, mem_setOf_eq] at * apply ENNReal.le_of_forall_pos_le_add intro η η_pos _ rcases hs (δ + η) (lt_add_of_pos_right _ (NNReal.coe_pos.mpr η_pos)) with ⟨ε, ⟨hsε, hε⟩⟩ apply ((hx ε hsε).trans (ENNReal.ofReal_le_ofReal hε.2)).trans rw [ENNReal.coe_nnreal_eq η] exact ENNReal.ofReal_add_le #align metric.cthickening_eq_Inter_cthickening' Metric.cthickening_eq_iInter_cthickening' theorem cthickening_eq_iInter_cthickening {δ : ℝ} (E : Set α) : cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), cthickening ε E := by apply cthickening_eq_iInter_cthickening' (Ioi δ) rfl.subset simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self] exact fun _ hε => nonempty_Ioc.mpr hε #align metric.cthickening_eq_Inter_cthickening Metric.cthickening_eq_iInter_cthickening theorem cthickening_eq_iInter_thickening' {δ : ℝ} (δ_nn : 0 ≤ δ) (s : Set ℝ) (hsδ : s ⊆ Ioi δ) (hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) : cthickening δ E = ⋂ ε ∈ s, thickening ε E := by refine (subset_iInter₂ fun ε hε => ?_).antisymm ?_ · obtain ⟨ε', -, hε'⟩ := hs ε (hsδ hε) have ss := cthickening_subset_thickening' (lt_of_le_of_lt δ_nn hε'.1) hε'.1 E exact ss.trans (thickening_mono hε'.2 E) · rw [cthickening_eq_iInter_cthickening' s hsδ hs E] exact iInter₂_mono fun ε _ => thickening_subset_cthickening ε E #align metric.cthickening_eq_Inter_thickening' Metric.cthickening_eq_iInter_thickening' theorem cthickening_eq_iInter_thickening {δ : ℝ} (δ_nn : 0 ≤ δ) (E : Set α) : cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), thickening ε E := by apply cthickening_eq_iInter_thickening' δ_nn (Ioi δ) rfl.subset simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self] exact fun _ hε => nonempty_Ioc.mpr hε #align metric.cthickening_eq_Inter_thickening Metric.cthickening_eq_iInter_thickening theorem cthickening_eq_iInter_thickening'' (δ : ℝ) (E : Set α) : cthickening δ E = ⋂ (ε : ℝ) (_ : max 0 δ < ε), thickening ε E := by rw [← cthickening_max_zero, cthickening_eq_iInter_thickening] exact le_max_left _ _ #align metric.cthickening_eq_Inter_thickening'' Metric.cthickening_eq_iInter_thickening'' /-- The closure of a set equals the intersection of its closed thickenings of positive radii accumulating at zero. -/ theorem closure_eq_iInter_cthickening' (E : Set α) (s : Set ℝ) (hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, cthickening δ E := by by_cases hs₀ : s ⊆ Ioi 0 · rw [← cthickening_zero] apply cthickening_eq_iInter_cthickening' _ hs₀ hs obtain ⟨δ, hδs, δ_nonpos⟩ := not_subset.mp hs₀ rw [Set.mem_Ioi, not_lt] at δ_nonpos apply Subset.antisymm · exact subset_iInter₂ fun ε _ => closure_subset_cthickening ε E · rw [← cthickening_of_nonpos δ_nonpos E] exact biInter_subset_of_mem hδs #align metric.closure_eq_Inter_cthickening' Metric.closure_eq_iInter_cthickening' /-- The closure of a set equals the intersection of its closed thickenings of positive radii. -/ theorem closure_eq_iInter_cthickening (E : Set α) : closure E = ⋂ (δ : ℝ) (_ : 0 < δ), cthickening δ E := by rw [← cthickening_zero] exact cthickening_eq_iInter_cthickening E #align metric.closure_eq_Inter_cthickening Metric.closure_eq_iInter_cthickening /-- The closure of a set equals the intersection of its open thickenings of positive radii accumulating at zero. -/ theorem closure_eq_iInter_thickening' (E : Set α) (s : Set ℝ) (hs₀ : s ⊆ Ioi 0) (hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, thickening δ E := by rw [← cthickening_zero] apply cthickening_eq_iInter_thickening' le_rfl _ hs₀ hs #align metric.closure_eq_Inter_thickening' Metric.closure_eq_iInter_thickening' /-- The closure of a set equals the intersection of its (open) thickenings of positive radii. -/ theorem closure_eq_iInter_thickening (E : Set α) : closure E = ⋂ (δ : ℝ) (_ : 0 < δ), thickening δ E := by rw [← cthickening_zero] exact cthickening_eq_iInter_thickening rfl.ge E #align metric.closure_eq_Inter_thickening Metric.closure_eq_iInter_thickening /-- The frontier of the closed thickening of a set is contained in an `EMetric.infEdist` level set. -/ theorem frontier_cthickening_subset (E : Set α) {δ : ℝ} : frontier (cthickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } := frontier_le_subset_eq continuous_infEdist continuous_const #align metric.frontier_cthickening_subset Metric.frontier_cthickening_subset /-- The closed ball of radius `δ` centered at a point of `E` is included in the closed thickening of `E`. -/
Mathlib/Topology/MetricSpace/Thickening.lean
588
591
theorem closedBall_subset_cthickening {α : Type*} [PseudoMetricSpace α] {x : α} {E : Set α} (hx : x ∈ E) (δ : ℝ) : closedBall x δ ⊆ cthickening δ E := by
refine (closedBall_subset_cthickening_singleton _ _).trans (cthickening_subset_of_subset _ ?_) simpa using hx
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Sites.Sheaf import Mathlib.CategoryTheory.Sites.CoverLifting import Mathlib.CategoryTheory.Adjunction.FullyFaithful #align_import category_theory.sites.dense_subsite from "leanprover-community/mathlib"@"1d650c2e131f500f3c17f33b4d19d2ea15987f2c" /-! # Dense subsites We define `IsCoverDense` functors into sites as functors such that there exists a covering sieve that factors through images of the functor for each object in `D`. We will primarily consider cover-dense functors that are also full, since this notion is in general not well-behaved otherwise. Note that https://ncatlab.org/nlab/show/dense+sub-site indeed has a weaker notion of cover-dense that loosens this requirement, but it would not have all the properties we would need, and some sheafification would be needed for here and there. ## Main results - `CategoryTheory.Functor.IsCoverDense.Types.presheafHom`: If `G : C ⥤ (D, K)` is full and cover-dense, then given any presheaf `ℱ` and sheaf `ℱ'` on `D`, and a morphism `α : G ⋙ ℱ ⟶ G ⋙ ℱ'`, we may glue them together to obtain a morphism of presheaves `ℱ ⟶ ℱ'`. - `CategoryTheory.Functor.IsCoverDense.sheafIso`: If `ℱ` above is a sheaf and `α` is an iso, then the result is also an iso. - `CategoryTheory.Functor.IsCoverDense.iso_of_restrict_iso`: If `G : C ⥤ (D, K)` is full and cover-dense, then given any sheaves `ℱ, ℱ'` on `D`, and a morphism `α : ℱ ⟶ ℱ'`, then `α` is an iso if `G ⋙ ℱ ⟶ G ⋙ ℱ'` is iso. - `CategoryTheory.Functor.IsCoverDense.sheafEquivOfCoverPreservingCoverLifting`: If `G : (C, J) ⥤ (D, K)` is fully-faithful, cover-lifting, cover-preserving, and cover-dense, then it will induce an equivalence of categories of sheaves valued in a complete category. ## References * [Elephant]: *Sketches of an Elephant*, ℱ. T. Johnstone: C2.2. * https://ncatlab.org/nlab/show/dense+sub-site * https://ncatlab.org/nlab/show/comparison+lemma -/ universe w v u namespace CategoryTheory variable {C : Type*} [Category C] {D : Type*} [Category D] {E : Type*} [Category E] variable (J : GrothendieckTopology C) (K : GrothendieckTopology D) variable {L : GrothendieckTopology E} /-- An auxiliary structure that witnesses the fact that `f` factors through an image object of `G`. -/ -- Porting note(#5171): removed `@[nolint has_nonempty_instance]` structure Presieve.CoverByImageStructure (G : C ⥤ D) {V U : D} (f : V ⟶ U) where obj : C lift : V ⟶ G.obj obj map : G.obj obj ⟶ U fac : lift ≫ map = f := by aesop_cat #align category_theory.presieve.cover_by_image_structure CategoryTheory.Presieve.CoverByImageStructure attribute [nolint docBlame] Presieve.CoverByImageStructure.obj Presieve.CoverByImageStructure.lift Presieve.CoverByImageStructure.map Presieve.CoverByImageStructure.fac attribute [reassoc (attr := simp)] Presieve.CoverByImageStructure.fac /-- For a functor `G : C ⥤ D`, and an object `U : D`, `Presieve.coverByImage G U` is the presieve of `U` consisting of those arrows that factor through images of `G`. -/ def Presieve.coverByImage (G : C ⥤ D) (U : D) : Presieve U := fun _ f => Nonempty (Presieve.CoverByImageStructure G f) #align category_theory.presieve.cover_by_image CategoryTheory.Presieve.coverByImage /-- For a functor `G : C ⥤ D`, and an object `U : D`, `Sieve.coverByImage G U` is the sieve of `U` consisting of those arrows that factor through images of `G`. -/ def Sieve.coverByImage (G : C ⥤ D) (U : D) : Sieve U := ⟨Presieve.coverByImage G U, fun ⟨⟨Z, f₁, f₂, (e : _ = _)⟩⟩ g => ⟨⟨Z, g ≫ f₁, f₂, show (g ≫ f₁) ≫ f₂ = g ≫ _ by rw [Category.assoc, ← e]⟩⟩⟩ #align category_theory.sieve.cover_by_image CategoryTheory.Sieve.coverByImage theorem Presieve.in_coverByImage (G : C ⥤ D) {X : D} {Y : C} (f : G.obj Y ⟶ X) : Presieve.coverByImage G X f := ⟨⟨Y, 𝟙 _, f, by simp⟩⟩ #align category_theory.presieve.in_cover_by_image CategoryTheory.Presieve.in_coverByImage /-- A functor `G : (C, J) ⥤ (D, K)` is cover dense if for each object in `D`, there exists a covering sieve in `D` that factors through images of `G`. This definition can be found in https://ncatlab.org/nlab/show/dense+sub-site Definition 2.2. -/ class Functor.IsCoverDense (G : C ⥤ D) (K : GrothendieckTopology D) : Prop where is_cover : ∀ U : D, Sieve.coverByImage G U ∈ K U #align category_theory.cover_dense CategoryTheory.Functor.IsCoverDense lemma Functor.is_cover_of_isCoverDense (G : C ⥤ D) (K : GrothendieckTopology D) [G.IsCoverDense K] (U : D) : Sieve.coverByImage G U ∈ K U := by apply Functor.IsCoverDense.is_cover lemma Functor.isCoverDense_of_generate_singleton_functor_π_mem (G : C ⥤ D) (K : GrothendieckTopology D) (h : ∀ B, ∃ (X : C) (f : G.obj X ⟶ B), Sieve.generate (Presieve.singleton f) ∈ K B) : G.IsCoverDense K where is_cover B := by obtain ⟨X, f, h⟩ := h B refine K.superset_covering ?_ h intro Y f ⟨Z, g, _, h, w⟩ cases h exact ⟨⟨_, g, _, w⟩⟩ attribute [nolint docBlame] CategoryTheory.Functor.IsCoverDense.is_cover open Presieve Opposite namespace Functor namespace IsCoverDense variable {K} variable {A : Type*} [Category A] (G : C ⥤ D) [G.IsCoverDense K] -- this is not marked with `@[ext]` because `H` can not be inferred from the type theorem ext (ℱ : SheafOfTypes K) (X : D) {s t : ℱ.val.obj (op X)} (h : ∀ ⦃Y : C⦄ (f : G.obj Y ⟶ X), ℱ.val.map f.op s = ℱ.val.map f.op t) : s = t := by apply (ℱ.cond (Sieve.coverByImage G X) (G.is_cover_of_isCoverDense K X)).isSeparatedFor.ext rintro Y _ ⟨Z, f₁, f₂, ⟨rfl⟩⟩ simp [h f₂] #align category_theory.cover_dense.ext CategoryTheory.Functor.IsCoverDense.ext variable {G}
Mathlib/CategoryTheory/Sites/DenseSubsite.lean
133
141
theorem functorPullback_pushforward_covering [Full G] {X : C} (T : K (G.obj X)) : (T.val.functorPullback G).functorPushforward G ∈ K (G.obj X) := by
refine K.superset_covering ?_ (K.bind_covering T.property fun Y f _ => G.is_cover_of_isCoverDense K Y) rintro Y _ ⟨Z, _, f, hf, ⟨W, g, f', ⟨rfl⟩⟩, rfl⟩ use W; use G.preimage (f' ≫ f); use g constructor · simpa using T.val.downward_closed hf f' · simp
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.ExpChar import Mathlib.Algebra.GeomSum import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.RingTheory.Polynomial.Content import Mathlib.RingTheory.UniqueFactorizationDomain #align_import ring_theory.polynomial.basic from "leanprover-community/mathlib"@"da420a8c6dd5bdfb85c4ced85c34388f633bc6ff" /-! # Ring-theoretic supplement of Algebra.Polynomial. ## Main results * `MvPolynomial.isDomain`: If a ring is an integral domain, then so is its polynomial ring over finitely many variables. * `Polynomial.isNoetherianRing`: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring. * `Polynomial.wfDvdMonoid`: If an integral domain is a `WFDvdMonoid`, then so is its polynomial ring. * `Polynomial.uniqueFactorizationMonoid`, `MvPolynomial.uniqueFactorizationMonoid`: If an integral domain is a `UniqueFactorizationMonoid`, then so is its polynomial ring (of any number of variables). -/ noncomputable section open Polynomial open Finset universe u v w variable {R : Type u} {S : Type*} namespace Polynomial section Semiring variable [Semiring R] instance instCharP (p : ℕ) [h : CharP R p] : CharP R[X] p := let ⟨h⟩ := h ⟨fun n => by rw [← map_natCast C, ← C_0, C_inj, h]⟩ instance instExpChar (p : ℕ) [h : ExpChar R p] : ExpChar R[X] p := by cases h; exacts [ExpChar.zero, ExpChar.prime ‹_›] variable (R) /-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/ def degreeLE (n : WithBot ℕ) : Submodule R R[X] := ⨅ k : ℕ, ⨅ _ : ↑k > n, LinearMap.ker (lcoeff R k) #align polynomial.degree_le Polynomial.degreeLE /-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/ def degreeLT (n : ℕ) : Submodule R R[X] := ⨅ k : ℕ, ⨅ (_ : k ≥ n), LinearMap.ker (lcoeff R k) #align polynomial.degree_lt Polynomial.degreeLT variable {R} theorem mem_degreeLE {n : WithBot ℕ} {f : R[X]} : f ∈ degreeLE R n ↔ degree f ≤ n := by simp only [degreeLE, Submodule.mem_iInf, degree_le_iff_coeff_zero, LinearMap.mem_ker]; rfl #align polynomial.mem_degree_le Polynomial.mem_degreeLE @[mono] theorem degreeLE_mono {m n : WithBot ℕ} (H : m ≤ n) : degreeLE R m ≤ degreeLE R n := fun _ hf => mem_degreeLE.2 (le_trans (mem_degreeLE.1 hf) H) #align polynomial.degree_le_mono Polynomial.degreeLE_mono theorem degreeLE_eq_span_X_pow [DecidableEq R] {n : ℕ} : degreeLE R n = Submodule.span R ↑((Finset.range (n + 1)).image fun n => (X : R[X]) ^ n) := by apply le_antisymm · intro p hp replace hp := mem_degreeLE.1 hp rw [← Polynomial.sum_monomial_eq p, Polynomial.sum] refine Submodule.sum_mem _ fun k hk => ?_ have := WithBot.coe_le_coe.1 (Finset.sup_le_iff.1 hp k hk) rw [← C_mul_X_pow_eq_monomial, C_mul'] refine Submodule.smul_mem _ _ (Submodule.subset_span <| Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 (Nat.lt_succ_of_le this), rfl⟩) rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff] intro k hk apply mem_degreeLE.2 exact (degree_X_pow_le _).trans (WithBot.coe_le_coe.2 <| Nat.le_of_lt_succ <| Finset.mem_range.1 hk) set_option linter.uppercaseLean3 false in #align polynomial.degree_le_eq_span_X_pow Polynomial.degreeLE_eq_span_X_pow theorem mem_degreeLT {n : ℕ} {f : R[X]} : f ∈ degreeLT R n ↔ degree f < n := by rw [degreeLT, Submodule.mem_iInf] conv_lhs => intro i; rw [Submodule.mem_iInf] rw [degree, Finset.max_eq_sup_coe] rw [Finset.sup_lt_iff ?_] rotate_left · apply WithBot.bot_lt_coe conv_rhs => simp only [mem_support_iff] intro b rw [Nat.cast_withBot, WithBot.coe_lt_coe, lt_iff_not_le, Ne, not_imp_not] rfl #align polynomial.mem_degree_lt Polynomial.mem_degreeLT @[mono] theorem degreeLT_mono {m n : ℕ} (H : m ≤ n) : degreeLT R m ≤ degreeLT R n := fun _ hf => mem_degreeLT.2 (lt_of_lt_of_le (mem_degreeLT.1 hf) <| WithBot.coe_le_coe.2 H) #align polynomial.degree_lt_mono Polynomial.degreeLT_mono theorem degreeLT_eq_span_X_pow [DecidableEq R] {n : ℕ} : degreeLT R n = Submodule.span R ↑((Finset.range n).image fun n => X ^ n : Finset R[X]) := by apply le_antisymm · intro p hp replace hp := mem_degreeLT.1 hp rw [← Polynomial.sum_monomial_eq p, Polynomial.sum] refine Submodule.sum_mem _ fun k hk => ?_ have := WithBot.coe_lt_coe.1 ((Finset.sup_lt_iff <| WithBot.bot_lt_coe n).1 hp k hk) rw [← C_mul_X_pow_eq_monomial, C_mul'] refine Submodule.smul_mem _ _ (Submodule.subset_span <| Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 this, rfl⟩) rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff] intro k hk apply mem_degreeLT.2 exact lt_of_le_of_lt (degree_X_pow_le _) (WithBot.coe_lt_coe.2 <| Finset.mem_range.1 hk) set_option linter.uppercaseLean3 false in #align polynomial.degree_lt_eq_span_X_pow Polynomial.degreeLT_eq_span_X_pow /-- The first `n` coefficients on `degreeLT n` form a linear equivalence with `Fin n → R`. -/ def degreeLTEquiv (R) [Semiring R] (n : ℕ) : degreeLT R n ≃ₗ[R] Fin n → R where toFun p n := (↑p : R[X]).coeff n invFun f := ⟨∑ i : Fin n, monomial i (f i), (degreeLT R n).sum_mem fun i _ => mem_degreeLT.mpr (lt_of_le_of_lt (degree_monomial_le i (f i)) (WithBot.coe_lt_coe.mpr i.is_lt))⟩ map_add' p q := by ext dsimp rw [coeff_add] map_smul' x p := by ext dsimp rw [coeff_smul] rfl left_inv := by rintro ⟨p, hp⟩ ext1 simp only [Submodule.coe_mk] by_cases hp0 : p = 0 · subst hp0 simp only [coeff_zero, LinearMap.map_zero, Finset.sum_const_zero] rw [mem_degreeLT, degree_eq_natDegree hp0, Nat.cast_lt] at hp conv_rhs => rw [p.as_sum_range' n hp, ← Fin.sum_univ_eq_sum_range] right_inv f := by ext i simp only [finset_sum_coeff, Submodule.coe_mk] rw [Finset.sum_eq_single i, coeff_monomial, if_pos rfl] · rintro j - hji rw [coeff_monomial, if_neg] rwa [← Fin.ext_iff] · intro h exact (h (Finset.mem_univ _)).elim #align polynomial.degree_lt_equiv Polynomial.degreeLTEquiv -- Porting note: removed @[simp] as simp can prove this theorem degreeLTEquiv_eq_zero_iff_eq_zero {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) : degreeLTEquiv _ _ ⟨p, hp⟩ = 0 ↔ p = 0 := by rw [LinearEquiv.map_eq_zero_iff, Submodule.mk_eq_zero] #align polynomial.degree_lt_equiv_eq_zero_iff_eq_zero Polynomial.degreeLTEquiv_eq_zero_iff_eq_zero theorem eval_eq_sum_degreeLTEquiv {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) (x : R) : p.eval x = ∑ i, degreeLTEquiv _ _ ⟨p, hp⟩ i * x ^ (i : ℕ) := by simp_rw [eval_eq_sum] exact (sum_fin _ (by simp_rw [zero_mul, forall_const]) (mem_degreeLT.mp hp)).symm #align polynomial.eval_eq_sum_degree_lt_equiv Polynomial.eval_eq_sum_degreeLTEquiv theorem degreeLT_succ_eq_degreeLE {n : ℕ} : degreeLT R (n + 1) = degreeLE R n := by ext x by_cases x_zero : x = 0 · simp_rw [x_zero, Submodule.zero_mem] · rw [mem_degreeLT, mem_degreeLE, ← natDegree_lt_iff_degree_lt (by rwa [ne_eq]), ← natDegree_le_iff_degree_le, Nat.lt_succ] /-- For every polynomial `p` in the span of a set `s : Set R[X]`, there exists a polynomial of `p' ∈ s` with higher degree. See also `Polynomial.exists_degree_le_of_mem_span_of_finite`. -/ theorem exists_degree_le_of_mem_span {s : Set R[X]} {p : R[X]} (hs : s.Nonempty) (hp : p ∈ Submodule.span R s) : ∃ p' ∈ s, degree p ≤ degree p' := by by_contra! h by_cases hp_zero : p = 0 · rw [hp_zero, degree_zero] at h rcases hs with ⟨x, hx⟩ exact not_lt_bot (h x hx) · have : p ∈ degreeLT R (natDegree p) := by refine (Submodule.span_le.mpr fun p' p'_mem => ?_) hp rw [SetLike.mem_coe, mem_degreeLT, Nat.cast_withBot] exact lt_of_lt_of_le (h p' p'_mem) degree_le_natDegree rwa [mem_degreeLT, Nat.cast_withBot, degree_eq_natDegree hp_zero, Nat.cast_withBot, lt_self_iff_false] at this /-- A stronger version of `Polynomial.exists_degree_le_of_mem_span` under the assumption that the set `s : R[X]` is finite. There exists a polynomial `p' ∈ s` whose degree dominates the degree of every element of `p ∈ span R s`-/ theorem exists_degree_le_of_mem_span_of_finite {s : Set R[X]} (s_fin : s.Finite) (hs : s.Nonempty) : ∃ p' ∈ s, ∀ (p : R[X]), p ∈ Submodule.span R s → degree p ≤ degree p' := by rcases Set.Finite.exists_maximal_wrt degree s s_fin hs with ⟨a, has, hmax⟩ refine ⟨a, has, fun p hp => ?_⟩ rcases exists_degree_le_of_mem_span hs hp with ⟨p', hp'⟩ by_cases h : degree a ≤ degree p' · rw [← hmax p' hp'.left h] at hp'; exact hp'.right · exact le_trans hp'.right (not_le.mp h).le /-- The span of every finite set of polynomials is contained in a `degreeLE n` for some `n`. -/ theorem span_le_degreeLE_of_finite {s : Set R[X]} (s_fin : s.Finite) : ∃ n : ℕ, Submodule.span R s ≤ degreeLE R n := by by_cases s_emp : s.Nonempty · rcases exists_degree_le_of_mem_span_of_finite s_fin s_emp with ⟨p', _, hp'max⟩ exact ⟨natDegree p', fun p hp => mem_degreeLE.mpr ((hp'max _ hp).trans degree_le_natDegree)⟩ · rw [Set.not_nonempty_iff_eq_empty] at s_emp rw [s_emp, Submodule.span_empty] exact ⟨0, bot_le⟩ /-- The span of every finite set of polynomials is contained in a `degreeLT n` for some `n`. -/ theorem span_of_finite_le_degreeLT {s : Set R[X]} (s_fin : s.Finite) : ∃ n : ℕ, Submodule.span R s ≤ degreeLT R n := by rcases span_le_degreeLE_of_finite s_fin with ⟨n, _⟩ exact ⟨n + 1, by rwa [degreeLT_succ_eq_degreeLE]⟩ /-- If `R` is a nontrivial ring, the polynomials `R[X]` are not finite as an `R`-module. When `R` is a field, this is equivalent to `R[X]` being an infinite-dimensional vector space over `R`. -/ theorem not_finite [Nontrivial R] : ¬ Module.Finite R R[X] := by rw [Module.finite_def, Submodule.fg_def] push_neg intro s hs contra rcases span_le_degreeLE_of_finite hs with ⟨n,hn⟩ have : ((X : R[X]) ^ (n + 1)) ∈ Polynomial.degreeLE R ↑n := by rw [contra] at hn exact hn Submodule.mem_top rw [mem_degreeLE, degree_X_pow, Nat.cast_le, add_le_iff_nonpos_right, nonpos_iff_eq_zero] at this exact one_ne_zero this /-- The finset of nonzero coefficients of a polynomial. -/ def coeffs (p : R[X]) : Finset R := letI := Classical.decEq R Finset.image (fun n => p.coeff n) p.support #align polynomial.frange Polynomial.coeffs @[deprecated (since := "2024-05-17")] noncomputable alias frange := coeffs theorem coeffs_zero : coeffs (0 : R[X]) = ∅ := rfl #align polynomial.frange_zero Polynomial.coeffs_zero @[deprecated (since := "2024-05-17")] alias frange_zero := coeffs_zero theorem mem_coeffs_iff {p : R[X]} {c : R} : c ∈ p.coeffs ↔ ∃ n ∈ p.support, c = p.coeff n := by simp [coeffs, eq_comm, (Finset.mem_image)] #align polynomial.mem_frange_iff Polynomial.mem_coeffs_iff @[deprecated (since := "2024-05-17")] alias mem_frange_iff := mem_coeffs_iff theorem coeffs_one : coeffs (1 : R[X]) ⊆ {1} := by classical simp_rw [coeffs, Finset.image_subset_iff] simp_all [coeff_one] #align polynomial.frange_one Polynomial.coeffs_one @[deprecated (since := "2024-05-17")] alias frange_one := coeffs_one theorem coeff_mem_coeffs (p : R[X]) (n : ℕ) (h : p.coeff n ≠ 0) : p.coeff n ∈ p.coeffs := by classical simp only [coeffs, exists_prop, mem_support_iff, Finset.mem_image, Ne] exact ⟨n, h, rfl⟩ #align polynomial.coeff_mem_frange Polynomial.coeff_mem_coeffs @[deprecated (since := "2024-05-17")] alias coeff_mem_frange := coeff_mem_coeffs theorem geom_sum_X_comp_X_add_one_eq_sum (n : ℕ) : (∑ i ∈ range n, (X : R[X]) ^ i).comp (X + 1) = (Finset.range n).sum fun i : ℕ => (n.choose (i + 1) : R[X]) * X ^ i := by ext i trans (n.choose (i + 1) : R); swap · simp only [finset_sum_coeff, ← C_eq_natCast, coeff_C_mul_X_pow] rw [Finset.sum_eq_single i, if_pos rfl] · simp (config := { contextual := true }) only [@eq_comm _ i, if_false, eq_self_iff_true, imp_true_iff] · simp (config := { contextual := true }) only [Nat.lt_add_one_iff, Nat.choose_eq_zero_of_lt, Nat.cast_zero, Finset.mem_range, not_lt, eq_self_iff_true, if_true, imp_true_iff] induction' n with n ih generalizing i · dsimp; simp only [zero_comp, coeff_zero, Nat.cast_zero] · simp only [geom_sum_succ', ih, add_comp, X_pow_comp, coeff_add, Nat.choose_succ_succ, Nat.cast_add, coeff_X_add_one_pow] set_option linter.uppercaseLean3 false in #align polynomial.geom_sum_X_comp_X_add_one_eq_sum Polynomial.geom_sum_X_comp_X_add_one_eq_sum theorem Monic.geom_sum {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.natDegree) {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, P ^ i).Monic := by nontriviality R obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn rw [geom_sum_succ'] refine (hP.pow _).add_of_left ?_ refine lt_of_le_of_lt (degree_sum_le _ _) ?_ rw [Finset.sup_lt_iff] · simp only [Finset.mem_range, degree_eq_natDegree (hP.pow _).ne_zero] simp only [Nat.cast_lt, hP.natDegree_pow] intro k exact nsmul_lt_nsmul_left hdeg · rw [bot_lt_iff_ne_bot, Ne, degree_eq_bot] exact (hP.pow _).ne_zero #align polynomial.monic.geom_sum Polynomial.Monic.geom_sum theorem Monic.geom_sum' {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.degree) {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, P ^ i).Monic := hP.geom_sum (natDegree_pos_iff_degree_pos.2 hdeg) hn #align polynomial.monic.geom_sum' Polynomial.Monic.geom_sum' theorem monic_geom_sum_X {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, (X : R[X]) ^ i).Monic := by nontriviality R apply monic_X.geom_sum _ hn simp only [natDegree_X, zero_lt_one] set_option linter.uppercaseLean3 false in #align polynomial.monic_geom_sum_X Polynomial.monic_geom_sum_X end Semiring section Ring variable [Ring R] /-- Given a polynomial, return the polynomial whose coefficients are in the ring closure of the original coefficients. -/ def restriction (p : R[X]) : Polynomial (Subring.closure (↑p.coeffs : Set R)) := ∑ i ∈ p.support, monomial i (⟨p.coeff i, letI := Classical.decEq R if H : p.coeff i = 0 then H.symm ▸ (Subring.closure _).zero_mem else Subring.subset_closure (p.coeff_mem_coeffs _ H)⟩ : Subring.closure (↑p.coeffs : Set R)) #align polynomial.restriction Polynomial.restriction @[simp] theorem coeff_restriction {p : R[X]} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := by classical simp only [restriction, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq', Ne, ite_not] split_ifs with h · rw [h] rfl · rfl #align polynomial.coeff_restriction Polynomial.coeff_restriction -- Porting note: removed @[simp] as simp can prove this theorem coeff_restriction' {p : R[X]} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := coeff_restriction #align polynomial.coeff_restriction' Polynomial.coeff_restriction' @[simp] theorem support_restriction (p : R[X]) : support (restriction p) = support p := by ext i simp only [mem_support_iff, not_iff_not, Ne] conv_rhs => rw [← coeff_restriction] exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩ #align polynomial.support_restriction Polynomial.support_restriction @[simp] theorem map_restriction {R : Type u} [CommRing R] (p : R[X]) : p.restriction.map (algebraMap _ _) = p := ext fun n => by rw [coeff_map, Algebra.algebraMap_ofSubring_apply, coeff_restriction] #align polynomial.map_restriction Polynomial.map_restriction @[simp] theorem degree_restriction {p : R[X]} : (restriction p).degree = p.degree := by simp [degree] #align polynomial.degree_restriction Polynomial.degree_restriction @[simp] theorem natDegree_restriction {p : R[X]} : (restriction p).natDegree = p.natDegree := by simp [natDegree] #align polynomial.nat_degree_restriction Polynomial.natDegree_restriction @[simp] theorem monic_restriction {p : R[X]} : Monic (restriction p) ↔ Monic p := by simp only [Monic, leadingCoeff, natDegree_restriction] rw [← @coeff_restriction _ _ p] exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩ #align polynomial.monic_restriction Polynomial.monic_restriction @[simp] theorem restriction_zero : restriction (0 : R[X]) = 0 := by simp only [restriction, Finset.sum_empty, support_zero] #align polynomial.restriction_zero Polynomial.restriction_zero @[simp] theorem restriction_one : restriction (1 : R[X]) = 1 := ext fun i => Subtype.eq <| by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs <;> rfl #align polynomial.restriction_one Polynomial.restriction_one variable [Semiring S] {f : R →+* S} {x : S} theorem eval₂_restriction {p : R[X]} : eval₂ f x p = eval₂ (f.comp (Subring.subtype (Subring.closure (p.coeffs : Set R)))) x p.restriction := by simp only [eval₂_eq_sum, sum, support_restriction, ← @coeff_restriction _ _ p, RingHom.comp_apply, Subring.coeSubtype] #align polynomial.eval₂_restriction Polynomial.eval₂_restriction section ToSubring variable (p : R[X]) (T : Subring R) /-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`, return the corresponding polynomial whose coefficients are in `T`. -/ def toSubring (hp : (↑p.coeffs : Set R) ⊆ T) : T[X] := ∑ i ∈ p.support, monomial i (⟨p.coeff i, letI := Classical.decEq R if H : p.coeff i = 0 then H.symm ▸ T.zero_mem else hp (p.coeff_mem_coeffs _ H)⟩ : T) #align polynomial.to_subring Polynomial.toSubring variable (hp : (↑p.coeffs : Set R) ⊆ T) @[simp] theorem coeff_toSubring {n : ℕ} : ↑(coeff (toSubring p T hp) n) = coeff p n := by classical simp only [toSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq', Ne, ite_not] split_ifs with h · rw [h] rfl · rfl #align polynomial.coeff_to_subring Polynomial.coeff_toSubring -- Porting note: removed @[simp] as simp can prove this theorem coeff_toSubring' {n : ℕ} : (coeff (toSubring p T hp) n).1 = coeff p n := coeff_toSubring _ _ hp #align polynomial.coeff_to_subring' Polynomial.coeff_toSubring' @[simp] theorem support_toSubring : support (toSubring p T hp) = support p := by ext i simp only [mem_support_iff, not_iff_not, Ne] conv_rhs => rw [← coeff_toSubring p T hp] exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩ #align polynomial.support_to_subring Polynomial.support_toSubring @[simp] theorem degree_toSubring : (toSubring p T hp).degree = p.degree := by simp [degree] #align polynomial.degree_to_subring Polynomial.degree_toSubring @[simp] theorem natDegree_toSubring : (toSubring p T hp).natDegree = p.natDegree := by simp [natDegree] #align polynomial.nat_degree_to_subring Polynomial.natDegree_toSubring @[simp] theorem monic_toSubring : Monic (toSubring p T hp) ↔ Monic p := by simp_rw [Monic, leadingCoeff, natDegree_toSubring, ← coeff_toSubring p T hp] exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩ #align polynomial.monic_to_subring Polynomial.monic_toSubring @[simp] theorem toSubring_zero : toSubring (0 : R[X]) T (by simp [coeffs]) = 0 := by ext i simp #align polynomial.to_subring_zero Polynomial.toSubring_zero @[simp] theorem toSubring_one : toSubring (1 : R[X]) T (Set.Subset.trans coeffs_one <| Finset.singleton_subset_set_iff.2 T.one_mem) = 1 := ext fun i => Subtype.eq <| by rw [coeff_toSubring', coeff_one, coeff_one, apply_ite Subtype.val, ZeroMemClass.coe_zero, OneMemClass.coe_one] #align polynomial.to_subring_one Polynomial.toSubring_one @[simp] theorem map_toSubring : (p.toSubring T hp).map (Subring.subtype T) = p := by ext n simp [coeff_map] #align polynomial.map_to_subring Polynomial.map_toSubring end ToSubring variable (T : Subring R) /-- Given a polynomial whose coefficients are in some subring, return the corresponding polynomial whose coefficients are in the ambient ring. -/ def ofSubring (p : T[X]) : R[X] := ∑ i ∈ p.support, monomial i (p.coeff i : R) #align polynomial.of_subring Polynomial.ofSubring theorem coeff_ofSubring (p : T[X]) (n : ℕ) : coeff (ofSubring T p) n = (coeff p n : T) := by simp only [ofSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq', ite_eq_right_iff, Ne, ite_not, Classical.not_not, ite_eq_left_iff] intro h rw [h, ZeroMemClass.coe_zero] #align polynomial.coeff_of_subring Polynomial.coeff_ofSubring @[simp] theorem coeffs_ofSubring {p : T[X]} : (↑(p.ofSubring T).coeffs : Set R) ⊆ T := by classical intro i hi simp only [coeffs, Set.mem_image, mem_support_iff, Ne, Finset.mem_coe, (Finset.coe_image)] at hi rcases hi with ⟨n, _, h'n⟩ rw [← h'n, coeff_ofSubring] exact Subtype.mem (coeff p n : T) #align polynomial.frange_of_subring Polynomial.coeffs_ofSubring @[deprecated (since := "2024-05-17")] alias frange_ofSubring := coeffs_ofSubring end Ring section CommRing variable [CommRing R] section ModByMonic variable {q : R[X]} theorem mem_ker_modByMonic (hq : q.Monic) {p : R[X]} : p ∈ LinearMap.ker (modByMonicHom q) ↔ q ∣ p := LinearMap.mem_ker.trans (modByMonic_eq_zero_iff_dvd hq) #align polynomial.mem_ker_mod_by_monic Polynomial.mem_ker_modByMonic @[simp] theorem ker_modByMonicHom (hq : q.Monic) : LinearMap.ker (Polynomial.modByMonicHom q) = (Ideal.span {q}).restrictScalars R := Submodule.ext fun _ => (mem_ker_modByMonic hq).trans Ideal.mem_span_singleton.symm #align polynomial.ker_mod_by_monic_hom Polynomial.ker_modByMonicHom end ModByMonic end CommRing end Polynomial namespace Ideal open Polynomial section Semiring variable [Semiring R] /-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/ def ofPolynomial (I : Ideal R[X]) : Submodule R R[X] where carrier := I.carrier zero_mem' := I.zero_mem add_mem' := I.add_mem smul_mem' c x H := by rw [← C_mul'] exact I.mul_mem_left _ H #align ideal.of_polynomial Ideal.ofPolynomial variable {I : Ideal R[X]} theorem mem_ofPolynomial (x) : x ∈ I.ofPolynomial ↔ x ∈ I := Iff.rfl #align ideal.mem_of_polynomial Ideal.mem_ofPolynomial variable (I) /-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I` consisting of polynomials of degree ≤ `n`. -/ def degreeLE (n : WithBot ℕ) : Submodule R R[X] := Polynomial.degreeLE R n ⊓ I.ofPolynomial #align ideal.degree_le Ideal.degreeLE /-- Given an ideal `I` of `R[X]`, make the ideal in `R` of leading coefficients of polynomials in `I` with degree ≤ `n`. -/ def leadingCoeffNth (n : ℕ) : Ideal R := (I.degreeLE n).map <| lcoeff R n #align ideal.leading_coeff_nth Ideal.leadingCoeffNth /-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the leading coefficients in `I`. -/ def leadingCoeff : Ideal R := ⨆ n : ℕ, I.leadingCoeffNth n #align ideal.leading_coeff Ideal.leadingCoeff end Semiring section CommSemiring variable [CommSemiring R] [Semiring S] /-- If every coefficient of a polynomial is in an ideal `I`, then so is the polynomial itself -/ theorem polynomial_mem_ideal_of_coeff_mem_ideal (I : Ideal R[X]) (p : R[X]) (hp : ∀ n : ℕ, p.coeff n ∈ I.comap (C : R →+* R[X])) : p ∈ I := sum_C_mul_X_pow_eq p ▸ Submodule.sum_mem I fun n _ => I.mul_mem_right _ (hp n) #align ideal.polynomial_mem_ideal_of_coeff_mem_ideal Ideal.polynomial_mem_ideal_of_coeff_mem_ideal /-- The push-forward of an ideal `I` of `R` to `R[X]` via inclusion is exactly the set of polynomials whose coefficients are in `I` -/ theorem mem_map_C_iff {I : Ideal R} {f : R[X]} : f ∈ (Ideal.map (C : R →+* R[X]) I : Ideal R[X]) ↔ ∀ n : ℕ, f.coeff n ∈ I := by constructor · intro hf apply @Submodule.span_induction _ _ _ _ _ f _ _ hf · intro f hf n cases' (Set.mem_image _ _ _).mp hf with x hx rw [← hx.right, coeff_C] by_cases h : n = 0 · simpa [h] using hx.left · simp [h] · simp · exact fun f g hf hg n => by simp [I.add_mem (hf n) (hg n)] · refine fun f g hg n => ?_ rw [smul_eq_mul, coeff_mul] exact I.sum_mem fun c _ => I.mul_mem_left (f.coeff c.fst) (hg c.snd) · intro hf rw [← sum_monomial_eq f] refine (I.map C : Ideal R[X]).sum_mem fun n _ => ?_ simp only [← C_mul_X_pow_eq_monomial, ne_eq] rw [mul_comm] exact (I.map C : Ideal R[X]).mul_mem_left _ (mem_map_of_mem _ (hf n)) set_option linter.uppercaseLean3 false in #align ideal.mem_map_C_iff Ideal.mem_map_C_iff theorem _root_.Polynomial.ker_mapRingHom (f : R →+* S) : LinearMap.ker (Polynomial.mapRingHom f).toSemilinearMap = f.ker.map (C : R →+* R[X]) := by ext simp only [LinearMap.mem_ker, RingHom.toSemilinearMap_apply, coe_mapRingHom] rw [mem_map_C_iff, Polynomial.ext_iff] simp_rw [RingHom.mem_ker f] simp #align polynomial.ker_map_ring_hom Polynomial.ker_mapRingHom variable (I : Ideal R[X]) theorem mem_leadingCoeffNth (n : ℕ) (x) : x ∈ I.leadingCoeffNth n ↔ ∃ p ∈ I, degree p ≤ n ∧ p.leadingCoeff = x := by simp only [leadingCoeffNth, degreeLE, Submodule.mem_map, lcoeff_apply, Submodule.mem_inf, mem_degreeLE] constructor · rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩ rcases lt_or_eq_of_le hpdeg with hpdeg | hpdeg · refine ⟨0, I.zero_mem, bot_le, ?_⟩ rw [leadingCoeff_zero, eq_comm] exact coeff_eq_zero_of_degree_lt hpdeg · refine ⟨p, hpI, le_of_eq hpdeg, ?_⟩ rw [Polynomial.leadingCoeff, natDegree, hpdeg, Nat.cast_withBot, WithBot.unbot'_coe] · rintro ⟨p, hpI, hpdeg, rfl⟩ have : natDegree p + (n - natDegree p) = n := add_tsub_cancel_of_le (natDegree_le_of_degree_le hpdeg) refine ⟨p * X ^ (n - natDegree p), ⟨?_, I.mul_mem_right _ hpI⟩, ?_⟩ · apply le_trans (degree_mul_le _ _) _ apply le_trans (add_le_add degree_le_natDegree (degree_X_pow_le _)) _ rw [← Nat.cast_add, this] · rw [Polynomial.leadingCoeff, ← coeff_mul_X_pow p (n - natDegree p), this] #align ideal.mem_leading_coeff_nth Ideal.mem_leadingCoeffNth theorem mem_leadingCoeffNth_zero (x) : x ∈ I.leadingCoeffNth 0 ↔ C x ∈ I := (mem_leadingCoeffNth _ _ _).trans ⟨fun ⟨p, hpI, hpdeg, hpx⟩ => by rwa [← hpx, Polynomial.leadingCoeff, Nat.eq_zero_of_le_zero (natDegree_le_of_degree_le hpdeg), ← eq_C_of_degree_le_zero hpdeg], fun hx => ⟨C x, hx, degree_C_le, leadingCoeff_C x⟩⟩ #align ideal.mem_leading_coeff_nth_zero Ideal.mem_leadingCoeffNth_zero theorem leadingCoeffNth_mono {m n : ℕ} (H : m ≤ n) : I.leadingCoeffNth m ≤ I.leadingCoeffNth n := by intro r hr simp only [SetLike.mem_coe, mem_leadingCoeffNth] at hr ⊢ rcases hr with ⟨p, hpI, hpdeg, rfl⟩ refine ⟨p * X ^ (n - m), I.mul_mem_right _ hpI, ?_, leadingCoeff_mul_X_pow⟩ refine le_trans (degree_mul_le _ _) ?_ refine le_trans (add_le_add hpdeg (degree_X_pow_le _)) ?_ rw [← Nat.cast_add, add_tsub_cancel_of_le H] #align ideal.leading_coeff_nth_mono Ideal.leadingCoeffNth_mono theorem mem_leadingCoeff (x) : x ∈ I.leadingCoeff ↔ ∃ p ∈ I, Polynomial.leadingCoeff p = x := by rw [leadingCoeff, Submodule.mem_iSup_of_directed] · simp only [mem_leadingCoeffNth] constructor · rintro ⟨i, p, hpI, _, rfl⟩ exact ⟨p, hpI, rfl⟩ rintro ⟨p, hpI, rfl⟩ exact ⟨natDegree p, p, hpI, degree_le_natDegree, rfl⟩ intro i j exact ⟨i + j, I.leadingCoeffNth_mono (Nat.le_add_right _ _), I.leadingCoeffNth_mono (Nat.le_add_left _ _)⟩ #align ideal.mem_leading_coeff Ideal.mem_leadingCoeff /-- If `I` is an ideal, and `pᵢ` is a finite family of polynomials each satisfying `∀ k, (pᵢ)ₖ ∈ Iⁿⁱ⁻ᵏ` for some `nᵢ`, then `p = ∏ pᵢ` also satisfies `∀ k, pₖ ∈ Iⁿ⁻ᵏ` with `n = ∑ nᵢ`. -/ theorem _root_.Polynomial.coeff_prod_mem_ideal_pow_tsub {ι : Type*} (s : Finset ι) (f : ι → R[X]) (I : Ideal R) (n : ι → ℕ) (h : ∀ i ∈ s, ∀ (k), (f i).coeff k ∈ I ^ (n i - k)) (k : ℕ) : (s.prod f).coeff k ∈ I ^ (s.sum n - k) := by classical induction' s using Finset.induction with a s ha hs generalizing k · rw [sum_empty, prod_empty, coeff_one, zero_tsub, pow_zero, Ideal.one_eq_top] exact Submodule.mem_top · rw [sum_insert ha, prod_insert ha, coeff_mul] apply sum_mem rintro ⟨i, j⟩ e obtain rfl : i + j = k := mem_antidiagonal.mp e apply Ideal.pow_le_pow_right add_tsub_add_le_tsub_add_tsub rw [pow_add] exact Ideal.mul_mem_mul (h _ (Finset.mem_insert.mpr <| Or.inl rfl) _) (hs (fun i hi k => h _ (Finset.mem_insert.mpr <| Or.inr hi) _) j) #align polynomial.coeff_prod_mem_ideal_pow_tsub Polynomial.coeff_prod_mem_ideal_pow_tsub end CommSemiring section Ring variable [Ring R] /-- `R[X]` is never a field for any ring `R`. -/ theorem polynomial_not_isField : ¬IsField R[X] := by nontriviality R intro hR obtain ⟨p, hp⟩ := hR.mul_inv_cancel X_ne_zero have hp0 : p ≠ 0 := right_ne_zero_of_mul_eq_one hp have := degree_lt_degree_mul_X hp0 rw [← X_mul, congr_arg degree hp, degree_one, Nat.WithBot.lt_zero_iff, degree_eq_bot] at this exact hp0 this #align ideal.polynomial_not_is_field Ideal.polynomial_not_isField /-- The only constant in a maximal ideal over a field is `0`. -/ theorem eq_zero_of_constant_mem_of_maximal (hR : IsField R) (I : Ideal R[X]) [hI : I.IsMaximal] (x : R) (hx : C x ∈ I) : x = 0 := by refine Classical.by_contradiction fun hx0 => hI.ne_top ((eq_top_iff_one I).2 ?_) obtain ⟨y, hy⟩ := hR.mul_inv_cancel hx0 convert I.mul_mem_left (C y) hx rw [← C.map_mul, hR.mul_comm y x, hy, RingHom.map_one] #align ideal.eq_zero_of_constant_mem_of_maximal Ideal.eq_zero_of_constant_mem_of_maximal end Ring section CommRing variable [CommRing R] /-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/ theorem isPrime_map_C_iff_isPrime (P : Ideal R) : IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) ↔ IsPrime P := by -- Note: the following proof avoids quotient rings -- It can be golfed substantially by using something like -- `(Quotient.isDomain_iff_prime (map C P : Ideal R[X]))` constructor · intro H have := comap_isPrime C (map C P) convert this using 1 ext x simp only [mem_comap, mem_map_C_iff] constructor · rintro h (- | n) · rwa [coeff_C_zero] · simp only [coeff_C_ne_zero (Nat.succ_ne_zero _), Submodule.zero_mem] · intro h simpa only [coeff_C_zero] using h 0 · intro h constructor · rw [Ne, eq_top_iff_one, mem_map_C_iff, not_forall] use 0 rw [coeff_one_zero, ← eq_top_iff_one] exact h.1 · intro f g simp only [mem_map_C_iff] contrapose! rintro ⟨hf, hg⟩ classical let m := Nat.find hf let n := Nat.find hg refine ⟨m + n, ?_⟩ rw [coeff_mul, ← Finset.insert_erase ((Finset.mem_antidiagonal (a := (m,n))).mpr rfl), Finset.sum_insert (Finset.not_mem_erase _ _), (P.add_mem_iff_left _).not] · apply mt h.2 rw [not_or] exact ⟨Nat.find_spec hf, Nat.find_spec hg⟩ apply P.sum_mem rintro ⟨i, j⟩ hij rw [Finset.mem_erase, Finset.mem_antidiagonal] at hij simp only [Ne, Prod.mk.inj_iff, not_and_or] at hij obtain hi | hj : i < m ∨ j < n := by rw [or_iff_not_imp_left, not_lt, le_iff_lt_or_eq] rintro (hmi | rfl) · rw [← not_le] intro hnj exact (add_lt_add_of_lt_of_le hmi hnj).ne hij.2.symm · simp only [eq_self_iff_true, not_true, false_or_iff, add_right_inj, not_and_self_iff] at hij · rw [mul_comm] apply P.mul_mem_left exact Classical.not_not.1 (Nat.find_min hf hi) · apply P.mul_mem_left exact Classical.not_not.1 (Nat.find_min hg hj) set_option linter.uppercaseLean3 false in #align ideal.is_prime_map_C_iff_is_prime Ideal.isPrime_map_C_iff_isPrime /-- If `P` is a prime ideal of `R`, then `P.R[x]` is a prime ideal of `R[x]`. -/ theorem isPrime_map_C_of_isPrime {P : Ideal R} (H : IsPrime P) : IsPrime (map (C : R →+* R[X]) P : Ideal R[X]) := (isPrime_map_C_iff_isPrime P).mpr H set_option linter.uppercaseLean3 false in #align ideal.is_prime_map_C_of_is_prime Ideal.isPrime_map_C_of_isPrime theorem is_fg_degreeLE [IsNoetherianRing R] (I : Ideal R[X]) (n : ℕ) : Submodule.FG (I.degreeLE n) := letI := Classical.decEq R isNoetherian_submodule_left.1 (isNoetherian_of_fg_of_noetherian _ ⟨_, degreeLE_eq_span_X_pow.symm⟩) _ #align ideal.is_fg_degree_le Ideal.is_fg_degreeLE end CommRing end Ideal variable {σ : Type v} {M : Type w} variable [CommRing R] [CommRing S] [AddCommGroup M] [Module R M] section Prime variable (σ) {r : R} namespace Polynomial theorem prime_C_iff : Prime (C r) ↔ Prime r := ⟨comap_prime C (evalRingHom (0 : R)) fun r => eval_C, fun hr => by have := hr.1 rw [← Ideal.span_singleton_prime] at hr ⊢ · rw [← Set.image_singleton, ← Ideal.map_span] apply Ideal.isPrime_map_C_of_isPrime hr · intro h; apply (this (C_eq_zero.mp h)) · assumption⟩ set_option linter.uppercaseLean3 false in #align polynomial.prime_C_iff Polynomial.prime_C_iff end Polynomial namespace MvPolynomial private theorem prime_C_iff_of_fintype {R : Type u} (σ : Type v) {r : R} [CommRing R] [Fintype σ] : Prime (C r : MvPolynomial σ R) ↔ Prime r := by rw [(renameEquiv R (Fintype.equivFin σ)).toMulEquiv.prime_iff] convert_to Prime (C r) ↔ _ · congr! apply rename_C · symm induction' Fintype.card σ with d hd · exact (isEmptyAlgEquiv R (Fin 0)).toMulEquiv.symm.prime_iff · rw [hd, ← Polynomial.prime_C_iff] convert (finSuccEquiv R d).toMulEquiv.symm.prime_iff (p := Polynomial.C (C r)) rw [← finSuccEquiv_comp_C_eq_C]; rfl theorem prime_C_iff : Prime (C r : MvPolynomial σ R) ↔ Prime r := ⟨comap_prime C constantCoeff (constantCoeff_C _), fun hr => ⟨fun h => hr.1 <| by rw [← C_inj, h] simp, fun h => hr.2.1 <| by rw [← constantCoeff_C _ r] exact h.map _, fun a b hd => by obtain ⟨s, a', b', rfl, rfl⟩ := exists_finset_rename₂ a b rw [← algebraMap_eq] at hd have : algebraMap R _ r ∣ a' * b' := by convert killCompl Subtype.coe_injective |>.toRingHom.map_dvd hd <;> simp rw [← rename_C ((↑) : s → σ)] let f := (rename (R := R) ((↑) : s → σ)).toRingHom exact (((prime_C_iff_of_fintype s).2 hr).2.2 a' b' this).imp f.map_dvd f.map_dvd⟩⟩ set_option linter.uppercaseLean3 false in #align mv_polynomial.prime_C_iff MvPolynomial.prime_C_iff variable {σ} theorem prime_rename_iff (s : Set σ) {p : MvPolynomial s R} : Prime (rename ((↑) : s → σ) p) ↔ Prime (p : MvPolynomial s R) := by classical symm let eqv := (sumAlgEquiv R (↥sᶜ) s).symm.trans (renameEquiv R <| (Equiv.sumComm (↥sᶜ) s).trans <| Equiv.Set.sumCompl s) have : (rename (↑)).toRingHom = eqv.toAlgHom.toRingHom.comp C := by apply ringHom_ext · intro simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_C, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply, iterToSum_C_C, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply] · intro simp only [eqv, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, rename_X, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, AlgEquiv.coe_trans, Function.comp_apply, MvPolynomial.sumAlgEquiv_symm_apply, iterToSum_C_X, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply, Sum.swap_inr, Equiv.Set.sumCompl_apply_inl] apply_fun (· p) at this simp_rw [AlgHom.toRingHom_eq_coe, RingHom.coe_coe] at this rw [← prime_C_iff, eqv.toMulEquiv.prime_iff, this] simp only [MulEquiv.coe_mk, AlgEquiv.toEquiv_eq_coe, EquivLike.coe_coe, AlgEquiv.trans_apply, MvPolynomial.sumAlgEquiv_symm_apply, renameEquiv_apply, Equiv.coe_trans, Equiv.sumComm_apply, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, RingHom.coe_comp, RingHom.coe_coe, AlgEquiv.coe_trans, Function.comp_apply] #align mv_polynomial.prime_rename_iff MvPolynomial.prime_rename_iff end MvPolynomial end Prime namespace Polynomial instance (priority := 100) wfDvdMonoid {R : Type*} [CommRing R] [IsDomain R] [WfDvdMonoid R] : WfDvdMonoid R[X] where wellFounded_dvdNotUnit := by classical refine RelHomClass.wellFounded (⟨fun p : R[X] => ((if p = 0 then ⊤ else ↑p.degree : WithTop (WithBot ℕ)), p.leadingCoeff), ?_⟩ : DvdNotUnit →r Prod.Lex (· < ·) DvdNotUnit) (wellFounded_lt.prod_lex ‹WfDvdMonoid R›.wellFounded_dvdNotUnit) rintro a b ⟨ane0, ⟨c, ⟨not_unit_c, rfl⟩⟩⟩ dsimp rw [Polynomial.degree_mul, if_neg ane0] split_ifs with hac · rw [hac, Polynomial.leadingCoeff_zero] apply Prod.Lex.left exact lt_of_le_of_ne le_top WithTop.coe_ne_top have cne0 : c ≠ 0 := right_ne_zero_of_mul hac simp only [cne0, ane0, Polynomial.leadingCoeff_mul] by_cases hdeg : c.degree = 0 · simp only [hdeg, add_zero] refine Prod.Lex.right _ ⟨?_, ⟨c.leadingCoeff, fun unit_c => not_unit_c ?_, rfl⟩⟩ · rwa [Ne, Polynomial.leadingCoeff_eq_zero] rw [Polynomial.isUnit_iff, Polynomial.eq_C_of_degree_eq_zero hdeg] use c.leadingCoeff, unit_c rw [Polynomial.leadingCoeff, Polynomial.natDegree_eq_of_degree_eq_some hdeg]; rfl · apply Prod.Lex.left rw [Polynomial.degree_eq_natDegree cne0] at * rw [WithTop.coe_lt_coe, Polynomial.degree_eq_natDegree ane0, ← Nat.cast_add, Nat.cast_lt] exact lt_add_of_pos_right _ (Nat.pos_of_ne_zero fun h => hdeg (h.symm ▸ WithBot.coe_zero)) end Polynomial /-- Hilbert basis theorem: a polynomial ring over a noetherian ring is a noetherian ring. -/ protected theorem Polynomial.isNoetherianRing [inst : IsNoetherianRing R] : IsNoetherianRing R[X] := isNoetherianRing_iff.2 ⟨fun I : Ideal R[X] => let M := WellFounded.min (isNoetherian_iff_wellFounded.1 (by infer_instance)) (Set.range I.leadingCoeffNth) ⟨_, ⟨0, rfl⟩⟩ have hm : M ∈ Set.range I.leadingCoeffNth := WellFounded.min_mem _ _ _ let ⟨N, HN⟩ := hm let ⟨s, hs⟩ := I.is_fg_degreeLE N have hm2 : ∀ k, I.leadingCoeffNth k ≤ M := fun k => Or.casesOn (le_or_lt k N) (fun h => HN ▸ I.leadingCoeffNth_mono h) fun h x hx => Classical.by_contradiction fun hxm => haveI : IsNoetherian R R := inst have : ¬M < I.leadingCoeffNth k := by refine WellFounded.not_lt_min (wellFounded_submodule_gt R R) _ _ ?_; exact ⟨k, rfl⟩ this ⟨HN ▸ I.leadingCoeffNth_mono (le_of_lt h), fun H => hxm (H hx)⟩ have hs2 : ∀ {x}, x ∈ I.degreeLE N → x ∈ Ideal.span (↑s : Set R[X]) := hs ▸ fun hx => Submodule.span_induction hx (fun _ hx => Ideal.subset_span hx) (Ideal.zero_mem _) (fun _ _ => Ideal.add_mem _) fun c f hf => f.C_mul' c ▸ Ideal.mul_mem_left _ _ hf ⟨s, le_antisymm (Ideal.span_le.2 fun x hx => have : x ∈ I.degreeLE N := hs ▸ Submodule.subset_span hx this.2) <| by have : Submodule.span R[X] ↑s = Ideal.span ↑s := rfl rw [this] intro p hp generalize hn : p.natDegree = k induction' k using Nat.strong_induction_on with k ih generalizing p rcases le_or_lt k N with h | h · subst k refine hs2 ⟨Polynomial.mem_degreeLE.2 (le_trans Polynomial.degree_le_natDegree <| WithBot.coe_le_coe.2 h), hp⟩ · have hp0 : p ≠ 0 := by rintro rfl cases hn exact Nat.not_lt_zero _ h have : (0 : R) ≠ 1 := by intro h apply hp0 ext i refine (mul_one _).symm.trans ?_ rw [← h, mul_zero] rfl haveI : Nontrivial R := ⟨⟨0, 1, this⟩⟩ have : p.leadingCoeff ∈ I.leadingCoeffNth N := by rw [HN] exact hm2 k ((I.mem_leadingCoeffNth _ _).2 ⟨_, hp, hn ▸ Polynomial.degree_le_natDegree, rfl⟩) rw [I.mem_leadingCoeffNth] at this rcases this with ⟨q, hq, hdq, hlqp⟩ have hq0 : q ≠ 0 := by intro H rw [← Polynomial.leadingCoeff_eq_zero] at H rw [hlqp, Polynomial.leadingCoeff_eq_zero] at H exact hp0 H have h1 : p.degree = (q * Polynomial.X ^ (k - q.natDegree)).degree := by rw [Polynomial.degree_mul', Polynomial.degree_X_pow] · rw [Polynomial.degree_eq_natDegree hp0, Polynomial.degree_eq_natDegree hq0] rw [← Nat.cast_add, add_tsub_cancel_of_le, hn] · refine le_trans (Polynomial.natDegree_le_of_degree_le hdq) (le_of_lt h) rw [Polynomial.leadingCoeff_X_pow, mul_one] exact mt Polynomial.leadingCoeff_eq_zero.1 hq0 have h2 : p.leadingCoeff = (q * Polynomial.X ^ (k - q.natDegree)).leadingCoeff := by rw [← hlqp, Polynomial.leadingCoeff_mul_X_pow] have := Polynomial.degree_sub_lt h1 hp0 h2 rw [Polynomial.degree_eq_natDegree hp0] at this rw [← sub_add_cancel p (q * Polynomial.X ^ (k - q.natDegree))] convert (Ideal.span ↑s).add_mem _ ((Ideal.span (s : Set R[X])).mul_mem_right _ _) · by_cases hpq : p - q * Polynomial.X ^ (k - q.natDegree) = 0 · rw [hpq] exact Ideal.zero_mem _ refine ih _ ?_ (I.sub_mem hp (I.mul_mem_right _ hq)) rfl rwa [Polynomial.degree_eq_natDegree hpq, Nat.cast_lt, hn] at this exact hs2 ⟨Polynomial.mem_degreeLE.2 hdq, hq⟩⟩⟩ #align polynomial.is_noetherian_ring Polynomial.isNoetherianRing attribute [instance] Polynomial.isNoetherianRing namespace Polynomial theorem exists_irreducible_of_degree_pos {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R] {f : R[X]} (hf : 0 < f.degree) : ∃ g, Irreducible g ∧ g ∣ f := WfDvdMonoid.exists_irreducible_factor (fun huf => ne_of_gt hf <| degree_eq_zero_of_isUnit huf) fun hf0 => not_lt_of_lt hf <| hf0.symm ▸ (@degree_zero R _).symm ▸ WithBot.bot_lt_coe _ #align polynomial.exists_irreducible_of_degree_pos Polynomial.exists_irreducible_of_degree_pos theorem exists_irreducible_of_natDegree_pos {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R] {f : R[X]} (hf : 0 < f.natDegree) : ∃ g, Irreducible g ∧ g ∣ f := exists_irreducible_of_degree_pos <| by contrapose! hf exact natDegree_le_of_degree_le hf #align polynomial.exists_irreducible_of_nat_degree_pos Polynomial.exists_irreducible_of_natDegree_pos theorem exists_irreducible_of_natDegree_ne_zero {R : Type u} [CommRing R] [IsDomain R] [WfDvdMonoid R] {f : R[X]} (hf : f.natDegree ≠ 0) : ∃ g, Irreducible g ∧ g ∣ f := exists_irreducible_of_natDegree_pos <| Nat.pos_of_ne_zero hf #align polynomial.exists_irreducible_of_nat_degree_ne_zero Polynomial.exists_irreducible_of_natDegree_ne_zero
Mathlib/RingTheory/Polynomial/Basic.lean
1,051
1,056
theorem linearIndependent_powers_iff_aeval (f : M →ₗ[R] M) (v : M) : (LinearIndependent R fun n : ℕ => (f ^ n) v) ↔ ∀ p : R[X], aeval f p v = 0 → p = 0 := by
rw [linearIndependent_iff] simp only [Finsupp.total_apply, aeval_endomorphism, forall_iff_forall_finsupp, Sum, support, coeff, ofFinsupp_eq_zero] exact Iff.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, Yury Kudryashov -/ import Mathlib.MeasureTheory.Constructions.BorelSpace.Order #align_import measure_theory.constructions.borel_space.basic from "leanprover-community/mathlib"@"9f55d0d4363ae59948c33864cbc52e0b12e0e8ce" /-! # Borel (measurable) spaces ℝ, ℝ≥0, ℝ≥0∞ ## Main statements * `borel_eq_generateFrom_Ixx_rat` (where Ixx is one of {Ioo, Ioi, Iio, Ici, Iic): the Borel sigma algebra on ℝ is generated by intervals with rational endpoints; * `isPiSystem_Ixx_rat` (where Ixx is one of {Ioo, Ioi, Iio, Ici, Iic): intervals with rational endpoints form a pi system on ℝ; * `measurable_real_toNNReal`, `measurable_coe_nnreal_real`, `measurable_coe_nnreal_ennreal`, `ENNReal.measurable_ofReal`, `ENNReal.measurable_toReal`: measurability of various coercions between ℝ, ℝ≥0, and ℝ≥0∞; * `Measurable.real_toNNReal`, `Measurable.coe_nnreal_real`, `Measurable.coe_nnreal_ennreal`, `Measurable.ennreal_ofReal`, `Measurable.ennreal_toNNReal`, `Measurable.ennreal_toReal`: measurability of functions composed with various coercions between ℝ, ℝ≥0, and ℝ≥0∞ (also similar results for a.e.-measurability); * `Measurable.ennreal*` : measurability of special cases for arithmetic operations on `ℝ≥0∞`. -/ open Set Filter MeasureTheory MeasurableSpace open scoped Classical Topology NNReal ENNReal MeasureTheory universe u v w x y variable {α β γ δ : Type*} {ι : Sort y} {s t u : Set α} namespace Real theorem borel_eq_generateFrom_Ioo_rat : borel ℝ = .generateFrom (⋃ (a : ℚ) (b : ℚ) (_ : a < b), {Ioo (a : ℝ) (b : ℝ)}) := isTopologicalBasis_Ioo_rat.borel_eq_generateFrom #align real.borel_eq_generate_from_Ioo_rat Real.borel_eq_generateFrom_Ioo_rat theorem borel_eq_generateFrom_Iio_rat : borel ℝ = .generateFrom (⋃ a : ℚ, {Iio (a : ℝ)}) := by rw [borel_eq_generateFrom_Iio] refine le_antisymm (generateFrom_le ?_) (generateFrom_mono <| iUnion_subset fun q ↦ singleton_subset_iff.mpr <| mem_range_self _) rintro _ ⟨a, rfl⟩ have : IsLUB (range ((↑) : ℚ → ℝ) ∩ Iio a) a := by simp [isLUB_iff_le_iff, mem_upperBounds, ← le_iff_forall_rat_lt_imp_le] rw [← this.biUnion_Iio_eq, ← image_univ, ← image_inter_preimage, univ_inter, biUnion_image] exact MeasurableSet.biUnion (to_countable _) fun b _ => GenerateMeasurable.basic (Iio (b : ℝ)) (by simp)
Mathlib/MeasureTheory/Constructions/BorelSpace/Real.lean
56
66
theorem borel_eq_generateFrom_Ioi_rat : borel ℝ = .generateFrom (⋃ a : ℚ, {Ioi (a : ℝ)}) := by
rw [borel_eq_generateFrom_Ioi] refine le_antisymm (generateFrom_le ?_) (generateFrom_mono <| iUnion_subset fun q ↦ singleton_subset_iff.mpr <| mem_range_self _) rintro _ ⟨a, rfl⟩ have : IsGLB (range ((↑) : ℚ → ℝ) ∩ Ioi a) a := by simp [isGLB_iff_le_iff, mem_lowerBounds, ← le_iff_forall_lt_rat_imp_le] rw [← this.biUnion_Ioi_eq, ← image_univ, ← image_inter_preimage, univ_inter, biUnion_image] exact MeasurableSet.biUnion (to_countable _) fun b _ => GenerateMeasurable.basic (Ioi (b : ℝ)) (by simp)
/- 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 -/ 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' #align measure_theory.integral_comp_mul_deriv_Ioi MeasureTheory.integral_comp_mul_deriv_Ioi /-- Substitution `y = x ^ p` in integrals over `Ioi 0` -/ theorem integral_comp_rpow_Ioi (g : ℝ → E) {p : ℝ} (hp : p ≠ 0) : (∫ x in Ioi 0, (|p| * x ^ (p - 1)) • g (x ^ p)) = ∫ y in Ioi 0, g y := by let S := Ioi (0 : ℝ) have a1 : ∀ x : ℝ, x ∈ S → HasDerivWithinAt (fun t : ℝ => t ^ p) (p * x ^ (p - 1)) S x := fun x hx => (hasDerivAt_rpow_const (Or.inl (mem_Ioi.mp hx).ne')).hasDerivWithinAt have a2 : InjOn (fun x : ℝ => x ^ p) S := by rcases lt_or_gt_of_ne hp with (h | h) · apply StrictAntiOn.injOn intro x hx y hy hxy rw [← inv_lt_inv (rpow_pos_of_pos hx p) (rpow_pos_of_pos hy p), ← rpow_neg (le_of_lt hx), ← rpow_neg (le_of_lt hy)] exact rpow_lt_rpow (le_of_lt hx) hxy (neg_pos.mpr h) exact StrictMonoOn.injOn fun x hx y _ hxy => rpow_lt_rpow (mem_Ioi.mp hx).le hxy h have a3 : (fun t : ℝ => t ^ p) '' S = S := by ext1 x; rw [mem_image]; constructor · rintro ⟨y, hy, rfl⟩; exact rpow_pos_of_pos hy p · intro hx; refine ⟨x ^ (1 / p), rpow_pos_of_pos hx _, ?_⟩ rw [← rpow_mul (le_of_lt hx), one_div_mul_cancel hp, rpow_one] have := integral_image_eq_integral_abs_deriv_smul measurableSet_Ioi a1 a2 g rw [a3] at this; rw [this] refine setIntegral_congr measurableSet_Ioi ?_ intro x hx; dsimp only rw [abs_mul, abs_of_nonneg (rpow_nonneg (le_of_lt hx) _)] #align measure_theory.integral_comp_rpow_Ioi MeasureTheory.integral_comp_rpow_Ioi theorem integral_comp_rpow_Ioi_of_pos {g : ℝ → E} {p : ℝ} (hp : 0 < p) : (∫ x in Ioi 0, (p * x ^ (p - 1)) • g (x ^ p)) = ∫ y in Ioi 0, g y := by convert integral_comp_rpow_Ioi g hp.ne' rw [abs_of_nonneg hp.le] #align measure_theory.integral_comp_rpow_Ioi_of_pos MeasureTheory.integral_comp_rpow_Ioi_of_pos theorem integral_comp_mul_left_Ioi (g : ℝ → E) (a : ℝ) {b : ℝ} (hb : 0 < b) : (∫ x in Ioi a, g (b * x)) = b⁻¹ • ∫ x in Ioi (b * a), g x := by have : ∀ c : ℝ, MeasurableSet (Ioi c) := fun c => measurableSet_Ioi rw [← integral_indicator (this a), ← integral_indicator (this (b * a)), ← abs_of_pos (inv_pos.mpr hb), ← Measure.integral_comp_mul_left] congr ext1 x rw [← indicator_comp_right, preimage_const_mul_Ioi _ hb, mul_div_cancel_left₀ _ hb.ne'] rfl #align measure_theory.integral_comp_mul_left_Ioi MeasureTheory.integral_comp_mul_left_Ioi theorem integral_comp_mul_right_Ioi (g : ℝ → E) (a : ℝ) {b : ℝ} (hb : 0 < b) : (∫ x in Ioi a, g (x * b)) = b⁻¹ • ∫ x in Ioi (a * b), g x := by simpa only [mul_comm] using integral_comp_mul_left_Ioi g a hb #align measure_theory.integral_comp_mul_right_Ioi MeasureTheory.integral_comp_mul_right_Ioi end IoiChangeVariables section IoiIntegrability open Real open scoped Interval variable {E : Type*} [NormedAddCommGroup E] /-- The substitution `y = x ^ p` in integrals over `Ioi 0` preserves integrability. -/ theorem integrableOn_Ioi_comp_rpow_iff [NormedSpace ℝ E] (f : ℝ → E) {p : ℝ} (hp : p ≠ 0) : IntegrableOn (fun x => (|p| * x ^ (p - 1)) • f (x ^ p)) (Ioi 0) ↔ IntegrableOn f (Ioi 0) := by let S := Ioi (0 : ℝ) have a1 : ∀ x : ℝ, x ∈ S → HasDerivWithinAt (fun t : ℝ => t ^ p) (p * x ^ (p - 1)) S x := fun x hx => (hasDerivAt_rpow_const (Or.inl (mem_Ioi.mp hx).ne')).hasDerivWithinAt have a2 : InjOn (fun x : ℝ => x ^ p) S := by rcases lt_or_gt_of_ne hp with (h | h) · apply StrictAntiOn.injOn intro x hx y hy hxy rw [← inv_lt_inv (rpow_pos_of_pos hx p) (rpow_pos_of_pos hy p), ← rpow_neg (le_of_lt hx), ← rpow_neg (le_of_lt hy)] exact rpow_lt_rpow (le_of_lt hx) hxy (neg_pos.mpr h) exact StrictMonoOn.injOn fun x hx y _hy hxy => rpow_lt_rpow (mem_Ioi.mp hx).le hxy h have a3 : (fun t : ℝ => t ^ p) '' S = S := by ext1 x; rw [mem_image]; constructor · rintro ⟨y, hy, rfl⟩; exact rpow_pos_of_pos hy p · intro hx; refine ⟨x ^ (1 / p), rpow_pos_of_pos hx _, ?_⟩ rw [← rpow_mul (le_of_lt hx), one_div_mul_cancel hp, rpow_one] have := integrableOn_image_iff_integrableOn_abs_deriv_smul measurableSet_Ioi a1 a2 f rw [a3] at this rw [this] refine integrableOn_congr_fun (fun x hx => ?_) measurableSet_Ioi simp_rw [abs_mul, abs_of_nonneg (rpow_nonneg (le_of_lt hx) _)] #align measure_theory.integrable_on_Ioi_comp_rpow_iff MeasureTheory.integrableOn_Ioi_comp_rpow_iff /-- The substitution `y = x ^ p` in integrals over `Ioi 0` preserves integrability (version without `|p|` factor) -/ theorem integrableOn_Ioi_comp_rpow_iff' [NormedSpace ℝ E] (f : ℝ → E) {p : ℝ} (hp : p ≠ 0) : IntegrableOn (fun x => x ^ (p - 1) • f (x ^ p)) (Ioi 0) ↔ IntegrableOn f (Ioi 0) := by simpa only [← integrableOn_Ioi_comp_rpow_iff f hp, mul_smul] using (integrable_smul_iff (abs_pos.mpr hp).ne' _).symm #align measure_theory.integrable_on_Ioi_comp_rpow_iff' MeasureTheory.integrableOn_Ioi_comp_rpow_iff'
Mathlib/MeasureTheory/Integral/IntegralEqImproper.lean
1,209
1,217
theorem integrableOn_Ioi_comp_mul_left_iff (f : ℝ → E) (c : ℝ) {a : ℝ} (ha : 0 < a) : IntegrableOn (fun x => f (a * x)) (Ioi c) ↔ IntegrableOn f (Ioi <| a * c) := by
rw [← integrable_indicator_iff (measurableSet_Ioi : MeasurableSet <| Ioi c)] rw [← integrable_indicator_iff (measurableSet_Ioi : MeasurableSet <| Ioi <| a * c)] convert integrable_comp_mul_left_iff ((Ioi (a * c)).indicator f) ha.ne' using 2 ext1 x rw [← indicator_comp_right, preimage_const_mul_Ioi _ ha, mul_comm a c, mul_div_cancel_right₀ _ ha.ne'] 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, Kyle Miller -/ import Mathlib.Data.Finset.Basic import Mathlib.Data.Finite.Basic import Mathlib.Data.Set.Functor import Mathlib.Data.Set.Lattice #align_import data.set.finite from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Finite sets This file defines predicates for finite and infinite sets and provides `Fintype` instances for many set constructions. It also proves basic facts about finite sets and gives ways to manipulate `Set.Finite` expressions. ## Main definitions * `Set.Finite : Set α → Prop` * `Set.Infinite : Set α → Prop` * `Set.toFinite` to prove `Set.Finite` for a `Set` from a `Finite` instance. * `Set.Finite.toFinset` to noncomputably produce a `Finset` from a `Set.Finite` proof. (See `Set.toFinset` for a computable version.) ## Implementation A finite set is defined to be a set whose coercion to a type has a `Finite` instance. There are two components to finiteness constructions. The first is `Fintype` instances for each construction. This gives a way to actually compute a `Finset` that represents the set, and these may be accessed using `set.toFinset`. This gets the `Finset` in the correct form, since otherwise `Finset.univ : Finset s` is a `Finset` for the subtype for `s`. The second component is "constructors" for `Set.Finite` that give proofs that `Fintype` instances exist classically given other `Set.Finite` proofs. Unlike the `Fintype` instances, these *do not* use any decidability instances since they do not compute anything. ## Tags finite sets -/ assert_not_exists OrderedRing assert_not_exists MonoidWithZero open Set Function universe u v w x variable {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x} namespace Set /-- A set is finite if the corresponding `Subtype` is finite, i.e., if there exists a natural `n : ℕ` and an equivalence `s ≃ Fin n`. -/ protected def Finite (s : Set α) : Prop := Finite s #align set.finite Set.Finite -- The `protected` attribute does not take effect within the same namespace block. end Set namespace Set theorem finite_def {s : Set α} : s.Finite ↔ Nonempty (Fintype s) := finite_iff_nonempty_fintype s #align set.finite_def Set.finite_def protected alias ⟨Finite.nonempty_fintype, _⟩ := finite_def #align set.finite.nonempty_fintype Set.Finite.nonempty_fintype theorem finite_coe_iff {s : Set α} : Finite s ↔ s.Finite := .rfl #align set.finite_coe_iff Set.finite_coe_iff /-- Constructor for `Set.Finite` using a `Finite` instance. -/ theorem toFinite (s : Set α) [Finite s] : s.Finite := ‹_› #align set.to_finite Set.toFinite /-- Construct a `Finite` instance for a `Set` from a `Finset` with the same elements. -/ protected theorem Finite.ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : p.Finite := have := Fintype.ofFinset s H; p.toFinite #align set.finite.of_finset Set.Finite.ofFinset /-- Projection of `Set.Finite` to its `Finite` instance. This is intended to be used with dot notation. See also `Set.Finite.Fintype` and `Set.Finite.nonempty_fintype`. -/ protected theorem Finite.to_subtype {s : Set α} (h : s.Finite) : Finite s := h #align set.finite.to_subtype Set.Finite.to_subtype /-- A finite set coerced to a type is a `Fintype`. This is the `Fintype` projection for a `Set.Finite`. Note that because `Finite` isn't a typeclass, this definition will not fire if it is made into an instance -/ protected noncomputable def Finite.fintype {s : Set α} (h : s.Finite) : Fintype s := h.nonempty_fintype.some #align set.finite.fintype Set.Finite.fintype /-- Using choice, get the `Finset` that represents this `Set`. -/ protected noncomputable def Finite.toFinset {s : Set α} (h : s.Finite) : Finset α := @Set.toFinset _ _ h.fintype #align set.finite.to_finset Set.Finite.toFinset theorem Finite.toFinset_eq_toFinset {s : Set α} [Fintype s] (h : s.Finite) : h.toFinset = s.toFinset := by -- Porting note: was `rw [Finite.toFinset]; congr` -- in Lean 4, a goal is left after `congr` have : h.fintype = ‹_› := Subsingleton.elim _ _ rw [Finite.toFinset, this] #align set.finite.to_finset_eq_to_finset Set.Finite.toFinset_eq_toFinset @[simp] theorem toFinite_toFinset (s : Set α) [Fintype s] : s.toFinite.toFinset = s.toFinset := s.toFinite.toFinset_eq_toFinset #align set.to_finite_to_finset Set.toFinite_toFinset theorem Finite.exists_finset {s : Set α} (h : s.Finite) : ∃ s' : Finset α, ∀ a : α, a ∈ s' ↔ a ∈ s := by cases h.nonempty_fintype exact ⟨s.toFinset, fun _ => mem_toFinset⟩ #align set.finite.exists_finset Set.Finite.exists_finset theorem Finite.exists_finset_coe {s : Set α} (h : s.Finite) : ∃ s' : Finset α, ↑s' = s := by cases h.nonempty_fintype exact ⟨s.toFinset, s.coe_toFinset⟩ #align set.finite.exists_finset_coe Set.Finite.exists_finset_coe /-- Finite sets can be lifted to finsets. -/ instance : CanLift (Set α) (Finset α) (↑) Set.Finite where prf _ hs := hs.exists_finset_coe /-- A set is infinite if it is not finite. This is protected so that it does not conflict with global `Infinite`. -/ protected def Infinite (s : Set α) : Prop := ¬s.Finite #align set.infinite Set.Infinite @[simp] theorem not_infinite {s : Set α} : ¬s.Infinite ↔ s.Finite := not_not #align set.not_infinite Set.not_infinite alias ⟨_, Finite.not_infinite⟩ := not_infinite #align set.finite.not_infinite Set.Finite.not_infinite attribute [simp] Finite.not_infinite /-- See also `finite_or_infinite`, `fintypeOrInfinite`. -/ protected theorem finite_or_infinite (s : Set α) : s.Finite ∨ s.Infinite := em _ #align set.finite_or_infinite Set.finite_or_infinite protected theorem infinite_or_finite (s : Set α) : s.Infinite ∨ s.Finite := em' _ #align set.infinite_or_finite Set.infinite_or_finite /-! ### Basic properties of `Set.Finite.toFinset` -/ namespace Finite variable {s t : Set α} {a : α} (hs : s.Finite) {ht : t.Finite} @[simp] protected theorem mem_toFinset : a ∈ hs.toFinset ↔ a ∈ s := @mem_toFinset _ _ hs.fintype _ #align set.finite.mem_to_finset Set.Finite.mem_toFinset @[simp] protected theorem coe_toFinset : (hs.toFinset : Set α) = s := @coe_toFinset _ _ hs.fintype #align set.finite.coe_to_finset Set.Finite.coe_toFinset @[simp] protected theorem toFinset_nonempty : hs.toFinset.Nonempty ↔ s.Nonempty := by rw [← Finset.coe_nonempty, Finite.coe_toFinset] #align set.finite.to_finset_nonempty Set.Finite.toFinset_nonempty /-- Note that this is an equality of types not holding definitionally. Use wisely. -/ theorem coeSort_toFinset : ↥hs.toFinset = ↥s := by rw [← Finset.coe_sort_coe _, hs.coe_toFinset] #align set.finite.coe_sort_to_finset Set.Finite.coeSort_toFinset /-- The identity map, bundled as an equivalence between the subtypes of `s : Set α` and of `h.toFinset : Finset α`, where `h` is a proof of finiteness of `s`. -/ @[simps!] def subtypeEquivToFinset : {x // x ∈ s} ≃ {x // x ∈ hs.toFinset} := (Equiv.refl α).subtypeEquiv fun _ ↦ hs.mem_toFinset.symm variable {hs} @[simp] protected theorem toFinset_inj : hs.toFinset = ht.toFinset ↔ s = t := @toFinset_inj _ _ _ hs.fintype ht.fintype #align set.finite.to_finset_inj Set.Finite.toFinset_inj @[simp] theorem toFinset_subset {t : Finset α} : hs.toFinset ⊆ t ↔ s ⊆ t := by rw [← Finset.coe_subset, Finite.coe_toFinset] #align set.finite.to_finset_subset Set.Finite.toFinset_subset @[simp] theorem toFinset_ssubset {t : Finset α} : hs.toFinset ⊂ t ↔ s ⊂ t := by rw [← Finset.coe_ssubset, Finite.coe_toFinset] #align set.finite.to_finset_ssubset Set.Finite.toFinset_ssubset @[simp] theorem subset_toFinset {s : Finset α} : s ⊆ ht.toFinset ↔ ↑s ⊆ t := by rw [← Finset.coe_subset, Finite.coe_toFinset] #align set.finite.subset_to_finset Set.Finite.subset_toFinset @[simp] theorem ssubset_toFinset {s : Finset α} : s ⊂ ht.toFinset ↔ ↑s ⊂ t := by rw [← Finset.coe_ssubset, Finite.coe_toFinset] #align set.finite.ssubset_to_finset Set.Finite.ssubset_toFinset @[mono] protected theorem toFinset_subset_toFinset : hs.toFinset ⊆ ht.toFinset ↔ s ⊆ t := by simp only [← Finset.coe_subset, Finite.coe_toFinset] #align set.finite.to_finset_subset_to_finset Set.Finite.toFinset_subset_toFinset @[mono] protected theorem toFinset_ssubset_toFinset : hs.toFinset ⊂ ht.toFinset ↔ s ⊂ t := by simp only [← Finset.coe_ssubset, Finite.coe_toFinset] #align set.finite.to_finset_ssubset_to_finset Set.Finite.toFinset_ssubset_toFinset alias ⟨_, toFinset_mono⟩ := Finite.toFinset_subset_toFinset #align set.finite.to_finset_mono Set.Finite.toFinset_mono alias ⟨_, toFinset_strictMono⟩ := Finite.toFinset_ssubset_toFinset #align set.finite.to_finset_strict_mono Set.Finite.toFinset_strictMono -- Porting note: attribute [protected] doesn't work -- attribute [protected] toFinset_mono toFinset_strictMono -- Porting note: `simp` can simplify LHS but then it simplifies something -- in the generated `Fintype {x | p x}` instance and fails to apply `Set.toFinset_setOf` @[simp high] protected theorem toFinset_setOf [Fintype α] (p : α → Prop) [DecidablePred p] (h : { x | p x }.Finite) : h.toFinset = Finset.univ.filter p := by ext -- Porting note: `simp` doesn't use the `simp` lemma `Set.toFinset_setOf` without the `_` simp [Set.toFinset_setOf _] #align set.finite.to_finset_set_of Set.Finite.toFinset_setOf @[simp] nonrec theorem disjoint_toFinset {hs : s.Finite} {ht : t.Finite} : Disjoint hs.toFinset ht.toFinset ↔ Disjoint s t := @disjoint_toFinset _ _ _ hs.fintype ht.fintype #align set.finite.disjoint_to_finset Set.Finite.disjoint_toFinset protected theorem toFinset_inter [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s ∩ t).Finite) : h.toFinset = hs.toFinset ∩ ht.toFinset := by ext simp #align set.finite.to_finset_inter Set.Finite.toFinset_inter protected theorem toFinset_union [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s ∪ t).Finite) : h.toFinset = hs.toFinset ∪ ht.toFinset := by ext simp #align set.finite.to_finset_union Set.Finite.toFinset_union protected theorem toFinset_diff [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s \ t).Finite) : h.toFinset = hs.toFinset \ ht.toFinset := by ext simp #align set.finite.to_finset_diff Set.Finite.toFinset_diff open scoped symmDiff in protected theorem toFinset_symmDiff [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s ∆ t).Finite) : h.toFinset = hs.toFinset ∆ ht.toFinset := by ext simp [mem_symmDiff, Finset.mem_symmDiff] #align set.finite.to_finset_symm_diff Set.Finite.toFinset_symmDiff protected theorem toFinset_compl [DecidableEq α] [Fintype α] (hs : s.Finite) (h : sᶜ.Finite) : h.toFinset = hs.toFinsetᶜ := by ext simp #align set.finite.to_finset_compl Set.Finite.toFinset_compl protected theorem toFinset_univ [Fintype α] (h : (Set.univ : Set α).Finite) : h.toFinset = Finset.univ := by simp #align set.finite.to_finset_univ Set.Finite.toFinset_univ @[simp] protected theorem toFinset_eq_empty {h : s.Finite} : h.toFinset = ∅ ↔ s = ∅ := @toFinset_eq_empty _ _ h.fintype #align set.finite.to_finset_eq_empty Set.Finite.toFinset_eq_empty protected theorem toFinset_empty (h : (∅ : Set α).Finite) : h.toFinset = ∅ := by simp #align set.finite.to_finset_empty Set.Finite.toFinset_empty @[simp] protected theorem toFinset_eq_univ [Fintype α] {h : s.Finite} : h.toFinset = Finset.univ ↔ s = univ := @toFinset_eq_univ _ _ _ h.fintype #align set.finite.to_finset_eq_univ Set.Finite.toFinset_eq_univ protected theorem toFinset_image [DecidableEq β] (f : α → β) (hs : s.Finite) (h : (f '' s).Finite) : h.toFinset = hs.toFinset.image f := by ext simp #align set.finite.to_finset_image Set.Finite.toFinset_image -- Porting note (#10618): now `simp` can prove it but it needs the `fintypeRange` instance -- from the next section protected theorem toFinset_range [DecidableEq α] [Fintype β] (f : β → α) (h : (range f).Finite) : h.toFinset = Finset.univ.image f := by ext simp #align set.finite.to_finset_range Set.Finite.toFinset_range end Finite /-! ### Fintype instances Every instance here should have a corresponding `Set.Finite` constructor in the next section. -/ section FintypeInstances instance fintypeUniv [Fintype α] : Fintype (@univ α) := Fintype.ofEquiv α (Equiv.Set.univ α).symm #align set.fintype_univ Set.fintypeUniv /-- If `(Set.univ : Set α)` is finite then `α` is a finite type. -/ noncomputable def fintypeOfFiniteUniv (H : (univ (α := α)).Finite) : Fintype α := @Fintype.ofEquiv _ (univ : Set α) H.fintype (Equiv.Set.univ _) #align set.fintype_of_finite_univ Set.fintypeOfFiniteUniv instance fintypeUnion [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] : Fintype (s ∪ t : Set α) := Fintype.ofFinset (s.toFinset ∪ t.toFinset) <| by simp #align set.fintype_union Set.fintypeUnion instance fintypeSep (s : Set α) (p : α → Prop) [Fintype s] [DecidablePred p] : Fintype ({ a ∈ s | p a } : Set α) := Fintype.ofFinset (s.toFinset.filter p) <| by simp #align set.fintype_sep Set.fintypeSep instance fintypeInter (s t : Set α) [DecidableEq α] [Fintype s] [Fintype t] : Fintype (s ∩ t : Set α) := Fintype.ofFinset (s.toFinset ∩ t.toFinset) <| by simp #align set.fintype_inter Set.fintypeInter /-- A `Fintype` instance for set intersection where the left set has a `Fintype` instance. -/ instance fintypeInterOfLeft (s t : Set α) [Fintype s] [DecidablePred (· ∈ t)] : Fintype (s ∩ t : Set α) := Fintype.ofFinset (s.toFinset.filter (· ∈ t)) <| by simp #align set.fintype_inter_of_left Set.fintypeInterOfLeft /-- A `Fintype` instance for set intersection where the right set has a `Fintype` instance. -/ instance fintypeInterOfRight (s t : Set α) [Fintype t] [DecidablePred (· ∈ s)] : Fintype (s ∩ t : Set α) := Fintype.ofFinset (t.toFinset.filter (· ∈ s)) <| by simp [and_comm] #align set.fintype_inter_of_right Set.fintypeInterOfRight /-- A `Fintype` structure on a set defines a `Fintype` structure on its subset. -/ def fintypeSubset (s : Set α) {t : Set α} [Fintype s] [DecidablePred (· ∈ t)] (h : t ⊆ s) : Fintype t := by rw [← inter_eq_self_of_subset_right h] apply Set.fintypeInterOfLeft #align set.fintype_subset Set.fintypeSubset instance fintypeDiff [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] : Fintype (s \ t : Set α) := Fintype.ofFinset (s.toFinset \ t.toFinset) <| by simp #align set.fintype_diff Set.fintypeDiff instance fintypeDiffLeft (s t : Set α) [Fintype s] [DecidablePred (· ∈ t)] : Fintype (s \ t : Set α) := Set.fintypeSep s (· ∈ tᶜ) #align set.fintype_diff_left Set.fintypeDiffLeft instance fintypeiUnion [DecidableEq α] [Fintype (PLift ι)] (f : ι → Set α) [∀ i, Fintype (f i)] : Fintype (⋃ i, f i) := Fintype.ofFinset (Finset.univ.biUnion fun i : PLift ι => (f i.down).toFinset) <| by simp #align set.fintype_Union Set.fintypeiUnion instance fintypesUnion [DecidableEq α] {s : Set (Set α)} [Fintype s] [H : ∀ t : s, Fintype (t : Set α)] : Fintype (⋃₀ s) := by rw [sUnion_eq_iUnion] exact @Set.fintypeiUnion _ _ _ _ _ H #align set.fintype_sUnion Set.fintypesUnion /-- A union of sets with `Fintype` structure over a set with `Fintype` structure has a `Fintype` structure. -/ def fintypeBiUnion [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α) (H : ∀ i ∈ s, Fintype (t i)) : Fintype (⋃ x ∈ s, t x) := haveI : ∀ i : toFinset s, Fintype (t i) := fun i => H i (mem_toFinset.1 i.2) Fintype.ofFinset (s.toFinset.attach.biUnion fun x => (t x).toFinset) fun x => by simp #align set.fintype_bUnion Set.fintypeBiUnion instance fintypeBiUnion' [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α) [∀ i, Fintype (t i)] : Fintype (⋃ x ∈ s, t x) := Fintype.ofFinset (s.toFinset.biUnion fun x => (t x).toFinset) <| by simp #align set.fintype_bUnion' Set.fintypeBiUnion' section monad attribute [local instance] Set.monad /-- If `s : Set α` is a set with `Fintype` instance and `f : α → Set β` is a function such that each `f a`, `a ∈ s`, has a `Fintype` structure, then `s >>= f` has a `Fintype` structure. -/ def fintypeBind {α β} [DecidableEq β] (s : Set α) [Fintype s] (f : α → Set β) (H : ∀ a ∈ s, Fintype (f a)) : Fintype (s >>= f) := Set.fintypeBiUnion s f H #align set.fintype_bind Set.fintypeBind instance fintypeBind' {α β} [DecidableEq β] (s : Set α) [Fintype s] (f : α → Set β) [∀ a, Fintype (f a)] : Fintype (s >>= f) := Set.fintypeBiUnion' s f #align set.fintype_bind' Set.fintypeBind' end monad instance fintypeEmpty : Fintype (∅ : Set α) := Fintype.ofFinset ∅ <| by simp #align set.fintype_empty Set.fintypeEmpty instance fintypeSingleton (a : α) : Fintype ({a} : Set α) := Fintype.ofFinset {a} <| by simp #align set.fintype_singleton Set.fintypeSingleton instance fintypePure : ∀ a : α, Fintype (pure a : Set α) := Set.fintypeSingleton #align set.fintype_pure Set.fintypePure /-- A `Fintype` instance for inserting an element into a `Set` using the corresponding `insert` function on `Finset`. This requires `DecidableEq α`. There is also `Set.fintypeInsert'` when `a ∈ s` is decidable. -/ instance fintypeInsert (a : α) (s : Set α) [DecidableEq α] [Fintype s] : Fintype (insert a s : Set α) := Fintype.ofFinset (insert a s.toFinset) <| by simp #align set.fintype_insert Set.fintypeInsert /-- A `Fintype` structure on `insert a s` when inserting a new element. -/ def fintypeInsertOfNotMem {a : α} (s : Set α) [Fintype s] (h : a ∉ s) : Fintype (insert a s : Set α) := Fintype.ofFinset ⟨a ::ₘ s.toFinset.1, s.toFinset.nodup.cons (by simp [h])⟩ <| by simp #align set.fintype_insert_of_not_mem Set.fintypeInsertOfNotMem /-- A `Fintype` structure on `insert a s` when inserting a pre-existing element. -/ def fintypeInsertOfMem {a : α} (s : Set α) [Fintype s] (h : a ∈ s) : Fintype (insert a s : Set α) := Fintype.ofFinset s.toFinset <| by simp [h] #align set.fintype_insert_of_mem Set.fintypeInsertOfMem /-- The `Set.fintypeInsert` instance requires decidable equality, but when `a ∈ s` is decidable for this particular `a` we can still get a `Fintype` instance by using `Set.fintypeInsertOfNotMem` or `Set.fintypeInsertOfMem`. This instance pre-dates `Set.fintypeInsert`, and it is less efficient. When `Set.decidableMemOfFintype` is made a local instance, then this instance would override `Set.fintypeInsert` if not for the fact that its priority has been adjusted. See Note [lower instance priority]. -/ instance (priority := 100) fintypeInsert' (a : α) (s : Set α) [Decidable <| a ∈ s] [Fintype s] : Fintype (insert a s : Set α) := if h : a ∈ s then fintypeInsertOfMem s h else fintypeInsertOfNotMem s h #align set.fintype_insert' Set.fintypeInsert' instance fintypeImage [DecidableEq β] (s : Set α) (f : α → β) [Fintype s] : Fintype (f '' s) := Fintype.ofFinset (s.toFinset.image f) <| by simp #align set.fintype_image Set.fintypeImage /-- If a function `f` has a partial inverse and sends a set `s` to a set with `[Fintype]` instance, then `s` has a `Fintype` structure as well. -/ def fintypeOfFintypeImage (s : Set α) {f : α → β} {g} (I : IsPartialInv f g) [Fintype (f '' s)] : Fintype s := Fintype.ofFinset ⟨_, (f '' s).toFinset.2.filterMap g <| injective_of_isPartialInv_right I⟩ fun a => by suffices (∃ b x, f x = b ∧ g b = some a ∧ x ∈ s) ↔ a ∈ s by simpa [exists_and_left.symm, and_comm, and_left_comm, and_assoc] rw [exists_swap] suffices (∃ x, x ∈ s ∧ g (f x) = some a) ↔ a ∈ s by simpa [and_comm, and_left_comm, and_assoc] simp [I _, (injective_of_isPartialInv I).eq_iff] #align set.fintype_of_fintype_image Set.fintypeOfFintypeImage instance fintypeRange [DecidableEq α] (f : ι → α) [Fintype (PLift ι)] : Fintype (range f) := Fintype.ofFinset (Finset.univ.image <| f ∘ PLift.down) <| by simp #align set.fintype_range Set.fintypeRange instance fintypeMap {α β} [DecidableEq β] : ∀ (s : Set α) (f : α → β) [Fintype s], Fintype (f <$> s) := Set.fintypeImage #align set.fintype_map Set.fintypeMap instance fintypeLTNat (n : ℕ) : Fintype { i | i < n } := Fintype.ofFinset (Finset.range n) <| by simp #align set.fintype_lt_nat Set.fintypeLTNat instance fintypeLENat (n : ℕ) : Fintype { i | i ≤ n } := by simpa [Nat.lt_succ_iff] using Set.fintypeLTNat (n + 1) #align set.fintype_le_nat Set.fintypeLENat /-- This is not an instance so that it does not conflict with the one in `Mathlib/Order/LocallyFinite.lean`. -/ def Nat.fintypeIio (n : ℕ) : Fintype (Iio n) := Set.fintypeLTNat n #align set.nat.fintype_Iio Set.Nat.fintypeIio instance fintypeProd (s : Set α) (t : Set β) [Fintype s] [Fintype t] : Fintype (s ×ˢ t : Set (α × β)) := Fintype.ofFinset (s.toFinset ×ˢ t.toFinset) <| by simp #align set.fintype_prod Set.fintypeProd instance fintypeOffDiag [DecidableEq α] (s : Set α) [Fintype s] : Fintype s.offDiag := Fintype.ofFinset s.toFinset.offDiag <| by simp #align set.fintype_off_diag Set.fintypeOffDiag /-- `image2 f s t` is `Fintype` if `s` and `t` are. -/ instance fintypeImage2 [DecidableEq γ] (f : α → β → γ) (s : Set α) (t : Set β) [hs : Fintype s] [ht : Fintype t] : Fintype (image2 f s t : Set γ) := by rw [← image_prod] apply Set.fintypeImage #align set.fintype_image2 Set.fintypeImage2 instance fintypeSeq [DecidableEq β] (f : Set (α → β)) (s : Set α) [Fintype f] [Fintype s] : Fintype (f.seq s) := by rw [seq_def] apply Set.fintypeBiUnion' #align set.fintype_seq Set.fintypeSeq instance fintypeSeq' {α β : Type u} [DecidableEq β] (f : Set (α → β)) (s : Set α) [Fintype f] [Fintype s] : Fintype (f <*> s) := Set.fintypeSeq f s #align set.fintype_seq' Set.fintypeSeq' instance fintypeMemFinset (s : Finset α) : Fintype { a | a ∈ s } := Finset.fintypeCoeSort s #align set.fintype_mem_finset Set.fintypeMemFinset end FintypeInstances end Set theorem Equiv.set_finite_iff {s : Set α} {t : Set β} (hst : s ≃ t) : s.Finite ↔ t.Finite := by simp_rw [← Set.finite_coe_iff, hst.finite_iff] #align equiv.set_finite_iff Equiv.set_finite_iff /-! ### Finset -/ namespace Finset /-- Gives a `Set.Finite` for the `Finset` coerced to a `Set`. This is a wrapper around `Set.toFinite`. -/ @[simp] theorem finite_toSet (s : Finset α) : (s : Set α).Finite := Set.toFinite _ #align finset.finite_to_set Finset.finite_toSet -- Porting note (#10618): was @[simp], now `simp` can prove it theorem finite_toSet_toFinset (s : Finset α) : s.finite_toSet.toFinset = s := by rw [toFinite_toFinset, toFinset_coe] #align finset.finite_to_set_to_finset Finset.finite_toSet_toFinset end Finset namespace Multiset @[simp] theorem finite_toSet (s : Multiset α) : { x | x ∈ s }.Finite := by classical simpa only [← Multiset.mem_toFinset] using s.toFinset.finite_toSet #align multiset.finite_to_set Multiset.finite_toSet @[simp] theorem finite_toSet_toFinset [DecidableEq α] (s : Multiset α) : s.finite_toSet.toFinset = s.toFinset := by ext x simp #align multiset.finite_to_set_to_finset Multiset.finite_toSet_toFinset end Multiset @[simp] theorem List.finite_toSet (l : List α) : { x | x ∈ l }.Finite := (show Multiset α from ⟦l⟧).finite_toSet #align list.finite_to_set List.finite_toSet /-! ### Finite instances There is seemingly some overlap between the following instances and the `Fintype` instances in `Data.Set.Finite`. While every `Fintype` instance gives a `Finite` instance, those instances that depend on `Fintype` or `Decidable` instances need an additional `Finite` instance to be able to generally apply. Some set instances do not appear here since they are consequences of others, for example `Subtype.Finite` for subsets of a finite type. -/ namespace Finite.Set open scoped Classical example {s : Set α} [Finite α] : Finite s := inferInstance example : Finite (∅ : Set α) := inferInstance example (a : α) : Finite ({a} : Set α) := inferInstance instance finite_union (s t : Set α) [Finite s] [Finite t] : Finite (s ∪ t : Set α) := by cases nonempty_fintype s cases nonempty_fintype t infer_instance #align finite.set.finite_union Finite.Set.finite_union instance finite_sep (s : Set α) (p : α → Prop) [Finite s] : Finite ({ a ∈ s | p a } : Set α) := by cases nonempty_fintype s infer_instance #align finite.set.finite_sep Finite.Set.finite_sep protected theorem subset (s : Set α) {t : Set α} [Finite s] (h : t ⊆ s) : Finite t := by rw [← sep_eq_of_subset h] infer_instance #align finite.set.subset Finite.Set.subset instance finite_inter_of_right (s t : Set α) [Finite t] : Finite (s ∩ t : Set α) := Finite.Set.subset t inter_subset_right #align finite.set.finite_inter_of_right Finite.Set.finite_inter_of_right instance finite_inter_of_left (s t : Set α) [Finite s] : Finite (s ∩ t : Set α) := Finite.Set.subset s inter_subset_left #align finite.set.finite_inter_of_left Finite.Set.finite_inter_of_left instance finite_diff (s t : Set α) [Finite s] : Finite (s \ t : Set α) := Finite.Set.subset s diff_subset #align finite.set.finite_diff Finite.Set.finite_diff instance finite_range (f : ι → α) [Finite ι] : Finite (range f) := by haveI := Fintype.ofFinite (PLift ι) infer_instance #align finite.set.finite_range Finite.Set.finite_range instance finite_iUnion [Finite ι] (f : ι → Set α) [∀ i, Finite (f i)] : Finite (⋃ i, f i) := by rw [iUnion_eq_range_psigma] apply Set.finite_range #align finite.set.finite_Union Finite.Set.finite_iUnion instance finite_sUnion {s : Set (Set α)} [Finite s] [H : ∀ t : s, Finite (t : Set α)] : Finite (⋃₀ s) := by rw [sUnion_eq_iUnion] exact @Finite.Set.finite_iUnion _ _ _ _ H #align finite.set.finite_sUnion Finite.Set.finite_sUnion theorem finite_biUnion {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α) (H : ∀ i ∈ s, Finite (t i)) : Finite (⋃ x ∈ s, t x) := by rw [biUnion_eq_iUnion] haveI : ∀ i : s, Finite (t i) := fun i => H i i.property infer_instance #align finite.set.finite_bUnion Finite.Set.finite_biUnion instance finite_biUnion' {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α) [∀ i, Finite (t i)] : Finite (⋃ x ∈ s, t x) := finite_biUnion s t fun _ _ => inferInstance #align finite.set.finite_bUnion' Finite.Set.finite_biUnion' /-- Example: `Finite (⋃ (i < n), f i)` where `f : ℕ → Set α` and `[∀ i, Finite (f i)]` (when given instances from `Order.Interval.Finset.Nat`). -/ instance finite_biUnion'' {ι : Type*} (p : ι → Prop) [h : Finite { x | p x }] (t : ι → Set α) [∀ i, Finite (t i)] : Finite (⋃ (x) (_ : p x), t x) := @Finite.Set.finite_biUnion' _ _ (setOf p) h t _ #align finite.set.finite_bUnion'' Finite.Set.finite_biUnion'' instance finite_iInter {ι : Sort*} [Nonempty ι] (t : ι → Set α) [∀ i, Finite (t i)] : Finite (⋂ i, t i) := Finite.Set.subset (t <| Classical.arbitrary ι) (iInter_subset _ _) #align finite.set.finite_Inter Finite.Set.finite_iInter instance finite_insert (a : α) (s : Set α) [Finite s] : Finite (insert a s : Set α) := Finite.Set.finite_union {a} s #align finite.set.finite_insert Finite.Set.finite_insert instance finite_image (s : Set α) (f : α → β) [Finite s] : Finite (f '' s) := by cases nonempty_fintype s infer_instance #align finite.set.finite_image Finite.Set.finite_image instance finite_replacement [Finite α] (f : α → β) : Finite {f x | x : α} := Finite.Set.finite_range f #align finite.set.finite_replacement Finite.Set.finite_replacement instance finite_prod (s : Set α) (t : Set β) [Finite s] [Finite t] : Finite (s ×ˢ t : Set (α × β)) := Finite.of_equiv _ (Equiv.Set.prod s t).symm #align finite.set.finite_prod Finite.Set.finite_prod instance finite_image2 (f : α → β → γ) (s : Set α) (t : Set β) [Finite s] [Finite t] : Finite (image2 f s t : Set γ) := by rw [← image_prod] infer_instance #align finite.set.finite_image2 Finite.Set.finite_image2 instance finite_seq (f : Set (α → β)) (s : Set α) [Finite f] [Finite s] : Finite (f.seq s) := by rw [seq_def] infer_instance #align finite.set.finite_seq Finite.Set.finite_seq end Finite.Set namespace Set /-! ### Constructors for `Set.Finite` Every constructor here should have a corresponding `Fintype` instance in the previous section (or in the `Fintype` module). The implementation of these constructors ideally should be no more than `Set.toFinite`, after possibly setting up some `Fintype` and classical `Decidable` instances. -/ section SetFiniteConstructors @[nontriviality] theorem Finite.of_subsingleton [Subsingleton α] (s : Set α) : s.Finite := s.toFinite #align set.finite.of_subsingleton Set.Finite.of_subsingleton theorem finite_univ [Finite α] : (@univ α).Finite := Set.toFinite _ #align set.finite_univ Set.finite_univ theorem finite_univ_iff : (@univ α).Finite ↔ Finite α := (Equiv.Set.univ α).finite_iff #align set.finite_univ_iff Set.finite_univ_iff alias ⟨_root_.Finite.of_finite_univ, _⟩ := finite_univ_iff #align finite.of_finite_univ Finite.of_finite_univ theorem Finite.subset {s : Set α} (hs : s.Finite) {t : Set α} (ht : t ⊆ s) : t.Finite := by have := hs.to_subtype exact Finite.Set.subset _ ht #align set.finite.subset Set.Finite.subset theorem Finite.union {s t : Set α} (hs : s.Finite) (ht : t.Finite) : (s ∪ t).Finite := by rw [Set.Finite] at hs ht apply toFinite #align set.finite.union Set.Finite.union theorem Finite.finite_of_compl {s : Set α} (hs : s.Finite) (hsc : sᶜ.Finite) : Finite α := by rw [← finite_univ_iff, ← union_compl_self s] exact hs.union hsc #align set.finite.finite_of_compl Set.Finite.finite_of_compl theorem Finite.sup {s t : Set α} : s.Finite → t.Finite → (s ⊔ t).Finite := Finite.union #align set.finite.sup Set.Finite.sup theorem Finite.sep {s : Set α} (hs : s.Finite) (p : α → Prop) : { a ∈ s | p a }.Finite := hs.subset <| sep_subset _ _ #align set.finite.sep Set.Finite.sep theorem Finite.inter_of_left {s : Set α} (hs : s.Finite) (t : Set α) : (s ∩ t).Finite := hs.subset inter_subset_left #align set.finite.inter_of_left Set.Finite.inter_of_left theorem Finite.inter_of_right {s : Set α} (hs : s.Finite) (t : Set α) : (t ∩ s).Finite := hs.subset inter_subset_right #align set.finite.inter_of_right Set.Finite.inter_of_right theorem Finite.inf_of_left {s : Set α} (h : s.Finite) (t : Set α) : (s ⊓ t).Finite := h.inter_of_left t #align set.finite.inf_of_left Set.Finite.inf_of_left theorem Finite.inf_of_right {s : Set α} (h : s.Finite) (t : Set α) : (t ⊓ s).Finite := h.inter_of_right t #align set.finite.inf_of_right Set.Finite.inf_of_right protected lemma Infinite.mono {s t : Set α} (h : s ⊆ t) : s.Infinite → t.Infinite := mt fun ht ↦ ht.subset h #align set.infinite.mono Set.Infinite.mono theorem Finite.diff {s : Set α} (hs : s.Finite) (t : Set α) : (s \ t).Finite := hs.subset diff_subset #align set.finite.diff Set.Finite.diff theorem Finite.of_diff {s t : Set α} (hd : (s \ t).Finite) (ht : t.Finite) : s.Finite := (hd.union ht).subset <| subset_diff_union _ _ #align set.finite.of_diff Set.Finite.of_diff theorem finite_iUnion [Finite ι] {f : ι → Set α} (H : ∀ i, (f i).Finite) : (⋃ i, f i).Finite := haveI := fun i => (H i).to_subtype toFinite _ #align set.finite_Union Set.finite_iUnion /-- Dependent version of `Finite.biUnion`. -/ theorem Finite.biUnion' {ι} {s : Set ι} (hs : s.Finite) {t : ∀ i ∈ s, Set α} (ht : ∀ i (hi : i ∈ s), (t i hi).Finite) : (⋃ i ∈ s, t i ‹_›).Finite := by have := hs.to_subtype rw [biUnion_eq_iUnion] apply finite_iUnion fun i : s => ht i.1 i.2 #align set.finite.bUnion' Set.Finite.biUnion' theorem Finite.biUnion {ι} {s : Set ι} (hs : s.Finite) {t : ι → Set α} (ht : ∀ i ∈ s, (t i).Finite) : (⋃ i ∈ s, t i).Finite := hs.biUnion' ht #align set.finite.bUnion Set.Finite.biUnion theorem Finite.sUnion {s : Set (Set α)} (hs : s.Finite) (H : ∀ t ∈ s, Set.Finite t) : (⋃₀ s).Finite := by simpa only [sUnion_eq_biUnion] using hs.biUnion H #align set.finite.sUnion Set.Finite.sUnion theorem Finite.sInter {α : Type*} {s : Set (Set α)} {t : Set α} (ht : t ∈ s) (hf : t.Finite) : (⋂₀ s).Finite := hf.subset (sInter_subset_of_mem ht) #align set.finite.sInter Set.Finite.sInter /-- If sets `s i` are finite for all `i` from a finite set `t` and are empty for `i ∉ t`, then the union `⋃ i, s i` is a finite set. -/ theorem Finite.iUnion {ι : Type*} {s : ι → Set α} {t : Set ι} (ht : t.Finite) (hs : ∀ i ∈ t, (s i).Finite) (he : ∀ i, i ∉ t → s i = ∅) : (⋃ i, s i).Finite := by suffices ⋃ i, s i ⊆ ⋃ i ∈ t, s i by exact (ht.biUnion hs).subset this refine iUnion_subset fun i x hx => ?_ by_cases hi : i ∈ t · exact mem_biUnion hi hx · rw [he i hi, mem_empty_iff_false] at hx contradiction #align set.finite.Union Set.Finite.iUnion section monad attribute [local instance] Set.monad theorem Finite.bind {α β} {s : Set α} {f : α → Set β} (h : s.Finite) (hf : ∀ a ∈ s, (f a).Finite) : (s >>= f).Finite := h.biUnion hf #align set.finite.bind Set.Finite.bind end monad @[simp] theorem finite_empty : (∅ : Set α).Finite := toFinite _ #align set.finite_empty Set.finite_empty protected theorem Infinite.nonempty {s : Set α} (h : s.Infinite) : s.Nonempty := nonempty_iff_ne_empty.2 <| by rintro rfl exact h finite_empty #align set.infinite.nonempty Set.Infinite.nonempty @[simp] theorem finite_singleton (a : α) : ({a} : Set α).Finite := toFinite _ #align set.finite_singleton Set.finite_singleton theorem finite_pure (a : α) : (pure a : Set α).Finite := toFinite _ #align set.finite_pure Set.finite_pure @[simp] protected theorem Finite.insert (a : α) {s : Set α} (hs : s.Finite) : (insert a s).Finite := (finite_singleton a).union hs #align set.finite.insert Set.Finite.insert theorem Finite.image {s : Set α} (f : α → β) (hs : s.Finite) : (f '' s).Finite := by have := hs.to_subtype apply toFinite #align set.finite.image Set.Finite.image theorem finite_range (f : ι → α) [Finite ι] : (range f).Finite := toFinite _ #align set.finite_range Set.finite_range lemma Finite.of_surjOn {s : Set α} {t : Set β} (f : α → β) (hf : SurjOn f s t) (hs : s.Finite) : t.Finite := (hs.image _).subset hf theorem Finite.dependent_image {s : Set α} (hs : s.Finite) (F : ∀ i ∈ s, β) : {y : β | ∃ x hx, F x hx = y}.Finite := by have := hs.to_subtype simpa [range] using finite_range fun x : s => F x x.2 #align set.finite.dependent_image Set.Finite.dependent_image theorem Finite.map {α β} {s : Set α} : ∀ f : α → β, s.Finite → (f <$> s).Finite := Finite.image #align set.finite.map Set.Finite.map theorem Finite.of_finite_image {s : Set α} {f : α → β} (h : (f '' s).Finite) (hi : Set.InjOn f s) : s.Finite := have := h.to_subtype .of_injective _ hi.bijOn_image.bijective.injective #align set.finite.of_finite_image Set.Finite.of_finite_image section preimage variable {f : α → β} {s : Set β} theorem finite_of_finite_preimage (h : (f ⁻¹' s).Finite) (hs : s ⊆ range f) : s.Finite := by rw [← image_preimage_eq_of_subset hs] exact Finite.image f h #align set.finite_of_finite_preimage Set.finite_of_finite_preimage theorem Finite.of_preimage (h : (f ⁻¹' s).Finite) (hf : Surjective f) : s.Finite := hf.image_preimage s ▸ h.image _ #align set.finite.of_preimage Set.Finite.of_preimage theorem Finite.preimage (I : Set.InjOn f (f ⁻¹' s)) (h : s.Finite) : (f ⁻¹' s).Finite := (h.subset (image_preimage_subset f s)).of_finite_image I #align set.finite.preimage Set.Finite.preimage protected lemma Infinite.preimage (hs : s.Infinite) (hf : s ⊆ range f) : (f ⁻¹' s).Infinite := fun h ↦ hs <| finite_of_finite_preimage h hf lemma Infinite.preimage' (hs : (s ∩ range f).Infinite) : (f ⁻¹' s).Infinite := (hs.preimage inter_subset_right).mono <| preimage_mono inter_subset_left theorem Finite.preimage_embedding {s : Set β} (f : α ↪ β) (h : s.Finite) : (f ⁻¹' s).Finite := h.preimage fun _ _ _ _ h' => f.injective h' #align set.finite.preimage_embedding Set.Finite.preimage_embedding end preimage theorem finite_lt_nat (n : ℕ) : Set.Finite { i | i < n } := toFinite _ #align set.finite_lt_nat Set.finite_lt_nat theorem finite_le_nat (n : ℕ) : Set.Finite { i | i ≤ n } := toFinite _ #align set.finite_le_nat Set.finite_le_nat section MapsTo variable {s : Set α} {f : α → α} (hs : s.Finite) (hm : MapsTo f s s) theorem Finite.surjOn_iff_bijOn_of_mapsTo : SurjOn f s s ↔ BijOn f s s := by refine ⟨fun h ↦ ⟨hm, ?_, h⟩, BijOn.surjOn⟩ have : Finite s := finite_coe_iff.mpr hs exact hm.restrict_inj.mp (Finite.injective_iff_surjective.mpr <| hm.restrict_surjective_iff.mpr h) theorem Finite.injOn_iff_bijOn_of_mapsTo : InjOn f s ↔ BijOn f s s := by refine ⟨fun h ↦ ⟨hm, h, ?_⟩, BijOn.injOn⟩ have : Finite s := finite_coe_iff.mpr hs exact hm.restrict_surjective_iff.mp (Finite.injective_iff_surjective.mp <| hm.restrict_inj.mpr h) end MapsTo section Prod variable {s : Set α} {t : Set β} protected theorem Finite.prod (hs : s.Finite) (ht : t.Finite) : (s ×ˢ t : Set (α × β)).Finite := by have := hs.to_subtype have := ht.to_subtype apply toFinite #align set.finite.prod Set.Finite.prod theorem Finite.of_prod_left (h : (s ×ˢ t : Set (α × β)).Finite) : t.Nonempty → s.Finite := fun ⟨b, hb⟩ => (h.image Prod.fst).subset fun a ha => ⟨(a, b), ⟨ha, hb⟩, rfl⟩ #align set.finite.of_prod_left Set.Finite.of_prod_left theorem Finite.of_prod_right (h : (s ×ˢ t : Set (α × β)).Finite) : s.Nonempty → t.Finite := fun ⟨a, ha⟩ => (h.image Prod.snd).subset fun b hb => ⟨(a, b), ⟨ha, hb⟩, rfl⟩ #align set.finite.of_prod_right Set.Finite.of_prod_right protected theorem Infinite.prod_left (hs : s.Infinite) (ht : t.Nonempty) : (s ×ˢ t).Infinite := fun h => hs <| h.of_prod_left ht #align set.infinite.prod_left Set.Infinite.prod_left protected theorem Infinite.prod_right (ht : t.Infinite) (hs : s.Nonempty) : (s ×ˢ t).Infinite := fun h => ht <| h.of_prod_right hs #align set.infinite.prod_right Set.Infinite.prod_right protected theorem infinite_prod : (s ×ˢ t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by refine ⟨fun h => ?_, ?_⟩ · simp_rw [Set.Infinite, @and_comm ¬_, ← Classical.not_imp] by_contra! exact h ((this.1 h.nonempty.snd).prod <| this.2 h.nonempty.fst) · rintro (h | h) · exact h.1.prod_left h.2 · exact h.1.prod_right h.2 #align set.infinite_prod Set.infinite_prod theorem finite_prod : (s ×ˢ t).Finite ↔ (s.Finite ∨ t = ∅) ∧ (t.Finite ∨ s = ∅) := by simp only [← not_infinite, Set.infinite_prod, not_or, not_and_or, not_nonempty_iff_eq_empty] #align set.finite_prod Set.finite_prod protected theorem Finite.offDiag {s : Set α} (hs : s.Finite) : s.offDiag.Finite := (hs.prod hs).subset s.offDiag_subset_prod #align set.finite.off_diag Set.Finite.offDiag protected theorem Finite.image2 (f : α → β → γ) (hs : s.Finite) (ht : t.Finite) : (image2 f s t).Finite := by have := hs.to_subtype have := ht.to_subtype apply toFinite #align set.finite.image2 Set.Finite.image2 end Prod theorem Finite.seq {f : Set (α → β)} {s : Set α} (hf : f.Finite) (hs : s.Finite) : (f.seq s).Finite := hf.image2 _ hs #align set.finite.seq Set.Finite.seq theorem Finite.seq' {α β : Type u} {f : Set (α → β)} {s : Set α} (hf : f.Finite) (hs : s.Finite) : (f <*> s).Finite := hf.seq hs #align set.finite.seq' Set.Finite.seq' theorem finite_mem_finset (s : Finset α) : { a | a ∈ s }.Finite := toFinite _ #align set.finite_mem_finset Set.finite_mem_finset theorem Subsingleton.finite {s : Set α} (h : s.Subsingleton) : s.Finite := h.induction_on finite_empty finite_singleton #align set.subsingleton.finite Set.Subsingleton.finite theorem Infinite.nontrivial {s : Set α} (hs : s.Infinite) : s.Nontrivial := not_subsingleton_iff.1 <| mt Subsingleton.finite hs theorem finite_preimage_inl_and_inr {s : Set (Sum α β)} : (Sum.inl ⁻¹' s).Finite ∧ (Sum.inr ⁻¹' s).Finite ↔ s.Finite := ⟨fun h => image_preimage_inl_union_image_preimage_inr s ▸ (h.1.image _).union (h.2.image _), fun h => ⟨h.preimage Sum.inl_injective.injOn, h.preimage Sum.inr_injective.injOn⟩⟩ #align set.finite_preimage_inl_and_inr Set.finite_preimage_inl_and_inr theorem exists_finite_iff_finset {p : Set α → Prop} : (∃ s : Set α, s.Finite ∧ p s) ↔ ∃ s : Finset α, p ↑s := ⟨fun ⟨_, hs, hps⟩ => ⟨hs.toFinset, hs.coe_toFinset.symm ▸ hps⟩, fun ⟨s, hs⟩ => ⟨s, s.finite_toSet, hs⟩⟩ #align set.exists_finite_iff_finset Set.exists_finite_iff_finset /-- There are finitely many subsets of a given finite set -/ theorem Finite.finite_subsets {α : Type u} {a : Set α} (h : a.Finite) : { b | b ⊆ a }.Finite := by convert ((Finset.powerset h.toFinset).map Finset.coeEmb.1).finite_toSet ext s simpa [← @exists_finite_iff_finset α fun t => t ⊆ a ∧ t = s, Finite.subset_toFinset, ← and_assoc, Finset.coeEmb] using h.subset #align set.finite.finite_subsets Set.Finite.finite_subsets section Pi variable {ι : Type*} [Finite ι] {κ : ι → Type*} {t : ∀ i, Set (κ i)} /-- Finite product of finite sets is finite -/ theorem Finite.pi (ht : ∀ i, (t i).Finite) : (pi univ t).Finite := by cases nonempty_fintype ι lift t to ∀ d, Finset (κ d) using ht classical rw [← Fintype.coe_piFinset] apply Finset.finite_toSet #align set.finite.pi Set.Finite.pi /-- Finite product of finite sets is finite. Note this is a variant of `Set.Finite.pi` without the extra `i ∈ univ` binder. -/ lemma Finite.pi' (ht : ∀ i, (t i).Finite) : {f : ∀ i, κ i | ∀ i, f i ∈ t i}.Finite := by simpa [Set.pi] using Finite.pi ht end Pi /-- A finite union of finsets is finite. -/ theorem union_finset_finite_of_range_finite (f : α → Finset β) (h : (range f).Finite) : (⋃ a, (f a : Set β)).Finite := by rw [← biUnion_range] exact h.biUnion fun y _ => y.finite_toSet #align set.union_finset_finite_of_range_finite Set.union_finset_finite_of_range_finite theorem finite_range_ite {p : α → Prop} [DecidablePred p] {f g : α → β} (hf : (range f).Finite) (hg : (range g).Finite) : (range fun x => if p x then f x else g x).Finite := (hf.union hg).subset range_ite_subset #align set.finite_range_ite Set.finite_range_ite theorem finite_range_const {c : β} : (range fun _ : α => c).Finite := (finite_singleton c).subset range_const_subset #align set.finite_range_const Set.finite_range_const end SetFiniteConstructors /-! ### Properties -/ instance Finite.inhabited : Inhabited { s : Set α // s.Finite } := ⟨⟨∅, finite_empty⟩⟩ #align set.finite.inhabited Set.Finite.inhabited @[simp] theorem finite_union {s t : Set α} : (s ∪ t).Finite ↔ s.Finite ∧ t.Finite := ⟨fun h => ⟨h.subset subset_union_left, h.subset subset_union_right⟩, fun ⟨hs, ht⟩ => hs.union ht⟩ #align set.finite_union Set.finite_union theorem finite_image_iff {s : Set α} {f : α → β} (hi : InjOn f s) : (f '' s).Finite ↔ s.Finite := ⟨fun h => h.of_finite_image hi, Finite.image _⟩ #align set.finite_image_iff Set.finite_image_iff theorem univ_finite_iff_nonempty_fintype : (univ : Set α).Finite ↔ Nonempty (Fintype α) := ⟨fun h => ⟨fintypeOfFiniteUniv h⟩, fun ⟨_i⟩ => finite_univ⟩ #align set.univ_finite_iff_nonempty_fintype Set.univ_finite_iff_nonempty_fintype -- Porting note: moved `@[simp]` to `Set.toFinset_singleton` because `simp` can now simplify LHS theorem Finite.toFinset_singleton {a : α} (ha : ({a} : Set α).Finite := finite_singleton _) : ha.toFinset = {a} := Set.toFinite_toFinset _ #align set.finite.to_finset_singleton Set.Finite.toFinset_singleton @[simp] theorem Finite.toFinset_insert [DecidableEq α] {s : Set α} {a : α} (hs : (insert a s).Finite) : hs.toFinset = insert a (hs.subset <| subset_insert _ _).toFinset := Finset.ext <| by simp #align set.finite.to_finset_insert Set.Finite.toFinset_insert theorem Finite.toFinset_insert' [DecidableEq α] {a : α} {s : Set α} (hs : s.Finite) : (hs.insert a).toFinset = insert a hs.toFinset := Finite.toFinset_insert _ #align set.finite.to_finset_insert' Set.Finite.toFinset_insert' theorem Finite.toFinset_prod {s : Set α} {t : Set β} (hs : s.Finite) (ht : t.Finite) : hs.toFinset ×ˢ ht.toFinset = (hs.prod ht).toFinset := Finset.ext <| by simp #align set.finite.to_finset_prod Set.Finite.toFinset_prod theorem Finite.toFinset_offDiag {s : Set α} [DecidableEq α] (hs : s.Finite) : hs.offDiag.toFinset = hs.toFinset.offDiag := Finset.ext <| by simp #align set.finite.to_finset_off_diag Set.Finite.toFinset_offDiag theorem Finite.fin_embedding {s : Set α} (h : s.Finite) : ∃ (n : ℕ) (f : Fin n ↪ α), range f = s := ⟨_, (Fintype.equivFin (h.toFinset : Set α)).symm.asEmbedding, by simp only [Finset.coe_sort_coe, Equiv.asEmbedding_range, Finite.coe_toFinset, setOf_mem_eq]⟩ #align set.finite.fin_embedding Set.Finite.fin_embedding theorem Finite.fin_param {s : Set α} (h : s.Finite) : ∃ (n : ℕ) (f : Fin n → α), Injective f ∧ range f = s := let ⟨n, f, hf⟩ := h.fin_embedding ⟨n, f, f.injective, hf⟩ #align set.finite.fin_param Set.Finite.fin_param theorem finite_option {s : Set (Option α)} : s.Finite ↔ { x : α | some x ∈ s }.Finite := ⟨fun h => h.preimage_embedding Embedding.some, fun h => ((h.image some).insert none).subset fun x => x.casesOn (fun _ => Or.inl rfl) fun _ hx => Or.inr <| mem_image_of_mem _ hx⟩ #align set.finite_option Set.finite_option theorem finite_image_fst_and_snd_iff {s : Set (α × β)} : (Prod.fst '' s).Finite ∧ (Prod.snd '' s).Finite ↔ s.Finite := ⟨fun h => (h.1.prod h.2).subset fun _ h => ⟨mem_image_of_mem _ h, mem_image_of_mem _ h⟩, fun h => ⟨h.image _, h.image _⟩⟩ #align set.finite_image_fst_and_snd_iff Set.finite_image_fst_and_snd_iff theorem forall_finite_image_eval_iff {δ : Type*} [Finite δ] {κ : δ → Type*} {s : Set (∀ d, κ d)} : (∀ d, (eval d '' s).Finite) ↔ s.Finite := ⟨fun h => (Finite.pi h).subset <| subset_pi_eval_image _ _, fun h _ => h.image _⟩ #align set.forall_finite_image_eval_iff Set.forall_finite_image_eval_iff
Mathlib/Data/Set/Finite.lean
1,151
1,157
theorem finite_subset_iUnion {s : Set α} (hs : s.Finite) {ι} {t : ι → Set α} (h : s ⊆ ⋃ i, t i) : ∃ I : Set ι, I.Finite ∧ s ⊆ ⋃ i ∈ I, t i := by
have := hs.to_subtype choose f hf using show ∀ x : s, ∃ i, x.1 ∈ t i by simpa [subset_def] using h refine ⟨range f, finite_range f, fun x hx => ?_⟩ rw [biUnion_range, mem_iUnion] exact ⟨⟨x, hx⟩, hf _⟩
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Mario Carneiro, Johan Commelin -/ import Mathlib.NumberTheory.Padics.PadicNumbers import Mathlib.RingTheory.DiscreteValuationRing.Basic #align_import number_theory.padics.padic_integers from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # p-adic integers This file defines the `p`-adic integers `ℤ_[p]` as the subtype of `ℚ_[p]` with norm `≤ 1`. We show that `ℤ_[p]` * is complete, * is nonarchimedean, * is a normed ring, * is a local ring, and * is a discrete valuation ring. The relation between `ℤ_[p]` and `ZMod p` is established in another file. ## Important definitions * `PadicInt` : the type of `p`-adic integers ## Notation We introduce the notation `ℤ_[p]` for the `p`-adic integers. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. Coercions into `ℤ_[p]` are set up to work with the `norm_cast` tactic. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, p-adic integer -/ open Padic Metric LocalRing noncomputable section open scoped Classical /-- The `p`-adic integers `ℤ_[p]` are the `p`-adic numbers with norm `≤ 1`. -/ def PadicInt (p : ℕ) [Fact p.Prime] := { x : ℚ_[p] // ‖x‖ ≤ 1 } #align padic_int PadicInt /-- The ring of `p`-adic integers. -/ notation "ℤ_[" p "]" => PadicInt p namespace PadicInt /-! ### Ring structure and coercion to `ℚ_[p]` -/ variable {p : ℕ} [Fact p.Prime] instance : Coe ℤ_[p] ℚ_[p] := ⟨Subtype.val⟩ theorem ext {x y : ℤ_[p]} : (x : ℚ_[p]) = y → x = y := Subtype.ext #align padic_int.ext PadicInt.ext variable (p) /-- The `p`-adic integers as a subring of `ℚ_[p]`. -/ def subring : Subring ℚ_[p] where carrier := { x : ℚ_[p] | ‖x‖ ≤ 1 } zero_mem' := by set_option tactic.skipAssignedInstances false in norm_num one_mem' := by set_option tactic.skipAssignedInstances false in norm_num add_mem' hx hy := (padicNormE.nonarchimedean _ _).trans <| max_le_iff.2 ⟨hx, hy⟩ mul_mem' hx hy := (padicNormE.mul _ _).trans_le <| mul_le_one hx (norm_nonneg _) hy neg_mem' hx := (norm_neg _).trans_le hx #align padic_int.subring PadicInt.subring @[simp] theorem mem_subring_iff {x : ℚ_[p]} : x ∈ subring p ↔ ‖x‖ ≤ 1 := Iff.rfl #align padic_int.mem_subring_iff PadicInt.mem_subring_iff variable {p} /-- Addition on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Add ℤ_[p] := (by infer_instance : Add (subring p)) /-- Multiplication on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Mul ℤ_[p] := (by infer_instance : Mul (subring p)) /-- Negation on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Neg ℤ_[p] := (by infer_instance : Neg (subring p)) /-- Subtraction on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Sub ℤ_[p] := (by infer_instance : Sub (subring p)) /-- Zero on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Zero ℤ_[p] := (by infer_instance : Zero (subring p)) instance : Inhabited ℤ_[p] := ⟨0⟩ /-- One on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : One ℤ_[p] := ⟨⟨1, by norm_num⟩⟩ @[simp] theorem mk_zero {h} : (⟨0, h⟩ : ℤ_[p]) = (0 : ℤ_[p]) := rfl #align padic_int.mk_zero PadicInt.mk_zero @[simp, norm_cast] theorem coe_add (z1 z2 : ℤ_[p]) : ((z1 + z2 : ℤ_[p]) : ℚ_[p]) = z1 + z2 := rfl #align padic_int.coe_add PadicInt.coe_add @[simp, norm_cast] theorem coe_mul (z1 z2 : ℤ_[p]) : ((z1 * z2 : ℤ_[p]) : ℚ_[p]) = z1 * z2 := rfl #align padic_int.coe_mul PadicInt.coe_mul @[simp, norm_cast] theorem coe_neg (z1 : ℤ_[p]) : ((-z1 : ℤ_[p]) : ℚ_[p]) = -z1 := rfl #align padic_int.coe_neg PadicInt.coe_neg @[simp, norm_cast] theorem coe_sub (z1 z2 : ℤ_[p]) : ((z1 - z2 : ℤ_[p]) : ℚ_[p]) = z1 - z2 := rfl #align padic_int.coe_sub PadicInt.coe_sub @[simp, norm_cast] theorem coe_one : ((1 : ℤ_[p]) : ℚ_[p]) = 1 := rfl #align padic_int.coe_one PadicInt.coe_one @[simp, norm_cast] theorem coe_zero : ((0 : ℤ_[p]) : ℚ_[p]) = 0 := rfl #align padic_int.coe_zero PadicInt.coe_zero theorem coe_eq_zero (z : ℤ_[p]) : (z : ℚ_[p]) = 0 ↔ z = 0 := by rw [← coe_zero, Subtype.coe_inj] #align padic_int.coe_eq_zero PadicInt.coe_eq_zero theorem coe_ne_zero (z : ℤ_[p]) : (z : ℚ_[p]) ≠ 0 ↔ z ≠ 0 := z.coe_eq_zero.not #align padic_int.coe_ne_zero PadicInt.coe_ne_zero instance : AddCommGroup ℤ_[p] := (by infer_instance : AddCommGroup (subring p)) instance instCommRing : CommRing ℤ_[p] := (by infer_instance : CommRing (subring p)) @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℤ_[p]) : ℚ_[p]) = n := rfl #align padic_int.coe_nat_cast PadicInt.coe_natCast @[deprecated (since := "2024-04-17")] alias coe_nat_cast := coe_natCast @[simp, norm_cast] theorem coe_intCast (z : ℤ) : ((z : ℤ_[p]) : ℚ_[p]) = z := rfl #align padic_int.coe_int_cast PadicInt.coe_intCast @[deprecated (since := "2024-04-17")] alias coe_int_cast := coe_intCast /-- The coercion from `ℤ_[p]` to `ℚ_[p]` as a ring homomorphism. -/ def Coe.ringHom : ℤ_[p] →+* ℚ_[p] := (subring p).subtype #align padic_int.coe.ring_hom PadicInt.Coe.ringHom @[simp, norm_cast] theorem coe_pow (x : ℤ_[p]) (n : ℕ) : (↑(x ^ n) : ℚ_[p]) = (↑x : ℚ_[p]) ^ n := rfl #align padic_int.coe_pow PadicInt.coe_pow -- @[simp] -- Porting note: not in simpNF theorem mk_coe (k : ℤ_[p]) : (⟨k, k.2⟩ : ℤ_[p]) = k := Subtype.coe_eta _ _ #align padic_int.mk_coe PadicInt.mk_coe /-- The inverse of a `p`-adic integer with norm equal to `1` is also a `p`-adic integer. Otherwise, the inverse is defined to be `0`. -/ def inv : ℤ_[p] → ℤ_[p] | ⟨k, _⟩ => if h : ‖k‖ = 1 then ⟨k⁻¹, by simp [h]⟩ else 0 #align padic_int.inv PadicInt.inv instance : CharZero ℤ_[p] where cast_injective m n h := Nat.cast_injective (by rw [Subtype.ext_iff] at h; norm_cast at h) @[norm_cast] -- @[simp] -- Porting note: not in simpNF theorem intCast_eq (z1 z2 : ℤ) : (z1 : ℤ_[p]) = z2 ↔ z1 = z2 := by suffices (z1 : ℚ_[p]) = z2 ↔ z1 = z2 from Iff.trans (by norm_cast) this norm_cast #align padic_int.coe_int_eq PadicInt.intCast_eq -- 2024-04-05 @[deprecated] alias coe_int_eq := intCast_eq /-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic integer. -/ def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] := ⟨⟦⟨_, h⟩⟧, show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by rw [PadicSeq.norm] split_ifs with hne <;> norm_cast apply padicNorm.of_int⟩ #align padic_int.of_int_seq PadicInt.ofIntSeq end PadicInt namespace PadicInt /-! ### Instances We now show that `ℤ_[p]` is a * complete metric space * normed ring * integral domain -/ variable (p : ℕ) [Fact p.Prime] instance : MetricSpace ℤ_[p] := Subtype.metricSpace instance completeSpace : CompleteSpace ℤ_[p] := have : IsClosed { x : ℚ_[p] | ‖x‖ ≤ 1 } := isClosed_le continuous_norm continuous_const this.completeSpace_coe #align padic_int.complete_space PadicInt.completeSpace instance : Norm ℤ_[p] := ⟨fun z => ‖(z : ℚ_[p])‖⟩ variable {p} theorem norm_def {z : ℤ_[p]} : ‖z‖ = ‖(z : ℚ_[p])‖ := rfl #align padic_int.norm_def PadicInt.norm_def variable (p) instance : NormedCommRing ℤ_[p] := { PadicInt.instCommRing with dist_eq := fun ⟨_, _⟩ ⟨_, _⟩ => rfl norm_mul := by simp [norm_def] norm := norm } instance : NormOneClass ℤ_[p] := ⟨norm_def.trans norm_one⟩ instance isAbsoluteValue : IsAbsoluteValue fun z : ℤ_[p] => ‖z‖ where abv_nonneg' := norm_nonneg abv_eq_zero' := by simp [norm_eq_zero] abv_add' := fun ⟨_, _⟩ ⟨_, _⟩ => norm_add_le _ _ abv_mul' _ _ := by simp only [norm_def, padicNormE.mul, PadicInt.coe_mul] #align padic_int.is_absolute_value PadicInt.isAbsoluteValue variable {p} instance : IsDomain ℤ_[p] := Function.Injective.isDomain (subring p).subtype Subtype.coe_injective end PadicInt namespace PadicInt /-! ### Norm -/ variable {p : ℕ} [Fact p.Prime] theorem norm_le_one (z : ℤ_[p]) : ‖z‖ ≤ 1 := z.2 #align padic_int.norm_le_one PadicInt.norm_le_one @[simp] theorem norm_mul (z1 z2 : ℤ_[p]) : ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ := by simp [norm_def] #align padic_int.norm_mul PadicInt.norm_mul @[simp] theorem norm_pow (z : ℤ_[p]) : ∀ n : ℕ, ‖z ^ n‖ = ‖z‖ ^ n | 0 => by simp | k + 1 => by rw [pow_succ, pow_succ, norm_mul] congr apply norm_pow #align padic_int.norm_pow PadicInt.norm_pow theorem nonarchimedean (q r : ℤ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := padicNormE.nonarchimedean _ _ #align padic_int.nonarchimedean PadicInt.nonarchimedean theorem norm_add_eq_max_of_ne {q r : ℤ_[p]} : ‖q‖ ≠ ‖r‖ → ‖q + r‖ = max ‖q‖ ‖r‖ := padicNormE.add_eq_max_of_ne #align padic_int.norm_add_eq_max_of_ne PadicInt.norm_add_eq_max_of_ne theorem norm_eq_of_norm_add_lt_right {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ := by_contra fun hne => not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_right) h #align padic_int.norm_eq_of_norm_add_lt_right PadicInt.norm_eq_of_norm_add_lt_right theorem norm_eq_of_norm_add_lt_left {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ := by_contra fun hne => not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_left) h #align padic_int.norm_eq_of_norm_add_lt_left PadicInt.norm_eq_of_norm_add_lt_left @[simp] theorem padic_norm_e_of_padicInt (z : ℤ_[p]) : ‖(z : ℚ_[p])‖ = ‖z‖ := by simp [norm_def] #align padic_int.padic_norm_e_of_padic_int PadicInt.padic_norm_e_of_padicInt theorem norm_intCast_eq_padic_norm (z : ℤ) : ‖(z : ℤ_[p])‖ = ‖(z : ℚ_[p])‖ := by simp [norm_def] #align padic_int.norm_int_cast_eq_padic_norm PadicInt.norm_intCast_eq_padic_norm @[deprecated (since := "2024-04-17")] alias norm_int_cast_eq_padic_norm := norm_intCast_eq_padic_norm @[simp] theorem norm_eq_padic_norm {q : ℚ_[p]} (hq : ‖q‖ ≤ 1) : @norm ℤ_[p] _ ⟨q, hq⟩ = ‖q‖ := rfl #align padic_int.norm_eq_padic_norm PadicInt.norm_eq_padic_norm @[simp] theorem norm_p : ‖(p : ℤ_[p])‖ = (p : ℝ)⁻¹ := padicNormE.norm_p #align padic_int.norm_p PadicInt.norm_p -- @[simp] -- Porting note: not in simpNF theorem norm_p_pow (n : ℕ) : ‖(p : ℤ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := padicNormE.norm_p_pow n #align padic_int.norm_p_pow PadicInt.norm_p_pow private def cauSeq_to_rat_cauSeq (f : CauSeq ℤ_[p] norm) : CauSeq ℚ_[p] fun a => ‖a‖ := ⟨fun n => f n, fun _ hε => by simpa [norm, norm_def] using f.cauchy hε⟩ variable (p) instance complete : CauSeq.IsComplete ℤ_[p] norm := ⟨fun f => have hqn : ‖CauSeq.lim (cauSeq_to_rat_cauSeq f)‖ ≤ 1 := padicNormE_lim_le zero_lt_one fun _ => norm_le_one _ ⟨⟨_, hqn⟩, fun ε => by simpa [norm, norm_def] using CauSeq.equiv_lim (cauSeq_to_rat_cauSeq f) ε⟩⟩ #align padic_int.complete PadicInt.complete end PadicInt namespace PadicInt variable (p : ℕ) [hp : Fact p.Prime] theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹ use k rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)] · rw [zpow_neg, inv_inv, zpow_natCast] apply lt_of_lt_of_le hk norm_cast apply le_of_lt convert Nat.lt_pow_self _ _ using 1 exact hp.1.one_lt · exact mod_cast hp.1.pos #align padic_int.exists_pow_neg_lt PadicInt.exists_pow_neg_lt theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε) use k rw [show (p : ℝ) = (p : ℚ) by simp] at hk exact mod_cast hk #align padic_int.exists_pow_neg_lt_rat PadicInt.exists_pow_neg_lt_rat variable {p} theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℤ_[p])‖ < 1 ↔ (p : ℤ) ∣ k := suffices ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k by rwa [norm_intCast_eq_padic_norm] padicNormE.norm_int_lt_one_iff_dvd k #align padic_int.norm_int_lt_one_iff_dvd PadicInt.norm_int_lt_one_iff_dvd theorem norm_int_le_pow_iff_dvd {k : ℤ} {n : ℕ} : ‖(k : ℤ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k := suffices ‖(k : ℚ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k by simpa [norm_intCast_eq_padic_norm] padicNormE.norm_int_le_pow_iff_dvd _ _ #align padic_int.norm_int_le_pow_iff_dvd PadicInt.norm_int_le_pow_iff_dvd /-! ### Valuation on `ℤ_[p]` -/ /-- `PadicInt.valuation` lifts the `p`-adic valuation on `ℚ` to `ℤ_[p]`. -/ def valuation (x : ℤ_[p]) := Padic.valuation (x : ℚ_[p]) #align padic_int.valuation PadicInt.valuation theorem norm_eq_pow_val {x : ℤ_[p]} (hx : x ≠ 0) : ‖x‖ = (p : ℝ) ^ (-x.valuation) := by refine @Padic.norm_eq_pow_val p hp x ?_ contrapose! hx exact Subtype.val_injective hx #align padic_int.norm_eq_pow_val PadicInt.norm_eq_pow_val @[simp] theorem valuation_zero : valuation (0 : ℤ_[p]) = 0 := Padic.valuation_zero #align padic_int.valuation_zero PadicInt.valuation_zero @[simp] theorem valuation_one : valuation (1 : ℤ_[p]) = 0 := Padic.valuation_one #align padic_int.valuation_one PadicInt.valuation_one @[simp] theorem valuation_p : valuation (p : ℤ_[p]) = 1 := by simp [valuation] #align padic_int.valuation_p PadicInt.valuation_p theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by by_cases hx : x = 0 · simp [hx] have h : (1 : ℝ) < p := mod_cast hp.1.one_lt rw [← neg_nonpos, ← (zpow_strictMono h).le_iff_le] show (p : ℝ) ^ (-valuation x) ≤ (p : ℝ) ^ (0 : ℤ) rw [← norm_eq_pow_val hx] simpa using x.property #align padic_int.valuation_nonneg PadicInt.valuation_nonneg @[simp] theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) : ((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _ have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by contrapose! hc rw [mul_eq_zero] at hc cases' hc with hc hc · refine (hp.1.ne_zero ?_).elim exact_mod_cast pow_eq_zero hc · exact hc rwa [norm_eq_pow_val aux, norm_p_pow, norm_eq_pow_val hc, ← zpow_add₀, ← neg_add, zpow_inj, neg_inj] at this · exact mod_cast hp.1.pos · exact mod_cast hp.1.ne_one · exact mod_cast hp.1.ne_zero #align padic_int.valuation_p_pow_mul PadicInt.valuation_p_pow_mul section Units /-! ### Units of `ℤ_[p]` -/ -- Porting note: `reducible` cannot be local and making it global breaks a lot of things -- attribute [local reducible] PadicInt theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1 | ⟨k, _⟩, h => by have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h) unfold PadicInt.inv rw [norm_eq_padic_norm] at h dsimp only rw [dif_pos h] apply Subtype.ext_iff_val.2 simp [mul_inv_cancel hk] #align padic_int.mul_inv PadicInt.mul_inv theorem inv_mul {z : ℤ_[p]} (hz : ‖z‖ = 1) : z.inv * z = 1 := by rw [mul_comm, mul_inv hz] #align padic_int.inv_mul PadicInt.inv_mul theorem isUnit_iff {z : ℤ_[p]} : IsUnit z ↔ ‖z‖ = 1 := ⟨fun h => by rcases isUnit_iff_dvd_one.1 h with ⟨w, eq⟩ refine le_antisymm (norm_le_one _) ?_ have := mul_le_mul_of_nonneg_left (norm_le_one w) (norm_nonneg z) rwa [mul_one, ← norm_mul, ← eq, norm_one] at this, fun h => ⟨⟨z, z.inv, mul_inv h, inv_mul h⟩, rfl⟩⟩ #align padic_int.is_unit_iff PadicInt.isUnit_iff theorem norm_lt_one_add {z1 z2 : ℤ_[p]} (hz1 : ‖z1‖ < 1) (hz2 : ‖z2‖ < 1) : ‖z1 + z2‖ < 1 := lt_of_le_of_lt (nonarchimedean _ _) (max_lt hz1 hz2) #align padic_int.norm_lt_one_add PadicInt.norm_lt_one_add theorem norm_lt_one_mul {z1 z2 : ℤ_[p]} (hz2 : ‖z2‖ < 1) : ‖z1 * z2‖ < 1 := calc ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ := by simp _ < 1 := mul_lt_one_of_nonneg_of_lt_one_right (norm_le_one _) (norm_nonneg _) hz2 #align padic_int.norm_lt_one_mul PadicInt.norm_lt_one_mul -- @[simp] -- Porting note: not in simpNF theorem mem_nonunits {z : ℤ_[p]} : z ∈ nonunits ℤ_[p] ↔ ‖z‖ < 1 := by rw [lt_iff_le_and_ne]; simp [norm_le_one z, nonunits, isUnit_iff] #align padic_int.mem_nonunits PadicInt.mem_nonunits /-- A `p`-adic number `u` with `‖u‖ = 1` is a unit of `ℤ_[p]`. -/ def mkUnits {u : ℚ_[p]} (h : ‖u‖ = 1) : ℤ_[p]ˣ := let z : ℤ_[p] := ⟨u, le_of_eq h⟩ ⟨z, z.inv, mul_inv h, inv_mul h⟩ #align padic_int.mk_units PadicInt.mkUnits @[simp] theorem mkUnits_eq {u : ℚ_[p]} (h : ‖u‖ = 1) : ((mkUnits h : ℤ_[p]) : ℚ_[p]) = u := rfl #align padic_int.mk_units_eq PadicInt.mkUnits_eq @[simp] theorem norm_units (u : ℤ_[p]ˣ) : ‖(u : ℤ_[p])‖ = 1 := isUnit_iff.mp <| by simp #align padic_int.norm_units PadicInt.norm_units /-- `unitCoeff hx` is the unit `u` in the unique representation `x = u * p ^ n`. See `unitCoeff_spec`. -/ def unitCoeff {x : ℤ_[p]} (hx : x ≠ 0) : ℤ_[p]ˣ := let u : ℚ_[p] := x * (p : ℚ_[p]) ^ (-x.valuation) have hu : ‖u‖ = 1 := by simp [u, hx, Nat.zpow_ne_zero_of_pos (mod_cast hp.1.pos) x.valuation, norm_eq_pow_val, zpow_neg, inv_mul_cancel] mkUnits hu #align padic_int.unit_coeff PadicInt.unitCoeff @[simp] theorem unitCoeff_coe {x : ℤ_[p]} (hx : x ≠ 0) : (unitCoeff hx : ℚ_[p]) = x * (p : ℚ_[p]) ^ (-x.valuation) := rfl #align padic_int.unit_coeff_coe PadicInt.unitCoeff_coe theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) : x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by apply Subtype.coe_injective push_cast have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by rw [unitCoeff_coe, mul_assoc, ← zpow_add₀] · simp · exact mod_cast hp.1.ne_zero convert repr using 2 rw [← zpow_natCast, Int.natAbs_of_nonneg (valuation_nonneg x)] #align padic_int.unit_coeff_spec PadicInt.unitCoeff_spec end Units section NormLeIff /-! ### Various characterizations of open unit balls -/
Mathlib/NumberTheory/Padics/PadicIntegers.lean
525
537
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) : ‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
rw [norm_eq_pow_val hx] lift x.valuation to ℕ using x.valuation_nonneg with k simp only [Int.ofNat_le, zpow_neg, zpow_natCast] have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by intro m refine pow_pos ?_ m exact mod_cast hp.1.pos rw [inv_le_inv (aux _) (aux _)] have : p ^ n ≤ p ^ k ↔ n ≤ k := (pow_right_strictMono hp.1.one_lt).le_iff_le rw [← this] norm_cast
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.SetTheory.Cardinal.Finite #align_import data.finite.card from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8" /-! # Cardinality of finite types The cardinality of a finite type `α` is given by `Nat.card α`. This function has the "junk value" of `0` for infinite types, but to ensure the function has valid output, one just needs to know that it's possible to produce a `Finite` instance for the type. (Note: we could have defined a `Finite.card` that required you to supply a `Finite` instance, but (a) the function would be `noncomputable` anyway so there is no need to supply the instance and (b) the function would have a more complicated dependent type that easily leads to "motive not type correct" errors.) ## Implementation notes Theorems about `Nat.card` are sometimes incidentally true for both finite and infinite types. If removing a finiteness constraint results in no loss in legibility, we remove it. We generally put such theorems into the `SetTheory.Cardinal.Finite` module. -/ noncomputable section open scoped Classical variable {α β γ : Type*} /-- There is (noncomputably) an equivalence between a finite type `α` and `Fin (Nat.card α)`. -/ def Finite.equivFin (α : Type*) [Finite α] : α ≃ Fin (Nat.card α) := by have := (Finite.exists_equiv_fin α).choose_spec.some rwa [Nat.card_eq_of_equiv_fin this] #align finite.equiv_fin Finite.equivFin /-- Similar to `Finite.equivFin` but with control over the term used for the cardinality. -/ def Finite.equivFinOfCardEq [Finite α] {n : ℕ} (h : Nat.card α = n) : α ≃ Fin n := by subst h apply Finite.equivFin #align finite.equiv_fin_of_card_eq Finite.equivFinOfCardEq theorem Nat.card_eq (α : Type*) : Nat.card α = if h : Finite α then @Fintype.card α (Fintype.ofFinite α) else 0 := by cases finite_or_infinite α · letI := Fintype.ofFinite α simp only [*, Nat.card_eq_fintype_card, dif_pos] · simp only [*, card_eq_zero_of_infinite, not_finite_iff_infinite.mpr, dite_false] #align nat.card_eq Nat.card_eq theorem Finite.card_pos_iff [Finite α] : 0 < Nat.card α ↔ Nonempty α := by haveI := Fintype.ofFinite α rw [Nat.card_eq_fintype_card, Fintype.card_pos_iff] #align finite.card_pos_iff Finite.card_pos_iff theorem Finite.card_pos [Finite α] [h : Nonempty α] : 0 < Nat.card α := Finite.card_pos_iff.mpr h #align finite.card_pos Finite.card_pos namespace Finite theorem cast_card_eq_mk {α : Type*} [Finite α] : ↑(Nat.card α) = Cardinal.mk α := Cardinal.cast_toNat_of_lt_aleph0 (Cardinal.lt_aleph0_of_finite α) #align finite.cast_card_eq_mk Finite.cast_card_eq_mk theorem card_eq [Finite α] [Finite β] : Nat.card α = Nat.card β ↔ Nonempty (α ≃ β) := by haveI := Fintype.ofFinite α haveI := Fintype.ofFinite β simp only [Nat.card_eq_fintype_card, Fintype.card_eq] #align finite.card_eq Finite.card_eq theorem card_le_one_iff_subsingleton [Finite α] : Nat.card α ≤ 1 ↔ Subsingleton α := by haveI := Fintype.ofFinite α simp only [Nat.card_eq_fintype_card, Fintype.card_le_one_iff_subsingleton] #align finite.card_le_one_iff_subsingleton Finite.card_le_one_iff_subsingleton
Mathlib/Data/Finite/Card.lean
83
85
theorem one_lt_card_iff_nontrivial [Finite α] : 1 < Nat.card α ↔ Nontrivial α := by
haveI := Fintype.ofFinite α simp only [Nat.card_eq_fintype_card, Fintype.one_lt_card_iff_nontrivial]
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.Hom.Bounded import Mathlib.Order.SymmDiff #align_import order.hom.lattice from "leanprover-community/mathlib"@"7581030920af3dcb241d1df0e36f6ec8289dd6be" /-! # Lattice homomorphisms This file defines (bounded) lattice homomorphisms. We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `SupHom`: Maps which preserve `⊔`. * `InfHom`: Maps which preserve `⊓`. * `SupBotHom`: Finitary supremum homomorphisms. Maps which preserve `⊔` and `⊥`. * `InfTopHom`: Finitary infimum homomorphisms. Maps which preserve `⊓` and `⊤`. * `LatticeHom`: Lattice homomorphisms. Maps which preserve `⊔` and `⊓`. * `BoundedLatticeHom`: Bounded lattice homomorphisms. Maps which preserve `⊤`, `⊥`, `⊔` and `⊓`. ## Typeclasses * `SupHomClass` * `InfHomClass` * `SupBotHomClass` * `InfTopHomClass` * `LatticeHomClass` * `BoundedLatticeHomClass` ## TODO Do we need more intersections between `BotHom`, `TopHom` and lattice homomorphisms? -/ open Function OrderDual variable {F ι α β γ δ : Type*} /-- The type of `⊔`-preserving functions from `α` to `β`. -/ structure SupHom (α β : Type*) [Sup α] [Sup β] where /-- The underlying function of a `SupHom` -/ toFun : α → β /-- A `SupHom` preserves suprema. -/ map_sup' (a b : α) : toFun (a ⊔ b) = toFun a ⊔ toFun b #align sup_hom SupHom /-- The type of `⊓`-preserving functions from `α` to `β`. -/ structure InfHom (α β : Type*) [Inf α] [Inf β] where /-- The underlying function of an `InfHom` -/ toFun : α → β /-- An `InfHom` preserves infima. -/ map_inf' (a b : α) : toFun (a ⊓ b) = toFun a ⊓ toFun b #align inf_hom InfHom /-- The type of finitary supremum-preserving homomorphisms from `α` to `β`. -/ structure SupBotHom (α β : Type*) [Sup α] [Sup β] [Bot α] [Bot β] extends SupHom α β where /-- A `SupBotHom` preserves the bottom element. -/ map_bot' : toFun ⊥ = ⊥ #align sup_bot_hom SupBotHom /-- The type of finitary infimum-preserving homomorphisms from `α` to `β`. -/ structure InfTopHom (α β : Type*) [Inf α] [Inf β] [Top α] [Top β] extends InfHom α β where /-- An `InfTopHom` preserves the top element. -/ map_top' : toFun ⊤ = ⊤ #align inf_top_hom InfTopHom /-- The type of lattice homomorphisms from `α` to `β`. -/ structure LatticeHom (α β : Type*) [Lattice α] [Lattice β] extends SupHom α β where /-- A `LatticeHom` preserves infima. -/ map_inf' (a b : α) : toFun (a ⊓ b) = toFun a ⊓ toFun b #align lattice_hom LatticeHom /-- The type of bounded lattice homomorphisms from `α` to `β`. -/ structure BoundedLatticeHom (α β : Type*) [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] extends LatticeHom α β where /-- A `BoundedLatticeHom` preserves the top element. -/ map_top' : toFun ⊤ = ⊤ /-- A `BoundedLatticeHom` preserves the bottom element. -/ map_bot' : toFun ⊥ = ⊥ #align bounded_lattice_hom BoundedLatticeHom -- Porting note (#11215): TODO: remove this configuration and use the default configuration. -- We keep this to be consistent with Lean 3. initialize_simps_projections SupBotHom (+toSupHom, -toFun) initialize_simps_projections InfTopHom (+toInfHom, -toFun) initialize_simps_projections LatticeHom (+toSupHom, -toFun) initialize_simps_projections BoundedLatticeHom (+toLatticeHom, -toFun) section /-- `SupHomClass F α β` states that `F` is a type of `⊔`-preserving morphisms. You should extend this class when you extend `SupHom`. -/ class SupHomClass (F α β : Type*) [Sup α] [Sup β] [FunLike F α β] : Prop where /-- A `SupHomClass` morphism preserves suprema. -/ map_sup (f : F) (a b : α) : f (a ⊔ b) = f a ⊔ f b #align sup_hom_class SupHomClass /-- `InfHomClass F α β` states that `F` is a type of `⊓`-preserving morphisms. You should extend this class when you extend `InfHom`. -/ class InfHomClass (F α β : Type*) [Inf α] [Inf β] [FunLike F α β] : Prop where /-- An `InfHomClass` morphism preserves infima. -/ map_inf (f : F) (a b : α) : f (a ⊓ b) = f a ⊓ f b #align inf_hom_class InfHomClass /-- `SupBotHomClass F α β` states that `F` is a type of finitary supremum-preserving morphisms. You should extend this class when you extend `SupBotHom`. -/ class SupBotHomClass (F α β : Type*) [Sup α] [Sup β] [Bot α] [Bot β] [FunLike F α β] extends SupHomClass F α β : Prop where /-- A `SupBotHomClass` morphism preserves the bottom element. -/ map_bot (f : F) : f ⊥ = ⊥ #align sup_bot_hom_class SupBotHomClass /-- `InfTopHomClass F α β` states that `F` is a type of finitary infimum-preserving morphisms. You should extend this class when you extend `SupBotHom`. -/ class InfTopHomClass (F α β : Type*) [Inf α] [Inf β] [Top α] [Top β] [FunLike F α β] extends InfHomClass F α β : Prop where /-- An `InfTopHomClass` morphism preserves the top element. -/ map_top (f : F) : f ⊤ = ⊤ #align inf_top_hom_class InfTopHomClass /-- `LatticeHomClass F α β` states that `F` is a type of lattice morphisms. You should extend this class when you extend `LatticeHom`. -/ class LatticeHomClass (F α β : Type*) [Lattice α] [Lattice β] [FunLike F α β] extends SupHomClass F α β : Prop where /-- A `LatticeHomClass` morphism preserves infima. -/ map_inf (f : F) (a b : α) : f (a ⊓ b) = f a ⊓ f b #align lattice_hom_class LatticeHomClass /-- `BoundedLatticeHomClass F α β` states that `F` is a type of bounded lattice morphisms. You should extend this class when you extend `BoundedLatticeHom`. -/ class BoundedLatticeHomClass (F α β : Type*) [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [FunLike F α β] extends LatticeHomClass F α β : Prop where /-- A `BoundedLatticeHomClass` morphism preserves the top element. -/ map_top (f : F) : f ⊤ = ⊤ /-- A `BoundedLatticeHomClass` morphism preserves the bottom element. -/ map_bot (f : F) : f ⊥ = ⊥ #align bounded_lattice_hom_class BoundedLatticeHomClass end export SupHomClass (map_sup) export InfHomClass (map_inf) attribute [simp] map_top map_bot map_sup map_inf section Hom variable [FunLike F α β] -- Porting note: changes to the typeclass inference system mean that we need to -- make a lot of changes here, adding `outParams`, changing `[]`s into `{}` and -- so on. -- See note [lower instance priority] instance (priority := 100) SupHomClass.toOrderHomClass [SemilatticeSup α] [SemilatticeSup β] [SupHomClass F α β] : OrderHomClass F α β := { ‹SupHomClass F α β› with map_rel := fun f a b h => by rw [← sup_eq_right, ← map_sup, sup_eq_right.2 h] } #align sup_hom_class.to_order_hom_class SupHomClass.toOrderHomClass -- See note [lower instance priority] instance (priority := 100) InfHomClass.toOrderHomClass [SemilatticeInf α] [SemilatticeInf β] [InfHomClass F α β] : OrderHomClass F α β := { ‹InfHomClass F α β› with map_rel := fun f a b h => by rw [← inf_eq_left, ← map_inf, inf_eq_left.2 h] } #align inf_hom_class.to_order_hom_class InfHomClass.toOrderHomClass -- See note [lower instance priority] instance (priority := 100) SupBotHomClass.toBotHomClass [Sup α] [Sup β] [Bot α] [Bot β] [SupBotHomClass F α β] : BotHomClass F α β := { ‹SupBotHomClass F α β› with } #align sup_bot_hom_class.to_bot_hom_class SupBotHomClass.toBotHomClass -- See note [lower instance priority] instance (priority := 100) InfTopHomClass.toTopHomClass [Inf α] [Inf β] [Top α] [Top β] [InfTopHomClass F α β] : TopHomClass F α β := { ‹InfTopHomClass F α β› with } #align inf_top_hom_class.to_top_hom_class InfTopHomClass.toTopHomClass -- See note [lower instance priority] instance (priority := 100) LatticeHomClass.toInfHomClass [Lattice α] [Lattice β] [LatticeHomClass F α β] : InfHomClass F α β := { ‹LatticeHomClass F α β› with } #align lattice_hom_class.to_inf_hom_class LatticeHomClass.toInfHomClass -- See note [lower instance priority] instance (priority := 100) BoundedLatticeHomClass.toSupBotHomClass [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] : SupBotHomClass F α β := { ‹BoundedLatticeHomClass F α β› with } #align bounded_lattice_hom_class.to_sup_bot_hom_class BoundedLatticeHomClass.toSupBotHomClass -- See note [lower instance priority] instance (priority := 100) BoundedLatticeHomClass.toInfTopHomClass [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] : InfTopHomClass F α β := { ‹BoundedLatticeHomClass F α β› with } #align bounded_lattice_hom_class.to_inf_top_hom_class BoundedLatticeHomClass.toInfTopHomClass -- See note [lower instance priority] instance (priority := 100) BoundedLatticeHomClass.toBoundedOrderHomClass [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] : BoundedOrderHomClass F α β := { show OrderHomClass F α β from inferInstance, ‹BoundedLatticeHomClass F α β› with } #align bounded_lattice_hom_class.to_bounded_order_hom_class BoundedLatticeHomClass.toBoundedOrderHomClass end Hom section Equiv variable [EquivLike F α β] -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toSupHomClass [SemilatticeSup α] [SemilatticeSup β] [OrderIsoClass F α β] : SupHomClass F α β := { show OrderHomClass F α β from inferInstance with map_sup := fun f a b => eq_of_forall_ge_iff fun c => by simp only [← le_map_inv_iff, sup_le_iff] } #align order_iso_class.to_sup_hom_class OrderIsoClass.toSupHomClass -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toInfHomClass [SemilatticeInf α] [SemilatticeInf β] [OrderIsoClass F α β] : InfHomClass F α β := { show OrderHomClass F α β from inferInstance with map_inf := fun f a b => eq_of_forall_le_iff fun c => by simp only [← map_inv_le_iff, le_inf_iff] } #align order_iso_class.to_inf_hom_class OrderIsoClass.toInfHomClass -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toSupBotHomClass [SemilatticeSup α] [OrderBot α] [SemilatticeSup β] [OrderBot β] [OrderIsoClass F α β] : SupBotHomClass F α β := { OrderIsoClass.toSupHomClass, OrderIsoClass.toBotHomClass with } #align order_iso_class.to_sup_bot_hom_class OrderIsoClass.toSupBotHomClass -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toInfTopHomClass [SemilatticeInf α] [OrderTop α] [SemilatticeInf β] [OrderTop β] [OrderIsoClass F α β] : InfTopHomClass F α β := { OrderIsoClass.toInfHomClass, OrderIsoClass.toTopHomClass with } #align order_iso_class.to_inf_top_hom_class OrderIsoClass.toInfTopHomClass -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toLatticeHomClass [Lattice α] [Lattice β] [OrderIsoClass F α β] : LatticeHomClass F α β := { OrderIsoClass.toSupHomClass, OrderIsoClass.toInfHomClass with } #align order_iso_class.to_lattice_hom_class OrderIsoClass.toLatticeHomClass -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toBoundedLatticeHomClass [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [OrderIsoClass F α β] : BoundedLatticeHomClass F α β := { OrderIsoClass.toLatticeHomClass, OrderIsoClass.toBoundedOrderHomClass with } #align order_iso_class.to_bounded_lattice_hom_class OrderIsoClass.toBoundedLatticeHomClass end Equiv section OrderEmbedding variable [FunLike F α β] /-- We can regard an injective map preserving binary infima as an order embedding. -/ @[simps! apply] def orderEmbeddingOfInjective [SemilatticeInf α] [SemilatticeInf β] (f : F) [InfHomClass F α β] (hf : Injective f) : α ↪o β := OrderEmbedding.ofMapLEIff f (fun x y ↦ by refine ⟨fun h ↦ ?_, fun h ↦ OrderHomClass.mono f h⟩ rwa [← inf_eq_left, ← hf.eq_iff, map_inf, inf_eq_left]) end OrderEmbedding section BoundedLattice variable [Lattice α] [BoundedOrder α] [Lattice β] [BoundedOrder β] variable [FunLike F α β] [BoundedLatticeHomClass F α β] variable (f : F) {a b : α} theorem Disjoint.map (h : Disjoint a b) : Disjoint (f a) (f b) := by rw [disjoint_iff, ← map_inf, h.eq_bot, map_bot] #align disjoint.map Disjoint.map theorem Codisjoint.map (h : Codisjoint a b) : Codisjoint (f a) (f b) := by rw [codisjoint_iff, ← map_sup, h.eq_top, map_top] #align codisjoint.map Codisjoint.map theorem IsCompl.map (h : IsCompl a b) : IsCompl (f a) (f b) := ⟨h.1.map _, h.2.map _⟩ #align is_compl.map IsCompl.map end BoundedLattice section BooleanAlgebra variable [BooleanAlgebra α] [BooleanAlgebra β] [FunLike F α β] [BoundedLatticeHomClass F α β] variable (f : F) /-- Special case of `map_compl` for boolean algebras. -/ theorem map_compl' (a : α) : f aᶜ = (f a)ᶜ := (isCompl_compl.map _).compl_eq.symm #align map_compl' map_compl' /-- Special case of `map_sdiff` for boolean algebras. -/ theorem map_sdiff' (a b : α) : f (a \ b) = f a \ f b := by rw [sdiff_eq, sdiff_eq, map_inf, map_compl'] #align map_sdiff' map_sdiff' open scoped symmDiff in /-- Special case of `map_symmDiff` for boolean algebras. -/
Mathlib/Order/Hom/Lattice.lean
322
323
theorem map_symmDiff' (a b : α) : f (a ∆ b) = f a ∆ f b := by
rw [symmDiff, symmDiff, map_sup, map_sdiff', map_sdiff']
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Data.Finsupp.Encodable import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Span import Mathlib.Data.Set.Countable #align_import linear_algebra.finsupp from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Properties of the module `α →₀ M` Given an `R`-module `M`, the `R`-module structure on `α →₀ M` is defined in `Data.Finsupp.Basic`. In this file we define `Finsupp.supported s` to be the set `{f : α →₀ M | f.support ⊆ s}` interpreted as a submodule of `α →₀ M`. We also define `LinearMap` versions of various maps: * `Finsupp.lsingle a : M →ₗ[R] ι →₀ M`: `Finsupp.single a` as a linear map; * `Finsupp.lapply a : (ι →₀ M) →ₗ[R] M`: the map `fun f ↦ f a` as a linear map; * `Finsupp.lsubtypeDomain (s : Set α) : (α →₀ M) →ₗ[R] (s →₀ M)`: restriction to a subtype as a linear map; * `Finsupp.restrictDom`: `Finsupp.filter` as a linear map to `Finsupp.supported s`; * `Finsupp.lsum`: `Finsupp.sum` or `Finsupp.liftAddHom` as a `LinearMap`; * `Finsupp.total α M R (v : ι → M)`: sends `l : ι → R` to the linear combination of `v i` with coefficients `l i`; * `Finsupp.totalOn`: a restricted version of `Finsupp.total` with domain `Finsupp.supported R R s` and codomain `Submodule.span R (v '' s)`; * `Finsupp.supportedEquivFinsupp`: a linear equivalence between the functions `α →₀ M` supported on `s` and the functions `s →₀ M`; * `Finsupp.lmapDomain`: a linear map version of `Finsupp.mapDomain`; * `Finsupp.domLCongr`: a `LinearEquiv` version of `Finsupp.domCongr`; * `Finsupp.congr`: if the sets `s` and `t` are equivalent, then `supported M R s` is equivalent to `supported M R t`; * `Finsupp.lcongr`: a `LinearEquiv`alence between `α →₀ M` and `β →₀ N` constructed using `e : α ≃ β` and `e' : M ≃ₗ[R] N`. ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp section SMul variable {α : Type*} {β : Type*} {R : Type*} {M : Type*} {M₂ : Type*} theorem smul_sum [Zero β] [AddCommMonoid M] [DistribSMul R M] {v : α →₀ β} {c : R} {h : α → β → M} : c • v.sum h = v.sum fun a b => c • h a b := Finset.smul_sum #align finsupp.smul_sum Finsupp.smul_sum @[simp] theorem sum_smul_index_linearMap' [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R M₂] {v : α →₀ M} {c : R} {h : α → M →ₗ[R] M₂} : ((c • v).sum fun a => h a) = c • v.sum fun a => h a := by rw [Finsupp.sum_smul_index', Finsupp.smul_sum] · simp only [map_smul] · intro i exact (h i).map_zero #align finsupp.sum_smul_index_linear_map' Finsupp.sum_smul_index_linearMap' end SMul section LinearEquivFunOnFinite variable (R : Type*) {S : Type*} (M : Type*) (α : Type*) variable [Finite α] [AddCommMonoid M] [Semiring R] [Module R M] /-- Given `Finite α`, `linearEquivFunOnFinite R` is the natural `R`-linear equivalence between `α →₀ β` and `α → β`. -/ @[simps apply] noncomputable def linearEquivFunOnFinite : (α →₀ M) ≃ₗ[R] α → M := { equivFunOnFinite with toFun := (⇑) map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv_fun_on_finite Finsupp.linearEquivFunOnFinite @[simp] theorem linearEquivFunOnFinite_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α) (single x m) = Pi.single x m := equivFunOnFinite_single x m #align finsupp.linear_equiv_fun_on_finite_single Finsupp.linearEquivFunOnFinite_single @[simp] theorem linearEquivFunOnFinite_symm_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α).symm (Pi.single x m) = single x m := equivFunOnFinite_symm_single x m #align finsupp.linear_equiv_fun_on_finite_symm_single Finsupp.linearEquivFunOnFinite_symm_single @[simp] theorem linearEquivFunOnFinite_symm_coe (f : α →₀ M) : (linearEquivFunOnFinite R M α).symm f = f := (linearEquivFunOnFinite R M α).symm_apply_apply f #align finsupp.linear_equiv_fun_on_finite_symm_coe Finsupp.linearEquivFunOnFinite_symm_coe end LinearEquivFunOnFinite section LinearEquiv.finsuppUnique variable (R : Type*) {S : Type*} (M : Type*) variable [AddCommMonoid M] [Semiring R] [Module R M] variable (α : Type*) [Unique α] /-- If `α` has a unique term, then the type of finitely supported functions `α →₀ M` is `R`-linearly equivalent to `M`. -/ noncomputable def LinearEquiv.finsuppUnique : (α →₀ M) ≃ₗ[R] M := { Finsupp.equivFunOnFinite.trans (Equiv.funUnique α M) with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv.finsupp_unique Finsupp.LinearEquiv.finsuppUnique variable {R M} @[simp] theorem LinearEquiv.finsuppUnique_apply (f : α →₀ M) : LinearEquiv.finsuppUnique R M α f = f default := rfl #align finsupp.linear_equiv.finsupp_unique_apply Finsupp.LinearEquiv.finsuppUnique_apply variable {α} @[simp] theorem LinearEquiv.finsuppUnique_symm_apply [Unique α] (m : M) : (LinearEquiv.finsuppUnique R M α).symm m = Finsupp.single default m := by ext; simp [LinearEquiv.finsuppUnique, Equiv.funUnique, single, Pi.single, equivFunOnFinite, Function.update] #align finsupp.linear_equiv.finsupp_unique_symm_apply Finsupp.LinearEquiv.finsuppUnique_symm_apply end LinearEquiv.finsuppUnique variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] /-- Interpret `Finsupp.single a` as a linear map. -/ def lsingle (a : α) : M →ₗ[R] α →₀ M := { Finsupp.singleAddHom a with map_smul' := fun _ _ => (smul_single _ _ _).symm } #align finsupp.lsingle Finsupp.lsingle /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. -/ theorem lhom_ext ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a b, φ (single a b) = ψ (single a b)) : φ = ψ := LinearMap.toAddMonoidHom_injective <| addHom_ext h #align finsupp.lhom_ext Finsupp.lhom_ext /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. We formulate this fact using equality of linear maps `φ.comp (lsingle a)` and `ψ.comp (lsingle a)` so that the `ext` tactic can apply a type-specific extensionality lemma to prove equality of these maps. E.g., if `M = R`, then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/ -- Porting note: The priority should be higher than `LinearMap.ext`. @[ext high] theorem lhom_ext' ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a, φ.comp (lsingle a) = ψ.comp (lsingle a)) : φ = ψ := lhom_ext fun a => LinearMap.congr_fun (h a) #align finsupp.lhom_ext' Finsupp.lhom_ext' /-- Interpret `fun f : α →₀ M ↦ f a` as a linear map. -/ def lapply (a : α) : (α →₀ M) →ₗ[R] M := { Finsupp.applyAddHom a with map_smul' := fun _ _ => rfl } #align finsupp.lapply Finsupp.lapply section CompatibleSMul variable (R S M N ι : Type*) variable [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [Module S M] [Module S N] instance _root_.LinearMap.CompatibleSMul.finsupp_dom [SMulZeroClass R M] [DistribSMul R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul (ι →₀ M) N R S where map_smul f r m := by conv_rhs => rw [← sum_single m, map_finsupp_sum, smul_sum] erw [← sum_single (r • m), sum_mapRange_index single_zero, map_finsupp_sum] congr; ext i m; exact (f.comp <| lsingle i).map_smul_of_tower r m instance _root_.LinearMap.CompatibleSMul.finsupp_cod [SMul R M] [SMulZeroClass R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul M (ι →₀ N) R S where map_smul f r m := by ext i; apply ((lapply i).comp f).map_smul_of_tower end CompatibleSMul /-- Forget that a function is finitely supported. This is the linear version of `Finsupp.toFun`. -/ @[simps] def lcoeFun : (α →₀ M) →ₗ[R] α → M where toFun := (⇑) map_add' x y := by ext simp map_smul' x y := by ext simp #align finsupp.lcoe_fun Finsupp.lcoeFun section LSubtypeDomain variable (s : Set α) /-- Interpret `Finsupp.subtypeDomain s` as a linear map. -/ def lsubtypeDomain : (α →₀ M) →ₗ[R] s →₀ M where toFun := subtypeDomain fun x => x ∈ s map_add' _ _ := subtypeDomain_add map_smul' _ _ := ext fun _ => rfl #align finsupp.lsubtype_domain Finsupp.lsubtypeDomain theorem lsubtypeDomain_apply (f : α →₀ M) : (lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M) f = subtypeDomain (fun x => x ∈ s) f := rfl #align finsupp.lsubtype_domain_apply Finsupp.lsubtypeDomain_apply end LSubtypeDomain @[simp] theorem lsingle_apply (a : α) (b : M) : (lsingle a : M →ₗ[R] α →₀ M) b = single a b := rfl #align finsupp.lsingle_apply Finsupp.lsingle_apply @[simp] theorem lapply_apply (a : α) (f : α →₀ M) : (lapply a : (α →₀ M) →ₗ[R] M) f = f a := rfl #align finsupp.lapply_apply Finsupp.lapply_apply @[simp] theorem lapply_comp_lsingle_same (a : α) : lapply a ∘ₗ lsingle a = (.id : M →ₗ[R] M) := by ext; simp @[simp] theorem lapply_comp_lsingle_of_ne (a a' : α) (h : a ≠ a') : lapply a ∘ₗ lsingle a' = (0 : M →ₗ[R] M) := by ext; simp [h.symm] @[simp] theorem ker_lsingle (a : α) : ker (lsingle a : M →ₗ[R] α →₀ M) = ⊥ := ker_eq_bot_of_injective (single_injective a) #align finsupp.ker_lsingle Finsupp.ker_lsingle theorem lsingle_range_le_ker_lapply (s t : Set α) (h : Disjoint s t) : ⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) ≤ ⨅ a ∈ t, ker (lapply a : (α →₀ M) →ₗ[R] M) := by refine iSup_le fun a₁ => iSup_le fun h₁ => range_le_iff_comap.2 ?_ simp only [(ker_comp _ _).symm, eq_top_iff, SetLike.le_def, mem_ker, comap_iInf, mem_iInf] intro b _ a₂ h₂ have : a₁ ≠ a₂ := fun eq => h.le_bot ⟨h₁, eq.symm ▸ h₂⟩ exact single_eq_of_ne this #align finsupp.lsingle_range_le_ker_lapply Finsupp.lsingle_range_le_ker_lapply theorem iInf_ker_lapply_le_bot : ⨅ a, ker (lapply a : (α →₀ M) →ₗ[R] M) ≤ ⊥ := by simp only [SetLike.le_def, mem_iInf, mem_ker, mem_bot, lapply_apply] exact fun a h => Finsupp.ext h #align finsupp.infi_ker_lapply_le_bot Finsupp.iInf_ker_lapply_le_bot theorem iSup_lsingle_range : ⨆ a, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) = ⊤ := by refine eq_top_iff.2 <| SetLike.le_def.2 fun f _ => ?_ rw [← sum_single f] exact sum_mem fun a _ => Submodule.mem_iSup_of_mem a ⟨_, rfl⟩ #align finsupp.supr_lsingle_range Finsupp.iSup_lsingle_range theorem disjoint_lsingle_lsingle (s t : Set α) (hs : Disjoint s t) : Disjoint (⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) (⨆ a ∈ t, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) := by -- Porting note: 2 placeholders are added to prevent timeout. refine (Disjoint.mono (lsingle_range_le_ker_lapply s sᶜ ?_) (lsingle_range_le_ker_lapply t tᶜ ?_)) ?_ · apply disjoint_compl_right · apply disjoint_compl_right rw [disjoint_iff_inf_le] refine le_trans (le_iInf fun i => ?_) iInf_ker_lapply_le_bot classical by_cases his : i ∈ s · by_cases hit : i ∈ t · exact (hs.le_bot ⟨his, hit⟩).elim exact inf_le_of_right_le (iInf_le_of_le i <| iInf_le _ hit) exact inf_le_of_left_le (iInf_le_of_le i <| iInf_le _ his) #align finsupp.disjoint_lsingle_lsingle Finsupp.disjoint_lsingle_lsingle theorem span_single_image (s : Set M) (a : α) : Submodule.span R (single a '' s) = (Submodule.span R s).map (lsingle a : M →ₗ[R] α →₀ M) := by rw [← span_image]; rfl #align finsupp.span_single_image Finsupp.span_single_image variable (M R) /-- `Finsupp.supported M R s` is the `R`-submodule of all `p : α →₀ M` such that `p.support ⊆ s`. -/ def supported (s : Set α) : Submodule R (α →₀ M) where carrier := { p | ↑p.support ⊆ s } add_mem' {p q} hp hq := by classical refine Subset.trans (Subset.trans (Finset.coe_subset.2 support_add) ?_) (union_subset hp hq) rw [Finset.coe_union] zero_mem' := by simp only [subset_def, Finset.mem_coe, Set.mem_setOf_eq, mem_support_iff, zero_apply] intro h ha exact (ha rfl).elim smul_mem' a p hp := Subset.trans (Finset.coe_subset.2 support_smul) hp #align finsupp.supported Finsupp.supported variable {M} theorem mem_supported {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ↑p.support ⊆ s := Iff.rfl #align finsupp.mem_supported Finsupp.mem_supported theorem mem_supported' {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ∀ x ∉ s, p x = 0 := by haveI := Classical.decPred fun x : α => x ∈ s; simp [mem_supported, Set.subset_def, not_imp_comm] #align finsupp.mem_supported' Finsupp.mem_supported' theorem mem_supported_support (p : α →₀ M) : p ∈ Finsupp.supported M R (p.support : Set α) := by rw [Finsupp.mem_supported] #align finsupp.mem_supported_support Finsupp.mem_supported_support theorem single_mem_supported {s : Set α} {a : α} (b : M) (h : a ∈ s) : single a b ∈ supported M R s := Set.Subset.trans support_single_subset (Finset.singleton_subset_set_iff.2 h) #align finsupp.single_mem_supported Finsupp.single_mem_supported theorem supported_eq_span_single (s : Set α) : supported R R s = span R ((fun i => single i 1) '' s) := by refine (span_eq_of_le _ ?_ (SetLike.le_def.2 fun l hl => ?_)).symm · rintro _ ⟨_, hp, rfl⟩ exact single_mem_supported R 1 hp · rw [← l.sum_single] refine sum_mem fun i il => ?_ -- Porting note: Needed to help this convert quite a bit replacing underscores convert smul_mem (M := α →₀ R) (x := single i 1) (span R ((fun i => single i 1) '' s)) (l i) ?_ · simp [span] · apply subset_span apply Set.mem_image_of_mem _ (hl il) #align finsupp.supported_eq_span_single Finsupp.supported_eq_span_single variable (M) /-- Interpret `Finsupp.filter s` as a linear map from `α →₀ M` to `supported M R s`. -/ def restrictDom (s : Set α) [DecidablePred (· ∈ s)] : (α →₀ M) →ₗ[R] supported M R s := LinearMap.codRestrict _ { toFun := filter (· ∈ s) map_add' := fun _ _ => filter_add map_smul' := fun _ _ => filter_smul } fun l => (mem_supported' _ _).2 fun _ => filter_apply_neg (· ∈ s) l #align finsupp.restrict_dom Finsupp.restrictDom variable {M R} section @[simp] theorem restrictDom_apply (s : Set α) (l : α →₀ M) [DecidablePred (· ∈ s)]: (restrictDom M R s l : α →₀ M) = Finsupp.filter (· ∈ s) l := rfl #align finsupp.restrict_dom_apply Finsupp.restrictDom_apply end theorem restrictDom_comp_subtype (s : Set α) [DecidablePred (· ∈ s)] : (restrictDom M R s).comp (Submodule.subtype _) = LinearMap.id := by ext l a by_cases h : a ∈ s <;> simp [h] exact ((mem_supported' R l.1).1 l.2 a h).symm #align finsupp.restrict_dom_comp_subtype Finsupp.restrictDom_comp_subtype theorem range_restrictDom (s : Set α) [DecidablePred (· ∈ s)] : LinearMap.range (restrictDom M R s) = ⊤ := range_eq_top.2 <| Function.RightInverse.surjective <| LinearMap.congr_fun (restrictDom_comp_subtype s) #align finsupp.range_restrict_dom Finsupp.range_restrictDom theorem supported_mono {s t : Set α} (st : s ⊆ t) : supported M R s ≤ supported M R t := fun _ h => Set.Subset.trans h st #align finsupp.supported_mono Finsupp.supported_mono @[simp] theorem supported_empty : supported M R (∅ : Set α) = ⊥ := eq_bot_iff.2 fun l h => (Submodule.mem_bot R).2 <| by ext; simp_all [mem_supported'] #align finsupp.supported_empty Finsupp.supported_empty @[simp] theorem supported_univ : supported M R (Set.univ : Set α) = ⊤ := eq_top_iff.2 fun _ _ => Set.subset_univ _ #align finsupp.supported_univ Finsupp.supported_univ theorem supported_iUnion {δ : Type*} (s : δ → Set α) : supported M R (⋃ i, s i) = ⨆ i, supported M R (s i) := by refine le_antisymm ?_ (iSup_le fun i => supported_mono <| Set.subset_iUnion _ _) haveI := Classical.decPred fun x => x ∈ ⋃ i, s i suffices LinearMap.range ((Submodule.subtype _).comp (restrictDom M R (⋃ i, s i))) ≤ ⨆ i, supported M R (s i) by rwa [LinearMap.range_comp, range_restrictDom, Submodule.map_top, range_subtype] at this rw [range_le_iff_comap, eq_top_iff] rintro l ⟨⟩ -- Porting note: Was ported as `induction l using Finsupp.induction` refine Finsupp.induction l ?_ ?_ · exact zero_mem _ · refine fun x a l _ _ => add_mem ?_ by_cases h : ∃ i, x ∈ s i <;> simp [h] cases' h with i hi exact le_iSup (fun i => supported M R (s i)) i (single_mem_supported R _ hi) #align finsupp.supported_Union Finsupp.supported_iUnion theorem supported_union (s t : Set α) : supported M R (s ∪ t) = supported M R s ⊔ supported M R t := by erw [Set.union_eq_iUnion, supported_iUnion, iSup_bool_eq]; rfl #align finsupp.supported_union Finsupp.supported_union theorem supported_iInter {ι : Type*} (s : ι → Set α) : supported M R (⋂ i, s i) = ⨅ i, supported M R (s i) := Submodule.ext fun x => by simp [mem_supported, subset_iInter_iff] #align finsupp.supported_Inter Finsupp.supported_iInter theorem supported_inter (s t : Set α) : supported M R (s ∩ t) = supported M R s ⊓ supported M R t := by rw [Set.inter_eq_iInter, supported_iInter, iInf_bool_eq]; rfl #align finsupp.supported_inter Finsupp.supported_inter theorem disjoint_supported_supported {s t : Set α} (h : Disjoint s t) : Disjoint (supported M R s) (supported M R t) := disjoint_iff.2 <| by rw [← supported_inter, disjoint_iff_inter_eq_empty.1 h, supported_empty] #align finsupp.disjoint_supported_supported Finsupp.disjoint_supported_supported theorem disjoint_supported_supported_iff [Nontrivial M] {s t : Set α} : Disjoint (supported M R s) (supported M R t) ↔ Disjoint s t := by refine ⟨fun h => Set.disjoint_left.mpr fun x hx1 hx2 => ?_, disjoint_supported_supported⟩ rcases exists_ne (0 : M) with ⟨y, hy⟩ have := h.le_bot ⟨single_mem_supported R y hx1, single_mem_supported R y hx2⟩ rw [mem_bot, single_eq_zero] at this exact hy this #align finsupp.disjoint_supported_supported_iff Finsupp.disjoint_supported_supported_iff /-- Interpret `Finsupp.restrictSupportEquiv` as a linear equivalence between `supported M R s` and `s →₀ M`. -/ def supportedEquivFinsupp (s : Set α) : supported M R s ≃ₗ[R] s →₀ M := by let F : supported M R s ≃ (s →₀ M) := restrictSupportEquiv s M refine F.toLinearEquiv ?_ have : (F : supported M R s → ↥s →₀ M) = (lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M).comp (Submodule.subtype (supported M R s)) := rfl rw [this] exact LinearMap.isLinear _ #align finsupp.supported_equiv_finsupp Finsupp.supportedEquivFinsupp section LSum variable (S) variable [Module S N] [SMulCommClass R S N] /-- Lift a family of linear maps `M →ₗ[R] N` indexed by `x : α` to a linear map from `α →₀ M` to `N` using `Finsupp.sum`. This is an upgraded version of `Finsupp.liftAddHom`. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ def lsum : (α → M →ₗ[R] N) ≃ₗ[S] (α →₀ M) →ₗ[R] N where toFun F := { toFun := fun d => d.sum fun i => F i map_add' := (liftAddHom (α := α) (M := M) (N := N) fun x => (F x).toAddMonoidHom).map_add map_smul' := fun c f => by simp [sum_smul_index', smul_sum] } invFun F x := F.comp (lsingle x) left_inv F := by ext x y simp right_inv F := by ext x y simp map_add' F G := by ext x y simp map_smul' F G := by ext x y simp #align finsupp.lsum Finsupp.lsum @[simp] theorem coe_lsum (f : α → M →ₗ[R] N) : (lsum S f : (α →₀ M) → N) = fun d => d.sum fun i => f i := rfl #align finsupp.coe_lsum Finsupp.coe_lsum theorem lsum_apply (f : α → M →ₗ[R] N) (l : α →₀ M) : Finsupp.lsum S f l = l.sum fun b => f b := rfl #align finsupp.lsum_apply Finsupp.lsum_apply theorem lsum_single (f : α → M →ₗ[R] N) (i : α) (m : M) : Finsupp.lsum S f (Finsupp.single i m) = f i m := Finsupp.sum_single_index (f i).map_zero #align finsupp.lsum_single Finsupp.lsum_single @[simp] theorem lsum_comp_lsingle (f : α → M →ₗ[R] N) (i : α) : Finsupp.lsum S f ∘ₗ lsingle i = f i := by ext; simp theorem lsum_symm_apply (f : (α →₀ M) →ₗ[R] N) (x : α) : (lsum S).symm f x = f.comp (lsingle x) := rfl #align finsupp.lsum_symm_apply Finsupp.lsum_symm_apply end LSum section variable (M) (R) (X : Type*) (S) variable [Module S M] [SMulCommClass R S M] /-- A slight rearrangement from `lsum` gives us the bijection underlying the free-forgetful adjunction for R-modules. -/ noncomputable def lift : (X → M) ≃+ ((X →₀ R) →ₗ[R] M) := (AddEquiv.arrowCongr (Equiv.refl X) (ringLmapEquivSelf R ℕ M).toAddEquiv.symm).trans (lsum _ : _ ≃ₗ[ℕ] _).toAddEquiv #align finsupp.lift Finsupp.lift @[simp] theorem lift_symm_apply (f) (x) : ((lift M R X).symm f) x = f (single x 1) := rfl #align finsupp.lift_symm_apply Finsupp.lift_symm_apply @[simp] theorem lift_apply (f) (g) : ((lift M R X) f) g = g.sum fun x r => r • f x := rfl #align finsupp.lift_apply Finsupp.lift_apply /-- Given compatible `S` and `R`-module structures on `M` and a type `X`, the set of functions `X → M` is `S`-linearly equivalent to the `R`-linear maps from the free `R`-module on `X` to `M`. -/ noncomputable def llift : (X → M) ≃ₗ[S] (X →₀ R) →ₗ[R] M := { lift M R X with map_smul' := by intros dsimp ext simp only [coe_comp, Function.comp_apply, lsingle_apply, lift_apply, Pi.smul_apply, sum_single_index, zero_smul, one_smul, LinearMap.smul_apply] } #align finsupp.llift Finsupp.llift @[simp] theorem llift_apply (f : X → M) (x : X →₀ R) : llift M R S X f x = lift M R X f x := rfl #align finsupp.llift_apply Finsupp.llift_apply @[simp] theorem llift_symm_apply (f : (X →₀ R) →ₗ[R] M) (x : X) : (llift M R S X).symm f x = f (single x 1) := rfl #align finsupp.llift_symm_apply Finsupp.llift_symm_apply end section LMapDomain variable {α' : Type*} {α'' : Type*} (M R) /-- Interpret `Finsupp.mapDomain` as a linear map. -/ def lmapDomain (f : α → α') : (α →₀ M) →ₗ[R] α' →₀ M where toFun := mapDomain f map_add' _ _ := mapDomain_add map_smul' := mapDomain_smul #align finsupp.lmap_domain Finsupp.lmapDomain @[simp] theorem lmapDomain_apply (f : α → α') (l : α →₀ M) : (lmapDomain M R f : (α →₀ M) →ₗ[R] α' →₀ M) l = mapDomain f l := rfl #align finsupp.lmap_domain_apply Finsupp.lmapDomain_apply @[simp] theorem lmapDomain_id : (lmapDomain M R _root_.id : (α →₀ M) →ₗ[R] α →₀ M) = LinearMap.id := LinearMap.ext fun _ => mapDomain_id #align finsupp.lmap_domain_id Finsupp.lmapDomain_id theorem lmapDomain_comp (f : α → α') (g : α' → α'') : lmapDomain M R (g ∘ f) = (lmapDomain M R g).comp (lmapDomain M R f) := LinearMap.ext fun _ => mapDomain_comp #align finsupp.lmap_domain_comp Finsupp.lmapDomain_comp theorem supported_comap_lmapDomain (f : α → α') (s : Set α') : supported M R (f ⁻¹' s) ≤ (supported M R s).comap (lmapDomain M R f) := by classical intro l (hl : (l.support : Set α) ⊆ f ⁻¹' s) show ↑(mapDomain f l).support ⊆ s rw [← Set.image_subset_iff, ← Finset.coe_image] at hl exact Set.Subset.trans mapDomain_support hl #align finsupp.supported_comap_lmap_domain Finsupp.supported_comap_lmapDomain theorem lmapDomain_supported (f : α → α') (s : Set α) : (supported M R s).map (lmapDomain M R f) = supported M R (f '' s) := by classical cases isEmpty_or_nonempty α · simp [s.eq_empty_of_isEmpty] refine le_antisymm (map_le_iff_le_comap.2 <| le_trans (supported_mono <| Set.subset_preimage_image _ _) (supported_comap_lmapDomain M R _ _)) ?_ intro l hl refine ⟨(lmapDomain M R (Function.invFunOn f s) : (α' →₀ M) →ₗ[R] α →₀ M) l, fun x hx => ?_, ?_⟩ · rcases Finset.mem_image.1 (mapDomain_support hx) with ⟨c, hc, rfl⟩ exact Function.invFunOn_mem (by simpa using hl hc) · rw [← LinearMap.comp_apply, ← lmapDomain_comp] refine (mapDomain_congr fun c hc => ?_).trans mapDomain_id exact Function.invFunOn_eq (by simpa using hl hc) #align finsupp.lmap_domain_supported Finsupp.lmapDomain_supported theorem lmapDomain_disjoint_ker (f : α → α') {s : Set α} (H : ∀ a ∈ s, ∀ b ∈ s, f a = f b → a = b) : Disjoint (supported M R s) (ker (lmapDomain M R f)) := by rw [disjoint_iff_inf_le] rintro l ⟨h₁, h₂⟩ rw [SetLike.mem_coe, mem_ker, lmapDomain_apply, mapDomain] at h₂ simp; ext x haveI := Classical.decPred fun x => x ∈ s by_cases xs : x ∈ s · have : Finsupp.sum l (fun a => Finsupp.single (f a)) (f x) = 0 := by rw [h₂] rfl rw [Finsupp.sum_apply, Finsupp.sum_eq_single x, single_eq_same] at this · simpa · intro y hy xy simp only [SetLike.mem_coe, mem_supported, subset_def, Finset.mem_coe, mem_support_iff] at h₁ simp [mt (H _ (h₁ _ hy) _ xs) xy] · simp (config := { contextual := true }) · by_contra h exact xs (h₁ <| Finsupp.mem_support_iff.2 h) #align finsupp.lmap_domain_disjoint_ker Finsupp.lmapDomain_disjoint_ker end LMapDomain section LComapDomain variable {β : Type*} /-- Given `f : α → β` and a proof `hf` that `f` is injective, `lcomapDomain f hf` is the linear map sending `l : β →₀ M` to the finitely supported function from `α` to `M` given by composing `l` with `f`. This is the linear version of `Finsupp.comapDomain`. -/ def lcomapDomain (f : α → β) (hf : Function.Injective f) : (β →₀ M) →ₗ[R] α →₀ M where toFun l := Finsupp.comapDomain f l hf.injOn map_add' x y := by ext; simp map_smul' c x := by ext; simp #align finsupp.lcomap_domain Finsupp.lcomapDomain end LComapDomain section Total variable (α) (M) (R) variable {α' : Type*} {M' : Type*} [AddCommMonoid M'] [Module R M'] (v : α → M) {v' : α' → M'} /-- Interprets (l : α →₀ R) as linear combination of the elements in the family (v : α → M) and evaluates this linear combination. -/ protected def total : (α →₀ R) →ₗ[R] M := Finsupp.lsum ℕ fun i => LinearMap.id.smulRight (v i) #align finsupp.total Finsupp.total variable {α M v} theorem total_apply (l : α →₀ R) : Finsupp.total α M R v l = l.sum fun i a => a • v i := rfl #align finsupp.total_apply Finsupp.total_apply theorem total_apply_of_mem_supported {l : α →₀ R} {s : Finset α} (hs : l ∈ supported R R (↑s : Set α)) : Finsupp.total α M R v l = s.sum fun i => l i • v i := Finset.sum_subset hs fun x _ hxg => show l x • v x = 0 by rw [not_mem_support_iff.1 hxg, zero_smul] #align finsupp.total_apply_of_mem_supported Finsupp.total_apply_of_mem_supported @[simp] theorem total_single (c : R) (a : α) : Finsupp.total α M R v (single a c) = c • v a := by simp [total_apply, sum_single_index] #align finsupp.total_single Finsupp.total_single theorem total_zero_apply (x : α →₀ R) : (Finsupp.total α M R 0) x = 0 := by simp [Finsupp.total_apply] #align finsupp.total_zero_apply Finsupp.total_zero_apply variable (α M) @[simp] theorem total_zero : Finsupp.total α M R 0 = 0 := LinearMap.ext (total_zero_apply R) #align finsupp.total_zero Finsupp.total_zero variable {α M} theorem apply_total (f : M →ₗ[R] M') (v) (l : α →₀ R) : f (Finsupp.total α M R v l) = Finsupp.total α M' R (f ∘ v) l := by apply Finsupp.induction_linear l <;> simp (config := { contextual := true }) #align finsupp.apply_total Finsupp.apply_total theorem apply_total_id (f : M →ₗ[R] M') (l : M →₀ R) : f (Finsupp.total M M R _root_.id l) = Finsupp.total M M' R f l := apply_total .. theorem total_unique [Unique α] (l : α →₀ R) (v) : Finsupp.total α M R v l = l default • v default := by rw [← total_single, ← unique_single l] #align finsupp.total_unique Finsupp.total_unique theorem total_surjective (h : Function.Surjective v) : Function.Surjective (Finsupp.total α M R v) := by intro x obtain ⟨y, hy⟩ := h x exact ⟨Finsupp.single y 1, by simp [hy]⟩ #align finsupp.total_surjective Finsupp.total_surjective theorem total_range (h : Function.Surjective v) : LinearMap.range (Finsupp.total α M R v) = ⊤ := range_eq_top.2 <| total_surjective R h #align finsupp.total_range Finsupp.total_range /-- Any module is a quotient of a free module. This is stated as surjectivity of `Finsupp.total M M R id : (M →₀ R) →ₗ[R] M`. -/ theorem total_id_surjective (M) [AddCommMonoid M] [Module R M] : Function.Surjective (Finsupp.total M M R _root_.id) := total_surjective R Function.surjective_id #align finsupp.total_id_surjective Finsupp.total_id_surjective theorem range_total : LinearMap.range (Finsupp.total α M R v) = span R (range v) := by ext x constructor · intro hx rw [LinearMap.mem_range] at hx rcases hx with ⟨l, hl⟩ rw [← hl] rw [Finsupp.total_apply] exact sum_mem fun i _ => Submodule.smul_mem _ _ (subset_span (mem_range_self i)) · apply span_le.2 intro x hx rcases hx with ⟨i, hi⟩ rw [SetLike.mem_coe, LinearMap.mem_range] use Finsupp.single i 1 simp [hi] #align finsupp.range_total Finsupp.range_total theorem lmapDomain_total (f : α → α') (g : M →ₗ[R] M') (h : ∀ i, g (v i) = v' (f i)) : (Finsupp.total α' M' R v').comp (lmapDomain R R f) = g.comp (Finsupp.total α M R v) := by ext l simp [total_apply, Finsupp.sum_mapDomain_index, add_smul, h] #align finsupp.lmap_domain_total Finsupp.lmapDomain_total theorem total_comp_lmapDomain (f : α → α') : (Finsupp.total α' M' R v').comp (Finsupp.lmapDomain R R f) = Finsupp.total α M' R (v' ∘ f) := by ext simp #align finsupp.total_comp_lmap_domain Finsupp.total_comp_lmapDomain @[simp] theorem total_embDomain (f : α ↪ α') (l : α →₀ R) : (Finsupp.total α' M' R v') (embDomain f l) = (Finsupp.total α M' R (v' ∘ f)) l := by simp [total_apply, Finsupp.sum, support_embDomain, embDomain_apply] #align finsupp.total_emb_domain Finsupp.total_embDomain @[simp] theorem total_mapDomain (f : α → α') (l : α →₀ R) : (Finsupp.total α' M' R v') (mapDomain f l) = (Finsupp.total α M' R (v' ∘ f)) l := LinearMap.congr_fun (total_comp_lmapDomain _ _) l #align finsupp.total_map_domain Finsupp.total_mapDomain @[simp] theorem total_equivMapDomain (f : α ≃ α') (l : α →₀ R) : (Finsupp.total α' M' R v') (equivMapDomain f l) = (Finsupp.total α M' R (v' ∘ f)) l := by rw [equivMapDomain_eq_mapDomain, total_mapDomain] #align finsupp.total_equiv_map_domain Finsupp.total_equivMapDomain /-- A version of `Finsupp.range_total` which is useful for going in the other direction -/ theorem span_eq_range_total (s : Set M) : span R s = LinearMap.range (Finsupp.total s M R (↑)) := by rw [range_total, Subtype.range_coe_subtype, Set.setOf_mem_eq] #align finsupp.span_eq_range_total Finsupp.span_eq_range_total theorem mem_span_iff_total (s : Set M) (x : M) : x ∈ span R s ↔ ∃ l : s →₀ R, Finsupp.total s M R (↑) l = x := (SetLike.ext_iff.1 <| span_eq_range_total _ _) x #align finsupp.mem_span_iff_total Finsupp.mem_span_iff_total variable {R} theorem mem_span_range_iff_exists_finsupp {v : α → M} {x : M} : x ∈ span R (range v) ↔ ∃ c : α →₀ R, (c.sum fun i a => a • v i) = x := by simp only [← Finsupp.range_total, LinearMap.mem_range, Finsupp.total_apply] #align finsupp.mem_span_range_iff_exists_finsupp Finsupp.mem_span_range_iff_exists_finsupp variable (R) theorem span_image_eq_map_total (s : Set α) : span R (v '' s) = Submodule.map (Finsupp.total α M R v) (supported R R s) := by apply span_eq_of_le · intro x hx rw [Set.mem_image] at hx apply Exists.elim hx intro i hi exact ⟨_, Finsupp.single_mem_supported R 1 hi.1, by simp [hi.2]⟩ · refine map_le_iff_le_comap.2 fun z hz => ?_ have : ∀ i, z i • v i ∈ span R (v '' s) := by intro c haveI := Classical.decPred fun x => x ∈ s by_cases h : c ∈ s · exact smul_mem _ _ (subset_span (Set.mem_image_of_mem _ h)) · simp [(Finsupp.mem_supported' R _).1 hz _ h] -- Porting note: `rw` is required to infer metavariables in `sum_mem`. rw [mem_comap, total_apply] refine sum_mem ?_ simp [this] #align finsupp.span_image_eq_map_total Finsupp.span_image_eq_map_total theorem mem_span_image_iff_total {s : Set α} {x : M} : x ∈ span R (v '' s) ↔ ∃ l ∈ supported R R s, Finsupp.total α M R v l = x := by rw [span_image_eq_map_total] simp #align finsupp.mem_span_image_iff_total Finsupp.mem_span_image_iff_total theorem total_option (v : Option α → M) (f : Option α →₀ R) : Finsupp.total (Option α) M R v f = f none • v none + Finsupp.total α M R (v ∘ Option.some) f.some := by rw [total_apply, sum_option_index_smul, total_apply]; simp #align finsupp.total_option Finsupp.total_option theorem total_total {α β : Type*} (A : α → M) (B : β → α →₀ R) (f : β →₀ R) : Finsupp.total α M R A (Finsupp.total β (α →₀ R) R B f) = Finsupp.total β M R (fun b => Finsupp.total α M R A (B b)) f := by classical simp only [total_apply] apply induction_linear f · simp only [sum_zero_index] · intro f₁ f₂ h₁ h₂ simp [sum_add_index, h₁, h₂, add_smul] · simp [sum_single_index, sum_smul_index, smul_sum, mul_smul] #align finsupp.total_total Finsupp.total_total @[simp] theorem total_fin_zero (f : Fin 0 → M) : Finsupp.total (Fin 0) M R f = 0 := by ext i apply finZeroElim i #align finsupp.total_fin_zero Finsupp.total_fin_zero variable (α) (M) (v) /-- `Finsupp.totalOn M v s` interprets `p : α →₀ R` as a linear combination of a subset of the vectors in `v`, mapping it to the span of those vectors. The subset is indicated by a set `s : Set α` of indices. -/ protected def totalOn (s : Set α) : supported R R s →ₗ[R] span R (v '' s) := LinearMap.codRestrict _ ((Finsupp.total _ _ _ v).comp (Submodule.subtype (supported R R s))) fun ⟨l, hl⟩ => (mem_span_image_iff_total _).2 ⟨l, hl, rfl⟩ #align finsupp.total_on Finsupp.totalOn variable {α} {M} {v} theorem totalOn_range (s : Set α) : LinearMap.range (Finsupp.totalOn α M R v s) = ⊤ := by rw [Finsupp.totalOn, LinearMap.range_eq_map, LinearMap.map_codRestrict, ← LinearMap.range_le_iff_comap, range_subtype, Submodule.map_top, LinearMap.range_comp, range_subtype] exact (span_image_eq_map_total _ _).le #align finsupp.total_on_range Finsupp.totalOn_range theorem total_comp (f : α' → α) : Finsupp.total α' M R (v ∘ f) = (Finsupp.total α M R v).comp (lmapDomain R R f) := by ext simp [total_apply] #align finsupp.total_comp Finsupp.total_comp theorem total_comapDomain (f : α → α') (l : α' →₀ R) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) : Finsupp.total α M R v (Finsupp.comapDomain f l hf) = (l.support.preimage f hf).sum fun i => l (f i) • v i := by rw [Finsupp.total_apply]; rfl #align finsupp.total_comap_domain Finsupp.total_comapDomain theorem total_onFinset {s : Finset α} {f : α → R} (g : α → M) (hf : ∀ a, f a ≠ 0 → a ∈ s) : Finsupp.total α M R g (Finsupp.onFinset s f hf) = Finset.sum s fun x : α => f x • g x := by classical simp only [Finsupp.total_apply, Finsupp.sum, Finsupp.onFinset_apply, Finsupp.support_onFinset] rw [Finset.sum_filter_of_ne] intro x _ h contrapose! h simp [h] #align finsupp.total_on_finset Finsupp.total_onFinset end Total /-- An equivalence of domains induces a linear equivalence of finitely supported functions. This is `Finsupp.domCongr` as a `LinearEquiv`. See also `LinearMap.funCongrLeft` for the case of arbitrary functions. -/ protected def domLCongr {α₁ α₂ : Type*} (e : α₁ ≃ α₂) : (α₁ →₀ M) ≃ₗ[R] α₂ →₀ M := (Finsupp.domCongr e : (α₁ →₀ M) ≃+ (α₂ →₀ M)).toLinearEquiv <| by simpa only [equivMapDomain_eq_mapDomain, domCongr_apply] using (lmapDomain M R e).map_smul #align finsupp.dom_lcongr Finsupp.domLCongr @[simp] theorem domLCongr_apply {α₁ : Type*} {α₂ : Type*} (e : α₁ ≃ α₂) (v : α₁ →₀ M) : (Finsupp.domLCongr e : _ ≃ₗ[R] _) v = Finsupp.domCongr e v := rfl #align finsupp.dom_lcongr_apply Finsupp.domLCongr_apply @[simp] theorem domLCongr_refl : Finsupp.domLCongr (Equiv.refl α) = LinearEquiv.refl R (α →₀ M) := LinearEquiv.ext fun _ => equivMapDomain_refl _ #align finsupp.dom_lcongr_refl Finsupp.domLCongr_refl theorem domLCongr_trans {α₁ α₂ α₃ : Type*} (f : α₁ ≃ α₂) (f₂ : α₂ ≃ α₃) : (Finsupp.domLCongr f).trans (Finsupp.domLCongr f₂) = (Finsupp.domLCongr (f.trans f₂) : (_ →₀ M) ≃ₗ[R] _) := LinearEquiv.ext fun _ => (equivMapDomain_trans _ _ _).symm #align finsupp.dom_lcongr_trans Finsupp.domLCongr_trans @[simp] theorem domLCongr_symm {α₁ α₂ : Type*} (f : α₁ ≃ α₂) : ((Finsupp.domLCongr f).symm : (_ →₀ M) ≃ₗ[R] _) = Finsupp.domLCongr f.symm := LinearEquiv.ext fun _ => rfl #align finsupp.dom_lcongr_symm Finsupp.domLCongr_symm -- @[simp] -- Porting note (#10618): simp can prove this theorem domLCongr_single {α₁ : Type*} {α₂ : Type*} (e : α₁ ≃ α₂) (i : α₁) (m : M) : (Finsupp.domLCongr e : _ ≃ₗ[R] _) (Finsupp.single i m) = Finsupp.single (e i) m := by simp #align finsupp.dom_lcongr_single Finsupp.domLCongr_single /-- An equivalence of sets induces a linear equivalence of `Finsupp`s supported on those sets. -/ noncomputable def congr {α' : Type*} (s : Set α) (t : Set α') (e : s ≃ t) : supported M R s ≃ₗ[R] supported M R t := by haveI := Classical.decPred fun x => x ∈ s haveI := Classical.decPred fun x => x ∈ t exact Finsupp.supportedEquivFinsupp s ≪≫ₗ (Finsupp.domLCongr e ≪≫ₗ (Finsupp.supportedEquivFinsupp t).symm) #align finsupp.congr Finsupp.congr /-- `Finsupp.mapRange` as a `LinearMap`. -/ def mapRange.linearMap (f : M →ₗ[R] N) : (α →₀ M) →ₗ[R] α →₀ N := { mapRange.addMonoidHom f.toAddMonoidHom with toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N) -- Porting note: `hf` should be specified. map_smul' := fun c v => mapRange_smul (hf := f.map_zero) c v (f.map_smul c) } #align finsupp.map_range.linear_map Finsupp.mapRange.linearMap -- Porting note: This was generated by `simps!`. @[simp] theorem mapRange.linearMap_apply (f : M →ₗ[R] N) (g : α →₀ M) : mapRange.linearMap f g = mapRange f f.map_zero g := rfl #align finsupp.map_range.linear_map_apply Finsupp.mapRange.linearMap_apply @[simp] theorem mapRange.linearMap_id : mapRange.linearMap LinearMap.id = (LinearMap.id : (α →₀ M) →ₗ[R] _) := LinearMap.ext mapRange_id #align finsupp.map_range.linear_map_id Finsupp.mapRange.linearMap_id theorem mapRange.linearMap_comp (f : N →ₗ[R] P) (f₂ : M →ₗ[R] N) : (mapRange.linearMap (f.comp f₂) : (α →₀ _) →ₗ[R] _) = (mapRange.linearMap f).comp (mapRange.linearMap f₂) := -- Porting note: Placeholders should be filled. LinearMap.ext <| mapRange_comp f f.map_zero f₂ f₂.map_zero (comp f f₂).map_zero #align finsupp.map_range.linear_map_comp Finsupp.mapRange.linearMap_comp @[simp] theorem mapRange.linearMap_toAddMonoidHom (f : M →ₗ[R] N) : (mapRange.linearMap f).toAddMonoidHom = (mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ M) →+ _) := AddMonoidHom.ext fun _ => rfl #align finsupp.map_range.linear_map_to_add_monoid_hom Finsupp.mapRange.linearMap_toAddMonoidHom /-- `Finsupp.mapRange` as a `LinearEquiv`. -/ def mapRange.linearEquiv (e : M ≃ₗ[R] N) : (α →₀ M) ≃ₗ[R] α →₀ N := { mapRange.linearMap e.toLinearMap, mapRange.addEquiv e.toAddEquiv with toFun := mapRange e e.map_zero invFun := mapRange e.symm e.symm.map_zero } #align finsupp.map_range.linear_equiv Finsupp.mapRange.linearEquiv -- Porting note: This was generated by `simps`. @[simp] theorem mapRange.linearEquiv_apply (e : M ≃ₗ[R] N) (g : α →₀ M) : mapRange.linearEquiv e g = mapRange.linearMap e.toLinearMap g := rfl #align finsupp.map_range.linear_equiv_apply Finsupp.mapRange.linearEquiv_apply @[simp] theorem mapRange.linearEquiv_refl : mapRange.linearEquiv (LinearEquiv.refl R M) = LinearEquiv.refl R (α →₀ M) := LinearEquiv.ext mapRange_id #align finsupp.map_range.linear_equiv_refl Finsupp.mapRange.linearEquiv_refl theorem mapRange.linearEquiv_trans (f : M ≃ₗ[R] N) (f₂ : N ≃ₗ[R] P) : (mapRange.linearEquiv (f.trans f₂) : (α →₀ _) ≃ₗ[R] _) = (mapRange.linearEquiv f).trans (mapRange.linearEquiv f₂) := -- Porting note: Placeholders should be filled. LinearEquiv.ext <| mapRange_comp f₂ f₂.map_zero f f.map_zero (f.trans f₂).map_zero #align finsupp.map_range.linear_equiv_trans Finsupp.mapRange.linearEquiv_trans @[simp] theorem mapRange.linearEquiv_symm (f : M ≃ₗ[R] N) : ((mapRange.linearEquiv f).symm : (α →₀ _) ≃ₗ[R] _) = mapRange.linearEquiv f.symm := LinearEquiv.ext fun _x => rfl #align finsupp.map_range.linear_equiv_symm Finsupp.mapRange.linearEquiv_symm -- Porting note: This priority should be higher than `LinearEquiv.coe_toAddEquiv`. @[simp 1500] theorem mapRange.linearEquiv_toAddEquiv (f : M ≃ₗ[R] N) : (mapRange.linearEquiv f).toAddEquiv = (mapRange.addEquiv f.toAddEquiv : (α →₀ M) ≃+ _) := AddEquiv.ext fun _ => rfl #align finsupp.map_range.linear_equiv_to_add_equiv Finsupp.mapRange.linearEquiv_toAddEquiv @[simp] theorem mapRange.linearEquiv_toLinearMap (f : M ≃ₗ[R] N) : (mapRange.linearEquiv f).toLinearMap = (mapRange.linearMap f.toLinearMap : (α →₀ M) →ₗ[R] _) := LinearMap.ext fun _ => rfl #align finsupp.map_range.linear_equiv_to_linear_map Finsupp.mapRange.linearEquiv_toLinearMap /-- An equivalence of domain and a linear equivalence of codomain induce a linear equivalence of the corresponding finitely supported functions. -/ def lcongr {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₗ[R] N) : (ι →₀ M) ≃ₗ[R] κ →₀ N := (Finsupp.domLCongr e₁).trans (mapRange.linearEquiv e₂) #align finsupp.lcongr Finsupp.lcongr @[simp]
Mathlib/LinearAlgebra/Finsupp.lean
1,019
1,020
theorem lcongr_single {ι κ : Sort _} (e₁ : ι ≃ κ) (e₂ : M ≃ₗ[R] N) (i : ι) (m : M) : lcongr e₁ e₂ (Finsupp.single i m) = Finsupp.single (e₁ i) (e₂ m) := by
simp [lcongr]
/- 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. -/
Mathlib/Topology/Order/IntermediateValue.lean
235
240
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⟩
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Jujian Zhang -/ import Mathlib.Algebra.Algebra.Bilinear import Mathlib.RingTheory.Localization.Basic #align_import algebra.module.localized_module from "leanprover-community/mathlib"@"831c494092374cfe9f50591ed0ac81a25efc5b86" /-! # Localized Module Given a commutative semiring `R`, a multiplicative subset `S ⊆ R` and an `R`-module `M`, we can localize `M` by `S`. This gives us a `Localization S`-module. ## Main definitions * `LocalizedModule.r` : the equivalence relation defining this localization, namely `(m, s) ≈ (m', s')` if and only if there is some `u : S` such that `u • s' • m = u • s • m'`. * `LocalizedModule M S` : the localized module by `S`. * `LocalizedModule.mk` : the canonical map sending `(m, s) : M × S ↦ m/s : LocalizedModule M S` * `LocalizedModule.liftOn` : any well defined function `f : M × S → α` respecting `r` descents to a function `LocalizedModule M S → α` * `LocalizedModule.liftOn₂` : any well defined function `f : M × S → M × S → α` respecting `r` descents to a function `LocalizedModule M S → LocalizedModule M S` * `LocalizedModule.mk_add_mk` : in the localized module `mk m s + mk m' s' = mk (s' • m + s • m') (s * s')` * `LocalizedModule.mk_smul_mk` : in the localized module, for any `r : R`, `s t : S`, `m : M`, we have `mk r s • mk m t = mk (r • m) (s * t)` where `mk r s : Localization S` is localized ring by `S`. * `LocalizedModule.isModule` : `LocalizedModule M S` is a `Localization S`-module. ## Future work * Redefine `Localization` for monoids and rings to coincide with `LocalizedModule`. -/ namespace LocalizedModule universe u v variable {R : Type u} [CommSemiring R] (S : Submonoid R) variable (M : Type v) [AddCommMonoid M] [Module R M] variable (T : Type*) [CommSemiring T] [Algebra R T] [IsLocalization S T] /-- The equivalence relation on `M × S` where `(m1, s1) ≈ (m2, s2)` if and only if for some (u : S), u * (s2 • m1 - s1 • m2) = 0-/ /- Porting note: We use small letter `r` since `R` is used for a ring. -/ def r (a b : M × S) : Prop := ∃ u : S, u • b.2 • a.1 = u • a.2 • b.1 #align localized_module.r LocalizedModule.r theorem r.isEquiv : IsEquiv _ (r S M) := { refl := fun ⟨m, s⟩ => ⟨1, by rw [one_smul]⟩ trans := fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m3, s3⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => by use u1 * u2 * s2 -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s3) • ·) hu1.symm have hu2' := congr_arg ((u1 * s1) • ·) hu2.symm simp only [← mul_smul, smul_assoc, mul_assoc, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu2', hu1'] symm := fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => ⟨u, hu.symm⟩ } #align localized_module.r.is_equiv LocalizedModule.r.isEquiv instance r.setoid : Setoid (M × S) where r := r S M iseqv := ⟨(r.isEquiv S M).refl, (r.isEquiv S M).symm _ _, (r.isEquiv S M).trans _ _ _⟩ #align localized_module.r.setoid LocalizedModule.r.setoid -- TODO: change `Localization` to use `r'` instead of `r` so that the two types are also defeq, -- `Localization S = LocalizedModule S R`. example {R} [CommSemiring R] (S : Submonoid R) : ⇑(Localization.r' S) = LocalizedModule.r S R := rfl /-- If `S` is a multiplicative subset of a ring `R` and `M` an `R`-module, then we can localize `M` by `S`. -/ -- Porting note(#5171): @[nolint has_nonempty_instance] def _root_.LocalizedModule : Type max u v := Quotient (r.setoid S M) #align localized_module LocalizedModule section variable {M S} /-- The canonical map sending `(m, s) ↦ m/s`-/ def mk (m : M) (s : S) : LocalizedModule S M := Quotient.mk' ⟨m, s⟩ #align localized_module.mk LocalizedModule.mk theorem mk_eq {m m' : M} {s s' : S} : mk m s = mk m' s' ↔ ∃ u : S, u • s' • m = u • s • m' := Quotient.eq' #align localized_module.mk_eq LocalizedModule.mk_eq @[elab_as_elim] theorem induction_on {β : LocalizedModule S M → Prop} (h : ∀ (m : M) (s : S), β (mk m s)) : ∀ x : LocalizedModule S M, β x := by rintro ⟨⟨m, s⟩⟩ exact h m s #align localized_module.induction_on LocalizedModule.induction_on @[elab_as_elim] theorem induction_on₂ {β : LocalizedModule S M → LocalizedModule S M → Prop} (h : ∀ (m m' : M) (s s' : S), β (mk m s) (mk m' s')) : ∀ x y, β x y := by rintro ⟨⟨m, s⟩⟩ ⟨⟨m', s'⟩⟩ exact h m m' s s' #align localized_module.induction_on₂ LocalizedModule.induction_on₂ /-- If `f : M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → α`. -/ def liftOn {α : Type*} (x : LocalizedModule S M) (f : M × S → α) (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') : α := Quotient.liftOn x f wd #align localized_module.lift_on LocalizedModule.liftOn theorem liftOn_mk {α : Type*} {f : M × S → α} (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') (m : M) (s : S) : liftOn (mk m s) f wd = f ⟨m, s⟩ := by convert Quotient.liftOn_mk f wd ⟨m, s⟩ #align localized_module.lift_on_mk LocalizedModule.liftOn_mk /-- If `f : M × S → M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → LocalizedModule M S → α`. -/ def liftOn₂ {α : Type*} (x y : LocalizedModule S M) (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') : α := Quotient.liftOn₂ x y f wd #align localized_module.lift_on₂ LocalizedModule.liftOn₂ theorem liftOn₂_mk {α : Type*} (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') (m m' : M) (s s' : S) : liftOn₂ (mk m s) (mk m' s') f wd = f ⟨m, s⟩ ⟨m', s'⟩ := by convert Quotient.liftOn₂_mk f wd _ _ #align localized_module.lift_on₂_mk LocalizedModule.liftOn₂_mk instance : Zero (LocalizedModule S M) := ⟨mk 0 1⟩ /-- If `S` contains `0` then the localization at `S` is trivial. -/ theorem subsingleton (h : 0 ∈ S) : Subsingleton (LocalizedModule S M) := by refine ⟨fun a b ↦ ?_⟩ induction a,b using LocalizedModule.induction_on₂ exact mk_eq.mpr ⟨⟨0, h⟩, by simp only [Submonoid.mk_smul, zero_smul]⟩ @[simp] theorem zero_mk (s : S) : mk (0 : M) s = 0 := mk_eq.mpr ⟨1, by rw [one_smul, smul_zero, smul_zero, one_smul]⟩ #align localized_module.zero_mk LocalizedModule.zero_mk instance : Add (LocalizedModule S M) where add p1 p2 := liftOn₂ p1 p2 (fun x y => mk (y.2 • x.1 + x.2 • y.1) (x.2 * y.2)) <| fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m1', s1'⟩ ⟨m2', s2'⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => mk_eq.mpr ⟨u1 * u2, by -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s2 * s2') • ·) hu1 have hu2' := congr_arg ((u1 * s1 * s1') • ·) hu2 simp only [smul_add, ← mul_smul, smul_assoc, mul_assoc, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu1', hu2']⟩ theorem mk_add_mk {m1 m2 : M} {s1 s2 : S} : mk m1 s1 + mk m2 s2 = mk (s2 • m1 + s1 • m2) (s1 * s2) := mk_eq.mpr <| ⟨1, rfl⟩ #align localized_module.mk_add_mk LocalizedModule.mk_add_mk /-- Porting note: Some auxiliary lemmas are declared with `private` in the original mathlib3 file. We take that policy here as well, and remove the `#align` lines accordingly. -/ private theorem add_assoc' (x y z : LocalizedModule S M) : x + y + z = x + (y + z) := by induction' x using LocalizedModule.induction_on with mx sx induction' y using LocalizedModule.induction_on with my sy induction' z using LocalizedModule.induction_on with mz sz simp only [mk_add_mk, smul_add] refine mk_eq.mpr ⟨1, ?_⟩ rw [one_smul, one_smul] congr 1 · rw [mul_assoc] · rw [eq_comm, mul_comm, add_assoc, mul_smul, mul_smul, ← mul_smul sx sz, mul_comm, mul_smul] private theorem add_comm' (x y : LocalizedModule S M) : x + y = y + x := LocalizedModule.induction_on₂ (fun m m' s s' => by rw [mk_add_mk, mk_add_mk, add_comm, mul_comm]) x y private theorem zero_add' (x : LocalizedModule S M) : 0 + x = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, zero_add, mk_eq]; exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x private theorem add_zero' (x : LocalizedModule S M) : x + 0 = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, add_zero, mk_eq]; exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x instance hasNatSMul : SMul ℕ (LocalizedModule S M) where smul n := nsmulRec n #align localized_module.has_nat_smul LocalizedModule.hasNatSMul private theorem nsmul_zero' (x : LocalizedModule S M) : (0 : ℕ) • x = 0 := LocalizedModule.induction_on (fun _ _ => rfl) x private theorem nsmul_succ' (n : ℕ) (x : LocalizedModule S M) : n.succ • x = n • x + x := LocalizedModule.induction_on (fun _ _ => rfl) x instance : AddCommMonoid (LocalizedModule S M) where add := (· + ·) add_assoc := add_assoc' zero := 0 zero_add := zero_add' add_zero := add_zero' nsmul := (· • ·) nsmul_zero := nsmul_zero' nsmul_succ := nsmul_succ' add_comm := add_comm' instance {M : Type*} [AddCommGroup M] [Module R M] : Neg (LocalizedModule S M) where neg p := liftOn p (fun x => LocalizedModule.mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩ instance {M : Type*} [AddCommGroup M] [Module R M] : AddCommGroup (LocalizedModule S M) := { show AddCommMonoid (LocalizedModule S M) by infer_instance with add_left_neg := by rintro ⟨m, s⟩ change (liftOn (mk m s) (fun x => mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩) + mk m s = 0 rw [liftOn_mk, mk_add_mk] simp -- TODO: fix the diamond zsmul := zsmulRec } theorem mk_neg {M : Type*} [AddCommGroup M] [Module R M] {m : M} {s : S} : mk (-m) s = -mk m s := rfl #align localized_module.mk_neg LocalizedModule.mk_neg instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Monoid (LocalizedModule S A) := { mul := fun m₁ m₂ => liftOn₂ m₁ m₂ (fun x₁ x₂ => LocalizedModule.mk (x₁.1 * x₂.1) (x₁.2 * x₂.2)) (by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨b₁, t₁⟩ ⟨b₂, t₂⟩ ⟨u₁, e₁⟩ ⟨u₂, e₂⟩ rw [mk_eq] use u₁ * u₂ dsimp only at e₁ e₂ ⊢ rw [eq_comm] trans (u₁ • t₁ • a₁) • u₂ • t₂ • a₂ on_goal 1 => rw [e₁, e₂] on_goal 2 => rw [eq_comm] all_goals rw [smul_smul, mul_mul_mul_comm, ← smul_eq_mul, ← smul_eq_mul A, smul_smul_smul_comm, mul_smul, mul_smul]) one := mk 1 (1 : S) one_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [one_mul, one_smul]⟩ mul_one := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_one, one_smul]⟩ mul_assoc := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_smul, ← mul_assoc, mul_right_comm] } instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Semiring (LocalizedModule S A) := { show (AddCommMonoid (LocalizedModule S A)) by infer_instance, show (Monoid (LocalizedModule S A)) by infer_instance with left_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, mul_add, mul_smul_comm, smul_smul, ← mul_assoc, mul_right_comm] right_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, add_mul, smul_smul, ← mul_assoc, smul_mul_assoc, mul_right_comm] zero_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [zero_mul, smul_zero]⟩ mul_zero := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_zero, smul_zero]⟩ } instance {A : Type*} [CommSemiring A] [Algebra R A] {S : Submonoid R} : CommSemiring (LocalizedModule S A) := { show Semiring (LocalizedModule S A) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } instance {A : Type*} [Ring A] [Algebra R A] {S : Submonoid R} : Ring (LocalizedModule S A) := { inferInstanceAs (AddCommGroup (LocalizedModule S A)), inferInstanceAs (Semiring (LocalizedModule S A)) with } instance {A : Type*} [CommRing A] [Algebra R A] {S : Submonoid R} : CommRing (LocalizedModule S A) := { show (Ring (LocalizedModule S A)) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } theorem mk_mul_mk {A : Type*} [Semiring A] [Algebra R A] {a₁ a₂ : A} {s₁ s₂ : S} : mk a₁ s₁ * mk a₂ s₂ = mk (a₁ * a₂) (s₁ * s₂) := rfl #align localized_module.mk_mul_mk LocalizedModule.mk_mul_mk noncomputable instance : SMul T (LocalizedModule S M) where smul x p := let a := IsLocalization.sec S x liftOn p (fun p ↦ mk (a.1 • p.1) (a.2 * p.2)) (by rintro p p' ⟨s, h⟩ refine mk_eq.mpr ⟨s, ?_⟩ calc _ = a.2 • a.1 • s • p'.2 • p.1 := by simp_rw [Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul]; ring_nf _ = a.2 • a.1 • s • p.2 • p'.1 := by rw [h] _ = s • (a.2 * p.2) • a.1 • p'.1 := by simp_rw [Submonoid.smul_def, ← mul_smul, Submonoid.coe_mul]; ring_nf ) theorem smul_def (x : T) (m : M) (s : S) : x • mk m s = mk ((IsLocalization.sec S x).1 • m) ((IsLocalization.sec S x).2 * s) := rfl theorem mk'_smul_mk (r : R) (m : M) (s s' : S) : IsLocalization.mk' T r s • mk m s' = mk (r • m) (s * s') := by rw [smul_def, mk_eq] obtain ⟨c, hc⟩ := IsLocalization.eq.mp <| IsLocalization.mk'_sec T (IsLocalization.mk' T r s) use c simp_rw [← mul_smul, Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul, ← mul_assoc, mul_comm _ (s':R), mul_assoc, hc] theorem mk_smul_mk (r : R) (m : M) (s t : S) : Localization.mk r s • mk m t = mk (r • m) (s * t) := by rw [Localization.mk_eq_mk'] exact mk'_smul_mk .. #align localized_module.mk_smul_mk LocalizedModule.mk_smul_mk variable {T} private theorem one_smul_aux (p : LocalizedModule S M) : (1 : T) • p = p := by induction' p using LocalizedModule.induction_on with m s rw [show (1:T) = IsLocalization.mk' T (1:R) (1:S) by rw [IsLocalization.mk'_one, map_one]] rw [mk'_smul_mk, one_smul, one_mul] private theorem mul_smul_aux (x y : T) (p : LocalizedModule S M) : (x * y) • p = x • y • p := by induction' p using LocalizedModule.induction_on with m s rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y] simp_rw [← IsLocalization.mk'_mul, mk'_smul_mk, ← mul_smul, mul_assoc] private theorem smul_add_aux (x : T) (p q : LocalizedModule S M) : x • (p + q) = x • p + x • q := by induction' p using LocalizedModule.induction_on with m s induction' q using LocalizedModule.induction_on with n t rw [smul_def, smul_def, mk_add_mk, mk_add_mk] rw [show x • _ = IsLocalization.mk' T _ _ • _ by rw [IsLocalization.mk'_sec (M := S) T]] rw [← IsLocalization.mk'_cancel _ _ (IsLocalization.sec S x).2, mk'_smul_mk] congr 1 · simp only [Submonoid.smul_def, smul_add, ← mul_smul, Submonoid.coe_mul]; ring_nf · rw [mul_mul_mul_comm] -- ring does not work here private theorem smul_zero_aux (x : T) : x • (0 : LocalizedModule S M) = 0 := by erw [smul_def, smul_zero, zero_mk] private theorem add_smul_aux (x y : T) (p : LocalizedModule S M) : (x + y) • p = x • p + y • p := by induction' p using LocalizedModule.induction_on with m s rw [smul_def T x, smul_def T y, mk_add_mk, show (x + y) • _ = IsLocalization.mk' T _ _ • _ by rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y, ← IsLocalization.mk'_add, IsLocalization.mk'_cancel _ _ s], mk'_smul_mk, ← smul_assoc, ← smul_assoc, ← add_smul] congr 1 · simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_eq_mul]; ring_nf · rw [mul_mul_mul_comm, mul_assoc] -- ring does not work here private theorem zero_smul_aux (p : LocalizedModule S M) : (0 : T) • p = 0 := by induction' p using LocalizedModule.induction_on with m s rw [show (0:T) = IsLocalization.mk' T (0:R) (1:S) by rw [IsLocalization.mk'_zero], mk'_smul_mk, zero_smul, zero_mk] noncomputable instance isModule : Module T (LocalizedModule S M) where smul := (· • ·) one_smul := one_smul_aux mul_smul := mul_smul_aux smul_add := smul_add_aux smul_zero := smul_zero_aux add_smul := add_smul_aux zero_smul := zero_smul_aux @[simp] theorem mk_cancel_common_left (s' s : S) (m : M) : mk (s' • m) (s' * s) = mk m s := mk_eq.mpr ⟨1, by simp only [mul_smul, one_smul] rw [smul_comm]⟩ #align localized_module.mk_cancel_common_left LocalizedModule.mk_cancel_common_left @[simp] theorem mk_cancel (s : S) (m : M) : mk (s • m) s = mk m 1 := mk_eq.mpr ⟨1, by simp⟩ #align localized_module.mk_cancel LocalizedModule.mk_cancel @[simp] theorem mk_cancel_common_right (s s' : S) (m : M) : mk (s' • m) (s * s') = mk m s := mk_eq.mpr ⟨1, by simp [mul_smul]⟩ #align localized_module.mk_cancel_common_right LocalizedModule.mk_cancel_common_right noncomputable instance isModule' : Module R (LocalizedModule S M) := { Module.compHom (LocalizedModule S M) <| algebraMap R (Localization S) with } #align localized_module.is_module' LocalizedModule.isModule' theorem smul'_mk (r : R) (s : S) (m : M) : r • mk m s = mk (r • m) s := by erw [mk_smul_mk r m 1 s, one_mul] #align localized_module.smul'_mk LocalizedModule.smul'_mk theorem smul'_mul {A : Type*} [Semiring A] [Algebra R A] (x : T) (p₁ p₂ : LocalizedModule S A) : x • p₁ * p₂ = x • (p₁ * p₂) := by induction p₁, p₂ using induction_on₂ with | _ a₁ s₁ a₂ s₂ => _ rw [mk_mul_mk, smul_def, smul_def, mk_mul_mk, mul_assoc, smul_mul_assoc] theorem mul_smul' {A : Type*} [Semiring A] [Algebra R A] (x : T) (p₁ p₂ : LocalizedModule S A) : p₁ * x • p₂ = x • (p₁ * p₂) := by induction p₁, p₂ using induction_on₂ with | _ a₁ s₁ a₂ s₂ => _ rw [smul_def, mk_mul_mk, mk_mul_mk, smul_def, mul_left_comm, mul_smul_comm] variable (T) noncomputable instance {A : Type*} [Semiring A] [Algebra R A] : Algebra T (LocalizedModule S A) := Algebra.ofModule smul'_mul mul_smul' theorem algebraMap_mk' {A : Type*} [Semiring A] [Algebra R A] (a : R) (s : S) : algebraMap _ _ (IsLocalization.mk' T a s) = mk (algebraMap R A a) s := by rw [Algebra.algebraMap_eq_smul_one] change _ • mk _ _ = _ rw [mk'_smul_mk, Algebra.algebraMap_eq_smul_one, mul_one] theorem algebraMap_mk {A : Type*} [Semiring A] [Algebra R A] (a : R) (s : S) : algebraMap _ _ (Localization.mk a s) = mk (algebraMap R A a) s := by rw [Localization.mk_eq_mk'] exact algebraMap_mk' .. #align localized_module.algebra_map_mk LocalizedModule.algebraMap_mk instance : IsScalarTower R T (LocalizedModule S M) where smul_assoc r x p := by induction' p using LocalizedModule.induction_on with m s rw [← IsLocalization.mk'_sec (M := S) T x, IsLocalization.smul_mk', mk'_smul_mk, mk'_smul_mk, smul'_mk, mul_smul] noncomputable instance algebra' {A : Type*} [Semiring A] [Algebra R A] : Algebra R (LocalizedModule S A) := { (algebraMap (Localization S) (LocalizedModule S A)).comp (algebraMap R <| Localization S), show Module R (LocalizedModule S A) by infer_instance with commutes' := by intro r x induction x using induction_on with | _ a s => _ dsimp rw [← Localization.mk_one_eq_algebraMap, algebraMap_mk, mk_mul_mk, mk_mul_mk, mul_comm, Algebra.commutes] smul_def' := by intro r x induction x using induction_on with | _ a s => _ dsimp rw [← Localization.mk_one_eq_algebraMap, algebraMap_mk, mk_mul_mk, smul'_mk, Algebra.smul_def, one_mul] } #align localized_module.algebra' LocalizedModule.algebra' section variable (S M) /-- The function `m ↦ m / 1` as an `R`-linear map. -/ @[simps] def mkLinearMap : M →ₗ[R] LocalizedModule S M where toFun m := mk m 1 map_add' x y := by simp [mk_add_mk] map_smul' r x := (smul'_mk _ _ _).symm #align localized_module.mk_linear_map LocalizedModule.mkLinearMap end /-- For any `s : S`, there is an `R`-linear map given by `a/b ↦ a/(b*s)`. -/ @[simps] def divBy (s : S) : LocalizedModule S M →ₗ[R] LocalizedModule S M where toFun p := p.liftOn (fun p => mk p.1 (p.2 * s)) fun ⟨a, b⟩ ⟨a', b'⟩ ⟨c, eq1⟩ => mk_eq.mpr ⟨c, by rw [mul_smul, mul_smul, smul_comm _ s, smul_comm _ s, eq1, smul_comm _ s, smul_comm _ s]⟩ map_add' x y := by refine x.induction_on₂ ?_ y intro m₁ m₂ t₁ t₂ simp_rw [mk_add_mk, LocalizedModule.liftOn_mk, mk_add_mk, mul_smul, mul_comm _ s, mul_assoc, smul_comm _ s, ← smul_add, mul_left_comm s t₁ t₂, mk_cancel_common_left s] map_smul' r x := by refine x.induction_on (fun _ _ ↦ ?_) dsimp only change liftOn (mk _ _) _ _ = r • (liftOn (mk _ _) _ _) simp_rw [liftOn_mk, mul_assoc, ← smul_def] congr! #align localized_module.div_by LocalizedModule.divBy theorem divBy_mul_by (s : S) (p : LocalizedModule S M) : divBy s (algebraMap R (Module.End R (LocalizedModule S M)) s p) = p := p.induction_on fun m t => by rw [Module.algebraMap_end_apply, divBy_apply] erw [smul_def] rw [LocalizedModule.liftOn_mk, mul_assoc, ← smul_def] erw [smul'_mk] rw [← Submonoid.smul_def, mk_cancel_common_right _ s] #align localized_module.div_by_mul_by LocalizedModule.divBy_mul_by theorem mul_by_divBy (s : S) (p : LocalizedModule S M) : algebraMap R (Module.End R (LocalizedModule S M)) s (divBy s p) = p := p.induction_on fun m t => by rw [divBy_apply, Module.algebraMap_end_apply, LocalizedModule.liftOn_mk, smul'_mk, ← Submonoid.smul_def, mk_cancel_common_right _ s] #align localized_module.mul_by_div_by LocalizedModule.mul_by_divBy end end LocalizedModule section IsLocalizedModule universe u v variable {R : Type*} [CommSemiring R] (S : Submonoid R) variable {M M' M'' : Type*} [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M''] variable {A : Type*} [CommSemiring A] [Algebra R A] [Module A M'] [IsLocalization S A] variable [Module R M] [Module R M'] [Module R M''] [IsScalarTower R A M'] variable (f : M →ₗ[R] M') (g : M →ₗ[R] M'') /-- The characteristic predicate for localized module. `IsLocalizedModule S f` describes that `f : M ⟶ M'` is the localization map identifying `M'` as `LocalizedModule S M`. -/ @[mk_iff] class IsLocalizedModule : Prop where map_units : ∀ x : S, IsUnit (algebraMap R (Module.End R M') x) surj' : ∀ y : M', ∃ x : M × S, x.2 • y = f x.1 exists_of_eq : ∀ {x₁ x₂}, f x₁ = f x₂ → ∃ c : S, c • x₁ = c • x₂ #align is_localized_module IsLocalizedModule attribute [nolint docBlame] IsLocalizedModule.map_units IsLocalizedModule.surj' IsLocalizedModule.exists_of_eq -- Porting note: Manually added to make `S` and `f` explicit. lemma IsLocalizedModule.surj [IsLocalizedModule S f] (y : M') : ∃ x : M × S, x.2 • y = f x.1 := surj' y -- Porting note: Manually added to make `S` and `f` explicit. lemma IsLocalizedModule.eq_iff_exists [IsLocalizedModule S f] {x₁ x₂} : f x₁ = f x₂ ↔ ∃ c : S, c • x₁ = c • x₂ := Iff.intro exists_of_eq fun ⟨c, h⟩ ↦ by apply_fun f at h simp_rw [f.map_smul_of_tower, Submonoid.smul_def, ← Module.algebraMap_end_apply R R] at h exact ((Module.End_isUnit_iff _).mp <| map_units f c).1 h
Mathlib/Algebra/Module/LocalizedModule.lean
574
588
theorem IsLocalizedModule.of_linearEquiv (e : M' ≃ₗ[R] M'') [hf : IsLocalizedModule S f] : IsLocalizedModule S (e ∘ₗ f : M →ₗ[R] M'') where map_units s := by
rw [show algebraMap R (Module.End R M'') s = e ∘ₗ (algebraMap R (Module.End R M') s) ∘ₗ e.symm by ext; simp, Module.End_isUnit_iff, LinearMap.coe_comp, LinearMap.coe_comp, LinearEquiv.coe_coe, LinearEquiv.coe_coe, EquivLike.comp_bijective, EquivLike.bijective_comp] exact (Module.End_isUnit_iff _).mp <| hf.map_units s surj' x := by obtain ⟨p, h⟩ := hf.surj' (e.symm x) exact ⟨p, by rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, ← e.congr_arg h, Submonoid.smul_def, Submonoid.smul_def, LinearEquiv.map_smul, LinearEquiv.apply_symm_apply]⟩ exists_of_eq h := by simp_rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, EmbeddingLike.apply_eq_iff_eq] at h exact hf.exists_of_eq h
/- 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] 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)) #align monoid_hom.ker_eq_bot_of_cancel MonoidHom.ker_eq_bot_of_cancel #align add_monoid_hom.ker_eq_bot_of_cancel AddMonoidHom.ker_eq_bot_of_cancel end section variable [CommGroup A] [CommGroup B] @[to_additive] theorem range_eq_top_of_cancel {f : A →* B} (h : ∀ u v : B →* B ⧸ f.range, u.comp f = v.comp f → u = v) : f.range = ⊤ := by specialize h 1 (QuotientGroup.mk' _) _ · ext1 x simp only [one_apply, coe_comp, coe_mk', Function.comp_apply] rw [show (1 : B ⧸ f.range) = (1 : B) from QuotientGroup.mk_one _, QuotientGroup.eq, inv_one, one_mul] exact ⟨x, rfl⟩ replace h : (QuotientGroup.mk' f.range).ker = (1 : B →* B ⧸ f.range).ker := by rw [h] rwa [ker_one, QuotientGroup.ker_mk'] at h #align monoid_hom.range_eq_top_of_cancel MonoidHom.range_eq_top_of_cancel #align add_monoid_hom.range_eq_top_of_cancel AddMonoidHom.range_eq_top_of_cancel end end MonoidHom section open CategoryTheory namespace GroupCat set_option linter.uppercaseLean3 false -- Porting note: already have Group G but Lean can't use that @[to_additive] instance (G : GroupCat) : Group G.α := G.str variable {A B : GroupCat.{u}} (f : A ⟶ B) @[to_additive] theorem ker_eq_bot_of_mono [Mono f] : f.ker = ⊥ := MonoidHom.ker_eq_bot_of_cancel fun u _ => (@cancel_mono _ _ _ _ _ f _ (show GroupCat.of f.ker ⟶ A from u) _).1 #align Group.ker_eq_bot_of_mono GroupCat.ker_eq_bot_of_mono #align AddGroup.ker_eq_bot_of_mono AddGroupCat.ker_eq_bot_of_mono @[to_additive] theorem mono_iff_ker_eq_bot : Mono f ↔ f.ker = ⊥ := ⟨fun _ => ker_eq_bot_of_mono f, fun h => ConcreteCategory.mono_of_injective _ <| (MonoidHom.ker_eq_bot_iff f).1 h⟩ #align Group.mono_iff_ker_eq_bot GroupCat.mono_iff_ker_eq_bot #align AddGroup.mono_iff_ker_eq_bot AddGroupCat.mono_iff_ker_eq_bot @[to_additive] theorem mono_iff_injective : Mono f ↔ Function.Injective f := Iff.trans (mono_iff_ker_eq_bot f) <| MonoidHom.ker_eq_bot_iff f #align Group.mono_iff_injective GroupCat.mono_iff_injective #align AddGroup.mono_iff_injective AddGroupCat.mono_iff_injective namespace SurjectiveOfEpiAuxs set_option quotPrecheck false in local notation "X" => Set.range (· • (f.range : Set B) : B → Set B) /-- Define `X'` to be the set of all left cosets with an extra point at "infinity". -/ inductive XWithInfinity | fromCoset : Set.range (· • (f.range : Set B) : B → Set B) → XWithInfinity | infinity : XWithInfinity #align Group.surjective_of_epi_auxs.X_with_infinity GroupCat.SurjectiveOfEpiAuxs.XWithInfinity open XWithInfinity Equiv.Perm local notation "X'" => XWithInfinity f local notation "∞" => XWithInfinity.infinity local notation "SX'" => Equiv.Perm X' instance : SMul B X' where smul b x := match x with | fromCoset y => fromCoset ⟨b • y, by rw [← y.2.choose_spec, leftCoset_assoc] -- Porting note: should we make `Bundled.α` reducible? let b' : B := y.2.choose use b * b'⟩ | ∞ => ∞ theorem mul_smul (b b' : B) (x : X') : (b * b') • x = b • b' • x := match x with | fromCoset y => by change fromCoset _ = fromCoset _ simp only [leftCoset_assoc] | ∞ => rfl #align Group.surjective_of_epi_auxs.mul_smul GroupCat.SurjectiveOfEpiAuxs.mul_smul theorem one_smul (x : X') : (1 : B) • x = x := match x with | fromCoset y => by change fromCoset _ = fromCoset _ simp only [one_leftCoset, Subtype.ext_iff_val] | ∞ => rfl #align Group.surjective_of_epi_auxs.one_smul GroupCat.SurjectiveOfEpiAuxs.one_smul theorem fromCoset_eq_of_mem_range {b : B} (hb : b ∈ f.range) : fromCoset ⟨b • ↑f.range, b, rfl⟩ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by congr let b : B.α := b change b • (f.range : Set B) = f.range nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] rw [leftCoset_eq_iff, mul_one] exact Subgroup.inv_mem _ hb #align Group.surjective_of_epi_auxs.from_coset_eq_of_mem_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_eq_of_mem_range example (G : Type) [Group G] (S : Subgroup G) : Set G := S theorem fromCoset_ne_of_nin_range {b : B} (hb : b ∉ f.range) : fromCoset ⟨b • ↑f.range, b, rfl⟩ ≠ fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by intro r simp only [fromCoset.injEq, Subtype.mk.injEq] at r -- Porting note: annoying dance between types CoeSort.coe B, B.α, and B let b' : B.α := b change b' • (f.range : Set B) = f.range at r nth_rw 2 [show (f.range : Set B.α) = (1 : B) • f.range from (one_leftCoset _).symm] at r rw [leftCoset_eq_iff, mul_one] at r exact hb (inv_inv b ▸ Subgroup.inv_mem _ r) #align Group.surjective_of_epi_auxs.from_coset_ne_of_nin_range GroupCat.SurjectiveOfEpiAuxs.fromCoset_ne_of_nin_range instance : DecidableEq X' := Classical.decEq _ /-- Let `τ` be the permutation on `X'` exchanging `f.range` and the point at infinity. -/ noncomputable def tau : SX' := Equiv.swap (fromCoset ⟨↑f.range, ⟨1, one_leftCoset _⟩⟩) ∞ #align Group.surjective_of_epi_auxs.tau GroupCat.SurjectiveOfEpiAuxs.tau local notation "τ" => tau f theorem τ_apply_infinity : τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := Equiv.swap_apply_right _ _ #align Group.surjective_of_epi_auxs.τ_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_apply_infinity theorem τ_apply_fromCoset : τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := Equiv.swap_apply_left _ _ #align Group.surjective_of_epi_auxs.τ_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset theorem τ_apply_fromCoset' (x : B) (hx : x ∈ f.range) : τ (fromCoset ⟨x • ↑f.range, ⟨x, rfl⟩⟩) = ∞ := (fromCoset_eq_of_mem_range _ hx).symm ▸ τ_apply_fromCoset _ #align Group.surjective_of_epi_auxs.τ_apply_fromCoset' GroupCat.SurjectiveOfEpiAuxs.τ_apply_fromCoset' theorem τ_symm_apply_fromCoset : Equiv.symm τ (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = ∞ := by rw [tau, Equiv.symm_swap, Equiv.swap_apply_left] #align Group.surjective_of_epi_auxs.τ_symm_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_fromCoset theorem τ_symm_apply_infinity : Equiv.symm τ ∞ = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by rw [tau, Equiv.symm_swap, Equiv.swap_apply_right] #align Group.surjective_of_epi_auxs.τ_symm_apply_infinity GroupCat.SurjectiveOfEpiAuxs.τ_symm_apply_infinity /-- Let `g : B ⟶ S(X')` be defined as such that, for any `β : B`, `g(β)` is the function sending point at infinity to point at infinity and sending coset `y` to `β • y`. -/ def g : B →* SX' where toFun β := { toFun := fun x => β • x invFun := fun x => β⁻¹ • x left_inv := fun x => by dsimp only rw [← mul_smul, mul_left_inv, one_smul] right_inv := fun x => by dsimp only rw [← mul_smul, mul_right_inv, one_smul] } map_one' := by ext simp [one_smul] map_mul' b1 b2 := by ext simp [mul_smul] #align Group.surjective_of_epi_auxs.G GroupCat.SurjectiveOfEpiAuxs.g local notation "g" => g f /-- Define `h : B ⟶ S(X')` to be `τ g τ⁻¹` -/ def h : B →* SX' where -- Porting note: mathport removed () from (τ) which are needed toFun β := ((τ).symm.trans (g β)).trans τ map_one' := by ext simp map_mul' b1 b2 := by ext simp #align Group.surjective_of_epi_auxs.H GroupCat.SurjectiveOfEpiAuxs.h local notation "h" => h f /-! The strategy is the following: assuming `epi f` * prove that `f.range = {x | h x = g x}`; * thus `f ≫ h = f ≫ g` so that `h = g`; * but if `f` is not surjective, then some `x ∉ f.range`, then `h x ≠ g x` at the coset `f.range`. -/ theorem g_apply_fromCoset (x : B) (y : Set.range (· • (f.range : Set B) : B → Set B)) : g x (fromCoset y) = fromCoset ⟨x • ↑y, by obtain ⟨z, hz⟩ := y.2; exact ⟨x * z, by simp [← hz, smul_smul]⟩⟩ := rfl #align Group.surjective_of_epi_auxs.g_apply_fromCoset GroupCat.SurjectiveOfEpiAuxs.g_apply_fromCoset theorem g_apply_infinity (x : B) : (g x) ∞ = ∞ := rfl #align Group.surjective_of_epi_auxs.g_apply_infinity GroupCat.SurjectiveOfEpiAuxs.g_apply_infinity theorem h_apply_infinity (x : B) (hx : x ∈ f.range) : (h x) ∞ = ∞ := by change ((τ).symm.trans (g x)).trans τ _ = _ simp only [MonoidHom.coe_mk, Equiv.toFun_as_coe, Equiv.coe_trans, Function.comp_apply] rw [τ_symm_apply_infinity, g_apply_fromCoset] simpa only using τ_apply_fromCoset' f x hx #align Group.surjective_of_epi_auxs.h_apply_infinity GroupCat.SurjectiveOfEpiAuxs.h_apply_infinity
Mathlib/Algebra/Category/GroupCat/EpiMono.lean
263
267
theorem h_apply_fromCoset (x : B) : (h x) (fromCoset ⟨f.range, 1, one_leftCoset _⟩) = fromCoset ⟨f.range, 1, one_leftCoset _⟩ := by
change ((τ).symm.trans (g x)).trans τ _ = _ simp [-MonoidHom.coe_range, τ_symm_apply_fromCoset, g_apply_infinity, τ_apply_infinity]
/- Copyright (c) 2014 Robert Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Equiv import Mathlib.Algebra.Order.Field.Defs import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core #align_import algebra.order.field.basic from "leanprover-community/mathlib"@"84771a9f5f0bd5e5d6218811556508ddf476dcbd" /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ι α β : Type*} section LinearOrderedSemifield variable [LinearOrderedSemifield α] {a b c d e : α} {m n : ℤ} /-- `Equiv.mulLeft₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulLeft₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulLeft₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_left ha } #align order_iso.mul_left₀ OrderIso.mulLeft₀ #align order_iso.mul_left₀_symm_apply OrderIso.mulLeft₀_symm_apply #align order_iso.mul_left₀_apply OrderIso.mulLeft₀_apply /-- `Equiv.mulRight₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulRight₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulRight₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_right ha } #align order_iso.mul_right₀ OrderIso.mulRight₀ #align order_iso.mul_right₀_symm_apply OrderIso.mulRight₀_symm_apply #align order_iso.mul_right₀_apply OrderIso.mulRight₀_apply /-! ### Relating one division with another term. -/ theorem le_div_iff (hc : 0 < c) : a ≤ b / c ↔ a * c ≤ b := ⟨fun h => div_mul_cancel₀ b (ne_of_lt hc).symm ▸ mul_le_mul_of_nonneg_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc).symm _ ≤ b * (1 / c) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ #align le_div_iff le_div_iff theorem le_div_iff' (hc : 0 < c) : a ≤ b / c ↔ c * a ≤ b := by rw [mul_comm, le_div_iff hc] #align le_div_iff' le_div_iff' theorem div_le_iff (hb : 0 < b) : a / b ≤ c ↔ a ≤ c * b := ⟨fun h => calc a = a / b * b := by rw [div_mul_cancel₀ _ (ne_of_lt hb).symm] _ ≤ c * b := mul_le_mul_of_nonneg_right h hb.le , fun h => calc a / b = a * (1 / b) := div_eq_mul_one_div a b _ ≤ c * b * (1 / b) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hb).le _ = c * b / b := (div_eq_mul_one_div (c * b) b).symm _ = c := by refine (div_eq_iff (ne_of_gt hb)).mpr rfl ⟩ #align div_le_iff div_le_iff theorem div_le_iff' (hb : 0 < b) : a / b ≤ c ↔ a ≤ b * c := by rw [mul_comm, div_le_iff hb] #align div_le_iff' div_le_iff' lemma div_le_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b ≤ c ↔ a / c ≤ b := by rw [div_le_iff hb, div_le_iff' hc] theorem lt_div_iff (hc : 0 < c) : a < b / c ↔ a * c < b := lt_iff_lt_of_le_iff_le <| div_le_iff hc #align lt_div_iff lt_div_iff
Mathlib/Algebra/Order/Field/Basic.lean
86
86
theorem lt_div_iff' (hc : 0 < c) : a < b / c ↔ c * a < b := by
rw [mul_comm, lt_div_iff hc]
/- Copyright (c) 2024 Paul Reichert. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul Reichert -/ import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Final import Mathlib.CategoryTheory.Conj /-! # Colimits of connected index categories This file proves two characterizations of connected categories by means of colimits. ## Characterization of connected categories by means of the unit-valued functor First, it is proved that a category `C` is connected if and only if `colim F` is a singleton, where `F : C ⥤ Type w` and `F.obj _ = PUnit` (for arbitrary `w`). See `isConnected_iff_colimit_constPUnitFunctor_iso_pUnit` for the proof of this characterization and `constPUnitFunctor` for the definition of the constant functor used in the statement. A formulation based on `IsColimit` instead of `colimit` is given in `isConnected_iff_isColimit_pUnitCocone`. The `if` direction is also available directly in several formulations: For connected index categories `C`, `PUnit.{w}` is a colimit of the `constPUnitFunctor`, where `w` is arbitrary. See `instHasColimitConstPUnitFunctor`, `isColimitPUnitCocone` and `colimitConstPUnitIsoPUnit`. ## Final functors preserve connectedness of categories (in both directions) `isConnected_iff_of_final` proves that the domain of a final functor is connected if and only if its codomain is connected. ## Tags unit-valued, singleton, colimit -/ universe w v u namespace CategoryTheory.Limits.Types variable (C : Type u) [Category.{v} C] /-- The functor mapping every object to `PUnit`. -/ def constPUnitFunctor : C ⥤ Type w := (Functor.const C).obj PUnit.{w + 1} /-- The cocone on `constPUnitFunctor` with cone point `PUnit`. -/ @[simps] def pUnitCocone : Cocone (constPUnitFunctor.{w} C) where pt := PUnit ι := { app := fun X => id } /-- If `C` is connected, the cocone on `constPUnitFunctor` with cone point `PUnit` is a colimit cocone. -/ noncomputable def isColimitPUnitCocone [IsConnected C] : IsColimit (pUnitCocone.{w} C) where desc s := s.ι.app Classical.ofNonempty fac s j := by ext ⟨⟩ apply constant_of_preserves_morphisms (s.ι.app · PUnit.unit) intros X Y f exact congrFun (s.ι.naturality f).symm PUnit.unit uniq s m h := by ext ⟨⟩ simp [← h Classical.ofNonempty] instance instHasColimitConstPUnitFunctor [IsConnected C] : HasColimit (constPUnitFunctor.{w} C) := ⟨_, isColimitPUnitCocone _⟩ instance instSubsingletonColimitPUnit [IsPreconnected C] [HasColimit (constPUnitFunctor.{w} C)] : Subsingleton (colimit (constPUnitFunctor.{w} C)) where allEq a b := by obtain ⟨c, ⟨⟩, rfl⟩ := jointly_surjective' a obtain ⟨d, ⟨⟩, rfl⟩ := jointly_surjective' b apply constant_of_preserves_morphisms (colimit.ι (constPUnitFunctor C) · PUnit.unit) exact fun c d f => colimit_sound f rfl /-- Given a connected index category, the colimit of the constant unit-valued functor is `PUnit`. -/ noncomputable def colimitConstPUnitIsoPUnit [IsConnected C] : colimit (constPUnitFunctor.{w} C) ≅ PUnit.{w + 1} := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitPUnitCocone.{w} C) /-- Let `F` be a `Type`-valued functor. If two elements `a : F c` and `b : F d` represent the same element of `colimit F`, then `c` and `d` are related by a `Zigzag`. -/
Mathlib/CategoryTheory/Limits/IsConnected.lean
87
93
theorem zigzag_of_eqvGen_quot_rel (F : C ⥤ Type w) (c d : Σ j, F.obj j) (h : EqvGen (Quot.Rel F) c d) : Zigzag c.1 d.1 := by
induction h with | rel _ _ h => exact Zigzag.of_hom <| Exists.choose h | refl _ => exact Zigzag.refl _ | symm _ _ _ ih => exact zigzag_symmetric ih | trans _ _ _ _ _ ih₁ ih₂ => exact ih₁.trans ih₂
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import Mathlib.Analysis.NormedSpace.BoundedLinearMaps import Mathlib.MeasureTheory.Measure.WithDensity import Mathlib.MeasureTheory.Function.SimpleFuncDense import Mathlib.Topology.Algebra.Module.FiniteDimension #align_import measure_theory.function.strongly_measurable.basic from "leanprover-community/mathlib"@"3b52265189f3fb43aa631edffce5d060fafaf82f" /-! # Strongly measurable and finitely strongly measurable functions A function `f` is said to be strongly measurable if `f` is the sequential limit of simple functions. It is said to be finitely strongly measurable with respect to a measure `μ` if the supports of those simple functions have finite measure. We also provide almost everywhere versions of these notions. Almost everywhere strongly measurable functions form the largest class of functions that can be integrated using the Bochner integral. If the target space has a second countable topology, strongly measurable and measurable are equivalent. If the measure is sigma-finite, strongly measurable and finitely strongly measurable are equivalent. The main property of finitely strongly measurable functions is `FinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that the function is supported on `t` and `μ.restrict t` is sigma-finite. As a consequence, we can prove some results for those functions as if the measure was sigma-finite. ## Main definitions * `StronglyMeasurable f`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β`. * `FinStronglyMeasurable f μ`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β` such that for all `n ∈ ℕ`, the measure of the support of `fs n` is finite. * `AEStronglyMeasurable f μ`: `f` is almost everywhere equal to a `StronglyMeasurable` function. * `AEFinStronglyMeasurable f μ`: `f` is almost everywhere equal to a `FinStronglyMeasurable` function. * `AEFinStronglyMeasurable.sigmaFiniteSet`: a measurable set `t` such that `f =ᵐ[μ.restrict tᶜ] 0` and `μ.restrict t` is sigma-finite. ## Main statements * `AEFinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that `f =ᵐ[μ.restrict tᶜ] 0` and `μ.restrict t` is sigma-finite. We provide a solid API for strongly measurable functions, and for almost everywhere strongly measurable functions, as a basis for the Bochner integral. ## References * Hytönen, Tuomas, Jan Van Neerven, Mark Veraar, and Lutz Weis. Analysis in Banach spaces. Springer, 2016. -/ open MeasureTheory Filter TopologicalSpace Function Set MeasureTheory.Measure open ENNReal Topology MeasureTheory NNReal variable {α β γ ι : Type*} [Countable ι] namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc section Definitions variable [TopologicalSpace β] /-- A function is `StronglyMeasurable` if it is the limit of simple functions. -/ def StronglyMeasurable [MeasurableSpace α] (f : α → β) : Prop := ∃ fs : ℕ → α →ₛ β, ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) #align measure_theory.strongly_measurable MeasureTheory.StronglyMeasurable /-- The notation for StronglyMeasurable giving the measurable space instance explicitly. -/ scoped notation "StronglyMeasurable[" m "]" => @MeasureTheory.StronglyMeasurable _ _ _ m /-- A function is `FinStronglyMeasurable` with respect to a measure if it is the limit of simple functions with support with finite measure. -/ def FinStronglyMeasurable [Zero β] {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := ∃ fs : ℕ → α →ₛ β, (∀ n, μ (support (fs n)) < ∞) ∧ ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) #align measure_theory.fin_strongly_measurable MeasureTheory.FinStronglyMeasurable /-- A function is `AEStronglyMeasurable` with respect to a measure `μ` if it is almost everywhere equal to the limit of a sequence of simple functions. -/ def AEStronglyMeasurable {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := ∃ g, StronglyMeasurable g ∧ f =ᵐ[μ] g #align measure_theory.ae_strongly_measurable MeasureTheory.AEStronglyMeasurable /-- A function is `AEFinStronglyMeasurable` with respect to a measure if it is almost everywhere equal to the limit of a sequence of simple functions with support with finite measure. -/ def AEFinStronglyMeasurable [Zero β] {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := ∃ g, FinStronglyMeasurable g μ ∧ f =ᵐ[μ] g #align measure_theory.ae_fin_strongly_measurable MeasureTheory.AEFinStronglyMeasurable end Definitions open MeasureTheory /-! ## Strongly measurable functions -/ @[aesop 30% apply (rule_sets := [Measurable])] protected theorem StronglyMeasurable.aestronglyMeasurable {α β} {_ : MeasurableSpace α} [TopologicalSpace β] {f : α → β} {μ : Measure α} (hf : StronglyMeasurable f) : AEStronglyMeasurable f μ := ⟨f, hf, EventuallyEq.refl _ _⟩ #align measure_theory.strongly_measurable.ae_strongly_measurable MeasureTheory.StronglyMeasurable.aestronglyMeasurable @[simp] theorem Subsingleton.stronglyMeasurable {α β} [MeasurableSpace α] [TopologicalSpace β] [Subsingleton β] (f : α → β) : StronglyMeasurable f := by let f_sf : α →ₛ β := ⟨f, fun x => ?_, Set.Subsingleton.finite Set.subsingleton_of_subsingleton⟩ · exact ⟨fun _ => f_sf, fun x => tendsto_const_nhds⟩ · have h_univ : f ⁻¹' {x} = Set.univ := by ext1 y simp [eq_iff_true_of_subsingleton] rw [h_univ] exact MeasurableSet.univ #align measure_theory.subsingleton.strongly_measurable MeasureTheory.Subsingleton.stronglyMeasurable theorem SimpleFunc.stronglyMeasurable {α β} {_ : MeasurableSpace α} [TopologicalSpace β] (f : α →ₛ β) : StronglyMeasurable f := ⟨fun _ => f, fun _ => tendsto_const_nhds⟩ #align measure_theory.simple_func.strongly_measurable MeasureTheory.SimpleFunc.stronglyMeasurable @[nontriviality] theorem StronglyMeasurable.of_finite [Finite α] {_ : MeasurableSpace α} [MeasurableSingletonClass α] [TopologicalSpace β] (f : α → β) : StronglyMeasurable f := ⟨fun _ => SimpleFunc.ofFinite f, fun _ => tendsto_const_nhds⟩ @[deprecated (since := "2024-02-05")] alias stronglyMeasurable_of_fintype := StronglyMeasurable.of_finite @[deprecated StronglyMeasurable.of_finite (since := "2024-02-06")] theorem stronglyMeasurable_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} [TopologicalSpace β] (f : α → β) : StronglyMeasurable f := .of_finite f #align measure_theory.strongly_measurable_of_is_empty MeasureTheory.StronglyMeasurable.of_finite theorem stronglyMeasurable_const {α β} {_ : MeasurableSpace α} [TopologicalSpace β] {b : β} : StronglyMeasurable fun _ : α => b := ⟨fun _ => SimpleFunc.const α b, fun _ => tendsto_const_nhds⟩ #align measure_theory.strongly_measurable_const MeasureTheory.stronglyMeasurable_const @[to_additive] theorem stronglyMeasurable_one {α β} {_ : MeasurableSpace α} [TopologicalSpace β] [One β] : StronglyMeasurable (1 : α → β) := stronglyMeasurable_const #align measure_theory.strongly_measurable_one MeasureTheory.stronglyMeasurable_one #align measure_theory.strongly_measurable_zero MeasureTheory.stronglyMeasurable_zero /-- A version of `stronglyMeasurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ theorem stronglyMeasurable_const' {α β} {m : MeasurableSpace α} [TopologicalSpace β] {f : α → β} (hf : ∀ x y, f x = f y) : StronglyMeasurable f := by nontriviality α inhabit α convert stronglyMeasurable_const (β := β) using 1 exact funext fun x => hf x default #align measure_theory.strongly_measurable_const' MeasureTheory.stronglyMeasurable_const' -- Porting note: changed binding type of `MeasurableSpace α`. @[simp] theorem Subsingleton.stronglyMeasurable' {α β} [MeasurableSpace α] [TopologicalSpace β] [Subsingleton α] (f : α → β) : StronglyMeasurable f := stronglyMeasurable_const' fun x y => by rw [Subsingleton.elim x y] #align measure_theory.subsingleton.strongly_measurable' MeasureTheory.Subsingleton.stronglyMeasurable' namespace StronglyMeasurable variable {f g : α → β} section BasicPropertiesInAnyTopologicalSpace variable [TopologicalSpace β] /-- A sequence of simple functions such that `∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x))`. That property is given by `stronglyMeasurable.tendsto_approx`. -/ protected noncomputable def approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) : ℕ → α →ₛ β := hf.choose #align measure_theory.strongly_measurable.approx MeasureTheory.StronglyMeasurable.approx protected theorem tendsto_approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) : ∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x)) := hf.choose_spec #align measure_theory.strongly_measurable.tendsto_approx MeasureTheory.StronglyMeasurable.tendsto_approx /-- Similar to `stronglyMeasurable.approx`, but enforces that the norm of every function in the sequence is less than `c` everywhere. If `‖f x‖ ≤ c` this sequence of simple functions verifies `Tendsto (fun n => hf.approxBounded n x) atTop (𝓝 (f x))`. -/ noncomputable def approxBounded {_ : MeasurableSpace α} [Norm β] [SMul ℝ β] (hf : StronglyMeasurable f) (c : ℝ) : ℕ → SimpleFunc α β := fun n => (hf.approx n).map fun x => min 1 (c / ‖x‖) • x #align measure_theory.strongly_measurable.approx_bounded MeasureTheory.StronglyMeasurable.approxBounded theorem tendsto_approxBounded_of_norm_le {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β] {m : MeasurableSpace α} (hf : StronglyMeasurable[m] f) {c : ℝ} {x : α} (hfx : ‖f x‖ ≤ c) : Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by have h_tendsto := hf.tendsto_approx x simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] by_cases hfx0 : ‖f x‖ = 0 · rw [norm_eq_zero] at hfx0 rw [hfx0] at h_tendsto ⊢ have h_tendsto_norm : Tendsto (fun n => ‖hf.approx n x‖) atTop (𝓝 0) := by convert h_tendsto.norm rw [norm_zero] refine squeeze_zero_norm (fun n => ?_) h_tendsto_norm calc ‖min 1 (c / ‖hf.approx n x‖) • hf.approx n x‖ = ‖min 1 (c / ‖hf.approx n x‖)‖ * ‖hf.approx n x‖ := norm_smul _ _ _ ≤ ‖(1 : ℝ)‖ * ‖hf.approx n x‖ := by refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _) rw [norm_one, Real.norm_of_nonneg] · exact min_le_left _ _ · exact le_min zero_le_one (div_nonneg ((norm_nonneg _).trans hfx) (norm_nonneg _)) _ = ‖hf.approx n x‖ := by rw [norm_one, one_mul] rw [← one_smul ℝ (f x)] refine Tendsto.smul ?_ h_tendsto have : min 1 (c / ‖f x‖) = 1 := by rw [min_eq_left_iff, one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm hfx0))] exact hfx nth_rw 2 [this.symm] refine Tendsto.min tendsto_const_nhds ?_ exact Tendsto.div tendsto_const_nhds h_tendsto.norm hfx0 #align measure_theory.strongly_measurable.tendsto_approx_bounded_of_norm_le MeasureTheory.StronglyMeasurable.tendsto_approxBounded_of_norm_le theorem tendsto_approxBounded_ae {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β] {m m0 : MeasurableSpace α} {μ : Measure α} (hf : StronglyMeasurable[m] f) {c : ℝ} (hf_bound : ∀ᵐ x ∂μ, ‖f x‖ ≤ c) : ∀ᵐ x ∂μ, Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by filter_upwards [hf_bound] with x hfx using tendsto_approxBounded_of_norm_le hf hfx #align measure_theory.strongly_measurable.tendsto_approx_bounded_ae MeasureTheory.StronglyMeasurable.tendsto_approxBounded_ae theorem norm_approxBounded_le {β} {f : α → β} [SeminormedAddCommGroup β] [NormedSpace ℝ β] {m : MeasurableSpace α} {c : ℝ} (hf : StronglyMeasurable[m] f) (hc : 0 ≤ c) (n : ℕ) (x : α) : ‖hf.approxBounded c n x‖ ≤ c := by simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] refine (norm_smul_le _ _).trans ?_ by_cases h0 : ‖hf.approx n x‖ = 0 · simp only [h0, _root_.div_zero, min_eq_right, zero_le_one, norm_zero, mul_zero] exact hc rcases le_total ‖hf.approx n x‖ c with h | h · rw [min_eq_left _] · simpa only [norm_one, one_mul] using h · rwa [one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] · rw [min_eq_right _] · rw [norm_div, norm_norm, mul_comm, mul_div, div_eq_mul_inv, mul_comm, ← mul_assoc, inv_mul_cancel h0, one_mul, Real.norm_of_nonneg hc] · rwa [div_le_one (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] #align measure_theory.strongly_measurable.norm_approx_bounded_le MeasureTheory.StronglyMeasurable.norm_approxBounded_le theorem _root_.stronglyMeasurable_bot_iff [Nonempty β] [T2Space β] : StronglyMeasurable[⊥] f ↔ ∃ c, f = fun _ => c := by cases' isEmpty_or_nonempty α with hα hα · simp only [@Subsingleton.stronglyMeasurable' _ _ ⊥ _ _ f, eq_iff_true_of_subsingleton, exists_const] refine ⟨fun hf => ?_, fun hf_eq => ?_⟩ · refine ⟨f hα.some, ?_⟩ let fs := hf.approx have h_fs_tendsto : ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) := hf.tendsto_approx have : ∀ n, ∃ c, ∀ x, fs n x = c := fun n => SimpleFunc.simpleFunc_bot (fs n) let cs n := (this n).choose have h_cs_eq : ∀ n, ⇑(fs n) = fun _ => cs n := fun n => funext (this n).choose_spec conv at h_fs_tendsto => enter [x, 1, n]; rw [h_cs_eq] have h_tendsto : Tendsto cs atTop (𝓝 (f hα.some)) := h_fs_tendsto hα.some ext1 x exact tendsto_nhds_unique (h_fs_tendsto x) h_tendsto · obtain ⟨c, rfl⟩ := hf_eq exact stronglyMeasurable_const #align strongly_measurable_bot_iff stronglyMeasurable_bot_iff end BasicPropertiesInAnyTopologicalSpace theorem finStronglyMeasurable_of_set_sigmaFinite [TopologicalSpace β] [Zero β] {m : MeasurableSpace α} {μ : Measure α} (hf_meas : StronglyMeasurable f) {t : Set α} (ht : MeasurableSet t) (hft_zero : ∀ x ∈ tᶜ, f x = 0) (htμ : SigmaFinite (μ.restrict t)) : FinStronglyMeasurable f μ := by haveI : SigmaFinite (μ.restrict t) := htμ let S := spanningSets (μ.restrict t) have hS_meas : ∀ n, MeasurableSet (S n) := measurable_spanningSets (μ.restrict t) let f_approx := hf_meas.approx let fs n := SimpleFunc.restrict (f_approx n) (S n ∩ t) have h_fs_t_compl : ∀ n, ∀ x, x ∉ t → fs n x = 0 := by intro n x hxt rw [SimpleFunc.restrict_apply _ ((hS_meas n).inter ht)] refine Set.indicator_of_not_mem ?_ _ simp [hxt] refine ⟨fs, ?_, fun x => ?_⟩ · simp_rw [SimpleFunc.support_eq] refine fun n => (measure_biUnion_finset_le _ _).trans_lt ?_ refine ENNReal.sum_lt_top_iff.mpr fun y hy => ?_ rw [SimpleFunc.restrict_preimage_singleton _ ((hS_meas n).inter ht)] swap · letI : (y : β) → Decidable (y = 0) := fun y => Classical.propDecidable _ rw [Finset.mem_filter] at hy exact hy.2 refine (measure_mono Set.inter_subset_left).trans_lt ?_ have h_lt_top := measure_spanningSets_lt_top (μ.restrict t) n rwa [Measure.restrict_apply' ht] at h_lt_top · by_cases hxt : x ∈ t swap · rw [funext fun n => h_fs_t_compl n x hxt, hft_zero x hxt] exact tendsto_const_nhds have h : Tendsto (fun n => (f_approx n) x) atTop (𝓝 (f x)) := hf_meas.tendsto_approx x obtain ⟨n₁, hn₁⟩ : ∃ n, ∀ m, n ≤ m → fs m x = f_approx m x := by obtain ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m ∩ t := by rsuffices ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m · exact ⟨n, fun m hnm => Set.mem_inter (hn m hnm) hxt⟩ rsuffices ⟨n, hn⟩ : ∃ n, x ∈ S n · exact ⟨n, fun m hnm => monotone_spanningSets (μ.restrict t) hnm hn⟩ rw [← Set.mem_iUnion, iUnion_spanningSets (μ.restrict t)] trivial refine ⟨n, fun m hnm => ?_⟩ simp_rw [fs, SimpleFunc.restrict_apply _ ((hS_meas m).inter ht), Set.indicator_of_mem (hn m hnm)] rw [tendsto_atTop'] at h ⊢ intro s hs obtain ⟨n₂, hn₂⟩ := h s hs refine ⟨max n₁ n₂, fun m hm => ?_⟩ rw [hn₁ m ((le_max_left _ _).trans hm.le)] exact hn₂ m ((le_max_right _ _).trans hm.le) #align measure_theory.strongly_measurable.fin_strongly_measurable_of_set_sigma_finite MeasureTheory.StronglyMeasurable.finStronglyMeasurable_of_set_sigmaFinite /-- If the measure is sigma-finite, all strongly measurable functions are `FinStronglyMeasurable`. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem finStronglyMeasurable [TopologicalSpace β] [Zero β] {m0 : MeasurableSpace α} (hf : StronglyMeasurable f) (μ : Measure α) [SigmaFinite μ] : FinStronglyMeasurable f μ := hf.finStronglyMeasurable_of_set_sigmaFinite MeasurableSet.univ (by simp) (by rwa [Measure.restrict_univ]) #align measure_theory.strongly_measurable.fin_strongly_measurable MeasureTheory.StronglyMeasurable.finStronglyMeasurable /-- A strongly measurable function is measurable. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem measurable {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf : StronglyMeasurable f) : Measurable f := measurable_of_tendsto_metrizable (fun n => (hf.approx n).measurable) (tendsto_pi_nhds.mpr hf.tendsto_approx) #align measure_theory.strongly_measurable.measurable MeasureTheory.StronglyMeasurable.measurable /-- A strongly measurable function is almost everywhere measurable. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem aemeasurable {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] {μ : Measure α} (hf : StronglyMeasurable f) : AEMeasurable f μ := hf.measurable.aemeasurable #align measure_theory.strongly_measurable.ae_measurable MeasureTheory.StronglyMeasurable.aemeasurable theorem _root_.Continuous.comp_stronglyMeasurable {_ : MeasurableSpace α} [TopologicalSpace β] [TopologicalSpace γ] {g : β → γ} {f : α → β} (hg : Continuous g) (hf : StronglyMeasurable f) : StronglyMeasurable fun x => g (f x) := ⟨fun n => SimpleFunc.map g (hf.approx n), fun x => (hg.tendsto _).comp (hf.tendsto_approx x)⟩ #align continuous.comp_strongly_measurable Continuous.comp_stronglyMeasurable @[to_additive] nonrec theorem measurableSet_mulSupport {m : MeasurableSpace α} [One β] [TopologicalSpace β] [MetrizableSpace β] (hf : StronglyMeasurable f) : MeasurableSet (mulSupport f) := by borelize β exact measurableSet_mulSupport hf.measurable #align measure_theory.strongly_measurable.measurable_set_mul_support MeasureTheory.StronglyMeasurable.measurableSet_mulSupport #align measure_theory.strongly_measurable.measurable_set_support MeasureTheory.StronglyMeasurable.measurableSet_support protected theorem mono {m m' : MeasurableSpace α} [TopologicalSpace β] (hf : StronglyMeasurable[m'] f) (h_mono : m' ≤ m) : StronglyMeasurable[m] f := by let f_approx : ℕ → @SimpleFunc α m β := fun n => @SimpleFunc.mk α m β (hf.approx n) (fun x => h_mono _ (SimpleFunc.measurableSet_fiber' _ x)) (SimpleFunc.finite_range (hf.approx n)) exact ⟨f_approx, hf.tendsto_approx⟩ #align measure_theory.strongly_measurable.mono MeasureTheory.StronglyMeasurable.mono protected theorem prod_mk {m : MeasurableSpace α} [TopologicalSpace β] [TopologicalSpace γ] {f : α → β} {g : α → γ} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => (f x, g x) := by refine ⟨fun n => SimpleFunc.pair (hf.approx n) (hg.approx n), fun x => ?_⟩ rw [nhds_prod_eq] exact Tendsto.prod_mk (hf.tendsto_approx x) (hg.tendsto_approx x) #align measure_theory.strongly_measurable.prod_mk MeasureTheory.StronglyMeasurable.prod_mk theorem comp_measurable [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → β} {g : γ → α} (hf : StronglyMeasurable f) (hg : Measurable g) : StronglyMeasurable (f ∘ g) := ⟨fun n => SimpleFunc.comp (hf.approx n) g hg, fun x => hf.tendsto_approx (g x)⟩ #align measure_theory.strongly_measurable.comp_measurable MeasureTheory.StronglyMeasurable.comp_measurable theorem of_uncurry_left [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → γ → β} (hf : StronglyMeasurable (uncurry f)) {x : α} : StronglyMeasurable (f x) := hf.comp_measurable measurable_prod_mk_left #align measure_theory.strongly_measurable.of_uncurry_left MeasureTheory.StronglyMeasurable.of_uncurry_left theorem of_uncurry_right [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → γ → β} (hf : StronglyMeasurable (uncurry f)) {y : γ} : StronglyMeasurable fun x => f x y := hf.comp_measurable measurable_prod_mk_right #align measure_theory.strongly_measurable.of_uncurry_right MeasureTheory.StronglyMeasurable.of_uncurry_right section Arithmetic variable {mα : MeasurableSpace α} [TopologicalSpace β] @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem mul [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f * g) := ⟨fun n => hf.approx n * hg.approx n, fun x => (hf.tendsto_approx x).mul (hg.tendsto_approx x)⟩ #align measure_theory.strongly_measurable.mul MeasureTheory.StronglyMeasurable.mul #align measure_theory.strongly_measurable.add MeasureTheory.StronglyMeasurable.add @[to_additive (attr := measurability)] theorem mul_const [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => f x * c := hf.mul stronglyMeasurable_const #align measure_theory.strongly_measurable.mul_const MeasureTheory.StronglyMeasurable.mul_const #align measure_theory.strongly_measurable.add_const MeasureTheory.StronglyMeasurable.add_const @[to_additive (attr := measurability)] theorem const_mul [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => c * f x := stronglyMeasurable_const.mul hf #align measure_theory.strongly_measurable.const_mul MeasureTheory.StronglyMeasurable.const_mul #align measure_theory.strongly_measurable.const_add MeasureTheory.StronglyMeasurable.const_add @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable])) const_nsmul] protected theorem pow [Monoid β] [ContinuousMul β] (hf : StronglyMeasurable f) (n : ℕ) : StronglyMeasurable (f ^ n) := ⟨fun k => hf.approx k ^ n, fun x => (hf.tendsto_approx x).pow n⟩ @[to_additive (attr := measurability)] protected theorem inv [Inv β] [ContinuousInv β] (hf : StronglyMeasurable f) : StronglyMeasurable f⁻¹ := ⟨fun n => (hf.approx n)⁻¹, fun x => (hf.tendsto_approx x).inv⟩ #align measure_theory.strongly_measurable.inv MeasureTheory.StronglyMeasurable.inv #align measure_theory.strongly_measurable.neg MeasureTheory.StronglyMeasurable.neg @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem div [Div β] [ContinuousDiv β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f / g) := ⟨fun n => hf.approx n / hg.approx n, fun x => (hf.tendsto_approx x).div' (hg.tendsto_approx x)⟩ #align measure_theory.strongly_measurable.div MeasureTheory.StronglyMeasurable.div #align measure_theory.strongly_measurable.sub MeasureTheory.StronglyMeasurable.sub @[to_additive] theorem mul_iff_right [CommGroup β] [TopologicalGroup β] (hf : StronglyMeasurable f) : StronglyMeasurable (f * g) ↔ StronglyMeasurable g := ⟨fun h ↦ show g = f * g * f⁻¹ by simp only [mul_inv_cancel_comm] ▸ h.mul hf.inv, fun h ↦ hf.mul h⟩ @[to_additive] theorem mul_iff_left [CommGroup β] [TopologicalGroup β] (hf : StronglyMeasurable f) : StronglyMeasurable (g * f) ↔ StronglyMeasurable g := mul_comm g f ▸ mul_iff_right hf @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem smul {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜} {g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => f x • g x := continuous_smul.comp_stronglyMeasurable (hf.prod_mk hg) #align measure_theory.strongly_measurable.smul MeasureTheory.StronglyMeasurable.smul #align measure_theory.strongly_measurable.vadd MeasureTheory.StronglyMeasurable.vadd @[to_additive (attr := measurability)] protected theorem const_smul {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : StronglyMeasurable f) (c : 𝕜) : StronglyMeasurable (c • f) := ⟨fun n => c • hf.approx n, fun x => (hf.tendsto_approx x).const_smul c⟩ #align measure_theory.strongly_measurable.const_smul MeasureTheory.StronglyMeasurable.const_smul @[to_additive (attr := measurability)] protected theorem const_smul' {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : StronglyMeasurable f) (c : 𝕜) : StronglyMeasurable fun x => c • f x := hf.const_smul c #align measure_theory.strongly_measurable.const_smul' MeasureTheory.StronglyMeasurable.const_smul' @[to_additive (attr := measurability)] protected theorem smul_const {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜} (hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => f x • c := continuous_smul.comp_stronglyMeasurable (hf.prod_mk stronglyMeasurable_const) #align measure_theory.strongly_measurable.smul_const MeasureTheory.StronglyMeasurable.smul_const #align measure_theory.strongly_measurable.vadd_const MeasureTheory.StronglyMeasurable.vadd_const /-- In a normed vector space, the addition of a measurable function and a strongly measurable function is measurable. Note that this is not true without further second-countability assumptions for the addition of two measurable functions. -/ theorem _root_.Measurable.add_stronglyMeasurable {α E : Type*} {_ : MeasurableSpace α} [AddGroup E] [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [PseudoMetrizableSpace E] {g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) : Measurable (g + f) := by rcases hf with ⟨φ, hφ⟩ have : Tendsto (fun n x ↦ g x + φ n x) atTop (𝓝 (g + f)) := tendsto_pi_nhds.2 (fun x ↦ tendsto_const_nhds.add (hφ x)) apply measurable_of_tendsto_metrizable (fun n ↦ ?_) this exact hg.add_simpleFunc _ /-- In a normed vector space, the subtraction of a measurable function and a strongly measurable function is measurable. Note that this is not true without further second-countability assumptions for the subtraction of two measurable functions. -/ theorem _root_.Measurable.sub_stronglyMeasurable {α E : Type*} {_ : MeasurableSpace α} [AddCommGroup E] [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [ContinuousNeg E] [PseudoMetrizableSpace E] {g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) : Measurable (g - f) := by rw [sub_eq_add_neg] exact hg.add_stronglyMeasurable hf.neg /-- In a normed vector space, the addition of a strongly measurable function and a measurable function is measurable. Note that this is not true without further second-countability assumptions for the addition of two measurable functions. -/ theorem _root_.Measurable.stronglyMeasurable_add {α E : Type*} {_ : MeasurableSpace α} [AddGroup E] [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [PseudoMetrizableSpace E] {g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) : Measurable (f + g) := by rcases hf with ⟨φ, hφ⟩ have : Tendsto (fun n x ↦ φ n x + g x) atTop (𝓝 (f + g)) := tendsto_pi_nhds.2 (fun x ↦ (hφ x).add tendsto_const_nhds) apply measurable_of_tendsto_metrizable (fun n ↦ ?_) this exact hg.simpleFunc_add _ end Arithmetic section MulAction variable {M G G₀ : Type*} variable [TopologicalSpace β] variable [Monoid M] [MulAction M β] [ContinuousConstSMul M β] variable [Group G] [MulAction G β] [ContinuousConstSMul G β] variable [GroupWithZero G₀] [MulAction G₀ β] [ContinuousConstSMul G₀ β] theorem _root_.stronglyMeasurable_const_smul_iff {m : MeasurableSpace α} (c : G) : (StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f := ⟨fun h => by simpa only [inv_smul_smul] using h.const_smul' c⁻¹, fun h => h.const_smul c⟩ #align strongly_measurable_const_smul_iff stronglyMeasurable_const_smul_iff nonrec theorem _root_.IsUnit.stronglyMeasurable_const_smul_iff {_ : MeasurableSpace α} {c : M} (hc : IsUnit c) : (StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f := let ⟨u, hu⟩ := hc hu ▸ stronglyMeasurable_const_smul_iff u #align is_unit.strongly_measurable_const_smul_iff IsUnit.stronglyMeasurable_const_smul_iff theorem _root_.stronglyMeasurable_const_smul_iff₀ {_ : MeasurableSpace α} {c : G₀} (hc : c ≠ 0) : (StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f := (IsUnit.mk0 _ hc).stronglyMeasurable_const_smul_iff #align strongly_measurable_const_smul_iff₀ stronglyMeasurable_const_smul_iff₀ end MulAction section Order variable [MeasurableSpace α] [TopologicalSpace β] open Filter open Filter @[aesop safe 20 (rule_sets := [Measurable])] protected theorem sup [Sup β] [ContinuousSup β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f ⊔ g) := ⟨fun n => hf.approx n ⊔ hg.approx n, fun x => (hf.tendsto_approx x).sup_nhds (hg.tendsto_approx x)⟩ #align measure_theory.strongly_measurable.sup MeasureTheory.StronglyMeasurable.sup @[aesop safe 20 (rule_sets := [Measurable])] protected theorem inf [Inf β] [ContinuousInf β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f ⊓ g) := ⟨fun n => hf.approx n ⊓ hg.approx n, fun x => (hf.tendsto_approx x).inf_nhds (hg.tendsto_approx x)⟩ #align measure_theory.strongly_measurable.inf MeasureTheory.StronglyMeasurable.inf end Order /-! ### Big operators: `∏` and `∑` -/ section Monoid variable {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M] {m : MeasurableSpace α} @[to_additive (attr := measurability)] theorem _root_.List.stronglyMeasurable_prod' (l : List (α → M)) (hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable l.prod := by induction' l with f l ihl; · exact stronglyMeasurable_one rw [List.forall_mem_cons] at hl rw [List.prod_cons] exact hl.1.mul (ihl hl.2) #align list.strongly_measurable_prod' List.stronglyMeasurable_prod' #align list.strongly_measurable_sum' List.stronglyMeasurable_sum' @[to_additive (attr := measurability)] theorem _root_.List.stronglyMeasurable_prod (l : List (α → M)) (hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable fun x => (l.map fun f : α → M => f x).prod := by simpa only [← Pi.list_prod_apply] using l.stronglyMeasurable_prod' hl #align list.strongly_measurable_prod List.stronglyMeasurable_prod #align list.strongly_measurable_sum List.stronglyMeasurable_sum end Monoid section CommMonoid variable {M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] {m : MeasurableSpace α} @[to_additive (attr := measurability)] theorem _root_.Multiset.stronglyMeasurable_prod' (l : Multiset (α → M)) (hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable l.prod := by rcases l with ⟨l⟩ simpa using l.stronglyMeasurable_prod' (by simpa using hl) #align multiset.strongly_measurable_prod' Multiset.stronglyMeasurable_prod' #align multiset.strongly_measurable_sum' Multiset.stronglyMeasurable_sum' @[to_additive (attr := measurability)] theorem _root_.Multiset.stronglyMeasurable_prod (s : Multiset (α → M)) (hs : ∀ f ∈ s, StronglyMeasurable f) : StronglyMeasurable fun x => (s.map fun f : α → M => f x).prod := by simpa only [← Pi.multiset_prod_apply] using s.stronglyMeasurable_prod' hs #align multiset.strongly_measurable_prod Multiset.stronglyMeasurable_prod #align multiset.strongly_measurable_sum Multiset.stronglyMeasurable_sum @[to_additive (attr := measurability)] theorem _root_.Finset.stronglyMeasurable_prod' {ι : Type*} {f : ι → α → M} (s : Finset ι) (hf : ∀ i ∈ s, StronglyMeasurable (f i)) : StronglyMeasurable (∏ i ∈ s, f i) := Finset.prod_induction _ _ (fun _a _b ha hb => ha.mul hb) (@stronglyMeasurable_one α M _ _ _) hf #align finset.strongly_measurable_prod' Finset.stronglyMeasurable_prod' #align finset.strongly_measurable_sum' Finset.stronglyMeasurable_sum' @[to_additive (attr := measurability)] theorem _root_.Finset.stronglyMeasurable_prod {ι : Type*} {f : ι → α → M} (s : Finset ι) (hf : ∀ i ∈ s, StronglyMeasurable (f i)) : StronglyMeasurable fun a => ∏ i ∈ s, f i a := by simpa only [← Finset.prod_apply] using s.stronglyMeasurable_prod' hf #align finset.strongly_measurable_prod Finset.stronglyMeasurable_prod #align finset.strongly_measurable_sum Finset.stronglyMeasurable_sum end CommMonoid /-- The range of a strongly measurable function is separable. -/ protected theorem isSeparable_range {m : MeasurableSpace α} [TopologicalSpace β] (hf : StronglyMeasurable f) : TopologicalSpace.IsSeparable (range f) := by have : IsSeparable (closure (⋃ n, range (hf.approx n))) := .closure <| .iUnion fun n => (hf.approx n).finite_range.isSeparable apply this.mono rintro _ ⟨x, rfl⟩ apply mem_closure_of_tendsto (hf.tendsto_approx x) filter_upwards with n apply mem_iUnion_of_mem n exact mem_range_self _ #align measure_theory.strongly_measurable.is_separable_range MeasureTheory.StronglyMeasurable.isSeparable_range theorem separableSpace_range_union_singleton {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] (hf : StronglyMeasurable f) {b : β} : SeparableSpace (range f ∪ {b} : Set β) := letI := pseudoMetrizableSpacePseudoMetric β (hf.isSeparable_range.union (finite_singleton _).isSeparable).separableSpace #align measure_theory.strongly_measurable.separable_space_range_union_singleton MeasureTheory.StronglyMeasurable.separableSpace_range_union_singleton section SecondCountableStronglyMeasurable variable {mα : MeasurableSpace α} [MeasurableSpace β] /-- In a space with second countable topology, measurable implies strongly measurable. -/ @[aesop 90% apply (rule_sets := [Measurable])] theorem _root_.Measurable.stronglyMeasurable [TopologicalSpace β] [PseudoMetrizableSpace β] [SecondCountableTopology β] [OpensMeasurableSpace β] (hf : Measurable f) : StronglyMeasurable f := by letI := pseudoMetrizableSpacePseudoMetric β nontriviality β; inhabit β exact ⟨SimpleFunc.approxOn f hf Set.univ default (Set.mem_univ _), fun x ↦ SimpleFunc.tendsto_approxOn hf (Set.mem_univ _) (by rw [closure_univ]; simp)⟩ #align measurable.strongly_measurable Measurable.stronglyMeasurable /-- In a space with second countable topology, strongly measurable and measurable are equivalent. -/ theorem _root_.stronglyMeasurable_iff_measurable [TopologicalSpace β] [MetrizableSpace β] [BorelSpace β] [SecondCountableTopology β] : StronglyMeasurable f ↔ Measurable f := ⟨fun h => h.measurable, fun h => Measurable.stronglyMeasurable h⟩ #align strongly_measurable_iff_measurable stronglyMeasurable_iff_measurable @[measurability] theorem _root_.stronglyMeasurable_id [TopologicalSpace α] [PseudoMetrizableSpace α] [OpensMeasurableSpace α] [SecondCountableTopology α] : StronglyMeasurable (id : α → α) := measurable_id.stronglyMeasurable #align strongly_measurable_id stronglyMeasurable_id end SecondCountableStronglyMeasurable /-- A function is strongly measurable if and only if it is measurable and has separable range. -/ theorem _root_.stronglyMeasurable_iff_measurable_separable {m : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] : StronglyMeasurable f ↔ Measurable f ∧ IsSeparable (range f) := by refine ⟨fun H ↦ ⟨H.measurable, H.isSeparable_range⟩, fun ⟨Hm, Hsep⟩ ↦ ?_⟩ have := Hsep.secondCountableTopology have Hm' : StronglyMeasurable (rangeFactorization f) := Hm.subtype_mk.stronglyMeasurable exact continuous_subtype_val.comp_stronglyMeasurable Hm' #align strongly_measurable_iff_measurable_separable stronglyMeasurable_iff_measurable_separable /-- A continuous function is strongly measurable when either the source space or the target space is second-countable. -/ theorem _root_.Continuous.stronglyMeasurable [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [TopologicalSpace β] [PseudoMetrizableSpace β] [h : SecondCountableTopologyEither α β] {f : α → β} (hf : Continuous f) : StronglyMeasurable f := by borelize β cases h.out · rw [stronglyMeasurable_iff_measurable_separable] refine ⟨hf.measurable, ?_⟩ exact isSeparable_range hf · exact hf.measurable.stronglyMeasurable #align continuous.strongly_measurable Continuous.stronglyMeasurable /-- A continuous function whose support is contained in a compact set is strongly measurable. -/ @[to_additive] theorem _root_.Continuous.stronglyMeasurable_of_mulSupport_subset_isCompact [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [MeasurableSpace β] [TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [One β] {f : α → β} (hf : Continuous f) {k : Set α} (hk : IsCompact k) (h'f : mulSupport f ⊆ k) : StronglyMeasurable f := by letI : PseudoMetricSpace β := pseudoMetrizableSpacePseudoMetric β rw [stronglyMeasurable_iff_measurable_separable] exact ⟨hf.measurable, (isCompact_range_of_mulSupport_subset_isCompact hf hk h'f).isSeparable⟩ /-- A continuous function with compact support is strongly measurable. -/ @[to_additive] theorem _root_.Continuous.stronglyMeasurable_of_hasCompactMulSupport [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [MeasurableSpace β] [TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [One β] {f : α → β} (hf : Continuous f) (h'f : HasCompactMulSupport f) : StronglyMeasurable f := hf.stronglyMeasurable_of_mulSupport_subset_isCompact h'f (subset_mulTSupport f) /-- A continuous function with compact support on a product space is strongly measurable for the product sigma-algebra. The subtlety is that we do not assume that the spaces are separable, so the product of the Borel sigma algebras might not contain all open sets, but still it contains enough of them to approximate compactly supported continuous functions. -/ lemma _root_.HasCompactSupport.stronglyMeasurable_of_prod {X Y : Type*} [Zero α] [TopologicalSpace X] [TopologicalSpace Y] [MeasurableSpace X] [MeasurableSpace Y] [OpensMeasurableSpace X] [OpensMeasurableSpace Y] [TopologicalSpace α] [PseudoMetrizableSpace α] {f : X × Y → α} (hf : Continuous f) (h'f : HasCompactSupport f) : StronglyMeasurable f := by borelize α apply stronglyMeasurable_iff_measurable_separable.2 ⟨h'f.measurable_of_prod hf, ?_⟩ letI : PseudoMetricSpace α := pseudoMetrizableSpacePseudoMetric α exact IsCompact.isSeparable (s := range f) (h'f.isCompact_range hf) /-- If `g` is a topological embedding, then `f` is strongly measurable iff `g ∘ f` is. -/ theorem _root_.Embedding.comp_stronglyMeasurable_iff {m : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [TopologicalSpace γ] [PseudoMetrizableSpace γ] {g : β → γ} {f : α → β} (hg : Embedding g) : (StronglyMeasurable fun x => g (f x)) ↔ StronglyMeasurable f := by letI := pseudoMetrizableSpacePseudoMetric γ borelize β γ refine ⟨fun H => stronglyMeasurable_iff_measurable_separable.2 ⟨?_, ?_⟩, fun H => hg.continuous.comp_stronglyMeasurable H⟩ · let G : β → range g := rangeFactorization g have hG : ClosedEmbedding G := { hg.codRestrict _ _ with isClosed_range := by rw [surjective_onto_range.range_eq] exact isClosed_univ } have : Measurable (G ∘ f) := Measurable.subtype_mk H.measurable exact hG.measurableEmbedding.measurable_comp_iff.1 this · have : IsSeparable (g ⁻¹' range (g ∘ f)) := hg.isSeparable_preimage H.isSeparable_range rwa [range_comp, hg.inj.preimage_image] at this #align embedding.comp_strongly_measurable_iff Embedding.comp_stronglyMeasurable_iff /-- A sequential limit of strongly measurable functions is strongly measurable. -/ theorem _root_.stronglyMeasurable_of_tendsto {ι : Type*} {m : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] (u : Filter ι) [NeBot u] [IsCountablyGenerated u] {f : ι → α → β} {g : α → β} (hf : ∀ i, StronglyMeasurable (f i)) (lim : Tendsto f u (𝓝 g)) : StronglyMeasurable g := by borelize β refine stronglyMeasurable_iff_measurable_separable.2 ⟨?_, ?_⟩ · exact measurable_of_tendsto_metrizable' u (fun i => (hf i).measurable) lim · rcases u.exists_seq_tendsto with ⟨v, hv⟩ have : IsSeparable (closure (⋃ i, range (f (v i)))) := .closure <| .iUnion fun i => (hf (v i)).isSeparable_range apply this.mono rintro _ ⟨x, rfl⟩ rw [tendsto_pi_nhds] at lim apply mem_closure_of_tendsto ((lim x).comp hv) filter_upwards with n apply mem_iUnion_of_mem n exact mem_range_self _ #align strongly_measurable_of_tendsto stronglyMeasurable_of_tendsto protected theorem piecewise {m : MeasurableSpace α} [TopologicalSpace β] {s : Set α} {_ : DecidablePred (· ∈ s)} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (Set.piecewise s f g) := by refine ⟨fun n => SimpleFunc.piecewise s hs (hf.approx n) (hg.approx n), fun x => ?_⟩ by_cases hx : x ∈ s · simpa [@Set.piecewise_eq_of_mem _ _ _ _ _ (fun _ => Classical.propDecidable _) _ hx, hx] using hf.tendsto_approx x · simpa [@Set.piecewise_eq_of_not_mem _ _ _ _ _ (fun _ => Classical.propDecidable _) _ hx, hx] using hg.tendsto_approx x #align measure_theory.strongly_measurable.piecewise MeasureTheory.StronglyMeasurable.piecewise /-- this is slightly different from `StronglyMeasurable.piecewise`. It can be used to show `StronglyMeasurable (ite (x=0) 0 1)` by `exact StronglyMeasurable.ite (measurableSet_singleton 0) stronglyMeasurable_const stronglyMeasurable_const`, but replacing `StronglyMeasurable.ite` by `StronglyMeasurable.piecewise` in that example proof does not work. -/ protected theorem ite {_ : MeasurableSpace α} [TopologicalSpace β] {p : α → Prop} {_ : DecidablePred p} (hp : MeasurableSet { a : α | p a }) (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => ite (p x) (f x) (g x) := StronglyMeasurable.piecewise hp hf hg #align measure_theory.strongly_measurable.ite MeasureTheory.StronglyMeasurable.ite @[measurability] theorem _root_.MeasurableEmbedding.stronglyMeasurable_extend {f : α → β} {g : α → γ} {g' : γ → β} {mα : MeasurableSpace α} {mγ : MeasurableSpace γ} [TopologicalSpace β] (hg : MeasurableEmbedding g) (hf : StronglyMeasurable f) (hg' : StronglyMeasurable g') : StronglyMeasurable (Function.extend g f g') := by refine ⟨fun n => SimpleFunc.extend (hf.approx n) g hg (hg'.approx n), ?_⟩ intro x by_cases hx : ∃ y, g y = x · rcases hx with ⟨y, rfl⟩ simpa only [SimpleFunc.extend_apply, hg.injective, Injective.extend_apply] using hf.tendsto_approx y · simpa only [hx, SimpleFunc.extend_apply', not_false_iff, extend_apply'] using hg'.tendsto_approx x #align measurable_embedding.strongly_measurable_extend MeasurableEmbedding.stronglyMeasurable_extend theorem _root_.MeasurableEmbedding.exists_stronglyMeasurable_extend {f : α → β} {g : α → γ} {_ : MeasurableSpace α} {_ : MeasurableSpace γ} [TopologicalSpace β] (hg : MeasurableEmbedding g) (hf : StronglyMeasurable f) (hne : γ → Nonempty β) : ∃ f' : γ → β, StronglyMeasurable f' ∧ f' ∘ g = f := ⟨Function.extend g f fun x => Classical.choice (hne x), hg.stronglyMeasurable_extend hf (stronglyMeasurable_const' fun _ _ => rfl), funext fun _ => hg.injective.extend_apply _ _ _⟩ #align measurable_embedding.exists_strongly_measurable_extend MeasurableEmbedding.exists_stronglyMeasurable_extend theorem _root_.stronglyMeasurable_of_stronglyMeasurable_union_cover {m : MeasurableSpace α} [TopologicalSpace β] {f : α → β} (s t : Set α) (hs : MeasurableSet s) (ht : MeasurableSet t) (h : univ ⊆ s ∪ t) (hc : StronglyMeasurable fun a : s => f a) (hd : StronglyMeasurable fun a : t => f a) : StronglyMeasurable f := by nontriviality β; inhabit β suffices Function.extend Subtype.val (fun x : s ↦ f x) (Function.extend (↑) (fun x : t ↦ f x) fun _ ↦ default) = f from this ▸ (MeasurableEmbedding.subtype_coe hs).stronglyMeasurable_extend hc <| (MeasurableEmbedding.subtype_coe ht).stronglyMeasurable_extend hd stronglyMeasurable_const ext x by_cases hxs : x ∈ s · lift x to s using hxs simp [Subtype.coe_injective.extend_apply] · lift x to t using (h trivial).resolve_left hxs rw [extend_apply', Subtype.coe_injective.extend_apply] exact fun ⟨y, hy⟩ ↦ hxs <| hy ▸ y.2 #align strongly_measurable_of_strongly_measurable_union_cover stronglyMeasurable_of_stronglyMeasurable_union_cover theorem _root_.stronglyMeasurable_of_restrict_of_restrict_compl {_ : MeasurableSpace α} [TopologicalSpace β] {f : α → β} {s : Set α} (hs : MeasurableSet s) (h₁ : StronglyMeasurable (s.restrict f)) (h₂ : StronglyMeasurable (sᶜ.restrict f)) : StronglyMeasurable f := stronglyMeasurable_of_stronglyMeasurable_union_cover s sᶜ hs hs.compl (union_compl_self s).ge h₁ h₂ #align strongly_measurable_of_restrict_of_restrict_compl stronglyMeasurable_of_restrict_of_restrict_compl @[measurability] protected theorem indicator {_ : MeasurableSpace α} [TopologicalSpace β] [Zero β] (hf : StronglyMeasurable f) {s : Set α} (hs : MeasurableSet s) : StronglyMeasurable (s.indicator f) := hf.piecewise hs stronglyMeasurable_const #align measure_theory.strongly_measurable.indicator MeasureTheory.StronglyMeasurable.indicator @[aesop safe 20 apply (rule_sets := [Measurable])] protected theorem dist {_ : MeasurableSpace α} {β : Type*} [PseudoMetricSpace β] {f g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => dist (f x) (g x) := continuous_dist.comp_stronglyMeasurable (hf.prod_mk hg) #align measure_theory.strongly_measurable.dist MeasureTheory.StronglyMeasurable.dist @[measurability] protected theorem norm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ‖f x‖ := continuous_norm.comp_stronglyMeasurable hf #align measure_theory.strongly_measurable.norm MeasureTheory.StronglyMeasurable.norm @[measurability] protected theorem nnnorm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ‖f x‖₊ := continuous_nnnorm.comp_stronglyMeasurable hf #align measure_theory.strongly_measurable.nnnorm MeasureTheory.StronglyMeasurable.nnnorm @[measurability] protected theorem ennnorm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : StronglyMeasurable f) : Measurable fun a => (‖f a‖₊ : ℝ≥0∞) := (ENNReal.continuous_coe.comp_stronglyMeasurable hf.nnnorm).measurable #align measure_theory.strongly_measurable.ennnorm MeasureTheory.StronglyMeasurable.ennnorm @[measurability] protected theorem real_toNNReal {_ : MeasurableSpace α} {f : α → ℝ} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => (f x).toNNReal := continuous_real_toNNReal.comp_stronglyMeasurable hf #align measure_theory.strongly_measurable.real_to_nnreal MeasureTheory.StronglyMeasurable.real_toNNReal theorem measurableSet_eq_fun {m : MeasurableSpace α} {E} [TopologicalSpace E] [MetrizableSpace E] {f g : α → E} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : MeasurableSet { x | f x = g x } := by borelize (E × E) exact (hf.prod_mk hg).measurable isClosed_diagonal.measurableSet #align measure_theory.strongly_measurable.measurable_set_eq_fun MeasureTheory.StronglyMeasurable.measurableSet_eq_fun theorem measurableSet_lt {m : MeasurableSpace α} [TopologicalSpace β] [LinearOrder β] [OrderClosedTopology β] [PseudoMetrizableSpace β] {f g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : MeasurableSet { a | f a < g a } := by borelize (β × β) exact (hf.prod_mk hg).measurable isOpen_lt_prod.measurableSet #align measure_theory.strongly_measurable.measurable_set_lt MeasureTheory.StronglyMeasurable.measurableSet_lt theorem measurableSet_le {m : MeasurableSpace α} [TopologicalSpace β] [Preorder β] [OrderClosedTopology β] [PseudoMetrizableSpace β] {f g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : MeasurableSet { a | f a ≤ g a } := by borelize (β × β) exact (hf.prod_mk hg).measurable isClosed_le_prod.measurableSet #align measure_theory.strongly_measurable.measurable_set_le MeasureTheory.StronglyMeasurable.measurableSet_le theorem stronglyMeasurable_in_set {m : MeasurableSpace α} [TopologicalSpace β] [Zero β] {s : Set α} {f : α → β} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hf_zero : ∀ x, x ∉ s → f x = 0) : ∃ fs : ℕ → α →ₛ β, (∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x))) ∧ ∀ x ∉ s, ∀ n, fs n x = 0 := by let g_seq_s : ℕ → @SimpleFunc α m β := fun n => (hf.approx n).restrict s have hg_eq : ∀ x ∈ s, ∀ n, g_seq_s n x = hf.approx n x := by intro x hx n rw [SimpleFunc.coe_restrict _ hs, Set.indicator_of_mem hx] have hg_zero : ∀ x ∉ s, ∀ n, g_seq_s n x = 0 := by intro x hx n rw [SimpleFunc.coe_restrict _ hs, Set.indicator_of_not_mem hx] refine ⟨g_seq_s, fun x => ?_, hg_zero⟩ by_cases hx : x ∈ s · simp_rw [hg_eq x hx] exact hf.tendsto_approx x · simp_rw [hg_zero x hx, hf_zero x hx] exact tendsto_const_nhds #align measure_theory.strongly_measurable.strongly_measurable_in_set MeasureTheory.StronglyMeasurable.stronglyMeasurable_in_set /-- If the restriction to a set `s` of a σ-algebra `m` is included in the restriction to `s` of another σ-algebra `m₂` (hypothesis `hs`), the set `s` is `m` measurable and a function `f` supported on `s` is `m`-strongly-measurable, then `f` is also `m₂`-strongly-measurable. -/ theorem stronglyMeasurable_of_measurableSpace_le_on {α E} {m m₂ : MeasurableSpace α} [TopologicalSpace E] [Zero E] {s : Set α} {f : α → E} (hs_m : MeasurableSet[m] s) (hs : ∀ t, MeasurableSet[m] (s ∩ t) → MeasurableSet[m₂] (s ∩ t)) (hf : StronglyMeasurable[m] f) (hf_zero : ∀ x ∉ s, f x = 0) : StronglyMeasurable[m₂] f := by have hs_m₂ : MeasurableSet[m₂] s := by rw [← Set.inter_univ s] refine hs Set.univ ?_ rwa [Set.inter_univ] obtain ⟨g_seq_s, hg_seq_tendsto, hg_seq_zero⟩ := stronglyMeasurable_in_set hs_m hf hf_zero let g_seq_s₂ : ℕ → @SimpleFunc α m₂ E := fun n => { toFun := g_seq_s n measurableSet_fiber' := fun x => by rw [← Set.inter_univ (g_seq_s n ⁻¹' {x}), ← Set.union_compl_self s, Set.inter_union_distrib_left, Set.inter_comm (g_seq_s n ⁻¹' {x})] refine MeasurableSet.union (hs _ (hs_m.inter ?_)) ?_ · exact @SimpleFunc.measurableSet_fiber _ _ m _ _ by_cases hx : x = 0 · suffices g_seq_s n ⁻¹' {x} ∩ sᶜ = sᶜ by rw [this] exact hs_m₂.compl ext1 y rw [hx, Set.mem_inter_iff, Set.mem_preimage, Set.mem_singleton_iff] exact ⟨fun h => h.2, fun h => ⟨hg_seq_zero y h n, h⟩⟩ · suffices g_seq_s n ⁻¹' {x} ∩ sᶜ = ∅ by rw [this] exact MeasurableSet.empty ext1 y simp only [mem_inter_iff, mem_preimage, mem_singleton_iff, mem_compl_iff, mem_empty_iff_false, iff_false_iff, not_and, not_not_mem] refine Function.mtr fun hys => ?_ rw [hg_seq_zero y hys n] exact Ne.symm hx finite_range' := @SimpleFunc.finite_range _ _ m (g_seq_s n) } exact ⟨g_seq_s₂, hg_seq_tendsto⟩ #align measure_theory.strongly_measurable.strongly_measurable_of_measurable_space_le_on MeasureTheory.StronglyMeasurable.stronglyMeasurable_of_measurableSpace_le_on /-- If a function `f` is strongly measurable w.r.t. a sub-σ-algebra `m` and the measure is σ-finite on `m`, then there exists spanning measurable sets with finite measure on which `f` has bounded norm. In particular, `f` is integrable on each of those sets. -/ theorem exists_spanning_measurableSet_norm_le [SeminormedAddCommGroup β] {m m0 : MeasurableSpace α} (hm : m ≤ m0) (hf : StronglyMeasurable[m] f) (μ : Measure α) [SigmaFinite (μ.trim hm)] : ∃ s : ℕ → Set α, (∀ n, MeasurableSet[m] (s n) ∧ μ (s n) < ∞ ∧ ∀ x ∈ s n, ‖f x‖ ≤ n) ∧ ⋃ i, s i = Set.univ := by obtain ⟨s, hs, hs_univ⟩ := exists_spanning_measurableSet_le hf.nnnorm.measurable (μ.trim hm) refine ⟨s, fun n ↦ ⟨(hs n).1, (le_trim hm).trans_lt (hs n).2.1, fun x hx ↦ ?_⟩, hs_univ⟩ have hx_nnnorm : ‖f x‖₊ ≤ n := (hs n).2.2 x hx rw [← coe_nnnorm] norm_cast #align measure_theory.strongly_measurable.exists_spanning_measurable_set_norm_le MeasureTheory.StronglyMeasurable.exists_spanning_measurableSet_norm_le end StronglyMeasurable /-! ## Finitely strongly measurable functions -/ theorem finStronglyMeasurable_zero {α β} {m : MeasurableSpace α} {μ : Measure α} [Zero β] [TopologicalSpace β] : FinStronglyMeasurable (0 : α → β) μ := ⟨0, by simp only [Pi.zero_apply, SimpleFunc.coe_zero, support_zero', measure_empty, zero_lt_top, forall_const], fun _ => tendsto_const_nhds⟩ #align measure_theory.fin_strongly_measurable_zero MeasureTheory.finStronglyMeasurable_zero namespace FinStronglyMeasurable variable {m0 : MeasurableSpace α} {μ : Measure α} {f g : α → β} theorem aefinStronglyMeasurable [Zero β] [TopologicalSpace β] (hf : FinStronglyMeasurable f μ) : AEFinStronglyMeasurable f μ := ⟨f, hf, ae_eq_refl f⟩ #align measure_theory.fin_strongly_measurable.ae_fin_strongly_measurable MeasureTheory.FinStronglyMeasurable.aefinStronglyMeasurable section sequence variable [Zero β] [TopologicalSpace β] (hf : FinStronglyMeasurable f μ) /-- A sequence of simple functions such that `∀ x, Tendsto (fun n ↦ hf.approx n x) atTop (𝓝 (f x))` and `∀ n, μ (support (hf.approx n)) < ∞`. These properties are given by `FinStronglyMeasurable.tendsto_approx` and `FinStronglyMeasurable.fin_support_approx`. -/ protected noncomputable def approx : ℕ → α →ₛ β := hf.choose #align measure_theory.fin_strongly_measurable.approx MeasureTheory.FinStronglyMeasurable.approx protected theorem fin_support_approx : ∀ n, μ (support (hf.approx n)) < ∞ := hf.choose_spec.1 #align measure_theory.fin_strongly_measurable.fin_support_approx MeasureTheory.FinStronglyMeasurable.fin_support_approx protected theorem tendsto_approx : ∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x)) := hf.choose_spec.2 #align measure_theory.fin_strongly_measurable.tendsto_approx MeasureTheory.FinStronglyMeasurable.tendsto_approx end sequence /-- A finitely strongly measurable function is strongly measurable. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem stronglyMeasurable [Zero β] [TopologicalSpace β] (hf : FinStronglyMeasurable f μ) : StronglyMeasurable f := ⟨hf.approx, hf.tendsto_approx⟩ #align measure_theory.fin_strongly_measurable.strongly_measurable MeasureTheory.FinStronglyMeasurable.stronglyMeasurable theorem exists_set_sigmaFinite [Zero β] [TopologicalSpace β] [T2Space β] (hf : FinStronglyMeasurable f μ) : ∃ t, MeasurableSet t ∧ (∀ x ∈ tᶜ, f x = 0) ∧ SigmaFinite (μ.restrict t) := by rcases hf with ⟨fs, hT_lt_top, h_approx⟩ let T n := support (fs n) have hT_meas : ∀ n, MeasurableSet (T n) := fun n => SimpleFunc.measurableSet_support (fs n) let t := ⋃ n, T n refine ⟨t, MeasurableSet.iUnion hT_meas, ?_, ?_⟩ · have h_fs_zero : ∀ n, ∀ x ∈ tᶜ, fs n x = 0 := by intro n x hxt rw [Set.mem_compl_iff, Set.mem_iUnion, not_exists] at hxt simpa [T] using hxt n refine fun x hxt => tendsto_nhds_unique (h_approx x) ?_ rw [funext fun n => h_fs_zero n x hxt] exact tendsto_const_nhds · refine ⟨⟨⟨fun n => tᶜ ∪ T n, fun _ => trivial, fun n => ?_, ?_⟩⟩⟩ · rw [Measure.restrict_apply' (MeasurableSet.iUnion hT_meas), Set.union_inter_distrib_right, Set.compl_inter_self t, Set.empty_union] exact (measure_mono Set.inter_subset_left).trans_lt (hT_lt_top n) · rw [← Set.union_iUnion tᶜ T] exact Set.compl_union_self _ #align measure_theory.fin_strongly_measurable.exists_set_sigma_finite MeasureTheory.FinStronglyMeasurable.exists_set_sigmaFinite /-- A finitely strongly measurable function is measurable. -/ protected theorem measurable [Zero β] [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf : FinStronglyMeasurable f μ) : Measurable f := hf.stronglyMeasurable.measurable #align measure_theory.fin_strongly_measurable.measurable MeasureTheory.FinStronglyMeasurable.measurable section Arithmetic variable [TopologicalSpace β] @[aesop safe 20 (rule_sets := [Measurable])] protected theorem mul [MonoidWithZero β] [ContinuousMul β] (hf : FinStronglyMeasurable f μ) (hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f * g) μ := by refine ⟨fun n => hf.approx n * hg.approx n, ?_, fun x => (hf.tendsto_approx x).mul (hg.tendsto_approx x)⟩ intro n exact (measure_mono (support_mul_subset_left _ _)).trans_lt (hf.fin_support_approx n) #align measure_theory.fin_strongly_measurable.mul MeasureTheory.FinStronglyMeasurable.mul @[aesop safe 20 (rule_sets := [Measurable])] protected theorem add [AddMonoid β] [ContinuousAdd β] (hf : FinStronglyMeasurable f μ) (hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f + g) μ := ⟨fun n => hf.approx n + hg.approx n, fun n => (measure_mono (Function.support_add _ _)).trans_lt ((measure_union_le _ _).trans_lt (ENNReal.add_lt_top.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩)), fun x => (hf.tendsto_approx x).add (hg.tendsto_approx x)⟩ #align measure_theory.fin_strongly_measurable.add MeasureTheory.FinStronglyMeasurable.add @[measurability] protected theorem neg [AddGroup β] [TopologicalAddGroup β] (hf : FinStronglyMeasurable f μ) : FinStronglyMeasurable (-f) μ := by refine ⟨fun n => -hf.approx n, fun n => ?_, fun x => (hf.tendsto_approx x).neg⟩ suffices μ (Function.support fun x => -(hf.approx n) x) < ∞ by convert this rw [Function.support_neg (hf.approx n)] exact hf.fin_support_approx n #align measure_theory.fin_strongly_measurable.neg MeasureTheory.FinStronglyMeasurable.neg @[measurability] protected theorem sub [AddGroup β] [ContinuousSub β] (hf : FinStronglyMeasurable f μ) (hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f - g) μ := ⟨fun n => hf.approx n - hg.approx n, fun n => (measure_mono (Function.support_sub _ _)).trans_lt ((measure_union_le _ _).trans_lt (ENNReal.add_lt_top.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩)), fun x => (hf.tendsto_approx x).sub (hg.tendsto_approx x)⟩ #align measure_theory.fin_strongly_measurable.sub MeasureTheory.FinStronglyMeasurable.sub @[measurability] protected theorem const_smul {𝕜} [TopologicalSpace 𝕜] [AddMonoid β] [Monoid 𝕜] [DistribMulAction 𝕜 β] [ContinuousSMul 𝕜 β] (hf : FinStronglyMeasurable f μ) (c : 𝕜) : FinStronglyMeasurable (c • f) μ := by refine ⟨fun n => c • hf.approx n, fun n => ?_, fun x => (hf.tendsto_approx x).const_smul c⟩ rw [SimpleFunc.coe_smul] exact (measure_mono (support_const_smul_subset c _)).trans_lt (hf.fin_support_approx n) #align measure_theory.fin_strongly_measurable.const_smul MeasureTheory.FinStronglyMeasurable.const_smul end Arithmetic section Order variable [TopologicalSpace β] [Zero β] @[aesop safe 20 (rule_sets := [Measurable])] protected theorem sup [SemilatticeSup β] [ContinuousSup β] (hf : FinStronglyMeasurable f μ) (hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f ⊔ g) μ := by refine ⟨fun n => hf.approx n ⊔ hg.approx n, fun n => ?_, fun x => (hf.tendsto_approx x).sup_nhds (hg.tendsto_approx x)⟩ refine (measure_mono (support_sup _ _)).trans_lt ?_ exact measure_union_lt_top_iff.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩ #align measure_theory.fin_strongly_measurable.sup MeasureTheory.FinStronglyMeasurable.sup @[aesop safe 20 (rule_sets := [Measurable])] protected theorem inf [SemilatticeInf β] [ContinuousInf β] (hf : FinStronglyMeasurable f μ) (hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f ⊓ g) μ := by refine ⟨fun n => hf.approx n ⊓ hg.approx n, fun n => ?_, fun x => (hf.tendsto_approx x).inf_nhds (hg.tendsto_approx x)⟩ refine (measure_mono (support_inf _ _)).trans_lt ?_ exact measure_union_lt_top_iff.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩ #align measure_theory.fin_strongly_measurable.inf MeasureTheory.FinStronglyMeasurable.inf end Order end FinStronglyMeasurable theorem finStronglyMeasurable_iff_stronglyMeasurable_and_exists_set_sigmaFinite {α β} {f : α → β} [TopologicalSpace β] [T2Space β] [Zero β] {_ : MeasurableSpace α} {μ : Measure α} : FinStronglyMeasurable f μ ↔ StronglyMeasurable f ∧ ∃ t, MeasurableSet t ∧ (∀ x ∈ tᶜ, f x = 0) ∧ SigmaFinite (μ.restrict t) := ⟨fun hf => ⟨hf.stronglyMeasurable, hf.exists_set_sigmaFinite⟩, fun hf => hf.1.finStronglyMeasurable_of_set_sigmaFinite hf.2.choose_spec.1 hf.2.choose_spec.2.1 hf.2.choose_spec.2.2⟩ #align measure_theory.fin_strongly_measurable_iff_strongly_measurable_and_exists_set_sigma_finite MeasureTheory.finStronglyMeasurable_iff_stronglyMeasurable_and_exists_set_sigmaFinite theorem aefinStronglyMeasurable_zero {α β} {_ : MeasurableSpace α} (μ : Measure α) [Zero β] [TopologicalSpace β] : AEFinStronglyMeasurable (0 : α → β) μ := ⟨0, finStronglyMeasurable_zero, EventuallyEq.rfl⟩ #align measure_theory.ae_fin_strongly_measurable_zero MeasureTheory.aefinStronglyMeasurable_zero /-! ## Almost everywhere strongly measurable functions -/ @[measurability] theorem aestronglyMeasurable_const {α β} {_ : MeasurableSpace α} {μ : Measure α} [TopologicalSpace β] {b : β} : AEStronglyMeasurable (fun _ : α => b) μ := stronglyMeasurable_const.aestronglyMeasurable #align measure_theory.ae_strongly_measurable_const MeasureTheory.aestronglyMeasurable_const @[to_additive (attr := measurability)] theorem aestronglyMeasurable_one {α β} {_ : MeasurableSpace α} {μ : Measure α} [TopologicalSpace β] [One β] : AEStronglyMeasurable (1 : α → β) μ := stronglyMeasurable_one.aestronglyMeasurable #align measure_theory.ae_strongly_measurable_one MeasureTheory.aestronglyMeasurable_one #align measure_theory.ae_strongly_measurable_zero MeasureTheory.aestronglyMeasurable_zero @[simp] theorem Subsingleton.aestronglyMeasurable {_ : MeasurableSpace α} [TopologicalSpace β] [Subsingleton β] {μ : Measure α} (f : α → β) : AEStronglyMeasurable f μ := (Subsingleton.stronglyMeasurable f).aestronglyMeasurable #align measure_theory.subsingleton.ae_strongly_measurable MeasureTheory.Subsingleton.aestronglyMeasurable @[simp] theorem Subsingleton.aestronglyMeasurable' {_ : MeasurableSpace α} [TopologicalSpace β] [Subsingleton α] {μ : Measure α} (f : α → β) : AEStronglyMeasurable f μ := (Subsingleton.stronglyMeasurable' f).aestronglyMeasurable #align measure_theory.subsingleton.ae_strongly_measurable' MeasureTheory.Subsingleton.aestronglyMeasurable' @[simp] theorem aestronglyMeasurable_zero_measure [MeasurableSpace α] [TopologicalSpace β] (f : α → β) : AEStronglyMeasurable f (0 : Measure α) := by nontriviality α inhabit α exact ⟨fun _ => f default, stronglyMeasurable_const, rfl⟩ #align measure_theory.ae_strongly_measurable_zero_measure MeasureTheory.aestronglyMeasurable_zero_measure @[measurability] theorem SimpleFunc.aestronglyMeasurable {_ : MeasurableSpace α} {μ : Measure α} [TopologicalSpace β] (f : α →ₛ β) : AEStronglyMeasurable f μ := f.stronglyMeasurable.aestronglyMeasurable #align measure_theory.simple_func.ae_strongly_measurable MeasureTheory.SimpleFunc.aestronglyMeasurable namespace AEStronglyMeasurable variable {m : MeasurableSpace α} {μ ν : Measure α} [TopologicalSpace β] [TopologicalSpace γ] {f g : α → β} section Mk /-- A `StronglyMeasurable` function such that `f =ᵐ[μ] hf.mk f`. See lemmas `stronglyMeasurable_mk` and `ae_eq_mk`. -/ protected noncomputable def mk (f : α → β) (hf : AEStronglyMeasurable f μ) : α → β := hf.choose #align measure_theory.ae_strongly_measurable.mk MeasureTheory.AEStronglyMeasurable.mk theorem stronglyMeasurable_mk (hf : AEStronglyMeasurable f μ) : StronglyMeasurable (hf.mk f) := hf.choose_spec.1 #align measure_theory.ae_strongly_measurable.strongly_measurable_mk MeasureTheory.AEStronglyMeasurable.stronglyMeasurable_mk theorem measurable_mk [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf : AEStronglyMeasurable f μ) : Measurable (hf.mk f) := hf.stronglyMeasurable_mk.measurable #align measure_theory.ae_strongly_measurable.measurable_mk MeasureTheory.AEStronglyMeasurable.measurable_mk theorem ae_eq_mk (hf : AEStronglyMeasurable f μ) : f =ᵐ[μ] hf.mk f := hf.choose_spec.2 #align measure_theory.ae_strongly_measurable.ae_eq_mk MeasureTheory.AEStronglyMeasurable.ae_eq_mk @[aesop 5% apply (rule_sets := [Measurable])] protected theorem aemeasurable {β} [MeasurableSpace β] [TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] {f : α → β} (hf : AEStronglyMeasurable f μ) : AEMeasurable f μ := ⟨hf.mk f, hf.stronglyMeasurable_mk.measurable, hf.ae_eq_mk⟩ #align measure_theory.ae_strongly_measurable.ae_measurable MeasureTheory.AEStronglyMeasurable.aemeasurable end Mk theorem congr (hf : AEStronglyMeasurable f μ) (h : f =ᵐ[μ] g) : AEStronglyMeasurable g μ := ⟨hf.mk f, hf.stronglyMeasurable_mk, h.symm.trans hf.ae_eq_mk⟩ #align measure_theory.ae_strongly_measurable.congr MeasureTheory.AEStronglyMeasurable.congr theorem _root_.aestronglyMeasurable_congr (h : f =ᵐ[μ] g) : AEStronglyMeasurable f μ ↔ AEStronglyMeasurable g μ := ⟨fun hf => hf.congr h, fun hg => hg.congr h.symm⟩ #align ae_strongly_measurable_congr aestronglyMeasurable_congr theorem mono_measure {ν : Measure α} (hf : AEStronglyMeasurable f μ) (h : ν ≤ μ) : AEStronglyMeasurable f ν := ⟨hf.mk f, hf.stronglyMeasurable_mk, Eventually.filter_mono (ae_mono h) hf.ae_eq_mk⟩ #align measure_theory.ae_strongly_measurable.mono_measure MeasureTheory.AEStronglyMeasurable.mono_measure protected lemma mono_ac (h : ν ≪ μ) (hμ : AEStronglyMeasurable f μ) : AEStronglyMeasurable f ν := let ⟨g, hg, hg'⟩ := hμ; ⟨g, hg, h.ae_eq hg'⟩ #align measure_theory.ae_strongly_measurable.mono' MeasureTheory.AEStronglyMeasurable.mono_ac #align measure_theory.ae_strongly_measurable_of_absolutely_continuous MeasureTheory.AEStronglyMeasurable.mono_ac @[deprecated (since := "2024-02-15")] protected alias mono' := AEStronglyMeasurable.mono_ac theorem mono_set {s t} (h : s ⊆ t) (ht : AEStronglyMeasurable f (μ.restrict t)) : AEStronglyMeasurable f (μ.restrict s) := ht.mono_measure (restrict_mono h le_rfl) #align measure_theory.ae_strongly_measurable.mono_set MeasureTheory.AEStronglyMeasurable.mono_set protected theorem restrict (hfm : AEStronglyMeasurable f μ) {s} : AEStronglyMeasurable f (μ.restrict s) := hfm.mono_measure Measure.restrict_le_self #align measure_theory.ae_strongly_measurable.restrict MeasureTheory.AEStronglyMeasurable.restrict theorem ae_mem_imp_eq_mk {s} (h : AEStronglyMeasurable f (μ.restrict s)) : ∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x := ae_imp_of_ae_restrict h.ae_eq_mk #align measure_theory.ae_strongly_measurable.ae_mem_imp_eq_mk MeasureTheory.AEStronglyMeasurable.ae_mem_imp_eq_mk /-- The composition of a continuous function and an ae strongly measurable function is ae strongly measurable. -/ theorem _root_.Continuous.comp_aestronglyMeasurable {g : β → γ} {f : α → β} (hg : Continuous g) (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x => g (f x)) μ := ⟨_, hg.comp_stronglyMeasurable hf.stronglyMeasurable_mk, EventuallyEq.fun_comp hf.ae_eq_mk g⟩ #align continuous.comp_ae_strongly_measurable Continuous.comp_aestronglyMeasurable /-- A continuous function from `α` to `β` is ae strongly measurable when one of the two spaces is second countable. -/ theorem _root_.Continuous.aestronglyMeasurable [TopologicalSpace α] [OpensMeasurableSpace α] [PseudoMetrizableSpace β] [SecondCountableTopologyEither α β] (hf : Continuous f) : AEStronglyMeasurable f μ := hf.stronglyMeasurable.aestronglyMeasurable #align continuous.ae_strongly_measurable Continuous.aestronglyMeasurable protected theorem prod_mk {f : α → β} {g : α → γ} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (fun x => (f x, g x)) μ := ⟨fun x => (hf.mk f x, hg.mk g x), hf.stronglyMeasurable_mk.prod_mk hg.stronglyMeasurable_mk, hf.ae_eq_mk.prod_mk hg.ae_eq_mk⟩ #align measure_theory.ae_strongly_measurable.prod_mk MeasureTheory.AEStronglyMeasurable.prod_mk /-- The composition of a continuous function of two variables and two ae strongly measurable functions is ae strongly measurable. -/ theorem _root_.Continuous.comp_aestronglyMeasurable₂ {β' : Type*} [TopologicalSpace β'] {g : β → β' → γ} {f : α → β} {f' : α → β'} (hg : Continuous g.uncurry) (hf : AEStronglyMeasurable f μ) (h'f : AEStronglyMeasurable f' μ) : AEStronglyMeasurable (fun x => g (f x) (f' x)) μ := hg.comp_aestronglyMeasurable (hf.prod_mk h'f) /-- In a space with second countable topology, measurable implies ae strongly measurable. -/ @[aesop unsafe 30% apply (rule_sets := [Measurable])] theorem _root_.Measurable.aestronglyMeasurable {_ : MeasurableSpace α} {μ : Measure α} [MeasurableSpace β] [PseudoMetrizableSpace β] [SecondCountableTopology β] [OpensMeasurableSpace β] (hf : Measurable f) : AEStronglyMeasurable f μ := hf.stronglyMeasurable.aestronglyMeasurable #align measurable.ae_strongly_measurable Measurable.aestronglyMeasurable section Arithmetic @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem mul [Mul β] [ContinuousMul β] (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (f * g) μ := ⟨hf.mk f * hg.mk g, hf.stronglyMeasurable_mk.mul hg.stronglyMeasurable_mk, hf.ae_eq_mk.mul hg.ae_eq_mk⟩ #align measure_theory.ae_strongly_measurable.mul MeasureTheory.AEStronglyMeasurable.mul #align measure_theory.ae_strongly_measurable.add MeasureTheory.AEStronglyMeasurable.add @[to_additive (attr := measurability)] protected theorem mul_const [Mul β] [ContinuousMul β] (hf : AEStronglyMeasurable f μ) (c : β) : AEStronglyMeasurable (fun x => f x * c) μ := hf.mul aestronglyMeasurable_const #align measure_theory.ae_strongly_measurable.mul_const MeasureTheory.AEStronglyMeasurable.mul_const #align measure_theory.ae_strongly_measurable.add_const MeasureTheory.AEStronglyMeasurable.add_const @[to_additive (attr := measurability)] protected theorem const_mul [Mul β] [ContinuousMul β] (hf : AEStronglyMeasurable f μ) (c : β) : AEStronglyMeasurable (fun x => c * f x) μ := aestronglyMeasurable_const.mul hf #align measure_theory.ae_strongly_measurable.const_mul MeasureTheory.AEStronglyMeasurable.const_mul #align measure_theory.ae_strongly_measurable.const_add MeasureTheory.AEStronglyMeasurable.const_add @[to_additive (attr := measurability)] protected theorem inv [Inv β] [ContinuousInv β] (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable f⁻¹ μ := ⟨(hf.mk f)⁻¹, hf.stronglyMeasurable_mk.inv, hf.ae_eq_mk.inv⟩ #align measure_theory.ae_strongly_measurable.inv MeasureTheory.AEStronglyMeasurable.inv #align measure_theory.ae_strongly_measurable.neg MeasureTheory.AEStronglyMeasurable.neg @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem div [Group β] [TopologicalGroup β] (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (f / g) μ := ⟨hf.mk f / hg.mk g, hf.stronglyMeasurable_mk.div hg.stronglyMeasurable_mk, hf.ae_eq_mk.div hg.ae_eq_mk⟩ #align measure_theory.ae_strongly_measurable.div MeasureTheory.AEStronglyMeasurable.div #align measure_theory.ae_strongly_measurable.sub MeasureTheory.AEStronglyMeasurable.sub @[to_additive] theorem mul_iff_right [CommGroup β] [TopologicalGroup β] (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (f * g) μ ↔ AEStronglyMeasurable g μ := ⟨fun h ↦ show g = f * g * f⁻¹ by simp only [mul_inv_cancel_comm] ▸ h.mul hf.inv, fun h ↦ hf.mul h⟩ @[to_additive] theorem mul_iff_left [CommGroup β] [TopologicalGroup β] (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (g * f) μ ↔ AEStronglyMeasurable g μ := mul_comm g f ▸ AEStronglyMeasurable.mul_iff_right hf @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem smul {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜} {g : α → β} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (fun x => f x • g x) μ := continuous_smul.comp_aestronglyMeasurable (hf.prod_mk hg) #align measure_theory.ae_strongly_measurable.smul MeasureTheory.AEStronglyMeasurable.smul #align measure_theory.ae_strongly_measurable.vadd MeasureTheory.AEStronglyMeasurable.vadd @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable])) const_nsmul] protected theorem pow [Monoid β] [ContinuousMul β] (hf : AEStronglyMeasurable f μ) (n : ℕ) : AEStronglyMeasurable (f ^ n) μ := ⟨hf.mk f ^ n, hf.stronglyMeasurable_mk.pow _, hf.ae_eq_mk.pow_const _⟩ @[to_additive (attr := measurability)] protected theorem const_smul {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : AEStronglyMeasurable f μ) (c : 𝕜) : AEStronglyMeasurable (c • f) μ := ⟨c • hf.mk f, hf.stronglyMeasurable_mk.const_smul c, hf.ae_eq_mk.const_smul c⟩ #align measure_theory.ae_strongly_measurable.const_smul MeasureTheory.AEStronglyMeasurable.const_smul @[to_additive (attr := measurability)] protected theorem const_smul' {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : AEStronglyMeasurable f μ) (c : 𝕜) : AEStronglyMeasurable (fun x => c • f x) μ := hf.const_smul c #align measure_theory.ae_strongly_measurable.const_smul' MeasureTheory.AEStronglyMeasurable.const_smul' @[to_additive (attr := measurability)] protected theorem smul_const {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜} (hf : AEStronglyMeasurable f μ) (c : β) : AEStronglyMeasurable (fun x => f x • c) μ := continuous_smul.comp_aestronglyMeasurable (hf.prod_mk aestronglyMeasurable_const) #align measure_theory.ae_strongly_measurable.smul_const MeasureTheory.AEStronglyMeasurable.smul_const #align measure_theory.ae_strongly_measurable.vadd_const MeasureTheory.AEStronglyMeasurable.vadd_const end Arithmetic section Order @[aesop safe 20 apply (rule_sets := [Measurable])] protected theorem sup [SemilatticeSup β] [ContinuousSup β] (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (f ⊔ g) μ := ⟨hf.mk f ⊔ hg.mk g, hf.stronglyMeasurable_mk.sup hg.stronglyMeasurable_mk, hf.ae_eq_mk.sup hg.ae_eq_mk⟩ #align measure_theory.ae_strongly_measurable.sup MeasureTheory.AEStronglyMeasurable.sup @[aesop safe 20 apply (rule_sets := [Measurable])] protected theorem inf [SemilatticeInf β] [ContinuousInf β] (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (f ⊓ g) μ := ⟨hf.mk f ⊓ hg.mk g, hf.stronglyMeasurable_mk.inf hg.stronglyMeasurable_mk, hf.ae_eq_mk.inf hg.ae_eq_mk⟩ #align measure_theory.ae_strongly_measurable.inf MeasureTheory.AEStronglyMeasurable.inf end Order /-! ### Big operators: `∏` and `∑` -/ section Monoid variable {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M] @[to_additive (attr := measurability)] theorem _root_.List.aestronglyMeasurable_prod' (l : List (α → M)) (hl : ∀ f ∈ l, AEStronglyMeasurable f μ) : AEStronglyMeasurable l.prod μ := by induction' l with f l ihl; · exact aestronglyMeasurable_one rw [List.forall_mem_cons] at hl rw [List.prod_cons] exact hl.1.mul (ihl hl.2) #align list.ae_strongly_measurable_prod' List.aestronglyMeasurable_prod' #align list.ae_strongly_measurable_sum' List.aestronglyMeasurable_sum' @[to_additive (attr := measurability)] theorem _root_.List.aestronglyMeasurable_prod (l : List (α → M)) (hl : ∀ f ∈ l, AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x => (l.map fun f : α → M => f x).prod) μ := by simpa only [← Pi.list_prod_apply] using l.aestronglyMeasurable_prod' hl #align list.ae_strongly_measurable_prod List.aestronglyMeasurable_prod #align list.ae_strongly_measurable_sum List.aestronglyMeasurable_sum end Monoid section CommMonoid variable {M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] @[to_additive (attr := measurability)] theorem _root_.Multiset.aestronglyMeasurable_prod' (l : Multiset (α → M)) (hl : ∀ f ∈ l, AEStronglyMeasurable f μ) : AEStronglyMeasurable l.prod μ := by rcases l with ⟨l⟩ simpa using l.aestronglyMeasurable_prod' (by simpa using hl) #align multiset.ae_strongly_measurable_prod' Multiset.aestronglyMeasurable_prod' #align multiset.ae_strongly_measurable_sum' Multiset.aestronglyMeasurable_sum' @[to_additive (attr := measurability)] theorem _root_.Multiset.aestronglyMeasurable_prod (s : Multiset (α → M)) (hs : ∀ f ∈ s, AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x => (s.map fun f : α → M => f x).prod) μ := by simpa only [← Pi.multiset_prod_apply] using s.aestronglyMeasurable_prod' hs #align multiset.ae_strongly_measurable_prod Multiset.aestronglyMeasurable_prod #align multiset.ae_strongly_measurable_sum Multiset.aestronglyMeasurable_sum @[to_additive (attr := measurability)] theorem _root_.Finset.aestronglyMeasurable_prod' {ι : Type*} {f : ι → α → M} (s : Finset ι) (hf : ∀ i ∈ s, AEStronglyMeasurable (f i) μ) : AEStronglyMeasurable (∏ i ∈ s, f i) μ := Multiset.aestronglyMeasurable_prod' _ fun _g hg => let ⟨_i, hi, hg⟩ := Multiset.mem_map.1 hg hg ▸ hf _ hi #align finset.ae_strongly_measurable_prod' Finset.aestronglyMeasurable_prod' #align finset.ae_strongly_measurable_sum' Finset.aestronglyMeasurable_sum' @[to_additive (attr := measurability)] theorem _root_.Finset.aestronglyMeasurable_prod {ι : Type*} {f : ι → α → M} (s : Finset ι) (hf : ∀ i ∈ s, AEStronglyMeasurable (f i) μ) : AEStronglyMeasurable (fun a => ∏ i ∈ s, f i a) μ := by simpa only [← Finset.prod_apply] using s.aestronglyMeasurable_prod' hf #align finset.ae_strongly_measurable_prod Finset.aestronglyMeasurable_prod #align finset.ae_strongly_measurable_sum Finset.aestronglyMeasurable_sum end CommMonoid section SecondCountableAEStronglyMeasurable variable [MeasurableSpace β] /-- In a space with second countable topology, measurable implies strongly measurable. -/ @[aesop 90% apply (rule_sets := [Measurable])] theorem _root_.AEMeasurable.aestronglyMeasurable [PseudoMetrizableSpace β] [OpensMeasurableSpace β] [SecondCountableTopology β] (hf : AEMeasurable f μ) : AEStronglyMeasurable f μ := ⟨hf.mk f, hf.measurable_mk.stronglyMeasurable, hf.ae_eq_mk⟩ #align ae_measurable.ae_strongly_measurable AEMeasurable.aestronglyMeasurable @[measurability] theorem _root_.aestronglyMeasurable_id {α : Type*} [TopologicalSpace α] [PseudoMetrizableSpace α] {_ : MeasurableSpace α} [OpensMeasurableSpace α] [SecondCountableTopology α] {μ : Measure α} : AEStronglyMeasurable (id : α → α) μ := aemeasurable_id.aestronglyMeasurable #align ae_strongly_measurable_id aestronglyMeasurable_id /-- In a space with second countable topology, strongly measurable and measurable are equivalent. -/ theorem _root_.aestronglyMeasurable_iff_aemeasurable [PseudoMetrizableSpace β] [BorelSpace β] [SecondCountableTopology β] : AEStronglyMeasurable f μ ↔ AEMeasurable f μ := ⟨fun h => h.aemeasurable, fun h => h.aestronglyMeasurable⟩ #align ae_strongly_measurable_iff_ae_measurable aestronglyMeasurable_iff_aemeasurable end SecondCountableAEStronglyMeasurable @[aesop safe 20 apply (rule_sets := [Measurable])] protected theorem dist {β : Type*} [PseudoMetricSpace β] {f g : α → β} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (fun x => dist (f x) (g x)) μ := continuous_dist.comp_aestronglyMeasurable (hf.prod_mk hg) #align measure_theory.ae_strongly_measurable.dist MeasureTheory.AEStronglyMeasurable.dist @[measurability] protected theorem norm {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x => ‖f x‖) μ := continuous_norm.comp_aestronglyMeasurable hf #align measure_theory.ae_strongly_measurable.norm MeasureTheory.AEStronglyMeasurable.norm @[measurability] protected theorem nnnorm {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x => ‖f x‖₊) μ := continuous_nnnorm.comp_aestronglyMeasurable hf #align measure_theory.ae_strongly_measurable.nnnorm MeasureTheory.AEStronglyMeasurable.nnnorm @[measurability] protected theorem ennnorm {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : AEStronglyMeasurable f μ) : AEMeasurable (fun a => (‖f a‖₊ : ℝ≥0∞)) μ := (ENNReal.continuous_coe.comp_aestronglyMeasurable hf.nnnorm).aemeasurable #align measure_theory.ae_strongly_measurable.ennnorm MeasureTheory.AEStronglyMeasurable.ennnorm @[aesop safe 20 apply (rule_sets := [Measurable])] protected theorem edist {β : Type*} [SeminormedAddCommGroup β] {f g : α → β} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : AEMeasurable (fun a => edist (f a) (g a)) μ := (continuous_edist.comp_aestronglyMeasurable (hf.prod_mk hg)).aemeasurable #align measure_theory.ae_strongly_measurable.edist MeasureTheory.AEStronglyMeasurable.edist @[measurability] protected theorem real_toNNReal {f : α → ℝ} (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable (fun x => (f x).toNNReal) μ := continuous_real_toNNReal.comp_aestronglyMeasurable hf #align measure_theory.ae_strongly_measurable.real_to_nnreal MeasureTheory.AEStronglyMeasurable.real_toNNReal theorem _root_.aestronglyMeasurable_indicator_iff [Zero β] {s : Set α} (hs : MeasurableSet s) : AEStronglyMeasurable (indicator s f) μ ↔ AEStronglyMeasurable f (μ.restrict s) := by constructor · intro h exact (h.mono_measure Measure.restrict_le_self).congr (indicator_ae_eq_restrict hs) · intro h refine ⟨indicator s (h.mk f), h.stronglyMeasurable_mk.indicator hs, ?_⟩ have A : s.indicator f =ᵐ[μ.restrict s] s.indicator (h.mk f) := (indicator_ae_eq_restrict hs).trans (h.ae_eq_mk.trans <| (indicator_ae_eq_restrict hs).symm) have B : s.indicator f =ᵐ[μ.restrict sᶜ] s.indicator (h.mk f) := (indicator_ae_eq_restrict_compl hs).trans (indicator_ae_eq_restrict_compl hs).symm exact ae_of_ae_restrict_of_ae_restrict_compl _ A B #align ae_strongly_measurable_indicator_iff aestronglyMeasurable_indicator_iff @[measurability] protected theorem indicator [Zero β] (hfm : AEStronglyMeasurable f μ) {s : Set α} (hs : MeasurableSet s) : AEStronglyMeasurable (s.indicator f) μ := (aestronglyMeasurable_indicator_iff hs).mpr hfm.restrict #align measure_theory.ae_strongly_measurable.indicator MeasureTheory.AEStronglyMeasurable.indicator theorem nullMeasurableSet_eq_fun {E} [TopologicalSpace E] [MetrizableSpace E] {f g : α → E} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : NullMeasurableSet { x | f x = g x } μ := by apply (hf.stronglyMeasurable_mk.measurableSet_eq_fun hg.stronglyMeasurable_mk).nullMeasurableSet.congr filter_upwards [hf.ae_eq_mk, hg.ae_eq_mk] with x hfx hgx change (hf.mk f x = hg.mk g x) = (f x = g x) simp only [hfx, hgx] #align measure_theory.ae_strongly_measurable.null_measurable_set_eq_fun MeasureTheory.AEStronglyMeasurable.nullMeasurableSet_eq_fun @[to_additive] lemma nullMeasurableSet_mulSupport {E} [TopologicalSpace E] [MetrizableSpace E] [One E] {f : α → E} (hf : AEStronglyMeasurable f μ) : NullMeasurableSet (mulSupport f) μ := (hf.nullMeasurableSet_eq_fun stronglyMeasurable_const.aestronglyMeasurable).compl theorem nullMeasurableSet_lt [LinearOrder β] [OrderClosedTopology β] [PseudoMetrizableSpace β] {f g : α → β} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : NullMeasurableSet { a | f a < g a } μ := by apply (hf.stronglyMeasurable_mk.measurableSet_lt hg.stronglyMeasurable_mk).nullMeasurableSet.congr filter_upwards [hf.ae_eq_mk, hg.ae_eq_mk] with x hfx hgx change (hf.mk f x < hg.mk g x) = (f x < g x) simp only [hfx, hgx] #align measure_theory.ae_strongly_measurable.null_measurable_set_lt MeasureTheory.AEStronglyMeasurable.nullMeasurableSet_lt
Mathlib/MeasureTheory/Function/StronglyMeasurable/Basic.lean
1,610
1,617
theorem nullMeasurableSet_le [Preorder β] [OrderClosedTopology β] [PseudoMetrizableSpace β] {f g : α → β} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) : NullMeasurableSet { a | f a ≤ g a } μ := by
apply (hf.stronglyMeasurable_mk.measurableSet_le hg.stronglyMeasurable_mk).nullMeasurableSet.congr filter_upwards [hf.ae_eq_mk, hg.ae_eq_mk] with x hfx hgx change (hf.mk f x ≤ hg.mk g x) = (f x ≤ g x) simp only [hfx, hgx]
/- 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.Derivative import Mathlib.Algebra.Polynomial.Roots import Mathlib.RingTheory.EuclideanDomain #align_import data.polynomial.field_division from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821" /-! # Theory of univariate polynomials This file starts looking like the ring theory of $R[X]$ -/ noncomputable section open Polynomial namespace Polynomial universe u v w y z variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ} section CommRing variable [CommRing R] theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero (p : R[X]) (t : R) (hnezero : derivative p ≠ 0) : p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := (le_rootMultiplicity_iff hnezero).2 <| pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t) theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors {p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t) (hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) : (derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by by_cases h : p = 0 · simp only [h, map_zero, rootMultiplicity_zero] obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t set m := p.rootMultiplicity t have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt have hndvd : ¬(X - C t) ^ m ∣ derivative p := by rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _), derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc, dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)] rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢ rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd] have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _) exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm]) (rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero) theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ} (hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t := dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans (pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t) open Finset in theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} : (derivative^[p.rootMultiplicity t] p).eval t = (p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by set m := p.rootMultiplicity t with hm conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm] rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)] · rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self, eval_natCast, nsmul_eq_mul]; rfl · intro b hb hb0 rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow, Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self, zero_pow hb0, smul_zero, zero_mul, smul_zero] theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by by_contra! h' replace hroot := hroot _ h' simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot obtain ⟨q, hq⟩ := Nat.cast_dvd_cast (α := R) <| Nat.factorial_dvd_factorial h' rw [hq, mul_mem_nonZeroDivisors] at hnzd rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t := by apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot clear hroot induction' n with n ih · simp only [Nat.zero_eq, Nat.factorial_zero, Nat.cast_one] exact Submonoid.one_mem _ · rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors] exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : (n.factorial : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩ theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors' {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩ theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t := lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h (by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _) theorem one_lt_rootMultiplicity_iff_isRoot {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h] refine ⟨fun h ↦ ⟨h 0 (by norm_num), h 1 (by norm_num)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩ obtain (_|_|m) := m exacts [h0, h1, by omega] end CommRing section IsDomain variable [CommRing R] [IsDomain R] theorem one_lt_rootMultiplicity_iff_isRoot_gcd [GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) : 1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff] theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) : p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by by_cases h : p = 0 · rw [h, map_zero, rootMultiplicity_zero] exact derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors hpt <| mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 ((rootMultiplicity_pos h).2 hpt).ne' #align polynomial.derivative_root_multiplicity_of_root Polynomial.derivative_rootMultiplicity_of_root theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity [CharZero R] (p : R[X]) (t : R) : p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := by by_cases h : p.IsRoot t · exact (derivative_rootMultiplicity_of_root h).symm.le · rw [rootMultiplicity_eq_zero h, zero_tsub] exact zero_le _ #align polynomial.root_multiplicity_sub_one_le_derivative_root_multiplicity Polynomial.rootMultiplicity_sub_one_le_derivative_rootMultiplicity theorem lt_rootMultiplicity_of_isRoot_iterate_derivative [CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) (hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) : n < p.rootMultiplicity t := lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot <| mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 <| Nat.factorial_ne_zero n theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative [CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) : n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t := ⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn, fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative h hr⟩ section NormalizationMonoid variable [NormalizationMonoid R] instance instNormalizationMonoid : NormalizationMonoid R[X] where normUnit p := ⟨C ↑(normUnit p.leadingCoeff), C ↑(normUnit p.leadingCoeff)⁻¹, by rw [← RingHom.map_mul, Units.mul_inv, C_1], by rw [← RingHom.map_mul, Units.inv_mul, C_1]⟩ normUnit_zero := Units.ext (by simp) normUnit_mul hp0 hq0 := Units.ext (by dsimp rw [Ne, ← leadingCoeff_eq_zero] at * rw [leadingCoeff_mul, normUnit_mul hp0 hq0, Units.val_mul, C_mul]) normUnit_coe_units u := Units.ext (by dsimp rw [← mul_one u⁻¹, Units.val_mul, Units.eq_inv_mul_iff_mul_eq] rcases Polynomial.isUnit_iff.1 ⟨u, rfl⟩ with ⟨_, ⟨w, rfl⟩, h2⟩ rw [← h2, leadingCoeff_C, normUnit_coe_units, ← C_mul, Units.mul_inv, C_1] rfl) @[simp] theorem coe_normUnit {p : R[X]} : (normUnit p : R[X]) = C ↑(normUnit p.leadingCoeff) := by simp [normUnit] #align polynomial.coe_norm_unit Polynomial.coe_normUnit theorem leadingCoeff_normalize (p : R[X]) : leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp #align polynomial.leading_coeff_normalize Polynomial.leadingCoeff_normalize theorem Monic.normalize_eq_self {p : R[X]} (hp : p.Monic) : normalize p = p := by simp only [Polynomial.coe_normUnit, normalize_apply, hp.leadingCoeff, normUnit_one, Units.val_one, Polynomial.C.map_one, mul_one] #align polynomial.monic.normalize_eq_self Polynomial.Monic.normalize_eq_self theorem roots_normalize {p : R[X]} : (normalize p).roots = p.roots := by rw [normalize_apply, mul_comm, coe_normUnit, roots_C_mul _ (normUnit (leadingCoeff p)).ne_zero] #align polynomial.roots_normalize Polynomial.roots_normalize
Mathlib/Algebra/Polynomial/FieldDivision.lean
214
216
theorem normUnit_X : normUnit (X : Polynomial R) = 1 := by
have := coe_normUnit (R := R) (p := X) rwa [leadingCoeff_X, normUnit_one, Units.val_one, map_one, Units.val_eq_one] at this
/- 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
Mathlib/Algebra/Polynomial/Eval.lean
959
970
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]
/- Copyright (c) 2019 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Data.Bracket import Mathlib.LinearAlgebra.Basic #align_import algebra.lie.basic from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # Lie algebras This file defines Lie rings and Lie algebras over a commutative ring together with their modules, morphisms and equivalences, as well as various lemmas to make these definitions usable. ## Main definitions * `LieRing` * `LieAlgebra` * `LieRingModule` * `LieModule` * `LieHom` * `LieEquiv` * `LieModuleHom` * `LieModuleEquiv` ## Notation Working over a fixed commutative ring `R`, we introduce the notations: * `L →ₗ⁅R⁆ L'` for a morphism of Lie algebras, * `L ≃ₗ⁅R⁆ L'` for an equivalence of Lie algebras, * `M →ₗ⁅R,L⁆ N` for a morphism of Lie algebra modules `M`, `N` over a Lie algebra `L`, * `M ≃ₗ⁅R,L⁆ N` for an equivalence of Lie algebra modules `M`, `N` over a Lie algebra `L`. ## Implementation notes Lie algebras are defined as modules with a compatible Lie ring structure and thus, like modules, are partially unbundled. ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975) ## Tags lie bracket, jacobi identity, lie ring, lie algebra, lie module -/ universe u v w w₁ w₂ open Function /-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the Jacobi identity. -/ class LieRing (L : Type v) extends AddCommGroup L, Bracket L L where /-- A Lie ring bracket is additive in its first component. -/ protected add_lie : ∀ x y z : L, ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆ /-- A Lie ring bracket is additive in its second component. -/ protected lie_add : ∀ x y z : L, ⁅x, y + z⁆ = ⁅x, y⁆ + ⁅x, z⁆ /-- A Lie ring bracket vanishes on the diagonal in L × L. -/ protected lie_self : ∀ x : L, ⁅x, x⁆ = 0 /-- A Lie ring bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : ∀ x y z : L, ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆ #align lie_ring LieRing /-- A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring. -/ class LieAlgebra (R : Type u) (L : Type v) [CommRing R] [LieRing L] extends Module R L where /-- A Lie algebra bracket is compatible with scalar multiplication in its second argument. The compatibility in the first argument is not a class property, but follows since every Lie algebra has a natural Lie module action on itself, see `LieModule`. -/ protected lie_smul : ∀ (t : R) (x y : L), ⁅x, t • y⁆ = t • ⁅x, y⁆ #align lie_algebra LieAlgebra /-- A Lie ring module is an additive group, together with an additive action of a Lie ring on this group, such that the Lie bracket acts as the commutator of endomorphisms. (For representations of Lie *algebras* see `LieModule`.) -/ class LieRingModule (L : Type v) (M : Type w) [LieRing L] [AddCommGroup M] extends Bracket L M where /-- A Lie ring module bracket is additive in its first component. -/ protected add_lie : ∀ (x y : L) (m : M), ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ /-- A Lie ring module bracket is additive in its second component. -/ protected lie_add : ∀ (x : L) (m n : M), ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ /-- A Lie ring module bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : ∀ (x y : L) (m : M), ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ #align lie_ring_module LieRingModule /-- A Lie module is a module over a commutative ring, together with a linear action of a Lie algebra on this module, such that the Lie bracket acts as the commutator of endomorphisms. -/ class LieModule (R : Type u) (L : Type v) (M : Type w) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] : Prop where /-- A Lie module bracket is compatible with scalar multiplication in its first argument. -/ protected smul_lie : ∀ (t : R) (x : L) (m : M), ⁅t • x, m⁆ = t • ⁅x, m⁆ /-- A Lie module bracket is compatible with scalar multiplication in its second argument. -/ protected lie_smul : ∀ (t : R) (x : L) (m : M), ⁅x, t • m⁆ = t • ⁅x, m⁆ #align lie_module LieModule section BasicProperties variable {R : Type u} {L : Type v} {M : Type w} {N : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N] variable (t : R) (x y z : L) (m n : M) @[simp] theorem add_lie : ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ := LieRingModule.add_lie x y m #align add_lie add_lie @[simp] theorem lie_add : ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ := LieRingModule.lie_add x m n #align lie_add lie_add @[simp] theorem smul_lie : ⁅t • x, m⁆ = t • ⁅x, m⁆ := LieModule.smul_lie t x m #align smul_lie smul_lie @[simp] theorem lie_smul : ⁅x, t • m⁆ = t • ⁅x, m⁆ := LieModule.lie_smul t x m #align lie_smul lie_smul theorem leibniz_lie : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ := LieRingModule.leibniz_lie x y m #align leibniz_lie leibniz_lie @[simp] theorem lie_zero : ⁅x, 0⁆ = (0 : M) := (AddMonoidHom.mk' _ (lie_add x)).map_zero #align lie_zero lie_zero @[simp] theorem zero_lie : ⁅(0 : L), m⁆ = 0 := (AddMonoidHom.mk' (fun x : L => ⁅x, m⁆) fun x y => add_lie x y m).map_zero #align zero_lie zero_lie @[simp] theorem lie_self : ⁅x, x⁆ = 0 := LieRing.lie_self x #align lie_self lie_self instance lieRingSelfModule : LieRingModule L L := { (inferInstance : LieRing L) with } #align lie_ring_self_module lieRingSelfModule @[simp] theorem lie_skew : -⁅y, x⁆ = ⁅x, y⁆ := by have h : ⁅x + y, x⁆ + ⁅x + y, y⁆ = 0 := by rw [← lie_add]; apply lie_self simpa [neg_eq_iff_add_eq_zero] using h #align lie_skew lie_skew /-- Every Lie algebra is a module over itself. -/ instance lieAlgebraSelfModule : LieModule R L L where smul_lie t x m := by rw [← lie_skew, ← lie_skew x m, LieAlgebra.lie_smul, smul_neg] lie_smul := by apply LieAlgebra.lie_smul #align lie_algebra_self_module lieAlgebraSelfModule @[simp] theorem neg_lie : ⁅-x, m⁆ = -⁅x, m⁆ := by rw [← sub_eq_zero, sub_neg_eq_add, ← add_lie] simp #align neg_lie neg_lie @[simp] theorem lie_neg : ⁅x, -m⁆ = -⁅x, m⁆ := by rw [← sub_eq_zero, sub_neg_eq_add, ← lie_add] simp #align lie_neg lie_neg @[simp] theorem sub_lie : ⁅x - y, m⁆ = ⁅x, m⁆ - ⁅y, m⁆ := by simp [sub_eq_add_neg] #align sub_lie sub_lie @[simp] theorem lie_sub : ⁅x, m - n⁆ = ⁅x, m⁆ - ⁅x, n⁆ := by simp [sub_eq_add_neg] #align lie_sub lie_sub @[simp] theorem nsmul_lie (n : ℕ) : ⁅n • x, m⁆ = n • ⁅x, m⁆ := AddMonoidHom.map_nsmul { toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ } _ _ #align nsmul_lie nsmul_lie @[simp] theorem lie_nsmul (n : ℕ) : ⁅x, n • m⁆ = n • ⁅x, m⁆ := AddMonoidHom.map_nsmul { toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _} _ _ #align lie_nsmul lie_nsmul @[simp] theorem zsmul_lie (a : ℤ) : ⁅a • x, m⁆ = a • ⁅x, m⁆ := AddMonoidHom.map_zsmul { toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ } _ _ #align zsmul_lie zsmul_lie @[simp] theorem lie_zsmul (a : ℤ) : ⁅x, a • m⁆ = a • ⁅x, m⁆ := AddMonoidHom.map_zsmul { toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _ } _ _ #align lie_zsmul lie_zsmul @[simp] lemma lie_lie : ⁅⁅x, y⁆, m⁆ = ⁅x, ⁅y, m⁆⁆ - ⁅y, ⁅x, m⁆⁆ := by rw [leibniz_lie, add_sub_cancel_right] #align lie_lie lie_lie theorem lie_jacobi : ⁅x, ⁅y, z⁆⁆ + ⁅y, ⁅z, x⁆⁆ + ⁅z, ⁅x, y⁆⁆ = 0 := by rw [← neg_neg ⁅x, y⁆, lie_neg z, lie_skew y x, ← lie_skew, lie_lie] abel #align lie_jacobi lie_jacobi instance LieRing.instLieAlgebra : LieAlgebra ℤ L where lie_smul n x y := lie_zsmul x y n #align lie_ring.int_lie_algebra LieRing.instLieAlgebra instance LinearMap.instLieRingModule : LieRingModule L (M →ₗ[R] N) where bracket x f := { toFun := fun m => ⁅x, f m⁆ - f ⁅x, m⁆ map_add' := fun m n => by simp only [lie_add, LinearMap.map_add] abel map_smul' := fun t m => by simp only [smul_sub, LinearMap.map_smul, lie_smul, RingHom.id_apply] } add_lie x y f := by ext n simp only [add_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.add_apply, LinearMap.map_add] abel lie_add x f g := by ext n simp only [LinearMap.coe_mk, AddHom.coe_mk, lie_add, LinearMap.add_apply] abel leibniz_lie x y f := by ext n simp only [lie_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.map_sub, LinearMap.add_apply, lie_sub] abel @[simp] theorem LieHom.lie_apply (f : M →ₗ[R] N) (x : L) (m : M) : ⁅x, f⁆ m = ⁅x, f m⁆ - f ⁅x, m⁆ := rfl #align lie_hom.lie_apply LieHom.lie_apply instance LinearMap.instLieModule : LieModule R L (M →ₗ[R] N) where smul_lie t x f := by ext n simp only [smul_sub, smul_lie, LinearMap.smul_apply, LieHom.lie_apply, LinearMap.map_smul] lie_smul t x f := by ext n simp only [smul_sub, LinearMap.smul_apply, LieHom.lie_apply, lie_smul] /-- We could avoid defining this by instead defining a `LieRingModule L R` instance with a zero bracket and relying on `LinearMap.instLieRingModule`. We do not do this because in the case that `L = R` we would have a non-defeq diamond via `Ring.instBracket`. -/ instance Module.Dual.instLieRingModule : LieRingModule L (M →ₗ[R] R) where bracket := fun x f ↦ { toFun := fun m ↦ - f ⁅x, m⁆ map_add' := by simp [-neg_add_rev, neg_add] map_smul' := by simp } add_lie := fun x y m ↦ by ext n; simp [-neg_add_rev, neg_add] lie_add := fun x m n ↦ by ext p; simp [-neg_add_rev, neg_add] leibniz_lie := fun x m n ↦ by ext p; simp @[simp] lemma Module.Dual.lie_apply (f : M →ₗ[R] R) : ⁅x, f⁆ m = - f ⁅x, m⁆ := rfl instance Module.Dual.instLieModule : LieModule R L (M →ₗ[R] R) where smul_lie := fun t x m ↦ by ext n; simp lie_smul := fun t x m ↦ by ext n; simp end BasicProperties /-- A morphism of Lie algebras is a linear map respecting the bracket operations. -/ structure LieHom (R L L': Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] extends L →ₗ[R] L' where /-- A morphism of Lie algebras is compatible with brackets. -/ map_lie' : ∀ {x y : L}, toFun ⁅x, y⁆ = ⁅toFun x, toFun y⁆ #align lie_hom LieHom @[inherit_doc] notation:25 L " →ₗ⁅" R:25 "⁆ " L':0 => LieHom R L L' namespace LieHom variable {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁} variable [CommRing R] variable [LieRing L₁] [LieAlgebra R L₁] variable [LieRing L₂] [LieAlgebra R L₂] variable [LieRing L₃] [LieAlgebra R L₃] attribute [coe] LieHom.toLinearMap instance : Coe (L₁ →ₗ⁅R⁆ L₂) (L₁ →ₗ[R] L₂) := ⟨LieHom.toLinearMap⟩ instance : FunLike (L₁ →ₗ⁅R⁆ L₂) L₁ L₂ := { coe := fun f => f.toFun, coe_injective' := fun x y h => by cases x; cases y; simp at h; simp [h] } initialize_simps_projections LieHom (toFun → apply) @[simp, norm_cast] theorem coe_toLinearMap (f : L₁ →ₗ⁅R⁆ L₂) : ⇑(f : L₁ →ₗ[R] L₂) = f := rfl #align lie_hom.coe_to_linear_map LieHom.coe_toLinearMap @[simp] theorem toFun_eq_coe (f : L₁ →ₗ⁅R⁆ L₂) : f.toFun = ⇑f := rfl #align lie_hom.to_fun_eq_coe LieHom.toFun_eq_coe @[simp] theorem map_smul (f : L₁ →ₗ⁅R⁆ L₂) (c : R) (x : L₁) : f (c • x) = c • f x := LinearMap.map_smul (f : L₁ →ₗ[R] L₂) c x #align lie_hom.map_smul LieHom.map_smul @[simp] theorem map_add (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x + y) = f x + f y := LinearMap.map_add (f : L₁ →ₗ[R] L₂) x y #align lie_hom.map_add LieHom.map_add @[simp] theorem map_sub (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x - y) = f x - f y := LinearMap.map_sub (f : L₁ →ₗ[R] L₂) x y #align lie_hom.map_sub LieHom.map_sub @[simp] theorem map_neg (f : L₁ →ₗ⁅R⁆ L₂) (x : L₁) : f (-x) = -f x := LinearMap.map_neg (f : L₁ →ₗ[R] L₂) x #align lie_hom.map_neg LieHom.map_neg @[simp] theorem map_lie (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f ⁅x, y⁆ = ⁅f x, f y⁆ := LieHom.map_lie' f #align lie_hom.map_lie LieHom.map_lie @[simp] theorem map_zero (f : L₁ →ₗ⁅R⁆ L₂) : f 0 = 0 := (f : L₁ →ₗ[R] L₂).map_zero #align lie_hom.map_zero LieHom.map_zero /-- The identity map is a morphism of Lie algebras. -/ def id : L₁ →ₗ⁅R⁆ L₁ := { (LinearMap.id : L₁ →ₗ[R] L₁) with map_lie' := rfl } #align lie_hom.id LieHom.id @[simp] theorem coe_id : ⇑(id : L₁ →ₗ⁅R⁆ L₁) = _root_.id := rfl #align lie_hom.coe_id LieHom.coe_id theorem id_apply (x : L₁) : (id : L₁ →ₗ⁅R⁆ L₁) x = x := rfl #align lie_hom.id_apply LieHom.id_apply /-- The constant 0 map is a Lie algebra morphism. -/ instance : Zero (L₁ →ₗ⁅R⁆ L₂) := ⟨{ (0 : L₁ →ₗ[R] L₂) with map_lie' := by simp }⟩ @[norm_cast, simp] theorem coe_zero : ((0 : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = 0 := rfl #align lie_hom.coe_zero LieHom.coe_zero theorem zero_apply (x : L₁) : (0 : L₁ →ₗ⁅R⁆ L₂) x = 0 := rfl #align lie_hom.zero_apply LieHom.zero_apply /-- The identity map is a Lie algebra morphism. -/ instance : One (L₁ →ₗ⁅R⁆ L₁) := ⟨id⟩ @[simp] theorem coe_one : ((1 : L₁ →ₗ⁅R⁆ L₁) : L₁ → L₁) = _root_.id := rfl #align lie_hom.coe_one LieHom.coe_one theorem one_apply (x : L₁) : (1 : L₁ →ₗ⁅R⁆ L₁) x = x := rfl #align lie_hom.one_apply LieHom.one_apply instance : Inhabited (L₁ →ₗ⁅R⁆ L₂) := ⟨0⟩ theorem coe_injective : @Function.Injective (L₁ →ₗ⁅R⁆ L₂) (L₁ → L₂) (↑) := by rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h congr #align lie_hom.coe_injective LieHom.coe_injective @[ext] theorem ext {f g : L₁ →ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g := coe_injective <| funext h #align lie_hom.ext LieHom.ext theorem ext_iff {f g : L₁ →ₗ⁅R⁆ L₂} : f = g ↔ ∀ x, f x = g x := ⟨by rintro rfl x rfl, ext⟩ #align lie_hom.ext_iff LieHom.ext_iff theorem congr_fun {f g : L₁ →ₗ⁅R⁆ L₂} (h : f = g) (x : L₁) : f x = g x := h ▸ rfl #align lie_hom.congr_fun LieHom.congr_fun @[simp] theorem mk_coe (f : L₁ →ₗ⁅R⁆ L₂) (h₁ h₂ h₃) : (⟨⟨⟨f, h₁⟩, h₂⟩, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) = f := by ext rfl #align lie_hom.mk_coe LieHom.mk_coe @[simp] theorem coe_mk (f : L₁ → L₂) (h₁ h₂ h₃) : ((⟨⟨⟨f, h₁⟩, h₂⟩, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = f := rfl #align lie_hom.coe_mk LieHom.coe_mk /-- The composition of morphisms is a morphism. -/ def comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : L₁ →ₗ⁅R⁆ L₃ := { LinearMap.comp f.toLinearMap g.toLinearMap with map_lie' := by intros x y change f (g ⁅x, y⁆) = ⁅f (g x), f (g y)⁆ rw [map_lie, map_lie] } #align lie_hom.comp LieHom.comp theorem comp_apply (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) (x : L₁) : f.comp g x = f (g x) := rfl #align lie_hom.comp_apply LieHom.comp_apply @[norm_cast, simp] theorem coe_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : (f.comp g : L₁ → L₃) = f ∘ g := rfl #align lie_hom.coe_comp LieHom.coe_comp @[norm_cast, simp] theorem coe_linearMap_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : (f.comp g : L₁ →ₗ[R] L₃) = (f : L₂ →ₗ[R] L₃).comp (g : L₁ →ₗ[R] L₂) := rfl #align lie_hom.coe_linear_map_comp LieHom.coe_linearMap_comp @[simp] theorem comp_id (f : L₁ →ₗ⁅R⁆ L₂) : f.comp (id : L₁ →ₗ⁅R⁆ L₁) = f := by ext rfl #align lie_hom.comp_id LieHom.comp_id @[simp] theorem id_comp (f : L₁ →ₗ⁅R⁆ L₂) : (id : L₂ →ₗ⁅R⁆ L₂).comp f = f := by ext rfl #align lie_hom.id_comp LieHom.id_comp /-- The inverse of a bijective morphism is a morphism. -/ def inverse (f : L₁ →ₗ⁅R⁆ L₂) (g : L₂ → L₁) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : L₂ →ₗ⁅R⁆ L₁ := { LinearMap.inverse f.toLinearMap g h₁ h₂ with map_lie' := by intros x y calc g ⁅x, y⁆ = g ⁅f (g x), f (g y)⁆ := by conv_lhs => rw [← h₂ x, ← h₂ y] _ = g (f ⁅g x, g y⁆) := by rw [map_lie] _ = ⁅g x, g y⁆ := h₁ _ } #align lie_hom.inverse LieHom.inverse end LieHom section ModulePullBack variable {R : Type u} {L₁ : Type v} {L₂ : Type w} (M : Type w₁) variable [CommRing R] [LieRing L₁] [LieAlgebra R L₁] [LieRing L₂] [LieAlgebra R L₂] variable [AddCommGroup M] [LieRingModule L₂ M] variable (f : L₁ →ₗ⁅R⁆ L₂) /-- A Lie ring module may be pulled back along a morphism of Lie algebras. See note [reducible non-instances]. -/ def LieRingModule.compLieHom : LieRingModule L₁ M where bracket x m := ⁅f x, m⁆ lie_add x := lie_add (f x) add_lie x y m := by simp only [LieHom.map_add, add_lie] leibniz_lie x y m := by simp only [lie_lie, sub_add_cancel, LieHom.map_lie] #align lie_ring_module.comp_lie_hom LieRingModule.compLieHom theorem LieRingModule.compLieHom_apply (x : L₁) (m : M) : haveI := LieRingModule.compLieHom M f ⁅x, m⁆ = ⁅f x, m⁆ := rfl #align lie_ring_module.comp_lie_hom_apply LieRingModule.compLieHom_apply /-- A Lie module may be pulled back along a morphism of Lie algebras. -/ theorem LieModule.compLieHom [Module R M] [LieModule R L₂ M] : @LieModule R L₁ M _ _ _ _ _ (LieRingModule.compLieHom M f) := { __ := LieRingModule.compLieHom M f smul_lie := fun t x m => by simp only [LieRingModule.compLieHom_apply, smul_lie, LieHom.map_smul] lie_smul := fun t x m => by simp only [LieRingModule.compLieHom_apply, lie_smul] } #align lie_module.comp_lie_hom LieModule.compLieHom end ModulePullBack /-- An equivalence of Lie algebras is a morphism which is also a linear equivalence. We could instead define an equivalence to be a morphism which is also a (plain) equivalence. However it is more convenient to define via linear equivalence to get `.toLinearEquiv` for free. -/ structure LieEquiv (R : Type u) (L : Type v) (L' : Type w) [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] extends L →ₗ⁅R⁆ L' where /-- The inverse function of an equivalence of Lie algebras -/ invFun : L' → L /-- The inverse function of an equivalence of Lie algebras is a left inverse of the underlying function. -/ left_inv : Function.LeftInverse invFun toLieHom.toFun /-- The inverse function of an equivalence of Lie algebras is a right inverse of the underlying function. -/ right_inv : Function.RightInverse invFun toLieHom.toFun #align lie_equiv LieEquiv @[inherit_doc] notation:50 L " ≃ₗ⁅" R "⁆ " L' => LieEquiv R L L' namespace LieEquiv variable {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁} variable [CommRing R] [LieRing L₁] [LieRing L₂] [LieRing L₃] variable [LieAlgebra R L₁] [LieAlgebra R L₂] [LieAlgebra R L₃] /-- Consider an equivalence of Lie algebras as a linear equivalence. -/ def toLinearEquiv (f : L₁ ≃ₗ⁅R⁆ L₂) : L₁ ≃ₗ[R] L₂ := { f.toLieHom, f with } #align lie_equiv.to_linear_equiv LieEquiv.toLinearEquiv instance hasCoeToLieHom : Coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ →ₗ⁅R⁆ L₂) := ⟨toLieHom⟩ #align lie_equiv.has_coe_to_lie_hom LieEquiv.hasCoeToLieHom instance hasCoeToLinearEquiv : Coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ ≃ₗ[R] L₂) := ⟨toLinearEquiv⟩ #align lie_equiv.has_coe_to_linear_equiv LieEquiv.hasCoeToLinearEquiv instance : EquivLike (L₁ ≃ₗ⁅R⁆ L₂) L₁ L₂ := { coe := fun f => f.toFun, inv := fun f => f.invFun, left_inv := fun f => f.left_inv, right_inv := fun f => f.right_inv, coe_injective' := fun f g h₁ h₂ => by cases f; cases g; simp at h₁ h₂; simp [*] } theorem coe_to_lieHom (e : L₁ ≃ₗ⁅R⁆ L₂) : ⇑(e : L₁ →ₗ⁅R⁆ L₂) = e := rfl #align lie_equiv.coe_to_lie_hom LieEquiv.coe_to_lieHom @[simp] theorem coe_to_linearEquiv (e : L₁ ≃ₗ⁅R⁆ L₂) : ⇑(e : L₁ ≃ₗ[R] L₂) = e := rfl #align lie_equiv.coe_to_linear_equiv LieEquiv.coe_to_linearEquiv @[simp] theorem to_linearEquiv_mk (f : L₁ →ₗ⁅R⁆ L₂) (g h₁ h₂) : (mk f g h₁ h₂ : L₁ ≃ₗ[R] L₂) = { f with invFun := g left_inv := h₁ right_inv := h₂ } := rfl #align lie_equiv.to_linear_equiv_mk LieEquiv.to_linearEquiv_mk theorem coe_linearEquiv_injective : Injective ((↑) : (L₁ ≃ₗ⁅R⁆ L₂) → L₁ ≃ₗ[R] L₂) := by rintro ⟨⟨⟨⟨f, -⟩, -⟩, -⟩, f_inv⟩ ⟨⟨⟨⟨g, -⟩, -⟩, -⟩, g_inv⟩ intro h simp only [to_linearEquiv_mk, LinearEquiv.mk.injEq, LinearMap.mk.injEq, AddHom.mk.injEq] at h congr exacts [h.1, h.2] #align lie_equiv.coe_linear_equiv_injective LieEquiv.coe_linearEquiv_injective theorem coe_injective : @Injective (L₁ ≃ₗ⁅R⁆ L₂) (L₁ → L₂) (↑) := LinearEquiv.coe_injective.comp coe_linearEquiv_injective #align lie_equiv.coe_injective LieEquiv.coe_injective @[ext] theorem ext {f g : L₁ ≃ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g := coe_injective <| funext h #align lie_equiv.ext LieEquiv.ext instance : One (L₁ ≃ₗ⁅R⁆ L₁) := ⟨{ (1 : L₁ ≃ₗ[R] L₁) with map_lie' := rfl }⟩ @[simp] theorem one_apply (x : L₁) : (1 : L₁ ≃ₗ⁅R⁆ L₁) x = x := rfl #align lie_equiv.one_apply LieEquiv.one_apply instance : Inhabited (L₁ ≃ₗ⁅R⁆ L₁) := ⟨1⟩ lemma map_lie (e : L₁ ≃ₗ⁅R⁆ L₂) (x y : L₁) : e ⁅x, y⁆ = ⁅e x, e y⁆ := LieHom.map_lie e.toLieHom x y /-- Lie algebra equivalences are reflexive. -/ def refl : L₁ ≃ₗ⁅R⁆ L₁ := 1 #align lie_equiv.refl LieEquiv.refl @[simp] theorem refl_apply (x : L₁) : (refl : L₁ ≃ₗ⁅R⁆ L₁) x = x := rfl #align lie_equiv.refl_apply LieEquiv.refl_apply /-- Lie algebra equivalences are symmetric. -/ @[symm] def symm (e : L₁ ≃ₗ⁅R⁆ L₂) : L₂ ≃ₗ⁅R⁆ L₁ := { LieHom.inverse e.toLieHom e.invFun e.left_inv e.right_inv, e.toLinearEquiv.symm with } #align lie_equiv.symm LieEquiv.symm @[simp]
Mathlib/Algebra/Lie/Basic.lean
619
621
theorem symm_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.symm = e := by
ext rfl
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Justus Springer -/ import Mathlib.Topology.Category.TopCat.OpenNhds import Mathlib.Topology.Sheaves.Presheaf import Mathlib.Topology.Sheaves.SheafCondition.UniqueGluing import Mathlib.CategoryTheory.Adjunction.Evaluation import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.Limits.Preserves.Filtered import Mathlib.CategoryTheory.Limits.Final import Mathlib.Tactic.CategoryTheory.Elementwise import Mathlib.Algebra.Category.Ring.Colimits import Mathlib.CategoryTheory.Sites.Pullback #align_import topology.sheaves.stalks from "leanprover-community/mathlib"@"5dc6092d09e5e489106865241986f7f2ad28d4c8" /-! # Stalks For a presheaf `F` on a topological space `X`, valued in some category `C`, the *stalk* of `F` at the point `x : X` is defined as the colimit of the composition of the inclusion of categories `(OpenNhds x)ᵒᵖ ⥤ (Opens X)ᵒᵖ` and the functor `F : (Opens X)ᵒᵖ ⥤ C`. For an open neighborhood `U` of `x`, we define the map `F.germ x : F.obj (op U) ⟶ F.stalk x` as the canonical morphism into this colimit. Taking stalks is functorial: For every point `x : X` we define a functor `stalkFunctor C x`, sending presheaves on `X` to objects of `C`. Furthermore, for a map `f : X ⟶ Y` between topological spaces, we define `stalkPushforward` as the induced map on the stalks `(f _* ℱ).stalk (f x) ⟶ ℱ.stalk x`. Some lemmas about stalks and germs only hold for certain classes of concrete categories. A basic property of forgetful functors of categories of algebraic structures (like `MonCat`, `CommRingCat`,...) is that they preserve filtered colimits. Since stalks are filtered colimits, this ensures that the stalks of presheaves valued in these categories behave exactly as for `Type`-valued presheaves. For example, in `germ_exist` we prove that in such a category, every element of the stalk is the germ of a section. Furthermore, if we require the forgetful functor to reflect isomorphisms and preserve limits (as is the case for most algebraic structures), we have access to the unique gluing API and can prove further properties. Most notably, in `is_iso_iff_stalk_functor_map_iso`, we prove that in such a category, a morphism of sheaves is an isomorphism if and only if all of its stalk maps are isomorphisms. See also the definition of "algebraic structures" in the stacks project: https://stacks.math.columbia.edu/tag/007L -/ noncomputable section universe v u v' u' open CategoryTheory open TopCat open CategoryTheory.Limits open TopologicalSpace open Opposite variable {C : Type u} [Category.{v} C] variable [HasColimits.{v} C] variable {X Y Z : TopCat.{v}} namespace TopCat.Presheaf variable (C) /-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/ def stalkFunctor (x : X) : X.Presheaf C ⥤ C := (whiskeringLeft _ _ C).obj (OpenNhds.inclusion x).op ⋙ colim set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor TopCat.Presheaf.stalkFunctor variable {C} /-- The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor nbhds x ⥤ opens F.X ⥤ C -/ def stalk (ℱ : X.Presheaf C) (x : X) : C := (stalkFunctor C x).obj ℱ set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk TopCat.Presheaf.stalk -- -- colimit ((open_nhds.inclusion x).op ⋙ ℱ) @[simp] theorem stalkFunctor_obj (ℱ : X.Presheaf C) (x : X) : (stalkFunctor C x).obj ℱ = ℱ.stalk x := rfl set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor_obj TopCat.Presheaf.stalkFunctor_obj /-- The germ of a section of a presheaf over an open at a point of that open. -/ def germ (F : X.Presheaf C) {U : Opens X} (x : U) : F.obj (op U) ⟶ stalk F x := colimit.ι ((OpenNhds.inclusion x.1).op ⋙ F) (op ⟨U, x.2⟩) set_option linter.uppercaseLean3 false in #align Top.presheaf.germ TopCat.Presheaf.germ theorem germ_res (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : U) : F.map i.op ≫ germ F x = germ F (i x : V) := let i' : (⟨U, x.2⟩ : OpenNhds x.1) ⟶ ⟨V, (i x : V).2⟩ := i colimit.w ((OpenNhds.inclusion x.1).op ⋙ F) i'.op set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_res TopCat.Presheaf.germ_res -- Porting note: `@[elementwise]` did not generate the best lemma when applied to `germ_res` attribute [local instance] ConcreteCategory.instFunLike in theorem germ_res_apply (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : U) [ConcreteCategory C] (s) : germ F x (F.map i.op s) = germ F (i x) s := by rw [← comp_apply, germ_res] set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_res_apply TopCat.Presheaf.germ_res_apply /-- A morphism from the stalk of `F` at `x` to some object `Y` is completely determined by its composition with the `germ` morphisms. -/ @[ext] theorem stalk_hom_ext (F : X.Presheaf C) {x} {Y : C} {f₁ f₂ : F.stalk x ⟶ Y} (ih : ∀ (U : Opens X) (hxU : x ∈ U), F.germ ⟨x, hxU⟩ ≫ f₁ = F.germ ⟨x, hxU⟩ ≫ f₂) : f₁ = f₂ := colimit.hom_ext fun U => by induction' U using Opposite.rec with U; cases' U with U hxU; exact ih U hxU set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_hom_ext TopCat.Presheaf.stalk_hom_ext @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkFunctor_map_germ {F G : X.Presheaf C} (U : Opens X) (x : U) (f : F ⟶ G) : germ F x ≫ (stalkFunctor C x.1).map f = f.app (op U) ≫ germ G x := colimit.ι_map (whiskerLeft (OpenNhds.inclusion x.1).op f) (op ⟨U, x.2⟩) set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor_map_germ TopCat.Presheaf.stalkFunctor_map_germ variable (C) /-- For a presheaf `F` on a space `X`, a continuous map `f : X ⟶ Y` induces a morphisms between the stalk of `f _ * F` at `f x` and the stalk of `F` at `x`. -/ def stalkPushforward (f : X ⟶ Y) (F : X.Presheaf C) (x : X) : (f _* F).stalk (f x) ⟶ F.stalk x := by -- This is a hack; Lean doesn't like to elaborate the term written directly. -- Porting note: The original proof was `trans; swap`, but `trans` does nothing. refine ?_ ≫ colimit.pre _ (OpenNhds.map f x).op exact colim.map (whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) F) set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pushforward TopCat.Presheaf.stalkPushforward @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkPushforward_germ (f : X ⟶ Y) (F : X.Presheaf C) (U : Opens Y) (x : (Opens.map f).obj U) : (f _* F).germ ⟨(f : X → Y) (x : X), x.2⟩ ≫ F.stalkPushforward C f x = F.germ x := by simp [germ, stalkPushforward] set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pushforward_germ TopCat.Presheaf.stalkPushforward_germ -- Here are two other potential solutions, suggested by @fpvandoorn at -- <https://github.com/leanprover-community/mathlib/pull/1018#discussion_r283978240> -- However, I can't get the subsequent two proofs to work with either one. -- def stalkPushforward'' (f : X ⟶ Y) (ℱ : X.Presheaf C) (x : X) : -- (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- colim.map ((Functor.associator _ _ _).inv ≫ -- whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) ℱ) ≫ -- colimit.pre ((OpenNhds.inclusion x).op ⋙ ℱ) (OpenNhds.map f x).op -- def stalkPushforward''' (f : X ⟶ Y) (ℱ : X.Presheaf C) (x : X) : -- (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- (colim.map (whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) ℱ) : -- colim.obj ((OpenNhds.inclusion (f x) ⋙ Opens.map f).op ⋙ ℱ) ⟶ _) ≫ -- colimit.pre ((OpenNhds.inclusion x).op ⋙ ℱ) (OpenNhds.map f x).op namespace stalkPushforward @[simp] theorem id (ℱ : X.Presheaf C) (x : X) : ℱ.stalkPushforward C (𝟙 X) x = (stalkFunctor C x).map (Pushforward.id ℱ).hom := by ext simp only [stalkPushforward, germ, colim_map, ι_colimMap_assoc, whiskerRight_app] erw [CategoryTheory.Functor.map_id] simp [stalkFunctor] set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pushforward.id TopCat.Presheaf.stalkPushforward.id @[simp] theorem comp (ℱ : X.Presheaf C) (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : ℱ.stalkPushforward C (f ≫ g) x = (f _* ℱ).stalkPushforward C g (f x) ≫ ℱ.stalkPushforward C f x := by ext simp only [germ, stalkPushforward] -- Now `simp` finishes, but slowly: simp only [pushforwardObj_obj, Functor.op_obj, Opens.map_comp_obj, whiskeringLeft_obj_obj, OpenNhds.inclusionMapIso_inv, NatTrans.op_id, colim_map, ι_colimMap_assoc, Functor.comp_obj, OpenNhds.inclusion_obj, OpenNhds.map_obj, whiskerRight_app, NatTrans.id_app, CategoryTheory.Functor.map_id, colimit.ι_pre, Category.id_comp, Category.assoc, pushforwardObj_map, Functor.op_map, unop_id, op_id, colimit.ι_pre_assoc] set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pushforward.comp TopCat.Presheaf.stalkPushforward.comp theorem stalkPushforward_iso_of_openEmbedding {f : X ⟶ Y} (hf : OpenEmbedding f) (F : X.Presheaf C) (x : X) : IsIso (F.stalkPushforward _ f x) := by haveI := Functor.initial_of_adjunction (hf.isOpenMap.adjunctionNhds x) convert ((Functor.Final.colimitIso (hf.isOpenMap.functorNhds x).op ((OpenNhds.inclusion (f x)).op ⋙ f _* F) : _).symm ≪≫ colim.mapIso _).isIso_hom swap · fapply NatIso.ofComponents · intro U refine F.mapIso (eqToIso ?_) dsimp only [Functor.op] exact congr_arg op (Opens.ext <| Set.preimage_image_eq (unop U).1.1 hf.inj) · intro U V i; erw [← F.map_comp, ← F.map_comp]; congr 1 · change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _) ext U rw [← Iso.comp_inv_eq] erw [colimit.ι_map_assoc] rw [colimit.ι_pre, Category.assoc] erw [colimit.ι_map_assoc, colimit.ι_pre, ← F.map_comp_assoc] apply colimit.w ((OpenNhds.inclusion (f x)).op ⋙ f _* F) _ dsimp only [Functor.op] refine ((homOfLE ?_).op : op (unop U) ⟶ _) exact Set.image_preimage_subset _ _ set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pushforward.stalk_pushforward_iso_of_open_embedding TopCat.Presheaf.stalkPushforward.stalkPushforward_iso_of_openEmbedding end stalkPushforward section stalkPullback /-- The morphism `ℱ_{f x} ⟶ (f⁻¹ℱ)ₓ` that factors through `(f_*f⁻¹ℱ)_{f x}`. -/ def stalkPullbackHom (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) : F.stalk (f x) ⟶ (pullbackObj f F).stalk x := (stalkFunctor _ (f x)).map ((pushforwardPullbackAdjunction C f).unit.app F) ≫ stalkPushforward _ _ _ x set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pullback_hom TopCat.Presheaf.stalkPullbackHom /-- The morphism `(f⁻¹ℱ)(U) ⟶ ℱ_{f(x)}` for some `U ∋ x`. -/ def germToPullbackStalk (f : X ⟶ Y) (F : Y.Presheaf C) (U : Opens X) (x : U) : (pullbackObj f F).obj (op U) ⟶ F.stalk ((f : X → Y) (x : X)) := colimit.desc (Lan.diagram (Opens.map f).op F (op U)) { pt := F.stalk ((f : X → Y) (x : X)) ι := { app := fun V => F.germ ⟨((f : X → Y) (x : X)), V.hom.unop.le x.2⟩ naturality := fun _ _ i => by erw [Category.comp_id]; exact F.germ_res i.left.unop _ } } set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_to_pullback_stalk TopCat.Presheaf.germToPullbackStalk /-- The morphism `(f⁻¹ℱ)ₓ ⟶ ℱ_{f(x)}`. -/ def stalkPullbackInv (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) : (pullbackObj f F).stalk x ⟶ F.stalk (f x) := colimit.desc ((OpenNhds.inclusion x).op ⋙ Presheaf.pullbackObj f F) { pt := F.stalk (f x) ι := { app := fun U => F.germToPullbackStalk _ f (unop U).1 ⟨x, (unop U).2⟩ naturality := fun _ _ _ => by erw [colimit.pre_desc, Category.comp_id]; congr } } set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pullback_inv TopCat.Presheaf.stalkPullbackInv /-- The isomorphism `ℱ_{f(x)} ≅ (f⁻¹ℱ)ₓ`. -/ def stalkPullbackIso (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) : F.stalk (f x) ≅ (pullbackObj f F).stalk x where hom := stalkPullbackHom _ _ _ _ inv := stalkPullbackInv _ _ _ _ hom_inv_id := by delta stalkPullbackHom stalkPullbackInv stalkFunctor Presheaf.pullback stalkPushforward germToPullbackStalk germ change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _) ext j induction' j with j cases j simp only [TopologicalSpace.OpenNhds.inclusionMapIso_inv, whiskerRight_app, whiskerLeft_app, whiskeringLeft_obj_map, Functor.comp_map, colimit.ι_map_assoc, NatTrans.op_id, lan_obj_map, pushforwardPullbackAdjunction_unit_app_app, Category.assoc, colimit.ι_pre_assoc] erw [colimit.ι_desc, colimit.pre_desc, colimit.ι_desc, Category.comp_id] simp inv_hom_id := by delta stalkPullbackHom stalkPullbackInv stalkFunctor Presheaf.pullback stalkPushforward change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _) ext ⟨U_obj, U_property⟩ change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _) ext ⟨j_left, ⟨⟨⟩⟩, j_hom⟩ erw [colimit.map_desc, colimit.map_desc, colimit.ι_desc_assoc, colimit.ι_desc_assoc, colimit.ι_desc, Category.comp_id] simp only [Cocone.whisker_ι, colimit.cocone_ι, OpenNhds.inclusionMapIso_inv, Cocones.precompose_obj_ι, whiskerRight_app, whiskerLeft_app, NatTrans.comp_app, whiskeringLeft_obj_map, NatTrans.op_id, lan_obj_map, pushforwardPullbackAdjunction_unit_app_app] erw [← colimit.w _ (@homOfLE (OpenNhds x) _ ⟨_, U_property⟩ ⟨(Opens.map f).obj (unop j_left), j_hom.unop.le U_property⟩ j_hom.unop.le).op] erw [colimit.ι_pre_assoc (Lan.diagram _ F _) (CostructuredArrow.map _)] erw [colimit.ι_pre_assoc (Lan.diagram _ F (op U_obj)) (CostructuredArrow.map _)] rfl set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pullback_iso TopCat.Presheaf.stalkPullbackIso end stalkPullback section stalkSpecializes variable {C} /-- If `x` specializes to `y`, then there is a natural map `F.stalk y ⟶ F.stalk x`. -/ noncomputable def stalkSpecializes (F : X.Presheaf C) {x y : X} (h : x ⤳ y) : F.stalk y ⟶ F.stalk x := by refine colimit.desc _ ⟨_, fun U => ?_, ?_⟩ · exact colimit.ι ((OpenNhds.inclusion x).op ⋙ F) (op ⟨(unop U).1, (specializes_iff_forall_open.mp h _ (unop U).1.2 (unop U).2 : _)⟩) · intro U V i dsimp rw [Category.comp_id] let U' : OpenNhds x := ⟨_, (specializes_iff_forall_open.mp h _ (unop U).1.2 (unop U).2 : _)⟩ let V' : OpenNhds x := ⟨_, (specializes_iff_forall_open.mp h _ (unop V).1.2 (unop V).2 : _)⟩ exact colimit.w ((OpenNhds.inclusion x).op ⋙ F) (show V' ⟶ U' from i.unop).op set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_specializes TopCat.Presheaf.stalkSpecializes @[reassoc (attr := simp), elementwise nosimp] theorem germ_stalkSpecializes (F : X.Presheaf C) {U : Opens X} {y : U} {x : X} (h : x ⤳ y) : F.germ y ≫ F.stalkSpecializes h = F.germ (⟨x, h.mem_open U.isOpen y.prop⟩ : U) := colimit.ι_desc _ _ set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_stalk_specializes TopCat.Presheaf.germ_stalkSpecializes @[reassoc, elementwise nosimp] theorem germ_stalkSpecializes' (F : X.Presheaf C) {U : Opens X} {x y : X} (h : x ⤳ y) (hy : y ∈ U) : F.germ ⟨y, hy⟩ ≫ F.stalkSpecializes h = F.germ ⟨x, h.mem_open U.isOpen hy⟩ := colimit.ι_desc _ _ set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_stalk_specializes' TopCat.Presheaf.germ_stalkSpecializes' @[simp] theorem stalkSpecializes_refl {C : Type*} [Category C] [Limits.HasColimits C] {X : TopCat} (F : X.Presheaf C) (x : X) : F.stalkSpecializes (specializes_refl x) = 𝟙 _ := by ext simp set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_specializes_refl TopCat.Presheaf.stalkSpecializes_refl @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkSpecializes_comp {C : Type*} [Category C] [Limits.HasColimits C] {X : TopCat} (F : X.Presheaf C) {x y z : X} (h : x ⤳ y) (h' : y ⤳ z) : F.stalkSpecializes h' ≫ F.stalkSpecializes h = F.stalkSpecializes (h.trans h') := by ext simp set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_specializes_comp TopCat.Presheaf.stalkSpecializes_comp @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkSpecializes_stalkFunctor_map {F G : X.Presheaf C} (f : F ⟶ G) {x y : X} (h : x ⤳ y) : F.stalkSpecializes h ≫ (stalkFunctor C x).map f = (stalkFunctor C y).map f ≫ G.stalkSpecializes h := by change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _) ext; delta stalkFunctor; simpa [stalkSpecializes] using by rfl set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_specializes_stalk_functor_map TopCat.Presheaf.stalkSpecializes_stalkFunctor_map @[reassoc, elementwise, simp, nolint simpNF] -- see std4#365 for the simpNF issue theorem stalkSpecializes_stalkPushforward (f : X ⟶ Y) (F : X.Presheaf C) {x y : X} (h : x ⤳ y) : (f _* F).stalkSpecializes (f.map_specializes h) ≫ F.stalkPushforward _ f x = F.stalkPushforward _ f y ≫ F.stalkSpecializes h := by change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _) ext; delta stalkPushforward simp only [stalkSpecializes, colimit.ι_desc_assoc, colimit.ι_map_assoc, colimit.ι_pre, Category.assoc, colimit.pre_desc, colimit.ι_desc] rfl set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_specializes_stalk_pushforward TopCat.Presheaf.stalkSpecializes_stalkPushforward /-- The stalks are isomorphic on inseparable points -/ @[simps] def stalkCongr {X : TopCat} {C : Type*} [Category C] [HasColimits C] (F : X.Presheaf C) {x y : X} (e : Inseparable x y) : F.stalk x ≅ F.stalk y := ⟨F.stalkSpecializes e.ge, F.stalkSpecializes e.le, by simp, by simp⟩ set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_congr TopCat.Presheaf.stalkCongr end stalkSpecializes section Concrete variable {C} variable [ConcreteCategory.{v} C] attribute [local instance] ConcreteCategory.hasCoeToSort ConcreteCategory.instFunLike -- Porting note (#11215): TODO: @[ext] attribute only applies to structures or lemmas proving x = y -- @[ext] theorem germ_ext (F : X.Presheaf C) {U V : Opens X} {x : X} {hxU : x ∈ U} {hxV : x ∈ V} (W : Opens X) (hxW : x ∈ W) (iWU : W ⟶ U) (iWV : W ⟶ V) {sU : F.obj (op U)} {sV : F.obj (op V)} (ih : F.map iWU.op sU = F.map iWV.op sV) : F.germ ⟨x, hxU⟩ sU = F.germ ⟨x, hxV⟩ sV := by erw [← F.germ_res iWU ⟨x, hxW⟩, ← F.germ_res iWV ⟨x, hxW⟩, comp_apply, comp_apply, ih] set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_ext TopCat.Presheaf.germ_ext variable [PreservesFilteredColimits (forget C)] /-- For presheaves valued in a concrete category whose forgetful functor preserves filtered colimits, every element of the stalk is the germ of a section. -/ theorem germ_exist (F : X.Presheaf C) (x : X) (t : (stalk.{v, u} F x : Type v)) : ∃ (U : Opens X) (m : x ∈ U) (s : F.obj (op U)), F.germ ⟨x, m⟩ s = t := by obtain ⟨U, s, e⟩ := Types.jointly_surjective.{v, v} _ (isColimitOfPreserves (forget C) (colimit.isColimit _)) t revert s e induction U with | h U => ?_ cases' U with V m intro s e exact ⟨V, m, s, e⟩ set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_exist TopCat.Presheaf.germ_exist theorem germ_eq (F : X.Presheaf C) {U V : Opens X} (x : X) (mU : x ∈ U) (mV : x ∈ V) (s : F.obj (op U)) (t : F.obj (op V)) (h : germ F ⟨x, mU⟩ s = germ F ⟨x, mV⟩ t) : ∃ (W : Opens X) (_m : x ∈ W) (iU : W ⟶ U) (iV : W ⟶ V), F.map iU.op s = F.map iV.op t := by obtain ⟨W, iU, iV, e⟩ := (Types.FilteredColimit.isColimit_eq_iff.{v, v} _ (isColimitOfPreserves _ (colimit.isColimit ((OpenNhds.inclusion x).op ⋙ F)))).mp h exact ⟨(unop W).1, (unop W).2, iU.unop, iV.unop, e⟩ set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_eq TopCat.Presheaf.germ_eq theorem stalkFunctor_map_injective_of_app_injective {F G : Presheaf C X} (f : F ⟶ G) (h : ∀ U : Opens X, Function.Injective (f.app (op U))) (x : X) : Function.Injective ((stalkFunctor C x).map f) := fun s t hst => by rcases germ_exist F x s with ⟨U₁, hxU₁, s, rfl⟩ rcases germ_exist F x t with ⟨U₂, hxU₂, t, rfl⟩ erw [stalkFunctor_map_germ_apply _ ⟨x, _⟩] at hst erw [stalkFunctor_map_germ_apply _ ⟨x, _⟩] at hst obtain ⟨W, hxW, iWU₁, iWU₂, heq⟩ := G.germ_eq x hxU₁ hxU₂ _ _ hst rw [← comp_apply, ← comp_apply, ← f.naturality, ← f.naturality, comp_apply, comp_apply] at heq replace heq := h W heq convert congr_arg (F.germ ⟨x, hxW⟩) heq using 1 exacts [(F.germ_res_apply iWU₁ ⟨x, hxW⟩ s).symm, (F.germ_res_apply iWU₂ ⟨x, hxW⟩ t).symm] set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor_map_injective_of_app_injective TopCat.Presheaf.stalkFunctor_map_injective_of_app_injective variable [HasLimits C] [PreservesLimits (forget C)] [(forget C).ReflectsIsomorphisms] /-- Let `F` be a sheaf valued in a concrete category, whose forgetful functor reflects isomorphisms, preserves limits and filtered colimits. Then two sections who agree on every stalk must be equal. -/ theorem section_ext (F : Sheaf C X) (U : Opens X) (s t : F.1.obj (op U)) (h : ∀ x : U, F.presheaf.germ x s = F.presheaf.germ x t) : s = t := by -- We use `germ_eq` and the axiom of choice, to pick for every point `x` a neighbourhood -- `V x`, such that the restrictions of `s` and `t` to `V x` coincide. choose V m i₁ i₂ heq using fun x : U => F.presheaf.germ_eq x.1 x.2 x.2 s t (h x) -- Since `F` is a sheaf, we can prove the equality locally, if we can show that these -- neighborhoods form a cover of `U`. apply F.eq_of_locally_eq' V U i₁ · intro x hxU simp only [Opens.coe_iSup, Set.mem_iUnion, SetLike.mem_coe] exact ⟨⟨x, hxU⟩, m ⟨x, hxU⟩⟩ · intro x rw [heq, Subsingleton.elim (i₁ x) (i₂ x)] set_option linter.uppercaseLean3 false in #align Top.presheaf.section_ext TopCat.Presheaf.section_ext /- Note that the analogous statement for surjectivity is false: Surjectivity on stalks does not imply surjectivity of the components of a sheaf morphism. However it does imply that the morphism is an epi, but this fact is not yet formalized. -/ theorem app_injective_of_stalkFunctor_map_injective {F : Sheaf C X} {G : Presheaf C X} (f : F.1 ⟶ G) (U : Opens X) (h : ∀ x : U, Function.Injective ((stalkFunctor C x.val).map f)) : Function.Injective (f.app (op U)) := fun s t hst => section_ext F _ _ _ fun x => h x <| by erw [stalkFunctor_map_germ_apply, stalkFunctor_map_germ_apply, hst] set_option linter.uppercaseLean3 false in #align Top.presheaf.app_injective_of_stalk_functor_map_injective TopCat.Presheaf.app_injective_of_stalkFunctor_map_injective theorem app_injective_iff_stalkFunctor_map_injective {F : Sheaf C X} {G : Presheaf C X} (f : F.1 ⟶ G) : (∀ x : X, Function.Injective ((stalkFunctor C x).map f)) ↔ ∀ U : Opens X, Function.Injective (f.app (op U)) := ⟨fun h U => app_injective_of_stalkFunctor_map_injective f U fun x => h x.1, stalkFunctor_map_injective_of_app_injective f⟩ set_option linter.uppercaseLean3 false in #align Top.presheaf.app_injective_iff_stalk_functor_map_injective TopCat.Presheaf.app_injective_iff_stalkFunctor_map_injective instance stalkFunctor_preserves_mono (x : X) : Functor.PreservesMonomorphisms (Sheaf.forget C X ⋙ stalkFunctor C x) := ⟨@fun _𝓐 _𝓑 f _ => ConcreteCategory.mono_of_injective _ <| (app_injective_iff_stalkFunctor_map_injective f.1).mpr (fun c => (@ConcreteCategory.mono_iff_injective_of_preservesPullback _ _ _ _ _ (f.1.app (op c))).mp ((NatTrans.mono_iff_mono_app _ f.1).mp (CategoryTheory.presheaf_mono_of_mono ..) <| op c)) x⟩ set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor_preserves_mono TopCat.Presheaf.stalkFunctor_preserves_mono theorem stalk_mono_of_mono {F G : Sheaf C X} (f : F ⟶ G) [Mono f] : ∀ x, Mono <| (stalkFunctor C x).map f.1 := fun x => Functor.map_mono (Sheaf.forget.{v} C X ⋙ stalkFunctor C x) f set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_mono_of_mono TopCat.Presheaf.stalk_mono_of_mono theorem mono_of_stalk_mono {F G : Sheaf C X} (f : F ⟶ G) [∀ x, Mono <| (stalkFunctor C x).map f.1] : Mono f := (Sheaf.Hom.mono_iff_presheaf_mono _ _ _).mpr <| (NatTrans.mono_iff_mono_app _ _).mpr fun U => (ConcreteCategory.mono_iff_injective_of_preservesPullback _).mpr <| app_injective_of_stalkFunctor_map_injective f.1 U.unop fun ⟨_x, _hx⟩ => (ConcreteCategory.mono_iff_injective_of_preservesPullback _).mp <| inferInstance set_option linter.uppercaseLean3 false in #align Top.presheaf.mono_of_stalk_mono TopCat.Presheaf.mono_of_stalk_mono theorem mono_iff_stalk_mono {F G : Sheaf C X} (f : F ⟶ G) : Mono f ↔ ∀ x, Mono ((stalkFunctor C x).map f.1) := ⟨fun _ => stalk_mono_of_mono _, fun _ => mono_of_stalk_mono _⟩ set_option linter.uppercaseLean3 false in #align Top.presheaf.mono_iff_stalk_mono TopCat.Presheaf.mono_iff_stalk_mono /-- For surjectivity, we are given an arbitrary section `t` and need to find a preimage for it. We claim that it suffices to find preimages *locally*. That is, for each `x : U` we construct a neighborhood `V ≤ U` and a section `s : F.obj (op V))` such that `f.app (op V) s` and `t` agree on `V`. -/ theorem app_surjective_of_injective_of_locally_surjective {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X) (hinj : ∀ x : U, Function.Injective ((stalkFunctor C x.1).map f.1)) (hsurj : ∀ (t) (x : U), ∃ (V : Opens X) (_ : x.1 ∈ V) (iVU : V ⟶ U) (s : F.1.obj (op V)), f.1.app (op V) s = G.1.map iVU.op t) : Function.Surjective (f.1.app (op U)) := by intro t -- We use the axiom of choice to pick around each point `x` an open neighborhood `V` and a -- preimage under `f` on `V`. choose V mV iVU sf heq using hsurj t -- These neighborhoods clearly cover all of `U`. have V_cover : U ≤ iSup V := by intro x hxU simp only [Opens.coe_iSup, Set.mem_iUnion, SetLike.mem_coe] exact ⟨⟨x, hxU⟩, mV ⟨x, hxU⟩⟩ suffices IsCompatible F.val V sf by -- Since `F` is a sheaf, we can glue all the local preimages together to get a global preimage. obtain ⟨s, s_spec, -⟩ := F.existsUnique_gluing' V U iVU V_cover sf this · use s apply G.eq_of_locally_eq' V U iVU V_cover intro x rw [← comp_apply, ← f.1.naturality, comp_apply, s_spec, heq] intro x y -- What's left to show here is that the sections `sf` are compatible, i.e. they agree on -- the intersections `V x ⊓ V y`. We prove this by showing that all germs are equal. apply section_ext intro z -- Here, we need to use injectivity of the stalk maps. apply hinj ⟨z, (iVU x).le ((inf_le_left : V x ⊓ V y ≤ V x) z.2)⟩ dsimp only erw [stalkFunctor_map_germ_apply, stalkFunctor_map_germ_apply] simp_rw [← comp_apply, f.1.naturality, comp_apply, heq, ← comp_apply, ← G.1.map_comp] rfl set_option linter.uppercaseLean3 false in #align Top.presheaf.app_surjective_of_injective_of_locally_surjective TopCat.Presheaf.app_surjective_of_injective_of_locally_surjective theorem app_surjective_of_stalkFunctor_map_bijective {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X) (h : ∀ x : U, Function.Bijective ((stalkFunctor C x.val).map f.1)) : Function.Surjective (f.1.app (op U)) := by refine app_surjective_of_injective_of_locally_surjective f U (fun x => (h x).1) fun t x => ?_ -- Now we need to prove our initial claim: That we can find preimages of `t` locally. -- Since `f` is surjective on stalks, we can find a preimage `s₀` of the germ of `t` at `x` obtain ⟨s₀, hs₀⟩ := (h x).2 (G.presheaf.germ x t) -- ... and this preimage must come from some section `s₁` defined on some open neighborhood `V₁` obtain ⟨V₁, hxV₁, s₁, hs₁⟩ := F.presheaf.germ_exist x.1 s₀ subst hs₁; rename' hs₀ => hs₁ erw [stalkFunctor_map_germ_apply V₁ ⟨x.1, hxV₁⟩ f.1 s₁] at hs₁ -- Now, the germ of `f.app (op V₁) s₁` equals the germ of `t`, hence they must coincide on -- some open neighborhood `V₂`. obtain ⟨V₂, hxV₂, iV₂V₁, iV₂U, heq⟩ := G.presheaf.germ_eq x.1 hxV₁ x.2 _ _ hs₁ -- The restriction of `s₁` to that neighborhood is our desired local preimage. use V₂, hxV₂, iV₂U, F.1.map iV₂V₁.op s₁ rw [← comp_apply, f.1.naturality, comp_apply, heq] set_option linter.uppercaseLean3 false in #align Top.presheaf.app_surjective_of_stalk_functor_map_bijective TopCat.Presheaf.app_surjective_of_stalkFunctor_map_bijective theorem app_bijective_of_stalkFunctor_map_bijective {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X) (h : ∀ x : U, Function.Bijective ((stalkFunctor C x.val).map f.1)) : Function.Bijective (f.1.app (op U)) := ⟨app_injective_of_stalkFunctor_map_injective f.1 U fun x => (h x).1, app_surjective_of_stalkFunctor_map_bijective f U h⟩ set_option linter.uppercaseLean3 false in #align Top.presheaf.app_bijective_of_stalk_functor_map_bijective TopCat.Presheaf.app_bijective_of_stalkFunctor_map_bijective theorem app_isIso_of_stalkFunctor_map_iso {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X) [∀ x : U, IsIso ((stalkFunctor C x.val).map f.1)] : IsIso (f.1.app (op U)) := by -- Since the forgetful functor of `C` reflects isomorphisms, it suffices to see that the -- underlying map between types is an isomorphism, i.e. bijective. suffices IsIso ((forget C).map (f.1.app (op U))) by exact isIso_of_reflects_iso (f.1.app (op U)) (forget C) rw [isIso_iff_bijective] apply app_bijective_of_stalkFunctor_map_bijective intro x apply (isIso_iff_bijective _).mp exact Functor.map_isIso (forget C) ((stalkFunctor C x.1).map f.1) set_option linter.uppercaseLean3 false in #align Top.presheaf.app_is_iso_of_stalk_functor_map_iso TopCat.Presheaf.app_isIso_of_stalkFunctor_map_iso -- Making this an instance would cause a loop in typeclass resolution with `Functor.map_isIso` /-- Let `F` and `G` be sheaves valued in a concrete category, whose forgetful functor reflects isomorphisms, preserves limits and filtered colimits. Then if the stalk maps of a morphism `f : F ⟶ G` are all isomorphisms, `f` must be an isomorphism. -/
Mathlib/Topology/Sheaves/Stalks.lean
609
618
theorem isIso_of_stalkFunctor_map_iso {F G : Sheaf C X} (f : F ⟶ G) [∀ x : X, IsIso ((stalkFunctor C x).map f.1)] : IsIso f := by
-- Since the inclusion functor from sheaves to presheaves is fully faithful, it suffices to -- show that `f`, as a morphism between _presheaves_, is an isomorphism. suffices IsIso ((Sheaf.forget C X).map f) by exact isIso_of_fully_faithful (Sheaf.forget C X) f -- We show that all components of `f` are isomorphisms. suffices ∀ U : (Opens X)ᵒᵖ, IsIso (f.1.app U) by exact @NatIso.isIso_of_isIso_app _ _ _ _ F.1 G.1 f.1 this intro U; induction U apply app_isIso_of_stalkFunctor_map_iso
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Control.Applicative import Mathlib.Control.Traversable.Basic import Mathlib.Data.List.Basic import Mathlib.Logic.Equiv.Defs import Mathlib.Tactic.AdaptationNote #align_import algebra.free from "leanprover-community/mathlib"@"6d0adfa76594f304b4650d098273d4366edeb61b" /-! # Free constructions ## Main definitions * `FreeMagma α`: free magma (structure with binary operation without any axioms) over alphabet `α`, defined inductively, with traversable instance and decidable equality. * `MagmaAssocQuotient α`: quotient of a magma `α` by the associativity equivalence relation. * `FreeSemigroup α`: free semigroup over alphabet `α`, defined as a structure with two fields `head : α` and `tail : List α` (i.e. nonempty lists), with traversable instance and decidable equality. * `FreeMagmaAssocQuotientEquiv α`: isomorphism between `MagmaAssocQuotient (FreeMagma α)` and `FreeSemigroup α`. * `FreeMagma.lift`: the universal property of the free magma, expressing its adjointness. -/ universe u v l /-- Free nonabelian additive magma over a given alphabet. -/ inductive FreeAddMagma (α : Type u) : Type u | of : α → FreeAddMagma α | add : FreeAddMagma α → FreeAddMagma α → FreeAddMagma α deriving DecidableEq #align free_add_magma FreeAddMagma compile_inductive% FreeAddMagma /-- Free magma over a given alphabet. -/ @[to_additive] inductive FreeMagma (α : Type u) : Type u | of : α → FreeMagma α | mul : FreeMagma α → FreeMagma α → FreeMagma α deriving DecidableEq #align free_magma FreeMagma compile_inductive% FreeMagma namespace FreeMagma variable {α : Type u} @[to_additive] instance [Inhabited α] : Inhabited (FreeMagma α) := ⟨of default⟩ @[to_additive] instance : Mul (FreeMagma α) := ⟨FreeMagma.mul⟩ -- Porting note: invalid attribute 'match_pattern', declaration is in an imported module -- attribute [match_pattern] Mul.mul @[to_additive (attr := simp)] theorem mul_eq (x y : FreeMagma α) : mul x y = x * y := rfl #align free_magma.mul_eq FreeMagma.mul_eq /- Porting note: these lemmas are autogenerated by the inductive definition and due to the existence of mul_eq not in simp normal form -/ attribute [nolint simpNF] FreeAddMagma.add.sizeOf_spec attribute [nolint simpNF] FreeMagma.mul.sizeOf_spec attribute [nolint simpNF] FreeAddMagma.add.injEq attribute [nolint simpNF] FreeMagma.mul.injEq /-- Recursor for `FreeMagma` using `x * y` instead of `FreeMagma.mul x y`. -/ @[to_additive (attr := elab_as_elim) "Recursor for `FreeAddMagma` using `x + y` instead of `FreeAddMagma.add x y`."] def recOnMul {C : FreeMagma α → Sort l} (x) (ih1 : ∀ x, C (of x)) (ih2 : ∀ x y, C x → C y → C (x * y)) : C x := FreeMagma.recOn x ih1 ih2 #align free_magma.rec_on_mul FreeMagma.recOnMul @[to_additive (attr := ext 1100)] theorem hom_ext {β : Type v} [Mul β] {f g : FreeMagma α →ₙ* β} (h : f ∘ of = g ∘ of) : f = g := (DFunLike.ext _ _) fun x ↦ recOnMul x (congr_fun h) <| by intros; simp only [map_mul, *] #align free_magma.hom_ext FreeMagma.hom_ext end FreeMagma #adaptation_note /-- around nightly-2024-02-25, we need to write `mul x y` in the second pattern, instead of `x * y`. --/ /-- Lifts a function `α → β` to a magma homomorphism `FreeMagma α → β` given a magma `β`. -/ def FreeMagma.liftAux {α : Type u} {β : Type v} [Mul β] (f : α → β) : FreeMagma α → β | FreeMagma.of x => f x | mul x y => liftAux f x * liftAux f y #align free_magma.lift_aux FreeMagma.liftAux /-- Lifts a function `α → β` to an additive magma homomorphism `FreeAddMagma α → β` given an additive magma `β`. -/ def FreeAddMagma.liftAux {α : Type u} {β : Type v} [Add β] (f : α → β) : FreeAddMagma α → β | FreeAddMagma.of x => f x | x + y => liftAux f x + liftAux f y #align free_add_magma.lift_aux FreeAddMagma.liftAux attribute [to_additive existing] FreeMagma.liftAux namespace FreeMagma section lift variable {α : Type u} {β : Type v} [Mul β] (f : α → β) /-- The universal property of the free magma expressing its adjointness. -/ @[to_additive (attr := simps symm_apply) "The universal property of the free additive magma expressing its adjointness."] def lift : (α → β) ≃ (FreeMagma α →ₙ* β) where toFun f := { toFun := liftAux f map_mul' := fun x y ↦ rfl } invFun F := F ∘ of left_inv f := rfl right_inv F := by ext; rfl #align free_magma.lift FreeMagma.lift @[to_additive (attr := simp)] theorem lift_of (x) : lift f (of x) = f x := rfl #align free_magma.lift_of FreeMagma.lift_of @[to_additive (attr := simp)] theorem lift_comp_of : lift f ∘ of = f := rfl #align free_magma.lift_comp_of FreeMagma.lift_comp_of @[to_additive (attr := simp)] theorem lift_comp_of' (f : FreeMagma α →ₙ* β) : lift (f ∘ of) = f := lift.apply_symm_apply f #align free_magma.lift_comp_of' FreeMagma.lift_comp_of' end lift section Map variable {α : Type u} {β : Type v} (f : α → β) /-- The unique magma homomorphism `FreeMagma α →ₙ* FreeMagma β` that sends each `of x` to `of (f x)`. -/ @[to_additive "The unique additive magma homomorphism `FreeAddMagma α → FreeAddMagma β` that sends each `of x` to `of (f x)`."] def map (f : α → β) : FreeMagma α →ₙ* FreeMagma β := lift (of ∘ f) #align free_magma.map FreeMagma.map @[to_additive (attr := simp)] theorem map_of (x) : map f (of x) = of (f x) := rfl #align free_magma.map_of FreeMagma.map_of end Map section Category variable {α β : Type u} @[to_additive] instance : Monad FreeMagma where pure := of bind x f := lift f x /-- Recursor on `FreeMagma` using `pure` instead of `of`. -/ @[to_additive (attr := elab_as_elim) "Recursor on `FreeAddMagma` using `pure` instead of `of`."] protected def recOnPure {C : FreeMagma α → Sort l} (x) (ih1 : ∀ x, C (pure x)) (ih2 : ∀ x y, C x → C y → C (x * y)) : C x := FreeMagma.recOnMul x ih1 ih2 #align free_magma.rec_on_pure FreeMagma.recOnPure -- Porting note (#10675): dsimp can not prove this @[to_additive (attr := simp, nolint simpNF)] theorem map_pure (f : α → β) (x) : (f <$> pure x : FreeMagma β) = pure (f x) := rfl #align free_magma.map_pure FreeMagma.map_pure @[to_additive (attr := simp)] theorem map_mul' (f : α → β) (x y : FreeMagma α) : f <$> (x * y) = f <$> x * f <$> y := rfl #align free_magma.map_mul' FreeMagma.map_mul' -- Porting note (#10675): dsimp can not prove this @[to_additive (attr := simp, nolint simpNF)] theorem pure_bind (f : α → FreeMagma β) (x) : pure x >>= f = f x := rfl #align free_magma.pure_bind FreeMagma.pure_bind @[to_additive (attr := simp)] theorem mul_bind (f : α → FreeMagma β) (x y : FreeMagma α) : x * y >>= f = (x >>= f) * (y >>= f) := rfl #align free_magma.mul_bind FreeMagma.mul_bind @[to_additive (attr := simp)] theorem pure_seq {α β : Type u} {f : α → β} {x : FreeMagma α} : pure f <*> x = f <$> x := rfl #align free_magma.pure_seq FreeMagma.pure_seq @[to_additive (attr := simp)] theorem mul_seq {α β : Type u} {f g : FreeMagma (α → β)} {x : FreeMagma α} : f * g <*> x = (f <*> x) * (g <*> x) := rfl #align free_magma.mul_seq FreeMagma.mul_seq @[to_additive] instance instLawfulMonad : LawfulMonad FreeMagma.{u} := LawfulMonad.mk' (pure_bind := fun f x ↦ rfl) (bind_assoc := fun x f g ↦ FreeMagma.recOnPure x (fun x ↦ rfl) fun x y ih1 ih2 ↦ by rw [mul_bind, mul_bind, mul_bind, ih1, ih2]) (id_map := fun x ↦ FreeMagma.recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by rw [map_mul', ih1, ih2]) end Category end FreeMagma #adaptation_note /-- around nightly-2024-02-25, we need to write `mul x y` in the second pattern, instead of `x * y`. -/ /-- `FreeMagma` is traversable. -/ protected def FreeMagma.traverse {m : Type u → Type u} [Applicative m] {α β : Type u} (F : α → m β) : FreeMagma α → m (FreeMagma β) | FreeMagma.of x => FreeMagma.of <$> F x | mul x y => (· * ·) <$> x.traverse F <*> y.traverse F #align free_magma.traverse FreeMagma.traverse /-- `FreeAddMagma` is traversable. -/ protected def FreeAddMagma.traverse {m : Type u → Type u} [Applicative m] {α β : Type u} (F : α → m β) : FreeAddMagma α → m (FreeAddMagma β) | FreeAddMagma.of x => FreeAddMagma.of <$> F x | x + y => (· + ·) <$> x.traverse F <*> y.traverse F #align free_add_magma.traverse FreeAddMagma.traverse attribute [to_additive existing] FreeMagma.traverse namespace FreeMagma variable {α : Type u} section Category variable {β : Type u} @[to_additive] instance : Traversable FreeMagma := ⟨@FreeMagma.traverse⟩ variable {m : Type u → Type u} [Applicative m] (F : α → m β) @[to_additive (attr := simp)] theorem traverse_pure (x) : traverse F (pure x : FreeMagma α) = pure <$> F x := rfl #align free_magma.traverse_pure FreeMagma.traverse_pure @[to_additive (attr := simp)] theorem traverse_pure' : traverse F ∘ pure = fun x ↦ (pure <$> F x : m (FreeMagma β)) := rfl #align free_magma.traverse_pure' FreeMagma.traverse_pure' @[to_additive (attr := simp)] theorem traverse_mul (x y : FreeMagma α) : traverse F (x * y) = (· * ·) <$> traverse F x <*> traverse F y := rfl #align free_magma.traverse_mul FreeMagma.traverse_mul @[to_additive (attr := simp)] theorem traverse_mul' : Function.comp (traverse F) ∘ (HMul.hMul : FreeMagma α → FreeMagma α → FreeMagma α) = fun x y ↦ (· * ·) <$> traverse F x <*> traverse F y := rfl #align free_magma.traverse_mul' FreeMagma.traverse_mul' @[to_additive (attr := simp)] theorem traverse_eq (x) : FreeMagma.traverse F x = traverse F x := rfl #align free_magma.traverse_eq FreeMagma.traverse_eq -- Porting note (#10675): dsimp can not prove this @[to_additive (attr := simp, nolint simpNF)] theorem mul_map_seq (x y : FreeMagma α) : ((· * ·) <$> x <*> y : Id (FreeMagma α)) = (x * y : FreeMagma α) := rfl #align free_magma.mul_map_seq FreeMagma.mul_map_seq @[to_additive] instance : LawfulTraversable FreeMagma.{u} := { instLawfulMonad with id_traverse := fun x ↦ FreeMagma.recOnPure x (fun x ↦ rfl) fun x y ih1 ih2 ↦ by rw [traverse_mul, ih1, ih2, mul_map_seq] comp_traverse := fun f g x ↦ FreeMagma.recOnPure x (fun x ↦ by simp only [(· ∘ ·), traverse_pure, traverse_pure', functor_norm]) (fun x y ih1 ih2 ↦ by rw [traverse_mul, ih1, ih2, traverse_mul]; simp [Functor.Comp.map_mk, Functor.map_map, (· ∘ ·), Comp.seq_mk, seq_map_assoc, map_seq, traverse_mul]) naturality := fun η α β f x ↦ FreeMagma.recOnPure x (fun x ↦ by simp only [traverse_pure, functor_norm, Function.comp_apply]) (fun x y ih1 ih2 ↦ by simp only [traverse_mul, functor_norm, ih1, ih2]) traverse_eq_map_id := fun f x ↦ FreeMagma.recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by rw [traverse_mul, ih1, ih2, map_mul', mul_map_seq]; rfl } end Category end FreeMagma -- Porting note: changed String to Lean.Format #adaptation_note /-- around nightly-2024-02-25, we need to write `mul x y` in the second pattern, instead of `x * y`. -/ /-- Representation of an element of a free magma. -/ protected def FreeMagma.repr {α : Type u} [Repr α] : FreeMagma α → Lean.Format | FreeMagma.of x => repr x | mul x y => "( " ++ x.repr ++ " * " ++ y.repr ++ " )" #align free_magma.repr FreeMagma.repr /-- Representation of an element of a free additive magma. -/ protected def FreeAddMagma.repr {α : Type u} [Repr α] : FreeAddMagma α → Lean.Format | FreeAddMagma.of x => repr x | x + y => "( " ++ x.repr ++ " + " ++ y.repr ++ " )" #align free_add_magma.repr FreeAddMagma.repr attribute [to_additive existing] FreeMagma.repr @[to_additive] instance {α : Type u} [Repr α] : Repr (FreeMagma α) := ⟨fun o _ => FreeMagma.repr o⟩ #adaptation_note /-- around nightly-2024-02-25, we need to write `mul x y` in the second pattern, instead of `x * y`. -/ /-- Length of an element of a free magma. -/ def FreeMagma.length {α : Type u} : FreeMagma α → ℕ | FreeMagma.of _x => 1 | mul x y => x.length + y.length #align free_magma.length FreeMagma.length /-- Length of an element of a free additive magma. -/ def FreeAddMagma.length {α : Type u} : FreeAddMagma α → ℕ | FreeAddMagma.of _x => 1 | x + y => x.length + y.length #align free_add_magma.length FreeAddMagma.length attribute [to_additive existing (attr := simp)] FreeMagma.length /-- The length of an element of a free magma is positive. -/ @[to_additive "The length of an element of a free additive magma is positive."] lemma FreeMagma.length_pos {α : Type u} (x : FreeMagma α) : 0 < x.length := match x with | FreeMagma.of _ => Nat.succ_pos 0 | mul y z => Nat.add_pos_left (length_pos y) z.length /-- Associativity relations for an additive magma. -/ inductive AddMagma.AssocRel (α : Type u) [Add α] : α → α → Prop | intro : ∀ x y z, AddMagma.AssocRel α (x + y + z) (x + (y + z)) | left : ∀ w x y z, AddMagma.AssocRel α (w + (x + y + z)) (w + (x + (y + z))) #align add_magma.assoc_rel AddMagma.AssocRel /-- Associativity relations for a magma. -/ @[to_additive AddMagma.AssocRel "Associativity relations for an additive magma."] inductive Magma.AssocRel (α : Type u) [Mul α] : α → α → Prop | intro : ∀ x y z, Magma.AssocRel α (x * y * z) (x * (y * z)) | left : ∀ w x y z, Magma.AssocRel α (w * (x * y * z)) (w * (x * (y * z))) #align magma.assoc_rel Magma.AssocRel namespace Magma /-- Semigroup quotient of a magma. -/ @[to_additive AddMagma.FreeAddSemigroup "Additive semigroup quotient of an additive magma."] def AssocQuotient (α : Type u) [Mul α] : Type u := Quot <| AssocRel α #align magma.assoc_quotient Magma.AssocQuotient namespace AssocQuotient variable {α : Type u} [Mul α] @[to_additive] theorem quot_mk_assoc (x y z : α) : Quot.mk (AssocRel α) (x * y * z) = Quot.mk _ (x * (y * z)) := Quot.sound (AssocRel.intro _ _ _) #align magma.assoc_quotient.quot_mk_assoc Magma.AssocQuotient.quot_mk_assoc @[to_additive] theorem quot_mk_assoc_left (x y z w : α) : Quot.mk (AssocRel α) (x * (y * z * w)) = Quot.mk _ (x * (y * (z * w))) := Quot.sound (AssocRel.left _ _ _ _) #align magma.assoc_quotient.quot_mk_assoc_left Magma.AssocQuotient.quot_mk_assoc_left @[to_additive] instance : Semigroup (AssocQuotient α) where mul x y := by refine Quot.liftOn₂ x y (fun x y ↦ Quot.mk _ (x * y)) ?_ ?_ · rintro a b₁ b₂ (⟨c, d, e⟩ | ⟨c, d, e, f⟩) <;> simp only · exact quot_mk_assoc_left _ _ _ _ · rw [← quot_mk_assoc, quot_mk_assoc_left, quot_mk_assoc] · rintro a₁ a₂ b (⟨c, d, e⟩ | ⟨c, d, e, f⟩) <;> simp only · simp only [quot_mk_assoc, quot_mk_assoc_left] · rw [quot_mk_assoc, quot_mk_assoc, quot_mk_assoc_left, quot_mk_assoc_left, quot_mk_assoc_left, ← quot_mk_assoc c d, ← quot_mk_assoc c d, quot_mk_assoc_left] mul_assoc x y z := Quot.induction_on₃ x y z fun a b c ↦ quot_mk_assoc a b c /-- Embedding from magma to its free semigroup. -/ @[to_additive "Embedding from additive magma to its free additive semigroup."] def of : α →ₙ* AssocQuotient α where toFun := Quot.mk _; map_mul' _x _y := rfl #align magma.assoc_quotient.of Magma.AssocQuotient.of @[to_additive] instance [Inhabited α] : Inhabited (AssocQuotient α) := ⟨of default⟩ @[to_additive (attr := elab_as_elim)] protected theorem induction_on {C : AssocQuotient α → Prop} (x : AssocQuotient α) (ih : ∀ x, C (of x)) : C x := Quot.induction_on x ih #align magma.assoc_quotient.induction_on Magma.AssocQuotient.induction_on section lift variable {β : Type v} [Semigroup β] (f : α →ₙ* β) @[to_additive (attr := ext 1100)] theorem hom_ext {f g : AssocQuotient α →ₙ* β} (h : f.comp of = g.comp of) : f = g := (DFunLike.ext _ _) fun x => AssocQuotient.induction_on x <| DFunLike.congr_fun h #align magma.assoc_quotient.hom_ext Magma.AssocQuotient.hom_ext /-- Lifts a magma homomorphism `α → β` to a semigroup homomorphism `Magma.AssocQuotient α → β` given a semigroup `β`. -/ @[to_additive (attr := simps symm_apply) "Lifts an additive magma homomorphism `α → β` to an additive semigroup homomorphism `AddMagma.AssocQuotient α → β` given an additive semigroup `β`."] def lift : (α →ₙ* β) ≃ (AssocQuotient α →ₙ* β) where toFun f := { toFun := fun x ↦ Quot.liftOn x f <| by rintro a b (⟨c, d, e⟩ | ⟨c, d, e, f⟩) <;> simp only [map_mul, mul_assoc] map_mul' := fun x y ↦ Quot.induction_on₂ x y (map_mul f) } invFun f := f.comp of left_inv f := (DFunLike.ext _ _) fun x ↦ rfl right_inv f := hom_ext <| (DFunLike.ext _ _) fun x ↦ rfl #align magma.assoc_quotient.lift Magma.AssocQuotient.lift @[to_additive (attr := simp)] theorem lift_of (x : α) : lift f (of x) = f x := rfl #align magma.assoc_quotient.lift_of Magma.AssocQuotient.lift_of @[to_additive (attr := simp)] theorem lift_comp_of : (lift f).comp of = f := lift.symm_apply_apply f #align magma.assoc_quotient.lift_comp_of Magma.AssocQuotient.lift_comp_of @[to_additive (attr := simp)] theorem lift_comp_of' (f : AssocQuotient α →ₙ* β) : lift (f.comp of) = f := lift.apply_symm_apply f #align magma.assoc_quotient.lift_comp_of' Magma.AssocQuotient.lift_comp_of' end lift variable {β : Type v} [Mul β] (f : α →ₙ* β) /-- From a magma homomorphism `α →ₙ* β` to a semigroup homomorphism `Magma.AssocQuotient α →ₙ* Magma.AssocQuotient β`. -/ @[to_additive "From an additive magma homomorphism `α → β` to an additive semigroup homomorphism `AddMagma.AssocQuotient α → AddMagma.AssocQuotient β`."] def map : AssocQuotient α →ₙ* AssocQuotient β := lift (of.comp f) #align magma.assoc_quotient.map Magma.AssocQuotient.map @[to_additive (attr := simp)] theorem map_of (x) : map f (of x) = of (f x) := rfl #align magma.assoc_quotient.map_of Magma.AssocQuotient.map_of end AssocQuotient end Magma /-- Free additive semigroup over a given alphabet. -/ structure FreeAddSemigroup (α : Type u) where /-- The head of the element -/ head : α /-- The tail of the element -/ tail : List α #align free_add_semigroup FreeAddSemigroup compile_inductive% FreeAddSemigroup /-- Free semigroup over a given alphabet. -/ @[to_additive (attr := ext)] structure FreeSemigroup (α : Type u) where /-- The head of the element -/ head : α /-- The tail of the element -/ tail : List α #align free_semigroup FreeSemigroup compile_inductive% FreeSemigroup namespace FreeSemigroup variable {α : Type u} @[to_additive] instance : Semigroup (FreeSemigroup α) where mul L1 L2 := ⟨L1.1, L1.2 ++ L2.1 :: L2.2⟩ -- Porting note: replaced ext by FreeSemigroup.ext mul_assoc _L1 _L2 _L3 := FreeSemigroup.ext _ _ rfl <| List.append_assoc _ _ _ @[to_additive (attr := simp)] theorem head_mul (x y : FreeSemigroup α) : (x * y).1 = x.1 := rfl #align free_semigroup.head_mul FreeSemigroup.head_mul @[to_additive (attr := simp)] theorem tail_mul (x y : FreeSemigroup α) : (x * y).2 = x.2 ++ y.1 :: y.2 := rfl #align free_semigroup.tail_mul FreeSemigroup.tail_mul @[to_additive (attr := simp)] theorem mk_mul_mk (x y : α) (L1 L2 : List α) : mk x L1 * mk y L2 = mk x (L1 ++ y :: L2) := rfl #align free_semigroup.mk_mul_mk FreeSemigroup.mk_mul_mk /-- The embedding `α → FreeSemigroup α`. -/ @[to_additive (attr := simps) "The embedding `α → FreeAddSemigroup α`."] def of (x : α) : FreeSemigroup α := ⟨x, []⟩ #align free_semigroup.of FreeSemigroup.of /-- Length of an element of free semigroup. -/ @[to_additive "Length of an element of free additive semigroup"] def length (x : FreeSemigroup α) : ℕ := x.tail.length + 1 #align free_semigroup.length FreeSemigroup.length @[to_additive (attr := simp)] theorem length_mul (x y : FreeSemigroup α) : (x * y).length = x.length + y.length := by simp [length, Nat.add_right_comm, List.length, List.length_append] #align free_semigroup.length_mul FreeSemigroup.length_mul @[to_additive (attr := simp)] theorem length_of (x : α) : (of x).length = 1 := rfl #align free_semigroup.length_of FreeSemigroup.length_of @[to_additive] instance [Inhabited α] : Inhabited (FreeSemigroup α) := ⟨of default⟩ /-- Recursor for free semigroup using `of` and `*`. -/ @[to_additive (attr := elab_as_elim) "Recursor for free additive semigroup using `of` and `+`."] protected def recOnMul {C : FreeSemigroup α → Sort l} (x) (ih1 : ∀ x, C (of x)) (ih2 : ∀ x y, C (of x) → C y → C (of x * y)) : C x := FreeSemigroup.recOn x fun f s ↦ List.recOn s ih1 (fun hd tl ih f ↦ ih2 f ⟨hd, tl⟩ (ih1 f) (ih hd)) f #align free_semigroup.rec_on_mul FreeSemigroup.recOnMul @[to_additive (attr := ext 1100)] theorem hom_ext {β : Type v} [Mul β] {f g : FreeSemigroup α →ₙ* β} (h : f ∘ of = g ∘ of) : f = g := (DFunLike.ext _ _) fun x ↦ FreeSemigroup.recOnMul x (congr_fun h) fun x y hx hy ↦ by simp only [map_mul, *] #align free_semigroup.hom_ext FreeSemigroup.hom_ext section lift variable {β : Type v} [Semigroup β] (f : α → β) /-- Lifts a function `α → β` to a semigroup homomorphism `FreeSemigroup α → β` given a semigroup `β`. -/ @[to_additive (attr := simps symm_apply) "Lifts a function `α → β` to an additive semigroup homomorphism `FreeAddSemigroup α → β` given an additive semigroup `β`."] def lift : (α → β) ≃ (FreeSemigroup α →ₙ* β) where toFun f := { toFun := fun x ↦ x.2.foldl (fun a b ↦ a * f b) (f x.1) map_mul' := fun x y ↦ by simp [head_mul, tail_mul, ← List.foldl_map, List.foldl_append, List.foldl_cons, List.foldl_assoc] } invFun f := f ∘ of left_inv f := rfl right_inv f := hom_ext rfl #align free_semigroup.lift FreeSemigroup.lift @[to_additive (attr := simp)] theorem lift_of (x : α) : lift f (of x) = f x := rfl #align free_semigroup.lift_of FreeSemigroup.lift_of @[to_additive (attr := simp)] theorem lift_comp_of : lift f ∘ of = f := rfl #align free_semigroup.lift_comp_of FreeSemigroup.lift_comp_of @[to_additive (attr := simp)] theorem lift_comp_of' (f : FreeSemigroup α →ₙ* β) : lift (f ∘ of) = f := hom_ext rfl #align free_semigroup.lift_comp_of' FreeSemigroup.lift_comp_of' @[to_additive] theorem lift_of_mul (x y) : lift f (of x * y) = f x * lift f y := by rw [map_mul, lift_of] #align free_semigroup.lift_of_mul FreeSemigroup.lift_of_mul end lift section Map variable {β : Type v} (f : α → β) /-- The unique semigroup homomorphism that sends `of x` to `of (f x)`. -/ @[to_additive "The unique additive semigroup homomorphism that sends `of x` to `of (f x)`."] def map : FreeSemigroup α →ₙ* FreeSemigroup β := lift <| of ∘ f #align free_semigroup.map FreeSemigroup.map @[to_additive (attr := simp)] theorem map_of (x) : map f (of x) = of (f x) := rfl #align free_semigroup.map_of FreeSemigroup.map_of @[to_additive (attr := simp)] theorem length_map (x) : (map f x).length = x.length := FreeSemigroup.recOnMul x (fun x ↦ rfl) (fun x y hx hy ↦ by simp only [map_mul, length_mul, *]) #align free_semigroup.length_map FreeSemigroup.length_map end Map section Category variable {β : Type u} @[to_additive] instance : Monad FreeSemigroup where pure := of bind x f := lift f x /-- Recursor that uses `pure` instead of `of`. -/ @[to_additive (attr := elab_as_elim) "Recursor that uses `pure` instead of `of`."] def recOnPure {C : FreeSemigroup α → Sort l} (x) (ih1 : ∀ x, C (pure x)) (ih2 : ∀ x y, C (pure x) → C y → C (pure x * y)) : C x := FreeSemigroup.recOnMul x ih1 ih2 #align free_semigroup.rec_on_pure FreeSemigroup.recOnPure -- Porting note (#10675): dsimp can not prove this @[to_additive (attr := simp, nolint simpNF)] theorem map_pure (f : α → β) (x) : (f <$> pure x : FreeSemigroup β) = pure (f x) := rfl #align free_semigroup.map_pure FreeSemigroup.map_pure @[to_additive (attr := simp)] theorem map_mul' (f : α → β) (x y : FreeSemigroup α) : f <$> (x * y) = f <$> x * f <$> y := map_mul (map f) _ _ #align free_semigroup.map_mul' FreeSemigroup.map_mul' -- Porting note (#10675): dsimp can not prove this @[to_additive (attr := simp, nolint simpNF)] theorem pure_bind (f : α → FreeSemigroup β) (x) : pure x >>= f = f x := rfl #align free_semigroup.pure_bind FreeSemigroup.pure_bind @[to_additive (attr := simp)] theorem mul_bind (f : α → FreeSemigroup β) (x y : FreeSemigroup α) : x * y >>= f = (x >>= f) * (y >>= f) := map_mul (lift f) _ _ #align free_semigroup.mul_bind FreeSemigroup.mul_bind @[to_additive (attr := simp)] theorem pure_seq {f : α → β} {x : FreeSemigroup α} : pure f <*> x = f <$> x := rfl #align free_semigroup.pure_seq FreeSemigroup.pure_seq @[to_additive (attr := simp)] theorem mul_seq {f g : FreeSemigroup (α → β)} {x : FreeSemigroup α} : f * g <*> x = (f <*> x) * (g <*> x) := mul_bind _ _ _ #align free_semigroup.mul_seq FreeSemigroup.mul_seq @[to_additive] instance instLawfulMonad : LawfulMonad FreeSemigroup.{u} := LawfulMonad.mk' (pure_bind := fun _ _ ↦ rfl) (bind_assoc := fun x g f ↦ recOnPure x (fun x ↦ rfl) fun x y ih1 ih2 ↦ by rw [mul_bind, mul_bind, mul_bind, ih1, ih2]) (id_map := fun x ↦ recOnPure x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by rw [map_mul', ih1, ih2]) /-- `FreeSemigroup` is traversable. -/ @[to_additive "`FreeAddSemigroup` is traversable."] protected def traverse {m : Type u → Type u} [Applicative m] {α β : Type u} (F : α → m β) (x : FreeSemigroup α) : m (FreeSemigroup β) := recOnPure x (fun x ↦ pure <$> F x) fun _x _y ihx ihy ↦ (· * ·) <$> ihx <*> ihy #align free_semigroup.traverse FreeSemigroup.traverse @[to_additive] instance : Traversable FreeSemigroup := ⟨@FreeSemigroup.traverse⟩ variable {m : Type u → Type u} [Applicative m] (F : α → m β) @[to_additive (attr := simp)] theorem traverse_pure (x) : traverse F (pure x : FreeSemigroup α) = pure <$> F x := rfl #align free_semigroup.traverse_pure FreeSemigroup.traverse_pure @[to_additive (attr := simp)] theorem traverse_pure' : traverse F ∘ pure = fun x ↦ (pure <$> F x : m (FreeSemigroup β)) := rfl #align free_semigroup.traverse_pure' FreeSemigroup.traverse_pure' section variable [LawfulApplicative m] @[to_additive (attr := simp)] theorem traverse_mul (x y : FreeSemigroup α) : traverse F (x * y) = (· * ·) <$> traverse F x <*> traverse F y := let ⟨x, L1⟩ := x let ⟨y, L2⟩ := y List.recOn L1 (fun x ↦ rfl) (fun hd tl ih x ↦ show (· * ·) <$> pure <$> F x <*> traverse F (mk hd tl * mk y L2) = (· * ·) <$> ((· * ·) <$> pure <$> F x <*> traverse F (mk hd tl)) <*> traverse F (mk y L2) by rw [ih]; simp only [(· ∘ ·), (mul_assoc _ _ _).symm, functor_norm]) x #align free_semigroup.traverse_mul FreeSemigroup.traverse_mul @[to_additive (attr := simp)] theorem traverse_mul' : Function.comp (traverse F) ∘ (HMul.hMul : FreeSemigroup α → FreeSemigroup α → FreeSemigroup α) = fun x y ↦ (· * ·) <$> traverse F x <*> traverse F y := funext fun x ↦ funext fun y ↦ traverse_mul F x y #align free_semigroup.traverse_mul' FreeSemigroup.traverse_mul' end @[to_additive (attr := simp)] theorem traverse_eq (x) : FreeSemigroup.traverse F x = traverse F x := rfl #align free_semigroup.traverse_eq FreeSemigroup.traverse_eq -- Porting note (#10675): dsimp can not prove this @[to_additive (attr := simp, nolint simpNF)] theorem mul_map_seq (x y : FreeSemigroup α) : ((· * ·) <$> x <*> y : Id (FreeSemigroup α)) = (x * y : FreeSemigroup α) := rfl #align free_semigroup.mul_map_seq FreeSemigroup.mul_map_seq @[to_additive] instance : LawfulTraversable FreeSemigroup.{u} := { instLawfulMonad with id_traverse := fun x ↦ FreeSemigroup.recOnMul x (fun x ↦ rfl) fun x y ih1 ih2 ↦ by rw [traverse_mul, ih1, ih2, mul_map_seq] comp_traverse := fun f g x ↦ recOnPure x (fun x ↦ by simp only [traverse_pure, functor_norm, (· ∘ ·)]) fun x y ih1 ih2 ↦ by (rw [traverse_mul, ih1, ih2, traverse_mul, Functor.Comp.map_mk]; simp only [Function.comp, functor_norm, traverse_mul]) naturality := fun η α β f x ↦ recOnPure x (fun x ↦ by simp only [traverse_pure, functor_norm, Function.comp]) (fun x y ih1 ih2 ↦ by simp only [traverse_mul, functor_norm, ih1, ih2]) traverse_eq_map_id := fun f x ↦ FreeSemigroup.recOnMul x (fun _ ↦ rfl) fun x y ih1 ih2 ↦ by rw [traverse_mul, ih1, ih2, map_mul', mul_map_seq]; rfl } end Category @[to_additive] instance [DecidableEq α] : DecidableEq (FreeSemigroup α) := fun _ _ ↦ decidable_of_iff' _ (FreeSemigroup.ext_iff _ _) end FreeSemigroup namespace FreeMagma variable {α : Type u} {β : Type v} /-- The canonical multiplicative morphism from `FreeMagma α` to `FreeSemigroup α`. -/ @[to_additive "The canonical additive morphism from `FreeAddMagma α` to `FreeAddSemigroup α`."] def toFreeSemigroup : FreeMagma α →ₙ* FreeSemigroup α := FreeMagma.lift FreeSemigroup.of #align free_magma.to_free_semigroup FreeMagma.toFreeSemigroup @[to_additive (attr := simp)] theorem toFreeSemigroup_of (x : α) : toFreeSemigroup (of x) = FreeSemigroup.of x := rfl #align free_magma.to_free_semigroup_of FreeMagma.toFreeSemigroup_of @[to_additive (attr := simp)] theorem toFreeSemigroup_comp_of : @toFreeSemigroup α ∘ of = FreeSemigroup.of := rfl #align free_magma.to_free_semigroup_comp_of FreeMagma.toFreeSemigroup_comp_of @[to_additive]
Mathlib/Algebra/Free.lean
742
743
theorem toFreeSemigroup_comp_map (f : α → β) : toFreeSemigroup.comp (map f) = (FreeSemigroup.map f).comp toFreeSemigroup := by
ext1; rfl
/- 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 theorem coe_support {u v : V} (p : G.Walk u v) : (p.support : Multiset V) = {u} + p.support.tail := by cases p <;> rfl #align simple_graph.walk.coe_support SimpleGraph.Walk.coe_support theorem coe_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = {u} + p.support.tail + p'.support.tail := by rw [support_append, ← Multiset.coe_add, coe_support] #align simple_graph.walk.coe_support_append SimpleGraph.Walk.coe_support_append theorem coe_support_append' [DecidableEq V] {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = p.support + p'.support - {v} := by rw [support_append, ← Multiset.coe_add] simp only [coe_support] rw [add_comm ({v} : Multiset V)] simp only [← add_assoc, add_tsub_cancel_right] #align simple_graph.walk.coe_support_append' SimpleGraph.Walk.coe_support_append' theorem chain_adj_support {u v w : V} (h : G.Adj u v) : ∀ (p : G.Walk v w), List.Chain G.Adj u p.support | nil => List.Chain.cons h List.Chain.nil | cons h' p => List.Chain.cons h (chain_adj_support h' p) #align simple_graph.walk.chain_adj_support SimpleGraph.Walk.chain_adj_support theorem chain'_adj_support {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.Adj p.support | nil => List.Chain.nil | cons h p => chain_adj_support h p #align simple_graph.walk.chain'_adj_support SimpleGraph.Walk.chain'_adj_support theorem chain_dartAdj_darts {d : G.Dart} {v w : V} (h : d.snd = v) (p : G.Walk v w) : List.Chain G.DartAdj d p.darts := by induction p generalizing d with | nil => exact List.Chain.nil -- Porting note: needed to defer `h` and `rfl` to help elaboration | cons h' p ih => exact List.Chain.cons (by exact h) (ih (by rfl)) #align simple_graph.walk.chain_dart_adj_darts SimpleGraph.Walk.chain_dartAdj_darts theorem chain'_dartAdj_darts {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.DartAdj p.darts | nil => trivial -- Porting note: needed to defer `rfl` to help elaboration | cons h p => chain_dartAdj_darts (by rfl) p #align simple_graph.walk.chain'_dart_adj_darts SimpleGraph.Walk.chain'_dartAdj_darts /-- Every edge in a walk's edge list is an edge of the graph. It is written in this form (rather than using `⊆`) to avoid unsightly coercions. -/ theorem edges_subset_edgeSet {u v : V} : ∀ (p : G.Walk u v) ⦃e : Sym2 V⦄, e ∈ p.edges → e ∈ G.edgeSet | cons h' p', e, h => by cases h · exact h' next h' => exact edges_subset_edgeSet p' h' #align simple_graph.walk.edges_subset_edge_set SimpleGraph.Walk.edges_subset_edgeSet theorem adj_of_mem_edges {u v x y : V} (p : G.Walk u v) (h : s(x, y) ∈ p.edges) : G.Adj x y := edges_subset_edgeSet p h #align simple_graph.walk.adj_of_mem_edges SimpleGraph.Walk.adj_of_mem_edges @[simp] theorem darts_nil {u : V} : (nil : G.Walk u u).darts = [] := rfl #align simple_graph.walk.darts_nil SimpleGraph.Walk.darts_nil @[simp] theorem darts_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).darts = ⟨(u, v), h⟩ :: p.darts := rfl #align simple_graph.walk.darts_cons SimpleGraph.Walk.darts_cons @[simp] theorem darts_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).darts = p.darts.concat ⟨(v, w), h⟩ := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.darts_concat SimpleGraph.Walk.darts_concat @[simp] theorem darts_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).darts = p.darts := by subst_vars rfl #align simple_graph.walk.darts_copy SimpleGraph.Walk.darts_copy @[simp] theorem darts_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').darts = p.darts ++ p'.darts := by induction p <;> simp [*] #align simple_graph.walk.darts_append SimpleGraph.Walk.darts_append @[simp] theorem darts_reverse {u v : V} (p : G.Walk u v) : p.reverse.darts = (p.darts.map Dart.symm).reverse := by induction p <;> simp [*, Sym2.eq_swap] #align simple_graph.walk.darts_reverse SimpleGraph.Walk.darts_reverse
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
735
736
theorem mem_darts_reverse {u v : V} {d : G.Dart} {p : G.Walk u v} : d ∈ p.reverse.darts ↔ d.symm ∈ p.darts := by
simp
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.Orientation import Mathlib.Data.Complex.Orientation import Mathlib.Tactic.LinearCombination #align_import analysis.inner_product_space.two_dim from "leanprover-community/mathlib"@"cd8fafa2fac98e1a67097e8a91ad9901cfde48af" /-! # Oriented two-dimensional real inner product spaces This file defines constructions specific to the geometry of an oriented two-dimensional real inner product space `E`. ## Main declarations * `Orientation.areaForm`: an antisymmetric bilinear form `E →ₗ[ℝ] E →ₗ[ℝ] ℝ` (usual notation `ω`). Morally, when `ω` is evaluated on two vectors, it gives the oriented area of the parallelogram they span. (But mathlib does not yet have a construction of oriented area, and in fact the construction of oriented area should pass through `ω`.) * `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᵢ[ℝ] E` (usual notation `J`). This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined, in such a way that this automorphism is equal to rotation by 90 degrees. * `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]` for `E`. * `Orientation.kahler`: a complex-valued real-bilinear map `E →ₗ[ℝ] E →ₗ[ℝ] ℂ`. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`, the complex number `o.kahler x y` has modulus `‖x‖ * ‖y‖`. In a later file, oriented angles (`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the oriented angle from `x` to `y`. ## Main results * `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x` * `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if and only if `0 ≤ ⟪x, y⟫` and `ω x y = 0` * `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y` * `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner product space `ℂ` * `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`, `Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `ℂ`, expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete interpretations on `ℂ` ## Implementation notes Notation `ω` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be defined locally in each file which uses them, since otherwise one would need a more cumbersome notation which mentions the orientation explicitly (something like `ω[o]`). Write ``` local notation "ω" => o.areaForm local notation "J" => o.rightAngleRotation ``` -/ noncomputable section open scoped RealInnerProductSpace ComplexConjugate open FiniteDimensional lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V := .of_fact_finrank_eq_succ 1 attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two @[deprecated (since := "2024-02-02")] alias FiniteDimensional.finiteDimensional_of_fact_finrank_eq_two := FiniteDimensional.of_fact_finrank_eq_two variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)] (o : Orientation ℝ E (Fin 2)) namespace Orientation /-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual notation `ω`). When evaluated on two vectors, it gives the oriented area of the parallelogram they span. -/ irreducible_def areaForm : E →ₗ[ℝ] E →ₗ[ℝ] ℝ := by let z : E [⋀^Fin 0]→ₗ[ℝ] ℝ ≃ₗ[ℝ] ℝ := AlternatingMap.constLinearEquivOfIsEmpty.symm let y : E [⋀^Fin 1]→ₗ[ℝ] ℝ →ₗ[ℝ] E →ₗ[ℝ] ℝ := LinearMap.llcomp ℝ E (E [⋀^Fin 0]→ₗ[ℝ] ℝ) ℝ z ∘ₗ AlternatingMap.curryLeftLinearMap exact y ∘ₗ AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm #align orientation.area_form Orientation.areaForm local notation "ω" => o.areaForm theorem areaForm_to_volumeForm (x y : E) : ω x y = o.volumeForm ![x, y] := by simp [areaForm] #align orientation.area_form_to_volume_form Orientation.areaForm_to_volumeForm @[simp] theorem areaForm_apply_self (x : E) : ω x x = 0 := by rw [areaForm_to_volumeForm] refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) ≠ 1) · simp · norm_num #align orientation.area_form_apply_self Orientation.areaForm_apply_self theorem areaForm_swap (x y : E) : ω x y = -ω y x := by simp only [areaForm_to_volumeForm] convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) ≠ 1) · ext i fin_cases i <;> rfl · norm_num #align orientation.area_form_swap Orientation.areaForm_swap @[simp] theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by ext x y simp [areaForm_to_volumeForm] #align orientation.area_form_neg_orientation Orientation.areaForm_neg_orientation /-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/ def areaForm' : E →L[ℝ] E →L[ℝ] ℝ := LinearMap.toContinuousLinearMap (↑(LinearMap.toContinuousLinearMap : (E →ₗ[ℝ] ℝ) ≃ₗ[ℝ] E →L[ℝ] ℝ) ∘ₗ o.areaForm) #align orientation.area_form' Orientation.areaForm' @[simp] theorem areaForm'_apply (x : E) : o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) := rfl #align orientation.area_form'_apply Orientation.areaForm'_apply theorem abs_areaForm_le (x y : E) : |ω x y| ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y] #align orientation.abs_area_form_le Orientation.abs_areaForm_le theorem areaForm_le (x y : E) : ω x y ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y] #align orientation.area_form_le Orientation.areaForm_le theorem abs_areaForm_of_orthogonal {x y : E} (h : ⟪x, y⟫ = 0) : |ω x y| = ‖x‖ * ‖y‖ := by rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal] · simp [Fin.prod_univ_succ] intro i j hij fin_cases i <;> fin_cases j · simp_all · simpa using h · simpa [real_inner_comm] using h · simp_all #align orientation.abs_area_form_of_orthogonal Orientation.abs_areaForm_of_orthogonal theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).areaForm x y = o.areaForm (φ.symm x) (φ.symm y) := by have : φ.symm ∘ ![x, y] = ![φ.symm x, φ.symm y] := by ext i fin_cases i <;> rfl simp [areaForm_to_volumeForm, volumeForm_map, this] #align orientation.area_form_map Orientation.areaForm_map /-- The area form is invariant under pullback by a positively-oriented isometric automorphism. -/ theorem areaForm_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) : o.areaForm (φ x) (φ y) = o.areaForm x y := by convert o.areaForm_map φ (φ x) (φ y) · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] · simp · simp #align orientation.area_form_comp_linear_isometry_equiv Orientation.areaForm_comp_linearIsometryEquiv /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ irreducible_def rightAngleRotationAux₁ : E →ₗ[ℝ] E := let to_dual : E ≃ₗ[ℝ] E →ₗ[ℝ] ℝ := (InnerProductSpace.toDual ℝ E).toLinearEquiv ≪≫ₗ LinearMap.toContinuousLinearMap.symm ↑to_dual.symm ∘ₗ ω #align orientation.right_angle_rotation_aux₁ Orientation.rightAngleRotationAux₁ @[simp] theorem inner_rightAngleRotationAux₁_left (x y : E) : ⟪o.rightAngleRotationAux₁ x, y⟫ = ω x y := by -- Porting note: split `simp only` for greater proof control simp only [rightAngleRotationAux₁, LinearEquiv.trans_symm, LinearIsometryEquiv.toLinearEquiv_symm, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply, LinearIsometryEquiv.coe_toLinearEquiv] rw [InnerProductSpace.toDual_symm_apply] norm_cast #align orientation.inner_right_angle_rotation_aux₁_left Orientation.inner_rightAngleRotationAux₁_left @[simp] theorem inner_rightAngleRotationAux₁_right (x y : E) : ⟪x, o.rightAngleRotationAux₁ y⟫ = -ω x y := by rw [real_inner_comm] simp [o.areaForm_swap y x] #align orientation.inner_right_angle_rotation_aux₁_right Orientation.inner_rightAngleRotationAux₁_right /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ def rightAngleRotationAux₂ : E →ₗᵢ[ℝ] E := { o.rightAngleRotationAux₁ with norm_map' := fun x => by dsimp refine le_antisymm ?_ ?_ · cases' eq_or_lt_of_le (norm_nonneg (o.rightAngleRotationAux₁ x)) with h h · rw [← h] positivity refine le_of_mul_le_mul_right ?_ h rw [← real_inner_self_eq_norm_mul_norm, o.inner_rightAngleRotationAux₁_left] exact o.areaForm_le x (o.rightAngleRotationAux₁ x) · let K : Submodule ℝ E := ℝ ∙ x have : Nontrivial Kᗮ := by apply @FiniteDimensional.nontrivial_of_finrank_pos ℝ have : finrank ℝ K ≤ Finset.card {x} := by rw [← Set.toFinset_singleton] exact finrank_span_le_card ({x} : Set E) have : Finset.card {x} = 1 := Finset.card_singleton x have : finrank ℝ K + finrank ℝ Kᗮ = finrank ℝ E := K.finrank_add_finrank_orthogonal have : finrank ℝ E = 2 := Fact.out linarith obtain ⟨w, hw₀⟩ : ∃ w : Kᗮ, w ≠ 0 := exists_ne 0 have hw' : ⟪x, (w : E)⟫ = 0 := Submodule.mem_orthogonal_singleton_iff_inner_right.mp w.2 have hw : (w : E) ≠ 0 := fun h => hw₀ (Submodule.coe_eq_zero.mp h) refine le_of_mul_le_mul_right ?_ (by rwa [norm_pos_iff] : 0 < ‖(w : E)‖) rw [← o.abs_areaForm_of_orthogonal hw'] rw [← o.inner_rightAngleRotationAux₁_left x w] exact abs_real_inner_le_norm (o.rightAngleRotationAux₁ x) w } #align orientation.right_angle_rotation_aux₂ Orientation.rightAngleRotationAux₂ @[simp] theorem rightAngleRotationAux₁_rightAngleRotationAux₁ (x : E) : o.rightAngleRotationAux₁ (o.rightAngleRotationAux₁ x) = -x := by apply ext_inner_left ℝ intro y have : ⟪o.rightAngleRotationAux₁ y, o.rightAngleRotationAux₁ x⟫ = ⟪y, x⟫ := LinearIsometry.inner_map_map o.rightAngleRotationAux₂ y x rw [o.inner_rightAngleRotationAux₁_right, ← o.inner_rightAngleRotationAux₁_left, this, inner_neg_right] #align orientation.right_angle_rotation_aux₁_right_angle_rotation_aux₁ Orientation.rightAngleRotationAux₁_rightAngleRotationAux₁ /-- An isometric automorphism of an oriented real inner product space of dimension 2 (usual notation `J`). This automorphism squares to -1. We will define rotations in such a way that this automorphism is equal to rotation by 90 degrees. -/ irreducible_def rightAngleRotation : E ≃ₗᵢ[ℝ] E := LinearIsometryEquiv.ofLinearIsometry o.rightAngleRotationAux₂ (-o.rightAngleRotationAux₁) (by ext; simp [rightAngleRotationAux₂]) (by ext; simp [rightAngleRotationAux₂]) #align orientation.right_angle_rotation Orientation.rightAngleRotation local notation "J" => o.rightAngleRotation @[simp] theorem inner_rightAngleRotation_left (x y : E) : ⟪J x, y⟫ = ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_left x y #align orientation.inner_right_angle_rotation_left Orientation.inner_rightAngleRotation_left @[simp] theorem inner_rightAngleRotation_right (x y : E) : ⟪x, J y⟫ = -ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_right x y #align orientation.inner_right_angle_rotation_right Orientation.inner_rightAngleRotation_right @[simp] theorem rightAngleRotation_rightAngleRotation (x : E) : J (J x) = -x := by rw [rightAngleRotation] exact o.rightAngleRotationAux₁_rightAngleRotationAux₁ x #align orientation.right_angle_rotation_right_angle_rotation Orientation.rightAngleRotation_rightAngleRotation @[simp] theorem rightAngleRotation_symm : LinearIsometryEquiv.symm J = LinearIsometryEquiv.trans J (LinearIsometryEquiv.neg ℝ) := by rw [rightAngleRotation] exact LinearIsometryEquiv.toLinearIsometry_injective rfl #align orientation.right_angle_rotation_symm Orientation.rightAngleRotation_symm -- @[simp] -- Porting note (#10618): simp already proves this theorem inner_rightAngleRotation_self (x : E) : ⟪J x, x⟫ = 0 := by simp #align orientation.inner_right_angle_rotation_self Orientation.inner_rightAngleRotation_self theorem inner_rightAngleRotation_swap (x y : E) : ⟪x, J y⟫ = -⟪J x, y⟫ := by simp #align orientation.inner_right_angle_rotation_swap Orientation.inner_rightAngleRotation_swap
Mathlib/Analysis/InnerProductSpace/TwoDim.lean
293
294
theorem inner_rightAngleRotation_swap' (x y : E) : ⟪J x, y⟫ = -⟪x, J y⟫ := by
simp [o.inner_rightAngleRotation_swap x y]
/- 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.MeasureSpace /-! # Restricting a measure to a subset or a subtype Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as the restriction of `μ` to `s` (still as a measure on `α`). We investigate how this notion interacts with usual operations on measures (sum, pushforward, pullback), and on sets (inclusion, union, Union). We also study the relationship between the restriction of a measure to a subtype (given by the pullback under `Subtype.val`) and the restriction to a set as above. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function variable {R α β δ γ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-! ### Restricting a measure -/ /-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/ noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α := liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc] exact le_toOuterMeasure_caratheodory _ _ hs' _ #align measure_theory.measure.restrictₗ MeasureTheory.Measure.restrictₗ /-- Restrict a measure `μ` to a set `s`. -/ noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α := restrictₗ s μ #align measure_theory.measure.restrict MeasureTheory.Measure.restrict @[simp] theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) : restrictₗ s μ = μ.restrict s := rfl #align measure_theory.measure.restrictₗ_apply MeasureTheory.Measure.restrictₗ_apply /-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a restrict on measures and the RHS has a restrict on outer measures. -/ theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) : (μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk, toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed] #align measure_theory.measure.restrict_to_outer_measure_eq_to_outer_measure_restrict MeasureTheory.Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply, coe_toOuterMeasure] #align measure_theory.measure.restrict_apply₀ MeasureTheory.Measure.restrict_apply₀ /-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s` be measurable instead of `t` exists as `Measure.restrict_apply'`. -/ @[simp] theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) := restrict_apply₀ ht.nullMeasurableSet #align measure_theory.measure.restrict_apply MeasureTheory.Measure.restrict_apply /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s') (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩) _ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s') _ = ν.restrict s' t := (restrict_apply ht).symm #align measure_theory.measure.restrict_mono' MeasureTheory.Measure.restrict_mono' /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ @[mono] theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := restrict_mono' (ae_of_all _ hs) hμν #align measure_theory.measure.restrict_mono MeasureTheory.Measure.restrict_mono theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t := restrict_mono' h (le_refl μ) #align measure_theory.measure.restrict_mono_ae MeasureTheory.Measure.restrict_mono_ae theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t := le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le) #align measure_theory.measure.restrict_congr_set MeasureTheory.Measure.restrict_congr_set /-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of `Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/ @[simp] theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by rw [← toOuterMeasure_apply, Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs, OuterMeasure.restrict_apply s t _, toOuterMeasure_apply] #align measure_theory.measure.restrict_apply' MeasureTheory.Measure.restrict_apply' theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by rw [← restrict_congr_set hs.toMeasurable_ae_eq, restrict_apply' (measurableSet_toMeasurable _ _), measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)] #align measure_theory.measure.restrict_apply₀' MeasureTheory.Measure.restrict_apply₀' theorem restrict_le_self : μ.restrict s ≤ μ := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ t := measure_mono inter_subset_left #align measure_theory.measure.restrict_le_self MeasureTheory.Measure.restrict_le_self variable (μ) theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s := (le_iff'.1 restrict_le_self s).antisymm <| calc μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) := measure_mono (subset_inter (subset_toMeasurable _ _) h) _ = μ.restrict t s := by rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable] #align measure_theory.measure.restrict_eq_self MeasureTheory.Measure.restrict_eq_self @[simp] theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s := restrict_eq_self μ Subset.rfl #align measure_theory.measure.restrict_apply_self MeasureTheory.Measure.restrict_apply_self variable {μ} theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by rw [restrict_apply MeasurableSet.univ, Set.univ_inter] #align measure_theory.measure.restrict_apply_univ MeasureTheory.Measure.restrict_apply_univ theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t := calc μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm _ ≤ μ.restrict s t := measure_mono inter_subset_left #align measure_theory.measure.le_restrict_apply MeasureTheory.Measure.le_restrict_apply theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t := Measure.le_iff'.1 restrict_le_self _ theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s := ((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm ((restrict_apply_self μ s).symm.trans_le <| measure_mono h) #align measure_theory.measure.restrict_apply_superset MeasureTheory.Measure.restrict_apply_superset @[simp] theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) : (μ + ν).restrict s = μ.restrict s + ν.restrict s := (restrictₗ s).map_add μ ν #align measure_theory.measure.restrict_add MeasureTheory.Measure.restrict_add @[simp] theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 := (restrictₗ s).map_zero #align measure_theory.measure.restrict_zero MeasureTheory.Measure.restrict_zero @[simp] theorem restrict_smul {_m0 : MeasurableSpace α} (c : ℝ≥0∞) (μ : Measure α) (s : Set α) : (c • μ).restrict s = c • μ.restrict s := (restrictₗ s).map_smul c μ #align measure_theory.measure.restrict_smul MeasureTheory.Measure.restrict_smul theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [Set.inter_assoc, restrict_apply hu, restrict_apply₀ (hu.nullMeasurableSet.inter hs)] #align measure_theory.measure.restrict_restrict₀ MeasureTheory.Measure.restrict_restrict₀ @[simp] theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀ hs.nullMeasurableSet #align measure_theory.measure.restrict_restrict MeasureTheory.Measure.restrict_restrict theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by ext1 u hu rw [restrict_apply hu, restrict_apply hu, restrict_eq_self] exact inter_subset_right.trans h #align measure_theory.measure.restrict_restrict_of_subset MeasureTheory.Measure.restrict_restrict_of_subset theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc] #align measure_theory.measure.restrict_restrict₀' MeasureTheory.Measure.restrict_restrict₀' theorem restrict_restrict' (ht : MeasurableSet t) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀' ht.nullMeasurableSet #align measure_theory.measure.restrict_restrict' MeasureTheory.Measure.restrict_restrict' theorem restrict_comm (hs : MeasurableSet s) : (μ.restrict t).restrict s = (μ.restrict s).restrict t := by rw [restrict_restrict hs, restrict_restrict' hs, inter_comm] #align measure_theory.measure.restrict_comm MeasureTheory.Measure.restrict_comm theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply ht] #align measure_theory.measure.restrict_apply_eq_zero MeasureTheory.Measure.restrict_apply_eq_zero theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 := nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _) #align measure_theory.measure.measure_inter_eq_zero_of_restrict MeasureTheory.Measure.measure_inter_eq_zero_of_restrict theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply' hs] #align measure_theory.measure.restrict_apply_eq_zero' MeasureTheory.Measure.restrict_apply_eq_zero' @[simp] theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by rw [← measure_univ_eq_zero, restrict_apply_univ] #align measure_theory.measure.restrict_eq_zero MeasureTheory.Measure.restrict_eq_zero /-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/ instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) := ⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩ theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 := restrict_eq_zero.2 h #align measure_theory.measure.restrict_zero_set MeasureTheory.Measure.restrict_zero_set @[simp] theorem restrict_empty : μ.restrict ∅ = 0 := restrict_zero_set measure_empty #align measure_theory.measure.restrict_empty MeasureTheory.Measure.restrict_empty @[simp] theorem restrict_univ : μ.restrict univ = μ := ext fun s hs => by simp [hs] #align measure_theory.measure.restrict_univ MeasureTheory.Measure.restrict_univ theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by ext1 u hu simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq] exact measure_inter_add_diff₀ (u ∩ s) ht #align measure_theory.measure.restrict_inter_add_diff₀ MeasureTheory.Measure.restrict_inter_add_diff₀ theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := restrict_inter_add_diff₀ s ht.nullMeasurableSet #align measure_theory.measure.restrict_inter_add_diff MeasureTheory.Measure.restrict_inter_add_diff theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ← restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm] #align measure_theory.measure.restrict_union_add_inter₀ MeasureTheory.Measure.restrict_union_add_inter₀ theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := restrict_union_add_inter₀ s ht.nullMeasurableSet #align measure_theory.measure.restrict_union_add_inter MeasureTheory.Measure.restrict_union_add_inter theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs #align measure_theory.measure.restrict_union_add_inter' MeasureTheory.Measure.restrict_union_add_inter' theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h] #align measure_theory.measure.restrict_union₀ MeasureTheory.Measure.restrict_union₀ theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := restrict_union₀ h.aedisjoint ht.nullMeasurableSet #align measure_theory.measure.restrict_union MeasureTheory.Measure.restrict_union theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by rw [union_comm, restrict_union h.symm hs, add_comm] #align measure_theory.measure.restrict_union' MeasureTheory.Measure.restrict_union' @[simp] theorem restrict_add_restrict_compl (hs : MeasurableSet s) : μ.restrict s + μ.restrict sᶜ = μ := by rw [← restrict_union (@disjoint_compl_right (Set α) _ _) hs.compl, union_compl_self, restrict_univ] #align measure_theory.measure.restrict_add_restrict_compl MeasureTheory.Measure.restrict_add_restrict_compl @[simp] theorem restrict_compl_add_restrict (hs : MeasurableSet s) : μ.restrict sᶜ + μ.restrict s = μ := by rw [add_comm, restrict_add_restrict_compl hs] #align measure_theory.measure.restrict_compl_add_restrict MeasureTheory.Measure.restrict_compl_add_restrict theorem restrict_union_le (s s' : Set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' := le_iff.2 fun t ht ↦ by simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s') #align measure_theory.measure.restrict_union_le MeasureTheory.Measure.restrict_union_le theorem restrict_iUnion_apply_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s)) (hm : ∀ i, NullMeasurableSet (s i) μ) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := by simp only [restrict_apply, ht, inter_iUnion] exact measure_iUnion₀ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right) fun i => ht.nullMeasurableSet.inter (hm i) #align measure_theory.measure.restrict_Union_apply_ae MeasureTheory.Measure.restrict_iUnion_apply_ae theorem restrict_iUnion_apply [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s)) (hm : ∀ i, MeasurableSet (s i)) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht #align measure_theory.measure.restrict_Union_apply MeasureTheory.Measure.restrict_iUnion_apply
Mathlib/MeasureTheory/Measure/Restrict.lean
318
322
theorem restrict_iUnion_apply_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t := by
simp only [restrict_apply ht, inter_iUnion] rw [measure_iUnion_eq_iSup] exacts [hd.mono_comp _ fun s₁ s₂ => inter_subset_inter_right _]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov, Neil Strickland, Aaron Anderson -/ import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Units #align_import algebra.divisibility.units from "leanprover-community/mathlib"@"e574b1a4e891376b0ef974b926da39e05da12a06" /-! # Divisibility and units ## Main definition * `IsRelPrime x y`: that `x` and `y` are relatively prime, defined to mean that the only common divisors of `x` and `y` are the units. -/ variable {α : Type*} namespace Units section Monoid variable [Monoid α] {a b : α} {u : αˣ} /-- Elements of the unit group of a monoid represented as elements of the monoid divide any element of the monoid. -/ theorem coe_dvd : ↑u ∣ a := ⟨↑u⁻¹ * a, by simp⟩ #align units.coe_dvd Units.coe_dvd /-- In a monoid, an element `a` divides an element `b` iff `a` divides all associates of `b`. -/ theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b := Iff.intro (fun ⟨c, Eq⟩ ↦ ⟨c * ↑u⁻¹, by rw [← mul_assoc, ← Eq, Units.mul_inv_cancel_right]⟩) fun ⟨c, Eq⟩ ↦ Eq.symm ▸ (_root_.dvd_mul_right _ _).mul_right _ #align units.dvd_mul_right Units.dvd_mul_right /-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/ theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b := Iff.intro (fun ⟨c, Eq⟩ => ⟨↑u * c, Eq.trans (mul_assoc _ _ _)⟩) fun h => dvd_trans (Dvd.intro (↑u⁻¹) (by rw [mul_assoc, u.mul_inv, mul_one])) h #align units.mul_right_dvd Units.mul_right_dvd end Monoid section CommMonoid variable [CommMonoid α] {a b : α} {u : αˣ} /-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left associates of `b`. -/ theorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by rw [mul_comm] apply dvd_mul_right #align units.dvd_mul_left Units.dvd_mul_left /-- In a commutative monoid, an element `a` divides an element `b` iff all left associates of `a` divide `b`. -/ theorem mul_left_dvd : ↑u * a ∣ b ↔ a ∣ b := by rw [mul_comm] apply mul_right_dvd #align units.mul_left_dvd Units.mul_left_dvd end CommMonoid end Units namespace IsUnit section Monoid variable [Monoid α] {a b u : α} (hu : IsUnit u) /-- Units of a monoid divide any element of the monoid. -/ @[simp] theorem dvd : u ∣ a := by rcases hu with ⟨u, rfl⟩ apply Units.coe_dvd #align is_unit.dvd IsUnit.dvd @[simp] theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.dvd_mul_right #align is_unit.dvd_mul_right IsUnit.dvd_mul_right /-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`. -/ @[simp] theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.mul_right_dvd #align is_unit.mul_right_dvd IsUnit.mul_right_dvd theorem isPrimal : IsPrimal u := fun _ _ _ ↦ ⟨u, 1, hu.dvd, one_dvd _, (mul_one u).symm⟩ end Monoid section CommMonoid variable [CommMonoid α] {a b u : α} (hu : IsUnit u) /-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left associates of `b`. -/ @[simp] theorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.dvd_mul_left #align is_unit.dvd_mul_left IsUnit.dvd_mul_left /-- In a commutative monoid, an element `a` divides an element `b` iff all left associates of `a` divide `b`. -/ @[simp] theorem mul_left_dvd : u * a ∣ b ↔ a ∣ b := by rcases hu with ⟨u, rfl⟩ apply Units.mul_left_dvd #align is_unit.mul_left_dvd IsUnit.mul_left_dvd end CommMonoid end IsUnit section CommMonoid variable [CommMonoid α] theorem isUnit_iff_dvd_one {x : α} : IsUnit x ↔ x ∣ 1 := ⟨IsUnit.dvd, fun ⟨y, h⟩ => ⟨⟨x, y, h.symm, by rw [h, mul_comm]⟩, rfl⟩⟩ #align is_unit_iff_dvd_one isUnit_iff_dvd_one theorem isUnit_iff_forall_dvd {x : α} : IsUnit x ↔ ∀ y, x ∣ y := isUnit_iff_dvd_one.trans ⟨fun h _ => h.trans (one_dvd _), fun h => h _⟩ #align is_unit_iff_forall_dvd isUnit_iff_forall_dvd theorem isUnit_of_dvd_unit {x y : α} (xy : x ∣ y) (hu : IsUnit y) : IsUnit x := isUnit_iff_dvd_one.2 <| xy.trans <| isUnit_iff_dvd_one.1 hu #align is_unit_of_dvd_unit isUnit_of_dvd_unit theorem isUnit_of_dvd_one {a : α} (h : a ∣ 1) : IsUnit (a : α) := isUnit_iff_dvd_one.mpr h #align is_unit_of_dvd_one isUnit_of_dvd_one theorem not_isUnit_of_not_isUnit_dvd {a b : α} (ha : ¬IsUnit a) (hb : a ∣ b) : ¬IsUnit b := mt (isUnit_of_dvd_unit hb) ha #align not_is_unit_of_not_is_unit_dvd not_isUnit_of_not_isUnit_dvd end CommMonoid section RelPrime /-- `x` and `y` are relatively prime if every common divisor is a unit. -/ def IsRelPrime [Monoid α] (x y : α) : Prop := ∀ ⦃d⦄, d ∣ x → d ∣ y → IsUnit d variable [CommMonoid α] {x y z : α} @[symm] theorem IsRelPrime.symm (H : IsRelPrime x y) : IsRelPrime y x := fun _ hx hy ↦ H hy hx theorem isRelPrime_comm : IsRelPrime x y ↔ IsRelPrime y x := ⟨IsRelPrime.symm, IsRelPrime.symm⟩ theorem isRelPrime_self : IsRelPrime x x ↔ IsUnit x := ⟨(· dvd_rfl dvd_rfl), fun hu _ _ dvd ↦ isUnit_of_dvd_unit dvd hu⟩ theorem IsUnit.isRelPrime_left (h : IsUnit x) : IsRelPrime x y := fun _ hx _ ↦ isUnit_of_dvd_unit hx h theorem IsUnit.isRelPrime_right (h : IsUnit y) : IsRelPrime x y := h.isRelPrime_left.symm theorem isRelPrime_one_left : IsRelPrime 1 x := isUnit_one.isRelPrime_left theorem isRelPrime_one_right : IsRelPrime x 1 := isUnit_one.isRelPrime_right theorem IsRelPrime.of_mul_left_left (H : IsRelPrime (x * y) z) : IsRelPrime x z := fun _ hx ↦ H (dvd_mul_of_dvd_left hx _) theorem IsRelPrime.of_mul_left_right (H : IsRelPrime (x * y) z) : IsRelPrime y z := (mul_comm x y ▸ H).of_mul_left_left theorem IsRelPrime.of_mul_right_left (H : IsRelPrime x (y * z)) : IsRelPrime x y := by rw [isRelPrime_comm] at H ⊢ exact H.of_mul_left_left theorem IsRelPrime.of_mul_right_right (H : IsRelPrime x (y * z)) : IsRelPrime x z := (mul_comm y z ▸ H).of_mul_right_left theorem IsRelPrime.of_dvd_left (h : IsRelPrime y z) (dvd : x ∣ y) : IsRelPrime x z := by obtain ⟨d, rfl⟩ := dvd; exact IsRelPrime.of_mul_left_left h theorem IsRelPrime.of_dvd_right (h : IsRelPrime z y) (dvd : x ∣ y) : IsRelPrime z x := (h.symm.of_dvd_left dvd).symm theorem IsRelPrime.isUnit_of_dvd (H : IsRelPrime x y) (d : x ∣ y) : IsUnit x := H dvd_rfl d section IsUnit variable (hu : IsUnit x) theorem isRelPrime_mul_unit_left_left : IsRelPrime (x * y) z ↔ IsRelPrime y z := ⟨IsRelPrime.of_mul_left_right, fun H _ h ↦ H (hu.dvd_mul_left.mp h)⟩ theorem isRelPrime_mul_unit_left_right : IsRelPrime y (x * z) ↔ IsRelPrime y z := by rw [isRelPrime_comm, isRelPrime_mul_unit_left_left hu, isRelPrime_comm] theorem isRelPrime_mul_unit_left : IsRelPrime (x * y) (x * z) ↔ IsRelPrime y z := by rw [isRelPrime_mul_unit_left_left hu, isRelPrime_mul_unit_left_right hu] theorem isRelPrime_mul_unit_right_left : IsRelPrime (y * x) z ↔ IsRelPrime y z := by rw [mul_comm, isRelPrime_mul_unit_left_left hu] theorem isRelPrime_mul_unit_right_right : IsRelPrime y (z * x) ↔ IsRelPrime y z := by rw [mul_comm, isRelPrime_mul_unit_left_right hu]
Mathlib/Algebra/Divisibility/Units.lean
214
215
theorem isRelPrime_mul_unit_right : IsRelPrime (y * x) (z * x) ↔ IsRelPrime y z := by
rw [isRelPrime_mul_unit_right_left hu, isRelPrime_mul_unit_right_right hu]
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Floris van Doorn, Gabriel Ebner, Yury Kudryashov -/ import Mathlib.Order.ConditionallyCompleteLattice.Finset import Mathlib.Order.Interval.Finset.Nat #align_import data.nat.lattice from "leanprover-community/mathlib"@"52fa514ec337dd970d71d8de8d0fd68b455a1e54" /-! # Conditionally complete linear order structure on `ℕ` In this file we * define a `ConditionallyCompleteLinearOrderBot` structure on `ℕ`; * prove a few lemmas about `iSup`/`iInf`/`Set.iUnion`/`Set.iInter` and natural numbers. -/ assert_not_exists MonoidWithZero open Set namespace Nat open scoped Classical noncomputable instance : InfSet ℕ := ⟨fun s ↦ if h : ∃ n, n ∈ s then @Nat.find (fun n ↦ n ∈ s) _ h else 0⟩ noncomputable instance : SupSet ℕ := ⟨fun s ↦ if h : ∃ n, ∀ a ∈ s, a ≤ n then @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h else 0⟩ theorem sInf_def {s : Set ℕ} (h : s.Nonempty) : sInf s = @Nat.find (fun n ↦ n ∈ s) _ h := dif_pos _ #align nat.Inf_def Nat.sInf_def theorem sSup_def {s : Set ℕ} (h : ∃ n, ∀ a ∈ s, a ≤ n) : sSup s = @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h := dif_pos _ #align nat.Sup_def Nat.sSup_def theorem _root_.Set.Infinite.Nat.sSup_eq_zero {s : Set ℕ} (h : s.Infinite) : sSup s = 0 := dif_neg fun ⟨n, hn⟩ ↦ let ⟨k, hks, hk⟩ := h.exists_gt n (hn k hks).not_lt hk #align set.infinite.nat.Sup_eq_zero Set.Infinite.Nat.sSup_eq_zero @[simp] theorem sInf_eq_zero {s : Set ℕ} : sInf s = 0 ↔ 0 ∈ s ∨ s = ∅ := by cases eq_empty_or_nonempty s with | inl h => subst h simp only [or_true_iff, eq_self_iff_true, iff_true_iff, iInf, InfSet.sInf, mem_empty_iff_false, exists_false, dif_neg, not_false_iff] | inr h => simp only [h.ne_empty, or_false_iff, Nat.sInf_def, h, Nat.find_eq_zero] #align nat.Inf_eq_zero Nat.sInf_eq_zero @[simp] theorem sInf_empty : sInf ∅ = 0 := by rw [sInf_eq_zero] right rfl #align nat.Inf_empty Nat.sInf_empty @[simp] theorem iInf_of_empty {ι : Sort*} [IsEmpty ι] (f : ι → ℕ) : iInf f = 0 := by rw [iInf_of_isEmpty, sInf_empty] #align nat.infi_of_empty Nat.iInf_of_empty /-- This combines `Nat.iInf_of_empty` with `ciInf_const`. -/ @[simp] lemma iInf_const_zero {ι : Sort*} : ⨅ i : ι, 0 = 0 := (isEmpty_or_nonempty ι).elim (fun h ↦ by simp) fun h ↦ sInf_eq_zero.2 <| by simp theorem sInf_mem {s : Set ℕ} (h : s.Nonempty) : sInf s ∈ s := by rw [Nat.sInf_def h] exact Nat.find_spec h #align nat.Inf_mem Nat.sInf_mem theorem not_mem_of_lt_sInf {s : Set ℕ} {m : ℕ} (hm : m < sInf s) : m ∉ s := by cases eq_empty_or_nonempty s with | inl h => subst h; apply not_mem_empty | inr h => rw [Nat.sInf_def h] at hm; exact Nat.find_min h hm #align nat.not_mem_of_lt_Inf Nat.not_mem_of_lt_sInf protected theorem sInf_le {s : Set ℕ} {m : ℕ} (hm : m ∈ s) : sInf s ≤ m := by rw [Nat.sInf_def ⟨m, hm⟩] exact Nat.find_min' ⟨m, hm⟩ hm #align nat.Inf_le Nat.sInf_le theorem nonempty_of_pos_sInf {s : Set ℕ} (h : 0 < sInf s) : s.Nonempty := by by_contra contra rw [Set.not_nonempty_iff_eq_empty] at contra have h' : sInf s ≠ 0 := ne_of_gt h apply h' rw [Nat.sInf_eq_zero] right assumption #align nat.nonempty_of_pos_Inf Nat.nonempty_of_pos_sInf theorem nonempty_of_sInf_eq_succ {s : Set ℕ} {k : ℕ} (h : sInf s = k + 1) : s.Nonempty := nonempty_of_pos_sInf (h.symm ▸ succ_pos k : sInf s > 0) #align nat.nonempty_of_Inf_eq_succ Nat.nonempty_of_sInf_eq_succ theorem eq_Ici_of_nonempty_of_upward_closed {s : Set ℕ} (hs : s.Nonempty) (hs' : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s) : s = Ici (sInf s) := ext fun n ↦ ⟨fun H ↦ Nat.sInf_le H, fun H ↦ hs' (sInf s) n H (sInf_mem hs)⟩ #align nat.eq_Ici_of_nonempty_of_upward_closed Nat.eq_Ici_of_nonempty_of_upward_closed theorem sInf_upward_closed_eq_succ_iff {s : Set ℕ} (hs : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s) (k : ℕ) : sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s := by constructor · intro H rw [eq_Ici_of_nonempty_of_upward_closed (nonempty_of_sInf_eq_succ _) hs, H, mem_Ici, mem_Ici] · exact ⟨le_rfl, k.not_succ_le_self⟩; · exact k · assumption · rintro ⟨H, H'⟩ rw [sInf_def (⟨_, H⟩ : s.Nonempty), find_eq_iff] exact ⟨H, fun n hnk hns ↦ H' <| hs n k (Nat.lt_succ_iff.mp hnk) hns⟩ #align nat.Inf_upward_closed_eq_succ_iff Nat.sInf_upward_closed_eq_succ_iff /-- This instance is necessary, otherwise the lattice operations would be derived via `ConditionallyCompleteLinearOrderBot` and marked as noncomputable. -/ instance : Lattice ℕ := LinearOrder.toLattice noncomputable instance : ConditionallyCompleteLinearOrderBot ℕ := { (inferInstance : OrderBot ℕ), (LinearOrder.toLattice : Lattice ℕ), (inferInstance : LinearOrder ℕ) with -- sup := sSup -- Porting note: removed, unnecessary? -- inf := sInf -- Porting note: removed, unnecessary? le_csSup := fun s a hb ha ↦ by rw [sSup_def hb]; revert a ha; exact @Nat.find_spec _ _ hb csSup_le := fun s a _ ha ↦ by rw [sSup_def ⟨a, ha⟩]; exact Nat.find_min' _ ha le_csInf := fun s a hs hb ↦ by rw [sInf_def hs]; exact hb (@Nat.find_spec (fun n ↦ n ∈ s) _ _) csInf_le := fun s a _ ha ↦ by rw [sInf_def ⟨a, ha⟩]; exact Nat.find_min' _ ha csSup_empty := by simp only [sSup_def, Set.mem_empty_iff_false, forall_const, forall_prop_of_false, not_false_iff, exists_const] apply bot_unique (Nat.find_min' _ _) trivial csSup_of_not_bddAbove := by intro s hs simp only [mem_univ, forall_true_left, sSup, mem_empty_iff_false, IsEmpty.forall_iff, forall_const, exists_const, dite_true] rw [dif_neg] · exact le_antisymm (zero_le _) (find_le trivial) · exact hs csInf_of_not_bddBelow := fun s hs ↦ by simp at hs } theorem sSup_mem {s : Set ℕ} (h₁ : s.Nonempty) (h₂ : BddAbove s) : sSup s ∈ s := let ⟨k, hk⟩ := h₂ h₁.csSup_mem ((finite_le_nat k).subset hk) #align nat.Sup_mem Nat.sSup_mem theorem sInf_add {n : ℕ} {p : ℕ → Prop} (hn : n ≤ sInf { m | p m }) : sInf { m | p (m + n) } + n = sInf { m | p m } := by obtain h | ⟨m, hm⟩ := { m | p (m + n) }.eq_empty_or_nonempty · rw [h, Nat.sInf_empty, zero_add] obtain hnp | hnp := hn.eq_or_lt · exact hnp suffices hp : p (sInf { m | p m } - n + n) from (h.subset hp).elim rw [Nat.sub_add_cancel hn] exact csInf_mem (nonempty_of_pos_sInf <| n.zero_le.trans_lt hnp) · have hp : ∃ n, n ∈ { m | p m } := ⟨_, hm⟩ rw [Nat.sInf_def ⟨m, hm⟩, Nat.sInf_def hp] rw [Nat.sInf_def hp] at hn exact find_add hn #align nat.Inf_add Nat.sInf_add theorem sInf_add' {n : ℕ} {p : ℕ → Prop} (h : 0 < sInf { m | p m }) : sInf { m | p m } + n = sInf { m | p (m - n) } := by suffices h₁ : n ≤ sInf {m | p (m - n)} by convert sInf_add h₁ simp_rw [Nat.add_sub_cancel_right] obtain ⟨m, hm⟩ := nonempty_of_pos_sInf h refine le_csInf ⟨m + n, ?_⟩ fun b hb ↦ le_of_not_lt fun hbn ↦ ne_of_mem_of_not_mem ?_ (not_mem_of_lt_sInf h) (Nat.sub_eq_zero_of_le hbn.le) · dsimp rwa [Nat.add_sub_cancel_right] · exact hb #align nat.Inf_add' Nat.sInf_add' section variable {α : Type*} [CompleteLattice α] theorem iSup_lt_succ (u : ℕ → α) (n : ℕ) : ⨆ k < n + 1, u k = (⨆ k < n, u k) ⊔ u n := by simp [Nat.lt_succ_iff_lt_or_eq, iSup_or, iSup_sup_eq] #align nat.supr_lt_succ Nat.iSup_lt_succ
Mathlib/Data/Nat/Lattice.lean
195
197
theorem iSup_lt_succ' (u : ℕ → α) (n : ℕ) : ⨆ k < n + 1, u k = u 0 ⊔ ⨆ k < n, u (k + 1) := by
rw [← sup_iSup_nat_succ] simp
/- 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.GroupWithZero.Divisibility import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.Data.Finset.Sort #align_import data.polynomial.basic from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Theory of univariate polynomials This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds a semiring structure on it, and gives basic definitions that are expanded in other files in this directory. ## Main definitions * `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map. * `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism. * `X` is the polynomial `X`, i.e., `monomial 1 1`. * `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied to coefficients of the polynomial `p`. * `p.erase n` is the polynomial `p` in which one removes the `c X^n` term. There are often two natural variants of lemmas involving sums, depending on whether one acts on the polynomials, or on the function. The naming convention is that one adds `index` when acting on the polynomials. For instance, * `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`; * `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`. * Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`. ## Implementation Polynomials are defined using `R[ℕ]`, where `R` is a semiring. The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity `X * p = p * X`. The relationship to `R[ℕ]` is through a structure to make polynomials irreducible from the point of view of the kernel. Most operations are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two exceptions that we make semireducible: * The zero polynomial, so that its coefficients are definitionally equal to `0`. * The scalar action, to permit typeclass search to unfold it to resolve potential instance diamonds. The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should in general not be used once the basic API for polynomials is constructed. -/ set_option linter.uppercaseLean3 false noncomputable section /-- `Polynomial R` is the type of univariate polynomials over `R`. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from `R` is called `C`. -/ structure Polynomial (R : Type*) [Semiring R] where ofFinsupp :: toFinsupp : AddMonoidAlgebra R ℕ #align polynomial Polynomial #align polynomial.of_finsupp Polynomial.ofFinsupp #align polynomial.to_finsupp Polynomial.toFinsupp @[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R open AddMonoidAlgebra open Finsupp hiding single open Function hiding Commute open Polynomial namespace Polynomial universe u variable {R : Type u} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q : R[X]} theorem forall_iff_forall_finsupp (P : R[X] → Prop) : (∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ := ⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩ #align polynomial.forall_iff_forall_finsupp Polynomial.forall_iff_forall_finsupp theorem exists_iff_exists_finsupp (P : R[X] → Prop) : (∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ := ⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩ #align polynomial.exists_iff_exists_finsupp Polynomial.exists_iff_exists_finsupp @[simp] theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl #align polynomial.eta Polynomial.eta /-! ### Conversions to and from `AddMonoidAlgebra` Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping it, we have to copy across all the arithmetic operators manually, along with the lemmas about how they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`. -/ section AddMonoidAlgebra private irreducible_def add : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a + b⟩ private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X] | ⟨a⟩ => ⟨-a⟩ private irreducible_def mul : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a * b⟩ instance zero : Zero R[X] := ⟨⟨0⟩⟩ #align polynomial.has_zero Polynomial.zero instance one : One R[X] := ⟨⟨1⟩⟩ #align polynomial.one Polynomial.one instance add' : Add R[X] := ⟨add⟩ #align polynomial.has_add Polynomial.add' instance neg' {R : Type u} [Ring R] : Neg R[X] := ⟨neg⟩ #align polynomial.has_neg Polynomial.neg' instance sub {R : Type u} [Ring R] : Sub R[X] := ⟨fun a b => a + -b⟩ #align polynomial.has_sub Polynomial.sub instance mul' : Mul R[X] := ⟨mul⟩ #align polynomial.has_mul Polynomial.mul' -- If the private definitions are accidentally exposed, simplify them away. @[simp] theorem add_eq_add : add p q = p + q := rfl @[simp] theorem mul_eq_mul : mul p q = p * q := rfl instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where smul r p := ⟨r • p.toFinsupp⟩ smul_zero a := congr_arg ofFinsupp (smul_zero a) #align polynomial.smul_zero_class Polynomial.smulZeroClass -- to avoid a bug in the `ring` tactic instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p #align polynomial.has_pow Polynomial.pow @[simp] theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 := rfl #align polynomial.of_finsupp_zero Polynomial.ofFinsupp_zero @[simp] theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 := rfl #align polynomial.of_finsupp_one Polynomial.ofFinsupp_one @[simp] theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ := show _ = add _ _ by rw [add_def] #align polynomial.of_finsupp_add Polynomial.ofFinsupp_add @[simp] theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ := show _ = neg _ by rw [neg_def] #align polynomial.of_finsupp_neg Polynomial.ofFinsupp_neg @[simp] theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg] rfl #align polynomial.of_finsupp_sub Polynomial.ofFinsupp_sub @[simp] theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ := show _ = mul _ _ by rw [mul_def] #align polynomial.of_finsupp_mul Polynomial.ofFinsupp_mul @[simp] theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) : (⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) := rfl #align polynomial.of_finsupp_smul Polynomial.ofFinsupp_smul @[simp] theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by change _ = npowRec n _ induction n with | zero => simp [npowRec] | succ n n_ih => simp [npowRec, n_ih, pow_succ] #align polynomial.of_finsupp_pow Polynomial.ofFinsupp_pow @[simp] theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 := rfl #align polynomial.to_finsupp_zero Polynomial.toFinsupp_zero @[simp] theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 := rfl #align polynomial.to_finsupp_one Polynomial.toFinsupp_one @[simp] theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by cases a cases b rw [← ofFinsupp_add] #align polynomial.to_finsupp_add Polynomial.toFinsupp_add @[simp] theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by cases a rw [← ofFinsupp_neg] #align polynomial.to_finsupp_neg Polynomial.toFinsupp_neg @[simp] theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) : (a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add] rfl #align polynomial.to_finsupp_sub Polynomial.toFinsupp_sub @[simp] theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by cases a cases b rw [← ofFinsupp_mul] #align polynomial.to_finsupp_mul Polynomial.toFinsupp_mul @[simp] theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) : (a • b).toFinsupp = a • b.toFinsupp := rfl #align polynomial.to_finsupp_smul Polynomial.toFinsupp_smul @[simp] theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by cases a rw [← ofFinsupp_pow] #align polynomial.to_finsupp_pow Polynomial.toFinsupp_pow theorem _root_.IsSMulRegular.polynomial {S : Type*} [Monoid S] [DistribMulAction S R] {a : S} (ha : IsSMulRegular R a) : IsSMulRegular R[X] a | ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h) #align is_smul_regular.polynomial IsSMulRegular.polynomial theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) := fun ⟨_x⟩ ⟨_y⟩ => congr_arg _ #align polynomial.to_finsupp_injective Polynomial.toFinsupp_injective @[simp] theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b := toFinsupp_injective.eq_iff #align polynomial.to_finsupp_inj Polynomial.toFinsupp_inj @[simp] theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by rw [← toFinsupp_zero, toFinsupp_inj] #align polynomial.to_finsupp_eq_zero Polynomial.toFinsupp_eq_zero @[simp] theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by rw [← toFinsupp_one, toFinsupp_inj] #align polynomial.to_finsupp_eq_one Polynomial.toFinsupp_eq_one /-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/ theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b := iff_of_eq (ofFinsupp.injEq _ _) #align polynomial.of_finsupp_inj Polynomial.ofFinsupp_inj @[simp] theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by rw [← ofFinsupp_zero, ofFinsupp_inj] #align polynomial.of_finsupp_eq_zero Polynomial.ofFinsupp_eq_zero @[simp] theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj] #align polynomial.of_finsupp_eq_one Polynomial.ofFinsupp_eq_one instance inhabited : Inhabited R[X] := ⟨0⟩ #align polynomial.inhabited Polynomial.inhabited instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n #align polynomial.has_nat_cast Polynomial.instNatCast instance semiring : Semiring R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.semiring toFinsupp toFinsupp_injective toFinsupp_zero toFinsupp_one toFinsupp_add toFinsupp_mul (fun _ _ => toFinsupp_smul _ _) toFinsupp_pow fun _ => rfl with toAdd := Polynomial.add' toMul := Polynomial.mul' toZero := Polynomial.zero toOne := Polynomial.one nsmul := (· • ·) npow := fun n x => (x ^ n) } #align polynomial.semiring Polynomial.semiring instance distribSMul {S} [DistribSMul S R] : DistribSMul S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toSMulZeroClass := Polynomial.smulZeroClass } #align polynomial.distrib_smul Polynomial.distribSMul instance distribMulAction {S} [Monoid S] [DistribMulAction S R] : DistribMulAction S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.distribMulAction ⟨⟨toFinsupp, toFinsupp_zero (R := R)⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toSMul := Polynomial.smulZeroClass.toSMul } #align polynomial.distrib_mul_action Polynomial.distribMulAction instance faithfulSMul {S} [SMulZeroClass S R] [FaithfulSMul S R] : FaithfulSMul S R[X] where eq_of_smul_eq_smul {_s₁ _s₂} h := eq_of_smul_eq_smul fun a : ℕ →₀ R => congr_arg toFinsupp (h ⟨a⟩) #align polynomial.has_faithful_smul Polynomial.faithfulSMul instance module {S} [Semiring S] [Module S R] : Module S R[X] := --TODO: add reference to library note in PR #7432 { Function.Injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul with toDistribMulAction := Polynomial.distribMulAction } #align polynomial.module Polynomial.module instance smulCommClass {S₁ S₂} [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [SMulCommClass S₁ S₂ R] : SMulCommClass S₁ S₂ R[X] := ⟨by rintro m n ⟨f⟩ simp_rw [← ofFinsupp_smul, smul_comm m n f]⟩ #align polynomial.smul_comm_class Polynomial.smulCommClass instance isScalarTower {S₁ S₂} [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ R[X] := ⟨by rintro _ _ ⟨⟩ simp_rw [← ofFinsupp_smul, smul_assoc]⟩ #align polynomial.is_scalar_tower Polynomial.isScalarTower instance isScalarTower_right {α K : Type*} [Semiring K] [DistribSMul α K] [IsScalarTower α K K] : IsScalarTower α K[X] K[X] := ⟨by rintro _ ⟨⟩ ⟨⟩; simp_rw [smul_eq_mul, ← ofFinsupp_smul, ← ofFinsupp_mul, ← ofFinsupp_smul, smul_mul_assoc]⟩ #align polynomial.is_scalar_tower_right Polynomial.isScalarTower_right instance isCentralScalar {S} [SMulZeroClass S R] [SMulZeroClass Sᵐᵒᵖ R] [IsCentralScalar S R] : IsCentralScalar S R[X] := ⟨by rintro _ ⟨⟩ simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩ #align polynomial.is_central_scalar Polynomial.isCentralScalar instance unique [Subsingleton R] : Unique R[X] := { Polynomial.inhabited with uniq := by rintro ⟨x⟩ apply congr_arg ofFinsupp simp [eq_iff_true_of_subsingleton] } #align polynomial.unique Polynomial.unique variable (R) /-- Ring isomorphism between `R[X]` and `R[ℕ]`. This is just an implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/ @[simps apply symm_apply] def toFinsuppIso : R[X] ≃+* R[ℕ] where toFun := toFinsupp invFun := ofFinsupp left_inv := fun ⟨_p⟩ => rfl right_inv _p := rfl map_mul' := toFinsupp_mul map_add' := toFinsupp_add #align polynomial.to_finsupp_iso Polynomial.toFinsuppIso #align polynomial.to_finsupp_iso_apply Polynomial.toFinsuppIso_apply #align polynomial.to_finsupp_iso_symm_apply Polynomial.toFinsuppIso_symm_apply instance [DecidableEq R] : DecidableEq R[X] := @Equiv.decidableEq R[X] _ (toFinsuppIso R).toEquiv (Finsupp.instDecidableEq) end AddMonoidAlgebra theorem ofFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[ℕ]) : (⟨∑ i ∈ s, f i⟩ : R[X]) = ∑ i ∈ s, ⟨f i⟩ := map_sum (toFinsuppIso R).symm f s #align polynomial.of_finsupp_sum Polynomial.ofFinsupp_sum theorem toFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[X]) : (∑ i ∈ s, f i : R[X]).toFinsupp = ∑ i ∈ s, (f i).toFinsupp := map_sum (toFinsuppIso R) f s #align polynomial.to_finsupp_sum Polynomial.toFinsupp_sum /-- The set of all `n` such that `X^n` has a non-zero coefficient. -/ -- @[simp] -- Porting note: The original generated theorem is same to `support_ofFinsupp` and -- the new generated theorem is different, so this attribute should be -- removed. def support : R[X] → Finset ℕ | ⟨p⟩ => p.support #align polynomial.support Polynomial.support @[simp]
Mathlib/Algebra/Polynomial/Basic.lean
411
411
theorem support_ofFinsupp (p) : support (⟨p⟩ : R[X]) = p.support := by
rw [support]
/- Copyright (c) 2021 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Combinatorics.SetFamily.Shadow #align_import combinatorics.set_family.compression.uv from "leanprover-community/mathlib"@"6f8ab7de1c4b78a68ab8cf7dd83d549eb78a68a1" /-! # UV-compressions This file defines UV-compression. It is an operation on a set family that reduces its shadow. UV-compressing `a : α` along `u v : α` means replacing `a` by `(a ⊔ u) \ v` if `a` and `u` are disjoint and `v ≤ a`. In some sense, it's moving `a` from `v` to `u`. UV-compressions are immensely useful to prove the Kruskal-Katona theorem. The idea is that compressing a set family might decrease the size of its shadow, so iterated compressions hopefully minimise the shadow. ## Main declarations * `UV.compress`: `compress u v a` is `a` compressed along `u` and `v`. * `UV.compression`: `compression u v s` is the compression of the set family `s` along `u` and `v`. It is the compressions of the elements of `s` whose compression is not already in `s` along with the element whose compression is already in `s`. This way of splitting into what moves and what does not ensures the compression doesn't squash the set family, which is proved by `UV.card_compression`. * `UV.card_shadow_compression_le`: Compressing reduces the size of the shadow. This is a key fact in the proof of Kruskal-Katona. ## Notation `𝓒` (typed with `\MCC`) is notation for `UV.compression` in locale `FinsetFamily`. ## Notes Even though our emphasis is on `Finset α`, we define UV-compressions more generally in a generalized boolean algebra, so that one can use it for `Set α`. ## References * https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf ## Tags compression, UV-compression, shadow -/ open Finset variable {α : Type*} /-- UV-compression is injective on the elements it moves. See `UV.compress`. -/
Mathlib/Combinatorics/SetFamily/Compression/UV.lean
57
64
theorem sup_sdiff_injOn [GeneralizedBooleanAlgebra α] (u v : α) : { x | Disjoint u x ∧ v ≤ x }.InjOn fun x => (x ⊔ u) \ v := by
rintro a ha b hb hab have h : ((a ⊔ u) \ v) \ u ⊔ v = ((b ⊔ u) \ v) \ u ⊔ v := by dsimp at hab rw [hab] rwa [sdiff_sdiff_comm, ha.1.symm.sup_sdiff_cancel_right, sdiff_sdiff_comm, hb.1.symm.sup_sdiff_cancel_right, sdiff_sup_cancel ha.2, sdiff_sup_cancel hb.2] at h
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Order.Ring.Int import Mathlib.Data.Nat.SuccPred #align_import data.int.succ_pred from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Successors and predecessors of integers In this file, we show that `ℤ` is both an archimedean `SuccOrder` and an archimedean `PredOrder`. -/ open Function Order namespace Int -- so that Lean reads `Int.succ` through `SuccOrder.succ` @[instance] abbrev instSuccOrder : SuccOrder ℤ := { SuccOrder.ofSuccLeIff succ fun {_ _} => Iff.rfl with succ := succ } -- so that Lean reads `Int.pred` through `PredOrder.pred` @[instance] abbrev instPredOrder : PredOrder ℤ where pred := pred pred_le _ := (sub_one_lt_of_le le_rfl).le min_of_le_pred ha := ((sub_one_lt_of_le le_rfl).not_le ha).elim le_pred_of_lt {_ _} := le_sub_one_of_lt le_of_pred_lt {_ _} := le_of_sub_one_lt @[simp] theorem succ_eq_succ : Order.succ = succ := rfl #align int.succ_eq_succ Int.succ_eq_succ @[simp] theorem pred_eq_pred : Order.pred = pred := rfl #align int.pred_eq_pred Int.pred_eq_pred theorem pos_iff_one_le {a : ℤ} : 0 < a ↔ 1 ≤ a := Order.succ_le_iff.symm #align int.pos_iff_one_le Int.pos_iff_one_le theorem succ_iterate (a : ℤ) : ∀ n, succ^[n] a = a + n | 0 => (add_zero a).symm | n + 1 => by rw [Function.iterate_succ', Int.ofNat_succ, ← add_assoc] exact congr_arg _ (succ_iterate a n) #align int.succ_iterate Int.succ_iterate theorem pred_iterate (a : ℤ) : ∀ n, pred^[n] a = a - n | 0 => (sub_zero a).symm | n + 1 => by rw [Function.iterate_succ', Int.ofNat_succ, ← sub_sub] exact congr_arg _ (pred_iterate a n) #align int.pred_iterate Int.pred_iterate instance : IsSuccArchimedean ℤ := ⟨fun {a b} h => ⟨(b - a).toNat, by rw [succ_eq_succ, succ_iterate, toNat_sub_of_le h, ← add_sub_assoc, add_sub_cancel_left]⟩⟩ instance : IsPredArchimedean ℤ := ⟨fun {a b} h => ⟨(b - a).toNat, by rw [pred_eq_pred, pred_iterate, toNat_sub_of_le h, sub_sub_cancel]⟩⟩ /-! ### Covering relation -/ protected theorem covBy_iff_succ_eq {m n : ℤ} : m ⋖ n ↔ m + 1 = n := succ_eq_iff_covBy.symm #align int.covby_iff_succ_eq Int.covBy_iff_succ_eq @[simp]
Mathlib/Data/Int/SuccPred.lean
79
79
theorem sub_one_covBy (z : ℤ) : z - 1 ⋖ z := by
rw [Int.covBy_iff_succ_eq, sub_add_cancel]
/- Copyright (c) 2024 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.MeasureTheory.Integral.PeakFunction import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform /-! # Fourier inversion formula In a finite-dimensional real inner product space, we show the Fourier inversion formula, i.e., `𝓕⁻ (𝓕 f) v = f v` if `f` and `𝓕 f` are integrable, and `f` is continuous at `v`. This is proved in `MeasureTheory.Integrable.fourier_inversion`. See also `Continuous.fourier_inversion` giving `𝓕⁻ (𝓕 f) = f` under an additional continuity assumption for `f`. We use the following proof. A naïve computation gives `𝓕⁻ (𝓕 f) v = ∫_w exp (2 I π ⟪w, v⟫) 𝓕 f (w) dw = ∫_w exp (2 I π ⟪w, v⟫) ∫_x, exp (-2 I π ⟪w, x⟫) f x dx) dw = ∫_x (∫_ w, exp (2 I π ⟪w, v - x⟫ dw) f x dx ` However, the Fubini step does not make sense for lack of integrability, and the middle integral `∫_ w, exp (2 I π ⟪w, v - x⟫ dw` (which one would like to be a Dirac at `v - x`) is not defined. To gain integrability, one multiplies with a Gaussian function `exp (-c⁻¹ ‖w‖^2)`, with a large (but finite) `c`. As this function converges pointwise to `1` when `c → ∞`, we get `∫_w exp (2 I π ⟪w, v⟫) 𝓕 f (w) dw = lim_c ∫_w exp (-c⁻¹ ‖w‖^2 + 2 I π ⟪w, v⟫) 𝓕 f (w) dw`. One can perform Fubini on the right hand side for fixed `c`, writing the integral as `∫_x (∫_w exp (-c⁻¹‖w‖^2 + 2 I π ⟪w, v - x⟫ dw)) f x dx`. The middle factor is the Fourier transform of a more and more flat function (converging to the constant `1`), hence it becomes more and more concentrated, around the point `v`. (Morally, it converges to the Dirac at `v`). Moreover, it has integral one. Therefore, multiplying by `f` and integrating, one gets a term converging to `f v` as `c → ∞`. Since it also converges to `𝓕⁻ (𝓕 f) v`, this proves the result. To check the concentration property of the middle factor and the fact that it has integral one, we rely on the explicit computation of the Fourier transform of Gaussians. -/ open Filter MeasureTheory Complex FiniteDimensional Metric Real Bornology open scoped Topology FourierTransform RealInnerProductSpace Complex variable {V E : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MeasurableSpace V] [BorelSpace V] [FiniteDimensional ℝ V] [NormedAddCommGroup E] [NormedSpace ℂ E] {f : V → E} namespace Real lemma tendsto_integral_cexp_sq_smul (hf : Integrable f) : Tendsto (fun (c : ℝ) ↦ (∫ v : V, cexp (- c⁻¹ * ‖v‖^2) • f v)) atTop (𝓝 (∫ v : V, f v)) := by apply tendsto_integral_filter_of_dominated_convergence _ _ _ hf.norm · filter_upwards with v nth_rewrite 2 [show f v = cexp (- (0 : ℝ) * ‖v‖^2) • f v by simp] apply (Tendsto.cexp _).smul_const exact tendsto_inv_atTop_zero.ofReal.neg.mul_const _ · filter_upwards with c using AEStronglyMeasurable.smul (Continuous.aestronglyMeasurable (by continuity)) hf.1 · filter_upwards [Ici_mem_atTop (0 : ℝ)] with c (hc : 0 ≤ c) filter_upwards with v simp only [ofReal_inv, neg_mul, norm_smul, Complex.norm_eq_abs] norm_cast conv_rhs => rw [← one_mul (‖f v‖)] gcongr simp only [abs_exp, exp_le_one_iff, Left.neg_nonpos_iff] positivity variable [CompleteSpace E] lemma tendsto_integral_gaussian_smul (hf : Integrable f) (h'f : Integrable (𝓕 f)) (v : V) : Tendsto (fun (c : ℝ) ↦ ∫ w : V, ((π * c) ^ (finrank ℝ V / 2 : ℂ) * cexp (-π ^ 2 * c * ‖v - w‖ ^ 2)) • f w) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by have A : Tendsto (fun (c : ℝ) ↦ (∫ w : V, cexp (- c⁻¹ * ‖w‖^2 + 2 * π * I * ⟪v, w⟫) • (𝓕 f) w)) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by have : Integrable (fun w ↦ 𝐞 ⟪w, v⟫ • (𝓕 f) w) := by have B : Continuous fun p : V × V => (- innerₗ V) p.1 p.2 := continuous_inner.neg simpa using (VectorFourier.fourierIntegral_convergent_iff Real.continuous_fourierChar B v).2 h'f convert tendsto_integral_cexp_sq_smul this using 4 with c w · rw [Submonoid.smul_def, Real.fourierChar_apply, smul_smul, ← Complex.exp_add, real_inner_comm] congr 3 simp only [ofReal_mul, ofReal_ofNat] ring · simp [fourierIntegralInv_eq] have B : Tendsto (fun (c : ℝ) ↦ (∫ w : V, 𝓕 (fun w ↦ cexp (- c⁻¹ * ‖w‖^2 + 2 * π * I * ⟪v, w⟫)) w • f w)) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by apply A.congr' filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c) have J : Integrable (fun w ↦ cexp (- c⁻¹ * ‖w‖^2 + 2 * π * I * ⟪v, w⟫)) := GaussianFourier.integrable_cexp_neg_mul_sq_norm_add (by simpa) _ _ simpa using (VectorFourier.integral_fourierIntegral_smul_eq_flip (L := innerₗ V) Real.continuous_fourierChar continuous_inner J hf).symm apply B.congr' filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c) congr with w rw [fourierIntegral_gaussian_innerProductSpace' (by simpa)] congr · simp · simp; ring lemma tendsto_integral_gaussian_smul' (hf : Integrable f) {v : V} (h'f : ContinuousAt f v) : Tendsto (fun (c : ℝ) ↦ ∫ w : V, ((π * c : ℂ) ^ (finrank ℝ V / 2 : ℂ) * cexp (-π ^ 2 * c * ‖v - w‖ ^ 2)) • f w) atTop (𝓝 (f v)) := by let φ : V → ℝ := fun w ↦ π ^ (finrank ℝ V / 2 : ℝ) * Real.exp (-π^2 * ‖w‖^2) have A : Tendsto (fun (c : ℝ) ↦ ∫ w : V, (c ^ finrank ℝ V * φ (c • (v - w))) • f w) atTop (𝓝 (f v)) := by apply tendsto_integral_comp_smul_smul_of_integrable' · exact fun x ↦ by positivity · rw [integral_mul_left, GaussianFourier.integral_rexp_neg_mul_sq_norm (by positivity)] nth_rewrite 2 [← pow_one π] rw [← rpow_natCast, ← rpow_natCast, ← rpow_sub pi_pos, ← rpow_mul pi_nonneg, ← rpow_add pi_pos] ring_nf exact rpow_zero _ · have A : Tendsto (fun (w : V) ↦ π^2 * ‖w‖^2) (cobounded V) atTop := by rw [tendsto_const_mul_atTop_of_pos (by positivity)] apply (tendsto_pow_atTop two_ne_zero).comp tendsto_norm_cobounded_atTop have B := tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (finrank ℝ V / 2) 1 zero_lt_one |>.comp A |>.const_mul (π ^ (-finrank ℝ V / 2 : ℝ)) rw [mul_zero] at B convert B using 2 with x simp only [neg_mul, one_mul, Function.comp_apply, ← mul_assoc, ← rpow_natCast, φ] congr 1 rw [mul_rpow (by positivity) (by positivity), ← rpow_mul pi_nonneg, ← rpow_mul (norm_nonneg _), ← mul_assoc, ← rpow_add pi_pos, mul_comm] congr <;> ring · exact hf · exact h'f have B : Tendsto (fun (c : ℝ) ↦ ∫ w : V, ((c^(1/2:ℝ)) ^ finrank ℝ V * φ ((c^(1/2:ℝ)) • (v - w))) • f w) atTop (𝓝 (f v)) := A.comp (tendsto_rpow_atTop (by norm_num)) apply B.congr' filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c) congr with w rw [← coe_smul] congr rw [ofReal_mul, ofReal_mul, ofReal_exp, ← mul_assoc] congr · rw [mul_cpow_ofReal_nonneg pi_nonneg hc.le, ← rpow_natCast, ← rpow_mul hc.le, mul_comm, ofReal_cpow pi_nonneg, ofReal_cpow hc.le] simp [div_eq_inv_mul] · norm_cast simp only [one_div, norm_smul, Real.norm_eq_abs, mul_pow, _root_.sq_abs, neg_mul, neg_inj, ← rpow_natCast, ← rpow_mul hc.le, mul_assoc] norm_num end Real variable [CompleteSpace E] /-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product space is integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕⁻ (𝓕 f) = f` at continuity points of `f`. -/ theorem MeasureTheory.Integrable.fourier_inversion (hf : Integrable f) (h'f : Integrable (𝓕 f)) {v : V} (hv : ContinuousAt f v) : 𝓕⁻ (𝓕 f) v = f v := tendsto_nhds_unique (Real.tendsto_integral_gaussian_smul hf h'f v) (Real.tendsto_integral_gaussian_smul' hf hv) /-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product space is continuous, integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕⁻ (𝓕 f) = f`. -/
Mathlib/Analysis/Fourier/Inversion.lean
168
172
theorem Continuous.fourier_inversion (h : Continuous f) (hf : Integrable f) (h'f : Integrable (𝓕 f)) : 𝓕⁻ (𝓕 f) = f := by
ext v exact hf.fourier_inversion h'f h.continuousAt
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.Algebra.Category.ModuleCat.Free import Mathlib.Topology.Category.Profinite.CofilteredLimit import Mathlib.Topology.Category.Profinite.Product import Mathlib.Topology.LocallyConstant.Algebra import Mathlib.Init.Data.Bool.Lemmas /-! # Nöbeling's theorem This file proves Nöbeling's theorem. ## Main result * `LocallyConstant.freeOfProfinite`: Nöbeling's theorem. For `S : Profinite`, the `ℤ`-module `LocallyConstant S ℤ` is free. ## Proof idea We follow the proof of theorem 5.4 in [scholze2019condensed], in which the idea is to embed `S` in a product of `I` copies of `Bool` for some sufficiently large `I`, and then to choose a well-ordering on `I` and use ordinal induction over that well-order. Here we can let `I` be the set of clopen subsets of `S` since `S` is totally separated. The above means it suffices to prove the following statement: For a closed subset `C` of `I → Bool`, the `ℤ`-module `LocallyConstant C ℤ` is free. For `i : I`, let `e C i : LocallyConstant C ℤ` denote the map `fun f ↦ (if f.val i then 1 else 0)`. The basis will consist of products `e C iᵣ * ⋯ * e C i₁` with `iᵣ > ⋯ > i₁` which cannot be written as linear combinations of lexicographically smaller products. We call this set `GoodProducts C` What is proved by ordinal induction is that this set is linearly independent. The fact that it spans can be proved directly. ## References - [scholze2019condensed], Theorem 5.4. -/ universe u namespace Profinite namespace NobelingProof variable {I : Type u} [LinearOrder I] [IsWellOrder I (·<·)] (C : Set (I → Bool)) open Profinite ContinuousMap CategoryTheory Limits Opposite Submodule section Projections /-! ## Projection maps The purpose of this section is twofold. Firstly, in the proof that the set `GoodProducts C` spans the whole module `LocallyConstant C ℤ`, we need to project `C` down to finite discrete subsets and write `C` as a cofiltered limit of those. Secondly, in the inductive argument, we need to project `C` down to "smaller" sets satisfying the inductive hypothesis. In this section we define the relevant projection maps and prove some compatibility results. ### Main definitions * Let `J : I → Prop`. Then `Proj J : (I → Bool) → (I → Bool)` is the projection mapping everything that satisfies `J i` to itself, and everything else to `false`. * The image of `C` under `Proj J` is denoted `π C J` and the corresponding map `C → π C J` is called `ProjRestrict`. If `J` implies `K` we have a map `ProjRestricts : π C K → π C J`. * `spanCone_isLimit` establishes that when `C` is compact, it can be written as a limit of its images under the maps `Proj (· ∈ s)` where `s : Finset I`. -/ variable (J K L : I → Prop) [∀ i, Decidable (J i)] [∀ i, Decidable (K i)] [∀ i, Decidable (L i)] /-- The projection mapping everything that satisfies `J i` to itself, and everything else to `false` -/ def Proj : (I → Bool) → (I → Bool) := fun c i ↦ if J i then c i else false @[simp] theorem continuous_proj : Continuous (Proj J : (I → Bool) → (I → Bool)) := by dsimp (config := { unfoldPartialApp := true }) [Proj] apply continuous_pi intro i split · apply continuous_apply · apply continuous_const /-- The image of `Proj π J` -/ def π : Set (I → Bool) := (Proj J) '' C /-- The restriction of `Proj π J` to a subset, mapping to its image. -/ @[simps!] def ProjRestrict : C → π C J := Set.MapsTo.restrict (Proj J) _ _ (Set.mapsTo_image _ _) @[simp] theorem continuous_projRestrict : Continuous (ProjRestrict C J) := Continuous.restrict _ (continuous_proj _) theorem proj_eq_self {x : I → Bool} (h : ∀ i, x i ≠ false → J i) : Proj J x = x := by ext i simp only [Proj, ite_eq_left_iff] contrapose! simpa only [ne_comm] using h i theorem proj_prop_eq_self (hh : ∀ i x, x ∈ C → x i ≠ false → J i) : π C J = C := by ext x refine ⟨fun ⟨y, hy, h⟩ ↦ ?_, fun h ↦ ⟨x, h, ?_⟩⟩ · rwa [← h, proj_eq_self]; exact (hh · y hy) · rw [proj_eq_self]; exact (hh · x h) theorem proj_comp_of_subset (h : ∀ i, J i → K i) : (Proj J ∘ Proj K) = (Proj J : (I → Bool) → (I → Bool)) := by ext x i; dsimp [Proj]; aesop theorem proj_eq_of_subset (h : ∀ i, J i → K i) : π (π C K) J = π C J := by ext x refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · obtain ⟨y, ⟨z, hz, rfl⟩, rfl⟩ := h refine ⟨z, hz, (?_ : _ = (Proj J ∘ Proj K) z)⟩ rw [proj_comp_of_subset J K h] · obtain ⟨y, hy, rfl⟩ := h dsimp [π] rw [← Set.image_comp] refine ⟨y, hy, ?_⟩ rw [proj_comp_of_subset J K h] variable {J K L} /-- A variant of `ProjRestrict` with domain of the form `π C K` -/ @[simps!] def ProjRestricts (h : ∀ i, J i → K i) : π C K → π C J := Homeomorph.setCongr (proj_eq_of_subset C J K h) ∘ ProjRestrict (π C K) J @[simp] theorem continuous_projRestricts (h : ∀ i, J i → K i) : Continuous (ProjRestricts C h) := Continuous.comp (Homeomorph.continuous _) (continuous_projRestrict _ _) theorem surjective_projRestricts (h : ∀ i, J i → K i) : Function.Surjective (ProjRestricts C h) := (Homeomorph.surjective _).comp (Set.surjective_mapsTo_image_restrict _ _) variable (J) in theorem projRestricts_eq_id : ProjRestricts C (fun i (h : J i) ↦ h) = id := by ext ⟨x, y, hy, rfl⟩ i simp (config := { contextual := true }) only [π, Proj, ProjRestricts_coe, id_eq, if_true] theorem projRestricts_eq_comp (hJK : ∀ i, J i → K i) (hKL : ∀ i, K i → L i) : ProjRestricts C hJK ∘ ProjRestricts C hKL = ProjRestricts C (fun i ↦ hKL i ∘ hJK i) := by ext x i simp only [π, Proj, Function.comp_apply, ProjRestricts_coe] aesop theorem projRestricts_comp_projRestrict (h : ∀ i, J i → K i) : ProjRestricts C h ∘ ProjRestrict C K = ProjRestrict C J := by ext x i simp only [π, Proj, Function.comp_apply, ProjRestricts_coe, ProjRestrict_coe] aesop variable (J) /-- The objectwise map in the isomorphism `spanFunctor ≅ Profinite.indexFunctor`. -/ def iso_map : C(π C J, (IndexFunctor.obj C J)) := ⟨fun x ↦ ⟨fun i ↦ x.val i.val, by rcases x with ⟨x, y, hy, rfl⟩ refine ⟨y, hy, ?_⟩ ext ⟨i, hi⟩ simp [precomp, Proj, hi]⟩, by refine Continuous.subtype_mk (continuous_pi fun i ↦ ?_) _ exact (continuous_apply i.val).comp continuous_subtype_val⟩ lemma iso_map_bijective : Function.Bijective (iso_map C J) := by refine ⟨fun a b h ↦ ?_, fun a ↦ ?_⟩ · ext i rw [Subtype.ext_iff] at h by_cases hi : J i · exact congr_fun h ⟨i, hi⟩ · rcases a with ⟨_, c, hc, rfl⟩ rcases b with ⟨_, d, hd, rfl⟩ simp only [Proj, if_neg hi] · refine ⟨⟨fun i ↦ if hi : J i then a.val ⟨i, hi⟩ else false, ?_⟩, ?_⟩ · rcases a with ⟨_, y, hy, rfl⟩ exact ⟨y, hy, rfl⟩ · ext i exact dif_pos i.prop variable {C} (hC : IsCompact C) /-- For a given compact subset `C` of `I → Bool`, `spanFunctor` is the functor from the poset of finsets of `I` to `Profinite`, sending a finite subset set `J` to the image of `C` under the projection `Proj J`. -/ noncomputable def spanFunctor [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : (Finset I)ᵒᵖ ⥤ Profinite.{u} where obj s := @Profinite.of (π C (· ∈ (unop s))) _ (by rw [← isCompact_iff_compactSpace]; exact hC.image (continuous_proj _)) _ _ map h := ⟨(ProjRestricts C (leOfHom h.unop)), continuous_projRestricts _ _⟩ map_id J := by simp only [projRestricts_eq_id C (· ∈ (unop J))]; rfl map_comp _ _ := by dsimp; congr; dsimp; rw [projRestricts_eq_comp] /-- The limit cone on `spanFunctor` with point `C`. -/ noncomputable def spanCone [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : Cone (spanFunctor hC) where pt := @Profinite.of C _ (by rwa [← isCompact_iff_compactSpace]) _ _ π := { app := fun s ↦ ⟨ProjRestrict C (· ∈ unop s), continuous_projRestrict _ _⟩ naturality := by intro X Y h simp only [Functor.const_obj_obj, Homeomorph.setCongr, Homeomorph.homeomorph_mk_coe, Functor.const_obj_map, Category.id_comp, ← projRestricts_comp_projRestrict C (leOfHom h.unop)] rfl } /-- `spanCone` is a limit cone. -/ noncomputable def spanCone_isLimit [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : CategoryTheory.Limits.IsLimit (spanCone hC) := by refine (IsLimit.postcomposeHomEquiv (NatIso.ofComponents (fun s ↦ (Profinite.isoOfBijective _ (iso_map_bijective C (· ∈ unop s)))) ?_) (spanCone hC)) (IsLimit.ofIsoLimit (indexCone_isLimit hC) (Cones.ext (Iso.refl _) ?_)) · intro ⟨s⟩ ⟨t⟩ ⟨⟨⟨f⟩⟩⟩ ext x have : iso_map C (· ∈ t) ∘ ProjRestricts C f = IndexFunctor.map C f ∘ iso_map C (· ∈ s) := by ext _ i; exact dif_pos i.prop exact congr_fun this x · intro ⟨s⟩ ext x have : iso_map C (· ∈ s) ∘ ProjRestrict C (· ∈ s) = IndexFunctor.π_app C (· ∈ s) := by ext _ i; exact dif_pos i.prop erw [← this] rfl end Projections section Products /-! ## Defining the basis Our proposed basis consists of products `e C iᵣ * ⋯ * e C i₁` with `iᵣ > ⋯ > i₁` which cannot be written as linear combinations of lexicographically smaller products. See below for the definition of `e`. ### Main definitions * For `i : I`, we let `e C i : LocallyConstant C ℤ` denote the map `fun f ↦ (if f.val i then 1 else 0)`. * `Products I` is the type of lists of decreasing elements of `I`, so a typical element is `[i₁, i₂,..., iᵣ]` with `i₁ > i₂ > ... > iᵣ`. * `Products.eval C` is the `C`-evaluation of a list. It takes a term `[i₁, i₂,..., iᵣ] : Products I` and returns the actual product `e C i₁ ··· e C iᵣ : LocallyConstant C ℤ`. * `GoodProducts C` is the set of `Products I` such that their `C`-evaluation cannot be written as a linear combination of evaluations of lexicographically smaller lists. ### Main results * `Products.evalFacProp` and `Products.evalFacProps` establish the fact that `Products.eval`  interacts nicely with the projection maps from the previous section. * `GoodProducts.span_iff_products`: the good products span `LocallyConstant C ℤ` iff all the products span `LocallyConstant C ℤ`. -/ /-- `e C i` is the locally constant map from `C : Set (I → Bool)` to `ℤ` sending `f` to 1 if `f.val i = true`, and 0 otherwise. -/ def e (i : I) : LocallyConstant C ℤ where toFun := fun f ↦ (if f.val i then 1 else 0) isLocallyConstant := by rw [IsLocallyConstant.iff_continuous] exact (continuous_of_discreteTopology (f := fun (a : Bool) ↦ (if a then (1 : ℤ) else 0))).comp ((continuous_apply i).comp continuous_subtype_val) /-- `Products I` is the type of lists of decreasing elements of `I`, so a typical element is `[i₁, i₂, ...]` with `i₁ > i₂ > ...`. We order `Products I` lexicographically, so `[] < [i₁, ...]`, and `[i₁, i₂, ...] < [j₁, j₂, ...]` if either `i₁ < j₁`, or `i₁ = j₁` and `[i₂, ...] < [j₂, ...]`. Terms `m = [i₁, i₂, ..., iᵣ]` of this type will be used to represent products of the form `e C i₁ ··· e C iᵣ : LocallyConstant C ℤ` . The function associated to `m` is `m.eval`. -/ def Products (I : Type*) [LinearOrder I] := {l : List I // l.Chain' (·>·)} namespace Products instance : LinearOrder (Products I) := inferInstanceAs (LinearOrder {l : List I // l.Chain' (·>·)}) @[simp] theorem lt_iff_lex_lt (l m : Products I) : l < m ↔ List.Lex (·<·) l.val m.val := by cases l; cases m; rw [Subtype.mk_lt_mk]; exact Iff.rfl instance : IsWellFounded (Products I) (·<·) := by have : (· < · : Products I → _ → _) = (fun l m ↦ List.Lex (·<·) l.val m.val) := by ext; exact lt_iff_lex_lt _ _ rw [this] dsimp [Products] rw [(by rfl : (·>· : I → _) = flip (·<·))] infer_instance /-- The evaluation `e C i₁ ··· e C iᵣ : C → ℤ` of a formal product `[i₁, i₂, ..., iᵣ]`. -/ def eval (l : Products I) := (l.1.map (e C)).prod /-- The predicate on products which we prove picks out a basis of `LocallyConstant C ℤ`. We call such a product "good". -/ def isGood (l : Products I) : Prop := l.eval C ∉ Submodule.span ℤ ((Products.eval C) '' {m | m < l}) theorem rel_head!_of_mem [Inhabited I] {i : I} {l : Products I} (hi : i ∈ l.val) : i ≤ l.val.head! := List.Sorted.le_head! (List.chain'_iff_pairwise.mp l.prop) hi theorem head!_le_of_lt [Inhabited I] {q l : Products I} (h : q < l) (hq : q.val ≠ []) : q.val.head! ≤ l.val.head! := List.head!_le_of_lt l.val q.val h hq end Products /-- The set of good products. -/ def GoodProducts := {l : Products I | l.isGood C} namespace GoodProducts /-- Evaluation of good products. -/ def eval (l : {l : Products I // l.isGood C}) : LocallyConstant C ℤ := Products.eval C l.1 theorem injective : Function.Injective (eval C) := by intro ⟨a, ha⟩ ⟨b, hb⟩ h dsimp [eval] at h rcases lt_trichotomy a b with (h'|rfl|h') · exfalso; apply hb; rw [← h] exact Submodule.subset_span ⟨a, h', rfl⟩ · rfl · exfalso; apply ha; rw [h] exact Submodule.subset_span ⟨b, ⟨h',rfl⟩⟩ /-- The image of the good products in the module `LocallyConstant C ℤ`. -/ def range := Set.range (GoodProducts.eval C) /-- The type of good products is equivalent to its image. -/ noncomputable def equiv_range : GoodProducts C ≃ range C := Equiv.ofInjective (eval C) (injective C) theorem equiv_toFun_eq_eval : (equiv_range C).toFun = Set.rangeFactorization (eval C) := rfl theorem linearIndependent_iff_range : LinearIndependent ℤ (GoodProducts.eval C) ↔ LinearIndependent ℤ (fun (p : range C) ↦ p.1) := by rw [← @Set.rangeFactorization_eq _ _ (GoodProducts.eval C), ← equiv_toFun_eq_eval C] exact linearIndependent_equiv (equiv_range C) end GoodProducts namespace Products theorem eval_eq (l : Products I) (x : C) : l.eval C x = if ∀ i, i ∈ l.val → (x.val i = true) then 1 else 0 := by change LocallyConstant.evalMonoidHom x (l.eval C) = _ rw [eval, map_list_prod] split_ifs with h · simp only [List.map_map] apply List.prod_eq_one simp only [List.mem_map, Function.comp_apply] rintro _ ⟨i, hi, rfl⟩ exact if_pos (h i hi) · simp only [List.map_map, List.prod_eq_zero_iff, List.mem_map, Function.comp_apply] push_neg at h convert h with i dsimp [LocallyConstant.evalMonoidHom, e] simp only [ite_eq_right_iff, one_ne_zero] theorem evalFacProp {l : Products I} (J : I → Prop) (h : ∀ a, a ∈ l.val → J a) [∀ j, Decidable (J j)] : l.eval (π C J) ∘ ProjRestrict C J = l.eval C := by ext x dsimp [ProjRestrict] rw [Products.eval_eq, Products.eval_eq] congr apply forall_congr; intro i apply forall_congr; intro hi simp [h i hi, Proj] theorem evalFacProps {l : Products I} (J K : I → Prop) (h : ∀ a, a ∈ l.val → J a) [∀ j, Decidable (J j)] [∀ j, Decidable (K j)] (hJK : ∀ i, J i → K i) : l.eval (π C J) ∘ ProjRestricts C hJK = l.eval (π C K) := by have : l.eval (π C J) ∘ Homeomorph.setCongr (proj_eq_of_subset C J K hJK) = l.eval (π (π C K) J) := by ext; simp [Homeomorph.setCongr, Products.eval_eq] rw [ProjRestricts, ← Function.comp.assoc, this, ← evalFacProp (π C K) J h] theorem prop_of_isGood {l : Products I} (J : I → Prop) [∀ j, Decidable (J j)] (h : l.isGood (π C J)) : ∀ a, a ∈ l.val → J a := by intro i hi by_contra h' apply h suffices eval (π C J) l = 0 by rw [this] exact Submodule.zero_mem _ ext ⟨_, _, _, rfl⟩ rw [eval_eq, if_neg fun h ↦ ?_, LocallyConstant.zero_apply] simpa [Proj, h'] using h i hi end Products /-- The good products span `LocallyConstant C ℤ` if and only all the products do. -/ theorem GoodProducts.span_iff_products : ⊤ ≤ span ℤ (Set.range (eval C)) ↔ ⊤ ≤ span ℤ (Set.range (Products.eval C)) := by refine ⟨fun h ↦ le_trans h (span_mono (fun a ⟨b, hb⟩ ↦ ⟨b.val, hb⟩)), fun h ↦ le_trans h ?_⟩ rw [span_le] rintro f ⟨l, rfl⟩ let L : Products I → Prop := fun m ↦ m.eval C ∈ span ℤ (Set.range (GoodProducts.eval C)) suffices L l by assumption apply IsWellFounded.induction (·<· : Products I → Products I → Prop) intro l h dsimp by_cases hl : l.isGood C · apply subset_span exact ⟨⟨l, hl⟩, rfl⟩ · simp only [Products.isGood, not_not] at hl suffices Products.eval C '' {m | m < l} ⊆ span ℤ (Set.range (GoodProducts.eval C)) by rw [← span_le] at this exact this hl rintro a ⟨m, hm, rfl⟩ exact h m hm end Products section Span /-! ## The good products span Most of the argument is developing an API for `π C (· ∈ s)` when `s : Finset I`; then the image of `C` is finite with the discrete topology. In this case, there is a direct argument that the good products span. The general result is deduced from this. ### Main theorems * `GoodProducts.spanFin` : The good products span the locally constant functions on `π C (· ∈ s)` if `s` is finite. * `GoodProducts.span` : The good products span `LocallyConstant C ℤ` for every closed subset `C`. -/ section Fin variable (s : Finset I) /-- The `ℤ`-linear map induced by precomposition of the projection `C → π C (· ∈ s)`. -/ noncomputable def πJ : LocallyConstant (π C (· ∈ s)) ℤ →ₗ[ℤ] LocallyConstant C ℤ := LocallyConstant.comapₗ ℤ ⟨_, (continuous_projRestrict C (· ∈ s))⟩ theorem eval_eq_πJ (l : Products I) (hl : l.isGood (π C (· ∈ s))) : l.eval C = πJ C s (l.eval (π C (· ∈ s))) := by ext f simp only [πJ, LocallyConstant.comapₗ, LinearMap.coe_mk, AddHom.coe_mk, (continuous_projRestrict C (· ∈ s)), LocallyConstant.coe_comap, Function.comp_apply] exact (congr_fun (Products.evalFacProp C (· ∈ s) (Products.prop_of_isGood C (· ∈ s) hl)) _).symm /-- `π C (· ∈ s)` is finite for a finite set `s`. -/ noncomputable instance : Fintype (π C (· ∈ s)) := by let f : π C (· ∈ s) → (s → Bool) := fun x j ↦ x.val j.val refine Fintype.ofInjective f ?_ intro ⟨_, x, hx, rfl⟩ ⟨_, y, hy, rfl⟩ h ext i by_cases hi : i ∈ s · exact congrFun h ⟨i, hi⟩ · simp only [Proj, if_neg hi] open scoped Classical in /-- The Kronecker delta as a locally constant map from `π C (· ∈ s)` to `ℤ`. -/ noncomputable def spanFinBasis (x : π C (· ∈ s)) : LocallyConstant (π C (· ∈ s)) ℤ where toFun := fun y ↦ if y = x then 1 else 0 isLocallyConstant := haveI : DiscreteTopology (π C (· ∈ s)) := discrete_of_t1_of_finite IsLocallyConstant.of_discrete _ open scoped Classical in theorem spanFinBasis.span : ⊤ ≤ Submodule.span ℤ (Set.range (spanFinBasis C s)) := by intro f _ rw [Finsupp.mem_span_range_iff_exists_finsupp] use Finsupp.onFinset (Finset.univ) f.toFun (fun _ _ ↦ Finset.mem_univ _) ext x change LocallyConstant.evalₗ ℤ x _ = _ simp only [zsmul_eq_mul, map_finsupp_sum, LocallyConstant.evalₗ_apply, LocallyConstant.coe_mul, Pi.mul_apply, spanFinBasis, LocallyConstant.coe_mk, mul_ite, mul_one, mul_zero, Finsupp.sum_ite_eq, Finsupp.mem_support_iff, ne_eq, ite_not] split_ifs with h <;> [exact h.symm; rfl] /-- A certain explicit list of locally constant maps. The theorem `factors_prod_eq_basis` shows that the product of the elements in this list is the delta function `spanFinBasis C s x`. -/ def factors (x : π C (· ∈ s)) : List (LocallyConstant (π C (· ∈ s)) ℤ) := List.map (fun i ↦ if x.val i = true then e (π C (· ∈ s)) i else (1 - (e (π C (· ∈ s)) i))) (s.sort (·≥·)) theorem list_prod_apply (x : C) (l : List (LocallyConstant C ℤ)) : l.prod x = (l.map (LocallyConstant.evalMonoidHom x)).prod := by rw [← map_list_prod (LocallyConstant.evalMonoidHom x) l] rfl theorem factors_prod_eq_basis_of_eq {x y : (π C fun x ↦ x ∈ s)} (h : y = x) : (factors C s x).prod y = 1 := by rw [list_prod_apply (π C (· ∈ s)) y _] apply List.prod_eq_one simp only [h, List.mem_map, LocallyConstant.evalMonoidHom, factors] rintro _ ⟨a, ⟨b, _, rfl⟩, rfl⟩ dsimp split_ifs with hh · rw [e, LocallyConstant.coe_mk, if_pos hh] · rw [LocallyConstant.sub_apply, e, LocallyConstant.coe_mk, LocallyConstant.coe_mk, if_neg hh] simp only [LocallyConstant.toFun_eq_coe, LocallyConstant.coe_one, Pi.one_apply, sub_zero] theorem e_mem_of_eq_true {x : (π C (· ∈ s))} {a : I} (hx : x.val a = true) : e (π C (· ∈ s)) a ∈ factors C s x := by rcases x with ⟨_, z, hz, rfl⟩ simp only [factors, List.mem_map, Finset.mem_sort] refine ⟨a, ?_, if_pos hx⟩ aesop (add simp Proj) theorem one_sub_e_mem_of_false {x y : (π C (· ∈ s))} {a : I} (ha : y.val a = true) (hx : x.val a = false) : 1 - e (π C (· ∈ s)) a ∈ factors C s x := by simp only [factors, List.mem_map, Finset.mem_sort] use a simp only [hx, ite_false, and_true] rcases y with ⟨_, z, hz, rfl⟩ aesop (add simp Proj) theorem factors_prod_eq_basis_of_ne {x y : (π C (· ∈ s))} (h : y ≠ x) : (factors C s x).prod y = 0 := by rw [list_prod_apply (π C (· ∈ s)) y _] apply List.prod_eq_zero simp only [List.mem_map] obtain ⟨a, ha⟩ : ∃ a, y.val a ≠ x.val a := by contrapose! h; ext; apply h cases hx : x.val a · rw [hx, ne_eq, Bool.not_eq_false] at ha refine ⟨1 - (e (π C (· ∈ s)) a), ⟨one_sub_e_mem_of_false _ _ ha hx, ?_⟩⟩ rw [e, LocallyConstant.evalMonoidHom_apply, LocallyConstant.sub_apply, LocallyConstant.coe_one, Pi.one_apply, LocallyConstant.coe_mk, if_pos ha, sub_self] · refine ⟨e (π C (· ∈ s)) a, ⟨e_mem_of_eq_true _ _ hx, ?_⟩⟩ rw [hx] at ha rw [LocallyConstant.evalMonoidHom_apply, e, LocallyConstant.coe_mk, if_neg ha] /-- If `s` is finite, the product of the elements of the list `factors C s x` is the delta function at `x`. -/ theorem factors_prod_eq_basis (x : π C (· ∈ s)) : (factors C s x).prod = spanFinBasis C s x := by ext y dsimp [spanFinBasis] split_ifs with h <;> [exact factors_prod_eq_basis_of_eq _ _ h; exact factors_prod_eq_basis_of_ne _ _ h] theorem GoodProducts.finsupp_sum_mem_span_eval {a : I} {as : List I} (ha : List.Chain' (· > ·) (a :: as)) {c : Products I →₀ ℤ} (hc : (c.support : Set (Products I)) ⊆ {m | m.val ≤ as}) : (Finsupp.sum c fun a_1 b ↦ e (π C (· ∈ s)) a * b • Products.eval (π C (· ∈ s)) a_1) ∈ Submodule.span ℤ (Products.eval (π C (· ∈ s)) '' {m | m.val ≤ a :: as}) := by apply Submodule.finsupp_sum_mem intro m hm have hsm := (LinearMap.mulLeft ℤ (e (π C (· ∈ s)) a)).map_smul dsimp at hsm rw [hsm] apply Submodule.smul_mem apply Submodule.subset_span have hmas : m.val ≤ as := by apply hc simpa only [Finset.mem_coe, Finsupp.mem_support_iff] using hm refine ⟨⟨a :: m.val, ha.cons_of_le m.prop hmas⟩, ⟨List.cons_le_cons a hmas, ?_⟩⟩ simp only [Products.eval, List.map, List.prod_cons] /-- If `s` is a finite subset of `I`, then the good products span. -/ theorem GoodProducts.spanFin : ⊤ ≤ Submodule.span ℤ (Set.range (eval (π C (· ∈ s)))) := by rw [span_iff_products] refine le_trans (spanFinBasis.span C s) ?_ rw [Submodule.span_le] rintro _ ⟨x, rfl⟩ rw [← factors_prod_eq_basis] let l := s.sort (·≥·) dsimp [factors] suffices l.Chain' (·>·) → (l.map (fun i ↦ if x.val i = true then e (π C (· ∈ s)) i else (1 - (e (π C (· ∈ s)) i)))).prod ∈ Submodule.span ℤ ((Products.eval (π C (· ∈ s))) '' {m | m.val ≤ l}) from Submodule.span_mono (Set.image_subset_range _ _) (this (Finset.sort_sorted_gt _).chain') induction l with | nil => intro _ apply Submodule.subset_span exact ⟨⟨[], List.chain'_nil⟩,⟨Or.inl rfl, rfl⟩⟩ | cons a as ih => rw [List.map_cons, List.prod_cons] intro ha specialize ih (by rw [List.chain'_cons'] at ha; exact ha.2) rw [Finsupp.mem_span_image_iff_total] at ih simp only [Finsupp.mem_supported, Finsupp.total_apply] at ih obtain ⟨c, hc, hc'⟩ := ih rw [← hc']; clear hc' have hmap := fun g ↦ map_finsupp_sum (LinearMap.mulLeft ℤ (e (π C (· ∈ s)) a)) c g dsimp at hmap ⊢ split_ifs · rw [hmap] exact finsupp_sum_mem_span_eval _ _ ha hc · ring_nf rw [hmap] apply Submodule.add_mem · apply Submodule.neg_mem exact finsupp_sum_mem_span_eval _ _ ha hc · apply Submodule.finsupp_sum_mem intro m hm apply Submodule.smul_mem apply Submodule.subset_span refine ⟨m, ⟨?_, rfl⟩⟩ simp only [Set.mem_setOf_eq] have hmas : m.val ≤ as := hc (by simpa only [Finset.mem_coe, Finsupp.mem_support_iff] using hm) refine le_trans hmas ?_ cases as with | nil => exact (List.nil_lt_cons a []).le | cons b bs => apply le_of_lt rw [List.chain'_cons] at ha have hlex := List.lt.head bs (b :: bs) ha.1 exact (List.lt_iff_lex_lt _ _).mp hlex end Fin theorem fin_comap_jointlySurjective (hC : IsClosed C) (f : LocallyConstant C ℤ) : ∃ (s : Finset I) (g : LocallyConstant (π C (· ∈ s)) ℤ), f = g.comap ⟨(ProjRestrict C (· ∈ s)), continuous_projRestrict _ _⟩ := by obtain ⟨J, g, h⟩ := @Profinite.exists_locallyConstant.{0, u, u} (Finset I)ᵒᵖ _ _ _ (spanCone hC.isCompact) ℤ (spanCone_isLimit hC.isCompact) f exact ⟨(Opposite.unop J), g, h⟩ /-- The good products span all of `LocallyConstant C ℤ` if `C` is closed. -/ theorem GoodProducts.span (hC : IsClosed C) : ⊤ ≤ Submodule.span ℤ (Set.range (eval C)) := by rw [span_iff_products] intro f _ obtain ⟨K, f', rfl⟩ : ∃ K f', f = πJ C K f' := fin_comap_jointlySurjective C hC f refine Submodule.span_mono ?_ <| Submodule.apply_mem_span_image_of_mem_span (πJ C K) <| spanFin C K (Submodule.mem_top : f' ∈ ⊤) rintro l ⟨y, ⟨m, rfl⟩, rfl⟩ exact ⟨m.val, eval_eq_πJ C K m.val m.prop⟩ end Span section Ordinal /-! ## Relating elements of the well-order `I` with ordinals We choose a well-ordering on `I`. This amounts to regarding `I` as an ordinal, and as such it can be regarded as the set of all strictly smaller ordinals, allowing to apply ordinal induction. ### Main definitions * `ord I i` is the term `i` of `I` regarded as an ordinal. * `term I ho` is a sufficiently small ordinal regarded as a term of `I`. * `contained C o` is a predicate saying that `C` is "small" enough in relation to the ordinal `o` to satisfy the inductive hypothesis. * `P I` is the predicate on ordinals about linear independence of good products, which the rest of this file is spent on proving by induction. -/ variable (I) /-- A term of `I` regarded as an ordinal. -/ def ord (i : I) : Ordinal := Ordinal.typein ((·<·) : I → I → Prop) i /-- An ordinal regarded as a term of `I`. -/ noncomputable def term {o : Ordinal} (ho : o < Ordinal.type ((·<·) : I → I → Prop)) : I := Ordinal.enum ((·<·) : I → I → Prop) o ho variable {I} theorem term_ord_aux {i : I} (ho : ord I i < Ordinal.type ((·<·) : I → I → Prop)) : term I ho = i := by simp only [term, ord, Ordinal.enum_typein] @[simp] theorem ord_term_aux {o : Ordinal} (ho : o < Ordinal.type ((·<·) : I → I → Prop)) : ord I (term I ho) = o := by simp only [ord, term, Ordinal.typein_enum] theorem ord_term {o : Ordinal} (ho : o < Ordinal.type ((·<·) : I → I → Prop)) (i : I) : ord I i = o ↔ term I ho = i := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · subst h exact term_ord_aux ho · subst h exact ord_term_aux ho /-- A predicate saying that `C` is "small" enough to satisfy the inductive hypothesis. -/ def contained (o : Ordinal) : Prop := ∀ f, f ∈ C → ∀ (i : I), f i = true → ord I i < o variable (I) in /-- The predicate on ordinals which we prove by induction, see `GoodProducts.P0`, `GoodProducts.Plimit` and `GoodProducts.linearIndependentAux` in the section `Induction` below -/ def P (o : Ordinal) : Prop := o ≤ Ordinal.type (·<· : I → I → Prop) → (∀ (C : Set (I → Bool)), IsClosed C → contained C o → LinearIndependent ℤ (GoodProducts.eval C)) theorem Products.prop_of_isGood_of_contained {l : Products I} (o : Ordinal) (h : l.isGood C) (hsC : contained C o) (i : I) (hi : i ∈ l.val) : ord I i < o := by by_contra h' apply h suffices eval C l = 0 by simp [this, Submodule.zero_mem] ext x simp only [eval_eq, LocallyConstant.coe_zero, Pi.zero_apply, ite_eq_right_iff, one_ne_zero] contrapose! h' exact hsC x.val x.prop i (h'.1 i hi) end Ordinal section Zero /-! ## The zero case of the induction In this case, we have `contained C 0` which means that `C` is either empty or a singleton. -/ instance : Subsingleton (LocallyConstant (∅ : Set (I → Bool)) ℤ) := subsingleton_iff.mpr (fun _ _ ↦ LocallyConstant.ext isEmptyElim) instance : IsEmpty { l // Products.isGood (∅ : Set (I → Bool)) l } := isEmpty_iff.mpr fun ⟨l, hl⟩ ↦ hl <| by rw [subsingleton_iff.mp inferInstance (Products.eval ∅ l) 0] exact Submodule.zero_mem _ theorem GoodProducts.linearIndependentEmpty : LinearIndependent ℤ (eval (∅ : Set (I → Bool))) := linearIndependent_empty_type /-- The empty list as a `Products` -/ def Products.nil : Products I := ⟨[], by simp only [List.chain'_nil]⟩ theorem Products.lt_nil_empty : { m : Products I | m < Products.nil } = ∅ := by ext ⟨m, hm⟩ refine ⟨fun h ↦ ?_, by tauto⟩ simp only [Set.mem_setOf_eq, lt_iff_lex_lt, nil, List.Lex.not_nil_right] at h instance {α : Type*} [TopologicalSpace α] [Nonempty α] : Nontrivial (LocallyConstant α ℤ) := ⟨0, 1, ne_of_apply_ne DFunLike.coe <| (Function.const_injective (β := ℤ)).ne zero_ne_one⟩ set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Products.isGood_nil : Products.isGood ({fun _ ↦ false} : Set (I → Bool)) Products.nil := by intro h simp only [Products.lt_nil_empty, Products.eval, List.map, List.prod_nil, Set.image_empty, Submodule.span_empty, Submodule.mem_bot, one_ne_zero] at h set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Products.span_nil_eq_top : Submodule.span ℤ (eval ({fun _ ↦ false} : Set (I → Bool)) '' {nil}) = ⊤ := by rw [Set.image_singleton, eq_top_iff] intro f _ rw [Submodule.mem_span_singleton] refine ⟨f default, ?_⟩ simp only [eval, List.map, List.prod_nil, zsmul_eq_mul, mul_one] ext x obtain rfl : x = default := by simp only [Set.default_coe_singleton, eq_iff_true_of_subsingleton] rfl /-- There is a unique `GoodProducts` for the singleton `{fun _ ↦ false}`. -/ noncomputable instance : Unique { l // Products.isGood ({fun _ ↦ false} : Set (I → Bool)) l } where default := ⟨Products.nil, Products.isGood_nil⟩ uniq := by intro ⟨⟨l, hl⟩, hll⟩ ext apply Subtype.ext apply (List.Lex.nil_left_or_eq_nil l (r := (·<·))).resolve_left intro _ apply hll have he : {Products.nil} ⊆ {m | m < ⟨l,hl⟩} := by simpa only [Products.nil, Products.lt_iff_lex_lt, Set.singleton_subset_iff, Set.mem_setOf_eq] apply Submodule.span_mono (Set.image_subset _ he) rw [Products.span_nil_eq_top] exact Submodule.mem_top instance (α : Type*) [TopologicalSpace α] : NoZeroSMulDivisors ℤ (LocallyConstant α ℤ) := by constructor intro c f h rw [or_iff_not_imp_left] intro hc ext x apply mul_right_injective₀ hc simp [LocallyConstant.ext_iff] at h ⊢ exact h x set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem GoodProducts.linearIndependentSingleton : LinearIndependent ℤ (eval ({fun _ ↦ false} : Set (I → Bool))) := by refine linearIndependent_unique (eval ({fun _ ↦ false} : Set (I → Bool))) ?_ simp only [eval, Products.eval, List.map, List.prod_nil, ne_eq, one_ne_zero, not_false_eq_true] end Zero section Maps /-! ## `ℤ`-linear maps induced by projections We define injective `ℤ`-linear maps between modules of the form `LocallyConstant C ℤ` induced by precomposition with the projections defined in the section `Projections`. ### Main definitions * `πs` and `πs'` are the `ℤ`-linear maps corresponding to `ProjRestrict` and `ProjRestricts`  respectively. ### Main result * We prove that `πs` and `πs'` interact well with `Products.eval` and the main application is the theorem `isGood_mono` which says that the property `isGood` is "monotone" on ordinals. -/ theorem contained_eq_proj (o : Ordinal) (h : contained C o) : C = π C (ord I · < o) := by have := proj_prop_eq_self C (ord I · < o) simp [π, Bool.not_eq_false] at this exact (this (fun i x hx ↦ h x hx i)).symm theorem isClosed_proj (o : Ordinal) (hC : IsClosed C) : IsClosed (π C (ord I · < o)) := (continuous_proj (ord I · < o)).isClosedMap C hC theorem contained_proj (o : Ordinal) : contained (π C (ord I · < o)) o := by intro x ⟨_, _, h⟩ j hj aesop (add simp Proj) /-- The `ℤ`-linear map induced by precomposition of the projection `C → π C (ord I · < o)`. -/ @[simps!] noncomputable def πs (o : Ordinal) : LocallyConstant (π C (ord I · < o)) ℤ →ₗ[ℤ] LocallyConstant C ℤ := LocallyConstant.comapₗ ℤ ⟨(ProjRestrict C (ord I · < o)), (continuous_projRestrict _ _)⟩ theorem coe_πs (o : Ordinal) (f : LocallyConstant (π C (ord I · < o)) ℤ) : πs C o f = f ∘ ProjRestrict C (ord I · < o) := by rfl theorem injective_πs (o : Ordinal) : Function.Injective (πs C o) := LocallyConstant.comap_injective ⟨_, (continuous_projRestrict _ _)⟩ (Set.surjective_mapsTo_image_restrict _ _) /-- The `ℤ`-linear map induced by precomposition of the projection `π C (ord I · < o₂) → π C (ord I · < o₁)` for `o₁ ≤ o₂`. -/ @[simps!] noncomputable def πs' {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) : LocallyConstant (π C (ord I · < o₁)) ℤ →ₗ[ℤ] LocallyConstant (π C (ord I · < o₂)) ℤ := LocallyConstant.comapₗ ℤ ⟨(ProjRestricts C (fun _ hh ↦ lt_of_lt_of_le hh h)), (continuous_projRestricts _ _)⟩ theorem coe_πs' {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) (f : LocallyConstant (π C (ord I · < o₁)) ℤ) : (πs' C h f).toFun = f.toFun ∘ (ProjRestricts C (fun _ hh ↦ lt_of_lt_of_le hh h)) := by rfl theorem injective_πs' {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) : Function.Injective (πs' C h) := LocallyConstant.comap_injective ⟨_, (continuous_projRestricts _ _)⟩ (surjective_projRestricts _ fun _ hi ↦ lt_of_lt_of_le hi h) namespace Products theorem lt_ord_of_lt {l m : Products I} {o : Ordinal} (h₁ : m < l) (h₂ : ∀ i ∈ l.val, ord I i < o) : ∀ i ∈ m.val, ord I i < o := List.Sorted.lt_ord_of_lt (List.chain'_iff_pairwise.mp l.2) (List.chain'_iff_pairwise.mp m.2) h₁ h₂ theorem eval_πs {l : Products I} {o : Ordinal} (hlt : ∀ i ∈ l.val, ord I i < o) : πs C o (l.eval (π C (ord I · < o))) = l.eval C := by simpa only [← LocallyConstant.coe_inj] using evalFacProp C (ord I · < o) hlt theorem eval_πs' {l : Products I} {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) (hlt : ∀ i ∈ l.val, ord I i < o₁) : πs' C h (l.eval (π C (ord I · < o₁))) = l.eval (π C (ord I · < o₂)) := by rw [← LocallyConstant.coe_inj, ← LocallyConstant.toFun_eq_coe] exact evalFacProps C (fun (i : I) ↦ ord I i < o₁) (fun (i : I) ↦ ord I i < o₂) hlt (fun _ hh ↦ lt_of_lt_of_le hh h) theorem eval_πs_image {l : Products I} {o : Ordinal} (hl : ∀ i ∈ l.val, ord I i < o) : eval C '' { m | m < l } = (πs C o) '' (eval (π C (ord I · < o)) '' { m | m < l }) := by ext f simp only [Set.mem_image, Set.mem_setOf_eq, exists_exists_and_eq_and] apply exists_congr; intro m apply and_congr_right; intro hm rw [eval_πs C (lt_ord_of_lt hm hl)] theorem eval_πs_image' {l : Products I} {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) (hl : ∀ i ∈ l.val, ord I i < o₁) : eval (π C (ord I · < o₂)) '' { m | m < l } = (πs' C h) '' (eval (π C (ord I · < o₁)) '' { m | m < l }) := by ext f simp only [Set.mem_image, Set.mem_setOf_eq, exists_exists_and_eq_and] apply exists_congr; intro m apply and_congr_right; intro hm rw [eval_πs' C h (lt_ord_of_lt hm hl)] theorem head_lt_ord_of_isGood [Inhabited I] {l : Products I} {o : Ordinal} (h : l.isGood (π C (ord I · < o))) (hn : l.val ≠ []) : ord I (l.val.head!) < o := prop_of_isGood C (ord I · < o) h l.val.head! (List.head!_mem_self hn) /-- If `l` is good w.r.t. `π C (ord I · < o₁)` and `o₁ ≤ o₂`, then it is good w.r.t. `π C (ord I · < o₂)` -/ theorem isGood_mono {l : Products I} {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) (hl : l.isGood (π C (ord I · < o₁))) : l.isGood (π C (ord I · < o₂)) := by intro hl' apply hl rwa [eval_πs_image' C h (prop_of_isGood C _ hl), ← eval_πs' C h (prop_of_isGood C _ hl), Submodule.apply_mem_span_image_iff_mem_span (injective_πs' C h)] at hl' end Products end Maps section Limit /-! ## The limit case of the induction We relate linear independence in `LocallyConstant (π C (ord I · < o')) ℤ` with linear independence in `LocallyConstant C ℤ`, where `contained C o` and `o' < o`. When `o` is a limit ordinal, we prove that the good products in `LocallyConstant C ℤ` are linearly independent if and only if a certain directed union is linearly independent. Each term in this directed union is in bijection with the good products w.r.t. `π C (ord I · < o')` for an ordinal `o' < o`, and these are linearly independent by the inductive hypothesis. ### Main definitions * `GoodProducts.smaller` is the image of good products coming from a smaller ordinal. * `GoodProducts.range_equiv`: The image of the `GoodProducts` in `C` is equivalent to the union of `smaller C o'` over all ordinals `o' < o`. ### Main results * `Products.limitOrdinal`: for `o` a limit ordinal such that `contained C o`, a product `l` is good w.r.t. `C` iff it there exists an ordinal `o' < o` such that `l` is good w.r.t. `π C (ord I · < o')`. * `GoodProducts.linearIndependent_iff_union_smaller` is the result mentioned above, that the good products are linearly independent iff a directed union is. -/ namespace GoodProducts /-- The image of the `GoodProducts` for `π C (ord I · < o)` in `LocallyConstant C ℤ`. The name `smaller` refers to the setting in which we will use this, when we are mapping in `GoodProducts` from a smaller set, i.e. when `o` is a smaller ordinal than the one `C` is "contained" in. -/ def smaller (o : Ordinal) : Set (LocallyConstant C ℤ) := (πs C o) '' (range (π C (ord I · < o))) /-- The map from the image of the `GoodProducts` in `LocallyConstant (π C (ord I · < o)) ℤ` to `smaller C o` -/ noncomputable def range_equiv_smaller_toFun (o : Ordinal) (x : range (π C (ord I · < o))) : smaller C o := ⟨πs C o ↑x, x.val, x.property, rfl⟩ theorem range_equiv_smaller_toFun_bijective (o : Ordinal) : Function.Bijective (range_equiv_smaller_toFun C o) := by dsimp (config := { unfoldPartialApp := true }) [range_equiv_smaller_toFun] refine ⟨fun a b hab ↦ ?_, fun ⟨a, b, hb⟩ ↦ ?_⟩ · ext1 simp only [Subtype.mk.injEq] at hab exact injective_πs C o hab · use ⟨b, hb.1⟩ simpa only [Subtype.mk.injEq] using hb.2 /-- The equivalence from the image of the `GoodProducts` in `LocallyConstant (π C (ord I · < o)) ℤ` to `smaller C o` -/ noncomputable def range_equiv_smaller (o : Ordinal) : range (π C (ord I · < o)) ≃ smaller C o := Equiv.ofBijective (range_equiv_smaller_toFun C o) (range_equiv_smaller_toFun_bijective C o) theorem smaller_factorization (o : Ordinal) : (fun (p : smaller C o) ↦ p.1) ∘ (range_equiv_smaller C o).toFun = (πs C o) ∘ (fun (p : range (π C (ord I · < o))) ↦ p.1) := by rfl
Mathlib/Topology/Category/Profinite/Nobeling.lean
1,021
1,027
theorem linearIndependent_iff_smaller (o : Ordinal) : LinearIndependent ℤ (GoodProducts.eval (π C (ord I · < o))) ↔ LinearIndependent ℤ (fun (p : smaller C o) ↦ p.1) := by
rw [GoodProducts.linearIndependent_iff_range, ← LinearMap.linearIndependent_iff (πs C o) (LinearMap.ker_eq_bot_of_injective (injective_πs _ _)), ← smaller_factorization C o] exact linearIndependent_equiv _
/- 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}
Mathlib/Analysis/Convex/Cone/Basic.lean
641
642
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]
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Shapes.NormalMono.Equalizers import Mathlib.CategoryTheory.Abelian.Images import Mathlib.CategoryTheory.Preadditive.Basic #align_import category_theory.abelian.non_preadditive from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3" /-! # Every NonPreadditiveAbelian category is preadditive In mathlib, we define an abelian category as a preadditive category with a zero object, kernels and cokernels, products and coproducts and in which every monomorphism and epimorphism is normal. While virtually every interesting abelian category has a natural preadditive structure (which is why it is included in the definition), preadditivity is not actually needed: Every category that has all of the other properties appearing in the definition of an abelian category admits a preadditive structure. This is the construction we carry out in this file. The proof proceeds in roughly five steps: 1. Prove some results (for example that all equalizers exist) that would be trivial if we already had the preadditive structure but are a bit of work without it. 2. Develop images and coimages to show that every monomorphism is the kernel of its cokernel. The results of the first two steps are also useful for the "normal" development of abelian categories, and will be used there. 3. For every object `A`, define a "subtraction" morphism `σ : A ⨯ A ⟶ A` and use it to define subtraction on morphisms as `f - g := prod.lift f g ≫ σ`. 4. Prove a small number of identities about this subtraction from the definition of `σ`. 5. From these identities, prove a large number of other identities that imply that defining `f + g := f - (0 - g)` indeed gives an abelian group structure on morphisms such that composition is bilinear. The construction is non-trivial and it is quite remarkable that this abelian group structure can be constructed purely from the existence of a few limits and colimits. Even more remarkably, since abelian categories admit exactly one preadditive structure (see `subsingletonPreadditiveOfHasBinaryBiproducts`), the construction manages to exactly reconstruct any natural preadditive structure the category may have. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section open CategoryTheory open CategoryTheory.Limits namespace CategoryTheory section universe v u variable (C : Type u) [Category.{v} C] /-- We call a category `NonPreadditiveAbelian` if it has a zero object, kernels, cokernels, binary products and coproducts, and every monomorphism and every epimorphism is normal. -/ class NonPreadditiveAbelian extends HasZeroMorphisms C, NormalMonoCategory C, NormalEpiCategory C where [has_zero_object : HasZeroObject C] [has_kernels : HasKernels C] [has_cokernels : HasCokernels C] [has_finite_products : HasFiniteProducts C] [has_finite_coproducts : HasFiniteCoproducts C] #align category_theory.non_preadditive_abelian CategoryTheory.NonPreadditiveAbelian attribute [instance] NonPreadditiveAbelian.has_zero_object attribute [instance] NonPreadditiveAbelian.has_kernels attribute [instance] NonPreadditiveAbelian.has_cokernels attribute [instance] NonPreadditiveAbelian.has_finite_products attribute [instance] NonPreadditiveAbelian.has_finite_coproducts end end CategoryTheory open CategoryTheory universe v u variable {C : Type u} [Category.{v} C] [NonPreadditiveAbelian C] namespace CategoryTheory.NonPreadditiveAbelian section Factor variable {P Q : C} (f : P ⟶ Q) /-- The map `p : P ⟶ image f` is an epimorphism -/ instance : Epi (Abelian.factorThruImage f) := let I := Abelian.image f let p := Abelian.factorThruImage f let i := kernel.ι (cokernel.π f) -- It will suffice to consider some g : I ⟶ R such that p ≫ g = 0 and show that g = 0. NormalMonoCategory.epi_of_zero_cancel _ fun R (g : I ⟶ R) (hpg : p ≫ g = 0) => by -- Since C is abelian, u := ker g ≫ i is the kernel of some morphism h. let u := kernel.ι g ≫ i haveI : Mono u := mono_comp _ _ haveI hu := normalMonoOfMono u let h := hu.g -- By hypothesis, p factors through the kernel of g via some t. obtain ⟨t, ht⟩ := kernel.lift' g p hpg have fh : f ≫ h = 0 := calc f ≫ h = (p ≫ i) ≫ h := (Abelian.image.fac f).symm ▸ rfl _ = ((t ≫ kernel.ι g) ≫ i) ≫ h := ht ▸ rfl _ = t ≫ u ≫ h := by simp only [u, Category.assoc] _ = t ≫ 0 := hu.w ▸ rfl _ = 0 := HasZeroMorphisms.comp_zero _ _ -- h factors through the cokernel of f via some l. obtain ⟨l, hl⟩ := cokernel.desc' f h fh have hih : i ≫ h = 0 := calc i ≫ h = i ≫ cokernel.π f ≫ l := hl ▸ rfl _ = 0 ≫ l := by rw [← Category.assoc, kernel.condition] _ = 0 := zero_comp -- i factors through u = ker h via some s. obtain ⟨s, hs⟩ := NormalMono.lift' u i hih have hs' : (s ≫ kernel.ι g) ≫ i = 𝟙 I ≫ i := by rw [Category.assoc, hs, Category.id_comp] haveI : Epi (kernel.ι g) := epi_of_epi_fac ((cancel_mono _).1 hs') -- ker g is an epimorphism, but ker g ≫ g = 0 = ker g ≫ 0, so g = 0 as required. exact zero_of_epi_comp _ (kernel.condition g) instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) := isIso_of_mono_of_epi <| Abelian.factorThruImage f #align category_theory.non_preadditive_abelian.is_iso_factor_thru_image CategoryTheory.NonPreadditiveAbelian.isIso_factorThruImage /-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/ instance : Mono (Abelian.factorThruCoimage f) := let I := Abelian.coimage f let i := Abelian.factorThruCoimage f let p := cokernel.π (kernel.ι f) NormalEpiCategory.mono_of_cancel_zero _ fun R (g : R ⟶ I) (hgi : g ≫ i = 0) => by -- Since C is abelian, u := p ≫ coker g is the cokernel of some morphism h. let u := p ≫ cokernel.π g haveI : Epi u := epi_comp _ _ haveI hu := normalEpiOfEpi u let h := hu.g -- By hypothesis, i factors through the cokernel of g via some t. obtain ⟨t, ht⟩ := cokernel.desc' g i hgi have hf : h ≫ f = 0 := calc h ≫ f = h ≫ p ≫ i := (Abelian.coimage.fac f).symm ▸ rfl _ = h ≫ p ≫ cokernel.π g ≫ t := ht ▸ rfl _ = h ≫ u ≫ t := by simp only [u, Category.assoc] _ = 0 ≫ t := by rw [← Category.assoc, hu.w] _ = 0 := zero_comp -- h factors through the kernel of f via some l. obtain ⟨l, hl⟩ := kernel.lift' f h hf have hhp : h ≫ p = 0 := calc h ≫ p = (l ≫ kernel.ι f) ≫ p := hl ▸ rfl _ = l ≫ 0 := by rw [Category.assoc, cokernel.condition] _ = 0 := comp_zero -- p factors through u = coker h via some s. obtain ⟨s, hs⟩ := NormalEpi.desc' u p hhp have hs' : p ≫ cokernel.π g ≫ s = p ≫ 𝟙 I := by rw [← Category.assoc, hs, Category.comp_id] haveI : Mono (cokernel.π g) := mono_of_mono_fac ((cancel_epi _).1 hs') -- coker g is a monomorphism, but g ≫ coker g = 0 = 0 ≫ coker g, so g = 0 as required. exact zero_of_comp_mono _ (cokernel.condition g) instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) := isIso_of_mono_of_epi _ #align category_theory.non_preadditive_abelian.is_iso_factor_thru_coimage CategoryTheory.NonPreadditiveAbelian.isIso_factorThruCoimage end Factor section CokernelOfKernel variable {X Y : C} {f : X ⟶ Y} /-- In a `NonPreadditiveAbelian` category, an epi is the cokernel of its kernel. More precisely: If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel of `Fork.ι s`. -/ def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) : IsColimit (CokernelCofork.ofπ f (KernelFork.condition s)) := IsCokernel.cokernelIso _ _ (cokernel.ofIsoComp _ _ (Limits.IsLimit.conePointUniqueUpToIso (limit.isLimit _) h) (ConeMorphism.w (Limits.IsLimit.uniqueUpToIso (limit.isLimit _) h).hom _)) (asIso <| Abelian.factorThruCoimage f) (Abelian.coimage.fac f) #align category_theory.non_preadditive_abelian.epi_is_cokernel_of_kernel CategoryTheory.NonPreadditiveAbelian.epiIsCokernelOfKernel /-- In a `NonPreadditiveAbelian` category, a mono is the kernel of its cokernel. More precisely: If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel of `Cofork.π s`. -/ def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) : IsLimit (KernelFork.ofι f (CokernelCofork.condition s)) := IsKernel.isoKernel _ _ (kernel.ofCompIso _ _ (Limits.IsColimit.coconePointUniqueUpToIso h (colimit.isColimit _)) (CoconeMorphism.w (Limits.IsColimit.uniqueUpToIso h <| colimit.isColimit _).hom _)) (asIso <| Abelian.factorThruImage f) (Abelian.image.fac f) #align category_theory.non_preadditive_abelian.mono_is_kernel_of_cokernel CategoryTheory.NonPreadditiveAbelian.monoIsKernelOfCokernel end CokernelOfKernel section /-- The composite `A ⟶ A ⨯ A ⟶ cokernel (Δ A)`, where the first map is `(𝟙 A, 0)` and the second map is the canonical projection into the cokernel. -/ abbrev r (A : C) : A ⟶ cokernel (diag A) := prod.lift (𝟙 A) 0 ≫ cokernel.π (diag A) #align category_theory.non_preadditive_abelian.r CategoryTheory.NonPreadditiveAbelian.r instance mono_Δ {A : C} : Mono (diag A) := mono_of_mono_fac <| prod.lift_fst _ _ #align category_theory.non_preadditive_abelian.mono_Δ CategoryTheory.NonPreadditiveAbelian.mono_Δ instance mono_r {A : C} : Mono (r A) := by let hl : IsLimit (KernelFork.ofι (diag A) (cokernel.condition (diag A))) := monoIsKernelOfCokernel _ (colimit.isColimit _) apply NormalEpiCategory.mono_of_cancel_zero intro Z x hx have hxx : (x ≫ prod.lift (𝟙 A) (0 : A ⟶ A)) ≫ cokernel.π (diag A) = 0 := by rw [Category.assoc, hx] obtain ⟨y, hy⟩ := KernelFork.IsLimit.lift' hl _ hxx rw [KernelFork.ι_ofι] at hy have hyy : y = 0 := by erw [← Category.comp_id y, ← Limits.prod.lift_snd (𝟙 A) (𝟙 A), ← Category.assoc, hy, Category.assoc, prod.lift_snd, HasZeroMorphisms.comp_zero] haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _) apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1 rw [← hy, hyy, zero_comp, zero_comp] #align category_theory.non_preadditive_abelian.mono_r CategoryTheory.NonPreadditiveAbelian.mono_r instance epi_r {A : C} : Epi (r A) := by have hlp : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ Limits.prod.snd = 0 := prod.lift_snd _ _ let hp1 : IsLimit (KernelFork.ofι (prod.lift (𝟙 A) (0 : A ⟶ A)) hlp) := by refine Fork.IsLimit.mk _ (fun s => Fork.ι s ≫ Limits.prod.fst) ?_ ?_ · intro s apply prod.hom_ext <;> simp · intro s m h haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _) apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1 convert h apply prod.hom_ext <;> simp let hp2 : IsColimit (CokernelCofork.ofπ (Limits.prod.snd : A ⨯ A ⟶ A) hlp) := epiIsCokernelOfKernel _ hp1 apply NormalMonoCategory.epi_of_zero_cancel intro Z z hz have h : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ cokernel.π (diag A) ≫ z = 0 := by rw [← Category.assoc, hz] obtain ⟨t, ht⟩ := CokernelCofork.IsColimit.desc' hp2 _ h rw [CokernelCofork.π_ofπ] at ht have htt : t = 0 := by rw [← Category.id_comp t] change 𝟙 A ≫ t = 0 rw [← Limits.prod.lift_snd (𝟙 A) (𝟙 A), Category.assoc, ht, ← Category.assoc, cokernel.condition, zero_comp] apply (cancel_epi (cokernel.π (diag A))).1 rw [← ht, htt, comp_zero, comp_zero] #align category_theory.non_preadditive_abelian.epi_r CategoryTheory.NonPreadditiveAbelian.epi_r instance isIso_r {A : C} : IsIso (r A) := isIso_of_mono_of_epi _ #align category_theory.non_preadditive_abelian.is_iso_r CategoryTheory.NonPreadditiveAbelian.isIso_r /-- The composite `A ⨯ A ⟶ cokernel (diag A) ⟶ A` given by the natural projection into the cokernel followed by the inverse of `r`. In the category of modules, using the normal kernels and cokernels, this map is equal to the map `(a, b) ↦ a - b`, hence the name `σ` for "subtraction". -/ abbrev σ {A : C} : A ⨯ A ⟶ A := cokernel.π (diag A) ≫ inv (r A) #align category_theory.non_preadditive_abelian.σ CategoryTheory.NonPreadditiveAbelian.σ end -- Porting note (#10618): simp can prove these @[reassoc] theorem diag_σ {X : C} : diag X ≫ σ = 0 := by rw [cokernel.condition_assoc, zero_comp] #align category_theory.non_preadditive_abelian.diag_σ CategoryTheory.NonPreadditiveAbelian.diag_σ @[reassoc (attr := simp)] theorem lift_σ {X : C} : prod.lift (𝟙 X) 0 ≫ σ = 𝟙 X := by rw [← Category.assoc, IsIso.hom_inv_id] #align category_theory.non_preadditive_abelian.lift_σ CategoryTheory.NonPreadditiveAbelian.lift_σ @[reassoc] theorem lift_map {X Y : C} (f : X ⟶ Y) : prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f = f ≫ prod.lift (𝟙 Y) 0 := by simp #align category_theory.non_preadditive_abelian.lift_map CategoryTheory.NonPreadditiveAbelian.lift_map /-- σ is a cokernel of Δ X. -/ def isColimitσ {X : C} : IsColimit (CokernelCofork.ofπ (σ : X ⨯ X ⟶ X) diag_σ) := cokernel.cokernelIso _ σ (asIso (r X)).symm (by rw [Iso.symm_hom, asIso_inv]) #align category_theory.non_preadditive_abelian.is_colimit_σ CategoryTheory.NonPreadditiveAbelian.isColimitσ /-- This is the key identity satisfied by `σ`. -/ theorem σ_comp {X Y : C} (f : X ⟶ Y) : σ ≫ f = Limits.prod.map f f ≫ σ := by obtain ⟨g, hg⟩ := CokernelCofork.IsColimit.desc' isColimitσ (Limits.prod.map f f ≫ σ) (by rw [prod.diag_map_assoc, diag_σ, comp_zero]) suffices hfg : f = g by rw [← hg, Cofork.π_ofπ, hfg] calc f = f ≫ prod.lift (𝟙 Y) 0 ≫ σ := by rw [lift_σ, Category.comp_id] _ = prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f ≫ σ := by rw [lift_map_assoc] _ = prod.lift (𝟙 X) 0 ≫ σ ≫ g := by rw [← hg, CokernelCofork.π_ofπ] _ = g := by rw [← Category.assoc, lift_σ, Category.id_comp] #align category_theory.non_preadditive_abelian.σ_comp CategoryTheory.NonPreadditiveAbelian.σ_comp section -- We write `f - g` for `prod.lift f g ≫ σ`. /-- Subtraction of morphisms in a `NonPreadditiveAbelian` category. -/ def hasSub {X Y : C} : Sub (X ⟶ Y) := ⟨fun f g => prod.lift f g ≫ σ⟩ #align category_theory.non_preadditive_abelian.has_sub CategoryTheory.NonPreadditiveAbelian.hasSub attribute [local instance] hasSub -- We write `-f` for `0 - f`. /-- Negation of morphisms in a `NonPreadditiveAbelian` category. -/ def hasNeg {X Y : C} : Neg (X ⟶ Y) where neg := fun f => 0 - f #align category_theory.non_preadditive_abelian.has_neg CategoryTheory.NonPreadditiveAbelian.hasNeg attribute [local instance] hasNeg -- We write `f + g` for `f - (-g)`. /-- Addition of morphisms in a `NonPreadditiveAbelian` category. -/ def hasAdd {X Y : C} : Add (X ⟶ Y) := ⟨fun f g => f - -g⟩ #align category_theory.non_preadditive_abelian.has_add CategoryTheory.NonPreadditiveAbelian.hasAdd attribute [local instance] hasAdd theorem sub_def {X Y : C} (a b : X ⟶ Y) : a - b = prod.lift a b ≫ σ := rfl #align category_theory.non_preadditive_abelian.sub_def CategoryTheory.NonPreadditiveAbelian.sub_def theorem add_def {X Y : C} (a b : X ⟶ Y) : a + b = a - -b := rfl #align category_theory.non_preadditive_abelian.add_def CategoryTheory.NonPreadditiveAbelian.add_def theorem neg_def {X Y : C} (a : X ⟶ Y) : -a = 0 - a := rfl #align category_theory.non_preadditive_abelian.neg_def CategoryTheory.NonPreadditiveAbelian.neg_def theorem sub_zero {X Y : C} (a : X ⟶ Y) : a - 0 = a := by rw [sub_def] conv_lhs => congr; congr; rw [← Category.comp_id a] case a.g => rw [show 0 = a ≫ (0 : Y ⟶ Y) by simp] rw [← prod.comp_lift, Category.assoc, lift_σ, Category.comp_id] #align category_theory.non_preadditive_abelian.sub_zero CategoryTheory.NonPreadditiveAbelian.sub_zero theorem sub_self {X Y : C} (a : X ⟶ Y) : a - a = 0 := by rw [sub_def, ← Category.comp_id a, ← prod.comp_lift, Category.assoc, diag_σ, comp_zero] #align category_theory.non_preadditive_abelian.sub_self CategoryTheory.NonPreadditiveAbelian.sub_self theorem lift_sub_lift {X Y : C} (a b c d : X ⟶ Y) : prod.lift a b - prod.lift c d = prod.lift (a - c) (b - d) := by simp only [sub_def] ext · rw [Category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_fst, prod.lift_fst, prod.lift_fst] · rw [Category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_snd, prod.lift_snd, prod.lift_snd] #align category_theory.non_preadditive_abelian.lift_sub_lift CategoryTheory.NonPreadditiveAbelian.lift_sub_lift theorem sub_sub_sub {X Y : C} (a b c d : X ⟶ Y) : a - c - (b - d) = a - b - (c - d) := by rw [sub_def, ← lift_sub_lift, sub_def, Category.assoc, σ_comp, prod.lift_map_assoc]; rfl #align category_theory.non_preadditive_abelian.sub_sub_sub CategoryTheory.NonPreadditiveAbelian.sub_sub_sub theorem neg_sub {X Y : C} (a b : X ⟶ Y) : -a - b = -b - a := by conv_lhs => rw [neg_def, ← sub_zero b, sub_sub_sub, sub_zero, ← neg_def] #align category_theory.non_preadditive_abelian.neg_sub CategoryTheory.NonPreadditiveAbelian.neg_sub theorem neg_neg {X Y : C} (a : X ⟶ Y) : - -a = a := by rw [neg_def, neg_def] conv_lhs => congr; rw [← sub_self a] rw [sub_sub_sub, sub_zero, sub_self, sub_zero] #align category_theory.non_preadditive_abelian.neg_neg CategoryTheory.NonPreadditiveAbelian.neg_neg theorem add_comm {X Y : C} (a b : X ⟶ Y) : a + b = b + a := by rw [add_def] conv_lhs => rw [← neg_neg a] rw [neg_def, neg_def, neg_def, sub_sub_sub] conv_lhs => congr next => skip rw [← neg_def, neg_sub] rw [sub_sub_sub, add_def, ← neg_def, neg_neg b, neg_def] #align category_theory.non_preadditive_abelian.add_comm CategoryTheory.NonPreadditiveAbelian.add_comm theorem add_neg {X Y : C} (a b : X ⟶ Y) : a + -b = a - b := by rw [add_def, neg_neg] #align category_theory.non_preadditive_abelian.add_neg CategoryTheory.NonPreadditiveAbelian.add_neg theorem add_neg_self {X Y : C} (a : X ⟶ Y) : a + -a = 0 := by rw [add_neg, sub_self] #align category_theory.non_preadditive_abelian.add_neg_self CategoryTheory.NonPreadditiveAbelian.add_neg_self
Mathlib/CategoryTheory/Abelian/NonPreadditive.lean
402
402
theorem neg_add_self {X Y : C} (a : X ⟶ Y) : -a + a = 0 := by
rw [add_comm, add_neg_self]