Context
stringlengths
285
157k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
18
3.69k
theorem
stringlengths
25
2.71k
proof
stringlengths
5
10.6k
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell -/ import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Order.Monotone.Basic #align_import data.nat.choose.basic from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4" /-! # Binomial coefficients This file defines binomial coefficients and proves simple lemmas (i.e. those not requiring more imports). ## Main definition and results * `Nat.choose`: binomial coefficients, defined inductively * `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)` * `Nat.choose_symm`: symmetry of binomial coefficients * `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k` * `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2` * `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements for the ascending factorial. * `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations. The fact that this is indeed the correct counting function for multisets is proved in `Sym.card_sym_eq_multichoose` in `Data.Sym.Card`. * `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`. This is central to the "stars and bars" technique in informal mathematics, where we switch between counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements ("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail. ## Tags binomial coefficient, combination, multicombination, stars and bars -/ open Nat namespace Nat /-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial coefficients. -/ def choose : ℕ → ℕ → ℕ | _, 0 => 1 | 0, _ + 1 => 0 | n + 1, k + 1 => choose n k + choose n (k + 1) #align nat.choose Nat.choose @[simp]
Mathlib/Data/Nat/Choose/Basic.lean
54
54
theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by
cases n <;> rfl
/- 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.Associated import Mathlib.Algebra.Star.Unitary import Mathlib.RingTheory.Int.Basic import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.Ring #align_import number_theory.zsqrtd.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # ℤ[√d] The ring of integers adjoined with a square root of `d : ℤ`. After defining the norm, we show that it is a linearly ordered commutative ring, as well as an integral domain. We provide the universal property, that ring homomorphisms `ℤ√d →+* R` correspond to choices of square roots of `d` in `R`. -/ /-- The ring of integers adjoined with a square root of `d`. These have the form `a + b √d` where `a b : ℤ`. The components are called `re` and `im` by analogy to the negative `d` case. -/ @[ext] structure Zsqrtd (d : ℤ) where re : ℤ im : ℤ deriving DecidableEq #align zsqrtd Zsqrtd #align zsqrtd.ext Zsqrtd.ext_iff prefix:100 "ℤ√" => Zsqrtd namespace Zsqrtd section variable {d : ℤ} /-- Convert an integer to a `ℤ√d` -/ def ofInt (n : ℤ) : ℤ√d := ⟨n, 0⟩ #align zsqrtd.of_int Zsqrtd.ofInt theorem ofInt_re (n : ℤ) : (ofInt n : ℤ√d).re = n := rfl #align zsqrtd.of_int_re Zsqrtd.ofInt_re theorem ofInt_im (n : ℤ) : (ofInt n : ℤ√d).im = 0 := rfl #align zsqrtd.of_int_im Zsqrtd.ofInt_im /-- The zero of the ring -/ instance : Zero (ℤ√d) := ⟨ofInt 0⟩ @[simp] theorem zero_re : (0 : ℤ√d).re = 0 := rfl #align zsqrtd.zero_re Zsqrtd.zero_re @[simp] theorem zero_im : (0 : ℤ√d).im = 0 := rfl #align zsqrtd.zero_im Zsqrtd.zero_im instance : Inhabited (ℤ√d) := ⟨0⟩ /-- The one of the ring -/ instance : One (ℤ√d) := ⟨ofInt 1⟩ @[simp] theorem one_re : (1 : ℤ√d).re = 1 := rfl #align zsqrtd.one_re Zsqrtd.one_re @[simp] theorem one_im : (1 : ℤ√d).im = 0 := rfl #align zsqrtd.one_im Zsqrtd.one_im /-- The representative of `√d` in the ring -/ def sqrtd : ℤ√d := ⟨0, 1⟩ #align zsqrtd.sqrtd Zsqrtd.sqrtd @[simp] theorem sqrtd_re : (sqrtd : ℤ√d).re = 0 := rfl #align zsqrtd.sqrtd_re Zsqrtd.sqrtd_re @[simp] theorem sqrtd_im : (sqrtd : ℤ√d).im = 1 := rfl #align zsqrtd.sqrtd_im Zsqrtd.sqrtd_im /-- Addition of elements of `ℤ√d` -/ instance : Add (ℤ√d) := ⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩ @[simp] theorem add_def (x y x' y' : ℤ) : (⟨x, y⟩ + ⟨x', y'⟩ : ℤ√d) = ⟨x + x', y + y'⟩ := rfl #align zsqrtd.add_def Zsqrtd.add_def @[simp] theorem add_re (z w : ℤ√d) : (z + w).re = z.re + w.re := rfl #align zsqrtd.add_re Zsqrtd.add_re @[simp] theorem add_im (z w : ℤ√d) : (z + w).im = z.im + w.im := rfl #align zsqrtd.add_im Zsqrtd.add_im #noalign zsqrtd.bit0_re #noalign zsqrtd.bit0_im #noalign zsqrtd.bit1_re #noalign zsqrtd.bit1_im /-- Negation in `ℤ√d` -/ instance : Neg (ℤ√d) := ⟨fun z => ⟨-z.1, -z.2⟩⟩ @[simp] theorem neg_re (z : ℤ√d) : (-z).re = -z.re := rfl #align zsqrtd.neg_re Zsqrtd.neg_re @[simp] theorem neg_im (z : ℤ√d) : (-z).im = -z.im := rfl #align zsqrtd.neg_im Zsqrtd.neg_im /-- Multiplication in `ℤ√d` -/ instance : Mul (ℤ√d) := ⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩ @[simp] theorem mul_re (z w : ℤ√d) : (z * w).re = z.re * w.re + d * z.im * w.im := rfl #align zsqrtd.mul_re Zsqrtd.mul_re @[simp] theorem mul_im (z w : ℤ√d) : (z * w).im = z.re * w.im + z.im * w.re := rfl #align zsqrtd.mul_im Zsqrtd.mul_im instance addCommGroup : AddCommGroup (ℤ√d) := by refine { add := (· + ·) zero := (0 : ℤ√d) sub := fun a b => a + -b neg := Neg.neg nsmul := @nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ zsmul := @zsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩) add_assoc := ?_ zero_add := ?_ add_zero := ?_ add_left_neg := ?_ add_comm := ?_ } <;> intros <;> ext <;> simp [add_comm, add_left_comm] @[simp] theorem sub_re (z w : ℤ√d) : (z - w).re = z.re - w.re := rfl @[simp] theorem sub_im (z w : ℤ√d) : (z - w).im = z.im - w.im := rfl instance addGroupWithOne : AddGroupWithOne (ℤ√d) := { Zsqrtd.addCommGroup with natCast := fun n => ofInt n intCast := ofInt one := 1 } instance commRing : CommRing (ℤ√d) := by refine { Zsqrtd.addGroupWithOne with mul := (· * ·) npow := @npowRec (ℤ√d) ⟨1⟩ ⟨(· * ·)⟩, add_comm := ?_ left_distrib := ?_ right_distrib := ?_ zero_mul := ?_ mul_zero := ?_ mul_assoc := ?_ one_mul := ?_ mul_one := ?_ mul_comm := ?_ } <;> intros <;> ext <;> simp <;> ring instance : AddMonoid (ℤ√d) := by infer_instance instance : Monoid (ℤ√d) := by infer_instance instance : CommMonoid (ℤ√d) := by infer_instance instance : CommSemigroup (ℤ√d) := by infer_instance instance : Semigroup (ℤ√d) := by infer_instance instance : AddCommSemigroup (ℤ√d) := by infer_instance instance : AddSemigroup (ℤ√d) := by infer_instance instance : CommSemiring (ℤ√d) := by infer_instance instance : Semiring (ℤ√d) := by infer_instance instance : Ring (ℤ√d) := by infer_instance instance : Distrib (ℤ√d) := by infer_instance /-- Conjugation in `ℤ√d`. The conjugate of `a + b √d` is `a - b √d`. -/ instance : Star (ℤ√d) where star z := ⟨z.1, -z.2⟩ @[simp] theorem star_mk (x y : ℤ) : star (⟨x, y⟩ : ℤ√d) = ⟨x, -y⟩ := rfl #align zsqrtd.star_mk Zsqrtd.star_mk @[simp] theorem star_re (z : ℤ√d) : (star z).re = z.re := rfl #align zsqrtd.star_re Zsqrtd.star_re @[simp] theorem star_im (z : ℤ√d) : (star z).im = -z.im := rfl #align zsqrtd.star_im Zsqrtd.star_im instance : StarRing (ℤ√d) where star_involutive x := Zsqrtd.ext _ _ rfl (neg_neg _) star_mul a b := by ext <;> simp <;> ring star_add a b := Zsqrtd.ext _ _ rfl (neg_add _ _) -- Porting note: proof was `by decide` instance nontrivial : Nontrivial (ℤ√d) := ⟨⟨0, 1, (Zsqrtd.ext_iff 0 1).not.mpr (by simp)⟩⟩ @[simp] theorem natCast_re (n : ℕ) : (n : ℤ√d).re = n := rfl #align zsqrtd.coe_nat_re Zsqrtd.natCast_re @[simp] theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : ℤ√d).re = n := rfl @[simp] theorem natCast_im (n : ℕ) : (n : ℤ√d).im = 0 := rfl #align zsqrtd.coe_nat_im Zsqrtd.natCast_im @[simp] theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : ℤ√d).im = 0 := rfl theorem natCast_val (n : ℕ) : (n : ℤ√d) = ⟨n, 0⟩ := rfl #align zsqrtd.coe_nat_val Zsqrtd.natCast_val @[simp] theorem intCast_re (n : ℤ) : (n : ℤ√d).re = n := by cases n <;> rfl #align zsqrtd.coe_int_re Zsqrtd.intCast_re @[simp] theorem intCast_im (n : ℤ) : (n : ℤ√d).im = 0 := by cases n <;> rfl #align zsqrtd.coe_int_im Zsqrtd.intCast_im theorem intCast_val (n : ℤ) : (n : ℤ√d) = ⟨n, 0⟩ := by ext <;> simp #align zsqrtd.coe_int_val Zsqrtd.intCast_val instance : CharZero (ℤ√d) where cast_injective m n := by simp [Zsqrtd.ext_iff] @[simp] theorem ofInt_eq_intCast (n : ℤ) : (ofInt n : ℤ√d) = n := by ext <;> simp [ofInt_re, ofInt_im] #align zsqrtd.of_int_eq_coe Zsqrtd.ofInt_eq_intCast @[deprecated (since := "2024-04-05")] alias coe_nat_re := natCast_re @[deprecated (since := "2024-04-05")] alias coe_nat_im := natCast_im @[deprecated (since := "2024-04-05")] alias coe_nat_val := natCast_val @[deprecated (since := "2024-04-05")] alias coe_int_re := intCast_re @[deprecated (since := "2024-04-05")] alias coe_int_im := intCast_im @[deprecated (since := "2024-04-05")] alias coe_int_val := intCast_val @[deprecated (since := "2024-04-05")] alias ofInt_eq_coe := ofInt_eq_intCast @[simp] theorem smul_val (n x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp #align zsqrtd.smul_val Zsqrtd.smul_val theorem smul_re (a : ℤ) (b : ℤ√d) : (↑a * b).re = a * b.re := by simp #align zsqrtd.smul_re Zsqrtd.smul_re theorem smul_im (a : ℤ) (b : ℤ√d) : (↑a * b).im = a * b.im := by simp #align zsqrtd.smul_im Zsqrtd.smul_im @[simp] theorem muld_val (x y : ℤ) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp #align zsqrtd.muld_val Zsqrtd.muld_val @[simp] theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp #align zsqrtd.dmuld Zsqrtd.dmuld @[simp] theorem smuld_val (n x y : ℤ) : sqrtd * (n : ℤ√d) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp #align zsqrtd.smuld_val Zsqrtd.smuld_val theorem decompose {x y : ℤ} : (⟨x, y⟩ : ℤ√d) = x + sqrtd (d := d) * y := by ext <;> simp #align zsqrtd.decompose Zsqrtd.decompose theorem mul_star {x y : ℤ} : (⟨x, y⟩ * star ⟨x, y⟩ : ℤ√d) = x * x - d * y * y := by ext <;> simp [sub_eq_add_neg, mul_comm] #align zsqrtd.mul_star Zsqrtd.mul_star @[deprecated (since := "2024-05-25")] alias coe_int_add := Int.cast_add @[deprecated (since := "2024-05-25")] alias coe_int_sub := Int.cast_sub @[deprecated (since := "2024-05-25")] alias coe_int_mul := Int.cast_mul @[deprecated (since := "2024-05-25")] alias coe_int_inj := Int.cast_inj theorem intCast_dvd (z : ℤ) (a : ℤ√d) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by constructor · rintro ⟨x, rfl⟩ simp only [add_zero, intCast_re, zero_mul, mul_im, dvd_mul_right, and_self_iff, mul_re, mul_zero, intCast_im] · rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩ use ⟨r, i⟩ rw [smul_val, Zsqrtd.ext_iff] exact ⟨hr, hi⟩ #align zsqrtd.coe_int_dvd_iff Zsqrtd.intCast_dvd @[simp, norm_cast] theorem intCast_dvd_intCast (a b : ℤ) : (a : ℤ√d) ∣ b ↔ a ∣ b := by rw [intCast_dvd] constructor · rintro ⟨hre, -⟩ rwa [intCast_re] at hre · rw [intCast_re, intCast_im] exact fun hc => ⟨hc, dvd_zero a⟩ #align zsqrtd.coe_int_dvd_coe_int Zsqrtd.intCast_dvd_intCast @[deprecated (since := "2024-05-25")] alias coe_int_dvd_iff := intCast_dvd @[deprecated (since := "2024-05-25")] alias coe_int_dvd_coe_int := intCast_dvd_intCast protected theorem eq_of_smul_eq_smul_left {a : ℤ} {b c : ℤ√d} (ha : a ≠ 0) (h : ↑a * b = a * c) : b = c := by rw [Zsqrtd.ext_iff] at h ⊢ apply And.imp _ _ h <;> simpa only [smul_re, smul_im] using mul_left_cancel₀ ha #align zsqrtd.eq_of_smul_eq_smul_left Zsqrtd.eq_of_smul_eq_smul_left section Gcd theorem gcd_eq_zero_iff (a : ℤ√d) : Int.gcd a.re a.im = 0 ↔ a = 0 := by simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, eq_self_iff_true, zero_im, zero_re] #align zsqrtd.gcd_eq_zero_iff Zsqrtd.gcd_eq_zero_iff theorem gcd_pos_iff (a : ℤ√d) : 0 < Int.gcd a.re a.im ↔ a ≠ 0 := pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff #align zsqrtd.gcd_pos_iff Zsqrtd.gcd_pos_iff theorem coprime_of_dvd_coprime {a b : ℤ√d} (hcoprime : IsCoprime a.re a.im) (hdvd : b ∣ a) : IsCoprime b.re b.im := by apply isCoprime_of_dvd · rintro ⟨hre, him⟩ obtain rfl : b = 0 := Zsqrtd.ext b 0 hre him rw [zero_dvd_iff] at hdvd simp [hdvd, zero_im, zero_re, not_isCoprime_zero_zero] at hcoprime · rintro z hz - hzdvdu hzdvdv apply hz obtain ⟨ha, hb⟩ : z ∣ a.re ∧ z ∣ a.im := by rw [← intCast_dvd] apply dvd_trans _ hdvd rw [intCast_dvd] exact ⟨hzdvdu, hzdvdv⟩ exact hcoprime.isUnit_of_dvd' ha hb #align zsqrtd.coprime_of_dvd_coprime Zsqrtd.coprime_of_dvd_coprime theorem exists_coprime_of_gcd_pos {a : ℤ√d} (hgcd : 0 < Int.gcd a.re a.im) : ∃ b : ℤ√d, a = ((Int.gcd a.re a.im : ℤ) : ℤ√d) * b ∧ IsCoprime b.re b.im := by obtain ⟨re, im, H1, Hre, Him⟩ := Int.exists_gcd_one hgcd rw [mul_comm] at Hre Him refine ⟨⟨re, im⟩, ?_, ?_⟩ · rw [smul_val, ← Hre, ← Him] · rw [← Int.gcd_eq_one_iff_coprime, H1] #align zsqrtd.exists_coprime_of_gcd_pos Zsqrtd.exists_coprime_of_gcd_pos end Gcd /-- Read `SqLe a c b d` as `a √c ≤ b √d` -/ def SqLe (a c b d : ℕ) : Prop := c * a * a ≤ d * b * b #align zsqrtd.sq_le Zsqrtd.SqLe theorem sqLe_of_le {c d x y z w : ℕ} (xz : z ≤ x) (yw : y ≤ w) (xy : SqLe x c y d) : SqLe z c w d := le_trans (mul_le_mul (Nat.mul_le_mul_left _ xz) xz (Nat.zero_le _) (Nat.zero_le _)) <| le_trans xy (mul_le_mul (Nat.mul_le_mul_left _ yw) yw (Nat.zero_le _) (Nat.zero_le _)) #align zsqrtd.sq_le_of_le Zsqrtd.sqLe_of_le theorem sqLe_add_mixed {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) : c * (x * z) ≤ d * (y * w) := Nat.mul_self_le_mul_self_iff.1 <| by simpa [mul_comm, mul_left_comm] using mul_le_mul xy zw (Nat.zero_le _) (Nat.zero_le _) #align zsqrtd.sq_le_add_mixed Zsqrtd.sqLe_add_mixed theorem sqLe_add {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) : SqLe (x + z) c (y + w) d := by have xz := sqLe_add_mixed xy zw simp? [SqLe, mul_assoc] at xy zw says simp only [SqLe, mul_assoc] at xy zw simp [SqLe, mul_add, mul_comm, mul_left_comm, add_le_add, *] #align zsqrtd.sq_le_add Zsqrtd.sqLe_add theorem sqLe_cancel {c d x y z w : ℕ} (zw : SqLe y d x c) (h : SqLe (x + z) c (y + w) d) : SqLe z c w d := by apply le_of_not_gt intro l refine not_le_of_gt ?_ h simp only [SqLe, mul_add, mul_comm, mul_left_comm, add_assoc, gt_iff_lt] have hm := sqLe_add_mixed zw (le_of_lt l) simp only [SqLe, mul_assoc, gt_iff_lt] at l zw exact lt_of_le_of_lt (add_le_add_right zw _) (add_lt_add_left (add_lt_add_of_le_of_lt hm (add_lt_add_of_le_of_lt hm l)) _) #align zsqrtd.sq_le_cancel Zsqrtd.sqLe_cancel theorem sqLe_smul {c d x y : ℕ} (n : ℕ) (xy : SqLe x c y d) : SqLe (n * x) c (n * y) d := by simpa [SqLe, mul_left_comm, mul_assoc] using Nat.mul_le_mul_left (n * n) xy #align zsqrtd.sq_le_smul Zsqrtd.sqLe_smul theorem sqLe_mul {d x y z w : ℕ} : (SqLe x 1 y d → SqLe z 1 w d → SqLe (x * w + y * z) d (x * z + d * y * w) 1) ∧ (SqLe x 1 y d → SqLe w d z 1 → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 → SqLe z 1 w d → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 → SqLe w d z 1 → SqLe (x * w + y * z) d (x * z + d * y * w) 1) := by refine ⟨?_, ?_, ?_, ?_⟩ <;> · intro xy zw have := Int.mul_nonneg (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le xy)) (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le zw)) refine Int.le_of_ofNat_le_ofNat (le_of_sub_nonneg ?_) convert this using 1 simp only [one_mul, Int.ofNat_add, Int.ofNat_mul] ring #align zsqrtd.sq_le_mul Zsqrtd.sqLe_mul open Int in /-- "Generalized" `nonneg`. `nonnegg c d x y` means `a √c + b √d ≥ 0`; we are interested in the case `c = 1` but this is more symmetric -/ def Nonnegg (c d : ℕ) : ℤ → ℤ → Prop | (a : ℕ), (b : ℕ) => True | (a : ℕ), -[b+1] => SqLe (b + 1) c a d | -[a+1], (b : ℕ) => SqLe (a + 1) d b c | -[_+1], -[_+1] => False #align zsqrtd.nonnegg Zsqrtd.Nonnegg theorem nonnegg_comm {c d : ℕ} {x y : ℤ} : Nonnegg c d x y = Nonnegg d c y x := by induction x <;> induction y <;> rfl #align zsqrtd.nonnegg_comm Zsqrtd.nonnegg_comm theorem nonnegg_neg_pos {c d} : ∀ {a b : ℕ}, Nonnegg c d (-a) b ↔ SqLe a d b c | 0, b => ⟨by simp [SqLe, Nat.zero_le], fun _ => trivial⟩ | a + 1, b => by rw [← Int.negSucc_coe]; rfl #align zsqrtd.nonnegg_neg_pos Zsqrtd.nonnegg_neg_pos theorem nonnegg_pos_neg {c d} {a b : ℕ} : Nonnegg c d a (-b) ↔ SqLe b c a d := by rw [nonnegg_comm]; exact nonnegg_neg_pos #align zsqrtd.nonnegg_pos_neg Zsqrtd.nonnegg_pos_neg open Int in theorem nonnegg_cases_right {c d} {a : ℕ} : ∀ {b : ℤ}, (∀ x : ℕ, b = -x → SqLe x c a d) → Nonnegg c d a b | (b : Nat), _ => trivial | -[b+1], h => h (b + 1) rfl #align zsqrtd.nonnegg_cases_right Zsqrtd.nonnegg_cases_right theorem nonnegg_cases_left {c d} {b : ℕ} {a : ℤ} (h : ∀ x : ℕ, a = -x → SqLe x d b c) : Nonnegg c d a b := cast nonnegg_comm (nonnegg_cases_right h) #align zsqrtd.nonnegg_cases_left Zsqrtd.nonnegg_cases_left section Norm /-- The norm of an element of `ℤ[√d]`. -/ def norm (n : ℤ√d) : ℤ := n.re * n.re - d * n.im * n.im #align zsqrtd.norm Zsqrtd.norm theorem norm_def (n : ℤ√d) : n.norm = n.re * n.re - d * n.im * n.im := rfl #align zsqrtd.norm_def Zsqrtd.norm_def @[simp] theorem norm_zero : norm (0 : ℤ√d) = 0 := by simp [norm] #align zsqrtd.norm_zero Zsqrtd.norm_zero @[simp] theorem norm_one : norm (1 : ℤ√d) = 1 := by simp [norm] #align zsqrtd.norm_one Zsqrtd.norm_one @[simp] theorem norm_intCast (n : ℤ) : norm (n : ℤ√d) = n * n := by simp [norm] #align zsqrtd.norm_int_cast Zsqrtd.norm_intCast @[deprecated (since := "2024-04-17")] alias norm_int_cast := norm_intCast @[simp] theorem norm_natCast (n : ℕ) : norm (n : ℤ√d) = n * n := norm_intCast n #align zsqrtd.norm_nat_cast Zsqrtd.norm_natCast @[deprecated (since := "2024-04-17")] alias norm_nat_cast := norm_natCast @[simp] theorem norm_mul (n m : ℤ√d) : norm (n * m) = norm n * norm m := by simp only [norm, mul_im, mul_re] ring #align zsqrtd.norm_mul Zsqrtd.norm_mul /-- `norm` as a `MonoidHom`. -/ def normMonoidHom : ℤ√d →* ℤ where toFun := norm map_mul' := norm_mul map_one' := norm_one #align zsqrtd.norm_monoid_hom Zsqrtd.normMonoidHom theorem norm_eq_mul_conj (n : ℤ√d) : (norm n : ℤ√d) = n * star n := by ext <;> simp [norm, star, mul_comm, sub_eq_add_neg] #align zsqrtd.norm_eq_mul_conj Zsqrtd.norm_eq_mul_conj @[simp] theorem norm_neg (x : ℤ√d) : (-x).norm = x.norm := -- Porting note: replaced `simp` with `rw` -- See https://github.com/leanprover-community/mathlib4/issues/5026 Int.cast_inj.1 <| by rw [norm_eq_mul_conj, star_neg, neg_mul_neg, norm_eq_mul_conj] #align zsqrtd.norm_neg Zsqrtd.norm_neg @[simp] theorem norm_conj (x : ℤ√d) : (star x).norm = x.norm := -- Porting note: replaced `simp` with `rw` -- See https://github.com/leanprover-community/mathlib4/issues/5026 Int.cast_inj.1 <| by rw [norm_eq_mul_conj, star_star, mul_comm, norm_eq_mul_conj] #align zsqrtd.norm_conj Zsqrtd.norm_conj theorem norm_nonneg (hd : d ≤ 0) (n : ℤ√d) : 0 ≤ n.norm := add_nonneg (mul_self_nonneg _) (by rw [mul_assoc, neg_mul_eq_neg_mul] exact mul_nonneg (neg_nonneg.2 hd) (mul_self_nonneg _)) #align zsqrtd.norm_nonneg Zsqrtd.norm_nonneg theorem norm_eq_one_iff {x : ℤ√d} : x.norm.natAbs = 1 ↔ IsUnit x := ⟨fun h => isUnit_iff_dvd_one.2 <| (le_total 0 (norm x)).casesOn (fun hx => ⟨star x, by rwa [← Int.natCast_inj, Int.natAbs_of_nonneg hx, ← @Int.cast_inj (ℤ√d) _ _, norm_eq_mul_conj, eq_comm] at h⟩) fun hx => ⟨-star x, by rwa [← Int.natCast_inj, Int.ofNat_natAbs_of_nonpos hx, ← @Int.cast_inj (ℤ√d) _ _, Int.cast_neg, norm_eq_mul_conj, neg_mul_eq_mul_neg, eq_comm] at h⟩, fun h => by let ⟨y, hy⟩ := isUnit_iff_dvd_one.1 h have := congr_arg (Int.natAbs ∘ norm) hy rw [Function.comp_apply, Function.comp_apply, norm_mul, Int.natAbs_mul, norm_one, Int.natAbs_one, eq_comm, mul_eq_one] at this exact this.1⟩ #align zsqrtd.norm_eq_one_iff Zsqrtd.norm_eq_one_iff theorem isUnit_iff_norm_isUnit {d : ℤ} (z : ℤ√d) : IsUnit z ↔ IsUnit z.norm := by rw [Int.isUnit_iff_natAbs_eq, norm_eq_one_iff] #align zsqrtd.is_unit_iff_norm_is_unit Zsqrtd.isUnit_iff_norm_isUnit theorem norm_eq_one_iff' {d : ℤ} (hd : d ≤ 0) (z : ℤ√d) : z.norm = 1 ↔ IsUnit z := by rw [← norm_eq_one_iff, ← Int.natCast_inj, Int.natAbs_of_nonneg (norm_nonneg hd z), Int.ofNat_one] #align zsqrtd.norm_eq_one_iff' Zsqrtd.norm_eq_one_iff' theorem norm_eq_zero_iff {d : ℤ} (hd : d < 0) (z : ℤ√d) : z.norm = 0 ↔ z = 0 := by constructor · intro h rw [norm_def, sub_eq_add_neg, mul_assoc] at h have left := mul_self_nonneg z.re have right := neg_nonneg.mpr (mul_nonpos_of_nonpos_of_nonneg hd.le (mul_self_nonneg z.im)) obtain ⟨ha, hb⟩ := (add_eq_zero_iff' left right).mp h ext <;> apply eq_zero_of_mul_self_eq_zero · exact ha · rw [neg_eq_zero, mul_eq_zero] at hb exact hb.resolve_left hd.ne · rintro rfl exact norm_zero #align zsqrtd.norm_eq_zero_iff Zsqrtd.norm_eq_zero_iff theorem norm_eq_of_associated {d : ℤ} (hd : d ≤ 0) {x y : ℤ√d} (h : Associated x y) : x.norm = y.norm := by obtain ⟨u, rfl⟩ := h rw [norm_mul, (norm_eq_one_iff' hd _).mpr u.isUnit, mul_one] #align zsqrtd.norm_eq_of_associated Zsqrtd.norm_eq_of_associated end Norm end section variable {d : ℕ} /-- Nonnegativity of an element of `ℤ√d`. -/ def Nonneg : ℤ√d → Prop | ⟨a, b⟩ => Nonnegg d 1 a b #align zsqrtd.nonneg Zsqrtd.Nonneg instance : LE (ℤ√d) := ⟨fun a b => Nonneg (b - a)⟩ instance : LT (ℤ√d) := ⟨fun a b => ¬b ≤ a⟩ instance decidableNonnegg (c d a b) : Decidable (Nonnegg c d a b) := by cases a <;> cases b <;> unfold Nonnegg SqLe <;> infer_instance #align zsqrtd.decidable_nonnegg Zsqrtd.decidableNonnegg instance decidableNonneg : ∀ a : ℤ√d, Decidable (Nonneg a) | ⟨_, _⟩ => Zsqrtd.decidableNonnegg _ _ _ _ #align zsqrtd.decidable_nonneg Zsqrtd.decidableNonneg instance decidableLE : @DecidableRel (ℤ√d) (· ≤ ·) := fun _ _ => decidableNonneg _ #align zsqrtd.decidable_le Zsqrtd.decidableLE open Int in theorem nonneg_cases : ∀ {a : ℤ√d}, Nonneg a → ∃ x y : ℕ, a = ⟨x, y⟩ ∨ a = ⟨x, -y⟩ ∨ a = ⟨-x, y⟩ | ⟨(x : ℕ), (y : ℕ)⟩, _ => ⟨x, y, Or.inl rfl⟩ | ⟨(x : ℕ), -[y+1]⟩, _ => ⟨x, y + 1, Or.inr <| Or.inl rfl⟩ | ⟨-[x+1], (y : ℕ)⟩, _ => ⟨x + 1, y, Or.inr <| Or.inr rfl⟩ | ⟨-[_+1], -[_+1]⟩, h => False.elim h #align zsqrtd.nonneg_cases Zsqrtd.nonneg_cases open Int in theorem nonneg_add_lem {x y z w : ℕ} (xy : Nonneg (⟨x, -y⟩ : ℤ√d)) (zw : Nonneg (⟨-z, w⟩ : ℤ√d)) : Nonneg (⟨x, -y⟩ + ⟨-z, w⟩ : ℤ√d) := by have : Nonneg ⟨Int.subNatNat x z, Int.subNatNat w y⟩ := Int.subNatNat_elim x z (fun m n i => SqLe y d m 1 → SqLe n 1 w d → Nonneg ⟨i, Int.subNatNat w y⟩) (fun j k => Int.subNatNat_elim w y (fun m n i => SqLe n d (k + j) 1 → SqLe k 1 m d → Nonneg ⟨Int.ofNat j, i⟩) (fun _ _ _ _ => trivial) fun m n xy zw => sqLe_cancel zw xy) (fun j k => Int.subNatNat_elim w y (fun m n i => SqLe n d k 1 → SqLe (k + j + 1) 1 m d → Nonneg ⟨-[j+1], i⟩) (fun m n xy zw => sqLe_cancel xy zw) fun m n xy zw => let t := Nat.le_trans zw (sqLe_of_le (Nat.le_add_right n (m + 1)) le_rfl xy) have : k + j + 1 ≤ k := Nat.mul_self_le_mul_self_iff.1 (by simpa [one_mul] using t) absurd this (not_le_of_gt <| Nat.succ_le_succ <| Nat.le_add_right _ _)) (nonnegg_pos_neg.1 xy) (nonnegg_neg_pos.1 zw) rw [add_def, neg_add_eq_sub] rwa [Int.subNatNat_eq_coe, Int.subNatNat_eq_coe] at this #align zsqrtd.nonneg_add_lem Zsqrtd.nonneg_add_lem
Mathlib/NumberTheory/Zsqrtd/Basic.lean
679
713
theorem Nonneg.add {a b : ℤ√d} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a + b) := by
rcases nonneg_cases ha with ⟨x, y, rfl | rfl | rfl⟩ <;> rcases nonneg_cases hb with ⟨z, w, rfl | rfl | rfl⟩ · trivial · refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 hb) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro y (by simp [add_comm, *]))) · apply Nat.le_add_left · refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 hb) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro x (by simp [add_comm, *]))) · apply Nat.le_add_left · refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 ha) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro w (by simp [*]))) · apply Nat.le_add_right · have : Nonneg ⟨_, _⟩ := nonnegg_pos_neg.2 (sqLe_add (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb)) rw [Nat.cast_add, Nat.cast_add, neg_add] at this rwa [add_def] -- Porting note: was -- simpa [add_comm] using -- nonnegg_pos_neg.2 (sqLe_add (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb)) · exact nonneg_add_lem ha hb · refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 ha) · dsimp only at h exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro _ h)) · apply Nat.le_add_right · dsimp rw [add_comm, add_comm (y : ℤ)] exact nonneg_add_lem hb ha · have : Nonneg ⟨_, _⟩ := nonnegg_neg_pos.2 (sqLe_add (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb)) rw [Nat.cast_add, Nat.cast_add, neg_add] at this rwa [add_def]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Data.Fin.VecNotation import Mathlib.Logic.Embedding.Set #align_import logic.equiv.fin from "leanprover-community/mathlib"@"bd835ef554f37ef9b804f0903089211f89cb370b" /-! # Equivalences for `Fin n` -/ assert_not_exists MonoidWithZero universe u variable {m n : ℕ} /-- Equivalence between `Fin 0` and `Empty`. -/ def finZeroEquiv : Fin 0 ≃ Empty := Equiv.equivEmpty _ #align fin_zero_equiv finZeroEquiv /-- Equivalence between `Fin 0` and `PEmpty`. -/ def finZeroEquiv' : Fin 0 ≃ PEmpty.{u} := Equiv.equivPEmpty _ #align fin_zero_equiv' finZeroEquiv' /-- Equivalence between `Fin 1` and `Unit`. -/ def finOneEquiv : Fin 1 ≃ Unit := Equiv.equivPUnit _ #align fin_one_equiv finOneEquiv /-- Equivalence between `Fin 2` and `Bool`. -/ def finTwoEquiv : Fin 2 ≃ Bool where toFun := ![false, true] invFun b := b.casesOn 0 1 left_inv := Fin.forall_fin_two.2 <| by simp right_inv := Bool.forall_bool.2 <| by simp #align fin_two_equiv finTwoEquiv /-- `Π i : Fin 2, α i` is equivalent to `α 0 × α 1`. See also `finTwoArrowEquiv` for a non-dependent version and `prodEquivPiFinTwo` for a version with inputs `α β : Type u`. -/ @[simps (config := .asFn)] def piFinTwoEquiv (α : Fin 2 → Type u) : (∀ i, α i) ≃ α 0 × α 1 where toFun f := (f 0, f 1) invFun p := Fin.cons p.1 <| Fin.cons p.2 finZeroElim left_inv _ := funext <| Fin.forall_fin_two.2 ⟨rfl, rfl⟩ right_inv := fun _ => rfl #align pi_fin_two_equiv piFinTwoEquiv #align pi_fin_two_equiv_symm_apply piFinTwoEquiv_symm_apply #align pi_fin_two_equiv_apply piFinTwoEquiv_apply theorem Fin.preimage_apply_01_prod {α : Fin 2 → Type u} (s : Set (α 0)) (t : Set (α 1)) : (fun f : ∀ i, α i => (f 0, f 1)) ⁻¹' s ×ˢ t = Set.pi Set.univ (Fin.cons s <| Fin.cons t finZeroElim) := by ext f simp [Fin.forall_fin_two] #align fin.preimage_apply_01_prod Fin.preimage_apply_01_prod theorem Fin.preimage_apply_01_prod' {α : Type u} (s t : Set α) : (fun f : Fin 2 → α => (f 0, f 1)) ⁻¹' s ×ˢ t = Set.pi Set.univ ![s, t] := @Fin.preimage_apply_01_prod (fun _ => α) s t #align fin.preimage_apply_01_prod' Fin.preimage_apply_01_prod' /-- A product space `α × β` is equivalent to the space `Π i : Fin 2, γ i`, where `γ = Fin.cons α (Fin.cons β finZeroElim)`. See also `piFinTwoEquiv` and `finTwoArrowEquiv`. -/ @[simps! (config := .asFn)] def prodEquivPiFinTwo (α β : Type u) : α × β ≃ ∀ i : Fin 2, ![α, β] i := (piFinTwoEquiv (Fin.cons α (Fin.cons β finZeroElim))).symm #align prod_equiv_pi_fin_two prodEquivPiFinTwo #align prod_equiv_pi_fin_two_apply prodEquivPiFinTwo_apply #align prod_equiv_pi_fin_two_symm_apply prodEquivPiFinTwo_symm_apply /-- The space of functions `Fin 2 → α` is equivalent to `α × α`. See also `piFinTwoEquiv` and `prodEquivPiFinTwo`. -/ @[simps (config := .asFn)] def finTwoArrowEquiv (α : Type*) : (Fin 2 → α) ≃ α × α := { piFinTwoEquiv fun _ => α with invFun := fun x => ![x.1, x.2] } #align fin_two_arrow_equiv finTwoArrowEquiv #align fin_two_arrow_equiv_symm_apply finTwoArrowEquiv_symm_apply #align fin_two_arrow_equiv_apply finTwoArrowEquiv_apply /-- `Π i : Fin 2, α i` is order equivalent to `α 0 × α 1`. See also `OrderIso.finTwoArrowEquiv` for a non-dependent version. -/ def OrderIso.piFinTwoIso (α : Fin 2 → Type u) [∀ i, Preorder (α i)] : (∀ i, α i) ≃o α 0 × α 1 where toEquiv := piFinTwoEquiv α map_rel_iff' := Iff.symm Fin.forall_fin_two #align order_iso.pi_fin_two_iso OrderIso.piFinTwoIso /-- The space of functions `Fin 2 → α` is order equivalent to `α × α`. See also `OrderIso.piFinTwoIso`. -/ def OrderIso.finTwoArrowIso (α : Type*) [Preorder α] : (Fin 2 → α) ≃o α × α := { OrderIso.piFinTwoIso fun _ => α with toEquiv := finTwoArrowEquiv α } #align order_iso.fin_two_arrow_iso OrderIso.finTwoArrowIso /-- An equivalence that removes `i` and maps it to `none`. This is a version of `Fin.predAbove` that produces `Option (Fin n)` instead of mapping both `i.cast_succ` and `i.succ` to `i`. -/ def finSuccEquiv' (i : Fin (n + 1)) : Fin (n + 1) ≃ Option (Fin n) where toFun := i.insertNth none some invFun x := x.casesOn' i (Fin.succAbove i) left_inv x := Fin.succAboveCases i (by simp) (fun j => by simp) x right_inv x := by cases x <;> dsimp <;> simp #align fin_succ_equiv' finSuccEquiv' @[simp] theorem finSuccEquiv'_at (i : Fin (n + 1)) : (finSuccEquiv' i) i = none := by simp [finSuccEquiv'] #align fin_succ_equiv'_at finSuccEquiv'_at @[simp] theorem finSuccEquiv'_succAbove (i : Fin (n + 1)) (j : Fin n) : finSuccEquiv' i (i.succAbove j) = some j := @Fin.insertNth_apply_succAbove n (fun _ => Option (Fin n)) i _ _ _ #align fin_succ_equiv'_succ_above finSuccEquiv'_succAbove theorem finSuccEquiv'_below {i : Fin (n + 1)} {m : Fin n} (h : Fin.castSucc m < i) : (finSuccEquiv' i) (Fin.castSucc m) = m := by rw [← Fin.succAbove_of_castSucc_lt _ _ h, finSuccEquiv'_succAbove] #align fin_succ_equiv'_below finSuccEquiv'_below theorem finSuccEquiv'_above {i : Fin (n + 1)} {m : Fin n} (h : i ≤ Fin.castSucc m) : (finSuccEquiv' i) m.succ = some m := by rw [← Fin.succAbove_of_le_castSucc _ _ h, finSuccEquiv'_succAbove] #align fin_succ_equiv'_above finSuccEquiv'_above @[simp] theorem finSuccEquiv'_symm_none (i : Fin (n + 1)) : (finSuccEquiv' i).symm none = i := rfl #align fin_succ_equiv'_symm_none finSuccEquiv'_symm_none @[simp] theorem finSuccEquiv'_symm_some (i : Fin (n + 1)) (j : Fin n) : (finSuccEquiv' i).symm (some j) = i.succAbove j := rfl #align fin_succ_equiv'_symm_some finSuccEquiv'_symm_some theorem finSuccEquiv'_symm_some_below {i : Fin (n + 1)} {m : Fin n} (h : Fin.castSucc m < i) : (finSuccEquiv' i).symm (some m) = Fin.castSucc m := Fin.succAbove_of_castSucc_lt i m h #align fin_succ_equiv'_symm_some_below finSuccEquiv'_symm_some_below theorem finSuccEquiv'_symm_some_above {i : Fin (n + 1)} {m : Fin n} (h : i ≤ Fin.castSucc m) : (finSuccEquiv' i).symm (some m) = m.succ := Fin.succAbove_of_le_castSucc i m h #align fin_succ_equiv'_symm_some_above finSuccEquiv'_symm_some_above theorem finSuccEquiv'_symm_coe_below {i : Fin (n + 1)} {m : Fin n} (h : Fin.castSucc m < i) : (finSuccEquiv' i).symm m = Fin.castSucc m := finSuccEquiv'_symm_some_below h #align fin_succ_equiv'_symm_coe_below finSuccEquiv'_symm_coe_below theorem finSuccEquiv'_symm_coe_above {i : Fin (n + 1)} {m : Fin n} (h : i ≤ Fin.castSucc m) : (finSuccEquiv' i).symm m = m.succ := finSuccEquiv'_symm_some_above h #align fin_succ_equiv'_symm_coe_above finSuccEquiv'_symm_coe_above /-- Equivalence between `Fin (n + 1)` and `Option (Fin n)`. This is a version of `Fin.pred` that produces `Option (Fin n)` instead of requiring a proof that the input is not `0`. -/ def finSuccEquiv (n : ℕ) : Fin (n + 1) ≃ Option (Fin n) := finSuccEquiv' 0 #align fin_succ_equiv finSuccEquiv @[simp] theorem finSuccEquiv_zero : (finSuccEquiv n) 0 = none := rfl #align fin_succ_equiv_zero finSuccEquiv_zero @[simp] theorem finSuccEquiv_succ (m : Fin n) : (finSuccEquiv n) m.succ = some m := finSuccEquiv'_above (Fin.zero_le _) #align fin_succ_equiv_succ finSuccEquiv_succ @[simp] theorem finSuccEquiv_symm_none : (finSuccEquiv n).symm none = 0 := finSuccEquiv'_symm_none _ #align fin_succ_equiv_symm_none finSuccEquiv_symm_none @[simp] theorem finSuccEquiv_symm_some (m : Fin n) : (finSuccEquiv n).symm (some m) = m.succ := congr_fun Fin.succAbove_zero m #align fin_succ_equiv_symm_some finSuccEquiv_symm_some #align fin_succ_equiv_symm_coe finSuccEquiv_symm_some /-- The equiv version of `Fin.predAbove_zero`. -/ theorem finSuccEquiv'_zero : finSuccEquiv' (0 : Fin (n + 1)) = finSuccEquiv n := rfl #align fin_succ_equiv'_zero finSuccEquiv'_zero theorem finSuccEquiv'_last_apply_castSucc (i : Fin n) : finSuccEquiv' (Fin.last n) (Fin.castSucc i) = i := by rw [← Fin.succAbove_last, finSuccEquiv'_succAbove] theorem finSuccEquiv'_last_apply {i : Fin (n + 1)} (h : i ≠ Fin.last n) : finSuccEquiv' (Fin.last n) i = Fin.castLT i (Fin.val_lt_last h) := by rcases Fin.exists_castSucc_eq.2 h with ⟨i, rfl⟩ rw [finSuccEquiv'_last_apply_castSucc] rfl #align fin_succ_equiv'_last_apply finSuccEquiv'_last_apply theorem finSuccEquiv'_ne_last_apply {i j : Fin (n + 1)} (hi : i ≠ Fin.last n) (hj : j ≠ i) : finSuccEquiv' i j = (i.castLT (Fin.val_lt_last hi)).predAbove j := by rcases Fin.exists_succAbove_eq hj with ⟨j, rfl⟩ rcases Fin.exists_castSucc_eq.2 hi with ⟨i, rfl⟩ simp #align fin_succ_equiv'_ne_last_apply finSuccEquiv'_ne_last_apply /-- `Fin.succAbove` as an order isomorphism between `Fin n` and `{x : Fin (n + 1) // x ≠ p}`. -/ def finSuccAboveEquiv (p : Fin (n + 1)) : Fin n ≃o { x : Fin (n + 1) // x ≠ p } := { Equiv.optionSubtype p ⟨(finSuccEquiv' p).symm, rfl⟩ with map_rel_iff' := p.succAboveOrderEmb.map_rel_iff' } #align fin_succ_above_equiv finSuccAboveEquiv theorem finSuccAboveEquiv_apply (p : Fin (n + 1)) (i : Fin n) : finSuccAboveEquiv p i = ⟨p.succAbove i, p.succAbove_ne i⟩ := rfl #align fin_succ_above_equiv_apply finSuccAboveEquiv_apply theorem finSuccAboveEquiv_symm_apply_last (x : { x : Fin (n + 1) // x ≠ Fin.last n }) : (finSuccAboveEquiv (Fin.last n)).symm x = Fin.castLT x.1 (Fin.val_lt_last x.2) := by rw [← Option.some_inj] simpa [finSuccAboveEquiv, OrderIso.symm] using finSuccEquiv'_last_apply x.property #align fin_succ_above_equiv_symm_apply_last finSuccAboveEquiv_symm_apply_last theorem finSuccAboveEquiv_symm_apply_ne_last {p : Fin (n + 1)} (h : p ≠ Fin.last n) (x : { x : Fin (n + 1) // x ≠ p }) : (finSuccAboveEquiv p).symm x = (p.castLT (Fin.val_lt_last h)).predAbove x := by rw [← Option.some_inj] simpa [finSuccAboveEquiv, OrderIso.symm] using finSuccEquiv'_ne_last_apply h x.property #align fin_succ_above_equiv_symm_apply_ne_last finSuccAboveEquiv_symm_apply_ne_last /-- `Equiv` between `Fin (n + 1)` and `Option (Fin n)` sending `Fin.last n` to `none` -/ def finSuccEquivLast : Fin (n + 1) ≃ Option (Fin n) := finSuccEquiv' (Fin.last n) #align fin_succ_equiv_last finSuccEquivLast @[simp] theorem finSuccEquivLast_castSucc (i : Fin n) : finSuccEquivLast (Fin.castSucc i) = some i := finSuccEquiv'_below i.2 #align fin_succ_equiv_last_cast_succ finSuccEquivLast_castSucc @[simp] theorem finSuccEquivLast_last : finSuccEquivLast (Fin.last n) = none := by simp [finSuccEquivLast] #align fin_succ_equiv_last_last finSuccEquivLast_last @[simp] theorem finSuccEquivLast_symm_some (i : Fin n) : finSuccEquivLast.symm (some i) = Fin.castSucc i := finSuccEquiv'_symm_some_below i.2 #align fin_succ_equiv_last_symm_some finSuccEquivLast_symm_some #align fin_succ_equiv_last_symm_coe finSuccEquivLast_symm_some @[simp] theorem finSuccEquivLast_symm_none : finSuccEquivLast.symm none = Fin.last n := finSuccEquiv'_symm_none _ #align fin_succ_equiv_last_symm_none finSuccEquivLast_symm_none /-- Equivalence between `Π j : Fin (n + 1), α j` and `α i × Π j : Fin n, α (Fin.succAbove i j)`. -/ @[simps (config := .asFn)] def Equiv.piFinSuccAbove (α : Fin (n + 1) → Type u) (i : Fin (n + 1)) : (∀ j, α j) ≃ α i × ∀ j, α (i.succAbove j) where toFun f := i.extractNth f invFun f := i.insertNth f.1 f.2 left_inv f := by simp right_inv f := by simp #align equiv.pi_fin_succ_above_equiv Equiv.piFinSuccAbove #align equiv.pi_fin_succ_above_equiv_apply Equiv.piFinSuccAbove_apply #align equiv.pi_fin_succ_above_equiv_symm_apply Equiv.piFinSuccAbove_symm_apply /-- Order isomorphism between `Π j : Fin (n + 1), α j` and `α i × Π j : Fin n, α (Fin.succAbove i j)`. -/ def OrderIso.piFinSuccAboveIso (α : Fin (n + 1) → Type u) [∀ i, LE (α i)] (i : Fin (n + 1)) : (∀ j, α j) ≃o α i × ∀ j, α (i.succAbove j) where toEquiv := Equiv.piFinSuccAbove α i map_rel_iff' := Iff.symm i.forall_iff_succAbove #align order_iso.pi_fin_succ_above_iso OrderIso.piFinSuccAboveIso /-- Equivalence between `Fin (n + 1) → β` and `β × (Fin n → β)`. -/ @[simps! (config := .asFn)] def Equiv.piFinSucc (n : ℕ) (β : Type u) : (Fin (n + 1) → β) ≃ β × (Fin n → β) := Equiv.piFinSuccAbove (fun _ => β) 0 #align equiv.pi_fin_succ Equiv.piFinSucc #align equiv.pi_fin_succ_apply Equiv.piFinSucc_apply #align equiv.pi_fin_succ_symm_apply Equiv.piFinSucc_symm_apply /-- An embedding `e : Fin (n+1) ↪ ι` corresponds to an embedding `f : Fin n ↪ ι` (corresponding the last `n` coordinates of `e`) together with a value not taken by `f` (corresponding to `e 0`). -/ def Equiv.embeddingFinSucc (n : ℕ) (ι : Type*) : (Fin (n+1) ↪ ι) ≃ (Σ (e : Fin n ↪ ι), {i // i ∉ Set.range e}) := ((finSuccEquiv n).embeddingCongr (Equiv.refl ι)).trans (Function.Embedding.optionEmbeddingEquiv (Fin n) ι) @[simp] lemma Equiv.embeddingFinSucc_fst {n : ℕ} {ι : Type*} (e : Fin (n+1) ↪ ι) : ((Equiv.embeddingFinSucc n ι e).1 : Fin n → ι) = e ∘ Fin.succ := rfl @[simp] lemma Equiv.embeddingFinSucc_snd {n : ℕ} {ι : Type*} (e : Fin (n+1) ↪ ι) : ((Equiv.embeddingFinSucc n ι e).2 : ι) = e 0 := rfl @[simp] lemma Equiv.coe_embeddingFinSucc_symm {n : ℕ} {ι : Type*} (f : Σ (e : Fin n ↪ ι), {i // i ∉ Set.range e}) : ((Equiv.embeddingFinSucc n ι).symm f : Fin (n + 1) → ι) = Fin.cons f.2.1 f.1 := by ext i exact Fin.cases rfl (fun j ↦ rfl) i /-- Equivalence between `Fin (n + 1) → β` and `β × (Fin n → β)` which separates out the last element of the tuple. -/ @[simps! (config := .asFn)] def Equiv.piFinCastSucc (n : ℕ) (β : Type u) : (Fin (n + 1) → β) ≃ β × (Fin n → β) := Equiv.piFinSuccAbove (fun _ => β) (.last _) /-- Equivalence between `Fin m ⊕ Fin n` and `Fin (m + n)` -/ def finSumFinEquiv : Sum (Fin m) (Fin n) ≃ Fin (m + n) where toFun := Sum.elim (Fin.castAdd n) (Fin.natAdd m) invFun i := @Fin.addCases m n (fun _ => Sum (Fin m) (Fin n)) Sum.inl Sum.inr i left_inv x := by cases' x with y y <;> dsimp <;> simp right_inv x := by refine Fin.addCases (fun i => ?_) (fun i => ?_) x <;> simp #align fin_sum_fin_equiv finSumFinEquiv @[simp] theorem finSumFinEquiv_apply_left (i : Fin m) : (finSumFinEquiv (Sum.inl i) : Fin (m + n)) = Fin.castAdd n i := rfl #align fin_sum_fin_equiv_apply_left finSumFinEquiv_apply_left @[simp] theorem finSumFinEquiv_apply_right (i : Fin n) : (finSumFinEquiv (Sum.inr i) : Fin (m + n)) = Fin.natAdd m i := rfl #align fin_sum_fin_equiv_apply_right finSumFinEquiv_apply_right @[simp] theorem finSumFinEquiv_symm_apply_castAdd (x : Fin m) : finSumFinEquiv.symm (Fin.castAdd n x) = Sum.inl x := finSumFinEquiv.symm_apply_apply (Sum.inl x) #align fin_sum_fin_equiv_symm_apply_cast_add finSumFinEquiv_symm_apply_castAdd @[simp] theorem finSumFinEquiv_symm_apply_natAdd (x : Fin n) : finSumFinEquiv.symm (Fin.natAdd m x) = Sum.inr x := finSumFinEquiv.symm_apply_apply (Sum.inr x) #align fin_sum_fin_equiv_symm_apply_nat_add finSumFinEquiv_symm_apply_natAdd @[simp] theorem finSumFinEquiv_symm_last : finSumFinEquiv.symm (Fin.last n) = Sum.inr 0 := finSumFinEquiv_symm_apply_natAdd 0 #align fin_sum_fin_equiv_symm_last finSumFinEquiv_symm_last /-- The equivalence between `Fin (m + n)` and `Fin (n + m)` which rotates by `n`. -/ def finAddFlip : Fin (m + n) ≃ Fin (n + m) := (finSumFinEquiv.symm.trans (Equiv.sumComm _ _)).trans finSumFinEquiv #align fin_add_flip finAddFlip @[simp] theorem finAddFlip_apply_castAdd (k : Fin m) (n : ℕ) : finAddFlip (Fin.castAdd n k) = Fin.natAdd n k := by simp [finAddFlip] #align fin_add_flip_apply_cast_add finAddFlip_apply_castAdd @[simp] theorem finAddFlip_apply_natAdd (k : Fin n) (m : ℕ) : finAddFlip (Fin.natAdd m k) = Fin.castAdd m k := by simp [finAddFlip] #align fin_add_flip_apply_nat_add finAddFlip_apply_natAdd @[simp] theorem finAddFlip_apply_mk_left {k : ℕ} (h : k < m) (hk : k < m + n := Nat.lt_add_right n h) (hnk : n + k < n + m := Nat.add_lt_add_left h n) : finAddFlip (⟨k, hk⟩ : Fin (m + n)) = ⟨n + k, hnk⟩ := by convert finAddFlip_apply_castAdd ⟨k, h⟩ n #align fin_add_flip_apply_mk_left finAddFlip_apply_mk_left @[simp] theorem finAddFlip_apply_mk_right {k : ℕ} (h₁ : m ≤ k) (h₂ : k < m + n) : finAddFlip (⟨k, h₂⟩ : Fin (m + n)) = ⟨k - m, by omega⟩ := by convert @finAddFlip_apply_natAdd n ⟨k - m, by omega⟩ m simp [Nat.add_sub_cancel' h₁] #align fin_add_flip_apply_mk_right finAddFlip_apply_mk_right /-- Rotate `Fin n` one step to the right. -/ def finRotate : ∀ n, Equiv.Perm (Fin n) | 0 => Equiv.refl _ | n + 1 => finAddFlip.trans (finCongr (Nat.add_comm 1 n)) #align fin_rotate finRotate @[simp] lemma finRotate_zero : finRotate 0 = Equiv.refl _ := rfl #align fin_rotate_zero finRotate_zero lemma finRotate_succ (n : ℕ) : finRotate (n + 1) = finAddFlip.trans (finCongr (Nat.add_comm 1 n)) := rfl theorem finRotate_of_lt {k : ℕ} (h : k < n) : finRotate (n + 1) ⟨k, h.trans_le n.le_succ⟩ = ⟨k + 1, Nat.succ_lt_succ h⟩ := by ext dsimp [finRotate_succ] simp [finAddFlip_apply_mk_left h, Nat.add_comm] #align fin_rotate_of_lt finRotate_of_lt
Mathlib/Logic/Equiv/Fin.lean
401
404
theorem finRotate_last' : finRotate (n + 1) ⟨n, by omega⟩ = ⟨0, Nat.zero_lt_succ _⟩ := by
dsimp [finRotate_succ] rw [finAddFlip_apply_mk_right le_rfl] simp
/- 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.Convex.Topology import Mathlib.LinearAlgebra.Dimension.DivisionRing import Mathlib.Topology.Algebra.Module.Cardinality /-! # Connectedness of subsets of vector spaces We show several results related to the (path)-connectedness of subsets of real vector spaces: * `Set.Countable.isPathConnected_compl_of_one_lt_rank` asserts that the complement of a countable set is path-connected in a space of dimension `> 1`. * `isPathConnected_compl_singleton_of_one_lt_rank` is the special case of the complement of a singleton. * `isPathConnected_sphere` shows that any sphere is path-connected in dimension `> 1`. * `isPathConnected_compl_of_one_lt_codim` shows that the complement of a subspace of codimension `> 1` is path-connected. Statements with connectedness instead of path-connectedness are also given. -/ open Convex Set Metric section TopologicalVectorSpace variable {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul ℝ E] /-- In a real vector space of dimension `> 1`, the complement of any countable set is path connected. -/ theorem Set.Countable.isPathConnected_compl_of_one_lt_rank (h : 1 < Module.rank ℝ E) {s : Set E} (hs : s.Countable) : IsPathConnected sᶜ := by have : Nontrivial E := (rank_pos_iff_nontrivial (R := ℝ)).1 (zero_lt_one.trans h) -- the set `sᶜ` is dense, therefore nonempty. Pick `a ∈ sᶜ`. We have to show that any -- `b ∈ sᶜ` can be joined to `a`. obtain ⟨a, ha⟩ : sᶜ.Nonempty := (hs.dense_compl ℝ).nonempty refine ⟨a, ha, ?_⟩ intro b hb rcases eq_or_ne a b with rfl|hab · exact JoinedIn.refl ha /- Assume `b ≠ a`. Write `a = c - x` and `b = c + x` for some nonzero `x`. Choose `y` which is linearly independent from `x`. Then the segments joining `a = c - x` to `c + ty` are pairwise disjoint for varying `t` (except for the endpoint `a`) so only countably many of them can intersect `s`. In the same way, there are countably many `t`s for which the segment from `b = c + x` to `c + ty` intersects `s`. Choosing `t` outside of these countable exceptions, one gets a path in the complement of `s` from `a` to `z = c + ty` and then to `b`. -/ let c := (2 : ℝ)⁻¹ • (a + b) let x := (2 : ℝ)⁻¹ • (b - a) have Ia : c - x = a := by simp only [c, x, smul_add, smul_sub] abel_nf simp [zsmul_eq_smul_cast ℝ 2] have Ib : c + x = b := by simp only [c, x, smul_add, smul_sub] abel_nf simp [zsmul_eq_smul_cast ℝ 2] have x_ne_zero : x ≠ 0 := by simpa [x] using sub_ne_zero.2 hab.symm obtain ⟨y, hy⟩ : ∃ y, LinearIndependent ℝ ![x, y] := exists_linearIndependent_pair_of_one_lt_rank h x_ne_zero have A : Set.Countable {t : ℝ | ([c + x -[ℝ] c + t • y] ∩ s).Nonempty} := by apply countable_setOf_nonempty_of_disjoint _ (fun t ↦ inter_subset_right) hs intro t t' htt' apply disjoint_iff_inter_eq_empty.2 have N : {c + x} ∩ s = ∅ := by simpa only [singleton_inter_eq_empty, mem_compl_iff, Ib] using hb rw [inter_assoc, inter_comm s, inter_assoc, inter_self, ← inter_assoc, ← subset_empty_iff, ← N] apply inter_subset_inter_left apply Eq.subset apply segment_inter_eq_endpoint_of_linearIndependent_of_ne hy htt'.symm have B : Set.Countable {t : ℝ | ([c - x -[ℝ] c + t • y] ∩ s).Nonempty} := by apply countable_setOf_nonempty_of_disjoint _ (fun t ↦ inter_subset_right) hs intro t t' htt' apply disjoint_iff_inter_eq_empty.2 have N : {c - x} ∩ s = ∅ := by simpa only [singleton_inter_eq_empty, mem_compl_iff, Ia] using ha rw [inter_assoc, inter_comm s, inter_assoc, inter_self, ← inter_assoc, ← subset_empty_iff, ← N] apply inter_subset_inter_left rw [sub_eq_add_neg _ x] apply Eq.subset apply segment_inter_eq_endpoint_of_linearIndependent_of_ne _ htt'.symm convert hy.units_smul ![-1, 1] simp [← List.ofFn_inj] obtain ⟨t, ht⟩ : Set.Nonempty ({t : ℝ | ([c + x -[ℝ] c + t • y] ∩ s).Nonempty} ∪ {t : ℝ | ([c - x -[ℝ] c + t • y] ∩ s).Nonempty})ᶜ := ((A.union B).dense_compl ℝ).nonempty let z := c + t • y simp only [compl_union, mem_inter_iff, mem_compl_iff, mem_setOf_eq, not_nonempty_iff_eq_empty] at ht have JA : JoinedIn sᶜ a z := by apply JoinedIn.of_segment_subset rw [subset_compl_iff_disjoint_right, disjoint_iff_inter_eq_empty] convert ht.2 exact Ia.symm have JB : JoinedIn sᶜ b z := by apply JoinedIn.of_segment_subset rw [subset_compl_iff_disjoint_right, disjoint_iff_inter_eq_empty] convert ht.1 exact Ib.symm exact JA.trans JB.symm /-- In a real vector space of dimension `> 1`, the complement of any countable set is connected. -/ theorem Set.Countable.isConnected_compl_of_one_lt_rank (h : 1 < Module.rank ℝ E) {s : Set E} (hs : s.Countable) : IsConnected sᶜ := (hs.isPathConnected_compl_of_one_lt_rank h).isConnected /-- In a real vector space of dimension `> 1`, the complement of any singleton is path-connected. -/ theorem isPathConnected_compl_singleton_of_one_lt_rank (h : 1 < Module.rank ℝ E) (x : E) : IsPathConnected {x}ᶜ := Set.Countable.isPathConnected_compl_of_one_lt_rank h (countable_singleton x) /-- In a real vector space of dimension `> 1`, the complement of a singleton is connected. -/ theorem isConnected_compl_singleton_of_one_lt_rank (h : 1 < Module.rank ℝ E) (x : E) : IsConnected {x}ᶜ := (isPathConnected_compl_singleton_of_one_lt_rank h x).isConnected end TopologicalVectorSpace section NormedSpace variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- In a real vector space of dimension `> 1`, any sphere of nonnegative radius is path connected. -/ theorem isPathConnected_sphere (h : 1 < Module.rank ℝ E) (x : E) {r : ℝ} (hr : 0 ≤ r) : IsPathConnected (sphere x r) := by /- when `r > 0`, we write the sphere as the image of `{0}ᶜ` under the map `y ↦ x + (r * ‖y‖⁻¹) • y`. Since the image under a continuous map of a path connected set is path connected, this concludes the proof. -/ rcases hr.eq_or_lt with rfl|rpos · simpa using isPathConnected_singleton x let f : E → E := fun y ↦ x + (r * ‖y‖⁻¹) • y have A : ContinuousOn f {0}ᶜ := by intro y hy apply (continuousAt_const.add _).continuousWithinAt apply (continuousAt_const.mul (ContinuousAt.inv₀ continuousAt_id.norm ?_)).smul continuousAt_id simpa using hy have B : IsPathConnected ({0}ᶜ : Set E) := isPathConnected_compl_singleton_of_one_lt_rank h 0 have C : IsPathConnected (f '' {0}ᶜ) := B.image' A have : f '' {0}ᶜ = sphere x r := by apply Subset.antisymm · rintro - ⟨y, hy, rfl⟩ have : ‖y‖ ≠ 0 := by simpa using hy simp [f, norm_smul, abs_of_nonneg hr, mul_assoc, inv_mul_cancel this] · intro y hy refine ⟨y - x, ?_, ?_⟩ · intro H simp only [mem_singleton_iff, sub_eq_zero] at H simp only [H, mem_sphere_iff_norm, sub_self, norm_zero] at hy exact rpos.ne hy · simp [f, mem_sphere_iff_norm.1 hy, mul_inv_cancel rpos.ne'] rwa [this] at C /-- In a real vector space of dimension `> 1`, any sphere of nonnegative radius is connected. -/ theorem isConnected_sphere (h : 1 < Module.rank ℝ E) (x : E) {r : ℝ} (hr : 0 ≤ r) : IsConnected (sphere x r) := (isPathConnected_sphere h x hr).isConnected /-- In a real vector space of dimension `> 1`, any sphere is preconnected. -/
Mathlib/Analysis/NormedSpace/Connected.lean
164
168
theorem isPreconnected_sphere (h : 1 < Module.rank ℝ E) (x : E) (r : ℝ) : IsPreconnected (sphere x r) := by
rcases le_or_lt 0 r with hr|hr · exact (isConnected_sphere h x hr).isPreconnected · simpa [hr] using isPreconnected_empty
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Balanced import Mathlib.CategoryTheory.Limits.EssentiallySmall import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms import Mathlib.CategoryTheory.Subobject.Lattice import Mathlib.CategoryTheory.Subobject.WellPowered import Mathlib.Data.Set.Opposite import Mathlib.Data.Set.Subsingleton #align_import category_theory.generator from "leanprover-community/mathlib"@"f187f1074fa1857c94589cc653c786cadc4c35ff" /-! # Separating and detecting sets There are several non-equivalent notions of a generator of a category. Here, we consider two of them: * We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`. * We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms, i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism. There are, of course, also the dual notions of coseparating and codetecting sets. ## Main results We * define predicates `IsSeparating`, `IsCoseparating`, `IsDetecting` and `IsCodetecting` on sets of objects; * show that separating and coseparating are dual notions; * show that detecting and codetecting are dual notions; * show that if `C` has equalizers, then detecting implies separating; * show that if `C` has coequalizers, then codetecting implies separating; * show that if `C` is balanced, then separating implies detecting and coseparating implies codetecting; * show that `∅` is separating if and only if `∅` is coseparating if and only if `C` is thin; * show that `∅` is detecting if and only if `∅` is codetecting if and only if `C` is a groupoid; * define predicates `IsSeparator`, `IsCoseparator`, `IsDetector` and `IsCodetector` as the singleton counterparts to the definitions for sets above and restate the above results in this situation; * show that `G` is a separator if and only if `coyoneda.obj (op G)` is faithful (and the dual); * show that `G` is a detector if and only if `coyoneda.obj (op G)` reflects isomorphisms (and the dual). ## Future work * We currently don't have any examples yet. * We will want typeclasses `HasSeparator C` and similar. -/ universe w v₁ v₂ u₁ u₂ open CategoryTheory.Limits Opposite namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] /-- We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`. -/ def IsSeparating (𝒢 : Set C) : Prop := ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : G ⟶ X), h ≫ f = h ≫ g) → f = g #align category_theory.is_separating CategoryTheory.IsSeparating /-- We say that `𝒢` is a coseparating set if the functors `C(-, G)` for `G ∈ 𝒢` are collectively faithful, i.e., if `f ≫ h = g ≫ h` for all `h` with codomain in `𝒢` implies `f = g`. -/ def IsCoseparating (𝒢 : Set C) : Prop := ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : Y ⟶ G), f ≫ h = g ≫ h) → f = g #align category_theory.is_coseparating CategoryTheory.IsCoseparating /-- We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms, i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism. -/ def IsDetecting (𝒢 : Set C) : Prop := ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : G ⟶ Y), ∃! h' : G ⟶ X, h' ≫ f = h) → IsIso f #align category_theory.is_detecting CategoryTheory.IsDetecting /-- We say that `𝒢` is a codetecting set if the functors `C(-, G)` collectively reflect isomorphisms, i.e., if any `h` with codomain in `G` uniquely factors through `f`, then `f` is an isomorphism. -/ def IsCodetecting (𝒢 : Set C) : Prop := ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : X ⟶ G), ∃! h' : Y ⟶ G, f ≫ h' = h) → IsIso f #align category_theory.is_codetecting CategoryTheory.IsCodetecting section Dual theorem isSeparating_op_iff (𝒢 : Set C) : IsSeparating 𝒢.op ↔ IsCoseparating 𝒢 := by refine ⟨fun h𝒢 X Y f g hfg => ?_, fun h𝒢 X Y f g hfg => ?_⟩ · refine Quiver.Hom.op_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.unop_inj ?_) simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ (Set.mem_op.1 hG) _ · refine Quiver.Hom.unop_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.op_inj ?_) simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ (Set.op_mem_op.2 hG) _ #align category_theory.is_separating_op_iff CategoryTheory.isSeparating_op_iff theorem isCoseparating_op_iff (𝒢 : Set C) : IsCoseparating 𝒢.op ↔ IsSeparating 𝒢 := by refine ⟨fun h𝒢 X Y f g hfg => ?_, fun h𝒢 X Y f g hfg => ?_⟩ · refine Quiver.Hom.op_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.unop_inj ?_) simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ (Set.mem_op.1 hG) _ · refine Quiver.Hom.unop_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.op_inj ?_) simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ (Set.op_mem_op.2 hG) _ #align category_theory.is_coseparating_op_iff CategoryTheory.isCoseparating_op_iff theorem isCoseparating_unop_iff (𝒢 : Set Cᵒᵖ) : IsCoseparating 𝒢.unop ↔ IsSeparating 𝒢 := by rw [← isSeparating_op_iff, Set.unop_op] #align category_theory.is_coseparating_unop_iff CategoryTheory.isCoseparating_unop_iff theorem isSeparating_unop_iff (𝒢 : Set Cᵒᵖ) : IsSeparating 𝒢.unop ↔ IsCoseparating 𝒢 := by rw [← isCoseparating_op_iff, Set.unop_op] #align category_theory.is_separating_unop_iff CategoryTheory.isSeparating_unop_iff theorem isDetecting_op_iff (𝒢 : Set C) : IsDetecting 𝒢.op ↔ IsCodetecting 𝒢 := by refine ⟨fun h𝒢 X Y f hf => ?_, fun h𝒢 X Y f hf => ?_⟩ · refine (isIso_op_iff _).1 (h𝒢 _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (unop G) (Set.mem_op.1 hG) h.unop exact ⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩ · refine (isIso_unop_iff _).1 (h𝒢 _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (op G) (Set.op_mem_op.2 hG) h.op refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩ exact Quiver.Hom.unop_inj (by simpa only using hy) #align category_theory.is_detecting_op_iff CategoryTheory.isDetecting_op_iff theorem isCodetecting_op_iff (𝒢 : Set C) : IsCodetecting 𝒢.op ↔ IsDetecting 𝒢 := by refine ⟨fun h𝒢 X Y f hf => ?_, fun h𝒢 X Y f hf => ?_⟩ · refine (isIso_op_iff _).1 (h𝒢 _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (unop G) (Set.mem_op.1 hG) h.unop exact ⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩ · refine (isIso_unop_iff _).1 (h𝒢 _ fun G hG h => ?_) obtain ⟨t, ht, ht'⟩ := hf (op G) (Set.op_mem_op.2 hG) h.op refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩ exact Quiver.Hom.unop_inj (by simpa only using hy) #align category_theory.is_codetecting_op_iff CategoryTheory.isCodetecting_op_iff theorem isDetecting_unop_iff (𝒢 : Set Cᵒᵖ) : IsDetecting 𝒢.unop ↔ IsCodetecting 𝒢 := by rw [← isCodetecting_op_iff, Set.unop_op] #align category_theory.is_detecting_unop_iff CategoryTheory.isDetecting_unop_iff theorem isCodetecting_unop_iff {𝒢 : Set Cᵒᵖ} : IsCodetecting 𝒢.unop ↔ IsDetecting 𝒢 := by rw [← isDetecting_op_iff, Set.unop_op] #align category_theory.is_codetecting_unop_iff CategoryTheory.isCodetecting_unop_iff end Dual theorem IsDetecting.isSeparating [HasEqualizers C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) : IsSeparating 𝒢 := fun _ _ f g hfg => have : IsIso (equalizer.ι f g) := h𝒢 _ fun _ hG _ => equalizer.existsUnique _ (hfg _ hG _) eq_of_epi_equalizer #align category_theory.is_detecting.is_separating CategoryTheory.IsDetecting.isSeparating section theorem IsCodetecting.isCoseparating [HasCoequalizers C] {𝒢 : Set C} : IsCodetecting 𝒢 → IsCoseparating 𝒢 := by simpa only [← isSeparating_op_iff, ← isDetecting_op_iff] using IsDetecting.isSeparating #align category_theory.is_codetecting.is_coseparating CategoryTheory.IsCodetecting.isCoseparating end theorem IsSeparating.isDetecting [Balanced C] {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) : IsDetecting 𝒢 := by intro X Y f hf refine (isIso_iff_mono_and_epi _).2 ⟨⟨fun g h hgh => h𝒢 _ _ fun G hG i => ?_⟩, ⟨fun g h hgh => ?_⟩⟩ · obtain ⟨t, -, ht⟩ := hf G hG (i ≫ g ≫ f) rw [ht (i ≫ g) (Category.assoc _ _ _), ht (i ≫ h) (hgh.symm ▸ Category.assoc _ _ _)] · refine h𝒢 _ _ fun G hG i => ?_ obtain ⟨t, rfl, -⟩ := hf G hG i rw [Category.assoc, hgh, Category.assoc] #align category_theory.is_separating.is_detecting CategoryTheory.IsSeparating.isDetecting section attribute [local instance] balanced_opposite theorem IsCoseparating.isCodetecting [Balanced C] {𝒢 : Set C} : IsCoseparating 𝒢 → IsCodetecting 𝒢 := by simpa only [← isDetecting_op_iff, ← isSeparating_op_iff] using IsSeparating.isDetecting #align category_theory.is_coseparating.is_codetecting CategoryTheory.IsCoseparating.isCodetecting end theorem isDetecting_iff_isSeparating [HasEqualizers C] [Balanced C] (𝒢 : Set C) : IsDetecting 𝒢 ↔ IsSeparating 𝒢 := ⟨IsDetecting.isSeparating, IsSeparating.isDetecting⟩ #align category_theory.is_detecting_iff_is_separating CategoryTheory.isDetecting_iff_isSeparating theorem isCodetecting_iff_isCoseparating [HasCoequalizers C] [Balanced C] {𝒢 : Set C} : IsCodetecting 𝒢 ↔ IsCoseparating 𝒢 := ⟨IsCodetecting.isCoseparating, IsCoseparating.isCodetecting⟩ #align category_theory.is_codetecting_iff_is_coseparating CategoryTheory.isCodetecting_iff_isCoseparating section Mono theorem IsSeparating.mono {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) : IsSeparating ℋ := fun _ _ _ _ hfg => h𝒢 _ _ fun _ hG _ => hfg _ (h𝒢ℋ hG) _ #align category_theory.is_separating.mono CategoryTheory.IsSeparating.mono theorem IsCoseparating.mono {𝒢 : Set C} (h𝒢 : IsCoseparating 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) : IsCoseparating ℋ := fun _ _ _ _ hfg => h𝒢 _ _ fun _ hG _ => hfg _ (h𝒢ℋ hG) _ #align category_theory.is_coseparating.mono CategoryTheory.IsCoseparating.mono theorem IsDetecting.mono {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) : IsDetecting ℋ := fun _ _ _ hf => h𝒢 _ fun _ hG _ => hf _ (h𝒢ℋ hG) _ #align category_theory.is_detecting.mono CategoryTheory.IsDetecting.mono theorem IsCodetecting.mono {𝒢 : Set C} (h𝒢 : IsCodetecting 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) : IsCodetecting ℋ := fun _ _ _ hf => h𝒢 _ fun _ hG _ => hf _ (h𝒢ℋ hG) _ #align category_theory.is_codetecting.mono CategoryTheory.IsCodetecting.mono end Mono section Empty theorem thin_of_isSeparating_empty (h : IsSeparating (∅ : Set C)) : Quiver.IsThin C := fun _ _ => ⟨fun _ _ => h _ _ fun _ => False.elim⟩ #align category_theory.thin_of_is_separating_empty CategoryTheory.thin_of_isSeparating_empty theorem isSeparating_empty_of_thin [Quiver.IsThin C] : IsSeparating (∅ : Set C) := fun _ _ _ _ _ => Subsingleton.elim _ _ #align category_theory.is_separating_empty_of_thin CategoryTheory.isSeparating_empty_of_thin theorem thin_of_isCoseparating_empty (h : IsCoseparating (∅ : Set C)) : Quiver.IsThin C := fun _ _ => ⟨fun _ _ => h _ _ fun _ => False.elim⟩ #align category_theory.thin_of_is_coseparating_empty CategoryTheory.thin_of_isCoseparating_empty theorem isCoseparating_empty_of_thin [Quiver.IsThin C] : IsCoseparating (∅ : Set C) := fun _ _ _ _ _ => Subsingleton.elim _ _ #align category_theory.is_coseparating_empty_of_thin CategoryTheory.isCoseparating_empty_of_thin theorem groupoid_of_isDetecting_empty (h : IsDetecting (∅ : Set C)) {X Y : C} (f : X ⟶ Y) : IsIso f := h _ fun _ => False.elim #align category_theory.groupoid_of_is_detecting_empty CategoryTheory.groupoid_of_isDetecting_empty theorem isDetecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), IsIso f] : IsDetecting (∅ : Set C) := fun _ _ _ _ => inferInstance #align category_theory.is_detecting_empty_of_groupoid CategoryTheory.isDetecting_empty_of_groupoid theorem groupoid_of_isCodetecting_empty (h : IsCodetecting (∅ : Set C)) {X Y : C} (f : X ⟶ Y) : IsIso f := h _ fun _ => False.elim #align category_theory.groupoid_of_is_codetecting_empty CategoryTheory.groupoid_of_isCodetecting_empty theorem isCodetecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), IsIso f] : IsCodetecting (∅ : Set C) := fun _ _ _ _ => inferInstance #align category_theory.is_codetecting_empty_of_groupoid CategoryTheory.isCodetecting_empty_of_groupoid end Empty
Mathlib/CategoryTheory/Generator.lean
257
265
theorem isSeparating_iff_epi (𝒢 : Set C) [∀ A : C, HasCoproduct fun f : ΣG : 𝒢, (G : C) ⟶ A => (f.1 : C)] : IsSeparating 𝒢 ↔ ∀ A : C, Epi (Sigma.desc (@Sigma.snd 𝒢 fun G => (G : C) ⟶ A)) := by
refine ⟨fun h A => ⟨fun u v huv => h _ _ fun G hG f => ?_⟩, fun h X Y f g hh => ?_⟩ · simpa using Sigma.ι (fun f : ΣG : 𝒢, (G : C) ⟶ A => (f.1 : C)) ⟨⟨G, hG⟩, f⟩ ≫= huv · haveI := h X refine (cancel_epi (Sigma.desc (@Sigma.snd 𝒢 fun G => (G : C) ⟶ X))).1 (colimit.hom_ext fun j => ?_) simpa using hh j.as.1.1 j.as.1.2 j.as.2
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Scott Morrison, Adam Topaz -/ import Mathlib.Tactic.Linarith import Mathlib.CategoryTheory.Skeletal import Mathlib.Data.Fintype.Sort import Mathlib.Order.Category.NonemptyFinLinOrd import Mathlib.CategoryTheory.Functor.ReflectsIso #align_import algebraic_topology.simplex_category from "leanprover-community/mathlib"@"e8ac6315bcfcbaf2d19a046719c3b553206dac75" /-! # The simplex category We construct a skeletal model of the simplex category, with objects `ℕ` and the morphism `n ⟶ m` being the monotone maps from `Fin (n+1)` to `Fin (m+1)`. We show that this category is equivalent to `NonemptyFinLinOrd`. ## Remarks The definitions `SimplexCategory` and `SimplexCategory.Hom` are marked as irreducible. We provide the following functions to work with these objects: 1. `SimplexCategory.mk` creates an object of `SimplexCategory` out of a natural number. Use the notation `[n]` in the `Simplicial` locale. 2. `SimplexCategory.len` gives the "length" of an object of `SimplexCategory`, as a natural. 3. `SimplexCategory.Hom.mk` makes a morphism out of a monotone map between `Fin`'s. 4. `SimplexCategory.Hom.toOrderHom` gives the underlying monotone map associated to a term of `SimplexCategory.Hom`. -/ universe v open CategoryTheory CategoryTheory.Limits /-- The simplex category: * objects are natural numbers `n : ℕ` * morphisms from `n` to `m` are monotone functions `Fin (n+1) → Fin (m+1)` -/ def SimplexCategory := ℕ #align simplex_category SimplexCategory namespace SimplexCategory section -- Porting note: the definition of `SimplexCategory` is made irreducible below /-- Interpret a natural number as an object of the simplex category. -/ def mk (n : ℕ) : SimplexCategory := n #align simplex_category.mk SimplexCategory.mk /-- the `n`-dimensional simplex can be denoted `[n]` -/ scoped[Simplicial] notation "[" n "]" => SimplexCategory.mk n -- TODO: Make `len` irreducible. /-- The length of an object of `SimplexCategory`. -/ def len (n : SimplexCategory) : ℕ := n #align simplex_category.len SimplexCategory.len @[ext] theorem ext (a b : SimplexCategory) : a.len = b.len → a = b := id #align simplex_category.ext SimplexCategory.ext attribute [irreducible] SimplexCategory open Simplicial @[simp] theorem len_mk (n : ℕ) : [n].len = n := rfl #align simplex_category.len_mk SimplexCategory.len_mk @[simp] theorem mk_len (n : SimplexCategory) : ([n.len] : SimplexCategory) = n := rfl #align simplex_category.mk_len SimplexCategory.mk_len /-- A recursor for `SimplexCategory`. Use it as `induction Δ using SimplexCategory.rec`. -/ protected def rec {F : SimplexCategory → Sort*} (h : ∀ n : ℕ, F [n]) : ∀ X, F X := fun n => h n.len #align simplex_category.rec SimplexCategory.rec -- porting note (#5171): removed @[nolint has_nonempty_instance] /-- Morphisms in the `SimplexCategory`. -/ protected def Hom (a b : SimplexCategory) := Fin (a.len + 1) →o Fin (b.len + 1) #align simplex_category.hom SimplexCategory.Hom namespace Hom /-- Make a morphism in `SimplexCategory` from a monotone map of `Fin`'s. -/ def mk {a b : SimplexCategory} (f : Fin (a.len + 1) →o Fin (b.len + 1)) : SimplexCategory.Hom a b := f #align simplex_category.hom.mk SimplexCategory.Hom.mk /-- Recover the monotone map from a morphism in the simplex category. -/ def toOrderHom {a b : SimplexCategory} (f : SimplexCategory.Hom a b) : Fin (a.len + 1) →o Fin (b.len + 1) := f #align simplex_category.hom.to_order_hom SimplexCategory.Hom.toOrderHom theorem ext' {a b : SimplexCategory} (f g : SimplexCategory.Hom a b) : f.toOrderHom = g.toOrderHom → f = g := id #align simplex_category.hom.ext SimplexCategory.Hom.ext' attribute [irreducible] SimplexCategory.Hom @[simp] theorem mk_toOrderHom {a b : SimplexCategory} (f : SimplexCategory.Hom a b) : mk f.toOrderHom = f := rfl #align simplex_category.hom.mk_to_order_hom SimplexCategory.Hom.mk_toOrderHom @[simp] theorem toOrderHom_mk {a b : SimplexCategory} (f : Fin (a.len + 1) →o Fin (b.len + 1)) : (mk f).toOrderHom = f := rfl #align simplex_category.hom.to_order_hom_mk SimplexCategory.Hom.toOrderHom_mk theorem mk_toOrderHom_apply {a b : SimplexCategory} (f : Fin (a.len + 1) →o Fin (b.len + 1)) (i : Fin (a.len + 1)) : (mk f).toOrderHom i = f i := rfl #align simplex_category.hom.mk_to_order_hom_apply SimplexCategory.Hom.mk_toOrderHom_apply /-- Identity morphisms of `SimplexCategory`. -/ @[simp] def id (a : SimplexCategory) : SimplexCategory.Hom a a := mk OrderHom.id #align simplex_category.hom.id SimplexCategory.Hom.id /-- Composition of morphisms of `SimplexCategory`. -/ @[simp] def comp {a b c : SimplexCategory} (f : SimplexCategory.Hom b c) (g : SimplexCategory.Hom a b) : SimplexCategory.Hom a c := mk <| f.toOrderHom.comp g.toOrderHom #align simplex_category.hom.comp SimplexCategory.Hom.comp end Hom instance smallCategory : SmallCategory.{0} SimplexCategory where Hom n m := SimplexCategory.Hom n m id m := SimplexCategory.Hom.id _ comp f g := SimplexCategory.Hom.comp g f #align simplex_category.small_category SimplexCategory.smallCategory @[simp] lemma id_toOrderHom (a : SimplexCategory) : Hom.toOrderHom (𝟙 a) = OrderHom.id := rfl @[simp] lemma comp_toOrderHom {a b c: SimplexCategory} (f : a ⟶ b) (g : b ⟶ c) : (f ≫ g).toOrderHom = g.toOrderHom.comp f.toOrderHom := rfl -- Porting note: added because `Hom.ext'` is not triggered automatically @[ext] theorem Hom.ext {a b : SimplexCategory} (f g : a ⟶ b) : f.toOrderHom = g.toOrderHom → f = g := Hom.ext' _ _ /-- The constant morphism from [0]. -/ def const (x y : SimplexCategory) (i : Fin (y.len + 1)) : x ⟶ y := Hom.mk <| ⟨fun _ => i, by tauto⟩ #align simplex_category.const SimplexCategory.const @[simp] lemma const_eq_id : const [0] [0] 0 = 𝟙 _ := by aesop @[simp] lemma const_apply (x y : SimplexCategory) (i : Fin (y.len + 1)) (a : Fin (x.len + 1)) : (const x y i).toOrderHom a = i := rfl @[simp] theorem const_comp (x : SimplexCategory) {y z : SimplexCategory} (f : y ⟶ z) (i : Fin (y.len + 1)) : const x y i ≫ f = const x z (f.toOrderHom i) := rfl #align simplex_category.const_comp SimplexCategory.const_comp /-- Make a morphism `[n] ⟶ [m]` from a monotone map between fin's. This is useful for constructing morphisms between `[n]` directly without identifying `n` with `[n].len`. -/ @[simp] def mkHom {n m : ℕ} (f : Fin (n + 1) →o Fin (m + 1)) : ([n] : SimplexCategory) ⟶ [m] := SimplexCategory.Hom.mk f #align simplex_category.mk_hom SimplexCategory.mkHom theorem hom_zero_zero (f : ([0] : SimplexCategory) ⟶ [0]) : f = 𝟙 _ := by ext : 3 apply @Subsingleton.elim (Fin 1) #align simplex_category.hom_zero_zero SimplexCategory.hom_zero_zero end open Simplicial section Generators /-! ## Generating maps for the simplex category TODO: prove that the simplex category is equivalent to one given by the following generators and relations. -/ /-- The `i`-th face map from `[n]` to `[n+1]` -/ def δ {n} (i : Fin (n + 2)) : ([n] : SimplexCategory) ⟶ [n + 1] := mkHom (Fin.succAboveOrderEmb i).toOrderHom #align simplex_category.δ SimplexCategory.δ /-- The `i`-th degeneracy map from `[n+1]` to `[n]` -/ def σ {n} (i : Fin (n + 1)) : ([n + 1] : SimplexCategory) ⟶ [n] := mkHom { toFun := Fin.predAbove i monotone' := Fin.predAbove_right_monotone i } #align simplex_category.σ SimplexCategory.σ /-- The generic case of the first simplicial identity -/ theorem δ_comp_δ {n} {i j : Fin (n + 2)} (H : i ≤ j) : δ i ≫ δ j.succ = δ j ≫ δ (Fin.castSucc i) := by ext k dsimp [δ, Fin.succAbove] rcases i with ⟨i, _⟩ rcases j with ⟨j, _⟩ rcases k with ⟨k, _⟩ split_ifs <;> · simp at * <;> omega #align simplex_category.δ_comp_δ SimplexCategory.δ_comp_δ theorem δ_comp_δ' {n} {i : Fin (n + 2)} {j : Fin (n + 3)} (H : Fin.castSucc i < j) : δ i ≫ δ j = δ (j.pred fun (hj : j = 0) => by simp [hj, Fin.not_lt_zero] at H) ≫ δ (Fin.castSucc i) := by rw [← δ_comp_δ] · rw [Fin.succ_pred] · simpa only [Fin.le_iff_val_le_val, ← Nat.lt_succ_iff, Nat.succ_eq_add_one, ← Fin.val_succ, j.succ_pred, Fin.lt_iff_val_lt_val] using H #align simplex_category.δ_comp_δ' SimplexCategory.δ_comp_δ' theorem δ_comp_δ'' {n} {i : Fin (n + 3)} {j : Fin (n + 2)} (H : i ≤ Fin.castSucc j) : δ (i.castLT (Nat.lt_of_le_of_lt (Fin.le_iff_val_le_val.mp H) j.is_lt)) ≫ δ j.succ = δ j ≫ δ i := by rw [δ_comp_δ] · rfl · exact H #align simplex_category.δ_comp_δ'' SimplexCategory.δ_comp_δ'' /-- The special case of the first simplicial identity -/ @[reassoc] theorem δ_comp_δ_self {n} {i : Fin (n + 2)} : δ i ≫ δ (Fin.castSucc i) = δ i ≫ δ i.succ := (δ_comp_δ (le_refl i)).symm #align simplex_category.δ_comp_δ_self SimplexCategory.δ_comp_δ_self @[reassoc] theorem δ_comp_δ_self' {n} {i : Fin (n + 2)} {j : Fin (n + 3)} (H : j = Fin.castSucc i) : δ i ≫ δ j = δ i ≫ δ i.succ := by subst H rw [δ_comp_δ_self] #align simplex_category.δ_comp_δ_self' SimplexCategory.δ_comp_δ_self' /-- The second simplicial identity -/ @[reassoc] theorem δ_comp_σ_of_le {n} {i : Fin (n + 2)} {j : Fin (n + 1)} (H : i ≤ Fin.castSucc j) : δ (Fin.castSucc i) ≫ σ j.succ = σ j ≫ δ i := by ext k : 3 dsimp [σ, δ] rcases le_or_lt i k with (hik | hik) · rw [Fin.succAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr hik), Fin.succ_predAbove_succ, Fin.succAbove_of_le_castSucc] rcases le_or_lt k (j.castSucc) with (hjk | hjk) · rwa [Fin.predAbove_of_le_castSucc _ _ hjk, Fin.castSucc_castPred] · rw [Fin.le_castSucc_iff, Fin.predAbove_of_castSucc_lt _ _ hjk, Fin.succ_pred] exact H.trans_lt hjk · rw [Fin.succAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_castSucc_iff.mpr hik)] have hjk := H.trans_lt' hik rw [Fin.predAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr (hjk.trans (Fin.castSucc_lt_succ _)).le), Fin.predAbove_of_le_castSucc _ _ hjk.le, Fin.castPred_castSucc, Fin.succAbove_of_castSucc_lt, Fin.castSucc_castPred] rwa [Fin.castSucc_castPred] #align simplex_category.δ_comp_σ_of_le SimplexCategory.δ_comp_σ_of_le /-- The first part of the third simplicial identity -/ @[reassoc] theorem δ_comp_σ_self {n} {i : Fin (n + 1)} : δ (Fin.castSucc i) ≫ σ i = 𝟙 ([n] : SimplexCategory) := by rcases i with ⟨i, hi⟩ ext ⟨j, hj⟩ simp? at hj says simp only [len_mk] at hj dsimp [σ, δ, Fin.predAbove, Fin.succAbove] simp only [Fin.lt_iff_val_lt_val, Fin.dite_val, Fin.ite_val, Fin.coe_pred, ge_iff_le, Fin.coe_castLT, dite_eq_ite] split_ifs any_goals simp all_goals omega #align simplex_category.δ_comp_σ_self SimplexCategory.δ_comp_σ_self @[reassoc] theorem δ_comp_σ_self' {n} {j : Fin (n + 2)} {i : Fin (n + 1)} (H : j = Fin.castSucc i) : δ j ≫ σ i = 𝟙 ([n] : SimplexCategory) := by subst H rw [δ_comp_σ_self] #align simplex_category.δ_comp_σ_self' SimplexCategory.δ_comp_σ_self' /-- The second part of the third simplicial identity -/ @[reassoc] theorem δ_comp_σ_succ {n} {i : Fin (n + 1)} : δ i.succ ≫ σ i = 𝟙 ([n] : SimplexCategory) := by ext j rcases i with ⟨i, _⟩ rcases j with ⟨j, _⟩ dsimp [δ, σ, Fin.succAbove, Fin.predAbove] split_ifs <;> simp <;> simp at * <;> omega #align simplex_category.δ_comp_σ_succ SimplexCategory.δ_comp_σ_succ @[reassoc] theorem δ_comp_σ_succ' {n} (j : Fin (n + 2)) (i : Fin (n + 1)) (H : j = i.succ) : δ j ≫ σ i = 𝟙 ([n] : SimplexCategory) := by subst H rw [δ_comp_σ_succ] #align simplex_category.δ_comp_σ_succ' SimplexCategory.δ_comp_σ_succ' /-- The fourth simplicial identity -/ @[reassoc] theorem δ_comp_σ_of_gt {n} {i : Fin (n + 2)} {j : Fin (n + 1)} (H : Fin.castSucc j < i) : δ i.succ ≫ σ (Fin.castSucc j) = σ j ≫ δ i := by ext k : 3 dsimp [δ, σ] rcases le_or_lt k i with (hik | hik) · rw [Fin.succAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_succ_iff.mpr hik)] rcases le_or_lt k (j.castSucc) with (hjk | hjk) · rw [Fin.predAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr hjk), Fin.castPred_castSucc, Fin.predAbove_of_le_castSucc _ _ hjk, Fin.succAbove_of_castSucc_lt, Fin.castSucc_castPred] rw [Fin.castSucc_castPred] exact hjk.trans_lt H · rw [Fin.predAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_castSucc_iff.mpr hjk), Fin.predAbove_of_castSucc_lt _ _ hjk, Fin.succAbove_of_castSucc_lt, Fin.castSucc_pred_eq_pred_castSucc] rwa [Fin.castSucc_lt_iff_succ_le, Fin.succ_pred] · rw [Fin.succAbove_of_le_castSucc _ _ (Fin.succ_le_castSucc_iff.mpr hik)] have hjk := H.trans hik rw [Fin.predAbove_of_castSucc_lt _ _ hjk, Fin.predAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_succ_iff.mpr hjk.le), Fin.pred_succ, Fin.succAbove_of_le_castSucc, Fin.succ_pred] rwa [Fin.le_castSucc_pred_iff] #align simplex_category.δ_comp_σ_of_gt SimplexCategory.δ_comp_σ_of_gt @[reassoc] theorem δ_comp_σ_of_gt' {n} {i : Fin (n + 3)} {j : Fin (n + 2)} (H : j.succ < i) : δ i ≫ σ j = σ (j.castLT ((add_lt_add_iff_right 1).mp (lt_of_lt_of_le H i.is_le))) ≫ δ (i.pred fun (hi : i = 0) => by simp only [Fin.not_lt_zero, hi] at H) := by rw [← δ_comp_σ_of_gt] · simp · rw [Fin.castSucc_castLT, ← Fin.succ_lt_succ_iff, Fin.succ_pred] exact H #align simplex_category.δ_comp_σ_of_gt' SimplexCategory.δ_comp_σ_of_gt' /-- The fifth simplicial identity -/ @[reassoc] theorem σ_comp_σ {n} {i j : Fin (n + 1)} (H : i ≤ j) : σ (Fin.castSucc i) ≫ σ j = σ j.succ ≫ σ i := by ext k : 3 dsimp [σ] cases' k using Fin.lastCases with k · simp only [len_mk, Fin.predAbove_right_last] · cases' k using Fin.cases with k · rw [Fin.castSucc_zero, Fin.predAbove_of_le_castSucc _ 0 (Fin.zero_le _), Fin.predAbove_of_le_castSucc _ _ (Fin.zero_le _), Fin.castPred_zero, Fin.predAbove_of_le_castSucc _ 0 (Fin.zero_le _), Fin.predAbove_of_le_castSucc _ _ (Fin.zero_le _)] · rcases le_or_lt i k with (h | h) · simp_rw [Fin.predAbove_of_castSucc_lt i.castSucc _ (Fin.castSucc_lt_castSucc_iff.mpr (Fin.castSucc_lt_succ_iff.mpr h)), ← Fin.succ_castSucc, Fin.pred_succ, Fin.succ_predAbove_succ] rw [Fin.predAbove_of_castSucc_lt i _ (Fin.castSucc_lt_succ_iff.mpr _), Fin.pred_succ] rcases le_or_lt k j with (hkj | hkj) · rwa [Fin.predAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr hkj), Fin.castPred_castSucc] · rw [Fin.predAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_castSucc_iff.mpr hkj), Fin.le_pred_iff, Fin.succ_le_castSucc_iff] exact H.trans_lt hkj · simp_rw [Fin.predAbove_of_le_castSucc i.castSucc _ (Fin.castSucc_le_castSucc_iff.mpr (Fin.succ_le_castSucc_iff.mpr h)), Fin.castPred_castSucc, ← Fin.succ_castSucc, Fin.succ_predAbove_succ] rw [Fin.predAbove_of_le_castSucc _ k.castSucc (Fin.castSucc_le_castSucc_iff.mpr (h.le.trans H)), Fin.castPred_castSucc, Fin.predAbove_of_le_castSucc _ k.succ (Fin.succ_le_castSucc_iff.mpr (H.trans_lt' h)), Fin.predAbove_of_le_castSucc _ k.succ (Fin.succ_le_castSucc_iff.mpr h)] #align simplex_category.σ_comp_σ SimplexCategory.σ_comp_σ /-- If `f : [m] ⟶ [n+1]` is a morphism and `j` is not in the range of `f`, then `factor_δ f j` is a morphism `[m] ⟶ [n]` such that `factor_δ f j ≫ δ j = f` (as witnessed by `factor_δ_spec`). -/ def factor_δ {m n : ℕ} (f : ([m] : SimplexCategory) ⟶ [n+1]) (j : Fin (n+2)) : ([m] : SimplexCategory) ⟶ [n] := f ≫ σ (Fin.predAbove 0 j) open Fin in lemma factor_δ_spec {m n : ℕ} (f : ([m] : SimplexCategory) ⟶ [n+1]) (j : Fin (n+2)) (hj : ∀ (k : Fin (m+1)), f.toOrderHom k ≠ j) : factor_δ f j ≫ δ j = f := by ext k : 3 specialize hj k dsimp [factor_δ, δ, σ] cases' j using cases with j · rw [predAbove_of_le_castSucc _ _ (zero_le _), castPred_zero, predAbove_of_castSucc_lt 0 _ (castSucc_zero ▸ pos_of_ne_zero hj), zero_succAbove, succ_pred] · rw [predAbove_of_castSucc_lt 0 _ (castSucc_zero ▸ succ_pos _), pred_succ] rcases hj.lt_or_lt with (hj | hj) · rw [predAbove_of_le_castSucc j _] swap · exact (le_castSucc_iff.mpr hj) · rw [succAbove_of_castSucc_lt] swap · rwa [castSucc_lt_succ_iff, castPred_le_iff, le_castSucc_iff] rw [castSucc_castPred] · rw [predAbove_of_castSucc_lt] swap · exact (castSucc_lt_succ _).trans hj rw [succAbove_of_le_castSucc] swap · rwa [succ_le_castSucc_iff, lt_pred_iff] rw [succ_pred] end Generators section Skeleton /-- The functor that exhibits `SimplexCategory` as skeleton of `NonemptyFinLinOrd` -/ @[simps obj map] def skeletalFunctor : SimplexCategory ⥤ NonemptyFinLinOrd where obj a := NonemptyFinLinOrd.of (Fin (a.len + 1)) map f := f.toOrderHom #align simplex_category.skeletal_functor SimplexCategory.skeletalFunctor theorem skeletalFunctor.coe_map {Δ₁ Δ₂ : SimplexCategory} (f : Δ₁ ⟶ Δ₂) : ↑(skeletalFunctor.map f) = f.toOrderHom := rfl #align simplex_category.skeletal_functor.coe_map SimplexCategory.skeletalFunctor.coe_map theorem skeletal : Skeletal SimplexCategory := fun X Y ⟨I⟩ => by suffices Fintype.card (Fin (X.len + 1)) = Fintype.card (Fin (Y.len + 1)) by ext simpa apply Fintype.card_congr exact ((skeletalFunctor ⋙ forget NonemptyFinLinOrd).mapIso I).toEquiv #align simplex_category.skeletal SimplexCategory.skeletal namespace SkeletalFunctor instance : skeletalFunctor.Full where map_surjective f := ⟨SimplexCategory.Hom.mk f, rfl⟩ instance : skeletalFunctor.Faithful where map_injective {_ _ f g} h := by ext1 exact h instance : skeletalFunctor.EssSurj where mem_essImage X := ⟨mk (Fintype.card X - 1 : ℕ), ⟨by have aux : Fintype.card X = Fintype.card X - 1 + 1 := (Nat.succ_pred_eq_of_pos <| Fintype.card_pos_iff.mpr ⟨⊥⟩).symm let f := monoEquivOfFin X aux have hf := (Finset.univ.orderEmbOfFin aux).strictMono refine { hom := ⟨f, hf.monotone⟩ inv := ⟨f.symm, ?_⟩ hom_inv_id := by ext1; apply f.symm_apply_apply inv_hom_id := by ext1; apply f.apply_symm_apply } intro i j h show f.symm i ≤ f.symm j rw [← hf.le_iff_le] show f (f.symm i) ≤ f (f.symm j) simpa only [OrderIso.apply_symm_apply]⟩⟩ noncomputable instance isEquivalence : skeletalFunctor.IsEquivalence where #align simplex_category.skeletal_functor.is_equivalence SimplexCategory.SkeletalFunctor.isEquivalence end SkeletalFunctor /-- The equivalence that exhibits `SimplexCategory` as skeleton of `NonemptyFinLinOrd` -/ noncomputable def skeletalEquivalence : SimplexCategory ≌ NonemptyFinLinOrd := Functor.asEquivalence skeletalFunctor #align simplex_category.skeletal_equivalence SimplexCategory.skeletalEquivalence end Skeleton /-- `SimplexCategory` is a skeleton of `NonemptyFinLinOrd`. -/ lemma isSkeletonOf : IsSkeletonOf NonemptyFinLinOrd SimplexCategory skeletalFunctor where skel := skeletal eqv := SkeletalFunctor.isEquivalence #align simplex_category.is_skeleton_of SimplexCategory.isSkeletonOf /-- The truncated simplex category. -/ def Truncated (n : ℕ) := FullSubcategory fun a : SimplexCategory => a.len ≤ n #align simplex_category.truncated SimplexCategory.Truncated instance (n : ℕ) : SmallCategory.{0} (Truncated n) := FullSubcategory.category _ namespace Truncated instance {n} : Inhabited (Truncated n) := ⟨⟨[0], by simp⟩⟩ /-- The fully faithful inclusion of the truncated simplex category into the usual simplex category. -/ def inclusion {n : ℕ} : SimplexCategory.Truncated n ⥤ SimplexCategory := fullSubcategoryInclusion _ #align simplex_category.truncated.inclusion SimplexCategory.Truncated.inclusion instance (n : ℕ) : (inclusion : Truncated n ⥤ _).Full := FullSubcategory.full _ instance (n : ℕ) : (inclusion : Truncated n ⥤ _).Faithful := FullSubcategory.faithful _ end Truncated section Concrete instance : ConcreteCategory.{0} SimplexCategory where forget := { obj := fun i => Fin (i.len + 1) map := fun f => f.toOrderHom } forget_faithful := ⟨fun h => by ext : 2; exact h⟩ end Concrete section EpiMono /-- A morphism in `SimplexCategory` is a monomorphism precisely when it is an injective function -/ theorem mono_iff_injective {n m : SimplexCategory} {f : n ⟶ m} : Mono f ↔ Function.Injective f.toOrderHom := by rw [← Functor.mono_map_iff_mono skeletalEquivalence.functor] dsimp only [skeletalEquivalence, Functor.asEquivalence_functor] simp only [skeletalFunctor_obj, skeletalFunctor_map, NonemptyFinLinOrd.mono_iff_injective, NonemptyFinLinOrd.coe_of] #align simplex_category.mono_iff_injective SimplexCategory.mono_iff_injective /-- A morphism in `SimplexCategory` is an epimorphism if and only if it is a surjective function -/ theorem epi_iff_surjective {n m : SimplexCategory} {f : n ⟶ m} : Epi f ↔ Function.Surjective f.toOrderHom := by rw [← Functor.epi_map_iff_epi skeletalEquivalence.functor] dsimp only [skeletalEquivalence, Functor.asEquivalence_functor] simp only [skeletalFunctor_obj, skeletalFunctor_map, NonemptyFinLinOrd.epi_iff_surjective, NonemptyFinLinOrd.coe_of] #align simplex_category.epi_iff_surjective SimplexCategory.epi_iff_surjective /-- A monomorphism in `SimplexCategory` must increase lengths-/ theorem len_le_of_mono {x y : SimplexCategory} {f : x ⟶ y} : Mono f → x.len ≤ y.len := by intro hyp_f_mono have f_inj : Function.Injective f.toOrderHom.toFun := mono_iff_injective.1 hyp_f_mono simpa using Fintype.card_le_of_injective f.toOrderHom.toFun f_inj #align simplex_category.len_le_of_mono SimplexCategory.len_le_of_mono theorem le_of_mono {n m : ℕ} {f : ([n] : SimplexCategory) ⟶ [m]} : CategoryTheory.Mono f → n ≤ m := len_le_of_mono #align simplex_category.le_of_mono SimplexCategory.le_of_mono /-- An epimorphism in `SimplexCategory` must decrease lengths-/ theorem len_le_of_epi {x y : SimplexCategory} {f : x ⟶ y} : Epi f → y.len ≤ x.len := by intro hyp_f_epi have f_surj : Function.Surjective f.toOrderHom.toFun := epi_iff_surjective.1 hyp_f_epi simpa using Fintype.card_le_of_surjective f.toOrderHom.toFun f_surj #align simplex_category.len_le_of_epi SimplexCategory.len_le_of_epi theorem le_of_epi {n m : ℕ} {f : ([n] : SimplexCategory) ⟶ [m]} : Epi f → m ≤ n := len_le_of_epi #align simplex_category.le_of_epi SimplexCategory.le_of_epi instance {n : ℕ} {i : Fin (n + 2)} : Mono (δ i) := by rw [mono_iff_injective] exact Fin.succAbove_right_injective instance {n : ℕ} {i : Fin (n + 1)} : Epi (σ i) := by rw [epi_iff_surjective] intro b simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk] by_cases h : b ≤ i · use b -- This was not needed before leanprover/lean4#2644 dsimp rw [Fin.predAbove_of_le_castSucc i b (by simpa only [Fin.coe_eq_castSucc] using h)] simp only [len_mk, Fin.coe_eq_castSucc, Fin.castPred_castSucc] · use b.succ -- This was not needed before leanprover/lean4#2644 dsimp rw [Fin.predAbove_of_castSucc_lt i b.succ _, Fin.pred_succ] rw [not_le] at h rw [Fin.lt_iff_val_lt_val] at h ⊢ simpa only [Fin.val_succ, Fin.coe_castSucc] using Nat.lt.step h instance : (forget SimplexCategory).ReflectsIsomorphisms := ⟨fun f hf => Iso.isIso_hom { hom := f inv := Hom.mk { toFun := inv ((forget SimplexCategory).map f) monotone' := fun y₁ y₂ h => by by_cases h' : y₁ < y₂ · by_contra h'' apply not_le.mpr h' convert f.toOrderHom.monotone (le_of_not_ge h'') all_goals exact (congr_hom (Iso.inv_hom_id (asIso ((forget SimplexCategory).map f))) _).symm · rw [eq_of_le_of_not_lt h h'] } hom_inv_id := by ext1 ext1 exact Iso.hom_inv_id (asIso ((forget _).map f)) inv_hom_id := by ext1 ext1 exact Iso.inv_hom_id (asIso ((forget _).map f)) }⟩ theorem isIso_of_bijective {x y : SimplexCategory} {f : x ⟶ y} (hf : Function.Bijective f.toOrderHom.toFun) : IsIso f := haveI : IsIso ((forget SimplexCategory).map f) := (isIso_iff_bijective _).mpr hf isIso_of_reflects_iso f (forget SimplexCategory) #align simplex_category.is_iso_of_bijective SimplexCategory.isIso_of_bijective /-- An isomorphism in `SimplexCategory` induces an `OrderIso`. -/ @[simp] def orderIsoOfIso {x y : SimplexCategory} (e : x ≅ y) : Fin (x.len + 1) ≃o Fin (y.len + 1) := Equiv.toOrderIso { toFun := e.hom.toOrderHom invFun := e.inv.toOrderHom left_inv := fun i => by simpa only using congr_arg (fun φ => (Hom.toOrderHom φ) i) e.hom_inv_id right_inv := fun i => by simpa only using congr_arg (fun φ => (Hom.toOrderHom φ) i) e.inv_hom_id } e.hom.toOrderHom.monotone e.inv.toOrderHom.monotone #align simplex_category.order_iso_of_iso SimplexCategory.orderIsoOfIso theorem iso_eq_iso_refl {x : SimplexCategory} (e : x ≅ x) : e = Iso.refl x := by have h : (Finset.univ : Finset (Fin (x.len + 1))).card = x.len + 1 := Finset.card_fin (x.len + 1) have eq₁ := Finset.orderEmbOfFin_unique' h fun i => Finset.mem_univ ((orderIsoOfIso e) i) have eq₂ := Finset.orderEmbOfFin_unique' h fun i => Finset.mem_univ ((orderIsoOfIso (Iso.refl x)) i) -- Porting note: the proof was rewritten from this point in #3414 (reenableeta) -- It could be investigated again to see if the original can be restored. ext x replace eq₁ := congr_arg (· x) eq₁ replace eq₂ := congr_arg (· x) eq₂.symm simp_all #align simplex_category.iso_eq_iso_refl SimplexCategory.iso_eq_iso_refl theorem eq_id_of_isIso {x : SimplexCategory} (f : x ⟶ x) [IsIso f] : f = 𝟙 _ := congr_arg (fun φ : _ ≅ _ => φ.hom) (iso_eq_iso_refl (asIso f)) #align simplex_category.eq_id_of_is_iso SimplexCategory.eq_id_of_isIso theorem eq_σ_comp_of_not_injective' {n : ℕ} {Δ' : SimplexCategory} (θ : mk (n + 1) ⟶ Δ') (i : Fin (n + 1)) (hi : θ.toOrderHom (Fin.castSucc i) = θ.toOrderHom i.succ) : ∃ θ' : mk n ⟶ Δ', θ = σ i ≫ θ' := by use δ i.succ ≫ θ ext1; ext1; ext1 x simp only [len_mk, σ, mkHom, comp_toOrderHom, Hom.toOrderHom_mk, OrderHom.comp_coe, OrderHom.coe_mk, Function.comp_apply] by_cases h' : x ≤ Fin.castSucc i · -- This was not needed before leanprover/lean4#2644 dsimp rw [Fin.predAbove_of_le_castSucc i x h'] dsimp [δ] erw [Fin.succAbove_of_castSucc_lt _ _ _] · rw [Fin.castSucc_castPred] · exact (Fin.castSucc_lt_succ_iff.mpr h') · simp only [not_le] at h' let y := x.pred <| by rintro (rfl : x = 0); simp at h' have hy : x = y.succ := (Fin.succ_pred x _).symm rw [hy] at h' ⊢ -- This was not needed before leanprover/lean4#2644 conv_rhs => dsimp rw [Fin.predAbove_of_castSucc_lt i y.succ h', Fin.pred_succ] by_cases h'' : y = i · rw [h''] refine hi.symm.trans ?_ congr 1 dsimp [δ] erw [Fin.succAbove_of_castSucc_lt i.succ] exact Fin.lt_succ · dsimp [δ] erw [Fin.succAbove_of_le_castSucc i.succ _] simp only [Fin.lt_iff_val_lt_val, Fin.le_iff_val_le_val, Fin.val_succ, Fin.coe_castSucc, Nat.lt_succ_iff, Fin.ext_iff] at h' h'' ⊢ cases' Nat.le.dest h' with c hc cases c · exfalso simp only [Nat.zero_eq, add_zero, len_mk, Fin.coe_pred, ge_iff_le] at hc rw [hc] at h'' exact h'' rfl · rw [← hc] simp only [add_le_add_iff_left, Nat.succ_eq_add_one, le_add_iff_nonneg_left, zero_le] #align simplex_category.eq_σ_comp_of_not_injective' SimplexCategory.eq_σ_comp_of_not_injective' theorem eq_σ_comp_of_not_injective {n : ℕ} {Δ' : SimplexCategory} (θ : mk (n + 1) ⟶ Δ') (hθ : ¬Function.Injective θ.toOrderHom) : ∃ (i : Fin (n + 1)) (θ' : mk n ⟶ Δ'), θ = σ i ≫ θ' := by simp only [Function.Injective, exists_prop, not_forall] at hθ -- as θ is not injective, there exists `x<y` such that `θ x = θ y` -- and then, `θ x = θ (x+1)` have hθ₂ : ∃ x y : Fin (n + 2), (Hom.toOrderHom θ) x = (Hom.toOrderHom θ) y ∧ x < y := by rcases hθ with ⟨x, y, ⟨h₁, h₂⟩⟩ by_cases h : x < y · exact ⟨x, y, ⟨h₁, h⟩⟩ · refine ⟨y, x, ⟨h₁.symm, ?_⟩⟩ rcases lt_or_eq_of_le (not_lt.mp h) with h' | h' · exact h' · exfalso exact h₂ h'.symm rcases hθ₂ with ⟨x, y, ⟨h₁, h₂⟩⟩ use x.castPred ((Fin.le_last _).trans_lt' h₂).ne apply eq_σ_comp_of_not_injective' apply le_antisymm · exact θ.toOrderHom.monotone (le_of_lt (Fin.castSucc_lt_succ _)) · rw [Fin.castSucc_castPred, h₁] exact θ.toOrderHom.monotone ((Fin.succ_castPred_le_iff _).mpr h₂) #align simplex_category.eq_σ_comp_of_not_injective SimplexCategory.eq_σ_comp_of_not_injective theorem eq_comp_δ_of_not_surjective' {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1)) (i : Fin (n + 2)) (hi : ∀ x, θ.toOrderHom x ≠ i) : ∃ θ' : Δ ⟶ mk n, θ = θ' ≫ δ i := by by_cases h : i < Fin.last (n + 1) · use θ ≫ σ (Fin.castPred i h.ne) ext1 ext1 ext1 x simp only [len_mk, Category.assoc, comp_toOrderHom, OrderHom.comp_coe, Function.comp_apply] by_cases h' : θ.toOrderHom x ≤ i · simp only [σ, mkHom, Hom.toOrderHom_mk, OrderHom.coe_mk] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [Fin.predAbove_of_le_castSucc _ _ (by rwa [Fin.castSucc_castPred])] dsimp [δ] erw [Fin.succAbove_of_castSucc_lt i] · rw [Fin.castSucc_castPred] · rw [(hi x).le_iff_lt] at h' exact h' · simp only [not_le] at h' dsimp [σ, δ] erw [Fin.predAbove_of_castSucc_lt _ _ (by rwa [Fin.castSucc_castPred])] rw [Fin.succAbove_of_le_castSucc i _] · erw [Fin.succ_pred] · exact Nat.le_sub_one_of_lt (Fin.lt_iff_val_lt_val.mp h') · obtain rfl := le_antisymm (Fin.le_last i) (not_lt.mp h) use θ ≫ σ (Fin.last _) ext x : 3 dsimp [δ, σ] simp_rw [Fin.succAbove_last, Fin.predAbove_last_apply] erw [dif_neg (hi x)] rw [Fin.castSucc_castPred] #align simplex_category.eq_comp_δ_of_not_surjective' SimplexCategory.eq_comp_δ_of_not_surjective' theorem eq_comp_δ_of_not_surjective {n : ℕ} {Δ : SimplexCategory} (θ : Δ ⟶ mk (n + 1)) (hθ : ¬Function.Surjective θ.toOrderHom) : ∃ (i : Fin (n + 2)) (θ' : Δ ⟶ mk n), θ = θ' ≫ δ i := by cases' not_forall.mp hθ with i hi use i exact eq_comp_δ_of_not_surjective' θ i (not_exists.mp hi) #align simplex_category.eq_comp_δ_of_not_surjective SimplexCategory.eq_comp_δ_of_not_surjective theorem eq_id_of_mono {x : SimplexCategory} (i : x ⟶ x) [Mono i] : i = 𝟙 _ := by suffices IsIso i by apply eq_id_of_isIso apply isIso_of_bijective dsimp rw [Fintype.bijective_iff_injective_and_card i.toOrderHom, ← mono_iff_injective, eq_self_iff_true, and_true_iff] infer_instance #align simplex_category.eq_id_of_mono SimplexCategory.eq_id_of_mono theorem eq_id_of_epi {x : SimplexCategory} (i : x ⟶ x) [Epi i] : i = 𝟙 _ := by suffices IsIso i by haveI := this apply eq_id_of_isIso apply isIso_of_bijective dsimp rw [Fintype.bijective_iff_surjective_and_card i.toOrderHom, ← epi_iff_surjective, eq_self_iff_true, and_true_iff] infer_instance #align simplex_category.eq_id_of_epi SimplexCategory.eq_id_of_epi
Mathlib/AlgebraicTopology/SimplexCategory.lean
803
812
theorem eq_σ_of_epi {n : ℕ} (θ : mk (n + 1) ⟶ mk n) [Epi θ] : ∃ i : Fin (n + 1), θ = σ i := by
rcases eq_σ_comp_of_not_injective θ (by by_contra h simpa using le_of_mono (mono_iff_injective.mpr h)) with ⟨i, θ', h⟩ use i haveI : Epi (σ i ≫ θ') := by rw [← h] infer_instance haveI := CategoryTheory.epi_of_epi (σ i) θ' rw [h, eq_id_of_epi θ', Category.comp_id]
/- 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. -/ 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⟩⟩ #align cardinal.ord_aleph'_eq_enum_card Cardinal.ord_aleph'_eq_enum_card /-- Infinite ordinals that are cardinals are unbounded. -/ theorem ord_card_unbounded' : Unbounded (· < ·) { b : Ordinal | b.card.ord = b ∧ ω ≤ b } := (unbounded_lt_inter_le ω).2 ord_card_unbounded #align cardinal.ord_card_unbounded' Cardinal.ord_card_unbounded' theorem eq_aleph_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) (ho' : ω ≤ o) : ∃ a, (aleph a).ord = o := by cases' eq_aleph'_of_eq_card_ord ho with a ha use a - ω unfold aleph rwa [Ordinal.add_sub_cancel_of_le] rwa [← aleph0_le_aleph', ← ord_le_ord, ha, ord_aleph0] #align cardinal.eq_aleph_of_eq_card_ord Cardinal.eq_aleph_of_eq_card_ord /-- `ord ∘ aleph` enumerates the infinite ordinals that are cardinals. -/ theorem ord_aleph_eq_enum_card : ord ∘ aleph = enumOrd { b : Ordinal | b.card.ord = b ∧ ω ≤ b } := by rw [← eq_enumOrd _ ord_card_unbounded'] use aleph_isNormal.strictMono rw [range_eq_iff] refine ⟨fun a => ⟨?_, ?_⟩, fun b hb => eq_aleph_of_eq_card_ord hb.1 hb.2⟩ · rw [Function.comp_apply, card_ord] · rw [← ord_aleph0, Function.comp_apply, ord_le_ord] exact aleph0_le_aleph _ #align cardinal.ord_aleph_eq_enum_card Cardinal.ord_aleph_eq_enum_card end aleph /-! ### Beth cardinals -/ section beth /-- Beth numbers are defined so that `beth 0 = ℵ₀`, `beth (succ o) = 2 ^ (beth o)`, and when `o` is a limit ordinal, `beth o` is the supremum of `beth o'` for `o' < o`. Assuming the generalized continuum hypothesis, which is undecidable in ZFC, `beth o = aleph o` for every `o`. -/ def beth (o : Ordinal.{u}) : Cardinal.{u} := limitRecOn o aleph0 (fun _ x => (2 : Cardinal) ^ x) fun a _ IH => ⨆ b : Iio a, IH b.1 b.2 #align cardinal.beth Cardinal.beth @[simp] theorem beth_zero : beth 0 = aleph0 := limitRecOn_zero _ _ _ #align cardinal.beth_zero Cardinal.beth_zero @[simp] theorem beth_succ (o : Ordinal) : beth (succ o) = 2 ^ beth o := limitRecOn_succ _ _ _ _ #align cardinal.beth_succ Cardinal.beth_succ theorem beth_limit {o : Ordinal} : o.IsLimit → beth o = ⨆ a : Iio o, beth a := limitRecOn_limit _ _ _ _ #align cardinal.beth_limit Cardinal.beth_limit theorem beth_strictMono : StrictMono beth := by intro a b induction' b using Ordinal.induction with b IH generalizing a intro h rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb) · exact (Ordinal.not_lt_zero a h).elim · rw [lt_succ_iff] at h rw [beth_succ] apply lt_of_le_of_lt _ (cantor _) rcases eq_or_lt_of_le h with (rfl | h) · rfl exact (IH c (lt_succ c) h).le · apply (cantor _).trans_le rw [beth_limit hb, ← beth_succ] exact le_ciSup (bddAbove_of_small _) (⟨_, hb.succ_lt h⟩ : Iio b) #align cardinal.beth_strict_mono Cardinal.beth_strictMono theorem beth_mono : Monotone beth := beth_strictMono.monotone #align cardinal.beth_mono Cardinal.beth_mono @[simp] theorem beth_lt {o₁ o₂ : Ordinal} : beth o₁ < beth o₂ ↔ o₁ < o₂ := beth_strictMono.lt_iff_lt #align cardinal.beth_lt Cardinal.beth_lt @[simp] theorem beth_le {o₁ o₂ : Ordinal} : beth o₁ ≤ beth o₂ ↔ o₁ ≤ o₂ := beth_strictMono.le_iff_le #align cardinal.beth_le Cardinal.beth_le theorem aleph_le_beth (o : Ordinal) : aleph o ≤ beth o := by induction o using limitRecOn with | H₁ => simp | H₂ o h => rw [aleph_succ, beth_succ, succ_le_iff] exact (cantor _).trans_le (power_le_power_left two_ne_zero h) | H₃ o ho IH => rw [aleph_limit ho, beth_limit ho] exact ciSup_mono (bddAbove_of_small _) fun x => IH x.1 x.2 #align cardinal.aleph_le_beth Cardinal.aleph_le_beth theorem aleph0_le_beth (o : Ordinal) : ℵ₀ ≤ beth o := (aleph0_le_aleph o).trans <| aleph_le_beth o #align cardinal.aleph_0_le_beth Cardinal.aleph0_le_beth theorem beth_pos (o : Ordinal) : 0 < beth o := aleph0_pos.trans_le <| aleph0_le_beth o #align cardinal.beth_pos Cardinal.beth_pos theorem beth_ne_zero (o : Ordinal) : beth o ≠ 0 := (beth_pos o).ne' #align cardinal.beth_ne_zero Cardinal.beth_ne_zero theorem beth_normal : IsNormal.{u} fun o => (beth o).ord := (isNormal_iff_strictMono_limit _).2 ⟨ord_strictMono.comp beth_strictMono, fun o ho a ha => by rw [beth_limit ho, ord_le] exact ciSup_le' fun b => ord_le.1 (ha _ b.2)⟩ #align cardinal.beth_normal Cardinal.beth_normal end beth /-! ### Properties of `mul` -/ section mulOrdinals /-- If `α` is an infinite type, then `α × α` and `α` have the same cardinality. -/ theorem mul_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : c * c = c := by refine le_antisymm ?_ (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans h) c) -- the only nontrivial part is `c * c ≤ c`. We prove it inductively. refine Acc.recOn (Cardinal.lt_wf.apply c) (fun c _ => Quotient.inductionOn c fun α IH ol => ?_) h -- consider the minimal well-order `r` on `α` (a type with cardinality `c`). rcases ord_eq α with ⟨r, wo, e⟩ letI := linearOrderOfSTO r haveI : IsWellOrder α (· < ·) := wo -- Define an order `s` on `α × α` by writing `(a, b) < (c, d)` if `max a b < max c d`, or -- the max are equal and `a < c`, or the max are equal and `a = c` and `b < d`. let g : α × α → α := fun p => max p.1 p.2 let f : α × α ↪ Ordinal × α × α := ⟨fun p : α × α => (typein (· < ·) (g p), p), fun p q => congr_arg Prod.snd⟩ let s := f ⁻¹'o Prod.Lex (· < ·) (Prod.Lex (· < ·) (· < ·)) -- this is a well order on `α × α`. haveI : IsWellOrder _ s := (RelEmbedding.preimage _ _).isWellOrder /- it suffices to show that this well order is smaller than `r` if it were larger, then `r` would be a strict prefix of `s`. It would be contained in `β × β` for some `β` of cardinality `< c`. By the inductive assumption, this set has the same cardinality as `β` (or it is finite if `β` is finite), so it is `< c`, which is a contradiction. -/ suffices type s ≤ type r by exact card_le_card this refine le_of_forall_lt fun o h => ?_ rcases typein_surj s h with ⟨p, rfl⟩ rw [← e, lt_ord] refine lt_of_le_of_lt (?_ : _ ≤ card (succ (typein (· < ·) (g p))) * card (succ (typein (· < ·) (g p)))) ?_ · have : { q | s q p } ⊆ insert (g p) { x | x < g p } ×ˢ insert (g p) { x | x < g p } := by intro q h simp only [s, f, Preimage, ge_iff_le, Embedding.coeFn_mk, Prod.lex_def, typein_lt_typein, typein_inj, mem_setOf_eq] at h exact max_le_iff.1 (le_iff_lt_or_eq.2 <| h.imp_right And.left) suffices H : (insert (g p) { x | r x (g p) } : Set α) ≃ Sum { x | r x (g p) } PUnit from ⟨(Set.embeddingOfSubset _ _ this).trans ((Equiv.Set.prod _ _).trans (H.prodCongr H)).toEmbedding⟩ refine (Equiv.Set.insert ?_).trans ((Equiv.refl _).sumCongr punitEquivPUnit) apply @irrefl _ r cases' lt_or_le (card (succ (typein (· < ·) (g p)))) ℵ₀ with qo qo · exact (mul_lt_aleph0 qo qo).trans_le ol · suffices (succ (typein LT.lt (g p))).card < ⟦α⟧ from (IH _ this qo).trans_lt this rw [← lt_ord] apply (ord_isLimit ol).2 rw [mk'_def, e] apply typein_lt_type #align cardinal.mul_eq_self Cardinal.mul_eq_self end mulOrdinals end UsingOrdinals /-! Properties of `mul`, not requiring ordinals -/ section mul /-- If `α` and `β` are infinite types, then the cardinality of `α × β` is the maximum of the cardinalities of `α` and `β`. -/ theorem mul_eq_max {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : ℵ₀ ≤ b) : a * b = max a b := le_antisymm (mul_eq_self (ha.trans (le_max_left a b)) ▸ mul_le_mul' (le_max_left _ _) (le_max_right _ _)) <| max_le (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans hb) a) (by simpa only [one_mul] using mul_le_mul_right' (one_le_aleph0.trans ha) b) #align cardinal.mul_eq_max Cardinal.mul_eq_max @[simp] theorem mul_mk_eq_max {α β : Type u} [Infinite α] [Infinite β] : #α * #β = max #α #β := mul_eq_max (aleph0_le_mk α) (aleph0_le_mk β) #align cardinal.mul_mk_eq_max Cardinal.mul_mk_eq_max @[simp] theorem aleph_mul_aleph (o₁ o₂ : Ordinal) : aleph o₁ * aleph o₂ = aleph (max o₁ o₂) := by rw [Cardinal.mul_eq_max (aleph0_le_aleph o₁) (aleph0_le_aleph o₂), max_aleph_eq] #align cardinal.aleph_mul_aleph Cardinal.aleph_mul_aleph @[simp] theorem aleph0_mul_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : ℵ₀ * a = a := (mul_eq_max le_rfl ha).trans (max_eq_right ha) #align cardinal.aleph_0_mul_eq Cardinal.aleph0_mul_eq @[simp] theorem mul_aleph0_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : a * ℵ₀ = a := (mul_eq_max ha le_rfl).trans (max_eq_left ha) #align cardinal.mul_aleph_0_eq Cardinal.mul_aleph0_eq -- Porting note (#10618): removed `simp`, `simp` can prove it theorem aleph0_mul_mk_eq {α : Type*} [Infinite α] : ℵ₀ * #α = #α := aleph0_mul_eq (aleph0_le_mk α) #align cardinal.aleph_0_mul_mk_eq Cardinal.aleph0_mul_mk_eq -- Porting note (#10618): removed `simp`, `simp` can prove it theorem mk_mul_aleph0_eq {α : Type*} [Infinite α] : #α * ℵ₀ = #α := mul_aleph0_eq (aleph0_le_mk α) #align cardinal.mk_mul_aleph_0_eq Cardinal.mk_mul_aleph0_eq @[simp] theorem aleph0_mul_aleph (o : Ordinal) : ℵ₀ * aleph o = aleph o := aleph0_mul_eq (aleph0_le_aleph o) #align cardinal.aleph_0_mul_aleph Cardinal.aleph0_mul_aleph @[simp] theorem aleph_mul_aleph0 (o : Ordinal) : aleph o * ℵ₀ = aleph o := mul_aleph0_eq (aleph0_le_aleph o) #align cardinal.aleph_mul_aleph_0 Cardinal.aleph_mul_aleph0 theorem mul_lt_of_lt {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a * b < c := (mul_le_mul' (le_max_left a b) (le_max_right a b)).trans_lt <| (lt_or_le (max a b) ℵ₀).elim (fun h => (mul_lt_aleph0 h h).trans_le hc) fun h => by rw [mul_eq_self h] exact max_lt h1 h2 #align cardinal.mul_lt_of_lt Cardinal.mul_lt_of_lt theorem mul_le_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) : a * b ≤ max a b := by convert mul_le_mul' (le_max_left a b) (le_max_right a b) using 1 rw [mul_eq_self] exact h.trans (le_max_left a b) #align cardinal.mul_le_max_of_aleph_0_le_left Cardinal.mul_le_max_of_aleph0_le_left theorem mul_eq_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) (h' : b ≠ 0) : a * b = max a b := by rcases le_or_lt ℵ₀ b with hb | hb · exact mul_eq_max h hb refine (mul_le_max_of_aleph0_le_left h).antisymm ?_ have : b ≤ a := hb.le.trans h rw [max_eq_left this] convert mul_le_mul_left' (one_le_iff_ne_zero.mpr h') a rw [mul_one] #align cardinal.mul_eq_max_of_aleph_0_le_left Cardinal.mul_eq_max_of_aleph0_le_left theorem mul_le_max_of_aleph0_le_right {a b : Cardinal} (h : ℵ₀ ≤ b) : a * b ≤ max a b := by simpa only [mul_comm b, max_comm b] using mul_le_max_of_aleph0_le_left h #align cardinal.mul_le_max_of_aleph_0_le_right Cardinal.mul_le_max_of_aleph0_le_right theorem mul_eq_max_of_aleph0_le_right {a b : Cardinal} (h' : a ≠ 0) (h : ℵ₀ ≤ b) : a * b = max a b := by rw [mul_comm, max_comm] exact mul_eq_max_of_aleph0_le_left h h' #align cardinal.mul_eq_max_of_aleph_0_le_right Cardinal.mul_eq_max_of_aleph0_le_right theorem mul_eq_max' {a b : Cardinal} (h : ℵ₀ ≤ a * b) : a * b = max a b := by rcases aleph0_le_mul_iff.mp h with ⟨ha, hb, ha' | hb'⟩ · exact mul_eq_max_of_aleph0_le_left ha' hb · exact mul_eq_max_of_aleph0_le_right ha hb' #align cardinal.mul_eq_max' Cardinal.mul_eq_max' theorem mul_le_max (a b : Cardinal) : a * b ≤ max (max a b) ℵ₀ := by rcases eq_or_ne a 0 with (rfl | ha0); · simp rcases eq_or_ne b 0 with (rfl | hb0); · simp rcases le_or_lt ℵ₀ a with ha | ha · rw [mul_eq_max_of_aleph0_le_left ha hb0] exact le_max_left _ _ · rcases le_or_lt ℵ₀ b with hb | hb · rw [mul_comm, mul_eq_max_of_aleph0_le_left hb ha0, max_comm] exact le_max_left _ _ · exact le_max_of_le_right (mul_lt_aleph0 ha hb).le #align cardinal.mul_le_max Cardinal.mul_le_max theorem mul_eq_left {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) (hb' : b ≠ 0) : a * b = a := by rw [mul_eq_max_of_aleph0_le_left ha hb', max_eq_left hb] #align cardinal.mul_eq_left Cardinal.mul_eq_left theorem mul_eq_right {a b : Cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) (ha' : a ≠ 0) : a * b = b := by rw [mul_comm, mul_eq_left hb ha ha'] #align cardinal.mul_eq_right Cardinal.mul_eq_right theorem le_mul_left {a b : Cardinal} (h : b ≠ 0) : a ≤ b * a := by convert mul_le_mul_right' (one_le_iff_ne_zero.mpr h) a rw [one_mul] #align cardinal.le_mul_left Cardinal.le_mul_left theorem le_mul_right {a b : Cardinal} (h : b ≠ 0) : a ≤ a * b := by rw [mul_comm] exact le_mul_left h #align cardinal.le_mul_right Cardinal.le_mul_right theorem mul_eq_left_iff {a b : Cardinal} : a * b = a ↔ max ℵ₀ b ≤ a ∧ b ≠ 0 ∨ b = 1 ∨ a = 0 := by rw [max_le_iff] refine ⟨fun h => ?_, ?_⟩ · rcases le_or_lt ℵ₀ a with ha | ha · have : a ≠ 0 := by rintro rfl exact ha.not_lt aleph0_pos left rw [and_assoc] use ha constructor · rw [← not_lt] exact fun hb => ne_of_gt (hb.trans_le (le_mul_left this)) h · rintro rfl apply this rw [mul_zero] at h exact h.symm right by_cases h2a : a = 0 · exact Or.inr h2a have hb : b ≠ 0 := by rintro rfl apply h2a rw [mul_zero] at h exact h.symm left rw [← h, mul_lt_aleph0_iff, lt_aleph0, lt_aleph0] at ha rcases ha with (rfl | rfl | ⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩) · contradiction · contradiction rw [← Ne] at h2a rw [← one_le_iff_ne_zero] at h2a hb norm_cast at h2a hb h ⊢ apply le_antisymm _ hb rw [← not_lt] apply fun h2b => ne_of_gt _ h conv_rhs => left; rw [← mul_one n] rw [mul_lt_mul_left] · exact id apply Nat.lt_of_succ_le h2a · rintro (⟨⟨ha, hab⟩, hb⟩ | rfl | rfl) · rw [mul_eq_max_of_aleph0_le_left ha hb, max_eq_left hab] all_goals simp #align cardinal.mul_eq_left_iff Cardinal.mul_eq_left_iff end mul /-! ### Properties of `add` -/ section add /-- If `α` is an infinite type, then `α ⊕ α` and `α` have the same cardinality. -/ theorem add_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : c + c = c := le_antisymm (by convert mul_le_mul_right' ((nat_lt_aleph0 2).le.trans h) c using 1 <;> simp [two_mul, mul_eq_self h]) (self_le_add_left c c) #align cardinal.add_eq_self Cardinal.add_eq_self /-- If `α` is an infinite type, then the cardinality of `α ⊕ β` is the maximum of the cardinalities of `α` and `β`. -/ theorem add_eq_max {a b : Cardinal} (ha : ℵ₀ ≤ a) : a + b = max a b := le_antisymm (add_eq_self (ha.trans (le_max_left a b)) ▸ add_le_add (le_max_left _ _) (le_max_right _ _)) <| max_le (self_le_add_right _ _) (self_le_add_left _ _) #align cardinal.add_eq_max Cardinal.add_eq_max theorem add_eq_max' {a b : Cardinal} (ha : ℵ₀ ≤ b) : a + b = max a b := by rw [add_comm, max_comm, add_eq_max ha] #align cardinal.add_eq_max' Cardinal.add_eq_max' @[simp] theorem add_mk_eq_max {α β : Type u} [Infinite α] : #α + #β = max #α #β := add_eq_max (aleph0_le_mk α) #align cardinal.add_mk_eq_max Cardinal.add_mk_eq_max @[simp] theorem add_mk_eq_max' {α β : Type u} [Infinite β] : #α + #β = max #α #β := add_eq_max' (aleph0_le_mk β) #align cardinal.add_mk_eq_max' Cardinal.add_mk_eq_max' theorem add_le_max (a b : Cardinal) : a + b ≤ max (max a b) ℵ₀ := by rcases le_or_lt ℵ₀ a with ha | ha · rw [add_eq_max ha] exact le_max_left _ _ · rcases le_or_lt ℵ₀ b with hb | hb · rw [add_comm, add_eq_max hb, max_comm] exact le_max_left _ _ · exact le_max_of_le_right (add_lt_aleph0 ha hb).le #align cardinal.add_le_max Cardinal.add_le_max theorem add_le_of_le {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a ≤ c) (h2 : b ≤ c) : a + b ≤ c := (add_le_add h1 h2).trans <| le_of_eq <| add_eq_self hc #align cardinal.add_le_of_le Cardinal.add_le_of_le theorem add_lt_of_lt {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a + b < c := (add_le_add (le_max_left a b) (le_max_right a b)).trans_lt <| (lt_or_le (max a b) ℵ₀).elim (fun h => (add_lt_aleph0 h h).trans_le hc) fun h => by rw [add_eq_self h]; exact max_lt h1 h2 #align cardinal.add_lt_of_lt Cardinal.add_lt_of_lt theorem eq_of_add_eq_of_aleph0_le {a b c : Cardinal} (h : a + b = c) (ha : a < c) (hc : ℵ₀ ≤ c) : b = c := by apply le_antisymm · rw [← h] apply self_le_add_left rw [← not_lt]; intro hb have : a + b < c := add_lt_of_lt hc ha hb simp [h, lt_irrefl] at this #align cardinal.eq_of_add_eq_of_aleph_0_le Cardinal.eq_of_add_eq_of_aleph0_le theorem add_eq_left {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) : a + b = a := by rw [add_eq_max ha, max_eq_left hb] #align cardinal.add_eq_left Cardinal.add_eq_left theorem add_eq_right {a b : Cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) : a + b = b := by rw [add_comm, add_eq_left hb ha] #align cardinal.add_eq_right Cardinal.add_eq_right theorem add_eq_left_iff {a b : Cardinal} : a + b = a ↔ max ℵ₀ b ≤ a ∨ b = 0 := by rw [max_le_iff] refine ⟨fun h => ?_, ?_⟩ · rcases le_or_lt ℵ₀ a with ha | ha · left use ha rw [← not_lt] apply fun hb => ne_of_gt _ h intro hb exact hb.trans_le (self_le_add_left b a) right rw [← h, add_lt_aleph0_iff, lt_aleph0, lt_aleph0] at ha rcases ha with ⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩ norm_cast at h ⊢ rw [← add_right_inj, h, add_zero] · rintro (⟨h1, h2⟩ | h3) · rw [add_eq_max h1, max_eq_left h2] · rw [h3, add_zero] #align cardinal.add_eq_left_iff Cardinal.add_eq_left_iff theorem add_eq_right_iff {a b : Cardinal} : a + b = b ↔ max ℵ₀ a ≤ b ∨ a = 0 := by rw [add_comm, add_eq_left_iff] #align cardinal.add_eq_right_iff Cardinal.add_eq_right_iff theorem add_nat_eq {a : Cardinal} (n : ℕ) (ha : ℵ₀ ≤ a) : a + n = a := add_eq_left ha ((nat_lt_aleph0 _).le.trans ha) #align cardinal.add_nat_eq Cardinal.add_nat_eq theorem nat_add_eq {a : Cardinal} (n : ℕ) (ha : ℵ₀ ≤ a) : n + a = a := by rw [add_comm, add_nat_eq n ha] theorem add_one_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : a + 1 = a := add_one_of_aleph0_le ha #align cardinal.add_one_eq Cardinal.add_one_eq -- Porting note (#10618): removed `simp`, `simp` can prove it theorem mk_add_one_eq {α : Type*} [Infinite α] : #α + 1 = #α := add_one_eq (aleph0_le_mk α) #align cardinal.mk_add_one_eq Cardinal.mk_add_one_eq protected theorem eq_of_add_eq_add_left {a b c : Cardinal} (h : a + b = a + c) (ha : a < ℵ₀) : b = c := by rcases le_or_lt ℵ₀ b with hb | hb · have : a < b := ha.trans_le hb rw [add_eq_right hb this.le, eq_comm] at h rw [eq_of_add_eq_of_aleph0_le h this hb] · have hc : c < ℵ₀ := by rw [← not_le] intro hc apply lt_irrefl ℵ₀ apply (hc.trans (self_le_add_left _ a)).trans_lt rw [← h] apply add_lt_aleph0 ha hb rw [lt_aleph0] at * rcases ha with ⟨n, rfl⟩ rcases hb with ⟨m, rfl⟩ rcases hc with ⟨k, rfl⟩ norm_cast at h ⊢ apply add_left_cancel h #align cardinal.eq_of_add_eq_add_left Cardinal.eq_of_add_eq_add_left protected theorem eq_of_add_eq_add_right {a b c : Cardinal} (h : a + b = c + b) (hb : b < ℵ₀) : a = c := by rw [add_comm a b, add_comm c b] at h exact Cardinal.eq_of_add_eq_add_left h hb #align cardinal.eq_of_add_eq_add_right Cardinal.eq_of_add_eq_add_right end add section ciSup variable {ι : Type u} {ι' : Type w} (f : ι → Cardinal.{v}) section add variable [Nonempty ι] [Nonempty ι'] (hf : BddAbove (range f)) protected theorem ciSup_add (c : Cardinal.{v}) : (⨆ i, f i) + c = ⨆ i, f i + c := by have : ∀ i, f i + c ≤ (⨆ i, f i) + c := fun i ↦ add_le_add_right (le_ciSup hf i) c refine le_antisymm ?_ (ciSup_le' this) have bdd : BddAbove (range (f · + c)) := ⟨_, forall_mem_range.mpr this⟩ obtain hs | hs := lt_or_le (⨆ i, f i) ℵ₀ · obtain ⟨i, hi⟩ := exists_eq_of_iSup_eq_of_not_isLimit f hf _ (fun h ↦ hs.not_le h.aleph0_le) rfl exact hi ▸ le_ciSup bdd i rw [add_eq_max hs, max_le_iff] exact ⟨ciSup_mono bdd fun i ↦ self_le_add_right _ c, (self_le_add_left _ _).trans (le_ciSup bdd <| Classical.arbitrary ι)⟩ protected theorem add_ciSup (c : Cardinal.{v}) : c + (⨆ i, f i) = ⨆ i, c + f i := by rw [add_comm, Cardinal.ciSup_add f hf]; simp_rw [add_comm] protected theorem ciSup_add_ciSup (g : ι' → Cardinal.{v}) (hg : BddAbove (range g)) : (⨆ i, f i) + (⨆ j, g j) = ⨆ (i) (j), f i + g j := by simp_rw [Cardinal.ciSup_add f hf, Cardinal.add_ciSup g hg] end add protected theorem ciSup_mul (c : Cardinal.{v}) : (⨆ i, f i) * c = ⨆ i, f i * c := by cases isEmpty_or_nonempty ι; · simp obtain rfl | h0 := eq_or_ne c 0; · simp by_cases hf : BddAbove (range f); swap · have hfc : ¬ BddAbove (range (f · * c)) := fun bdd ↦ hf ⟨⨆ i, f i * c, forall_mem_range.mpr fun i ↦ (le_mul_right h0).trans (le_ciSup bdd i)⟩ simp [iSup, csSup_of_not_bddAbove, hf, hfc] have : ∀ i, f i * c ≤ (⨆ i, f i) * c := fun i ↦ mul_le_mul_right' (le_ciSup hf i) c refine le_antisymm ?_ (ciSup_le' this) have bdd : BddAbove (range (f · * c)) := ⟨_, forall_mem_range.mpr this⟩ obtain hs | hs := lt_or_le (⨆ i, f i) ℵ₀ · obtain ⟨i, hi⟩ := exists_eq_of_iSup_eq_of_not_isLimit f hf _ (fun h ↦ hs.not_le h.aleph0_le) rfl exact hi ▸ le_ciSup bdd i rw [mul_eq_max_of_aleph0_le_left hs h0, max_le_iff] obtain ⟨i, hi⟩ := exists_lt_of_lt_ciSup' (one_lt_aleph0.trans_le hs) exact ⟨ciSup_mono bdd fun i ↦ le_mul_right h0, (le_mul_left (zero_lt_one.trans hi).ne').trans (le_ciSup bdd i)⟩ protected theorem mul_ciSup (c : Cardinal.{v}) : c * (⨆ i, f i) = ⨆ i, c * f i := by rw [mul_comm, Cardinal.ciSup_mul f]; simp_rw [mul_comm] protected theorem ciSup_mul_ciSup (g : ι' → Cardinal.{v}) : (⨆ i, f i) * (⨆ j, g j) = ⨆ (i) (j), f i * g j := by simp_rw [Cardinal.ciSup_mul f, Cardinal.mul_ciSup g] end ciSup @[simp] theorem aleph_add_aleph (o₁ o₂ : Ordinal) : aleph o₁ + aleph o₂ = aleph (max o₁ o₂) := by rw [Cardinal.add_eq_max (aleph0_le_aleph o₁), max_aleph_eq] #align cardinal.aleph_add_aleph Cardinal.aleph_add_aleph theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Ordinal.Principal (· + ·) c.ord := fun a b ha hb => by rw [lt_ord, Ordinal.card_add] at * exact add_lt_of_lt hc ha hb #align cardinal.principal_add_ord Cardinal.principal_add_ord theorem principal_add_aleph (o : Ordinal) : Ordinal.Principal (· + ·) (aleph o).ord := principal_add_ord <| aleph0_le_aleph o #align cardinal.principal_add_aleph Cardinal.principal_add_aleph theorem add_right_inj_of_lt_aleph0 {α β γ : Cardinal} (γ₀ : γ < aleph0) : α + γ = β + γ ↔ α = β := ⟨fun h => Cardinal.eq_of_add_eq_add_right h γ₀, fun h => congr_arg (· + γ) h⟩ #align cardinal.add_right_inj_of_lt_aleph_0 Cardinal.add_right_inj_of_lt_aleph0 @[simp] theorem add_nat_inj {α β : Cardinal} (n : ℕ) : α + n = β + n ↔ α = β := add_right_inj_of_lt_aleph0 (nat_lt_aleph0 _) #align cardinal.add_nat_inj Cardinal.add_nat_inj @[simp] theorem add_one_inj {α β : Cardinal} : α + 1 = β + 1 ↔ α = β := add_right_inj_of_lt_aleph0 one_lt_aleph0 #align cardinal.add_one_inj Cardinal.add_one_inj theorem add_le_add_iff_of_lt_aleph0 {α β γ : Cardinal} (γ₀ : γ < Cardinal.aleph0) : α + γ ≤ β + γ ↔ α ≤ β := by refine ⟨fun h => ?_, fun h => add_le_add_right h γ⟩ contrapose h rw [not_le, lt_iff_le_and_ne, Ne] at h ⊢ exact ⟨add_le_add_right h.1 γ, mt (add_right_inj_of_lt_aleph0 γ₀).1 h.2⟩ #align cardinal.add_le_add_iff_of_lt_aleph_0 Cardinal.add_le_add_iff_of_lt_aleph0 @[simp] theorem add_nat_le_add_nat_iff {α β : Cardinal} (n : ℕ) : α + n ≤ β + n ↔ α ≤ β := add_le_add_iff_of_lt_aleph0 (nat_lt_aleph0 n) #align cardinal.add_nat_le_add_nat_iff_of_lt_aleph_0 Cardinal.add_nat_le_add_nat_iff @[deprecated (since := "2024-02-12")] alias add_nat_le_add_nat_iff_of_lt_aleph_0 := add_nat_le_add_nat_iff @[simp] theorem add_one_le_add_one_iff {α β : Cardinal} : α + 1 ≤ β + 1 ↔ α ≤ β := add_le_add_iff_of_lt_aleph0 one_lt_aleph0 #align cardinal.add_one_le_add_one_iff_of_lt_aleph_0 Cardinal.add_one_le_add_one_iff @[deprecated (since := "2024-02-12")] alias add_one_le_add_one_iff_of_lt_aleph_0 := add_one_le_add_one_iff /-! ### Properties about power -/ section pow theorem pow_le {κ μ : Cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : μ < ℵ₀) : κ ^ μ ≤ κ := let ⟨n, H3⟩ := lt_aleph0.1 H2 H3.symm ▸ Quotient.inductionOn κ (fun α H1 => Nat.recOn n (lt_of_lt_of_le (by rw [Nat.cast_zero, power_zero] exact one_lt_aleph0) H1).le fun n ih => le_of_le_of_eq (by rw [Nat.cast_succ, power_add, power_one] exact mul_le_mul_right' ih _) (mul_eq_self H1)) H1 #align cardinal.pow_le Cardinal.pow_le theorem pow_eq {κ μ : Cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : 1 ≤ μ) (H3 : μ < ℵ₀) : κ ^ μ = κ := (pow_le H1 H3).antisymm <| self_le_power κ H2 #align cardinal.pow_eq Cardinal.pow_eq theorem power_self_eq {c : Cardinal} (h : ℵ₀ ≤ c) : c ^ c = 2 ^ c := by apply ((power_le_power_right <| (cantor c).le).trans _).antisymm · exact power_le_power_right ((nat_lt_aleph0 2).le.trans h) · rw [← power_mul, mul_eq_self h] #align cardinal.power_self_eq Cardinal.power_self_eq theorem prod_eq_two_power {ι : Type u} [Infinite ι] {c : ι → Cardinal.{v}} (h₁ : ∀ i, 2 ≤ c i) (h₂ : ∀ i, lift.{u} (c i) ≤ lift.{v} #ι) : prod c = 2 ^ lift.{v} #ι := by rw [← lift_id'.{u, v} (prod.{u, v} c), lift_prod, ← lift_two_power] apply le_antisymm · refine (prod_le_prod _ _ h₂).trans_eq ?_ rw [prod_const, lift_lift, ← lift_power, power_self_eq (aleph0_le_mk ι), lift_umax.{u, v}] · rw [← prod_const', lift_prod] refine prod_le_prod _ _ fun i => ?_ rw [lift_two, ← lift_two.{u, v}, lift_le] exact h₁ i #align cardinal.prod_eq_two_power Cardinal.prod_eq_two_power theorem power_eq_two_power {c₁ c₂ : Cardinal} (h₁ : ℵ₀ ≤ c₁) (h₂ : 2 ≤ c₂) (h₂' : c₂ ≤ c₁) : c₂ ^ c₁ = 2 ^ c₁ := le_antisymm (power_self_eq h₁ ▸ power_le_power_right h₂') (power_le_power_right h₂) #align cardinal.power_eq_two_power Cardinal.power_eq_two_power theorem nat_power_eq {c : Cardinal.{u}} (h : ℵ₀ ≤ c) {n : ℕ} (hn : 2 ≤ n) : (n : Cardinal.{u}) ^ c = 2 ^ c := power_eq_two_power h (by assumption_mod_cast) ((nat_lt_aleph0 n).le.trans h) #align cardinal.nat_power_eq Cardinal.nat_power_eq theorem power_nat_le {c : Cardinal.{u}} {n : ℕ} (h : ℵ₀ ≤ c) : c ^ n ≤ c := pow_le h (nat_lt_aleph0 n) #align cardinal.power_nat_le Cardinal.power_nat_le theorem power_nat_eq {c : Cardinal.{u}} {n : ℕ} (h1 : ℵ₀ ≤ c) (h2 : 1 ≤ n) : c ^ n = c := pow_eq h1 (mod_cast h2) (nat_lt_aleph0 n) #align cardinal.power_nat_eq Cardinal.power_nat_eq theorem power_nat_le_max {c : Cardinal.{u}} {n : ℕ} : c ^ (n : Cardinal.{u}) ≤ max c ℵ₀ := by rcases le_or_lt ℵ₀ c with hc | hc · exact le_max_of_le_left (power_nat_le hc) · exact le_max_of_le_right (power_lt_aleph0 hc (nat_lt_aleph0 _)).le #align cardinal.power_nat_le_max Cardinal.power_nat_le_max theorem powerlt_aleph0 {c : Cardinal} (h : ℵ₀ ≤ c) : c ^< ℵ₀ = c := by apply le_antisymm · rw [powerlt_le] intro c' rw [lt_aleph0] rintro ⟨n, rfl⟩ apply power_nat_le h convert le_powerlt c one_lt_aleph0; rw [power_one] #align cardinal.powerlt_aleph_0 Cardinal.powerlt_aleph0 theorem powerlt_aleph0_le (c : Cardinal) : c ^< ℵ₀ ≤ max c ℵ₀ := by rcases le_or_lt ℵ₀ c with h | h · rw [powerlt_aleph0 h] apply le_max_left rw [powerlt_le] exact fun c' hc' => (power_lt_aleph0 h hc').le.trans (le_max_right _ _) #align cardinal.powerlt_aleph_0_le Cardinal.powerlt_aleph0_le end pow /-! ### Computing cardinality of various types -/ section computing section Function variable {α β : Type u} {β' : Type v} theorem mk_equiv_eq_zero_iff_lift_ne : #(α ≃ β') = 0 ↔ lift.{v} #α ≠ lift.{u} #β' := by rw [mk_eq_zero_iff, ← not_nonempty_iff, ← lift_mk_eq'] theorem mk_equiv_eq_zero_iff_ne : #(α ≃ β) = 0 ↔ #α ≠ #β := by rw [mk_equiv_eq_zero_iff_lift_ne, lift_id, lift_id] /-- This lemma makes lemmas assuming `Infinite α` applicable to the situation where we have `Infinite β` instead. -/ theorem mk_equiv_comm : #(α ≃ β') = #(β' ≃ α) := (ofBijective _ symm_bijective).cardinal_eq
Mathlib/SetTheory/Cardinal/Ordinal.lean
1,079
1,080
theorem mk_embedding_eq_zero_iff_lift_lt : #(α ↪ β') = 0 ↔ lift.{u} #β' < lift.{v} #α := by
rw [mk_eq_zero_iff, ← not_nonempty_iff, ← lift_mk_le', not_le]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky -/ import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Data.Fintype.Card import Mathlib.GroupTheory.Perm.Basic #align_import group_theory.perm.support from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # support of a permutation ## Main definitions In the following, `f g : Equiv.Perm α`. * `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed either by `f`, or by `g`. Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint. * `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`. * `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`. Assume `α` is a Fintype: * `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`. (Equivalently, `f.support` has at least 2 elements.) -/ open Equiv Finset namespace Equiv.Perm variable {α : Type*} section Disjoint /-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e., every element is fixed either by `f`, or by `g`. -/ def Disjoint (f g : Perm α) := ∀ x, f x = x ∨ g x = x #align equiv.perm.disjoint Equiv.Perm.Disjoint variable {f g h : Perm α} @[symm] theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self] #align equiv.perm.disjoint.symm Equiv.Perm.Disjoint.symm theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm #align equiv.perm.disjoint.symmetric Equiv.Perm.Disjoint.symmetric instance : IsSymm (Perm α) Disjoint := ⟨Disjoint.symmetric⟩ theorem disjoint_comm : Disjoint f g ↔ Disjoint g f := ⟨Disjoint.symm, Disjoint.symm⟩ #align equiv.perm.disjoint_comm Equiv.Perm.disjoint_comm theorem Disjoint.commute (h : Disjoint f g) : Commute f g := Equiv.ext fun x => (h x).elim (fun hf => (h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by simp [mul_apply, hf, g.injective hg]) fun hg => (h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by simp [mul_apply, hf, hg] #align equiv.perm.disjoint.commute Equiv.Perm.Disjoint.commute @[simp] theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl #align equiv.perm.disjoint_one_left Equiv.Perm.disjoint_one_left @[simp] theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl #align equiv.perm.disjoint_one_right Equiv.Perm.disjoint_one_right theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x := Iff.rfl #align equiv.perm.disjoint_iff_eq_or_eq Equiv.Perm.disjoint_iff_eq_or_eq @[simp] theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩ ext x cases' h x with hx hx <;> simp [hx] #align equiv.perm.disjoint_refl_iff Equiv.Perm.disjoint_refl_iff theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by intro x rw [inv_eq_iff_eq, eq_comm] exact h x #align equiv.perm.disjoint.inv_left Equiv.Perm.Disjoint.inv_left theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ := h.symm.inv_left.symm #align equiv.perm.disjoint.inv_right Equiv.Perm.Disjoint.inv_right @[simp] theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by refine ⟨fun h => ?_, Disjoint.inv_left⟩ convert h.inv_left #align equiv.perm.disjoint_inv_left_iff Equiv.Perm.disjoint_inv_left_iff @[simp] theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm] #align equiv.perm.disjoint_inv_right_iff Equiv.Perm.disjoint_inv_right_iff theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x => by cases H1 x <;> cases H2 x <;> simp [*] #align equiv.perm.disjoint.mul_left Equiv.Perm.Disjoint.mul_left theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by rw [disjoint_comm] exact H1.symm.mul_left H2.symm #align equiv.perm.disjoint.mul_right Equiv.Perm.Disjoint.mul_right -- Porting note (#11215): TODO: make it `@[simp]` theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g := (h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq] theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) := (disjoint_conj h).2 H theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) : Disjoint f l.prod := by induction' l with g l ih · exact disjoint_one_right _ · rw [List.prod_cons] exact (h _ (List.mem_cons_self _ _)).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg)) #align equiv.perm.disjoint_prod_right Equiv.Perm.disjoint_prod_right open scoped List in theorem disjoint_prod_perm {l₁ l₂ : List (Perm α)} (hl : l₁.Pairwise Disjoint) (hp : l₁ ~ l₂) : l₁.prod = l₂.prod := hp.prod_eq' <| hl.imp Disjoint.commute #align equiv.perm.disjoint_prod_perm Equiv.Perm.disjoint_prod_perm theorem nodup_of_pairwise_disjoint {l : List (Perm α)} (h1 : (1 : Perm α) ∉ l) (h2 : l.Pairwise Disjoint) : l.Nodup := by refine List.Pairwise.imp_of_mem ?_ h2 intro τ σ h_mem _ h_disjoint _ subst τ suffices (σ : Perm α) = 1 by rw [this] at h_mem exact h1 h_mem exact ext fun a => or_self_iff.mp (h_disjoint a) #align equiv.perm.nodup_of_pairwise_disjoint Equiv.Perm.nodup_of_pairwise_disjoint theorem pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x | 0 => rfl | n + 1 => by rw [pow_succ, mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self hfx n] #align equiv.perm.pow_apply_eq_self_of_apply_eq_self Equiv.Perm.pow_apply_eq_self_of_apply_eq_self theorem zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x | (n : ℕ) => pow_apply_eq_self_of_apply_eq_self hfx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx] #align equiv.perm.zpow_apply_eq_self_of_apply_eq_self Equiv.Perm.zpow_apply_eq_self_of_apply_eq_self theorem pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x | 0 => Or.inl rfl | n + 1 => (pow_apply_eq_of_apply_apply_eq_self hffx n).elim (fun h => Or.inr (by rw [pow_succ', mul_apply, h])) fun h => Or.inl (by rw [pow_succ', mul_apply, h, hffx]) #align equiv.perm.pow_apply_eq_of_apply_apply_eq_self Equiv.Perm.pow_apply_eq_of_apply_apply_eq_self theorem zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x | (n : ℕ) => pow_apply_eq_of_apply_apply_eq_self hffx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply, ← pow_succ', eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ, @eq_comm _ x, or_comm] exact pow_apply_eq_of_apply_apply_eq_self hffx _ #align equiv.perm.zpow_apply_eq_of_apply_apply_eq_self Equiv.Perm.zpow_apply_eq_of_apply_apply_eq_self theorem Disjoint.mul_apply_eq_iff {σ τ : Perm α} (hστ : Disjoint σ τ) {a : α} : (σ * τ) a = a ↔ σ a = a ∧ τ a = a := by refine ⟨fun h => ?_, fun h => by rw [mul_apply, h.2, h.1]⟩ cases' hστ a with hσ hτ · exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩ · exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩ #align equiv.perm.disjoint.mul_apply_eq_iff Equiv.Perm.Disjoint.mul_apply_eq_iff theorem Disjoint.mul_eq_one_iff {σ τ : Perm α} (hστ : Disjoint σ τ) : σ * τ = 1 ↔ σ = 1 ∧ τ = 1 := by simp_rw [ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and] #align equiv.perm.disjoint.mul_eq_one_iff Equiv.Perm.Disjoint.mul_eq_one_iff theorem Disjoint.zpow_disjoint_zpow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℤ) : Disjoint (σ ^ m) (τ ^ n) := fun x => Or.imp (fun h => zpow_apply_eq_self_of_apply_eq_self h m) (fun h => zpow_apply_eq_self_of_apply_eq_self h n) (hστ x) #align equiv.perm.disjoint.zpow_disjoint_zpow Equiv.Perm.Disjoint.zpow_disjoint_zpow theorem Disjoint.pow_disjoint_pow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℕ) : Disjoint (σ ^ m) (τ ^ n) := hστ.zpow_disjoint_zpow m n #align equiv.perm.disjoint.pow_disjoint_pow Equiv.Perm.Disjoint.pow_disjoint_pow end Disjoint section IsSwap variable [DecidableEq α] /-- `f.IsSwap` indicates that the permutation `f` is a transposition of two elements. -/ def IsSwap (f : Perm α) : Prop := ∃ x y, x ≠ y ∧ f = swap x y #align equiv.perm.is_swap Equiv.Perm.IsSwap @[simp] theorem ofSubtype_swap_eq {p : α → Prop} [DecidablePred p] (x y : Subtype p) : ofSubtype (Equiv.swap x y) = Equiv.swap ↑x ↑y := Equiv.ext fun z => by by_cases hz : p z · rw [swap_apply_def, ofSubtype_apply_of_mem _ hz] split_ifs with hzx hzy · simp_rw [hzx, Subtype.coe_eta, swap_apply_left] · simp_rw [hzy, Subtype.coe_eta, swap_apply_right] · rw [swap_apply_of_ne_of_ne] <;> simp [Subtype.ext_iff, *] · rw [ofSubtype_apply_of_not_mem _ hz, swap_apply_of_ne_of_ne] · intro h apply hz rw [h] exact Subtype.prop x intro h apply hz rw [h] exact Subtype.prop y #align equiv.perm.of_subtype_swap_eq Equiv.Perm.ofSubtype_swap_eq theorem IsSwap.of_subtype_isSwap {p : α → Prop} [DecidablePred p] {f : Perm (Subtype p)} (h : f.IsSwap) : (ofSubtype f).IsSwap := let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h ⟨x, y, by simp only [Ne, Subtype.ext_iff] at hxy exact hxy.1, by rw [hxy.2, ofSubtype_swap_eq]⟩ #align equiv.perm.is_swap.of_subtype_is_swap Equiv.Perm.IsSwap.of_subtype_isSwap theorem ne_and_ne_of_swap_mul_apply_ne_self {f : Perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x := by simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at * by_cases h : f y = x · constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne] · split_ifs at hy with h h <;> try { simp [*] at * } #align equiv.perm.ne_and_ne_of_swap_mul_apply_ne_self Equiv.Perm.ne_and_ne_of_swap_mul_apply_ne_self end IsSwap section support section Set variable (p q : Perm α) theorem set_support_inv_eq : { x | p⁻¹ x ≠ x } = { x | p x ≠ x } := by ext x simp only [Set.mem_setOf_eq, Ne] rw [inv_def, symm_apply_eq, eq_comm] #align equiv.perm.set_support_inv_eq Equiv.Perm.set_support_inv_eq theorem set_support_apply_mem {p : Perm α} {a : α} : p a ∈ { x | p x ≠ x } ↔ a ∈ { x | p x ≠ x } := by simp #align equiv.perm.set_support_apply_mem Equiv.Perm.set_support_apply_mem theorem set_support_zpow_subset (n : ℤ) : { x | (p ^ n) x ≠ x } ⊆ { x | p x ≠ x } := by intro x simp only [Set.mem_setOf_eq, Ne] intro hx H simp [zpow_apply_eq_self_of_apply_eq_self H] at hx #align equiv.perm.set_support_zpow_subset Equiv.Perm.set_support_zpow_subset theorem set_support_mul_subset : { x | (p * q) x ≠ x } ⊆ { x | p x ≠ x } ∪ { x | q x ≠ x } := by intro x simp only [Perm.coe_mul, Function.comp_apply, Ne, Set.mem_union, Set.mem_setOf_eq] by_cases hq : q x = x <;> simp [hq] #align equiv.perm.set_support_mul_subset Equiv.Perm.set_support_mul_subset end Set variable [DecidableEq α] [Fintype α] {f g : Perm α} /-- The `Finset` of nonfixed points of a permutation. -/ def support (f : Perm α) : Finset α := univ.filter fun x => f x ≠ x #align equiv.perm.support Equiv.Perm.support @[simp] theorem mem_support {x : α} : x ∈ f.support ↔ f x ≠ x := by rw [support, mem_filter, and_iff_right (mem_univ x)] #align equiv.perm.mem_support Equiv.Perm.mem_support theorem not_mem_support {x : α} : x ∉ f.support ↔ f x = x := by simp #align equiv.perm.not_mem_support Equiv.Perm.not_mem_support theorem coe_support_eq_set_support (f : Perm α) : (f.support : Set α) = { x | f x ≠ x } := by ext simp #align equiv.perm.coe_support_eq_set_support Equiv.Perm.coe_support_eq_set_support @[simp] theorem support_eq_empty_iff {σ : Perm α} : σ.support = ∅ ↔ σ = 1 := by simp_rw [Finset.ext_iff, mem_support, Finset.not_mem_empty, iff_false_iff, not_not, Equiv.Perm.ext_iff, one_apply] #align equiv.perm.support_eq_empty_iff Equiv.Perm.support_eq_empty_iff @[simp] theorem support_one : (1 : Perm α).support = ∅ := by rw [support_eq_empty_iff] #align equiv.perm.support_one Equiv.Perm.support_one @[simp] theorem support_refl : support (Equiv.refl α) = ∅ := support_one #align equiv.perm.support_refl Equiv.Perm.support_refl theorem support_congr (h : f.support ⊆ g.support) (h' : ∀ x ∈ g.support, f x = g x) : f = g := by ext x by_cases hx : x ∈ g.support · exact h' x hx · rw [not_mem_support.mp hx, ← not_mem_support] exact fun H => hx (h H) #align equiv.perm.support_congr Equiv.Perm.support_congr theorem support_mul_le (f g : Perm α) : (f * g).support ≤ f.support ⊔ g.support := fun x => by simp only [sup_eq_union] rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ← not_and_or, not_imp_not] rintro ⟨hf, hg⟩ rw [hg, hf] #align equiv.perm.support_mul_le Equiv.Perm.support_mul_le theorem exists_mem_support_of_mem_support_prod {l : List (Perm α)} {x : α} (hx : x ∈ l.prod.support) : ∃ f : Perm α, f ∈ l ∧ x ∈ f.support := by contrapose! hx simp_rw [mem_support, not_not] at hx ⊢ induction' l with f l ih · rfl · rw [List.prod_cons, mul_apply, ih, hx] · simp only [List.find?, List.mem_cons, true_or] intros f' hf' refine hx f' ?_ simp only [List.find?, List.mem_cons] exact Or.inr hf' #align equiv.perm.exists_mem_support_of_mem_support_prod Equiv.Perm.exists_mem_support_of_mem_support_prod theorem support_pow_le (σ : Perm α) (n : ℕ) : (σ ^ n).support ≤ σ.support := fun _ h1 => mem_support.mpr fun h2 => mem_support.mp h1 (pow_apply_eq_self_of_apply_eq_self h2 n) #align equiv.perm.support_pow_le Equiv.Perm.support_pow_le @[simp] theorem support_inv (σ : Perm α) : support σ⁻¹ = σ.support := by simp_rw [Finset.ext_iff, mem_support, not_iff_not, inv_eq_iff_eq.trans eq_comm, imp_true_iff] #align equiv.perm.support_inv Equiv.Perm.support_inv -- @[simp] -- Porting note (#10618): simp can prove this theorem apply_mem_support {x : α} : f x ∈ f.support ↔ x ∈ f.support := by rw [mem_support, mem_support, Ne, Ne, apply_eq_iff_eq] #align equiv.perm.apply_mem_support Equiv.Perm.apply_mem_support -- Porting note (#10756): new theorem @[simp] theorem apply_pow_apply_eq_iff (f : Perm α) (n : ℕ) {x : α} : f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by rw [← mul_apply, Commute.self_pow f, mul_apply, apply_eq_iff_eq] -- @[simp] -- Porting note (#10618): simp can prove this theorem pow_apply_mem_support {n : ℕ} {x : α} : (f ^ n) x ∈ f.support ↔ x ∈ f.support := by simp only [mem_support, ne_eq, apply_pow_apply_eq_iff] #align equiv.perm.pow_apply_mem_support Equiv.Perm.pow_apply_mem_support -- Porting note (#10756): new theorem @[simp] theorem apply_zpow_apply_eq_iff (f : Perm α) (n : ℤ) {x : α} : f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by rw [← mul_apply, Commute.self_zpow f, mul_apply, apply_eq_iff_eq] -- @[simp] -- Porting note (#10618): simp can prove this theorem zpow_apply_mem_support {n : ℤ} {x : α} : (f ^ n) x ∈ f.support ↔ x ∈ f.support := by simp only [mem_support, ne_eq, apply_zpow_apply_eq_iff] #align equiv.perm.zpow_apply_mem_support Equiv.Perm.zpow_apply_mem_support theorem pow_eq_on_of_mem_support (h : ∀ x ∈ f.support ∩ g.support, f x = g x) (k : ℕ) : ∀ x ∈ f.support ∩ g.support, (f ^ k) x = (g ^ k) x := by induction' k with k hk · simp · intro x hx rw [pow_succ, mul_apply, pow_succ, mul_apply, h _ hx, hk] rwa [mem_inter, apply_mem_support, ← h _ hx, apply_mem_support, ← mem_inter] #align equiv.perm.pow_eq_on_of_mem_support Equiv.Perm.pow_eq_on_of_mem_support theorem disjoint_iff_disjoint_support : Disjoint f g ↔ _root_.Disjoint f.support g.support := by simp [disjoint_iff_eq_or_eq, disjoint_iff, disjoint_iff, Finset.ext_iff, not_and_or, imp_iff_not_or] #align equiv.perm.disjoint_iff_disjoint_support Equiv.Perm.disjoint_iff_disjoint_support theorem Disjoint.disjoint_support (h : Disjoint f g) : _root_.Disjoint f.support g.support := disjoint_iff_disjoint_support.1 h #align equiv.perm.disjoint.disjoint_support Equiv.Perm.Disjoint.disjoint_support theorem Disjoint.support_mul (h : Disjoint f g) : (f * g).support = f.support ∪ g.support := by refine le_antisymm (support_mul_le _ _) fun a => ?_ rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ← not_and_or, not_imp_not] exact (h a).elim (fun hf h => ⟨hf, f.apply_eq_iff_eq.mp (h.trans hf.symm)⟩) fun hg h => ⟨(congr_arg f hg).symm.trans h, hg⟩ #align equiv.perm.disjoint.support_mul Equiv.Perm.Disjoint.support_mul theorem support_prod_of_pairwise_disjoint (l : List (Perm α)) (h : l.Pairwise Disjoint) : l.prod.support = (l.map support).foldr (· ⊔ ·) ⊥ := by induction' l with hd tl hl · simp · rw [List.pairwise_cons] at h have : Disjoint hd tl.prod := disjoint_prod_right _ h.left simp [this.support_mul, hl h.right] #align equiv.perm.support_prod_of_pairwise_disjoint Equiv.Perm.support_prod_of_pairwise_disjoint theorem support_prod_le (l : List (Perm α)) : l.prod.support ≤ (l.map support).foldr (· ⊔ ·) ⊥ := by induction' l with hd tl hl · simp · rw [List.prod_cons, List.map_cons, List.foldr_cons] refine (support_mul_le hd tl.prod).trans ?_ exact sup_le_sup le_rfl hl #align equiv.perm.support_prod_le Equiv.Perm.support_prod_le theorem support_zpow_le (σ : Perm α) (n : ℤ) : (σ ^ n).support ≤ σ.support := fun _ h1 => mem_support.mpr fun h2 => mem_support.mp h1 (zpow_apply_eq_self_of_apply_eq_self h2 n) #align equiv.perm.support_zpow_le Equiv.Perm.support_zpow_le @[simp] theorem support_swap {x y : α} (h : x ≠ y) : support (swap x y) = {x, y} := by ext z by_cases hx : z = x any_goals simpa [hx] using h.symm by_cases hy : z = y <;> · simp [swap_apply_of_ne_of_ne, hx, hy] <;> exact h #align equiv.perm.support_swap Equiv.Perm.support_swap theorem support_swap_iff (x y : α) : support (swap x y) = {x, y} ↔ x ≠ y := by refine ⟨fun h => ?_, fun h => support_swap h⟩ rintro rfl simp [Finset.ext_iff] at h #align equiv.perm.support_swap_iff Equiv.Perm.support_swap_iff theorem support_swap_mul_swap {x y z : α} (h : List.Nodup [x, y, z]) : support (swap x y * swap y z) = {x, y, z} := by simp only [List.not_mem_nil, and_true_iff, List.mem_cons, not_false_iff, List.nodup_cons, List.mem_singleton, and_self_iff, List.nodup_nil] at h push_neg at h apply le_antisymm · convert support_mul_le (swap x y) (swap y z) using 1 rw [support_swap h.left.left, support_swap h.right.left] simp [Finset.ext_iff] · intro simp only [mem_insert, mem_singleton] rintro (rfl | rfl | rfl | _) <;> simp [swap_apply_of_ne_of_ne, h.left.left, h.left.left.symm, h.left.right.symm, h.left.right.left.symm, h.right.left.symm] #align equiv.perm.support_swap_mul_swap Equiv.Perm.support_swap_mul_swap theorem support_swap_mul_ge_support_diff (f : Perm α) (x y : α) : f.support \ {x, y} ≤ (swap x y * f).support := by intro simp only [and_imp, Perm.coe_mul, Function.comp_apply, Ne, mem_support, mem_insert, mem_sdiff, mem_singleton] push_neg rintro ha ⟨hx, hy⟩ H rw [swap_apply_eq_iff, swap_apply_of_ne_of_ne hx hy] at H exact ha H #align equiv.perm.support_swap_mul_ge_support_diff Equiv.Perm.support_swap_mul_ge_support_diff theorem support_swap_mul_eq (f : Perm α) (x : α) (h : f (f x) ≠ x) : (swap x (f x) * f).support = f.support \ {x} := by by_cases hx : f x = x · simp [hx, sdiff_singleton_eq_erase, not_mem_support.mpr hx, erase_eq_of_not_mem] ext z by_cases hzx : z = x · simp [hzx] by_cases hzf : z = f x · simp [hzf, hx, h, swap_apply_of_ne_of_ne] by_cases hzfx : f z = x · simp [Ne.symm hzx, hzx, Ne.symm hzf, hzfx] · simp [Ne.symm hzx, hzx, Ne.symm hzf, hzfx, f.injective.ne hzx, swap_apply_of_ne_of_ne] #align equiv.perm.support_swap_mul_eq Equiv.Perm.support_swap_mul_eq theorem mem_support_swap_mul_imp_mem_support_ne {x y : α} (hy : y ∈ support (swap x (f x) * f)) : y ∈ support f ∧ y ≠ x := by simp only [mem_support, swap_apply_def, mul_apply, f.injective.eq_iff] at * by_cases h : f y = x · constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne] · split_ifs at hy with hf heq <;> simp_all only [not_true] · exact ⟨h, hy⟩ · exact ⟨hy, heq⟩ #align equiv.perm.mem_support_swap_mul_imp_mem_support_ne Equiv.Perm.mem_support_swap_mul_imp_mem_support_ne theorem Disjoint.mem_imp (h : Disjoint f g) {x : α} (hx : x ∈ f.support) : x ∉ g.support := disjoint_left.mp h.disjoint_support hx #align equiv.perm.disjoint.mem_imp Equiv.Perm.Disjoint.mem_imp theorem eq_on_support_mem_disjoint {l : List (Perm α)} (h : f ∈ l) (hl : l.Pairwise Disjoint) : ∀ x ∈ f.support, f x = l.prod x := by induction' l with hd tl IH · simp at h · intro x hx rw [List.pairwise_cons] at hl rw [List.mem_cons] at h rcases h with (rfl | h) · rw [List.prod_cons, mul_apply, not_mem_support.mp ((disjoint_prod_right tl hl.left).mem_imp hx)] · rw [List.prod_cons, mul_apply, ← IH h hl.right _ hx, eq_comm, ← not_mem_support] refine (hl.left _ h).symm.mem_imp ?_ simpa using hx #align equiv.perm.eq_on_support_mem_disjoint Equiv.Perm.eq_on_support_mem_disjoint theorem Disjoint.mono {x y : Perm α} (h : Disjoint f g) (hf : x.support ≤ f.support) (hg : y.support ≤ g.support) : Disjoint x y := by rw [disjoint_iff_disjoint_support] at h ⊢ exact h.mono hf hg #align equiv.perm.disjoint.mono Equiv.Perm.Disjoint.mono theorem support_le_prod_of_mem {l : List (Perm α)} (h : f ∈ l) (hl : l.Pairwise Disjoint) : f.support ≤ l.prod.support := by intro x hx rwa [mem_support, ← eq_on_support_mem_disjoint h hl _ hx, ← mem_support] #align equiv.perm.support_le_prod_of_mem Equiv.Perm.support_le_prod_of_mem section ExtendDomain variable {β : Type*} [DecidableEq β] [Fintype β] {p : β → Prop} [DecidablePred p] @[simp] theorem support_extend_domain (f : α ≃ Subtype p) {g : Perm α} : support (g.extendDomain f) = g.support.map f.asEmbedding := by ext b simp only [exists_prop, Function.Embedding.coeFn_mk, toEmbedding_apply, mem_map, Ne, Function.Embedding.trans_apply, mem_support] by_cases pb : p b · rw [extendDomain_apply_subtype _ _ pb] constructor · rintro h refine ⟨f.symm ⟨b, pb⟩, ?_, by simp⟩ contrapose! h simp [h] · rintro ⟨a, ha, hb⟩ contrapose! ha obtain rfl : a = f.symm ⟨b, pb⟩ := by rw [eq_symm_apply] exact Subtype.coe_injective hb rw [eq_symm_apply] exact Subtype.coe_injective ha · rw [extendDomain_apply_not_subtype _ _ pb] simp only [not_exists, false_iff_iff, not_and, eq_self_iff_true, not_true] rintro a _ rfl exact pb (Subtype.prop _) #align equiv.perm.support_extend_domain Equiv.Perm.support_extend_domain theorem card_support_extend_domain (f : α ≃ Subtype p) {g : Perm α} : (g.extendDomain f).support.card = g.support.card := by simp #align equiv.perm.card_support_extend_domain Equiv.Perm.card_support_extend_domain end ExtendDomain section Card -- @[simp] -- Porting note (#10618): simp can prove thisrove this theorem card_support_eq_zero {f : Perm α} : f.support.card = 0 ↔ f = 1 := by rw [Finset.card_eq_zero, support_eq_empty_iff] #align equiv.perm.card_support_eq_zero Equiv.Perm.card_support_eq_zero theorem one_lt_card_support_of_ne_one {f : Perm α} (h : f ≠ 1) : 1 < f.support.card := by simp_rw [one_lt_card_iff, mem_support, ← not_or] contrapose! h ext a specialize h (f a) a rwa [apply_eq_iff_eq, or_self_iff, or_self_iff] at h #align equiv.perm.one_lt_card_support_of_ne_one Equiv.Perm.one_lt_card_support_of_ne_one
Mathlib/GroupTheory/Perm/Support.lean
586
589
theorem card_support_ne_one (f : Perm α) : f.support.card ≠ 1 := by
by_cases h : f = 1 · exact ne_of_eq_of_ne (card_support_eq_zero.mpr h) zero_ne_one · exact ne_of_gt (one_lt_card_support_of_ne_one h)
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Fintype.Perm import Mathlib.GroupTheory.Perm.Finite import Mathlib.GroupTheory.Perm.List #align_import group_theory.perm.cycle.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Cycles of a permutation This file starts the theory of cycles in permutations. ## Main definitions In the following, `f : Equiv.Perm β`. * `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`. * `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated applications of `f`, and `f` is not the identity. * `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by repeated applications of `f`. ## Notes `Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways: * `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set. * `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton). * `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them. -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm /-! ### `SameCycle` -/ section SameCycle variable {f g : Perm α} {p : α → Prop} {x y z : α} /-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/ def SameCycle (f : Perm α) (x y : α) : Prop := ∃ i : ℤ, (f ^ i) x = y #align equiv.perm.same_cycle Equiv.Perm.SameCycle @[refl] theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x := ⟨0, rfl⟩ #align equiv.perm.same_cycle.refl Equiv.Perm.SameCycle.refl theorem SameCycle.rfl : SameCycle f x x := SameCycle.refl _ _ #align equiv.perm.same_cycle.rfl Equiv.Perm.SameCycle.rfl protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h] #align eq.same_cycle Eq.sameCycle @[symm] theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ => ⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩ #align equiv.perm.same_cycle.symm Equiv.Perm.SameCycle.symm theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x := ⟨SameCycle.symm, SameCycle.symm⟩ #align equiv.perm.same_cycle_comm Equiv.Perm.sameCycle_comm @[trans] theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z := fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩ #align equiv.perm.same_cycle.trans Equiv.Perm.SameCycle.trans variable (f) in theorem SameCycle.equivalence : Equivalence (SameCycle f) := ⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩ /-- The setoid defined by the `SameCycle` relation. -/ def SameCycle.setoid (f : Perm α) : Setoid α where iseqv := SameCycle.equivalence f @[simp] theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle] #align equiv.perm.same_cycle_one Equiv.Perm.sameCycle_one @[simp] theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y := (Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle] #align equiv.perm.same_cycle_inv Equiv.Perm.sameCycle_inv alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv #align equiv.perm.same_cycle.of_inv Equiv.Perm.SameCycle.of_inv #align equiv.perm.same_cycle.inv Equiv.Perm.SameCycle.inv @[simp] theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) := exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq] #align equiv.perm.same_cycle_conj Equiv.Perm.sameCycle_conj theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by simp [sameCycle_conj] #align equiv.perm.same_cycle.conj Equiv.Perm.SameCycle.conj theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply, (f ^ i).injective.eq_iff] #align equiv.perm.same_cycle.apply_eq_self_iff Equiv.Perm.SameCycle.apply_eq_self_iff theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y := let ⟨_, hn⟩ := h (hx.perm_zpow _).eq.symm.trans hn #align equiv.perm.same_cycle.eq_of_left Equiv.Perm.SameCycle.eq_of_left theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y := h.eq_of_left <| h.apply_eq_self_iff.2 hy #align equiv.perm.same_cycle.eq_of_right Equiv.Perm.SameCycle.eq_of_right @[simp] theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y := (Equiv.addRight 1).exists_congr_left.trans <| by simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp] #align equiv.perm.same_cycle_apply_left Equiv.Perm.sameCycle_apply_left @[simp] theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm] #align equiv.perm.same_cycle_apply_right Equiv.Perm.sameCycle_apply_right @[simp] theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by rw [← sameCycle_apply_left, apply_inv_self] #align equiv.perm.same_cycle_inv_apply_left Equiv.Perm.sameCycle_inv_apply_left @[simp] theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by rw [← sameCycle_apply_right, apply_inv_self] #align equiv.perm.same_cycle_inv_apply_right Equiv.Perm.sameCycle_inv_apply_right @[simp] theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := (Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add] #align equiv.perm.same_cycle_zpow_left Equiv.Perm.sameCycle_zpow_left @[simp] theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm] #align equiv.perm.same_cycle_zpow_right Equiv.Perm.sameCycle_zpow_right @[simp] theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_left] #align equiv.perm.same_cycle_pow_left Equiv.Perm.sameCycle_pow_left @[simp] theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by rw [← zpow_natCast, sameCycle_zpow_right] #align equiv.perm.same_cycle_pow_right Equiv.Perm.sameCycle_pow_right alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left #align equiv.perm.same_cycle.of_apply_left Equiv.Perm.SameCycle.of_apply_left #align equiv.perm.same_cycle.apply_left Equiv.Perm.SameCycle.apply_left alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right #align equiv.perm.same_cycle.of_apply_right Equiv.Perm.SameCycle.of_apply_right #align equiv.perm.same_cycle.apply_right Equiv.Perm.SameCycle.apply_right alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left #align equiv.perm.same_cycle.of_inv_apply_left Equiv.Perm.SameCycle.of_inv_apply_left #align equiv.perm.same_cycle.inv_apply_left Equiv.Perm.SameCycle.inv_apply_left alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right #align equiv.perm.same_cycle.of_inv_apply_right Equiv.Perm.SameCycle.of_inv_apply_right #align equiv.perm.same_cycle.inv_apply_right Equiv.Perm.SameCycle.inv_apply_right alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left #align equiv.perm.same_cycle.of_pow_left Equiv.Perm.SameCycle.of_pow_left #align equiv.perm.same_cycle.pow_left Equiv.Perm.SameCycle.pow_left alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right #align equiv.perm.same_cycle.of_pow_right Equiv.Perm.SameCycle.of_pow_right #align equiv.perm.same_cycle.pow_right Equiv.Perm.SameCycle.pow_right alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left #align equiv.perm.same_cycle.of_zpow_left Equiv.Perm.SameCycle.of_zpow_left #align equiv.perm.same_cycle.zpow_left Equiv.Perm.SameCycle.zpow_left alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right #align equiv.perm.same_cycle.of_zpow_right Equiv.Perm.SameCycle.of_zpow_right #align equiv.perm.same_cycle.zpow_right Equiv.Perm.SameCycle.zpow_right theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ #align equiv.perm.same_cycle.of_pow Equiv.Perm.SameCycle.of_pow theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ => ⟨n * m, by simp [zpow_mul, h]⟩ #align equiv.perm.same_cycle.of_zpow Equiv.Perm.SameCycle.of_zpow @[simp] theorem sameCycle_subtypePerm {h} {x y : { x // p x }} : (f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y := exists_congr fun n => by simp [Subtype.ext_iff] #align equiv.perm.same_cycle_subtype_perm Equiv.Perm.sameCycle_subtypePerm alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm #align equiv.perm.same_cycle.subtype_perm Equiv.Perm.SameCycle.subtypePerm @[simp] theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} : SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y := exists_congr fun n => by rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff] #align equiv.perm.same_cycle_extend_domain Equiv.Perm.sameCycle_extendDomain alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain #align equiv.perm.same_cycle.extend_domain Equiv.Perm.SameCycle.extendDomain theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by classical rintro ⟨k, rfl⟩ use (k % orderOf f).natAbs have h₀ := Int.natCast_pos.mpr (orderOf_pos f) have h₁ := Int.emod_nonneg k h₀.ne' rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf] refine ⟨?_, by rfl⟩ rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁] exact Int.emod_lt_of_pos _ h₀ #align equiv.perm.same_cycle.exists_pow_eq' Equiv.Perm.SameCycle.exists_pow_eq' theorem SameCycle.exists_pow_eq'' [Finite α] (h : SameCycle f x y) : ∃ i : ℕ, 0 < i ∧ i ≤ orderOf f ∧ (f ^ i) x = y := by classical obtain ⟨_ | i, hi, rfl⟩ := h.exists_pow_eq' · refine ⟨orderOf f, orderOf_pos f, le_rfl, ?_⟩ rw [pow_orderOf_eq_one, pow_zero] · exact ⟨i.succ, i.zero_lt_succ, hi.le, by rfl⟩ #align equiv.perm.same_cycle.exists_pow_eq'' Equiv.Perm.SameCycle.exists_pow_eq'' instance [Fintype α] [DecidableEq α] (f : Perm α) : DecidableRel (SameCycle f) := fun x y => decidable_of_iff (∃ n ∈ List.range (Fintype.card (Perm α)), (f ^ n) x = y) ⟨fun ⟨n, _, hn⟩ => ⟨n, hn⟩, fun ⟨i, hi⟩ => ⟨(i % orderOf f).natAbs, List.mem_range.2 (Int.ofNat_lt.1 <| by rw [Int.natAbs_of_nonneg (Int.emod_nonneg _ <| Int.natCast_ne_zero.2 (orderOf_pos _).ne')] refine (Int.emod_lt _ <| Int.natCast_ne_zero_iff_pos.2 <| orderOf_pos _).trans_le ?_ simp [orderOf_le_card_univ]), by rw [← zpow_natCast, Int.natAbs_of_nonneg (Int.emod_nonneg _ <| Int.natCast_ne_zero_iff_pos.2 <| orderOf_pos _), zpow_mod_orderOf, hi]⟩⟩ end SameCycle /-! ### `IsCycle` -/ section IsCycle variable {f g : Perm α} {x y : α} /-- A cycle is a non identity permutation where any two nonfixed points of the permutation are related by repeated application of the permutation. -/ def IsCycle (f : Perm α) : Prop := ∃ x, f x ≠ x ∧ ∀ ⦃y⦄, f y ≠ y → SameCycle f x y #align equiv.perm.is_cycle Equiv.Perm.IsCycle theorem IsCycle.ne_one (h : IsCycle f) : f ≠ 1 := fun hf => by simp [hf, IsCycle] at h #align equiv.perm.is_cycle.ne_one Equiv.Perm.IsCycle.ne_one @[simp] theorem not_isCycle_one : ¬(1 : Perm α).IsCycle := fun H => H.ne_one rfl #align equiv.perm.not_is_cycle_one Equiv.Perm.not_isCycle_one protected theorem IsCycle.sameCycle (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) : SameCycle f x y := let ⟨g, hg⟩ := hf let ⟨a, ha⟩ := hg.2 hx let ⟨b, hb⟩ := hg.2 hy ⟨b - a, by rw [← ha, ← mul_apply, ← zpow_add, sub_add_cancel, hb]⟩ #align equiv.perm.is_cycle.same_cycle Equiv.Perm.IsCycle.sameCycle theorem IsCycle.exists_zpow_eq : IsCycle f → f x ≠ x → f y ≠ y → ∃ i : ℤ, (f ^ i) x = y := IsCycle.sameCycle #align equiv.perm.is_cycle.exists_zpow_eq Equiv.Perm.IsCycle.exists_zpow_eq theorem IsCycle.inv (hf : IsCycle f) : IsCycle f⁻¹ := hf.imp fun _ ⟨hx, h⟩ => ⟨inv_eq_iff_eq.not.2 hx.symm, fun _ hy => (h <| inv_eq_iff_eq.not.2 hy.symm).inv⟩ #align equiv.perm.is_cycle.inv Equiv.Perm.IsCycle.inv @[simp] theorem isCycle_inv : IsCycle f⁻¹ ↔ IsCycle f := ⟨fun h => h.inv, IsCycle.inv⟩ #align equiv.perm.is_cycle_inv Equiv.Perm.isCycle_inv theorem IsCycle.conj : IsCycle f → IsCycle (g * f * g⁻¹) := by rintro ⟨x, hx, h⟩ refine ⟨g x, by simp [coe_mul, inv_apply_self, hx], fun y hy => ?_⟩ rw [← apply_inv_self g y] exact (h <| eq_inv_iff_eq.not.2 hy).conj #align equiv.perm.is_cycle.conj Equiv.Perm.IsCycle.conj protected theorem IsCycle.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) : IsCycle g → IsCycle (g.extendDomain f) := by rintro ⟨a, ha, ha'⟩ refine ⟨f a, ?_, fun b hb => ?_⟩ · rw [extendDomain_apply_image] exact Subtype.coe_injective.ne (f.injective.ne ha) have h : b = f (f.symm ⟨b, of_not_not <| hb ∘ extendDomain_apply_not_subtype _ _⟩) := by rw [apply_symm_apply, Subtype.coe_mk] rw [h] at hb ⊢ simp only [extendDomain_apply_image, Subtype.coe_injective.ne_iff, f.injective.ne_iff] at hb exact (ha' hb).extendDomain #align equiv.perm.is_cycle.extend_domain Equiv.Perm.IsCycle.extendDomain theorem isCycle_iff_sameCycle (hx : f x ≠ x) : IsCycle f ↔ ∀ {y}, SameCycle f x y ↔ f y ≠ y := ⟨fun hf y => ⟨fun ⟨i, hi⟩ hy => hx <| by rw [← zpow_apply_eq_self_of_apply_eq_self hy i, (f ^ i).injective.eq_iff] at hi rw [hi, hy], hf.exists_zpow_eq hx⟩, fun h => ⟨x, hx, fun y hy => h.2 hy⟩⟩ #align equiv.perm.is_cycle_iff_same_cycle Equiv.Perm.isCycle_iff_sameCycle section Finite variable [Finite α] theorem IsCycle.exists_pow_eq (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) : ∃ i : ℕ, (f ^ i) x = y := by let ⟨n, hn⟩ := hf.exists_zpow_eq hx hy classical exact ⟨(n % orderOf f).toNat, by {have := n.emod_nonneg (Int.natCast_ne_zero.mpr (ne_of_gt (orderOf_pos f))) rwa [← zpow_natCast, Int.toNat_of_nonneg this, zpow_mod_orderOf]}⟩ #align equiv.perm.is_cycle.exists_pow_eq Equiv.Perm.IsCycle.exists_pow_eq end Finite variable [DecidableEq α] theorem isCycle_swap (hxy : x ≠ y) : IsCycle (swap x y) := ⟨y, by rwa [swap_apply_right], fun a (ha : ite (a = x) y (ite (a = y) x a) ≠ a) => if hya : y = a then ⟨0, hya⟩ else ⟨1, by rw [zpow_one, swap_apply_def] split_ifs at * <;> tauto⟩⟩ #align equiv.perm.is_cycle_swap Equiv.Perm.isCycle_swap protected theorem IsSwap.isCycle : IsSwap f → IsCycle f := by rintro ⟨x, y, hxy, rfl⟩ exact isCycle_swap hxy #align equiv.perm.is_swap.is_cycle Equiv.Perm.IsSwap.isCycle variable [Fintype α] theorem IsCycle.two_le_card_support (h : IsCycle f) : 2 ≤ f.support.card := two_le_card_support_of_ne_one h.ne_one #align equiv.perm.is_cycle.two_le_card_support Equiv.Perm.IsCycle.two_le_card_support #noalign equiv.perm.is_cycle.exists_pow_eq_one /-- The subgroup generated by a cycle is in bijection with its support -/ noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ) : (Subgroup.zpowers σ) ≃ σ.support := Equiv.ofBijective (fun (τ : ↥ ((Subgroup.zpowers σ) : Set (Perm α))) => ⟨(τ : Perm α) (Classical.choose hσ), by obtain ⟨τ, n, rfl⟩ := τ erw [Finset.mem_coe, Subtype.coe_mk, zpow_apply_mem_support, mem_support] exact (Classical.choose_spec hσ).1⟩) (by constructor · rintro ⟨a, m, rfl⟩ ⟨b, n, rfl⟩ h ext y by_cases hy : σ y = y · simp_rw [zpow_apply_eq_self_of_apply_eq_self hy] · obtain ⟨i, rfl⟩ := (Classical.choose_spec hσ).2 hy rw [Subtype.coe_mk, Subtype.coe_mk, zpow_apply_comm σ m i, zpow_apply_comm σ n i] exact congr_arg _ (Subtype.ext_iff.mp h) · rintro ⟨y, hy⟩ erw [Finset.mem_coe, mem_support] at hy obtain ⟨n, rfl⟩ := (Classical.choose_spec hσ).2 hy exact ⟨⟨σ ^ n, n, rfl⟩, rfl⟩) #align equiv.perm.is_cycle.zpowers_equiv_support Equiv.Perm.IsCycle.zpowersEquivSupport @[simp] theorem IsCycle.zpowersEquivSupport_apply {σ : Perm α} (hσ : IsCycle σ) {n : ℕ} : hσ.zpowersEquivSupport ⟨σ ^ n, n, rfl⟩ = ⟨(σ ^ n) (Classical.choose hσ), pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ := rfl #align equiv.perm.is_cycle.zpowers_equiv_support_apply Equiv.Perm.IsCycle.zpowersEquivSupport_apply @[simp] theorem IsCycle.zpowersEquivSupport_symm_apply {σ : Perm α} (hσ : IsCycle σ) (n : ℕ) : hσ.zpowersEquivSupport.symm ⟨(σ ^ n) (Classical.choose hσ), pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ = ⟨σ ^ n, n, rfl⟩ := (Equiv.symm_apply_eq _).2 hσ.zpowersEquivSupport_apply #align equiv.perm.is_cycle.zpowers_equiv_support_symm_apply Equiv.Perm.IsCycle.zpowersEquivSupport_symm_apply protected theorem IsCycle.orderOf (hf : IsCycle f) : orderOf f = f.support.card := by rw [← Fintype.card_zpowers, ← Fintype.card_coe] convert Fintype.card_congr (IsCycle.zpowersEquivSupport hf) #align equiv.perm.is_cycle.order_of Equiv.Perm.IsCycle.orderOf theorem isCycle_swap_mul_aux₁ {α : Type*} [DecidableEq α] : ∀ (n : ℕ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by intro n induction' n with n hn · exact fun _ h => ⟨0, h⟩ · intro b x f hb h exact if hfbx : f x = b then ⟨0, hfbx⟩ else have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b := by rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx), Ne, ← f.injective.eq_iff, apply_inv_self] exact this.1 let ⟨i, hi⟩ := hn hb' (f.injective <| by rw [apply_inv_self]; rwa [pow_succ', mul_apply] at h) ⟨i + 1, by rw [add_comm, zpow_add, mul_apply, hi, zpow_one, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne (ne_and_ne_of_swap_mul_apply_ne_self hb).2 (Ne.symm hfbx)]⟩ #align equiv.perm.is_cycle_swap_mul_aux₁ Equiv.Perm.isCycle_swap_mul_aux₁
Mathlib/GroupTheory/Perm/Cycle/Basic.lean
438
465
theorem isCycle_swap_mul_aux₂ {α : Type*} [DecidableEq α] : ∀ (n : ℤ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b), ∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n induction' n with n n · exact isCycle_swap_mul_aux₁ n · intro b x f hb h exact if hfbx' : f x = b then ⟨0, hfbx'⟩ else have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b := by rw [mul_apply, swap_apply_def] split_ifs <;> simp only [inv_eq_iff_eq, Perm.mul_apply, zpow_negSucc, Ne, Perm.apply_inv_self] at * <;> tauto let ⟨i, hi⟩ := isCycle_swap_mul_aux₁ n hb (show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b by rw [← zpow_natCast, ← h, ← mul_apply, ← mul_apply, ← mul_apply, zpow_negSucc, ← inv_pow, pow_succ, mul_assoc, mul_assoc, inv_mul_self, mul_one, zpow_natCast, ← pow_succ', ← pow_succ]) have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x := by rw [mul_apply, inv_apply_self, swap_apply_left] ⟨-i, by rw [← add_sub_cancel_right i 1, neg_sub, sub_eq_add_neg, zpow_add, zpow_one, zpow_neg, ← inv_zpow, mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x, zpow_add, zpow_one, mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx')]⟩
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.Algebra.GroupWithZero import Mathlib.Topology.Order.OrderClosed #align_import topology.algebra.with_zero_topology from "leanprover-community/mathlib"@"3e0c4d76b6ebe9dfafb67d16f7286d2731ed6064" /-! # The topology on linearly ordered commutative groups with zero Let `Γ₀` be a linearly ordered commutative group to which we have adjoined a zero element. Then `Γ₀` may naturally be endowed with a topology that turns `Γ₀` into a topological monoid. Neighborhoods of zero are sets containing `{ γ | γ < γ₀ }` for some invertible element `γ₀` and every invertible element is open. In particular the topology is the following: "a subset `U ⊆ Γ₀` is open if `0 ∉ U` or if there is an invertible `γ₀ ∈ Γ₀` such that `{ γ | γ < γ₀ } ⊆ U`", see `WithZeroTopology.isOpen_iff`. We prove this topology is ordered and T₅ (in addition to be compatible with the monoid structure). All this is useful to extend a valuation to a completion. This is an abstract version of how the absolute value (resp. `p`-adic absolute value) on `ℚ` is extended to `ℝ` (resp. `ℚₚ`). ## Implementation notes This topology is defined as a scoped instance since it may not be the desired topology on a linearly ordered commutative group with zero. You can locally activate this topology using `open WithZeroTopology`. -/ open Topology Filter TopologicalSpace Filter Set Function namespace WithZeroTopology variable {α Γ₀ : Type*} [LinearOrderedCommGroupWithZero Γ₀] {γ γ₁ γ₂ : Γ₀} {l : Filter α} {f : α → Γ₀} /-- The topology on a linearly ordered commutative group with a zero element adjoined. A subset U is open if 0 ∉ U or if there is an invertible element γ₀ such that {γ | γ < γ₀} ⊆ U. -/ scoped instance (priority := 100) topologicalSpace : TopologicalSpace Γ₀ := nhdsAdjoint 0 <| ⨅ γ ≠ 0, 𝓟 (Iio γ) #align with_zero_topology.topological_space WithZeroTopology.topologicalSpace theorem nhds_eq_update : (𝓝 : Γ₀ → Filter Γ₀) = update pure 0 (⨅ γ ≠ 0, 𝓟 (Iio γ)) := by rw [nhds_nhdsAdjoint, sup_of_le_right] exact le_iInf₂ fun γ hγ ↦ le_principal_iff.2 <| zero_lt_iff.2 hγ #align with_zero_topology.nhds_eq_update WithZeroTopology.nhds_eq_update /-! ### Neighbourhoods of zero -/
Mathlib/Topology/Algebra/WithZeroTopology.lean
56
57
theorem nhds_zero : 𝓝 (0 : Γ₀) = ⨅ γ ≠ 0, 𝓟 (Iio γ) := by
rw [nhds_eq_update, update_same]
/- 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) 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⟩ #align exists_affine_independent exists_affineIndependent variable {V} /-- Two different points are affinely independent. -/ theorem affineIndependent_of_ne {p₁ p₂ : P} (h : p₁ ≠ p₂) : AffineIndependent k ![p₁, p₂] := by rw [affineIndependent_iff_linearIndependent_vsub k ![p₁, p₂] 0] let i₁ : { x // x ≠ (0 : Fin 2) } := ⟨1, by norm_num⟩ have he' : ∀ i, i = i₁ := by rintro ⟨i, hi⟩ ext fin_cases i · simp at hi · simp only [Fin.val_one] haveI : Unique { x // x ≠ (0 : Fin 2) } := ⟨⟨i₁⟩, he'⟩ apply linearIndependent_unique rw [he' default] simpa using h.symm #align affine_independent_of_ne affineIndependent_of_ne variable {k} /-- If all but one point of a family are affinely independent, and that point does not lie in the affine span of that family, the family is affinely independent. -/ theorem AffineIndependent.affineIndependent_of_not_mem_span {p : ι → P} {i : ι} (ha : AffineIndependent k fun x : { y // y ≠ i } => p x) (hi : p i ∉ affineSpan k (p '' { x | x ≠ i })) : AffineIndependent k p := by classical intro s w hw hs let s' : Finset { y // y ≠ i } := s.subtype (· ≠ i) let p' : { y // y ≠ i } → P := fun x => p x by_cases his : i ∈ s ∧ w i ≠ 0 · refine False.elim (hi ?_) let wm : ι → k := -(w i)⁻¹ • w have hms : s.weightedVSub p wm = (0 : V) := by simp [wm, hs] have hwm : ∑ i ∈ s, wm i = 0 := by simp [wm, ← Finset.mul_sum, hw] have hwmi : wm i = -1 := by simp [wm, his.2] let w' : { y // y ≠ i } → k := fun x => wm x have hw' : ∑ x ∈ s', w' x = 1 := by simp_rw [w', s', Finset.sum_subtype_eq_sum_filter] rw [← s.sum_filter_add_sum_filter_not (· ≠ i)] at hwm simp_rw [Classical.not_not] at hwm -- Porting note: this `erw` used to be part of the `simp_rw` erw [Finset.filter_eq'] at hwm simp_rw [if_pos his.1, Finset.sum_singleton, hwmi, ← sub_eq_add_neg, sub_eq_zero] at hwm exact hwm rw [← s.affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one hms his.1 hwmi, ← (Subtype.range_coe : _ = { x | x ≠ i }), ← Set.range_comp, ← s.affineCombination_subtype_eq_filter] exact affineCombination_mem_affineSpan hw' p' · rw [not_and_or, Classical.not_not] at his let w' : { y // y ≠ i } → k := fun x => w x have hw' : ∑ x ∈ s', w' x = 0 := by simp_rw [w', s', Finset.sum_subtype_eq_sum_filter] rw [Finset.sum_filter_of_ne, hw] rintro x hxs hwx rfl exact hwx (his.neg_resolve_left hxs) have hs' : s'.weightedVSub p' w' = (0 : V) := by simp_rw [w', s', p', Finset.weightedVSub_subtype_eq_filter] rw [Finset.weightedVSub_filter_of_ne, hs] rintro x hxs hwx rfl exact hwx (his.neg_resolve_left hxs) intro j hj by_cases hji : j = i · rw [hji] at hj exact hji.symm ▸ his.neg_resolve_left hj · exact ha s' w' hw' hs' ⟨j, hji⟩ (Finset.mem_subtype.2 hj) #align affine_independent.affine_independent_of_not_mem_span AffineIndependent.affineIndependent_of_not_mem_span /-- If distinct points `p₁` and `p₂` lie in `s` but `p₃` does not, the three points are affinely independent. -/ theorem affineIndependent_of_ne_of_mem_of_mem_of_not_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∉ s) : AffineIndependent k ![p₁, p₂, p₃] := by have ha : AffineIndependent k fun x : { x : Fin 3 // x ≠ 2 } => ![p₁, p₂, p₃] x := by rw [← affineIndependent_equiv (finSuccAboveEquiv (2 : Fin 3)).toEquiv] convert affineIndependent_of_ne k hp₁p₂ ext x fin_cases x <;> rfl refine ha.affineIndependent_of_not_mem_span ?_ intro h refine hp₃ ((AffineSubspace.le_def' _ s).1 ?_ p₃ h) simp_rw [affineSpan_le, Set.image_subset_iff, Set.subset_def, Set.mem_preimage] intro x fin_cases x <;> simp (config := {decide := true}) [hp₁, hp₂] #align affine_independent_of_ne_of_mem_of_mem_of_not_mem affineIndependent_of_ne_of_mem_of_mem_of_not_mem /-- If distinct points `p₁` and `p₃` lie in `s` but `p₂` does not, the three points are affinely independent. -/ theorem affineIndependent_of_ne_of_mem_of_not_mem_of_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P} (hp₁p₃ : p₁ ≠ p₃) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∉ s) (hp₃ : p₃ ∈ s) : AffineIndependent k ![p₁, p₂, p₃] := by rw [← affineIndependent_equiv (Equiv.swap (1 : Fin 3) 2)] convert affineIndependent_of_ne_of_mem_of_mem_of_not_mem hp₁p₃ hp₁ hp₃ hp₂ using 1 ext x fin_cases x <;> rfl #align affine_independent_of_ne_of_mem_of_not_mem_of_mem affineIndependent_of_ne_of_mem_of_not_mem_of_mem /-- If distinct points `p₂` and `p₃` lie in `s` but `p₁` does not, the three points are affinely independent. -/ theorem affineIndependent_of_ne_of_not_mem_of_mem_of_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P} (hp₂p₃ : p₂ ≠ p₃) (hp₁ : p₁ ∉ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) : AffineIndependent k ![p₁, p₂, p₃] := by rw [← affineIndependent_equiv (Equiv.swap (0 : Fin 3) 2)] convert affineIndependent_of_ne_of_mem_of_mem_of_not_mem hp₂p₃.symm hp₃ hp₂ hp₁ using 1 ext x fin_cases x <;> rfl #align affine_independent_of_ne_of_not_mem_of_mem_of_mem affineIndependent_of_ne_of_not_mem_of_mem_of_mem end DivisionRing section Ordered variable {k : Type*} {V : Type*} {P : Type*} [LinearOrderedRing k] [AddCommGroup V] variable [Module k V] [AffineSpace V P] {ι : Type*} attribute [local instance] LinearOrderedRing.decidableLT /-- Given an affinely independent family of points, suppose that an affine combination lies in the span of two points given as affine combinations, and suppose that, for two indices, the coefficients in the first point in the span are zero and those in the second point in the span have the same sign. Then the coefficients in the combination lying in the span have the same sign. -/
Mathlib/LinearAlgebra/AffineSpace/Independent.lean
752
762
theorem sign_eq_of_affineCombination_mem_affineSpan_pair {p : ι → P} (h : AffineIndependent k p) {w w₁ w₂ : ι → k} {s : Finset ι} (hw : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (hs : s.affineCombination k p w ∈ line[k, s.affineCombination k p w₁, s.affineCombination k p w₂]) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (hi0 : w₁ i = 0) (hj0 : w₁ j = 0) (hij : SignType.sign (w₂ i) = SignType.sign (w₂ j)) : SignType.sign (w i) = SignType.sign (w j) := by
rw [affineCombination_mem_affineSpan_pair h hw hw₁ hw₂] at hs rcases hs with ⟨r, hr⟩ rw [hr i hi, hr j hj, hi0, hj0, add_zero, add_zero, sub_zero, sub_zero, sign_mul, sign_mul, hij]
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Analysis.LocallyConvex.Polar #align_import analysis.normed_space.dual from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The topological dual of a normed space In this file we define the topological dual `NormedSpace.Dual` of a normed space, and the continuous linear map `NormedSpace.inclusionInDoubleDual` from a normed space into its double dual. For base field `𝕜 = ℝ` or `𝕜 = ℂ`, this map is actually an isometric embedding; we provide a version `NormedSpace.inclusionInDoubleDualLi` of the map which is of type a bundled linear isometric embedding, `E →ₗᵢ[𝕜] (Dual 𝕜 (Dual 𝕜 E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `SeminormedAddCommGroup` and we specialize to `NormedAddCommGroup` when needed. ## Main definitions * `inclusionInDoubleDual` and `inclusionInDoubleDualLi` are the inclusion of a normed space in its double dual, considered as a bounded linear map and as a linear isometry, respectively. * `polar 𝕜 s` is the subset of `Dual 𝕜 E` consisting of those functionals `x'` for which `‖x' z‖ ≤ 1` for every `z ∈ s`. ## Tags dual -/ noncomputable section open scoped Classical open Topology Bornology universe u v namespace NormedSpace section General variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] variable (E : Type*) [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace 𝕜 F] /-- The topological dual of a seminormed space `E`. -/ abbrev Dual : Type _ := E →L[𝕜] 𝕜 #align normed_space.dual NormedSpace.Dual -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_eq until -- leanprover/lean4#2522 is resolved; remove once fixed instance : NormedSpace 𝕜 (Dual 𝕜 E) := inferInstance -- TODO: helper instance for elaboration of inclusionInDoubleDual_norm_le until -- leanprover/lean4#2522 is resolved; remove once fixed instance : SeminormedAddCommGroup (Dual 𝕜 E) := inferInstance /-- The inclusion of a normed space in its double (topological) dual, considered as a bounded linear map. -/ def inclusionInDoubleDual : E →L[𝕜] Dual 𝕜 (Dual 𝕜 E) := ContinuousLinearMap.apply 𝕜 𝕜 #align normed_space.inclusion_in_double_dual NormedSpace.inclusionInDoubleDual @[simp] theorem dual_def (x : E) (f : Dual 𝕜 E) : inclusionInDoubleDual 𝕜 E x f = f x := rfl #align normed_space.dual_def NormedSpace.dual_def theorem inclusionInDoubleDual_norm_eq : ‖inclusionInDoubleDual 𝕜 E‖ = ‖ContinuousLinearMap.id 𝕜 (Dual 𝕜 E)‖ := ContinuousLinearMap.opNorm_flip _ #align normed_space.inclusion_in_double_dual_norm_eq NormedSpace.inclusionInDoubleDual_norm_eq theorem inclusionInDoubleDual_norm_le : ‖inclusionInDoubleDual 𝕜 E‖ ≤ 1 := by rw [inclusionInDoubleDual_norm_eq] exact ContinuousLinearMap.norm_id_le #align normed_space.inclusion_in_double_dual_norm_le NormedSpace.inclusionInDoubleDual_norm_le theorem double_dual_bound (x : E) : ‖(inclusionInDoubleDual 𝕜 E) x‖ ≤ ‖x‖ := by simpa using ContinuousLinearMap.le_of_opNorm_le _ (inclusionInDoubleDual_norm_le 𝕜 E) x #align normed_space.double_dual_bound NormedSpace.double_dual_bound /-- The dual pairing as a bilinear form. -/ def dualPairing : Dual 𝕜 E →ₗ[𝕜] E →ₗ[𝕜] 𝕜 := ContinuousLinearMap.coeLM 𝕜 #align normed_space.dual_pairing NormedSpace.dualPairing @[simp] theorem dualPairing_apply {v : Dual 𝕜 E} {x : E} : dualPairing 𝕜 E v x = v x := rfl #align normed_space.dual_pairing_apply NormedSpace.dualPairing_apply theorem dualPairing_separatingLeft : (dualPairing 𝕜 E).SeparatingLeft := by rw [LinearMap.separatingLeft_iff_ker_eq_bot, LinearMap.ker_eq_bot] exact ContinuousLinearMap.coe_injective #align normed_space.dual_pairing_separating_left NormedSpace.dualPairing_separatingLeft end General section BidualIsometry variable (𝕜 : Type v) [RCLike 𝕜] {E : Type u} [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `ContinuousLinearMap.opNorm_le_bound`. -/ theorem norm_le_dual_bound (x : E) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ f : Dual 𝕜 E, ‖f x‖ ≤ M * ‖f‖) : ‖x‖ ≤ M := by classical by_cases h : x = 0 · simp only [h, hMp, norm_zero] · obtain ⟨f, hf₁, hfx⟩ : ∃ f : E →L[𝕜] 𝕜, ‖f‖ = 1 ∧ f x = ‖x‖ := exists_dual_vector 𝕜 x h calc ‖x‖ = ‖(‖x‖ : 𝕜)‖ := RCLike.norm_coe_norm.symm _ = ‖f x‖ := by rw [hfx] _ ≤ M * ‖f‖ := hM f _ = M := by rw [hf₁, mul_one] #align normed_space.norm_le_dual_bound NormedSpace.norm_le_dual_bound theorem eq_zero_of_forall_dual_eq_zero {x : E} (h : ∀ f : Dual 𝕜 E, f x = (0 : 𝕜)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound 𝕜 x le_rfl fun f => by simp [h f]) #align normed_space.eq_zero_of_forall_dual_eq_zero NormedSpace.eq_zero_of_forall_dual_eq_zero theorem eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 ↔ ∀ g : Dual 𝕜 E, g x = 0 := ⟨fun hx => by simp [hx], fun h => eq_zero_of_forall_dual_eq_zero 𝕜 h⟩ #align normed_space.eq_zero_iff_forall_dual_eq_zero NormedSpace.eq_zero_iff_forall_dual_eq_zero /-- See also `geometric_hahn_banach_point_point`. -/ theorem eq_iff_forall_dual_eq {x y : E} : x = y ↔ ∀ g : Dual 𝕜 E, g x = g y := by rw [← sub_eq_zero, eq_zero_iff_forall_dual_eq_zero 𝕜 (x - y)] simp [sub_eq_zero] #align normed_space.eq_iff_forall_dual_eq NormedSpace.eq_iff_forall_dual_eq /-- The inclusion of a normed space in its double dual is an isometry onto its image. -/ def inclusionInDoubleDualLi : E →ₗᵢ[𝕜] Dual 𝕜 (Dual 𝕜 E) := { inclusionInDoubleDual 𝕜 E with norm_map' := by intro x apply le_antisymm · exact double_dual_bound 𝕜 E x rw [ContinuousLinearMap.norm_def] refine le_csInf ContinuousLinearMap.bounds_nonempty ?_ rintro c ⟨hc1, hc2⟩ exact norm_le_dual_bound 𝕜 x hc1 hc2 } #align normed_space.inclusion_in_double_dual_li NormedSpace.inclusionInDoubleDualLi end BidualIsometry section PolarSets open Metric Set NormedSpace /-- Given a subset `s` in a normed space `E` (over a field `𝕜`), the polar `polar 𝕜 s` is the subset of `Dual 𝕜 E` consisting of those functionals which evaluate to something of norm at most one at all points `z ∈ s`. -/ def polar (𝕜 : Type*) [NontriviallyNormedField 𝕜] {E : Type*} [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] : Set E → Set (Dual 𝕜 E) := (dualPairing 𝕜 E).flip.polar #align normed_space.polar NormedSpace.polar variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] theorem mem_polar_iff {x' : Dual 𝕜 E} (s : Set E) : x' ∈ polar 𝕜 s ↔ ∀ z ∈ s, ‖x' z‖ ≤ 1 := Iff.rfl #align normed_space.mem_polar_iff NormedSpace.mem_polar_iff @[simp] theorem polar_univ : polar 𝕜 (univ : Set E) = {(0 : Dual 𝕜 E)} := (dualPairing 𝕜 E).flip.polar_univ (LinearMap.flip_separatingRight.mpr (dualPairing_separatingLeft 𝕜 E)) #align normed_space.polar_univ NormedSpace.polar_univ
Mathlib/Analysis/NormedSpace/Dual.lean
181
185
theorem isClosed_polar (s : Set E) : IsClosed (polar 𝕜 s) := by
dsimp only [NormedSpace.polar] simp only [LinearMap.polar_eq_iInter, LinearMap.flip_apply] refine isClosed_biInter fun z _ => ?_ exact isClosed_Iic.preimage (ContinuousLinearMap.apply 𝕜 𝕜 z).continuous.norm
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Simon Hudon -/ import Mathlib.CategoryTheory.Monoidal.Category import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.PEmpty #align_import category_theory.monoidal.of_chosen_finite_products.basic from "leanprover-community/mathlib"@"95a87616d63b3cb49d3fe678d416fbe9c4217bf4" /-! # The monoidal structure on a category with chosen finite products. This is a variant of the development in `CategoryTheory.Monoidal.OfHasFiniteProducts`, which uses specified choices of the terminal object and binary product, enabling the construction of a cartesian category with specific definitions of the tensor unit and tensor product. (Because the construction in `CategoryTheory.Monoidal.OfHasFiniteProducts` uses `HasLimit` classes, the actual definitions there are opaque behind `Classical.choice`.) We use this in `CategoryTheory.Monoidal.TypeCat` to construct the monoidal category of types so that the tensor product is the usual cartesian product of types. For now we only do the construction from products, and not from coproducts, which seems less often useful. -/ universe v u namespace CategoryTheory variable (C : Type u) [Category.{v} C] {X Y : C} namespace Limits section variable {C} /-- Swap the two sides of a `BinaryFan`. -/ def BinaryFan.swap {P Q : C} (t : BinaryFan P Q) : BinaryFan Q P := BinaryFan.mk t.snd t.fst #align category_theory.limits.binary_fan.swap CategoryTheory.Limits.BinaryFan.swap @[simp] theorem BinaryFan.swap_fst {P Q : C} (t : BinaryFan P Q) : t.swap.fst = t.snd := rfl #align category_theory.limits.binary_fan.swap_fst CategoryTheory.Limits.BinaryFan.swap_fst @[simp] theorem BinaryFan.swap_snd {P Q : C} (t : BinaryFan P Q) : t.swap.snd = t.fst := rfl #align category_theory.limits.binary_fan.swap_snd CategoryTheory.Limits.BinaryFan.swap_snd /-- If a binary fan `t` over `P Q` is a limit cone, then `t.swap` is a limit cone over `Q P`. -/ @[simps] def IsLimit.swapBinaryFan {P Q : C} {t : BinaryFan P Q} (I : IsLimit t) : IsLimit t.swap where lift s := I.lift (BinaryFan.swap s) fac s := by rintro ⟨⟨⟩⟩ <;> simp uniq s m w := by have h := I.uniq (BinaryFan.swap s) m rw [h] rintro ⟨j⟩ specialize w ⟨WalkingPair.swap j⟩ cases j <;> exact w #align category_theory.limits.is_limit.swap_binary_fan CategoryTheory.Limits.IsLimit.swapBinaryFan /-- Construct `HasBinaryProduct Q P` from `HasBinaryProduct P Q`. This can't be an instance, as it would cause a loop in typeclass search. -/ theorem HasBinaryProduct.swap (P Q : C) [HasBinaryProduct P Q] : HasBinaryProduct Q P := HasLimit.mk ⟨BinaryFan.swap (limit.cone (pair P Q)), (limit.isLimit (pair P Q)).swapBinaryFan⟩ #align category_theory.limits.has_binary_product.swap CategoryTheory.Limits.HasBinaryProduct.swap /-- Given a limit cone over `X` and `Y`, and another limit cone over `Y` and `X`, we can construct an isomorphism between the cone points. Relative to some fixed choice of limits cones for every pair, these isomorphisms constitute a braiding. -/ def BinaryFan.braiding {X Y : C} {s : BinaryFan X Y} (P : IsLimit s) {t : BinaryFan Y X} (Q : IsLimit t) : s.pt ≅ t.pt := IsLimit.conePointUniqueUpToIso P Q.swapBinaryFan #align category_theory.limits.binary_fan.braiding CategoryTheory.Limits.BinaryFan.braiding /-- Given binary fans `sXY` over `X Y`, and `sYZ` over `Y Z`, and `s` over `sXY.X Z`, if `sYZ` is a limit cone we can construct a binary fan over `X sYZ.X`. This is an ingredient of building the associator for a cartesian category. -/ def BinaryFan.assoc {X Y Z : C} {sXY : BinaryFan X Y} {sYZ : BinaryFan Y Z} (Q : IsLimit sYZ) (s : BinaryFan sXY.pt Z) : BinaryFan X sYZ.pt := BinaryFan.mk (s.fst ≫ sXY.fst) (Q.lift (BinaryFan.mk (s.fst ≫ sXY.snd) s.snd)) #align category_theory.limits.binary_fan.assoc CategoryTheory.Limits.BinaryFan.assoc @[simp] theorem BinaryFan.assoc_fst {X Y Z : C} {sXY : BinaryFan X Y} {sYZ : BinaryFan Y Z} (Q : IsLimit sYZ) (s : BinaryFan sXY.pt Z) : (BinaryFan.assoc Q s).fst = s.fst ≫ sXY.fst := rfl #align category_theory.limits.binary_fan.assoc_fst CategoryTheory.Limits.BinaryFan.assoc_fst @[simp] theorem BinaryFan.assoc_snd {X Y Z : C} {sXY : BinaryFan X Y} {sYZ : BinaryFan Y Z} (Q : IsLimit sYZ) (s : BinaryFan sXY.pt Z) : (BinaryFan.assoc Q s).snd = Q.lift (BinaryFan.mk (s.fst ≫ sXY.snd) s.snd) := rfl #align category_theory.limits.binary_fan.assoc_snd CategoryTheory.Limits.BinaryFan.assoc_snd /-- Given binary fans `sXY` over `X Y`, and `sYZ` over `Y Z`, and `s` over `X sYZ.X`, if `sYZ` is a limit cone we can construct a binary fan over `sXY.X Z`. This is an ingredient of building the associator for a cartesian category. -/ def BinaryFan.assocInv {X Y Z : C} {sXY : BinaryFan X Y} (P : IsLimit sXY) {sYZ : BinaryFan Y Z} (s : BinaryFan X sYZ.pt) : BinaryFan sXY.pt Z := BinaryFan.mk (P.lift (BinaryFan.mk s.fst (s.snd ≫ sYZ.fst))) (s.snd ≫ sYZ.snd) #align category_theory.limits.binary_fan.assoc_inv CategoryTheory.Limits.BinaryFan.assocInv @[simp] theorem BinaryFan.assocInv_fst {X Y Z : C} {sXY : BinaryFan X Y} (P : IsLimit sXY) {sYZ : BinaryFan Y Z} (s : BinaryFan X sYZ.pt) : (BinaryFan.assocInv P s).fst = P.lift (BinaryFan.mk s.fst (s.snd ≫ sYZ.fst)) := rfl #align category_theory.limits.binary_fan.assoc_inv_fst CategoryTheory.Limits.BinaryFan.assocInv_fst @[simp] theorem BinaryFan.assocInv_snd {X Y Z : C} {sXY : BinaryFan X Y} (P : IsLimit sXY) {sYZ : BinaryFan Y Z} (s : BinaryFan X sYZ.pt) : (BinaryFan.assocInv P s).snd = s.snd ≫ sYZ.snd := rfl #align category_theory.limits.binary_fan.assoc_inv_snd CategoryTheory.Limits.BinaryFan.assocInv_snd /-- If all the binary fans involved a limit cones, `BinaryFan.assoc` produces another limit cone. -/ @[simps] def IsLimit.assoc {X Y Z : C} {sXY : BinaryFan X Y} (P : IsLimit sXY) {sYZ : BinaryFan Y Z} (Q : IsLimit sYZ) {s : BinaryFan sXY.pt Z} (R : IsLimit s) : IsLimit (BinaryFan.assoc Q s) where lift t := R.lift (BinaryFan.assocInv P t) fac t := by rintro ⟨⟨⟩⟩ <;> simp apply Q.hom_ext rintro ⟨⟨⟩⟩ <;> simp uniq t m w := by have h := R.uniq (BinaryFan.assocInv P t) m rw [h] rintro ⟨⟨⟩⟩ <;> simp · apply P.hom_ext rintro ⟨⟨⟩⟩ <;> simp · exact w ⟨WalkingPair.left⟩ · specialize w ⟨WalkingPair.right⟩ simp? at w says simp only [pair_obj_right, BinaryFan.π_app_right, BinaryFan.assoc_snd, Functor.const_obj_obj, pair_obj_left] at w rw [← w] simp · specialize w ⟨WalkingPair.right⟩ simp? at w says simp only [pair_obj_right, BinaryFan.π_app_right, BinaryFan.assoc_snd, Functor.const_obj_obj, pair_obj_left] at w rw [← w] simp #align category_theory.limits.is_limit.assoc CategoryTheory.Limits.IsLimit.assoc /-- Given two pairs of limit cones corresponding to the parenthesisations of `X × Y × Z`, we obtain an isomorphism between the cone points. -/ abbrev BinaryFan.associator {X Y Z : C} {sXY : BinaryFan X Y} (P : IsLimit sXY) {sYZ : BinaryFan Y Z} (Q : IsLimit sYZ) {s : BinaryFan sXY.pt Z} (R : IsLimit s) {t : BinaryFan X sYZ.pt} (S : IsLimit t) : s.pt ≅ t.pt := IsLimit.conePointUniqueUpToIso (IsLimit.assoc P Q R) S #align category_theory.limits.binary_fan.associator CategoryTheory.Limits.BinaryFan.associator /-- Given a fixed family of limit data for every pair `X Y`, we obtain an associator. -/ abbrev BinaryFan.associatorOfLimitCone (L : ∀ X Y : C, LimitCone (pair X Y)) (X Y Z : C) : (L (L X Y).cone.pt Z).cone.pt ≅ (L X (L Y Z).cone.pt).cone.pt := BinaryFan.associator (L X Y).isLimit (L Y Z).isLimit (L (L X Y).cone.pt Z).isLimit (L X (L Y Z).cone.pt).isLimit #align category_theory.limits.binary_fan.associator_of_limit_cone CategoryTheory.Limits.BinaryFan.associatorOfLimitCone /-- Construct a left unitor from specified limit cones. -/ @[simps] def BinaryFan.leftUnitor {X : C} {s : Cone (Functor.empty.{0} C)} (P : IsLimit s) {t : BinaryFan s.pt X} (Q : IsLimit t) : t.pt ≅ X where hom := t.snd inv := Q.lift <| BinaryFan.mk (P.lift ⟨_, fun x => x.as.elim, fun {x} => x.as.elim⟩) (𝟙 _) hom_inv_id := by apply Q.hom_ext rintro ⟨⟨⟩⟩ · apply P.hom_ext rintro ⟨⟨⟩⟩ · simp #align category_theory.limits.binary_fan.left_unitor CategoryTheory.Limits.BinaryFan.leftUnitor /-- Construct a right unitor from specified limit cones. -/ @[simps] def BinaryFan.rightUnitor {X : C} {s : Cone (Functor.empty.{0} C)} (P : IsLimit s) {t : BinaryFan X s.pt} (Q : IsLimit t) : t.pt ≅ X where hom := t.fst inv := Q.lift <| BinaryFan.mk (𝟙 _) <| P.lift ⟨_, fun x => x.as.elim, fun {x} => x.as.elim⟩ hom_inv_id := by apply Q.hom_ext rintro ⟨⟨⟩⟩ · simp · apply P.hom_ext rintro ⟨⟨⟩⟩ #align category_theory.limits.binary_fan.right_unitor CategoryTheory.Limits.BinaryFan.rightUnitor end end Limits open CategoryTheory.Limits section -- Porting note: no tidy -- attribute [local tidy] tactic.case_bash variable {C} variable (𝒯 : LimitCone (Functor.empty.{0} C)) variable (ℬ : ∀ X Y : C, LimitCone (pair X Y)) namespace MonoidalOfChosenFiniteProducts /-- Implementation of the tensor product for `MonoidalOfChosenFiniteProducts`. -/ abbrev tensorObj (X Y : C) : C := (ℬ X Y).cone.pt #align category_theory.monoidal_of_chosen_finite_products.tensor_obj CategoryTheory.MonoidalOfChosenFiniteProducts.tensorObj /-- Implementation of the tensor product of morphisms for `MonoidalOfChosenFiniteProducts`. -/ abbrev tensorHom {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : tensorObj ℬ W Y ⟶ tensorObj ℬ X Z := (BinaryFan.IsLimit.lift' (ℬ X Z).isLimit ((ℬ W Y).cone.π.app ⟨WalkingPair.left⟩ ≫ f) (((ℬ W Y).cone.π.app ⟨WalkingPair.right⟩ : (ℬ W Y).cone.pt ⟶ Y) ≫ g)).val #align category_theory.monoidal_of_chosen_finite_products.tensor_hom CategoryTheory.MonoidalOfChosenFiniteProducts.tensorHom theorem tensor_id (X₁ X₂ : C) : tensorHom ℬ (𝟙 X₁) (𝟙 X₂) = 𝟙 (tensorObj ℬ X₁ X₂) := by apply IsLimit.hom_ext (ℬ _ _).isLimit; rintro ⟨⟨⟩⟩ <;> · dsimp [tensorHom] simp #align category_theory.monoidal_of_chosen_finite_products.tensor_id CategoryTheory.MonoidalOfChosenFiniteProducts.tensor_id theorem tensor_comp {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂) : tensorHom ℬ (f₁ ≫ g₁) (f₂ ≫ g₂) = tensorHom ℬ f₁ f₂ ≫ tensorHom ℬ g₁ g₂ := by apply IsLimit.hom_ext (ℬ _ _).isLimit; rintro ⟨⟨⟩⟩ <;> · dsimp [tensorHom] simp #align category_theory.monoidal_of_chosen_finite_products.tensor_comp CategoryTheory.MonoidalOfChosenFiniteProducts.tensor_comp theorem pentagon (W X Y Z : C) : tensorHom ℬ (BinaryFan.associatorOfLimitCone ℬ W X Y).hom (𝟙 Z) ≫ (BinaryFan.associatorOfLimitCone ℬ W (tensorObj ℬ X Y) Z).hom ≫ tensorHom ℬ (𝟙 W) (BinaryFan.associatorOfLimitCone ℬ X Y Z).hom = (BinaryFan.associatorOfLimitCone ℬ (tensorObj ℬ W X) Y Z).hom ≫ (BinaryFan.associatorOfLimitCone ℬ W X (tensorObj ℬ Y Z)).hom := by dsimp [tensorHom] apply IsLimit.hom_ext (ℬ _ _).isLimit; rintro ⟨⟨⟩⟩ · simp · apply IsLimit.hom_ext (ℬ _ _).isLimit rintro ⟨⟨⟩⟩ · simp apply IsLimit.hom_ext (ℬ _ _).isLimit rintro ⟨⟨⟩⟩ · simp · simp #align category_theory.monoidal_of_chosen_finite_products.pentagon CategoryTheory.MonoidalOfChosenFiniteProducts.pentagon theorem triangle (X Y : C) : (BinaryFan.associatorOfLimitCone ℬ X 𝒯.cone.pt Y).hom ≫ tensorHom ℬ (𝟙 X) (BinaryFan.leftUnitor 𝒯.isLimit (ℬ 𝒯.cone.pt Y).isLimit).hom = tensorHom ℬ (BinaryFan.rightUnitor 𝒯.isLimit (ℬ X 𝒯.cone.pt).isLimit).hom (𝟙 Y) := by dsimp [tensorHom] apply IsLimit.hom_ext (ℬ _ _).isLimit; rintro ⟨⟨⟩⟩ <;> simp #align category_theory.monoidal_of_chosen_finite_products.triangle CategoryTheory.MonoidalOfChosenFiniteProducts.triangle theorem leftUnitor_naturality {X₁ X₂ : C} (f : X₁ ⟶ X₂) : tensorHom ℬ (𝟙 𝒯.cone.pt) f ≫ (BinaryFan.leftUnitor 𝒯.isLimit (ℬ 𝒯.cone.pt X₂).isLimit).hom = (BinaryFan.leftUnitor 𝒯.isLimit (ℬ 𝒯.cone.pt X₁).isLimit).hom ≫ f := by dsimp [tensorHom] simp #align category_theory.monoidal_of_chosen_finite_products.left_unitor_naturality CategoryTheory.MonoidalOfChosenFiniteProducts.leftUnitor_naturality
Mathlib/CategoryTheory/Monoidal/OfChosenFiniteProducts/Basic.lean
290
294
theorem rightUnitor_naturality {X₁ X₂ : C} (f : X₁ ⟶ X₂) : tensorHom ℬ f (𝟙 𝒯.cone.pt) ≫ (BinaryFan.rightUnitor 𝒯.isLimit (ℬ X₂ 𝒯.cone.pt).isLimit).hom = (BinaryFan.rightUnitor 𝒯.isLimit (ℬ X₁ 𝒯.cone.pt).isLimit).hom ≫ f := by
dsimp [tensorHom] simp
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Simon Hudon -/ import Mathlib.Data.PFunctor.Multivariate.Basic #align_import data.pfunctor.multivariate.W from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988" /-! # The W construction as a multivariate polynomial functor. W types are well-founded tree-like structures. They are defined as the least fixpoint of a polynomial functor. ## Main definitions * `W_mk` - constructor * `W_dest - destructor * `W_rec` - recursor: basis for defining functions by structural recursion on `P.W α` * `W_rec_eq` - defining equation for `W_rec` * `W_ind` - induction principle for `P.W α` ## Implementation notes Three views of M-types: * `wp`: polynomial functor * `W`: data type inductively defined by a triple: shape of the root, data in the root and children of the root * `W`: least fixed point of a polynomial functor Specifically, we define the polynomial functor `wp` as: * A := a tree-like structure without information in the nodes * B := given the tree-like structure `t`, `B t` is a valid path (specified inductively by `W_path`) from the root of `t` to any given node. As a result `wp α` is made of a dataless tree and a function from its valid paths to values of `α` ## Reference * Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u v namespace MvPFunctor open TypeVec open MvFunctor variable {n : ℕ} (P : MvPFunctor.{u} (n + 1)) /-- A path from the root of a tree to one of its node -/ inductive WPath : P.last.W → Fin2 n → Type u | root (a : P.A) (f : P.last.B a → P.last.W) (i : Fin2 n) (c : P.drop.B a i) : WPath ⟨a, f⟩ i | child (a : P.A) (f : P.last.B a → P.last.W) (i : Fin2 n) (j : P.last.B a) (c : WPath (f j) i) : WPath ⟨a, f⟩ i set_option linter.uppercaseLean3 false in #align mvpfunctor.W_path MvPFunctor.WPath instance WPath.inhabited (x : P.last.W) {i} [I : Inhabited (P.drop.B x.head i)] : Inhabited (WPath P x i) := ⟨match x, I with | ⟨a, f⟩, I => WPath.root a f i (@default _ I)⟩ set_option linter.uppercaseLean3 false in #align mvpfunctor.W_path.inhabited MvPFunctor.WPath.inhabited /-- Specialized destructor on `WPath` -/ def wPathCasesOn {α : TypeVec n} {a : P.A} {f : P.last.B a → P.last.W} (g' : P.drop.B a ⟹ α) (g : ∀ j : P.last.B a, P.WPath (f j) ⟹ α) : P.WPath ⟨a, f⟩ ⟹ α := by intro i x; match x with | WPath.root _ _ i c => exact g' i c | WPath.child _ _ i j c => exact g j i c set_option linter.uppercaseLean3 false in #align mvpfunctor.W_path_cases_on MvPFunctor.wPathCasesOn /-- Specialized destructor on `WPath` -/ def wPathDestLeft {α : TypeVec n} {a : P.A} {f : P.last.B a → P.last.W} (h : P.WPath ⟨a, f⟩ ⟹ α) : P.drop.B a ⟹ α := fun i c => h i (WPath.root a f i c) set_option linter.uppercaseLean3 false in #align mvpfunctor.W_path_dest_left MvPFunctor.wPathDestLeft /-- Specialized destructor on `WPath` -/ def wPathDestRight {α : TypeVec n} {a : P.A} {f : P.last.B a → P.last.W} (h : P.WPath ⟨a, f⟩ ⟹ α) : ∀ j : P.last.B a, P.WPath (f j) ⟹ α := fun j i c => h i (WPath.child a f i j c) set_option linter.uppercaseLean3 false in #align mvpfunctor.W_path_dest_right MvPFunctor.wPathDestRight theorem wPathDestLeft_wPathCasesOn {α : TypeVec n} {a : P.A} {f : P.last.B a → P.last.W} (g' : P.drop.B a ⟹ α) (g : ∀ j : P.last.B a, P.WPath (f j) ⟹ α) : P.wPathDestLeft (P.wPathCasesOn g' g) = g' := rfl set_option linter.uppercaseLean3 false in #align mvpfunctor.W_path_dest_left_W_path_cases_on MvPFunctor.wPathDestLeft_wPathCasesOn theorem wPathDestRight_wPathCasesOn {α : TypeVec n} {a : P.A} {f : P.last.B a → P.last.W} (g' : P.drop.B a ⟹ α) (g : ∀ j : P.last.B a, P.WPath (f j) ⟹ α) : P.wPathDestRight (P.wPathCasesOn g' g) = g := rfl set_option linter.uppercaseLean3 false in #align mvpfunctor.W_path_dest_right_W_path_cases_on MvPFunctor.wPathDestRight_wPathCasesOn theorem wPathCasesOn_eta {α : TypeVec n} {a : P.A} {f : P.last.B a → P.last.W} (h : P.WPath ⟨a, f⟩ ⟹ α) : P.wPathCasesOn (P.wPathDestLeft h) (P.wPathDestRight h) = h := by ext i x; cases x <;> rfl set_option linter.uppercaseLean3 false in #align mvpfunctor.W_path_cases_on_eta MvPFunctor.wPathCasesOn_eta theorem comp_wPathCasesOn {α β : TypeVec n} (h : α ⟹ β) {a : P.A} {f : P.last.B a → P.last.W} (g' : P.drop.B a ⟹ α) (g : ∀ j : P.last.B a, P.WPath (f j) ⟹ α) : h ⊚ P.wPathCasesOn g' g = P.wPathCasesOn (h ⊚ g') fun i => h ⊚ g i := by ext i x; cases x <;> rfl set_option linter.uppercaseLean3 false in #align mvpfunctor.comp_W_path_cases_on MvPFunctor.comp_wPathCasesOn /-- Polynomial functor for the W-type of `P`. `A` is a data-less well-founded tree whereas, for a given `a : A`, `B a` is a valid path in tree `a` so that `Wp.obj α` is made of a tree and a function from its valid paths to the values it contains -/ def wp : MvPFunctor n where A := P.last.W B := P.WPath set_option linter.uppercaseLean3 false in #align mvpfunctor.Wp MvPFunctor.wp /-- W-type of `P` -/ -- Porting note(#5171): used to have @[nolint has_nonempty_instance] def W (α : TypeVec n) : Type _ := P.wp α set_option linter.uppercaseLean3 false in #align mvpfunctor.W MvPFunctor.W instance mvfunctorW : MvFunctor P.W := by delta MvPFunctor.W; infer_instance set_option linter.uppercaseLean3 false in #align mvpfunctor.mvfunctor_W MvPFunctor.mvfunctorW /-! First, describe operations on `W` as a polynomial functor. -/ /-- Constructor for `wp` -/ def wpMk {α : TypeVec n} (a : P.A) (f : P.last.B a → P.last.W) (f' : P.WPath ⟨a, f⟩ ⟹ α) : P.W α := ⟨⟨a, f⟩, f'⟩ set_option linter.uppercaseLean3 false in #align mvpfunctor.Wp_mk MvPFunctor.wpMk def wpRec {α : TypeVec n} {C : Type*} (g : ∀ (a : P.A) (f : P.last.B a → P.last.W), P.WPath ⟨a, f⟩ ⟹ α → (P.last.B a → C) → C) : ∀ (x : P.last.W) (_ : P.WPath x ⟹ α), C | ⟨a, f⟩, f' => g a f f' fun i => wpRec g (f i) (P.wPathDestRight f' i) set_option linter.uppercaseLean3 false in #align mvpfunctor.Wp_rec MvPFunctor.wpRec theorem wpRec_eq {α : TypeVec n} {C : Type*} (g : ∀ (a : P.A) (f : P.last.B a → P.last.W), P.WPath ⟨a, f⟩ ⟹ α → (P.last.B a → C) → C) (a : P.A) (f : P.last.B a → P.last.W) (f' : P.WPath ⟨a, f⟩ ⟹ α) : P.wpRec g ⟨a, f⟩ f' = g a f f' fun i => P.wpRec g (f i) (P.wPathDestRight f' i) := rfl set_option linter.uppercaseLean3 false in #align mvpfunctor.Wp_rec_eq MvPFunctor.wpRec_eq -- Note: we could replace Prop by Type* and obtain a dependent recursor theorem wp_ind {α : TypeVec n} {C : ∀ x : P.last.W, P.WPath x ⟹ α → Prop} (ih : ∀ (a : P.A) (f : P.last.B a → P.last.W) (f' : P.WPath ⟨a, f⟩ ⟹ α), (∀ i : P.last.B a, C (f i) (P.wPathDestRight f' i)) → C ⟨a, f⟩ f') : ∀ (x : P.last.W) (f' : P.WPath x ⟹ α), C x f' | ⟨a, f⟩, f' => ih a f f' fun _i => wp_ind ih _ _ set_option linter.uppercaseLean3 false in #align mvpfunctor.Wp_ind MvPFunctor.wp_ind /-! Now think of W as defined inductively by the data ⟨a, f', f⟩ where - `a : P.A` is the shape of the top node - `f' : P.drop.B a ⟹ α` is the contents of the top node - `f : P.last.B a → P.last.W` are the subtrees -/ /-- Constructor for `W` -/ def wMk {α : TypeVec n} (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) : P.W α := let g : P.last.B a → P.last.W := fun i => (f i).fst let g' : P.WPath ⟨a, g⟩ ⟹ α := P.wPathCasesOn f' fun i => (f i).snd ⟨⟨a, g⟩, g'⟩ set_option linter.uppercaseLean3 false in #align mvpfunctor.W_mk MvPFunctor.wMk /-- Recursor for `W` -/ def wRec {α : TypeVec n} {C : Type*} (g : ∀ a : P.A, P.drop.B a ⟹ α → (P.last.B a → P.W α) → (P.last.B a → C) → C) : P.W α → C | ⟨a, f'⟩ => let g' (a : P.A) (f : P.last.B a → P.last.W) (h : P.WPath ⟨a, f⟩ ⟹ α) (h' : P.last.B a → C) : C := g a (P.wPathDestLeft h) (fun i => ⟨f i, P.wPathDestRight h i⟩) h' P.wpRec g' a f' set_option linter.uppercaseLean3 false in #align mvpfunctor.W_rec MvPFunctor.wRec /-- Defining equation for the recursor of `W` -/ theorem wRec_eq {α : TypeVec n} {C : Type*} (g : ∀ a : P.A, P.drop.B a ⟹ α → (P.last.B a → P.W α) → (P.last.B a → C) → C) (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) : P.wRec g (P.wMk a f' f) = g a f' f fun i => P.wRec g (f i) := by rw [wMk, wRec]; dsimp; rw [wpRec_eq] dsimp only [wPathDestLeft_wPathCasesOn, wPathDestRight_wPathCasesOn] congr set_option linter.uppercaseLean3 false in #align mvpfunctor.W_rec_eq MvPFunctor.wRec_eq /-- Induction principle for `W` -/ theorem w_ind {α : TypeVec n} {C : P.W α → Prop} (ih : ∀ (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α), (∀ i, C (f i)) → C (P.wMk a f' f)) : ∀ x, C x := by intro x; cases' x with a f apply @wp_ind n P α fun a f => C ⟨a, f⟩ intro a f f' ih' dsimp [wMk] at ih let ih'' := ih a (P.wPathDestLeft f') fun i => ⟨f i, P.wPathDestRight f' i⟩ dsimp at ih''; rw [wPathCasesOn_eta] at ih'' apply ih'' apply ih' set_option linter.uppercaseLean3 false in #align mvpfunctor.W_ind MvPFunctor.w_ind theorem w_cases {α : TypeVec n} {C : P.W α → Prop} (ih : ∀ (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α), C (P.wMk a f' f)) : ∀ x, C x := P.w_ind fun a f' f _ih' => ih a f' f set_option linter.uppercaseLean3 false in #align mvpfunctor.W_cases MvPFunctor.w_cases /-- W-types are functorial -/ def wMap {α β : TypeVec n} (g : α ⟹ β) : P.W α → P.W β := fun x => g <$$> x set_option linter.uppercaseLean3 false in #align mvpfunctor.W_map MvPFunctor.wMap theorem wMk_eq {α : TypeVec n} (a : P.A) (f : P.last.B a → P.last.W) (g' : P.drop.B a ⟹ α) (g : ∀ j : P.last.B a, P.WPath (f j) ⟹ α) : (P.wMk a g' fun i => ⟨f i, g i⟩) = ⟨⟨a, f⟩, P.wPathCasesOn g' g⟩ := rfl set_option linter.uppercaseLean3 false in #align mvpfunctor.W_mk_eq MvPFunctor.wMk_eq theorem w_map_wMk {α β : TypeVec n} (g : α ⟹ β) (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) : g <$$> P.wMk a f' f = P.wMk a (g ⊚ f') fun i => g <$$> f i := by show _ = P.wMk a (g ⊚ f') (MvFunctor.map g ∘ f) have : MvFunctor.map g ∘ f = fun i => ⟨(f i).fst, g ⊚ (f i).snd⟩ := by ext i : 1 dsimp [Function.comp_def] cases f i rfl rw [this] have : f = fun i => ⟨(f i).fst, (f i).snd⟩ := by ext1 x cases f x rfl rw [this] dsimp rw [wMk_eq, wMk_eq] have h := MvPFunctor.map_eq P.wp g rw [h, comp_wPathCasesOn] set_option linter.uppercaseLean3 false in #align mvpfunctor.W_map_W_mk MvPFunctor.w_map_wMk -- TODO: this technical theorem is used in one place in constructing the initial algebra. -- Can it be avoided? /-- Constructor of a value of `P.obj (α ::: β)` from components. Useful to avoid complicated type annotation -/ abbrev objAppend1 {α : TypeVec n} {β : Type u} (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → β) : P (α ::: β) := ⟨a, splitFun f' f⟩ #align mvpfunctor.obj_append1 MvPFunctor.objAppend1 theorem map_objAppend1 {α γ : TypeVec n} (g : α ⟹ γ) (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) : appendFun g (P.wMap g) <$$> P.objAppend1 a f' f = P.objAppend1 a (g ⊚ f') fun x => P.wMap g (f x) := by rw [objAppend1, objAppend1, map_eq, appendFun, ← splitFun_comp]; rfl #align mvpfunctor.map_obj_append1 MvPFunctor.map_objAppend1 /-! Yet another view of the W type: as a fixed point for a multivariate polynomial functor. These are needed to use the W-construction to construct a fixed point of a qpf, since the qpf axioms are expressed in terms of `map` on `P`. -/ /-- Constructor for the W-type of `P` -/ def wMk' {α : TypeVec n} : P (α ::: P.W α) → P.W α | ⟨a, f⟩ => P.wMk a (dropFun f) (lastFun f) set_option linter.uppercaseLean3 false in #align mvpfunctor.W_mk' MvPFunctor.wMk' /-- Destructor for the W-type of `P` -/ def wDest' {α : TypeVec.{u} n} : P.W α → P (α.append1 (P.W α)) := P.wRec fun a f' f _ => ⟨a, splitFun f' f⟩ set_option linter.uppercaseLean3 false in #align mvpfunctor.W_dest' MvPFunctor.wDest'
Mathlib/Data/PFunctor/Multivariate/W.lean
305
306
theorem wDest'_wMk {α : TypeVec n} (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) : P.wDest' (P.wMk a f' f) = ⟨a, splitFun f' f⟩ := by
rw [wDest', wRec_eq]
/- 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.SetTheory.Cardinal.ENat #align_import set_theory.cardinal.basic from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8" /-! # Projection from cardinal numbers to natural numbers In this file we define `Cardinal.toNat` to be the natural projection `Cardinal → ℕ`, sending all infinite cardinals to zero. We also prove basic lemmas about this definition. -/ universe u v open Function Set namespace Cardinal variable {α : Type u} {c d : Cardinal.{u}} /-- This function sends finite cardinals to the corresponding natural, and infinite cardinals to 0. -/ noncomputable def toNat : Cardinal →*₀ ℕ := ENat.toNat.comp toENat #align cardinal.to_nat Cardinal.toNat #align cardinal.to_nat_hom Cardinal.toNat @[simp] lemma toNat_toENat (a : Cardinal) : ENat.toNat (toENat a) = toNat a := rfl @[simp] theorem toNat_ofENat (n : ℕ∞) : toNat n = ENat.toNat n := congr_arg ENat.toNat <| toENat_ofENat n @[simp, norm_cast] theorem toNat_natCast (n : ℕ) : toNat n = n := toNat_ofENat n @[simp] lemma toNat_eq_zero : toNat c = 0 ↔ c = 0 ∨ ℵ₀ ≤ c := by rw [← toNat_toENat, ENat.toNat_eq_zero, toENat_eq_zero, toENat_eq_top] lemma toNat_ne_zero : toNat c ≠ 0 ↔ c ≠ 0 ∧ c < ℵ₀ := by simp [not_or] @[simp] lemma toNat_pos : 0 < toNat c ↔ c ≠ 0 ∧ c < ℵ₀ := pos_iff_ne_zero.trans toNat_ne_zero theorem cast_toNat_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : ↑(toNat c) = c := by lift c to ℕ using h rw [toNat_natCast] #align cardinal.cast_to_nat_of_lt_aleph_0 Cardinal.cast_toNat_of_lt_aleph0 theorem toNat_apply_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : toNat c = Classical.choose (lt_aleph0.1 h) := Nat.cast_injective <| by rw [cast_toNat_of_lt_aleph0 h, ← Classical.choose_spec (lt_aleph0.1 h)] #align cardinal.to_nat_apply_of_lt_aleph_0 Cardinal.toNat_apply_of_lt_aleph0 theorem toNat_apply_of_aleph0_le {c : Cardinal} (h : ℵ₀ ≤ c) : toNat c = 0 := by simp [h] #align cardinal.to_nat_apply_of_aleph_0_le Cardinal.toNat_apply_of_aleph0_le theorem cast_toNat_of_aleph0_le {c : Cardinal} (h : ℵ₀ ≤ c) : ↑(toNat c) = (0 : Cardinal) := by rw [toNat_apply_of_aleph0_le h, Nat.cast_zero] #align cardinal.cast_to_nat_of_aleph_0_le Cardinal.cast_toNat_of_aleph0_le theorem toNat_strictMonoOn : StrictMonoOn toNat (Iio ℵ₀) := by simp only [← range_natCast, StrictMonoOn, forall_mem_range, toNat_natCast, Nat.cast_lt] exact fun _ _ ↦ id theorem toNat_monotoneOn : MonotoneOn toNat (Iio ℵ₀) := toNat_strictMonoOn.monotoneOn theorem toNat_injOn : InjOn toNat (Iio ℵ₀) := toNat_strictMonoOn.injOn /-- Two finite cardinals are equal iff they are equal their `Cardinal.toNat` projections are equal. -/ theorem toNat_eq_iff_eq_of_lt_aleph0 (hc : c < ℵ₀) (hd : d < ℵ₀) : toNat c = toNat d ↔ c = d := toNat_injOn.eq_iff hc hd #align cardinal.to_nat_eq_iff_eq_of_lt_aleph_0 Cardinal.toNat_eq_iff_eq_of_lt_aleph0 theorem toNat_le_iff_le_of_lt_aleph0 (hc : c < ℵ₀) (hd : d < ℵ₀) : toNat c ≤ toNat d ↔ c ≤ d := toNat_strictMonoOn.le_iff_le hc hd #align cardinal.to_nat_le_iff_le_of_lt_aleph_0 Cardinal.toNat_le_iff_le_of_lt_aleph0 theorem toNat_lt_iff_lt_of_lt_aleph0 (hc : c < ℵ₀) (hd : d < ℵ₀) : toNat c < toNat d ↔ c < d := toNat_strictMonoOn.lt_iff_lt hc hd #align cardinal.to_nat_lt_iff_lt_of_lt_aleph_0 Cardinal.toNat_lt_iff_lt_of_lt_aleph0 @[gcongr] theorem toNat_le_toNat (hcd : c ≤ d) (hd : d < ℵ₀) : toNat c ≤ toNat d := toNat_monotoneOn (hcd.trans_lt hd) hd hcd #align cardinal.to_nat_le_of_le_of_lt_aleph_0 Cardinal.toNat_le_toNat @[deprecated toNat_le_toNat (since := "2024-02-15")] theorem toNat_le_of_le_of_lt_aleph0 (hd : d < ℵ₀) (hcd : c ≤ d) : toNat c ≤ toNat d := toNat_le_toNat hcd hd theorem toNat_lt_toNat (hcd : c < d) (hd : d < ℵ₀) : toNat c < toNat d := toNat_strictMonoOn (hcd.trans hd) hd hcd #align cardinal.to_nat_lt_of_lt_of_lt_aleph_0 Cardinal.toNat_lt_toNat @[deprecated toNat_lt_toNat (since := "2024-02-15")] theorem toNat_lt_of_lt_of_lt_aleph0 (hd : d < ℵ₀) (hcd : c < d) : toNat c < toNat d := toNat_lt_toNat hcd hd @[deprecated (since := "2024-02-15")] alias toNat_cast := toNat_natCast #align cardinal.to_nat_cast Cardinal.toNat_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem toNat_ofNat (n : ℕ) [n.AtLeastTwo] : Cardinal.toNat (no_index (OfNat.ofNat n)) = OfNat.ofNat n := toNat_natCast n /-- `toNat` has a right-inverse: coercion. -/ theorem toNat_rightInverse : Function.RightInverse ((↑) : ℕ → Cardinal) toNat := toNat_natCast #align cardinal.to_nat_right_inverse Cardinal.toNat_rightInverse theorem toNat_surjective : Surjective toNat := toNat_rightInverse.surjective #align cardinal.to_nat_surjective Cardinal.toNat_surjective @[simp] theorem mk_toNat_of_infinite [h : Infinite α] : toNat #α = 0 := by simp #align cardinal.mk_to_nat_of_infinite Cardinal.mk_toNat_of_infinite @[simp] theorem aleph0_toNat : toNat ℵ₀ = 0 := toNat_apply_of_aleph0_le le_rfl #align cardinal.aleph_0_to_nat Cardinal.aleph0_toNat theorem mk_toNat_eq_card [Fintype α] : toNat #α = Fintype.card α := by simp #align cardinal.mk_to_nat_eq_card Cardinal.mk_toNat_eq_card -- porting note (#10618): simp can prove this -- @[simp] theorem zero_toNat : toNat 0 = 0 := map_zero _ #align cardinal.zero_to_nat Cardinal.zero_toNat theorem one_toNat : toNat 1 = 1 := map_one _ #align cardinal.one_to_nat Cardinal.one_toNat theorem toNat_eq_iff {n : ℕ} (hn : n ≠ 0) : toNat c = n ↔ c = n := by rw [← toNat_toENat, ENat.toNat_eq_iff hn, toENat_eq_nat] #align cardinal.to_nat_eq_iff Cardinal.toNat_eq_iff /-- A version of `toNat_eq_iff` for literals -/ theorem toNat_eq_ofNat {n : ℕ} [Nat.AtLeastTwo n] : toNat c = OfNat.ofNat n ↔ c = OfNat.ofNat n := toNat_eq_iff <| OfNat.ofNat_ne_zero n @[simp] theorem toNat_eq_one : toNat c = 1 ↔ c = 1 := by rw [toNat_eq_iff one_ne_zero, Nat.cast_one] #align cardinal.to_nat_eq_one Cardinal.toNat_eq_one theorem toNat_eq_one_iff_unique : toNat #α = 1 ↔ Subsingleton α ∧ Nonempty α := toNat_eq_one.trans eq_one_iff_unique #align cardinal.to_nat_eq_one_iff_unique Cardinal.toNat_eq_one_iff_unique @[simp] theorem toNat_lift (c : Cardinal.{v}) : toNat (lift.{u, v} c) = toNat c := by simp only [← toNat_toENat, toENat_lift] #align cardinal.to_nat_lift Cardinal.toNat_lift theorem toNat_congr {β : Type v} (e : α ≃ β) : toNat #α = toNat #β := by -- Porting note: Inserted universe hint below rw [← toNat_lift, (lift_mk_eq.{_,_,v}).mpr ⟨e⟩, toNat_lift] #align cardinal.to_nat_congr Cardinal.toNat_congr theorem toNat_mul (x y : Cardinal) : toNat (x * y) = toNat x * toNat y := map_mul toNat x y #align cardinal.to_nat_mul Cardinal.toNat_mul @[deprecated map_prod (since := "2024-02-15")] theorem toNat_finset_prod (s : Finset α) (f : α → Cardinal) : toNat (∏ i ∈ s, f i) = ∏ i ∈ s, toNat (f i) := map_prod toNat _ _ #align cardinal.to_nat_finset_prod Cardinal.toNat_finset_prod @[simp] theorem toNat_add (hc : c < ℵ₀) (hd : d < ℵ₀) : toNat (c + d) = toNat c + toNat d := by lift c to ℕ using hc lift d to ℕ using hd norm_cast @[simp]
Mathlib/SetTheory/Cardinal/ToNat.lean
189
191
theorem toNat_lift_add_lift {a : Cardinal.{u}} {b : Cardinal.{v}} (ha : a < ℵ₀) (hb : b < ℵ₀) : toNat (lift.{v} a + lift.{u} b) = toNat a + toNat b := by
simp [*]
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.LinearAlgebra.StdBasis import Mathlib.RingTheory.AlgebraTower import Mathlib.Algebra.Algebra.Subalgebra.Tower #align_import linear_algebra.matrix.to_lin from "leanprover-community/mathlib"@"0e2aab2b0d521f060f62a14d2cf2e2c54e8491d6" /-! # Linear maps and matrices This file defines the maps to send matrices to a linear map, and to send linear maps between modules with a finite bases to matrices. This defines a linear equivalence between linear maps between finite-dimensional vector spaces and matrices indexed by the respective bases. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite types used for indexing. * `LinearMap.toMatrix`: given bases `v₁ : ι → M₁` and `v₂ : κ → M₂`, the `R`-linear equivalence from `M₁ →ₗ[R] M₂` to `Matrix κ ι R` * `Matrix.toLin`: the inverse of `LinearMap.toMatrix` * `LinearMap.toMatrix'`: the `R`-linear equivalence from `(m → R) →ₗ[R] (n → R)` to `Matrix m n R` (with the standard basis on `m → R` and `n → R`) * `Matrix.toLin'`: the inverse of `LinearMap.toMatrix'` * `algEquivMatrix`: given a basis indexed by `n`, the `R`-algebra equivalence between `R`-endomorphisms of `M` and `Matrix n n R` ## Issues This file was originally written without attention to non-commutative rings, and so mostly only works in the commutative setting. This should be fixed. In particular, `Matrix.mulVec` gives us a linear equivalence `Matrix m n R ≃ₗ[R] (n → R) →ₗ[Rᵐᵒᵖ] (m → R)` while `Matrix.vecMul` gives us a linear equivalence `Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] (n → R)`. At present, the first equivalence is developed in detail but only for commutative rings (and we omit the distinction between `Rᵐᵒᵖ` and `R`), while the second equivalence is developed only in brief, but for not-necessarily-commutative rings. Naming is slightly inconsistent between the two developments. In the original (commutative) development `linear` is abbreviated to `lin`, although this is not consistent with the rest of mathlib. In the new (non-commutative) development `linear` is not abbreviated, and declarations use `_right` to indicate they use the right action of matrices on vectors (via `Matrix.vecMul`). When the two developments are made uniform, the names should be made uniform, too, by choosing between `linear` and `lin` consistently, and (presumably) adding `_left` where necessary. ## Tags linear_map, matrix, linear_equiv, diagonal, det, trace -/ noncomputable section open LinearMap Matrix Set Submodule section ToMatrixRight variable {R : Type*} [Semiring R] variable {l m n : Type*} /-- `Matrix.vecMul M` is a linear map. -/ def Matrix.vecMulLinear [Fintype m] (M : Matrix m n R) : (m → R) →ₗ[R] n → R where toFun x := x ᵥ* M map_add' _ _ := funext fun _ ↦ add_dotProduct _ _ _ map_smul' _ _ := funext fun _ ↦ smul_dotProduct _ _ _ #align matrix.vec_mul_linear Matrix.vecMulLinear @[simp] theorem Matrix.vecMulLinear_apply [Fintype m] (M : Matrix m n R) (x : m → R) : M.vecMulLinear x = x ᵥ* M := rfl theorem Matrix.coe_vecMulLinear [Fintype m] (M : Matrix m n R) : (M.vecMulLinear : _ → _) = M.vecMul := rfl variable [Fintype m] [DecidableEq m] @[simp] theorem Matrix.vecMul_stdBasis (M : Matrix m n R) (i j) : (LinearMap.stdBasis R (fun _ ↦ R) i 1 ᵥ* M) j = M i j := by have : (∑ i', (if i = i' then 1 else 0) * M i' j) = M i j := by simp_rw [boole_mul, Finset.sum_ite_eq, Finset.mem_univ, if_true] simp only [vecMul, dotProduct] convert this split_ifs with h <;> simp only [stdBasis_apply] · rw [h, Function.update_same] · rw [Function.update_noteq (Ne.symm h), Pi.zero_apply] #align matrix.vec_mul_std_basis Matrix.vecMul_stdBasis theorem range_vecMulLinear (M : Matrix m n R) : LinearMap.range M.vecMulLinear = span R (range M) := by letI := Classical.decEq m simp_rw [range_eq_map, ← iSup_range_stdBasis, Submodule.map_iSup, range_eq_map, ← Ideal.span_singleton_one, Ideal.span, Submodule.map_span, image_image, image_singleton, Matrix.vecMulLinear_apply, iSup_span, range_eq_iUnion, iUnion_singleton_eq_range, LinearMap.stdBasis, coe_single] unfold vecMul simp_rw [single_dotProduct, one_mul] theorem Matrix.vecMul_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} : Function.Injective M.vecMul ↔ LinearIndependent R (fun i ↦ M i) := by rw [← coe_vecMulLinear] simp only [← LinearMap.ker_eq_bot, Fintype.linearIndependent_iff, Submodule.eq_bot_iff, LinearMap.mem_ker, vecMulLinear_apply] refine ⟨fun h c h0 ↦ congr_fun <| h c ?_, fun h c h0 ↦ funext <| h c ?_⟩ · rw [← h0] ext i simp [vecMul, dotProduct] · rw [← h0] ext j simp [vecMul, dotProduct] /-- Linear maps `(m → R) →ₗ[R] (n → R)` are linearly equivalent over `Rᵐᵒᵖ` to `Matrix m n R`, by having matrices act by right multiplication. -/ def LinearMap.toMatrixRight' : ((m → R) →ₗ[R] n → R) ≃ₗ[Rᵐᵒᵖ] Matrix m n R where toFun f i j := f (stdBasis R (fun _ ↦ R) i 1) j invFun := Matrix.vecMulLinear right_inv M := by ext i j simp only [Matrix.vecMul_stdBasis, Matrix.vecMulLinear_apply] left_inv f := by apply (Pi.basisFun R m).ext intro j; ext i simp only [Pi.basisFun_apply, Matrix.vecMul_stdBasis, Matrix.vecMulLinear_apply] map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, Matrix.smul_apply] #align linear_map.to_matrix_right' LinearMap.toMatrixRight' /-- A `Matrix m n R` is linearly equivalent over `Rᵐᵒᵖ` to a linear map `(m → R) →ₗ[R] (n → R)`, by having matrices act by right multiplication. -/ abbrev Matrix.toLinearMapRight' : Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] n → R := LinearEquiv.symm LinearMap.toMatrixRight' #align matrix.to_linear_map_right' Matrix.toLinearMapRight' @[simp] theorem Matrix.toLinearMapRight'_apply (M : Matrix m n R) (v : m → R) : (Matrix.toLinearMapRight') M v = v ᵥ* M := rfl #align matrix.to_linear_map_right'_apply Matrix.toLinearMapRight'_apply @[simp] theorem Matrix.toLinearMapRight'_mul [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLinearMapRight' (M * N) = (Matrix.toLinearMapRight' N).comp (Matrix.toLinearMapRight' M) := LinearMap.ext fun _x ↦ (vecMul_vecMul _ M N).symm #align matrix.to_linear_map_right'_mul Matrix.toLinearMapRight'_mul theorem Matrix.toLinearMapRight'_mul_apply [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLinearMapRight' (M * N) x = Matrix.toLinearMapRight' N (Matrix.toLinearMapRight' M x) := (vecMul_vecMul _ M N).symm #align matrix.to_linear_map_right'_mul_apply Matrix.toLinearMapRight'_mul_apply @[simp] theorem Matrix.toLinearMapRight'_one : Matrix.toLinearMapRight' (1 : Matrix m m R) = LinearMap.id := by ext simp [LinearMap.one_apply, stdBasis_apply] #align matrix.to_linear_map_right'_one Matrix.toLinearMapRight'_one /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `n → A` and `m → A` corresponding to `M.vecMul` and `M'.vecMul`. -/ @[simps] def Matrix.toLinearEquivRight'OfInv [Fintype n] [DecidableEq n] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (n → R) ≃ₗ[R] m → R := { LinearMap.toMatrixRight'.symm M' with toFun := Matrix.toLinearMapRight' M' invFun := Matrix.toLinearMapRight' M left_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hM'M, Matrix.toLinearMapRight'_one, id_apply] right_inv := fun x ↦ by dsimp only -- Porting note: needed due to non-flat structures rw [← Matrix.toLinearMapRight'_mul_apply, hMM', Matrix.toLinearMapRight'_one, id_apply] } #align matrix.to_linear_equiv_right'_of_inv Matrix.toLinearEquivRight'OfInv end ToMatrixRight /-! From this point on, we only work with commutative rings, and fail to distinguish between `Rᵐᵒᵖ` and `R`. This should eventually be remedied. -/ section mulVec variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} /-- `Matrix.mulVec M` is a linear map. -/ def Matrix.mulVecLin [Fintype n] (M : Matrix m n R) : (n → R) →ₗ[R] m → R where toFun := M.mulVec map_add' _ _ := funext fun _ ↦ dotProduct_add _ _ _ map_smul' _ _ := funext fun _ ↦ dotProduct_smul _ _ _ #align matrix.mul_vec_lin Matrix.mulVecLin theorem Matrix.coe_mulVecLin [Fintype n] (M : Matrix m n R) : (M.mulVecLin : _ → _) = M.mulVec := rfl @[simp] theorem Matrix.mulVecLin_apply [Fintype n] (M : Matrix m n R) (v : n → R) : M.mulVecLin v = M *ᵥ v := rfl #align matrix.mul_vec_lin_apply Matrix.mulVecLin_apply @[simp] theorem Matrix.mulVecLin_zero [Fintype n] : Matrix.mulVecLin (0 : Matrix m n R) = 0 := LinearMap.ext zero_mulVec #align matrix.mul_vec_lin_zero Matrix.mulVecLin_zero @[simp] theorem Matrix.mulVecLin_add [Fintype n] (M N : Matrix m n R) : (M + N).mulVecLin = M.mulVecLin + N.mulVecLin := LinearMap.ext fun _ ↦ add_mulVec _ _ _ #align matrix.mul_vec_lin_add Matrix.mulVecLin_add @[simp] theorem Matrix.mulVecLin_transpose [Fintype m] (M : Matrix m n R) : Mᵀ.mulVecLin = M.vecMulLinear := by ext; simp [mulVec_transpose] @[simp] theorem Matrix.vecMulLinear_transpose [Fintype n] (M : Matrix m n R) : Mᵀ.vecMulLinear = M.mulVecLin := by ext; simp [vecMul_transpose] theorem Matrix.mulVecLin_submatrix [Fintype n] [Fintype l] (f₁ : m → k) (e₂ : n ≃ l) (M : Matrix k l R) : (M.submatrix f₁ e₂).mulVecLin = funLeft R R f₁ ∘ₗ M.mulVecLin ∘ₗ funLeft _ _ e₂.symm := LinearMap.ext fun _ ↦ submatrix_mulVec_equiv _ _ _ _ #align matrix.mul_vec_lin_submatrix Matrix.mulVecLin_submatrix /-- A variant of `Matrix.mulVecLin_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.mulVecLin_reindex [Fintype n] [Fintype l] (e₁ : k ≃ m) (e₂ : l ≃ n) (M : Matrix k l R) : (reindex e₁ e₂ M).mulVecLin = ↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ M.mulVecLin ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) := Matrix.mulVecLin_submatrix _ _ _ #align matrix.mul_vec_lin_reindex Matrix.mulVecLin_reindex variable [Fintype n] @[simp] theorem Matrix.mulVecLin_one [DecidableEq n] : Matrix.mulVecLin (1 : Matrix n n R) = LinearMap.id := by ext; simp [Matrix.one_apply, Pi.single_apply] #align matrix.mul_vec_lin_one Matrix.mulVecLin_one @[simp] theorem Matrix.mulVecLin_mul [Fintype m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.mulVecLin (M * N) = (Matrix.mulVecLin M).comp (Matrix.mulVecLin N) := LinearMap.ext fun _ ↦ (mulVec_mulVec _ _ _).symm #align matrix.mul_vec_lin_mul Matrix.mulVecLin_mul theorem Matrix.ker_mulVecLin_eq_bot_iff {M : Matrix m n R} : (LinearMap.ker M.mulVecLin) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := by simp only [Submodule.eq_bot_iff, LinearMap.mem_ker, Matrix.mulVecLin_apply] #align matrix.ker_mul_vec_lin_eq_bot_iff Matrix.ker_mulVecLin_eq_bot_iff theorem Matrix.mulVec_stdBasis [DecidableEq n] (M : Matrix m n R) (i j) : (M *ᵥ LinearMap.stdBasis R (fun _ ↦ R) j 1) i = M i j := (congr_fun (Matrix.mulVec_single _ _ (1 : R)) i).trans <| mul_one _ #align matrix.mul_vec_std_basis Matrix.mulVec_stdBasis @[simp] theorem Matrix.mulVec_stdBasis_apply [DecidableEq n] (M : Matrix m n R) (j) : M *ᵥ LinearMap.stdBasis R (fun _ ↦ R) j 1 = Mᵀ j := funext fun i ↦ Matrix.mulVec_stdBasis M i j #align matrix.mul_vec_std_basis_apply Matrix.mulVec_stdBasis_apply theorem Matrix.range_mulVecLin (M : Matrix m n R) : LinearMap.range M.mulVecLin = span R (range Mᵀ) := by rw [← vecMulLinear_transpose, range_vecMulLinear] #align matrix.range_mul_vec_lin Matrix.range_mulVecLin theorem Matrix.mulVec_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} : Function.Injective M.mulVec ↔ LinearIndependent R (fun i ↦ Mᵀ i) := by change Function.Injective (fun x ↦ _) ↔ _ simp_rw [← M.vecMul_transpose, vecMul_injective_iff] end mulVec section ToMatrix' variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} [DecidableEq n] [Fintype n] /-- Linear maps `(n → R) →ₗ[R] (m → R)` are linearly equivalent to `Matrix m n R`. -/ def LinearMap.toMatrix' : ((n → R) →ₗ[R] m → R) ≃ₗ[R] Matrix m n R where toFun f := of fun i j ↦ f (stdBasis R (fun _ ↦ R) j 1) i invFun := Matrix.mulVecLin right_inv M := by ext i j simp only [Matrix.mulVec_stdBasis, Matrix.mulVecLin_apply, of_apply] left_inv f := by apply (Pi.basisFun R n).ext intro j; ext i simp only [Pi.basisFun_apply, Matrix.mulVec_stdBasis, Matrix.mulVecLin_apply, of_apply] map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, of_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, of_apply, Matrix.smul_apply] #align linear_map.to_matrix' LinearMap.toMatrix' /-- A `Matrix m n R` is linearly equivalent to a linear map `(n → R) →ₗ[R] (m → R)`. Note that the forward-direction does not require `DecidableEq` and is `Matrix.vecMulLin`. -/ def Matrix.toLin' : Matrix m n R ≃ₗ[R] (n → R) →ₗ[R] m → R := LinearMap.toMatrix'.symm #align matrix.to_lin' Matrix.toLin' theorem Matrix.toLin'_apply' (M : Matrix m n R) : Matrix.toLin' M = M.mulVecLin := rfl #align matrix.to_lin'_apply' Matrix.toLin'_apply' @[simp] theorem LinearMap.toMatrix'_symm : (LinearMap.toMatrix'.symm : Matrix m n R ≃ₗ[R] _) = Matrix.toLin' := rfl #align linear_map.to_matrix'_symm LinearMap.toMatrix'_symm @[simp] theorem Matrix.toLin'_symm : (Matrix.toLin'.symm : ((n → R) →ₗ[R] m → R) ≃ₗ[R] _) = LinearMap.toMatrix' := rfl #align matrix.to_lin'_symm Matrix.toLin'_symm @[simp] theorem LinearMap.toMatrix'_toLin' (M : Matrix m n R) : LinearMap.toMatrix' (Matrix.toLin' M) = M := LinearMap.toMatrix'.apply_symm_apply M #align linear_map.to_matrix'_to_lin' LinearMap.toMatrix'_toLin' @[simp] theorem Matrix.toLin'_toMatrix' (f : (n → R) →ₗ[R] m → R) : Matrix.toLin' (LinearMap.toMatrix' f) = f := Matrix.toLin'.apply_symm_apply f #align matrix.to_lin'_to_matrix' Matrix.toLin'_toMatrix' @[simp] theorem LinearMap.toMatrix'_apply (f : (n → R) →ₗ[R] m → R) (i j) : LinearMap.toMatrix' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp only [LinearMap.toMatrix', LinearEquiv.coe_mk, of_apply] refine congr_fun ?_ _ -- Porting note: `congr` didn't do this congr ext j' split_ifs with h · rw [h, stdBasis_same] apply stdBasis_ne _ _ _ _ h #align linear_map.to_matrix'_apply LinearMap.toMatrix'_apply @[simp] theorem Matrix.toLin'_apply (M : Matrix m n R) (v : n → R) : Matrix.toLin' M v = M *ᵥ v := rfl #align matrix.to_lin'_apply Matrix.toLin'_apply @[simp] theorem Matrix.toLin'_one : Matrix.toLin' (1 : Matrix n n R) = LinearMap.id := Matrix.mulVecLin_one #align matrix.to_lin'_one Matrix.toLin'_one @[simp] theorem LinearMap.toMatrix'_id : LinearMap.toMatrix' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := by ext rw [Matrix.one_apply, LinearMap.toMatrix'_apply, id_apply] #align linear_map.to_matrix'_id LinearMap.toMatrix'_id @[simp] theorem LinearMap.toMatrix'_one : LinearMap.toMatrix' (1 : (n → R) →ₗ[R] n → R) = 1 := LinearMap.toMatrix'_id @[simp] theorem Matrix.toLin'_mul [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLin' (M * N) = (Matrix.toLin' M).comp (Matrix.toLin' N) := Matrix.mulVecLin_mul _ _ #align matrix.to_lin'_mul Matrix.toLin'_mul @[simp] theorem Matrix.toLin'_submatrix [Fintype l] [DecidableEq l] (f₁ : m → k) (e₂ : n ≃ l) (M : Matrix k l R) : Matrix.toLin' (M.submatrix f₁ e₂) = funLeft R R f₁ ∘ₗ (Matrix.toLin' M) ∘ₗ funLeft _ _ e₂.symm := Matrix.mulVecLin_submatrix _ _ _ #align matrix.to_lin'_submatrix Matrix.toLin'_submatrix /-- A variant of `Matrix.toLin'_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.toLin'_reindex [Fintype l] [DecidableEq l] (e₁ : k ≃ m) (e₂ : l ≃ n) (M : Matrix k l R) : Matrix.toLin' (reindex e₁ e₂ M) = ↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ (Matrix.toLin' M) ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) := Matrix.mulVecLin_reindex _ _ _ #align matrix.to_lin'_reindex Matrix.toLin'_reindex /-- Shortcut lemma for `Matrix.toLin'_mul` and `LinearMap.comp_apply` -/ theorem Matrix.toLin'_mul_apply [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLin' (M * N) x = Matrix.toLin' M (Matrix.toLin' N x) := by rw [Matrix.toLin'_mul, LinearMap.comp_apply] #align matrix.to_lin'_mul_apply Matrix.toLin'_mul_apply theorem LinearMap.toMatrix'_comp [Fintype l] [DecidableEq l] (f : (n → R) →ₗ[R] m → R) (g : (l → R) →ₗ[R] n → R) : LinearMap.toMatrix' (f.comp g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := by suffices f.comp g = Matrix.toLin' (LinearMap.toMatrix' f * LinearMap.toMatrix' g) by rw [this, LinearMap.toMatrix'_toLin'] rw [Matrix.toLin'_mul, Matrix.toLin'_toMatrix', Matrix.toLin'_toMatrix'] #align linear_map.to_matrix'_comp LinearMap.toMatrix'_comp theorem LinearMap.toMatrix'_mul [Fintype m] [DecidableEq m] (f g : (m → R) →ₗ[R] m → R) : LinearMap.toMatrix' (f * g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := LinearMap.toMatrix'_comp f g #align linear_map.to_matrix'_mul LinearMap.toMatrix'_mul @[simp] theorem LinearMap.toMatrix'_algebraMap (x : R) : LinearMap.toMatrix' (algebraMap R (Module.End R (n → R)) x) = scalar n x := by simp [Module.algebraMap_end_eq_smul_id, smul_eq_diagonal_mul] #align linear_map.to_matrix'_algebra_map LinearMap.toMatrix'_algebraMap theorem Matrix.ker_toLin'_eq_bot_iff {M : Matrix n n R} : LinearMap.ker (Matrix.toLin' M) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := Matrix.ker_mulVecLin_eq_bot_iff #align matrix.ker_to_lin'_eq_bot_iff Matrix.ker_toLin'_eq_bot_iff theorem Matrix.range_toLin' (M : Matrix m n R) : LinearMap.range (Matrix.toLin' M) = span R (range Mᵀ) := Matrix.range_mulVecLin _ #align matrix.range_to_lin' Matrix.range_toLin' /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `m → A` and `n → A` corresponding to `M.mulVec` and `M'.mulVec`. -/ @[simps] def Matrix.toLin'OfInv [Fintype m] [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (m → R) ≃ₗ[R] n → R := { Matrix.toLin' M' with toFun := Matrix.toLin' M' invFun := Matrix.toLin' M left_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hMM', Matrix.toLin'_one, id_apply] right_inv := fun x ↦ by simp only rw [← Matrix.toLin'_mul_apply, hM'M, Matrix.toLin'_one, id_apply] } #align matrix.to_lin'_of_inv Matrix.toLin'OfInv /-- Linear maps `(n → R) →ₗ[R] (n → R)` are algebra equivalent to `Matrix n n R`. -/ def LinearMap.toMatrixAlgEquiv' : ((n → R) →ₗ[R] n → R) ≃ₐ[R] Matrix n n R := AlgEquiv.ofLinearEquiv LinearMap.toMatrix' LinearMap.toMatrix'_one LinearMap.toMatrix'_mul #align linear_map.to_matrix_alg_equiv' LinearMap.toMatrixAlgEquiv' /-- A `Matrix n n R` is algebra equivalent to a linear map `(n → R) →ₗ[R] (n → R)`. -/ def Matrix.toLinAlgEquiv' : Matrix n n R ≃ₐ[R] (n → R) →ₗ[R] n → R := LinearMap.toMatrixAlgEquiv'.symm #align matrix.to_lin_alg_equiv' Matrix.toLinAlgEquiv' @[simp] theorem LinearMap.toMatrixAlgEquiv'_symm : (LinearMap.toMatrixAlgEquiv'.symm : Matrix n n R ≃ₐ[R] _) = Matrix.toLinAlgEquiv' := rfl #align linear_map.to_matrix_alg_equiv'_symm LinearMap.toMatrixAlgEquiv'_symm @[simp] theorem Matrix.toLinAlgEquiv'_symm : (Matrix.toLinAlgEquiv'.symm : ((n → R) →ₗ[R] n → R) ≃ₐ[R] _) = LinearMap.toMatrixAlgEquiv' := rfl #align matrix.to_lin_alg_equiv'_symm Matrix.toLinAlgEquiv'_symm @[simp] theorem LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' (M : Matrix n n R) : LinearMap.toMatrixAlgEquiv' (Matrix.toLinAlgEquiv' M) = M := LinearMap.toMatrixAlgEquiv'.apply_symm_apply M #align linear_map.to_matrix_alg_equiv'_to_lin_alg_equiv' LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' @[simp] theorem Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' (f : (n → R) →ₗ[R] n → R) : Matrix.toLinAlgEquiv' (LinearMap.toMatrixAlgEquiv' f) = f := Matrix.toLinAlgEquiv'.apply_symm_apply f #align matrix.to_lin_alg_equiv'_to_matrix_alg_equiv' Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' @[simp] theorem LinearMap.toMatrixAlgEquiv'_apply (f : (n → R) →ₗ[R] n → R) (i j) : LinearMap.toMatrixAlgEquiv' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp [LinearMap.toMatrixAlgEquiv'] #align linear_map.to_matrix_alg_equiv'_apply LinearMap.toMatrixAlgEquiv'_apply @[simp] theorem Matrix.toLinAlgEquiv'_apply (M : Matrix n n R) (v : n → R) : Matrix.toLinAlgEquiv' M v = M *ᵥ v := rfl #align matrix.to_lin_alg_equiv'_apply Matrix.toLinAlgEquiv'_apply -- Porting note: the simpNF linter rejects this, as `simp` already simplifies the lhs -- to `(1 : (n → R) →ₗ[R] n → R)`. -- @[simp] theorem Matrix.toLinAlgEquiv'_one : Matrix.toLinAlgEquiv' (1 : Matrix n n R) = LinearMap.id := Matrix.toLin'_one #align matrix.to_lin_alg_equiv'_one Matrix.toLinAlgEquiv'_one @[simp] theorem LinearMap.toMatrixAlgEquiv'_id : LinearMap.toMatrixAlgEquiv' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := LinearMap.toMatrix'_id #align linear_map.to_matrix_alg_equiv'_id LinearMap.toMatrixAlgEquiv'_id #align matrix.to_lin_alg_equiv'_mul map_mulₓ theorem LinearMap.toMatrixAlgEquiv'_comp (f g : (n → R) →ₗ[R] n → R) : LinearMap.toMatrixAlgEquiv' (f.comp g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrix'_comp _ _ #align linear_map.to_matrix_alg_equiv'_comp LinearMap.toMatrixAlgEquiv'_comp theorem LinearMap.toMatrixAlgEquiv'_mul (f g : (n → R) →ₗ[R] n → R) : LinearMap.toMatrixAlgEquiv' (f * g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrixAlgEquiv'_comp f g #align linear_map.to_matrix_alg_equiv'_mul LinearMap.toMatrixAlgEquiv'_mul end ToMatrix' section ToMatrix section Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Finite m] [DecidableEq n] variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂) /-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear equivalence between linear maps `M₁ →ₗ M₂` and matrices over `R` indexed by the bases. -/ def LinearMap.toMatrix : (M₁ →ₗ[R] M₂) ≃ₗ[R] Matrix m n R := LinearEquiv.trans (LinearEquiv.arrowCongr v₁.equivFun v₂.equivFun) LinearMap.toMatrix' #align linear_map.to_matrix LinearMap.toMatrix /-- `LinearMap.toMatrix'` is a particular case of `LinearMap.toMatrix`, for the standard basis `Pi.basisFun R n`. -/ theorem LinearMap.toMatrix_eq_toMatrix' : LinearMap.toMatrix (Pi.basisFun R n) (Pi.basisFun R n) = LinearMap.toMatrix' := rfl #align linear_map.to_matrix_eq_to_matrix' LinearMap.toMatrix_eq_toMatrix' /-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear equivalence between matrices over `R` indexed by the bases and linear maps `M₁ →ₗ M₂`. -/ def Matrix.toLin : Matrix m n R ≃ₗ[R] M₁ →ₗ[R] M₂ := (LinearMap.toMatrix v₁ v₂).symm #align matrix.to_lin Matrix.toLin /-- `Matrix.toLin'` is a particular case of `Matrix.toLin`, for the standard basis `Pi.basisFun R n`. -/ theorem Matrix.toLin_eq_toLin' : Matrix.toLin (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLin' := rfl #align matrix.to_lin_eq_to_lin' Matrix.toLin_eq_toLin' @[simp] theorem LinearMap.toMatrix_symm : (LinearMap.toMatrix v₁ v₂).symm = Matrix.toLin v₁ v₂ := rfl #align linear_map.to_matrix_symm LinearMap.toMatrix_symm @[simp] theorem Matrix.toLin_symm : (Matrix.toLin v₁ v₂).symm = LinearMap.toMatrix v₁ v₂ := rfl #align matrix.to_lin_symm Matrix.toLin_symm @[simp] theorem Matrix.toLin_toMatrix (f : M₁ →ₗ[R] M₂) : Matrix.toLin v₁ v₂ (LinearMap.toMatrix v₁ v₂ f) = f := by rw [← Matrix.toLin_symm, LinearEquiv.apply_symm_apply] #align matrix.to_lin_to_matrix Matrix.toLin_toMatrix @[simp] theorem LinearMap.toMatrix_toLin (M : Matrix m n R) : LinearMap.toMatrix v₁ v₂ (Matrix.toLin v₁ v₂ M) = M := by rw [← Matrix.toLin_symm, LinearEquiv.symm_apply_apply] #align linear_map.to_matrix_to_lin LinearMap.toMatrix_toLin theorem LinearMap.toMatrix_apply (f : M₁ →ₗ[R] M₂) (i : m) (j : n) : LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := by rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearMap.toMatrix'_apply, LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Finset.sum_eq_single j, if_pos rfl, one_smul, Basis.equivFun_apply] · intro j' _ hj' rw [if_neg hj', zero_smul] · intro hj have := Finset.mem_univ j contradiction #align linear_map.to_matrix_apply LinearMap.toMatrix_apply theorem LinearMap.toMatrix_transpose_apply (f : M₁ →ₗ[R] M₂) (j : n) : (LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) := funext fun i ↦ f.toMatrix_apply _ _ i j #align linear_map.to_matrix_transpose_apply LinearMap.toMatrix_transpose_apply theorem LinearMap.toMatrix_apply' (f : M₁ →ₗ[R] M₂) (i : m) (j : n) : LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := LinearMap.toMatrix_apply v₁ v₂ f i j #align linear_map.to_matrix_apply' LinearMap.toMatrix_apply' theorem LinearMap.toMatrix_transpose_apply' (f : M₁ →ₗ[R] M₂) (j : n) : (LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) := LinearMap.toMatrix_transpose_apply v₁ v₂ f j #align linear_map.to_matrix_transpose_apply' LinearMap.toMatrix_transpose_apply' /-- This will be a special case of `LinearMap.toMatrix_id_eq_basis_toMatrix`. -/ theorem LinearMap.toMatrix_id : LinearMap.toMatrix v₁ v₁ id = 1 := by ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] #align linear_map.to_matrix_id LinearMap.toMatrix_id @[simp] theorem LinearMap.toMatrix_one : LinearMap.toMatrix v₁ v₁ 1 = 1 := LinearMap.toMatrix_id v₁ #align linear_map.to_matrix_one LinearMap.toMatrix_one @[simp] theorem Matrix.toLin_one : Matrix.toLin v₁ v₁ 1 = LinearMap.id := by rw [← LinearMap.toMatrix_id v₁, Matrix.toLin_toMatrix] #align matrix.to_lin_one Matrix.toLin_one theorem LinearMap.toMatrix_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₂) (k : m) (i : n) : LinearMap.toMatrix v₁.reindexRange v₂.reindexRange f ⟨v₂ k, Set.mem_range_self k⟩ ⟨v₁ i, Set.mem_range_self i⟩ = LinearMap.toMatrix v₁ v₂ f k i := by simp_rw [LinearMap.toMatrix_apply, Basis.reindexRange_self, Basis.reindexRange_repr] #align linear_map.to_matrix_reindex_range LinearMap.toMatrix_reindexRange @[simp] theorem LinearMap.toMatrix_algebraMap (x : R) : LinearMap.toMatrix v₁ v₁ (algebraMap R (Module.End R M₁) x) = scalar n x := by simp [Module.algebraMap_end_eq_smul_id, LinearMap.toMatrix_id, smul_eq_diagonal_mul] #align linear_map.to_matrix_algebra_map LinearMap.toMatrix_algebraMap theorem LinearMap.toMatrix_mulVec_repr (f : M₁ →ₗ[R] M₂) (x : M₁) : LinearMap.toMatrix v₁ v₂ f *ᵥ v₁.repr x = v₂.repr (f x) := by ext i rw [← Matrix.toLin'_apply, LinearMap.toMatrix, LinearEquiv.trans_apply, Matrix.toLin'_toMatrix', LinearEquiv.arrowCongr_apply, v₂.equivFun_apply] congr exact v₁.equivFun.symm_apply_apply x #align linear_map.to_matrix_mul_vec_repr LinearMap.toMatrix_mulVec_repr @[simp] theorem LinearMap.toMatrix_basis_equiv [Fintype l] [DecidableEq l] (b : Basis l R M₁) (b' : Basis l R M₂) : LinearMap.toMatrix b' b (b'.equiv b (Equiv.refl l) : M₂ →ₗ[R] M₁) = 1 := by ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] #align linear_map.to_matrix_basis_equiv LinearMap.toMatrix_basis_equiv end Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Fintype m] [DecidableEq n] variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂) theorem Matrix.toLin_apply (M : Matrix m n R) (v : M₁) : Matrix.toLin v₁ v₂ M v = ∑ j, (M *ᵥ v₁.repr v) j • v₂ j := show v₂.equivFun.symm (Matrix.toLin' M (v₁.repr v)) = _ by rw [Matrix.toLin'_apply, v₂.equivFun_symm_apply] #align matrix.to_lin_apply Matrix.toLin_apply @[simp] theorem Matrix.toLin_self (M : Matrix m n R) (i : n) : Matrix.toLin v₁ v₂ M (v₁ i) = ∑ j, M j i • v₂ j := by rw [Matrix.toLin_apply, Finset.sum_congr rfl fun j _hj ↦ ?_] rw [Basis.repr_self, Matrix.mulVec, dotProduct, Finset.sum_eq_single i, Finsupp.single_eq_same, mul_one] · intro i' _ i'_ne rw [Finsupp.single_eq_of_ne i'_ne.symm, mul_zero] · intros have := Finset.mem_univ i contradiction #align matrix.to_lin_self Matrix.toLin_self variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (v₃ : Basis l R M₃) theorem LinearMap.toMatrix_comp [Finite l] [DecidableEq m] (f : M₂ →ₗ[R] M₃) (g : M₁ →ₗ[R] M₂) : LinearMap.toMatrix v₁ v₃ (f.comp g) = LinearMap.toMatrix v₂ v₃ f * LinearMap.toMatrix v₁ v₂ g := by simp_rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearEquiv.arrowCongr_comp _ v₂.equivFun, LinearMap.toMatrix'_comp] #align linear_map.to_matrix_comp LinearMap.toMatrix_comp theorem LinearMap.toMatrix_mul (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrix v₁ v₁ (f * g) = LinearMap.toMatrix v₁ v₁ f * LinearMap.toMatrix v₁ v₁ g := by rw [LinearMap.mul_eq_comp, LinearMap.toMatrix_comp v₁ v₁ v₁ f g] #align linear_map.to_matrix_mul LinearMap.toMatrix_mul lemma LinearMap.toMatrix_pow (f : M₁ →ₗ[R] M₁) (k : ℕ) : (toMatrix v₁ v₁ f) ^ k = toMatrix v₁ v₁ (f ^ k) := by induction k with | zero => simp | succ k ih => rw [pow_succ, pow_succ, ih, ← toMatrix_mul] theorem Matrix.toLin_mul [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) : Matrix.toLin v₁ v₃ (A * B) = (Matrix.toLin v₂ v₃ A).comp (Matrix.toLin v₁ v₂ B) := by apply (LinearMap.toMatrix v₁ v₃).injective haveI : DecidableEq l := fun _ _ ↦ Classical.propDecidable _ rw [LinearMap.toMatrix_comp v₁ v₂ v₃] repeat' rw [LinearMap.toMatrix_toLin] #align matrix.to_lin_mul Matrix.toLin_mul /-- Shortcut lemma for `Matrix.toLin_mul` and `LinearMap.comp_apply`. -/ theorem Matrix.toLin_mul_apply [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) (x) : Matrix.toLin v₁ v₃ (A * B) x = (Matrix.toLin v₂ v₃ A) (Matrix.toLin v₁ v₂ B x) := by rw [Matrix.toLin_mul v₁ v₂, LinearMap.comp_apply] #align matrix.to_lin_mul_apply Matrix.toLin_mul_apply /-- If `M` and `M` are each other's inverse matrices, `Matrix.toLin M` and `Matrix.toLin M'` form a linear equivalence. -/ @[simps] def Matrix.toLinOfInv [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : M₁ ≃ₗ[R] M₂ := { Matrix.toLin v₁ v₂ M with toFun := Matrix.toLin v₁ v₂ M invFun := Matrix.toLin v₂ v₁ M' left_inv := fun x ↦ by rw [← Matrix.toLin_mul_apply, hM'M, Matrix.toLin_one, id_apply] right_inv := fun x ↦ by simp only rw [← Matrix.toLin_mul_apply, hMM', Matrix.toLin_one, id_apply] } #align matrix.to_lin_of_inv Matrix.toLinOfInv /-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra equivalence between linear maps `M₁ →ₗ M₁` and square matrices over `R` indexed by the basis. -/ def LinearMap.toMatrixAlgEquiv : (M₁ →ₗ[R] M₁) ≃ₐ[R] Matrix n n R := AlgEquiv.ofLinearEquiv (LinearMap.toMatrix v₁ v₁) (LinearMap.toMatrix_one v₁) (LinearMap.toMatrix_mul v₁) #align linear_map.to_matrix_alg_equiv LinearMap.toMatrixAlgEquiv /-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra equivalence between square matrices over `R` indexed by the basis and linear maps `M₁ →ₗ M₁`. -/ def Matrix.toLinAlgEquiv : Matrix n n R ≃ₐ[R] M₁ →ₗ[R] M₁ := (LinearMap.toMatrixAlgEquiv v₁).symm #align matrix.to_lin_alg_equiv Matrix.toLinAlgEquiv @[simp] theorem LinearMap.toMatrixAlgEquiv_symm : (LinearMap.toMatrixAlgEquiv v₁).symm = Matrix.toLinAlgEquiv v₁ := rfl #align linear_map.to_matrix_alg_equiv_symm LinearMap.toMatrixAlgEquiv_symm @[simp] theorem Matrix.toLinAlgEquiv_symm : (Matrix.toLinAlgEquiv v₁).symm = LinearMap.toMatrixAlgEquiv v₁ := rfl #align matrix.to_lin_alg_equiv_symm Matrix.toLinAlgEquiv_symm @[simp] theorem Matrix.toLinAlgEquiv_toMatrixAlgEquiv (f : M₁ →ₗ[R] M₁) : Matrix.toLinAlgEquiv v₁ (LinearMap.toMatrixAlgEquiv v₁ f) = f := by rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.apply_symm_apply] #align matrix.to_lin_alg_equiv_to_matrix_alg_equiv Matrix.toLinAlgEquiv_toMatrixAlgEquiv @[simp] theorem LinearMap.toMatrixAlgEquiv_toLinAlgEquiv (M : Matrix n n R) : LinearMap.toMatrixAlgEquiv v₁ (Matrix.toLinAlgEquiv v₁ M) = M := by rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.symm_apply_apply] #align linear_map.to_matrix_alg_equiv_to_lin_alg_equiv LinearMap.toMatrixAlgEquiv_toLinAlgEquiv theorem LinearMap.toMatrixAlgEquiv_apply (f : M₁ →ₗ[R] M₁) (i j : n) : LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i := by simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_apply] #align linear_map.to_matrix_alg_equiv_apply LinearMap.toMatrixAlgEquiv_apply theorem LinearMap.toMatrixAlgEquiv_transpose_apply (f : M₁ →ₗ[R] M₁) (j : n) : (LinearMap.toMatrixAlgEquiv v₁ f)ᵀ j = v₁.repr (f (v₁ j)) := funext fun i ↦ f.toMatrix_apply _ _ i j #align linear_map.to_matrix_alg_equiv_transpose_apply LinearMap.toMatrixAlgEquiv_transpose_apply theorem LinearMap.toMatrixAlgEquiv_apply' (f : M₁ →ₗ[R] M₁) (i j : n) : LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i := LinearMap.toMatrixAlgEquiv_apply v₁ f i j #align linear_map.to_matrix_alg_equiv_apply' LinearMap.toMatrixAlgEquiv_apply' theorem LinearMap.toMatrixAlgEquiv_transpose_apply' (f : M₁ →ₗ[R] M₁) (j : n) : (LinearMap.toMatrixAlgEquiv v₁ f)ᵀ j = v₁.repr (f (v₁ j)) := LinearMap.toMatrixAlgEquiv_transpose_apply v₁ f j #align linear_map.to_matrix_alg_equiv_transpose_apply' LinearMap.toMatrixAlgEquiv_transpose_apply' theorem Matrix.toLinAlgEquiv_apply (M : Matrix n n R) (v : M₁) : Matrix.toLinAlgEquiv v₁ M v = ∑ j, (M *ᵥ v₁.repr v) j • v₁ j := show v₁.equivFun.symm (Matrix.toLinAlgEquiv' M (v₁.repr v)) = _ by rw [Matrix.toLinAlgEquiv'_apply, v₁.equivFun_symm_apply] #align matrix.to_lin_alg_equiv_apply Matrix.toLinAlgEquiv_apply @[simp] theorem Matrix.toLinAlgEquiv_self (M : Matrix n n R) (i : n) : Matrix.toLinAlgEquiv v₁ M (v₁ i) = ∑ j, M j i • v₁ j := Matrix.toLin_self _ _ _ _ #align matrix.to_lin_alg_equiv_self Matrix.toLinAlgEquiv_self theorem LinearMap.toMatrixAlgEquiv_id : LinearMap.toMatrixAlgEquiv v₁ id = 1 := by simp_rw [LinearMap.toMatrixAlgEquiv, AlgEquiv.ofLinearEquiv_apply, LinearMap.toMatrix_id] #align linear_map.to_matrix_alg_equiv_id LinearMap.toMatrixAlgEquiv_id -- Porting note: the simpNF linter rejects this, as `simp` already simplifies the lhs -- to `(1 : M₁ →ₗ[R] M₁)`. -- @[simp] theorem Matrix.toLinAlgEquiv_one : Matrix.toLinAlgEquiv v₁ 1 = LinearMap.id := by rw [← LinearMap.toMatrixAlgEquiv_id v₁, Matrix.toLinAlgEquiv_toMatrixAlgEquiv] #align matrix.to_lin_alg_equiv_one Matrix.toLinAlgEquiv_one theorem LinearMap.toMatrixAlgEquiv_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₁) (k i : n) : LinearMap.toMatrixAlgEquiv v₁.reindexRange f ⟨v₁ k, Set.mem_range_self k⟩ ⟨v₁ i, Set.mem_range_self i⟩ = LinearMap.toMatrixAlgEquiv v₁ f k i := by simp_rw [LinearMap.toMatrixAlgEquiv_apply, Basis.reindexRange_self, Basis.reindexRange_repr] #align linear_map.to_matrix_alg_equiv_reindex_range LinearMap.toMatrixAlgEquiv_reindexRange theorem LinearMap.toMatrixAlgEquiv_comp (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrixAlgEquiv v₁ (f.comp g) = LinearMap.toMatrixAlgEquiv v₁ f * LinearMap.toMatrixAlgEquiv v₁ g := by simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_comp v₁ v₁ v₁ f g] #align linear_map.to_matrix_alg_equiv_comp LinearMap.toMatrixAlgEquiv_comp theorem LinearMap.toMatrixAlgEquiv_mul (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrixAlgEquiv v₁ (f * g) = LinearMap.toMatrixAlgEquiv v₁ f * LinearMap.toMatrixAlgEquiv v₁ g := by rw [LinearMap.mul_eq_comp, LinearMap.toMatrixAlgEquiv_comp v₁ f g] #align linear_map.to_matrix_alg_equiv_mul LinearMap.toMatrixAlgEquiv_mul theorem Matrix.toLinAlgEquiv_mul (A B : Matrix n n R) : Matrix.toLinAlgEquiv v₁ (A * B) = (Matrix.toLinAlgEquiv v₁ A).comp (Matrix.toLinAlgEquiv v₁ B) := by convert Matrix.toLin_mul v₁ v₁ v₁ A B #align matrix.to_lin_alg_equiv_mul Matrix.toLinAlgEquiv_mul @[simp] theorem Matrix.toLin_finTwoProd_apply (a b c d : R) (x : R × R) : Matrix.toLin (Basis.finTwoProd R) (Basis.finTwoProd R) !![a, b; c, d] x = (a * x.fst + b * x.snd, c * x.fst + d * x.snd) := by simp [Matrix.toLin_apply, Matrix.mulVec, Matrix.dotProduct] #align matrix.to_lin_fin_two_prod_apply Matrix.toLin_finTwoProd_apply theorem Matrix.toLin_finTwoProd (a b c d : R) : Matrix.toLin (Basis.finTwoProd R) (Basis.finTwoProd R) !![a, b; c, d] = (a • LinearMap.fst R R R + b • LinearMap.snd R R R).prod (c • LinearMap.fst R R R + d • LinearMap.snd R R R) := LinearMap.ext <| Matrix.toLin_finTwoProd_apply _ _ _ _ #align matrix.to_lin_fin_two_prod Matrix.toLin_finTwoProd @[simp] theorem toMatrix_distrib_mul_action_toLinearMap (x : R) : LinearMap.toMatrix v₁ v₁ (DistribMulAction.toLinearMap R M₁ x) = Matrix.diagonal fun _ ↦ x := by ext rw [LinearMap.toMatrix_apply, DistribMulAction.toLinearMap_apply, LinearEquiv.map_smul, Basis.repr_self, Finsupp.smul_single_one, Finsupp.single_eq_pi_single, Matrix.diagonal_apply, Pi.single_apply] #align to_matrix_distrib_mul_action_to_linear_map toMatrix_distrib_mul_action_toLinearMap lemma LinearMap.toMatrix_prodMap [DecidableEq n] [DecidableEq m] [DecidableEq (n ⊕ m)] (φ₁ : Module.End R M₁) (φ₂ : Module.End R M₂) : toMatrix (v₁.prod v₂) (v₁.prod v₂) (φ₁.prodMap φ₂) = Matrix.fromBlocks (toMatrix v₁ v₁ φ₁) 0 0 (toMatrix v₂ v₂ φ₂) := by ext (i|i) (j|j) <;> simp [toMatrix] end ToMatrix namespace Algebra section Lmul variable {R S : Type*} [CommRing R] [Ring S] [Algebra R S] variable {m : Type*} [Fintype m] [DecidableEq m] (b : Basis m R S) theorem toMatrix_lmul' (x : S) (i j) : LinearMap.toMatrix b b (lmul R S x) i j = b.repr (x * b j) i := by simp only [LinearMap.toMatrix_apply', coe_lmul_eq_mul, LinearMap.mul_apply'] #align algebra.to_matrix_lmul' Algebra.toMatrix_lmul' @[simp] theorem toMatrix_lsmul (x : R) : LinearMap.toMatrix b b (Algebra.lsmul R R S x) = Matrix.diagonal fun _ ↦ x := toMatrix_distrib_mul_action_toLinearMap b x #align algebra.to_matrix_lsmul Algebra.toMatrix_lsmul /-- `leftMulMatrix b x` is the matrix corresponding to the linear map `fun y ↦ x * y`. `leftMulMatrix_eq_repr_mul` gives a formula for the entries of `leftMulMatrix`. This definition is useful for doing (more) explicit computations with `LinearMap.mulLeft`, such as the trace form or norm map for algebras. -/ noncomputable def leftMulMatrix : S →ₐ[R] Matrix m m R where toFun x := LinearMap.toMatrix b b (Algebra.lmul R S x) map_zero' := by dsimp only -- porting node: needed due to new-style structures rw [AlgHom.map_zero, LinearEquiv.map_zero] map_one' := by dsimp only -- porting node: needed due to new-style structures rw [AlgHom.map_one, LinearMap.toMatrix_one] map_add' x y := by dsimp only -- porting node: needed due to new-style structures rw [AlgHom.map_add, LinearEquiv.map_add] map_mul' x y := by dsimp only -- porting node: needed due to new-style structures rw [AlgHom.map_mul, LinearMap.toMatrix_mul] commutes' r := by dsimp only -- porting node: needed due to new-style structures ext rw [lmul_algebraMap, toMatrix_lsmul, algebraMap_eq_diagonal, Pi.algebraMap_def, Algebra.id.map_eq_self] #align algebra.left_mul_matrix Algebra.leftMulMatrix theorem leftMulMatrix_apply (x : S) : leftMulMatrix b x = LinearMap.toMatrix b b (lmul R S x) := rfl #align algebra.left_mul_matrix_apply Algebra.leftMulMatrix_apply theorem leftMulMatrix_eq_repr_mul (x : S) (i j) : leftMulMatrix b x i j = b.repr (x * b j) i := by -- This is defeq to just `toMatrix_lmul' b x i j`, -- but the unfolding goes a lot faster with this explicit `rw`. rw [leftMulMatrix_apply, toMatrix_lmul' b x i j] #align algebra.left_mul_matrix_eq_repr_mul Algebra.leftMulMatrix_eq_repr_mul theorem leftMulMatrix_mulVec_repr (x y : S) : leftMulMatrix b x *ᵥ b.repr y = b.repr (x * y) := (LinearMap.mulLeft R x).toMatrix_mulVec_repr b b y #align algebra.left_mul_matrix_mul_vec_repr Algebra.leftMulMatrix_mulVec_repr @[simp] theorem toMatrix_lmul_eq (x : S) : LinearMap.toMatrix b b (LinearMap.mulLeft R x) = leftMulMatrix b x := rfl #align algebra.to_matrix_lmul_eq Algebra.toMatrix_lmul_eq theorem leftMulMatrix_injective : Function.Injective (leftMulMatrix b) := fun x x' h ↦ calc x = Algebra.lmul R S x 1 := (mul_one x).symm _ = Algebra.lmul R S x' 1 := by rw [(LinearMap.toMatrix b b).injective h] _ = x' := mul_one x' #align algebra.left_mul_matrix_injective Algebra.leftMulMatrix_injective end Lmul section LmulTower variable {R S T : Type*} [CommRing R] [CommRing S] [Ring T] variable [Algebra R S] [Algebra S T] [Algebra R T] [IsScalarTower R S T] variable {m n : Type*} [Fintype m] [Fintype n] [DecidableEq m] [DecidableEq n] variable (b : Basis m R S) (c : Basis n S T) theorem smul_leftMulMatrix (x) (ik jk) : leftMulMatrix (b.smul c) x ik jk = leftMulMatrix b (leftMulMatrix c x ik.2 jk.2) ik.1 jk.1 := by simp only [leftMulMatrix_apply, LinearMap.toMatrix_apply, mul_comm, Basis.smul_apply, Basis.smul_repr, Finsupp.smul_apply, id.smul_eq_mul, LinearEquiv.map_smul, mul_smul_comm, coe_lmul_eq_mul, LinearMap.mul_apply'] #align algebra.smul_left_mul_matrix Algebra.smul_leftMulMatrix theorem smul_leftMulMatrix_algebraMap (x : S) : leftMulMatrix (b.smul c) (algebraMap _ _ x) = blockDiagonal fun _ ↦ leftMulMatrix b x := by ext ⟨i, k⟩ ⟨j, k'⟩ rw [smul_leftMulMatrix, AlgHom.commutes, blockDiagonal_apply, algebraMap_matrix_apply] split_ifs with h <;> simp only at h <;> simp [h] #align algebra.smul_left_mul_matrix_algebra_map Algebra.smul_leftMulMatrix_algebraMap theorem smul_leftMulMatrix_algebraMap_eq (x : S) (i j k) : leftMulMatrix (b.smul c) (algebraMap _ _ x) (i, k) (j, k) = leftMulMatrix b x i j := by rw [smul_leftMulMatrix_algebraMap, blockDiagonal_apply_eq] #align algebra.smul_left_mul_matrix_algebra_map_eq Algebra.smul_leftMulMatrix_algebraMap_eq
Mathlib/LinearAlgebra/Matrix/ToLin.lean
979
981
theorem smul_leftMulMatrix_algebraMap_ne (x : S) (i j) {k k'} (h : k ≠ k') : leftMulMatrix (b.smul c) (algebraMap _ _ x) (i, k) (j, k') = 0 := by
rw [smul_leftMulMatrix_algebraMap, blockDiagonal_apply_ne _ _ _ h]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Finset.Sort import Mathlib.Data.Set.Subsingleton #align_import combinatorics.composition from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Compositions A composition of a natural number `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into non-empty blocks of consecutive integers, where the `iⱼ` are the lengths of the blocks. This notion is closely related to that of a partition of `n`, but in a composition of `n` the order of the `iⱼ`s matters. We implement two different structures covering these two viewpoints on compositions. The first one, made of a list of positive integers summing to `n`, is the main one and is called `Composition n`. The second one is useful for combinatorial arguments (for instance to show that the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}` containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost points of each block. The main API is built on `Composition n`, and we provide an equivalence between the two types. ## Main functions * `c : Composition n` is a structure, made of a list of integers which are all positive and add up to `n`. * `composition_card` states that the cardinality of `Composition n` is exactly `2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is nat subtraction). Let `c : Composition n` be a composition of `n`. Then * `c.blocks` is the list of blocks in `c`. * `c.length` is the number of blocks in the composition. * `c.blocks_fun : Fin c.length → ℕ` is the realization of `c.blocks` as a function on `Fin c.length`. This is the main object when using compositions to understand the composition of analytic functions. * `c.sizeUpTo : ℕ → ℕ` is the sum of the size of the blocks up to `i`.; * `c.embedding i : Fin (c.blocks_fun i) → Fin n` is the increasing embedding of the `i`-th block in `Fin n`; * `c.index j`, for `j : Fin n`, is the index of the block containing `j`. * `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`. * `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`. Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition of `n`. * `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the blocks of `c`. * `join_splitWrtComposition` states that splitting a list and then joining it gives back the original list. * `joinSplitWrtComposition_join` states that joining a list of lists, and then splitting it back according to the right composition, gives back the original list of lists. We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`. `c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries` and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not make sense in the edge case `n = 0`, while the previous description works in all cases). The elements of this set (other than `n`) correspond to leftmost points of blocks. Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n` from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that `CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)` (see `compositionAsSet_card` and `composition_card`). ## Implementation details The main motivation for this structure and its API is in the construction of the composition of formal multilinear series, and the proof that the composition of analytic functions is analytic. The representation of a composition as a list is very handy as lists are very flexible and already have a well-developed API. ## Tags Composition, partition ## References <https://en.wikipedia.org/wiki/Composition_(combinatorics)> -/ open List variable {n : ℕ} /-- A composition of `n` is a list of positive integers summing to `n`. -/ @[ext] structure Composition (n : ℕ) where /-- List of positive integers summing to `n`-/ blocks : List ℕ /-- Proof of positivity for `blocks`-/ blocks_pos : ∀ {i}, i ∈ blocks → 0 < i /-- Proof that `blocks` sums to `n`-/ blocks_sum : blocks.sum = n #align composition Composition /-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure `CompositionAsSet n`. -/ @[ext] structure CompositionAsSet (n : ℕ) where /-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}`-/ boundaries : Finset (Fin n.succ) /-- Proof that `0` is a member of `boundaries`-/ zero_mem : (0 : Fin n.succ) ∈ boundaries /-- Last element of the composition-/ getLast_mem : Fin.last n ∈ boundaries #align composition_as_set CompositionAsSet instance {n : ℕ} : Inhabited (CompositionAsSet n) := ⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩ /-! ### Compositions A composition of an integer `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of positive integers. -/ namespace Composition variable (c : Composition n) instance (n : ℕ) : ToString (Composition n) := ⟨fun c => toString c.blocks⟩ /-- The length of a composition, i.e., the number of blocks in the composition. -/ abbrev length : ℕ := c.blocks.length #align composition.length Composition.length theorem blocks_length : c.blocks.length = c.length := rfl #align composition.blocks_length Composition.blocks_length /-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic functions using compositions, this is the main player. -/ def blocksFun : Fin c.length → ℕ := c.blocks.get #align composition.blocks_fun Composition.blocksFun theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks := ofFn_get _ #align composition.of_fn_blocks_fun Composition.ofFn_blocksFun theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn] #align composition.sum_blocks_fun Composition.sum_blocksFun theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks := get_mem _ _ _ #align composition.blocks_fun_mem_blocks Composition.blocksFun_mem_blocks @[simp] theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i := c.blocks_pos h #align composition.one_le_blocks Composition.one_le_blocks @[simp] theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks.get ⟨i, h⟩ := c.one_le_blocks (get_mem (blocks c) i h) #align composition.one_le_blocks' Composition.one_le_blocks' @[simp] theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks.get ⟨i, h⟩ := c.one_le_blocks' h #align composition.blocks_pos' Composition.blocks_pos' theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i := c.one_le_blocks (c.blocksFun_mem_blocks i) #align composition.one_le_blocks_fun Composition.one_le_blocksFun
Mathlib/Combinatorics/Enumerative/Composition.lean
187
189
theorem length_le : c.length ≤ n := by
conv_rhs => rw [← c.blocks_sum] exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Analysis.SpecialFunctions.Bernstein import Mathlib.Topology.Algebra.Algebra #align_import topology.continuous_function.weierstrass from "leanprover-community/mathlib"@"17ef379e997badd73e5eabb4d38f11919ab3c4b3" /-! # The Weierstrass approximation theorem for continuous functions on `[a,b]` We've already proved the Weierstrass approximation theorem in the sense that we've shown that the Bernstein approximations to a continuous function on `[0,1]` converge uniformly. Here we rephrase this more abstractly as `polynomialFunctions_closure_eq_top' : (polynomialFunctions I).topologicalClosure = ⊤` and then, by precomposing with suitable affine functions, `polynomialFunctions_closure_eq_top : (polynomialFunctions (Set.Icc a b)).topologicalClosure = ⊤` -/ open ContinuousMap Filter open scoped unitInterval /-- The special case of the Weierstrass approximation theorem for the interval `[0,1]`. This is just a matter of unravelling definitions and using the Bernstein approximations. -/ theorem polynomialFunctions_closure_eq_top' : (polynomialFunctions I).topologicalClosure = ⊤ := by rw [eq_top_iff] rintro f - refine Filter.Frequently.mem_closure ?_ refine Filter.Tendsto.frequently (bernsteinApproximation_uniform f) ?_ apply frequently_of_forall intro n simp only [SetLike.mem_coe] apply Subalgebra.sum_mem rintro n - apply Subalgebra.smul_mem dsimp [bernstein, polynomialFunctions] simp #align polynomial_functions_closure_eq_top' polynomialFunctions_closure_eq_top' /-- The **Weierstrass Approximation Theorem**: polynomials functions on `[a, b] ⊆ ℝ` are dense in `C([a,b],ℝ)` (While we could deduce this as an application of the Stone-Weierstrass theorem, our proof of that relies on the fact that `abs` is in the closure of polynomials on `[-M, M]`, so we may as well get this done first.) -/ theorem polynomialFunctions_closure_eq_top (a b : ℝ) : (polynomialFunctions (Set.Icc a b)).topologicalClosure = ⊤ := by cases' lt_or_le a b with h h -- (Otherwise it's easy; we'll deal with that later.) · -- We can pullback continuous functions on `[a,b]` to continuous functions on `[0,1]`, -- by precomposing with an affine map. let W : C(Set.Icc a b, ℝ) →ₐ[ℝ] C(I, ℝ) := compRightAlgHom ℝ ℝ (iccHomeoI a b h).symm.toContinuousMap -- This operation is itself a homeomorphism -- (with respect to the norm topologies on continuous functions). let W' : C(Set.Icc a b, ℝ) ≃ₜ C(I, ℝ) := compRightHomeomorph ℝ (iccHomeoI a b h).symm have w : (W : C(Set.Icc a b, ℝ) → C(I, ℝ)) = W' := rfl -- Thus we take the statement of the Weierstrass approximation theorem for `[0,1]`, have p := polynomialFunctions_closure_eq_top' -- and pullback both sides, obtaining an equation between subalgebras of `C([a,b], ℝ)`. apply_fun fun s => s.comap W at p simp only [Algebra.comap_top] at p -- Since the pullback operation is continuous, it commutes with taking `topologicalClosure`, rw [Subalgebra.topologicalClosure_comap_homeomorph _ W W' w] at p -- and precomposing with an affine map takes polynomial functions to polynomial functions. rw [polynomialFunctions.comap_compRightAlgHom_iccHomeoI] at p -- 🎉 exact p · -- Otherwise, `b ≤ a`, and the interval is a subsingleton, have : Subsingleton (Set.Icc a b) := (Set.subsingleton_Icc_of_ge h).coe_sort apply Subsingleton.elim #align polynomial_functions_closure_eq_top polynomialFunctions_closure_eq_top /-- An alternative statement of Weierstrass' theorem. Every real-valued continuous function on `[a,b]` is a uniform limit of polynomials. -/ theorem continuousMap_mem_polynomialFunctions_closure (a b : ℝ) (f : C(Set.Icc a b, ℝ)) : f ∈ (polynomialFunctions (Set.Icc a b)).topologicalClosure := by rw [polynomialFunctions_closure_eq_top _ _] simp #align continuous_map_mem_polynomial_functions_closure continuousMap_mem_polynomialFunctions_closure open scoped Polynomial /-- An alternative statement of Weierstrass' theorem, for those who like their epsilons. Every real-valued continuous function on `[a,b]` is within any `ε > 0` of some polynomial. -/ theorem exists_polynomial_near_continuousMap (a b : ℝ) (f : C(Set.Icc a b, ℝ)) (ε : ℝ) (pos : 0 < ε) : ∃ p : ℝ[X], ‖p.toContinuousMapOn _ - f‖ < ε := by have w := mem_closure_iff_frequently.mp (continuousMap_mem_polynomialFunctions_closure _ _ f) rw [Metric.nhds_basis_ball.frequently_iff] at w obtain ⟨-, H, ⟨m, ⟨-, rfl⟩⟩⟩ := w ε pos rw [Metric.mem_ball, dist_eq_norm] at H exact ⟨m, H⟩ #align exists_polynomial_near_continuous_map exists_polynomial_near_continuousMap /-- Another alternative statement of Weierstrass's theorem, for those who like epsilons, but not bundled continuous functions. Every real-valued function `ℝ → ℝ` which is continuous on `[a,b]` can be approximated to within any `ε > 0` on `[a,b]` by some polynomial. -/
Mathlib/Topology/ContinuousFunction/Weierstrass.lean
114
122
theorem exists_polynomial_near_of_continuousOn (a b : ℝ) (f : ℝ → ℝ) (c : ContinuousOn f (Set.Icc a b)) (ε : ℝ) (pos : 0 < ε) : ∃ p : ℝ[X], ∀ x ∈ Set.Icc a b, |p.eval x - f x| < ε := by
let f' : C(Set.Icc a b, ℝ) := ⟨fun x => f x, continuousOn_iff_continuous_restrict.mp c⟩ obtain ⟨p, b⟩ := exists_polynomial_near_continuousMap a b f' ε pos use p rw [norm_lt_iff _ pos] at b intro x m exact b ⟨x, m⟩
/- Copyright (c) 2022 Floris van Doorn, Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Geometry.Manifold.ContMDiff.Atlas import Mathlib.Geometry.Manifold.VectorBundle.FiberwiseLinear import Mathlib.Topology.VectorBundle.Constructions #align_import geometry.manifold.vector_bundle.basic from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833" /-! # Smooth vector bundles This file defines smooth vector bundles over a smooth manifold. Let `E` be a topological vector bundle, with model fiber `F` and base space `B`. We consider `E` as carrying a charted space structure given by its trivializations -- these are charts to `B × F`. Then, by "composition", if `B` is itself a charted space over `H` (e.g. a smooth manifold), then `E` is also a charted space over `H × F`. Now, we define `SmoothVectorBundle` as the `Prop` of having smooth transition functions. Recall the structure groupoid `smoothFiberwiseLinear` on `B × F` consisting of smooth, fiberwise linear partial homeomorphisms. We show that our definition of "smooth vector bundle" implies `HasGroupoid` for this groupoid, and show (by a "composition" of `HasGroupoid` instances) that this means that a smooth vector bundle is a smooth manifold. Since `SmoothVectorBundle` is a mixin, it should be easy to make variants and for many such variants to coexist -- vector bundles can be smooth vector bundles over several different base fields, they can also be C^k vector bundles, etc. ## Main definitions and constructions * `FiberBundle.chartedSpace`: A fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `B × F`. * `FiberBundle.chartedSpace'`: Let `B` be a charted space modelled on `HB`. Then a fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `HB.prod F`. * `SmoothVectorBundle`: Mixin class stating that a (topological) `VectorBundle` is smooth, in the sense of having smooth transition functions. * `SmoothFiberwiseLinear.hasGroupoid`: For a smooth vector bundle `E` over `B` with fiber modelled on `F`, the change-of-co-ordinates between two trivializations `e`, `e'` for `E`, considered as charts to `B × F`, is smooth and fiberwise linear, in the sense of belonging to the structure groupoid `smoothFiberwiseLinear`. * `Bundle.TotalSpace.smoothManifoldWithCorners`: A smooth vector bundle is naturally a smooth manifold. * `VectorBundleCore.smoothVectorBundle`: If a (topological) `VectorBundleCore` is smooth, in the sense of having smooth transition functions (cf. `VectorBundleCore.IsSmooth`), then the vector bundle constructed from it is a smooth vector bundle. * `VectorPrebundle.smoothVectorBundle`: If a `VectorPrebundle` is smooth, in the sense of having smooth transition functions (cf. `VectorPrebundle.IsSmooth`), then the vector bundle constructed from it is a smooth vector bundle. * `Bundle.Prod.smoothVectorBundle`: The direct sum of two smooth vector bundles is a smooth vector bundle. -/ assert_not_exists mfderiv open Bundle Set PartialHomeomorph open Function (id_def) open Filter open scoped Manifold Bundle Topology variable {𝕜 B B' F M : Type*} {E : B → Type*} /-! ### Charted space structure on a fiber bundle -/ section variable [TopologicalSpace F] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] {HB : Type*} [TopologicalSpace HB] [TopologicalSpace B] [ChartedSpace HB B] [FiberBundle F E] /-- A fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `B × F`. -/ instance FiberBundle.chartedSpace' : ChartedSpace (B × F) (TotalSpace F E) where atlas := (fun e : Trivialization F (π F E) => e.toPartialHomeomorph) '' trivializationAtlas F E chartAt x := (trivializationAt F E x.proj).toPartialHomeomorph mem_chart_source x := (trivializationAt F E x.proj).mem_source.mpr (mem_baseSet_trivializationAt F E x.proj) chart_mem_atlas _ := mem_image_of_mem _ (trivialization_mem_atlas F E _) #align fiber_bundle.charted_space FiberBundle.chartedSpace' theorem FiberBundle.chartedSpace'_chartAt (x : TotalSpace F E) : chartAt (B × F) x = (trivializationAt F E x.proj).toPartialHomeomorph := rfl /- Porting note: In Lean 3, the next instance was inside a section with locally reducible `ModelProd` and it used `ModelProd B F` as the intermediate space. Using `B × F` in the middle gives the same instance. -/ --attribute [local reducible] ModelProd /-- Let `B` be a charted space modelled on `HB`. Then a fiber bundle `E` over a base `B` with model fiber `F` is naturally a charted space modelled on `HB.prod F`. -/ instance FiberBundle.chartedSpace : ChartedSpace (ModelProd HB F) (TotalSpace F E) := ChartedSpace.comp _ (B × F) _ #align fiber_bundle.charted_space' FiberBundle.chartedSpace theorem FiberBundle.chartedSpace_chartAt (x : TotalSpace F E) : chartAt (ModelProd HB F) x = (trivializationAt F E x.proj).toPartialHomeomorph ≫ₕ (chartAt HB x.proj).prod (PartialHomeomorph.refl F) := by dsimp only [chartAt_comp, prodChartedSpace_chartAt, FiberBundle.chartedSpace'_chartAt, chartAt_self_eq] rw [Trivialization.coe_coe, Trivialization.coe_fst' _ (mem_baseSet_trivializationAt F E x.proj)] #align fiber_bundle.charted_space_chart_at FiberBundle.chartedSpace_chartAt theorem FiberBundle.chartedSpace_chartAt_symm_fst (x : TotalSpace F E) (y : ModelProd HB F) (hy : y ∈ (chartAt (ModelProd HB F) x).target) : ((chartAt (ModelProd HB F) x).symm y).proj = (chartAt HB x.proj).symm y.1 := by simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] at hy ⊢ exact (trivializationAt F E x.proj).proj_symm_apply hy.2 #align fiber_bundle.charted_space_chart_at_symm_fst FiberBundle.chartedSpace_chartAt_symm_fst end section variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] {EB : Type*} [NormedAddCommGroup EB] [NormedSpace 𝕜 EB] {HB : Type*} [TopologicalSpace HB] (IB : ModelWithCorners 𝕜 EB HB) (E' : B → Type*) [∀ x, Zero (E' x)] {EM : Type*} [NormedAddCommGroup EM] [NormedSpace 𝕜 EM] {HM : Type*} [TopologicalSpace HM] {IM : ModelWithCorners 𝕜 EM HM} [TopologicalSpace M] [ChartedSpace HM M] [Is : SmoothManifoldWithCorners IM M] {n : ℕ∞} variable [TopologicalSpace B] [ChartedSpace HB B] [FiberBundle F E] protected theorem FiberBundle.extChartAt (x : TotalSpace F E) : extChartAt (IB.prod 𝓘(𝕜, F)) x = (trivializationAt F E x.proj).toPartialEquiv ≫ (extChartAt IB x.proj).prod (PartialEquiv.refl F) := by simp_rw [extChartAt, FiberBundle.chartedSpace_chartAt, extend] simp only [PartialEquiv.trans_assoc, mfld_simps] -- Porting note: should not be needed rw [PartialEquiv.prod_trans, PartialEquiv.refl_trans] #align fiber_bundle.ext_chart_at FiberBundle.extChartAt protected theorem FiberBundle.extChartAt_target (x : TotalSpace F E) : (extChartAt (IB.prod 𝓘(𝕜, F)) x).target = ((extChartAt IB x.proj).target ∩ (extChartAt IB x.proj).symm ⁻¹' (trivializationAt F E x.proj).baseSet) ×ˢ univ := by rw [FiberBundle.extChartAt, PartialEquiv.trans_target, Trivialization.target_eq, inter_prod] rfl theorem FiberBundle.writtenInExtChartAt_trivializationAt {x : TotalSpace F E} {y} (hy : y ∈ (extChartAt (IB.prod 𝓘(𝕜, F)) x).target) : writtenInExtChartAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) x (trivializationAt F E x.proj) y = y := writtenInExtChartAt_chartAt_comp _ _ hy theorem FiberBundle.writtenInExtChartAt_trivializationAt_symm {x : TotalSpace F E} {y} (hy : y ∈ (extChartAt (IB.prod 𝓘(𝕜, F)) x).target) : writtenInExtChartAt (IB.prod 𝓘(𝕜, F)) (IB.prod 𝓘(𝕜, F)) (trivializationAt F E x.proj x) (trivializationAt F E x.proj).toPartialHomeomorph.symm y = y := writtenInExtChartAt_chartAt_symm_comp _ _ hy /-! ### Smoothness of maps in/out fiber bundles Note: For these results we don't need that the bundle is a smooth vector bundle, or even a vector bundle at all, just that it is a fiber bundle over a charted base space. -/ namespace Bundle variable {IB} /-- Characterization of C^n functions into a smooth vector bundle. -/
Mathlib/Geometry/Manifold/VectorBundle/Basic.lean
178
196
theorem contMDiffWithinAt_totalSpace (f : M → TotalSpace F E) {s : Set M} {x₀ : M} : ContMDiffWithinAt IM (IB.prod 𝓘(𝕜, F)) n f s x₀ ↔ ContMDiffWithinAt IM IB n (fun x => (f x).proj) s x₀ ∧ ContMDiffWithinAt IM 𝓘(𝕜, F) n (fun x ↦ (trivializationAt F E (f x₀).proj (f x)).2) s x₀ := by
simp (config := { singlePass := true }) only [contMDiffWithinAt_iff_target] rw [and_and_and_comm, ← FiberBundle.continuousWithinAt_totalSpace, and_congr_right_iff] intro hf simp_rw [modelWithCornersSelf_prod, FiberBundle.extChartAt, Function.comp, PartialEquiv.trans_apply, PartialEquiv.prod_coe, PartialEquiv.refl_coe, extChartAt_self_apply, modelWithCornersSelf_coe, Function.id_def, ← chartedSpaceSelf_prod] refine (contMDiffWithinAt_prod_iff _).trans (and_congr ?_ Iff.rfl) have h1 : (fun x => (f x).proj) ⁻¹' (trivializationAt F E (f x₀).proj).baseSet ∈ 𝓝[s] x₀ := ((FiberBundle.continuous_proj F E).continuousWithinAt.comp hf (mapsTo_image f s)) ((Trivialization.open_baseSet _).mem_nhds (mem_baseSet_trivializationAt F E _)) refine EventuallyEq.contMDiffWithinAt_iff (eventually_of_mem h1 fun x hx => ?_) ?_ · simp_rw [Function.comp, PartialHomeomorph.coe_coe, Trivialization.coe_coe] rw [Trivialization.coe_fst'] exact hx · simp only [mfld_simps]
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Batteries.Control.ForInStep.Lemmas import Batteries.Data.List.Basic import Batteries.Tactic.Init import Batteries.Tactic.Alias namespace List open Nat /-! ### mem -/ @[simp] theorem mem_toArray {a : α} {l : List α} : a ∈ l.toArray ↔ a ∈ l := by simp [Array.mem_def] /-! ### drop -/ @[simp] theorem drop_one : ∀ l : List α, drop 1 l = tail l | [] | _ :: _ => rfl /-! ### zipWith -/ theorem zipWith_distrib_tail : (zipWith f l l').tail = zipWith f l.tail l'.tail := by rw [← drop_one]; simp [zipWith_distrib_drop] /-! ### List subset -/ theorem subset_def {l₁ l₂ : List α} : l₁ ⊆ l₂ ↔ ∀ {a : α}, a ∈ l₁ → a ∈ l₂ := .rfl @[simp] theorem nil_subset (l : List α) : [] ⊆ l := nofun @[simp] theorem Subset.refl (l : List α) : l ⊆ l := fun _ i => i theorem Subset.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ ⊆ l₂) (h₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ := fun _ i => h₂ (h₁ i) instance : Trans (Membership.mem : α → List α → Prop) Subset Membership.mem := ⟨fun h₁ h₂ => h₂ h₁⟩ instance : Trans (Subset : List α → List α → Prop) Subset Subset := ⟨Subset.trans⟩ @[simp] theorem subset_cons (a : α) (l : List α) : l ⊆ a :: l := fun _ => Mem.tail _ theorem subset_of_cons_subset {a : α} {l₁ l₂ : List α} : a :: l₁ ⊆ l₂ → l₁ ⊆ l₂ := fun s _ i => s (mem_cons_of_mem _ i) theorem subset_cons_of_subset (a : α) {l₁ l₂ : List α} : l₁ ⊆ l₂ → l₁ ⊆ a :: l₂ := fun s _ i => .tail _ (s i) theorem cons_subset_cons {l₁ l₂ : List α} (a : α) (s : l₁ ⊆ l₂) : a :: l₁ ⊆ a :: l₂ := fun _ => by simp only [mem_cons]; exact Or.imp_right (@s _) @[simp] theorem subset_append_left (l₁ l₂ : List α) : l₁ ⊆ l₁ ++ l₂ := fun _ => mem_append_left _ @[simp] theorem subset_append_right (l₁ l₂ : List α) : l₂ ⊆ l₁ ++ l₂ := fun _ => mem_append_right _ theorem subset_append_of_subset_left (l₂ : List α) : l ⊆ l₁ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_left _ _ theorem subset_append_of_subset_right (l₁ : List α) : l ⊆ l₂ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_right _ _ @[simp] theorem cons_subset : a :: l ⊆ m ↔ a ∈ m ∧ l ⊆ m := by simp only [subset_def, mem_cons, or_imp, forall_and, forall_eq] @[simp] theorem append_subset {l₁ l₂ l : List α} : l₁ ++ l₂ ⊆ l ↔ l₁ ⊆ l ∧ l₂ ⊆ l := by simp [subset_def, or_imp, forall_and] theorem subset_nil {l : List α} : l ⊆ [] ↔ l = [] := ⟨fun h => match l with | [] => rfl | _::_ => (nomatch h (.head ..)), fun | rfl => Subset.refl _⟩ theorem map_subset {l₁ l₂ : List α} (f : α → β) (H : l₁ ⊆ l₂) : map f l₁ ⊆ map f l₂ := fun x => by simp only [mem_map]; exact .imp fun a => .imp_left (@H _) /-! ### sublists -/ @[simp] theorem nil_sublist : ∀ l : List α, [] <+ l | [] => .slnil | a :: l => (nil_sublist l).cons a @[simp] theorem Sublist.refl : ∀ l : List α, l <+ l | [] => .slnil | a :: l => (Sublist.refl l).cons₂ a theorem Sublist.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ <+ l₂) (h₂ : l₂ <+ l₃) : l₁ <+ l₃ := by induction h₂ generalizing l₁ with | slnil => exact h₁ | cons _ _ IH => exact (IH h₁).cons _ | @cons₂ l₂ _ a _ IH => generalize e : a :: l₂ = l₂' match e ▸ h₁ with | .slnil => apply nil_sublist | .cons a' h₁' => cases e; apply (IH h₁').cons | .cons₂ a' h₁' => cases e; apply (IH h₁').cons₂ instance : Trans (@Sublist α) Sublist Sublist := ⟨Sublist.trans⟩ @[simp] theorem sublist_cons (a : α) (l : List α) : l <+ a :: l := (Sublist.refl l).cons _ theorem sublist_of_cons_sublist : a :: l₁ <+ l₂ → l₁ <+ l₂ := (sublist_cons a l₁).trans @[simp] theorem sublist_append_left : ∀ l₁ l₂ : List α, l₁ <+ l₁ ++ l₂ | [], _ => nil_sublist _ | _ :: l₁, l₂ => (sublist_append_left l₁ l₂).cons₂ _ @[simp] theorem sublist_append_right : ∀ l₁ l₂ : List α, l₂ <+ l₁ ++ l₂ | [], _ => Sublist.refl _ | _ :: l₁, l₂ => (sublist_append_right l₁ l₂).cons _ theorem sublist_append_of_sublist_left (s : l <+ l₁) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_left .. theorem sublist_append_of_sublist_right (s : l <+ l₂) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_right .. @[simp] theorem cons_sublist_cons : a :: l₁ <+ a :: l₂ ↔ l₁ <+ l₂ := ⟨fun | .cons _ s => sublist_of_cons_sublist s | .cons₂ _ s => s, .cons₂ _⟩ @[simp] theorem append_sublist_append_left : ∀ l, l ++ l₁ <+ l ++ l₂ ↔ l₁ <+ l₂ | [] => Iff.rfl | _ :: l => cons_sublist_cons.trans (append_sublist_append_left l) theorem Sublist.append_left : l₁ <+ l₂ → ∀ l, l ++ l₁ <+ l ++ l₂ := fun h l => (append_sublist_append_left l).mpr h theorem Sublist.append_right : l₁ <+ l₂ → ∀ l, l₁ ++ l <+ l₂ ++ l | .slnil, _ => Sublist.refl _ | .cons _ h, _ => (h.append_right _).cons _ | .cons₂ _ h, _ => (h.append_right _).cons₂ _ theorem sublist_or_mem_of_sublist (h : l <+ l₁ ++ a :: l₂) : l <+ l₁ ++ l₂ ∨ a ∈ l := by induction l₁ generalizing l with | nil => match h with | .cons _ h => exact .inl h | .cons₂ _ h => exact .inr (.head ..) | cons b l₁ IH => match h with | .cons _ h => exact (IH h).imp_left (Sublist.cons _) | .cons₂ _ h => exact (IH h).imp (Sublist.cons₂ _) (.tail _) theorem Sublist.reverse : l₁ <+ l₂ → l₁.reverse <+ l₂.reverse | .slnil => Sublist.refl _ | .cons _ h => by rw [reverse_cons]; exact sublist_append_of_sublist_left h.reverse | .cons₂ _ h => by rw [reverse_cons, reverse_cons]; exact h.reverse.append_right _ @[simp] theorem reverse_sublist : l₁.reverse <+ l₂.reverse ↔ l₁ <+ l₂ := ⟨fun h => l₁.reverse_reverse ▸ l₂.reverse_reverse ▸ h.reverse, Sublist.reverse⟩ @[simp] theorem append_sublist_append_right (l) : l₁ ++ l <+ l₂ ++ l ↔ l₁ <+ l₂ := ⟨fun h => by have := h.reverse simp only [reverse_append, append_sublist_append_left, reverse_sublist] at this exact this, fun h => h.append_right l⟩ theorem Sublist.append (hl : l₁ <+ l₂) (hr : r₁ <+ r₂) : l₁ ++ r₁ <+ l₂ ++ r₂ := (hl.append_right _).trans ((append_sublist_append_left _).2 hr) theorem Sublist.subset : l₁ <+ l₂ → l₁ ⊆ l₂ | .slnil, _, h => h | .cons _ s, _, h => .tail _ (s.subset h) | .cons₂ .., _, .head .. => .head .. | .cons₂ _ s, _, .tail _ h => .tail _ (s.subset h) instance : Trans (@Sublist α) Subset Subset := ⟨fun h₁ h₂ => trans h₁.subset h₂⟩ instance : Trans Subset (@Sublist α) Subset := ⟨fun h₁ h₂ => trans h₁ h₂.subset⟩ instance : Trans (Membership.mem : α → List α → Prop) Sublist Membership.mem := ⟨fun h₁ h₂ => h₂.subset h₁⟩ theorem Sublist.length_le : l₁ <+ l₂ → length l₁ ≤ length l₂ | .slnil => Nat.le_refl 0 | .cons _l s => le_succ_of_le (length_le s) | .cons₂ _ s => succ_le_succ (length_le s) @[simp] theorem sublist_nil {l : List α} : l <+ [] ↔ l = [] := ⟨fun s => subset_nil.1 s.subset, fun H => H ▸ Sublist.refl _⟩ theorem Sublist.eq_of_length : l₁ <+ l₂ → length l₁ = length l₂ → l₁ = l₂ | .slnil, _ => rfl | .cons a s, h => nomatch Nat.not_lt.2 s.length_le (h ▸ lt_succ_self _) | .cons₂ a s, h => by rw [s.eq_of_length (succ.inj h)] theorem Sublist.eq_of_length_le (s : l₁ <+ l₂) (h : length l₂ ≤ length l₁) : l₁ = l₂ := s.eq_of_length <| Nat.le_antisymm s.length_le h @[simp] theorem singleton_sublist {a : α} {l} : [a] <+ l ↔ a ∈ l := by refine ⟨fun h => h.subset (mem_singleton_self _), fun h => ?_⟩ obtain ⟨_, _, rfl⟩ := append_of_mem h exact ((nil_sublist _).cons₂ _).trans (sublist_append_right ..) @[simp] theorem replicate_sublist_replicate {m n} (a : α) : replicate m a <+ replicate n a ↔ m ≤ n := by refine ⟨fun h => ?_, fun h => ?_⟩ · have := h.length_le; simp only [length_replicate] at this ⊢; exact this · induction h with | refl => apply Sublist.refl | step => simp [*, replicate, Sublist.cons] theorem isSublist_iff_sublist [BEq α] [LawfulBEq α] {l₁ l₂ : List α} : l₁.isSublist l₂ ↔ l₁ <+ l₂ := by cases l₁ <;> cases l₂ <;> simp [isSublist] case cons.cons hd₁ tl₁ hd₂ tl₂ => if h_eq : hd₁ = hd₂ then simp [h_eq, cons_sublist_cons, isSublist_iff_sublist] else simp only [beq_iff_eq, h_eq] constructor · intro h_sub apply Sublist.cons exact isSublist_iff_sublist.mp h_sub · intro h_sub cases h_sub case cons h_sub => exact isSublist_iff_sublist.mpr h_sub case cons₂ => contradiction instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ <+ l₂) := decidable_of_iff (l₁.isSublist l₂) isSublist_iff_sublist /-! ### tail -/ theorem tail_eq_tailD (l) : @tail α l = tailD l [] := by cases l <;> rfl theorem tail_eq_tail? (l) : @tail α l = (tail? l).getD [] := by simp [tail_eq_tailD] /-! ### next? -/ @[simp] theorem next?_nil : @next? α [] = none := rfl @[simp] theorem next?_cons (a l) : @next? α (a :: l) = some (a, l) := rfl /-! ### get? -/ theorem get_eq_iff : List.get l n = x ↔ l.get? n.1 = some x := by simp [get?_eq_some] theorem get?_inj (h₀ : i < xs.length) (h₁ : Nodup xs) (h₂ : xs.get? i = xs.get? j) : i = j := by induction xs generalizing i j with | nil => cases h₀ | cons x xs ih => match i, j with | 0, 0 => rfl | i+1, j+1 => simp; cases h₁ with | cons ha h₁ => exact ih (Nat.lt_of_succ_lt_succ h₀) h₁ h₂ | i+1, 0 => ?_ | 0, j+1 => ?_ all_goals simp at h₂ cases h₁; rename_i h' h have := h x ?_ rfl; cases this rw [mem_iff_get?] exact ⟨_, h₂⟩; exact ⟨_ , h₂.symm⟩ /-! ### drop -/ theorem tail_drop (l : List α) (n : Nat) : (l.drop n).tail = l.drop (n + 1) := by induction l generalizing n with | nil => simp | cons hd tl hl => cases n · simp · simp [hl] /-! ### modifyNth -/ @[simp] theorem modifyNth_nil (f : α → α) (n) : [].modifyNth f n = [] := by cases n <;> rfl @[simp] theorem modifyNth_zero_cons (f : α → α) (a : α) (l : List α) : (a :: l).modifyNth f 0 = f a :: l := rfl @[simp] theorem modifyNth_succ_cons (f : α → α) (a : α) (l : List α) (n) : (a :: l).modifyNth f (n + 1) = a :: l.modifyNth f n := by rfl theorem modifyNthTail_id : ∀ n (l : List α), l.modifyNthTail id n = l | 0, _ => rfl | _+1, [] => rfl | n+1, a :: l => congrArg (cons a) (modifyNthTail_id n l) theorem eraseIdx_eq_modifyNthTail : ∀ n (l : List α), eraseIdx l n = modifyNthTail tail n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, a :: l => congrArg (cons _) (eraseIdx_eq_modifyNthTail _ _) @[deprecated] alias removeNth_eq_nth_tail := eraseIdx_eq_modifyNthTail theorem get?_modifyNth (f : α → α) : ∀ n (l : List α) m, (modifyNth f n l).get? m = (fun a => if n = m then f a else a) <$> l.get? m | n, l, 0 => by cases l <;> cases n <;> rfl | n, [], _+1 => by cases n <;> rfl | 0, _ :: l, m+1 => by cases h : l.get? m <;> simp [h, modifyNth, m.succ_ne_zero.symm] | n+1, a :: l, m+1 => (get?_modifyNth f n l m).trans <| by cases h' : l.get? m <;> by_cases h : n = m <;> simp [h, if_pos, if_neg, Option.map, mt Nat.succ.inj, not_false_iff, h'] theorem modifyNthTail_length (f : List α → List α) (H : ∀ l, length (f l) = length l) : ∀ n l, length (modifyNthTail f n l) = length l | 0, _ => H _ | _+1, [] => rfl | _+1, _ :: _ => congrArg (·+1) (modifyNthTail_length _ H _ _) theorem modifyNthTail_add (f : List α → List α) (n) (l₁ l₂ : List α) : modifyNthTail f (l₁.length + n) (l₁ ++ l₂) = l₁ ++ modifyNthTail f n l₂ := by induction l₁ <;> simp [*, Nat.succ_add] theorem exists_of_modifyNthTail (f : List α → List α) {n} {l : List α} (h : n ≤ l.length) : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n ∧ modifyNthTail f n l = l₁ ++ f l₂ := have ⟨_, _, eq, hl⟩ : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n := ⟨_, _, (take_append_drop n l).symm, length_take_of_le h⟩ ⟨_, _, eq, hl, hl ▸ eq ▸ modifyNthTail_add (n := 0) ..⟩ @[simp] theorem modify_get?_length (f : α → α) : ∀ n l, length (modifyNth f n l) = length l := modifyNthTail_length _ fun l => by cases l <;> rfl @[simp] theorem get?_modifyNth_eq (f : α → α) (n) (l : List α) : (modifyNth f n l).get? n = f <$> l.get? n := by simp only [get?_modifyNth, if_pos] @[simp] theorem get?_modifyNth_ne (f : α → α) {m n} (l : List α) (h : m ≠ n) : (modifyNth f m l).get? n = l.get? n := by simp only [get?_modifyNth, if_neg h, id_map'] theorem exists_of_modifyNth (f : α → α) {n} {l : List α} (h : n < l.length) : ∃ l₁ a l₂, l = l₁ ++ a :: l₂ ∧ l₁.length = n ∧ modifyNth f n l = l₁ ++ f a :: l₂ := match exists_of_modifyNthTail _ (Nat.le_of_lt h) with | ⟨_, _::_, eq, hl, H⟩ => ⟨_, _, _, eq, hl, H⟩ | ⟨_, [], eq, hl, _⟩ => nomatch Nat.ne_of_gt h (eq ▸ append_nil _ ▸ hl) theorem modifyNthTail_eq_take_drop (f : List α → List α) (H : f [] = []) : ∀ n l, modifyNthTail f n l = take n l ++ f (drop n l) | 0, _ => rfl | _ + 1, [] => H.symm | n + 1, b :: l => congrArg (cons b) (modifyNthTail_eq_take_drop f H n l) theorem modifyNth_eq_take_drop (f : α → α) : ∀ n l, modifyNth f n l = take n l ++ modifyHead f (drop n l) := modifyNthTail_eq_take_drop _ rfl theorem modifyNth_eq_take_cons_drop (f : α → α) {n l} (h) : modifyNth f n l = take n l ++ f (get l ⟨n, h⟩) :: drop (n + 1) l := by rw [modifyNth_eq_take_drop, drop_eq_get_cons h]; rfl /-! ### set -/ theorem set_eq_modifyNth (a : α) : ∀ n (l : List α), set l n a = modifyNth (fun _ => a) n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, b :: l => congrArg (cons _) (set_eq_modifyNth _ _ _) theorem set_eq_take_cons_drop (a : α) {n l} (h : n < length l) : set l n a = take n l ++ a :: drop (n + 1) l := by rw [set_eq_modifyNth, modifyNth_eq_take_cons_drop _ h] theorem modifyNth_eq_set_get? (f : α → α) : ∀ n (l : List α), l.modifyNth f n = ((fun a => l.set n (f a)) <$> l.get? n).getD l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, b :: l => (congrArg (cons _) (modifyNth_eq_set_get? ..)).trans <| by cases h : l.get? n <;> simp [h] theorem modifyNth_eq_set_get (f : α → α) {n} {l : List α} (h) : l.modifyNth f n = l.set n (f (l.get ⟨n, h⟩)) := by rw [modifyNth_eq_set_get?, get?_eq_get h]; rfl theorem exists_of_set {l : List α} (h : n < l.length) : ∃ l₁ a l₂, l = l₁ ++ a :: l₂ ∧ l₁.length = n ∧ l.set n a' = l₁ ++ a' :: l₂ := by rw [set_eq_modifyNth]; exact exists_of_modifyNth _ h theorem exists_of_set' {l : List α} (h : n < l.length) : ∃ l₁ l₂, l = l₁ ++ l.get ⟨n, h⟩ :: l₂ ∧ l₁.length = n ∧ l.set n a' = l₁ ++ a' :: l₂ := have ⟨_, _, _, h₁, h₂, h₃⟩ := exists_of_set h; ⟨_, _, get_of_append h₁ h₂ ▸ h₁, h₂, h₃⟩ @[simp] theorem get?_set_eq (a : α) (n) (l : List α) : (set l n a).get? n = (fun _ => a) <$> l.get? n := by simp only [set_eq_modifyNth, get?_modifyNth_eq] theorem get?_set_eq_of_lt (a : α) {n} {l : List α} (h : n < length l) : (set l n a).get? n = some a := by rw [get?_set_eq, get?_eq_get h]; rfl @[simp] theorem get?_set_ne (a : α) {m n} (l : List α) (h : m ≠ n) : (set l m a).get? n = l.get? n := by simp only [set_eq_modifyNth, get?_modifyNth_ne _ _ h] theorem get?_set (a : α) {m n} (l : List α) : (set l m a).get? n = if m = n then (fun _ => a) <$> l.get? n else l.get? n := by by_cases m = n <;> simp [*, get?_set_eq, get?_set_ne] theorem get?_set_of_lt (a : α) {m n} (l : List α) (h : n < length l) : (set l m a).get? n = if m = n then some a else l.get? n := by simp [get?_set, get?_eq_get h] theorem get?_set_of_lt' (a : α) {m n} (l : List α) (h : m < length l) : (set l m a).get? n = if m = n then some a else l.get? n := by simp [get?_set]; split <;> subst_vars <;> simp [*, get?_eq_get h] theorem drop_set_of_lt (a : α) {n m : Nat} (l : List α) (h : n < m) : (l.set n a).drop m = l.drop m := List.ext fun i => by rw [get?_drop, get?_drop, get?_set_ne _ _ (by omega)] theorem take_set_of_lt (a : α) {n m : Nat} (l : List α) (h : m < n) : (l.set n a).take m = l.take m := List.ext fun i => by rw [get?_take_eq_if, get?_take_eq_if] split · next h' => rw [get?_set_ne _ _ (by omega)] · rfl /-! ### removeNth -/ theorem length_eraseIdx : ∀ {l i}, i < length l → length (@eraseIdx α l i) = length l - 1 | [], _, _ => rfl | _::_, 0, _ => by simp [eraseIdx] | x::xs, i+1, h => by have : i < length xs := Nat.lt_of_succ_lt_succ h simp [eraseIdx, ← Nat.add_one] rw [length_eraseIdx this, Nat.sub_add_cancel (Nat.lt_of_le_of_lt (Nat.zero_le _) this)] @[deprecated] alias length_removeNth := length_eraseIdx /-! ### tail -/ @[simp] theorem length_tail (l : List α) : length (tail l) = length l - 1 := by cases l <;> rfl /-! ### eraseP -/ @[simp] theorem eraseP_nil : [].eraseP p = [] := rfl theorem eraseP_cons (a : α) (l : List α) : (a :: l).eraseP p = bif p a then l else a :: l.eraseP p := rfl @[simp] theorem eraseP_cons_of_pos {l : List α} (p) (h : p a) : (a :: l).eraseP p = l := by simp [eraseP_cons, h] @[simp] theorem eraseP_cons_of_neg {l : List α} (p) (h : ¬p a) : (a :: l).eraseP p = a :: l.eraseP p := by simp [eraseP_cons, h] theorem eraseP_of_forall_not {l : List α} (h : ∀ a, a ∈ l → ¬p a) : l.eraseP p = l := by induction l with | nil => rfl | cons _ _ ih => simp [h _ (.head ..), ih (forall_mem_cons.1 h).2] theorem exists_of_eraseP : ∀ {l : List α} {a} (al : a ∈ l) (pa : p a), ∃ a l₁ l₂, (∀ b ∈ l₁, ¬p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.eraseP p = l₁ ++ l₂ | b :: l, a, al, pa => if pb : p b then ⟨b, [], l, forall_mem_nil _, pb, by simp [pb]⟩ else match al with | .head .. => nomatch pb pa | .tail _ al => let ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩ := exists_of_eraseP al pa ⟨c, b::l₁, l₂, (forall_mem_cons ..).2 ⟨pb, h₁⟩, h₂, by rw [h₃, cons_append], by simp [pb, h₄]⟩ theorem exists_or_eq_self_of_eraseP (p) (l : List α) : l.eraseP p = l ∨ ∃ a l₁ l₂, (∀ b ∈ l₁, ¬p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.eraseP p = l₁ ++ l₂ := if h : ∃ a ∈ l, p a then let ⟨_, ha, pa⟩ := h .inr (exists_of_eraseP ha pa) else .inl (eraseP_of_forall_not (h ⟨·, ·, ·⟩)) @[simp] theorem length_eraseP_of_mem (al : a ∈ l) (pa : p a) : length (l.eraseP p) = Nat.pred (length l) := by let ⟨_, l₁, l₂, _, _, e₁, e₂⟩ := exists_of_eraseP al pa rw [e₂]; simp [length_append, e₁]; rfl theorem eraseP_append_left {a : α} (pa : p a) : ∀ {l₁ : List α} l₂, a ∈ l₁ → (l₁++l₂).eraseP p = l₁.eraseP p ++ l₂ | x :: xs, l₂, h => by by_cases h' : p x <;> simp [h'] rw [eraseP_append_left pa l₂ ((mem_cons.1 h).resolve_left (mt _ h'))] intro | rfl => exact pa theorem eraseP_append_right : ∀ {l₁ : List α} l₂, (∀ b ∈ l₁, ¬p b) → eraseP p (l₁++l₂) = l₁ ++ l₂.eraseP p | [], l₂, _ => rfl | x :: xs, l₂, h => by simp [(forall_mem_cons.1 h).1, eraseP_append_right _ (forall_mem_cons.1 h).2] theorem eraseP_sublist (l : List α) : l.eraseP p <+ l := by match exists_or_eq_self_of_eraseP p l with | .inl h => rw [h]; apply Sublist.refl | .inr ⟨c, l₁, l₂, _, _, h₃, h₄⟩ => rw [h₄, h₃]; simp theorem eraseP_subset (l : List α) : l.eraseP p ⊆ l := (eraseP_sublist l).subset protected theorem Sublist.eraseP : l₁ <+ l₂ → l₁.eraseP p <+ l₂.eraseP p | .slnil => Sublist.refl _ | .cons a s => by by_cases h : p a <;> simp [h] exacts [s.eraseP.trans (eraseP_sublist _), s.eraseP.cons _] | .cons₂ a s => by by_cases h : p a <;> simp [h] exacts [s, s.eraseP] theorem mem_of_mem_eraseP {l : List α} : a ∈ l.eraseP p → a ∈ l := (eraseP_subset _ ·) @[simp] theorem mem_eraseP_of_neg {l : List α} (pa : ¬p a) : a ∈ l.eraseP p ↔ a ∈ l := by refine ⟨mem_of_mem_eraseP, fun al => ?_⟩ match exists_or_eq_self_of_eraseP p l with | .inl h => rw [h]; assumption | .inr ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩ => rw [h₄]; rw [h₃] at al have : a ≠ c := fun h => (h ▸ pa).elim h₂ simp [this] at al; simp [al] theorem eraseP_map (f : β → α) : ∀ (l : List β), (map f l).eraseP p = map f (l.eraseP (p ∘ f)) | [] => rfl | b::l => by by_cases h : p (f b) <;> simp [h, eraseP_map f l, eraseP_cons_of_pos] @[simp] theorem extractP_eq_find?_eraseP (l : List α) : extractP p l = (find? p l, eraseP p l) := by let rec go (acc) : ∀ xs, l = acc.data ++ xs → extractP.go p l xs acc = (xs.find? p, acc.data ++ xs.eraseP p) | [] => fun h => by simp [extractP.go, find?, eraseP, h] | x::xs => by simp [extractP.go, find?, eraseP]; cases p x <;> simp · intro h; rw [go _ xs]; {simp}; simp [h] exact go #[] _ rfl /-! ### erase -/ section erase variable [BEq α] theorem erase_eq_eraseP' (a : α) (l : List α) : l.erase a = l.eraseP (· == a) := by induction l · simp · next b t ih => rw [erase_cons, eraseP_cons, ih] if h : b == a then simp [h] else simp [h] theorem erase_eq_eraseP [LawfulBEq α] (a : α) : ∀ l : List α, l.erase a = l.eraseP (a == ·) | [] => rfl | b :: l => by if h : a = b then simp [h] else simp [h, Ne.symm h, erase_eq_eraseP a l] theorem exists_erase_eq [LawfulBEq α] {a : α} {l : List α} (h : a ∈ l) : ∃ l₁ l₂, a ∉ l₁ ∧ l = l₁ ++ a :: l₂ ∧ l.erase a = l₁ ++ l₂ := by let ⟨_, l₁, l₂, h₁, e, h₂, h₃⟩ := exists_of_eraseP h (beq_self_eq_true _) rw [erase_eq_eraseP]; exact ⟨l₁, l₂, fun h => h₁ _ h (beq_self_eq_true _), eq_of_beq e ▸ h₂, h₃⟩ @[simp] theorem length_erase_of_mem [LawfulBEq α] {a : α} {l : List α} (h : a ∈ l) : length (l.erase a) = Nat.pred (length l) := by rw [erase_eq_eraseP]; exact length_eraseP_of_mem h (beq_self_eq_true a) theorem erase_append_left [LawfulBEq α] {l₁ : List α} (l₂) (h : a ∈ l₁) : (l₁ ++ l₂).erase a = l₁.erase a ++ l₂ := by simp [erase_eq_eraseP]; exact eraseP_append_left (beq_self_eq_true a) l₂ h theorem erase_append_right [LawfulBEq α] {a : α} {l₁ : List α} (l₂ : List α) (h : a ∉ l₁) : (l₁ ++ l₂).erase a = (l₁ ++ l₂.erase a) := by rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_append_right] intros b h' h''; rw [eq_of_beq h''] at h; exact h h' theorem erase_sublist (a : α) (l : List α) : l.erase a <+ l := erase_eq_eraseP' a l ▸ eraseP_sublist l theorem erase_subset (a : α) (l : List α) : l.erase a ⊆ l := (erase_sublist a l).subset theorem Sublist.erase (a : α) {l₁ l₂ : List α} (h : l₁ <+ l₂) : l₁.erase a <+ l₂.erase a := by simp only [erase_eq_eraseP']; exact h.eraseP @[deprecated] alias sublist.erase := Sublist.erase theorem mem_of_mem_erase {a b : α} {l : List α} (h : a ∈ l.erase b) : a ∈ l := erase_subset _ _ h @[simp] theorem mem_erase_of_ne [LawfulBEq α] {a b : α} {l : List α} (ab : a ≠ b) : a ∈ l.erase b ↔ a ∈ l := erase_eq_eraseP b l ▸ mem_eraseP_of_neg (mt eq_of_beq ab.symm) theorem erase_comm [LawfulBEq α] (a b : α) (l : List α) : (l.erase a).erase b = (l.erase b).erase a := by if ab : a == b then rw [eq_of_beq ab] else ?_ if ha : a ∈ l then ?_ else simp only [erase_of_not_mem ha, erase_of_not_mem (mt mem_of_mem_erase ha)] if hb : b ∈ l then ?_ else simp only [erase_of_not_mem hb, erase_of_not_mem (mt mem_of_mem_erase hb)] match l, l.erase a, exists_erase_eq ha with | _, _, ⟨l₁, l₂, ha', rfl, rfl⟩ => if h₁ : b ∈ l₁ then rw [erase_append_left _ h₁, erase_append_left _ h₁, erase_append_right _ (mt mem_of_mem_erase ha'), erase_cons_head] else rw [erase_append_right _ h₁, erase_append_right _ h₁, erase_append_right _ ha', erase_cons_tail _ ab, erase_cons_head] end erase /-! ### filter and partition -/ @[simp] theorem filter_sublist {p : α → Bool} : ∀ (l : List α), filter p l <+ l | [] => .slnil | a :: l => by rw [filter]; split <;> simp [Sublist.cons, Sublist.cons₂, filter_sublist l] /-! ### filterMap -/ theorem length_filter_le (p : α → Bool) (l : List α) : (l.filter p).length ≤ l.length := (filter_sublist _).length_le theorem length_filterMap_le (f : α → Option β) (l : List α) : (filterMap f l).length ≤ l.length := by rw [← length_map _ some, map_filterMap_some_eq_filter_map_is_some, ← length_map _ f] apply length_filter_le protected theorem Sublist.filterMap (f : α → Option β) (s : l₁ <+ l₂) : filterMap f l₁ <+ filterMap f l₂ := by induction s <;> simp <;> split <;> simp [*, cons, cons₂] theorem Sublist.filter (p : α → Bool) {l₁ l₂} (s : l₁ <+ l₂) : filter p l₁ <+ filter p l₂ := by rw [← filterMap_eq_filter]; apply s.filterMap @[simp] theorem filter_eq_self {l} : filter p l = l ↔ ∀ a ∈ l, p a := by induction l with simp | cons a l ih => cases h : p a <;> simp [*] intro h; exact Nat.lt_irrefl _ (h ▸ length_filter_le p l) @[simp] theorem filter_length_eq_length {l} : (filter p l).length = l.length ↔ ∀ a ∈ l, p a := Iff.trans ⟨l.filter_sublist.eq_of_length, congrArg length⟩ filter_eq_self /-! ### findIdx -/ @[simp] theorem findIdx_nil {α : Type _} (p : α → Bool) : [].findIdx p = 0 := rfl theorem findIdx_cons (p : α → Bool) (b : α) (l : List α) : (b :: l).findIdx p = bif p b then 0 else (l.findIdx p) + 1 := by cases H : p b with | true => simp [H, findIdx, findIdx.go] | false => simp [H, findIdx, findIdx.go, findIdx_go_succ] where findIdx_go_succ (p : α → Bool) (l : List α) (n : Nat) : List.findIdx.go p l (n + 1) = (findIdx.go p l n) + 1 := by cases l with | nil => unfold findIdx.go; exact Nat.succ_eq_add_one n | cons head tail => unfold findIdx.go cases p head <;> simp only [cond_false, cond_true] exact findIdx_go_succ p tail (n + 1) theorem findIdx_of_get?_eq_some {xs : List α} (w : xs.get? (xs.findIdx p) = some y) : p y := by induction xs with | nil => simp_all | cons x xs ih => by_cases h : p x <;> simp_all [findIdx_cons] theorem findIdx_get {xs : List α} {w : xs.findIdx p < xs.length} : p (xs.get ⟨xs.findIdx p, w⟩) := xs.findIdx_of_get?_eq_some (get?_eq_get w) theorem findIdx_lt_length_of_exists {xs : List α} (h : ∃ x ∈ xs, p x) : xs.findIdx p < xs.length := by induction xs with | nil => simp_all | cons x xs ih => by_cases p x · simp_all only [forall_exists_index, and_imp, mem_cons, exists_eq_or_imp, true_or, findIdx_cons, cond_true, length_cons] apply Nat.succ_pos · simp_all [findIdx_cons] refine Nat.succ_lt_succ ?_ obtain ⟨x', m', h'⟩ := h exact ih x' m' h' theorem findIdx_get?_eq_get_of_exists {xs : List α} (h : ∃ x ∈ xs, p x) : xs.get? (xs.findIdx p) = some (xs.get ⟨xs.findIdx p, xs.findIdx_lt_length_of_exists h⟩) := get?_eq_get (findIdx_lt_length_of_exists h) /-! ### findIdx? -/ @[simp] theorem findIdx?_nil : ([] : List α).findIdx? p i = none := rfl @[simp] theorem findIdx?_cons : (x :: xs).findIdx? p i = if p x then some i else findIdx? p xs (i + 1) := rfl @[simp] theorem findIdx?_succ : (xs : List α).findIdx? p (i+1) = (xs.findIdx? p i).map fun i => i + 1 := by induction xs generalizing i with simp | cons _ _ _ => split <;> simp_all theorem findIdx?_eq_some_iff (xs : List α) (p : α → Bool) : xs.findIdx? p = some i ↔ (xs.take (i + 1)).map p = replicate i false ++ [true] := by induction xs generalizing i with | nil => simp | cons x xs ih => simp only [findIdx?_cons, Nat.zero_add, findIdx?_succ, take_succ_cons, map_cons] split <;> cases i <;> simp_all theorem findIdx?_of_eq_some {xs : List α} {p : α → Bool} (w : xs.findIdx? p = some i) : match xs.get? i with | some a => p a | none => false := by induction xs generalizing i with | nil => simp_all | cons x xs ih => simp_all only [findIdx?_cons, Nat.zero_add, findIdx?_succ] split at w <;> cases i <;> simp_all theorem findIdx?_of_eq_none {xs : List α} {p : α → Bool} (w : xs.findIdx? p = none) : ∀ i, match xs.get? i with | some a => ¬ p a | none => true := by intro i induction xs generalizing i with | nil => simp_all | cons x xs ih => simp_all only [Bool.not_eq_true, findIdx?_cons, Nat.zero_add, findIdx?_succ] cases i with | zero => split at w <;> simp_all | succ i => simp only [get?_cons_succ] apply ih split at w <;> simp_all @[simp] theorem findIdx?_append : (xs ++ ys : List α).findIdx? p = (xs.findIdx? p <|> (ys.findIdx? p).map fun i => i + xs.length) := by induction xs with simp | cons _ _ _ => split <;> simp_all [Option.map_orElse, Option.map_map]; rfl @[simp] theorem findIdx?_replicate : (replicate n a).findIdx? p = if 0 < n ∧ p a then some 0 else none := by induction n with | zero => simp | succ n ih => simp only [replicate, findIdx?_cons, Nat.zero_add, findIdx?_succ, Nat.zero_lt_succ, true_and] split <;> simp_all /-! ### pairwise -/ theorem Pairwise.sublist : l₁ <+ l₂ → l₂.Pairwise R → l₁.Pairwise R | .slnil, h => h | .cons _ s, .cons _ h₂ => h₂.sublist s | .cons₂ _ s, .cons h₁ h₂ => (h₂.sublist s).cons fun _ h => h₁ _ (s.subset h) theorem pairwise_map {l : List α} : (l.map f).Pairwise R ↔ l.Pairwise fun a b => R (f a) (f b) := by induction l · simp · simp only [map, pairwise_cons, forall_mem_map_iff, *] theorem pairwise_append {l₁ l₂ : List α} : (l₁ ++ l₂).Pairwise R ↔ l₁.Pairwise R ∧ l₂.Pairwise R ∧ ∀ a ∈ l₁, ∀ b ∈ l₂, R a b := by induction l₁ <;> simp [*, or_imp, forall_and, and_assoc, and_left_comm] theorem pairwise_reverse {l : List α} : l.reverse.Pairwise R ↔ l.Pairwise (fun a b => R b a) := by induction l <;> simp [*, pairwise_append, and_comm] theorem Pairwise.imp {α R S} (H : ∀ {a b}, R a b → S a b) : ∀ {l : List α}, l.Pairwise R → l.Pairwise S | _, .nil => .nil | _, .cons h₁ h₂ => .cons (H ∘ h₁ ·) (h₂.imp H) /-! ### replaceF -/ theorem replaceF_nil : [].replaceF p = [] := rfl theorem replaceF_cons (a : α) (l : List α) : (a :: l).replaceF p = match p a with | none => a :: replaceF p l | some a' => a' :: l := rfl theorem replaceF_cons_of_some {l : List α} (p) (h : p a = some a') : (a :: l).replaceF p = a' :: l := by simp [replaceF_cons, h] theorem replaceF_cons_of_none {l : List α} (p) (h : p a = none) : (a :: l).replaceF p = a :: l.replaceF p := by simp [replaceF_cons, h] theorem replaceF_of_forall_none {l : List α} (h : ∀ a, a ∈ l → p a = none) : l.replaceF p = l := by induction l with | nil => rfl | cons _ _ ih => simp [h _ (.head ..), ih (forall_mem_cons.1 h).2] theorem exists_of_replaceF : ∀ {l : List α} {a a'} (al : a ∈ l) (pa : p a = some a'), ∃ a a' l₁ l₂, (∀ b ∈ l₁, p b = none) ∧ p a = some a' ∧ l = l₁ ++ a :: l₂ ∧ l.replaceF p = l₁ ++ a' :: l₂ | b :: l, a, a', al, pa => match pb : p b with | some b' => ⟨b, b', [], l, forall_mem_nil _, pb, by simp [pb]⟩ | none => match al with | .head .. => nomatch pb.symm.trans pa | .tail _ al => let ⟨c, c', l₁, l₂, h₁, h₂, h₃, h₄⟩ := exists_of_replaceF al pa ⟨c, c', b::l₁, l₂, (forall_mem_cons ..).2 ⟨pb, h₁⟩, h₂, by rw [h₃, cons_append], by simp [pb, h₄]⟩ theorem exists_or_eq_self_of_replaceF (p) (l : List α) : l.replaceF p = l ∨ ∃ a a' l₁ l₂, (∀ b ∈ l₁, p b = none) ∧ p a = some a' ∧ l = l₁ ++ a :: l₂ ∧ l.replaceF p = l₁ ++ a' :: l₂ := if h : ∃ a ∈ l, (p a).isSome then let ⟨_, ha, pa⟩ := h .inr (exists_of_replaceF ha (Option.get_mem pa)) else .inl <| replaceF_of_forall_none fun a ha => Option.not_isSome_iff_eq_none.1 fun h' => h ⟨a, ha, h'⟩ @[simp] theorem length_replaceF : length (replaceF f l) = length l := by induction l <;> simp [replaceF]; split <;> simp [*] /-! ### disjoint -/ theorem disjoint_symm (d : Disjoint l₁ l₂) : Disjoint l₂ l₁ := fun _ i₂ i₁ => d i₁ i₂ theorem disjoint_comm : Disjoint l₁ l₂ ↔ Disjoint l₂ l₁ := ⟨disjoint_symm, disjoint_symm⟩ theorem disjoint_left : Disjoint l₁ l₂ ↔ ∀ ⦃a⦄, a ∈ l₁ → a ∉ l₂ := by simp [Disjoint] theorem disjoint_right : Disjoint l₁ l₂ ↔ ∀ ⦃a⦄, a ∈ l₂ → a ∉ l₁ := disjoint_comm theorem disjoint_iff_ne : Disjoint l₁ l₂ ↔ ∀ a ∈ l₁, ∀ b ∈ l₂, a ≠ b := ⟨fun h _ al1 _ bl2 ab => h al1 (ab ▸ bl2), fun h _ al1 al2 => h _ al1 _ al2 rfl⟩ theorem disjoint_of_subset_left (ss : l₁ ⊆ l) (d : Disjoint l l₂) : Disjoint l₁ l₂ := fun _ m => d (ss m) theorem disjoint_of_subset_right (ss : l₂ ⊆ l) (d : Disjoint l₁ l) : Disjoint l₁ l₂ := fun _ m m₁ => d m (ss m₁) theorem disjoint_of_disjoint_cons_left {l₁ l₂} : Disjoint (a :: l₁) l₂ → Disjoint l₁ l₂ := disjoint_of_subset_left (subset_cons _ _) theorem disjoint_of_disjoint_cons_right {l₁ l₂} : Disjoint l₁ (a :: l₂) → Disjoint l₁ l₂ := disjoint_of_subset_right (subset_cons _ _) @[simp] theorem disjoint_nil_left (l : List α) : Disjoint [] l := fun a => (not_mem_nil a).elim @[simp] theorem disjoint_nil_right (l : List α) : Disjoint l [] := by rw [disjoint_comm]; exact disjoint_nil_left _ @[simp 1100] theorem singleton_disjoint : Disjoint [a] l ↔ a ∉ l := by simp [Disjoint] @[simp 1100] theorem disjoint_singleton : Disjoint l [a] ↔ a ∉ l := by rw [disjoint_comm, singleton_disjoint] @[simp] theorem disjoint_append_left : Disjoint (l₁ ++ l₂) l ↔ Disjoint l₁ l ∧ Disjoint l₂ l := by simp [Disjoint, or_imp, forall_and] @[simp] theorem disjoint_append_right : Disjoint l (l₁ ++ l₂) ↔ Disjoint l l₁ ∧ Disjoint l l₂ := disjoint_comm.trans <| by rw [disjoint_append_left]; simp [disjoint_comm] @[simp] theorem disjoint_cons_left : Disjoint (a::l₁) l₂ ↔ (a ∉ l₂) ∧ Disjoint l₁ l₂ := (disjoint_append_left (l₁ := [a])).trans <| by simp [singleton_disjoint] @[simp] theorem disjoint_cons_right : Disjoint l₁ (a :: l₂) ↔ (a ∉ l₁) ∧ Disjoint l₁ l₂ := disjoint_comm.trans <| by rw [disjoint_cons_left]; simp [disjoint_comm] theorem disjoint_of_disjoint_append_left_left (d : Disjoint (l₁ ++ l₂) l) : Disjoint l₁ l := (disjoint_append_left.1 d).1 theorem disjoint_of_disjoint_append_left_right (d : Disjoint (l₁ ++ l₂) l) : Disjoint l₂ l := (disjoint_append_left.1 d).2 theorem disjoint_of_disjoint_append_right_left (d : Disjoint l (l₁ ++ l₂)) : Disjoint l l₁ := (disjoint_append_right.1 d).1 theorem disjoint_of_disjoint_append_right_right (d : Disjoint l (l₁ ++ l₂)) : Disjoint l l₂ := (disjoint_append_right.1 d).2 /-! ### foldl / foldr -/ theorem foldl_hom (f : α₁ → α₂) (g₁ : α₁ → β → α₁) (g₂ : α₂ → β → α₂) (l : List β) (init : α₁) (H : ∀ x y, g₂ (f x) y = f (g₁ x y)) : l.foldl g₂ (f init) = f (l.foldl g₁ init) := by induction l generalizing init <;> simp [*, H]
.lake/packages/batteries/Batteries/Data/List/Lemmas.lean
878
880
theorem foldr_hom (f : β₁ → β₂) (g₁ : α → β₁ → β₁) (g₂ : α → β₂ → β₂) (l : List α) (init : β₁) (H : ∀ x y, g₂ x (f y) = f (g₁ x y)) : l.foldr g₂ (f init) = f (l.foldr g₁ init) := by
induction l <;> simp [*, H]
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic #align_import analysis.convex.gauge from "leanprover-community/mathlib"@"373b03b5b9d0486534edbe94747f23cb3712f93d" /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r • s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {𝕜 E F : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r • s } #align gauge gauge variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl #align gauge_def gauge_def /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _ #align gauge_def' gauge_def' private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty := let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos ⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ #align absorbent.gauge_set_nonempty Absorbent.gauge_set_nonempty theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ => csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩ #align gauge_mono gauge_mono theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) : ∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h exact ⟨b, hb, hba, hx⟩ #align exists_lt_of_gauge_lt exists_lt_of_gauge_lt /-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s` but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/ @[simp] theorem gauge_zero : gauge s 0 = 0 := by rw [gauge_def'] by_cases h : (0 : E) ∈ s · simp only [smul_zero, sep_true, h, csInf_Ioi] · simp only [smul_zero, sep_false, h, Real.sInf_empty] #align gauge_zero gauge_zero @[simp] theorem gauge_zero' : gauge (0 : Set E) = 0 := by ext x rw [gauge_def'] obtain rfl | hx := eq_or_ne x 0 · simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] · simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero] convert Real.sInf_empty exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx #align gauge_zero' gauge_zero' @[simp] theorem gauge_empty : gauge (∅ : Set E) = 0 := by ext simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false] #align gauge_empty gauge_empty theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by obtain rfl | rfl := subset_singleton_iff_eq.1 h exacts [gauge_empty, gauge_zero'] #align gauge_of_subset_zero gauge_of_subset_zero /-- The gauge is always nonnegative. -/ theorem gauge_nonneg (x : E) : 0 ≤ gauge s x := Real.sInf_nonneg _ fun _ hx => hx.1.le #align gauge_nonneg gauge_nonneg theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩ simp_rw [gauge_def', smul_neg, this] #align gauge_neg gauge_neg theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by simp_rw [gauge_def', smul_neg, neg_mem_neg] #align gauge_neg_set_neg gauge_neg_set_neg theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by rw [← gauge_neg_set_neg, neg_neg] #align gauge_neg_set_eq_gauge_neg gauge_neg_set_eq_gauge_neg theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by obtain rfl | ha' := ha.eq_or_lt · rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero] · exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩ #align gauge_le_of_mem gauge_le_of_mem theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) : { x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by ext x simp_rw [Set.mem_iInter, Set.mem_setOf_eq] refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩ · have hr' := ha.trans_lt hr rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne'] obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr) suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩ rw [inv_mul_le_iff hr', mul_one] exact hδr.le · have hε' := (lt_add_iff_pos_right a).2 (half_pos hε) exact (gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _) #align gauge_le_eq gauge_le_eq theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ #align gauge_lt_eq' gauge_lt_eq' theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ #align gauge_lt_eq gauge_lt_eq theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) : ∃ y ∈ s, x ∈ openSegment ℝ 0 y := by rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩ refine ⟨y, hy, 1 - r, r, ?_⟩ simp [*] theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) : { x | gauge s x < 1 } ⊆ s := fun _x hx ↦ let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx hs.openSegment_subset h₀ hys hx #align gauge_lt_one_subset_self gauge_lt_one_subset_self theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 := gauge_le_of_mem zero_le_one <| by rwa [one_smul] #align gauge_le_one_of_mem gauge_le_one_of_mem /-- Gauge is subadditive. -/ theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) : gauge s (x + y) ≤ gauge s x + gauge s y := by refine le_of_forall_pos_lt_add fun ε hε => ?_ obtain ⟨a, ha, ha', x, hx, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε)) obtain ⟨b, hb, hb', y, hy, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε)) calc gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by rw [hs.add_smul ha.le hb.le] exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) _ < gauge s (a • x) + gauge s (b • y) + ε := by linarith #align gauge_add_le gauge_add_le theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem #align self_subset_gauge_le_one self_subset_gauge_le_one
Mathlib/Analysis/Convex/Gauge.lean
218
225
theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) : Convex ℝ { x | gauge s x ≤ a } := by
by_cases ha : 0 ≤ a · rw [gauge_le_eq hs h₀ absorbs ha] exact convex_iInter fun i => convex_iInter fun _ => hs.smul _ · -- Porting note: `convert` needed help convert convex_empty (𝕜 := ℝ) (E := E) exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.SetTheory.Ordinal.Basic import Mathlib.Topology.ContinuousFunction.Algebra import Mathlib.Topology.Compactness.Paracompact import Mathlib.Topology.ShrinkingLemma import Mathlib.Topology.UrysohnsLemma #align_import topology.partition_of_unity from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Continuous partition of unity In this file we define `PartitionOfUnity (ι X : Type*) [TopologicalSpace X] (s : Set X := univ)` to be a continuous partition of unity on `s` indexed by `ι`. More precisely, `f : PartitionOfUnity ι X s` is a collection of continuous functions `f i : C(X, ℝ)`, `i : ι`, such that * the supports of `f i` form a locally finite family of sets; * each `f i` is nonnegative; * `∑ᶠ i, f i x = 1` for all `x ∈ s`; * `∑ᶠ i, f i x ≤ 1` for all `x : X`. In the case `s = univ` the last assumption follows from the previous one but it is convenient to have this assumption in the case `s ≠ univ`. We also define a bump function covering, `BumpCovering (ι X : Type*) [TopologicalSpace X] (s : Set X := univ)`, to be a collection of functions `f i : C(X, ℝ)`, `i : ι`, such that * the supports of `f i` form a locally finite family of sets; * each `f i` is nonnegative; * for each `x ∈ s` there exists `i : ι` such that `f i y = 1` in a neighborhood of `x`. The term is motivated by the smooth case. If `f` is a bump function covering indexed by a linearly ordered type, then `g i x = f i x * ∏ᶠ j < i, (1 - f j x)` is a partition of unity, see `BumpCovering.toPartitionOfUnity`. Note that only finitely many terms `1 - f j x` are not equal to one, so this product is well-defined. Note that `g i x = ∏ᶠ j ≤ i, (1 - f j x) - ∏ᶠ j < i, (1 - f j x)`, so most terms in the sum `∑ᶠ i, g i x` cancel, and we get `∑ᶠ i, g i x = 1 - ∏ᶠ i, (1 - f i x)`, and the latter product equals zero because one of `f i x` is equal to one. We say that a partition of unity or a bump function covering `f` is *subordinate* to a family of sets `U i`, `i : ι`, if the closure of the support of each `f i` is included in `U i`. We use Urysohn's Lemma to prove that a locally finite open covering of a normal topological space admits a subordinate bump function covering (hence, a subordinate partition of unity), see `BumpCovering.exists_isSubordinate_of_locallyFinite`. If `X` is a paracompact space, then any open covering admits a locally finite refinement, hence it admits a subordinate bump function covering and a subordinate partition of unity, see `BumpCovering.exists_isSubordinate`. We also provide two slightly more general versions of these lemmas, `BumpCovering.exists_isSubordinate_of_locallyFinite_of_prop` and `BumpCovering.exists_isSubordinate_of_prop`, to be used later in the construction of a smooth partition of unity. ## Implementation notes Most (if not all) books only define a partition of unity of the whole space. However, quite a few proofs only deal with `f i` such that `tsupport (f i)` meets a specific closed subset, and it is easier to formalize these proofs if we don't have other functions right away. We use `WellOrderingRel j i` instead of `j < i` in the definition of `BumpCovering.toPartitionOfUnity` to avoid a `[LinearOrder ι]` assumption. While `WellOrderingRel j i` is a well order, not only a strict linear order, we never use this property. ## Tags partition of unity, bump function, Urysohn's lemma, normal space, paracompact space -/ universe u v open Function Set Filter open scoped Classical open Topology noncomputable section /-- A continuous partition of unity on a set `s : Set X` is a collection of continuous functions `f i` such that * the supports of `f i` form a locally finite family of sets, i.e., for every point `x : X` there exists a neighborhood `U ∋ x` such that all but finitely many functions `f i` are zero on `U`; * the functions `f i` are nonnegative; * the sum `∑ᶠ i, f i x` is equal to one for every `x ∈ s` and is less than or equal to one otherwise. If `X` is a normal paracompact space, then `PartitionOfUnity.exists_isSubordinate` guarantees that for every open covering `U : Set (Set X)` of `s` there exists a partition of unity that is subordinate to `U`. -/ structure PartitionOfUnity (ι X : Type*) [TopologicalSpace X] (s : Set X := univ) where toFun : ι → C(X, ℝ) locallyFinite' : LocallyFinite fun i => support (toFun i) nonneg' : 0 ≤ toFun sum_eq_one' : ∀ x ∈ s, ∑ᶠ i, toFun i x = 1 sum_le_one' : ∀ x, ∑ᶠ i, toFun i x ≤ 1 #align partition_of_unity PartitionOfUnity /-- A `BumpCovering ι X s` is an indexed family of functions `f i`, `i : ι`, such that * the supports of `f i` form a locally finite family of sets, i.e., for every point `x : X` there exists a neighborhood `U ∋ x` such that all but finitely many functions `f i` are zero on `U`; * for all `i`, `x` we have `0 ≤ f i x ≤ 1`; * each point `x ∈ s` belongs to the interior of `{x | f i x = 1}` for some `i`. One of the main use cases for a `BumpCovering` is to define a `PartitionOfUnity`, see `BumpCovering.toPartitionOfUnity`, but some proofs can directly use a `BumpCovering` instead of a `PartitionOfUnity`. If `X` is a normal paracompact space, then `BumpCovering.exists_isSubordinate` guarantees that for every open covering `U : Set (Set X)` of `s` there exists a `BumpCovering` of `s` that is subordinate to `U`. -/ structure BumpCovering (ι X : Type*) [TopologicalSpace X] (s : Set X := univ) where toFun : ι → C(X, ℝ) locallyFinite' : LocallyFinite fun i => support (toFun i) nonneg' : 0 ≤ toFun le_one' : toFun ≤ 1 eventuallyEq_one' : ∀ x ∈ s, ∃ i, toFun i =ᶠ[𝓝 x] 1 #align bump_covering BumpCovering variable {ι : Type u} {X : Type v} [TopologicalSpace X] namespace PartitionOfUnity variable {E : Type*} [AddCommMonoid E] [SMulWithZero ℝ E] [TopologicalSpace E] [ContinuousSMul ℝ E] {s : Set X} (f : PartitionOfUnity ι X s) instance : FunLike (PartitionOfUnity ι X s) ι C(X, ℝ) where coe := toFun coe_injective' := fun f g h ↦ by cases f; cases g; congr protected theorem locallyFinite : LocallyFinite fun i => support (f i) := f.locallyFinite' #align partition_of_unity.locally_finite PartitionOfUnity.locallyFinite theorem locallyFinite_tsupport : LocallyFinite fun i => tsupport (f i) := f.locallyFinite.closure #align partition_of_unity.locally_finite_tsupport PartitionOfUnity.locallyFinite_tsupport theorem nonneg (i : ι) (x : X) : 0 ≤ f i x := f.nonneg' i x #align partition_of_unity.nonneg PartitionOfUnity.nonneg theorem sum_eq_one {x : X} (hx : x ∈ s) : ∑ᶠ i, f i x = 1 := f.sum_eq_one' x hx #align partition_of_unity.sum_eq_one PartitionOfUnity.sum_eq_one /-- If `f` is a partition of unity on `s`, then for every `x ∈ s` there exists an index `i` such that `0 < f i x`. -/ theorem exists_pos {x : X} (hx : x ∈ s) : ∃ i, 0 < f i x := by have H := f.sum_eq_one hx contrapose! H simpa only [fun i => (H i).antisymm (f.nonneg i x), finsum_zero] using zero_ne_one #align partition_of_unity.exists_pos PartitionOfUnity.exists_pos theorem sum_le_one (x : X) : ∑ᶠ i, f i x ≤ 1 := f.sum_le_one' x #align partition_of_unity.sum_le_one PartitionOfUnity.sum_le_one theorem sum_nonneg (x : X) : 0 ≤ ∑ᶠ i, f i x := finsum_nonneg fun i => f.nonneg i x #align partition_of_unity.sum_nonneg PartitionOfUnity.sum_nonneg theorem le_one (i : ι) (x : X) : f i x ≤ 1 := (single_le_finsum i (f.locallyFinite.point_finite x) fun j => f.nonneg j x).trans (f.sum_le_one x) #align partition_of_unity.le_one PartitionOfUnity.le_one section finsupport variable {s : Set X} (ρ : PartitionOfUnity ι X s) (x₀ : X) /-- The support of a partition of unity at a point `x₀` as a `Finset`. This is the set of `i : ι` such that `x₀ ∈ support f i`, i.e. `f i ≠ x₀`. -/ def finsupport : Finset ι := (ρ.locallyFinite.point_finite x₀).toFinset @[simp] theorem mem_finsupport (x₀ : X) {i} : i ∈ ρ.finsupport x₀ ↔ i ∈ support fun i ↦ ρ i x₀ := by simp only [finsupport, mem_support, Finite.mem_toFinset, mem_setOf_eq] @[simp] theorem coe_finsupport (x₀ : X) : (ρ.finsupport x₀ : Set ι) = support fun i ↦ ρ i x₀ := by ext rw [Finset.mem_coe, mem_finsupport] variable {x₀ : X} theorem sum_finsupport (hx₀ : x₀ ∈ s) : ∑ i ∈ ρ.finsupport x₀, ρ i x₀ = 1 := by rw [← ρ.sum_eq_one hx₀, finsum_eq_sum_of_support_subset _ (ρ.coe_finsupport x₀).superset] theorem sum_finsupport' (hx₀ : x₀ ∈ s) {I : Finset ι} (hI : ρ.finsupport x₀ ⊆ I) : ∑ i ∈ I, ρ i x₀ = 1 := by classical rw [← Finset.sum_sdiff hI, ρ.sum_finsupport hx₀] suffices ∑ i ∈ I \ ρ.finsupport x₀, (ρ i) x₀ = ∑ i ∈ I \ ρ.finsupport x₀, 0 by rw [this, add_left_eq_self, Finset.sum_const_zero] apply Finset.sum_congr rfl rintro x hx simp only [Finset.mem_sdiff, ρ.mem_finsupport, mem_support, Classical.not_not] at hx exact hx.2 theorem sum_finsupport_smul_eq_finsum {M : Type*} [AddCommGroup M] [Module ℝ M] (φ : ι → X → M) : ∑ i ∈ ρ.finsupport x₀, ρ i x₀ • φ i x₀ = ∑ᶠ i, ρ i x₀ • φ i x₀ := by apply (finsum_eq_sum_of_support_subset _ _).symm have : (fun i ↦ (ρ i) x₀ • φ i x₀) = (fun i ↦ (ρ i) x₀) • (fun i ↦ φ i x₀) := funext fun _ => (Pi.smul_apply' _ _ _).symm rw [ρ.coe_finsupport x₀, this, support_smul] exact inter_subset_left end finsupport section fintsupport -- partitions of unity have locally finite `tsupport` variable {s : Set X} (ρ : PartitionOfUnity ι X s) (x₀ : X) /-- The `tsupport`s of a partition of unity are locally finite. -/ theorem finite_tsupport : {i | x₀ ∈ tsupport (ρ i)}.Finite := by rcases ρ.locallyFinite x₀ with ⟨t, t_in, ht⟩ apply ht.subset rintro i hi simp only [inter_comm] exact mem_closure_iff_nhds.mp hi t t_in /-- The tsupport of a partition of unity at a point `x₀` as a `Finset`. This is the set of `i : ι` such that `x₀ ∈ tsupport f i`. -/ def fintsupport (x₀ : X) : Finset ι := (ρ.finite_tsupport x₀).toFinset theorem mem_fintsupport_iff (i : ι) : i ∈ ρ.fintsupport x₀ ↔ x₀ ∈ tsupport (ρ i) := Finite.mem_toFinset _ theorem eventually_fintsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.fintsupport y ⊆ ρ.fintsupport x₀ := by apply (ρ.locallyFinite.closure.eventually_subset (fun _ ↦ isClosed_closure) x₀).mono intro y hy z hz rw [PartitionOfUnity.mem_fintsupport_iff] at * exact hy hz theorem finsupport_subset_fintsupport : ρ.finsupport x₀ ⊆ ρ.fintsupport x₀ := fun i hi ↦ by rw [ρ.mem_fintsupport_iff] apply subset_closure exact (ρ.mem_finsupport x₀).mp hi theorem eventually_finsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.finsupport y ⊆ ρ.fintsupport x₀ := (ρ.eventually_fintsupport_subset x₀).mono fun y hy ↦ (ρ.finsupport_subset_fintsupport y).trans hy end fintsupport /-- If `f` is a partition of unity on `s : Set X` and `g : X → E` is continuous at every point of the topological support of some `f i`, then `fun x ↦ f i x • g x` is continuous on the whole space. -/ theorem continuous_smul {g : X → E} {i : ι} (hg : ∀ x ∈ tsupport (f i), ContinuousAt g x) : Continuous fun x => f i x • g x := continuous_of_tsupport fun x hx => ((f i).continuousAt x).smul <| hg x <| tsupport_smul_subset_left _ _ hx #align partition_of_unity.continuous_smul PartitionOfUnity.continuous_smul /-- If `f` is a partition of unity on a set `s : Set X` and `g : ι → X → E` is a family of functions such that each `g i` is continuous at every point of the topological support of `f i`, then the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is continuous on the whole space. -/ theorem continuous_finsum_smul [ContinuousAdd E] {g : ι → X → E} (hg : ∀ (i), ∀ x ∈ tsupport (f i), ContinuousAt (g i) x) : Continuous fun x => ∑ᶠ i, f i x • g i x := (continuous_finsum fun i => f.continuous_smul (hg i)) <| f.locallyFinite.subset fun _ => support_smul_subset_left _ _ #align partition_of_unity.continuous_finsum_smul PartitionOfUnity.continuous_finsum_smul /-- A partition of unity `f i` is subordinate to a family of sets `U i` indexed by the same type if for each `i` the closure of the support of `f i` is a subset of `U i`. -/ def IsSubordinate (U : ι → Set X) : Prop := ∀ i, tsupport (f i) ⊆ U i #align partition_of_unity.is_subordinate PartitionOfUnity.IsSubordinate variable {f} theorem exists_finset_nhd' {s : Set X} (ρ : PartitionOfUnity ι X s) (x₀ : X) : ∃ I : Finset ι, (∀ᶠ x in 𝓝[s] x₀, ∑ i ∈ I, ρ i x = 1) ∧ ∀ᶠ x in 𝓝 x₀, support (ρ · x) ⊆ I := by rcases ρ.locallyFinite.exists_finset_support x₀ with ⟨I, hI⟩ refine ⟨I, eventually_nhdsWithin_iff.mpr (hI.mono fun x hx x_in ↦ ?_), hI⟩ have : ∑ᶠ i : ι, ρ i x = ∑ i ∈ I, ρ i x := finsum_eq_sum_of_support_subset _ hx rwa [eq_comm, ρ.sum_eq_one x_in] at this theorem exists_finset_nhd (ρ : PartitionOfUnity ι X univ) (x₀ : X) : ∃ I : Finset ι, ∀ᶠ x in 𝓝 x₀, ∑ i ∈ I, ρ i x = 1 ∧ support (ρ · x) ⊆ I := by rcases ρ.exists_finset_nhd' x₀ with ⟨I, H⟩ use I rwa [nhdsWithin_univ, ← eventually_and] at H theorem exists_finset_nhd_support_subset {U : ι → Set X} (hso : f.IsSubordinate U) (ho : ∀ i, IsOpen (U i)) (x : X) : ∃ is : Finset ι, ∃ n ∈ 𝓝 x, n ⊆ ⋂ i ∈ is, U i ∧ ∀ z ∈ n, (support (f · z)) ⊆ is := f.locallyFinite.exists_finset_nhd_support_subset hso ho x #align partition_of_unity.exists_finset_nhd_support_subset PartitionOfUnity.exists_finset_nhd_support_subset /-- If `f` is a partition of unity that is subordinate to a family of open sets `U i` and `g : ι → X → E` is a family of functions such that each `g i` is continuous on `U i`, then the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is a continuous function. -/ theorem IsSubordinate.continuous_finsum_smul [ContinuousAdd E] {U : ι → Set X} (ho : ∀ i, IsOpen (U i)) (hf : f.IsSubordinate U) {g : ι → X → E} (hg : ∀ i, ContinuousOn (g i) (U i)) : Continuous fun x => ∑ᶠ i, f i x • g i x := f.continuous_finsum_smul fun i _ hx => (hg i).continuousAt <| (ho i).mem_nhds <| hf i hx #align partition_of_unity.is_subordinate.continuous_finsum_smul PartitionOfUnity.IsSubordinate.continuous_finsum_smul end PartitionOfUnity namespace BumpCovering variable {s : Set X} (f : BumpCovering ι X s) instance : FunLike (BumpCovering ι X s) ι C(X, ℝ) where coe := toFun coe_injective' := fun f g h ↦ by cases f; cases g; congr protected theorem locallyFinite : LocallyFinite fun i => support (f i) := f.locallyFinite' #align bump_covering.locally_finite BumpCovering.locallyFinite theorem locallyFinite_tsupport : LocallyFinite fun i => tsupport (f i) := f.locallyFinite.closure #align bump_covering.locally_finite_tsupport BumpCovering.locallyFinite_tsupport protected theorem point_finite (x : X) : { i | f i x ≠ 0 }.Finite := f.locallyFinite.point_finite x #align bump_covering.point_finite BumpCovering.point_finite theorem nonneg (i : ι) (x : X) : 0 ≤ f i x := f.nonneg' i x #align bump_covering.nonneg BumpCovering.nonneg theorem le_one (i : ι) (x : X) : f i x ≤ 1 := f.le_one' i x #align bump_covering.le_one BumpCovering.le_one /-- A `BumpCovering` that consists of a single function, uniformly equal to one, defined as an example for `Inhabited` instance. -/ protected def single (i : ι) (s : Set X) : BumpCovering ι X s where toFun := Pi.single i 1 locallyFinite' x := by refine ⟨univ, univ_mem, (finite_singleton i).subset ?_⟩ rintro j ⟨x, hx, -⟩ contrapose! hx rw [mem_singleton_iff] at hx simp [hx] nonneg' := le_update_iff.2 ⟨fun x => zero_le_one, fun _ _ => le_rfl⟩ le_one' := update_le_iff.2 ⟨le_rfl, fun _ _ _ => zero_le_one⟩ eventuallyEq_one' x _ := ⟨i, by rw [Pi.single_eq_same, ContinuousMap.coe_one]⟩ #align bump_covering.single BumpCovering.single @[simp] theorem coe_single (i : ι) (s : Set X) : ⇑(BumpCovering.single i s) = Pi.single i 1 := rfl #align bump_covering.coe_single BumpCovering.coe_single instance [Inhabited ι] : Inhabited (BumpCovering ι X s) := ⟨BumpCovering.single default s⟩ /-- A collection of bump functions `f i` is subordinate to a family of sets `U i` indexed by the same type if for each `i` the closure of the support of `f i` is a subset of `U i`. -/ def IsSubordinate (f : BumpCovering ι X s) (U : ι → Set X) : Prop := ∀ i, tsupport (f i) ⊆ U i #align bump_covering.is_subordinate BumpCovering.IsSubordinate theorem IsSubordinate.mono {f : BumpCovering ι X s} {U V : ι → Set X} (hU : f.IsSubordinate U) (hV : ∀ i, U i ⊆ V i) : f.IsSubordinate V := fun i => Subset.trans (hU i) (hV i) #align bump_covering.is_subordinate.mono BumpCovering.IsSubordinate.mono /-- If `X` is a normal topological space and `U i`, `i : ι`, is a locally finite open covering of a closed set `s`, then there exists a `BumpCovering ι X s` that is subordinate to `U`. If `X` is a paracompact space, then the assumption `hf : LocallyFinite U` can be omitted, see `BumpCovering.exists_isSubordinate`. This version assumes that `p : (X → ℝ) → Prop` is a predicate that satisfies Urysohn's lemma, and provides a `BumpCovering` such that each function of the covering satisfies `p`. -/
Mathlib/Topology/PartitionOfUnity.lean
387
406
theorem exists_isSubordinate_of_locallyFinite_of_prop [NormalSpace X] (p : (X → ℝ) → Prop) (h01 : ∀ s t, IsClosed s → IsClosed t → Disjoint s t → ∃ f : C(X, ℝ), p f ∧ EqOn f 0 s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1) (hs : IsClosed s) (U : ι → Set X) (ho : ∀ i, IsOpen (U i)) (hf : LocallyFinite U) (hU : s ⊆ ⋃ i, U i) : ∃ f : BumpCovering ι X s, (∀ i, p (f i)) ∧ f.IsSubordinate U := by
rcases exists_subset_iUnion_closure_subset hs ho (fun x _ => hf.point_finite x) hU with ⟨V, hsV, hVo, hVU⟩ have hVU' : ∀ i, V i ⊆ U i := fun i => Subset.trans subset_closure (hVU i) rcases exists_subset_iUnion_closure_subset hs hVo (fun x _ => (hf.subset hVU').point_finite x) hsV with ⟨W, hsW, hWo, hWV⟩ choose f hfp hf0 hf1 hf01 using fun i => h01 _ _ (isClosed_compl_iff.2 <| hVo i) isClosed_closure (disjoint_right.2 fun x hx => Classical.not_not.2 (hWV i hx)) have hsupp : ∀ i, support (f i) ⊆ V i := fun i => support_subset_iff'.2 (hf0 i) refine ⟨⟨f, hf.subset fun i => Subset.trans (hsupp i) (hVU' i), fun i x => (hf01 i x).1, fun i x => (hf01 i x).2, fun x hx => ?_⟩, hfp, fun i => Subset.trans (closure_mono (hsupp i)) (hVU i)⟩ rcases mem_iUnion.1 (hsW hx) with ⟨i, hi⟩ exact ⟨i, ((hf1 i).mono subset_closure).eventuallyEq_of_mem ((hWo i).mem_nhds hi)⟩
/- Copyright (c) 2023 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll, Sébastien Gouëzel, Jireh Loreaux -/ import Mathlib.Analysis.MeanInequalities import Mathlib.Analysis.NormedSpace.WithLp /-! # `L^p` distance on products of two metric spaces Given two metric spaces, one can put the max distance on their product, but there is also a whole family of natural distances, indexed by a parameter `p : ℝ≥0∞`, that also induce the product topology. We define them in this file. For `0 < p < ∞`, the distance on `α × β` is given by $$ d(x, y) = \left(d(x_1, y_1)^p + d(x_2, y_2)^p\right)^{1/p}. $$ For `p = ∞` the distance is the supremum of the distances and `p = 0` the distance is the cardinality of the elements that are not equal. We give instances of this construction for emetric spaces, metric spaces, normed groups and normed spaces. To avoid conflicting instances, all these are defined on a copy of the original Prod-type, named `WithLp p (α × β)`. The assumption `[Fact (1 ≤ p)]` is required for the metric and normed space instances. We ensure that the topology, bornology and uniform structure on `WithLp p (α × β)` are (defeq to) the product topology, product bornology and product uniformity, to be able to use freely continuity statements for the coordinate functions, for instance. # Implementation notes This files is a straight-forward adaption of `Mathlib.Analysis.NormedSpace.PiLp`. -/ open Real Set Filter RCLike Bornology Uniformity Topology NNReal ENNReal noncomputable section variable (p : ℝ≥0∞) (𝕜 α β : Type*) namespace WithLp section algebra /- Register simplification lemmas for the applications of `WithLp p (α × β)` elements, as the usual lemmas for `Prod` will not trigger. -/ variable {p 𝕜 α β} variable [Semiring 𝕜] [AddCommGroup α] [AddCommGroup β] variable (x y : WithLp p (α × β)) (c : 𝕜) @[simp] theorem zero_fst : (0 : WithLp p (α × β)).fst = 0 := rfl @[simp] theorem zero_snd : (0 : WithLp p (α × β)).snd = 0 := rfl @[simp] theorem add_fst : (x + y).fst = x.fst + y.fst := rfl @[simp] theorem add_snd : (x + y).snd = x.snd + y.snd := rfl @[simp] theorem sub_fst : (x - y).fst = x.fst - y.fst := rfl @[simp] theorem sub_snd : (x - y).snd = x.snd - y.snd := rfl @[simp] theorem neg_fst : (-x).fst = -x.fst := rfl @[simp] theorem neg_snd : (-x).snd = -x.snd := rfl variable [Module 𝕜 α] [Module 𝕜 β] @[simp] theorem smul_fst : (c • x).fst = c • x.fst := rfl @[simp] theorem smul_snd : (c • x).snd = c • x.snd := rfl end algebra /-! Note that the unapplied versions of these lemmas are deliberately omitted, as they break the use of the type synonym. -/ section equiv variable {p α β} @[simp] theorem equiv_fst (x : WithLp p (α × β)) : (WithLp.equiv p (α × β) x).fst = x.fst := rfl @[simp] theorem equiv_snd (x : WithLp p (α × β)) : (WithLp.equiv p (α × β) x).snd = x.snd := rfl @[simp] theorem equiv_symm_fst (x : α × β) : ((WithLp.equiv p (α × β)).symm x).fst = x.fst := rfl @[simp] theorem equiv_symm_snd (x : α × β) : ((WithLp.equiv p (α × β)).symm x).snd = x.snd := rfl end equiv section DistNorm /-! ### Definition of `edist`, `dist` and `norm` on `WithLp p (α × β)` In this section we define the `edist`, `dist` and `norm` functions on `WithLp p (α × β)` without assuming `[Fact (1 ≤ p)]` or metric properties of the spaces `α` and `β`. This allows us to provide the rewrite lemmas for each of three cases `p = 0`, `p = ∞` and `0 < p.toReal`. -/ section EDist variable [EDist α] [EDist β] open scoped Classical in /-- Endowing the space `WithLp p (α × β)` with the `L^p` edistance. We register this instance separate from `WithLp.instProdPseudoEMetric` since the latter requires the type class hypothesis `[Fact (1 ≤ p)]` in order to prove the triangle inequality. Registering this separately allows for a future emetric-like structure on `WithLp p (α × β)` for `p < 1` satisfying a relaxed triangle inequality. The terminology for this varies throughout the literature, but it is sometimes called a *quasi-metric* or *semi-metric*. -/ instance instProdEDist : EDist (WithLp p (α × β)) where edist f g := if _hp : p = 0 then (if edist f.fst g.fst = 0 then 0 else 1) + (if edist f.snd g.snd = 0 then 0 else 1) else if p = ∞ then edist f.fst g.fst ⊔ edist f.snd g.snd else (edist f.fst g.fst ^ p.toReal + edist f.snd g.snd ^ p.toReal) ^ (1 / p.toReal) variable {p α β} variable (x y : WithLp p (α × β)) (x' : α × β) @[simp] theorem prod_edist_eq_card (f g : WithLp 0 (α × β)) : edist f g = (if edist f.fst g.fst = 0 then 0 else 1) + (if edist f.snd g.snd = 0 then 0 else 1) := by convert if_pos rfl theorem prod_edist_eq_add (hp : 0 < p.toReal) (f g : WithLp p (α × β)) : edist f g = (edist f.fst g.fst ^ p.toReal + edist f.snd g.snd ^ p.toReal) ^ (1 / p.toReal) := let hp' := ENNReal.toReal_pos_iff.mp hp (if_neg hp'.1.ne').trans (if_neg hp'.2.ne) theorem prod_edist_eq_sup (f g : WithLp ∞ (α × β)) : edist f g = edist f.fst g.fst ⊔ edist f.snd g.snd := by dsimp [edist] exact if_neg ENNReal.top_ne_zero end EDist section EDistProp variable {α β} variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] /-- The distance from one point to itself is always zero. This holds independent of `p` and does not require `[Fact (1 ≤ p)]`. We keep it separate from `WithLp.instProdPseudoEMetricSpace` so it can be used also for `p < 1`. -/ theorem prod_edist_self (f : WithLp p (α × β)) : edist f f = 0 := by rcases p.trichotomy with (rfl | rfl | h) · classical simp · simp [prod_edist_eq_sup] · simp [prod_edist_eq_add h, ENNReal.zero_rpow_of_pos h, ENNReal.zero_rpow_of_pos (inv_pos.2 <| h)] /-- The distance is symmetric. This holds independent of `p` and does not require `[Fact (1 ≤ p)]`. We keep it separate from `WithLp.instProdPseudoEMetricSpace` so it can be used also for `p < 1`. -/ theorem prod_edist_comm (f g : WithLp p (α × β)) : edist f g = edist g f := by classical rcases p.trichotomy with (rfl | rfl | h) · simp only [prod_edist_eq_card, edist_comm] · simp only [prod_edist_eq_sup, edist_comm] · simp only [prod_edist_eq_add h, edist_comm] end EDistProp section Dist variable [Dist α] [Dist β] open scoped Classical in /-- Endowing the space `WithLp p (α × β)` with the `L^p` distance. We register this instance separate from `WithLp.instProdPseudoMetricSpace` since the latter requires the type class hypothesis `[Fact (1 ≤ p)]` in order to prove the triangle inequality. Registering this separately allows for a future metric-like structure on `WithLp p (α × β)` for `p < 1` satisfying a relaxed triangle inequality. The terminology for this varies throughout the literature, but it is sometimes called a *quasi-metric* or *semi-metric*. -/ instance instProdDist : Dist (WithLp p (α × β)) where dist f g := if _hp : p = 0 then (if dist f.fst g.fst = 0 then 0 else 1) + (if dist f.snd g.snd = 0 then 0 else 1) else if p = ∞ then dist f.fst g.fst ⊔ dist f.snd g.snd else (dist f.fst g.fst ^ p.toReal + dist f.snd g.snd ^ p.toReal) ^ (1 / p.toReal) variable {p α β} theorem prod_dist_eq_card (f g : WithLp 0 (α × β)) : dist f g = (if dist f.fst g.fst = 0 then 0 else 1) + (if dist f.snd g.snd = 0 then 0 else 1) := by convert if_pos rfl theorem prod_dist_eq_add (hp : 0 < p.toReal) (f g : WithLp p (α × β)) : dist f g = (dist f.fst g.fst ^ p.toReal + dist f.snd g.snd ^ p.toReal) ^ (1 / p.toReal) := let hp' := ENNReal.toReal_pos_iff.mp hp (if_neg hp'.1.ne').trans (if_neg hp'.2.ne) theorem prod_dist_eq_sup (f g : WithLp ∞ (α × β)) : dist f g = dist f.fst g.fst ⊔ dist f.snd g.snd := by dsimp [dist] exact if_neg ENNReal.top_ne_zero end Dist section Norm variable [Norm α] [Norm β] open scoped Classical in /-- Endowing the space `WithLp p (α × β)` with the `L^p` norm. We register this instance separate from `WithLp.instProdSeminormedAddCommGroup` since the latter requires the type class hypothesis `[Fact (1 ≤ p)]` in order to prove the triangle inequality. Registering this separately allows for a future norm-like structure on `WithLp p (α × β)` for `p < 1` satisfying a relaxed triangle inequality. These are called *quasi-norms*. -/ instance instProdNorm : Norm (WithLp p (α × β)) where norm f := if _hp : p = 0 then (if ‖f.fst‖ = 0 then 0 else 1) + (if ‖f.snd‖ = 0 then 0 else 1) else if p = ∞ then ‖f.fst‖ ⊔ ‖f.snd‖ else (‖f.fst‖ ^ p.toReal + ‖f.snd‖ ^ p.toReal) ^ (1 / p.toReal) variable {p α β} @[simp] theorem prod_norm_eq_card (f : WithLp 0 (α × β)) : ‖f‖ = (if ‖f.fst‖ = 0 then 0 else 1) + (if ‖f.snd‖ = 0 then 0 else 1) := by convert if_pos rfl theorem prod_norm_eq_sup (f : WithLp ∞ (α × β)) : ‖f‖ = ‖f.fst‖ ⊔ ‖f.snd‖ := by dsimp [Norm.norm] exact if_neg ENNReal.top_ne_zero theorem prod_norm_eq_add (hp : 0 < p.toReal) (f : WithLp p (α × β)) : ‖f‖ = (‖f.fst‖ ^ p.toReal + ‖f.snd‖ ^ p.toReal) ^ (1 / p.toReal) := let hp' := ENNReal.toReal_pos_iff.mp hp (if_neg hp'.1.ne').trans (if_neg hp'.2.ne) end Norm end DistNorm section Aux /-! ### The uniformity on finite `L^p` products is the product uniformity In this section, we put the `L^p` edistance on `WithLp p (α × β)`, and we check that the uniformity coming from this edistance coincides with the product uniformity, by showing that the canonical map to the Prod type (with the `L^∞` distance) is a uniform embedding, as it is both Lipschitz and antiLipschitz. We only register this emetric space structure as a temporary instance, as the true instance (to be registered later) will have as uniformity exactly the product uniformity, instead of the one coming from the edistance (which is equal to it, but not defeq). See Note [forgetful inheritance] explaining why having definitionally the right uniformity is often important. -/ variable [hp : Fact (1 ≤ p)] /-- Endowing the space `WithLp p (α × β)` with the `L^p` pseudoemetric structure. This definition is not satisfactory, as it does not register the fact that the topology and the uniform structure coincide with the product one. Therefore, we do not register it as an instance. Using this as a temporary pseudoemetric space instance, we will show that the uniform structure is equal (but not defeq) to the product one, and then register an instance in which we replace the uniform structure by the product one using this pseudoemetric space and `PseudoEMetricSpace.replaceUniformity`. -/ def prodPseudoEMetricAux [PseudoEMetricSpace α] [PseudoEMetricSpace β] : PseudoEMetricSpace (WithLp p (α × β)) where edist_self := prod_edist_self p edist_comm := prod_edist_comm p edist_triangle f g h := by rcases p.dichotomy with (rfl | hp) · simp only [prod_edist_eq_sup] exact sup_le ((edist_triangle _ g.fst _).trans <| add_le_add le_sup_left le_sup_left) ((edist_triangle _ g.snd _).trans <| add_le_add le_sup_right le_sup_right) · simp only [prod_edist_eq_add (zero_lt_one.trans_le hp)] calc (edist f.fst h.fst ^ p.toReal + edist f.snd h.snd ^ p.toReal) ^ (1 / p.toReal) ≤ ((edist f.fst g.fst + edist g.fst h.fst) ^ p.toReal + (edist f.snd g.snd + edist g.snd h.snd) ^ p.toReal) ^ (1 / p.toReal) := by gcongr <;> apply edist_triangle _ ≤ (edist f.fst g.fst ^ p.toReal + edist f.snd g.snd ^ p.toReal) ^ (1 / p.toReal) + (edist g.fst h.fst ^ p.toReal + edist g.snd h.snd ^ p.toReal) ^ (1 / p.toReal) := by have := ENNReal.Lp_add_le {0, 1} (if · = 0 then edist f.fst g.fst else edist f.snd g.snd) (if · = 0 then edist g.fst h.fst else edist g.snd h.snd) hp simp only [Finset.mem_singleton, not_false_eq_true, Finset.sum_insert, Finset.sum_singleton] at this exact this attribute [local instance] WithLp.prodPseudoEMetricAux variable {α β} /-- An auxiliary lemma used twice in the proof of `WithLp.prodPseudoMetricAux` below. Not intended for use outside this file. -/ theorem prod_sup_edist_ne_top_aux [PseudoMetricSpace α] [PseudoMetricSpace β] (f g : WithLp ∞ (α × β)) : edist f.fst g.fst ⊔ edist f.snd g.snd ≠ ⊤ := ne_of_lt <| by simp [edist, PseudoMetricSpace.edist_dist] variable (α β) /-- Endowing the space `WithLp p (α × β)` with the `L^p` pseudometric structure. This definition is not satisfactory, as it does not register the fact that the topology, the uniform structure, and the bornology coincide with the product ones. Therefore, we do not register it as an instance. Using this as a temporary pseudoemetric space instance, we will show that the uniform structure is equal (but not defeq) to the product one, and then register an instance in which we replace the uniform structure and the bornology by the product ones using this pseudometric space, `PseudoMetricSpace.replaceUniformity`, and `PseudoMetricSpace.replaceBornology`. See note [reducible non-instances] -/ abbrev prodPseudoMetricAux [PseudoMetricSpace α] [PseudoMetricSpace β] : PseudoMetricSpace (WithLp p (α × β)) := PseudoEMetricSpace.toPseudoMetricSpaceOfDist dist (fun f g => by rcases p.dichotomy with (rfl | h) · exact prod_sup_edist_ne_top_aux f g · rw [prod_edist_eq_add (zero_lt_one.trans_le h)] refine ENNReal.rpow_ne_top_of_nonneg (by positivity) (ne_of_lt ?_) simp [ENNReal.add_lt_top, ENNReal.rpow_lt_top_of_nonneg, edist_ne_top] ) fun f g => by rcases p.dichotomy with (rfl | h) · rw [prod_edist_eq_sup, prod_dist_eq_sup] refine le_antisymm (sup_le ?_ ?_) ?_ · rw [← ENNReal.ofReal_le_iff_le_toReal (prod_sup_edist_ne_top_aux f g), ← PseudoMetricSpace.edist_dist] exact le_sup_left · rw [← ENNReal.ofReal_le_iff_le_toReal (prod_sup_edist_ne_top_aux f g), ← PseudoMetricSpace.edist_dist] exact le_sup_right · refine ENNReal.toReal_le_of_le_ofReal ?_ ?_ · simp only [ge_iff_le, le_sup_iff, dist_nonneg, or_self] · simp [edist, PseudoMetricSpace.edist_dist, ENNReal.ofReal_le_ofReal] · have h1 : edist f.fst g.fst ^ p.toReal ≠ ⊤ := ENNReal.rpow_ne_top_of_nonneg (zero_le_one.trans h) (edist_ne_top _ _) have h2 : edist f.snd g.snd ^ p.toReal ≠ ⊤ := ENNReal.rpow_ne_top_of_nonneg (zero_le_one.trans h) (edist_ne_top _ _) simp only [prod_edist_eq_add (zero_lt_one.trans_le h), dist_edist, ENNReal.toReal_rpow, prod_dist_eq_add (zero_lt_one.trans_le h), ← ENNReal.toReal_add h1 h2] attribute [local instance] WithLp.prodPseudoMetricAux
Mathlib/Analysis/NormedSpace/ProdLp.lean
390
410
theorem prod_lipschitzWith_equiv_aux [PseudoEMetricSpace α] [PseudoEMetricSpace β] : LipschitzWith 1 (WithLp.equiv p (α × β)) := by
intro x y rcases p.dichotomy with (rfl | h) · simp [edist] · have cancel : p.toReal * (1 / p.toReal) = 1 := mul_div_cancel₀ 1 (zero_lt_one.trans_le h).ne' rw [prod_edist_eq_add (zero_lt_one.trans_le h)] simp only [edist, forall_prop_of_true, one_mul, ENNReal.coe_one, ge_iff_le, sup_le_iff] constructor · calc edist x.fst y.fst ≤ (edist x.fst y.fst ^ p.toReal) ^ (1 / p.toReal) := by simp only [← ENNReal.rpow_mul, cancel, ENNReal.rpow_one, le_refl] _ ≤ (edist x.fst y.fst ^ p.toReal + edist x.snd y.snd ^ p.toReal) ^ (1 / p.toReal) := by gcongr simp only [self_le_add_right] · calc edist x.snd y.snd ≤ (edist x.snd y.snd ^ p.toReal) ^ (1 / p.toReal) := by simp only [← ENNReal.rpow_mul, cancel, ENNReal.rpow_one, le_refl] _ ≤ (edist x.fst y.fst ^ p.toReal + edist x.snd y.snd ^ p.toReal) ^ (1 / p.toReal) := by gcongr simp only [self_le_add_left]
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Mul import Mathlib.Analysis.Calculus.Deriv.Inverse #align_import analysis.calculus.cont_diff from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Higher differentiability of usual operations We prove that the usual operations (addition, multiplication, difference, composition, and so on) preserve `C^n` functions. We also expand the API around `C^n` functions. ## Main results * `ContDiff.comp` states that the composition of two `C^n` functions is `C^n`. Similar results are given for `C^n` functions on domains. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `⊤ : ℕ∞` with `∞`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open scoped Classical NNReal Nat local notation "∞" => (⊤ : ℕ∞) universe u v w uD uE uF uG attribute [local instance 1001] NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid open Set Fin Filter Function open scoped Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {D : Type uD} [NormedAddCommGroup D] [NormedSpace 𝕜 D] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type*} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {b : E × F → G} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Constants -/ @[simp] theorem iteratedFDerivWithin_zero_fun (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} : iteratedFDerivWithin 𝕜 i (fun _ : E ↦ (0 : F)) s x = 0 := by induction i generalizing x with | zero => ext; simp | succ i IH => ext m rw [iteratedFDerivWithin_succ_apply_left, fderivWithin_congr (fun _ ↦ IH) (IH hx)] rw [fderivWithin_const_apply _ (hs x hx)] rfl @[simp] theorem iteratedFDeriv_zero_fun {n : ℕ} : (iteratedFDeriv 𝕜 n fun _ : E ↦ (0 : F)) = 0 := funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_zero_fun uniqueDiffOn_univ (mem_univ x) #align iterated_fderiv_zero_fun iteratedFDeriv_zero_fun theorem contDiff_zero_fun : ContDiff 𝕜 n fun _ : E => (0 : F) := contDiff_of_differentiable_iteratedFDeriv fun m _ => by rw [iteratedFDeriv_zero_fun] exact differentiable_const (0 : E[×m]→L[𝕜] F) #align cont_diff_zero_fun contDiff_zero_fun /-- Constants are `C^∞`. -/ theorem contDiff_const {c : F} : ContDiff 𝕜 n fun _ : E => c := by suffices h : ContDiff 𝕜 ∞ fun _ : E => c from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟨differentiable_const c, ?_⟩ rw [fderiv_const] exact contDiff_zero_fun #align cont_diff_const contDiff_const theorem contDiffOn_const {c : F} {s : Set E} : ContDiffOn 𝕜 n (fun _ : E => c) s := contDiff_const.contDiffOn #align cont_diff_on_const contDiffOn_const theorem contDiffAt_const {c : F} : ContDiffAt 𝕜 n (fun _ : E => c) x := contDiff_const.contDiffAt #align cont_diff_at_const contDiffAt_const theorem contDiffWithinAt_const {c : F} : ContDiffWithinAt 𝕜 n (fun _ : E => c) s x := contDiffAt_const.contDiffWithinAt #align cont_diff_within_at_const contDiffWithinAt_const @[nontriviality] theorem contDiff_of_subsingleton [Subsingleton F] : ContDiff 𝕜 n f := by rw [Subsingleton.elim f fun _ => 0]; exact contDiff_const #align cont_diff_of_subsingleton contDiff_of_subsingleton @[nontriviality] theorem contDiffAt_of_subsingleton [Subsingleton F] : ContDiffAt 𝕜 n f x := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffAt_const #align cont_diff_at_of_subsingleton contDiffAt_of_subsingleton @[nontriviality] theorem contDiffWithinAt_of_subsingleton [Subsingleton F] : ContDiffWithinAt 𝕜 n f s x := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffWithinAt_const #align cont_diff_within_at_of_subsingleton contDiffWithinAt_of_subsingleton @[nontriviality] theorem contDiffOn_of_subsingleton [Subsingleton F] : ContDiffOn 𝕜 n f s := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffOn_const #align cont_diff_on_of_subsingleton contDiffOn_of_subsingleton theorem iteratedFDerivWithin_succ_const (n : ℕ) (c : F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 (n + 1) (fun _ : E ↦ c) s x = 0 := by ext m rw [iteratedFDerivWithin_succ_apply_right hs hx] rw [iteratedFDerivWithin_congr (fun y hy ↦ fderivWithin_const_apply c (hs y hy)) hx] rw [iteratedFDerivWithin_zero_fun hs hx] simp [ContinuousMultilinearMap.zero_apply (R := 𝕜)] theorem iteratedFDeriv_succ_const (n : ℕ) (c : F) : (iteratedFDeriv 𝕜 (n + 1) fun _ : E ↦ c) = 0 := funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_succ_const n c uniqueDiffOn_univ (mem_univ x) #align iterated_fderiv_succ_const iteratedFDeriv_succ_const theorem iteratedFDerivWithin_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 n (fun _ : E ↦ c) s x = 0 := by cases n with | zero => contradiction | succ n => exact iteratedFDerivWithin_succ_const n c hs hx theorem iteratedFDeriv_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) : (iteratedFDeriv 𝕜 n fun _ : E ↦ c) = 0 := funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_const_of_ne hn c uniqueDiffOn_univ (mem_univ x) #align iterated_fderiv_const_of_ne iteratedFDeriv_const_of_ne /-! ### Smoothness of linear functions -/ /-- Unbundled bounded linear functions are `C^∞`. -/ theorem IsBoundedLinearMap.contDiff (hf : IsBoundedLinearMap 𝕜 f) : ContDiff 𝕜 n f := by suffices h : ContDiff 𝕜 ∞ f from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟨hf.differentiable, ?_⟩ simp_rw [hf.fderiv] exact contDiff_const #align is_bounded_linear_map.cont_diff IsBoundedLinearMap.contDiff theorem ContinuousLinearMap.contDiff (f : E →L[𝕜] F) : ContDiff 𝕜 n f := f.isBoundedLinearMap.contDiff #align continuous_linear_map.cont_diff ContinuousLinearMap.contDiff theorem ContinuousLinearEquiv.contDiff (f : E ≃L[𝕜] F) : ContDiff 𝕜 n f := (f : E →L[𝕜] F).contDiff #align continuous_linear_equiv.cont_diff ContinuousLinearEquiv.contDiff theorem LinearIsometry.contDiff (f : E →ₗᵢ[𝕜] F) : ContDiff 𝕜 n f := f.toContinuousLinearMap.contDiff #align linear_isometry.cont_diff LinearIsometry.contDiff theorem LinearIsometryEquiv.contDiff (f : E ≃ₗᵢ[𝕜] F) : ContDiff 𝕜 n f := (f : E →L[𝕜] F).contDiff #align linear_isometry_equiv.cont_diff LinearIsometryEquiv.contDiff /-- The identity is `C^∞`. -/ theorem contDiff_id : ContDiff 𝕜 n (id : E → E) := IsBoundedLinearMap.id.contDiff #align cont_diff_id contDiff_id theorem contDiffWithinAt_id {s x} : ContDiffWithinAt 𝕜 n (id : E → E) s x := contDiff_id.contDiffWithinAt #align cont_diff_within_at_id contDiffWithinAt_id theorem contDiffAt_id {x} : ContDiffAt 𝕜 n (id : E → E) x := contDiff_id.contDiffAt #align cont_diff_at_id contDiffAt_id theorem contDiffOn_id {s} : ContDiffOn 𝕜 n (id : E → E) s := contDiff_id.contDiffOn #align cont_diff_on_id contDiffOn_id /-- Bilinear functions are `C^∞`. -/ theorem IsBoundedBilinearMap.contDiff (hb : IsBoundedBilinearMap 𝕜 b) : ContDiff 𝕜 n b := by suffices h : ContDiff 𝕜 ∞ b from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟨hb.differentiable, ?_⟩ simp only [hb.fderiv] exact hb.isBoundedLinearMap_deriv.contDiff #align is_bounded_bilinear_map.cont_diff IsBoundedBilinearMap.contDiff /-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `g ∘ f` admits a Taylor series whose `k`-th term is given by `g ∘ (p k)`. -/ theorem HasFTaylorSeriesUpToOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : HasFTaylorSeriesUpToOn n f p s) : HasFTaylorSeriesUpToOn n (g ∘ f) (fun x k => g.compContinuousMultilinearMap (p x k)) s where zero_eq x hx := congr_arg g (hf.zero_eq x hx) fderivWithin m hm x hx := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜 (fun _ : Fin m => E) F G g).hasFDerivAt.comp_hasFDerivWithinAt x (hf.fderivWithin m hm x hx) cont m hm := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜 (fun _ : Fin m => E) F G g).continuous.comp_continuousOn (hf.cont m hm) #align has_ftaylor_series_up_to_on.continuous_linear_map_comp HasFTaylorSeriesUpToOn.continuousLinearMap_comp /-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain at a point. -/ theorem ContDiffWithinAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := fun m hm ↦ by rcases hf m hm with ⟨u, hu, p, hp⟩ exact ⟨u, hu, _, hp.continuousLinearMap_comp g⟩ #align cont_diff_within_at.continuous_linear_map_comp ContDiffWithinAt.continuousLinearMap_comp /-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain at a point. -/ theorem ContDiffAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x := ContDiffWithinAt.continuousLinearMap_comp g hf #align cont_diff_at.continuous_linear_map_comp ContDiffAt.continuousLinearMap_comp /-- Composition by continuous linear maps on the left preserves `C^n` functions on domains. -/ theorem ContDiffOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) s := fun x hx => (hf x hx).continuousLinearMap_comp g #align cont_diff_on.continuous_linear_map_comp ContDiffOn.continuousLinearMap_comp /-- Composition by continuous linear maps on the left preserves `C^n` functions. -/ theorem ContDiff.continuousLinearMap_comp {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => g (f x) := contDiffOn_univ.1 <| ContDiffOn.continuousLinearMap_comp _ (contDiffOn_univ.2 hf) #align cont_diff.continuous_linear_map_comp ContDiff.continuousLinearMap_comp /-- The iterated derivative within a set of the composition with a linear map on the left is obtained by applying the linear map to the iterated derivative. -/ theorem ContinuousLinearMap.iteratedFDerivWithin_comp_left {f : E → F} (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = g.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := (((hf.ftaylorSeriesWithin hs).continuousLinearMap_comp g).eq_iteratedFDerivWithin_of_uniqueDiffOn hi hs hx).symm #align continuous_linear_map.iterated_fderiv_within_comp_left ContinuousLinearMap.iteratedFDerivWithin_comp_left /-- The iterated derivative of the composition with a linear map on the left is obtained by applying the linear map to the iterated derivative. -/ theorem ContinuousLinearMap.iteratedFDeriv_comp_left {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) (x : E) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : iteratedFDeriv 𝕜 i (g ∘ f) x = g.compContinuousMultilinearMap (iteratedFDeriv 𝕜 i f x) := by simp only [← iteratedFDerivWithin_univ] exact g.iteratedFDerivWithin_comp_left hf.contDiffOn uniqueDiffOn_univ (mem_univ x) hi #align continuous_linear_map.iterated_fderiv_comp_left ContinuousLinearMap.iteratedFDeriv_comp_left /-- The iterated derivative within a set of the composition with a linear equiv on the left is obtained by applying the linear equiv to the iterated derivative. This is true without differentiability assumptions. -/ theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_left (g : F ≃L[𝕜] G) (f : E → F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = (g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := by induction' i with i IH generalizing x · ext1 m simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, comp_apply, ContinuousLinearMap.compContinuousMultilinearMap_coe, coe_coe] · ext1 m rw [iteratedFDerivWithin_succ_apply_left] have Z : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (g ∘ f) s) s x = fderivWithin 𝕜 (g.compContinuousMultilinearMapL (fun _ : Fin i => E) ∘ iteratedFDerivWithin 𝕜 i f s) s x := fderivWithin_congr' (@IH) hx simp_rw [Z] rw [(g.compContinuousMultilinearMapL fun _ : Fin i => E).comp_fderivWithin (hs x hx)] simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply, ContinuousLinearEquiv.compContinuousMultilinearMapL_apply, ContinuousLinearMap.compContinuousMultilinearMap_coe, EmbeddingLike.apply_eq_iff_eq] rw [iteratedFDerivWithin_succ_apply_left] #align continuous_linear_equiv.iterated_fderiv_within_comp_left ContinuousLinearEquiv.iteratedFDerivWithin_comp_left /-- Composition with a linear isometry on the left preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometry.norm_iteratedFDerivWithin_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G) (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : ‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by have : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = g.toContinuousLinearMap.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := g.toContinuousLinearMap.iteratedFDerivWithin_comp_left hf hs hx hi rw [this] apply LinearIsometry.norm_compContinuousMultilinearMap #align linear_isometry.norm_iterated_fderiv_within_comp_left LinearIsometry.norm_iteratedFDerivWithin_comp_left /-- Composition with a linear isometry on the left preserves the norm of the iterated derivative. -/ theorem LinearIsometry.norm_iteratedFDeriv_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G) (hf : ContDiff 𝕜 n f) (x : E) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : ‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by simp only [← iteratedFDerivWithin_univ] exact g.norm_iteratedFDerivWithin_comp_left hf.contDiffOn uniqueDiffOn_univ (mem_univ x) hi #align linear_isometry.norm_iterated_fderiv_comp_left LinearIsometry.norm_iteratedFDeriv_comp_left /-- Composition with a linear isometry equiv on the left preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) : ‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by have : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = (g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_left f hs hx i rw [this] apply LinearIsometry.norm_compContinuousMultilinearMap g.toLinearIsometry #align linear_isometry_equiv.norm_iterated_fderiv_within_comp_left LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left /-- Composition with a linear isometry equiv on the left preserves the norm of the iterated derivative. -/ theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F) (x : E) (i : ℕ) : ‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by rw [← iteratedFDerivWithin_univ, ← iteratedFDerivWithin_univ] apply g.norm_iteratedFDerivWithin_comp_left f uniqueDiffOn_univ (mem_univ x) i #align linear_isometry_equiv.norm_iterated_fderiv_comp_left LinearIsometryEquiv.norm_iteratedFDeriv_comp_left /-- Composition by continuous linear equivs on the left respects higher differentiability at a point in a domain. -/ theorem ContinuousLinearEquiv.comp_contDiffWithinAt_iff (e : F ≃L[𝕜] G) : ContDiffWithinAt 𝕜 n (e ∘ f) s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H => by simpa only [(· ∘ ·), e.symm.coe_coe, e.symm_apply_apply] using H.continuousLinearMap_comp (e.symm : G →L[𝕜] F), fun H => H.continuousLinearMap_comp (e : F →L[𝕜] G)⟩ #align continuous_linear_equiv.comp_cont_diff_within_at_iff ContinuousLinearEquiv.comp_contDiffWithinAt_iff /-- Composition by continuous linear equivs on the left respects higher differentiability at a point. -/ theorem ContinuousLinearEquiv.comp_contDiffAt_iff (e : F ≃L[𝕜] G) : ContDiffAt 𝕜 n (e ∘ f) x ↔ ContDiffAt 𝕜 n f x := by simp only [← contDiffWithinAt_univ, e.comp_contDiffWithinAt_iff] #align continuous_linear_equiv.comp_cont_diff_at_iff ContinuousLinearEquiv.comp_contDiffAt_iff /-- Composition by continuous linear equivs on the left respects higher differentiability on domains. -/ theorem ContinuousLinearEquiv.comp_contDiffOn_iff (e : F ≃L[𝕜] G) : ContDiffOn 𝕜 n (e ∘ f) s ↔ ContDiffOn 𝕜 n f s := by simp [ContDiffOn, e.comp_contDiffWithinAt_iff] #align continuous_linear_equiv.comp_cont_diff_on_iff ContinuousLinearEquiv.comp_contDiffOn_iff /-- Composition by continuous linear equivs on the left respects higher differentiability. -/ theorem ContinuousLinearEquiv.comp_contDiff_iff (e : F ≃L[𝕜] G) : ContDiff 𝕜 n (e ∘ f) ↔ ContDiff 𝕜 n f := by simp only [← contDiffOn_univ, e.comp_contDiffOn_iff] #align continuous_linear_equiv.comp_cont_diff_iff ContinuousLinearEquiv.comp_contDiff_iff /-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `f ∘ g` admits a Taylor series in `g ⁻¹' s`, whose `k`-th term is given by `p k (g v₁, ..., g vₖ)` . -/ theorem HasFTaylorSeriesUpToOn.compContinuousLinearMap (hf : HasFTaylorSeriesUpToOn n f p s) (g : G →L[𝕜] E) : HasFTaylorSeriesUpToOn n (f ∘ g) (fun x k => (p (g x) k).compContinuousLinearMap fun _ => g) (g ⁻¹' s) := by let A : ∀ m : ℕ, (E[×m]→L[𝕜] F) → G[×m]→L[𝕜] F := fun m h => h.compContinuousLinearMap fun _ => g have hA : ∀ m, IsBoundedLinearMap 𝕜 (A m) := fun m => isBoundedLinearMap_continuousMultilinearMap_comp_linear g constructor · intro x hx simp only [(hf.zero_eq (g x) hx).symm, Function.comp_apply] change (p (g x) 0 fun _ : Fin 0 => g 0) = p (g x) 0 0 rw [ContinuousLinearMap.map_zero] rfl · intro m hm x hx convert (hA m).hasFDerivAt.comp_hasFDerivWithinAt x ((hf.fderivWithin m hm (g x) hx).comp x g.hasFDerivWithinAt (Subset.refl _)) ext y v change p (g x) (Nat.succ m) (g ∘ cons y v) = p (g x) m.succ (cons (g y) (g ∘ v)) rw [comp_cons] · intro m hm exact (hA m).continuous.comp_continuousOn <| (hf.cont m hm).comp g.continuous.continuousOn <| Subset.refl _ #align has_ftaylor_series_up_to_on.comp_continuous_linear_map HasFTaylorSeriesUpToOn.compContinuousLinearMap /-- Composition by continuous linear maps on the right preserves `C^n` functions at a point on a domain. -/ theorem ContDiffWithinAt.comp_continuousLinearMap {x : G} (g : G →L[𝕜] E) (hf : ContDiffWithinAt 𝕜 n f s (g x)) : ContDiffWithinAt 𝕜 n (f ∘ g) (g ⁻¹' s) x := by intro m hm rcases hf m hm with ⟨u, hu, p, hp⟩ refine ⟨g ⁻¹' u, ?_, _, hp.compContinuousLinearMap g⟩ refine g.continuous.continuousWithinAt.tendsto_nhdsWithin ?_ hu exact (mapsTo_singleton.2 <| mem_singleton _).union_union (mapsTo_preimage _ _) #align cont_diff_within_at.comp_continuous_linear_map ContDiffWithinAt.comp_continuousLinearMap /-- Composition by continuous linear maps on the right preserves `C^n` functions on domains. -/ theorem ContDiffOn.comp_continuousLinearMap (hf : ContDiffOn 𝕜 n f s) (g : G →L[𝕜] E) : ContDiffOn 𝕜 n (f ∘ g) (g ⁻¹' s) := fun x hx => (hf (g x) hx).comp_continuousLinearMap g #align cont_diff_on.comp_continuous_linear_map ContDiffOn.comp_continuousLinearMap /-- Composition by continuous linear maps on the right preserves `C^n` functions. -/ theorem ContDiff.comp_continuousLinearMap {f : E → F} {g : G →L[𝕜] E} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n (f ∘ g) := contDiffOn_univ.1 <| ContDiffOn.comp_continuousLinearMap (contDiffOn_univ.2 hf) _ #align cont_diff.comp_continuous_linear_map ContDiff.comp_continuousLinearMap /-- The iterated derivative within a set of the composition with a linear map on the right is obtained by composing the iterated derivative with the linear map. -/ theorem ContinuousLinearMap.iteratedFDerivWithin_comp_right {f : E → F} (g : G →L[𝕜] E) (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (h's : UniqueDiffOn 𝕜 (g ⁻¹' s)) {x : G} (hx : g x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x = (iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := (((hf.ftaylorSeriesWithin hs).compContinuousLinearMap g).eq_iteratedFDerivWithin_of_uniqueDiffOn hi h's hx).symm #align continuous_linear_map.iterated_fderiv_within_comp_right ContinuousLinearMap.iteratedFDerivWithin_comp_right /-- The iterated derivative within a set of the composition with a linear equiv on the right is obtained by composing the iterated derivative with the linear equiv. -/ theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_right (g : G ≃L[𝕜] E) (f : E → F) (hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x = (iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := by induction' i with i IH generalizing x · ext1 simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, comp_apply, ContinuousMultilinearMap.compContinuousLinearMap_apply] · ext1 m simp only [ContinuousMultilinearMap.compContinuousLinearMap_apply, ContinuousLinearEquiv.coe_coe, iteratedFDerivWithin_succ_apply_left] have : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s)) (g ⁻¹' s) x = fderivWithin 𝕜 (ContinuousMultilinearMap.compContinuousLinearMapEquivL _ (fun _x : Fin i => g) ∘ (iteratedFDerivWithin 𝕜 i f s ∘ g)) (g ⁻¹' s) x := fderivWithin_congr' (@IH) hx rw [this, ContinuousLinearEquiv.comp_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx)] simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply, ContinuousMultilinearMap.compContinuousLinearMapEquivL_apply, ContinuousMultilinearMap.compContinuousLinearMap_apply] rw [ContinuousLinearEquiv.comp_right_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx), ContinuousLinearMap.coe_comp', coe_coe, comp_apply, tail_def, tail_def] #align continuous_linear_equiv.iterated_fderiv_within_comp_right ContinuousLinearEquiv.iteratedFDerivWithin_comp_right /-- The iterated derivative of the composition with a linear map on the right is obtained by composing the iterated derivative with the linear map. -/ theorem ContinuousLinearMap.iteratedFDeriv_comp_right (g : G →L[𝕜] E) {f : E → F} (hf : ContDiff 𝕜 n f) (x : G) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : iteratedFDeriv 𝕜 i (f ∘ g) x = (iteratedFDeriv 𝕜 i f (g x)).compContinuousLinearMap fun _ => g := by simp only [← iteratedFDerivWithin_univ] exact g.iteratedFDerivWithin_comp_right hf.contDiffOn uniqueDiffOn_univ uniqueDiffOn_univ (mem_univ _) hi #align continuous_linear_map.iterated_fderiv_comp_right ContinuousLinearMap.iteratedFDeriv_comp_right /-- Composition with a linear isometry on the right preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F) (hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) : ‖iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x‖ = ‖iteratedFDerivWithin 𝕜 i f s (g x)‖ := by have : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x = (iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_right f hs hx i rw [this, ContinuousMultilinearMap.norm_compContinuous_linearIsometryEquiv] #align linear_isometry_equiv.norm_iterated_fderiv_within_comp_right LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right /-- Composition with a linear isometry on the right preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F) (x : G) (i : ℕ) : ‖iteratedFDeriv 𝕜 i (f ∘ g) x‖ = ‖iteratedFDeriv 𝕜 i f (g x)‖ := by simp only [← iteratedFDerivWithin_univ] apply g.norm_iteratedFDerivWithin_comp_right f uniqueDiffOn_univ (mem_univ (g x)) i #align linear_isometry_equiv.norm_iterated_fderiv_comp_right LinearIsometryEquiv.norm_iteratedFDeriv_comp_right /-- Composition by continuous linear equivs on the right respects higher differentiability at a point in a domain. -/ theorem ContinuousLinearEquiv.contDiffWithinAt_comp_iff (e : G ≃L[𝕜] E) : ContDiffWithinAt 𝕜 n (f ∘ e) (e ⁻¹' s) (e.symm x) ↔ ContDiffWithinAt 𝕜 n f s x := by constructor · intro H simpa [← preimage_comp, (· ∘ ·)] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G) · intro H rw [← e.apply_symm_apply x, ← e.coe_coe] at H exact H.comp_continuousLinearMap _ #align continuous_linear_equiv.cont_diff_within_at_comp_iff ContinuousLinearEquiv.contDiffWithinAt_comp_iff /-- Composition by continuous linear equivs on the right respects higher differentiability at a point. -/ theorem ContinuousLinearEquiv.contDiffAt_comp_iff (e : G ≃L[𝕜] E) : ContDiffAt 𝕜 n (f ∘ e) (e.symm x) ↔ ContDiffAt 𝕜 n f x := by rw [← contDiffWithinAt_univ, ← contDiffWithinAt_univ, ← preimage_univ] exact e.contDiffWithinAt_comp_iff #align continuous_linear_equiv.cont_diff_at_comp_iff ContinuousLinearEquiv.contDiffAt_comp_iff /-- Composition by continuous linear equivs on the right respects higher differentiability on domains. -/ theorem ContinuousLinearEquiv.contDiffOn_comp_iff (e : G ≃L[𝕜] E) : ContDiffOn 𝕜 n (f ∘ e) (e ⁻¹' s) ↔ ContDiffOn 𝕜 n f s := ⟨fun H => by simpa [(· ∘ ·)] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G), fun H => H.comp_continuousLinearMap (e : G →L[𝕜] E)⟩ #align continuous_linear_equiv.cont_diff_on_comp_iff ContinuousLinearEquiv.contDiffOn_comp_iff /-- Composition by continuous linear equivs on the right respects higher differentiability. -/ theorem ContinuousLinearEquiv.contDiff_comp_iff (e : G ≃L[𝕜] E) : ContDiff 𝕜 n (f ∘ e) ↔ ContDiff 𝕜 n f := by rw [← contDiffOn_univ, ← contDiffOn_univ, ← preimage_univ] exact e.contDiffOn_comp_iff #align continuous_linear_equiv.cont_diff_comp_iff ContinuousLinearEquiv.contDiff_comp_iff /-- If two functions `f` and `g` admit Taylor series `p` and `q` in a set `s`, then the cartesian product of `f` and `g` admits the cartesian product of `p` and `q` as a Taylor series. -/ theorem HasFTaylorSeriesUpToOn.prod (hf : HasFTaylorSeriesUpToOn n f p s) {g : E → G} {q : E → FormalMultilinearSeries 𝕜 E G} (hg : HasFTaylorSeriesUpToOn n g q s) : HasFTaylorSeriesUpToOn n (fun y => (f y, g y)) (fun y k => (p y k).prod (q y k)) s := by set L := fun m => ContinuousMultilinearMap.prodL 𝕜 (fun _ : Fin m => E) F G constructor · intro x hx; rw [← hf.zero_eq x hx, ← hg.zero_eq x hx]; rfl · intro m hm x hx convert (L m).hasFDerivAt.comp_hasFDerivWithinAt x ((hf.fderivWithin m hm x hx).prod (hg.fderivWithin m hm x hx)) · intro m hm exact (L m).continuous.comp_continuousOn ((hf.cont m hm).prod (hg.cont m hm)) #align has_ftaylor_series_up_to_on.prod HasFTaylorSeriesUpToOn.prod /-- The cartesian product of `C^n` functions at a point in a domain is `C^n`. -/ theorem ContDiffWithinAt.prod {s : Set E} {f : E → F} {g : E → G} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x : E => (f x, g x)) s x := by intro m hm rcases hf m hm with ⟨u, hu, p, hp⟩ rcases hg m hm with ⟨v, hv, q, hq⟩ exact ⟨u ∩ v, Filter.inter_mem hu hv, _, (hp.mono inter_subset_left).prod (hq.mono inter_subset_right)⟩ #align cont_diff_within_at.prod ContDiffWithinAt.prod /-- The cartesian product of `C^n` functions on domains is `C^n`. -/ theorem ContDiffOn.prod {s : Set E} {f : E → F} {g : E → G} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x : E => (f x, g x)) s := fun x hx => (hf x hx).prod (hg x hx) #align cont_diff_on.prod ContDiffOn.prod /-- The cartesian product of `C^n` functions at a point is `C^n`. -/ theorem ContDiffAt.prod {f : E → F} {g : E → G} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x : E => (f x, g x)) x := contDiffWithinAt_univ.1 <| ContDiffWithinAt.prod (contDiffWithinAt_univ.2 hf) (contDiffWithinAt_univ.2 hg) #align cont_diff_at.prod ContDiffAt.prod /-- The cartesian product of `C^n` functions is `C^n`. -/ theorem ContDiff.prod {f : E → F} {g : E → G} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x : E => (f x, g x) := contDiffOn_univ.1 <| ContDiffOn.prod (contDiffOn_univ.2 hf) (contDiffOn_univ.2 hg) #align cont_diff.prod ContDiff.prod /-! ### Composition of `C^n` functions We show that the composition of `C^n` functions is `C^n`. One way to prove it would be to write the `n`-th derivative of the composition (this is Faà di Bruno's formula) and check its continuity, but this is very painful. Instead, we go for a simple inductive proof. Assume it is done for `n`. Then, to check it for `n+1`, one needs to check that the derivative of `g ∘ f` is `C^n`, i.e., that `Dg(f x) ⬝ Df(x)` is `C^n`. The term `Dg (f x)` is the composition of two `C^n` functions, so it is `C^n` by the inductive assumption. The term `Df(x)` is also `C^n`. Then, the matrix multiplication is the application of a bilinear map (which is `C^∞`, and therefore `C^n`) to `x ↦ (Dg(f x), Df x)`. As the composition of two `C^n` maps, it is again `C^n`, and we are done. There is a subtlety in this argument: we apply the inductive assumption to functions on other Banach spaces. In maths, one would say: prove by induction over `n` that, for all `C^n` maps between all pairs of Banach spaces, their composition is `C^n`. In Lean, this is fine as long as the spaces stay in the same universe. This is not the case in the above argument: if `E` lives in universe `u` and `F` lives in universe `v`, then linear maps from `E` to `F` (to which the derivative of `f` belongs) is in universe `max u v`. If one could quantify over finitely many universes, the above proof would work fine, but this is not the case. One could still write the proof considering spaces in any universe in `u, v, w, max u v, max v w, max u v w`, but it would be extremely tedious and lead to a lot of duplication. Instead, we formulate the above proof when all spaces live in the same universe (where everything is fine), and then we deduce the general result by lifting all our spaces to a common universe through `ULift`. This lifting is done through a continuous linear equiv. We have already proved that composing with such a linear equiv does not change the fact of being `C^n`, which concludes the proof. -/ /-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe assumption (but is deduced from this one). -/ private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu] {Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu] [NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu} (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) : ContDiffOn 𝕜 n (g ∘ f) s := by induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu · rw [contDiffOn_zero] at hf hg ⊢ exact ContinuousOn.comp hg hf st · rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢ intro x hx rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟨u, hu, f', hf', f'_diff⟩ rcases hg (f x) (st hx) with ⟨v, hv, g', hg', g'_diff⟩ rw [insert_eq_of_mem hx] at hu ⊢ have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu let w := s ∩ (u ∩ f ⁻¹' v) have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2 have wu : w ⊆ u := fun y hy => hy.2.1 have ws : w ⊆ s := fun y hy => hy.1 refine ⟨w, ?_, fun y => (g' (f y)).comp (f' y), ?_, ?_⟩ · show w ∈ 𝓝[s] x apply Filter.inter_mem self_mem_nhdsWithin apply Filter.inter_mem hu apply ContinuousWithinAt.preimage_mem_nhdsWithin' · rw [← continuousWithinAt_inter' hu] exact (hf' x xu).differentiableWithinAt.continuousWithinAt.mono inter_subset_right · apply nhdsWithin_mono _ _ hv exact Subset.trans (image_subset_iff.mpr st) (subset_insert (f x) t) · show ∀ y ∈ w, HasFDerivWithinAt (g ∘ f) ((g' (f y)).comp (f' y)) w y rintro y ⟨-, yu, yv⟩ exact (hg' (f y) yv).comp y ((hf' y yu).mono wu) wv · show ContDiffOn 𝕜 n (fun y => (g' (f y)).comp (f' y)) w have A : ContDiffOn 𝕜 n (fun y => g' (f y)) w := IH g'_diff ((hf.of_le (WithTop.coe_le_coe.2 (Nat.le_succ n))).mono ws) wv have B : ContDiffOn 𝕜 n f' w := f'_diff.mono wu have C : ContDiffOn 𝕜 n (fun y => (g' (f y), f' y)) w := A.prod B have D : ContDiffOn 𝕜 n (fun p : (Fu →L[𝕜] Gu) × (Eu →L[𝕜] Fu) => p.1.comp p.2) univ := isBoundedBilinearMap_comp.contDiff.contDiffOn exact IH D C (subset_univ _) · rw [contDiffOn_top] at hf hg ⊢ exact fun n => Itop n (hg n) (hf n) st /-- The composition of `C^n` functions on domains is `C^n`. -/ theorem ContDiffOn.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) : ContDiffOn 𝕜 n (g ∘ f) s := by /- we lift all the spaces to a common universe, as we have already proved the result in this situation. -/ let Eu : Type max uE uF uG := ULift.{max uF uG} E let Fu : Type max uE uF uG := ULift.{max uE uG} F let Gu : Type max uE uF uG := ULift.{max uE uF} G -- declare the isomorphisms have isoE : Eu ≃L[𝕜] E := ContinuousLinearEquiv.ulift have isoF : Fu ≃L[𝕜] F := ContinuousLinearEquiv.ulift have isoG : Gu ≃L[𝕜] G := ContinuousLinearEquiv.ulift -- lift the functions to the new spaces, check smoothness there, and then go back. let fu : Eu → Fu := (isoF.symm ∘ f) ∘ isoE have fu_diff : ContDiffOn 𝕜 n fu (isoE ⁻¹' s) := by rwa [isoE.contDiffOn_comp_iff, isoF.symm.comp_contDiffOn_iff] let gu : Fu → Gu := (isoG.symm ∘ g) ∘ isoF have gu_diff : ContDiffOn 𝕜 n gu (isoF ⁻¹' t) := by rwa [isoF.contDiffOn_comp_iff, isoG.symm.comp_contDiffOn_iff] have main : ContDiffOn 𝕜 n (gu ∘ fu) (isoE ⁻¹' s) := by apply ContDiffOn.comp_same_univ gu_diff fu_diff intro y hy simp only [fu, ContinuousLinearEquiv.coe_apply, Function.comp_apply, mem_preimage] rw [isoF.apply_symm_apply (f (isoE y))] exact st hy have : gu ∘ fu = (isoG.symm ∘ g ∘ f) ∘ isoE := by ext y simp only [fu, gu, Function.comp_apply] rw [isoF.apply_symm_apply (f (isoE y))] rwa [this, isoE.contDiffOn_comp_iff, isoG.symm.comp_contDiffOn_iff] at main #align cont_diff_on.comp ContDiffOn.comp /-- The composition of `C^n` functions on domains is `C^n`. -/ theorem ContDiffOn.comp' {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono inter_subset_left) inter_subset_right #align cont_diff_on.comp' ContDiffOn.comp' /-- The composition of a `C^n` function on a domain with a `C^n` function is `C^n`. -/ theorem ContDiff.comp_contDiffOn {s : Set E} {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) s := (contDiffOn_univ.2 hg).comp hf subset_preimage_univ #align cont_diff.comp_cont_diff_on ContDiff.comp_contDiffOn /-- The composition of `C^n` functions is `C^n`. -/ theorem ContDiff.comp {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g) (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n (g ∘ f) := contDiffOn_univ.1 <| ContDiffOn.comp (contDiffOn_univ.2 hg) (contDiffOn_univ.2 hf) (subset_univ _) #align cont_diff.comp ContDiff.comp /-- The composition of `C^n` functions at points in domains is `C^n`. -/ theorem ContDiffWithinAt.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E) (hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) (st : s ⊆ f ⁻¹' t) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by intro m hm rcases hg.contDiffOn hm with ⟨u, u_nhd, _, hu⟩ rcases hf.contDiffOn hm with ⟨v, v_nhd, vs, hv⟩ have xmem : x ∈ f ⁻¹' u ∩ v := ⟨(mem_of_mem_nhdsWithin (mem_insert (f x) _) u_nhd : _), mem_of_mem_nhdsWithin (mem_insert x s) v_nhd⟩ have : f ⁻¹' u ∈ 𝓝[insert x s] x := by apply hf.continuousWithinAt.insert_self.preimage_mem_nhdsWithin' apply nhdsWithin_mono _ _ u_nhd rw [image_insert_eq] exact insert_subset_insert (image_subset_iff.mpr st) have Z := (hu.comp (hv.mono inter_subset_right) inter_subset_left).contDiffWithinAt xmem m le_rfl have : 𝓝[f ⁻¹' u ∩ v] x = 𝓝[insert x s] x := by have A : f ⁻¹' u ∩ v = insert x s ∩ (f ⁻¹' u ∩ v) := by apply Subset.antisymm _ inter_subset_right rintro y ⟨hy1, hy2⟩ simpa only [mem_inter_iff, mem_preimage, hy2, and_true, true_and, vs hy2] using hy1 rw [A, ← nhdsWithin_restrict''] exact Filter.inter_mem this v_nhd rwa [insert_eq_of_mem xmem, this] at Z #align cont_diff_within_at.comp ContDiffWithinAt.comp /-- The composition of `C^n` functions at points in domains is `C^n`, with a weaker condition on `s` and `t`. -/ theorem ContDiffWithinAt.comp_of_mem {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E) (hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) (hs : t ∈ 𝓝[f '' s] f x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := (hg.mono_of_mem hs).comp x hf (subset_preimage_image f s) #align cont_diff_within_at.comp_of_mem ContDiffWithinAt.comp_of_mem /-- The composition of `C^n` functions at points in domains is `C^n`. -/ theorem ContDiffWithinAt.comp' {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E) (hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) x := hg.comp x (hf.mono inter_subset_left) inter_subset_right #align cont_diff_within_at.comp' ContDiffWithinAt.comp' theorem ContDiffAt.comp_contDiffWithinAt {n} (x : E) (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := hg.comp x hf (mapsTo_univ _ _) #align cont_diff_at.comp_cont_diff_within_at ContDiffAt.comp_contDiffWithinAt /-- The composition of `C^n` functions at points is `C^n`. -/ nonrec theorem ContDiffAt.comp (x : E) (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x := hg.comp x hf subset_preimage_univ #align cont_diff_at.comp ContDiffAt.comp theorem ContDiff.comp_contDiffWithinAt {g : F → G} {f : E → F} (h : ContDiff 𝕜 n g) (hf : ContDiffWithinAt 𝕜 n f t x) : ContDiffWithinAt 𝕜 n (g ∘ f) t x := haveI : ContDiffWithinAt 𝕜 n g univ (f x) := h.contDiffAt.contDiffWithinAt this.comp x hf (subset_univ _) #align cont_diff.comp_cont_diff_within_at ContDiff.comp_contDiffWithinAt theorem ContDiff.comp_contDiffAt {g : F → G} {f : E → F} (x : E) (hg : ContDiff 𝕜 n g) (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x := hg.comp_contDiffWithinAt hf #align cont_diff.comp_cont_diff_at ContDiff.comp_contDiffAt /-! ### Smoothness of projections -/ /-- The first projection in a product is `C^∞`. -/ theorem contDiff_fst : ContDiff 𝕜 n (Prod.fst : E × F → E) := IsBoundedLinearMap.contDiff IsBoundedLinearMap.fst #align cont_diff_fst contDiff_fst /-- Postcomposing `f` with `Prod.fst` is `C^n` -/ theorem ContDiff.fst {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).1 := contDiff_fst.comp hf #align cont_diff.fst ContDiff.fst /-- Precomposing `f` with `Prod.fst` is `C^n` -/ theorem ContDiff.fst' {f : E → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.1 := hf.comp contDiff_fst #align cont_diff.fst' ContDiff.fst' /-- The first projection on a domain in a product is `C^∞`. -/ theorem contDiffOn_fst {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.fst : E × F → E) s := ContDiff.contDiffOn contDiff_fst #align cont_diff_on_fst contDiffOn_fst theorem ContDiffOn.fst {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun x => (f x).1) s := contDiff_fst.comp_contDiffOn hf #align cont_diff_on.fst ContDiffOn.fst /-- The first projection at a point in a product is `C^∞`. -/ theorem contDiffAt_fst {p : E × F} : ContDiffAt 𝕜 n (Prod.fst : E × F → E) p := contDiff_fst.contDiffAt #align cont_diff_at_fst contDiffAt_fst /-- Postcomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/ theorem ContDiffAt.fst {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun x => (f x).1) x := contDiffAt_fst.comp x hf #align cont_diff_at.fst ContDiffAt.fst /-- Precomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/ theorem ContDiffAt.fst' {f : E → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun x : E × F => f x.1) (x, y) := ContDiffAt.comp (x, y) hf contDiffAt_fst #align cont_diff_at.fst' ContDiffAt.fst' /-- Precomposing `f` with `Prod.fst` is `C^n` at `x : E × F` -/ theorem ContDiffAt.fst'' {f : E → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.1) : ContDiffAt 𝕜 n (fun x : E × F => f x.1) x := hf.comp x contDiffAt_fst #align cont_diff_at.fst'' ContDiffAt.fst'' /-- The first projection within a domain at a point in a product is `C^∞`. -/ theorem contDiffWithinAt_fst {s : Set (E × F)} {p : E × F} : ContDiffWithinAt 𝕜 n (Prod.fst : E × F → E) s p := contDiff_fst.contDiffWithinAt #align cont_diff_within_at_fst contDiffWithinAt_fst /-- The second projection in a product is `C^∞`. -/ theorem contDiff_snd : ContDiff 𝕜 n (Prod.snd : E × F → F) := IsBoundedLinearMap.contDiff IsBoundedLinearMap.snd #align cont_diff_snd contDiff_snd /-- Postcomposing `f` with `Prod.snd` is `C^n` -/ theorem ContDiff.snd {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).2 := contDiff_snd.comp hf #align cont_diff.snd ContDiff.snd /-- Precomposing `f` with `Prod.snd` is `C^n` -/ theorem ContDiff.snd' {f : F → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.2 := hf.comp contDiff_snd #align cont_diff.snd' ContDiff.snd' /-- The second projection on a domain in a product is `C^∞`. -/ theorem contDiffOn_snd {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.snd : E × F → F) s := ContDiff.contDiffOn contDiff_snd #align cont_diff_on_snd contDiffOn_snd theorem ContDiffOn.snd {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun x => (f x).2) s := contDiff_snd.comp_contDiffOn hf #align cont_diff_on.snd ContDiffOn.snd /-- The second projection at a point in a product is `C^∞`. -/ theorem contDiffAt_snd {p : E × F} : ContDiffAt 𝕜 n (Prod.snd : E × F → F) p := contDiff_snd.contDiffAt #align cont_diff_at_snd contDiffAt_snd /-- Postcomposing `f` with `Prod.snd` is `C^n` at `x` -/ theorem ContDiffAt.snd {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun x => (f x).2) x := contDiffAt_snd.comp x hf #align cont_diff_at.snd ContDiffAt.snd /-- Precomposing `f` with `Prod.snd` is `C^n` at `(x, y)` -/ theorem ContDiffAt.snd' {f : F → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f y) : ContDiffAt 𝕜 n (fun x : E × F => f x.2) (x, y) := ContDiffAt.comp (x, y) hf contDiffAt_snd #align cont_diff_at.snd' ContDiffAt.snd' /-- Precomposing `f` with `Prod.snd` is `C^n` at `x : E × F` -/ theorem ContDiffAt.snd'' {f : F → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.2) : ContDiffAt 𝕜 n (fun x : E × F => f x.2) x := hf.comp x contDiffAt_snd #align cont_diff_at.snd'' ContDiffAt.snd'' /-- The second projection within a domain at a point in a product is `C^∞`. -/ theorem contDiffWithinAt_snd {s : Set (E × F)} {p : E × F} : ContDiffWithinAt 𝕜 n (Prod.snd : E × F → F) s p := contDiff_snd.contDiffWithinAt #align cont_diff_within_at_snd contDiffWithinAt_snd section NAry variable {E₁ E₂ E₃ E₄ : Type*} variable [NormedAddCommGroup E₁] [NormedAddCommGroup E₂] [NormedAddCommGroup E₃] [NormedAddCommGroup E₄] [NormedSpace 𝕜 E₁] [NormedSpace 𝕜 E₂] [NormedSpace 𝕜 E₃] [NormedSpace 𝕜 E₄] theorem ContDiff.comp₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) : ContDiff 𝕜 n fun x => g (f₁ x, f₂ x) := hg.comp <| hf₁.prod hf₂ #align cont_diff.comp₂ ContDiff.comp₂ theorem ContDiff.comp₃ {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) (hf₃ : ContDiff 𝕜 n f₃) : ContDiff 𝕜 n fun x => g (f₁ x, f₂ x, f₃ x) := hg.comp₂ hf₁ <| hf₂.prod hf₃ #align cont_diff.comp₃ ContDiff.comp₃ theorem ContDiff.comp_contDiff_on₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} {s : Set F} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s) : ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x)) s := hg.comp_contDiffOn <| hf₁.prod hf₂ #align cont_diff.comp_cont_diff_on₂ ContDiff.comp_contDiff_on₂ theorem ContDiff.comp_contDiff_on₃ {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃} {s : Set F} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s) (hf₃ : ContDiffOn 𝕜 n f₃ s) : ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x, f₃ x)) s := hg.comp_contDiff_on₂ hf₁ <| hf₂.prod hf₃ #align cont_diff.comp_cont_diff_on₃ ContDiff.comp_contDiff_on₃ end NAry section SpecificBilinearMaps theorem ContDiff.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} (hg : ContDiff 𝕜 n g) (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (g x).comp (f x) := isBoundedBilinearMap_comp.contDiff.comp₂ hg hf #align cont_diff.clm_comp ContDiff.clm_comp theorem ContDiffOn.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} {s : Set X} (hg : ContDiffOn 𝕜 n g s) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun x => (g x).comp (f x)) s := isBoundedBilinearMap_comp.contDiff.comp_contDiff_on₂ hg hf #align cont_diff_on.clm_comp ContDiffOn.clm_comp theorem ContDiff.clm_apply {f : E → F →L[𝕜] G} {g : E → F} {n : ℕ∞} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x) (g x) := isBoundedBilinearMap_apply.contDiff.comp₂ hf hg #align cont_diff.clm_apply ContDiff.clm_apply theorem ContDiffOn.clm_apply {f : E → F →L[𝕜] G} {g : E → F} {n : ℕ∞} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => (f x) (g x)) s := isBoundedBilinearMap_apply.contDiff.comp_contDiff_on₂ hf hg #align cont_diff_on.clm_apply ContDiffOn.clm_apply -- Porting note: In Lean 3 we had to give implicit arguments in proofs like the following, -- to speed up elaboration. In Lean 4 this isn't necessary anymore. theorem ContDiff.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G} {n : ℕ∞} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x).smulRight (g x) := isBoundedBilinearMap_smulRight.contDiff.comp₂ hf hg #align cont_diff.smul_right ContDiff.smulRight end SpecificBilinearMaps section ClmApplyConst /-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDerivWithin`. -/ theorem iteratedFDerivWithin_clm_apply_const_apply {s : Set E} (hs : UniqueDiffOn 𝕜 s) {n : ℕ∞} {c : E → F →L[𝕜] G} (hc : ContDiffOn 𝕜 n c s) {i : ℕ} (hi : i ≤ n) {x : E} (hx : x ∈ s) {u : F} {m : Fin i → E} : (iteratedFDerivWithin 𝕜 i (fun y ↦ (c y) u) s x) m = (iteratedFDerivWithin 𝕜 i c s x) m u := by induction i generalizing x with | zero => simp | succ i ih => replace hi : i < n := lt_of_lt_of_le (by norm_cast; simp) hi have h_deriv_apply : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i (fun y ↦ (c y) u) s) s := (hc.clm_apply contDiffOn_const).differentiableOn_iteratedFDerivWithin hi hs have h_deriv : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i c s) s := hc.differentiableOn_iteratedFDerivWithin hi hs simp only [iteratedFDerivWithin_succ_apply_left] rw [← fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv_apply x hx)] rw [fderivWithin_congr' (fun x hx ↦ ih hi.le hx) hx] rw [fderivWithin_clm_apply (hs x hx) (h_deriv.continuousMultilinear_apply_const _ x hx) (differentiableWithinAt_const u)] rw [fderivWithin_const_apply _ (hs x hx)] simp only [ContinuousLinearMap.flip_apply, ContinuousLinearMap.comp_zero, zero_add] rw [fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv x hx)] /-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDeriv`. -/ theorem iteratedFDeriv_clm_apply_const_apply {n : ℕ∞} {c : E → F →L[𝕜] G} (hc : ContDiff 𝕜 n c) {i : ℕ} (hi : i ≤ n) {x : E} {u : F} {m : Fin i → E} : (iteratedFDeriv 𝕜 i (fun y ↦ (c y) u) x) m = (iteratedFDeriv 𝕜 i c x) m u := by simp only [← iteratedFDerivWithin_univ] exact iteratedFDerivWithin_clm_apply_const_apply uniqueDiffOn_univ hc.contDiffOn hi (mem_univ _) end ClmApplyConst /-- The natural equivalence `(E × F) × G ≃ E × (F × G)` is smooth. Warning: if you think you need this lemma, it is likely that you can simplify your proof by reformulating the lemma that you're applying next using the tips in Note [continuity lemma statement] -/ theorem contDiff_prodAssoc : ContDiff 𝕜 ⊤ <| Equiv.prodAssoc E F G := (LinearIsometryEquiv.prodAssoc 𝕜 E F G).contDiff #align cont_diff_prod_assoc contDiff_prodAssoc /-- The natural equivalence `E × (F × G) ≃ (E × F) × G` is smooth. Warning: see remarks attached to `contDiff_prodAssoc` -/ theorem contDiff_prodAssoc_symm : ContDiff 𝕜 ⊤ <| (Equiv.prodAssoc E F G).symm := (LinearIsometryEquiv.prodAssoc 𝕜 E F G).symm.contDiff #align cont_diff_prod_assoc_symm contDiff_prodAssoc_symm /-! ### Bundled derivatives are smooth -/ /-- One direction of `contDiffWithinAt_succ_iff_hasFDerivWithinAt`, but where all derivatives taken within the same set. Version for partial derivatives / functions with parameters. `f x` is a `C^n+1` family of functions and `g x` is a `C^n` family of points, then the derivative of `f x` at `g x` depends in a `C^n` way on `x`. We give a general version of this fact relative to sets which may not have unique derivatives, in the following form. If `f : E × F → G` is `C^n+1` at `(x₀, g(x₀))` in `(s ∪ {x₀}) × t ⊆ E × F` and `g : E → F` is `C^n` at `x₀` within some set `s ⊆ E`, then there is a function `f' : E → F →L[𝕜] G` that is `C^n` at `x₀` within `s` such that for all `x` sufficiently close to `x₀` within `s ∪ {x₀}` the function `y ↦ f x y` has derivative `f' x` at `g x` within `t ⊆ F`. For convenience, we return an explicit set of `x`'s where this holds that is a subset of `s ∪ {x₀}`. We need one additional condition, namely that `t` is a neighborhood of `g(x₀)` within `g '' s`. -/ theorem ContDiffWithinAt.hasFDerivWithinAt_nhds {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ} {x₀ : E} (hf : ContDiffWithinAt 𝕜 (n + 1) (uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 n g s x₀) (hgt : t ∈ 𝓝[g '' s] g x₀) : ∃ v ∈ 𝓝[insert x₀ s] x₀, v ⊆ insert x₀ s ∧ ∃ f' : E → F →L[𝕜] G, (∀ x ∈ v, HasFDerivWithinAt (f x) (f' x) t (g x)) ∧ ContDiffWithinAt 𝕜 n (fun x => f' x) s x₀ := by have hst : insert x₀ s ×ˢ t ∈ 𝓝[(fun x => (x, g x)) '' s] (x₀, g x₀) := by refine nhdsWithin_mono _ ?_ (nhdsWithin_prod self_mem_nhdsWithin hgt) simp_rw [image_subset_iff, mk_preimage_prod, preimage_id', subset_inter_iff, subset_insert, true_and_iff, subset_preimage_image] obtain ⟨v, hv, hvs, f', hvf', hf'⟩ := contDiffWithinAt_succ_iff_hasFDerivWithinAt'.mp hf refine ⟨(fun z => (z, g z)) ⁻¹' v ∩ insert x₀ s, ?_, inter_subset_right, fun z => (f' (z, g z)).comp (ContinuousLinearMap.inr 𝕜 E F), ?_, ?_⟩ · refine inter_mem ?_ self_mem_nhdsWithin have := mem_of_mem_nhdsWithin (mem_insert _ _) hv refine mem_nhdsWithin_insert.mpr ⟨this, ?_⟩ refine (continuousWithinAt_id.prod hg.continuousWithinAt).preimage_mem_nhdsWithin' ?_ rw [← nhdsWithin_le_iff] at hst hv ⊢ exact (hst.trans <| nhdsWithin_mono _ <| subset_insert _ _).trans hv · intro z hz have := hvf' (z, g z) hz.1 refine this.comp _ (hasFDerivAt_prod_mk_right _ _).hasFDerivWithinAt ?_ exact mapsTo'.mpr (image_prod_mk_subset_prod_right hz.2) · exact (hf'.continuousLinearMap_comp <| (ContinuousLinearMap.compL 𝕜 F (E × F) G).flip (ContinuousLinearMap.inr 𝕜 E F)).comp_of_mem x₀ (contDiffWithinAt_id.prod hg) hst #align cont_diff_within_at.has_fderiv_within_at_nhds ContDiffWithinAt.hasFDerivWithinAt_nhds /-- The most general lemma stating that `x ↦ fderivWithin 𝕜 (f x) t (g x)` is `C^n` at a point within a set. To show that `x ↦ D_yf(x,y)g(x)` (taken within `t`) is `C^m` at `x₀` within `s`, we require that * `f` is `C^n` at `(x₀, g(x₀))` within `(s ∪ {x₀}) × t` for `n ≥ m+1`. * `g` is `C^m` at `x₀` within `s`; * Derivatives are unique at `g(x)` within `t` for `x` sufficiently close to `x₀` within `s ∪ {x₀}`; * `t` is a neighborhood of `g(x₀)` within `g '' s`; -/ theorem ContDiffWithinAt.fderivWithin'' {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ∞} (hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 m g s x₀) (ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≤ n) (hgt : t ∈ 𝓝[g '' s] g x₀) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by have : ∀ k : ℕ, (k : ℕ∞) ≤ m → ContDiffWithinAt 𝕜 k (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := fun k hkm ↦ by obtain ⟨v, hv, -, f', hvf', hf'⟩ := (hf.of_le <| (add_le_add_right hkm 1).trans hmn).hasFDerivWithinAt_nhds (hg.of_le hkm) hgt refine hf'.congr_of_eventuallyEq_insert ?_ filter_upwards [hv, ht] exact fun y hy h2y => (hvf' y hy).fderivWithin h2y induction' m with m · obtain rfl := eq_top_iff.mpr hmn rw [contDiffWithinAt_top] exact fun m => this m le_top exact this _ le_rfl #align cont_diff_within_at.fderiv_within'' ContDiffWithinAt.fderivWithin'' /-- A special case of `ContDiffWithinAt.fderivWithin''` where we require that `s ⊆ g⁻¹(t)`. -/ theorem ContDiffWithinAt.fderivWithin' {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ∞} (hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 m g s x₀) (ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≤ n) (hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := hf.fderivWithin'' hg ht hmn <| mem_of_superset self_mem_nhdsWithin <| image_subset_iff.mpr hst #align cont_diff_within_at.fderiv_within' ContDiffWithinAt.fderivWithin' /-- A special case of `ContDiffWithinAt.fderivWithin'` where we require that `x₀ ∈ s` and there are unique derivatives everywhere within `t`. -/ protected theorem ContDiffWithinAt.fderivWithin {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ∞} (hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 m g s x₀) (ht : UniqueDiffOn 𝕜 t) (hmn : m + 1 ≤ n) (hx₀ : x₀ ∈ s) (hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by rw [← insert_eq_self.mpr hx₀] at hf refine hf.fderivWithin' hg ?_ hmn hst rw [insert_eq_self.mpr hx₀] exact eventually_of_mem self_mem_nhdsWithin fun x hx => ht _ (hst hx) #align cont_diff_within_at.fderiv_within ContDiffWithinAt.fderivWithin /-- `x ↦ fderivWithin 𝕜 (f x) t (g x) (k x)` is smooth at a point within a set. -/ theorem ContDiffWithinAt.fderivWithin_apply {f : E → F → G} {g k : E → F} {t : Set F} {n : ℕ∞} (hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 m g s x₀) (hk : ContDiffWithinAt 𝕜 m k s x₀) (ht : UniqueDiffOn 𝕜 t) (hmn : m + 1 ≤ n) (hx₀ : x₀ ∈ s) (hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x) (k x)) s x₀ := (contDiff_fst.clm_apply contDiff_snd).contDiffAt.comp_contDiffWithinAt x₀ ((hf.fderivWithin hg ht hmn hx₀ hst).prod hk) #align cont_diff_within_at.fderiv_within_apply ContDiffWithinAt.fderivWithin_apply /-- `fderivWithin 𝕜 f s` is smooth at `x₀` within `s`. -/ theorem ContDiffWithinAt.fderivWithin_right (hf : ContDiffWithinAt 𝕜 n f s x₀) (hs : UniqueDiffOn 𝕜 s) (hmn : (m + 1 : ℕ∞) ≤ n) (hx₀s : x₀ ∈ s) : ContDiffWithinAt 𝕜 m (fderivWithin 𝕜 f s) s x₀ := ContDiffWithinAt.fderivWithin (ContDiffWithinAt.comp (x₀, x₀) hf contDiffWithinAt_snd <| prod_subset_preimage_snd s s) contDiffWithinAt_id hs hmn hx₀s (by rw [preimage_id']) #align cont_diff_within_at.fderiv_within_right ContDiffWithinAt.fderivWithin_right -- TODO: can we make a version of `ContDiffWithinAt.fderivWithin` for iterated derivatives? theorem ContDiffWithinAt.iteratedFderivWithin_right {i : ℕ} (hf : ContDiffWithinAt 𝕜 n f s x₀) (hs : UniqueDiffOn 𝕜 s) (hmn : (m + i : ℕ∞) ≤ n) (hx₀s : x₀ ∈ s) : ContDiffWithinAt 𝕜 m (iteratedFDerivWithin 𝕜 i f s) s x₀ := by induction' i with i hi generalizing m · rw [ENat.coe_zero, add_zero] at hmn exact (hf.of_le hmn).continuousLinearMap_comp ((continuousMultilinearCurryFin0 𝕜 E F).symm : _ →L[𝕜] E [×0]→L[𝕜] F) · rw [Nat.cast_succ, add_comm _ 1, ← add_assoc] at hmn exact ((hi hmn).fderivWithin_right hs le_rfl hx₀s).continuousLinearMap_comp (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (i+1) ↦ E) F : _ →L[𝕜] E [×(i+1)]→L[𝕜] F) /-- `x ↦ fderiv 𝕜 (f x) (g x)` is smooth at `x₀`. -/ protected theorem ContDiffAt.fderiv {f : E → F → G} {g : E → F} {n : ℕ∞} (hf : ContDiffAt 𝕜 n (Function.uncurry f) (x₀, g x₀)) (hg : ContDiffAt 𝕜 m g x₀) (hmn : m + 1 ≤ n) : ContDiffAt 𝕜 m (fun x => fderiv 𝕜 (f x) (g x)) x₀ := by simp_rw [← fderivWithin_univ] refine (ContDiffWithinAt.fderivWithin hf.contDiffWithinAt hg.contDiffWithinAt uniqueDiffOn_univ hmn (mem_univ x₀) ?_).contDiffAt univ_mem rw [preimage_univ] #align cont_diff_at.fderiv ContDiffAt.fderiv /-- `fderiv 𝕜 f` is smooth at `x₀`. -/ theorem ContDiffAt.fderiv_right (hf : ContDiffAt 𝕜 n f x₀) (hmn : (m + 1 : ℕ∞) ≤ n) : ContDiffAt 𝕜 m (fderiv 𝕜 f) x₀ := ContDiffAt.fderiv (ContDiffAt.comp (x₀, x₀) hf contDiffAt_snd) contDiffAt_id hmn #align cont_diff_at.fderiv_right ContDiffAt.fderiv_right theorem ContDiffAt.iteratedFDeriv_right {i : ℕ} (hf : ContDiffAt 𝕜 n f x₀) (hmn : (m + i : ℕ∞) ≤ n) : ContDiffAt 𝕜 m (iteratedFDeriv 𝕜 i f) x₀ := by rw [← iteratedFDerivWithin_univ, ← contDiffWithinAt_univ] at * exact hf.iteratedFderivWithin_right uniqueDiffOn_univ hmn trivial /-- `x ↦ fderiv 𝕜 (f x) (g x)` is smooth. -/ protected theorem ContDiff.fderiv {f : E → F → G} {g : E → F} {n m : ℕ∞} (hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hnm : n + 1 ≤ m) : ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) := contDiff_iff_contDiffAt.mpr fun _ => hf.contDiffAt.fderiv hg.contDiffAt hnm #align cont_diff.fderiv ContDiff.fderiv /-- `fderiv 𝕜 f` is smooth. -/ theorem ContDiff.fderiv_right (hf : ContDiff 𝕜 n f) (hmn : (m + 1 : ℕ∞) ≤ n) : ContDiff 𝕜 m (fderiv 𝕜 f) := contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.fderiv_right hmn #align cont_diff.fderiv_right ContDiff.fderiv_right theorem ContDiff.iteratedFDeriv_right {i : ℕ} (hf : ContDiff 𝕜 n f) (hmn : (m + i : ℕ∞) ≤ n) : ContDiff 𝕜 m (iteratedFDeriv 𝕜 i f) := contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.iteratedFDeriv_right hmn /-- `x ↦ fderiv 𝕜 (f x) (g x)` is continuous. -/ theorem Continuous.fderiv {f : E → F → G} {g : E → F} {n : ℕ∞} (hf : ContDiff 𝕜 n <| Function.uncurry f) (hg : Continuous g) (hn : 1 ≤ n) : Continuous fun x => fderiv 𝕜 (f x) (g x) := (hf.fderiv (contDiff_zero.mpr hg) hn).continuous #align continuous.fderiv Continuous.fderiv /-- `x ↦ fderiv 𝕜 (f x) (g x) (k x)` is smooth. -/ theorem ContDiff.fderiv_apply {f : E → F → G} {g k : E → F} {n m : ℕ∞} (hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hk : ContDiff 𝕜 n k) (hnm : n + 1 ≤ m) : ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) (k x) := (hf.fderiv hg hnm).clm_apply hk #align cont_diff.fderiv_apply ContDiff.fderiv_apply /-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/ theorem contDiffOn_fderivWithin_apply {m n : ℕ∞} {s : Set E} {f : E → F} (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E →L[𝕜] F) p.2) (s ×ˢ univ) := ((hf.fderivWithin hs hmn).comp contDiffOn_fst (prod_subset_preimage_fst _ _)).clm_apply contDiffOn_snd #align cont_diff_on_fderiv_within_apply contDiffOn_fderivWithin_apply /-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is continuous. -/ theorem ContDiffOn.continuousOn_fderivWithin_apply (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hn : 1 ≤ n) : ContinuousOn (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E → F) p.2) (s ×ˢ univ) := (contDiffOn_fderivWithin_apply hf hs <| by rwa [zero_add]).continuousOn #align cont_diff_on.continuous_on_fderiv_within_apply ContDiffOn.continuousOn_fderivWithin_apply /-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/ theorem ContDiff.contDiff_fderiv_apply {f : E → F} (hf : ContDiff 𝕜 n f) (hmn : m + 1 ≤ n) : ContDiff 𝕜 m fun p : E × E => (fderiv 𝕜 f p.1 : E →L[𝕜] F) p.2 := by rw [← contDiffOn_univ] at hf ⊢ rw [← fderivWithin_univ, ← univ_prod_univ] exact contDiffOn_fderivWithin_apply hf uniqueDiffOn_univ hmn #align cont_diff.cont_diff_fderiv_apply ContDiff.contDiff_fderiv_apply /-! ### Smoothness of functions `f : E → Π i, F' i` -/ section Pi variable {ι ι' : Type*} [Fintype ι] [Fintype ι'] {F' : ι → Type*} [∀ i, NormedAddCommGroup (F' i)] [∀ i, NormedSpace 𝕜 (F' i)] {φ : ∀ i, E → F' i} {p' : ∀ i, E → FormalMultilinearSeries 𝕜 E (F' i)} {Φ : E → ∀ i, F' i} {P' : E → FormalMultilinearSeries 𝕜 E (∀ i, F' i)} theorem hasFTaylorSeriesUpToOn_pi : HasFTaylorSeriesUpToOn n (fun x i => φ i x) (fun x m => ContinuousMultilinearMap.pi fun i => p' i x m) s ↔ ∀ i, HasFTaylorSeriesUpToOn n (φ i) (p' i) s := by set pr := @ContinuousLinearMap.proj 𝕜 _ ι F' _ _ _ letI : ∀ (m : ℕ) (i : ι), NormedSpace 𝕜 (E[×m]→L[𝕜] F' i) := fun m i => inferInstance set L : ∀ m : ℕ, (∀ i, E[×m]→L[𝕜] F' i) ≃ₗᵢ[𝕜] E[×m]→L[𝕜] ∀ i, F' i := fun m => ContinuousMultilinearMap.piₗᵢ _ _ refine ⟨fun h i => ?_, fun h => ⟨fun x hx => ?_, ?_, ?_⟩⟩ · convert h.continuousLinearMap_comp (pr i) · ext1 i exact (h i).zero_eq x hx · intro m hm x hx have := hasFDerivWithinAt_pi.2 fun i => (h i).fderivWithin m hm x hx convert (L m).hasFDerivAt.comp_hasFDerivWithinAt x this · intro m hm have := continuousOn_pi.2 fun i => (h i).cont m hm convert (L m).continuous.comp_continuousOn this #align has_ftaylor_series_up_to_on_pi hasFTaylorSeriesUpToOn_pi @[simp] theorem hasFTaylorSeriesUpToOn_pi' : HasFTaylorSeriesUpToOn n Φ P' s ↔ ∀ i, HasFTaylorSeriesUpToOn n (fun x => Φ x i) (fun x m => (@ContinuousLinearMap.proj 𝕜 _ ι F' _ _ _ i).compContinuousMultilinearMap (P' x m)) s := by convert hasFTaylorSeriesUpToOn_pi (𝕜 := 𝕜) (φ := fun i x ↦ Φ x i); ext; rfl #align has_ftaylor_series_up_to_on_pi' hasFTaylorSeriesUpToOn_pi' theorem contDiffWithinAt_pi : ContDiffWithinAt 𝕜 n Φ s x ↔ ∀ i, ContDiffWithinAt 𝕜 n (fun x => Φ x i) s x := by set pr := @ContinuousLinearMap.proj 𝕜 _ ι F' _ _ _ refine ⟨fun h i => h.continuousLinearMap_comp (pr i), fun h m hm => ?_⟩ choose u hux p hp using fun i => h i m hm exact ⟨⋂ i, u i, Filter.iInter_mem.2 hux, _, hasFTaylorSeriesUpToOn_pi.2 fun i => (hp i).mono <| iInter_subset _ _⟩ #align cont_diff_within_at_pi contDiffWithinAt_pi theorem contDiffOn_pi : ContDiffOn 𝕜 n Φ s ↔ ∀ i, ContDiffOn 𝕜 n (fun x => Φ x i) s := ⟨fun h _ x hx => contDiffWithinAt_pi.1 (h x hx) _, fun h x hx => contDiffWithinAt_pi.2 fun i => h i x hx⟩ #align cont_diff_on_pi contDiffOn_pi theorem contDiffAt_pi : ContDiffAt 𝕜 n Φ x ↔ ∀ i, ContDiffAt 𝕜 n (fun x => Φ x i) x := contDiffWithinAt_pi #align cont_diff_at_pi contDiffAt_pi theorem contDiff_pi : ContDiff 𝕜 n Φ ↔ ∀ i, ContDiff 𝕜 n fun x => Φ x i := by simp only [← contDiffOn_univ, contDiffOn_pi] #align cont_diff_pi contDiff_pi theorem contDiff_update [DecidableEq ι] (k : ℕ∞) (x : ∀ i, F' i) (i : ι) : ContDiff 𝕜 k (update x i) := by rw [contDiff_pi] intro j dsimp [Function.update] split_ifs with h · subst h exact contDiff_id · exact contDiff_const variable (F') in theorem contDiff_single [DecidableEq ι] (k : ℕ∞) (i : ι) : ContDiff 𝕜 k (Pi.single i : F' i → ∀ i, F' i) := contDiff_update k 0 i variable (𝕜 E) theorem contDiff_apply (i : ι) : ContDiff 𝕜 n fun f : ι → E => f i := contDiff_pi.mp contDiff_id i #align cont_diff_apply contDiff_apply theorem contDiff_apply_apply (i : ι) (j : ι') : ContDiff 𝕜 n fun f : ι → ι' → E => f i j := contDiff_pi.mp (contDiff_apply 𝕜 (ι' → E) i) j #align cont_diff_apply_apply contDiff_apply_apply end Pi /-! ### Sum of two functions -/ section Add theorem HasFTaylorSeriesUpToOn.add {q g} (hf : HasFTaylorSeriesUpToOn n f p s) (hg : HasFTaylorSeriesUpToOn n g q s) : HasFTaylorSeriesUpToOn n (f + g) (p + q) s := by convert HasFTaylorSeriesUpToOn.continuousLinearMap_comp (ContinuousLinearMap.fst 𝕜 F F + .snd 𝕜 F F) (hf.prod hg) -- The sum is smooth. theorem contDiff_add : ContDiff 𝕜 n fun p : F × F => p.1 + p.2 := (IsBoundedLinearMap.fst.add IsBoundedLinearMap.snd).contDiff #align cont_diff_add contDiff_add /-- The sum of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.add {s : Set E} {f g : E → F} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x + g x) s x := contDiff_add.contDiffWithinAt.comp x (hf.prod hg) subset_preimage_univ #align cont_diff_within_at.add ContDiffWithinAt.add /-- The sum of two `C^n` functions at a point is `C^n` at this point. -/ theorem ContDiffAt.add {f g : E → F} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => f x + g x) x := by rw [← contDiffWithinAt_univ] at *; exact hf.add hg #align cont_diff_at.add ContDiffAt.add /-- The sum of two `C^n`functions is `C^n`. -/ theorem ContDiff.add {f g : E → F} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => f x + g x := contDiff_add.comp (hf.prod hg) #align cont_diff.add ContDiff.add /-- The sum of two `C^n` functions on a domain is `C^n`. -/ theorem ContDiffOn.add {s : Set E} {f g : E → F} (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).add (hg x hx) #align cont_diff_on.add ContDiffOn.add variable {i : ℕ} /-- The iterated derivative of the sum of two functions is the sum of the iterated derivatives. See also `iteratedFDerivWithin_add_apply'`, which uses the spelling `(fun x ↦ f x + g x)` instead of `f + g`. -/ theorem iteratedFDerivWithin_add_apply {f g : E → F} (hf : ContDiffOn 𝕜 i f s) (hg : ContDiffOn 𝕜 i g s) (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 i (f + g) s x = iteratedFDerivWithin 𝕜 i f s x + iteratedFDerivWithin 𝕜 i g s x := Eq.symm <| ((hf.ftaylorSeriesWithin hu).add (hg.ftaylorSeriesWithin hu)).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hu hx #align iterated_fderiv_within_add_apply iteratedFDerivWithin_add_apply /-- The iterated derivative of the sum of two functions is the sum of the iterated derivatives. This is the same as `iteratedFDerivWithin_add_apply`, but using the spelling `(fun x ↦ f x + g x)` instead of `f + g`, which can be handy for some rewrites. TODO: use one form consistently. -/ theorem iteratedFDerivWithin_add_apply' {f g : E → F} (hf : ContDiffOn 𝕜 i f s) (hg : ContDiffOn 𝕜 i g s) (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 i (fun x => f x + g x) s x = iteratedFDerivWithin 𝕜 i f s x + iteratedFDerivWithin 𝕜 i g s x := iteratedFDerivWithin_add_apply hf hg hu hx #align iterated_fderiv_within_add_apply' iteratedFDerivWithin_add_apply' theorem iteratedFDeriv_add_apply {i : ℕ} {f g : E → F} (hf : ContDiff 𝕜 i f) (hg : ContDiff 𝕜 i g) : iteratedFDeriv 𝕜 i (f + g) x = iteratedFDeriv 𝕜 i f x + iteratedFDeriv 𝕜 i g x := by simp_rw [← contDiffOn_univ, ← iteratedFDerivWithin_univ] at hf hg ⊢ exact iteratedFDerivWithin_add_apply hf hg uniqueDiffOn_univ (Set.mem_univ _) #align iterated_fderiv_add_apply iteratedFDeriv_add_apply theorem iteratedFDeriv_add_apply' {i : ℕ} {f g : E → F} (hf : ContDiff 𝕜 i f) (hg : ContDiff 𝕜 i g) : iteratedFDeriv 𝕜 i (fun x => f x + g x) x = iteratedFDeriv 𝕜 i f x + iteratedFDeriv 𝕜 i g x := iteratedFDeriv_add_apply hf hg #align iterated_fderiv_add_apply' iteratedFDeriv_add_apply' end Add /-! ### Negative -/ section Neg -- The negative is smooth. theorem contDiff_neg : ContDiff 𝕜 n fun p : F => -p := IsBoundedLinearMap.id.neg.contDiff #align cont_diff_neg contDiff_neg /-- The negative of a `C^n` function within a domain at a point is `C^n` within this domain at this point. -/ theorem ContDiffWithinAt.neg {s : Set E} {f : E → F} (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (fun x => -f x) s x := contDiff_neg.contDiffWithinAt.comp x hf subset_preimage_univ #align cont_diff_within_at.neg ContDiffWithinAt.neg /-- The negative of a `C^n` function at a point is `C^n` at this point. -/ theorem ContDiffAt.neg {f : E → F} (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun x => -f x) x := by rw [← contDiffWithinAt_univ] at *; exact hf.neg #align cont_diff_at.neg ContDiffAt.neg /-- The negative of a `C^n`function is `C^n`. -/ theorem ContDiff.neg {f : E → F} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => -f x := contDiff_neg.comp hf #align cont_diff.neg ContDiff.neg /-- The negative of a `C^n` function on a domain is `C^n`. -/ theorem ContDiffOn.neg {s : Set E} {f : E → F} (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun x => -f x) s := fun x hx => (hf x hx).neg #align cont_diff_on.neg ContDiffOn.neg variable {i : ℕ} -- Porting note (#11215): TODO: define `Neg` instance on `ContinuousLinearEquiv`, -- prove it from `ContinuousLinearEquiv.iteratedFDerivWithin_comp_left` theorem iteratedFDerivWithin_neg_apply {f : E → F} (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 i (-f) s x = -iteratedFDerivWithin 𝕜 i f s x := by induction' i with i hi generalizing x · ext; simp · ext h calc iteratedFDerivWithin 𝕜 (i + 1) (-f) s x h = fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (-f) s) s x (h 0) (Fin.tail h) := rfl _ = fderivWithin 𝕜 (-iteratedFDerivWithin 𝕜 i f s) s x (h 0) (Fin.tail h) := by rw [fderivWithin_congr' (@hi) hx]; rfl _ = -(fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i f s) s) x (h 0) (Fin.tail h) := by rw [Pi.neg_def, fderivWithin_neg (hu x hx)]; rfl _ = -(iteratedFDerivWithin 𝕜 (i + 1) f s) x h := rfl #align iterated_fderiv_within_neg_apply iteratedFDerivWithin_neg_apply theorem iteratedFDeriv_neg_apply {i : ℕ} {f : E → F} : iteratedFDeriv 𝕜 i (-f) x = -iteratedFDeriv 𝕜 i f x := by simp_rw [← iteratedFDerivWithin_univ] exact iteratedFDerivWithin_neg_apply uniqueDiffOn_univ (Set.mem_univ _) #align iterated_fderiv_neg_apply iteratedFDeriv_neg_apply end Neg /-! ### Subtraction -/ /-- The difference of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.sub {s : Set E} {f g : E → F} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x - g x) s x := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align cont_diff_within_at.sub ContDiffWithinAt.sub /-- The difference of two `C^n` functions at a point is `C^n` at this point. -/ theorem ContDiffAt.sub {f g : E → F} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => f x - g x) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align cont_diff_at.sub ContDiffAt.sub /-- The difference of two `C^n` functions on a domain is `C^n`. -/ theorem ContDiffOn.sub {s : Set E} {f g : E → F} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => f x - g x) s := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align cont_diff_on.sub ContDiffOn.sub /-- The difference of two `C^n` functions is `C^n`. -/ theorem ContDiff.sub {f g : E → F} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => f x - g x := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align cont_diff.sub ContDiff.sub /-! ### Sum of finitely many functions -/ theorem ContDiffWithinAt.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} {t : Set E} {x : E} (h : ∀ i ∈ s, ContDiffWithinAt 𝕜 n (fun x => f i x) t x) : ContDiffWithinAt 𝕜 n (fun x => ∑ i ∈ s, f i x) t x := by classical induction' s using Finset.induction_on with i s is IH · simp [contDiffWithinAt_const] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) #align cont_diff_within_at.sum ContDiffWithinAt.sum theorem ContDiffAt.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} {x : E} (h : ∀ i ∈ s, ContDiffAt 𝕜 n (fun x => f i x) x) : ContDiffAt 𝕜 n (fun x => ∑ i ∈ s, f i x) x := by rw [← contDiffWithinAt_univ] at *; exact ContDiffWithinAt.sum h #align cont_diff_at.sum ContDiffAt.sum theorem ContDiffOn.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} {t : Set E} (h : ∀ i ∈ s, ContDiffOn 𝕜 n (fun x => f i x) t) : ContDiffOn 𝕜 n (fun x => ∑ i ∈ s, f i x) t := fun x hx => ContDiffWithinAt.sum fun i hi => h i hi x hx #align cont_diff_on.sum ContDiffOn.sum theorem ContDiff.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} (h : ∀ i ∈ s, ContDiff 𝕜 n fun x => f i x) : ContDiff 𝕜 n fun x => ∑ i ∈ s, f i x := by simp only [← contDiffOn_univ] at *; exact ContDiffOn.sum h #align cont_diff.sum ContDiff.sum theorem iteratedFDerivWithin_sum_apply {ι : Type*} {f : ι → E → F} {u : Finset ι} {i : ℕ} {x : E} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : ∀ j ∈ u, ContDiffOn 𝕜 i (f j) s) : iteratedFDerivWithin 𝕜 i (∑ j ∈ u, f j ·) s x = ∑ j ∈ u, iteratedFDerivWithin 𝕜 i (f j) s x := by induction u using Finset.cons_induction with | empty => ext; simp [hs, hx] | cons a u ha IH => simp only [Finset.mem_cons, forall_eq_or_imp] at h simp only [Finset.sum_cons] rw [iteratedFDerivWithin_add_apply' h.1 (ContDiffOn.sum h.2) hs hx, IH h.2] theorem iteratedFDeriv_sum {ι : Type*} {f : ι → E → F} {u : Finset ι} {i : ℕ} (h : ∀ j ∈ u, ContDiff 𝕜 i (f j)) : iteratedFDeriv 𝕜 i (∑ j ∈ u, f j ·) = ∑ j ∈ u, iteratedFDeriv 𝕜 i (f j) := funext fun x ↦ by simpa [iteratedFDerivWithin_univ] using iteratedFDerivWithin_sum_apply uniqueDiffOn_univ (mem_univ x) fun j hj ↦ (h j hj).contDiffOn /-! ### Product of two functions -/ section MulProd variable {𝔸 𝔸' ι 𝕜' : Type*} [NormedRing 𝔸] [NormedAlgebra 𝕜 𝔸] [NormedCommRing 𝔸'] [NormedAlgebra 𝕜 𝔸'] [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] -- The product is smooth. theorem contDiff_mul : ContDiff 𝕜 n fun p : 𝔸 × 𝔸 => p.1 * p.2 := (ContinuousLinearMap.mul 𝕜 𝔸).isBoundedBilinearMap.contDiff #align cont_diff_mul contDiff_mul /-- The product of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.mul {s : Set E} {f g : E → 𝔸} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x * g x) s x := contDiff_mul.comp_contDiffWithinAt (hf.prod hg) #align cont_diff_within_at.mul ContDiffWithinAt.mul /-- The product of two `C^n` functions at a point is `C^n` at this point. -/ nonrec theorem ContDiffAt.mul {f g : E → 𝔸} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => f x * g x) x := hf.mul hg #align cont_diff_at.mul ContDiffAt.mul /-- The product of two `C^n` functions on a domain is `C^n`. -/ theorem ContDiffOn.mul {f g : E → 𝔸} (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).mul (hg x hx) #align cont_diff_on.mul ContDiffOn.mul /-- The product of two `C^n`functions is `C^n`. -/ theorem ContDiff.mul {f g : E → 𝔸} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => f x * g x := contDiff_mul.comp (hf.prod hg) #align cont_diff.mul ContDiff.mul theorem contDiffWithinAt_prod' {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffWithinAt 𝕜 n (f i) s x) : ContDiffWithinAt 𝕜 n (∏ i ∈ t, f i) s x := Finset.prod_induction f (fun f => ContDiffWithinAt 𝕜 n f s x) (fun _ _ => ContDiffWithinAt.mul) (contDiffWithinAt_const (c := 1)) h #align cont_diff_within_at_prod' contDiffWithinAt_prod' theorem contDiffWithinAt_prod {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffWithinAt 𝕜 n (f i) s x) : ContDiffWithinAt 𝕜 n (fun y => ∏ i ∈ t, f i y) s x := by simpa only [← Finset.prod_apply] using contDiffWithinAt_prod' h #align cont_diff_within_at_prod contDiffWithinAt_prod theorem contDiffAt_prod' {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffAt 𝕜 n (f i) x) : ContDiffAt 𝕜 n (∏ i ∈ t, f i) x := contDiffWithinAt_prod' h #align cont_diff_at_prod' contDiffAt_prod' theorem contDiffAt_prod {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffAt 𝕜 n (f i) x) : ContDiffAt 𝕜 n (fun y => ∏ i ∈ t, f i y) x := contDiffWithinAt_prod h #align cont_diff_at_prod contDiffAt_prod theorem contDiffOn_prod' {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffOn 𝕜 n (f i) s) : ContDiffOn 𝕜 n (∏ i ∈ t, f i) s := fun x hx => contDiffWithinAt_prod' fun i hi => h i hi x hx #align cont_diff_on_prod' contDiffOn_prod' theorem contDiffOn_prod {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiffOn 𝕜 n (f i) s) : ContDiffOn 𝕜 n (fun y => ∏ i ∈ t, f i y) s := fun x hx => contDiffWithinAt_prod fun i hi => h i hi x hx #align cont_diff_on_prod contDiffOn_prod theorem contDiff_prod' {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiff 𝕜 n (f i)) : ContDiff 𝕜 n (∏ i ∈ t, f i) := contDiff_iff_contDiffAt.mpr fun _ => contDiffAt_prod' fun i hi => (h i hi).contDiffAt #align cont_diff_prod' contDiff_prod' theorem contDiff_prod {t : Finset ι} {f : ι → E → 𝔸'} (h : ∀ i ∈ t, ContDiff 𝕜 n (f i)) : ContDiff 𝕜 n fun y => ∏ i ∈ t, f i y := contDiff_iff_contDiffAt.mpr fun _ => contDiffAt_prod fun i hi => (h i hi).contDiffAt #align cont_diff_prod contDiff_prod theorem ContDiff.pow {f : E → 𝔸} (hf : ContDiff 𝕜 n f) : ∀ m : ℕ, ContDiff 𝕜 n fun x => f x ^ m | 0 => by simpa using contDiff_const | m + 1 => by simpa [pow_succ] using (hf.pow m).mul hf #align cont_diff.pow ContDiff.pow theorem ContDiffWithinAt.pow {f : E → 𝔸} (hf : ContDiffWithinAt 𝕜 n f s x) (m : ℕ) : ContDiffWithinAt 𝕜 n (fun y => f y ^ m) s x := (contDiff_id.pow m).comp_contDiffWithinAt hf #align cont_diff_within_at.pow ContDiffWithinAt.pow nonrec theorem ContDiffAt.pow {f : E → 𝔸} (hf : ContDiffAt 𝕜 n f x) (m : ℕ) : ContDiffAt 𝕜 n (fun y => f y ^ m) x := hf.pow m #align cont_diff_at.pow ContDiffAt.pow theorem ContDiffOn.pow {f : E → 𝔸} (hf : ContDiffOn 𝕜 n f s) (m : ℕ) : ContDiffOn 𝕜 n (fun y => f y ^ m) s := fun y hy => (hf y hy).pow m #align cont_diff_on.pow ContDiffOn.pow theorem ContDiffWithinAt.div_const {f : E → 𝕜'} {n} (hf : ContDiffWithinAt 𝕜 n f s x) (c : 𝕜') : ContDiffWithinAt 𝕜 n (fun x => f x / c) s x := by simpa only [div_eq_mul_inv] using hf.mul contDiffWithinAt_const #align cont_diff_within_at.div_const ContDiffWithinAt.div_const nonrec theorem ContDiffAt.div_const {f : E → 𝕜'} {n} (hf : ContDiffAt 𝕜 n f x) (c : 𝕜') : ContDiffAt 𝕜 n (fun x => f x / c) x := hf.div_const c #align cont_diff_at.div_const ContDiffAt.div_const theorem ContDiffOn.div_const {f : E → 𝕜'} {n} (hf : ContDiffOn 𝕜 n f s) (c : 𝕜') : ContDiffOn 𝕜 n (fun x => f x / c) s := fun x hx => (hf x hx).div_const c #align cont_diff_on.div_const ContDiffOn.div_const theorem ContDiff.div_const {f : E → 𝕜'} {n} (hf : ContDiff 𝕜 n f) (c : 𝕜') : ContDiff 𝕜 n fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul contDiff_const #align cont_diff.div_const ContDiff.div_const end MulProd /-! ### Scalar multiplication -/ section SMul -- The scalar multiplication is smooth. theorem contDiff_smul : ContDiff 𝕜 n fun p : 𝕜 × F => p.1 • p.2 := isBoundedBilinearMap_smul.contDiff #align cont_diff_smul contDiff_smul /-- The scalar multiplication of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.smul {s : Set E} {f : E → 𝕜} {g : E → F} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x • g x) s x := contDiff_smul.contDiffWithinAt.comp x (hf.prod hg) subset_preimage_univ #align cont_diff_within_at.smul ContDiffWithinAt.smul /-- The scalar multiplication of two `C^n` functions at a point is `C^n` at this point. -/ theorem ContDiffAt.smul {f : E → 𝕜} {g : E → F} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => f x • g x) x := by rw [← contDiffWithinAt_univ] at *; exact hf.smul hg #align cont_diff_at.smul ContDiffAt.smul /-- The scalar multiplication of two `C^n` functions is `C^n`. -/ theorem ContDiff.smul {f : E → 𝕜} {g : E → F} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => f x • g x := contDiff_smul.comp (hf.prod hg) #align cont_diff.smul ContDiff.smul /-- The scalar multiplication of two `C^n` functions on a domain is `C^n`. -/ theorem ContDiffOn.smul {s : Set E} {f : E → 𝕜} {g : E → F} (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).smul (hg x hx) #align cont_diff_on.smul ContDiffOn.smul end SMul /-! ### Constant scalar multiplication Porting note (#11215): TODO: generalize results in this section. 1. It should be possible to assume `[Monoid R] [DistribMulAction R F] [SMulCommClass 𝕜 R F]`. 2. If `c` is a unit (or `R` is a group), then one can drop `ContDiff*` assumptions in some lemmas. -/ section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] variable [ContinuousConstSMul R F] -- The scalar multiplication with a constant is smooth. theorem contDiff_const_smul (c : R) : ContDiff 𝕜 n fun p : F => c • p := (c • ContinuousLinearMap.id 𝕜 F).contDiff #align cont_diff_const_smul contDiff_const_smul /-- The scalar multiplication of a constant and a `C^n` function within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.const_smul {s : Set E} {f : E → F} {x : E} (c : R) (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (fun y => c • f y) s x := (contDiff_const_smul c).contDiffAt.comp_contDiffWithinAt x hf #align cont_diff_within_at.const_smul ContDiffWithinAt.const_smul /-- The scalar multiplication of a constant and a `C^n` function at a point is `C^n` at this point. -/ theorem ContDiffAt.const_smul {f : E → F} {x : E} (c : R) (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun y => c • f y) x := by rw [← contDiffWithinAt_univ] at *; exact hf.const_smul c #align cont_diff_at.const_smul ContDiffAt.const_smul /-- The scalar multiplication of a constant and a `C^n` function is `C^n`. -/ theorem ContDiff.const_smul {f : E → F} (c : R) (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun y => c • f y := (contDiff_const_smul c).comp hf #align cont_diff.const_smul ContDiff.const_smul /-- The scalar multiplication of a constant and a `C^n` on a domain is `C^n`. -/ theorem ContDiffOn.const_smul {s : Set E} {f : E → F} (c : R) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun y => c • f y) s := fun x hx => (hf x hx).const_smul c #align cont_diff_on.const_smul ContDiffOn.const_smul variable {i : ℕ} {a : R} theorem iteratedFDerivWithin_const_smul_apply (hf : ContDiffOn 𝕜 i f s) (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 i (a • f) s x = a • iteratedFDerivWithin 𝕜 i f s x := (a • (1 : F →L[𝕜] F)).iteratedFDerivWithin_comp_left hf hu hx le_rfl #align iterated_fderiv_within_const_smul_apply iteratedFDerivWithin_const_smul_apply theorem iteratedFDeriv_const_smul_apply {x : E} (hf : ContDiff 𝕜 i f) : iteratedFDeriv 𝕜 i (a • f) x = a • iteratedFDeriv 𝕜 i f x := by simp_rw [← contDiffOn_univ, ← iteratedFDerivWithin_univ] at * exact iteratedFDerivWithin_const_smul_apply hf uniqueDiffOn_univ (Set.mem_univ _) #align iterated_fderiv_const_smul_apply iteratedFDeriv_const_smul_apply theorem iteratedFDeriv_const_smul_apply' {x : E} (hf : ContDiff 𝕜 i f) : iteratedFDeriv 𝕜 i (fun x ↦ a • f x) x = a • iteratedFDeriv 𝕜 i f x := iteratedFDeriv_const_smul_apply hf end ConstSMul /-! ### Cartesian product of two functions -/ section prodMap variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] variable {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ theorem ContDiffWithinAt.prod_map' {s : Set E} {t : Set E'} {f : E → F} {g : E' → F'} {p : E × E'} (hf : ContDiffWithinAt 𝕜 n f s p.1) (hg : ContDiffWithinAt 𝕜 n g t p.2) : ContDiffWithinAt 𝕜 n (Prod.map f g) (s ×ˢ t) p := (hf.comp p contDiffWithinAt_fst (prod_subset_preimage_fst _ _)).prod (hg.comp p contDiffWithinAt_snd (prod_subset_preimage_snd _ _)) #align cont_diff_within_at.prod_map' ContDiffWithinAt.prod_map' theorem ContDiffWithinAt.prod_map {s : Set E} {t : Set E'} {f : E → F} {g : E' → F'} {x : E} {y : E'} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g t y) : ContDiffWithinAt 𝕜 n (Prod.map f g) (s ×ˢ t) (x, y) := ContDiffWithinAt.prod_map' hf hg #align cont_diff_within_at.prod_map ContDiffWithinAt.prod_map /-- The product map of two `C^n` functions on a set is `C^n` on the product set. -/ theorem ContDiffOn.prod_map {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {s : Set E} {t : Set E'} {f : E → F} {g : E' → F'} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g t) : ContDiffOn 𝕜 n (Prod.map f g) (s ×ˢ t) := (hf.comp contDiffOn_fst (prod_subset_preimage_fst _ _)).prod (hg.comp contDiffOn_snd (prod_subset_preimage_snd _ _)) #align cont_diff_on.prod_map ContDiffOn.prod_map /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ theorem ContDiffAt.prod_map {f : E → F} {g : E' → F'} {x : E} {y : E'} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g y) : ContDiffAt 𝕜 n (Prod.map f g) (x, y) := by rw [ContDiffAt] at * convert hf.prod_map hg simp only [univ_prod_univ] #align cont_diff_at.prod_map ContDiffAt.prod_map /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ theorem ContDiffAt.prod_map' {f : E → F} {g : E' → F'} {p : E × E'} (hf : ContDiffAt 𝕜 n f p.1) (hg : ContDiffAt 𝕜 n g p.2) : ContDiffAt 𝕜 n (Prod.map f g) p := by rcases p with ⟨⟩ exact ContDiffAt.prod_map hf hg #align cont_diff_at.prod_map' ContDiffAt.prod_map' /-- The product map of two `C^n` functions is `C^n`. -/ theorem ContDiff.prod_map {f : E → F} {g : E' → F'} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n (Prod.map f g) := by rw [contDiff_iff_contDiffAt] at * exact fun ⟨x, y⟩ => (hf x).prod_map (hg y) #align cont_diff.prod_map ContDiff.prod_map theorem contDiff_prod_mk_left (f₀ : F) : ContDiff 𝕜 n fun e : E => (e, f₀) := contDiff_id.prod contDiff_const #align cont_diff_prod_mk_left contDiff_prod_mk_left theorem contDiff_prod_mk_right (e₀ : E) : ContDiff 𝕜 n fun f : F => (e₀, f) := contDiff_const.prod contDiff_id #align cont_diff_prod_mk_right contDiff_prod_mk_right end prodMap /-! ### Inversion in a complete normed algebra -/ section AlgebraInverse variable (𝕜) {R : Type*} [NormedRing R] -- Porting note: this couldn't be on the same line as the binder type update of `𝕜` variable [NormedAlgebra 𝕜 R] open NormedRing ContinuousLinearMap Ring /-- In a complete normed algebra, the operation of inversion is `C^n`, for all `n`, at each invertible element. The proof is by induction, bootstrapping using an identity expressing the derivative of inversion as a bilinear map of inversion itself. -/ theorem contDiffAt_ring_inverse [CompleteSpace R] (x : Rˣ) : ContDiffAt 𝕜 n Ring.inverse (x : R) := by induction' n using ENat.nat_induction with n IH Itop · intro m hm refine ⟨{ y : R | IsUnit y }, ?_, ?_⟩ · simp [nhdsWithin_univ] exact x.nhds · use ftaylorSeriesWithin 𝕜 inverse univ rw [le_antisymm hm bot_le, hasFTaylorSeriesUpToOn_zero_iff] constructor · rintro _ ⟨x', rfl⟩ exact (inverse_continuousAt x').continuousWithinAt · simp [ftaylorSeriesWithin] · rw [contDiffAt_succ_iff_hasFDerivAt] refine ⟨fun x : R => -mulLeftRight 𝕜 R (inverse x) (inverse x), ?_, ?_⟩ · refine ⟨{ y : R | IsUnit y }, x.nhds, ?_⟩ rintro _ ⟨y, rfl⟩ simp_rw [inverse_unit] exact hasFDerivAt_ring_inverse y · convert (mulLeftRight_isBoundedBilinear 𝕜 R).contDiff.neg.comp_contDiffAt (x : R) (IH.prod IH) · exact contDiffAt_top.mpr Itop #align cont_diff_at_ring_inverse contDiffAt_ring_inverse variable {𝕜' : Type*} [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [CompleteSpace 𝕜'] theorem contDiffAt_inv {x : 𝕜'} (hx : x ≠ 0) {n} : ContDiffAt 𝕜 n Inv.inv x := by simpa only [Ring.inverse_eq_inv'] using contDiffAt_ring_inverse 𝕜 (Units.mk0 x hx) #align cont_diff_at_inv contDiffAt_inv theorem contDiffOn_inv {n} : ContDiffOn 𝕜 n (Inv.inv : 𝕜' → 𝕜') {0}ᶜ := fun _ hx => (contDiffAt_inv 𝕜 hx).contDiffWithinAt #align cont_diff_on_inv contDiffOn_inv variable {𝕜} -- TODO: the next few lemmas don't need `𝕜` or `𝕜'` to be complete -- A good way to show this is to generalize `contDiffAt_ring_inverse` to the setting -- of a function `f` such that `∀ᶠ x in 𝓝 a, x * f x = 1`. theorem ContDiffWithinAt.inv {f : E → 𝕜'} {n} (hf : ContDiffWithinAt 𝕜 n f s x) (hx : f x ≠ 0) : ContDiffWithinAt 𝕜 n (fun x => (f x)⁻¹) s x := (contDiffAt_inv 𝕜 hx).comp_contDiffWithinAt x hf #align cont_diff_within_at.inv ContDiffWithinAt.inv theorem ContDiffOn.inv {f : E → 𝕜'} {n} (hf : ContDiffOn 𝕜 n f s) (h : ∀ x ∈ s, f x ≠ 0) : ContDiffOn 𝕜 n (fun x => (f x)⁻¹) s := fun x hx => (hf.contDiffWithinAt hx).inv (h x hx) #align cont_diff_on.inv ContDiffOn.inv nonrec theorem ContDiffAt.inv {f : E → 𝕜'} {n} (hf : ContDiffAt 𝕜 n f x) (hx : f x ≠ 0) : ContDiffAt 𝕜 n (fun x => (f x)⁻¹) x := hf.inv hx #align cont_diff_at.inv ContDiffAt.inv theorem ContDiff.inv {f : E → 𝕜'} {n} (hf : ContDiff 𝕜 n f) (h : ∀ x, f x ≠ 0) : ContDiff 𝕜 n fun x => (f x)⁻¹ := by rw [contDiff_iff_contDiffAt]; exact fun x => hf.contDiffAt.inv (h x) #align cont_diff.inv ContDiff.inv -- TODO: generalize to `f g : E → 𝕜'` theorem ContDiffWithinAt.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) (hx : g x ≠ 0) : ContDiffWithinAt 𝕜 n (fun x => f x / g x) s x := by simpa only [div_eq_mul_inv] using hf.mul (hg.inv hx) #align cont_diff_within_at.div ContDiffWithinAt.div theorem ContDiffOn.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) (h₀ : ∀ x ∈ s, g x ≠ 0) : ContDiffOn 𝕜 n (f / g) s := fun x hx => (hf x hx).div (hg x hx) (h₀ x hx) #align cont_diff_on.div ContDiffOn.div nonrec theorem ContDiffAt.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) (hx : g x ≠ 0) : ContDiffAt 𝕜 n (fun x => f x / g x) x := hf.div hg hx #align cont_diff_at.div ContDiffAt.div theorem ContDiff.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) (h0 : ∀ x, g x ≠ 0) : ContDiff 𝕜 n fun x => f x / g x := by simp only [contDiff_iff_contDiffAt] at * exact fun x => (hf x).div (hg x) (h0 x) #align cont_diff.div ContDiff.div end AlgebraInverse /-! ### Inversion of continuous linear maps between Banach spaces -/ section MapInverse open ContinuousLinearMap /-- At a continuous linear equivalence `e : E ≃L[𝕜] F` between Banach spaces, the operation of inversion is `C^n`, for all `n`. -/ theorem contDiffAt_map_inverse [CompleteSpace E] (e : E ≃L[𝕜] F) : ContDiffAt 𝕜 n inverse (e : E →L[𝕜] F) := by nontriviality E -- first, we use the lemma `to_ring_inverse` to rewrite in terms of `Ring.inverse` in the ring -- `E →L[𝕜] E` let O₁ : (E →L[𝕜] E) → F →L[𝕜] E := fun f => f.comp (e.symm : F →L[𝕜] E) let O₂ : (E →L[𝕜] F) → E →L[𝕜] E := fun f => (e.symm : F →L[𝕜] E).comp f have : ContinuousLinearMap.inverse = O₁ ∘ Ring.inverse ∘ O₂ := funext (to_ring_inverse e) rw [this] -- `O₁` and `O₂` are `ContDiff`, -- so we reduce to proving that `Ring.inverse` is `ContDiff` have h₁ : ContDiff 𝕜 n O₁ := contDiff_id.clm_comp contDiff_const have h₂ : ContDiff 𝕜 n O₂ := contDiff_const.clm_comp contDiff_id refine h₁.contDiffAt.comp _ (ContDiffAt.comp _ ?_ h₂.contDiffAt) convert contDiffAt_ring_inverse 𝕜 (1 : (E →L[𝕜] E)ˣ) simp [O₂, one_def] #align cont_diff_at_map_inverse contDiffAt_map_inverse end MapInverse section FunctionInverse open ContinuousLinearMap /-- If `f` is a local homeomorphism and the point `a` is in its target, and if `f` is `n` times continuously differentiable at `f.symm a`, and if the derivative at `f.symm a` is a continuous linear equivalence, then `f.symm` is `n` times continuously differentiable at the point `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/
Mathlib/Analysis/Calculus/ContDiff/Basic.lean
1,880
1,924
theorem PartialHomeomorph.contDiffAt_symm [CompleteSpace E] (f : PartialHomeomorph E F) {f₀' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target) (hf₀' : HasFDerivAt f (f₀' : E →L[𝕜] F) (f.symm a)) (hf : ContDiffAt 𝕜 n f (f.symm a)) : ContDiffAt 𝕜 n f.symm a := by
-- We prove this by induction on `n` induction' n using ENat.nat_induction with n IH Itop · rw [contDiffAt_zero] exact ⟨f.target, IsOpen.mem_nhds f.open_target ha, f.continuousOn_invFun⟩ · obtain ⟨f', ⟨u, hu, hff'⟩, hf'⟩ := contDiffAt_succ_iff_hasFDerivAt.mp hf rw [contDiffAt_succ_iff_hasFDerivAt] -- For showing `n.succ` times continuous differentiability (the main inductive step), it -- suffices to produce the derivative and show that it is `n` times continuously differentiable have eq_f₀' : f' (f.symm a) = f₀' := (hff' (f.symm a) (mem_of_mem_nhds hu)).unique hf₀' -- This follows by a bootstrapping formula expressing the derivative as a function of `f` itself refine ⟨inverse ∘ f' ∘ f.symm, ?_, ?_⟩ · -- We first check that the derivative of `f` is that formula have h_nhds : { y : E | ∃ e : E ≃L[𝕜] F, ↑e = f' y } ∈ 𝓝 (f.symm a) := by have hf₀' := f₀'.nhds rw [← eq_f₀'] at hf₀' exact hf'.continuousAt.preimage_mem_nhds hf₀' obtain ⟨t, htu, ht, htf⟩ := mem_nhds_iff.mp (Filter.inter_mem hu h_nhds) use f.target ∩ f.symm ⁻¹' t refine ⟨IsOpen.mem_nhds ?_ ?_, ?_⟩ · exact f.isOpen_inter_preimage_symm ht · exact mem_inter ha (mem_preimage.mpr htf) intro x hx obtain ⟨hxu, e, he⟩ := htu hx.2 have h_deriv : HasFDerivAt f (e : E →L[𝕜] F) (f.symm x) := by rw [he] exact hff' (f.symm x) hxu convert f.hasFDerivAt_symm hx.1 h_deriv simp [← he] · -- Then we check that the formula, being a composition of `ContDiff` pieces, is -- itself `ContDiff` have h_deriv₁ : ContDiffAt 𝕜 n inverse (f' (f.symm a)) := by rw [eq_f₀'] exact contDiffAt_map_inverse _ have h_deriv₂ : ContDiffAt 𝕜 n f.symm a := by refine IH (hf.of_le ?_) norm_cast exact Nat.le_succ n exact (h_deriv₁.comp _ hf').comp _ h_deriv₂ · refine contDiffAt_top.mpr ?_ intro n exact Itop n (contDiffAt_top.mp hf n)
/- 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, Peter Pfaffelhuber -/ import Mathlib.MeasureTheory.PiSystem import Mathlib.Order.OmegaCompletePartialOrder import Mathlib.Topology.Constructions import Mathlib.MeasureTheory.MeasurableSpace.Basic /-! # π-systems of cylinders and square cylinders The instance `MeasurableSpace.pi` on `∀ i, α i`, where each `α i` has a `MeasurableSpace` `m i`, is defined as `⨆ i, (m i).comap (fun a => a i)`. That is, a function `g : β → ∀ i, α i` is measurable iff for all `i`, the function `b ↦ g b i` is measurable. We define two π-systems generating `MeasurableSpace.pi`, cylinders and square cylinders. ## Main definitions Given a finite set `s` of indices, a cylinder is the product of a set of `∀ i : s, α i` and of `univ` on the other indices. A square cylinder is a cylinder for which the set on `∀ i : s, α i` is a product set. * `cylinder s S`: cylinder with base set `S : Set (∀ i : s, α i)` where `s` is a `Finset` * `squareCylinders C` with `C : ∀ i, Set (Set (α i))`: set of all square cylinders such that for all `i` in the finset defining the box, the projection to `α i` belongs to `C i`. The main application of this is with `C i = {s : Set (α i) | MeasurableSet s}`. * `measurableCylinders`: set of all cylinders with measurable base sets. ## Main statements * `generateFrom_squareCylinders`: square cylinders formed from measurable sets generate the product σ-algebra * `generateFrom_measurableCylinders`: cylinders formed from measurable sets generate the product σ-algebra -/ open Set namespace MeasureTheory variable {ι : Type _} {α : ι → Type _} section squareCylinders /-- Given a finite set `s` of indices, a square cylinder is the product of a set `S` of `∀ i : s, α i` and of `univ` on the other indices. The set `S` is a product of sets `t i` such that for all `i : s`, `t i ∈ C i`. `squareCylinders` is the set of all such squareCylinders. -/ def squareCylinders (C : ∀ i, Set (Set (α i))) : Set (Set (∀ i, α i)) := {S | ∃ s : Finset ι, ∃ t ∈ univ.pi C, S = (s : Set ι).pi t} theorem squareCylinders_eq_iUnion_image (C : ∀ i, Set (Set (α i))) : squareCylinders C = ⋃ s : Finset ι, (fun t ↦ (s : Set ι).pi t) '' univ.pi C := by ext1 f simp only [squareCylinders, mem_iUnion, mem_image, mem_univ_pi, exists_prop, mem_setOf_eq, eq_comm (a := f)] theorem isPiSystem_squareCylinders {C : ∀ i, Set (Set (α i))} (hC : ∀ i, IsPiSystem (C i)) (hC_univ : ∀ i, univ ∈ C i) : IsPiSystem (squareCylinders C) := by rintro S₁ ⟨s₁, t₁, h₁, rfl⟩ S₂ ⟨s₂, t₂, h₂, rfl⟩ hst_nonempty classical let t₁' := s₁.piecewise t₁ (fun i ↦ univ) let t₂' := s₂.piecewise t₂ (fun i ↦ univ) have h1 : ∀ i ∈ (s₁ : Set ι), t₁ i = t₁' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h1' : ∀ i ∉ (s₁ : Set ι), t₁' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi have h2 : ∀ i ∈ (s₂ : Set ι), t₂ i = t₂' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h2' : ∀ i ∉ (s₂ : Set ι), t₂' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, ← union_pi_inter h1' h2'] refine ⟨s₁ ∪ s₂, fun i ↦ t₁' i ∩ t₂' i, ?_, ?_⟩ · rw [mem_univ_pi] intro i have : (t₁' i ∩ t₂' i).Nonempty := by obtain ⟨f, hf⟩ := hst_nonempty rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, mem_inter_iff, mem_pi, mem_pi] at hf refine ⟨f i, ⟨?_, ?_⟩⟩ · by_cases hi₁ : i ∈ s₁ · exact hf.1 i hi₁ · rw [h1' i hi₁] exact mem_univ _ · by_cases hi₂ : i ∈ s₂ · exact hf.2 i hi₂ · rw [h2' i hi₂] exact mem_univ _ refine hC i _ ?_ _ ?_ this · by_cases hi₁ : i ∈ s₁ · rw [← h1 i hi₁] exact h₁ i (mem_univ _) · rw [h1' i hi₁] exact hC_univ i · by_cases hi₂ : i ∈ s₂ · rw [← h2 i hi₂] exact h₂ i (mem_univ _) · rw [h2' i hi₂] exact hC_univ i · rw [Finset.coe_union] theorem comap_eval_le_generateFrom_squareCylinders_singleton (α : ι → Type*) [m : ∀ i, MeasurableSpace (α i)] (i : ι) : MeasurableSpace.comap (Function.eval i) (m i) ≤ MeasurableSpace.generateFrom ((fun t ↦ ({i} : Set ι).pi t) '' univ.pi fun i ↦ {s : Set (α i) | MeasurableSet s}) := by simp only [Function.eval, singleton_pi, ge_iff_le] rw [MeasurableSpace.comap_eq_generateFrom] refine MeasurableSpace.generateFrom_mono fun S ↦ ?_ simp only [mem_setOf_eq, mem_image, mem_univ_pi, forall_exists_index, and_imp] intro t ht h classical refine ⟨fun j ↦ if hji : j = i then by convert t else univ, fun j ↦ ?_, ?_⟩ · by_cases hji : j = i · simp only [hji, eq_self_iff_true, eq_mpr_eq_cast, dif_pos] convert ht simp only [id_eq, cast_heq] · simp only [hji, not_false_iff, dif_neg, MeasurableSet.univ] · simp only [id_eq, eq_mpr_eq_cast, ← h] ext1 x simp only [singleton_pi, Function.eval, cast_eq, dite_eq_ite, ite_true, mem_preimage] /-- The square cylinders formed from measurable sets generate the product σ-algebra. -/ theorem generateFrom_squareCylinders [∀ i, MeasurableSpace (α i)] : MeasurableSpace.generateFrom (squareCylinders fun i ↦ {s : Set (α i) | MeasurableSet s}) = MeasurableSpace.pi := by apply le_antisymm · rw [MeasurableSpace.generateFrom_le_iff] rintro S ⟨s, t, h, rfl⟩ simp only [mem_univ_pi, mem_setOf_eq] at h exact MeasurableSet.pi (Finset.countable_toSet _) (fun i _ ↦ h i) · refine iSup_le fun i ↦ ?_ refine (comap_eval_le_generateFrom_squareCylinders_singleton α i).trans ?_ refine MeasurableSpace.generateFrom_mono ?_ rw [← Finset.coe_singleton, squareCylinders_eq_iUnion_image] exact subset_iUnion (fun (s : Finset ι) ↦ (fun t : ∀ i, Set (α i) ↦ (s : Set ι).pi t) '' univ.pi (fun i ↦ setOf MeasurableSet)) ({i} : Finset ι) end squareCylinders section cylinder /-- Given a finite set `s` of indices, a cylinder is the preimage of a set `S` of `∀ i : s, α i` by the projection from `∀ i, α i` to `∀ i : s, α i`. -/ def cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : Set (∀ i, α i) := (fun (f : ∀ i, α i) (i : s) ↦ f i) ⁻¹' S @[simp] theorem mem_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) (f : ∀ i, α i) : f ∈ cylinder s S ↔ (fun i : s ↦ f i) ∈ S := mem_preimage @[simp] theorem cylinder_empty (s : Finset ι) : cylinder s (∅ : Set (∀ i : s, α i)) = ∅ := by rw [cylinder, preimage_empty] @[simp] theorem cylinder_univ (s : Finset ι) : cylinder s (univ : Set (∀ i : s, α i)) = univ := by rw [cylinder, preimage_univ] @[simp] theorem cylinder_eq_empty_iff [h_nonempty : Nonempty (∀ i, α i)] (s : Finset ι) (S : Set (∀ i : s, α i)) : cylinder s S = ∅ ↔ S = ∅ := by refine ⟨fun h ↦ ?_, fun h ↦ by (rw [h]; exact cylinder_empty _)⟩ by_contra hS rw [← Ne, ← nonempty_iff_ne_empty] at hS let f := hS.some have hf : f ∈ S := hS.choose_spec classical let f' : ∀ i, α i := fun i ↦ if hi : i ∈ s then f ⟨i, hi⟩ else h_nonempty.some i have hf' : f' ∈ cylinder s S := by rw [mem_cylinder] simpa only [f', Finset.coe_mem, dif_pos] rw [h] at hf' exact not_mem_empty _ hf' theorem inter_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∩ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) ((fun f ↦ fun j : s₁ ↦ f ⟨j, Finset.mem_union_left s₂ j.prop⟩) ⁻¹' S₁ ∩ (fun f ↦ fun j : s₂ ↦ f ⟨j, Finset.mem_union_right s₁ j.prop⟩) ⁻¹' S₂) := by ext1 f; simp only [mem_inter_iff, mem_cylinder, mem_setOf_eq]; rfl theorem inter_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∩ cylinder s S₂ = cylinder s (S₁ ∩ S₂) := by classical rw [inter_cylinder]; rfl theorem union_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∪ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) ((fun f ↦ fun j : s₁ ↦ f ⟨j, Finset.mem_union_left s₂ j.prop⟩) ⁻¹' S₁ ∪ (fun f ↦ fun j : s₂ ↦ f ⟨j, Finset.mem_union_right s₁ j.prop⟩) ⁻¹' S₂) := by ext1 f; simp only [mem_union, mem_cylinder, mem_setOf_eq]; rfl theorem union_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∪ cylinder s S₂ = cylinder s (S₁ ∪ S₂) := by classical rw [union_cylinder]; rfl theorem compl_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : (cylinder s S)ᶜ = cylinder s (Sᶜ) := by ext1 f; simp only [mem_compl_iff, mem_cylinder] theorem diff_cylinder_same (s : Finset ι) (S T : Set (∀ i : s, α i)) : cylinder s S \ cylinder s T = cylinder s (S \ T) := by ext1 f; simp only [mem_diff, mem_cylinder] theorem eq_of_cylinder_eq_of_subset [h_nonempty : Nonempty (∀ i, α i)] {I J : Finset ι} {S : Set (∀ i : I, α i)} {T : Set (∀ i : J, α i)} (h_eq : cylinder I S = cylinder J T) (hJI : J ⊆ I) : S = (fun f : ∀ i : I, α i ↦ fun j : J ↦ f ⟨j, hJI j.prop⟩) ⁻¹' T := by rw [Set.ext_iff] at h_eq simp only [mem_cylinder] at h_eq ext1 f simp only [mem_preimage] classical specialize h_eq fun i ↦ if hi : i ∈ I then f ⟨i, hi⟩ else h_nonempty.some i have h_mem : ∀ j : J, ↑j ∈ I := fun j ↦ hJI j.prop simp only [Finset.coe_mem, dite_true, h_mem] at h_eq exact h_eq theorem cylinder_eq_cylinder_union [DecidableEq ι] (I : Finset ι) (S : Set (∀ i : I, α i)) (J : Finset ι) : cylinder I S = cylinder (I ∪ J) ((fun f ↦ fun j : I ↦ f ⟨j, Finset.mem_union_left J j.prop⟩) ⁻¹' S) := by ext1 f; simp only [mem_cylinder, mem_preimage] theorem disjoint_cylinder_iff [Nonempty (∀ i, α i)] {s t : Finset ι} {S : Set (∀ i : s, α i)} {T : Set (∀ i : t, α i)} [DecidableEq ι] : Disjoint (cylinder s S) (cylinder t T) ↔ Disjoint ((fun f : ∀ i : (s ∪ t : Finset ι), α i ↦ fun j : s ↦ f ⟨j, Finset.mem_union_left t j.prop⟩) ⁻¹' S) ((fun f ↦ fun j : t ↦ f ⟨j, Finset.mem_union_right s j.prop⟩) ⁻¹' T) := by simp_rw [Set.disjoint_iff, subset_empty_iff, inter_cylinder, cylinder_eq_empty_iff] theorem IsClosed.cylinder [∀ i, TopologicalSpace (α i)] (s : Finset ι) {S : Set (∀ i : s, α i)} (hs : IsClosed S) : IsClosed (cylinder s S) := hs.preimage (continuous_pi fun _ ↦ continuous_apply _) theorem _root_.MeasurableSet.cylinder [∀ i, MeasurableSpace (α i)] (s : Finset ι) {S : Set (∀ i : s, α i)} (hS : MeasurableSet S) : MeasurableSet (cylinder s S) := measurable_pi_lambda _ (fun _ ↦ measurable_pi_apply _) hS end cylinder section cylinders /-- Given a finite set `s` of indices, a cylinder is the preimage of a set `S` of `∀ i : s, α i` by the projection from `∀ i, α i` to `∀ i : s, α i`. `measurableCylinders` is the set of all cylinders with measurable base `S`. -/ def measurableCylinders (α : ι → Type*) [∀ i, MeasurableSpace (α i)] : Set (Set (∀ i, α i)) := ⋃ (s) (S) (_ : MeasurableSet S), {cylinder s S} theorem empty_mem_measurableCylinders (α : ι → Type*) [∀ i, MeasurableSpace (α i)] : ∅ ∈ measurableCylinders α := by simp_rw [measurableCylinders, mem_iUnion, mem_singleton_iff] exact ⟨∅, ∅, MeasurableSet.empty, (cylinder_empty _).symm⟩ variable [∀ i, MeasurableSpace (α i)] {s t : Set (∀ i, α i)} @[simp] theorem mem_measurableCylinders (t : Set (∀ i, α i)) : t ∈ measurableCylinders α ↔ ∃ s S, MeasurableSet S ∧ t = cylinder s S := by simp_rw [measurableCylinders, mem_iUnion, exists_prop, mem_singleton_iff] /-- A finset `s` such that `t = cylinder s S`. `S` is given by `measurableCylinders.set`. -/ noncomputable def measurableCylinders.finset (ht : t ∈ measurableCylinders α) : Finset ι := ((mem_measurableCylinders t).mp ht).choose /-- A set `S` such that `t = cylinder s S`. `s` is given by `measurableCylinders.finset`. -/ def measurableCylinders.set (ht : t ∈ measurableCylinders α) : Set (∀ i : measurableCylinders.finset ht, α i) := ((mem_measurableCylinders t).mp ht).choose_spec.choose theorem measurableCylinders.measurableSet (ht : t ∈ measurableCylinders α) : MeasurableSet (measurableCylinders.set ht) := ((mem_measurableCylinders t).mp ht).choose_spec.choose_spec.left theorem measurableCylinders.eq_cylinder (ht : t ∈ measurableCylinders α) : t = cylinder (measurableCylinders.finset ht) (measurableCylinders.set ht) := ((mem_measurableCylinders t).mp ht).choose_spec.choose_spec.right theorem cylinder_mem_measurableCylinders (s : Finset ι) (S : Set (∀ i : s, α i)) (hS : MeasurableSet S) : cylinder s S ∈ measurableCylinders α := by rw [mem_measurableCylinders]; exact ⟨s, S, hS, rfl⟩ theorem inter_mem_measurableCylinders (hs : s ∈ measurableCylinders α) (ht : t ∈ measurableCylinders α) : s ∩ t ∈ measurableCylinders α := by rw [mem_measurableCylinders] at * obtain ⟨s₁, S₁, hS₁, rfl⟩ := hs obtain ⟨s₂, S₂, hS₂, rfl⟩ := ht classical refine ⟨s₁ ∪ s₂, (fun f ↦ (fun i ↦ f ⟨i, Finset.mem_union_left s₂ i.prop⟩ : ∀ i : s₁, α i)) ⁻¹' S₁ ∩ {f | (fun i ↦ f ⟨i, Finset.mem_union_right s₁ i.prop⟩ : ∀ i : s₂, α i) ∈ S₂}, ?_, ?_⟩ · refine MeasurableSet.inter ?_ ?_ · exact measurable_pi_lambda _ (fun _ ↦ measurable_pi_apply _) hS₁ · exact measurable_pi_lambda _ (fun _ ↦ measurable_pi_apply _) hS₂ · exact inter_cylinder _ _ _ _ theorem isPiSystem_measurableCylinders : IsPiSystem (measurableCylinders α) := fun _ hS _ hT _ ↦ inter_mem_measurableCylinders hS hT
Mathlib/MeasureTheory/Constructions/Cylinders.lean
317
322
theorem compl_mem_measurableCylinders (hs : s ∈ measurableCylinders α) : sᶜ ∈ measurableCylinders α := by
rw [mem_measurableCylinders] at hs ⊢ obtain ⟨s, S, hS, rfl⟩ := hs refine ⟨s, Sᶜ, hS.compl, ?_⟩ rw [compl_cylinder]
/- 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, Alex Kontorovich, Heather Macbeth -/ import Mathlib.MeasureTheory.Group.Action import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.MeasureTheory.Group.Pointwise #align_import measure_theory.group.fundamental_domain from "leanprover-community/mathlib"@"3b52265189f3fb43aa631edffce5d060fafaf82f" /-! # Fundamental domain of a group action A set `s` is said to be a *fundamental domain* of an action of a group `G` on a measurable space `α` with respect to a measure `μ` if * `s` is a measurable set; * the sets `g • s` over all `g : G` cover almost all points of the whole space; * the sets `g • s`, are pairwise a.e. disjoint, i.e., `μ (g₁ • s ∩ g₂ • s) = 0` whenever `g₁ ≠ g₂`; we require this for `g₂ = 1` in the definition, then deduce it for any two `g₁ ≠ g₂`. In this file we prove that in case of a countable group `G` and a measure preserving action, any two fundamental domains have the same measure, and for a `G`-invariant function, its integrals over any two fundamental domains are equal to each other. We also generate additive versions of all theorems in this file using the `to_additive` attribute. * We define the `HasFundamentalDomain` typeclass, in particular to be able to define the `covolume` of a quotient of `α` by a group `G`, which under reasonable conditions does not depend on the choice of fundamental domain. * We define the `QuotientMeasureEqMeasurePreimage` typeclass to describe a situation in which a measure `μ` on `α ⧸ G` can be computed by taking a measure `ν` on `α` of the intersection of the pullback with a fundamental domain. ## Main declarations * `MeasureTheory.IsFundamentalDomain`: Predicate for a set to be a fundamental domain of the action of a group * `MeasureTheory.fundamentalFrontier`: Fundamental frontier of a set under the action of a group. Elements of `s` that belong to some other translate of `s`. * `MeasureTheory.fundamentalInterior`: Fundamental interior of a set under the action of a group. Elements of `s` that do not belong to any other translate of `s`. -/ open scoped ENNReal Pointwise Topology NNReal ENNReal MeasureTheory open MeasureTheory MeasureTheory.Measure Set Function TopologicalSpace Filter namespace MeasureTheory /-- A measurable set `s` is a *fundamental domain* for an additive action of an additive group `G` on a measurable space `α` with respect to a measure `α` if the sets `g +ᵥ s`, `g : G`, are pairwise a.e. disjoint and cover the whole space. -/ structure IsAddFundamentalDomain (G : Type*) {α : Type*} [Zero G] [VAdd G α] [MeasurableSpace α] (s : Set α) (μ : Measure α := by volume_tac) : Prop where protected nullMeasurableSet : NullMeasurableSet s μ protected ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g +ᵥ x ∈ s protected aedisjoint : Pairwise <| (AEDisjoint μ on fun g : G => g +ᵥ s) #align measure_theory.is_add_fundamental_domain MeasureTheory.IsAddFundamentalDomain /-- A measurable set `s` is a *fundamental domain* for an action of a group `G` on a measurable space `α` with respect to a measure `α` if the sets `g • s`, `g : G`, are pairwise a.e. disjoint and cover the whole space. -/ @[to_additive IsAddFundamentalDomain] structure IsFundamentalDomain (G : Type*) {α : Type*} [One G] [SMul G α] [MeasurableSpace α] (s : Set α) (μ : Measure α := by volume_tac) : Prop where protected nullMeasurableSet : NullMeasurableSet s μ protected ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g • x ∈ s protected aedisjoint : Pairwise <| (AEDisjoint μ on fun g : G => g • s) #align measure_theory.is_fundamental_domain MeasureTheory.IsFundamentalDomain variable {G H α β E : Type*} namespace IsFundamentalDomain variable [Group G] [Group H] [MulAction G α] [MeasurableSpace α] [MulAction H β] [MeasurableSpace β] [NormedAddCommGroup E] {s t : Set α} {μ : Measure α} /-- If for each `x : α`, exactly one of `g • x`, `g : G`, belongs to a measurable set `s`, then `s` is a fundamental domain for the action of `G` on `α`. -/ @[to_additive "If for each `x : α`, exactly one of `g +ᵥ x`, `g : G`, belongs to a measurable set `s`, then `s` is a fundamental domain for the additive action of `G` on `α`."] theorem mk' (h_meas : NullMeasurableSet s μ) (h_exists : ∀ x : α, ∃! g : G, g • x ∈ s) : IsFundamentalDomain G s μ where nullMeasurableSet := h_meas ae_covers := eventually_of_forall fun x => (h_exists x).exists aedisjoint a b hab := Disjoint.aedisjoint <| disjoint_left.2 fun x hxa hxb => by rw [mem_smul_set_iff_inv_smul_mem] at hxa hxb exact hab (inv_injective <| (h_exists x).unique hxa hxb) #align measure_theory.is_fundamental_domain.mk' MeasureTheory.IsFundamentalDomain.mk' #align measure_theory.is_add_fundamental_domain.mk' MeasureTheory.IsAddFundamentalDomain.mk' /-- For `s` to be a fundamental domain, it's enough to check `MeasureTheory.AEDisjoint (g • s) s` for `g ≠ 1`. -/ @[to_additive "For `s` to be a fundamental domain, it's enough to check `MeasureTheory.AEDisjoint (g +ᵥ s) s` for `g ≠ 0`."] theorem mk'' (h_meas : NullMeasurableSet s μ) (h_ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g • x ∈ s) (h_ae_disjoint : ∀ g, g ≠ (1 : G) → AEDisjoint μ (g • s) s) (h_qmp : ∀ g : G, QuasiMeasurePreserving ((g • ·) : α → α) μ μ) : IsFundamentalDomain G s μ where nullMeasurableSet := h_meas ae_covers := h_ae_covers aedisjoint := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp #align measure_theory.is_fundamental_domain.mk'' MeasureTheory.IsFundamentalDomain.mk'' #align measure_theory.is_add_fundamental_domain.mk'' MeasureTheory.IsAddFundamentalDomain.mk'' /-- If a measurable space has a finite measure `μ` and a countable group `G` acts quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient to check that its translates `g • s` are (almost) disjoint and that the sum `∑' g, μ (g • s)` is sufficiently large. -/ @[to_additive "If a measurable space has a finite measure `μ` and a countable additive group `G` acts quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient to check that its translates `g +ᵥ s` are (almost) disjoint and that the sum `∑' g, μ (g +ᵥ s)` is sufficiently large."] theorem mk_of_measure_univ_le [IsFiniteMeasure μ] [Countable G] (h_meas : NullMeasurableSet s μ) (h_ae_disjoint : ∀ g ≠ (1 : G), AEDisjoint μ (g • s) s) (h_qmp : ∀ g : G, QuasiMeasurePreserving (g • · : α → α) μ μ) (h_measure_univ_le : μ (univ : Set α) ≤ ∑' g : G, μ (g • s)) : IsFundamentalDomain G s μ := have aedisjoint : Pairwise (AEDisjoint μ on fun g : G => g • s) := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp { nullMeasurableSet := h_meas aedisjoint ae_covers := by replace h_meas : ∀ g : G, NullMeasurableSet (g • s) μ := fun g => by rw [← inv_inv g, ← preimage_smul]; exact h_meas.preimage (h_qmp g⁻¹) have h_meas' : NullMeasurableSet {a | ∃ g : G, g • a ∈ s} μ := by rw [← iUnion_smul_eq_setOf_exists]; exact .iUnion h_meas rw [ae_iff_measure_eq h_meas', ← iUnion_smul_eq_setOf_exists] refine le_antisymm (measure_mono <| subset_univ _) ?_ rw [measure_iUnion₀ aedisjoint h_meas] exact h_measure_univ_le } #align measure_theory.is_fundamental_domain.mk_of_measure_univ_le MeasureTheory.IsFundamentalDomain.mk_of_measure_univ_le #align measure_theory.is_add_fundamental_domain.mk_of_measure_univ_le MeasureTheory.IsAddFundamentalDomain.mk_of_measure_univ_le @[to_additive] theorem iUnion_smul_ae_eq (h : IsFundamentalDomain G s μ) : ⋃ g : G, g • s =ᵐ[μ] univ := eventuallyEq_univ.2 <| h.ae_covers.mono fun _ ⟨g, hg⟩ => mem_iUnion.2 ⟨g⁻¹, _, hg, inv_smul_smul _ _⟩ #align measure_theory.is_fundamental_domain.Union_smul_ae_eq MeasureTheory.IsFundamentalDomain.iUnion_smul_ae_eq #align measure_theory.is_add_fundamental_domain.Union_vadd_ae_eq MeasureTheory.IsAddFundamentalDomain.iUnion_vadd_ae_eq @[to_additive] theorem measure_ne_zero [MeasurableSpace G] [Countable G] [MeasurableSMul G α] [SMulInvariantMeasure G α μ] (hμ : μ ≠ 0) (h : IsFundamentalDomain G s μ) : μ s ≠ 0 := by have hc := measure_univ_pos.mpr hμ contrapose! hc rw [← measure_congr h.iUnion_smul_ae_eq] refine le_trans (measure_iUnion_le _) ?_ simp_rw [measure_smul, hc, tsum_zero, le_refl] @[to_additive] theorem mono (h : IsFundamentalDomain G s μ) {ν : Measure α} (hle : ν ≪ μ) : IsFundamentalDomain G s ν := ⟨h.1.mono_ac hle, hle h.2, h.aedisjoint.mono fun _ _ h => hle h⟩ #align measure_theory.is_fundamental_domain.mono MeasureTheory.IsFundamentalDomain.mono #align measure_theory.is_add_fundamental_domain.mono MeasureTheory.IsAddFundamentalDomain.mono @[to_additive] theorem preimage_of_equiv {ν : Measure β} (h : IsFundamentalDomain G s μ) {f : β → α} (hf : QuasiMeasurePreserving f ν μ) {e : G → H} (he : Bijective e) (hef : ∀ g, Semiconj f (e g • ·) (g • ·)) : IsFundamentalDomain H (f ⁻¹' s) ν where nullMeasurableSet := h.nullMeasurableSet.preimage hf ae_covers := (hf.ae h.ae_covers).mono fun x ⟨g, hg⟩ => ⟨e g, by rwa [mem_preimage, hef g x]⟩ aedisjoint a b hab := by lift e to G ≃ H using he have : (e.symm a⁻¹)⁻¹ ≠ (e.symm b⁻¹)⁻¹ := by simp [hab] have := (h.aedisjoint this).preimage hf simp only [Semiconj] at hef simpa only [onFun, ← preimage_smul_inv, preimage_preimage, ← hef, e.apply_symm_apply, inv_inv] using this #align measure_theory.is_fundamental_domain.preimage_of_equiv MeasureTheory.IsFundamentalDomain.preimage_of_equiv #align measure_theory.is_add_fundamental_domain.preimage_of_equiv MeasureTheory.IsAddFundamentalDomain.preimage_of_equiv @[to_additive] theorem image_of_equiv {ν : Measure β} (h : IsFundamentalDomain G s μ) (f : α ≃ β) (hf : QuasiMeasurePreserving f.symm ν μ) (e : H ≃ G) (hef : ∀ g, Semiconj f (e g • ·) (g • ·)) : IsFundamentalDomain H (f '' s) ν := by rw [f.image_eq_preimage] refine h.preimage_of_equiv hf e.symm.bijective fun g x => ?_ rcases f.surjective x with ⟨x, rfl⟩ rw [← hef _ _, f.symm_apply_apply, f.symm_apply_apply, e.apply_symm_apply] #align measure_theory.is_fundamental_domain.image_of_equiv MeasureTheory.IsFundamentalDomain.image_of_equiv #align measure_theory.is_add_fundamental_domain.image_of_equiv MeasureTheory.IsAddFundamentalDomain.image_of_equiv @[to_additive] theorem pairwise_aedisjoint_of_ac {ν} (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) : Pairwise fun g₁ g₂ : G => AEDisjoint ν (g₁ • s) (g₂ • s) := h.aedisjoint.mono fun _ _ H => hν H #align measure_theory.is_fundamental_domain.pairwise_ae_disjoint_of_ac MeasureTheory.IsFundamentalDomain.pairwise_aedisjoint_of_ac #align measure_theory.is_add_fundamental_domain.pairwise_ae_disjoint_of_ac MeasureTheory.IsAddFundamentalDomain.pairwise_aedisjoint_of_ac @[to_additive] theorem smul_of_comm {G' : Type*} [Group G'] [MulAction G' α] [MeasurableSpace G'] [MeasurableSMul G' α] [SMulInvariantMeasure G' α μ] [SMulCommClass G' G α] (h : IsFundamentalDomain G s μ) (g : G') : IsFundamentalDomain G (g • s) μ := h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving (Equiv.refl _) <| smul_comm g #align measure_theory.is_fundamental_domain.smul_of_comm MeasureTheory.IsFundamentalDomain.smul_of_comm #align measure_theory.is_add_fundamental_domain.vadd_of_comm MeasureTheory.IsAddFundamentalDomain.vadd_of_comm variable [MeasurableSpace G] [MeasurableSMul G α] [SMulInvariantMeasure G α μ] @[to_additive] theorem nullMeasurableSet_smul (h : IsFundamentalDomain G s μ) (g : G) : NullMeasurableSet (g • s) μ := h.nullMeasurableSet.smul g #align measure_theory.is_fundamental_domain.null_measurable_set_smul MeasureTheory.IsFundamentalDomain.nullMeasurableSet_smul #align measure_theory.is_add_fundamental_domain.null_measurable_set_vadd MeasureTheory.IsAddFundamentalDomain.nullMeasurableSet_vadd @[to_additive] theorem restrict_restrict (h : IsFundamentalDomain G s μ) (g : G) (t : Set α) : (μ.restrict t).restrict (g • s) = μ.restrict (g • s ∩ t) := restrict_restrict₀ ((h.nullMeasurableSet_smul g).mono restrict_le_self) #align measure_theory.is_fundamental_domain.restrict_restrict MeasureTheory.IsFundamentalDomain.restrict_restrict #align measure_theory.is_add_fundamental_domain.restrict_restrict MeasureTheory.IsAddFundamentalDomain.restrict_restrict @[to_additive] theorem smul (h : IsFundamentalDomain G s μ) (g : G) : IsFundamentalDomain G (g • s) μ := h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving ⟨fun g' => g⁻¹ * g' * g, fun g' => g * g' * g⁻¹, fun g' => by simp [mul_assoc], fun g' => by simp [mul_assoc]⟩ fun g' x => by simp [smul_smul, mul_assoc] #align measure_theory.is_fundamental_domain.smul MeasureTheory.IsFundamentalDomain.smul #align measure_theory.is_add_fundamental_domain.vadd MeasureTheory.IsAddFundamentalDomain.vadd variable [Countable G] {ν : Measure α} @[to_additive] theorem sum_restrict_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) : (sum fun g : G => ν.restrict (g • s)) = ν := by rw [← restrict_iUnion_ae (h.aedisjoint.mono fun i j h => hν h) fun g => (h.nullMeasurableSet_smul g).mono_ac hν, restrict_congr_set (hν h.iUnion_smul_ae_eq), restrict_univ] #align measure_theory.is_fundamental_domain.sum_restrict_of_ac MeasureTheory.IsFundamentalDomain.sum_restrict_of_ac #align measure_theory.is_add_fundamental_domain.sum_restrict_of_ac MeasureTheory.IsAddFundamentalDomain.sum_restrict_of_ac @[to_additive] theorem lintegral_eq_tsum_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂ν = ∑' g : G, ∫⁻ x in g • s, f x ∂ν := by rw [← lintegral_sum_measure, h.sum_restrict_of_ac hν] #align measure_theory.is_fundamental_domain.lintegral_eq_tsum_of_ac MeasureTheory.IsFundamentalDomain.lintegral_eq_tsum_of_ac #align measure_theory.is_add_fundamental_domain.lintegral_eq_tsum_of_ac MeasureTheory.IsAddFundamentalDomain.lintegral_eq_tsum_of_ac @[to_additive] theorem sum_restrict (h : IsFundamentalDomain G s μ) : (sum fun g : G => μ.restrict (g • s)) = μ := h.sum_restrict_of_ac (refl _) #align measure_theory.is_fundamental_domain.sum_restrict MeasureTheory.IsFundamentalDomain.sum_restrict #align measure_theory.is_add_fundamental_domain.sum_restrict MeasureTheory.IsAddFundamentalDomain.sum_restrict @[to_additive] theorem lintegral_eq_tsum (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in g • s, f x ∂μ := h.lintegral_eq_tsum_of_ac (refl _) f #align measure_theory.is_fundamental_domain.lintegral_eq_tsum MeasureTheory.IsFundamentalDomain.lintegral_eq_tsum #align measure_theory.is_add_fundamental_domain.lintegral_eq_tsum MeasureTheory.IsAddFundamentalDomain.lintegral_eq_tsum @[to_additive] theorem lintegral_eq_tsum' (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in s, f (g⁻¹ • x) ∂μ := calc ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in g • s, f x ∂μ := h.lintegral_eq_tsum f _ = ∑' g : G, ∫⁻ x in g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫⁻ x in s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => Eq.symm <| (measurePreserving_smul g⁻¹ μ).set_lintegral_comp_emb (measurableEmbedding_const_smul _) _ _ #align measure_theory.is_fundamental_domain.lintegral_eq_tsum' MeasureTheory.IsFundamentalDomain.lintegral_eq_tsum' #align measure_theory.is_add_fundamental_domain.lintegral_eq_tsum' MeasureTheory.IsAddFundamentalDomain.lintegral_eq_tsum' @[to_additive] lemma lintegral_eq_tsum'' (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in s, f (g • x) ∂μ := (lintegral_eq_tsum' h f).trans ((Equiv.inv G).tsum_eq (fun g ↦ ∫⁻ (x : α) in s, f (g • x) ∂μ)) @[to_additive] theorem set_lintegral_eq_tsum (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) (t : Set α) : ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in t ∩ g • s, f x ∂μ := calc ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in g • s, f x ∂μ.restrict t := h.lintegral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous _ _ = ∑' g : G, ∫⁻ x in t ∩ g • s, f x ∂μ := by simp only [h.restrict_restrict, inter_comm] #align measure_theory.is_fundamental_domain.set_lintegral_eq_tsum MeasureTheory.IsFundamentalDomain.set_lintegral_eq_tsum #align measure_theory.is_add_fundamental_domain.set_lintegral_eq_tsum MeasureTheory.IsAddFundamentalDomain.set_lintegral_eq_tsum @[to_additive] theorem set_lintegral_eq_tsum' (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) (t : Set α) : ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := calc ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in t ∩ g • s, f x ∂μ := h.set_lintegral_eq_tsum f t _ = ∑' g : G, ∫⁻ x in t ∩ g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫⁻ x in g⁻¹ • (g • t ∩ s), f x ∂μ := by simp only [smul_set_inter, inv_smul_smul] _ = ∑' g : G, ∫⁻ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => Eq.symm <| (measurePreserving_smul g⁻¹ μ).set_lintegral_comp_emb (measurableEmbedding_const_smul _) _ _ #align measure_theory.is_fundamental_domain.set_lintegral_eq_tsum' MeasureTheory.IsFundamentalDomain.set_lintegral_eq_tsum' #align measure_theory.is_add_fundamental_domain.set_lintegral_eq_tsum' MeasureTheory.IsAddFundamentalDomain.set_lintegral_eq_tsum' @[to_additive] theorem measure_eq_tsum_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) (t : Set α) : ν t = ∑' g : G, ν (t ∩ g • s) := by have H : ν.restrict t ≪ μ := Measure.restrict_le_self.absolutelyContinuous.trans hν simpa only [set_lintegral_one, Pi.one_def, Measure.restrict_apply₀ ((h.nullMeasurableSet_smul _).mono_ac H), inter_comm] using h.lintegral_eq_tsum_of_ac H 1 #align measure_theory.is_fundamental_domain.measure_eq_tsum_of_ac MeasureTheory.IsFundamentalDomain.measure_eq_tsum_of_ac #align measure_theory.is_add_fundamental_domain.measure_eq_tsum_of_ac MeasureTheory.IsAddFundamentalDomain.measure_eq_tsum_of_ac @[to_additive] theorem measure_eq_tsum' (h : IsFundamentalDomain G s μ) (t : Set α) : μ t = ∑' g : G, μ (t ∩ g • s) := h.measure_eq_tsum_of_ac AbsolutelyContinuous.rfl t #align measure_theory.is_fundamental_domain.measure_eq_tsum' MeasureTheory.IsFundamentalDomain.measure_eq_tsum' #align measure_theory.is_add_fundamental_domain.measure_eq_tsum' MeasureTheory.IsAddFundamentalDomain.measure_eq_tsum' @[to_additive] theorem measure_eq_tsum (h : IsFundamentalDomain G s μ) (t : Set α) : μ t = ∑' g : G, μ (g • t ∩ s) := by simpa only [set_lintegral_one] using h.set_lintegral_eq_tsum' (fun _ => 1) t #align measure_theory.is_fundamental_domain.measure_eq_tsum MeasureTheory.IsFundamentalDomain.measure_eq_tsum #align measure_theory.is_add_fundamental_domain.measure_eq_tsum MeasureTheory.IsAddFundamentalDomain.measure_eq_tsum @[to_additive] theorem measure_zero_of_invariant (h : IsFundamentalDomain G s μ) (t : Set α) (ht : ∀ g : G, g • t = t) (hts : μ (t ∩ s) = 0) : μ t = 0 := by rw [measure_eq_tsum h]; simp [ht, hts] #align measure_theory.is_fundamental_domain.measure_zero_of_invariant MeasureTheory.IsFundamentalDomain.measure_zero_of_invariant #align measure_theory.is_add_fundamental_domain.measure_zero_of_invariant MeasureTheory.IsAddFundamentalDomain.measure_zero_of_invariant /-- Given a measure space with an action of a finite group `G`, the measure of any `G`-invariant set is determined by the measure of its intersection with a fundamental domain for the action of `G`. -/ @[to_additive measure_eq_card_smul_of_vadd_ae_eq_self "Given a measure space with an action of a finite additive group `G`, the measure of any `G`-invariant set is determined by the measure of its intersection with a fundamental domain for the action of `G`."] theorem measure_eq_card_smul_of_smul_ae_eq_self [Finite G] (h : IsFundamentalDomain G s μ) (t : Set α) (ht : ∀ g : G, (g • t : Set α) =ᵐ[μ] t) : μ t = Nat.card G • μ (t ∩ s) := by haveI : Fintype G := Fintype.ofFinite G rw [h.measure_eq_tsum] replace ht : ∀ g : G, (g • t ∩ s : Set α) =ᵐ[μ] (t ∩ s : Set α) := fun g => ae_eq_set_inter (ht g) (ae_eq_refl s) simp_rw [measure_congr (ht _), tsum_fintype, Finset.sum_const, Nat.card_eq_fintype_card, Finset.card_univ] #align measure_theory.is_fundamental_domain.measure_eq_card_smul_of_smul_ae_eq_self MeasureTheory.IsFundamentalDomain.measure_eq_card_smul_of_smul_ae_eq_self #align measure_theory.is_add_fundamental_domain.measure_eq_card_smul_of_vadd_ae_eq_self MeasureTheory.IsAddFundamentalDomain.measure_eq_card_smul_of_vadd_ae_eq_self @[to_additive] protected theorem set_lintegral_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) (f : α → ℝ≥0∞) (hf : ∀ (g : G) (x), f (g • x) = f x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := calc ∫⁻ x in s, f x ∂μ = ∑' g : G, ∫⁻ x in s ∩ g • t, f x ∂μ := ht.set_lintegral_eq_tsum _ _ _ = ∑' g : G, ∫⁻ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := by simp only [hf, inter_comm] _ = ∫⁻ x in t, f x ∂μ := (hs.set_lintegral_eq_tsum' _ _).symm #align measure_theory.is_fundamental_domain.set_lintegral_eq MeasureTheory.IsFundamentalDomain.set_lintegral_eq #align measure_theory.is_add_fundamental_domain.set_lintegral_eq MeasureTheory.IsAddFundamentalDomain.set_lintegral_eq @[to_additive] theorem measure_set_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {A : Set α} (hA₀ : MeasurableSet A) (hA : ∀ g : G, (fun x => g • x) ⁻¹' A = A) : μ (A ∩ s) = μ (A ∩ t) := by have : ∫⁻ x in s, A.indicator 1 x ∂μ = ∫⁻ x in t, A.indicator 1 x ∂μ := by refine hs.set_lintegral_eq ht (Set.indicator A fun _ => 1) fun g x ↦ ?_ convert (Set.indicator_comp_right (g • · : α → α) (g := fun _ ↦ (1 : ℝ≥0∞))).symm rw [hA g] simpa [Measure.restrict_apply hA₀, lintegral_indicator _ hA₀] using this #align measure_theory.is_fundamental_domain.measure_set_eq MeasureTheory.IsFundamentalDomain.measure_set_eq #align measure_theory.is_add_fundamental_domain.measure_set_eq MeasureTheory.IsAddFundamentalDomain.measure_set_eq /-- If `s` and `t` are two fundamental domains of the same action, then their measures are equal. -/ @[to_additive "If `s` and `t` are two fundamental domains of the same action, then their measures are equal."] protected theorem measure_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) : μ s = μ t := by simpa only [set_lintegral_one] using hs.set_lintegral_eq ht (fun _ => 1) fun _ _ => rfl #align measure_theory.is_fundamental_domain.measure_eq MeasureTheory.IsFundamentalDomain.measure_eq #align measure_theory.is_add_fundamental_domain.measure_eq MeasureTheory.IsAddFundamentalDomain.measure_eq @[to_additive] protected theorem aEStronglyMeasurable_on_iff {β : Type*} [TopologicalSpace β] [PseudoMetrizableSpace β] (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → β} (hf : ∀ (g : G) (x), f (g • x) = f x) : AEStronglyMeasurable f (μ.restrict s) ↔ AEStronglyMeasurable f (μ.restrict t) := calc AEStronglyMeasurable f (μ.restrict s) ↔ AEStronglyMeasurable f (Measure.sum fun g : G => μ.restrict (g • t ∩ s)) := by simp only [← ht.restrict_restrict, ht.sum_restrict_of_ac restrict_le_self.absolutelyContinuous] _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g • (g⁻¹ • s ∩ t))) := by simp only [smul_set_inter, inter_comm, smul_inv_smul, aestronglyMeasurable_sum_measure_iff] _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g⁻¹ • (g⁻¹⁻¹ • s ∩ t))) := inv_surjective.forall _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g⁻¹ • (g • s ∩ t))) := by simp only [inv_inv] _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g • s ∩ t)) := by refine forall_congr' fun g => ?_ have he : MeasurableEmbedding (g⁻¹ • · : α → α) := measurableEmbedding_const_smul _ rw [← image_smul, ← ((measurePreserving_smul g⁻¹ μ).restrict_image_emb he _).aestronglyMeasurable_comp_iff he] simp only [(· ∘ ·), hf] _ ↔ AEStronglyMeasurable f (μ.restrict t) := by simp only [← aestronglyMeasurable_sum_measure_iff, ← hs.restrict_restrict, hs.sum_restrict_of_ac restrict_le_self.absolutelyContinuous] #align measure_theory.is_fundamental_domain.ae_strongly_measurable_on_iff MeasureTheory.IsFundamentalDomain.aEStronglyMeasurable_on_iff #align measure_theory.is_add_fundamental_domain.ae_strongly_measurable_on_iff MeasureTheory.IsAddFundamentalDomain.aEStronglyMeasurable_on_iff @[to_additive] protected theorem hasFiniteIntegral_on_iff (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → E} (hf : ∀ (g : G) (x), f (g • x) = f x) : HasFiniteIntegral f (μ.restrict s) ↔ HasFiniteIntegral f (μ.restrict t) := by dsimp only [HasFiniteIntegral] rw [hs.set_lintegral_eq ht] intro g x; rw [hf] #align measure_theory.is_fundamental_domain.has_finite_integral_on_iff MeasureTheory.IsFundamentalDomain.hasFiniteIntegral_on_iff #align measure_theory.is_add_fundamental_domain.has_finite_integral_on_iff MeasureTheory.IsAddFundamentalDomain.hasFiniteIntegral_on_iff @[to_additive] protected theorem integrableOn_iff (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → E} (hf : ∀ (g : G) (x), f (g • x) = f x) : IntegrableOn f s μ ↔ IntegrableOn f t μ := and_congr (hs.aEStronglyMeasurable_on_iff ht hf) (hs.hasFiniteIntegral_on_iff ht hf) #align measure_theory.is_fundamental_domain.integrable_on_iff MeasureTheory.IsFundamentalDomain.integrableOn_iff #align measure_theory.is_add_fundamental_domain.integrable_on_iff MeasureTheory.IsAddFundamentalDomain.integrableOn_iff variable [NormedSpace ℝ E] [CompleteSpace E] @[to_additive] theorem integral_eq_tsum_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) (f : α → E) (hf : Integrable f ν) : ∫ x, f x ∂ν = ∑' g : G, ∫ x in g • s, f x ∂ν := by rw [← MeasureTheory.integral_sum_measure, h.sum_restrict_of_ac hν] rw [h.sum_restrict_of_ac hν] exact hf #align measure_theory.is_fundamental_domain.integral_eq_tsum_of_ac MeasureTheory.IsFundamentalDomain.integral_eq_tsum_of_ac #align measure_theory.is_add_fundamental_domain.integral_eq_tsum_of_ac MeasureTheory.IsAddFundamentalDomain.integral_eq_tsum_of_ac @[to_additive] theorem integral_eq_tsum (h : IsFundamentalDomain G s μ) (f : α → E) (hf : Integrable f μ) : ∫ x, f x ∂μ = ∑' g : G, ∫ x in g • s, f x ∂μ := integral_eq_tsum_of_ac h (by rfl) f hf #align measure_theory.is_fundamental_domain.integral_eq_tsum MeasureTheory.IsFundamentalDomain.integral_eq_tsum #align measure_theory.is_add_fundamental_domain.integral_eq_tsum MeasureTheory.IsAddFundamentalDomain.integral_eq_tsum @[to_additive] theorem integral_eq_tsum' (h : IsFundamentalDomain G s μ) (f : α → E) (hf : Integrable f μ) : ∫ x, f x ∂μ = ∑' g : G, ∫ x in s, f (g⁻¹ • x) ∂μ := calc ∫ x, f x ∂μ = ∑' g : G, ∫ x in g • s, f x ∂μ := h.integral_eq_tsum f hf _ = ∑' g : G, ∫ x in g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫ x in s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => (measurePreserving_smul g⁻¹ μ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _ #align measure_theory.is_fundamental_domain.integral_eq_tsum' MeasureTheory.IsFundamentalDomain.integral_eq_tsum' #align measure_theory.is_add_fundamental_domain.integral_eq_tsum' MeasureTheory.IsAddFundamentalDomain.integral_eq_tsum' @[to_additive] lemma integral_eq_tsum'' (h : IsFundamentalDomain G s μ) (f : α → E) (hf : Integrable f μ) : ∫ x, f x ∂μ = ∑' g : G, ∫ x in s, f (g • x) ∂μ := (integral_eq_tsum' h f hf).trans ((Equiv.inv G).tsum_eq (fun g ↦ ∫ (x : α) in s, f (g • x) ∂μ)) @[to_additive] theorem setIntegral_eq_tsum (h : IsFundamentalDomain G s μ) {f : α → E} {t : Set α} (hf : IntegrableOn f t μ) : ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in t ∩ g • s, f x ∂μ := calc ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in g • s, f x ∂μ.restrict t := h.integral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous f hf _ = ∑' g : G, ∫ x in t ∩ g • s, f x ∂μ := by simp only [h.restrict_restrict, measure_smul, inter_comm] #align measure_theory.is_fundamental_domain.set_integral_eq_tsum MeasureTheory.IsFundamentalDomain.setIntegral_eq_tsum #align measure_theory.is_add_fundamental_domain.set_integral_eq_tsum MeasureTheory.IsAddFundamentalDomain.setIntegral_eq_tsum @[deprecated (since := "2024-04-17")] alias set_integral_eq_tsum := setIntegral_eq_tsum @[to_additive] theorem setIntegral_eq_tsum' (h : IsFundamentalDomain G s μ) {f : α → E} {t : Set α} (hf : IntegrableOn f t μ) : ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := calc ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in t ∩ g • s, f x ∂μ := h.setIntegral_eq_tsum hf _ = ∑' g : G, ∫ x in t ∩ g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫ x in g⁻¹ • (g • t ∩ s), f x ∂μ := by simp only [smul_set_inter, inv_smul_smul] _ = ∑' g : G, ∫ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => (measurePreserving_smul g⁻¹ μ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _ #align measure_theory.is_fundamental_domain.set_integral_eq_tsum' MeasureTheory.IsFundamentalDomain.setIntegral_eq_tsum' #align measure_theory.is_add_fundamental_domain.set_integral_eq_tsum' MeasureTheory.IsAddFundamentalDomain.setIntegral_eq_tsum' @[deprecated (since := "2024-04-17")] alias set_integral_eq_tsum' := setIntegral_eq_tsum' @[to_additive] protected theorem setIntegral_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → E} (hf : ∀ (g : G) (x), f (g • x) = f x) : ∫ x in s, f x ∂μ = ∫ x in t, f x ∂μ := by by_cases hfs : IntegrableOn f s μ · have hft : IntegrableOn f t μ := by rwa [ht.integrableOn_iff hs hf] calc ∫ x in s, f x ∂μ = ∑' g : G, ∫ x in s ∩ g • t, f x ∂μ := ht.setIntegral_eq_tsum hfs _ = ∑' g : G, ∫ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := by simp only [hf, inter_comm] _ = ∫ x in t, f x ∂μ := (hs.setIntegral_eq_tsum' hft).symm · rw [integral_undef hfs, integral_undef] rwa [hs.integrableOn_iff ht hf] at hfs #align measure_theory.is_fundamental_domain.set_integral_eq MeasureTheory.IsFundamentalDomain.setIntegral_eq #align measure_theory.is_add_fundamental_domain.set_integral_eq MeasureTheory.IsAddFundamentalDomain.setIntegral_eq @[deprecated (since := "2024-04-17")] alias set_integral_eq := MeasureTheory.IsFundamentalDomain.setIntegral_eq /-- If the action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` such that the sets `g • t ∩ s` are pairwise a.e.-disjoint has measure at most `μ s`. -/ @[to_additive "If the additive action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` such that the sets `g +ᵥ t ∩ s` are pairwise a.e.-disjoint has measure at most `μ s`."] theorem measure_le_of_pairwise_disjoint (hs : IsFundamentalDomain G s μ) (ht : NullMeasurableSet t μ) (hd : Pairwise (AEDisjoint μ on fun g : G => g • t ∩ s)) : μ t ≤ μ s := calc μ t = ∑' g : G, μ (g • t ∩ s) := hs.measure_eq_tsum t _ = μ (⋃ g : G, g • t ∩ s) := Eq.symm <| measure_iUnion₀ hd fun _ => (ht.smul _).inter hs.nullMeasurableSet _ ≤ μ s := measure_mono (iUnion_subset fun _ => inter_subset_right) #align measure_theory.is_fundamental_domain.measure_le_of_pairwise_disjoint MeasureTheory.IsFundamentalDomain.measure_le_of_pairwise_disjoint #align measure_theory.is_add_fundamental_domain.measure_le_of_pairwise_disjoint MeasureTheory.IsAddFundamentalDomain.measure_le_of_pairwise_disjoint /-- If the action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than `μ s` contains two points `x y` such that `g • x = y` for some `g ≠ 1`. -/ @[to_additive "If the additive action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than `μ s` contains two points `x y` such that `g +ᵥ x = y` for some `g ≠ 0`."] theorem exists_ne_one_smul_eq (hs : IsFundamentalDomain G s μ) (htm : NullMeasurableSet t μ) (ht : μ s < μ t) : ∃ x ∈ t, ∃ y ∈ t, ∃ g, g ≠ (1 : G) ∧ g • x = y := by contrapose! ht refine hs.measure_le_of_pairwise_disjoint htm (Pairwise.aedisjoint fun g₁ g₂ hne => ?_) dsimp [Function.onFun] refine (Disjoint.inf_left _ ?_).inf_right _ rw [Set.disjoint_left] rintro _ ⟨x, hx, rfl⟩ ⟨y, hy, hxy : g₂ • y = g₁ • x⟩ refine ht x hx y hy (g₂⁻¹ * g₁) (mt inv_mul_eq_one.1 hne.symm) ?_ rw [mul_smul, ← hxy, inv_smul_smul] #align measure_theory.is_fundamental_domain.exists_ne_one_smul_eq MeasureTheory.IsFundamentalDomain.exists_ne_one_smul_eq #align measure_theory.is_add_fundamental_domain.exists_ne_zero_vadd_eq MeasureTheory.IsAddFundamentalDomain.exists_ne_zero_vadd_eq /-- If `f` is invariant under the action of a countable group `G`, and `μ` is a `G`-invariant measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s` is the same as that of `f` on all of its domain. -/ @[to_additive "If `f` is invariant under the action of a countable additive group `G`, and `μ` is a `G`-invariant measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s` is the same as that of `f` on all of its domain."] theorem essSup_measure_restrict (hs : IsFundamentalDomain G s μ) {f : α → ℝ≥0∞} (hf : ∀ γ : G, ∀ x : α, f (γ • x) = f x) : essSup f (μ.restrict s) = essSup f μ := by refine le_antisymm (essSup_mono_measure' Measure.restrict_le_self) ?_ rw [essSup_eq_sInf (μ.restrict s) f, essSup_eq_sInf μ f] refine sInf_le_sInf ?_ rintro a (ha : (μ.restrict s) {x : α | a < f x} = 0) rw [Measure.restrict_apply₀' hs.nullMeasurableSet] at ha refine measure_zero_of_invariant hs _ ?_ ha intro γ ext x rw [mem_smul_set_iff_inv_smul_mem] simp only [mem_setOf_eq, hf γ⁻¹ x] #align measure_theory.is_fundamental_domain.ess_sup_measure_restrict MeasureTheory.IsFundamentalDomain.essSup_measure_restrict #align measure_theory.is_add_fundamental_domain.ess_sup_measure_restrict MeasureTheory.IsAddFundamentalDomain.essSup_measure_restrict end IsFundamentalDomain /-! ### Interior/frontier of a fundamental domain -/ section MeasurableSpace variable (G) [Group G] [MulAction G α] (s : Set α) {x : α} /-- The boundary of a fundamental domain, those points of the domain that also lie in a nontrivial translate. -/ @[to_additive MeasureTheory.addFundamentalFrontier "The boundary of a fundamental domain, those points of the domain that also lie in a nontrivial translate."] def fundamentalFrontier : Set α := s ∩ ⋃ (g : G) (_ : g ≠ 1), g • s #align measure_theory.fundamental_frontier MeasureTheory.fundamentalFrontier #align measure_theory.add_fundamental_frontier MeasureTheory.addFundamentalFrontier /-- The interior of a fundamental domain, those points of the domain not lying in any translate. -/ @[to_additive MeasureTheory.addFundamentalInterior "The interior of a fundamental domain, those points of the domain not lying in any translate."] def fundamentalInterior : Set α := s \ ⋃ (g : G) (_ : g ≠ 1), g • s #align measure_theory.fundamental_interior MeasureTheory.fundamentalInterior #align measure_theory.add_fundamental_interior MeasureTheory.addFundamentalInterior variable {G s} @[to_additive (attr := simp) MeasureTheory.mem_addFundamentalFrontier] theorem mem_fundamentalFrontier : x ∈ fundamentalFrontier G s ↔ x ∈ s ∧ ∃ g : G, g ≠ 1 ∧ x ∈ g • s := by simp [fundamentalFrontier] #align measure_theory.mem_fundamental_frontier MeasureTheory.mem_fundamentalFrontier #align measure_theory.mem_add_fundamental_frontier MeasureTheory.mem_addFundamentalFrontier @[to_additive (attr := simp) MeasureTheory.mem_addFundamentalInterior]
Mathlib/MeasureTheory/Group/FundamentalDomain.lean
595
597
theorem mem_fundamentalInterior : x ∈ fundamentalInterior G s ↔ x ∈ s ∧ ∀ g : G, g ≠ 1 → x ∉ g • s := by
simp [fundamentalInterior]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Analysis.Convex.Segment import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.FieldSimp #align_import analysis.convex.between from "leanprover-community/mathlib"@"571e13cacbed7bf042fd3058ce27157101433842" /-! # Betweenness in affine spaces This file defines notions of a point in an affine space being between two given points. ## Main definitions * `affineSegment R x y`: The segment of points weakly between `x` and `y`. * `Wbtw R x y z`: The point `y` is weakly between `x` and `z`. * `Sbtw R x y z`: The point `y` is strictly between `x` and `z`. -/ variable (R : Type*) {V V' P P' : Type*} open AffineEquiv AffineMap section OrderedRing variable [OrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The segment of points weakly between `x` and `y`. When convexity is refactored to support abstract affine combination spaces, this will no longer need to be a separate definition from `segment`. However, lemmas involving `+ᵥ` or `-ᵥ` will still be relevant after such a refactoring, as distinct from versions involving `+` or `-` in a module. -/ def affineSegment (x y : P) := lineMap x y '' Set.Icc (0 : R) 1 #align affine_segment affineSegment theorem affineSegment_eq_segment (x y : V) : affineSegment R x y = segment R x y := by rw [segment_eq_image_lineMap, affineSegment] #align affine_segment_eq_segment affineSegment_eq_segment
Mathlib/Analysis/Convex/Between.lean
49
55
theorem affineSegment_comm (x y : P) : affineSegment R x y = affineSegment R y x := by
refine Set.ext fun z => ?_ constructor <;> · rintro ⟨t, ht, hxy⟩ refine ⟨1 - t, ?_, ?_⟩ · rwa [Set.sub_mem_Icc_iff_right, sub_self, sub_zero] · rwa [lineMap_apply_one_sub]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.SetToL1 #align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Bochner integral The Bochner integral extends the definition of the Lebesgue integral to functions that map from a measure space into a Banach space (complete normed vector space). It is constructed here by extending the integral on simple functions. ## Main definitions The Bochner integral is defined through the extension process described in the file `SetToL1`, which follows these steps: 1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`. `weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive` (defined in the file `SetToL1`) with respect to the set `s`. 2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`) where `E` is a real normed space. (See `SimpleFunc.integral` for details.) 3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation : `α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear map from `α →₁ₛ[μ] E` to `E`. 4. Define the Bochner integral on L1 functions by extending the integral on integrable simple functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of `α →₁ₛ[μ] E` into `α →₁[μ] E` is dense. 5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1 space, if it is in L1, and 0 otherwise. The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to `setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral (like linearity) are particular cases of the properties of `setToFun` (which are described in the file `SetToL1`). ## Main statements 1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure space and `E` is a real normed space. * `integral_zero` : `∫ 0 ∂μ = 0` * `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ` * `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ` * `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ` * `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ` * `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ` * `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ` 2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure space. * `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` * `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` 3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions, which is called `lintegral` and has the notation `∫⁻`. * `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` : `∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`, where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`. * `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ` 4. (In the file `DominatedConvergence`) `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem 5. (In the file `SetIntegral`) integration commutes with continuous linear maps. * `ContinuousLinearMap.integral_comp_comm` * `LinearIsometry.integral_comp_comm` ## Notes Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that you need to unfold the definition of the Bochner integral and go back to simple functions. One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove something for an arbitrary integrable function. Another method is using the following steps. See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` is scattered in sections with the name `posPart`. Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all functions : 1. First go to the `L¹` space. For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of `f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`. 2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`. 3. Show that the property holds for all simple functions `s` in `L¹` space. Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas like `L1.integral_coe_eq_integral`. 4. Since simple functions are dense in `L¹`, ``` univ = closure {s simple} = closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions ⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} = {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself ``` Use `isClosed_property` or `DenseRange.induction_on` for this argument. ## Notations * `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`) * `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in `MeasureTheory/LpSpace`) * `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple functions (defined in `MeasureTheory/SimpleFuncDense`) * `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ` * `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type We also define notations for integral on a set, which are described in the file `MeasureTheory/SetIntegral`. Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing. ## Tags Bochner integral, simple function, function space, Lebesgue dominated convergence theorem -/ assert_not_exists Differentiable noncomputable section open scoped Topology NNReal ENNReal MeasureTheory open Set Filter TopologicalSpace ENNReal EMetric namespace MeasureTheory variable {α E F 𝕜 : Type*} section WeightedSMul open ContinuousLinearMap variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α} /-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension of that set function through `setToL1` gives the Bochner integral of L1 functions. -/ def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F := (μ s).toReal • ContinuousLinearMap.id ℝ F #align measure_theory.weighted_smul MeasureTheory.weightedSMul theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) : weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul] #align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply @[simp] theorem weightedSMul_zero_measure {m : MeasurableSpace α} : weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul] #align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure @[simp] theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) : weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp #align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α} (hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) : (weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by ext1 x push_cast simp_rw [Pi.add_apply, weightedSMul_apply] push_cast rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul] #align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} : (weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by ext1 x push_cast simp_rw [Pi.smul_apply, weightedSMul_apply] push_cast simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul] #align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSMul_smul_measure theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) : (weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by ext1 x; simp_rw [weightedSMul_apply]; congr 2 #align measure_theory.weighted_smul_congr MeasureTheory.weightedSMul_congr theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by ext1 x; rw [weightedSMul_apply, h_zero]; simp #align measure_theory.weighted_smul_null MeasureTheory.weightedSMul_null theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by ext1 x simp_rw [add_apply, weightedSMul_apply, measure_union (Set.disjoint_iff_inter_eq_empty.mpr h_inter) ht, ENNReal.toReal_add hs_finite ht_finite, add_smul] #align measure_theory.weighted_smul_union' MeasureTheory.weightedSMul_union' @[nolint unusedArguments] theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := weightedSMul_union' s t ht hs_finite ht_finite h_inter #align measure_theory.weighted_smul_union MeasureTheory.weightedSMul_union theorem weightedSMul_smul [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜) (s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by simp_rw [weightedSMul_apply, smul_comm] #align measure_theory.weighted_smul_smul MeasureTheory.weightedSMul_smul theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ (μ s).toReal := calc ‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖(μ s).toReal‖ * ‖ContinuousLinearMap.id ℝ F‖ := norm_smul (μ s).toReal (ContinuousLinearMap.id ℝ F) _ ≤ ‖(μ s).toReal‖ := ((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le) _ = abs (μ s).toReal := Real.norm_eq_abs _ _ = (μ s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg #align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSMul_le theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) : DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 := ⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩ #align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditive_weightedSMul theorem weightedSMul_nonneg (s : Set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by simp only [weightedSMul, Algebra.id.smul_eq_mul, coe_smul', _root_.id, coe_id', Pi.smul_apply] exact mul_nonneg toReal_nonneg hx #align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSMul_nonneg end WeightedSMul local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc section PosPart variable [LinearOrder E] [Zero E] [MeasurableSpace α] /-- Positive part of a simple function. -/ def posPart (f : α →ₛ E) : α →ₛ E := f.map fun b => max b 0 #align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart /-- Negative part of a simple function. -/ def negPart [Neg E] (f : α →ₛ E) : α →ₛ E := posPart (-f) #align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _ #align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by rw [negPart]; exact posPart_map_norm _ #align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by simp only [posPart, negPart] ext a rw [coe_sub] exact max_zero_sub_eq_self (f a) #align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart end PosPart section Integral /-! ### The Bochner integral of simple functions Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group, and prove basic property of this integral. -/ open Finset variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {p : ℝ≥0∞} {G F' : Type*} [NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace ℝ F'] {m : MeasurableSpace α} {μ : Measure α} /-- Bochner integral of simple functions whose codomain is a real `NormedSpace`. This is equal to `∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x` (see `integral_eq`). -/ def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F := f.setToSimpleFunc (weightedSMul μ) #align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl #align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x := by simp [integral, setToSimpleFunc, weightedSMul_apply] #align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) : f.integral μ = ∑ x ∈ f.range.filter fun x => x ≠ 0, (μ (f ⁻¹' {x})).toReal • x := by rw [integral_def, setToSimpleFunc_eq_sum_filter]; simp_rw [weightedSMul_apply]; congr #align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter /-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/ theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F} (hs : (f.range.filter fun x => x ≠ 0) ⊆ s) : f.integral μ = ∑ x ∈ s, (μ (f ⁻¹' {x})).toReal • x := by rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs] rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx -- Porting note: reordered for clarity rcases hx.symm with (rfl | hx) · simp rw [SimpleFunc.mem_range] at hx -- Porting note: added simp only [Set.mem_range, not_exists] at hx rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx] #align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset @[simp] theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) : (const α y).integral μ = (μ univ).toReal • y := by classical calc (const α y).integral μ = ∑ z ∈ {y}, (μ (const α y ⁻¹' {z})).toReal • z := integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _) _ = (μ univ).toReal • y := by simp [Set.preimage] -- Porting note: added `Set.preimage` #align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const @[simp] theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α} (hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by classical refine (integral_eq_sum_of_subset ?_).trans ((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm) · intro y hy simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator, mem_range_indicator] at * rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩ exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩] · dsimp rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem, Measure.restrict_apply (f.measurableSet_preimage _)] exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀) #align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero /-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E` and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/ theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) : (f.map g).integral μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • g x := map_setToSimpleFunc _ weightedSMul_union hf hg #align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral /-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. See `integral_eq_lintegral` for a simpler version. -/ theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0) (ht : ∀ b, g b ≠ ∞) : (f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf simp only [← map_apply g f, lintegral_eq_lintegral] rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum] · refine Finset.sum_congr rfl fun b _ => ?_ -- Porting note: added `Function.comp_apply` rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply] · rintro a - by_cases a0 : a = 0 · rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top · apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne · simp [hg0] #align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral' variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) : f.integral μ = g.integral μ := setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h #align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr /-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/ theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) : f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) := h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm rw [← integral_eq_lintegral' hf] exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top] #align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f + g) = integral μ f + integral μ g := setToSimpleFunc_add _ weightedSMul_union hf hg #align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f := setToSimpleFunc_neg _ weightedSMul_union hf #align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f - g) = integral μ f - integral μ g := setToSimpleFunc_sub _ weightedSMul_union hf hg #align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub theorem integral_smul (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) : integral μ (c • f) = c • integral μ f := setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf #align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ} (hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) {f : α →ₛ E} (hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ := calc ‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) * ‖x‖ := norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf _ = C * (f.map norm).integral μ := by rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul] #align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) : ‖f.integral μ‖ ≤ (f.map norm).integral μ := by refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le exact (norm_weightedSMul_le s).trans (one_mul _).symm.le #align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) : f.integral (μ + ν) = f.integral μ + f.integral ν := by simp_rw [integral_def] refine setToSimpleFunc_add_left' (weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2] #align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure end Integral end SimpleFunc namespace L1 set_option linter.uppercaseLean3 false -- `L1` open AEEqFun Lp.simpleFunc Lp variable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace α} {μ : Measure α} namespace SimpleFunc theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero] simp_rw [smul_eq_mul] #align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral section PosPart /-- Positive part of a simple function in L1 space. -/ nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := ⟨Lp.posPart (f : α →₁[μ] ℝ), by rcases f with ⟨f, s, hsf⟩ use s.posPart simp only [Subtype.coe_mk, Lp.coe_posPart, ← hsf, AEEqFun.posPart_mk, SimpleFunc.coe_map, mk_eq_mk] -- Porting note: added simp [SimpleFunc.posPart, Function.comp, EventuallyEq.rfl] ⟩ #align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart /-- Negative part of a simple function in L1 space. -/ def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := posPart (-f) #align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart @[norm_cast] theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl #align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart @[norm_cast] theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl #align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart end PosPart section SimpleFuncIntegral /-! ### The Bochner integral of `L1` Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`, and prove basic properties of this integral. -/ variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace ℝ F'] attribute [local instance] simpleFunc.normedSpace /-- The Bochner integral over simple functions in L1 space. -/ def integral (f : α →₁ₛ[μ] E) : E := (toSimpleFunc f).integral μ #align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl #align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) : integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos] #align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl #align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1S nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) : integral f = integral g := SimpleFunc.integral_congr (SimpleFunc.integrable f) h #align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g := setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _ #align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f := setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f #align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by rw [integral, norm_eq_integral] exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f) #align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [NormedSpace 𝕜 E'] variable (α E μ 𝕜) /-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/ def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E := LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f => le_trans (norm_integral_le_norm _) <| by rw [one_mul] #align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralCLM' /-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E := integralCLM' α E ℝ μ #align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralCLM variable {α E μ 𝕜} local notation "Integral" => integralCLM α E μ open ContinuousLinearMap theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 := -- Porting note: Old proof was `LinearMap.mkContinuous_norm_le _ zero_le_one _` LinearMap.mkContinuous_norm_le _ zero_le_one (fun f => by rw [one_mul] exact norm_integral_le_norm f) #align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one section PosPart theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ), toSimpleFunc_eq_toFun f] with _ _ h₂ h₃ convert h₂ using 1 -- Porting note: added rw [h₃] refine ae_eq.mono fun a h => ?_ rw [h, eq] #align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart] filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f] intro a h₁ h₂ rw [h₁] show max _ _ = max _ _ rw [h₂] rfl #align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by filter_upwards [posPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply] -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by filter_upwards [negPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply] rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub] · show (toSimpleFunc f).integral μ = ((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f) filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂ show _ = _ - _ rw [← h₁, ← h₂] have := (toSimpleFunc f).posPart_sub_negPart conv_lhs => rw [← this] rfl · exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁ · exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂ #align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub end PosPart end SimpleFuncIntegral end SimpleFunc open SimpleFunc local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _ variable [NormedSpace ℝ E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedSpace ℝ F] [CompleteSpace E] section IntegrationInL1 attribute [local instance] simpleFunc.normedSpace open ContinuousLinearMap variable (𝕜) /-- The Bochner integral in L1 space as a continuous linear map. -/ nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E := (integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top) simpleFunc.uniformInducing #align measure_theory.L1.integral_clm' MeasureTheory.L1.integralCLM' variable {𝕜} /-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁[μ] E) →L[ℝ] E := integralCLM' ℝ #align measure_theory.L1.integral_clm MeasureTheory.L1.integralCLM -- Porting note: added `(E := E)` in several places below. /-- The Bochner integral in L1 space -/ irreducible_def integral (f : α →₁[μ] E) : E := integralCLM (E := E) f #align measure_theory.L1.integral MeasureTheory.L1.integral theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM (E := E) f := by simp only [integral] #align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq theorem integral_eq_setToL1 (f : α →₁[μ] E) : integral f = setToL1 (E := E) (dominatedFinMeasAdditive_weightedSMul μ) f := by simp only [integral]; rfl #align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1 @[norm_cast] theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) : L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by simp only [integral, L1.integral] exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f #align measure_theory.L1.simple_func.integral_L1_eq_integral MeasureTheory.L1.SimpleFunc.integral_L1_eq_integral variable (α E) @[simp] theorem integral_zero : integral (0 : α →₁[μ] E) = 0 := by simp only [integral] exact map_zero integralCLM #align measure_theory.L1.integral_zero MeasureTheory.L1.integral_zero variable {α E} @[integral_simps] theorem integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := by simp only [integral] exact map_add integralCLM f g #align measure_theory.L1.integral_add MeasureTheory.L1.integral_add @[integral_simps] theorem integral_neg (f : α →₁[μ] E) : integral (-f) = -integral f := by simp only [integral] exact map_neg integralCLM f #align measure_theory.L1.integral_neg MeasureTheory.L1.integral_neg @[integral_simps] theorem integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g := by simp only [integral] exact map_sub integralCLM f g #align measure_theory.L1.integral_sub MeasureTheory.L1.integral_sub @[integral_simps] theorem integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f := by simp only [integral] show (integralCLM' (E := E) 𝕜) (c • f) = c • (integralCLM' (E := E) 𝕜) f exact map_smul (integralCLM' (E := E) 𝕜) c f #align measure_theory.L1.integral_smul MeasureTheory.L1.integral_smul local notation "Integral" => @integralCLM α E _ _ μ _ _ local notation "sIntegral" => @SimpleFunc.integralCLM α E _ _ μ _ theorem norm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖ ≤ 1 := norm_setToL1_le (dominatedFinMeasAdditive_weightedSMul μ) zero_le_one #align measure_theory.L1.norm_Integral_le_one MeasureTheory.L1.norm_Integral_le_one theorem nnnorm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖₊ ≤ 1 := norm_Integral_le_one theorem norm_integral_le (f : α →₁[μ] E) : ‖integral f‖ ≤ ‖f‖ := calc ‖integral f‖ = ‖integralCLM (E := E) f‖ := by simp only [integral] _ ≤ ‖integralCLM (α := α) (E := E) (μ := μ)‖ * ‖f‖ := le_opNorm _ _ _ ≤ 1 * ‖f‖ := mul_le_mul_of_nonneg_right norm_Integral_le_one <| norm_nonneg _ _ = ‖f‖ := one_mul _ #align measure_theory.L1.norm_integral_le MeasureTheory.L1.norm_integral_le theorem nnnorm_integral_le (f : α →₁[μ] E) : ‖integral f‖₊ ≤ ‖f‖₊ := norm_integral_le f @[continuity] theorem continuous_integral : Continuous fun f : α →₁[μ] E => integral f := by simp only [integral] exact L1.integralCLM.continuous #align measure_theory.L1.continuous_integral MeasureTheory.L1.continuous_integral section PosPart theorem integral_eq_norm_posPart_sub (f : α →₁[μ] ℝ) : integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖ := by -- Use `isClosed_property` and `isClosed_eq` refine @isClosed_property _ _ _ ((↑) : (α →₁ₛ[μ] ℝ) → α →₁[μ] ℝ) (fun f : α →₁[μ] ℝ => integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖) (simpleFunc.denseRange one_ne_top) (isClosed_eq ?_ ?_) ?_ f · simp only [integral] exact cont _ · refine Continuous.sub (continuous_norm.comp Lp.continuous_posPart) (continuous_norm.comp Lp.continuous_negPart) -- Show that the property holds for all simple functions in the `L¹` space. · intro s norm_cast exact SimpleFunc.integral_eq_norm_posPart_sub _ #align measure_theory.L1.integral_eq_norm_pos_part_sub MeasureTheory.L1.integral_eq_norm_posPart_sub end PosPart end IntegrationInL1 end L1 /-! ## The Bochner integral on functions Define the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable functions, and 0 otherwise; prove its basic properties. -/ variable [NormedAddCommGroup E] [NormedSpace ℝ E] [hE : CompleteSpace E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] section open scoped Classical /-- The Bochner integral -/ irreducible_def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α → G) : G := if _ : CompleteSpace G then if hf : Integrable f μ then L1.integral (hf.toL1 f) else 0 else 0 #align measure_theory.integral MeasureTheory.integral end /-! In the notation for integrals, an expression like `∫ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => integral μ r @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)", "r:60:(scoped f => integral volume f) => r @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => integral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.integral] notation3 "∫ "(...)" in "s", "r:60:(scoped f => integral (Measure.restrict volume s) f) => r section Properties open ContinuousLinearMap MeasureTheory.SimpleFunc variable {f g : α → E} {m : MeasurableSpace α} {μ : Measure α} theorem integral_eq (f : α → E) (hf : Integrable f μ) : ∫ a, f a ∂μ = L1.integral (hf.toL1 f) := by simp [integral, hE, hf] #align measure_theory.integral_eq MeasureTheory.integral_eq theorem integral_eq_setToFun (f : α → E) : ∫ a, f a ∂μ = setToFun μ (weightedSMul μ) (dominatedFinMeasAdditive_weightedSMul μ) f := by simp only [integral, hE, L1.integral]; rfl #align measure_theory.integral_eq_set_to_fun MeasureTheory.integral_eq_setToFun theorem L1.integral_eq_integral (f : α →₁[μ] E) : L1.integral f = ∫ a, f a ∂μ := by simp only [integral, L1.integral, integral_eq_setToFun] exact (L1.setToFun_eq_setToL1 (dominatedFinMeasAdditive_weightedSMul μ) f).symm set_option linter.uppercaseLean3 false in #align measure_theory.L1.integral_eq_integral MeasureTheory.L1.integral_eq_integral theorem integral_undef {f : α → G} (h : ¬Integrable f μ) : ∫ a, f a ∂μ = 0 := by by_cases hG : CompleteSpace G · simp [integral, hG, h] · simp [integral, hG] #align measure_theory.integral_undef MeasureTheory.integral_undef theorem Integrable.of_integral_ne_zero {f : α → G} (h : ∫ a, f a ∂μ ≠ 0) : Integrable f μ := Not.imp_symm integral_undef h theorem integral_non_aestronglyMeasurable {f : α → G} (h : ¬AEStronglyMeasurable f μ) : ∫ a, f a ∂μ = 0 := integral_undef <| not_and_of_not_left _ h #align measure_theory.integral_non_ae_strongly_measurable MeasureTheory.integral_non_aestronglyMeasurable variable (α G) @[simp]
Mathlib/MeasureTheory/Integral/Bochner.lean
850
854
theorem integral_zero : ∫ _ : α, (0 : G) ∂μ = 0 := by
by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact setToFun_zero (dominatedFinMeasAdditive_weightedSMul μ) · simp [integral, hG]
/- 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. -/ 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) /-- Cantor's intersection theorem for sequences indexed by `ℕ`: the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed (t : ℕ → Set X) (htd : ∀ i, t (i + 1) ⊆ t i) (htn : ∀ i, (t i).Nonempty) (ht0 : IsCompact (t 0)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := have tmono : Antitone t := antitone_nat_of_succ_le htd have htd : Directed (· ⊇ ·) t := tmono.directed_ge have : ∀ i, t i ⊆ t 0 := fun i => tmono <| zero_le i have htc : ∀ i, IsCompact (t i) := fun i => ht0.of_isClosed_subset (htcl i) (this i) IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed t htd htn htc htcl #align is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed @[deprecated (since := "2024-02-28")] alias IsCompact.nonempty_iInter_of_sequence_nonempty_compact_closed := IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsCompact s) (hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) : ∃ b', b' ⊆ b ∧ Set.Finite b' ∧ s ⊆ ⋃ i ∈ b', c i := by simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂ rcases hs.elim_finite_subcover (fun i => c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩ refine ⟨Subtype.val '' d.toSet, ?_, d.finite_toSet.image _, ?_⟩ · simp · rwa [biUnion_image] #align is_compact.elim_finite_subcover_image IsCompact.elim_finite_subcover_imageₓ /-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_of_finite_subcover (h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i) : IsCompact s := fun f hf hfs => by contrapose! h simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall', (nhds_basis_opens _).disjoint_iff_left] at h choose U hU hUf using h refine ⟨s, U, fun x => (hU x).2, fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1⟩, fun t ht => ?_⟩ refine compl_not_mem (le_principal_iff.1 hfs) ?_ refine mem_of_superset ((biInter_finset_mem t).2 fun x _ => hUf x) ?_ rw [subset_compl_comm, compl_iInter₂] simpa only [compl_compl] #align is_compact_of_finite_subcover isCompact_of_finite_subcover -- Porting note (#11215): TODO: reformulate using `Disjoint` /-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_of_finite_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅) : IsCompact s := isCompact_of_finite_subcover fun U hUo hsU => by rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU rcases h (fun i => (U i)ᶜ) (fun i => (hUo _).isClosed_compl) hsU with ⟨t, ht⟩ refine ⟨t, ?_⟩ rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff] #align is_compact_of_finite_subfamily_closed isCompact_of_finite_subfamily_closed /-- A set `s` is compact if and only if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_iff_finite_subcover : IsCompact s ↔ ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := ⟨fun hs => hs.elim_finite_subcover, isCompact_of_finite_subcover⟩ #align is_compact_iff_finite_subcover isCompact_iff_finite_subcover /-- A set `s` is compact if and only if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_iff_finite_subfamily_closed : IsCompact s ↔ ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := ⟨fun hs => hs.elim_finite_subfamily_closed, isCompact_of_finite_subfamily_closed⟩ #align is_compact_iff_finite_subfamily_closed isCompact_iff_finite_subfamily_closed /-- If `s : Set (X × Y)` belongs to `𝓝 x ×ˢ l` for all `x` from a compact set `K`, then it belongs to `(𝓝ˢ K) ×ˢ l`, i.e., there exist an open `U ⊇ K` and `t ∈ l` such that `U ×ˢ t ⊆ s`. -/ theorem IsCompact.mem_nhdsSet_prod_of_forall {K : Set X} {l : Filter Y} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ×ˢ l) : s ∈ (𝓝ˢ K) ×ˢ l := by refine hK.induction_on (by simp) (fun t t' ht hs ↦ ?_) (fun t t' ht ht' ↦ ?_) fun x hx ↦ ?_ · exact prod_mono (nhdsSet_mono ht) le_rfl hs · simp [sup_prod, *] · rcases ((nhds_basis_opens _).prod l.basis_sets).mem_iff.1 (hs x hx) with ⟨⟨u, v⟩, ⟨⟨hx, huo⟩, hv⟩, hs⟩ refine ⟨u, nhdsWithin_le_nhds (huo.mem_nhds hx), mem_of_superset ?_ hs⟩ exact prod_mem_prod (huo.mem_nhdsSet.2 Subset.rfl) hv theorem IsCompact.nhdsSet_prod_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter Y) : (𝓝ˢ K) ×ˢ l = ⨆ x ∈ K, 𝓝 x ×ˢ l := le_antisymm (fun s hs ↦ hK.mem_nhdsSet_prod_of_forall <| by simpa using hs) (iSup₂_le fun x hx ↦ prod_mono (nhds_le_nhdsSet hx) le_rfl) theorem IsCompact.prod_nhdsSet_eq_biSup {K : Set Y} (hK : IsCompact K) (l : Filter X) : l ×ˢ (𝓝ˢ K) = ⨆ y ∈ K, l ×ˢ 𝓝 y := by simp only [prod_comm (f := l), hK.nhdsSet_prod_eq_biSup, map_iSup] /-- If `s : Set (X × Y)` belongs to `l ×ˢ 𝓝 y` for all `y` from a compact set `K`, then it belongs to `l ×ˢ (𝓝ˢ K)`, i.e., there exist `t ∈ l` and an open `U ⊇ K` such that `t ×ˢ U ⊆ s`. -/ theorem IsCompact.mem_prod_nhdsSet_of_forall {K : Set Y} {l : Filter X} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ×ˢ 𝓝 y) : s ∈ l ×ˢ 𝓝ˢ K := (hK.prod_nhdsSet_eq_biSup l).symm ▸ by simpa using hs -- TODO: Is there a way to prove directly the `inf` version and then deduce the `Prod` one ? -- That would seem a bit more natural. theorem IsCompact.nhdsSet_inf_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : (𝓝ˢ K) ⊓ l = ⨆ x ∈ K, 𝓝 x ⊓ l := by have : ∀ f : Filter X, f ⊓ l = comap (fun x ↦ (x, x)) (f ×ˢ l) := fun f ↦ by simpa only [comap_prod] using congrArg₂ (· ⊓ ·) comap_id.symm comap_id.symm simp_rw [this, ← comap_iSup, hK.nhdsSet_prod_eq_biSup] theorem IsCompact.inf_nhdsSet_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : l ⊓ (𝓝ˢ K) = ⨆ x ∈ K, l ⊓ 𝓝 x := by simp only [inf_comm l, hK.nhdsSet_inf_eq_biSup] /-- If `s : Set X` belongs to `𝓝 x ⊓ l` for all `x` from a compact set `K`, then it belongs to `(𝓝ˢ K) ⊓ l`, i.e., there exist an open `U ⊇ K` and `T ∈ l` such that `U ∩ T ⊆ s`. -/ theorem IsCompact.mem_nhdsSet_inf_of_forall {K : Set X} {l : Filter X} {s : Set X} (hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ⊓ l) : s ∈ (𝓝ˢ K) ⊓ l := (hK.nhdsSet_inf_eq_biSup l).symm ▸ by simpa using hs /-- If `s : Set S` belongs to `l ⊓ 𝓝 x` for all `x` from a compact set `K`, then it belongs to `l ⊓ (𝓝ˢ K)`, i.e., there exist `T ∈ l` and an open `U ⊇ K` such that `T ∩ U ⊆ s`. -/ theorem IsCompact.mem_inf_nhdsSet_of_forall {K : Set X} {l : Filter X} {s : Set X} (hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ⊓ 𝓝 y) : s ∈ l ⊓ 𝓝ˢ K := (hK.inf_nhdsSet_eq_biSup l).symm ▸ by simpa using hs /-- To show that `∀ y ∈ K, P x y` holds for `x` close enough to `x₀` when `K` is compact, it is sufficient to show that for all `y₀ ∈ K` there `P x y` holds for `(x, y)` close enough to `(x₀, y₀)`. Provided for backwards compatibility, see `IsCompact.mem_prod_nhdsSet_of_forall` for a stronger statement. -/ theorem IsCompact.eventually_forall_of_forall_eventually {x₀ : X} {K : Set Y} (hK : IsCompact K) {P : X → Y → Prop} (hP : ∀ y ∈ K, ∀ᶠ z : X × Y in 𝓝 (x₀, y), P z.1 z.2) : ∀ᶠ x in 𝓝 x₀, ∀ y ∈ K, P x y := by simp only [nhds_prod_eq, ← eventually_iSup, ← hK.prod_nhdsSet_eq_biSup] at hP exact hP.curry.mono fun _ h ↦ h.self_of_nhdsSet #align is_compact.eventually_forall_of_forall_eventually IsCompact.eventually_forall_of_forall_eventually @[simp] theorem isCompact_empty : IsCompact (∅ : Set X) := fun _f hnf hsf => Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf #align is_compact_empty isCompact_empty @[simp] theorem isCompact_singleton {x : X} : IsCompact ({x} : Set X) := fun f hf hfa => ⟨x, rfl, ClusterPt.of_le_nhds' (hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩ #align is_compact_singleton isCompact_singleton theorem Set.Subsingleton.isCompact (hs : s.Subsingleton) : IsCompact s := Subsingleton.induction_on hs isCompact_empty fun _ => isCompact_singleton #align set.subsingleton.is_compact Set.Subsingleton.isCompact -- Porting note: golfed a proof instead of fixing it theorem Set.Finite.isCompact_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite) (hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) := isCompact_iff_ultrafilter_le_nhds'.2 fun l hl => by rw [Ultrafilter.finite_biUnion_mem_iff hs] at hl rcases hl with ⟨i, his, hi⟩ rcases (hf i his).ultrafilter_le_nhds _ (le_principal_iff.2 hi) with ⟨x, hxi, hlx⟩ exact ⟨x, mem_iUnion₂.2 ⟨i, his, hxi⟩, hlx⟩ #align set.finite.is_compact_bUnion Set.Finite.isCompact_biUnion theorem Finset.isCompact_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) := s.finite_toSet.isCompact_biUnion hf #align finset.is_compact_bUnion Finset.isCompact_biUnion theorem isCompact_accumulate {K : ℕ → Set X} (hK : ∀ n, IsCompact (K n)) (n : ℕ) : IsCompact (Accumulate K n) := (finite_le_nat n).isCompact_biUnion fun k _ => hK k #align is_compact_accumulate isCompact_accumulate -- Porting note (#10756): new lemma theorem Set.Finite.isCompact_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsCompact s) : IsCompact (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isCompact_biUnion hc -- Porting note: generalized to `ι : Sort*` theorem isCompact_iUnion {ι : Sort*} {f : ι → Set X} [Finite ι] (h : ∀ i, IsCompact (f i)) : IsCompact (⋃ i, f i) := (finite_range f).isCompact_sUnion <| forall_mem_range.2 h #align is_compact_Union isCompact_iUnion theorem Set.Finite.isCompact (hs : s.Finite) : IsCompact s := biUnion_of_singleton s ▸ hs.isCompact_biUnion fun _ _ => isCompact_singleton #align set.finite.is_compact Set.Finite.isCompact theorem IsCompact.finite_of_discrete [DiscreteTopology X] (hs : IsCompact s) : s.Finite := by have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete] rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, _, hst⟩ simp only [← t.set_biUnion_coe, biUnion_of_singleton] at hst exact t.finite_toSet.subset hst #align is_compact.finite_of_discrete IsCompact.finite_of_discrete theorem isCompact_iff_finite [DiscreteTopology X] : IsCompact s ↔ s.Finite := ⟨fun h => h.finite_of_discrete, fun h => h.isCompact⟩ #align is_compact_iff_finite isCompact_iff_finite theorem IsCompact.union (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s ∪ t) := by rw [union_eq_iUnion]; exact isCompact_iUnion fun b => by cases b <;> assumption #align is_compact.union IsCompact.union protected theorem IsCompact.insert (hs : IsCompact s) (a) : IsCompact (insert a s) := isCompact_singleton.union hs #align is_compact.insert IsCompact.insert -- Porting note (#11215): TODO: reformulate using `𝓝ˢ` /-- If `V : ι → Set X` is a decreasing family of closed compact sets then any neighborhood of `⋂ i, V i` contains some `V i`. We assume each `V i` is compact *and* closed because `X` is not assumed to be Hausdorff. See `exists_subset_nhd_of_compact` for version assuming this. -/ theorem exists_subset_nhds_of_isCompact' [Nonempty ι] {V : ι → Set X} (hV : Directed (· ⊇ ·) V) (hV_cpct : ∀ i, IsCompact (V i)) (hV_closed : ∀ i, IsClosed (V i)) {U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := by obtain ⟨W, hsubW, W_op, hWU⟩ := exists_open_set_nhds hU suffices ∃ i, V i ⊆ W from this.imp fun i hi => hi.trans hWU by_contra! H replace H : ∀ i, (V i ∩ Wᶜ).Nonempty := fun i => Set.inter_compl_nonempty_iff.mpr (H i) have : (⋂ i, V i ∩ Wᶜ).Nonempty := by refine IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (fun i j => ?_) H (fun i => (hV_cpct i).inter_right W_op.isClosed_compl) fun i => (hV_closed i).inter W_op.isClosed_compl rcases hV i j with ⟨k, hki, hkj⟩ refine ⟨k, ⟨fun x => ?_, fun x => ?_⟩⟩ <;> simp only [and_imp, mem_inter_iff, mem_compl_iff] <;> tauto have : ¬⋂ i : ι, V i ⊆ W := by simpa [← iInter_inter, inter_compl_nonempty_iff] contradiction #align exists_subset_nhds_of_is_compact' exists_subset_nhds_of_isCompact' lemma eq_finite_iUnion_of_isTopologicalBasis_of_isCompact_open (b : ι → Set X) (hb : IsTopologicalBasis (Set.range b)) (U : Set X) (hUc : IsCompact U) (hUo : IsOpen U) : ∃ s : Set ι, s.Finite ∧ U = ⋃ i ∈ s, b i := by obtain ⟨Y, f, e, hf⟩ := hb.open_eq_iUnion hUo choose f' hf' using hf have : b ∘ f' = f := funext hf' subst this obtain ⟨t, ht⟩ := hUc.elim_finite_subcover (b ∘ f') (fun i => hb.isOpen (Set.mem_range_self _)) (by rw [e]) refine ⟨t.image f', Set.toFinite _, le_antisymm ?_ ?_⟩ · refine Set.Subset.trans ht ?_ simp only [Set.iUnion_subset_iff] intro i hi erw [← Set.iUnion_subtype (fun x : ι => x ∈ t.image f') fun i => b i.1] exact Set.subset_iUnion (fun i : t.image f' => b i) ⟨_, Finset.mem_image_of_mem _ hi⟩ · apply Set.iUnion₂_subset rintro i hi obtain ⟨j, -, rfl⟩ := Finset.mem_image.mp hi rw [e] exact Set.subset_iUnion (b ∘ f') j lemma eq_sUnion_finset_of_isTopologicalBasis_of_isCompact_open (b : Set (Set X)) (hb : IsTopologicalBasis b) (U : Set X) (hUc : IsCompact U) (hUo : IsOpen U) : ∃ s : Finset b, U = s.toSet.sUnion := by have hb' : b = range (fun i ↦ i : b → Set X) := by simp rw [hb'] at hb choose s hs hU using eq_finite_iUnion_of_isTopologicalBasis_of_isCompact_open _ hb U hUc hUo have : Finite s := hs let _ : Fintype s := Fintype.ofFinite _ use s.toFinset simp [hU] /-- If `X` has a basis consisting of compact opens, then an open set in `X` is compact open iff it is a finite union of some elements in the basis -/ theorem isCompact_open_iff_eq_finite_iUnion_of_isTopologicalBasis (b : ι → Set X) (hb : IsTopologicalBasis (Set.range b)) (hb' : ∀ i, IsCompact (b i)) (U : Set X) : IsCompact U ∧ IsOpen U ↔ ∃ s : Set ι, s.Finite ∧ U = ⋃ i ∈ s, b i := by constructor · exact fun ⟨h₁, h₂⟩ ↦ eq_finite_iUnion_of_isTopologicalBasis_of_isCompact_open _ hb U h₁ h₂ · rintro ⟨s, hs, rfl⟩ constructor · exact hs.isCompact_biUnion fun i _ => hb' i · exact isOpen_biUnion fun i _ => hb.isOpen (Set.mem_range_self _) #align is_compact_open_iff_eq_finite_Union_of_is_topological_basis isCompact_open_iff_eq_finite_iUnion_of_isTopologicalBasis namespace Filter theorem hasBasis_cocompact : (cocompact X).HasBasis IsCompact compl := hasBasis_biInf_principal' (fun s hs t ht => ⟨s ∪ t, hs.union ht, compl_subset_compl.2 subset_union_left, compl_subset_compl.2 subset_union_right⟩) ⟨∅, isCompact_empty⟩ #align filter.has_basis_cocompact Filter.hasBasis_cocompact theorem mem_cocompact : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ tᶜ ⊆ s := hasBasis_cocompact.mem_iff #align filter.mem_cocompact Filter.mem_cocompact theorem mem_cocompact' : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ sᶜ ⊆ t := mem_cocompact.trans <| exists_congr fun _ => and_congr_right fun _ => compl_subset_comm #align filter.mem_cocompact' Filter.mem_cocompact' theorem _root_.IsCompact.compl_mem_cocompact (hs : IsCompact s) : sᶜ ∈ Filter.cocompact X := hasBasis_cocompact.mem_of_mem hs #align is_compact.compl_mem_cocompact IsCompact.compl_mem_cocompact theorem cocompact_le_cofinite : cocompact X ≤ cofinite := fun s hs => compl_compl s ▸ hs.isCompact.compl_mem_cocompact #align filter.cocompact_le_cofinite Filter.cocompact_le_cofinite theorem cocompact_eq_cofinite (X : Type*) [TopologicalSpace X] [DiscreteTopology X] : cocompact X = cofinite := by simp only [cocompact, hasBasis_cofinite.eq_biInf, isCompact_iff_finite] #align filter.cocompact_eq_cofinite Filter.cocompact_eq_cofinite /-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/ theorem disjoint_cocompact_left (f : Filter X) : Disjoint (Filter.cocompact X) f ↔ ∃ K ∈ f, IsCompact K := by simp_rw [hasBasis_cocompact.disjoint_iff_left, compl_compl] tauto /-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/ theorem disjoint_cocompact_right (f : Filter X) : Disjoint f (Filter.cocompact X) ↔ ∃ K ∈ f, IsCompact K := by simp_rw [hasBasis_cocompact.disjoint_iff_right, compl_compl] tauto @[deprecated "see `cocompact_eq_atTop` with `import Mathlib.Topology.Instances.Nat`" (since := "2024-02-07")] theorem _root_.Nat.cocompact_eq : cocompact ℕ = atTop := (cocompact_eq_cofinite ℕ).trans Nat.cofinite_eq_atTop #align nat.cocompact_eq Nat.cocompact_eq theorem Tendsto.isCompact_insert_range_of_cocompact {f : X → Y} {y} (hf : Tendsto f (cocompact X) (𝓝 y)) (hfc : Continuous f) : IsCompact (insert y (range f)) := by intro l hne hle by_cases hy : ClusterPt y l · exact ⟨y, Or.inl rfl, hy⟩ simp only [clusterPt_iff, not_forall, ← not_disjoint_iff_nonempty_inter, not_not] at hy rcases hy with ⟨s, hsy, t, htl, hd⟩ rcases mem_cocompact.1 (hf hsy) with ⟨K, hKc, hKs⟩ have : f '' K ∈ l := by filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf rcases hyf with (rfl | ⟨x, rfl⟩) exacts [(hd.le_bot ⟨mem_of_mem_nhds hsy, hyt⟩).elim, mem_image_of_mem _ (not_not.1 fun hxK => hd.le_bot ⟨hKs hxK, hyt⟩)] rcases hKc.image hfc (le_principal_iff.2 this) with ⟨y, hy, hyl⟩ exact ⟨y, Or.inr <| image_subset_range _ _ hy, hyl⟩ #align filter.tendsto.is_compact_insert_range_of_cocompact Filter.Tendsto.isCompact_insert_range_of_cocompact
Mathlib/Topology/Compactness/Compact.lean
665
669
theorem Tendsto.isCompact_insert_range_of_cofinite {f : ι → X} {x} (hf : Tendsto f cofinite (𝓝 x)) : IsCompact (insert x (range f)) := by
letI : TopologicalSpace ι := ⊥; haveI h : DiscreteTopology ι := ⟨rfl⟩ rw [← cocompact_eq_cofinite ι] at hf exact hf.isCompact_insert_range_of_cocompact continuous_of_discreteTopology
/- 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, Mario Carneiro -/ import Mathlib.Algebra.Associated import Mathlib.Algebra.Order.Monoid.Unbundled.Pow import Mathlib.Algebra.Ring.Int import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Data.Nat.GCD.Basic import Mathlib.Order.Bounds.Basic #align_import data.nat.prime from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # Prime numbers This file deals with prime numbers: natural numbers `p ≥ 2` whose only divisors are `p` and `1`. ## Important declarations - `Nat.Prime`: the predicate that expresses that a natural number `p` is prime - `Nat.Primes`: the subtype of natural numbers that are prime - `Nat.minFac n`: the minimal prime factor of a natural number `n ≠ 1` - `Nat.exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers. This also appears as `Nat.not_bddAbove_setOf_prime` and `Nat.infinite_setOf_prime` (the latter in `Data.Nat.PrimeFin`). - `Nat.prime_iff`: `Nat.Prime` coincides with the general definition of `Prime` - `Nat.irreducible_iff_nat_prime`: a non-unit natural number is only divisible by `1` iff it is prime -/ open Bool Subtype open Nat namespace Nat variable {n : ℕ} /-- `Nat.Prime p` means that `p` is a prime number, that is, a natural number at least 2 whose only divisors are `p` and `1`. -/ -- Porting note (#11180): removed @[pp_nodot] def Prime (p : ℕ) := Irreducible p #align nat.prime Nat.Prime theorem irreducible_iff_nat_prime (a : ℕ) : Irreducible a ↔ Nat.Prime a := Iff.rfl #align irreducible_iff_nat_prime Nat.irreducible_iff_nat_prime @[aesop safe destruct] theorem not_prime_zero : ¬Prime 0 | h => h.ne_zero rfl #align nat.not_prime_zero Nat.not_prime_zero @[aesop safe destruct] theorem not_prime_one : ¬Prime 1 | h => h.ne_one rfl #align nat.not_prime_one Nat.not_prime_one theorem Prime.ne_zero {n : ℕ} (h : Prime n) : n ≠ 0 := Irreducible.ne_zero h #align nat.prime.ne_zero Nat.Prime.ne_zero theorem Prime.pos {p : ℕ} (pp : Prime p) : 0 < p := Nat.pos_of_ne_zero pp.ne_zero #align nat.prime.pos Nat.Prime.pos theorem Prime.two_le : ∀ {p : ℕ}, Prime p → 2 ≤ p | 0, h => (not_prime_zero h).elim | 1, h => (not_prime_one h).elim | _ + 2, _ => le_add_self #align nat.prime.two_le Nat.Prime.two_le theorem Prime.one_lt {p : ℕ} : Prime p → 1 < p := Prime.two_le #align nat.prime.one_lt Nat.Prime.one_lt lemma Prime.one_le {p : ℕ} (hp : p.Prime) : 1 ≤ p := hp.one_lt.le instance Prime.one_lt' (p : ℕ) [hp : Fact p.Prime] : Fact (1 < p) := ⟨hp.1.one_lt⟩ #align nat.prime.one_lt' Nat.Prime.one_lt' theorem Prime.ne_one {p : ℕ} (hp : p.Prime) : p ≠ 1 := hp.one_lt.ne' #align nat.prime.ne_one Nat.Prime.ne_one theorem Prime.eq_one_or_self_of_dvd {p : ℕ} (pp : p.Prime) (m : ℕ) (hm : m ∣ p) : m = 1 ∨ m = p := by obtain ⟨n, hn⟩ := hm have := pp.isUnit_or_isUnit hn rw [Nat.isUnit_iff, Nat.isUnit_iff] at this apply Or.imp_right _ this rintro rfl rw [hn, mul_one] #align nat.prime.eq_one_or_self_of_dvd Nat.Prime.eq_one_or_self_of_dvd theorem prime_def_lt'' {p : ℕ} : Prime p ↔ 2 ≤ p ∧ ∀ m, m ∣ p → m = 1 ∨ m = p := by refine ⟨fun h => ⟨h.two_le, h.eq_one_or_self_of_dvd⟩, fun h => ?_⟩ -- Porting note: needed to make ℕ explicit have h1 := (@one_lt_two ℕ ..).trans_le h.1 refine ⟨mt Nat.isUnit_iff.mp h1.ne', fun a b hab => ?_⟩ simp only [Nat.isUnit_iff] apply Or.imp_right _ (h.2 a _) · rintro rfl rw [← mul_right_inj' (pos_of_gt h1).ne', ← hab, mul_one] · rw [hab] exact dvd_mul_right _ _ #align nat.prime_def_lt'' Nat.prime_def_lt'' theorem prime_def_lt {p : ℕ} : Prime p ↔ 2 ≤ p ∧ ∀ m < p, m ∣ p → m = 1 := prime_def_lt''.trans <| and_congr_right fun p2 => forall_congr' fun _ => ⟨fun h l d => (h d).resolve_right (ne_of_lt l), fun h d => (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left fun l => h l d⟩ #align nat.prime_def_lt Nat.prime_def_lt theorem prime_def_lt' {p : ℕ} : Prime p ↔ 2 ≤ p ∧ ∀ m, 2 ≤ m → m < p → ¬m ∣ p := prime_def_lt.trans <| and_congr_right fun p2 => forall_congr' fun m => ⟨fun h m2 l d => not_lt_of_ge m2 ((h l d).symm ▸ by decide), fun h l d => by rcases m with (_ | _ | m) · rw [eq_zero_of_zero_dvd d] at p2 revert p2 decide · rfl · exact (h le_add_self l).elim d⟩ #align nat.prime_def_lt' Nat.prime_def_lt' theorem prime_def_le_sqrt {p : ℕ} : Prime p ↔ 2 ≤ p ∧ ∀ m, 2 ≤ m → m ≤ sqrt p → ¬m ∣ p := prime_def_lt'.trans <| and_congr_right fun p2 => ⟨fun a m m2 l => a m m2 <| lt_of_le_of_lt l <| sqrt_lt_self p2, fun a => have : ∀ {m k : ℕ}, m ≤ k → 1 < m → p ≠ m * k := fun {m k} mk m1 e => a m m1 (le_sqrt.2 (e.symm ▸ Nat.mul_le_mul_left m mk)) ⟨k, e⟩ fun m m2 l ⟨k, e⟩ => by rcases le_total m k with mk | km · exact this mk m2 e · rw [mul_comm] at e refine this km (lt_of_mul_lt_mul_right ?_ (zero_le m)) e rwa [one_mul, ← e]⟩ #align nat.prime_def_le_sqrt Nat.prime_def_le_sqrt theorem prime_of_coprime (n : ℕ) (h1 : 1 < n) (h : ∀ m < n, m ≠ 0 → n.Coprime m) : Prime n := by refine prime_def_lt.mpr ⟨h1, fun m mlt mdvd => ?_⟩ have hm : m ≠ 0 := by rintro rfl rw [zero_dvd_iff] at mdvd exact mlt.ne' mdvd exact (h m mlt hm).symm.eq_one_of_dvd mdvd #align nat.prime_of_coprime Nat.prime_of_coprime section /-- This instance is slower than the instance `decidablePrime` defined below, but has the advantage that it works in the kernel for small values. If you need to prove that a particular number is prime, in any case you should not use `by decide`, but rather `by norm_num`, which is much faster. -/ @[local instance] def decidablePrime1 (p : ℕ) : Decidable (Prime p) := decidable_of_iff' _ prime_def_lt' #align nat.decidable_prime_1 Nat.decidablePrime1 theorem prime_two : Prime 2 := by decide #align nat.prime_two Nat.prime_two theorem prime_three : Prime 3 := by decide #align nat.prime_three Nat.prime_three theorem prime_five : Prime 5 := by decide theorem Prime.five_le_of_ne_two_of_ne_three {p : ℕ} (hp : p.Prime) (h_two : p ≠ 2) (h_three : p ≠ 3) : 5 ≤ p := by by_contra! h revert h_two h_three hp -- Porting note (#11043): was `decide!` match p with | 0 => decide | 1 => decide | 2 => decide | 3 => decide | 4 => decide | n + 5 => exact (h.not_le le_add_self).elim #align nat.prime.five_le_of_ne_two_of_ne_three Nat.Prime.five_le_of_ne_two_of_ne_three end theorem Prime.pred_pos {p : ℕ} (pp : Prime p) : 0 < pred p := lt_pred_iff.2 pp.one_lt #align nat.prime.pred_pos Nat.Prime.pred_pos theorem succ_pred_prime {p : ℕ} (pp : Prime p) : succ (pred p) = p := succ_pred_eq_of_pos pp.pos #align nat.succ_pred_prime Nat.succ_pred_prime theorem dvd_prime {p m : ℕ} (pp : Prime p) : m ∣ p ↔ m = 1 ∨ m = p := ⟨fun d => pp.eq_one_or_self_of_dvd m d, fun h => h.elim (fun e => e.symm ▸ one_dvd _) fun e => e.symm ▸ dvd_rfl⟩ #align nat.dvd_prime Nat.dvd_prime theorem dvd_prime_two_le {p m : ℕ} (pp : Prime p) (H : 2 ≤ m) : m ∣ p ↔ m = p := (dvd_prime pp).trans <| or_iff_right_of_imp <| Not.elim <| ne_of_gt H #align nat.dvd_prime_two_le Nat.dvd_prime_two_le theorem prime_dvd_prime_iff_eq {p q : ℕ} (pp : p.Prime) (qp : q.Prime) : p ∣ q ↔ p = q := dvd_prime_two_le qp (Prime.two_le pp) #align nat.prime_dvd_prime_iff_eq Nat.prime_dvd_prime_iff_eq theorem Prime.not_dvd_one {p : ℕ} (pp : Prime p) : ¬p ∣ 1 := Irreducible.not_dvd_one pp #align nat.prime.not_dvd_one Nat.Prime.not_dvd_one theorem prime_mul_iff {a b : ℕ} : Nat.Prime (a * b) ↔ a.Prime ∧ b = 1 ∨ b.Prime ∧ a = 1 := by simp only [iff_self_iff, irreducible_mul_iff, ← irreducible_iff_nat_prime, Nat.isUnit_iff] #align nat.prime_mul_iff Nat.prime_mul_iff theorem not_prime_mul {a b : ℕ} (a1 : a ≠ 1) (b1 : b ≠ 1) : ¬Prime (a * b) := by simp [prime_mul_iff, _root_.not_or, *] #align nat.not_prime_mul Nat.not_prime_mul theorem not_prime_mul' {a b n : ℕ} (h : a * b = n) (h₁ : a ≠ 1) (h₂ : b ≠ 1) : ¬Prime n := h ▸ not_prime_mul h₁ h₂ #align nat.not_prime_mul' Nat.not_prime_mul' theorem Prime.dvd_iff_eq {p a : ℕ} (hp : p.Prime) (a1 : a ≠ 1) : a ∣ p ↔ p = a := by refine ⟨?_, by rintro rfl; rfl⟩ rintro ⟨j, rfl⟩ rcases prime_mul_iff.mp hp with (⟨_, rfl⟩ | ⟨_, rfl⟩) · exact mul_one _ · exact (a1 rfl).elim #align nat.prime.dvd_iff_eq Nat.Prime.dvd_iff_eq section MinFac theorem minFac_lemma (n k : ℕ) (h : ¬n < k * k) : sqrt n - k < sqrt n + 2 - k := (tsub_lt_tsub_iff_right <| le_sqrt.2 <| le_of_not_gt h).2 <| Nat.lt_add_of_pos_right (by decide) #align nat.min_fac_lemma Nat.minFac_lemma /-- If `n < k * k`, then `minFacAux n k = n`, if `k | n`, then `minFacAux n k = k`. Otherwise, `minFacAux n k = minFacAux n (k+2)` using well-founded recursion. If `n` is odd and `1 < n`, then `minFacAux n 3` is the smallest prime factor of `n`. By default this well-founded recursion would be irreducible. This prevents use `decide` to resolve `Nat.prime n` for small values of `n`, so we mark this as `@[semireducible]`. In future, we may want to remove this annotation and instead use `norm_num` instead of `decide` in these situations. -/ @[semireducible] def minFacAux (n : ℕ) : ℕ → ℕ | k => if n < k * k then n else if k ∣ n then k else minFacAux n (k + 2) termination_by k => sqrt n + 2 - k decreasing_by simp_wf; apply minFac_lemma n k; assumption #align nat.min_fac_aux Nat.minFacAux /-- Returns the smallest prime factor of `n ≠ 1`. -/ def minFac (n : ℕ) : ℕ := if 2 ∣ n then 2 else minFacAux n 3 #align nat.min_fac Nat.minFac @[simp] theorem minFac_zero : minFac 0 = 2 := rfl #align nat.min_fac_zero Nat.minFac_zero @[simp] theorem minFac_one : minFac 1 = 1 := by simp [minFac, minFacAux] #align nat.min_fac_one Nat.minFac_one @[simp] theorem minFac_two : minFac 2 = 2 := by simp [minFac, minFacAux] theorem minFac_eq (n : ℕ) : minFac n = if 2 ∣ n then 2 else minFacAux n 3 := rfl #align nat.min_fac_eq Nat.minFac_eq private def minFacProp (n k : ℕ) := 2 ≤ k ∧ k ∣ n ∧ ∀ m, 2 ≤ m → m ∣ n → k ≤ m theorem minFacAux_has_prop {n : ℕ} (n2 : 2 ≤ n) : ∀ k i, k = 2 * i + 3 → (∀ m, 2 ≤ m → m ∣ n → k ≤ m) → minFacProp n (minFacAux n k) | k => fun i e a => by rw [minFacAux] by_cases h : n < k * k <;> simp [h] · have pp : Prime n := prime_def_le_sqrt.2 ⟨n2, fun m m2 l d => not_lt_of_ge l <| lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)⟩ exact ⟨n2, dvd_rfl, fun m m2 d => le_of_eq ((dvd_prime_two_le pp m2).1 d).symm⟩ have k2 : 2 ≤ k := by subst e apply Nat.le_add_left by_cases dk : k ∣ n <;> simp [dk] · exact ⟨k2, dk, a⟩ · refine have := minFac_lemma n k h minFacAux_has_prop n2 (k + 2) (i + 1) (by simp [k, e, left_distrib, add_right_comm]) fun m m2 d => ?_ rcases Nat.eq_or_lt_of_le (a m m2 d) with me | ml · subst me contradiction apply (Nat.eq_or_lt_of_le ml).resolve_left intro me rw [← me, e] at d have d' : 2 * (i + 2) ∣ n := d have := a _ le_rfl (dvd_of_mul_right_dvd d') rw [e] at this exact absurd this (by contradiction) termination_by k => sqrt n + 2 - k #align nat.min_fac_aux_has_prop Nat.minFacAux_has_prop theorem minFac_has_prop {n : ℕ} (n1 : n ≠ 1) : minFacProp n (minFac n) := by by_cases n0 : n = 0 · simp [n0, minFacProp, GE.ge] have n2 : 2 ≤ n := by revert n0 n1 rcases n with (_ | _ | _) <;> simp [succ_le_succ] simp only [minFac_eq, Nat.isUnit_iff] by_cases d2 : 2 ∣ n <;> simp [d2] · exact ⟨le_rfl, d2, fun k k2 _ => k2⟩ · refine minFacAux_has_prop n2 3 0 rfl fun m m2 d => (Nat.eq_or_lt_of_le m2).resolve_left (mt ?_ d2) exact fun e => e.symm ▸ d #align nat.min_fac_has_prop Nat.minFac_has_prop theorem minFac_dvd (n : ℕ) : minFac n ∣ n := if n1 : n = 1 then by simp [n1] else (minFac_has_prop n1).2.1 #align nat.min_fac_dvd Nat.minFac_dvd theorem minFac_prime {n : ℕ} (n1 : n ≠ 1) : Prime (minFac n) := let ⟨f2, fd, a⟩ := minFac_has_prop n1 prime_def_lt'.2 ⟨f2, fun m m2 l d => not_le_of_gt l (a m m2 (d.trans fd))⟩ #align nat.min_fac_prime Nat.minFac_prime theorem minFac_le_of_dvd {n : ℕ} : ∀ {m : ℕ}, 2 ≤ m → m ∣ n → minFac n ≤ m := by by_cases n1 : n = 1 <;> [exact fun m2 _ => n1.symm ▸ le_trans (by simp) m2; apply (minFac_has_prop n1).2.2] #align nat.min_fac_le_of_dvd Nat.minFac_le_of_dvd theorem minFac_pos (n : ℕ) : 0 < minFac n := by by_cases n1 : n = 1 <;> [exact n1.symm ▸ (by simp); exact (minFac_prime n1).pos] #align nat.min_fac_pos Nat.minFac_pos theorem minFac_le {n : ℕ} (H : 0 < n) : minFac n ≤ n := le_of_dvd H (minFac_dvd n) #align nat.min_fac_le Nat.minFac_le theorem le_minFac {m n : ℕ} : n = 1 ∨ m ≤ minFac n ↔ ∀ p, Prime p → p ∣ n → m ≤ p := ⟨fun h p pp d => h.elim (by rintro rfl; cases pp.not_dvd_one d) fun h => le_trans h <| minFac_le_of_dvd pp.two_le d, fun H => or_iff_not_imp_left.2 fun n1 => H _ (minFac_prime n1) (minFac_dvd _)⟩ #align nat.le_min_fac Nat.le_minFac theorem le_minFac' {m n : ℕ} : n = 1 ∨ m ≤ minFac n ↔ ∀ p, 2 ≤ p → p ∣ n → m ≤ p := ⟨fun h p (pp : 1 < p) d => h.elim (by rintro rfl; cases not_le_of_lt pp (le_of_dvd (by decide) d)) fun h => le_trans h <| minFac_le_of_dvd pp d, fun H => le_minFac.2 fun p pp d => H p pp.two_le d⟩ #align nat.le_min_fac' Nat.le_minFac' theorem prime_def_minFac {p : ℕ} : Prime p ↔ 2 ≤ p ∧ minFac p = p := ⟨fun pp => ⟨pp.two_le, let ⟨f2, fd, _⟩ := minFac_has_prop <| ne_of_gt pp.one_lt ((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)⟩, fun ⟨p2, e⟩ => e ▸ minFac_prime (ne_of_gt p2)⟩ #align nat.prime_def_min_fac Nat.prime_def_minFac @[simp] theorem Prime.minFac_eq {p : ℕ} (hp : Prime p) : minFac p = p := (prime_def_minFac.1 hp).2 #align nat.prime.min_fac_eq Nat.Prime.minFac_eq /-- This instance is faster in the virtual machine than `decidablePrime1`, but slower in the kernel. If you need to prove that a particular number is prime, in any case you should not use `by decide`, but rather `by norm_num`, which is much faster. -/ instance decidablePrime (p : ℕ) : Decidable (Prime p) := decidable_of_iff' _ prime_def_minFac #align nat.decidable_prime Nat.decidablePrime theorem not_prime_iff_minFac_lt {n : ℕ} (n2 : 2 ≤ n) : ¬Prime n ↔ minFac n < n := (not_congr <| prime_def_minFac.trans <| and_iff_right n2).trans <| (lt_iff_le_and_ne.trans <| and_iff_right <| minFac_le <| le_of_succ_le n2).symm #align nat.not_prime_iff_min_fac_lt Nat.not_prime_iff_minFac_lt theorem minFac_le_div {n : ℕ} (pos : 0 < n) (np : ¬Prime n) : minFac n ≤ n / minFac n := match minFac_dvd n with | ⟨0, h0⟩ => absurd pos <| by rw [h0, mul_zero]; decide | ⟨1, h1⟩ => by rw [mul_one] at h1 rw [prime_def_minFac, not_and_or, ← h1, eq_self_iff_true, _root_.not_true, or_false_iff, not_le] at np rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), minFac_one, Nat.div_one] | ⟨x + 2, hx⟩ => by conv_rhs => congr rw [hx] rw [Nat.mul_div_cancel_left _ (minFac_pos _)] exact minFac_le_of_dvd (le_add_left 2 x) ⟨minFac n, by rwa [mul_comm]⟩ #align nat.min_fac_le_div Nat.minFac_le_div /-- The square of the smallest prime factor of a composite number `n` is at most `n`. -/ theorem minFac_sq_le_self {n : ℕ} (w : 0 < n) (h : ¬Prime n) : minFac n ^ 2 ≤ n := have t : minFac n ≤ n / minFac n := minFac_le_div w h calc minFac n ^ 2 = minFac n * minFac n := sq (minFac n) _ ≤ n / minFac n * minFac n := Nat.mul_le_mul_right (minFac n) t _ ≤ n := div_mul_le_self n (minFac n) #align nat.min_fac_sq_le_self Nat.minFac_sq_le_self @[simp] theorem minFac_eq_one_iff {n : ℕ} : minFac n = 1 ↔ n = 1 := by constructor · intro h by_contra hn have := minFac_prime hn rw [h] at this exact not_prime_one this · rintro rfl rfl #align nat.min_fac_eq_one_iff Nat.minFac_eq_one_iff @[simp]
Mathlib/Data/Nat/Prime.lean
442
454
theorem minFac_eq_two_iff (n : ℕ) : minFac n = 2 ↔ 2 ∣ n := by
constructor · intro h rw [← h] exact minFac_dvd n · intro h have ub := minFac_le_of_dvd (le_refl 2) h have lb := minFac_pos n refine ub.eq_or_lt.resolve_right fun h' => ?_ have := le_antisymm (Nat.succ_le_of_lt lb) (Nat.lt_succ_iff.mp h') rw [eq_comm, Nat.minFac_eq_one_iff] at this subst this exact not_lt_of_le (le_of_dvd zero_lt_one h) one_lt_two
/- Copyright (c) 2023 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.MeasureTheory.Constructions.Pi import Mathlib.MeasureTheory.Constructions.Prod.Integral /-! # Integration with respect to a finite product of measures On a finite product of measure spaces, we show that a product of integrable functions each depending on a single coordinate is integrable, in `MeasureTheory.integrable_fintype_prod`, and that its integral is the product of the individual integrals, in `MeasureTheory.integral_fintype_prod_eq_prod`. -/ open Fintype MeasureTheory MeasureTheory.Measure variable {𝕜 : Type*} [RCLike 𝕜] namespace MeasureTheory /-- On a finite product space in `n` variables, for a natural number `n`, a product of integrable functions depending on each coordinate is integrable. -/ theorem Integrable.fin_nat_prod {n : ℕ} {E : Fin n → Type*} [∀ i, MeasureSpace (E i)] [∀ i, SigmaFinite (volume : Measure (E i))] {f : (i : Fin n) → E i → 𝕜} (hf : ∀ i, Integrable (f i)) : Integrable (fun (x : (i : Fin n) → E i) ↦ ∏ i, f i (x i)) := by induction n with | zero => simp only [Nat.zero_eq, Finset.univ_eq_empty, Finset.prod_empty, volume_pi, integrable_const_iff, one_ne_zero, pi_empty_univ, ENNReal.one_lt_top, or_true] | succ n n_ih => have := ((measurePreserving_piFinSuccAbove (fun i => (volume : Measure (E i))) 0).symm) rw [volume_pi, ← this.integrable_comp_emb (MeasurableEquiv.measurableEmbedding _)] simp_rw [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.prod_univ_succ, Fin.insertNth_zero] simp only [Fin.zero_succAbove, cast_eq, Function.comp_def, Fin.cons_zero, Fin.cons_succ] have : Integrable (fun (x : (j : Fin n) → E (Fin.succ j)) ↦ ∏ j, f (Fin.succ j) (x j)) := n_ih (fun i ↦ hf _) exact Integrable.prod_mul (hf 0) this /-- On a finite product space, a product of integrable functions depending on each coordinate is integrable. Version with dependent target. -/ theorem Integrable.fintype_prod_dep {ι : Type*} [Fintype ι] {E : ι → Type*} {f : (i : ι) → E i → 𝕜} [∀ i, MeasureSpace (E i)] [∀ i, SigmaFinite (volume : Measure (E i))] (hf : ∀ i, Integrable (f i)) : Integrable (fun (x : (i : ι) → E i) ↦ ∏ i, f i (x i)) := by let e := (equivFin ι).symm simp_rw [← (volume_measurePreserving_piCongrLeft _ e).integrable_comp_emb (MeasurableEquiv.measurableEmbedding _), ← e.prod_comp, MeasurableEquiv.coe_piCongrLeft, Function.comp_def, Equiv.piCongrLeft_apply_apply] exact .fin_nat_prod (fun i ↦ hf _) /-- On a finite product space, a product of integrable functions depending on each coordinate is integrable. -/ theorem Integrable.fintype_prod {ι : Type*} [Fintype ι] {E : Type*} {f : ι → E → 𝕜} [MeasureSpace E] [SigmaFinite (volume : Measure E)] (hf : ∀ i, Integrable (f i)) : Integrable (fun (x : ι → E) ↦ ∏ i, f i (x i)) := Integrable.fintype_prod_dep hf /-- A version of **Fubini's theorem** in `n` variables, for a natural number `n`. -/
Mathlib/MeasureTheory/Integral/Pi.lean
65
84
theorem integral_fin_nat_prod_eq_prod {n : ℕ} {E : Fin n → Type*} [∀ i, MeasureSpace (E i)] [∀ i, SigmaFinite (volume : Measure (E i))] (f : (i : Fin n) → E i → 𝕜) : ∫ x : (i : Fin n) → E i, ∏ i, f i (x i) = ∏ i, ∫ x, f i x := by
induction n with | zero => simp only [Nat.zero_eq, volume_pi, Finset.univ_eq_empty, Finset.prod_empty, integral_const, pi_empty_univ, ENNReal.one_toReal, smul_eq_mul, mul_one, pow_zero, one_smul] | succ n n_ih => calc _ = ∫ x : E 0 × ((i : Fin n) → E (Fin.succ i)), f 0 x.1 * ∏ i : Fin n, f (Fin.succ i) (x.2 i) := by rw [volume_pi, ← ((measurePreserving_piFinSuccAbove (fun i => (volume : Measure (E i))) 0).symm).integral_comp'] simp_rw [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.prod_univ_succ, Fin.insertNth_zero, Fin.cons_succ, volume_eq_prod, volume_pi, Fin.zero_succAbove, cast_eq, Fin.cons_zero] _ = (∫ x, f 0 x) * ∏ i : Fin n, ∫ (x : E (Fin.succ i)), f (Fin.succ i) x := by rw [← n_ih, ← integral_prod_mul, volume_eq_prod] _ = ∏ i, ∫ x, f i x := by rw [Fin.prod_univ_succ]
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.RBMap.Alter import Batteries.Data.List.Lemmas /-! # Additional lemmas for Red-black trees -/ namespace Batteries namespace RBNode open RBColor attribute [simp] fold foldl foldr Any forM foldlM Ordered @[simp] theorem min?_reverse (t : RBNode α) : t.reverse.min? = t.max? := by unfold RBNode.max?; split <;> simp [RBNode.min?] unfold RBNode.min?; rw [min?.match_1.eq_3] · apply min?_reverse · simpa [reverse_eq_iff] @[simp] theorem max?_reverse (t : RBNode α) : t.reverse.max? = t.min? := by rw [← min?_reverse, reverse_reverse] @[simp] theorem mem_nil {x} : ¬x ∈ (.nil : RBNode α) := by simp [(·∈·), EMem] @[simp] theorem mem_node {y c a x b} : y ∈ (.node c a x b : RBNode α) ↔ y = x ∨ y ∈ a ∨ y ∈ b := by simp [(·∈·), EMem] theorem All_def {t : RBNode α} : t.All p ↔ ∀ x ∈ t, p x := by induction t <;> simp [or_imp, forall_and, *] theorem Any_def {t : RBNode α} : t.Any p ↔ ∃ x ∈ t, p x := by induction t <;> simp [or_and_right, exists_or, *] theorem memP_def : MemP cut t ↔ ∃ x ∈ t, cut x = .eq := Any_def theorem mem_def : Mem cmp x t ↔ ∃ y ∈ t, cmp x y = .eq := Any_def theorem mem_congr [@TransCmp α cmp] {t : RBNode α} (h : cmp x y = .eq) : Mem cmp x t ↔ Mem cmp y t := by simp [Mem, TransCmp.cmp_congr_left' h] theorem isOrdered_iff' [@TransCmp α cmp] {t : RBNode α} : isOrdered cmp t L R ↔ (∀ a ∈ L, t.All (cmpLT cmp a ·)) ∧ (∀ a ∈ R, t.All (cmpLT cmp · a)) ∧ (∀ a ∈ L, ∀ b ∈ R, cmpLT cmp a b) ∧ Ordered cmp t := by induction t generalizing L R with | nil => simp [isOrdered]; split <;> simp [cmpLT_iff] next h => intro _ ha _ hb; cases h _ _ ha hb | node _ l v r => simp [isOrdered, *] exact ⟨ fun ⟨⟨Ll, lv, Lv, ol⟩, ⟨vr, rR, vR, or⟩⟩ => ⟨ fun _ h => ⟨Lv _ h, Ll _ h, (Lv _ h).trans_l vr⟩, fun _ h => ⟨vR _ h, (vR _ h).trans_r lv, rR _ h⟩, fun _ hL _ hR => (Lv _ hL).trans (vR _ hR), lv, vr, ol, or⟩, fun ⟨hL, hR, _, lv, vr, ol, or⟩ => ⟨ ⟨fun _ h => (hL _ h).2.1, lv, fun _ h => (hL _ h).1, ol⟩, ⟨vr, fun _ h => (hR _ h).2.2, fun _ h => (hR _ h).1, or⟩⟩⟩ theorem isOrdered_iff [@TransCmp α cmp] {t : RBNode α} : isOrdered cmp t ↔ Ordered cmp t := by simp [isOrdered_iff'] instance (cmp) [@TransCmp α cmp] (t) : Decidable (Ordered cmp t) := decidable_of_iff _ isOrdered_iff /-- A cut is like a homomorphism of orderings: it is a monotonic predicate with respect to `cmp`, but it can make things that are distinguished by `cmp` equal. This is sufficient for `find?` to locate an element on which `cut` returns `.eq`, but there may be other elements, not returned by `find?`, on which `cut` also returns `.eq`. -/ class IsCut (cmp : α → α → Ordering) (cut : α → Ordering) : Prop where /-- The set `{x | cut x = .lt}` is downward-closed. -/ le_lt_trans [TransCmp cmp] : cmp x y ≠ .gt → cut x = .lt → cut y = .lt /-- The set `{x | cut x = .gt}` is upward-closed. -/ le_gt_trans [TransCmp cmp] : cmp x y ≠ .gt → cut y = .gt → cut x = .gt theorem IsCut.lt_trans [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .lt) : cut x = .lt → cut y = .lt := IsCut.le_lt_trans <| TransCmp.gt_asymm <| OrientedCmp.cmp_eq_gt.2 H theorem IsCut.gt_trans [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .lt) : cut y = .gt → cut x = .gt := IsCut.le_gt_trans <| TransCmp.gt_asymm <| OrientedCmp.cmp_eq_gt.2 H theorem IsCut.congr [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .eq) : cut x = cut y := by cases ey : cut y · exact IsCut.le_lt_trans (fun h => nomatch H.symm.trans <| OrientedCmp.cmp_eq_gt.1 h) ey · cases ex : cut x · exact IsCut.le_lt_trans (fun h => nomatch H.symm.trans h) ex |>.symm.trans ey · rfl · refine IsCut.le_gt_trans (cmp := cmp) (fun h => ?_) ex |>.symm.trans ey cases H.symm.trans <| OrientedCmp.cmp_eq_gt.1 h · exact IsCut.le_gt_trans (fun h => nomatch H.symm.trans h) ey instance (cmp cut) [@IsCut α cmp cut] : IsCut (flip cmp) (cut · |>.swap) where le_lt_trans h₁ h₂ := by have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))) rw [IsCut.le_gt_trans (cmp := cmp) h₁ (Ordering.swap_inj.1 h₂)]; rfl le_gt_trans h₁ h₂ := by have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))) rw [IsCut.le_lt_trans (cmp := cmp) h₁ (Ordering.swap_inj.1 h₂)]; rfl /-- `IsStrictCut` upgrades the `IsCut` property to ensure that at most one element of the tree can match the cut, and hence `find?` will return the unique such element if one exists. -/ class IsStrictCut (cmp : α → α → Ordering) (cut : α → Ordering) extends IsCut cmp cut : Prop where /-- If `cut = x`, then `cut` and `x` have compare the same with respect to other elements. -/ exact [TransCmp cmp] : cut x = .eq → cmp x y = cut y /-- A "representable cut" is one generated by `cmp a` for some `a`. This is always a valid cut. -/ instance (cmp) (a : α) : IsStrictCut cmp (cmp a) where le_lt_trans h₁ h₂ := TransCmp.lt_le_trans h₂ h₁ le_gt_trans h₁ := Decidable.not_imp_not.1 (TransCmp.le_trans · h₁) exact h := (TransCmp.cmp_congr_left h).symm instance (cmp cut) [@IsStrictCut α cmp cut] : IsStrictCut (flip cmp) (cut · |>.swap) where exact h := by have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))) rw [← IsStrictCut.exact (cmp := cmp) (Ordering.swap_inj.1 h), OrientedCmp.symm]; rfl section fold theorem foldr_cons (t : RBNode α) (l) : t.foldr (·::·) l = t.toList ++ l := by unfold toList induction t generalizing l with | nil => rfl | node _ a _ b iha ihb => rw [foldr, foldr, iha, iha (_::_), ihb]; simp @[simp] theorem toList_nil : (.nil : RBNode α).toList = [] := rfl @[simp] theorem toList_node : (.node c a x b : RBNode α).toList = a.toList ++ x :: b.toList := by rw [toList, foldr, foldr_cons]; rfl @[simp] theorem toList_reverse (t : RBNode α) : t.reverse.toList = t.toList.reverse := by induction t <;> simp [*] @[simp] theorem mem_toList {t : RBNode α} : x ∈ t.toList ↔ x ∈ t := by induction t <;> simp [*, or_left_comm] @[simp] theorem mem_reverse {t : RBNode α} : a ∈ t.reverse ↔ a ∈ t := by rw [← mem_toList]; simp theorem min?_eq_toList_head? {t : RBNode α} : t.min? = t.toList.head? := by induction t with | nil => rfl | node _ l _ _ ih => cases l <;> simp [RBNode.min?, ih] next ll _ _ => cases toList ll <;> rfl theorem max?_eq_toList_getLast? {t : RBNode α} : t.max? = t.toList.getLast? := by rw [← min?_reverse, min?_eq_toList_head?]; simp theorem foldr_eq_foldr_toList {t : RBNode α} : t.foldr f init = t.toList.foldr f init := by induction t generalizing init <;> simp [*] theorem foldl_eq_foldl_toList {t : RBNode α} : t.foldl f init = t.toList.foldl f init := by induction t generalizing init <;> simp [*] theorem foldl_reverse {α β : Type _} {t : RBNode α} {f : β → α → β} {init : β} : t.reverse.foldl f init = t.foldr (flip f) init := by simp (config := {unfoldPartialApp := true}) [foldr_eq_foldr_toList, foldl_eq_foldl_toList, flip] theorem foldr_reverse {α β : Type _} {t : RBNode α} {f : α → β → β} {init : β} : t.reverse.foldr f init = t.foldl (flip f) init := foldl_reverse.symm.trans (by simp; rfl) theorem forM_eq_forM_toList [Monad m] [LawfulMonad m] {t : RBNode α} : t.forM (m := m) f = t.toList.forM f := by induction t <;> simp [*] theorem foldlM_eq_foldlM_toList [Monad m] [LawfulMonad m] {t : RBNode α} : t.foldlM (m := m) f init = t.toList.foldlM f init := by induction t generalizing init <;> simp [*] theorem forIn_visit_eq_bindList [Monad m] [LawfulMonad m] {t : RBNode α} : forIn.visit (m := m) f t init = (ForInStep.yield init).bindList f t.toList := by induction t generalizing init <;> simp [*, forIn.visit] theorem forIn_eq_forIn_toList [Monad m] [LawfulMonad m] {t : RBNode α} : forIn (m := m) t init f = forIn t.toList init f := by conv => lhs; simp only [forIn, RBNode.forIn] rw [List.forIn_eq_bindList, forIn_visit_eq_bindList] end fold namespace Stream attribute [simp] foldl foldr theorem foldr_cons (t : RBNode.Stream α) (l) : t.foldr (·::·) l = t.toList ++ l := by unfold toList; apply Eq.symm; induction t <;> simp [*, foldr, RBNode.foldr_cons] @[simp] theorem toList_nil : (.nil : RBNode.Stream α).toList = [] := rfl @[simp] theorem toList_cons : (.cons x r s : RBNode.Stream α).toList = x :: r.toList ++ s.toList := by rw [toList, toList, foldr, RBNode.foldr_cons]; rfl theorem foldr_eq_foldr_toList {s : RBNode.Stream α} : s.foldr f init = s.toList.foldr f init := by induction s <;> simp [*, RBNode.foldr_eq_foldr_toList] theorem foldl_eq_foldl_toList {t : RBNode.Stream α} : t.foldl f init = t.toList.foldl f init := by induction t generalizing init <;> simp [*, RBNode.foldl_eq_foldl_toList] theorem forIn_eq_forIn_toList [Monad m] [LawfulMonad m] {t : RBNode α} : forIn (m := m) t init f = forIn t.toList init f := by conv => lhs; simp only [forIn, RBNode.forIn] rw [List.forIn_eq_bindList, forIn_visit_eq_bindList] end Stream theorem toStream_toList' {t : RBNode α} {s} : (t.toStream s).toList = t.toList ++ s.toList := by induction t generalizing s <;> simp [*, toStream] @[simp] theorem toStream_toList {t : RBNode α} : t.toStream.toList = t.toList := by simp [toStream_toList'] theorem Stream.next?_toList {s : RBNode.Stream α} : (s.next?.map fun (a, b) => (a, b.toList)) = s.toList.next? := by cases s <;> simp [next?, toStream_toList'] theorem ordered_iff {t : RBNode α} : t.Ordered cmp ↔ t.toList.Pairwise (cmpLT cmp) := by induction t with | nil => simp | node c l v r ihl ihr => simp [*, List.pairwise_append, Ordered, All_def, and_assoc, and_left_comm, and_comm, imp_and, forall_and] exact fun _ _ hl hr a ha b hb => (hl _ ha).trans (hr _ hb) theorem Ordered.toList_sorted {t : RBNode α} : t.Ordered cmp → t.toList.Pairwise (cmpLT cmp) := ordered_iff.1 theorem min?_mem {t : RBNode α} (h : t.min? = some a) : a ∈ t := by rw [min?_eq_toList_head?] at h rw [← mem_toList] revert h; cases toList t <;> rintro ⟨⟩; constructor theorem Ordered.min?_le {t : RBNode α} [TransCmp cmp] (ht : t.Ordered cmp) (h : t.min? = some a) (x) (hx : x ∈ t) : cmp a x ≠ .gt := by rw [min?_eq_toList_head?] at h rw [← mem_toList] at hx have := ht.toList_sorted revert h hx this; cases toList t <;> rintro ⟨⟩ (_ | ⟨_, hx⟩) (_ | ⟨h1,h2⟩) · rw [OrientedCmp.cmp_refl (cmp := cmp)]; decide · rw [(h1 _ hx).1]; decide theorem max?_mem {t : RBNode α} (h : t.max? = some a) : a ∈ t := by simpa using min?_mem ((min?_reverse _).trans h) theorem Ordered.le_max? {t : RBNode α} [TransCmp cmp] (ht : t.Ordered cmp) (h : t.max? = some a) (x) (hx : x ∈ t) : cmp x a ≠ .gt := ht.reverse.min?_le ((min?_reverse _).trans h) _ (by simpa using hx) @[simp] theorem setBlack_toList {t : RBNode α} : t.setBlack.toList = t.toList := by cases t <;> simp [setBlack] @[simp] theorem setRed_toList {t : RBNode α} : t.setRed.toList = t.toList := by cases t <;> simp [setRed] @[simp] theorem balance1_toList {l : RBNode α} {v r} : (l.balance1 v r).toList = l.toList ++ v :: r.toList := by unfold balance1; split <;> simp @[simp] theorem balance2_toList {l : RBNode α} {v r} : (l.balance2 v r).toList = l.toList ++ v :: r.toList := by unfold balance2; split <;> simp @[simp] theorem balLeft_toList {l : RBNode α} {v r} : (l.balLeft v r).toList = l.toList ++ v :: r.toList := by unfold balLeft; split <;> (try simp); split <;> simp @[simp] theorem balRight_toList {l : RBNode α} {v r} : (l.balRight v r).toList = l.toList ++ v :: r.toList := by unfold balRight; split <;> (try simp); split <;> simp theorem size_eq {t : RBNode α} : t.size = t.toList.length := by induction t <;> simp [*, size]; rfl @[simp] theorem reverse_size (t : RBNode α) : t.reverse.size = t.size := by simp [size_eq] @[simp] theorem Any_reverse {t : RBNode α} : t.reverse.Any p ↔ t.Any p := by simp [Any_def] @[simp] theorem memP_reverse {t : RBNode α} : MemP cut t.reverse ↔ MemP (cut · |>.swap) t := by simp [MemP]; apply Iff.of_eq; congr; funext x; rw [← Ordering.swap_inj]; rfl theorem Mem_reverse [@OrientedCmp α cmp] {t : RBNode α} : Mem cmp x t.reverse ↔ Mem (flip cmp) x t := by simp [Mem]; apply Iff.of_eq; congr; funext x; rw [OrientedCmp.symm]; rfl section find? theorem find?_some_eq_eq {t : RBNode α} : x ∈ t.find? cut → cut x = .eq := by induction t <;> simp [find?]; split <;> try assumption intro | rfl => assumption theorem find?_some_mem {t : RBNode α} : x ∈ t.find? cut → x ∈ t := by induction t <;> simp [find?]; split <;> simp (config := {contextual := true}) [*] theorem find?_some_memP {t : RBNode α} (h : x ∈ t.find? cut) : MemP cut t := memP_def.2 ⟨_, find?_some_mem h, find?_some_eq_eq h⟩ theorem Ordered.memP_iff_find? [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) : MemP cut t ↔ ∃ x, t.find? cut = some x := by refine ⟨fun H => ?_, fun ⟨x, h⟩ => find?_some_memP h⟩ induction t with simp [find?] at H ⊢ | nil => cases H | node _ l _ r ihl ihr => let ⟨lx, xr, hl, hr⟩ := ht split · next ev => refine ihl hl ?_ rcases H with ev' | hx | hx · cases ev.symm.trans ev' · exact hx · have ⟨z, hz, ez⟩ := Any_def.1 hx cases ez.symm.trans <| IsCut.lt_trans (All_def.1 xr _ hz).1 ev · next ev => refine ihr hr ?_ rcases H with ev' | hx | hx · cases ev.symm.trans ev' · have ⟨z, hz, ez⟩ := Any_def.1 hx cases ez.symm.trans <| IsCut.gt_trans (All_def.1 lx _ hz).1 ev · exact hx · exact ⟨_, rfl⟩ theorem Ordered.unique [@TransCmp α cmp] (ht : Ordered cmp t) (hx : x ∈ t) (hy : y ∈ t) (e : cmp x y = .eq) : x = y := by induction t with | nil => cases hx | node _ l _ r ihl ihr => let ⟨lx, xr, hl, hr⟩ := ht rcases hx, hy with ⟨rfl | hx | hx, rfl | hy | hy⟩ · rfl · cases e.symm.trans <| OrientedCmp.cmp_eq_gt.2 (All_def.1 lx _ hy).1 · cases e.symm.trans (All_def.1 xr _ hy).1 · cases e.symm.trans (All_def.1 lx _ hx).1 · exact ihl hl hx hy · cases e.symm.trans ((All_def.1 lx _ hx).trans (All_def.1 xr _ hy)).1 · cases e.symm.trans <| OrientedCmp.cmp_eq_gt.2 (All_def.1 xr _ hx).1 · cases e.symm.trans <| OrientedCmp.cmp_eq_gt.2 ((All_def.1 lx _ hy).trans (All_def.1 xr _ hx)).1 · exact ihr hr hx hy theorem Ordered.find?_some [@TransCmp α cmp] [IsStrictCut cmp cut] (ht : Ordered cmp t) : t.find? cut = some x ↔ x ∈ t ∧ cut x = .eq := by refine ⟨fun h => ⟨find?_some_mem h, find?_some_eq_eq h⟩, fun ⟨hx, e⟩ => ?_⟩ have ⟨y, hy⟩ := ht.memP_iff_find?.1 (memP_def.2 ⟨_, hx, e⟩) exact ht.unique hx (find?_some_mem hy) ((IsStrictCut.exact e).trans (find?_some_eq_eq hy)) ▸ hy @[simp] theorem find?_reverse (t : RBNode α) (cut : α → Ordering) : t.reverse.find? cut = t.find? (cut · |>.swap) := by induction t <;> simp [*, find?] cases cut _ <;> simp [Ordering.swap] /-- Auxiliary definition for `zoom_ins`: set the root of the tree to `v`, creating a node if necessary. -/ def setRoot (v : α) : RBNode α → RBNode α | nil => node red nil v nil | node c a _ b => node c a v b /-- Auxiliary definition for `zoom_ins`: set the root of the tree to `v`, creating a node if necessary. -/ def delRoot : RBNode α → RBNode α | nil => nil | node _ a _ b => a.append b end find? section «upperBound? and lowerBound?» @[simp] theorem upperBound?_reverse (t : RBNode α) (cut ub) : t.reverse.upperBound? cut ub = t.lowerBound? (cut · |>.swap) ub := by induction t generalizing ub <;> simp [lowerBound?, upperBound?] split <;> simp [*, Ordering.swap] @[simp] theorem lowerBound?_reverse (t : RBNode α) (cut lb) : t.reverse.lowerBound? cut lb = t.upperBound? (cut · |>.swap) lb := by simpa using (upperBound?_reverse t.reverse (cut · |>.swap) lb).symm theorem upperBound?_eq_find? {t : RBNode α} {cut} (ub) (H : t.find? cut = some x) : t.upperBound? cut ub = some x := by induction t generalizing ub with simp [find?] at H | node c a y b iha ihb => simp [upperBound?]; split at H · apply iha _ H · apply ihb _ H · exact H theorem lowerBound?_eq_find? {t : RBNode α} {cut} (lb) (H : t.find? cut = some x) : t.lowerBound? cut lb = some x := by rw [← reverse_reverse t] at H ⊢; rw [lowerBound?_reverse]; rw [find?_reverse] at H exact upperBound?_eq_find? _ H /-- The value `x` returned by `upperBound?` is greater or equal to the `cut`. -/ theorem upperBound?_ge' {t : RBNode α} (H : ∀ {x}, x ∈ ub → cut x ≠ .gt) : t.upperBound? cut ub = some x → cut x ≠ .gt := by induction t generalizing ub with | nil => exact H | node _ _ _ _ ihl ihr => simp [upperBound?]; split · next hv => exact ihl fun | rfl, e => nomatch hv.symm.trans e · exact ihr H · next hv => intro | rfl, e => cases hv.symm.trans e /-- The value `x` returned by `upperBound?` is greater or equal to the `cut`. -/ theorem upperBound?_ge {t : RBNode α} : t.upperBound? cut = some x → cut x ≠ .gt := upperBound?_ge' nofun /-- The value `x` returned by `lowerBound?` is less or equal to the `cut`. -/ theorem lowerBound?_le' {t : RBNode α} (H : ∀ {x}, x ∈ lb → cut x ≠ .lt) : t.lowerBound? cut lb = some x → cut x ≠ .lt := by rw [← reverse_reverse t, lowerBound?_reverse, Ne, ← Ordering.swap_inj] exact upperBound?_ge' fun h => by specialize H h; rwa [Ne, ← Ordering.swap_inj] at H /-- The value `x` returned by `lowerBound?` is less or equal to the `cut`. -/ theorem lowerBound?_le {t : RBNode α} : t.lowerBound? cut = some x → cut x ≠ .lt := lowerBound?_le' nofun theorem All.upperBound?_ub {t : RBNode α} (hp : t.All p) (H : ∀ {x}, ub = some x → p x) : t.upperBound? cut ub = some x → p x := by induction t generalizing ub with | nil => exact H | node _ _ _ _ ihl ihr => simp [upperBound?]; split · exact ihl hp.2.1 fun | rfl => hp.1 · exact ihr hp.2.2 H · exact fun | rfl => hp.1 theorem All.upperBound? {t : RBNode α} (hp : t.All p) : t.upperBound? cut = some x → p x := hp.upperBound?_ub nofun theorem All.lowerBound?_lb {t : RBNode α} (hp : t.All p) (H : ∀ {x}, lb = some x → p x) : t.lowerBound? cut lb = some x → p x := by rw [← reverse_reverse t, lowerBound?_reverse] exact All.upperBound?_ub (All.reverse.2 hp) H theorem All.lowerBound? {t : RBNode α} (hp : t.All p) : t.lowerBound? cut = some x → p x := hp.lowerBound?_lb nofun theorem upperBound?_mem_ub {t : RBNode α} (h : t.upperBound? cut ub = some x) : x ∈ t ∨ ub = some x := All.upperBound?_ub (p := fun x => x ∈ t ∨ ub = some x) (All_def.2 fun _ => .inl) Or.inr h theorem upperBound?_mem {t : RBNode α} (h : t.upperBound? cut = some x) : x ∈ t := (upperBound?_mem_ub h).resolve_right nofun theorem lowerBound?_mem_lb {t : RBNode α} (h : t.lowerBound? cut lb = some x) : x ∈ t ∨ lb = some x := All.lowerBound?_lb (p := fun x => x ∈ t ∨ lb = some x) (All_def.2 fun _ => .inl) Or.inr h theorem lowerBound?_mem {t : RBNode α} (h : t.lowerBound? cut = some x) : x ∈ t := (lowerBound?_mem_lb h).resolve_right nofun theorem upperBound?_of_some {t : RBNode α} : ∃ x, t.upperBound? cut (some y) = some x := by induction t generalizing y <;> simp [upperBound?]; split <;> simp [*] theorem lowerBound?_of_some {t : RBNode α} : ∃ x, t.lowerBound? cut (some y) = some x := by rw [← reverse_reverse t, lowerBound?_reverse]; exact upperBound?_of_some theorem Ordered.upperBound?_exists [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t) : (∃ x, t.upperBound? cut = some x) ↔ ∃ x ∈ t, cut x ≠ .gt := by refine ⟨fun ⟨x, hx⟩ => ⟨_, upperBound?_mem hx, upperBound?_ge hx⟩, fun H => ?_⟩ obtain ⟨x, hx, e⟩ := H induction t generalizing x with | nil => cases hx | node _ _ _ _ _ ihr => simp [upperBound?]; split · exact upperBound?_of_some · rcases hx with rfl | hx | hx · contradiction · next hv => cases e <| IsCut.gt_trans (All_def.1 h.1 _ hx).1 hv · exact ihr h.2.2.2 _ hx e · exact ⟨_, rfl⟩ theorem Ordered.lowerBound?_exists [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t) : (∃ x, t.lowerBound? cut = some x) ↔ ∃ x ∈ t, cut x ≠ .lt := by conv => enter [2, 1, x]; rw [Ne, ← Ordering.swap_inj] rw [← reverse_reverse t, lowerBound?_reverse] simpa [-Ordering.swap_inj] using h.reverse.upperBound?_exists (cut := (cut · |>.swap)) theorem Ordered.upperBound?_least_ub [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t) (hub : ∀ {x}, ub = some x → t.All (cmpLT cmp · x)) : t.upperBound? cut ub = some x → y ∈ t → cut x = .lt → cmp y x = .lt → cut y = .gt := by induction t generalizing ub with | nil => nofun | node _ _ _ _ ihl ihr => simp [upperBound?]; split <;> rename_i hv <;> rintro h₁ (rfl | hy' | hy') hx h₂ · rcases upperBound?_mem_ub h₁ with h₁ | ⟨⟨⟩⟩ · cases TransCmp.lt_asymm h₂ (All_def.1 h.1 _ h₁).1 · cases TransCmp.lt_asymm h₂ h₂ · exact ihl h.2.2.1 (by rintro _ ⟨⟨⟩⟩; exact h.1) h₁ hy' hx h₂ · refine (TransCmp.lt_asymm h₂ ?_).elim; have := (All_def.1 h.2.1 _ hy').1 rcases upperBound?_mem_ub h₁ with h₁ | ⟨⟨⟩⟩ · exact TransCmp.lt_trans (All_def.1 h.1 _ h₁).1 this · exact this · exact hv · exact IsCut.gt_trans (cut := cut) (cmp := cmp) (All_def.1 h.1 _ hy').1 hv · exact ihr h.2.2.2 (fun h => (hub h).2.2) h₁ hy' hx h₂ · cases h₁; cases TransCmp.lt_asymm h₂ h₂ · cases h₁; cases hx.symm.trans hv · cases h₁; cases hx.symm.trans hv theorem Ordered.lowerBound?_greatest_lb [@TransCmp α cmp] [IsCut cmp cut] (h : Ordered cmp t) (hlb : ∀ {x}, lb = some x → t.All (cmpLT cmp x ·)) : t.lowerBound? cut lb = some x → y ∈ t → cut x = .gt → cmp x y = .lt → cut y = .lt := by intro h1 h2 h3 h4 rw [← reverse_reverse t, lowerBound?_reverse] at h1 rw [← Ordering.swap_inj] at h3 ⊢ revert h2 h3 h4 simpa [-Ordering.swap_inj] using h.reverse.upperBound?_least_ub (fun h => All.reverse.2 <| (hlb h).imp .flip) h1 /-- A statement of the least-ness of the result of `upperBound?`. If `x` is the return value of `upperBound?` and it is strictly greater than the cut, then any other `y < x` in the tree is in fact strictly less than the cut (so there is no exact match, and nothing closer to the cut). -/ theorem Ordered.upperBound?_least [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) (H : t.upperBound? cut = some x) (hy : y ∈ t) (xy : cmp y x = .lt) (hx : cut x = .lt) : cut y = .gt := ht.upperBound?_least_ub (by nofun) H hy hx xy /-- A statement of the greatest-ness of the result of `lowerBound?`. If `x` is the return value of `lowerBound?` and it is strictly less than the cut, then any other `y > x` in the tree is in fact strictly greater than the cut (so there is no exact match, and nothing closer to the cut). -/ theorem Ordered.lowerBound?_greatest [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) (H : t.lowerBound? cut none = some x) (hy : y ∈ t) (xy : cmp x y = .lt) (hx : cut x = .gt) : cut y = .lt := ht.lowerBound?_greatest_lb (by nofun) H hy hx xy theorem Ordered.memP_iff_upperBound? [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) : t.MemP cut ↔ ∃ x, t.upperBound? cut = some x ∧ cut x = .eq := by refine memP_def.trans ⟨fun ⟨y, hy, ey⟩ => ?_, fun ⟨x, hx, e⟩ => ⟨_, upperBound?_mem hx, e⟩⟩ have ⟨x, hx⟩ := ht.upperBound?_exists.2 ⟨_, hy, fun h => nomatch ey.symm.trans h⟩ refine ⟨x, hx, ?_⟩; cases ex : cut x · cases e : cmp x y · cases ey.symm.trans <| IsCut.lt_trans e ex · cases ey.symm.trans <| IsCut.congr e |>.symm.trans ex · cases ey.symm.trans <| ht.upperBound?_least hx hy (OrientedCmp.cmp_eq_gt.1 e) ex · rfl · cases upperBound?_ge hx ex theorem Ordered.memP_iff_lowerBound? [@TransCmp α cmp] [IsCut cmp cut] (ht : Ordered cmp t) : t.MemP cut ↔ ∃ x, t.lowerBound? cut = some x ∧ cut x = .eq := by refine memP_def.trans ⟨fun ⟨y, hy, ey⟩ => ?_, fun ⟨x, hx, e⟩ => ⟨_, lowerBound?_mem hx, e⟩⟩ have ⟨x, hx⟩ := ht.lowerBound?_exists.2 ⟨_, hy, fun h => nomatch ey.symm.trans h⟩ refine ⟨x, hx, ?_⟩; cases ex : cut x · cases lowerBound?_le hx ex · rfl · cases e : cmp x y · cases ey.symm.trans <| ht.lowerBound?_greatest hx hy e ex · cases ey.symm.trans <| IsCut.congr e |>.symm.trans ex · cases ey.symm.trans <| IsCut.gt_trans (OrientedCmp.cmp_eq_gt.1 e) ex /-- A stronger version of `lowerBound?_greatest` that holds when the cut is strict. -/ theorem Ordered.lowerBound?_lt [@TransCmp α cmp] [IsStrictCut cmp cut] (ht : Ordered cmp t) (H : t.lowerBound? cut = some x) (hy : y ∈ t) : cmp x y = .lt ↔ cut y = .lt := by refine ⟨fun h => ?_, fun h => OrientedCmp.cmp_eq_gt.1 ?_⟩ · cases e : cut x · cases lowerBound?_le H e · exact IsStrictCut.exact e |>.symm.trans h · exact ht.lowerBound?_greatest H hy h e · by_contra h'; exact lowerBound?_le H <| IsCut.le_lt_trans (cmp := cmp) (cut := cut) h' h /-- A stronger version of `upperBound?_least` that holds when the cut is strict. -/ theorem Ordered.lt_upperBound? [@TransCmp α cmp] [IsStrictCut cmp cut] (ht : Ordered cmp t) (H : t.upperBound? cut = some x) (hy : y ∈ t) : cmp y x = .lt ↔ cut y = .gt := by rw [← reverse_reverse t, upperBound?_reverse] at H rw [← Ordering.swap_inj (o₂ := .gt)] revert hy; simpa [-Ordering.swap_inj] using ht.reverse.lowerBound?_lt H end «upperBound? and lowerBound?» namespace Path attribute [simp] RootOrdered Ordered /-- The list of elements to the left of the hole. (This function is intended for specification purposes only.) -/ @[simp] def listL : Path α → List α | .root => [] | .left _ parent _ _ => parent.listL | .right _ l v parent => parent.listL ++ (l.toList ++ [v]) /-- The list of elements to the right of the hole. (This function is intended for specification purposes only.) -/ @[simp] def listR : Path α → List α | .root => [] | .left _ parent v r => v :: r.toList ++ parent.listR | .right _ _ _ parent => parent.listR /-- Wraps a list of elements with the left and right elements of the path. -/ abbrev withList (p : Path α) (l : List α) : List α := p.listL ++ l ++ p.listR theorem rootOrdered_iff {p : Path α} (hp : p.Ordered cmp) : p.RootOrdered cmp v ↔ (∀ a ∈ p.listL, cmpLT cmp a v) ∧ (∀ a ∈ p.listR, cmpLT cmp v a) := by induction p with (simp [All_def] at hp; simp [*, and_assoc, and_left_comm, and_comm, or_imp, forall_and]) | left _ _ x _ ih => exact fun vx _ _ _ ha => vx.trans (hp.2.1 _ ha) | right _ _ x _ ih => exact fun xv _ _ _ ha => (hp.2.1 _ ha).trans xv theorem ordered_iff {p : Path α} : p.Ordered cmp ↔ p.listL.Pairwise (cmpLT cmp) ∧ p.listR.Pairwise (cmpLT cmp) ∧ ∀ x ∈ p.listL, ∀ y ∈ p.listR, cmpLT cmp x y := by induction p with | root => simp | left _ _ x _ ih | right _ _ x _ ih => ?_ all_goals rw [Ordered, and_congr_right_eq fun h => by simp [All_def, rootOrdered_iff h]; rfl] simp [List.pairwise_append, or_imp, forall_and, ih, RBNode.ordered_iff] -- FIXME: simp [and_assoc, and_left_comm, and_comm] is really slow here · exact ⟨ fun ⟨⟨hL, hR, LR⟩, xr, ⟨Lx, xR⟩, ⟨rL, rR⟩, hr⟩ => ⟨hL, ⟨⟨xr, xR⟩, hr, hR, rR⟩, Lx, fun _ ha _ hb => rL _ hb _ ha, LR⟩, fun ⟨hL, ⟨⟨xr, xR⟩, hr, hR, rR⟩, Lx, Lr, LR⟩ => ⟨⟨hL, hR, LR⟩, xr, ⟨Lx, xR⟩, ⟨fun _ ha _ hb => Lr _ hb _ ha, rR⟩, hr⟩⟩ · exact ⟨ fun ⟨⟨hL, hR, LR⟩, lx, ⟨Lx, xR⟩, ⟨lL, lR⟩, hl⟩ => ⟨⟨hL, ⟨hl, lx⟩, fun _ ha _ hb => lL _ hb _ ha, Lx⟩, hR, LR, lR, xR⟩, fun ⟨⟨hL, ⟨hl, lx⟩, Ll, Lx⟩, hR, LR, lR, xR⟩ => ⟨⟨hL, hR, LR⟩, lx, ⟨Lx, xR⟩, ⟨fun _ ha _ hb => Ll _ hb _ ha, lR⟩, hl⟩⟩ theorem zoom_zoomed₁ (e : zoom cut t path = (t', path')) : t'.OnRoot (cut · = .eq) := match t, e with | nil, rfl => trivial | node .., e => by revert e; unfold zoom; split · exact zoom_zoomed₁ · exact zoom_zoomed₁ · next H => intro e; cases e; exact H @[simp] theorem fill_toList {p : Path α} : (p.fill t).toList = p.withList t.toList := by induction p generalizing t <;> simp [*] theorem _root_.Batteries.RBNode.zoom_toList {t : RBNode α} (eq : t.zoom cut = (t', p')) : p'.withList t'.toList = t.toList := by rw [← fill_toList, ← zoom_fill eq]; rfl @[simp] theorem ins_toList {p : Path α} : (p.ins t).toList = p.withList t.toList := by match p with | .root | .left red .. | .right red .. | .left black .. | .right black .. => simp [ins, ins_toList] @[simp] theorem insertNew_toList {p : Path α} : (p.insertNew v).toList = p.withList [v] := by simp [insertNew] theorem insert_toList {p : Path α} : (p.insert t v).toList = p.withList (t.setRoot v).toList := by simp [insert]; split <;> simp [setRoot] protected theorem Balanced.insert {path : Path α} (hp : path.Balanced c₀ n₀ c n) : t.Balanced c n → ∃ c n, (path.insert t v).Balanced c n | .nil => ⟨_, hp.insertNew⟩ | .red ha hb => ⟨_, _, hp.fill (.red ha hb)⟩ | .black ha hb => ⟨_, _, hp.fill (.black ha hb)⟩ theorem Ordered.insert : ∀ {path : Path α} {t : RBNode α}, path.Ordered cmp → t.Ordered cmp → t.All (path.RootOrdered cmp) → path.RootOrdered cmp v → t.OnRoot (cmpEq cmp v) → (path.insert t v).Ordered cmp | _, nil, hp, _, _, vp, _ => hp.insertNew vp | _, node .., hp, ⟨ax, xb, ha, hb⟩, ⟨_, ap, bp⟩, vp, xv => Ordered.fill.2 ⟨hp, ⟨ax.imp xv.lt_congr_right.2, xb.imp xv.lt_congr_left.2, ha, hb⟩, vp, ap, bp⟩ theorem Ordered.erase : ∀ {path : Path α} {t : RBNode α}, path.Ordered cmp → t.Ordered cmp → t.All (path.RootOrdered cmp) → (path.erase t).Ordered cmp | _, nil, hp, ht, tp => Ordered.fill.2 ⟨hp, ht, tp⟩ | _, node .., hp, ⟨ax, xb, ha, hb⟩, ⟨_, ap, bp⟩ => hp.del (ha.append ax xb hb) (ap.append bp) theorem zoom_ins {t : RBNode α} {cmp : α → α → Ordering} : t.zoom (cmp v) path = (t', path') → path.ins (t.ins cmp v) = path'.ins (t'.setRoot v) := by unfold RBNode.ins; split <;> simp [zoom] · intro | rfl, rfl => rfl all_goals · split · exact zoom_ins · exact zoom_ins · intro | rfl => rfl theorem insertNew_eq_insert (h : zoom (cmp v) t = (nil, path)) : path.insertNew v = (t.insert cmp v).setBlack := insert_setBlack .. ▸ (zoom_ins h).symm theorem ins_eq_fill {path : Path α} {t : RBNode α} : path.Balanced c₀ n₀ c n → t.Balanced c n → path.ins t = (path.fill t).setBlack | .root, h => rfl | .redL hb H, ha | .redR ha H, hb => by unfold ins; exact ins_eq_fill H (.red ha hb) | .blackL hb H, ha => by rw [ins, fill, ← ins_eq_fill H (.black ha hb), balance1_eq ha] | .blackR ha H, hb => by rw [ins, fill, ← ins_eq_fill H (.black ha hb), balance2_eq hb] theorem zoom_insert {path : Path α} {t : RBNode α} (ht : t.Balanced c n) (H : zoom (cmp v) t = (t', path)) : (path.insert t' v).setBlack = (t.insert cmp v).setBlack := by have ⟨_, _, ht', hp'⟩ := ht.zoom .root H cases ht' with simp [insert] | nil => simp [insertNew_eq_insert H, setBlack_idem] | red hl hr => rw [← ins_eq_fill hp' (.red hl hr), insert_setBlack]; exact (zoom_ins H).symm | black hl hr => rw [← ins_eq_fill hp' (.black hl hr), insert_setBlack]; exact (zoom_ins H).symm theorem zoom_del {t : RBNode α} : t.zoom cut path = (t', path') → path.del (t.del cut) (match t with | node c .. => c | _ => red) = path'.del t'.delRoot (match t' with | node c .. => c | _ => red) := by unfold RBNode.del; split <;> simp [zoom] · intro | rfl, rfl => rfl · next c a y b => split · have IH := @zoom_del (t := a) match a with | nil => intro | rfl => rfl | node black .. | node red .. => apply IH · have IH := @zoom_del (t := b) match b with | nil => intro | rfl => rfl | node black .. | node red .. => apply IH · intro | rfl => rfl /-- Asserts that `p` holds on all elements to the left of the hole. -/ def AllL (p : α → Prop) : Path α → Prop | .root => True | .left _ parent _ _ => parent.AllL p | .right _ a x parent => a.All p ∧ p x ∧ parent.AllL p /-- Asserts that `p` holds on all elements to the right of the hole. -/ def AllR (p : α → Prop) : Path α → Prop | .root => True | .left _ parent x b => parent.AllR p ∧ p x ∧ b.All p | .right _ _ _ parent => parent.AllR p end Path theorem insert_toList_zoom {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (t', p)) : (t.insert cmp v).toList = p.withList (t'.setRoot v).toList := by rw [← setBlack_toList, ← Path.zoom_insert ht e, setBlack_toList, Path.insert_toList] theorem insert_toList_zoom_nil {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (nil, p)) : (t.insert cmp v).toList = p.withList [v] := insert_toList_zoom ht e theorem exists_insert_toList_zoom_nil {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (nil, p)) : ∃ L R, t.toList = L ++ R ∧ (t.insert cmp v).toList = L ++ v :: R := ⟨p.listL, p.listR, by simp [← zoom_toList e, insert_toList_zoom_nil ht e]⟩ theorem insert_toList_zoom_node {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (node c' l v' r, p)) : (t.insert cmp v).toList = p.withList (node c l v r).toList := insert_toList_zoom ht e
.lake/packages/batteries/Batteries/Data/RBMap/Lemmas.lean
761
765
theorem exists_insert_toList_zoom_node {t : RBNode α} (ht : Balanced t c n) (e : zoom (cmp v) t = (node c' l v' r, p)) : ∃ L R, t.toList = L ++ v' :: R ∧ (t.insert cmp v).toList = L ++ v :: R := by
refine ⟨p.listL ++ l.toList, r.toList ++ p.listR, ?_⟩ simp [← zoom_toList e, insert_toList_zoom_node ht e]
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Topology.MetricSpace.ProperSpace import Mathlib.Topology.MetricSpace.Cauchy /-! ## Boundedness in (pseudo)-metric spaces This file contains one definition, and various results on boundedness in pseudo-metric spaces. * `Metric.diam s` : The `iSup` of the distances of members of `s`. Defined in terms of `EMetric.diam`, for better handling of the case when it should be infinite. * `isBounded_iff_subset_closedBall`: a non-empty set is bounded if and only if it is is included in some closed ball * describing the cobounded filter, relating to the cocompact filter * `IsCompact.isBounded`: compact sets are bounded * `TotallyBounded.isBounded`: totally bounded sets are bounded * `isCompact_iff_isClosed_bounded`, the **Heine–Borel theorem**: in a proper space, a set is compact if and only if it is closed and bounded. * `cobounded_eq_cocompact`: in a proper space, cobounded and compact sets are the same diameter of a subset, and its relation to boundedness ## Tags metric, pseudo_metric, bounded, diameter, Heine-Borel theorem -/ open Set Filter Bornology open scoped ENNReal Uniformity Topology Pointwise universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} variable [PseudoMetricSpace α] namespace Metric #align metric.bounded Bornology.IsBounded section Bounded variable {x : α} {s t : Set α} {r : ℝ} #noalign metric.bounded_iff_is_bounded #align metric.bounded_empty Bornology.isBounded_empty #align metric.bounded_iff_mem_bounded Bornology.isBounded_iff_forall_mem #align metric.bounded.mono Bornology.IsBounded.subset /-- Closed balls are bounded -/ theorem isBounded_closedBall : IsBounded (closedBall x r) := isBounded_iff.2 ⟨r + r, fun y hy z hz => calc dist y z ≤ dist y x + dist z x := dist_triangle_right _ _ _ _ ≤ r + r := add_le_add hy hz⟩ #align metric.bounded_closed_ball Metric.isBounded_closedBall /-- Open balls are bounded -/ theorem isBounded_ball : IsBounded (ball x r) := isBounded_closedBall.subset ball_subset_closedBall #align metric.bounded_ball Metric.isBounded_ball /-- Spheres are bounded -/ theorem isBounded_sphere : IsBounded (sphere x r) := isBounded_closedBall.subset sphere_subset_closedBall #align metric.bounded_sphere Metric.isBounded_sphere /-- Given a point, a bounded subset is included in some ball around this point -/ theorem isBounded_iff_subset_closedBall (c : α) : IsBounded s ↔ ∃ r, s ⊆ closedBall c r := ⟨fun h ↦ (isBounded_iff.1 (h.insert c)).imp fun _r hr _x hx ↦ hr (.inr hx) (mem_insert _ _), fun ⟨_r, hr⟩ ↦ isBounded_closedBall.subset hr⟩ #align metric.bounded_iff_subset_ball Metric.isBounded_iff_subset_closedBall theorem _root_.Bornology.IsBounded.subset_closedBall (h : IsBounded s) (c : α) : ∃ r, s ⊆ closedBall c r := (isBounded_iff_subset_closedBall c).1 h #align metric.bounded.subset_ball Bornology.IsBounded.subset_closedBall theorem _root_.Bornology.IsBounded.subset_ball_lt (h : IsBounded s) (a : ℝ) (c : α) : ∃ r, a < r ∧ s ⊆ ball c r := let ⟨r, hr⟩ := h.subset_closedBall c ⟨max r a + 1, (le_max_right _ _).trans_lt (lt_add_one _), hr.trans <| closedBall_subset_ball <| (le_max_left _ _).trans_lt (lt_add_one _)⟩ theorem _root_.Bornology.IsBounded.subset_ball (h : IsBounded s) (c : α) : ∃ r, s ⊆ ball c r := (h.subset_ball_lt 0 c).imp fun _ ↦ And.right theorem isBounded_iff_subset_ball (c : α) : IsBounded s ↔ ∃ r, s ⊆ ball c r := ⟨(IsBounded.subset_ball · c), fun ⟨_r, hr⟩ ↦ isBounded_ball.subset hr⟩ theorem _root_.Bornology.IsBounded.subset_closedBall_lt (h : IsBounded s) (a : ℝ) (c : α) : ∃ r, a < r ∧ s ⊆ closedBall c r := let ⟨r, har, hr⟩ := h.subset_ball_lt a c ⟨r, har, hr.trans ball_subset_closedBall⟩ #align metric.bounded.subset_ball_lt Bornology.IsBounded.subset_closedBall_lt theorem isBounded_closure_of_isBounded (h : IsBounded s) : IsBounded (closure s) := let ⟨C, h⟩ := isBounded_iff.1 h isBounded_iff.2 ⟨C, fun _a ha _b hb => isClosed_Iic.closure_subset <| map_mem_closure₂ continuous_dist ha hb h⟩ #align metric.bounded_closure_of_bounded Metric.isBounded_closure_of_isBounded protected theorem _root_.Bornology.IsBounded.closure (h : IsBounded s) : IsBounded (closure s) := isBounded_closure_of_isBounded h #align metric.bounded.closure Bornology.IsBounded.closure @[simp] theorem isBounded_closure_iff : IsBounded (closure s) ↔ IsBounded s := ⟨fun h => h.subset subset_closure, fun h => h.closure⟩ #align metric.bounded_closure_iff Metric.isBounded_closure_iff #align metric.bounded_union Bornology.isBounded_union #align metric.bounded.union Bornology.IsBounded.union #align metric.bounded_bUnion Bornology.isBounded_biUnion #align metric.bounded.prod Bornology.IsBounded.prod theorem hasBasis_cobounded_compl_closedBall (c : α) : (cobounded α).HasBasis (fun _ ↦ True) (fun r ↦ (closedBall c r)ᶜ) := ⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_closedBall c).trans <| by simp⟩ theorem hasBasis_cobounded_compl_ball (c : α) : (cobounded α).HasBasis (fun _ ↦ True) (fun r ↦ (ball c r)ᶜ) := ⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_ball c).trans <| by simp⟩ @[simp] theorem comap_dist_right_atTop (c : α) : comap (dist · c) atTop = cobounded α := (atTop_basis.comap _).eq_of_same_basis <| by simpa only [compl_def, mem_ball, not_lt] using hasBasis_cobounded_compl_ball c @[simp] theorem comap_dist_left_atTop (c : α) : comap (dist c) atTop = cobounded α := by simpa only [dist_comm _ c] using comap_dist_right_atTop c @[simp] theorem tendsto_dist_right_atTop_iff (c : α) {f : β → α} {l : Filter β} : Tendsto (fun x ↦ dist (f x) c) l atTop ↔ Tendsto f l (cobounded α) := by rw [← comap_dist_right_atTop c, tendsto_comap_iff, Function.comp_def] @[simp] theorem tendsto_dist_left_atTop_iff (c : α) {f : β → α} {l : Filter β} : Tendsto (fun x ↦ dist c (f x)) l atTop ↔ Tendsto f l (cobounded α) := by simp only [dist_comm c, tendsto_dist_right_atTop_iff] theorem tendsto_dist_right_cobounded_atTop (c : α) : Tendsto (dist · c) (cobounded α) atTop := tendsto_iff_comap.2 (comap_dist_right_atTop c).ge theorem tendsto_dist_left_cobounded_atTop (c : α) : Tendsto (dist c) (cobounded α) atTop := tendsto_iff_comap.2 (comap_dist_left_atTop c).ge /-- A totally bounded set is bounded -/ theorem _root_.TotallyBounded.isBounded {s : Set α} (h : TotallyBounded s) : IsBounded s := -- We cover the totally bounded set by finitely many balls of radius 1, -- and then argue that a finite union of bounded sets is bounded let ⟨_t, fint, subs⟩ := (totallyBounded_iff.mp h) 1 zero_lt_one ((isBounded_biUnion fint).2 fun _ _ => isBounded_ball).subset subs #align totally_bounded.bounded TotallyBounded.isBounded /-- A compact set is bounded -/ theorem _root_.IsCompact.isBounded {s : Set α} (h : IsCompact s) : IsBounded s := -- A compact set is totally bounded, thus bounded h.totallyBounded.isBounded #align is_compact.bounded IsCompact.isBounded #align metric.bounded_of_finite Set.Finite.isBounded #align set.finite.bounded Set.Finite.isBounded #align metric.bounded_singleton Bornology.isBounded_singleton theorem cobounded_le_cocompact : cobounded α ≤ cocompact α := hasBasis_cocompact.ge_iff.2 fun _s hs ↦ hs.isBounded #align comap_dist_right_at_top_le_cocompact Metric.cobounded_le_cocompactₓ #align comap_dist_left_at_top_le_cocompact Metric.cobounded_le_cocompactₓ theorem isCobounded_iff_closedBall_compl_subset {s : Set α} (c : α) : IsCobounded s ↔ ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := by rw [← isBounded_compl_iff, isBounded_iff_subset_closedBall c] apply exists_congr intro r rw [compl_subset_comm] theorem _root_.Bornology.IsCobounded.closedBall_compl_subset {s : Set α} (hs : IsCobounded s) (c : α) : ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := (isCobounded_iff_closedBall_compl_subset c).mp hs theorem closedBall_compl_subset_of_mem_cocompact {s : Set α} (hs : s ∈ cocompact α) (c : α) : ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := IsCobounded.closedBall_compl_subset (cobounded_le_cocompact hs) c theorem mem_cocompact_of_closedBall_compl_subset [ProperSpace α] (c : α) (h : ∃ r, (closedBall c r)ᶜ ⊆ s) : s ∈ cocompact α := by rcases h with ⟨r, h⟩ rw [Filter.mem_cocompact] exact ⟨closedBall c r, isCompact_closedBall c r, h⟩ theorem mem_cocompact_iff_closedBall_compl_subset [ProperSpace α] (c : α) : s ∈ cocompact α ↔ ∃ r, (closedBall c r)ᶜ ⊆ s := ⟨(closedBall_compl_subset_of_mem_cocompact · _), mem_cocompact_of_closedBall_compl_subset _⟩ /-- Characterization of the boundedness of the range of a function -/ theorem isBounded_range_iff {f : β → α} : IsBounded (range f) ↔ ∃ C, ∀ x y, dist (f x) (f y) ≤ C := isBounded_iff.trans <| by simp only [forall_mem_range] #align metric.bounded_range_iff Metric.isBounded_range_iff theorem isBounded_image_iff {f : β → α} {s : Set β} : IsBounded (f '' s) ↔ ∃ C, ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ C := isBounded_iff.trans <| by simp only [forall_mem_image] theorem isBounded_range_of_tendsto_cofinite_uniformity {f : β → α} (hf : Tendsto (Prod.map f f) (.cofinite ×ˢ .cofinite) (𝓤 α)) : IsBounded (range f) := by rcases (hasBasis_cofinite.prod_self.tendsto_iff uniformity_basis_dist).1 hf 1 zero_lt_one with ⟨s, hsf, hs1⟩ rw [← image_union_image_compl_eq_range] refine (hsf.image f).isBounded.union (isBounded_image_iff.2 ⟨1, fun x hx y hy ↦ ?_⟩) exact le_of_lt (hs1 (x, y) ⟨hx, hy⟩) #align metric.bounded_range_of_tendsto_cofinite_uniformity Metric.isBounded_range_of_tendsto_cofinite_uniformity theorem isBounded_range_of_cauchy_map_cofinite {f : β → α} (hf : Cauchy (map f cofinite)) : IsBounded (range f) := isBounded_range_of_tendsto_cofinite_uniformity <| (cauchy_map_iff.1 hf).2 #align metric.bounded_range_of_cauchy_map_cofinite Metric.isBounded_range_of_cauchy_map_cofinite theorem _root_.CauchySeq.isBounded_range {f : ℕ → α} (hf : CauchySeq f) : IsBounded (range f) := isBounded_range_of_cauchy_map_cofinite <| by rwa [Nat.cofinite_eq_atTop] #align cauchy_seq.bounded_range CauchySeq.isBounded_range theorem isBounded_range_of_tendsto_cofinite {f : β → α} {a : α} (hf : Tendsto f cofinite (𝓝 a)) : IsBounded (range f) := isBounded_range_of_tendsto_cofinite_uniformity <| (hf.prod_map hf).mono_right <| nhds_prod_eq.symm.trans_le (nhds_le_uniformity a) #align metric.bounded_range_of_tendsto_cofinite Metric.isBounded_range_of_tendsto_cofinite /-- In a compact space, all sets are bounded -/ theorem isBounded_of_compactSpace [CompactSpace α] : IsBounded s := isCompact_univ.isBounded.subset (subset_univ _) #align metric.bounded_of_compact_space Metric.isBounded_of_compactSpace theorem isBounded_range_of_tendsto (u : ℕ → α) {x : α} (hu : Tendsto u atTop (𝓝 x)) : IsBounded (range u) := hu.cauchySeq.isBounded_range #align metric.bounded_range_of_tendsto Metric.isBounded_range_of_tendsto theorem disjoint_nhds_cobounded (x : α) : Disjoint (𝓝 x) (cobounded α) := disjoint_of_disjoint_of_mem disjoint_compl_right (ball_mem_nhds _ one_pos) isBounded_ball theorem disjoint_cobounded_nhds (x : α) : Disjoint (cobounded α) (𝓝 x) := (disjoint_nhds_cobounded x).symm theorem disjoint_nhdsSet_cobounded {s : Set α} (hs : IsCompact s) : Disjoint (𝓝ˢ s) (cobounded α) := hs.disjoint_nhdsSet_left.2 fun _ _ ↦ disjoint_nhds_cobounded _ theorem disjoint_cobounded_nhdsSet {s : Set α} (hs : IsCompact s) : Disjoint (cobounded α) (𝓝ˢ s) := (disjoint_nhdsSet_cobounded hs).symm theorem exists_isBounded_image_of_tendsto {α β : Type*} [PseudoMetricSpace β] {l : Filter α} {f : α → β} {x : β} (hf : Tendsto f l (𝓝 x)) : ∃ s ∈ l, IsBounded (f '' s) := (l.basis_sets.map f).disjoint_iff_left.mp <| (disjoint_nhds_cobounded x).mono_left hf /-- If a function is continuous within a set `s` at every point of a compact set `k`, then it is bounded on some open neighborhood of `k` in `s`. -/ theorem exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt [TopologicalSpace β] {k s : Set β} {f : β → α} (hk : IsCompact k) (hf : ∀ x ∈ k, ContinuousWithinAt f s x) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' (t ∩ s)) := by have : Disjoint (𝓝ˢ k ⊓ 𝓟 s) (comap f (cobounded α)) := by rw [disjoint_assoc, inf_comm, hk.disjoint_nhdsSet_left] exact fun x hx ↦ disjoint_left_comm.2 <| tendsto_comap.disjoint (disjoint_cobounded_nhds _) (hf x hx) rcases ((((hasBasis_nhdsSet _).inf_principal _)).disjoint_iff ((basis_sets _).comap _)).1 this with ⟨U, ⟨hUo, hkU⟩, t, ht, hd⟩ refine ⟨U, hkU, hUo, (isBounded_compl_iff.2 ht).subset ?_⟩ rwa [image_subset_iff, preimage_compl, subset_compl_iff_disjoint_right] #align metric.exists_is_open_bounded_image_inter_of_is_compact_of_forall_continuous_within_at Metric.exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt /-- If a function is continuous at every point of a compact set `k`, then it is bounded on some open neighborhood of `k`. -/
Mathlib/Topology/MetricSpace/Bounded.lean
278
283
theorem exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt [TopologicalSpace β] {k : Set β} {f : β → α} (hk : IsCompact k) (hf : ∀ x ∈ k, ContinuousAt f x) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' t) := by
simp_rw [← continuousWithinAt_univ] at hf simpa only [inter_univ] using exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk hf
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine import Mathlib.Tactic.IntervalCases #align_import geometry.euclidean.triangle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Triangles This file proves basic geometrical results about distances and angles in (possibly degenerate) triangles in real inner product spaces and Euclidean affine spaces. More specialized results, and results developed for simplices in general rather than just for triangles, are in separate files. Definitions and results that make sense in more general affine spaces rather than just in the Euclidean case go under `LinearAlgebra.AffineSpace`. ## Implementation notes Results in this file are generally given in a form with only those non-degeneracy conditions needed for the particular result, rather than requiring affine independence of the points of a triangle unnecessarily. ## References * https://en.wikipedia.org/wiki/Law_of_cosines * https://en.wikipedia.org/wiki/Pons_asinorum * https://en.wikipedia.org/wiki/Sum_of_angles_of_a_triangle -/ noncomputable section open scoped Classical open scoped Real open scoped RealInnerProductSpace namespace InnerProductGeometry /-! ### Geometrical results on triangles in real inner product spaces This section develops some results on (possibly degenerate) triangles in real inner product spaces, where those definitions and results can most conveniently be developed in terms of vectors and then used to deduce corresponding results for Euclidean affine spaces. -/ variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- **Law of cosines** (cosine rule), vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle (x y : V) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - 2 * ‖x‖ * ‖y‖ * Real.cos (angle x y) := by rw [show 2 * ‖x‖ * ‖y‖ * Real.cos (angle x y) = 2 * (Real.cos (angle x y) * (‖x‖ * ‖y‖)) by ring, cos_angle_mul_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, real_inner_sub_sub_self, sub_add_eq_add_sub] #align inner_product_geometry.norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle InnerProductGeometry.norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle /-- **Pons asinorum**, vector angle form. -/ theorem angle_sub_eq_angle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : angle x (x - y) = angle y (y - x) := by refine Real.injOn_cos ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ?_ rw [cos_angle, cos_angle, h, ← neg_sub, norm_neg, neg_sub, inner_sub_right, inner_sub_right, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, h, real_inner_comm x y] #align inner_product_geometry.angle_sub_eq_angle_sub_rev_of_norm_eq InnerProductGeometry.angle_sub_eq_angle_sub_rev_of_norm_eq /-- **Converse of pons asinorum**, vector angle form. -/ theorem norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi {x y : V} (h : angle x (x - y) = angle y (y - x)) (hpi : angle x y ≠ π) : ‖x‖ = ‖y‖ := by replace h := Real.arccos_injOn (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x (x - y))) (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one y (y - x))) h by_cases hxy : x = y · rw [hxy] · rw [← norm_neg (y - x), neg_sub, mul_comm, mul_comm ‖y‖, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev, mul_inv_rev, ← mul_assoc, ← mul_assoc] at h replace h := mul_right_cancel₀ (inv_ne_zero fun hz => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 hz))) h rw [inner_sub_right, inner_sub_right, real_inner_comm x y, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, mul_sub_right_distrib, mul_sub_right_distrib, mul_self_mul_inv, mul_self_mul_inv, sub_eq_sub_iff_sub_eq_sub, ← mul_sub_left_distrib] at h by_cases hx0 : x = 0 · rw [hx0, norm_zero, inner_zero_left, zero_mul, zero_sub, neg_eq_zero] at h rw [hx0, norm_zero, h] · by_cases hy0 : y = 0 · rw [hy0, norm_zero, inner_zero_right, zero_mul, sub_zero] at h rw [hy0, norm_zero, h] · rw [inv_sub_inv (fun hz => hx0 (norm_eq_zero.1 hz)) fun hz => hy0 (norm_eq_zero.1 hz), ← neg_sub, ← mul_div_assoc, mul_comm, mul_div_assoc, ← mul_neg_one] at h symm by_contra hyx replace h := (mul_left_cancel₀ (sub_ne_zero_of_ne hyx) h).symm rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, ← angle_eq_pi_iff] at h exact hpi h #align inner_product_geometry.norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi InnerProductGeometry.norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi /-- The cosine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.cos (angle x (x - y) + angle y (y - x)) = -Real.cos (angle x y) := by by_cases hxy : x = y · rw [hxy, angle_self hy] simp · rw [Real.cos_add, cos_angle, cos_angle, cos_angle] have hxn : ‖x‖ ≠ 0 := fun h => hx (norm_eq_zero.1 h) have hyn : ‖y‖ ≠ 0 := fun h => hy (norm_eq_zero.1 h) have hxyn : ‖x - y‖ ≠ 0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h)) apply mul_right_cancel₀ hxn apply mul_right_cancel₀ hyn apply mul_right_cancel₀ hxyn apply mul_right_cancel₀ hxyn have H1 : Real.sin (angle x (x - y)) * Real.sin (angle y (y - x)) * ‖x‖ * ‖y‖ * ‖x - y‖ * ‖x - y‖ = Real.sin (angle x (x - y)) * (‖x‖ * ‖x - y‖) * (Real.sin (angle y (y - x)) * (‖y‖ * ‖x - y‖)) := by ring have H2 : ⟪x, x⟫ * (⟪x, x⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪y, y⟫)) - (⟪x, x⟫ - ⟪x, y⟫) * (⟪x, x⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring have H3 : ⟪y, y⟫ * (⟪y, y⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪x, x⟫)) - (⟪y, y⟫ - ⟪x, y⟫) * (⟪y, y⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring rw [mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y, sin_angle_mul_norm_mul_norm, norm_sub_rev y x, inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H2, H3, Real.mul_self_sqrt (sub_nonneg_of_le (real_inner_mul_inner_self_le x y)), real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two] field_simp [hxn, hyn, hxyn] ring #align inner_product_geometry.cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle InnerProductGeometry.cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle /-- The sine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem sin_angle_sub_add_angle_sub_rev_eq_sin_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.sin (angle x (x - y) + angle y (y - x)) = Real.sin (angle x y) := by by_cases hxy : x = y · rw [hxy, angle_self hy] simp · rw [Real.sin_add, cos_angle, cos_angle] have hxn : ‖x‖ ≠ 0 := fun h => hx (norm_eq_zero.1 h) have hyn : ‖y‖ ≠ 0 := fun h => hy (norm_eq_zero.1 h) have hxyn : ‖x - y‖ ≠ 0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h)) apply mul_right_cancel₀ hxn apply mul_right_cancel₀ hyn apply mul_right_cancel₀ hxyn apply mul_right_cancel₀ hxyn have H1 : Real.sin (angle x (x - y)) * (⟪y, y - x⟫ / (‖y‖ * ‖y - x‖)) * ‖x‖ * ‖y‖ * ‖x - y‖ = Real.sin (angle x (x - y)) * (‖x‖ * ‖x - y‖) * (⟪y, y - x⟫ / (‖y‖ * ‖y - x‖)) * ‖y‖ := by ring have H2 : ⟪x, x - y⟫ / (‖x‖ * ‖y - x‖) * Real.sin (angle y (y - x)) * ‖x‖ * ‖y‖ * ‖y - x‖ = ⟪x, x - y⟫ / (‖x‖ * ‖y - x‖) * (Real.sin (angle y (y - x)) * (‖y‖ * ‖y - x‖)) * ‖x‖ := by ring have H3 : ⟪x, x⟫ * (⟪x, x⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪y, y⟫)) - (⟪x, x⟫ - ⟪x, y⟫) * (⟪x, x⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring have H4 : ⟪y, y⟫ * (⟪y, y⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪x, x⟫)) - (⟪y, y⟫ - ⟪x, y⟫) * (⟪y, y⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring rw [right_distrib, right_distrib, right_distrib, right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y, H2, sin_angle_mul_norm_mul_norm, norm_sub_rev y x, mul_assoc (Real.sin (angle x y)), sin_angle_mul_norm_mul_norm, inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H3, H4, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two] field_simp [hxn, hyn, hxyn] ring #align inner_product_geometry.sin_angle_sub_add_angle_sub_rev_eq_sin_angle InnerProductGeometry.sin_angle_sub_add_angle_sub_rev_eq_sin_angle /-- The cosine of the sum of the angles of a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem cos_angle_add_angle_sub_add_angle_sub_eq_neg_one {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.cos (angle x y + angle x (x - y) + angle y (y - x)) = -1 := by rw [add_assoc, Real.cos_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy, sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy, mul_neg, ← neg_add', add_comm, ← sq, ← sq, Real.sin_sq_add_cos_sq] #align inner_product_geometry.cos_angle_add_angle_sub_add_angle_sub_eq_neg_one InnerProductGeometry.cos_angle_add_angle_sub_add_angle_sub_eq_neg_one /-- The sine of the sum of the angles of a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/
Mathlib/Geometry/Euclidean/Triangle.lean
198
202
theorem sin_angle_add_angle_sub_add_angle_sub_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.sin (angle x y + angle x (x - y) + angle y (y - x)) = 0 := by
rw [add_assoc, Real.sin_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy, sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy] ring
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import Mathlib.MeasureTheory.Function.LpOrder #align_import measure_theory.function.l1_space from "leanprover-community/mathlib"@"ccdbfb6e5614667af5aa3ab2d50885e0ef44a46f" /-! # Integrable functions and `L¹` space In the first part of this file, the predicate `Integrable` is defined and basic properties of integrable functions are proved. Such a predicate is already available under the name `Memℒp 1`. We give a direct definition which is easier to use, and show that it is equivalent to `Memℒp 1` In the second part, we establish an API between `Integrable` and the space `L¹` of equivalence classes of integrable functions, already defined as a special case of `L^p` spaces for `p = 1`. ## Notation * `α →₁[μ] β` is the type of `L¹` space, where `α` is a `MeasureSpace` and `β` is a `NormedAddCommGroup` with a `SecondCountableTopology`. `f : α →ₘ β` is a "function" in `L¹`. In comments, `[f]` is also used to denote an `L¹` function. `₁` can be typed as `\1`. ## Main definitions * Let `f : α → β` be a function, where `α` is a `MeasureSpace` and `β` a `NormedAddCommGroup`. Then `HasFiniteIntegral f` means `(∫⁻ a, ‖f a‖₊) < ∞`. * If `β` is moreover a `MeasurableSpace` then `f` is called `Integrable` if `f` is `Measurable` and `HasFiniteIntegral f` holds. ## Implementation notes To prove something for an arbitrary integrable function, a useful theorem is `Integrable.induction` in the file `SetIntegral`. ## Tags integrable, function space, l1 -/ noncomputable section open scoped Classical open Topology ENNReal MeasureTheory NNReal open Set Filter TopologicalSpace ENNReal EMetric MeasureTheory variable {α β γ δ : Type*} {m : MeasurableSpace α} {μ ν : Measure α} [MeasurableSpace δ] variable [NormedAddCommGroup β] variable [NormedAddCommGroup γ] namespace MeasureTheory /-! ### Some results about the Lebesgue integral involving a normed group -/ theorem lintegral_nnnorm_eq_lintegral_edist (f : α → β) : ∫⁻ a, ‖f a‖₊ ∂μ = ∫⁻ a, edist (f a) 0 ∂μ := by simp only [edist_eq_coe_nnnorm] #align measure_theory.lintegral_nnnorm_eq_lintegral_edist MeasureTheory.lintegral_nnnorm_eq_lintegral_edist theorem lintegral_norm_eq_lintegral_edist (f : α → β) : ∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ = ∫⁻ a, edist (f a) 0 ∂μ := by simp only [ofReal_norm_eq_coe_nnnorm, edist_eq_coe_nnnorm] #align measure_theory.lintegral_norm_eq_lintegral_edist MeasureTheory.lintegral_norm_eq_lintegral_edist
Mathlib/MeasureTheory/Function/L1Space.lean
75
80
theorem lintegral_edist_triangle {f g h : α → β} (hf : AEStronglyMeasurable f μ) (hh : AEStronglyMeasurable h μ) : (∫⁻ a, edist (f a) (g a) ∂μ) ≤ (∫⁻ a, edist (f a) (h a) ∂μ) + ∫⁻ a, edist (g a) (h a) ∂μ := by
rw [← lintegral_add_left' (hf.edist hh)] refine lintegral_mono fun a => ?_ apply edist_triangle_right
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Order.LiminfLimsup import Mathlib.Topology.Instances.Rat import Mathlib.Topology.MetricSpace.Algebra import Mathlib.Topology.MetricSpace.IsometricSMul import Mathlib.Topology.Sequences #align_import analysis.normed.group.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## TODO This file is huge; move material into separate files, such as `Mathlib/Analysis/Normed/Group/Lemmas.lean`. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 𝕜 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ #align has_norm Norm /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 #align has_nnnorm NNNorm export Norm (norm) export NNNorm (nnnorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_group SeminormedAddGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_group SeminormedGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_group NormedAddGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_group NormedGroup /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_comm_group SeminormedAddCommGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_comm_group SeminormedCommGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_comm_group NormedAddCommGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_comm_group NormedCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } #align normed_group.to_seminormed_group NormedGroup.toSeminormedGroup #align normed_add_group.to_seminormed_add_group NormedAddGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_seminormed_comm_group NormedCommGroup.toSeminormedCommGroup #align normed_add_comm_group.to_seminormed_add_comm_group NormedAddCommGroup.toSeminormedAddCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } #align seminormed_comm_group.to_seminormed_group SeminormedCommGroup.toSeminormedGroup #align seminormed_add_comm_group.to_seminormed_add_group SeminormedAddCommGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_normed_group NormedCommGroup.toNormedGroup #align normed_add_comm_group.to_normed_add_group NormedAddCommGroup.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] def NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| by exact (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- Porting note: the `rwa` no longer worked, but it was easy enough to provide the term. -- however, notice that if you make `x` and `y` accessible, then the following does work: -- `have := ‹SeminormedGroup E›.dist_eq x y; rwa [← this]`, so I'm not sure why the `rwa` -- was broken. #align normed_group.of_separation NormedGroup.ofSeparation #align normed_add_group.of_separation NormedAddGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] def NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } #align normed_comm_group.of_separation NormedCommGroup.ofSeparation #align normed_add_comm_group.of_separation NormedAddCommGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant distance."] def SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y #align seminormed_group.of_mul_dist SeminormedGroup.ofMulDist #align seminormed_add_group.of_add_dist SeminormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ #align seminormed_group.of_mul_dist' SeminormedGroup.ofMulDist' #align seminormed_add_group.of_add_dist' SeminormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist SeminormedCommGroup.ofMulDist #align seminormed_add_comm_group.of_add_dist SeminormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist' SeminormedCommGroup.ofMulDist' #align seminormed_add_comm_group.of_add_dist' SeminormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant distance."] def NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist NormedGroup.ofMulDist #align normed_add_group.of_add_dist NormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist' NormedGroup.ofMulDist' #align normed_add_group.of_add_dist' NormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist NormedCommGroup.ofMulDist #align normed_add_comm_group.of_add_dist NormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist' NormedCommGroup.ofMulDist' #align normed_add_comm_group.of_add_dist' NormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq x y := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f edist_dist x y := by exact ENNReal.coe_nnreal_eq _ -- Porting note: how did `mathlib3` solve this automatically? #align group_seminorm.to_seminormed_group GroupSeminorm.toSeminormedGroup #align add_group_seminorm.to_seminormed_add_group AddGroupSeminorm.toSeminormedAddGroup -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } #align group_seminorm.to_seminormed_comm_group GroupSeminorm.toSeminormedCommGroup #align add_group_seminorm.to_seminormed_add_comm_group AddGroupSeminorm.toSeminormedAddCommGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } #align group_norm.to_normed_group GroupNorm.toNormedGroup #align add_group_norm.to_normed_add_group AddGroupNorm.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } #align group_norm.to_normed_comm_group GroupNorm.toNormedCommGroup #align add_group_norm.to_normed_add_comm_group AddGroupNorm.toNormedAddCommGroup instance PUnit.normedAddCommGroup : NormedAddCommGroup PUnit where norm := Function.const _ 0 dist_eq _ _ := rfl @[simp] theorem PUnit.norm_eq_zero (r : PUnit) : ‖r‖ = 0 := rfl #align punit.norm_eq_zero PUnit.norm_eq_zero section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ #align dist_eq_norm_div dist_eq_norm_div #align dist_eq_norm_sub dist_eq_norm_sub @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] #align dist_eq_norm_div' dist_eq_norm_div' #align dist_eq_norm_sub' dist_eq_norm_sub' alias dist_eq_norm := dist_eq_norm_sub #align dist_eq_norm dist_eq_norm alias dist_eq_norm' := dist_eq_norm_sub' #align dist_eq_norm' dist_eq_norm' @[to_additive] instance NormedGroup.to_isometricSMul_right : IsometricSMul Eᵐᵒᵖ E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_right NormedGroup.to_isometricSMul_right #align normed_add_group.to_has_isometric_vadd_right NormedAddGroup.to_isometricVAdd_right @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] #align dist_one_right dist_one_right #align dist_zero_right dist_zero_right @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive (attr := simp)] theorem dist_one_left : dist (1 : E) = norm := funext fun a => by rw [dist_comm, dist_one_right] #align dist_one_left dist_one_left #align dist_zero_left dist_zero_left @[to_additive] theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right] #align isometry.norm_map_of_map_one Isometry.norm_map_of_map_one #align isometry.norm_map_of_map_zero Isometry.norm_map_of_map_zero @[to_additive (attr := simp) comap_norm_atTop] theorem comap_norm_atTop' : comap norm atTop = cobounded E := by simpa only [dist_one_right] using comap_dist_right_atTop (1 : E) @[to_additive Filter.HasBasis.cobounded_of_norm] lemma Filter.HasBasis.cobounded_of_norm' {ι : Sort*} {p : ι → Prop} {s : ι → Set ℝ} (h : HasBasis atTop p s) : HasBasis (cobounded E) p fun i ↦ norm ⁻¹' s i := comap_norm_atTop' (E := E) ▸ h.comap _ @[to_additive Filter.hasBasis_cobounded_norm] lemma Filter.hasBasis_cobounded_norm' : HasBasis (cobounded E) (fun _ ↦ True) ({x | · ≤ ‖x‖}) := atTop_basis.cobounded_of_norm' @[to_additive (attr := simp) tendsto_norm_atTop_iff_cobounded] theorem tendsto_norm_atTop_iff_cobounded' {f : α → E} {l : Filter α} : Tendsto (‖f ·‖) l atTop ↔ Tendsto f l (cobounded E) := by rw [← comap_norm_atTop', tendsto_comap_iff]; rfl @[to_additive tendsto_norm_cobounded_atTop] theorem tendsto_norm_cobounded_atTop' : Tendsto norm (cobounded E) atTop := tendsto_norm_atTop_iff_cobounded'.2 tendsto_id @[to_additive eventually_cobounded_le_norm] lemma eventually_cobounded_le_norm' (a : ℝ) : ∀ᶠ x in cobounded E, a ≤ ‖x‖ := tendsto_norm_cobounded_atTop'.eventually_ge_atTop a @[to_additive tendsto_norm_cocompact_atTop] theorem tendsto_norm_cocompact_atTop' [ProperSpace E] : Tendsto norm (cocompact E) atTop := cobounded_eq_cocompact (α := E) ▸ tendsto_norm_cobounded_atTop' #align tendsto_norm_cocompact_at_top' tendsto_norm_cocompact_atTop' #align tendsto_norm_cocompact_at_top tendsto_norm_cocompact_atTop @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b #align norm_div_rev norm_div_rev #align norm_sub_rev norm_sub_rev @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a #align norm_inv' norm_inv' #align norm_neg norm_neg open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] @[to_additive (attr := simp)] theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul] #align dist_mul_self_right dist_mul_self_right #align dist_add_self_right dist_add_self_right @[to_additive (attr := simp)] theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by rw [dist_comm, dist_mul_self_right] #align dist_mul_self_left dist_mul_self_left #align dist_add_self_left dist_add_self_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by rw [← dist_mul_right _ _ b, div_mul_cancel] #align dist_div_eq_dist_mul_left dist_div_eq_dist_mul_left #align dist_sub_eq_dist_add_left dist_sub_eq_dist_add_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by rw [← dist_mul_right _ _ c, div_mul_cancel] #align dist_div_eq_dist_mul_right dist_div_eq_dist_mul_right #align dist_sub_eq_dist_add_right dist_sub_eq_dist_add_right @[to_additive (attr := simp)] lemma Filter.inv_cobounded : (cobounded E)⁻¹ = cobounded E := by simp only [← comap_norm_atTop', ← Filter.comap_inv, comap_comap, (· ∘ ·), norm_inv'] /-- In a (semi)normed group, inversion `x ↦ x⁻¹` tends to infinity at infinity. -/ @[to_additive "In a (semi)normed group, negation `x ↦ -x` tends to infinity at infinity."] theorem Filter.tendsto_inv_cobounded : Tendsto Inv.inv (cobounded E) (cobounded E) := inv_cobounded.le #align filter.tendsto_inv_cobounded Filter.tendsto_inv_cobounded #align filter.tendsto_neg_cobounded Filter.tendsto_neg_cobounded /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ #align norm_mul_le' norm_mul_le' #align norm_add_le norm_add_le @[to_additive] theorem norm_mul_le_of_le (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ #align norm_mul_le_of_le norm_mul_le_of_le #align norm_add_le_of_le norm_add_le_of_le @[to_additive norm_add₃_le] theorem norm_mul₃_le (a b c : E) : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le (norm_mul_le' _ _) le_rfl #align norm_mul₃_le norm_mul₃_le #align norm_add₃_le norm_add₃_le @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg]
Mathlib/Analysis/Normed/Group/Basic.lean
552
554
theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by
rw [← dist_one_right] exact dist_nonneg
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Order.MinMax import Mathlib.Data.Set.Subsingleton import Mathlib.Tactic.Says #align_import data.set.intervals.basic from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c" /-! # Intervals In any preorder `α`, we define intervals (which on each side can be either infinite, open, or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. This file contains these definitions, and basic facts on inclusion, intersection, difference of intervals (where the precise statements may depend on the properties of the order, in particular for some statements it should be `LinearOrder` or `DenselyOrdered`). TODO: This is just the beginning; a lot of rules are missing -/ open Function open OrderDual (toDual ofDual) variable {α β : Type*} namespace Set section Preorder variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α} /-- Left-open right-open interval -/ def Ioo (a b : α) := { x | a < x ∧ x < b } #align set.Ioo Set.Ioo /-- Left-closed right-open interval -/ def Ico (a b : α) := { x | a ≤ x ∧ x < b } #align set.Ico Set.Ico /-- Left-infinite right-open interval -/ def Iio (a : α) := { x | x < a } #align set.Iio Set.Iio /-- Left-closed right-closed interval -/ def Icc (a b : α) := { x | a ≤ x ∧ x ≤ b } #align set.Icc Set.Icc /-- Left-infinite right-closed interval -/ def Iic (b : α) := { x | x ≤ b } #align set.Iic Set.Iic /-- Left-open right-closed interval -/ def Ioc (a b : α) := { x | a < x ∧ x ≤ b } #align set.Ioc Set.Ioc /-- Left-closed right-infinite interval -/ def Ici (a : α) := { x | a ≤ x } #align set.Ici Set.Ici /-- Left-open right-infinite interval -/ def Ioi (a : α) := { x | a < x } #align set.Ioi Set.Ioi theorem Ioo_def (a b : α) : { x | a < x ∧ x < b } = Ioo a b := rfl #align set.Ioo_def Set.Ioo_def theorem Ico_def (a b : α) : { x | a ≤ x ∧ x < b } = Ico a b := rfl #align set.Ico_def Set.Ico_def theorem Iio_def (a : α) : { x | x < a } = Iio a := rfl #align set.Iio_def Set.Iio_def theorem Icc_def (a b : α) : { x | a ≤ x ∧ x ≤ b } = Icc a b := rfl #align set.Icc_def Set.Icc_def theorem Iic_def (b : α) : { x | x ≤ b } = Iic b := rfl #align set.Iic_def Set.Iic_def theorem Ioc_def (a b : α) : { x | a < x ∧ x ≤ b } = Ioc a b := rfl #align set.Ioc_def Set.Ioc_def theorem Ici_def (a : α) : { x | a ≤ x } = Ici a := rfl #align set.Ici_def Set.Ici_def theorem Ioi_def (a : α) : { x | a < x } = Ioi a := rfl #align set.Ioi_def Set.Ioi_def @[simp] theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := Iff.rfl #align set.mem_Ioo Set.mem_Ioo @[simp] theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := Iff.rfl #align set.mem_Ico Set.mem_Ico @[simp] theorem mem_Iio : x ∈ Iio b ↔ x < b := Iff.rfl #align set.mem_Iio Set.mem_Iio @[simp] theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := Iff.rfl #align set.mem_Icc Set.mem_Icc @[simp] theorem mem_Iic : x ∈ Iic b ↔ x ≤ b := Iff.rfl #align set.mem_Iic Set.mem_Iic @[simp] theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := Iff.rfl #align set.mem_Ioc Set.mem_Ioc @[simp] theorem mem_Ici : x ∈ Ici a ↔ a ≤ x := Iff.rfl #align set.mem_Ici Set.mem_Ici @[simp] theorem mem_Ioi : x ∈ Ioi a ↔ a < x := Iff.rfl #align set.mem_Ioi Set.mem_Ioi instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption #align set.decidable_mem_Ioo Set.decidableMemIoo instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption #align set.decidable_mem_Ico Set.decidableMemIco instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption #align set.decidable_mem_Iio Set.decidableMemIio instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption #align set.decidable_mem_Icc Set.decidableMemIcc instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption #align set.decidable_mem_Iic Set.decidableMemIic instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption #align set.decidable_mem_Ioc Set.decidableMemIoc instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption #align set.decidable_mem_Ici Set.decidableMemIci instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption #align set.decidable_mem_Ioi Set.decidableMemIoi -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioo Set.left_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] #align set.left_mem_Ico Set.left_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.left_mem_Icc Set.left_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioc Set.left_mem_Ioc theorem left_mem_Ici : a ∈ Ici a := by simp #align set.left_mem_Ici Set.left_mem_Ici -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ioo Set.right_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ico Set.right_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.right_mem_Icc Set.right_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] #align set.right_mem_Ioc Set.right_mem_Ioc theorem right_mem_Iic : a ∈ Iic a := by simp #align set.right_mem_Iic Set.right_mem_Iic @[simp] theorem dual_Ici : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl #align set.dual_Ici Set.dual_Ici @[simp] theorem dual_Iic : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl #align set.dual_Iic Set.dual_Iic @[simp] theorem dual_Ioi : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl #align set.dual_Ioi Set.dual_Ioi @[simp] theorem dual_Iio : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl #align set.dual_Iio Set.dual_Iio @[simp] theorem dual_Icc : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm #align set.dual_Icc Set.dual_Icc @[simp] theorem dual_Ioc : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm #align set.dual_Ioc Set.dual_Ioc @[simp] theorem dual_Ico : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm #align set.dual_Ico Set.dual_Ico @[simp] theorem dual_Ioo : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm #align set.dual_Ioo Set.dual_Ioo @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := ⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩ #align set.nonempty_Icc Set.nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩ #align set.nonempty_Ico Set.nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩ #align set.nonempty_Ioc Set.nonempty_Ioc @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ #align set.nonempty_Ici Set.nonempty_Ici @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ #align set.nonempty_Iic Set.nonempty_Iic @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ #align set.nonempty_Ioo Set.nonempty_Ioo @[simp] theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty := exists_gt a #align set.nonempty_Ioi Set.nonempty_Ioi @[simp] theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty := exists_lt a #align set.nonempty_Iio Set.nonempty_Iio theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) #align set.nonempty_Icc_subtype Set.nonempty_Icc_subtype theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) #align set.nonempty_Ico_subtype Set.nonempty_Ico_subtype theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) #align set.nonempty_Ioc_subtype Set.nonempty_Ioc_subtype /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici #align set.nonempty_Ici_subtype Set.nonempty_Ici_subtype /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic #align set.nonempty_Iic_subtype Set.nonempty_Iic_subtype theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) #align set.nonempty_Ioo_subtype Set.nonempty_Ioo_subtype /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi #align set.nonempty_Ioi_subtype Set.nonempty_Ioi_subtype /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio #align set.nonempty_Iio_subtype Set.nonempty_Iio_subtype instance [NoMinOrder α] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder α] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder α] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (α := Iio (toDual a)) instance [NoMaxOrder α] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (α := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Icc_eq_empty Set.Icc_eq_empty @[simp] theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) #align set.Ico_eq_empty Set.Ico_eq_empty @[simp] theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) #align set.Ioc_eq_empty Set.Ioc_eq_empty @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Ioo_eq_empty Set.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align set.Icc_eq_empty_of_lt Set.Icc_eq_empty_of_lt @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt #align set.Ico_eq_empty_of_le Set.Ico_eq_empty_of_le @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt #align set.Ioc_eq_empty_of_le Set.Ioc_eq_empty_of_le @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt #align set.Ioo_eq_empty_of_le Set.Ioo_eq_empty_of_le -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ #align set.Ico_self Set.Ico_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ #align set.Ioc_self Set.Ioc_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ #align set.Ioo_self Set.Ioo_self theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ #align set.Ici_subset_Ici Set.Ici_subset_Ici @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := @Ici_subset_Ici αᵒᵈ _ _ _ #align set.Iic_subset_Iic Set.Iic_subset_Iic @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ #align set.Ici_subset_Ioi Set.Ici_subset_Ioi theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ #align set.Iic_subset_Iio Set.Iic_subset_Iio @[gcongr] theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩ #align set.Ioo_subset_Ioo Set.Ioo_subset_Ioo @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align set.Ioo_subset_Ioo_left Set.Ioo_subset_Ioo_left @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align set.Ioo_subset_Ioo_right Set.Ioo_subset_Ioo_right @[gcongr] theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, hx₂.trans_le h₂⟩ #align set.Ico_subset_Ico Set.Ico_subset_Ico @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align set.Ico_subset_Ico_left Set.Ico_subset_Ico_left @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align set.Ico_subset_Ico_right Set.Ico_subset_Ico_right @[gcongr] theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, le_trans hx₂ h₂⟩ #align set.Icc_subset_Icc Set.Icc_subset_Icc @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align set.Icc_subset_Icc_left Set.Icc_subset_Icc_left @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align set.Icc_subset_Icc_right Set.Icc_subset_Icc_right theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ #align set.Icc_subset_Ioo Set.Icc_subset_Ioo theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left #align set.Icc_subset_Ici_self Set.Icc_subset_Ici_self theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right #align set.Icc_subset_Iic_self Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right #align set.Ioc_subset_Iic_self Set.Ioc_subset_Iic_self @[gcongr] theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩ #align set.Ioc_subset_Ioc Set.Ioc_subset_Ioc @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align set.Ioc_subset_Ioc_left Set.Ioc_subset_Ioc_left @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align set.Ioc_subset_Ioc_right Set.Ioc_subset_Ioc_right theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ => And.imp_left h₁.trans_le #align set.Ico_subset_Ioo_left Set.Ico_subset_Ioo_left theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ => And.imp_right fun h' => h'.trans_lt h #align set.Ioc_subset_Ioo_right Set.Ioc_subset_Ioo_right theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ => And.imp_right fun h₂ => h₂.trans_lt h₁ #align set.Icc_subset_Ico_right Set.Icc_subset_Ico_right theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt #align set.Ioo_subset_Ico_self Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt #align set.Ioo_subset_Ioc_self Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt #align set.Ico_subset_Icc_self Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt #align set.Ioc_subset_Icc_self Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self #align set.Ioo_subset_Icc_self Set.Ioo_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right #align set.Ico_subset_Iio_self Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right #align set.Ioo_subset_Iio_self Set.Ioo_subset_Iio_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left #align set.Ioc_subset_Ioi_self Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left #align set.Ioo_subset_Ioi_self Set.Ioo_subset_Ioi_self theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx #align set.Ioi_subset_Ici_self Set.Ioi_subset_Ici_self theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx #align set.Iio_subset_Iic_self Set.Iio_subset_Iic_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left #align set.Ico_subset_Ici_self Set.Ico_subset_Ici_self theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ #align set.Ioi_ssubset_Ici_self Set.Ioi_ssubset_Ici_self theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a := @Ioi_ssubset_Ici_self αᵒᵈ _ _ #align set.Iio_ssubset_Iic_self Set.Iio_ssubset_Iic_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Icc_iff Set.Icc_subset_Icc_iff theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ioo_iff Set.Icc_subset_Ioo_iff theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ico_iff Set.Icc_subset_Ico_iff theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Ioc_iff Set.Icc_subset_Ioc_iff theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ #align set.Icc_subset_Iio_iff Set.Icc_subset_Iio_iff theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ #align set.Icc_subset_Ioi_iff Set.Icc_subset_Ioi_iff theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ #align set.Icc_subset_Iic_iff Set.Icc_subset_Iic_iff theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩ #align set.Icc_subset_Ici_iff Set.Icc_subset_Ici_iff theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩ #align set.Icc_ssubset_Icc_left Set.Icc_ssubset_Icc_left theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ #align set.Icc_ssubset_Icc_right Set.Icc_ssubset_Icc_right /-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx #align set.Ioi_subset_Ioi Set.Ioi_subset_Ioi /-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self #align set.Ioi_subset_Ici Set.Ioi_subset_Ici /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h #align set.Iio_subset_Iio Set.Iio_subset_Iio /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self #align set.Iio_subset_Iic Set.Iio_subset_Iic theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl #align set.Ici_inter_Iic Set.Ici_inter_Iic theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl #align set.Ici_inter_Iio Set.Ici_inter_Iio theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl #align set.Ioi_inter_Iic Set.Ioi_inter_Iic theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl #align set.Ioi_inter_Iio Set.Ioi_inter_Iio theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ #align set.Iic_inter_Ici Set.Iic_inter_Ici theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ #align set.Iio_inter_Ici Set.Iio_inter_Ici theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ #align set.Iic_inter_Ioi Set.Iic_inter_Ioi theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ #align set.Iio_inter_Ioi Set.Iio_inter_Ioi theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h #align set.mem_Icc_of_Ioo Set.mem_Icc_of_Ioo theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h #align set.mem_Ico_of_Ioo Set.mem_Ico_of_Ioo theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h #align set.mem_Ioc_of_Ioo Set.mem_Ioc_of_Ioo theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h #align set.mem_Icc_of_Ico Set.mem_Icc_of_Ico theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h #align set.mem_Icc_of_Ioc Set.mem_Icc_of_Ioc theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h #align set.mem_Ici_of_Ioi Set.mem_Ici_of_Ioi theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h #align set.mem_Iic_of_Iio Set.mem_Iic_of_Iio theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] #align set.Icc_eq_empty_iff Set.Icc_eq_empty_iff theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico] #align set.Ico_eq_empty_iff Set.Ico_eq_empty_iff theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc] #align set.Ioc_eq_empty_iff Set.Ioc_eq_empty_iff theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo] #align set.Ioo_eq_empty_iff Set.Ioo_eq_empty_iff theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ := eq_univ_of_forall h #align is_top.Iic_eq IsTop.Iic_eq theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ := eq_univ_of_forall h #align is_bot.Ici_eq IsBot.Ici_eq theorem _root_.IsMax.Ioi_eq (h : IsMax a) : Ioi a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_max.Ioi_eq IsMax.Ioi_eq theorem _root_.IsMin.Iio_eq (h : IsMin a) : Iio a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_min.Iio_eq IsMin.Iio_eq theorem Iic_inter_Ioc_of_le (h : a ≤ c) : Iic a ∩ Ioc b c = Ioc b a := ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩ #align set.Iic_inter_Ioc_of_le Set.Iic_inter_Ioc_of_le theorem not_mem_Icc_of_lt (ha : c < a) : c ∉ Icc a b := fun h => ha.not_le h.1 #align set.not_mem_Icc_of_lt Set.not_mem_Icc_of_lt theorem not_mem_Icc_of_gt (hb : b < c) : c ∉ Icc a b := fun h => hb.not_le h.2 #align set.not_mem_Icc_of_gt Set.not_mem_Icc_of_gt theorem not_mem_Ico_of_lt (ha : c < a) : c ∉ Ico a b := fun h => ha.not_le h.1 #align set.not_mem_Ico_of_lt Set.not_mem_Ico_of_lt theorem not_mem_Ioc_of_gt (hb : b < c) : c ∉ Ioc a b := fun h => hb.not_le h.2 #align set.not_mem_Ioc_of_gt Set.not_mem_Ioc_of_gt -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Ioi_self : a ∉ Ioi a := lt_irrefl _ #align set.not_mem_Ioi_self Set.not_mem_Ioi_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Iio_self : b ∉ Iio b := lt_irrefl _ #align set.not_mem_Iio_self Set.not_mem_Iio_self theorem not_mem_Ioc_of_le (ha : c ≤ a) : c ∉ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioc_of_le Set.not_mem_Ioc_of_le theorem not_mem_Ico_of_ge (hb : b ≤ c) : c ∉ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ico_of_ge Set.not_mem_Ico_of_ge theorem not_mem_Ioo_of_le (ha : c ≤ a) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioo_of_le Set.not_mem_Ioo_of_le theorem not_mem_Ioo_of_ge (hb : b ≤ c) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ioo_of_ge Set.not_mem_Ioo_of_ge end Preorder section PartialOrder variable [PartialOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := Set.ext <| by simp [Icc, le_antisymm_iff, and_comm] #align set.Icc_self Set.Icc_self instance instIccUnique : Unique (Set.Icc a a) where default := ⟨a, by simp⟩ uniq y := Subtype.ext <| by simpa using y.2 @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by refine ⟨fun h => ?_, ?_⟩ · have hab : a ≤ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c) exact ⟨eq_of_mem_singleton <| h.subst <| left_mem_Icc.2 hab, eq_of_mem_singleton <| h.subst <| right_mem_Icc.2 hab⟩ · rintro ⟨rfl, rfl⟩ exact Icc_self _ #align set.Icc_eq_singleton_iff Set.Icc_eq_singleton_iff lemma subsingleton_Icc_of_ge (hba : b ≤ a) : Set.Subsingleton (Icc a b) := fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm (le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba) #align set.subsingleton_Icc_of_ge Set.subsingleton_Icc_of_ge @[simp] lemma subsingleton_Icc_iff {α : Type*} [LinearOrder α] {a b : α} : Set.Subsingleton (Icc a b) ↔ b ≤ a := by refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩ contrapose! h simp only [ge_iff_le, gt_iff_lt, not_subsingleton_iff] exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩ @[simp] theorem Icc_diff_left : Icc a b \ {a} = Ioc a b := ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm] #align set.Icc_diff_left Set.Icc_diff_left @[simp] theorem Icc_diff_right : Icc a b \ {b} = Ico a b := ext fun x => by simp [lt_iff_le_and_ne, and_assoc] #align set.Icc_diff_right Set.Icc_diff_right @[simp] theorem Ico_diff_left : Ico a b \ {a} = Ioo a b := ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm] #align set.Ico_diff_left Set.Ico_diff_left @[simp] theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b := ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne] #align set.Ioc_diff_right Set.Ioc_diff_right @[simp] theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right] #align set.Icc_diff_both Set.Icc_diff_both @[simp] theorem Ici_diff_left : Ici a \ {a} = Ioi a := ext fun x => by simp [lt_iff_le_and_ne, eq_comm] #align set.Ici_diff_left Set.Ici_diff_left @[simp] theorem Iic_diff_right : Iic a \ {a} = Iio a := ext fun x => by simp [lt_iff_le_and_ne] #align set.Iic_diff_right Set.Iic_diff_right @[simp] theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)] #align set.Ico_diff_Ioo_same Set.Ico_diff_Ioo_same @[simp] theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)] #align set.Ioc_diff_Ioo_same Set.Ioc_diff_Ioo_same @[simp] theorem Icc_diff_Ico_same (h : a ≤ b) : Icc a b \ Ico a b = {b} := by rw [← Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)] #align set.Icc_diff_Ico_same Set.Icc_diff_Ico_same @[simp] theorem Icc_diff_Ioc_same (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by rw [← Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)] #align set.Icc_diff_Ioc_same Set.Icc_diff_Ioc_same @[simp] theorem Icc_diff_Ioo_same (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by rw [← Icc_diff_both, diff_diff_cancel_left] simp [insert_subset_iff, h] #align set.Icc_diff_Ioo_same Set.Icc_diff_Ioo_same @[simp] theorem Ici_diff_Ioi_same : Ici a \ Ioi a = {a} := by rw [← Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)] #align set.Ici_diff_Ioi_same Set.Ici_diff_Ioi_same @[simp] theorem Iic_diff_Iio_same : Iic a \ Iio a = {a} := by rw [← Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)] #align set.Iic_diff_Iio_same Set.Iic_diff_Iio_same -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioi_union_left : Ioi a ∪ {a} = Ici a := ext fun x => by simp [eq_comm, le_iff_eq_or_lt] #align set.Ioi_union_left Set.Ioi_union_left -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Iio_union_right : Iio a ∪ {a} = Iic a := ext fun _ => le_iff_lt_or_eq.symm #align set.Iio_union_right Set.Iio_union_right theorem Ioo_union_left (hab : a < b) : Ioo a b ∪ {a} = Ico a b := by rw [← Ico_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Ico.2 hab)] #align set.Ioo_union_left Set.Ioo_union_left theorem Ioo_union_right (hab : a < b) : Ioo a b ∪ {b} = Ioc a b := by simpa only [dual_Ioo, dual_Ico] using Ioo_union_left hab.dual #align set.Ioo_union_right Set.Ioo_union_right theorem Ioo_union_both (h : a ≤ b) : Ioo a b ∪ {a, b} = Icc a b := by have : (Icc a b \ {a, b}) ∪ {a, b} = Icc a b := diff_union_of_subset fun | x, .inl rfl => left_mem_Icc.mpr h | x, .inr rfl => right_mem_Icc.mpr h rw [← this, Icc_diff_both] theorem Ioc_union_left (hab : a ≤ b) : Ioc a b ∪ {a} = Icc a b := by rw [← Icc_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Icc.2 hab)] #align set.Ioc_union_left Set.Ioc_union_left theorem Ico_union_right (hab : a ≤ b) : Ico a b ∪ {b} = Icc a b := by simpa only [dual_Ioc, dual_Icc] using Ioc_union_left hab.dual #align set.Ico_union_right Set.Ico_union_right @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [insert_eq, union_comm, Ico_union_right h] #align set.Ico_insert_right Set.Ico_insert_right @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [insert_eq, union_comm, Ioc_union_left h] #align set.Ioc_insert_left Set.Ioc_insert_left @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [insert_eq, union_comm, Ioo_union_left h] #align set.Ioo_insert_left Set.Ioo_insert_left @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [insert_eq, union_comm, Ioo_union_right h] #align set.Ioo_insert_right Set.Ioo_insert_right @[simp] theorem Iio_insert : insert a (Iio a) = Iic a := ext fun _ => le_iff_eq_or_lt.symm #align set.Iio_insert Set.Iio_insert @[simp] theorem Ioi_insert : insert a (Ioi a) = Ici a := ext fun _ => (or_congr_left eq_comm).trans le_iff_eq_or_lt.symm #align set.Ioi_insert Set.Ioi_insert theorem mem_Ici_Ioi_of_subset_of_subset {s : Set α} (ho : Ioi a ⊆ s) (hc : s ⊆ Ici a) : s ∈ ({Ici a, Ioi a} : Set (Set α)) := by_cases (fun h : a ∈ s => Or.inl <| Subset.antisymm hc <| by rw [← Ioi_union_left, union_subset_iff]; simp [*]) fun h => Or.inr <| Subset.antisymm (fun x hx => lt_of_le_of_ne (hc hx) fun heq => h <| heq.symm ▸ hx) ho #align set.mem_Ici_Ioi_of_subset_of_subset Set.mem_Ici_Ioi_of_subset_of_subset theorem mem_Iic_Iio_of_subset_of_subset {s : Set α} (ho : Iio a ⊆ s) (hc : s ⊆ Iic a) : s ∈ ({Iic a, Iio a} : Set (Set α)) := @mem_Ici_Ioi_of_subset_of_subset αᵒᵈ _ a s ho hc #align set.mem_Iic_Iio_of_subset_of_subset Set.mem_Iic_Iio_of_subset_of_subset theorem mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : Set α} (ho : Ioo a b ⊆ s) (hc : s ⊆ Icc a b) : s ∈ ({Icc a b, Ico a b, Ioc a b, Ioo a b} : Set (Set α)) := by classical by_cases ha : a ∈ s <;> by_cases hb : b ∈ s · refine Or.inl (Subset.antisymm hc ?_) rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha, ← Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_right] exact subset_diff_singleton hc hb · rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho · refine Or.inr <| Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_left] exact subset_diff_singleton hc ha · rwa [← Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inr <| Or.inr <| Subset.antisymm ?_ ho rw [← Ico_diff_left, ← Icc_diff_right] apply_rules [subset_diff_singleton] #align set.mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset Set.mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset theorem eq_left_or_mem_Ioo_of_mem_Ico {x : α} (hmem : x ∈ Ico a b) : x = a ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => ⟨h, hmem.2⟩ #align set.eq_left_or_mem_Ioo_of_mem_Ico Set.eq_left_or_mem_Ioo_of_mem_Ico theorem eq_right_or_mem_Ioo_of_mem_Ioc {x : α} (hmem : x ∈ Ioc a b) : x = b ∨ x ∈ Ioo a b := hmem.2.eq_or_lt.imp_right <| And.intro hmem.1 #align set.eq_right_or_mem_Ioo_of_mem_Ioc Set.eq_right_or_mem_Ioo_of_mem_Ioc theorem eq_endpoints_or_mem_Ioo_of_mem_Icc {x : α} (hmem : x ∈ Icc a b) : x = a ∨ x = b ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => eq_right_or_mem_Ioo_of_mem_Ioc ⟨h, hmem.2⟩ #align set.eq_endpoints_or_mem_Ioo_of_mem_Icc Set.eq_endpoints_or_mem_Ioo_of_mem_Icc theorem _root_.IsMax.Ici_eq (h : IsMax a) : Ici a = {a} := eq_singleton_iff_unique_mem.2 ⟨left_mem_Ici, fun _ => h.eq_of_ge⟩ #align is_max.Ici_eq IsMax.Ici_eq theorem _root_.IsMin.Iic_eq (h : IsMin a) : Iic a = {a} := h.toDual.Ici_eq #align is_min.Iic_eq IsMin.Iic_eq theorem Ici_injective : Injective (Ici : α → Set α) := fun _ _ => eq_of_forall_ge_iff ∘ Set.ext_iff.1 #align set.Ici_injective Set.Ici_injective theorem Iic_injective : Injective (Iic : α → Set α) := fun _ _ => eq_of_forall_le_iff ∘ Set.ext_iff.1 #align set.Iic_injective Set.Iic_injective theorem Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff #align set.Ici_inj Set.Ici_inj theorem Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff #align set.Iic_inj Set.Iic_inj end PartialOrder section OrderTop @[simp] theorem Ici_top [PartialOrder α] [OrderTop α] : Ici (⊤ : α) = {⊤} := isMax_top.Ici_eq #align set.Ici_top Set.Ici_top variable [Preorder α] [OrderTop α] {a : α} @[simp] theorem Ioi_top : Ioi (⊤ : α) = ∅ := isMax_top.Ioi_eq #align set.Ioi_top Set.Ioi_top @[simp] theorem Iic_top : Iic (⊤ : α) = univ := isTop_top.Iic_eq #align set.Iic_top Set.Iic_top @[simp] theorem Icc_top : Icc a ⊤ = Ici a := by simp [← Ici_inter_Iic] #align set.Icc_top Set.Icc_top @[simp] theorem Ioc_top : Ioc a ⊤ = Ioi a := by simp [← Ioi_inter_Iic] #align set.Ioc_top Set.Ioc_top end OrderTop section OrderBot @[simp] theorem Iic_bot [PartialOrder α] [OrderBot α] : Iic (⊥ : α) = {⊥} := isMin_bot.Iic_eq #align set.Iic_bot Set.Iic_bot variable [Preorder α] [OrderBot α] {a : α} @[simp] theorem Iio_bot : Iio (⊥ : α) = ∅ := isMin_bot.Iio_eq #align set.Iio_bot Set.Iio_bot @[simp] theorem Ici_bot : Ici (⊥ : α) = univ := isBot_bot.Ici_eq #align set.Ici_bot Set.Ici_bot @[simp] theorem Icc_bot : Icc ⊥ a = Iic a := by simp [← Ici_inter_Iic] #align set.Icc_bot Set.Icc_bot @[simp] theorem Ico_bot : Ico ⊥ a = Iio a := by simp [← Ici_inter_Iio] #align set.Ico_bot Set.Ico_bot end OrderBot theorem Icc_bot_top [PartialOrder α] [BoundedOrder α] : Icc (⊥ : α) ⊤ = univ := by simp #align set.Icc_bot_top Set.Icc_bot_top section LinearOrder variable [LinearOrder α] {a a₁ a₂ b b₁ b₂ c d : α} theorem not_mem_Ici : c ∉ Ici a ↔ c < a := not_le #align set.not_mem_Ici Set.not_mem_Ici theorem not_mem_Iic : c ∉ Iic b ↔ b < c := not_le #align set.not_mem_Iic Set.not_mem_Iic theorem not_mem_Ioi : c ∉ Ioi a ↔ c ≤ a := not_lt #align set.not_mem_Ioi Set.not_mem_Ioi theorem not_mem_Iio : c ∉ Iio b ↔ b ≤ c := not_lt #align set.not_mem_Iio Set.not_mem_Iio @[simp] theorem compl_Iic : (Iic a)ᶜ = Ioi a := ext fun _ => not_le #align set.compl_Iic Set.compl_Iic @[simp] theorem compl_Ici : (Ici a)ᶜ = Iio a := ext fun _ => not_le #align set.compl_Ici Set.compl_Ici @[simp] theorem compl_Iio : (Iio a)ᶜ = Ici a := ext fun _ => not_lt #align set.compl_Iio Set.compl_Iio @[simp] theorem compl_Ioi : (Ioi a)ᶜ = Iic a := ext fun _ => not_lt #align set.compl_Ioi Set.compl_Ioi @[simp] theorem Ici_diff_Ici : Ici a \ Ici b = Ico a b := by rw [diff_eq, compl_Ici, Ici_inter_Iio] #align set.Ici_diff_Ici Set.Ici_diff_Ici @[simp] theorem Ici_diff_Ioi : Ici a \ Ioi b = Icc a b := by rw [diff_eq, compl_Ioi, Ici_inter_Iic] #align set.Ici_diff_Ioi Set.Ici_diff_Ioi @[simp] theorem Ioi_diff_Ioi : Ioi a \ Ioi b = Ioc a b := by rw [diff_eq, compl_Ioi, Ioi_inter_Iic] #align set.Ioi_diff_Ioi Set.Ioi_diff_Ioi @[simp] theorem Ioi_diff_Ici : Ioi a \ Ici b = Ioo a b := by rw [diff_eq, compl_Ici, Ioi_inter_Iio] #align set.Ioi_diff_Ici Set.Ioi_diff_Ici @[simp] theorem Iic_diff_Iic : Iic b \ Iic a = Ioc a b := by rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iic] #align set.Iic_diff_Iic Set.Iic_diff_Iic @[simp] theorem Iio_diff_Iic : Iio b \ Iic a = Ioo a b := by rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iio] #align set.Iio_diff_Iic Set.Iio_diff_Iic @[simp] theorem Iic_diff_Iio : Iic b \ Iio a = Icc a b := by rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iic] #align set.Iic_diff_Iio Set.Iic_diff_Iio @[simp] theorem Iio_diff_Iio : Iio b \ Iio a = Ico a b := by rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iio] #align set.Iio_diff_Iio Set.Iio_diff_Iio theorem Ioi_injective : Injective (Ioi : α → Set α) := fun _ _ => eq_of_forall_gt_iff ∘ Set.ext_iff.1 #align set.Ioi_injective Set.Ioi_injective theorem Iio_injective : Injective (Iio : α → Set α) := fun _ _ => eq_of_forall_lt_iff ∘ Set.ext_iff.1 #align set.Iio_injective Set.Iio_injective theorem Ioi_inj : Ioi a = Ioi b ↔ a = b := Ioi_injective.eq_iff #align set.Ioi_inj Set.Ioi_inj theorem Iio_inj : Iio a = Iio b ↔ a = b := Iio_injective.eq_iff #align set.Iio_inj Set.Iio_inj theorem Ico_subset_Ico_iff (h₁ : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => have : a₂ ≤ a₁ ∧ a₁ < b₂ := h ⟨le_rfl, h₁⟩ ⟨this.1, le_of_not_lt fun h' => lt_irrefl b₂ (h ⟨this.2.le, h'⟩).2⟩, fun ⟨h₁, h₂⟩ => Ico_subset_Ico h₁ h₂⟩ #align set.Ico_subset_Ico_iff Set.Ico_subset_Ico_iff theorem Ioc_subset_Ioc_iff (h₁ : a₁ < b₁) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ b₁ ≤ b₂ ∧ a₂ ≤ a₁ := by convert @Ico_subset_Ico_iff αᵒᵈ _ b₁ b₂ a₁ a₂ h₁ using 2 <;> exact (@dual_Ico α _ _ _).symm #align set.Ioc_subset_Ioc_iff Set.Ioc_subset_Ioc_iff theorem Ioo_subset_Ioo_iff [DenselyOrdered α] (h₁ : a₁ < b₁) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => by rcases exists_between h₁ with ⟨x, xa, xb⟩ constructor <;> refine le_of_not_lt fun h' => ?_ · have ab := (h ⟨xa, xb⟩).1.trans xb exact lt_irrefl _ (h ⟨h', ab⟩).1 · have ab := xa.trans (h ⟨xa, xb⟩).2 exact lt_irrefl _ (h ⟨ab, h'⟩).2, fun ⟨h₁, h₂⟩ => Ioo_subset_Ioo h₁ h₂⟩ #align set.Ioo_subset_Ioo_iff Set.Ioo_subset_Ioo_iff theorem Ico_eq_Ico_iff (h : a₁ < b₁ ∨ a₂ < b₂) : Ico a₁ b₁ = Ico a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ := ⟨fun e => by simp only [Subset.antisymm_iff] at e simp only [le_antisymm_iff] cases' h with h h <;> simp only [gt_iff_lt, not_lt, ge_iff_le, Ico_subset_Ico_iff h] at e <;> [ rcases e with ⟨⟨h₁, h₂⟩, e'⟩; rcases e with ⟨e', ⟨h₁, h₂⟩⟩ ] <;> -- Porting note: restore `tauto` have hab := (Ico_subset_Ico_iff <| h₁.trans_lt <| h.trans_le h₂).1 e' <;> [ exact ⟨⟨hab.left, h₁⟩, ⟨h₂, hab.right⟩⟩; exact ⟨⟨h₁, hab.left⟩, ⟨hab.right, h₂⟩⟩ ], fun ⟨h₁, h₂⟩ => by rw [h₁, h₂]⟩ #align set.Ico_eq_Ico_iff Set.Ico_eq_Ico_iff lemma Ici_eq_singleton_iff_isTop {x : α} : (Ici x = {x}) ↔ IsTop x := by refine ⟨fun h y ↦ ?_, fun h ↦ by ext y; simp [(h y).ge_iff_eq]⟩ by_contra! H have : y ∈ Ici x := H.le rw [h, mem_singleton_iff] at this exact lt_irrefl y (this.le.trans_lt H) open scoped Classical @[simp] theorem Ioi_subset_Ioi_iff : Ioi b ⊆ Ioi a ↔ a ≤ b := by refine ⟨fun h => ?_, fun h => Ioi_subset_Ioi h⟩ by_contra ba exact lt_irrefl _ (h (not_le.mp ba)) #align set.Ioi_subset_Ioi_iff Set.Ioi_subset_Ioi_iff @[simp] theorem Ioi_subset_Ici_iff [DenselyOrdered α] : Ioi b ⊆ Ici a ↔ a ≤ b := by refine ⟨fun h => ?_, fun h => Ioi_subset_Ici h⟩ by_contra ba obtain ⟨c, bc, ca⟩ : ∃ c, b < c ∧ c < a := exists_between (not_le.mp ba) exact lt_irrefl _ (ca.trans_le (h bc)) #align set.Ioi_subset_Ici_iff Set.Ioi_subset_Ici_iff @[simp] theorem Iio_subset_Iio_iff : Iio a ⊆ Iio b ↔ a ≤ b := by refine ⟨fun h => ?_, fun h => Iio_subset_Iio h⟩ by_contra ab exact lt_irrefl _ (h (not_le.mp ab)) #align set.Iio_subset_Iio_iff Set.Iio_subset_Iio_iff @[simp] theorem Iio_subset_Iic_iff [DenselyOrdered α] : Iio a ⊆ Iic b ↔ a ≤ b := by rw [← diff_eq_empty, Iio_diff_Iic, Ioo_eq_empty_iff, not_lt] #align set.Iio_subset_Iic_iff Set.Iio_subset_Iic_iff /-! ### Unions of adjacent intervals -/ /-! #### Two infinite intervals -/ theorem Iic_union_Ioi_of_le (h : a ≤ b) : Iic b ∪ Ioi a = univ := eq_univ_of_forall fun x => (h.lt_or_le x).symm #align set.Iic_union_Ioi_of_le Set.Iic_union_Ioi_of_le theorem Iio_union_Ici_of_le (h : a ≤ b) : Iio b ∪ Ici a = univ := eq_univ_of_forall fun x => (h.le_or_lt x).symm #align set.Iio_union_Ici_of_le Set.Iio_union_Ici_of_le theorem Iic_union_Ici_of_le (h : a ≤ b) : Iic b ∪ Ici a = univ := eq_univ_of_forall fun x => (h.le_or_le x).symm #align set.Iic_union_Ici_of_le Set.Iic_union_Ici_of_le theorem Iio_union_Ioi_of_lt (h : a < b) : Iio b ∪ Ioi a = univ := eq_univ_of_forall fun x => (h.lt_or_lt x).symm #align set.Iio_union_Ioi_of_lt Set.Iio_union_Ioi_of_lt @[simp] theorem Iic_union_Ici : Iic a ∪ Ici a = univ := Iic_union_Ici_of_le le_rfl #align set.Iic_union_Ici Set.Iic_union_Ici @[simp] theorem Iio_union_Ici : Iio a ∪ Ici a = univ := Iio_union_Ici_of_le le_rfl #align set.Iio_union_Ici Set.Iio_union_Ici @[simp] theorem Iic_union_Ioi : Iic a ∪ Ioi a = univ := Iic_union_Ioi_of_le le_rfl #align set.Iic_union_Ioi Set.Iic_union_Ioi @[simp] theorem Iio_union_Ioi : Iio a ∪ Ioi a = {a}ᶜ := ext fun _ => lt_or_lt_iff_ne #align set.Iio_union_Ioi Set.Iio_union_Ioi /-! #### A finite and an infinite interval -/ theorem Ioo_union_Ioi' (h₁ : c < b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by ext1 x simp_rw [mem_union, mem_Ioo, mem_Ioi, min_lt_iff] by_cases hc : c < x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x < b := (le_of_not_gt hc).trans_lt h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Ioo_union_Ioi' Set.Ioo_union_Ioi' theorem Ioo_union_Ioi (h : c < max a b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by rcases le_total a b with hab | hab <;> simp [hab] at h · exact Ioo_union_Ioi' h · rw [min_comm] simp [*, min_eq_left_of_lt] #align set.Ioo_union_Ioi Set.Ioo_union_Ioi theorem Ioi_subset_Ioo_union_Ici : Ioi a ⊆ Ioo a b ∪ Ici b := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ioi_subset_Ioo_union_Ici Set.Ioi_subset_Ioo_union_Ici @[simp] theorem Ioo_union_Ici_eq_Ioi (h : a < b) : Ioo a b ∪ Ici b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_le) Ioi_subset_Ioo_union_Ici #align set.Ioo_union_Ici_eq_Ioi Set.Ioo_union_Ici_eq_Ioi theorem Ici_subset_Ico_union_Ici : Ici a ⊆ Ico a b ∪ Ici b := fun x hx => (lt_or_le x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ici_subset_Ico_union_Ici Set.Ici_subset_Ico_union_Ici @[simp] theorem Ico_union_Ici_eq_Ici (h : a ≤ b) : Ico a b ∪ Ici b = Ici a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans) Ici_subset_Ico_union_Ici #align set.Ico_union_Ici_eq_Ici Set.Ico_union_Ici_eq_Ici theorem Ico_union_Ici' (h₁ : c ≤ b) : Ico a b ∪ Ici c = Ici (min a c) := by ext1 x simp_rw [mem_union, mem_Ico, mem_Ici, min_le_iff] by_cases hc : c ≤ x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x < b := (lt_of_not_ge hc).trans_le h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Ico_union_Ici' Set.Ico_union_Ici' theorem Ico_union_Ici (h : c ≤ max a b) : Ico a b ∪ Ici c = Ici (min a c) := by rcases le_total a b with hab | hab <;> simp [hab] at h · exact Ico_union_Ici' h · simp [*] #align set.Ico_union_Ici Set.Ico_union_Ici theorem Ioi_subset_Ioc_union_Ioi : Ioi a ⊆ Ioc a b ∪ Ioi b := fun x hx => (le_or_lt x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ioi_subset_Ioc_union_Ioi Set.Ioi_subset_Ioc_union_Ioi @[simp] theorem Ioc_union_Ioi_eq_Ioi (h : a ≤ b) : Ioc a b ∪ Ioi b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_lt) Ioi_subset_Ioc_union_Ioi #align set.Ioc_union_Ioi_eq_Ioi Set.Ioc_union_Ioi_eq_Ioi theorem Ioc_union_Ioi' (h₁ : c ≤ b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by ext1 x simp_rw [mem_union, mem_Ioc, mem_Ioi, min_lt_iff] by_cases hc : c < x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x ≤ b := (le_of_not_gt hc).trans h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Ioc_union_Ioi' Set.Ioc_union_Ioi' theorem Ioc_union_Ioi (h : c ≤ max a b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by rcases le_total a b with hab | hab <;> simp [hab] at h · exact Ioc_union_Ioi' h · simp [*] #align set.Ioc_union_Ioi Set.Ioc_union_Ioi theorem Ici_subset_Icc_union_Ioi : Ici a ⊆ Icc a b ∪ Ioi b := fun x hx => (le_or_lt x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb #align set.Ici_subset_Icc_union_Ioi Set.Ici_subset_Icc_union_Ioi @[simp] theorem Icc_union_Ioi_eq_Ici (h : a ≤ b) : Icc a b ∪ Ioi b = Ici a := Subset.antisymm (fun _ hx => (hx.elim And.left) fun hx' => h.trans <| le_of_lt hx') Ici_subset_Icc_union_Ioi #align set.Icc_union_Ioi_eq_Ici Set.Icc_union_Ioi_eq_Ici theorem Ioi_subset_Ioc_union_Ici : Ioi a ⊆ Ioc a b ∪ Ici b := Subset.trans Ioi_subset_Ioo_union_Ici (union_subset_union_left _ Ioo_subset_Ioc_self) #align set.Ioi_subset_Ioc_union_Ici Set.Ioi_subset_Ioc_union_Ici @[simp] theorem Ioc_union_Ici_eq_Ioi (h : a < b) : Ioc a b ∪ Ici b = Ioi a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans_le) Ioi_subset_Ioc_union_Ici #align set.Ioc_union_Ici_eq_Ioi Set.Ioc_union_Ici_eq_Ioi theorem Ici_subset_Icc_union_Ici : Ici a ⊆ Icc a b ∪ Ici b := Subset.trans Ici_subset_Ico_union_Ici (union_subset_union_left _ Ico_subset_Icc_self) #align set.Ici_subset_Icc_union_Ici Set.Ici_subset_Icc_union_Ici @[simp] theorem Icc_union_Ici_eq_Ici (h : a ≤ b) : Icc a b ∪ Ici b = Ici a := Subset.antisymm (fun _ hx => hx.elim And.left h.trans) Ici_subset_Icc_union_Ici #align set.Icc_union_Ici_eq_Ici Set.Icc_union_Ici_eq_Ici theorem Icc_union_Ici' (h₁ : c ≤ b) : Icc a b ∪ Ici c = Ici (min a c) := by ext1 x simp_rw [mem_union, mem_Icc, mem_Ici, min_le_iff] by_cases hc : c ≤ x · simp only [hc, or_true] -- Porting note: restore `tauto` · have hxb : x ≤ b := (le_of_not_ge hc).trans h₁ simp only [hxb, and_true] -- Porting note: restore `tauto` #align set.Icc_union_Ici' Set.Icc_union_Ici' theorem Icc_union_Ici (h : c ≤ max a b) : Icc a b ∪ Ici c = Ici (min a c) := by rcases le_or_lt a b with hab | hab <;> simp [hab] at h · exact Icc_union_Ici' h · cases' h with h h · simp [*] · have hca : c ≤ a := h.trans hab.le simp [*] #align set.Icc_union_Ici Set.Icc_union_Ici /-! #### An infinite and a finite interval -/ theorem Iic_subset_Iio_union_Icc : Iic b ⊆ Iio a ∪ Icc a b := fun x hx => (lt_or_le x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ #align set.Iic_subset_Iio_union_Icc Set.Iic_subset_Iio_union_Icc @[simp] theorem Iio_union_Icc_eq_Iic (h : a ≤ b) : Iio a ∪ Icc a b = Iic b := Subset.antisymm (fun _ hx => hx.elim (fun hx => (le_of_lt hx).trans h) And.right) Iic_subset_Iio_union_Icc #align set.Iio_union_Icc_eq_Iic Set.Iio_union_Icc_eq_Iic theorem Iio_subset_Iio_union_Ico : Iio b ⊆ Iio a ∪ Ico a b := fun x hx => (lt_or_le x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩ #align set.Iio_subset_Iio_union_Ico Set.Iio_subset_Iio_union_Ico @[simp] theorem Iio_union_Ico_eq_Iio (h : a ≤ b) : Iio a ∪ Ico a b = Iio b := Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_lt_of_le hx' h) And.right) Iio_subset_Iio_union_Ico #align set.Iio_union_Ico_eq_Iio Set.Iio_union_Ico_eq_Iio
Mathlib/Order/Interval/Set/Basic.lean
1,426
1,432
theorem Iio_union_Ico' (h₁ : c ≤ b) : Iio b ∪ Ico c d = Iio (max b d) := by
ext1 x simp_rw [mem_union, mem_Iio, mem_Ico, lt_max_iff] by_cases hc : c ≤ x · simp only [hc, true_and] -- Porting note: restore `tauto` · have hxb : x < b := (lt_of_not_ge hc).trans_le h₁ simp only [hxb, true_or] -- Porting note: restore `tauto`
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Option.Basic import Mathlib.Data.Set.Basic #align_import data.pequiv from "leanprover-community/mathlib"@"7c3269ca3fa4c0c19e4d127cd7151edbdbf99ed4" /-! # Partial Equivalences In this file, we define partial equivalences `PEquiv`, which are a bijection between a subset of `α` and a subset of `β`. Notationally, a `PEquiv` is denoted by "`≃.`" (note that the full stop is part of the notation). The way we store these internally is with two functions `f : α → Option β` and the reverse function `g : β → Option α`, with the condition that if `f a` is `some b`, then `g b` is `some a`. ## Main results - `PEquiv.ofSet`: creates a `PEquiv` from a set `s`, which sends an element to itself if it is in `s`. - `PEquiv.single`: given two elements `a : α` and `b : β`, create a `PEquiv` that sends them to each other, and ignores all other elements. - `PEquiv.injective_of_forall_ne_isSome`/`injective_of_forall_isSome`: If the domain of a `PEquiv` is all of `α` (except possibly one point), its `toFun` is injective. ## Canonical order `PEquiv` is canonically ordered by inclusion; that is, if a function `f` defined on a subset `s` is equal to `g` on that subset, but `g` is also defined on a larger set, then `f ≤ g`. We also have a definition of `⊥`, which is the empty `PEquiv` (sends all to `none`), which in the end gives us a `SemilatticeInf` with an `OrderBot` instance. ## Tags pequiv, partial equivalence -/ universe u v w x /-- A `PEquiv` is a partial equivalence, a representation of a bijection between a subset of `α` and a subset of `β`. See also `PartialEquiv` for a version that requires `toFun` and `invFun` to be globally defined functions and has `source` and `target` sets as extra fields. -/ structure PEquiv (α : Type u) (β : Type v) where /-- The underlying partial function of a `PEquiv` -/ toFun : α → Option β /-- The partial inverse of `toFun` -/ invFun : β → Option α /-- `invFun` is the partial inverse of `toFun` -/ inv : ∀ (a : α) (b : β), a ∈ invFun b ↔ b ∈ toFun a #align pequiv PEquiv /-- A `PEquiv` is a partial equivalence, a representation of a bijection between a subset of `α` and a subset of `β`. See also `PartialEquiv` for a version that requires `toFun` and `invFun` to be globally defined functions and has `source` and `target` sets as extra fields. -/ infixr:25 " ≃. " => PEquiv namespace PEquiv variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} open Function Option instance : FunLike (α ≃. β) α (Option β) := { coe := toFun coe_injective' := by rintro ⟨f₁, f₂, hf⟩ ⟨g₁, g₂, hg⟩ (rfl : f₁ = g₁) congr with y x simp only [hf, hg] } @[simp] theorem coe_mk (f₁ : α → Option β) (f₂ h) : (mk f₁ f₂ h : α → Option β) = f₁ := rfl theorem coe_mk_apply (f₁ : α → Option β) (f₂ : β → Option α) (h) (x : α) : (PEquiv.mk f₁ f₂ h : α → Option β) x = f₁ x := rfl #align pequiv.coe_mk_apply PEquiv.coe_mk_apply @[ext] theorem ext {f g : α ≃. β} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h #align pequiv.ext PEquiv.ext theorem ext_iff {f g : α ≃. β} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align pequiv.ext_iff PEquiv.ext_iff /-- The identity map as a partial equivalence. -/ @[refl] protected def refl (α : Type*) : α ≃. α where toFun := some invFun := some inv _ _ := eq_comm #align pequiv.refl PEquiv.refl /-- The inverse partial equivalence. -/ @[symm] protected def symm (f : α ≃. β) : β ≃. α where toFun := f.2 invFun := f.1 inv _ _ := (f.inv _ _).symm #align pequiv.symm PEquiv.symm theorem mem_iff_mem (f : α ≃. β) : ∀ {a : α} {b : β}, a ∈ f.symm b ↔ b ∈ f a := f.3 _ _ #align pequiv.mem_iff_mem PEquiv.mem_iff_mem theorem eq_some_iff (f : α ≃. β) : ∀ {a : α} {b : β}, f.symm b = some a ↔ f a = some b := f.3 _ _ #align pequiv.eq_some_iff PEquiv.eq_some_iff /-- Composition of partial equivalences `f : α ≃. β` and `g : β ≃. γ`. -/ @[trans] protected def trans (f : α ≃. β) (g : β ≃. γ) : α ≃. γ where toFun a := (f a).bind g invFun a := (g.symm a).bind f.symm inv a b := by simp_all [and_comm, eq_some_iff f, eq_some_iff g, bind_eq_some] #align pequiv.trans PEquiv.trans @[simp] theorem refl_apply (a : α) : PEquiv.refl α a = some a := rfl #align pequiv.refl_apply PEquiv.refl_apply @[simp] theorem symm_refl : (PEquiv.refl α).symm = PEquiv.refl α := rfl #align pequiv.symm_refl PEquiv.symm_refl @[simp] theorem symm_symm (f : α ≃. β) : f.symm.symm = f := by cases f; rfl #align pequiv.symm_symm PEquiv.symm_symm theorem symm_bijective : Function.Bijective (PEquiv.symm : (α ≃. β) → β ≃. α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem symm_injective : Function.Injective (@PEquiv.symm α β) := symm_bijective.injective #align pequiv.symm_injective PEquiv.symm_injective theorem trans_assoc (f : α ≃. β) (g : β ≃. γ) (h : γ ≃. δ) : (f.trans g).trans h = f.trans (g.trans h) := ext fun _ => Option.bind_assoc _ _ _ #align pequiv.trans_assoc PEquiv.trans_assoc theorem mem_trans (f : α ≃. β) (g : β ≃. γ) (a : α) (c : γ) : c ∈ f.trans g a ↔ ∃ b, b ∈ f a ∧ c ∈ g b := Option.bind_eq_some' #align pequiv.mem_trans PEquiv.mem_trans theorem trans_eq_some (f : α ≃. β) (g : β ≃. γ) (a : α) (c : γ) : f.trans g a = some c ↔ ∃ b, f a = some b ∧ g b = some c := Option.bind_eq_some' #align pequiv.trans_eq_some PEquiv.trans_eq_some theorem trans_eq_none (f : α ≃. β) (g : β ≃. γ) (a : α) : f.trans g a = none ↔ ∀ b c, b ∉ f a ∨ c ∉ g b := by simp only [eq_none_iff_forall_not_mem, mem_trans, imp_iff_not_or.symm] push_neg exact forall_swap #align pequiv.trans_eq_none PEquiv.trans_eq_none @[simp] theorem refl_trans (f : α ≃. β) : (PEquiv.refl α).trans f = f := by ext; dsimp [PEquiv.trans]; rfl #align pequiv.refl_trans PEquiv.refl_trans @[simp] theorem trans_refl (f : α ≃. β) : f.trans (PEquiv.refl β) = f := by ext; dsimp [PEquiv.trans]; simp #align pequiv.trans_refl PEquiv.trans_refl protected theorem inj (f : α ≃. β) {a₁ a₂ : α} {b : β} (h₁ : b ∈ f a₁) (h₂ : b ∈ f a₂) : a₁ = a₂ := by rw [← mem_iff_mem] at *; cases h : f.symm b <;> simp_all #align pequiv.inj PEquiv.inj /-- If the domain of a `PEquiv` is `α` except a point, its forward direction is injective. -/ theorem injective_of_forall_ne_isSome (f : α ≃. β) (a₂ : α) (h : ∀ a₁ : α, a₁ ≠ a₂ → isSome (f a₁)) : Injective f := HasLeftInverse.injective ⟨fun b => Option.recOn b a₂ fun b' => Option.recOn (f.symm b') a₂ id, fun x => by classical cases hfx : f x · have : x = a₂ := not_imp_comm.1 (h x) (hfx.symm ▸ by simp) simp [this] · dsimp only rw [(eq_some_iff f).2 hfx] rfl⟩ #align pequiv.injective_of_forall_ne_is_some PEquiv.injective_of_forall_ne_isSome /-- If the domain of a `PEquiv` is all of `α`, its forward direction is injective. -/ theorem injective_of_forall_isSome {f : α ≃. β} (h : ∀ a : α, isSome (f a)) : Injective f := (Classical.em (Nonempty α)).elim (fun hn => injective_of_forall_ne_isSome f (Classical.choice hn) fun a _ => h a) fun hn x => (hn ⟨x⟩).elim #align pequiv.injective_of_forall_is_some PEquiv.injective_of_forall_isSome section OfSet variable (s : Set α) [DecidablePred (· ∈ s)] /-- Creates a `PEquiv` that is the identity on `s`, and `none` outside of it. -/ def ofSet (s : Set α) [DecidablePred (· ∈ s)] : α ≃. α where toFun a := if a ∈ s then some a else none invFun a := if a ∈ s then some a else none inv a b := by dsimp only split_ifs with hb ha ha · simp [eq_comm] · simp [ne_of_mem_of_not_mem hb ha] · simp [ne_of_mem_of_not_mem ha hb] · simp #align pequiv.of_set PEquiv.ofSet theorem mem_ofSet_self_iff {s : Set α} [DecidablePred (· ∈ s)] {a : α} : a ∈ ofSet s a ↔ a ∈ s := by dsimp [ofSet]; split_ifs <;> simp [*] #align pequiv.mem_of_set_self_iff PEquiv.mem_ofSet_self_iff theorem mem_ofSet_iff {s : Set α} [DecidablePred (· ∈ s)] {a b : α} : a ∈ ofSet s b ↔ a = b ∧ a ∈ s := by dsimp [ofSet] split_ifs with h · simp only [mem_def, eq_comm, some.injEq, iff_self_and] rintro rfl exact h · simp only [mem_def, false_iff, not_and] rintro rfl exact h #align pequiv.mem_of_set_iff PEquiv.mem_ofSet_iff @[simp] theorem ofSet_eq_some_iff {s : Set α} {_ : DecidablePred (· ∈ s)} {a b : α} : ofSet s b = some a ↔ a = b ∧ a ∈ s := mem_ofSet_iff #align pequiv.of_set_eq_some_iff PEquiv.ofSet_eq_some_iff theorem ofSet_eq_some_self_iff {s : Set α} {_ : DecidablePred (· ∈ s)} {a : α} : ofSet s a = some a ↔ a ∈ s := mem_ofSet_self_iff #align pequiv.of_set_eq_some_self_iff PEquiv.ofSet_eq_some_self_iff @[simp] theorem ofSet_symm : (ofSet s).symm = ofSet s := rfl #align pequiv.of_set_symm PEquiv.ofSet_symm @[simp] theorem ofSet_univ : ofSet Set.univ = PEquiv.refl α := rfl #align pequiv.of_set_univ PEquiv.ofSet_univ @[simp] theorem ofSet_eq_refl {s : Set α} [DecidablePred (· ∈ s)] : ofSet s = PEquiv.refl α ↔ s = Set.univ := ⟨fun h => by rw [Set.eq_univ_iff_forall] intro rw [← mem_ofSet_self_iff, h] exact rfl, fun h => by simp only [← ofSet_univ, h]⟩ #align pequiv.of_set_eq_refl PEquiv.ofSet_eq_refl end OfSet theorem symm_trans_rev (f : α ≃. β) (g : β ≃. γ) : (f.trans g).symm = g.symm.trans f.symm := rfl #align pequiv.symm_trans_rev PEquiv.symm_trans_rev theorem self_trans_symm (f : α ≃. β) : f.trans f.symm = ofSet { a | (f a).isSome } := by ext dsimp [PEquiv.trans] simp only [eq_some_iff f, Option.isSome_iff_exists, Option.mem_def, bind_eq_some', ofSet_eq_some_iff] constructor · rintro ⟨b, hb₁, hb₂⟩ exact ⟨PEquiv.inj _ hb₂ hb₁, b, hb₂⟩ · simp (config := { contextual := true }) #align pequiv.self_trans_symm PEquiv.self_trans_symm theorem symm_trans_self (f : α ≃. β) : f.symm.trans f = ofSet { b | (f.symm b).isSome } := symm_injective <| by simp [symm_trans_rev, self_trans_symm, -symm_symm] #align pequiv.symm_trans_self PEquiv.symm_trans_self theorem trans_symm_eq_iff_forall_isSome {f : α ≃. β} : f.trans f.symm = PEquiv.refl α ↔ ∀ a, isSome (f a) := by rw [self_trans_symm, ofSet_eq_refl, Set.eq_univ_iff_forall]; rfl #align pequiv.trans_symm_eq_iff_forall_is_some PEquiv.trans_symm_eq_iff_forall_isSome instance instBotPEquiv : Bot (α ≃. β) := ⟨{ toFun := fun _ => none invFun := fun _ => none inv := by simp }⟩ instance : Inhabited (α ≃. β) := ⟨⊥⟩ @[simp] theorem bot_apply (a : α) : (⊥ : α ≃. β) a = none := rfl #align pequiv.bot_apply PEquiv.bot_apply @[simp] theorem symm_bot : (⊥ : α ≃. β).symm = ⊥ := rfl #align pequiv.symm_bot PEquiv.symm_bot @[simp] theorem trans_bot (f : α ≃. β) : f.trans (⊥ : β ≃. γ) = ⊥ := by ext; dsimp [PEquiv.trans]; simp #align pequiv.trans_bot PEquiv.trans_bot @[simp] theorem bot_trans (f : β ≃. γ) : (⊥ : α ≃. β).trans f = ⊥ := by ext; dsimp [PEquiv.trans]; simp #align pequiv.bot_trans PEquiv.bot_trans theorem isSome_symm_get (f : α ≃. β) {a : α} (h : isSome (f a)) : isSome (f.symm (Option.get _ h)) := isSome_iff_exists.2 ⟨a, by rw [f.eq_some_iff, some_get]⟩ #align pequiv.is_some_symm_get PEquiv.isSome_symm_get section Single variable [DecidableEq α] [DecidableEq β] [DecidableEq γ] /-- Create a `PEquiv` which sends `a` to `b` and `b` to `a`, but is otherwise `none`. -/ def single (a : α) (b : β) : α ≃. β where toFun x := if x = a then some b else none invFun x := if x = b then some a else none inv x y := by dsimp only split_ifs with h1 h2 · simp [*] · simp only [mem_def, some.injEq, iff_false] at * exact Ne.symm h2 · simp only [mem_def, some.injEq, false_iff] at * exact Ne.symm h1 · simp #align pequiv.single PEquiv.single theorem mem_single (a : α) (b : β) : b ∈ single a b a := if_pos rfl #align pequiv.mem_single PEquiv.mem_single theorem mem_single_iff (a₁ a₂ : α) (b₁ b₂ : β) : b₁ ∈ single a₂ b₂ a₁ ↔ a₁ = a₂ ∧ b₁ = b₂ := by dsimp [single]; split_ifs <;> simp [*, eq_comm] #align pequiv.mem_single_iff PEquiv.mem_single_iff @[simp] theorem symm_single (a : α) (b : β) : (single a b).symm = single b a := rfl #align pequiv.symm_single PEquiv.symm_single @[simp] theorem single_apply (a : α) (b : β) : single a b a = some b := if_pos rfl #align pequiv.single_apply PEquiv.single_apply theorem single_apply_of_ne {a₁ a₂ : α} (h : a₁ ≠ a₂) (b : β) : single a₁ b a₂ = none := if_neg h.symm #align pequiv.single_apply_of_ne PEquiv.single_apply_of_ne theorem single_trans_of_mem (a : α) {b : β} {c : γ} {f : β ≃. γ} (h : c ∈ f b) : (single a b).trans f = single a c := by ext dsimp [single, PEquiv.trans] split_ifs <;> simp_all #align pequiv.single_trans_of_mem PEquiv.single_trans_of_mem theorem trans_single_of_mem {a : α} {b : β} (c : γ) {f : α ≃. β} (h : b ∈ f a) : f.trans (single b c) = single a c := symm_injective <| single_trans_of_mem _ ((mem_iff_mem f).2 h) #align pequiv.trans_single_of_mem PEquiv.trans_single_of_mem @[simp] theorem single_trans_single (a : α) (b : β) (c : γ) : (single a b).trans (single b c) = single a c := single_trans_of_mem _ (mem_single _ _) #align pequiv.single_trans_single PEquiv.single_trans_single @[simp]
Mathlib/Data/PEquiv.lean
388
391
theorem single_subsingleton_eq_refl [Subsingleton α] (a b : α) : single a b = PEquiv.refl α := by
ext i j dsimp [single] rw [if_pos (Subsingleton.elim i a), Subsingleton.elim i j, Subsingleton.elim b j]
/- Copyright (c) 2023 Luke Mantle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Luke Mantle -/ import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Data.Nat.Factorial.DoubleFactorial #align_import ring_theory.polynomial.hermite.basic from "leanprover-community/mathlib"@"938d3db9c278f8a52c0f964a405806f0f2b09b74" /-! # Hermite polynomials This file defines `Polynomial.hermite n`, the `n`th probabilists' Hermite polynomial. ## Main definitions * `Polynomial.hermite n`: the `n`th probabilists' Hermite polynomial, defined recursively as a `Polynomial ℤ` ## Results * `Polynomial.hermite_succ`: the recursion `hermite (n+1) = (x - d/dx) (hermite n)` * `Polynomial.coeff_hermite_explicit`: a closed formula for (nonvanishing) coefficients in terms of binomial coefficients and double factorials. * `Polynomial.coeff_hermite_of_odd_add`: for `n`,`k` where `n+k` is odd, `(hermite n).coeff k` is zero. * `Polynomial.coeff_hermite_of_even_add`: a closed formula for `(hermite n).coeff k` when `n+k` is even, equivalent to `Polynomial.coeff_hermite_explicit`. * `Polynomial.monic_hermite`: for all `n`, `hermite n` is monic. * `Polynomial.degree_hermite`: for all `n`, `hermite n` has degree `n`. ## References * [Hermite Polynomials](https://en.wikipedia.org/wiki/Hermite_polynomials) -/ noncomputable section open Polynomial namespace Polynomial /-- the probabilists' Hermite polynomials. -/ noncomputable def hermite : ℕ → Polynomial ℤ | 0 => 1 | n + 1 => X * hermite n - derivative (hermite n) #align polynomial.hermite Polynomial.hermite /-- The recursion `hermite (n+1) = (x - d/dx) (hermite n)` -/ @[simp] theorem hermite_succ (n : ℕ) : hermite (n + 1) = X * hermite n - derivative (hermite n) := by rw [hermite] #align polynomial.hermite_succ Polynomial.hermite_succ theorem hermite_eq_iterate (n : ℕ) : hermite n = (fun p => X * p - derivative p)^[n] 1 := by induction' n with n ih · rfl · rw [Function.iterate_succ_apply', ← ih, hermite_succ] #align polynomial.hermite_eq_iterate Polynomial.hermite_eq_iterate @[simp] theorem hermite_zero : hermite 0 = C 1 := rfl #align polynomial.hermite_zero Polynomial.hermite_zero -- Porting note (#10618): There was initially @[simp] on this line but it was removed -- because simp can prove this theorem theorem hermite_one : hermite 1 = X := by rw [hermite_succ, hermite_zero] simp only [map_one, mul_one, derivative_one, sub_zero] #align polynomial.hermite_one Polynomial.hermite_one /-! ### Lemmas about `Polynomial.coeff` -/ section coeff theorem coeff_hermite_succ_zero (n : ℕ) : coeff (hermite (n + 1)) 0 = -coeff (hermite n) 1 := by simp [coeff_derivative] #align polynomial.coeff_hermite_succ_zero Polynomial.coeff_hermite_succ_zero
Mathlib/RingTheory/Polynomial/Hermite/Basic.lean
86
89
theorem coeff_hermite_succ_succ (n k : ℕ) : coeff (hermite (n + 1)) (k + 1) = coeff (hermite n) k - (k + 2) * coeff (hermite n) (k + 2) := by
rw [hermite_succ, coeff_sub, coeff_X_mul, coeff_derivative, mul_comm] norm_cast
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Julian Kuelshammer, Heather Macbeth, Mitchell Lee -/ import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Tactic.LinearCombination #align_import ring_theory.polynomial.chebyshev from "leanprover-community/mathlib"@"d774451114d6045faeb6751c396bea1eb9058946" /-! # Chebyshev polynomials The Chebyshev polynomials are families of polynomials indexed by `ℤ`, with integral coefficients. ## Main definitions * `Polynomial.Chebyshev.T`: the Chebyshev polynomials of the first kind. * `Polynomial.Chebyshev.U`: the Chebyshev polynomials of the second kind. ## Main statements * The formal derivative of the Chebyshev polynomials of the first kind is a scalar multiple of the Chebyshev polynomials of the second kind. * `Polynomial.Chebyshev.mul_T`, twice the product of the `m`-th and `k`-th Chebyshev polynomials of the first kind is the sum of the `m + k`-th and `m - k`-th Chebyshev polynomials of the first kind. * `Polynomial.Chebyshev.T_mul`, the `(m * n)`-th Chebyshev polynomial of the first kind is the composition of the `m`-th and `n`-th Chebyshev polynomials of the first kind. ## Implementation details Since Chebyshev polynomials have interesting behaviour over the complex numbers and modulo `p`, we define them to have coefficients in an arbitrary commutative ring, even though technically `ℤ` would suffice. The benefit of allowing arbitrary coefficient rings, is that the statements afterwards are clean, and do not have `map (Int.castRingHom R)` interfering all the time. ## References [Lionel Ponton, _Roots of the Chebyshev polynomials: A purely algebraic approach_] [ponton2020chebyshev] ## TODO * Redefine and/or relate the definition of Chebyshev polynomials to `LinearRecurrence`. * Add explicit formula involving square roots for Chebyshev polynomials * Compute zeroes and extrema of Chebyshev polynomials. * Prove that the roots of the Chebyshev polynomials (except 0) are irrational. * Prove minimax properties of Chebyshev polynomials. -/ namespace Polynomial.Chebyshev set_option linter.uppercaseLean3 false -- `T` `U` `X` open Polynomial variable (R S : Type*) [CommRing R] [CommRing S] /-- `T n` is the `n`-th Chebyshev polynomial of the first kind. -/ -- Well-founded definitions are now irreducible by default; -- as this was implemented before this change, -- we just set it back to semireducible to avoid needing to change any proofs. @[semireducible] noncomputable def T : ℤ → R[X] | 0 => 1 | 1 => X | (n : ℕ) + 2 => 2 * X * T (n + 1) - T n | -((n : ℕ) + 1) => 2 * X * T (-n) - T (-n + 1) termination_by n => Int.natAbs n + Int.natAbs (n - 1) #align polynomial.chebyshev.T Polynomial.Chebyshev.T /-- Induction principle used for proving facts about Chebyshev polynomials. -/ @[elab_as_elim] protected theorem induct (motive : ℤ → Prop) (zero : motive 0) (one : motive 1) (add_two : ∀ (n : ℕ), motive (↑n + 1) → motive ↑n → motive (↑n + 2)) (neg_add_one : ∀ (n : ℕ), motive (-↑n) → motive (-↑n + 1) → motive (-↑n - 1)) : ∀ (a : ℤ), motive a := T.induct Unit motive zero one add_two fun n hn hnm => by simpa only [Int.negSucc_eq, neg_add] using neg_add_one n hn hnm @[simp] theorem T_add_two : ∀ n, T R (n + 2) = 2 * X * T R (n + 1) - T R n | (k : ℕ) => T.eq_3 R k | -(k + 1 : ℕ) => by linear_combination (norm := (simp [Int.negSucc_eq]; ring_nf)) T.eq_4 R k #align polynomial.chebyshev.T_add_two Polynomial.Chebyshev.T_add_two theorem T_add_one (n : ℤ) : T R (n + 1) = 2 * X * T R n - T R (n - 1) := by linear_combination (norm := ring_nf) T_add_two R (n - 1)
Mathlib/RingTheory/Polynomial/Chebyshev.lean
93
94
theorem T_sub_two (n : ℤ) : T R (n - 2) = 2 * X * T R (n - 1) - T R n := by
linear_combination (norm := ring_nf) T_add_two R (n - 2)
/- 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.Topology.Order.Basic import Mathlib.Data.Set.Pointwise.Basic /-! # Neighborhoods to the left and to the right on an `OrderTopology` We've seen some properties of left and right neighborhood of a point in an `OrderClosedTopology`. In an `OrderTopology`, such neighborhoods can be characterized as the sets containing suitable intervals to the right or to the left of `a`. We give now these characterizations. -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) variable {α β γ : Type*} section LinearOrder variable [TopologicalSpace α] [LinearOrder α] section OrderTopology variable [OrderTopology α] open List in /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `(a, +∞)`; 1. `s` is a neighborhood of `a` within `(a, b]`; 2. `s` is a neighborhood of `a` within `(a, b)`; 3. `s` includes `(a, u)` for some `u ∈ (a, b]`; 4. `s` includes `(a, u)` for some `u > a`. -/ theorem TFAE_mem_nhdsWithin_Ioi {a b : α} (hab : a < b) (s : Set α) : TFAE [s ∈ 𝓝[>] a, s ∈ 𝓝[Ioc a b] a, s ∈ 𝓝[Ioo a b] a, ∃ u ∈ Ioc a b, Ioo a u ⊆ s, ∃ u ∈ Ioi a, Ioo a u ⊆ s] := by tfae_have 1 ↔ 2 · rw [nhdsWithin_Ioc_eq_nhdsWithin_Ioi hab] tfae_have 1 ↔ 3 · rw [nhdsWithin_Ioo_eq_nhdsWithin_Ioi hab] tfae_have 4 → 5 · exact fun ⟨u, umem, hu⟩ => ⟨u, umem.1, hu⟩ tfae_have 5 → 1 · rintro ⟨u, hau, hu⟩ exact mem_of_superset (Ioo_mem_nhdsWithin_Ioi ⟨le_refl a, hau⟩) hu tfae_have 1 → 4 · intro h rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.1 h with ⟨v, va, hv⟩ rcases exists_Ico_subset_of_mem_nhds' va hab with ⟨u, au, hu⟩ exact ⟨u, au, fun x hx => hv ⟨hu ⟨le_of_lt hx.1, hx.2⟩, hx.1⟩⟩ tfae_finish #align tfae_mem_nhds_within_Ioi TFAE_mem_nhdsWithin_Ioi theorem mem_nhdsWithin_Ioi_iff_exists_mem_Ioc_Ioo_subset {a u' : α} {s : Set α} (hu' : a < u') : s ∈ 𝓝[>] a ↔ ∃ u ∈ Ioc a u', Ioo a u ⊆ s := (TFAE_mem_nhdsWithin_Ioi hu' s).out 0 3 #align mem_nhds_within_Ioi_iff_exists_mem_Ioc_Ioo_subset mem_nhdsWithin_Ioi_iff_exists_mem_Ioc_Ioo_subset /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u < u'`, provided `a` is not a top element. -/ theorem mem_nhdsWithin_Ioi_iff_exists_Ioo_subset' {a u' : α} {s : Set α} (hu' : a < u') : s ∈ 𝓝[>] a ↔ ∃ u ∈ Ioi a, Ioo a u ⊆ s := (TFAE_mem_nhdsWithin_Ioi hu' s).out 0 4 #align mem_nhds_within_Ioi_iff_exists_Ioo_subset' mem_nhdsWithin_Ioi_iff_exists_Ioo_subset' theorem nhdsWithin_Ioi_basis' {a : α} (h : ∃ b, a < b) : (𝓝[>] a).HasBasis (a < ·) (Ioo a) := let ⟨_, h⟩ := h ⟨fun _ => mem_nhdsWithin_Ioi_iff_exists_Ioo_subset' h⟩ lemma nhdsWithin_Ioi_basis [NoMaxOrder α] (a : α) : (𝓝[>] a).HasBasis (a < ·) (Ioo a) := nhdsWithin_Ioi_basis' <| exists_gt a theorem nhdsWithin_Ioi_eq_bot_iff {a : α} : 𝓝[>] a = ⊥ ↔ IsTop a ∨ ∃ b, a ⋖ b := by by_cases ha : IsTop a · simp [ha, ha.isMax.Ioi_eq] · simp only [ha, false_or] rw [isTop_iff_isMax, not_isMax_iff] at ha simp only [(nhdsWithin_Ioi_basis' ha).eq_bot_iff, covBy_iff_Ioo_eq] /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u`. -/ theorem mem_nhdsWithin_Ioi_iff_exists_Ioo_subset [NoMaxOrder α] {a : α} {s : Set α} : s ∈ 𝓝[>] a ↔ ∃ u ∈ Ioi a, Ioo a u ⊆ s := let ⟨_u', hu'⟩ := exists_gt a mem_nhdsWithin_Ioi_iff_exists_Ioo_subset' hu' #align mem_nhds_within_Ioi_iff_exists_Ioo_subset mem_nhdsWithin_Ioi_iff_exists_Ioo_subset /-- The set of points which are isolated on the right is countable when the space is second-countable. -/ theorem countable_setOf_isolated_right [SecondCountableTopology α] : { x : α | 𝓝[>] x = ⊥ }.Countable := by simp only [nhdsWithin_Ioi_eq_bot_iff, setOf_or] exact (subsingleton_isTop α).countable.union countable_setOf_covBy_right /-- The set of points which are isolated on the left is countable when the space is second-countable. -/ theorem countable_setOf_isolated_left [SecondCountableTopology α] : { x : α | 𝓝[<] x = ⊥ }.Countable := countable_setOf_isolated_right (α := αᵒᵈ) /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u]` with `a < u`. -/ theorem mem_nhdsWithin_Ioi_iff_exists_Ioc_subset [NoMaxOrder α] [DenselyOrdered α] {a : α} {s : Set α} : s ∈ 𝓝[>] a ↔ ∃ u ∈ Ioi a, Ioc a u ⊆ s := by rw [mem_nhdsWithin_Ioi_iff_exists_Ioo_subset] constructor · rintro ⟨u, au, as⟩ rcases exists_between au with ⟨v, hv⟩ exact ⟨v, hv.1, fun x hx => as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ · rintro ⟨u, au, as⟩ exact ⟨u, au, Subset.trans Ioo_subset_Ioc_self as⟩ #align mem_nhds_within_Ioi_iff_exists_Ioc_subset mem_nhdsWithin_Ioi_iff_exists_Ioc_subset open List in /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b)` 1. `s` is a neighborhood of `b` within `[a, b)` 2. `s` is a neighborhood of `b` within `(a, b)` 3. `s` includes `(l, b)` for some `l ∈ [a, b)` 4. `s` includes `(l, b)` for some `l < b` -/ theorem TFAE_mem_nhdsWithin_Iio {a b : α} (h : a < b) (s : Set α) : TFAE [s ∈ 𝓝[<] b,-- 0 : `s` is a neighborhood of `b` within `(-∞, b)` s ∈ 𝓝[Ico a b] b,-- 1 : `s` is a neighborhood of `b` within `[a, b)` s ∈ 𝓝[Ioo a b] b,-- 2 : `s` is a neighborhood of `b` within `(a, b)` ∃ l ∈ Ico a b, Ioo l b ⊆ s,-- 3 : `s` includes `(l, b)` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioo l b ⊆ s] := by-- 4 : `s` includes `(l, b)` for some `l < b` simpa only [exists_prop, OrderDual.exists, dual_Ioi, dual_Ioc, dual_Ioo] using TFAE_mem_nhdsWithin_Ioi h.dual (ofDual ⁻¹' s) #align tfae_mem_nhds_within_Iio TFAE_mem_nhdsWithin_Iio theorem mem_nhdsWithin_Iio_iff_exists_mem_Ico_Ioo_subset {a l' : α} {s : Set α} (hl' : l' < a) : s ∈ 𝓝[<] a ↔ ∃ l ∈ Ico l' a, Ioo l a ⊆ s := (TFAE_mem_nhdsWithin_Iio hl' s).out 0 3 #align mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset mem_nhdsWithin_Iio_iff_exists_mem_Ico_Ioo_subset /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`, provided `a` is not a bottom element. -/ theorem mem_nhdsWithin_Iio_iff_exists_Ioo_subset' {a l' : α} {s : Set α} (hl' : l' < a) : s ∈ 𝓝[<] a ↔ ∃ l ∈ Iio a, Ioo l a ⊆ s := (TFAE_mem_nhdsWithin_Iio hl' s).out 0 4 #align mem_nhds_within_Iio_iff_exists_Ioo_subset' mem_nhdsWithin_Iio_iff_exists_Ioo_subset' /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`. -/ theorem mem_nhdsWithin_Iio_iff_exists_Ioo_subset [NoMinOrder α] {a : α} {s : Set α} : s ∈ 𝓝[<] a ↔ ∃ l ∈ Iio a, Ioo l a ⊆ s := let ⟨_, h⟩ := exists_lt a mem_nhdsWithin_Iio_iff_exists_Ioo_subset' h #align mem_nhds_within_Iio_iff_exists_Ioo_subset mem_nhdsWithin_Iio_iff_exists_Ioo_subset /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `[l, a)` with `l < a`. -/ theorem mem_nhdsWithin_Iio_iff_exists_Ico_subset [NoMinOrder α] [DenselyOrdered α] {a : α} {s : Set α} : s ∈ 𝓝[<] a ↔ ∃ l ∈ Iio a, Ico l a ⊆ s := by have : ofDual ⁻¹' s ∈ 𝓝[>] toDual a ↔ _ := mem_nhdsWithin_Ioi_iff_exists_Ioc_subset simpa only [OrderDual.exists, exists_prop, dual_Ioc] using this #align mem_nhds_within_Iio_iff_exists_Ico_subset mem_nhdsWithin_Iio_iff_exists_Ico_subset theorem nhdsWithin_Iio_basis' {a : α} (h : ∃ b, b < a) : (𝓝[<] a).HasBasis (· < a) (Ioo · a) := let ⟨_, h⟩ := h ⟨fun _ => mem_nhdsWithin_Iio_iff_exists_Ioo_subset' h⟩ theorem nhdsWithin_Iio_eq_bot_iff {a : α} : 𝓝[<] a = ⊥ ↔ IsBot a ∨ ∃ b, b ⋖ a := by convert (config := {preTransparency := .default}) nhdsWithin_Ioi_eq_bot_iff (a := OrderDual.toDual a) using 4 exact ofDual_covBy_ofDual_iff open List in /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `[a, +∞)`; 1. `s` is a neighborhood of `a` within `[a, b]`; 2. `s` is a neighborhood of `a` within `[a, b)`; 3. `s` includes `[a, u)` for some `u ∈ (a, b]`; 4. `s` includes `[a, u)` for some `u > a`. -/ theorem TFAE_mem_nhdsWithin_Ici {a b : α} (hab : a < b) (s : Set α) : TFAE [s ∈ 𝓝[≥] a, s ∈ 𝓝[Icc a b] a, s ∈ 𝓝[Ico a b] a, ∃ u ∈ Ioc a b, Ico a u ⊆ s, ∃ u ∈ Ioi a , Ico a u ⊆ s] := by tfae_have 1 ↔ 2 · rw [nhdsWithin_Icc_eq_nhdsWithin_Ici hab] tfae_have 1 ↔ 3 · rw [nhdsWithin_Ico_eq_nhdsWithin_Ici hab] tfae_have 1 ↔ 5 · exact (nhdsWithin_Ici_basis' ⟨b, hab⟩).mem_iff tfae_have 4 → 5 · exact fun ⟨u, umem, hu⟩ => ⟨u, umem.1, hu⟩ tfae_have 5 → 4 · rintro ⟨u, hua, hus⟩ exact ⟨min u b, ⟨lt_min hua hab, min_le_right _ _⟩, (Ico_subset_Ico_right <| min_le_left _ _).trans hus⟩ tfae_finish #align tfae_mem_nhds_within_Ici TFAE_mem_nhdsWithin_Ici theorem mem_nhdsWithin_Ici_iff_exists_mem_Ioc_Ico_subset {a u' : α} {s : Set α} (hu' : a < u') : s ∈ 𝓝[≥] a ↔ ∃ u ∈ Ioc a u', Ico a u ⊆ s := (TFAE_mem_nhdsWithin_Ici hu' s).out 0 3 (by norm_num) (by norm_num) #align mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset mem_nhdsWithin_Ici_iff_exists_mem_Ioc_Ico_subset /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u < u'`, provided `a` is not a top element. -/ theorem mem_nhdsWithin_Ici_iff_exists_Ico_subset' {a u' : α} {s : Set α} (hu' : a < u') : s ∈ 𝓝[≥] a ↔ ∃ u ∈ Ioi a, Ico a u ⊆ s := (TFAE_mem_nhdsWithin_Ici hu' s).out 0 4 (by norm_num) (by norm_num) #align mem_nhds_within_Ici_iff_exists_Ico_subset' mem_nhdsWithin_Ici_iff_exists_Ico_subset' /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u`. -/ theorem mem_nhdsWithin_Ici_iff_exists_Ico_subset [NoMaxOrder α] {a : α} {s : Set α} : s ∈ 𝓝[≥] a ↔ ∃ u ∈ Ioi a, Ico a u ⊆ s := let ⟨_, hu'⟩ := exists_gt a mem_nhdsWithin_Ici_iff_exists_Ico_subset' hu' #align mem_nhds_within_Ici_iff_exists_Ico_subset mem_nhdsWithin_Ici_iff_exists_Ico_subset theorem nhdsWithin_Ici_basis_Ico [NoMaxOrder α] (a : α) : (𝓝[≥] a).HasBasis (fun u => a < u) (Ico a) := ⟨fun _ => mem_nhdsWithin_Ici_iff_exists_Ico_subset⟩ #align nhds_within_Ici_basis_Ico nhdsWithin_Ici_basis_Ico /-- The filter of right neighborhoods has a basis of closed intervals. -/ theorem nhdsWithin_Ici_basis_Icc [NoMaxOrder α] [DenselyOrdered α] {a : α} : (𝓝[≥] a).HasBasis (a < ·) (Icc a) := (nhdsWithin_Ici_basis _).to_hasBasis (fun _u hu ↦ (exists_between hu).imp fun _v hv ↦ hv.imp_right Icc_subset_Ico_right) fun u hu ↦ ⟨u, hu, Ico_subset_Icc_self⟩ /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u]` with `a < u`. -/ theorem mem_nhdsWithin_Ici_iff_exists_Icc_subset [NoMaxOrder α] [DenselyOrdered α] {a : α} {s : Set α} : s ∈ 𝓝[≥] a ↔ ∃ u, a < u ∧ Icc a u ⊆ s := nhdsWithin_Ici_basis_Icc.mem_iff #align mem_nhds_within_Ici_iff_exists_Icc_subset mem_nhdsWithin_Ici_iff_exists_Icc_subset open List in /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b]` 1. `s` is a neighborhood of `b` within `[a, b]` 2. `s` is a neighborhood of `b` within `(a, b]` 3. `s` includes `(l, b]` for some `l ∈ [a, b)` 4. `s` includes `(l, b]` for some `l < b` -/ theorem TFAE_mem_nhdsWithin_Iic {a b : α} (h : a < b) (s : Set α) : TFAE [s ∈ 𝓝[≤] b,-- 0 : `s` is a neighborhood of `b` within `(-∞, b]` s ∈ 𝓝[Icc a b] b,-- 1 : `s` is a neighborhood of `b` within `[a, b]` s ∈ 𝓝[Ioc a b] b,-- 2 : `s` is a neighborhood of `b` within `(a, b]` ∃ l ∈ Ico a b, Ioc l b ⊆ s,-- 3 : `s` includes `(l, b]` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioc l b ⊆ s] := by-- 4 : `s` includes `(l, b]` for some `l < b` simpa only [exists_prop, OrderDual.exists, dual_Ici, dual_Ioc, dual_Icc, dual_Ico] using TFAE_mem_nhdsWithin_Ici h.dual (ofDual ⁻¹' s) #align tfae_mem_nhds_within_Iic TFAE_mem_nhdsWithin_Iic theorem mem_nhdsWithin_Iic_iff_exists_mem_Ico_Ioc_subset {a l' : α} {s : Set α} (hl' : l' < a) : s ∈ 𝓝[≤] a ↔ ∃ l ∈ Ico l' a, Ioc l a ⊆ s := (TFAE_mem_nhdsWithin_Iic hl' s).out 0 3 (by norm_num) (by norm_num) #align mem_nhds_within_Iic_iff_exists_mem_Ico_Ioc_subset mem_nhdsWithin_Iic_iff_exists_mem_Ico_Ioc_subset /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`, provided `a` is not a bottom element. -/ theorem mem_nhdsWithin_Iic_iff_exists_Ioc_subset' {a l' : α} {s : Set α} (hl' : l' < a) : s ∈ 𝓝[≤] a ↔ ∃ l ∈ Iio a, Ioc l a ⊆ s := (TFAE_mem_nhdsWithin_Iic hl' s).out 0 4 (by norm_num) (by norm_num) #align mem_nhds_within_Iic_iff_exists_Ioc_subset' mem_nhdsWithin_Iic_iff_exists_Ioc_subset' /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`. -/ theorem mem_nhdsWithin_Iic_iff_exists_Ioc_subset [NoMinOrder α] {a : α} {s : Set α} : s ∈ 𝓝[≤] a ↔ ∃ l ∈ Iio a, Ioc l a ⊆ s := let ⟨_, hl'⟩ := exists_lt a mem_nhdsWithin_Iic_iff_exists_Ioc_subset' hl' #align mem_nhds_within_Iic_iff_exists_Ioc_subset mem_nhdsWithin_Iic_iff_exists_Ioc_subset /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `[l, a]` with `l < a`. -/ theorem mem_nhdsWithin_Iic_iff_exists_Icc_subset [NoMinOrder α] [DenselyOrdered α] {a : α} {s : Set α} : s ∈ 𝓝[≤] a ↔ ∃ l, l < a ∧ Icc l a ⊆ s := calc s ∈ 𝓝[≤] a ↔ ofDual ⁻¹' s ∈ 𝓝[≥] (toDual a) := Iff.rfl _ ↔ ∃ u : α, toDual a < toDual u ∧ Icc (toDual a) (toDual u) ⊆ ofDual ⁻¹' s := mem_nhdsWithin_Ici_iff_exists_Icc_subset _ ↔ ∃ l, l < a ∧ Icc l a ⊆ s := by simp only [dual_Icc]; rfl #align mem_nhds_within_Iic_iff_exists_Icc_subset mem_nhdsWithin_Iic_iff_exists_Icc_subset /-- The filter of left neighborhoods has a basis of closed intervals. -/ theorem nhdsWithin_Iic_basis_Icc [NoMinOrder α] [DenselyOrdered α] {a : α} : (𝓝[≤] a).HasBasis (· < a) (Icc · a) := ⟨fun _ ↦ mem_nhdsWithin_Iic_iff_exists_Icc_subset⟩ end OrderTopology end LinearOrder section LinearOrderedAddCommGroup variable [TopologicalSpace α] [LinearOrderedAddCommGroup α] [OrderTopology α] variable {l : Filter β} {f g : β → α} theorem nhds_eq_iInf_abs_sub (a : α) : 𝓝 a = ⨅ r > 0, 𝓟 { b | |a - b| < r } := by simp only [nhds_eq_order, abs_lt, setOf_and, ← inf_principal, iInf_inf_eq] refine (congr_arg₂ _ ?_ ?_).trans (inf_comm ..) · refine (Equiv.subLeft a).iInf_congr fun x => ?_; simp [Ioi] · refine (Equiv.subRight a).iInf_congr fun x => ?_; simp [Iio] #align nhds_eq_infi_abs_sub nhds_eq_iInf_abs_sub theorem orderTopology_of_nhds_abs {α : Type*} [TopologicalSpace α] [LinearOrderedAddCommGroup α] (h_nhds : ∀ a : α, 𝓝 a = ⨅ r > 0, 𝓟 { b | |a - b| < r }) : OrderTopology α := by refine ⟨TopologicalSpace.ext_nhds fun a => ?_⟩ rw [h_nhds] letI := Preorder.topology α; letI : OrderTopology α := ⟨rfl⟩ exact (nhds_eq_iInf_abs_sub a).symm #align order_topology_of_nhds_abs orderTopology_of_nhds_abs theorem LinearOrderedAddCommGroup.tendsto_nhds {x : Filter β} {a : α} : Tendsto f x (𝓝 a) ↔ ∀ ε > (0 : α), ∀ᶠ b in x, |f b - a| < ε := by simp [nhds_eq_iInf_abs_sub, abs_sub_comm a] #align linear_ordered_add_comm_group.tendsto_nhds LinearOrderedAddCommGroup.tendsto_nhds theorem eventually_abs_sub_lt (a : α) {ε : α} (hε : 0 < ε) : ∀ᶠ x in 𝓝 a, |x - a| < ε := (nhds_eq_iInf_abs_sub a).symm ▸ mem_iInf_of_mem ε (mem_iInf_of_mem hε <| by simp only [abs_sub_comm, mem_principal_self]) #align eventually_abs_sub_lt eventually_abs_sub_lt /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `C` and `g` tends to `atTop` then `f + g` tends to `atTop`. -/
Mathlib/Topology/Order/LeftRightNhds.lean
337
342
theorem Filter.Tendsto.add_atTop {C : α} (hf : Tendsto f l (𝓝 C)) (hg : Tendsto g l atTop) : Tendsto (fun x => f x + g x) l atTop := by
nontriviality α obtain ⟨C', hC'⟩ : ∃ C', C' < C := exists_lt C refine tendsto_atTop_add_left_of_le' _ C' ?_ hg exact (hf.eventually (lt_mem_nhds hC')).mono fun x => le_of_lt
/- 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.Data.Rat.Encodable import Mathlib.Data.Real.EReal import Mathlib.Topology.Instances.ENNReal import Mathlib.Topology.Order.MonotoneContinuity #align_import topology.instances.ereal from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Topological structure on `EReal` We endow `EReal` with the order topology, and prove basic properties of this topology. ## Main results * `Real.toEReal : ℝ → EReal` is an open embedding * `ENNReal.toEReal : ℝ≥0∞ → EReal` is a closed embedding * The addition on `EReal` is continuous except at `(⊥, ⊤)` and at `(⊤, ⊥)`. * Negation is a homeomorphism on `EReal`. ## Implementation Most proofs are adapted from the corresponding proofs on `ℝ≥0∞`. -/ noncomputable section open scoped Classical open Set Filter Metric TopologicalSpace Topology open scoped ENNReal NNReal Filter variable {α : Type*} [TopologicalSpace α] namespace EReal instance : TopologicalSpace EReal := Preorder.topology EReal instance : OrderTopology EReal := ⟨rfl⟩ instance : T5Space EReal := inferInstance instance : T2Space EReal := inferInstance lemma denseRange_ratCast : DenseRange (fun r : ℚ ↦ ((r : ℝ) : EReal)) := dense_of_exists_between fun _ _ h => exists_range_iff.2 <| exists_rat_btwn_of_lt h instance : SecondCountableTopology EReal := have : SeparableSpace EReal := ⟨⟨_, countable_range _, denseRange_ratCast⟩⟩ .of_separableSpace_orderTopology _ /-! ### Real coercion -/ theorem embedding_coe : Embedding ((↑) : ℝ → EReal) := coe_strictMono.embedding_of_ordConnected <| by rw [range_coe_eq_Ioo]; exact ordConnected_Ioo #align ereal.embedding_coe EReal.embedding_coe theorem openEmbedding_coe : OpenEmbedding ((↑) : ℝ → EReal) := ⟨embedding_coe, by simp only [range_coe_eq_Ioo, isOpen_Ioo]⟩ #align ereal.open_embedding_coe EReal.openEmbedding_coe @[norm_cast] theorem tendsto_coe {α : Type*} {f : Filter α} {m : α → ℝ} {a : ℝ} : Tendsto (fun a => (m a : EReal)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) := embedding_coe.tendsto_nhds_iff.symm #align ereal.tendsto_coe EReal.tendsto_coe theorem _root_.continuous_coe_real_ereal : Continuous ((↑) : ℝ → EReal) := embedding_coe.continuous #align continuous_coe_real_ereal continuous_coe_real_ereal theorem continuous_coe_iff {f : α → ℝ} : (Continuous fun a => (f a : EReal)) ↔ Continuous f := embedding_coe.continuous_iff.symm #align ereal.continuous_coe_iff EReal.continuous_coe_iff theorem nhds_coe {r : ℝ} : 𝓝 (r : EReal) = (𝓝 r).map (↑) := (openEmbedding_coe.map_nhds_eq r).symm #align ereal.nhds_coe EReal.nhds_coe theorem nhds_coe_coe {r p : ℝ} : 𝓝 ((r : EReal), (p : EReal)) = (𝓝 (r, p)).map fun p : ℝ × ℝ => (↑p.1, ↑p.2) := ((openEmbedding_coe.prod openEmbedding_coe).map_nhds_eq (r, p)).symm #align ereal.nhds_coe_coe EReal.nhds_coe_coe theorem tendsto_toReal {a : EReal} (ha : a ≠ ⊤) (h'a : a ≠ ⊥) : Tendsto EReal.toReal (𝓝 a) (𝓝 a.toReal) := by lift a to ℝ using ⟨ha, h'a⟩ rw [nhds_coe, tendsto_map'_iff] exact tendsto_id #align ereal.tendsto_to_real EReal.tendsto_toReal theorem continuousOn_toReal : ContinuousOn EReal.toReal ({⊥, ⊤}ᶜ : Set EReal) := fun _a ha => ContinuousAt.continuousWithinAt (tendsto_toReal (mt Or.inr ha) (mt Or.inl ha)) #align ereal.continuous_on_to_real EReal.continuousOn_toReal /-- The set of finite `EReal` numbers is homeomorphic to `ℝ`. -/ def neBotTopHomeomorphReal : ({⊥, ⊤}ᶜ : Set EReal) ≃ₜ ℝ where toEquiv := neTopBotEquivReal continuous_toFun := continuousOn_iff_continuous_restrict.1 continuousOn_toReal continuous_invFun := continuous_coe_real_ereal.subtype_mk _ #align ereal.ne_bot_top_homeomorph_real EReal.neBotTopHomeomorphReal /-! ### ennreal coercion -/ theorem embedding_coe_ennreal : Embedding ((↑) : ℝ≥0∞ → EReal) := coe_ennreal_strictMono.embedding_of_ordConnected <| by rw [range_coe_ennreal]; exact ordConnected_Ici #align ereal.embedding_coe_ennreal EReal.embedding_coe_ennreal theorem closedEmbedding_coe_ennreal : ClosedEmbedding ((↑) : ℝ≥0∞ → EReal) := ⟨embedding_coe_ennreal, by rw [range_coe_ennreal]; exact isClosed_Ici⟩ @[norm_cast] theorem tendsto_coe_ennreal {α : Type*} {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} : Tendsto (fun a => (m a : EReal)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) := embedding_coe_ennreal.tendsto_nhds_iff.symm #align ereal.tendsto_coe_ennreal EReal.tendsto_coe_ennreal theorem _root_.continuous_coe_ennreal_ereal : Continuous ((↑) : ℝ≥0∞ → EReal) := embedding_coe_ennreal.continuous #align continuous_coe_ennreal_ereal continuous_coe_ennreal_ereal theorem continuous_coe_ennreal_iff {f : α → ℝ≥0∞} : (Continuous fun a => (f a : EReal)) ↔ Continuous f := embedding_coe_ennreal.continuous_iff.symm #align ereal.continuous_coe_ennreal_iff EReal.continuous_coe_ennreal_iff /-! ### Neighborhoods of infinity -/ theorem nhds_top : 𝓝 (⊤ : EReal) = ⨅ (a) (_ : a ≠ ⊤), 𝓟 (Ioi a) := nhds_top_order.trans <| by simp only [lt_top_iff_ne_top] #align ereal.nhds_top EReal.nhds_top nonrec theorem nhds_top_basis : (𝓝 (⊤ : EReal)).HasBasis (fun _ : ℝ ↦ True) (Ioi ·) := by refine nhds_top_basis.to_hasBasis (fun x hx => ?_) fun _ _ ↦ ⟨_, coe_lt_top _, Subset.rfl⟩ rcases exists_rat_btwn_of_lt hx with ⟨y, hxy, -⟩ exact ⟨_, trivial, Ioi_subset_Ioi hxy.le⟩ theorem nhds_top' : 𝓝 (⊤ : EReal) = ⨅ a : ℝ, 𝓟 (Ioi ↑a) := nhds_top_basis.eq_iInf #align ereal.nhds_top' EReal.nhds_top' theorem mem_nhds_top_iff {s : Set EReal} : s ∈ 𝓝 (⊤ : EReal) ↔ ∃ y : ℝ, Ioi (y : EReal) ⊆ s := nhds_top_basis.mem_iff.trans <| by simp only [true_and] #align ereal.mem_nhds_top_iff EReal.mem_nhds_top_iff theorem tendsto_nhds_top_iff_real {α : Type*} {m : α → EReal} {f : Filter α} : Tendsto m f (𝓝 ⊤) ↔ ∀ x : ℝ, ∀ᶠ a in f, ↑x < m a := nhds_top_basis.tendsto_right_iff.trans <| by simp only [true_implies, mem_Ioi] #align ereal.tendsto_nhds_top_iff_real EReal.tendsto_nhds_top_iff_real theorem nhds_bot : 𝓝 (⊥ : EReal) = ⨅ (a) (_ : a ≠ ⊥), 𝓟 (Iio a) := nhds_bot_order.trans <| by simp only [bot_lt_iff_ne_bot] #align ereal.nhds_bot EReal.nhds_bot theorem nhds_bot_basis : (𝓝 (⊥ : EReal)).HasBasis (fun _ : ℝ ↦ True) (Iio ·) := by refine nhds_bot_basis.to_hasBasis (fun x hx => ?_) fun _ _ ↦ ⟨_, bot_lt_coe _, Subset.rfl⟩ rcases exists_rat_btwn_of_lt hx with ⟨y, -, hxy⟩ exact ⟨_, trivial, Iio_subset_Iio hxy.le⟩ theorem nhds_bot' : 𝓝 (⊥ : EReal) = ⨅ a : ℝ, 𝓟 (Iio ↑a) := nhds_bot_basis.eq_iInf #align ereal.nhds_bot' EReal.nhds_bot' theorem mem_nhds_bot_iff {s : Set EReal} : s ∈ 𝓝 (⊥ : EReal) ↔ ∃ y : ℝ, Iio (y : EReal) ⊆ s := nhds_bot_basis.mem_iff.trans <| by simp only [true_and] #align ereal.mem_nhds_bot_iff EReal.mem_nhds_bot_iff theorem tendsto_nhds_bot_iff_real {α : Type*} {m : α → EReal} {f : Filter α} : Tendsto m f (𝓝 ⊥) ↔ ∀ x : ℝ, ∀ᶠ a in f, m a < x := nhds_bot_basis.tendsto_right_iff.trans <| by simp only [true_implies, mem_Iio] #align ereal.tendsto_nhds_bot_iff_real EReal.tendsto_nhds_bot_iff_real /-! ### Continuity of addition -/ theorem continuousAt_add_coe_coe (a b : ℝ) : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (a, b) := by simp only [ContinuousAt, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (· ∘ ·), tendsto_coe, tendsto_add] #align ereal.continuous_at_add_coe_coe EReal.continuousAt_add_coe_coe theorem continuousAt_add_top_coe (a : ℝ) : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (⊤, a) := by simp only [ContinuousAt, tendsto_nhds_top_iff_real, top_add_coe] refine fun r ↦ ((lt_mem_nhds (coe_lt_top (r - (a - 1)))).prod_nhds (lt_mem_nhds <| EReal.coe_lt_coe_iff.2 <| sub_one_lt _)).mono fun _ h ↦ ?_ simpa only [← coe_add, sub_add_cancel] using add_lt_add h.1 h.2 #align ereal.continuous_at_add_top_coe EReal.continuousAt_add_top_coe theorem continuousAt_add_coe_top (a : ℝ) : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (a, ⊤) := by simpa only [add_comm, (· ∘ ·), ContinuousAt, Prod.swap] using Tendsto.comp (continuousAt_add_top_coe a) (continuous_swap.tendsto ((a : EReal), ⊤)) #align ereal.continuous_at_add_coe_top EReal.continuousAt_add_coe_top theorem continuousAt_add_top_top : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (⊤, ⊤) := by simp only [ContinuousAt, tendsto_nhds_top_iff_real, top_add_top] refine fun r ↦ ((lt_mem_nhds (coe_lt_top 0)).prod_nhds (lt_mem_nhds <| coe_lt_top r)).mono fun _ h ↦ ?_ simpa only [coe_zero, zero_add] using add_lt_add h.1 h.2 #align ereal.continuous_at_add_top_top EReal.continuousAt_add_top_top theorem continuousAt_add_bot_coe (a : ℝ) : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (⊥, a) := by simp only [ContinuousAt, tendsto_nhds_bot_iff_real, bot_add] refine fun r ↦ ((gt_mem_nhds (bot_lt_coe (r - (a + 1)))).prod_nhds (gt_mem_nhds <| EReal.coe_lt_coe_iff.2 <| lt_add_one _)).mono fun _ h ↦ ?_ simpa only [← coe_add, sub_add_cancel] using add_lt_add h.1 h.2 #align ereal.continuous_at_add_bot_coe EReal.continuousAt_add_bot_coe theorem continuousAt_add_coe_bot (a : ℝ) : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (a, ⊥) := by simpa only [add_comm, (· ∘ ·), ContinuousAt, Prod.swap] using Tendsto.comp (continuousAt_add_bot_coe a) (continuous_swap.tendsto ((a : EReal), ⊥)) #align ereal.continuous_at_add_coe_bot EReal.continuousAt_add_coe_bot theorem continuousAt_add_bot_bot : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (⊥, ⊥) := by simp only [ContinuousAt, tendsto_nhds_bot_iff_real, bot_add] refine fun r ↦ ((gt_mem_nhds (bot_lt_coe 0)).prod_nhds (gt_mem_nhds <| bot_lt_coe r)).mono fun _ h ↦ ?_ simpa only [coe_zero, zero_add] using add_lt_add h.1 h.2 #align ereal.continuous_at_add_bot_bot EReal.continuousAt_add_bot_bot /-- The addition on `EReal` is continuous except where it doesn't make sense (i.e., at `(⊥, ⊤)` and at `(⊤, ⊥)`). -/
Mathlib/Topology/Instances/EReal.lean
226
238
theorem continuousAt_add {p : EReal × EReal} (h : p.1 ≠ ⊤ ∨ p.2 ≠ ⊥) (h' : p.1 ≠ ⊥ ∨ p.2 ≠ ⊤) : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) p := by
rcases p with ⟨x, y⟩ induction x <;> induction y · exact continuousAt_add_bot_bot · exact continuousAt_add_bot_coe _ · simp at h' · exact continuousAt_add_coe_bot _ · exact continuousAt_add_coe_coe _ _ · exact continuousAt_add_coe_top _ · simp at h · exact continuousAt_add_top_coe _ · exact continuousAt_add_top_top
/- 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.) -/
Mathlib/Analysis/InnerProductSpace/TwoDim.lean
422
437
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
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Order.Monoid.Unbundled.Basic import Mathlib.Order.Lattice #align_import algebra.order.sub.defs from "leanprover-community/mathlib"@"de29c328903507bb7aff506af9135f4bdaf1849c" /-! # Ordered Subtraction This file proves lemmas relating (truncated) subtraction with an order. We provide a class `OrderedSub` stating that `a - b ≤ c ↔ a ≤ c + b`. The subtraction discussed here could both be normal subtraction in an additive group or truncated subtraction on a canonically ordered monoid (`ℕ`, `Multiset`, `PartENat`, `ENNReal`, ...) ## Implementation details `OrderedSub` is a mixin type-class, so that we can use the results in this file even in cases where we don't have a `CanonicallyOrderedAddCommMonoid` instance (even though that is our main focus). Conversely, this means we can use `CanonicallyOrderedAddCommMonoid` without necessarily having to define a subtraction. The results in this file are ordered by the type-class assumption needed to prove it. This means that similar results might not be close to each other. Furthermore, we don't prove implications if a bi-implication can be proven under the same assumptions. Lemmas using this class are named using `tsub` instead of `sub` (short for "truncated subtraction"). This is to avoid naming conflicts with similar lemmas about ordered groups. We provide a second version of most results that require `[ContravariantClass α α (+) (≤)]`. In the second version we replace this type-class assumption by explicit `AddLECancellable` assumptions. TODO: maybe we should make a multiplicative version of this, so that we can replace some identical lemmas about subtraction/division in `Ordered[Add]CommGroup` with these. TODO: generalize `Nat.le_of_le_of_sub_le_sub_right`, `Nat.sub_le_sub_right_iff`, `Nat.mul_self_sub_mul_self_eq` -/ variable {α β : Type*} /-- `OrderedSub α` means that `α` has a subtraction characterized by `a - b ≤ c ↔ a ≤ c + b`. In other words, `a - b` is the least `c` such that `a ≤ b + c`. This is satisfied both by the subtraction in additive ordered groups and by truncated subtraction in canonically ordered monoids on many specific types. -/ class OrderedSub (α : Type*) [LE α] [Add α] [Sub α] : Prop where /-- `a - b` provides a lower bound on `c` such that `a ≤ c + b`. -/ tsub_le_iff_right : ∀ a b c : α, a - b ≤ c ↔ a ≤ c + b #align has_ordered_sub OrderedSub section Add @[simp] theorem tsub_le_iff_right [LE α] [Add α] [Sub α] [OrderedSub α] {a b c : α} : a - b ≤ c ↔ a ≤ c + b := OrderedSub.tsub_le_iff_right a b c #align tsub_le_iff_right tsub_le_iff_right variable [Preorder α] [Add α] [Sub α] [OrderedSub α] {a b c d : α} /-- See `add_tsub_cancel_right` for the equality if `ContravariantClass α α (+) (≤)`. -/ theorem add_tsub_le_right : a + b - b ≤ a := tsub_le_iff_right.mpr le_rfl #align add_tsub_le_right add_tsub_le_right theorem le_tsub_add : b ≤ b - a + a := tsub_le_iff_right.mp le_rfl #align le_tsub_add le_tsub_add end Add /-! ### Preorder -/ section OrderedAddCommSemigroup section Preorder variable [Preorder α] section AddCommSemigroup variable [AddCommSemigroup α] [Sub α] [OrderedSub α] {a b c d : α} /- TODO: Most results can be generalized to [Add α] [IsSymmOp α α (· + ·)] -/ theorem tsub_le_iff_left : a - b ≤ c ↔ a ≤ b + c := by rw [tsub_le_iff_right, add_comm] #align tsub_le_iff_left tsub_le_iff_left theorem le_add_tsub : a ≤ b + (a - b) := tsub_le_iff_left.mp le_rfl #align le_add_tsub le_add_tsub /-- See `add_tsub_cancel_left` for the equality if `ContravariantClass α α (+) (≤)`. -/ theorem add_tsub_le_left : a + b - a ≤ b := tsub_le_iff_left.mpr le_rfl #align add_tsub_le_left add_tsub_le_left @[gcongr] theorem tsub_le_tsub_right (h : a ≤ b) (c : α) : a - c ≤ b - c := tsub_le_iff_left.mpr <| h.trans le_add_tsub #align tsub_le_tsub_right tsub_le_tsub_right theorem tsub_le_iff_tsub_le : a - b ≤ c ↔ a - c ≤ b := by rw [tsub_le_iff_left, tsub_le_iff_right] #align tsub_le_iff_tsub_le tsub_le_iff_tsub_le /-- See `tsub_tsub_cancel_of_le` for the equality. -/ theorem tsub_tsub_le : b - (b - a) ≤ a := tsub_le_iff_right.mpr le_add_tsub #align tsub_tsub_le tsub_tsub_le section Cov variable [CovariantClass α α (· + ·) (· ≤ ·)] @[gcongr] theorem tsub_le_tsub_left (h : a ≤ b) (c : α) : c - b ≤ c - a := tsub_le_iff_left.mpr <| le_add_tsub.trans <| add_le_add_right h _ #align tsub_le_tsub_left tsub_le_tsub_left @[gcongr] theorem tsub_le_tsub (hab : a ≤ b) (hcd : c ≤ d) : a - d ≤ b - c := (tsub_le_tsub_right hab _).trans <| tsub_le_tsub_left hcd _ #align tsub_le_tsub tsub_le_tsub theorem antitone_const_tsub : Antitone fun x => c - x := fun _ _ hxy => tsub_le_tsub rfl.le hxy #align antitone_const_tsub antitone_const_tsub /-- See `add_tsub_assoc_of_le` for the equality. -/ theorem add_tsub_le_assoc : a + b - c ≤ a + (b - c) := by rw [tsub_le_iff_left, add_left_comm] exact add_le_add_left le_add_tsub a #align add_tsub_le_assoc add_tsub_le_assoc /-- See `tsub_add_eq_add_tsub` for the equality. -/ theorem add_tsub_le_tsub_add : a + b - c ≤ a - c + b := by rw [add_comm, add_comm _ b] exact add_tsub_le_assoc #align add_tsub_le_tsub_add add_tsub_le_tsub_add theorem add_le_add_add_tsub : a + b ≤ a + c + (b - c) := by rw [add_assoc] exact add_le_add_left le_add_tsub a #align add_le_add_add_tsub add_le_add_add_tsub theorem le_tsub_add_add : a + b ≤ a - c + (b + c) := by rw [add_comm a, add_comm (a - c)] exact add_le_add_add_tsub #align le_tsub_add_add le_tsub_add_add theorem tsub_le_tsub_add_tsub : a - c ≤ a - b + (b - c) := by rw [tsub_le_iff_left, ← add_assoc, add_right_comm] exact le_add_tsub.trans (add_le_add_right le_add_tsub _) #align tsub_le_tsub_add_tsub tsub_le_tsub_add_tsub
Mathlib/Algebra/Order/Sub/Defs.lean
160
162
theorem tsub_tsub_tsub_le_tsub : c - a - (c - b) ≤ b - a := by
rw [tsub_le_iff_left, tsub_le_iff_left, add_left_comm] exact le_tsub_add.trans (add_le_add_left le_add_tsub _)
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Operations import Mathlib.Data.Fintype.Lattice import Mathlib.RingTheory.Coprime.Lemmas #align_import ring_theory.ideal.operations from "leanprover-community/mathlib"@"e7f0ddbf65bd7181a85edb74b64bdc35ba4bdc74" /-! # More operations on modules and ideals -/ assert_not_exists Basis -- See `RingTheory.Ideal.Basis` assert_not_exists Submodule.hasQuotient -- See `RingTheory.Ideal.QuotientOperations` universe u v w x open Pointwise namespace Submodule variable {R : Type u} {M : Type v} {M' F G : Type*} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] open Pointwise instance hasSMul' : SMul (Ideal R) (Submodule R M) := ⟨Submodule.map₂ (LinearMap.lsmul R M)⟩ #align submodule.has_smul' Submodule.hasSMul' /-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to apply. -/ protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J := rfl #align ideal.smul_eq_mul Ideal.smul_eq_mul variable (R M) in /-- `Module.annihilator R M` is the ideal of all elements `r : R` such that `r • M = 0`. -/ def _root_.Module.annihilator : Ideal R := LinearMap.ker (LinearMap.lsmul R M) theorem _root_.Module.mem_annihilator {r} : r ∈ Module.annihilator R M ↔ ∀ m : M, r • m = 0 := ⟨fun h ↦ (congr($h ·)), (LinearMap.ext ·)⟩ theorem _root_.LinearMap.annihilator_le_of_injective (f : M →ₗ[R] M') (hf : Function.Injective f) : Module.annihilator R M' ≤ Module.annihilator R M := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢; exact fun m ↦ hf (by rw [map_smul, h, f.map_zero]) theorem _root_.LinearMap.annihilator_le_of_surjective (f : M →ₗ[R] M') (hf : Function.Surjective f) : Module.annihilator R M ≤ Module.annihilator R M' := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢ intro m; obtain ⟨m, rfl⟩ := hf m rw [← map_smul, h, f.map_zero] theorem _root_.LinearEquiv.annihilator_eq (e : M ≃ₗ[R] M') : Module.annihilator R M = Module.annihilator R M' := (e.annihilator_le_of_surjective e.surjective).antisymm (e.annihilator_le_of_injective e.injective) /-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/ abbrev annihilator (N : Submodule R M) : Ideal R := Module.annihilator R N #align submodule.annihilator Submodule.annihilator theorem annihilator_top : (⊤ : Submodule R M).annihilator = Module.annihilator R M := topEquiv.annihilator_eq variable {I J : Ideal R} {N P : Submodule R M} theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0 : M) := by simp_rw [annihilator, Module.mem_annihilator, Subtype.forall, Subtype.ext_iff]; rfl #align submodule.mem_annihilator Submodule.mem_annihilator theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) ⊥ := mem_annihilator.trans ⟨fun H n hn => (mem_bot R).2 <| H n hn, fun H _ hn => (mem_bot R).1 <| H hn⟩ #align submodule.mem_annihilator' Submodule.mem_annihilator' theorem mem_annihilator_span (s : Set M) (r : R) : r ∈ (Submodule.span R s).annihilator ↔ ∀ n : s, r • (n : M) = 0 := by rw [Submodule.mem_annihilator] constructor · intro h n exact h _ (Submodule.subset_span n.prop) · intro h n hn refine Submodule.span_induction hn ?_ ?_ ?_ ?_ · intro x hx exact h ⟨x, hx⟩ · exact smul_zero _ · intro x y hx hy rw [smul_add, hx, hy, zero_add] · intro a x hx rw [smul_comm, hx, smul_zero] #align submodule.mem_annihilator_span Submodule.mem_annihilator_span theorem mem_annihilator_span_singleton (g : M) (r : R) : r ∈ (Submodule.span R ({g} : Set M)).annihilator ↔ r • g = 0 := by simp [mem_annihilator_span] #align submodule.mem_annihilator_span_singleton Submodule.mem_annihilator_span_singleton theorem annihilator_bot : (⊥ : Submodule R M).annihilator = ⊤ := (Ideal.eq_top_iff_one _).2 <| mem_annihilator'.2 bot_le #align submodule.annihilator_bot Submodule.annihilator_bot theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ := ⟨fun H => eq_bot_iff.2 fun (n : M) hn => (mem_bot R).2 <| one_smul R n ▸ mem_annihilator.1 ((Ideal.eq_top_iff_one _).1 H) n hn, fun H => H.symm ▸ annihilator_bot⟩ #align submodule.annihilator_eq_top_iff Submodule.annihilator_eq_top_iff theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator := fun _ hrp => mem_annihilator.2 fun n hn => mem_annihilator.1 hrp n <| h hn #align submodule.annihilator_mono Submodule.annihilator_mono theorem annihilator_iSup (ι : Sort w) (f : ι → Submodule R M) : annihilator (⨆ i, f i) = ⨅ i, annihilator (f i) := le_antisymm (le_iInf fun _ => annihilator_mono <| le_iSup _ _) fun _ H => mem_annihilator'.2 <| iSup_le fun i => have := (mem_iInf _).1 H i mem_annihilator'.1 this #align submodule.annihilator_supr Submodule.annihilator_iSup theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N := apply_mem_map₂ _ hr hn #align submodule.smul_mem_smul Submodule.smul_mem_smul theorem smul_le {P : Submodule R M} : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P := map₂_le #align submodule.smul_le Submodule.smul_le @[simp, norm_cast] lemma coe_set_smul : (I : Set R) • N = I • N := Submodule.set_smul_eq_of_le _ _ _ (fun _ _ hr hx => smul_mem_smul hr hx) (smul_le.mpr fun _ hr _ hx => mem_set_smul_of_mem_mem hr hx) @[elab_as_elim] theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N) (smul : ∀ r ∈ I, ∀ n ∈ N, p (r • n)) (add : ∀ x y, p x → p y → p (x + y)) : p x := by have H0 : p 0 := by simpa only [zero_smul] using smul 0 I.zero_mem 0 N.zero_mem refine Submodule.iSup_induction (x := x) _ H ?_ H0 add rintro ⟨i, hi⟩ m ⟨j, hj, hj'⟩ rw [← hj'] exact smul _ hi _ hj #align submodule.smul_induction_on Submodule.smul_induction_on /-- Dependent version of `Submodule.smul_induction_on`. -/ @[elab_as_elim] theorem smul_induction_on' {x : M} (hx : x ∈ I • N) {p : ∀ x, x ∈ I • N → Prop} (smul : ∀ (r : R) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r • n) (smul_mem_smul hr hn)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) : p x hx := by refine Exists.elim ?_ fun (h : x ∈ I • N) (H : p x h) => H exact smul_induction_on hx (fun a ha x hx => ⟨_, smul _ ha _ hx⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ => ⟨_, add _ _ _ _ hx hy⟩ #align submodule.smul_induction_on' Submodule.smul_induction_on' theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} : x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x := ⟨fun hx => smul_induction_on hx (fun r hri n hnm => let ⟨s, hs⟩ := mem_span_singleton.1 hnm ⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩) fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ => ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩, fun ⟨y, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩ #align submodule.mem_smul_span_singleton Submodule.mem_smul_span_singleton theorem smul_le_right : I • N ≤ N := smul_le.2 fun r _ _ => N.smul_mem r #align submodule.smul_le_right Submodule.smul_le_right theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P := map₂_le_map₂ hij hnp #align submodule.smul_mono Submodule.smul_mono theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N := map₂_le_map₂_left h #align submodule.smul_mono_left Submodule.smul_mono_left instance : CovariantClass (Ideal R) (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ => map₂_le_map₂_right⟩ @[deprecated smul_mono_right (since := "2024-03-31")] protected theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P := _root_.smul_mono_right I h #align submodule.smul_mono_right Submodule.smul_mono_right theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) : Submodule.map f I ≤ I • (⊤ : Submodule R M) := by rintro _ ⟨y, hy, rfl⟩ rw [← mul_one y, ← smul_eq_mul, f.map_smul] exact smul_mem_smul hy mem_top #align submodule.map_le_smul_top Submodule.map_le_smul_top @[simp] theorem annihilator_smul (N : Submodule R M) : annihilator N • N = ⊥ := eq_bot_iff.2 (smul_le.2 fun _ => mem_annihilator.1) #align submodule.annihilator_smul Submodule.annihilator_smul @[simp] theorem annihilator_mul (I : Ideal R) : annihilator I * I = ⊥ := annihilator_smul I #align submodule.annihilator_mul Submodule.annihilator_mul @[simp] theorem mul_annihilator (I : Ideal R) : I * annihilator I = ⊥ := by rw [mul_comm, annihilator_mul] #align submodule.mul_annihilator Submodule.mul_annihilator variable (I J N P) @[simp] theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ := map₂_bot_right _ _ #align submodule.smul_bot Submodule.smul_bot @[simp] theorem bot_smul : (⊥ : Ideal R) • N = ⊥ := map₂_bot_left _ _ #align submodule.bot_smul Submodule.bot_smul @[simp] theorem top_smul : (⊤ : Ideal R) • N = N := le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri #align submodule.top_smul Submodule.top_smul theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P := map₂_sup_right _ _ _ _ #align submodule.smul_sup Submodule.smul_sup theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N := map₂_sup_left _ _ _ _ #align submodule.sup_smul Submodule.sup_smul protected theorem smul_assoc : (I • J) • N = I • J • N := le_antisymm (smul_le.2 fun _ hrsij t htn => smul_induction_on hrsij (fun r hr s hs => (@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn)) fun x y => (add_smul x y t).symm ▸ Submodule.add_mem _) (smul_le.2 fun r hr _ hsn => suffices J • N ≤ Submodule.comap (r • (LinearMap.id : M →ₗ[R] M)) ((I • J) • N) from this hsn smul_le.2 fun s hs n hn => show r • s • n ∈ (I • J) • N from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn) #align submodule.smul_assoc Submodule.smul_assoc @[deprecated smul_inf_le (since := "2024-03-31")] protected theorem smul_inf_le (M₁ M₂ : Submodule R M) : I • (M₁ ⊓ M₂) ≤ I • M₁ ⊓ I • M₂ := smul_inf_le _ _ _ #align submodule.smul_inf_le Submodule.smul_inf_le theorem smul_iSup {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iSup t = ⨆ i, I • t i := map₂_iSup_right _ _ _ #align submodule.smul_supr Submodule.smul_iSup @[deprecated smul_iInf_le (since := "2024-03-31")] protected theorem smul_iInf_le {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iInf t ≤ ⨅ i, I • t i := smul_iInf_le #align submodule.smul_infi_le Submodule.smul_iInf_le variable (S : Set R) (T : Set M) theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) := (map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _ #align submodule.span_smul_span Submodule.span_smul_span theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) : (Ideal.span {r} : Ideal R) • N = r • N := by have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by convert span_eq (r • N) exact (Set.image_eq_iUnion _ (N : Set M)).symm conv_lhs => rw [← span_eq N, span_smul_span] simpa #align submodule.ideal_span_singleton_smul Submodule.ideal_span_singleton_smul theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by suffices (⊤ : Ideal R) • span R ({x} : Set M) ≤ M' by rw [top_smul] at this exact this (subset_span (Set.mem_singleton x)) rw [← hs, span_smul_span, span_le] simpa using H #align submodule.mem_of_span_top_of_smul_mem Submodule.mem_of_span_top_of_smul_mem /-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/ theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by obtain ⟨s', hs₁, hs₂⟩ := (Ideal.span_eq_top_iff_finite _).mp hs replace H : ∀ r : s', ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M' := fun r => H ⟨_, hs₁ r.2⟩ choose n₁ n₂ using H let N := s'.attach.sup n₁ have hs' := Ideal.span_pow_eq_top (s' : Set R) hs₂ N apply M'.mem_of_span_top_of_smul_mem _ hs' rintro ⟨_, r, hr, rfl⟩ convert M'.smul_mem (r ^ (N - n₁ ⟨r, hr⟩)) (n₂ ⟨r, hr⟩) using 1 simp only [Subtype.coe_mk, smul_smul, ← pow_add] rw [tsub_add_cancel_of_le (Finset.le_sup (s'.mem_attach _) : n₁ ⟨r, hr⟩ ≤ N)] #align submodule.mem_of_span_eq_top_of_smul_pow_mem Submodule.mem_of_span_eq_top_of_smul_pow_mem variable {M' : Type w} [AddCommMonoid M'] [Module R M'] @[simp] theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f := le_antisymm (map_le_iff_le_comap.2 <| smul_le.2 fun r hr n hn => show f (r • n) ∈ I • N.map f from (f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <| smul_le.2 fun r hr _ hn => let ⟨p, hp, hfp⟩ := mem_map.1 hn hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp) #align submodule.map_smul'' Submodule.map_smul'' open Pointwise in @[simp] theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') : (r • N).map f = r • N.map f := by simp_rw [← ideal_span_singleton_smul, map_smul''] variable {I} theorem mem_smul_span {s : Set M} {x : M} : x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by rw [← I.span_eq, Submodule.span_smul_span, I.span_eq] rfl #align submodule.mem_smul_span Submodule.mem_smul_span variable (I) /-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`, then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/ theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) : x ∈ I • span R (Set.range f) ↔ ∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by constructor; swap · rintro ⟨a, ha, rfl⟩ exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _ refine fun hx => span_induction (mem_smul_span.mp hx) ?_ ?_ ?_ ?_ · simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff] rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩ refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩ · letI := Classical.decEq ι rw [Finsupp.single_apply] split_ifs · assumption · exact I.zero_mem refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_ simp · exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩ · rintro x y ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩ refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;> intros <;> simp only [zero_smul, add_smul] · rintro c x ⟨a, ha, rfl⟩ refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩ rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul] #align submodule.mem_ideal_smul_span_iff_exists_sum Submodule.mem_ideal_smul_span_iff_exists_sum theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) : x ∈ I • span R (f '' s) ↔ ∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range] #align submodule.mem_ideal_smul_span_iff_exists_sum' Submodule.mem_ideal_smul_span_iff_exists_sum' theorem mem_smul_top_iff (N : Submodule R M) (x : N) : x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by change _ ↔ N.subtype x ∈ I • N have : Submodule.map N.subtype (I • ⊤) = I • N := by rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype] rw [← this] exact (Function.Injective.mem_set_image N.injective_subtype).symm #align submodule.mem_smul_top_iff Submodule.mem_smul_top_iff @[simp] theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) : I • S.comap f ≤ (I • S).comap f := by refine Submodule.smul_le.mpr fun r hr x hx => ?_ rw [Submodule.mem_comap] at hx ⊢ rw [f.map_smul] exact Submodule.smul_mem_smul hr hx #align submodule.smul_comap_le_comap_smul Submodule.smul_comap_le_comap_smul end CommSemiring end Submodule namespace Ideal section Add variable {R : Type u} [Semiring R] @[simp] theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J := rfl #align ideal.add_eq_sup Ideal.add_eq_sup @[simp] theorem zero_eq_bot : (0 : Ideal R) = ⊥ := rfl #align ideal.zero_eq_bot Ideal.zero_eq_bot @[simp] theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f := rfl #align ideal.sum_eq_sup Ideal.sum_eq_sup end Add section MulAndRadical variable {R : Type u} {ι : Type*} [CommSemiring R] variable {I J K L : Ideal R} instance : Mul (Ideal R) := ⟨(· • ·)⟩ @[simp] theorem one_eq_top : (1 : Ideal R) = ⊤ := by erw [Submodule.one_eq_range, LinearMap.range_id] #align ideal.one_eq_top Ideal.one_eq_top theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup] theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J := Submodule.smul_mem_smul hr hs #align ideal.mul_mem_mul Ideal.mul_mem_mul theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J := mul_comm r s ▸ mul_mem_mul hr hs #align ideal.mul_mem_mul_rev Ideal.mul_mem_mul_rev theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n := Submodule.pow_mem_pow _ hx _ #align ideal.pow_mem_pow Ideal.pow_mem_pow theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} : (∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by classical refine Finset.induction_on s ?_ ?_ · intro rw [Finset.prod_empty, Finset.prod_empty, one_eq_top] exact Submodule.mem_top · intro a s ha IH h rw [Finset.prod_insert ha, Finset.prod_insert ha] exact mul_mem_mul (h a <| Finset.mem_insert_self a s) (IH fun i hi => h i <| Finset.mem_insert_of_mem hi) #align ideal.prod_mem_prod Ideal.prod_mem_prod theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K := Submodule.smul_le #align ideal.mul_le Ideal.mul_le theorem mul_le_left : I * J ≤ J := Ideal.mul_le.2 fun _ _ _ => J.mul_mem_left _ #align ideal.mul_le_left Ideal.mul_le_left theorem mul_le_right : I * J ≤ I := Ideal.mul_le.2 fun _ hr _ _ => I.mul_mem_right _ hr #align ideal.mul_le_right Ideal.mul_le_right @[simp] theorem sup_mul_right_self : I ⊔ I * J = I := sup_eq_left.2 Ideal.mul_le_right #align ideal.sup_mul_right_self Ideal.sup_mul_right_self @[simp] theorem sup_mul_left_self : I ⊔ J * I = I := sup_eq_left.2 Ideal.mul_le_left #align ideal.sup_mul_left_self Ideal.sup_mul_left_self @[simp] theorem mul_right_self_sup : I * J ⊔ I = I := sup_eq_right.2 Ideal.mul_le_right #align ideal.mul_right_self_sup Ideal.mul_right_self_sup @[simp] theorem mul_left_self_sup : J * I ⊔ I = I := sup_eq_right.2 Ideal.mul_le_left #align ideal.mul_left_self_sup Ideal.mul_left_self_sup variable (I J K) protected theorem mul_comm : I * J = J * I := le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI) (mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ) #align ideal.mul_comm Ideal.mul_comm protected theorem mul_assoc : I * J * K = I * (J * K) := Submodule.smul_assoc I J K #align ideal.mul_assoc Ideal.mul_assoc theorem span_mul_span (S T : Set R) : span S * span T = span (⋃ (s ∈ S) (t ∈ T), {s * t}) := Submodule.span_smul_span S T #align ideal.span_mul_span Ideal.span_mul_span variable {I J K} theorem span_mul_span' (S T : Set R) : span S * span T = span (S * T) := by unfold span rw [Submodule.span_mul_span] #align ideal.span_mul_span' Ideal.span_mul_span' theorem span_singleton_mul_span_singleton (r s : R) : span {r} * span {s} = (span {r * s} : Ideal R) := by unfold span rw [Submodule.span_mul_span, Set.singleton_mul_singleton] #align ideal.span_singleton_mul_span_singleton Ideal.span_singleton_mul_span_singleton theorem span_singleton_pow (s : R) (n : ℕ) : span {s} ^ n = (span {s ^ n} : Ideal R) := by induction' n with n ih; · simp [Set.singleton_one] simp only [pow_succ, ih, span_singleton_mul_span_singleton] #align ideal.span_singleton_pow Ideal.span_singleton_pow theorem mem_mul_span_singleton {x y : R} {I : Ideal R} : x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x := Submodule.mem_smul_span_singleton #align ideal.mem_mul_span_singleton Ideal.mem_mul_span_singleton theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by simp only [mul_comm, mem_mul_span_singleton] #align ideal.mem_span_singleton_mul Ideal.mem_span_singleton_mul theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} : I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI := show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by simp only [mem_span_singleton_mul] #align ideal.le_span_singleton_mul_iff Ideal.le_span_singleton_mul_iff theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} : span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by simp only [mul_le, mem_span_singleton_mul, mem_span_singleton] constructor · intro h zI hzI exact h x (dvd_refl x) zI hzI · rintro h _ ⟨z, rfl⟩ zI hzI rw [mul_comm x z, mul_assoc] exact J.mul_mem_left _ (h zI hzI) #align ideal.span_singleton_mul_le_iff Ideal.span_singleton_mul_le_iff theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} : span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm] #align ideal.span_singleton_mul_le_span_singleton_mul Ideal.span_singleton_mul_le_span_singleton_mul theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I ≤ span {x} * J ↔ I ≤ J := by simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx, exists_eq_right', SetLike.le_def] #align ideal.span_singleton_mul_right_mono Ideal.span_singleton_mul_right_mono theorem span_singleton_mul_left_mono [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} ≤ J * span {x} ↔ I ≤ J := by simpa only [mul_comm I, mul_comm J] using span_singleton_mul_right_mono hx #align ideal.span_singleton_mul_left_mono Ideal.span_singleton_mul_left_mono theorem span_singleton_mul_right_inj [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I = span {x} * J ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_right_mono hx] #align ideal.span_singleton_mul_right_inj Ideal.span_singleton_mul_right_inj theorem span_singleton_mul_left_inj [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} = J * span {x} ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_left_mono hx] #align ideal.span_singleton_mul_left_inj Ideal.span_singleton_mul_left_inj theorem span_singleton_mul_right_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective ((span {x} : Ideal R) * ·) := fun _ _ => (span_singleton_mul_right_inj hx).mp #align ideal.span_singleton_mul_right_injective Ideal.span_singleton_mul_right_injective theorem span_singleton_mul_left_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective fun I : Ideal R => I * span {x} := fun _ _ => (span_singleton_mul_left_inj hx).mp #align ideal.span_singleton_mul_left_injective Ideal.span_singleton_mul_left_injective theorem eq_span_singleton_mul {x : R} (I J : Ideal R) : I = span {x} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I := by simp only [le_antisymm_iff, le_span_singleton_mul_iff, span_singleton_mul_le_iff] #align ideal.eq_span_singleton_mul Ideal.eq_span_singleton_mul theorem span_singleton_mul_eq_span_singleton_mul {x y : R} (I J : Ideal R) : span {x} * I = span {y} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ) ∧ ∀ zJ ∈ J, ∃ zI ∈ I, x * zI = y * zJ := by simp only [le_antisymm_iff, span_singleton_mul_le_span_singleton_mul, eq_comm] #align ideal.span_singleton_mul_eq_span_singleton_mul Ideal.span_singleton_mul_eq_span_singleton_mul theorem prod_span {ι : Type*} (s : Finset ι) (I : ι → Set R) : (∏ i ∈ s, Ideal.span (I i)) = Ideal.span (∏ i ∈ s, I i) := Submodule.prod_span s I #align ideal.prod_span Ideal.prod_span theorem prod_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) : (∏ i ∈ s, Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := Submodule.prod_span_singleton s I #align ideal.prod_span_singleton Ideal.prod_span_singleton @[simp] theorem multiset_prod_span_singleton (m : Multiset R) : (m.map fun x => Ideal.span {x}).prod = Ideal.span ({Multiset.prod m} : Set R) := Multiset.induction_on m (by simp) fun a m ih => by simp only [Multiset.map_cons, Multiset.prod_cons, ih, ← Ideal.span_singleton_mul_span_singleton] #align ideal.multiset_prod_span_singleton Ideal.multiset_prod_span_singleton theorem finset_inf_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) (hI : Set.Pairwise (↑s) (IsCoprime on I)) : (s.inf fun i => Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := by ext x simp only [Submodule.mem_finset_inf, Ideal.mem_span_singleton] exact ⟨Finset.prod_dvd_of_coprime hI, fun h i hi => (Finset.dvd_prod_of_mem _ hi).trans h⟩ #align ideal.finset_inf_span_singleton Ideal.finset_inf_span_singleton theorem iInf_span_singleton {ι : Type*} [Fintype ι] {I : ι → R} (hI : ∀ (i j) (_ : i ≠ j), IsCoprime (I i) (I j)) : ⨅ i, span ({I i} : Set R) = span {∏ i, I i} := by rw [← Finset.inf_univ_eq_iInf, finset_inf_span_singleton] rwa [Finset.coe_univ, Set.pairwise_univ] #align ideal.infi_span_singleton Ideal.iInf_span_singleton theorem iInf_span_singleton_natCast {R : Type*} [CommRing R] {ι : Type*} [Fintype ι] {I : ι → ℕ} (hI : Pairwise fun i j => (I i).Coprime (I j)) : ⨅ (i : ι), span {(I i : R)} = span {((∏ i : ι, I i : ℕ) : R)} := by rw [iInf_span_singleton, Nat.cast_prod] exact fun i j h ↦ (hI h).cast theorem sup_eq_top_iff_isCoprime {R : Type*} [CommSemiring R] (x y : R) : span ({x} : Set R) ⊔ span {y} = ⊤ ↔ IsCoprime x y := by rw [eq_top_iff_one, Submodule.mem_sup] constructor · rintro ⟨u, hu, v, hv, h1⟩ rw [mem_span_singleton'] at hu hv rw [← hu.choose_spec, ← hv.choose_spec] at h1 exact ⟨_, _, h1⟩ · exact fun ⟨u, v, h1⟩ => ⟨_, mem_span_singleton'.mpr ⟨_, rfl⟩, _, mem_span_singleton'.mpr ⟨_, rfl⟩, h1⟩ #align ideal.sup_eq_top_iff_is_coprime Ideal.sup_eq_top_iff_isCoprime theorem mul_le_inf : I * J ≤ I ⊓ J := mul_le.2 fun r hri s hsj => ⟨I.mul_mem_right s hri, J.mul_mem_left r hsj⟩ #align ideal.mul_le_inf Ideal.mul_le_inf theorem multiset_prod_le_inf {s : Multiset (Ideal R)} : s.prod ≤ s.inf := by classical refine s.induction_on ?_ ?_ · rw [Multiset.inf_zero] exact le_top intro a s ih rw [Multiset.prod_cons, Multiset.inf_cons] exact le_trans mul_le_inf (inf_le_inf le_rfl ih) #align ideal.multiset_prod_le_inf Ideal.multiset_prod_le_inf theorem prod_le_inf {s : Finset ι} {f : ι → Ideal R} : s.prod f ≤ s.inf f := multiset_prod_le_inf #align ideal.prod_le_inf Ideal.prod_le_inf theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J := le_antisymm mul_le_inf fun r ⟨hri, hrj⟩ => let ⟨s, hsi, t, htj, hst⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h) mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ Ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj) #align ideal.mul_eq_inf_of_coprime Ideal.mul_eq_inf_of_coprime theorem sup_mul_eq_of_coprime_left (h : I ⊔ J = ⊤) : I ⊔ J * K = I ⊔ K := le_antisymm (sup_le_sup_left mul_le_left _) fun i hi => by rw [eq_top_iff_one] at h; rw [Submodule.mem_sup] at h hi ⊢ obtain ⟨i1, hi1, j, hj, h⟩ := h; obtain ⟨i', hi', k, hk, hi⟩ := hi refine ⟨_, add_mem hi' (mul_mem_right k _ hi1), _, mul_mem_mul hj hk, ?_⟩ rw [add_assoc, ← add_mul, h, one_mul, hi] #align ideal.sup_mul_eq_of_coprime_left Ideal.sup_mul_eq_of_coprime_left theorem sup_mul_eq_of_coprime_right (h : I ⊔ K = ⊤) : I ⊔ J * K = I ⊔ J := by rw [mul_comm] exact sup_mul_eq_of_coprime_left h #align ideal.sup_mul_eq_of_coprime_right Ideal.sup_mul_eq_of_coprime_right theorem mul_sup_eq_of_coprime_left (h : I ⊔ J = ⊤) : I * K ⊔ J = K ⊔ J := by rw [sup_comm] at h rw [sup_comm, sup_mul_eq_of_coprime_left h, sup_comm] #align ideal.mul_sup_eq_of_coprime_left Ideal.mul_sup_eq_of_coprime_left theorem mul_sup_eq_of_coprime_right (h : K ⊔ J = ⊤) : I * K ⊔ J = I ⊔ J := by rw [sup_comm] at h rw [sup_comm, sup_mul_eq_of_coprime_right h, sup_comm] #align ideal.mul_sup_eq_of_coprime_right Ideal.mul_sup_eq_of_coprime_right theorem sup_prod_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) : (I ⊔ ∏ i ∈ s, J i) = ⊤ := Finset.prod_induction _ (fun J => I ⊔ J = ⊤) (fun J K hJ hK => (sup_mul_eq_of_coprime_left hJ).trans hK) (by simp_rw [one_eq_top, sup_top_eq]) h #align ideal.sup_prod_eq_top Ideal.sup_prod_eq_top theorem sup_iInf_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) : (I ⊔ ⨅ i ∈ s, J i) = ⊤ := eq_top_iff.mpr <| le_of_eq_of_le (sup_prod_eq_top h).symm <| sup_le_sup_left (le_of_le_of_eq prod_le_inf <| Finset.inf_eq_iInf _ _) _ #align ideal.sup_infi_eq_top Ideal.sup_iInf_eq_top theorem prod_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) : (∏ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_prod_eq_top]; intro i hi; rw [sup_comm, h i hi] #align ideal.prod_sup_eq_top Ideal.prod_sup_eq_top theorem iInf_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) : (⨅ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_iInf_eq_top]; intro i hi; rw [sup_comm, h i hi] #align ideal.infi_sup_eq_top Ideal.iInf_sup_eq_top theorem sup_pow_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ⊔ J ^ n = ⊤ := by rw [← Finset.card_range n, ← Finset.prod_const] exact sup_prod_eq_top fun _ _ => h #align ideal.sup_pow_eq_top Ideal.sup_pow_eq_top theorem pow_sup_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ^ n ⊔ J = ⊤ := by rw [← Finset.card_range n, ← Finset.prod_const] exact prod_sup_eq_top fun _ _ => h #align ideal.pow_sup_eq_top Ideal.pow_sup_eq_top theorem pow_sup_pow_eq_top {m n : ℕ} (h : I ⊔ J = ⊤) : I ^ m ⊔ J ^ n = ⊤ := sup_pow_eq_top (pow_sup_eq_top h) #align ideal.pow_sup_pow_eq_top Ideal.pow_sup_pow_eq_top variable (I) -- @[simp] -- Porting note (#10618): simp can prove this theorem mul_bot : I * ⊥ = ⊥ := by simp #align ideal.mul_bot Ideal.mul_bot -- @[simp] -- Porting note (#10618): simp can prove thisrove this theorem bot_mul : ⊥ * I = ⊥ := by simp #align ideal.bot_mul Ideal.bot_mul @[simp] theorem mul_top : I * ⊤ = I := Ideal.mul_comm ⊤ I ▸ Submodule.top_smul I #align ideal.mul_top Ideal.mul_top @[simp] theorem top_mul : ⊤ * I = I := Submodule.top_smul I #align ideal.top_mul Ideal.top_mul variable {I} theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L := Submodule.smul_mono hik hjl #align ideal.mul_mono Ideal.mul_mono theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K := Submodule.smul_mono_left h #align ideal.mul_mono_left Ideal.mul_mono_left theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K := smul_mono_right _ h #align ideal.mul_mono_right Ideal.mul_mono_right variable (I J K) theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K := Submodule.smul_sup I J K #align ideal.mul_sup Ideal.mul_sup theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K := Submodule.sup_smul I J K #align ideal.sup_mul Ideal.sup_mul variable {I J K} theorem pow_le_pow_right {m n : ℕ} (h : m ≤ n) : I ^ n ≤ I ^ m := by cases' Nat.exists_eq_add_of_le h with k hk rw [hk, pow_add] exact le_trans mul_le_inf inf_le_left #align ideal.pow_le_pow_right Ideal.pow_le_pow_right theorem pow_le_self {n : ℕ} (hn : n ≠ 0) : I ^ n ≤ I := calc I ^ n ≤ I ^ 1 := pow_le_pow_right (Nat.pos_of_ne_zero hn) _ = I := pow_one _ #align ideal.pow_le_self Ideal.pow_le_self theorem pow_right_mono {I J : Ideal R} (e : I ≤ J) (n : ℕ) : I ^ n ≤ J ^ n := by induction' n with _ hn · rw [pow_zero, pow_zero] · rw [pow_succ, pow_succ] exact Ideal.mul_mono hn e #align ideal.pow_right_mono Ideal.pow_right_mono @[simp] theorem mul_eq_bot {R : Type*} [CommSemiring R] [NoZeroDivisors R] {I J : Ideal R} : I * J = ⊥ ↔ I = ⊥ ∨ J = ⊥ := ⟨fun hij => or_iff_not_imp_left.mpr fun I_ne_bot => J.eq_bot_iff.mpr fun j hj => let ⟨i, hi, ne0⟩ := I.ne_bot_iff.mp I_ne_bot Or.resolve_left (mul_eq_zero.mp ((I * J).eq_bot_iff.mp hij _ (mul_mem_mul hi hj))) ne0, fun h => by cases' h with h h <;> rw [← Ideal.mul_bot, h, Ideal.mul_comm]⟩ #align ideal.mul_eq_bot Ideal.mul_eq_bot instance {R : Type*} [CommSemiring R] [NoZeroDivisors R] : NoZeroDivisors (Ideal R) where eq_zero_or_eq_zero_of_mul_eq_zero := mul_eq_bot.1 instance {R : Type*} [CommSemiring R] {S : Type*} [CommRing S] [Algebra R S] [NoZeroSMulDivisors R S] {I : Ideal S} : NoZeroSMulDivisors R I := Submodule.noZeroSMulDivisors (Submodule.restrictScalars R I) /-- A product of ideals in an integral domain is zero if and only if one of the terms is zero. -/ @[simp] lemma multiset_prod_eq_bot {R : Type*} [CommRing R] [IsDomain R] {s : Multiset (Ideal R)} : s.prod = ⊥ ↔ ⊥ ∈ s := Multiset.prod_eq_zero_iff /-- A product of ideals in an integral domain is zero if and only if one of the terms is zero. -/ @[deprecated multiset_prod_eq_bot (since := "2023-12-26")] theorem prod_eq_bot {R : Type*} [CommRing R] [IsDomain R] {s : Multiset (Ideal R)} : s.prod = ⊥ ↔ ∃ I ∈ s, I = ⊥ := by simp #align ideal.prod_eq_bot Ideal.prod_eq_bot theorem span_pair_mul_span_pair (w x y z : R) : (span {w, x} : Ideal R) * span {y, z} = span {w * y, w * z, x * y, x * z} := by simp_rw [span_insert, sup_mul, mul_sup, span_singleton_mul_span_singleton, sup_assoc] #align ideal.span_pair_mul_span_pair Ideal.span_pair_mul_span_pair theorem isCoprime_iff_codisjoint : IsCoprime I J ↔ Codisjoint I J := by rw [IsCoprime, codisjoint_iff] constructor · rintro ⟨x, y, hxy⟩ rw [eq_top_iff_one] apply (show x * I + y * J ≤ I ⊔ J from sup_le (mul_le_left.trans le_sup_left) (mul_le_left.trans le_sup_right)) rw [hxy] simp only [one_eq_top, Submodule.mem_top] · intro h refine ⟨1, 1, ?_⟩ simpa only [one_eq_top, top_mul, Submodule.add_eq_sup] theorem isCoprime_iff_add : IsCoprime I J ↔ I + J = 1 := by rw [isCoprime_iff_codisjoint, codisjoint_iff, add_eq_sup, one_eq_top] theorem isCoprime_iff_exists : IsCoprime I J ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [← add_eq_one_iff, isCoprime_iff_add] theorem isCoprime_iff_sup_eq : IsCoprime I J ↔ I ⊔ J = ⊤ := by rw [isCoprime_iff_codisjoint, codisjoint_iff] open List in
Mathlib/RingTheory/Ideal/Operations.lean
854
858
theorem isCoprime_tfae : TFAE [IsCoprime I J, Codisjoint I J, I + J = 1, ∃ i ∈ I, ∃ j ∈ J, i + j = 1, I ⊔ J = ⊤] := by
rw [← isCoprime_iff_codisjoint, ← isCoprime_iff_add, ← isCoprime_iff_exists, ← isCoprime_iff_sup_eq] simp
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Patrick Massot, Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.FDeriv.Measurable import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.NormedSpace.Dual import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.MeasureTheory.Integral.VitaliCaratheodory #align_import measure_theory.integral.fund_thm_calculus from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Fundamental Theorem of Calculus We prove various versions of the [fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus) for interval integrals in `ℝ`. Recall that its first version states that the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(δu, δv) ↦ δv • f b - δu • f a` at `(a, b)` provided that `f` is continuous at `a` and `b`, and its second version states that, if `f` has an integrable derivative on `[a, b]`, then `∫ x in a..b, f' x = f b - f a`. ## Main statements ### FTC-1 for Lebesgue measure We prove several versions of FTC-1, all in the `intervalIntegral` namespace. Many of them follow the naming scheme `integral_has(Strict?)(F?)Deriv(Within?)At(_of_tendsto_ae?)(_right|_left?)`. They formulate FTC in terms of `Has(Strict?)(F?)Deriv(Within?)At`. Let us explain the meaning of each part of the name: * `Strict` means that the theorem is about strict differentiability, see `HasStrictDerivAt` and `HasStrictFDerivAt`; * `F` means that the theorem is about differentiability in both endpoints; incompatible with `_right|_left`; * `Within` means that the theorem is about one-sided derivatives, see below for details; * `_of_tendsto_ae` means that instead of continuity the theorem assumes that `f` has a finite limit almost surely as `x` tends to `a` and/or `b`; * `_right` or `_left` mean that the theorem is about differentiability in the right (resp., left) endpoint. We also reformulate these theorems in terms of `(f?)deriv(Within?)`. These theorems are named `(f?)deriv(Within?)_integral(_of_tendsto_ae?)(_right|_left?)` with the same meaning of parts of the name. ### One-sided derivatives Theorem `intervalIntegral.integral_hasFDerivWithinAt_of_tendsto_ae` states that `(u, v) ↦ ∫ x in u..v, f x` has a derivative `(δu, δv) ↦ δv • cb - δu • ca` within the set `s × t` at `(a, b)` provided that `f` tends to `ca` (resp., `cb`) almost surely at `la` (resp., `lb`), where possible values of `s`, `t`, and corresponding filters `la`, `lb` are given in the following table. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` | | `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | We use a typeclass `intervalIntegral.FTCFilter` to make Lean automatically find `la`/`lb` based on `s`/`t`. This way we can formulate one theorem instead of `16` (or `8` if we leave only non-trivial ones not covered by `integral_hasDerivWithinAt_of_tendsto_ae_(left|right)` and `integral_hasFDerivAt_of_tendsto_ae`). Similarly, `integral_hasDerivWithinAt_of_tendsto_ae_right` works for both one-sided derivatives using the same typeclass to find an appropriate filter. ### FTC for a locally finite measure Before proving FTC for the Lebesgue measure, we prove a few statements that can be seen as FTC for any measure. The most general of them, `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae`, states the following. Let `(la, la')` be an `intervalIntegral.FTCFilter` pair of filters around `a` (i.e., `intervalIntegral.FTCFilter a la la'`) and let `(lb, lb')` be an `intervalIntegral.FTCFilter` pair of filters around `b`. If `f` has finite limits `ca` and `cb` almost surely at `la'` and `lb'`, respectively, then $$ \int_{va}^{vb} f ∂μ - \int_{ua}^{ub} f ∂μ = \int_{ub}^{vb} cb ∂μ - \int_{ua}^{va} ca ∂μ + o(‖∫_{ua}^{va} 1 ∂μ‖ + ‖∫_{ub}^{vb} (1:ℝ) ∂μ‖) $$ as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. ### FTC-2 and corollaries We use FTC-1 to prove several versions of FTC-2 for the Lebesgue measure, using a similar naming scheme as for the versions of FTC-1. They include: * `intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le` - most general version, for functions with a right derivative * `intervalIntegral.integral_eq_sub_of_hasDerivAt` - version for functions with a derivative on an open set * `intervalIntegral.integral_deriv_eq_sub'` - version that is easiest to use when computing the integral of a specific function We then derive additional integration techniques from FTC-2: * `intervalIntegral.integral_mul_deriv_eq_deriv_mul` - integration by parts * `intervalIntegral.integral_comp_mul_deriv''` - integration by substitution Many applications of these theorems can be found in the file `Mathlib/Analysis/SpecialFunctions/Integrals.lean`. Note that the assumptions of FTC-2 are formulated in the form that `f'` is integrable. To use it in a context with the stronger assumption that `f'` is continuous, one can use `ContinuousOn.intervalIntegrable` or `ContinuousOn.integrableOn_Icc` or `ContinuousOn.integrableOn_uIcc`. ### `intervalIntegral.FTCFilter` class As explained above, many theorems in this file rely on the typeclass `intervalIntegral.FTCFilter (a : ℝ) (l l' : Filter ℝ)` to avoid code duplication. This typeclass combines four assumptions: - `pure a ≤ l`; - `l' ≤ 𝓝 a`; - `l'` has a basis of measurable sets; - if `u n` and `v n` tend to `l`, then for any `s ∈ l'`, `Ioc (u n) (v n)` is eventually included in `s`. This typeclass has the following “real” instances: `(a, pure a, ⊥)`, `(a, 𝓝[≥] a, 𝓝[>] a)`, `(a, 𝓝[≤] a, 𝓝[≤] a)`, `(a, 𝓝 a, 𝓝 a)`. Furthermore, we have the following instances that are equal to the previously mentioned instances: `(a, 𝓝[{a}] a, ⊥)` and `(a, 𝓝[univ] a, 𝓝[univ] a)`. While the difference between `Ici a` and `Ioi a` doesn't matter for theorems about Lebesgue measure, it becomes important in the versions of FTC about any locally finite measure if this measure has an atom at one of the endpoints. ### Combining one-sided and two-sided derivatives There are some `intervalIntegral.FTCFilter` instances where the fact that it is one-sided or two-sided depends on the point, namely `(x, 𝓝[Set.Icc a b] x, 𝓝[Set.Icc a b] x)` (resp. `(x, 𝓝[Set.uIcc a b] x, 𝓝[Set.uIcc a b] x)`, with `x ∈ Icc a b` (resp. `x ∈ uIcc a b`). This results in a two-sided derivatives for `x ∈ Set.Ioo a b` and one-sided derivatives for `x ∈ {a, b}`. Other instances could be added when needed (in that case, one also needs to add instances for `Filter.IsMeasurablyGenerated` and `Filter.TendstoIxxClass`). ## Tags integral, fundamental theorem of calculus, FTC-1, FTC-2, change of variables in integrals -/ set_option autoImplicit true noncomputable section open scoped Classical open MeasureTheory Set Filter Function open scoped Classical Topology Filter ENNReal Interval NNReal variable {ι 𝕜 E F A : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] namespace intervalIntegral section FTC1 /-! ### Fundamental theorem of calculus, part 1, for any measure In this section we prove a few lemmas that can be seen as versions of FTC-1 for interval integrals w.r.t. any measure. Many theorems are formulated for one or two pairs of filters related by `intervalIntegral.FTCFilter a l l'`. This typeclass has exactly four “real” instances: `(a, pure a, ⊥)`, `(a, 𝓝[≥] a, 𝓝[>] a)`, `(a, 𝓝[≤] a, 𝓝[≤] a)`, `(a, 𝓝 a, 𝓝 a)`, and two instances that are equal to the first and last “real” instances: `(a, 𝓝[{a}] a, ⊥)` and `(a, 𝓝[univ] a, 𝓝[univ] a)`. We use this approach to avoid repeating arguments in many very similar cases. Lean can automatically find both `a` and `l'` based on `l`. The most general theorem `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae` can be seen as a generalization of lemma `integral_hasStrictFDerivAt` below which states strict differentiability of `∫ x in u..v, f x` in `(u, v)` at `(a, b)` for a measurable function `f` that is integrable on `a..b` and is continuous at `a` and `b`. The lemma is generalized in three directions: first, `measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae` deals with any locally finite measure `μ`; second, it works for one-sided limits/derivatives; third, it assumes only that `f` has finite limits almost surely at `a` and `b`. Namely, let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `intervalIntegral.FTCFilter`s around `a`; let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ ae μ` and `lb' ⊓ ae μ`, respectively. Then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ + o(‖∫ x in ua..va, (1:ℝ) ∂μ‖ + ‖∫ x in ub..vb, (1:ℝ) ∂μ‖)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. This theorem is formulated with integral of constants instead of measures in the right hand sides for two reasons: first, this way we avoid `min`/`max` in the statements; second, often it is possible to write better `simp` lemmas for these integrals, see `integral_const` and `integral_const_of_cdf`. In the next subsection we apply this theorem to prove various theorems about differentiability of the integral w.r.t. Lebesgue measure. -/ /-- An auxiliary typeclass for the Fundamental theorem of calculus, part 1. It is used to formulate theorems that work simultaneously for left and right one-sided derivatives of `∫ x in u..v, f x`. -/ class FTCFilter (a : outParam ℝ) (outer : Filter ℝ) (inner : outParam <| Filter ℝ) extends TendstoIxxClass Ioc outer inner : Prop where pure_le : pure a ≤ outer le_nhds : inner ≤ 𝓝 a [meas_gen : IsMeasurablyGenerated inner] set_option linter.uppercaseLean3 false in #align interval_integral.FTC_filter intervalIntegral.FTCFilter namespace FTCFilter set_option linter.uppercaseLean3 false -- `FTC` in every name instance pure (a : ℝ) : FTCFilter a (pure a) ⊥ where pure_le := le_rfl le_nhds := bot_le #align interval_integral.FTC_filter.pure intervalIntegral.FTCFilter.pure instance nhdsWithinSingleton (a : ℝ) : FTCFilter a (𝓝[{a}] a) ⊥ := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)]; infer_instance #align interval_integral.FTC_filter.nhds_within_singleton intervalIntegral.FTCFilter.nhdsWithinSingleton theorem finiteAt_inner {a : ℝ} (l : Filter ℝ) {l'} [h : FTCFilter a l l'] {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] : μ.FiniteAtFilter l' := (μ.finiteAt_nhds a).filter_mono h.le_nhds #align interval_integral.FTC_filter.finite_at_inner intervalIntegral.FTCFilter.finiteAt_inner instance nhds (a : ℝ) : FTCFilter a (𝓝 a) (𝓝 a) where pure_le := pure_le_nhds a le_nhds := le_rfl #align interval_integral.FTC_filter.nhds intervalIntegral.FTCFilter.nhds instance nhdsUniv (a : ℝ) : FTCFilter a (𝓝[univ] a) (𝓝 a) := by rw [nhdsWithin_univ]; infer_instance #align interval_integral.FTC_filter.nhds_univ intervalIntegral.FTCFilter.nhdsUniv instance nhdsLeft (a : ℝ) : FTCFilter a (𝓝[≤] a) (𝓝[≤] a) where pure_le := pure_le_nhdsWithin right_mem_Iic le_nhds := inf_le_left #align interval_integral.FTC_filter.nhds_left intervalIntegral.FTCFilter.nhdsLeft instance nhdsRight (a : ℝ) : FTCFilter a (𝓝[≥] a) (𝓝[>] a) where pure_le := pure_le_nhdsWithin left_mem_Ici le_nhds := inf_le_left #align interval_integral.FTC_filter.nhds_right intervalIntegral.FTCFilter.nhdsRight instance nhdsIcc {x a b : ℝ} [h : Fact (x ∈ Icc a b)] : FTCFilter x (𝓝[Icc a b] x) (𝓝[Icc a b] x) where pure_le := pure_le_nhdsWithin h.out le_nhds := inf_le_left #align interval_integral.FTC_filter.nhds_Icc intervalIntegral.FTCFilter.nhdsIcc instance nhdsUIcc {x a b : ℝ} [h : Fact (x ∈ [[a, b]])] : FTCFilter x (𝓝[[[a, b]]] x) (𝓝[[[a, b]]] x) := .nhdsIcc (h := h) #align interval_integral.FTC_filter.nhds_uIcc intervalIntegral.FTCFilter.nhdsUIcc end FTCFilter open Asymptotics section variable {f : ℝ → E} {a b : ℝ} {c ca cb : E} {l l' la la' lb lb' : Filter ℝ} {lt : Filter ι} {μ : Measure ℝ} {u v ua va ub vb : ι → ℝ} /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`. If `f` has a finite limit `c` at `l' ⊓ ae μ`, where `μ` is a measure finite at `l'`, then `∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae` for a version assuming `[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = atTop`. We use integrals of constants instead of measures because this way it is easier to formulate a statement that works in both cases `u ≤ v` and `v ≤ u`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae' [IsMeasurablyGenerated l'] [TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l) (hv : Tendsto v lt l) : (fun t => (∫ x in u t..v t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by by_cases hE : CompleteSpace E; swap · simp [intervalIntegral, integral, hE] have A := hf.integral_sub_linear_isLittleO_ae hfm hl (hu.Ioc hv) have B := hf.integral_sub_linear_isLittleO_ae hfm hl (hv.Ioc hu) simp_rw [integral_const', sub_smul] refine ((A.trans_le fun t ↦ ?_).sub (B.trans_le fun t ↦ ?_)).congr_left fun t ↦ ?_ · cases le_total (u t) (v t) <;> simp [*] · cases le_total (u t) (v t) <;> simp [*] · simp_rw [intervalIntegral] abel #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae' variable [CompleteSpace E] /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`. If `f` has a finite limit `c` at `l ⊓ ae μ`, where `μ` is a measure finite at `l`, then `∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both `u` and `v` tend to `l` so that `u ≤ v`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le` for a version assuming `[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' [IsMeasurablyGenerated l'] [TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : u ≤ᶠ[lt] v) : (fun t => (∫ x in u t..v t, f x ∂μ) - (μ (Ioc (u t) (v t))).toReal • c) =o[lt] fun t => (μ <| Ioc (u t) (v t)).toReal := (measure_integral_sub_linear_isLittleO_of_tendsto_ae' hfm hf hl hu hv).congr' (huv.mono fun x hx => by simp [integral_const', hx]) (huv.mono fun x hx => by simp [integral_const', hx]) #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_le' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `TendstoIxxClass Ioc`. If `f` has a finite limit `c` at `l ⊓ ae μ`, where `μ` is a measure finite at `l`, then `∫ x in u..v, f x ∂μ = -μ (Ioc v u) • c + o(μ(Ioc v u))` as both `u` and `v` tend to `l` so that `v ≤ u`. See also `measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge` for a version assuming `[intervalIntegral.FTCFilter a l l']` and `[MeasureTheory.IsLocallyFiniteMeasure μ]`. If `l` is one of `𝓝[≥] a`, `𝓝[≤] a`, `𝓝 a`, then it's easier to apply the non-primed version. The primed version also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' [IsMeasurablyGenerated l'] [TendstoIxxClass Ioc l l'] (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hl : μ.FiniteAtFilter l') (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : v ≤ᶠ[lt] u) : (fun t => (∫ x in u t..v t, f x ∂μ) + (μ (Ioc (v t) (u t))).toReal • c) =o[lt] fun t => (μ <| Ioc (v t) (u t)).toReal := (measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' hfm hf hl hv hu huv).neg_left.congr_left fun t => by simp [integral_symm (u t), add_comm] #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge' intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' section variable [IsLocallyFiniteMeasure μ] [FTCFilter a l l'] /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then `∫ x in u..v, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, 1 ∂μ)` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae'` for a version that also works, e.g., for `l = l' = Filter.atTop`. We use integrals of constants instead of measures because this way it is easier to formulate a statement that works in both cases `u ≤ v` and `v ≤ u`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt l) (hv : Tendsto v lt l) : (fun t => (∫ x in u t..v t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := haveI := FTCFilter.meas_gen l measure_integral_sub_linear_isLittleO_of_tendsto_ae' hfm hf (FTCFilter.finiteAt_inner l) hu hv #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then `∫ x in u..v, f x ∂μ = μ (Ioc u v) • c + o(μ(Ioc u v))` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le'` for a version that also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : u ≤ᶠ[lt] v) : (fun t => (∫ x in u t..v t, f x ∂μ) - (μ (Ioc (u t) (v t))).toReal • c) =o[lt] fun t => (μ <| Ioc (u t) (v t)).toReal := haveI := FTCFilter.meas_gen l measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le' hfm hf (FTCFilter.finiteAt_inner l) hu hv huv #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_le intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_le /-- **Fundamental theorem of calculus-1**, local version for any measure. Let filters `l` and `l'` be related by `[intervalIntegral.FTCFilter a l l']`; let `μ` be a locally finite measure. If `f` has a finite limit `c` at `l' ⊓ ae μ`, then `∫ x in u..v, f x ∂μ = -μ (Set.Ioc v u) • c + o(μ(Set.Ioc v u))` as both `u` and `v` tend to `l`. See also `measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge'` for a version that also works, e.g., for `l = l' = Filter.atTop`. -/ theorem measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge (hfm : StronglyMeasurableAtFilter f l' μ) (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt l) (hv : Tendsto v lt l) (huv : v ≤ᶠ[lt] u) : (fun t => (∫ x in u t..v t, f x ∂μ) + (μ (Ioc (v t) (u t))).toReal • c) =o[lt] fun t => (μ <| Ioc (v t) (u t)).toReal := haveI := FTCFilter.meas_gen l measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge' hfm hf (FTCFilter.finiteAt_inner l) hu hv huv #align interval_integral.measure_integral_sub_linear_is_o_of_tendsto_ae_of_ge intervalIntegral.measure_integral_sub_linear_isLittleO_of_tendsto_ae_of_ge end variable [FTCFilter a la la'] [FTCFilter b lb lb'] [IsLocallyFiniteMeasure μ] /-- **Fundamental theorem of calculus-1**, strict derivative in both limits for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `intervalIntegral.FTCFilter`s around `a`; let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has finite limits `ca` and `cb` at `la' ⊓ ae μ` and `lb' ⊓ ae μ`, respectively. Then `∫ x in va..vb, f x ∂μ - ∫ x in ua..ub, f x ∂μ = ∫ x in ub..vb, cb ∂μ - ∫ x in ua..va, ca ∂μ + o(‖∫ x in ua..va, (1:ℝ) ∂μ‖ + ‖∫ x in ub..vb, (1:ℝ) ∂μ‖)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. -/ theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae (hab : IntervalIntegrable f μ a b) (hmeas_a : StronglyMeasurableAtFilter f la' μ) (hmeas_b : StronglyMeasurableAtFilter f lb' μ) (ha_lim : Tendsto f (la' ⊓ ae μ) (𝓝 ca)) (hb_lim : Tendsto f (lb' ⊓ ae μ) (𝓝 cb)) (hua : Tendsto ua lt la) (hva : Tendsto va lt la) (hub : Tendsto ub lt lb) (hvb : Tendsto vb lt lb) : (fun t => ((∫ x in va t..vb t, f x ∂μ) - ∫ x in ua t..ub t, f x ∂μ) - ((∫ _ in ub t..vb t, cb ∂μ) - ∫ _ in ua t..va t, ca ∂μ)) =o[lt] fun t => ‖∫ _ in ua t..va t, (1 : ℝ) ∂μ‖ + ‖∫ _ in ub t..vb t, (1 : ℝ) ∂μ‖ := by haveI := FTCFilter.meas_gen la; haveI := FTCFilter.meas_gen lb refine ((measure_integral_sub_linear_isLittleO_of_tendsto_ae hmeas_a ha_lim hua hva).neg_left.add_add (measure_integral_sub_linear_isLittleO_of_tendsto_ae hmeas_b hb_lim hub hvb)).congr' ?_ EventuallyEq.rfl have A : ∀ᶠ t in lt, IntervalIntegrable f μ (ua t) (va t) := ha_lim.eventually_intervalIntegrable_ae hmeas_a (FTCFilter.finiteAt_inner la) hua hva have A' : ∀ᶠ t in lt, IntervalIntegrable f μ a (ua t) := ha_lim.eventually_intervalIntegrable_ae hmeas_a (FTCFilter.finiteAt_inner la) (tendsto_const_pure.mono_right FTCFilter.pure_le) hua have B : ∀ᶠ t in lt, IntervalIntegrable f μ (ub t) (vb t) := hb_lim.eventually_intervalIntegrable_ae hmeas_b (FTCFilter.finiteAt_inner lb) hub hvb have B' : ∀ᶠ t in lt, IntervalIntegrable f μ b (ub t) := hb_lim.eventually_intervalIntegrable_ae hmeas_b (FTCFilter.finiteAt_inner lb) (tendsto_const_pure.mono_right FTCFilter.pure_le) hub filter_upwards [A, A', B, B'] with _ ua_va a_ua ub_vb b_ub rw [← integral_interval_sub_interval_comm'] · abel exacts [ub_vb, ua_va, b_ub.symm.trans <| hab.symm.trans a_ua] #align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, strict derivative in right endpoint for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(lb, lb')` be a pair of `intervalIntegral.FTCFilter`s around `b`. Suppose that `f` has a finite limit `c` at `lb' ⊓ ae μ`. Then `∫ x in a..v, f x ∂μ - ∫ x in a..u, f x ∂μ = ∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)` as `u` and `v` tend to `lb`. -/ theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right (hab : IntervalIntegrable f μ a b) (hmeas : StronglyMeasurableAtFilter f lb' μ) (hf : Tendsto f (lb' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt lb) (hv : Tendsto v lt lb) : (fun t => ((∫ x in a..v t, f x ∂μ) - ∫ x in a..u t, f x ∂μ) - ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by simpa using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab stronglyMeasurableAt_bot hmeas ((tendsto_bot : Tendsto _ ⊥ (𝓝 (0 : E))).mono_left inf_le_left) hf (tendsto_const_pure : Tendsto _ _ (pure a)) tendsto_const_pure hu hv #align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right /-- **Fundamental theorem of calculus-1**, strict derivative in left endpoint for a locally finite measure. Let `f` be a measurable function integrable on `a..b`. Let `(la, la')` be a pair of `intervalIntegral.FTCFilter`s around `a`. Suppose that `f` has a finite limit `c` at `la' ⊓ ae μ`. Then `∫ x in v..b, f x ∂μ - ∫ x in u..b, f x ∂μ = -∫ x in u..v, c ∂μ + o(∫ x in u..v, (1:ℝ) ∂μ)` as `u` and `v` tend to `la`. -/ theorem measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left (hab : IntervalIntegrable f μ a b) (hmeas : StronglyMeasurableAtFilter f la' μ) (hf : Tendsto f (la' ⊓ ae μ) (𝓝 c)) (hu : Tendsto u lt la) (hv : Tendsto v lt la) : (fun t => ((∫ x in v t..b, f x ∂μ) - ∫ x in u t..b, f x ∂μ) + ∫ _ in u t..v t, c ∂μ) =o[lt] fun t => ∫ _ in u t..v t, (1 : ℝ) ∂μ := by simpa using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab hmeas stronglyMeasurableAt_bot hf ((tendsto_bot : Tendsto _ ⊥ (𝓝 (0 : E))).mono_left inf_le_left) hu hv (tendsto_const_pure : Tendsto _ _ (pure b)) tendsto_const_pure #align interval_integral.measure_integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left intervalIntegral.measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left end /-! ### Fundamental theorem of calculus-1 for Lebesgue measure In this section we restate theorems from the previous section for Lebesgue measure. In particular, we prove that `∫ x in u..v, f x` is strictly differentiable in `(u, v)` at `(a, b)` provided that `f` is integrable on `a..b` and is continuous at `a` and `b`. -/ variable [CompleteSpace E] {f : ℝ → E} {c ca cb : E} {l l' la la' lb lb' : Filter ℝ} {lt : Filter ι} {a b z : ℝ} {u v ua ub va vb : ι → ℝ} [FTCFilter a la la'] [FTCFilter b lb lb'] /-! #### Auxiliary `Asymptotics.IsLittleO` statements In this section we prove several lemmas that can be interpreted as strict differentiability of `(u, v) ↦ ∫ x in u..v, f x ∂μ` in `u` and/or `v` at a filter. The statements use `Asymptotics.isLittleO` because we have no definition of `HasStrict(F)DerivAtFilter` in the library. -/ /-- **Fundamental theorem of calculus-1**, local version. If `f` has a finite limit `c` almost surely at `l'`, where `(l, l')` is an `intervalIntegral.FTCFilter` pair around `a`, then `∫ x in u..v, f x ∂μ = (v - u) • c + o (v - u)` as both `u` and `v` tend to `l`. -/ theorem integral_sub_linear_isLittleO_of_tendsto_ae [FTCFilter a l l'] (hfm : StronglyMeasurableAtFilter f l') (hf : Tendsto f (l' ⊓ ae volume) (𝓝 c)) {u v : ι → ℝ} (hu : Tendsto u lt l) (hv : Tendsto v lt l) : (fun t => (∫ x in u t..v t, f x) - (v t - u t) • c) =o[lt] (v - u) := by simpa [integral_const] using measure_integral_sub_linear_isLittleO_of_tendsto_ae hfm hf hu hv #align interval_integral.integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, strict differentiability at filter in both endpoints. If `f` is a measurable function integrable on `a..b`, `(la, la')` is an `intervalIntegral.FTCFilter` pair around `a`, and `(lb, lb')` is an `intervalIntegral.FTCFilter` pair around `b`, and `f` has finite limits `ca` and `cb` almost surely at `la'` and `lb'`, respectively, then `(∫ x in va..vb, f x) - ∫ x in ua..ub, f x = (vb - ub) • cb - (va - ua) • ca + o(‖va - ua‖ + ‖vb - ub‖)` as `ua` and `va` tend to `la` while `ub` and `vb` tend to `lb`. This lemma could've been formulated using `HasStrictFDerivAtFilter` if we had this definition. -/ theorem integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae (hab : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f la') (hmeas_b : StronglyMeasurableAtFilter f lb') (ha_lim : Tendsto f (la' ⊓ ae volume) (𝓝 ca)) (hb_lim : Tendsto f (lb' ⊓ ae volume) (𝓝 cb)) (hua : Tendsto ua lt la) (hva : Tendsto va lt la) (hub : Tendsto ub lt lb) (hvb : Tendsto vb lt lb) : (fun t => ((∫ x in va t..vb t, f x) - ∫ x in ua t..ub t, f x) - ((vb t - ub t) • cb - (va t - ua t) • ca)) =o[lt] fun t => ‖va t - ua t‖ + ‖vb t - ub t‖ := by simpa [integral_const] using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hab hmeas_a hmeas_b ha_lim hb_lim hua hva hub hvb #align interval_integral.integral_sub_integral_sub_linear_is_o_of_tendsto_ae intervalIntegral.integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, strict differentiability at filter in both endpoints. If `f` is a measurable function integrable on `a..b`, `(lb, lb')` is an `intervalIntegral.FTCFilter` pair around `b`, and `f` has a finite limit `c` almost surely at `lb'`, then `(∫ x in a..v, f x) - ∫ x in a..u, f x = (v - u) • c + o(‖v - u‖)` as `u` and `v` tend to `lb`. This lemma could've been formulated using `HasStrictDerivAtFilter` if we had this definition. -/ theorem integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right (hab : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f lb') (hf : Tendsto f (lb' ⊓ ae volume) (𝓝 c)) (hu : Tendsto u lt lb) (hv : Tendsto v lt lb) : (fun t => ((∫ x in a..v t, f x) - ∫ x in a..u t, f x) - (v t - u t) • c) =o[lt] (v - u) := by simpa only [integral_const, smul_eq_mul, mul_one] using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right hab hmeas hf hu hv #align interval_integral.integral_sub_integral_sub_linear_is_o_of_tendsto_ae_right intervalIntegral.integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right /-- **Fundamental theorem of calculus-1**, strict differentiability at filter in both endpoints. If `f` is a measurable function integrable on `a..b`, `(la, la')` is an `intervalIntegral.FTCFilter` pair around `a`, and `f` has a finite limit `c` almost surely at `la'`, then `(∫ x in v..b, f x) - ∫ x in u..b, f x = -(v - u) • c + o(‖v - u‖)` as `u` and `v` tend to `la`. This lemma could've been formulated using `HasStrictDerivAtFilter` if we had this definition. -/ theorem integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left (hab : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f la') (hf : Tendsto f (la' ⊓ ae volume) (𝓝 c)) (hu : Tendsto u lt la) (hv : Tendsto v lt la) : (fun t => ((∫ x in v t..b, f x) - ∫ x in u t..b, f x) + (v t - u t) • c) =o[lt] (v - u) := by simpa only [integral_const, smul_eq_mul, mul_one] using measure_integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left hab hmeas hf hu hv #align interval_integral.integral_sub_integral_sub_linear_is_o_of_tendsto_ae_left intervalIntegral.integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_left open ContinuousLinearMap (fst snd smulRight sub_apply smulRight_apply coe_fst' coe_snd' map_sub) /-! #### Strict differentiability In this section we prove that for a measurable function `f` integrable on `a..b`, * `integral_hasStrictFDerivAt_of_tendsto_ae`: the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability provided that `f` tends to `ca` and `cb` almost surely as `x` tendsto to `a` and `b`, respectively; * `integral_hasStrictFDerivAt`: the function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • f b - u • f a` at `(a, b)` in the sense of strict differentiability provided that `f` is continuous at `a` and `b`; * `integral_hasStrictDerivAt_of_tendsto_ae_right`: the function `u ↦ ∫ x in a..u, f x` has derivative `c` at `b` in the sense of strict differentiability provided that `f` tends to `c` almost surely as `x` tends to `b`; * `integral_hasStrictDerivAt_right`: the function `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b` in the sense of strict differentiability provided that `f` is continuous at `b`; * `integral_hasStrictDerivAt_of_tendsto_ae_left`: the function `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a` in the sense of strict differentiability provided that `f` tends to `c` almost surely as `x` tends to `a`; * `integral_hasStrictDerivAt_left`: the function `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a` in the sense of strict differentiability provided that `f` is continuous at `a`. -/ /-- **Fundamental theorem of calculus-1**, strict differentiability in both endpoints. If `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability. -/ theorem integral_hasStrictFDerivAt_of_tendsto_ae (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 cb)) : HasStrictFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca) (a, b) := by have := integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hf hmeas_a hmeas_b ha hb (continuous_snd.fst.tendsto ((a, b), (a, b))) (continuous_fst.fst.tendsto ((a, b), (a, b))) (continuous_snd.snd.tendsto ((a, b), (a, b))) (continuous_fst.snd.tendsto ((a, b), (a, b))) refine (this.congr_left ?_).trans_isBigO ?_ · intro x; simp [sub_smul]; abel · exact isBigO_fst_prod.norm_left.add isBigO_snd_prod.norm_left #align interval_integral.integral_has_strict_fderiv_at_of_tendsto_ae intervalIntegral.integral_hasStrictFDerivAt_of_tendsto_ae /-- **Fundamental theorem of calculus-1**, strict differentiability in both endpoints. If `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)` in the sense of strict differentiability. -/ theorem integral_hasStrictFDerivAt (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : ContinuousAt f a) (hb : ContinuousAt f b) : HasStrictFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a)) (a, b) := integral_hasStrictFDerivAt_of_tendsto_ae hf hmeas_a hmeas_b (ha.mono_left inf_le_left) (hb.mono_left inf_le_left) #align interval_integral.integral_has_strict_fderiv_at intervalIntegral.integral_hasStrictFDerivAt /-- **Fundamental theorem of calculus-1**, strict differentiability in the right endpoint. If `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `c` at `b` in the sense of strict differentiability. -/ theorem integral_hasStrictDerivAt_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 c)) : HasStrictDerivAt (fun u => ∫ x in a..u, f x) c b := integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right hf hmeas hb continuousAt_snd continuousAt_fst #align interval_integral.integral_has_strict_deriv_at_of_tendsto_ae_right intervalIntegral.integral_hasStrictDerivAt_of_tendsto_ae_right /-- **Fundamental theorem of calculus-1**, strict differentiability in the right endpoint. If `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b` in the sense of strict differentiability. -/ theorem integral_hasStrictDerivAt_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : ContinuousAt f b) : HasStrictDerivAt (fun u => ∫ x in a..u, f x) (f b) b := integral_hasStrictDerivAt_of_tendsto_ae_right hf hmeas (hb.mono_left inf_le_left) #align interval_integral.integral_has_strict_deriv_at_right intervalIntegral.integral_hasStrictDerivAt_right /-- **Fundamental theorem of calculus-1**, strict differentiability in the left endpoint. If `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a` in the sense of strict differentiability. -/ theorem integral_hasStrictDerivAt_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 c)) : HasStrictDerivAt (fun u => ∫ x in u..b, f x) (-c) a := by simpa only [← integral_symm] using (integral_hasStrictDerivAt_of_tendsto_ae_right hf.symm hmeas ha).neg #align interval_integral.integral_has_strict_deriv_at_of_tendsto_ae_left intervalIntegral.integral_hasStrictDerivAt_of_tendsto_ae_left /-- **Fundamental theorem of calculus-1**, strict differentiability in the left endpoint. If `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a` in the sense of strict differentiability. -/ theorem integral_hasStrictDerivAt_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : ContinuousAt f a) : HasStrictDerivAt (fun u => ∫ x in u..b, f x) (-f a) a := by simpa only [← integral_symm] using (integral_hasStrictDerivAt_right hf.symm hmeas ha).neg #align interval_integral.integral_has_strict_deriv_at_left intervalIntegral.integral_hasStrictDerivAt_left /-- **Fundamental theorem of calculus-1**, strict differentiability in the right endpoint. If `f : ℝ → E` is continuous, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b` in the sense of strict differentiability. -/ theorem _root_.Continuous.integral_hasStrictDerivAt {f : ℝ → E} (hf : Continuous f) (a b : ℝ) : HasStrictDerivAt (fun u => ∫ x : ℝ in a..u, f x) (f b) b := integral_hasStrictDerivAt_right (hf.intervalIntegrable _ _) (hf.stronglyMeasurableAtFilter _ _) hf.continuousAt #align continuous.integral_has_strict_deriv_at Continuous.integral_hasStrictDerivAt /-- **Fundamental theorem of calculus-1**, derivative in the right endpoint. If `f : ℝ → E` is continuous, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` is `f b`. -/ theorem _root_.Continuous.deriv_integral (f : ℝ → E) (hf : Continuous f) (a b : ℝ) : deriv (fun u => ∫ x : ℝ in a..u, f x) b = f b := (hf.integral_hasStrictDerivAt a b).hasDerivAt.deriv #align continuous.deriv_integral Continuous.deriv_integral /-! #### Fréchet differentiability In this subsection we restate results from the previous subsection in terms of `HasFDerivAt`, `HasDerivAt`, `fderiv`, and `deriv`. -/ /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)`. -/ theorem integral_hasFDerivAt_of_tendsto_ae (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 cb)) : HasFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca) (a, b) := (integral_hasStrictFDerivAt_of_tendsto_ae hf hmeas_a hmeas_b ha hb).hasFDerivAt #align interval_integral.integral_has_fderiv_at_of_tendsto_ae intervalIntegral.integral_hasFDerivAt_of_tendsto_ae /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` at `(a, b)`. -/ theorem integral_hasFDerivAt (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : ContinuousAt f a) (hb : ContinuousAt f b) : HasFDerivAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a)) (a, b) := (integral_hasStrictFDerivAt hf hmeas_a hmeas_b ha hb).hasFDerivAt #align interval_integral.integral_has_fderiv_at intervalIntegral.integral_hasFDerivAt /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has finite limits `ca` and `cb` almost surely as `x` tends to `a` and `b`, respectively, then `fderiv` derivative of `(u, v) ↦ ∫ x in u..v, f x` at `(a, b)` equals `(u, v) ↦ v • cb - u • ca`. -/ theorem fderiv_integral_of_tendsto_ae (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 cb)) : fderiv ℝ (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) (a, b) = (snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca := (integral_hasFDerivAt_of_tendsto_ae hf hmeas_a hmeas_b ha hb).fderiv #align interval_integral.fderiv_integral_of_tendsto_ae intervalIntegral.fderiv_integral_of_tendsto_ae /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a` and `b`, then `fderiv` derivative of `(u, v) ↦ ∫ x in u..v, f x` at `(a, b)` equals `(u, v) ↦ v • cb - u • ca`. -/ theorem fderiv_integral (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f (𝓝 a)) (hmeas_b : StronglyMeasurableAtFilter f (𝓝 b)) (ha : ContinuousAt f a) (hb : ContinuousAt f b) : fderiv ℝ (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) (a, b) = (snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a) := (integral_hasFDerivAt hf hmeas_a hmeas_b ha hb).fderiv #align interval_integral.fderiv_integral intervalIntegral.fderiv_integral /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `c` at `b`. -/ theorem integral_hasDerivAt_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 c)) : HasDerivAt (fun u => ∫ x in a..u, f x) c b := (integral_hasStrictDerivAt_of_tendsto_ae_right hf hmeas hb).hasDerivAt #align interval_integral.integral_has_deriv_at_of_tendsto_ae_right intervalIntegral.integral_hasDerivAt_of_tendsto_ae_right /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then `u ↦ ∫ x in a..u, f x` has derivative `f b` at `b`. -/ theorem integral_hasDerivAt_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : ContinuousAt f b) : HasDerivAt (fun u => ∫ x in a..u, f x) (f b) b := (integral_hasStrictDerivAt_right hf hmeas hb).hasDerivAt #align interval_integral.integral_has_deriv_at_right intervalIntegral.integral_hasDerivAt_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` has a finite limit `c` almost surely at `b`, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `c`. -/ theorem deriv_integral_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : Tendsto f (𝓝 b ⊓ ae volume) (𝓝 c)) : deriv (fun u => ∫ x in a..u, f x) b = c := (integral_hasDerivAt_of_tendsto_ae_right hf hmeas hb).deriv #align interval_integral.deriv_integral_of_tendsto_ae_right intervalIntegral.deriv_integral_of_tendsto_ae_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `b`, then the derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `f b`. -/ theorem deriv_integral_right (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 b)) (hb : ContinuousAt f b) : deriv (fun u => ∫ x in a..u, f x) b = f b := (integral_hasDerivAt_right hf hmeas hb).deriv #align interval_integral.deriv_integral_right intervalIntegral.deriv_integral_right /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-c` at `a`. -/ theorem integral_hasDerivAt_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 c)) : HasDerivAt (fun u => ∫ x in u..b, f x) (-c) a := (integral_hasStrictDerivAt_of_tendsto_ae_left hf hmeas ha).hasDerivAt #align interval_integral.integral_has_deriv_at_of_tendsto_ae_left intervalIntegral.integral_hasDerivAt_of_tendsto_ae_left /-- **Fundamental theorem of calculus-1**: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then `u ↦ ∫ x in u..b, f x` has derivative `-f a` at `a`. -/ theorem integral_hasDerivAt_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (ha : ContinuousAt f a) : HasDerivAt (fun u => ∫ x in u..b, f x) (-f a) a := (integral_hasStrictDerivAt_left hf hmeas ha).hasDerivAt #align interval_integral.integral_has_deriv_at_left intervalIntegral.integral_hasDerivAt_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` has a finite limit `c` almost surely at `a`, then the derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-c`. -/ theorem deriv_integral_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (hb : Tendsto f (𝓝 a ⊓ ae volume) (𝓝 c)) : deriv (fun u => ∫ x in u..b, f x) a = -c := (integral_hasDerivAt_of_tendsto_ae_left hf hmeas hb).deriv #align interval_integral.deriv_integral_of_tendsto_ae_left intervalIntegral.deriv_integral_of_tendsto_ae_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f` is continuous at `a`, then the derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-f a`. -/ theorem deriv_integral_left (hf : IntervalIntegrable f volume a b) (hmeas : StronglyMeasurableAtFilter f (𝓝 a)) (hb : ContinuousAt f a) : deriv (fun u => ∫ x in u..b, f x) a = -f a := (integral_hasDerivAt_left hf hmeas hb).deriv #align interval_integral.deriv_integral_left intervalIntegral.deriv_integral_left /-! #### One-sided derivatives -/ /-- Let `f` be a measurable function integrable on `a..b`. The function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • cb - u • ca` within `s × t` at `(a, b)`, where `s ∈ {Iic a, {a}, Ici a, univ}` and `t ∈ {Iic b, {b}, Ici b, univ}` provided that `f` tends to `ca` and `cb` almost surely at the filters `la` and `lb` from the following table. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` | | `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | -/ theorem integral_hasFDerivWithinAt_of_tendsto_ae (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) la] [FTCFilter b (𝓝[t] b) lb] (hmeas_a : StronglyMeasurableAtFilter f la) (hmeas_b : StronglyMeasurableAtFilter f lb) (ha : Tendsto f (la ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (lb ⊓ ae volume) (𝓝 cb)) : HasFDerivWithinAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca) (s ×ˢ t) (a, b) := by rw [HasFDerivWithinAt, nhdsWithin_prod_eq] have := integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae hf hmeas_a hmeas_b ha hb (tendsto_const_pure.mono_right FTCFilter.pure_le : Tendsto _ _ (𝓝[s] a)) tendsto_fst (tendsto_const_pure.mono_right FTCFilter.pure_le : Tendsto _ _ (𝓝[t] b)) tendsto_snd refine .of_isLittleO <| (this.congr_left ?_).trans_isBigO ?_ · intro x; simp [sub_smul]; abel · exact isBigO_fst_prod.norm_left.add isBigO_snd_prod.norm_left #align interval_integral.integral_has_fderiv_within_at_of_tendsto_ae intervalIntegral.integral_hasFDerivWithinAt_of_tendsto_ae /-- Let `f` be a measurable function integrable on `a..b`. The function `(u, v) ↦ ∫ x in u..v, f x` has derivative `(u, v) ↦ v • f b - u • f a` within `s × t` at `(a, b)`, where `s ∈ {Iic a, {a}, Ici a, univ}` and `t ∈ {Iic b, {b}, Ici b, univ}` provided that `f` tends to `f a` and `f b` at the filters `la` and `lb` from the following table. In most cases this assumption is definitionally equal `ContinuousAt f _` or `ContinuousWithinAt f _ _`. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` | | `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | -/ theorem integral_hasFDerivWithinAt (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f la) (hmeas_b : StronglyMeasurableAtFilter f lb) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) la] [FTCFilter b (𝓝[t] b) lb] (ha : Tendsto f la (𝓝 <| f a)) (hb : Tendsto f lb (𝓝 <| f b)) : HasFDerivWithinAt (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) ((snd ℝ ℝ ℝ).smulRight (f b) - (fst ℝ ℝ ℝ).smulRight (f a)) (s ×ˢ t) (a, b) := integral_hasFDerivWithinAt_of_tendsto_ae hf hmeas_a hmeas_b (ha.mono_left inf_le_left) (hb.mono_left inf_le_left) #align interval_integral.integral_has_fderiv_within_at intervalIntegral.integral_hasFDerivWithinAt /-- An auxiliary tactic closing goals `UniqueDiffWithinAt ℝ s a` where `s ∈ {Iic a, Ici a, univ}`. -/ macro "uniqueDiffWithinAt_Ici_Iic_univ" : tactic => `(tactic| (first | exact uniqueDiffOn_Ici _ _ left_mem_Ici | exact uniqueDiffOn_Iic _ _ right_mem_Iic | exact uniqueDiffWithinAt_univ (𝕜 := ℝ) (E := ℝ))) #noalign interval_integral.unique_diff_within_at_Ici_Iic_univ /-- Let `f` be a measurable function integrable on `a..b`. Choose `s ∈ {Iic a, Ici a, univ}` and `t ∈ {Iic b, Ici b, univ}`. Suppose that `f` tends to `ca` and `cb` almost surely at the filters `la` and `lb` from the table below. Then `fderivWithin ℝ (fun p ↦ ∫ x in p.1..p.2, f x) (s ×ˢ t)` is equal to `(u, v) ↦ u • cb - v • ca`. | `s` | `la` | `t` | `lb` | | ------- | ---- | --- | ---- | | `Iic a` | `𝓝[≤] a` | `Iic b` | `𝓝[≤] b` | | `Ici a` | `𝓝[>] a` | `Ici b` | `𝓝[>] b` | | `{a}` | `⊥` | `{b}` | `⊥` | | `univ` | `𝓝 a` | `univ` | `𝓝 b` | -/ theorem fderivWithin_integral_of_tendsto_ae (hf : IntervalIntegrable f volume a b) (hmeas_a : StronglyMeasurableAtFilter f la) (hmeas_b : StronglyMeasurableAtFilter f lb) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) la] [FTCFilter b (𝓝[t] b) lb] (ha : Tendsto f (la ⊓ ae volume) (𝓝 ca)) (hb : Tendsto f (lb ⊓ ae volume) (𝓝 cb)) (hs : UniqueDiffWithinAt ℝ s a := by uniqueDiffWithinAt_Ici_Iic_univ) (ht : UniqueDiffWithinAt ℝ t b := by uniqueDiffWithinAt_Ici_Iic_univ) : fderivWithin ℝ (fun p : ℝ × ℝ => ∫ x in p.1..p.2, f x) (s ×ˢ t) (a, b) = (snd ℝ ℝ ℝ).smulRight cb - (fst ℝ ℝ ℝ).smulRight ca := (integral_hasFDerivWithinAt_of_tendsto_ae hf hmeas_a hmeas_b ha hb).fderivWithin <| hs.prod ht #align interval_integral.fderiv_within_integral_of_tendsto_ae intervalIntegral.fderivWithin_integral_of_tendsto_ae /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `b` from the right or from the left, then `u ↦ ∫ x in a..u, f x` has right (resp., left) derivative `c` at `b`. -/ theorem integral_hasDerivWithinAt_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter b (𝓝[s] b) (𝓝[t] b)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] b)) (hb : Tendsto f (𝓝[t] b ⊓ ae volume) (𝓝 c)) : HasDerivWithinAt (fun u => ∫ x in a..u, f x) c s b := .of_isLittleO <| integral_sub_integral_sub_linear_isLittleO_of_tendsto_ae_right hf hmeas hb (tendsto_const_pure.mono_right FTCFilter.pure_le) tendsto_id #align interval_integral.integral_has_deriv_within_at_of_tendsto_ae_right intervalIntegral.integral_hasDerivWithinAt_of_tendsto_ae_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous from the left or from the right at `b`, then `u ↦ ∫ x in a..u, f x` has left (resp., right) derivative `f b` at `b`. -/ theorem integral_hasDerivWithinAt_right (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter b (𝓝[s] b) (𝓝[t] b)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] b)) (hb : ContinuousWithinAt f t b) : HasDerivWithinAt (fun u => ∫ x in a..u, f x) (f b) s b := integral_hasDerivWithinAt_of_tendsto_ae_right hf hmeas (hb.mono_left inf_le_left) #align interval_integral.integral_has_deriv_within_at_right intervalIntegral.integral_hasDerivWithinAt_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `b` from the right or from the left, then the right (resp., left) derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `c`. -/ theorem derivWithin_integral_of_tendsto_ae_right (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter b (𝓝[s] b) (𝓝[t] b)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] b)) (hb : Tendsto f (𝓝[t] b ⊓ ae volume) (𝓝 c)) (hs : UniqueDiffWithinAt ℝ s b := by uniqueDiffWithinAt_Ici_Iic_univ) : derivWithin (fun u => ∫ x in a..u, f x) s b = c := (integral_hasDerivWithinAt_of_tendsto_ae_right hf hmeas hb).derivWithin hs #align interval_integral.deriv_within_integral_of_tendsto_ae_right intervalIntegral.derivWithin_integral_of_tendsto_ae_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous on the right or on the left at `b`, then the right (resp., left) derivative of `u ↦ ∫ x in a..u, f x` at `b` equals `f b`. -/ theorem derivWithin_integral_right (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter b (𝓝[s] b) (𝓝[t] b)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] b)) (hb : ContinuousWithinAt f t b) (hs : UniqueDiffWithinAt ℝ s b := by uniqueDiffWithinAt_Ici_Iic_univ) : derivWithin (fun u => ∫ x in a..u, f x) s b = f b := (integral_hasDerivWithinAt_right hf hmeas hb).derivWithin hs #align interval_integral.deriv_within_integral_right intervalIntegral.derivWithin_integral_right /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `a` from the right or from the left, then `u ↦ ∫ x in u..b, f x` has right (resp., left) derivative `-c` at `a`. -/ theorem integral_hasDerivWithinAt_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) (𝓝[t] a)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] a)) (ha : Tendsto f (𝓝[t] a ⊓ ae volume) (𝓝 c)) : HasDerivWithinAt (fun u => ∫ x in u..b, f x) (-c) s a := by simp only [integral_symm b] exact (integral_hasDerivWithinAt_of_tendsto_ae_right hf.symm hmeas ha).neg #align interval_integral.integral_has_deriv_within_at_of_tendsto_ae_left intervalIntegral.integral_hasDerivWithinAt_of_tendsto_ae_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous from the left or from the right at `a`, then `u ↦ ∫ x in u..b, f x` has left (resp., right) derivative `-f a` at `a`. -/ theorem integral_hasDerivWithinAt_left (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) (𝓝[t] a)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] a)) (ha : ContinuousWithinAt f t a) : HasDerivWithinAt (fun u => ∫ x in u..b, f x) (-f a) s a := integral_hasDerivWithinAt_of_tendsto_ae_left hf hmeas (ha.mono_left inf_le_left) #align interval_integral.integral_has_deriv_within_at_left intervalIntegral.integral_hasDerivWithinAt_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` has a finite limit `c` almost surely as `x` tends to `a` from the right or from the left, then the right (resp., left) derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-c`. -/ theorem derivWithin_integral_of_tendsto_ae_left (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) (𝓝[t] a)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] a)) (ha : Tendsto f (𝓝[t] a ⊓ ae volume) (𝓝 c)) (hs : UniqueDiffWithinAt ℝ s a := by uniqueDiffWithinAt_Ici_Iic_univ) : derivWithin (fun u => ∫ x in u..b, f x) s a = -c := (integral_hasDerivWithinAt_of_tendsto_ae_left hf hmeas ha).derivWithin hs #align interval_integral.deriv_within_integral_of_tendsto_ae_left intervalIntegral.derivWithin_integral_of_tendsto_ae_left /-- Fundamental theorem of calculus: if `f : ℝ → E` is integrable on `a..b` and `f x` is continuous on the right or on the left at `a`, then the right (resp., left) derivative of `u ↦ ∫ x in u..b, f x` at `a` equals `-f a`. -/ theorem derivWithin_integral_left (hf : IntervalIntegrable f volume a b) {s t : Set ℝ} [FTCFilter a (𝓝[s] a) (𝓝[t] a)] (hmeas : StronglyMeasurableAtFilter f (𝓝[t] a)) (ha : ContinuousWithinAt f t a) (hs : UniqueDiffWithinAt ℝ s a := by uniqueDiffWithinAt_Ici_Iic_univ) : derivWithin (fun u => ∫ x in u..b, f x) s a = -f a := (integral_hasDerivWithinAt_left hf hmeas ha).derivWithin hs #align interval_integral.deriv_within_integral_left intervalIntegral.derivWithin_integral_left /-- The integral of a continuous function is differentiable on a real set `s`. -/ theorem differentiableOn_integral_of_continuous {s : Set ℝ} (hintg : ∀ x ∈ s, IntervalIntegrable f volume a x) (hcont : Continuous f) : DifferentiableOn ℝ (fun u => ∫ x in a..u, f x) s := fun y hy => (integral_hasDerivAt_right (hintg y hy) hcont.aestronglyMeasurable.stronglyMeasurableAtFilter hcont.continuousAt).differentiableAt.differentiableWithinAt #align interval_integral.differentiable_on_integral_of_continuous intervalIntegral.differentiableOn_integral_of_continuous end FTC1 /-! ### Fundamental theorem of calculus, part 2 This section contains theorems pertaining to FTC-2 for interval integrals, i.e., the assertion that `∫ x in a..b, f' x = f b - f a` under suitable assumptions. The most classical version of this theorem assumes that `f'` is continuous. However, this is unnecessarily strong: the result holds if `f'` is just integrable. We prove the strong version, following [Rudin, *Real and Complex Analysis* (Theorem 7.21)][rudin2006real]. The proof is first given for real-valued functions, and then deduced for functions with a general target space. For a real-valued function `g`, it suffices to show that `g b - g a ≤ (∫ x in a..b, g' x) + ε` for all positive `ε`. To prove this, choose a lower-semicontinuous function `G'` with `g' < G'` and with integral close to that of `g'` (its existence is guaranteed by the Vitali-Carathéodory theorem). It satisfies `g t - g a ≤ ∫ x in a..t, G' x` for all `t ∈ [a, b]`: this inequality holds at `a`, and if it holds at `t` then it holds for `u` close to `t` on its right, as the left hand side increases by `g u - g t ∼ (u -t) g' t`, while the right hand side increases by `∫ x in t..u, G' x` which is roughly at least `∫ x in t..u, G' t = (u - t) G' t`, by lower semicontinuity. As `g' t < G' t`, this gives the conclusion. One can therefore push progressively this inequality to the right until the point `b`, where it gives the desired conclusion. -/ variable {f : ℝ → E} {g' g φ : ℝ → ℝ} /-- Hard part of FTC-2 for integrable derivatives, real-valued functions: one has `g b - g a ≤ ∫ y in a..b, g' y` when `g'` is integrable. Auxiliary lemma in the proof of `integral_eq_sub_of_hasDeriv_right_of_le`. We give the slightly more general version that `g b - g a ≤ ∫ y in a..b, φ y` when `g' ≤ φ` and `φ` is integrable (even if `g'` is not known to be integrable). Version assuming that `g` is differentiable on `[a, b)`. -/
Mathlib/MeasureTheory/Integral/FundThmCalculus.lean
1,024
1,114
theorem sub_le_integral_of_hasDeriv_right_of_le_Ico (hab : a ≤ b) (hcont : ContinuousOn g (Icc a b)) (hderiv : ∀ x ∈ Ico a b, HasDerivWithinAt g (g' x) (Ioi x) x) (φint : IntegrableOn φ (Icc a b)) (hφg : ∀ x ∈ Ico a b, g' x ≤ φ x) : g b - g a ≤ ∫ y in a..b, φ y := by
refine le_of_forall_pos_le_add fun ε εpos => ?_ -- Bound from above `g'` by a lower-semicontinuous function `G'`. rcases exists_lt_lowerSemicontinuous_integral_lt φ φint εpos with ⟨G', f_lt_G', G'cont, G'int, G'lt_top, hG'⟩ -- we will show by "induction" that `g t - g a ≤ ∫ u in a..t, G' u` for all `t ∈ [a, b]`. set s := {t | g t - g a ≤ ∫ u in a..t, (G' u).toReal} ∩ Icc a b -- the set `s` of points where this property holds is closed. have s_closed : IsClosed s := by have : ContinuousOn (fun t => (g t - g a, ∫ u in a..t, (G' u).toReal)) (Icc a b) := by rw [← uIcc_of_le hab] at G'int hcont ⊢ exact (hcont.sub continuousOn_const).prod (continuousOn_primitive_interval G'int) simp only [s, inter_comm] exact this.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' have main : Icc a b ⊆ {t | g t - g a ≤ ∫ u in a..t, (G' u).toReal} := by -- to show that the set `s` is all `[a, b]`, it suffices to show that any point `t` in `s` -- with `t < b` admits another point in `s` slightly to its right -- (this is a sort of real induction). refine s_closed.Icc_subset_of_forall_exists_gt (by simp only [integral_same, mem_setOf_eq, sub_self, le_rfl]) fun t ht v t_lt_v => ?_ obtain ⟨y, g'_lt_y', y_lt_G'⟩ : ∃ y : ℝ, (g' t : EReal) < y ∧ (y : EReal) < G' t := EReal.lt_iff_exists_real_btwn.1 ((EReal.coe_le_coe_iff.2 (hφg t ht.2)).trans_lt (f_lt_G' t)) -- bound from below the increase of `∫ x in a..u, G' x` on the right of `t`, using the lower -- semicontinuity of `G'`. have I1 : ∀ᶠ u in 𝓝[>] t, (u - t) * y ≤ ∫ w in t..u, (G' w).toReal := by have B : ∀ᶠ u in 𝓝 t, (y : EReal) < G' u := G'cont.lowerSemicontinuousAt _ _ y_lt_G' rcases mem_nhds_iff_exists_Ioo_subset.1 B with ⟨m, M, ⟨hm, hM⟩, H⟩ have : Ioo t (min M b) ∈ 𝓝[>] t := Ioo_mem_nhdsWithin_Ioi' (lt_min hM ht.right.right) filter_upwards [this] with u hu have I : Icc t u ⊆ Icc a b := Icc_subset_Icc ht.2.1 (hu.2.le.trans (min_le_right _ _)) calc (u - t) * y = ∫ _ in Icc t u, y := by simp only [hu.left.le, MeasureTheory.integral_const, Algebra.id.smul_eq_mul, sub_nonneg, MeasurableSet.univ, Real.volume_Icc, Measure.restrict_apply, univ_inter, ENNReal.toReal_ofReal] _ ≤ ∫ w in t..u, (G' w).toReal := by rw [intervalIntegral.integral_of_le hu.1.le, ← integral_Icc_eq_integral_Ioc] apply setIntegral_mono_ae_restrict · simp only [integrableOn_const, Real.volume_Icc, ENNReal.ofReal_lt_top, or_true_iff] · exact IntegrableOn.mono_set G'int I · have C1 : ∀ᵐ x : ℝ ∂volume.restrict (Icc t u), G' x < ∞ := ae_mono (Measure.restrict_mono I le_rfl) G'lt_top have C2 : ∀ᵐ x : ℝ ∂volume.restrict (Icc t u), x ∈ Icc t u := ae_restrict_mem measurableSet_Icc filter_upwards [C1, C2] with x G'x hx apply EReal.coe_le_coe_iff.1 have : x ∈ Ioo m M := by simp only [hm.trans_le hx.left, (hx.right.trans_lt hu.right).trans_le (min_le_left M b), mem_Ioo, and_self_iff] refine (H this).out.le.trans_eq ?_ exact (EReal.coe_toReal G'x.ne (f_lt_G' x).ne_bot).symm -- bound from above the increase of `g u - g a` on the right of `t`, using the derivative at `t` have I2 : ∀ᶠ u in 𝓝[>] t, g u - g t ≤ (u - t) * y := by have g'_lt_y : g' t < y := EReal.coe_lt_coe_iff.1 g'_lt_y' filter_upwards [(hderiv t ⟨ht.2.1, ht.2.2⟩).limsup_slope_le' (not_mem_Ioi.2 le_rfl) g'_lt_y, self_mem_nhdsWithin] with u hu t_lt_u have := mul_le_mul_of_nonneg_left hu.le (sub_pos.2 t_lt_u.out).le rwa [← smul_eq_mul, sub_smul_slope] at this -- combine the previous two bounds to show that `g u - g a` increases less quickly than -- `∫ x in a..u, G' x`. have I3 : ∀ᶠ u in 𝓝[>] t, g u - g t ≤ ∫ w in t..u, (G' w).toReal := by filter_upwards [I1, I2] with u hu1 hu2 using hu2.trans hu1 have I4 : ∀ᶠ u in 𝓝[>] t, u ∈ Ioc t (min v b) := by refine mem_nhdsWithin_Ioi_iff_exists_Ioc_subset.2 ⟨min v b, ?_, Subset.rfl⟩ simp only [lt_min_iff, mem_Ioi] exact ⟨t_lt_v, ht.2.2⟩ -- choose a point `x` slightly to the right of `t` which satisfies the above bound rcases (I3.and I4).exists with ⟨x, hx, h'x⟩ -- we check that it belongs to `s`, essentially by construction refine ⟨x, ?_, Ioc_subset_Ioc le_rfl (min_le_left _ _) h'x⟩ calc g x - g a = g t - g a + (g x - g t) := by abel _ ≤ (∫ w in a..t, (G' w).toReal) + ∫ w in t..x, (G' w).toReal := add_le_add ht.1 hx _ = ∫ w in a..x, (G' w).toReal := by apply integral_add_adjacent_intervals · rw [intervalIntegrable_iff_integrableOn_Ioc_of_le ht.2.1] exact IntegrableOn.mono_set G'int (Ioc_subset_Icc_self.trans (Icc_subset_Icc le_rfl ht.2.2.le)) · rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x.1.le] apply IntegrableOn.mono_set G'int exact Ioc_subset_Icc_self.trans (Icc_subset_Icc ht.2.1 (h'x.2.trans (min_le_right _ _))) -- now that we know that `s` contains `[a, b]`, we get the desired result by applying this to `b`. calc g b - g a ≤ ∫ y in a..b, (G' y).toReal := main (right_mem_Icc.2 hab) _ ≤ (∫ y in a..b, φ y) + ε := by convert hG'.le <;> · rw [intervalIntegral.integral_of_le hab] simp only [integral_Icc_eq_integral_Ioc', Real.volume_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, Patrick Massot -/ import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Algebra.Order.Interval.Set.Monoid import Mathlib.Data.Set.Pointwise.Basic import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax #align_import data.set.pointwise.interval from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # (Pre)images of intervals In this file we prove a bunch of trivial lemmas like “if we add `a` to all points of `[b, c]`, then we get `[a + b, a + c]`”. For the functions `x ↦ x ± a`, `x ↦ a ± x`, and `x ↦ -x` we prove lemmas about preimages and images of all intervals. We also prove a few lemmas about images under `x ↦ a * x`, `x ↦ x * a` and `x ↦ x⁻¹`. -/ open Interval Pointwise variable {α : Type*} namespace Set /-! ### Binary pointwise operations Note that the subset operations below only cover the cases with the largest possible intervals on the LHS: to conclude that `Ioo a b * Ioo c d ⊆ Ioo (a * c) (c * d)`, you can use monotonicity of `*` and `Set.Ico_mul_Ioc_subset`. TODO: repeat these lemmas for the generality of `mul_le_mul` (which assumes nonnegativity), which the unprimed names have been reserved for -/ section ContravariantLE variable [Mul α] [Preorder α] variable [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (Function.swap HMul.hMul) LE.le] @[to_additive Icc_add_Icc_subset] theorem Icc_mul_Icc_subset' (a b c d : α) : Icc a b * Icc c d ⊆ Icc (a * c) (b * d) := by rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_le_mul' hyb hzd⟩ @[to_additive Iic_add_Iic_subset] theorem Iic_mul_Iic_subset' (a b : α) : Iic a * Iic b ⊆ Iic (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb @[to_additive Ici_add_Ici_subset] theorem Ici_mul_Ici_subset' (a b : α) : Ici a * Ici b ⊆ Ici (a * b) := by rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_le_mul' hya hzb end ContravariantLE section ContravariantLT variable [Mul α] [PartialOrder α] variable [CovariantClass α α (· * ·) (· < ·)] [CovariantClass α α (Function.swap HMul.hMul) LT.lt] @[to_additive Icc_add_Ico_subset] theorem Icc_mul_Ico_subset' (a b c d : α) : Icc a b * Ico c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Icc_subset] theorem Ico_mul_Icc_subset' (a b c d : α) : Ico a b * Icc c d ⊆ Ico (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_le_mul' hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Ioc_add_Ico_subset] theorem Ioc_mul_Ico_subset' (a b c d : α) : Ioc a b * Ico c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_lt_of_le hya hzc, mul_lt_mul_of_le_of_lt hyb hzd⟩ @[to_additive Ico_add_Ioc_subset] theorem Ico_mul_Ioc_subset' (a b c d : α) : Ico a b * Ioc c d ⊆ Ioo (a * c) (b * d) := by haveI := covariantClass_le_of_lt rintro x ⟨y, ⟨hya, hyb⟩, z, ⟨hzc, hzd⟩, rfl⟩ exact ⟨mul_lt_mul_of_le_of_lt hya hzc, mul_lt_mul_of_lt_of_le hyb hzd⟩ @[to_additive Iic_add_Iio_subset] theorem Iic_mul_Iio_subset' (a b : α) : Iic a * Iio b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb @[to_additive Iio_add_Iic_subset] theorem Iio_mul_Iic_subset' (a b : α) : Iio a * Iic b ⊆ Iio (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ioi_add_Ici_subset] theorem Ioi_mul_Ici_subset' (a b : α) : Ioi a * Ici b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_lt_of_le hya hzb @[to_additive Ici_add_Ioi_subset] theorem Ici_mul_Ioi_subset' (a b : α) : Ici a * Ioi b ⊆ Ioi (a * b) := by haveI := covariantClass_le_of_lt rintro x ⟨y, hya, z, hzb, rfl⟩ exact mul_lt_mul_of_le_of_lt hya hzb end ContravariantLT section OrderedAddCommGroup variable [OrderedAddCommGroup α] (a b c : α) /-! ### Preimages under `x ↦ a + x` -/ @[simp] theorem preimage_const_add_Ici : (fun x => a + x) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add'.symm #align set.preimage_const_add_Ici Set.preimage_const_add_Ici @[simp] theorem preimage_const_add_Ioi : (fun x => a + x) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add'.symm #align set.preimage_const_add_Ioi Set.preimage_const_add_Ioi @[simp] theorem preimage_const_add_Iic : (fun x => a + x) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le'.symm #align set.preimage_const_add_Iic Set.preimage_const_add_Iic @[simp] theorem preimage_const_add_Iio : (fun x => a + x) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt'.symm #align set.preimage_const_add_Iio Set.preimage_const_add_Iio @[simp] theorem preimage_const_add_Icc : (fun x => a + x) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_const_add_Icc Set.preimage_const_add_Icc @[simp] theorem preimage_const_add_Ico : (fun x => a + x) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_const_add_Ico Set.preimage_const_add_Ico @[simp] theorem preimage_const_add_Ioc : (fun x => a + x) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_const_add_Ioc Set.preimage_const_add_Ioc @[simp] theorem preimage_const_add_Ioo : (fun x => a + x) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_const_add_Ioo Set.preimage_const_add_Ioo /-! ### Preimages under `x ↦ x + a` -/ @[simp] theorem preimage_add_const_Ici : (fun x => x + a) ⁻¹' Ici b = Ici (b - a) := ext fun _x => sub_le_iff_le_add.symm #align set.preimage_add_const_Ici Set.preimage_add_const_Ici @[simp] theorem preimage_add_const_Ioi : (fun x => x + a) ⁻¹' Ioi b = Ioi (b - a) := ext fun _x => sub_lt_iff_lt_add.symm #align set.preimage_add_const_Ioi Set.preimage_add_const_Ioi @[simp] theorem preimage_add_const_Iic : (fun x => x + a) ⁻¹' Iic b = Iic (b - a) := ext fun _x => le_sub_iff_add_le.symm #align set.preimage_add_const_Iic Set.preimage_add_const_Iic @[simp] theorem preimage_add_const_Iio : (fun x => x + a) ⁻¹' Iio b = Iio (b - a) := ext fun _x => lt_sub_iff_add_lt.symm #align set.preimage_add_const_Iio Set.preimage_add_const_Iio @[simp] theorem preimage_add_const_Icc : (fun x => x + a) ⁻¹' Icc b c = Icc (b - a) (c - a) := by simp [← Ici_inter_Iic] #align set.preimage_add_const_Icc Set.preimage_add_const_Icc @[simp] theorem preimage_add_const_Ico : (fun x => x + a) ⁻¹' Ico b c = Ico (b - a) (c - a) := by simp [← Ici_inter_Iio] #align set.preimage_add_const_Ico Set.preimage_add_const_Ico @[simp] theorem preimage_add_const_Ioc : (fun x => x + a) ⁻¹' Ioc b c = Ioc (b - a) (c - a) := by simp [← Ioi_inter_Iic] #align set.preimage_add_const_Ioc Set.preimage_add_const_Ioc @[simp] theorem preimage_add_const_Ioo : (fun x => x + a) ⁻¹' Ioo b c = Ioo (b - a) (c - a) := by simp [← Ioi_inter_Iio] #align set.preimage_add_const_Ioo Set.preimage_add_const_Ioo /-! ### Preimages under `x ↦ -x` -/ @[simp] theorem preimage_neg_Ici : -Ici a = Iic (-a) := ext fun _x => le_neg #align set.preimage_neg_Ici Set.preimage_neg_Ici @[simp] theorem preimage_neg_Iic : -Iic a = Ici (-a) := ext fun _x => neg_le #align set.preimage_neg_Iic Set.preimage_neg_Iic @[simp] theorem preimage_neg_Ioi : -Ioi a = Iio (-a) := ext fun _x => lt_neg #align set.preimage_neg_Ioi Set.preimage_neg_Ioi @[simp] theorem preimage_neg_Iio : -Iio a = Ioi (-a) := ext fun _x => neg_lt #align set.preimage_neg_Iio Set.preimage_neg_Iio @[simp] theorem preimage_neg_Icc : -Icc a b = Icc (-b) (-a) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_neg_Icc Set.preimage_neg_Icc @[simp] theorem preimage_neg_Ico : -Ico a b = Ioc (-b) (-a) := by simp [← Ici_inter_Iio, ← Ioi_inter_Iic, inter_comm] #align set.preimage_neg_Ico Set.preimage_neg_Ico @[simp] theorem preimage_neg_Ioc : -Ioc a b = Ico (-b) (-a) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_neg_Ioc Set.preimage_neg_Ioc @[simp] theorem preimage_neg_Ioo : -Ioo a b = Ioo (-b) (-a) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_neg_Ioo Set.preimage_neg_Ioo /-! ### Preimages under `x ↦ x - a` -/ @[simp] theorem preimage_sub_const_Ici : (fun x => x - a) ⁻¹' Ici b = Ici (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ici Set.preimage_sub_const_Ici @[simp] theorem preimage_sub_const_Ioi : (fun x => x - a) ⁻¹' Ioi b = Ioi (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioi Set.preimage_sub_const_Ioi @[simp] theorem preimage_sub_const_Iic : (fun x => x - a) ⁻¹' Iic b = Iic (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iic Set.preimage_sub_const_Iic @[simp] theorem preimage_sub_const_Iio : (fun x => x - a) ⁻¹' Iio b = Iio (b + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Iio Set.preimage_sub_const_Iio @[simp] theorem preimage_sub_const_Icc : (fun x => x - a) ⁻¹' Icc b c = Icc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Icc Set.preimage_sub_const_Icc @[simp] theorem preimage_sub_const_Ico : (fun x => x - a) ⁻¹' Ico b c = Ico (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ico Set.preimage_sub_const_Ico @[simp] theorem preimage_sub_const_Ioc : (fun x => x - a) ⁻¹' Ioc b c = Ioc (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioc Set.preimage_sub_const_Ioc @[simp] theorem preimage_sub_const_Ioo : (fun x => x - a) ⁻¹' Ioo b c = Ioo (b + a) (c + a) := by simp [sub_eq_add_neg] #align set.preimage_sub_const_Ioo Set.preimage_sub_const_Ioo /-! ### Preimages under `x ↦ a - x` -/ @[simp] theorem preimage_const_sub_Ici : (fun x => a - x) ⁻¹' Ici b = Iic (a - b) := ext fun _x => le_sub_comm #align set.preimage_const_sub_Ici Set.preimage_const_sub_Ici @[simp] theorem preimage_const_sub_Iic : (fun x => a - x) ⁻¹' Iic b = Ici (a - b) := ext fun _x => sub_le_comm #align set.preimage_const_sub_Iic Set.preimage_const_sub_Iic @[simp] theorem preimage_const_sub_Ioi : (fun x => a - x) ⁻¹' Ioi b = Iio (a - b) := ext fun _x => lt_sub_comm #align set.preimage_const_sub_Ioi Set.preimage_const_sub_Ioi @[simp] theorem preimage_const_sub_Iio : (fun x => a - x) ⁻¹' Iio b = Ioi (a - b) := ext fun _x => sub_lt_comm #align set.preimage_const_sub_Iio Set.preimage_const_sub_Iio @[simp] theorem preimage_const_sub_Icc : (fun x => a - x) ⁻¹' Icc b c = Icc (a - c) (a - b) := by simp [← Ici_inter_Iic, inter_comm] #align set.preimage_const_sub_Icc Set.preimage_const_sub_Icc @[simp] theorem preimage_const_sub_Ico : (fun x => a - x) ⁻¹' Ico b c = Ioc (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ico Set.preimage_const_sub_Ico @[simp] theorem preimage_const_sub_Ioc : (fun x => a - x) ⁻¹' Ioc b c = Ico (a - c) (a - b) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioc Set.preimage_const_sub_Ioc @[simp] theorem preimage_const_sub_Ioo : (fun x => a - x) ⁻¹' Ioo b c = Ioo (a - c) (a - b) := by simp [← Ioi_inter_Iio, inter_comm] #align set.preimage_const_sub_Ioo Set.preimage_const_sub_Ioo /-! ### Images under `x ↦ a + x` -/ -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iic : (fun x => a + x) '' Iic b = Iic (a + b) := by simp [add_comm] #align set.image_const_add_Iic Set.image_const_add_Iic -- @[simp] -- Porting note (#10618): simp can prove this modulo `add_comm` theorem image_const_add_Iio : (fun x => a + x) '' Iio b = Iio (a + b) := by simp [add_comm] #align set.image_const_add_Iio Set.image_const_add_Iio /-! ### Images under `x ↦ x + a` -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_Iic : (fun x => x + a) '' Iic b = Iic (b + a) := by simp #align set.image_add_const_Iic Set.image_add_const_Iic -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_Iio : (fun x => x + a) '' Iio b = Iio (b + a) := by simp #align set.image_add_const_Iio Set.image_add_const_Iio /-! ### Images under `x ↦ -x` -/ theorem image_neg_Ici : Neg.neg '' Ici a = Iic (-a) := by simp #align set.image_neg_Ici Set.image_neg_Ici theorem image_neg_Iic : Neg.neg '' Iic a = Ici (-a) := by simp #align set.image_neg_Iic Set.image_neg_Iic theorem image_neg_Ioi : Neg.neg '' Ioi a = Iio (-a) := by simp #align set.image_neg_Ioi Set.image_neg_Ioi theorem image_neg_Iio : Neg.neg '' Iio a = Ioi (-a) := by simp #align set.image_neg_Iio Set.image_neg_Iio theorem image_neg_Icc : Neg.neg '' Icc a b = Icc (-b) (-a) := by simp #align set.image_neg_Icc Set.image_neg_Icc theorem image_neg_Ico : Neg.neg '' Ico a b = Ioc (-b) (-a) := by simp #align set.image_neg_Ico Set.image_neg_Ico theorem image_neg_Ioc : Neg.neg '' Ioc a b = Ico (-b) (-a) := by simp #align set.image_neg_Ioc Set.image_neg_Ioc theorem image_neg_Ioo : Neg.neg '' Ioo a b = Ioo (-b) (-a) := by simp #align set.image_neg_Ioo Set.image_neg_Ioo /-! ### Images under `x ↦ a - x` -/ @[simp] theorem image_const_sub_Ici : (fun x => a - x) '' Ici b = Iic (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ici Set.image_const_sub_Ici @[simp] theorem image_const_sub_Iic : (fun x => a - x) '' Iic b = Ici (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Iic Set.image_const_sub_Iic @[simp] theorem image_const_sub_Ioi : (fun x => a - x) '' Ioi b = Iio (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioi Set.image_const_sub_Ioi @[simp] theorem image_const_sub_Iio : (fun x => a - x) '' Iio b = Ioi (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Iio Set.image_const_sub_Iio @[simp] theorem image_const_sub_Icc : (fun x => a - x) '' Icc b c = Icc (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Icc Set.image_const_sub_Icc @[simp] theorem image_const_sub_Ico : (fun x => a - x) '' Ico b c = Ioc (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ico Set.image_const_sub_Ico @[simp] theorem image_const_sub_Ioc : (fun x => a - x) '' Ioc b c = Ico (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioc Set.image_const_sub_Ioc @[simp] theorem image_const_sub_Ioo : (fun x => a - x) '' Ioo b c = Ioo (a - c) (a - b) := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_Ioo Set.image_const_sub_Ioo /-! ### Images under `x ↦ x - a` -/ @[simp] theorem image_sub_const_Ici : (fun x => x - a) '' Ici b = Ici (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ici Set.image_sub_const_Ici @[simp] theorem image_sub_const_Iic : (fun x => x - a) '' Iic b = Iic (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Iic Set.image_sub_const_Iic @[simp] theorem image_sub_const_Ioi : (fun x => x - a) '' Ioi b = Ioi (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioi Set.image_sub_const_Ioi @[simp] theorem image_sub_const_Iio : (fun x => x - a) '' Iio b = Iio (b - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Iio Set.image_sub_const_Iio @[simp] theorem image_sub_const_Icc : (fun x => x - a) '' Icc b c = Icc (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Icc Set.image_sub_const_Icc @[simp] theorem image_sub_const_Ico : (fun x => x - a) '' Ico b c = Ico (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ico Set.image_sub_const_Ico @[simp] theorem image_sub_const_Ioc : (fun x => x - a) '' Ioc b c = Ioc (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioc Set.image_sub_const_Ioc @[simp] theorem image_sub_const_Ioo : (fun x => x - a) '' Ioo b c = Ioo (b - a) (c - a) := by simp [sub_eq_neg_add] #align set.image_sub_const_Ioo Set.image_sub_const_Ioo /-! ### Bijections -/ theorem Iic_add_bij : BijOn (· + a) (Iic b) (Iic (b + a)) := image_add_const_Iic a b ▸ (add_left_injective _).injOn.bijOn_image #align set.Iic_add_bij Set.Iic_add_bij theorem Iio_add_bij : BijOn (· + a) (Iio b) (Iio (b + a)) := image_add_const_Iio a b ▸ (add_left_injective _).injOn.bijOn_image #align set.Iio_add_bij Set.Iio_add_bij end OrderedAddCommGroup section LinearOrderedAddCommGroup variable [LinearOrderedAddCommGroup α] (a b c d : α) @[simp] theorem preimage_const_add_uIcc : (fun x => a + x) ⁻¹' [[b, c]] = [[b - a, c - a]] := by simp only [← Icc_min_max, preimage_const_add_Icc, min_sub_sub_right, max_sub_sub_right] #align set.preimage_const_add_uIcc Set.preimage_const_add_uIcc @[simp] theorem preimage_add_const_uIcc : (fun x => x + a) ⁻¹' [[b, c]] = [[b - a, c - a]] := by simpa only [add_comm] using preimage_const_add_uIcc a b c #align set.preimage_add_const_uIcc Set.preimage_add_const_uIcc -- TODO: Why is the notation `-[[a, b]]` broken? @[simp] theorem preimage_neg_uIcc : @Neg.neg (Set α) Set.neg [[a, b]] = [[-a, -b]] := by simp only [← Icc_min_max, preimage_neg_Icc, min_neg_neg, max_neg_neg] #align set.preimage_neg_uIcc Set.preimage_neg_uIcc @[simp] theorem preimage_sub_const_uIcc : (fun x => x - a) ⁻¹' [[b, c]] = [[b + a, c + a]] := by simp [sub_eq_add_neg] #align set.preimage_sub_const_uIcc Set.preimage_sub_const_uIcc @[simp] theorem preimage_const_sub_uIcc : (fun x => a - x) ⁻¹' [[b, c]] = [[a - b, a - c]] := by simp_rw [← Icc_min_max, preimage_const_sub_Icc] simp only [sub_eq_add_neg, min_add_add_left, max_add_add_left, min_neg_neg, max_neg_neg] #align set.preimage_const_sub_uIcc Set.preimage_const_sub_uIcc -- @[simp] -- Porting note (#10618): simp can prove this module `add_comm` theorem image_const_add_uIcc : (fun x => a + x) '' [[b, c]] = [[a + b, a + c]] := by simp [add_comm] #align set.image_const_add_uIcc Set.image_const_add_uIcc -- @[simp] -- Porting note (#10618): simp can prove this theorem image_add_const_uIcc : (fun x => x + a) '' [[b, c]] = [[b + a, c + a]] := by simp #align set.image_add_const_uIcc Set.image_add_const_uIcc @[simp] theorem image_const_sub_uIcc : (fun x => a - x) '' [[b, c]] = [[a - b, a - c]] := by have := image_comp (fun x => a + x) fun x => -x; dsimp [Function.comp_def] at this simp [sub_eq_add_neg, this, add_comm] #align set.image_const_sub_uIcc Set.image_const_sub_uIcc @[simp] theorem image_sub_const_uIcc : (fun x => x - a) '' [[b, c]] = [[b - a, c - a]] := by simp [sub_eq_add_neg, add_comm] #align set.image_sub_const_uIcc Set.image_sub_const_uIcc theorem image_neg_uIcc : Neg.neg '' [[a, b]] = [[-a, -b]] := by simp #align set.image_neg_uIcc Set.image_neg_uIcc variable {a b c d} /-- If `[c, d]` is a subinterval of `[a, b]`, then the distance between `c` and `d` is less than or equal to that of `a` and `b` -/ theorem abs_sub_le_of_uIcc_subset_uIcc (h : [[c, d]] ⊆ [[a, b]]) : |d - c| ≤ |b - a| := by rw [← max_sub_min_eq_abs, ← max_sub_min_eq_abs] rw [uIcc_subset_uIcc_iff_le] at h exact sub_le_sub h.2 h.1 #align set.abs_sub_le_of_uIcc_subset_uIcc Set.abs_sub_le_of_uIcc_subset_uIcc /-- If `c ∈ [a, b]`, then the distance between `a` and `c` is less than or equal to that of `a` and `b` -/ theorem abs_sub_left_of_mem_uIcc (h : c ∈ [[a, b]]) : |c - a| ≤ |b - a| := abs_sub_le_of_uIcc_subset_uIcc <| uIcc_subset_uIcc_left h #align set.abs_sub_left_of_mem_uIcc Set.abs_sub_left_of_mem_uIcc /-- If `x ∈ [a, b]`, then the distance between `c` and `b` is less than or equal to that of `a` and `b` -/ theorem abs_sub_right_of_mem_uIcc (h : c ∈ [[a, b]]) : |b - c| ≤ |b - a| := abs_sub_le_of_uIcc_subset_uIcc <| uIcc_subset_uIcc_right h #align set.abs_sub_right_of_mem_uIcc Set.abs_sub_right_of_mem_uIcc end LinearOrderedAddCommGroup /-! ### Multiplication and inverse in a field -/ section LinearOrderedField variable [LinearOrderedField α] {a : α} @[simp] theorem preimage_mul_const_Iio (a : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Iio a = Iio (a / c) := ext fun _x => (lt_div_iff h).symm #align set.preimage_mul_const_Iio Set.preimage_mul_const_Iio @[simp] theorem preimage_mul_const_Ioi (a : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ioi a = Ioi (a / c) := ext fun _x => (div_lt_iff h).symm #align set.preimage_mul_const_Ioi Set.preimage_mul_const_Ioi @[simp] theorem preimage_mul_const_Iic (a : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Iic a = Iic (a / c) := ext fun _x => (le_div_iff h).symm #align set.preimage_mul_const_Iic Set.preimage_mul_const_Iic @[simp] theorem preimage_mul_const_Ici (a : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ici a = Ici (a / c) := ext fun _x => (div_le_iff h).symm #align set.preimage_mul_const_Ici Set.preimage_mul_const_Ici @[simp] theorem preimage_mul_const_Ioo (a b : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ioo a b = Ioo (a / c) (b / c) := by simp [← Ioi_inter_Iio, h] #align set.preimage_mul_const_Ioo Set.preimage_mul_const_Ioo @[simp] theorem preimage_mul_const_Ioc (a b : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ioc a b = Ioc (a / c) (b / c) := by simp [← Ioi_inter_Iic, h] #align set.preimage_mul_const_Ioc Set.preimage_mul_const_Ioc @[simp] theorem preimage_mul_const_Ico (a b : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Ico a b = Ico (a / c) (b / c) := by simp [← Ici_inter_Iio, h] #align set.preimage_mul_const_Ico Set.preimage_mul_const_Ico @[simp] theorem preimage_mul_const_Icc (a b : α) {c : α} (h : 0 < c) : (fun x => x * c) ⁻¹' Icc a b = Icc (a / c) (b / c) := by simp [← Ici_inter_Iic, h] #align set.preimage_mul_const_Icc Set.preimage_mul_const_Icc @[simp] theorem preimage_mul_const_Iio_of_neg (a : α) {c : α} (h : c < 0) : (fun x => x * c) ⁻¹' Iio a = Ioi (a / c) := ext fun _x => (div_lt_iff_of_neg h).symm #align set.preimage_mul_const_Iio_of_neg Set.preimage_mul_const_Iio_of_neg @[simp] theorem preimage_mul_const_Ioi_of_neg (a : α) {c : α} (h : c < 0) : (fun x => x * c) ⁻¹' Ioi a = Iio (a / c) := ext fun _x => (lt_div_iff_of_neg h).symm #align set.preimage_mul_const_Ioi_of_neg Set.preimage_mul_const_Ioi_of_neg @[simp] theorem preimage_mul_const_Iic_of_neg (a : α) {c : α} (h : c < 0) : (fun x => x * c) ⁻¹' Iic a = Ici (a / c) := ext fun _x => (div_le_iff_of_neg h).symm #align set.preimage_mul_const_Iic_of_neg Set.preimage_mul_const_Iic_of_neg @[simp] theorem preimage_mul_const_Ici_of_neg (a : α) {c : α} (h : c < 0) : (fun x => x * c) ⁻¹' Ici a = Iic (a / c) := ext fun _x => (le_div_iff_of_neg h).symm #align set.preimage_mul_const_Ici_of_neg Set.preimage_mul_const_Ici_of_neg @[simp] theorem preimage_mul_const_Ioo_of_neg (a b : α) {c : α} (h : c < 0) : (fun x => x * c) ⁻¹' Ioo a b = Ioo (b / c) (a / c) := by simp [← Ioi_inter_Iio, h, inter_comm] #align set.preimage_mul_const_Ioo_of_neg Set.preimage_mul_const_Ioo_of_neg @[simp] theorem preimage_mul_const_Ioc_of_neg (a b : α) {c : α} (h : c < 0) : (fun x => x * c) ⁻¹' Ioc a b = Ico (b / c) (a / c) := by simp [← Ioi_inter_Iic, ← Ici_inter_Iio, h, inter_comm] #align set.preimage_mul_const_Ioc_of_neg Set.preimage_mul_const_Ioc_of_neg @[simp] theorem preimage_mul_const_Ico_of_neg (a b : α) {c : α} (h : c < 0) : (fun x => x * c) ⁻¹' Ico a b = Ioc (b / c) (a / c) := by simp [← Ici_inter_Iio, ← Ioi_inter_Iic, h, inter_comm] #align set.preimage_mul_const_Ico_of_neg Set.preimage_mul_const_Ico_of_neg @[simp] theorem preimage_mul_const_Icc_of_neg (a b : α) {c : α} (h : c < 0) : (fun x => x * c) ⁻¹' Icc a b = Icc (b / c) (a / c) := by simp [← Ici_inter_Iic, h, inter_comm] #align set.preimage_mul_const_Icc_of_neg Set.preimage_mul_const_Icc_of_neg @[simp] theorem preimage_const_mul_Iio (a : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Iio a = Iio (a / c) := ext fun _x => (lt_div_iff' h).symm #align set.preimage_const_mul_Iio Set.preimage_const_mul_Iio @[simp] theorem preimage_const_mul_Ioi (a : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Ioi a = Ioi (a / c) := ext fun _x => (div_lt_iff' h).symm #align set.preimage_const_mul_Ioi Set.preimage_const_mul_Ioi @[simp] theorem preimage_const_mul_Iic (a : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Iic a = Iic (a / c) := ext fun _x => (le_div_iff' h).symm #align set.preimage_const_mul_Iic Set.preimage_const_mul_Iic @[simp] theorem preimage_const_mul_Ici (a : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Ici a = Ici (a / c) := ext fun _x => (div_le_iff' h).symm #align set.preimage_const_mul_Ici Set.preimage_const_mul_Ici @[simp] theorem preimage_const_mul_Ioo (a b : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Ioo a b = Ioo (a / c) (b / c) := by simp [← Ioi_inter_Iio, h] #align set.preimage_const_mul_Ioo Set.preimage_const_mul_Ioo @[simp] theorem preimage_const_mul_Ioc (a b : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Ioc a b = Ioc (a / c) (b / c) := by simp [← Ioi_inter_Iic, h] #align set.preimage_const_mul_Ioc Set.preimage_const_mul_Ioc @[simp] theorem preimage_const_mul_Ico (a b : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Ico a b = Ico (a / c) (b / c) := by simp [← Ici_inter_Iio, h] #align set.preimage_const_mul_Ico Set.preimage_const_mul_Ico @[simp] theorem preimage_const_mul_Icc (a b : α) {c : α} (h : 0 < c) : (c * ·) ⁻¹' Icc a b = Icc (a / c) (b / c) := by simp [← Ici_inter_Iic, h] #align set.preimage_const_mul_Icc Set.preimage_const_mul_Icc @[simp]
Mathlib/Data/Set/Pointwise/Interval.lean
725
727
theorem preimage_const_mul_Iio_of_neg (a : α) {c : α} (h : c < 0) : (c * ·) ⁻¹' Iio a = Ioi (a / c) := by
simpa only [mul_comm] using preimage_mul_const_Iio_of_neg a h
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Batteries.Control.ForInStep.Lemmas import Batteries.Data.List.Basic import Batteries.Tactic.Init import Batteries.Tactic.Alias namespace List open Nat /-! ### mem -/ @[simp] theorem mem_toArray {a : α} {l : List α} : a ∈ l.toArray ↔ a ∈ l := by simp [Array.mem_def] /-! ### drop -/ @[simp] theorem drop_one : ∀ l : List α, drop 1 l = tail l | [] | _ :: _ => rfl /-! ### zipWith -/ theorem zipWith_distrib_tail : (zipWith f l l').tail = zipWith f l.tail l'.tail := by rw [← drop_one]; simp [zipWith_distrib_drop] /-! ### List subset -/ theorem subset_def {l₁ l₂ : List α} : l₁ ⊆ l₂ ↔ ∀ {a : α}, a ∈ l₁ → a ∈ l₂ := .rfl @[simp] theorem nil_subset (l : List α) : [] ⊆ l := nofun @[simp] theorem Subset.refl (l : List α) : l ⊆ l := fun _ i => i theorem Subset.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ ⊆ l₂) (h₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ := fun _ i => h₂ (h₁ i) instance : Trans (Membership.mem : α → List α → Prop) Subset Membership.mem := ⟨fun h₁ h₂ => h₂ h₁⟩ instance : Trans (Subset : List α → List α → Prop) Subset Subset := ⟨Subset.trans⟩ @[simp] theorem subset_cons (a : α) (l : List α) : l ⊆ a :: l := fun _ => Mem.tail _ theorem subset_of_cons_subset {a : α} {l₁ l₂ : List α} : a :: l₁ ⊆ l₂ → l₁ ⊆ l₂ := fun s _ i => s (mem_cons_of_mem _ i) theorem subset_cons_of_subset (a : α) {l₁ l₂ : List α} : l₁ ⊆ l₂ → l₁ ⊆ a :: l₂ := fun s _ i => .tail _ (s i) theorem cons_subset_cons {l₁ l₂ : List α} (a : α) (s : l₁ ⊆ l₂) : a :: l₁ ⊆ a :: l₂ := fun _ => by simp only [mem_cons]; exact Or.imp_right (@s _) @[simp] theorem subset_append_left (l₁ l₂ : List α) : l₁ ⊆ l₁ ++ l₂ := fun _ => mem_append_left _ @[simp] theorem subset_append_right (l₁ l₂ : List α) : l₂ ⊆ l₁ ++ l₂ := fun _ => mem_append_right _ theorem subset_append_of_subset_left (l₂ : List α) : l ⊆ l₁ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_left _ _ theorem subset_append_of_subset_right (l₁ : List α) : l ⊆ l₂ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_right _ _ @[simp] theorem cons_subset : a :: l ⊆ m ↔ a ∈ m ∧ l ⊆ m := by simp only [subset_def, mem_cons, or_imp, forall_and, forall_eq] @[simp] theorem append_subset {l₁ l₂ l : List α} : l₁ ++ l₂ ⊆ l ↔ l₁ ⊆ l ∧ l₂ ⊆ l := by simp [subset_def, or_imp, forall_and] theorem subset_nil {l : List α} : l ⊆ [] ↔ l = [] := ⟨fun h => match l with | [] => rfl | _::_ => (nomatch h (.head ..)), fun | rfl => Subset.refl _⟩ theorem map_subset {l₁ l₂ : List α} (f : α → β) (H : l₁ ⊆ l₂) : map f l₁ ⊆ map f l₂ := fun x => by simp only [mem_map]; exact .imp fun a => .imp_left (@H _) /-! ### sublists -/ @[simp] theorem nil_sublist : ∀ l : List α, [] <+ l | [] => .slnil | a :: l => (nil_sublist l).cons a @[simp] theorem Sublist.refl : ∀ l : List α, l <+ l | [] => .slnil | a :: l => (Sublist.refl l).cons₂ a theorem Sublist.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ <+ l₂) (h₂ : l₂ <+ l₃) : l₁ <+ l₃ := by induction h₂ generalizing l₁ with | slnil => exact h₁ | cons _ _ IH => exact (IH h₁).cons _ | @cons₂ l₂ _ a _ IH => generalize e : a :: l₂ = l₂' match e ▸ h₁ with | .slnil => apply nil_sublist | .cons a' h₁' => cases e; apply (IH h₁').cons | .cons₂ a' h₁' => cases e; apply (IH h₁').cons₂ instance : Trans (@Sublist α) Sublist Sublist := ⟨Sublist.trans⟩ @[simp] theorem sublist_cons (a : α) (l : List α) : l <+ a :: l := (Sublist.refl l).cons _ theorem sublist_of_cons_sublist : a :: l₁ <+ l₂ → l₁ <+ l₂ := (sublist_cons a l₁).trans @[simp] theorem sublist_append_left : ∀ l₁ l₂ : List α, l₁ <+ l₁ ++ l₂ | [], _ => nil_sublist _ | _ :: l₁, l₂ => (sublist_append_left l₁ l₂).cons₂ _ @[simp] theorem sublist_append_right : ∀ l₁ l₂ : List α, l₂ <+ l₁ ++ l₂ | [], _ => Sublist.refl _ | _ :: l₁, l₂ => (sublist_append_right l₁ l₂).cons _ theorem sublist_append_of_sublist_left (s : l <+ l₁) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_left .. theorem sublist_append_of_sublist_right (s : l <+ l₂) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_right .. @[simp] theorem cons_sublist_cons : a :: l₁ <+ a :: l₂ ↔ l₁ <+ l₂ := ⟨fun | .cons _ s => sublist_of_cons_sublist s | .cons₂ _ s => s, .cons₂ _⟩ @[simp] theorem append_sublist_append_left : ∀ l, l ++ l₁ <+ l ++ l₂ ↔ l₁ <+ l₂ | [] => Iff.rfl | _ :: l => cons_sublist_cons.trans (append_sublist_append_left l) theorem Sublist.append_left : l₁ <+ l₂ → ∀ l, l ++ l₁ <+ l ++ l₂ := fun h l => (append_sublist_append_left l).mpr h theorem Sublist.append_right : l₁ <+ l₂ → ∀ l, l₁ ++ l <+ l₂ ++ l | .slnil, _ => Sublist.refl _ | .cons _ h, _ => (h.append_right _).cons _ | .cons₂ _ h, _ => (h.append_right _).cons₂ _ theorem sublist_or_mem_of_sublist (h : l <+ l₁ ++ a :: l₂) : l <+ l₁ ++ l₂ ∨ a ∈ l := by induction l₁ generalizing l with | nil => match h with | .cons _ h => exact .inl h | .cons₂ _ h => exact .inr (.head ..) | cons b l₁ IH => match h with | .cons _ h => exact (IH h).imp_left (Sublist.cons _) | .cons₂ _ h => exact (IH h).imp (Sublist.cons₂ _) (.tail _) theorem Sublist.reverse : l₁ <+ l₂ → l₁.reverse <+ l₂.reverse | .slnil => Sublist.refl _ | .cons _ h => by rw [reverse_cons]; exact sublist_append_of_sublist_left h.reverse | .cons₂ _ h => by rw [reverse_cons, reverse_cons]; exact h.reverse.append_right _ @[simp] theorem reverse_sublist : l₁.reverse <+ l₂.reverse ↔ l₁ <+ l₂ := ⟨fun h => l₁.reverse_reverse ▸ l₂.reverse_reverse ▸ h.reverse, Sublist.reverse⟩ @[simp] theorem append_sublist_append_right (l) : l₁ ++ l <+ l₂ ++ l ↔ l₁ <+ l₂ := ⟨fun h => by have := h.reverse simp only [reverse_append, append_sublist_append_left, reverse_sublist] at this exact this, fun h => h.append_right l⟩ theorem Sublist.append (hl : l₁ <+ l₂) (hr : r₁ <+ r₂) : l₁ ++ r₁ <+ l₂ ++ r₂ := (hl.append_right _).trans ((append_sublist_append_left _).2 hr) theorem Sublist.subset : l₁ <+ l₂ → l₁ ⊆ l₂ | .slnil, _, h => h | .cons _ s, _, h => .tail _ (s.subset h) | .cons₂ .., _, .head .. => .head .. | .cons₂ _ s, _, .tail _ h => .tail _ (s.subset h) instance : Trans (@Sublist α) Subset Subset := ⟨fun h₁ h₂ => trans h₁.subset h₂⟩ instance : Trans Subset (@Sublist α) Subset := ⟨fun h₁ h₂ => trans h₁ h₂.subset⟩ instance : Trans (Membership.mem : α → List α → Prop) Sublist Membership.mem := ⟨fun h₁ h₂ => h₂.subset h₁⟩ theorem Sublist.length_le : l₁ <+ l₂ → length l₁ ≤ length l₂ | .slnil => Nat.le_refl 0 | .cons _l s => le_succ_of_le (length_le s) | .cons₂ _ s => succ_le_succ (length_le s) @[simp] theorem sublist_nil {l : List α} : l <+ [] ↔ l = [] := ⟨fun s => subset_nil.1 s.subset, fun H => H ▸ Sublist.refl _⟩ theorem Sublist.eq_of_length : l₁ <+ l₂ → length l₁ = length l₂ → l₁ = l₂ | .slnil, _ => rfl | .cons a s, h => nomatch Nat.not_lt.2 s.length_le (h ▸ lt_succ_self _) | .cons₂ a s, h => by rw [s.eq_of_length (succ.inj h)] theorem Sublist.eq_of_length_le (s : l₁ <+ l₂) (h : length l₂ ≤ length l₁) : l₁ = l₂ := s.eq_of_length <| Nat.le_antisymm s.length_le h @[simp] theorem singleton_sublist {a : α} {l} : [a] <+ l ↔ a ∈ l := by refine ⟨fun h => h.subset (mem_singleton_self _), fun h => ?_⟩ obtain ⟨_, _, rfl⟩ := append_of_mem h exact ((nil_sublist _).cons₂ _).trans (sublist_append_right ..) @[simp] theorem replicate_sublist_replicate {m n} (a : α) : replicate m a <+ replicate n a ↔ m ≤ n := by refine ⟨fun h => ?_, fun h => ?_⟩ · have := h.length_le; simp only [length_replicate] at this ⊢; exact this · induction h with | refl => apply Sublist.refl | step => simp [*, replicate, Sublist.cons] theorem isSublist_iff_sublist [BEq α] [LawfulBEq α] {l₁ l₂ : List α} : l₁.isSublist l₂ ↔ l₁ <+ l₂ := by cases l₁ <;> cases l₂ <;> simp [isSublist] case cons.cons hd₁ tl₁ hd₂ tl₂ => if h_eq : hd₁ = hd₂ then simp [h_eq, cons_sublist_cons, isSublist_iff_sublist] else simp only [beq_iff_eq, h_eq] constructor · intro h_sub apply Sublist.cons exact isSublist_iff_sublist.mp h_sub · intro h_sub cases h_sub case cons h_sub => exact isSublist_iff_sublist.mpr h_sub case cons₂ => contradiction instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ <+ l₂) := decidable_of_iff (l₁.isSublist l₂) isSublist_iff_sublist /-! ### tail -/ theorem tail_eq_tailD (l) : @tail α l = tailD l [] := by cases l <;> rfl theorem tail_eq_tail? (l) : @tail α l = (tail? l).getD [] := by simp [tail_eq_tailD] /-! ### next? -/ @[simp] theorem next?_nil : @next? α [] = none := rfl @[simp] theorem next?_cons (a l) : @next? α (a :: l) = some (a, l) := rfl /-! ### get? -/ theorem get_eq_iff : List.get l n = x ↔ l.get? n.1 = some x := by simp [get?_eq_some] theorem get?_inj (h₀ : i < xs.length) (h₁ : Nodup xs) (h₂ : xs.get? i = xs.get? j) : i = j := by induction xs generalizing i j with | nil => cases h₀ | cons x xs ih => match i, j with | 0, 0 => rfl | i+1, j+1 => simp; cases h₁ with | cons ha h₁ => exact ih (Nat.lt_of_succ_lt_succ h₀) h₁ h₂ | i+1, 0 => ?_ | 0, j+1 => ?_ all_goals simp at h₂ cases h₁; rename_i h' h have := h x ?_ rfl; cases this rw [mem_iff_get?] exact ⟨_, h₂⟩; exact ⟨_ , h₂.symm⟩ /-! ### drop -/ theorem tail_drop (l : List α) (n : Nat) : (l.drop n).tail = l.drop (n + 1) := by induction l generalizing n with | nil => simp | cons hd tl hl => cases n · simp · simp [hl] /-! ### modifyNth -/ @[simp] theorem modifyNth_nil (f : α → α) (n) : [].modifyNth f n = [] := by cases n <;> rfl @[simp] theorem modifyNth_zero_cons (f : α → α) (a : α) (l : List α) : (a :: l).modifyNth f 0 = f a :: l := rfl @[simp] theorem modifyNth_succ_cons (f : α → α) (a : α) (l : List α) (n) : (a :: l).modifyNth f (n + 1) = a :: l.modifyNth f n := by rfl theorem modifyNthTail_id : ∀ n (l : List α), l.modifyNthTail id n = l | 0, _ => rfl | _+1, [] => rfl | n+1, a :: l => congrArg (cons a) (modifyNthTail_id n l) theorem eraseIdx_eq_modifyNthTail : ∀ n (l : List α), eraseIdx l n = modifyNthTail tail n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, a :: l => congrArg (cons _) (eraseIdx_eq_modifyNthTail _ _) @[deprecated] alias removeNth_eq_nth_tail := eraseIdx_eq_modifyNthTail theorem get?_modifyNth (f : α → α) : ∀ n (l : List α) m, (modifyNth f n l).get? m = (fun a => if n = m then f a else a) <$> l.get? m | n, l, 0 => by cases l <;> cases n <;> rfl | n, [], _+1 => by cases n <;> rfl | 0, _ :: l, m+1 => by cases h : l.get? m <;> simp [h, modifyNth, m.succ_ne_zero.symm] | n+1, a :: l, m+1 => (get?_modifyNth f n l m).trans <| by cases h' : l.get? m <;> by_cases h : n = m <;> simp [h, if_pos, if_neg, Option.map, mt Nat.succ.inj, not_false_iff, h'] theorem modifyNthTail_length (f : List α → List α) (H : ∀ l, length (f l) = length l) : ∀ n l, length (modifyNthTail f n l) = length l | 0, _ => H _ | _+1, [] => rfl | _+1, _ :: _ => congrArg (·+1) (modifyNthTail_length _ H _ _) theorem modifyNthTail_add (f : List α → List α) (n) (l₁ l₂ : List α) : modifyNthTail f (l₁.length + n) (l₁ ++ l₂) = l₁ ++ modifyNthTail f n l₂ := by induction l₁ <;> simp [*, Nat.succ_add] theorem exists_of_modifyNthTail (f : List α → List α) {n} {l : List α} (h : n ≤ l.length) : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n ∧ modifyNthTail f n l = l₁ ++ f l₂ := have ⟨_, _, eq, hl⟩ : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n := ⟨_, _, (take_append_drop n l).symm, length_take_of_le h⟩ ⟨_, _, eq, hl, hl ▸ eq ▸ modifyNthTail_add (n := 0) ..⟩ @[simp] theorem modify_get?_length (f : α → α) : ∀ n l, length (modifyNth f n l) = length l := modifyNthTail_length _ fun l => by cases l <;> rfl @[simp] theorem get?_modifyNth_eq (f : α → α) (n) (l : List α) : (modifyNth f n l).get? n = f <$> l.get? n := by simp only [get?_modifyNth, if_pos] @[simp] theorem get?_modifyNth_ne (f : α → α) {m n} (l : List α) (h : m ≠ n) : (modifyNth f m l).get? n = l.get? n := by simp only [get?_modifyNth, if_neg h, id_map'] theorem exists_of_modifyNth (f : α → α) {n} {l : List α} (h : n < l.length) : ∃ l₁ a l₂, l = l₁ ++ a :: l₂ ∧ l₁.length = n ∧ modifyNth f n l = l₁ ++ f a :: l₂ := match exists_of_modifyNthTail _ (Nat.le_of_lt h) with | ⟨_, _::_, eq, hl, H⟩ => ⟨_, _, _, eq, hl, H⟩ | ⟨_, [], eq, hl, _⟩ => nomatch Nat.ne_of_gt h (eq ▸ append_nil _ ▸ hl) theorem modifyNthTail_eq_take_drop (f : List α → List α) (H : f [] = []) : ∀ n l, modifyNthTail f n l = take n l ++ f (drop n l) | 0, _ => rfl | _ + 1, [] => H.symm | n + 1, b :: l => congrArg (cons b) (modifyNthTail_eq_take_drop f H n l) theorem modifyNth_eq_take_drop (f : α → α) : ∀ n l, modifyNth f n l = take n l ++ modifyHead f (drop n l) := modifyNthTail_eq_take_drop _ rfl theorem modifyNth_eq_take_cons_drop (f : α → α) {n l} (h) : modifyNth f n l = take n l ++ f (get l ⟨n, h⟩) :: drop (n + 1) l := by rw [modifyNth_eq_take_drop, drop_eq_get_cons h]; rfl /-! ### set -/ theorem set_eq_modifyNth (a : α) : ∀ n (l : List α), set l n a = modifyNth (fun _ => a) n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, b :: l => congrArg (cons _) (set_eq_modifyNth _ _ _) theorem set_eq_take_cons_drop (a : α) {n l} (h : n < length l) : set l n a = take n l ++ a :: drop (n + 1) l := by rw [set_eq_modifyNth, modifyNth_eq_take_cons_drop _ h] theorem modifyNth_eq_set_get? (f : α → α) : ∀ n (l : List α), l.modifyNth f n = ((fun a => l.set n (f a)) <$> l.get? n).getD l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, b :: l => (congrArg (cons _) (modifyNth_eq_set_get? ..)).trans <| by cases h : l.get? n <;> simp [h] theorem modifyNth_eq_set_get (f : α → α) {n} {l : List α} (h) : l.modifyNth f n = l.set n (f (l.get ⟨n, h⟩)) := by rw [modifyNth_eq_set_get?, get?_eq_get h]; rfl theorem exists_of_set {l : List α} (h : n < l.length) : ∃ l₁ a l₂, l = l₁ ++ a :: l₂ ∧ l₁.length = n ∧ l.set n a' = l₁ ++ a' :: l₂ := by rw [set_eq_modifyNth]; exact exists_of_modifyNth _ h theorem exists_of_set' {l : List α} (h : n < l.length) : ∃ l₁ l₂, l = l₁ ++ l.get ⟨n, h⟩ :: l₂ ∧ l₁.length = n ∧ l.set n a' = l₁ ++ a' :: l₂ := have ⟨_, _, _, h₁, h₂, h₃⟩ := exists_of_set h; ⟨_, _, get_of_append h₁ h₂ ▸ h₁, h₂, h₃⟩ @[simp] theorem get?_set_eq (a : α) (n) (l : List α) : (set l n a).get? n = (fun _ => a) <$> l.get? n := by simp only [set_eq_modifyNth, get?_modifyNth_eq] theorem get?_set_eq_of_lt (a : α) {n} {l : List α} (h : n < length l) : (set l n a).get? n = some a := by rw [get?_set_eq, get?_eq_get h]; rfl @[simp] theorem get?_set_ne (a : α) {m n} (l : List α) (h : m ≠ n) : (set l m a).get? n = l.get? n := by simp only [set_eq_modifyNth, get?_modifyNth_ne _ _ h] theorem get?_set (a : α) {m n} (l : List α) : (set l m a).get? n = if m = n then (fun _ => a) <$> l.get? n else l.get? n := by by_cases m = n <;> simp [*, get?_set_eq, get?_set_ne] theorem get?_set_of_lt (a : α) {m n} (l : List α) (h : n < length l) : (set l m a).get? n = if m = n then some a else l.get? n := by simp [get?_set, get?_eq_get h] theorem get?_set_of_lt' (a : α) {m n} (l : List α) (h : m < length l) : (set l m a).get? n = if m = n then some a else l.get? n := by simp [get?_set]; split <;> subst_vars <;> simp [*, get?_eq_get h] theorem drop_set_of_lt (a : α) {n m : Nat} (l : List α) (h : n < m) : (l.set n a).drop m = l.drop m := List.ext fun i => by rw [get?_drop, get?_drop, get?_set_ne _ _ (by omega)] theorem take_set_of_lt (a : α) {n m : Nat} (l : List α) (h : m < n) : (l.set n a).take m = l.take m := List.ext fun i => by rw [get?_take_eq_if, get?_take_eq_if] split · next h' => rw [get?_set_ne _ _ (by omega)] · rfl /-! ### removeNth -/ theorem length_eraseIdx : ∀ {l i}, i < length l → length (@eraseIdx α l i) = length l - 1 | [], _, _ => rfl | _::_, 0, _ => by simp [eraseIdx] | x::xs, i+1, h => by have : i < length xs := Nat.lt_of_succ_lt_succ h simp [eraseIdx, ← Nat.add_one] rw [length_eraseIdx this, Nat.sub_add_cancel (Nat.lt_of_le_of_lt (Nat.zero_le _) this)] @[deprecated] alias length_removeNth := length_eraseIdx /-! ### tail -/ @[simp] theorem length_tail (l : List α) : length (tail l) = length l - 1 := by cases l <;> rfl /-! ### eraseP -/ @[simp] theorem eraseP_nil : [].eraseP p = [] := rfl theorem eraseP_cons (a : α) (l : List α) : (a :: l).eraseP p = bif p a then l else a :: l.eraseP p := rfl @[simp] theorem eraseP_cons_of_pos {l : List α} (p) (h : p a) : (a :: l).eraseP p = l := by simp [eraseP_cons, h] @[simp] theorem eraseP_cons_of_neg {l : List α} (p) (h : ¬p a) : (a :: l).eraseP p = a :: l.eraseP p := by simp [eraseP_cons, h] theorem eraseP_of_forall_not {l : List α} (h : ∀ a, a ∈ l → ¬p a) : l.eraseP p = l := by induction l with | nil => rfl | cons _ _ ih => simp [h _ (.head ..), ih (forall_mem_cons.1 h).2] theorem exists_of_eraseP : ∀ {l : List α} {a} (al : a ∈ l) (pa : p a), ∃ a l₁ l₂, (∀ b ∈ l₁, ¬p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.eraseP p = l₁ ++ l₂ | b :: l, a, al, pa => if pb : p b then ⟨b, [], l, forall_mem_nil _, pb, by simp [pb]⟩ else match al with | .head .. => nomatch pb pa | .tail _ al => let ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩ := exists_of_eraseP al pa ⟨c, b::l₁, l₂, (forall_mem_cons ..).2 ⟨pb, h₁⟩, h₂, by rw [h₃, cons_append], by simp [pb, h₄]⟩ theorem exists_or_eq_self_of_eraseP (p) (l : List α) : l.eraseP p = l ∨ ∃ a l₁ l₂, (∀ b ∈ l₁, ¬p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.eraseP p = l₁ ++ l₂ := if h : ∃ a ∈ l, p a then let ⟨_, ha, pa⟩ := h .inr (exists_of_eraseP ha pa) else .inl (eraseP_of_forall_not (h ⟨·, ·, ·⟩)) @[simp] theorem length_eraseP_of_mem (al : a ∈ l) (pa : p a) : length (l.eraseP p) = Nat.pred (length l) := by let ⟨_, l₁, l₂, _, _, e₁, e₂⟩ := exists_of_eraseP al pa rw [e₂]; simp [length_append, e₁]; rfl theorem eraseP_append_left {a : α} (pa : p a) : ∀ {l₁ : List α} l₂, a ∈ l₁ → (l₁++l₂).eraseP p = l₁.eraseP p ++ l₂ | x :: xs, l₂, h => by by_cases h' : p x <;> simp [h'] rw [eraseP_append_left pa l₂ ((mem_cons.1 h).resolve_left (mt _ h'))] intro | rfl => exact pa theorem eraseP_append_right : ∀ {l₁ : List α} l₂, (∀ b ∈ l₁, ¬p b) → eraseP p (l₁++l₂) = l₁ ++ l₂.eraseP p | [], l₂, _ => rfl | x :: xs, l₂, h => by simp [(forall_mem_cons.1 h).1, eraseP_append_right _ (forall_mem_cons.1 h).2] theorem eraseP_sublist (l : List α) : l.eraseP p <+ l := by match exists_or_eq_self_of_eraseP p l with | .inl h => rw [h]; apply Sublist.refl | .inr ⟨c, l₁, l₂, _, _, h₃, h₄⟩ => rw [h₄, h₃]; simp theorem eraseP_subset (l : List α) : l.eraseP p ⊆ l := (eraseP_sublist l).subset protected theorem Sublist.eraseP : l₁ <+ l₂ → l₁.eraseP p <+ l₂.eraseP p | .slnil => Sublist.refl _ | .cons a s => by by_cases h : p a <;> simp [h] exacts [s.eraseP.trans (eraseP_sublist _), s.eraseP.cons _] | .cons₂ a s => by by_cases h : p a <;> simp [h] exacts [s, s.eraseP] theorem mem_of_mem_eraseP {l : List α} : a ∈ l.eraseP p → a ∈ l := (eraseP_subset _ ·) @[simp] theorem mem_eraseP_of_neg {l : List α} (pa : ¬p a) : a ∈ l.eraseP p ↔ a ∈ l := by refine ⟨mem_of_mem_eraseP, fun al => ?_⟩ match exists_or_eq_self_of_eraseP p l with | .inl h => rw [h]; assumption | .inr ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩ => rw [h₄]; rw [h₃] at al have : a ≠ c := fun h => (h ▸ pa).elim h₂ simp [this] at al; simp [al] theorem eraseP_map (f : β → α) : ∀ (l : List β), (map f l).eraseP p = map f (l.eraseP (p ∘ f)) | [] => rfl | b::l => by by_cases h : p (f b) <;> simp [h, eraseP_map f l, eraseP_cons_of_pos] @[simp] theorem extractP_eq_find?_eraseP (l : List α) : extractP p l = (find? p l, eraseP p l) := by let rec go (acc) : ∀ xs, l = acc.data ++ xs → extractP.go p l xs acc = (xs.find? p, acc.data ++ xs.eraseP p) | [] => fun h => by simp [extractP.go, find?, eraseP, h] | x::xs => by simp [extractP.go, find?, eraseP]; cases p x <;> simp · intro h; rw [go _ xs]; {simp}; simp [h] exact go #[] _ rfl /-! ### erase -/ section erase variable [BEq α] theorem erase_eq_eraseP' (a : α) (l : List α) : l.erase a = l.eraseP (· == a) := by induction l · simp · next b t ih => rw [erase_cons, eraseP_cons, ih] if h : b == a then simp [h] else simp [h] theorem erase_eq_eraseP [LawfulBEq α] (a : α) : ∀ l : List α, l.erase a = l.eraseP (a == ·) | [] => rfl | b :: l => by if h : a = b then simp [h] else simp [h, Ne.symm h, erase_eq_eraseP a l] theorem exists_erase_eq [LawfulBEq α] {a : α} {l : List α} (h : a ∈ l) : ∃ l₁ l₂, a ∉ l₁ ∧ l = l₁ ++ a :: l₂ ∧ l.erase a = l₁ ++ l₂ := by let ⟨_, l₁, l₂, h₁, e, h₂, h₃⟩ := exists_of_eraseP h (beq_self_eq_true _) rw [erase_eq_eraseP]; exact ⟨l₁, l₂, fun h => h₁ _ h (beq_self_eq_true _), eq_of_beq e ▸ h₂, h₃⟩ @[simp] theorem length_erase_of_mem [LawfulBEq α] {a : α} {l : List α} (h : a ∈ l) : length (l.erase a) = Nat.pred (length l) := by rw [erase_eq_eraseP]; exact length_eraseP_of_mem h (beq_self_eq_true a) theorem erase_append_left [LawfulBEq α] {l₁ : List α} (l₂) (h : a ∈ l₁) : (l₁ ++ l₂).erase a = l₁.erase a ++ l₂ := by simp [erase_eq_eraseP]; exact eraseP_append_left (beq_self_eq_true a) l₂ h theorem erase_append_right [LawfulBEq α] {a : α} {l₁ : List α} (l₂ : List α) (h : a ∉ l₁) : (l₁ ++ l₂).erase a = (l₁ ++ l₂.erase a) := by rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_append_right] intros b h' h''; rw [eq_of_beq h''] at h; exact h h' theorem erase_sublist (a : α) (l : List α) : l.erase a <+ l := erase_eq_eraseP' a l ▸ eraseP_sublist l theorem erase_subset (a : α) (l : List α) : l.erase a ⊆ l := (erase_sublist a l).subset theorem Sublist.erase (a : α) {l₁ l₂ : List α} (h : l₁ <+ l₂) : l₁.erase a <+ l₂.erase a := by simp only [erase_eq_eraseP']; exact h.eraseP @[deprecated] alias sublist.erase := Sublist.erase theorem mem_of_mem_erase {a b : α} {l : List α} (h : a ∈ l.erase b) : a ∈ l := erase_subset _ _ h @[simp] theorem mem_erase_of_ne [LawfulBEq α] {a b : α} {l : List α} (ab : a ≠ b) : a ∈ l.erase b ↔ a ∈ l := erase_eq_eraseP b l ▸ mem_eraseP_of_neg (mt eq_of_beq ab.symm) theorem erase_comm [LawfulBEq α] (a b : α) (l : List α) : (l.erase a).erase b = (l.erase b).erase a := by if ab : a == b then rw [eq_of_beq ab] else ?_ if ha : a ∈ l then ?_ else simp only [erase_of_not_mem ha, erase_of_not_mem (mt mem_of_mem_erase ha)] if hb : b ∈ l then ?_ else simp only [erase_of_not_mem hb, erase_of_not_mem (mt mem_of_mem_erase hb)] match l, l.erase a, exists_erase_eq ha with | _, _, ⟨l₁, l₂, ha', rfl, rfl⟩ => if h₁ : b ∈ l₁ then rw [erase_append_left _ h₁, erase_append_left _ h₁, erase_append_right _ (mt mem_of_mem_erase ha'), erase_cons_head] else rw [erase_append_right _ h₁, erase_append_right _ h₁, erase_append_right _ ha', erase_cons_tail _ ab, erase_cons_head] end erase /-! ### filter and partition -/ @[simp] theorem filter_sublist {p : α → Bool} : ∀ (l : List α), filter p l <+ l | [] => .slnil | a :: l => by rw [filter]; split <;> simp [Sublist.cons, Sublist.cons₂, filter_sublist l] /-! ### filterMap -/ theorem length_filter_le (p : α → Bool) (l : List α) : (l.filter p).length ≤ l.length := (filter_sublist _).length_le theorem length_filterMap_le (f : α → Option β) (l : List α) : (filterMap f l).length ≤ l.length := by rw [← length_map _ some, map_filterMap_some_eq_filter_map_is_some, ← length_map _ f] apply length_filter_le protected theorem Sublist.filterMap (f : α → Option β) (s : l₁ <+ l₂) : filterMap f l₁ <+ filterMap f l₂ := by induction s <;> simp <;> split <;> simp [*, cons, cons₂] theorem Sublist.filter (p : α → Bool) {l₁ l₂} (s : l₁ <+ l₂) : filter p l₁ <+ filter p l₂ := by rw [← filterMap_eq_filter]; apply s.filterMap @[simp] theorem filter_eq_self {l} : filter p l = l ↔ ∀ a ∈ l, p a := by induction l with simp | cons a l ih => cases h : p a <;> simp [*] intro h; exact Nat.lt_irrefl _ (h ▸ length_filter_le p l) @[simp] theorem filter_length_eq_length {l} : (filter p l).length = l.length ↔ ∀ a ∈ l, p a := Iff.trans ⟨l.filter_sublist.eq_of_length, congrArg length⟩ filter_eq_self /-! ### findIdx -/ @[simp] theorem findIdx_nil {α : Type _} (p : α → Bool) : [].findIdx p = 0 := rfl theorem findIdx_cons (p : α → Bool) (b : α) (l : List α) : (b :: l).findIdx p = bif p b then 0 else (l.findIdx p) + 1 := by cases H : p b with | true => simp [H, findIdx, findIdx.go] | false => simp [H, findIdx, findIdx.go, findIdx_go_succ] where findIdx_go_succ (p : α → Bool) (l : List α) (n : Nat) : List.findIdx.go p l (n + 1) = (findIdx.go p l n) + 1 := by cases l with | nil => unfold findIdx.go; exact Nat.succ_eq_add_one n | cons head tail => unfold findIdx.go cases p head <;> simp only [cond_false, cond_true] exact findIdx_go_succ p tail (n + 1) theorem findIdx_of_get?_eq_some {xs : List α} (w : xs.get? (xs.findIdx p) = some y) : p y := by induction xs with | nil => simp_all | cons x xs ih => by_cases h : p x <;> simp_all [findIdx_cons] theorem findIdx_get {xs : List α} {w : xs.findIdx p < xs.length} : p (xs.get ⟨xs.findIdx p, w⟩) := xs.findIdx_of_get?_eq_some (get?_eq_get w) theorem findIdx_lt_length_of_exists {xs : List α} (h : ∃ x ∈ xs, p x) : xs.findIdx p < xs.length := by induction xs with | nil => simp_all | cons x xs ih => by_cases p x · simp_all only [forall_exists_index, and_imp, mem_cons, exists_eq_or_imp, true_or, findIdx_cons, cond_true, length_cons] apply Nat.succ_pos · simp_all [findIdx_cons] refine Nat.succ_lt_succ ?_ obtain ⟨x', m', h'⟩ := h exact ih x' m' h' theorem findIdx_get?_eq_get_of_exists {xs : List α} (h : ∃ x ∈ xs, p x) : xs.get? (xs.findIdx p) = some (xs.get ⟨xs.findIdx p, xs.findIdx_lt_length_of_exists h⟩) := get?_eq_get (findIdx_lt_length_of_exists h) /-! ### findIdx? -/ @[simp] theorem findIdx?_nil : ([] : List α).findIdx? p i = none := rfl @[simp] theorem findIdx?_cons : (x :: xs).findIdx? p i = if p x then some i else findIdx? p xs (i + 1) := rfl @[simp] theorem findIdx?_succ : (xs : List α).findIdx? p (i+1) = (xs.findIdx? p i).map fun i => i + 1 := by induction xs generalizing i with simp | cons _ _ _ => split <;> simp_all theorem findIdx?_eq_some_iff (xs : List α) (p : α → Bool) : xs.findIdx? p = some i ↔ (xs.take (i + 1)).map p = replicate i false ++ [true] := by induction xs generalizing i with | nil => simp | cons x xs ih => simp only [findIdx?_cons, Nat.zero_add, findIdx?_succ, take_succ_cons, map_cons] split <;> cases i <;> simp_all theorem findIdx?_of_eq_some {xs : List α} {p : α → Bool} (w : xs.findIdx? p = some i) : match xs.get? i with | some a => p a | none => false := by induction xs generalizing i with | nil => simp_all | cons x xs ih => simp_all only [findIdx?_cons, Nat.zero_add, findIdx?_succ] split at w <;> cases i <;> simp_all theorem findIdx?_of_eq_none {xs : List α} {p : α → Bool} (w : xs.findIdx? p = none) : ∀ i, match xs.get? i with | some a => ¬ p a | none => true := by intro i induction xs generalizing i with | nil => simp_all | cons x xs ih => simp_all only [Bool.not_eq_true, findIdx?_cons, Nat.zero_add, findIdx?_succ] cases i with | zero => split at w <;> simp_all | succ i => simp only [get?_cons_succ] apply ih split at w <;> simp_all @[simp] theorem findIdx?_append : (xs ++ ys : List α).findIdx? p = (xs.findIdx? p <|> (ys.findIdx? p).map fun i => i + xs.length) := by induction xs with simp | cons _ _ _ => split <;> simp_all [Option.map_orElse, Option.map_map]; rfl @[simp] theorem findIdx?_replicate : (replicate n a).findIdx? p = if 0 < n ∧ p a then some 0 else none := by induction n with | zero => simp | succ n ih => simp only [replicate, findIdx?_cons, Nat.zero_add, findIdx?_succ, Nat.zero_lt_succ, true_and] split <;> simp_all /-! ### pairwise -/ theorem Pairwise.sublist : l₁ <+ l₂ → l₂.Pairwise R → l₁.Pairwise R | .slnil, h => h | .cons _ s, .cons _ h₂ => h₂.sublist s | .cons₂ _ s, .cons h₁ h₂ => (h₂.sublist s).cons fun _ h => h₁ _ (s.subset h) theorem pairwise_map {l : List α} : (l.map f).Pairwise R ↔ l.Pairwise fun a b => R (f a) (f b) := by induction l · simp · simp only [map, pairwise_cons, forall_mem_map_iff, *] theorem pairwise_append {l₁ l₂ : List α} : (l₁ ++ l₂).Pairwise R ↔ l₁.Pairwise R ∧ l₂.Pairwise R ∧ ∀ a ∈ l₁, ∀ b ∈ l₂, R a b := by induction l₁ <;> simp [*, or_imp, forall_and, and_assoc, and_left_comm] theorem pairwise_reverse {l : List α} : l.reverse.Pairwise R ↔ l.Pairwise (fun a b => R b a) := by induction l <;> simp [*, pairwise_append, and_comm] theorem Pairwise.imp {α R S} (H : ∀ {a b}, R a b → S a b) : ∀ {l : List α}, l.Pairwise R → l.Pairwise S | _, .nil => .nil | _, .cons h₁ h₂ => .cons (H ∘ h₁ ·) (h₂.imp H) /-! ### replaceF -/ theorem replaceF_nil : [].replaceF p = [] := rfl theorem replaceF_cons (a : α) (l : List α) : (a :: l).replaceF p = match p a with | none => a :: replaceF p l | some a' => a' :: l := rfl theorem replaceF_cons_of_some {l : List α} (p) (h : p a = some a') : (a :: l).replaceF p = a' :: l := by simp [replaceF_cons, h] theorem replaceF_cons_of_none {l : List α} (p) (h : p a = none) : (a :: l).replaceF p = a :: l.replaceF p := by simp [replaceF_cons, h] theorem replaceF_of_forall_none {l : List α} (h : ∀ a, a ∈ l → p a = none) : l.replaceF p = l := by induction l with | nil => rfl | cons _ _ ih => simp [h _ (.head ..), ih (forall_mem_cons.1 h).2] theorem exists_of_replaceF : ∀ {l : List α} {a a'} (al : a ∈ l) (pa : p a = some a'), ∃ a a' l₁ l₂, (∀ b ∈ l₁, p b = none) ∧ p a = some a' ∧ l = l₁ ++ a :: l₂ ∧ l.replaceF p = l₁ ++ a' :: l₂ | b :: l, a, a', al, pa => match pb : p b with | some b' => ⟨b, b', [], l, forall_mem_nil _, pb, by simp [pb]⟩ | none => match al with | .head .. => nomatch pb.symm.trans pa | .tail _ al => let ⟨c, c', l₁, l₂, h₁, h₂, h₃, h₄⟩ := exists_of_replaceF al pa ⟨c, c', b::l₁, l₂, (forall_mem_cons ..).2 ⟨pb, h₁⟩, h₂, by rw [h₃, cons_append], by simp [pb, h₄]⟩ theorem exists_or_eq_self_of_replaceF (p) (l : List α) : l.replaceF p = l ∨ ∃ a a' l₁ l₂, (∀ b ∈ l₁, p b = none) ∧ p a = some a' ∧ l = l₁ ++ a :: l₂ ∧ l.replaceF p = l₁ ++ a' :: l₂ := if h : ∃ a ∈ l, (p a).isSome then let ⟨_, ha, pa⟩ := h .inr (exists_of_replaceF ha (Option.get_mem pa)) else .inl <| replaceF_of_forall_none fun a ha => Option.not_isSome_iff_eq_none.1 fun h' => h ⟨a, ha, h'⟩ @[simp] theorem length_replaceF : length (replaceF f l) = length l := by induction l <;> simp [replaceF]; split <;> simp [*] /-! ### disjoint -/ theorem disjoint_symm (d : Disjoint l₁ l₂) : Disjoint l₂ l₁ := fun _ i₂ i₁ => d i₁ i₂ theorem disjoint_comm : Disjoint l₁ l₂ ↔ Disjoint l₂ l₁ := ⟨disjoint_symm, disjoint_symm⟩ theorem disjoint_left : Disjoint l₁ l₂ ↔ ∀ ⦃a⦄, a ∈ l₁ → a ∉ l₂ := by simp [Disjoint] theorem disjoint_right : Disjoint l₁ l₂ ↔ ∀ ⦃a⦄, a ∈ l₂ → a ∉ l₁ := disjoint_comm theorem disjoint_iff_ne : Disjoint l₁ l₂ ↔ ∀ a ∈ l₁, ∀ b ∈ l₂, a ≠ b := ⟨fun h _ al1 _ bl2 ab => h al1 (ab ▸ bl2), fun h _ al1 al2 => h _ al1 _ al2 rfl⟩ theorem disjoint_of_subset_left (ss : l₁ ⊆ l) (d : Disjoint l l₂) : Disjoint l₁ l₂ := fun _ m => d (ss m) theorem disjoint_of_subset_right (ss : l₂ ⊆ l) (d : Disjoint l₁ l) : Disjoint l₁ l₂ := fun _ m m₁ => d m (ss m₁) theorem disjoint_of_disjoint_cons_left {l₁ l₂} : Disjoint (a :: l₁) l₂ → Disjoint l₁ l₂ := disjoint_of_subset_left (subset_cons _ _) theorem disjoint_of_disjoint_cons_right {l₁ l₂} : Disjoint l₁ (a :: l₂) → Disjoint l₁ l₂ := disjoint_of_subset_right (subset_cons _ _) @[simp] theorem disjoint_nil_left (l : List α) : Disjoint [] l := fun a => (not_mem_nil a).elim @[simp] theorem disjoint_nil_right (l : List α) : Disjoint l [] := by rw [disjoint_comm]; exact disjoint_nil_left _ @[simp 1100] theorem singleton_disjoint : Disjoint [a] l ↔ a ∉ l := by simp [Disjoint] @[simp 1100] theorem disjoint_singleton : Disjoint l [a] ↔ a ∉ l := by rw [disjoint_comm, singleton_disjoint] @[simp] theorem disjoint_append_left : Disjoint (l₁ ++ l₂) l ↔ Disjoint l₁ l ∧ Disjoint l₂ l := by simp [Disjoint, or_imp, forall_and] @[simp] theorem disjoint_append_right : Disjoint l (l₁ ++ l₂) ↔ Disjoint l l₁ ∧ Disjoint l l₂ := disjoint_comm.trans <| by rw [disjoint_append_left]; simp [disjoint_comm] @[simp] theorem disjoint_cons_left : Disjoint (a::l₁) l₂ ↔ (a ∉ l₂) ∧ Disjoint l₁ l₂ := (disjoint_append_left (l₁ := [a])).trans <| by simp [singleton_disjoint] @[simp] theorem disjoint_cons_right : Disjoint l₁ (a :: l₂) ↔ (a ∉ l₁) ∧ Disjoint l₁ l₂ := disjoint_comm.trans <| by rw [disjoint_cons_left]; simp [disjoint_comm] theorem disjoint_of_disjoint_append_left_left (d : Disjoint (l₁ ++ l₂) l) : Disjoint l₁ l := (disjoint_append_left.1 d).1 theorem disjoint_of_disjoint_append_left_right (d : Disjoint (l₁ ++ l₂) l) : Disjoint l₂ l := (disjoint_append_left.1 d).2 theorem disjoint_of_disjoint_append_right_left (d : Disjoint l (l₁ ++ l₂)) : Disjoint l l₁ := (disjoint_append_right.1 d).1 theorem disjoint_of_disjoint_append_right_right (d : Disjoint l (l₁ ++ l₂)) : Disjoint l l₂ := (disjoint_append_right.1 d).2 /-! ### foldl / foldr -/ theorem foldl_hom (f : α₁ → α₂) (g₁ : α₁ → β → α₁) (g₂ : α₂ → β → α₂) (l : List β) (init : α₁) (H : ∀ x y, g₂ (f x) y = f (g₁ x y)) : l.foldl g₂ (f init) = f (l.foldl g₁ init) := by induction l generalizing init <;> simp [*, H] theorem foldr_hom (f : β₁ → β₂) (g₁ : α → β₁ → β₁) (g₂ : α → β₂ → β₂) (l : List α) (init : β₁) (H : ∀ x y, g₂ x (f y) = f (g₁ x y)) : l.foldr g₂ (f init) = f (l.foldr g₁ init) := by induction l <;> simp [*, H] /-! ### union -/ section union variable [BEq α] theorem union_def [BEq α] (l₁ l₂ : List α) : l₁ ∪ l₂ = foldr .insert l₂ l₁ := rfl @[simp] theorem nil_union (l : List α) : nil ∪ l = l := by simp [List.union_def, foldr] @[simp] theorem cons_union (a : α) (l₁ l₂ : List α) : (a :: l₁) ∪ l₂ = (l₁ ∪ l₂).insert a := by simp [List.union_def, foldr] @[simp] theorem mem_union_iff [LawfulBEq α] {x : α} {l₁ l₂ : List α} : x ∈ l₁ ∪ l₂ ↔ x ∈ l₁ ∨ x ∈ l₂ := by induction l₁ <;> simp [*, or_assoc] end union /-! ### inter -/ theorem inter_def [BEq α] (l₁ l₂ : List α) : l₁ ∩ l₂ = filter (elem · l₂) l₁ := rfl @[simp] theorem mem_inter_iff [BEq α] [LawfulBEq α] {x : α} {l₁ l₂ : List α} : x ∈ l₁ ∩ l₂ ↔ x ∈ l₁ ∧ x ∈ l₂ := by cases l₁ <;> simp [List.inter_def, mem_filter] /-! ### product -/ /-- List.prod satisfies a specification of cartesian product on lists. -/ @[simp] theorem pair_mem_product {xs : List α} {ys : List β} {x : α} {y : β} : (x, y) ∈ product xs ys ↔ x ∈ xs ∧ y ∈ ys := by simp only [product, and_imp, mem_map, Prod.mk.injEq, exists_eq_right_right, mem_bind, iff_self] /-! ### leftpad -/ /-- The length of the List returned by `List.leftpad n a l` is equal to the larger of `n` and `l.length` -/ @[simp] theorem leftpad_length (n : Nat) (a : α) (l : List α) : (leftpad n a l).length = max n l.length := by simp only [leftpad, length_append, length_replicate, Nat.sub_add_eq_max] theorem leftpad_prefix (n : Nat) (a : α) (l : List α) : replicate (n - length l) a <+: leftpad n a l := by simp only [IsPrefix, leftpad] exact Exists.intro l rfl theorem leftpad_suffix (n : Nat) (a : α) (l : List α) : l <:+ (leftpad n a l) := by simp only [IsSuffix, leftpad] exact Exists.intro (replicate (n - length l) a) rfl /-! ### monadic operations -/ -- we use ForIn.forIn as the simp normal form @[simp] theorem forIn_eq_forIn [Monad m] : @List.forIn α β m _ = forIn := rfl theorem forIn_eq_bindList [Monad m] [LawfulMonad m] (f : α → β → m (ForInStep β)) (l : List α) (init : β) : forIn l init f = ForInStep.run <$> (ForInStep.yield init).bindList f l := by induction l generalizing init <;> simp [*, map_eq_pure_bind] congr; ext (b | b) <;> simp @[simp] theorem forM_append [Monad m] [LawfulMonad m] (l₁ l₂ : List α) (f : α → m PUnit) : (l₁ ++ l₂).forM f = (do l₁.forM f; l₂.forM f) := by induction l₁ <;> simp [*] /-! ### diff -/ section Diff variable [BEq α] variable [LawfulBEq α] @[simp] theorem diff_nil (l : List α) : l.diff [] = l := rfl @[simp] theorem diff_cons (l₁ l₂ : List α) (a : α) : l₁.diff (a :: l₂) = (l₁.erase a).diff l₂ := by simp_all [List.diff, erase_of_not_mem] theorem diff_cons_right (l₁ l₂ : List α) (a : α) : l₁.diff (a :: l₂) = (l₁.diff l₂).erase a := by apply Eq.symm; induction l₂ generalizing l₁ <;> simp [erase_comm, *] theorem diff_erase (l₁ l₂ : List α) (a : α) : (l₁.diff l₂).erase a = (l₁.erase a).diff l₂ := by rw [← diff_cons_right, diff_cons] @[simp] theorem nil_diff (l : List α) : [].diff l = [] := by induction l <;> simp [*, erase_of_not_mem] theorem cons_diff (a : α) (l₁ l₂ : List α) : (a :: l₁).diff l₂ = if a ∈ l₂ then l₁.diff (l₂.erase a) else a :: l₁.diff l₂ := by induction l₂ generalizing l₁ with | nil => rfl | cons b l₂ ih => by_cases h : a = b next => simp [*] next => have := Ne.symm h simp[*] theorem cons_diff_of_mem {a : α} {l₂ : List α} (h : a ∈ l₂) (l₁ : List α) : (a :: l₁).diff l₂ = l₁.diff (l₂.erase a) := by rw [cons_diff, if_pos h] theorem cons_diff_of_not_mem {a : α} {l₂ : List α} (h : a ∉ l₂) (l₁ : List α) : (a :: l₁).diff l₂ = a :: l₁.diff l₂ := by rw [cons_diff, if_neg h] theorem diff_eq_foldl : ∀ l₁ l₂ : List α, l₁.diff l₂ = foldl List.erase l₁ l₂ | _, [] => rfl | l₁, a :: l₂ => (diff_cons l₁ l₂ a).trans (diff_eq_foldl _ _) @[simp] theorem diff_append (l₁ l₂ l₃ : List α) : l₁.diff (l₂ ++ l₃) = (l₁.diff l₂).diff l₃ := by simp only [diff_eq_foldl, foldl_append] theorem diff_sublist : ∀ l₁ l₂ : List α, l₁.diff l₂ <+ l₁ | _, [] => .refl _ | l₁, a :: l₂ => calc l₁.diff (a :: l₂) = (l₁.erase a).diff l₂ := diff_cons .. _ <+ l₁.erase a := diff_sublist .. _ <+ l₁ := erase_sublist .. theorem diff_subset (l₁ l₂ : List α) : l₁.diff l₂ ⊆ l₁ := (diff_sublist ..).subset theorem mem_diff_of_mem {a : α} : ∀ {l₁ l₂ : List α}, a ∈ l₁ → a ∉ l₂ → a ∈ l₁.diff l₂ | _, [], h₁, _ => h₁ | l₁, b :: l₂, h₁, h₂ => by rw [diff_cons] exact mem_diff_of_mem ((mem_erase_of_ne <| ne_of_not_mem_cons h₂).2 h₁) (mt (.tail _) h₂) theorem Sublist.diff_right : ∀ {l₁ l₂ l₃ : List α}, l₁ <+ l₂ → l₁.diff l₃ <+ l₂.diff l₃ | _, _, [], h => h | l₁, l₂, a :: l₃, h => by simp only [diff_cons, (h.erase _).diff_right] theorem Sublist.erase_diff_erase_sublist {a : α} : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → (l₂.erase a).diff (l₁.erase a) <+ l₂.diff l₁ | [], l₂, _ => erase_sublist _ _ | b :: l₁, l₂, h => by if heq : b = a then simp [heq] else simp [heq, erase_comm a] exact (erase_cons_head b _ ▸ h.erase b).erase_diff_erase_sublist end Diff /-! ### prefix, suffix, infix -/ @[simp] theorem prefix_append (l₁ l₂ : List α) : l₁ <+: l₁ ++ l₂ := ⟨l₂, rfl⟩ @[simp] theorem suffix_append (l₁ l₂ : List α) : l₂ <:+ l₁ ++ l₂ := ⟨l₁, rfl⟩ theorem infix_append (l₁ l₂ l₃ : List α) : l₂ <:+: l₁ ++ l₂ ++ l₃ := ⟨l₁, l₃, rfl⟩ @[simp] theorem infix_append' (l₁ l₂ l₃ : List α) : l₂ <:+: l₁ ++ (l₂ ++ l₃) := by rw [← List.append_assoc]; apply infix_append theorem IsPrefix.isInfix : l₁ <+: l₂ → l₁ <:+: l₂ := fun ⟨t, h⟩ => ⟨[], t, h⟩ theorem IsSuffix.isInfix : l₁ <:+ l₂ → l₁ <:+: l₂ := fun ⟨t, h⟩ => ⟨t, [], by rw [h, append_nil]⟩ theorem nil_prefix (l : List α) : [] <+: l := ⟨l, rfl⟩ theorem nil_suffix (l : List α) : [] <:+ l := ⟨l, append_nil _⟩ theorem nil_infix (l : List α) : [] <:+: l := (nil_prefix _).isInfix theorem prefix_refl (l : List α) : l <+: l := ⟨[], append_nil _⟩ theorem suffix_refl (l : List α) : l <:+ l := ⟨[], rfl⟩ theorem infix_refl (l : List α) : l <:+: l := (prefix_refl l).isInfix @[simp] theorem suffix_cons (a : α) : ∀ l, l <:+ a :: l := suffix_append [a] theorem infix_cons : l₁ <:+: l₂ → l₁ <:+: a :: l₂ := fun ⟨L₁, L₂, h⟩ => ⟨a :: L₁, L₂, h ▸ rfl⟩ theorem infix_concat : l₁ <:+: l₂ → l₁ <:+: concat l₂ a := fun ⟨L₁, L₂, h⟩ => ⟨L₁, concat L₂ a, by simp [← h, concat_eq_append, append_assoc]⟩ theorem IsPrefix.trans : ∀ {l₁ l₂ l₃ : List α}, l₁ <+: l₂ → l₂ <+: l₃ → l₁ <+: l₃ | _, _, _, ⟨r₁, rfl⟩, ⟨r₂, rfl⟩ => ⟨r₁ ++ r₂, (append_assoc _ _ _).symm⟩ theorem IsSuffix.trans : ∀ {l₁ l₂ l₃ : List α}, l₁ <:+ l₂ → l₂ <:+ l₃ → l₁ <:+ l₃ | _, _, _, ⟨l₁, rfl⟩, ⟨l₂, rfl⟩ => ⟨l₂ ++ l₁, append_assoc _ _ _⟩ theorem IsInfix.trans : ∀ {l₁ l₂ l₃ : List α}, l₁ <:+: l₂ → l₂ <:+: l₃ → l₁ <:+: l₃ | l, _, _, ⟨l₁, r₁, rfl⟩, ⟨l₂, r₂, rfl⟩ => ⟨l₂ ++ l₁, r₁ ++ r₂, by simp only [append_assoc]⟩ protected theorem IsInfix.sublist : l₁ <:+: l₂ → l₁ <+ l₂ | ⟨_, _, h⟩ => h ▸ (sublist_append_right ..).trans (sublist_append_left ..) protected theorem IsInfix.subset (hl : l₁ <:+: l₂) : l₁ ⊆ l₂ := hl.sublist.subset protected theorem IsPrefix.sublist (h : l₁ <+: l₂) : l₁ <+ l₂ := h.isInfix.sublist protected theorem IsPrefix.subset (hl : l₁ <+: l₂) : l₁ ⊆ l₂ := hl.sublist.subset protected theorem IsSuffix.sublist (h : l₁ <:+ l₂) : l₁ <+ l₂ := h.isInfix.sublist protected theorem IsSuffix.subset (hl : l₁ <:+ l₂) : l₁ ⊆ l₂ := hl.sublist.subset @[simp] theorem reverse_suffix : reverse l₁ <:+ reverse l₂ ↔ l₁ <+: l₂ := ⟨fun ⟨r, e⟩ => ⟨reverse r, by rw [← reverse_reverse l₁, ← reverse_append, e, reverse_reverse]⟩, fun ⟨r, e⟩ => ⟨reverse r, by rw [← reverse_append, e]⟩⟩ @[simp] theorem reverse_prefix : reverse l₁ <+: reverse l₂ ↔ l₁ <:+ l₂ := by rw [← reverse_suffix]; simp only [reverse_reverse] @[simp] theorem reverse_infix : reverse l₁ <:+: reverse l₂ ↔ l₁ <:+: l₂ := by refine ⟨fun ⟨s, t, e⟩ => ⟨reverse t, reverse s, ?_⟩, fun ⟨s, t, e⟩ => ⟨reverse t, reverse s, ?_⟩⟩ · rw [← reverse_reverse l₁, append_assoc, ← reverse_append, ← reverse_append, e, reverse_reverse] · rw [append_assoc, ← reverse_append, ← reverse_append, e] theorem IsInfix.length_le (h : l₁ <:+: l₂) : l₁.length ≤ l₂.length := h.sublist.length_le theorem IsPrefix.length_le (h : l₁ <+: l₂) : l₁.length ≤ l₂.length := h.sublist.length_le theorem IsSuffix.length_le (h : l₁ <:+ l₂) : l₁.length ≤ l₂.length := h.sublist.length_le @[simp] theorem infix_nil : l <:+: [] ↔ l = [] := ⟨(sublist_nil.1 ·.sublist), (· ▸ infix_refl _)⟩ @[simp] theorem prefix_nil : l <+: [] ↔ l = [] := ⟨(sublist_nil.1 ·.sublist), (· ▸ prefix_refl _)⟩ @[simp] theorem suffix_nil : l <:+ [] ↔ l = [] := ⟨(sublist_nil.1 ·.sublist), (· ▸ suffix_refl _)⟩ theorem infix_iff_prefix_suffix (l₁ l₂ : List α) : l₁ <:+: l₂ ↔ ∃ t, l₁ <+: t ∧ t <:+ l₂ := ⟨fun ⟨_, t, e⟩ => ⟨l₁ ++ t, ⟨_, rfl⟩, e ▸ append_assoc .. ▸ ⟨_, rfl⟩⟩, fun ⟨_, ⟨t, rfl⟩, s, e⟩ => ⟨s, t, append_assoc .. ▸ e⟩⟩ theorem IsInfix.eq_of_length (h : l₁ <:+: l₂) : l₁.length = l₂.length → l₁ = l₂ := h.sublist.eq_of_length theorem IsPrefix.eq_of_length (h : l₁ <+: l₂) : l₁.length = l₂.length → l₁ = l₂ := h.sublist.eq_of_length theorem IsSuffix.eq_of_length (h : l₁ <:+ l₂) : l₁.length = l₂.length → l₁ = l₂ := h.sublist.eq_of_length theorem prefix_of_prefix_length_le : ∀ {l₁ l₂ l₃ : List α}, l₁ <+: l₃ → l₂ <+: l₃ → length l₁ ≤ length l₂ → l₁ <+: l₂ | [], l₂, _, _, _, _ => nil_prefix _ | a :: l₁, b :: l₂, _, ⟨r₁, rfl⟩, ⟨r₂, e⟩, ll => by injection e with _ e'; subst b rcases prefix_of_prefix_length_le ⟨_, rfl⟩ ⟨_, e'⟩ (le_of_succ_le_succ ll) with ⟨r₃, rfl⟩ exact ⟨r₃, rfl⟩ theorem prefix_or_prefix_of_prefix (h₁ : l₁ <+: l₃) (h₂ : l₂ <+: l₃) : l₁ <+: l₂ ∨ l₂ <+: l₁ := (Nat.le_total (length l₁) (length l₂)).imp (prefix_of_prefix_length_le h₁ h₂) (prefix_of_prefix_length_le h₂ h₁) theorem suffix_of_suffix_length_le (h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) (ll : length l₁ ≤ length l₂) : l₁ <:+ l₂ := reverse_prefix.1 <| prefix_of_prefix_length_le (reverse_prefix.2 h₁) (reverse_prefix.2 h₂) (by simp [ll]) theorem suffix_or_suffix_of_suffix (h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) : l₁ <:+ l₂ ∨ l₂ <:+ l₁ := (prefix_or_prefix_of_prefix (reverse_prefix.2 h₁) (reverse_prefix.2 h₂)).imp reverse_prefix.1 reverse_prefix.1
.lake/packages/batteries/Batteries/Data/List/Lemmas.lean
1,148
1,157
theorem suffix_cons_iff : l₁ <:+ a :: l₂ ↔ l₁ = a :: l₂ ∨ l₁ <:+ l₂ := by
constructor · rintro ⟨⟨hd, tl⟩, hl₃⟩ · exact Or.inl hl₃ · simp only [cons_append] at hl₃ injection hl₃ with _ hl₄ exact Or.inr ⟨_, hl₄⟩ · rintro (rfl | hl₁) · exact (a :: l₂).suffix_refl · exact hl₁.trans (l₂.suffix_cons _)
/- Copyright (c) 2018 . All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Thomas Browning -/ import Mathlib.Data.ZMod.Basic import Mathlib.GroupTheory.Index import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.GroupTheory.GroupAction.Quotient import Mathlib.GroupTheory.Perm.Cycle.Type import Mathlib.GroupTheory.SpecificGroups.Cyclic import Mathlib.Tactic.IntervalCases #align_import group_theory.p_group from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # p-groups This file contains a proof that if `G` is a `p`-group acting on a finite set `α`, then the number of fixed points of the action is congruent mod `p` to the cardinality of `α`. It also contains proofs of some corollaries of this lemma about existence of fixed points. -/ open Fintype MulAction variable (p : ℕ) (G : Type*) [Group G] /-- A p-group is a group in which every element has prime power order -/ def IsPGroup : Prop := ∀ g : G, ∃ k : ℕ, g ^ p ^ k = 1 #align is_p_group IsPGroup variable {p} {G} namespace IsPGroup theorem iff_orderOf [hp : Fact p.Prime] : IsPGroup p G ↔ ∀ g : G, ∃ k : ℕ, orderOf g = p ^ k := forall_congr' fun g => ⟨fun ⟨k, hk⟩ => Exists.imp (fun _ h => h.right) ((Nat.dvd_prime_pow hp.out).mp (orderOf_dvd_of_pow_eq_one hk)), Exists.imp fun k hk => by rw [← hk, pow_orderOf_eq_one]⟩ #align is_p_group.iff_order_of IsPGroup.iff_orderOf theorem of_card [Fintype G] {n : ℕ} (hG : card G = p ^ n) : IsPGroup p G := fun g => ⟨n, by rw [← hG, pow_card_eq_one]⟩ #align is_p_group.of_card IsPGroup.of_card theorem of_bot : IsPGroup p (⊥ : Subgroup G) := of_card (by rw [← Nat.card_eq_fintype_card, Subgroup.card_bot, pow_zero]) #align is_p_group.of_bot IsPGroup.of_bot theorem iff_card [Fact p.Prime] [Fintype G] : IsPGroup p G ↔ ∃ n : ℕ, card G = p ^ n := by have hG : card G ≠ 0 := card_ne_zero refine ⟨fun h => ?_, fun ⟨n, hn⟩ => of_card hn⟩ suffices ∀ q ∈ Nat.factors (card G), q = p by use (card G).factors.length rw [← List.prod_replicate, ← List.eq_replicate_of_mem this, Nat.prod_factors hG] intro q hq obtain ⟨hq1, hq2⟩ := (Nat.mem_factors hG).mp hq haveI : Fact q.Prime := ⟨hq1⟩ obtain ⟨g, hg⟩ := exists_prime_orderOf_dvd_card q hq2 obtain ⟨k, hk⟩ := (iff_orderOf.mp h) g exact (hq1.pow_eq_iff.mp (hg.symm.trans hk).symm).1.symm #align is_p_group.iff_card IsPGroup.iff_card alias ⟨exists_card_eq, _⟩ := iff_card section GIsPGroup variable (hG : IsPGroup p G) theorem of_injective {H : Type*} [Group H] (ϕ : H →* G) (hϕ : Function.Injective ϕ) : IsPGroup p H := by simp_rw [IsPGroup, ← hϕ.eq_iff, ϕ.map_pow, ϕ.map_one] exact fun h => hG (ϕ h) #align is_p_group.of_injective IsPGroup.of_injective theorem to_subgroup (H : Subgroup G) : IsPGroup p H := hG.of_injective H.subtype Subtype.coe_injective #align is_p_group.to_subgroup IsPGroup.to_subgroup theorem of_surjective {H : Type*} [Group H] (ϕ : G →* H) (hϕ : Function.Surjective ϕ) : IsPGroup p H := by refine fun h => Exists.elim (hϕ h) fun g hg => Exists.imp (fun k hk => ?_) (hG g) rw [← hg, ← ϕ.map_pow, hk, ϕ.map_one] #align is_p_group.of_surjective IsPGroup.of_surjective theorem to_quotient (H : Subgroup G) [H.Normal] : IsPGroup p (G ⧸ H) := hG.of_surjective (QuotientGroup.mk' H) Quotient.surjective_Quotient_mk'' #align is_p_group.to_quotient IsPGroup.to_quotient theorem of_equiv {H : Type*} [Group H] (ϕ : G ≃* H) : IsPGroup p H := hG.of_surjective ϕ.toMonoidHom ϕ.surjective #align is_p_group.of_equiv IsPGroup.of_equiv theorem orderOf_coprime {n : ℕ} (hn : p.Coprime n) (g : G) : (orderOf g).Coprime n := let ⟨k, hk⟩ := hG g (hn.pow_left k).coprime_dvd_left (orderOf_dvd_of_pow_eq_one hk) #align is_p_group.order_of_coprime IsPGroup.orderOf_coprime /-- If `gcd(p,n) = 1`, then the `n`th power map is a bijection. -/ noncomputable def powEquiv {n : ℕ} (hn : p.Coprime n) : G ≃ G := let h : ∀ g : G, (Nat.card (Subgroup.zpowers g)).Coprime n := fun g => (Nat.card_zpowers g).symm ▸ hG.orderOf_coprime hn g { toFun := (· ^ n) invFun := fun g => (powCoprime (h g)).symm ⟨g, Subgroup.mem_zpowers g⟩ left_inv := fun g => Subtype.ext_iff.1 <| (powCoprime (h (g ^ n))).left_inv ⟨g, _, Subtype.ext_iff.1 <| (powCoprime (h g)).left_inv ⟨g, Subgroup.mem_zpowers g⟩⟩ right_inv := fun g => Subtype.ext_iff.1 <| (powCoprime (h g)).right_inv ⟨g, Subgroup.mem_zpowers g⟩ } #align is_p_group.pow_equiv IsPGroup.powEquiv @[simp] theorem powEquiv_apply {n : ℕ} (hn : p.Coprime n) (g : G) : hG.powEquiv hn g = g ^ n := rfl #align is_p_group.pow_equiv_apply IsPGroup.powEquiv_apply @[simp] theorem powEquiv_symm_apply {n : ℕ} (hn : p.Coprime n) (g : G) : (hG.powEquiv hn).symm g = g ^ (orderOf g).gcdB n := by rw [← Nat.card_zpowers]; rfl #align is_p_group.pow_equiv_symm_apply IsPGroup.powEquiv_symm_apply variable [hp : Fact p.Prime] /-- If `p ∤ n`, then the `n`th power map is a bijection. -/ noncomputable abbrev powEquiv' {n : ℕ} (hn : ¬p ∣ n) : G ≃ G := powEquiv hG (hp.out.coprime_iff_not_dvd.mpr hn) #align is_p_group.pow_equiv' IsPGroup.powEquiv' theorem index (H : Subgroup G) [H.FiniteIndex] : ∃ n : ℕ, H.index = p ^ n := by haveI := H.normalCore.fintypeQuotientOfFiniteIndex obtain ⟨n, hn⟩ := iff_card.mp (hG.to_quotient H.normalCore) obtain ⟨k, _, hk2⟩ := (Nat.dvd_prime_pow hp.out).mp ((congr_arg _ (H.normalCore.index_eq_card.trans hn)).mp (Subgroup.index_dvd_of_le H.normalCore_le)) exact ⟨k, hk2⟩ #align is_p_group.index IsPGroup.index theorem card_eq_or_dvd : Nat.card G = 1 ∨ p ∣ Nat.card G := by cases fintypeOrInfinite G · obtain ⟨n, hn⟩ := iff_card.mp hG rw [Nat.card_eq_fintype_card, hn] cases' n with n n · exact Or.inl rfl · exact Or.inr ⟨p ^ n, by rw [pow_succ']⟩ · rw [Nat.card_eq_zero_of_infinite] exact Or.inr ⟨0, rfl⟩ #align is_p_group.card_eq_or_dvd IsPGroup.card_eq_or_dvd theorem nontrivial_iff_card [Fintype G] : Nontrivial G ↔ ∃ n > 0, card G = p ^ n := ⟨fun hGnt => let ⟨k, hk⟩ := iff_card.1 hG ⟨k, Nat.pos_of_ne_zero fun hk0 => by rw [hk0, pow_zero] at hk; exact Fintype.one_lt_card.ne' hk, hk⟩, fun ⟨k, hk0, hk⟩ => one_lt_card_iff_nontrivial.1 <| hk.symm ▸ one_lt_pow (Fact.out (p := p.Prime)).one_lt (ne_of_gt hk0)⟩ #align is_p_group.nontrivial_iff_card IsPGroup.nontrivial_iff_card variable {α : Type*} [MulAction G α] theorem card_orbit (a : α) [Fintype (orbit G a)] : ∃ n : ℕ, card (orbit G a) = p ^ n := by let ϕ := orbitEquivQuotientStabilizer G a haveI := Fintype.ofEquiv (orbit G a) ϕ haveI := (stabilizer G a).finiteIndex_of_finite_quotient rw [card_congr ϕ, ← Subgroup.index_eq_card] exact hG.index (stabilizer G a) #align is_p_group.card_orbit IsPGroup.card_orbit variable (α) [Fintype α] /-- If `G` is a `p`-group acting on a finite set `α`, then the number of fixed points of the action is congruent mod `p` to the cardinality of `α` -/ theorem card_modEq_card_fixedPoints [Fintype (fixedPoints G α)] : card α ≡ card (fixedPoints G α) [MOD p] := by classical calc card α = card (Σy : Quotient (orbitRel G α), { x // Quotient.mk'' x = y }) := card_congr (Equiv.sigmaFiberEquiv (@Quotient.mk'' _ (orbitRel G α))).symm _ = ∑ a : Quotient (orbitRel G α), card { x // Quotient.mk'' x = a } := card_sigma _ ≡ ∑ _a : fixedPoints G α, 1 [MOD p] := ?_ _ = _ := by simp rw [← ZMod.eq_iff_modEq_nat p, Nat.cast_sum, Nat.cast_sum] have key : ∀ x, card { y // (Quotient.mk'' y : Quotient (orbitRel G α)) = Quotient.mk'' x } = card (orbit G x) := fun x => by simp only [Quotient.eq'']; congr refine Eq.symm (Finset.sum_bij_ne_zero (fun a _ _ => Quotient.mk'' a.1) (fun _ _ _ => Finset.mem_univ _) (fun a₁ _ _ a₂ _ _ h => Subtype.eq (mem_fixedPoints'.mp a₂.2 a₁.1 (Quotient.exact' h))) (fun b => Quotient.inductionOn' b fun b _ hb => ?_) fun a ha _ => by rw [key, mem_fixedPoints_iff_card_orbit_eq_one.mp a.2]) obtain ⟨k, hk⟩ := hG.card_orbit b have : k = 0 := Nat.le_zero.1 (Nat.le_of_lt_succ (lt_of_not_ge (mt (pow_dvd_pow p) (by rwa [pow_one, ← hk, ← Nat.modEq_zero_iff_dvd, ← ZMod.eq_iff_modEq_nat, ← key, Nat.cast_zero])))) exact ⟨⟨b, mem_fixedPoints_iff_card_orbit_eq_one.2 <| by rw [hk, this, pow_zero]⟩, Finset.mem_univ _, ne_of_eq_of_ne Nat.cast_one one_ne_zero, rfl⟩ #align is_p_group.card_modeq_card_fixed_points IsPGroup.card_modEq_card_fixedPoints /-- If a p-group acts on `α` and the cardinality of `α` is not a multiple of `p` then the action has a fixed point. -/ theorem nonempty_fixed_point_of_prime_not_dvd_card (hpα : ¬p ∣ card α) [Finite (fixedPoints G α)] : (fixedPoints G α).Nonempty := @Set.nonempty_of_nonempty_subtype _ _ (by cases nonempty_fintype (fixedPoints G α) rw [← card_pos_iff, pos_iff_ne_zero] contrapose! hpα rw [← Nat.modEq_zero_iff_dvd, ← hpα] exact hG.card_modEq_card_fixedPoints α) #align is_p_group.nonempty_fixed_point_of_prime_not_dvd_card IsPGroup.nonempty_fixed_point_of_prime_not_dvd_card /-- If a p-group acts on `α` and the cardinality of `α` is a multiple of `p`, and the action has one fixed point, then it has another fixed point. -/ theorem exists_fixed_point_of_prime_dvd_card_of_fixed_point (hpα : p ∣ card α) {a : α} (ha : a ∈ fixedPoints G α) : ∃ b, b ∈ fixedPoints G α ∧ a ≠ b := by cases nonempty_fintype (fixedPoints G α) have hpf : p ∣ card (fixedPoints G α) := Nat.modEq_zero_iff_dvd.mp ((hG.card_modEq_card_fixedPoints α).symm.trans hpα.modEq_zero_nat) have hα : 1 < card (fixedPoints G α) := (Fact.out (p := p.Prime)).one_lt.trans_le (Nat.le_of_dvd (card_pos_iff.2 ⟨⟨a, ha⟩⟩) hpf) exact let ⟨⟨b, hb⟩, hba⟩ := exists_ne_of_one_lt_card hα ⟨a, ha⟩ ⟨b, hb, fun hab => hba (by simp_rw [hab])⟩ #align is_p_group.exists_fixed_point_of_prime_dvd_card_of_fixed_point IsPGroup.exists_fixed_point_of_prime_dvd_card_of_fixed_point theorem center_nontrivial [Nontrivial G] [Finite G] : Nontrivial (Subgroup.center G) := by classical cases nonempty_fintype G have := (hG.of_equiv ConjAct.toConjAct).exists_fixed_point_of_prime_dvd_card_of_fixed_point G rw [ConjAct.fixedPoints_eq_center] at this have dvd : p ∣ card G := by obtain ⟨n, hn0, hn⟩ := hG.nontrivial_iff_card.mp inferInstance exact hn.symm ▸ dvd_pow_self _ (ne_of_gt hn0) obtain ⟨g, hg⟩ := this dvd (Subgroup.center G).one_mem exact ⟨⟨1, ⟨g, hg.1⟩, mt Subtype.ext_iff.mp hg.2⟩⟩ #align is_p_group.center_nontrivial IsPGroup.center_nontrivial theorem bot_lt_center [Nontrivial G] [Finite G] : ⊥ < Subgroup.center G := by haveI := center_nontrivial hG classical exact bot_lt_iff_ne_bot.mpr ((Subgroup.center G).one_lt_card_iff_ne_bot.mp Finite.one_lt_card) #align is_p_group.bot_lt_center IsPGroup.bot_lt_center end GIsPGroup theorem to_le {H K : Subgroup G} (hK : IsPGroup p K) (hHK : H ≤ K) : IsPGroup p H := hK.of_injective (Subgroup.inclusion hHK) fun a b h => Subtype.ext (by change ((Subgroup.inclusion hHK) a : G) = (Subgroup.inclusion hHK) b apply Subtype.ext_iff.mp h) #align is_p_group.to_le IsPGroup.to_le theorem to_inf_left {H K : Subgroup G} (hH : IsPGroup p H) : IsPGroup p (H ⊓ K : Subgroup G) := hH.to_le inf_le_left #align is_p_group.to_inf_left IsPGroup.to_inf_left theorem to_inf_right {H K : Subgroup G} (hK : IsPGroup p K) : IsPGroup p (H ⊓ K : Subgroup G) := hK.to_le inf_le_right #align is_p_group.to_inf_right IsPGroup.to_inf_right theorem map {H : Subgroup G} (hH : IsPGroup p H) {K : Type*} [Group K] (ϕ : G →* K) : IsPGroup p (H.map ϕ) := by rw [← H.subtype_range, MonoidHom.map_range] exact hH.of_surjective (ϕ.restrict H).rangeRestrict (ϕ.restrict H).rangeRestrict_surjective #align is_p_group.map IsPGroup.map theorem comap_of_ker_isPGroup {H : Subgroup G} (hH : IsPGroup p H) {K : Type*} [Group K] (ϕ : K →* G) (hϕ : IsPGroup p ϕ.ker) : IsPGroup p (H.comap ϕ) := by intro g obtain ⟨j, hj⟩ := hH ⟨ϕ g.1, g.2⟩ rw [Subtype.ext_iff, H.coe_pow, Subtype.coe_mk, ← ϕ.map_pow] at hj obtain ⟨k, hk⟩ := hϕ ⟨g.1 ^ p ^ j, hj⟩ rw [Subtype.ext_iff, ϕ.ker.coe_pow, Subtype.coe_mk, ← pow_mul, ← pow_add] at hk exact ⟨j + k, by rwa [Subtype.ext_iff, (H.comap ϕ).coe_pow]⟩ #align is_p_group.comap_of_ker_is_p_group IsPGroup.comap_of_ker_isPGroup theorem ker_isPGroup_of_injective {K : Type*} [Group K] {ϕ : K →* G} (hϕ : Function.Injective ϕ) : IsPGroup p ϕ.ker := (congr_arg (fun Q : Subgroup K => IsPGroup p Q) (ϕ.ker_eq_bot_iff.mpr hϕ)).mpr IsPGroup.of_bot #align is_p_group.ker_is_p_group_of_injective IsPGroup.ker_isPGroup_of_injective theorem comap_of_injective {H : Subgroup G} (hH : IsPGroup p H) {K : Type*} [Group K] (ϕ : K →* G) (hϕ : Function.Injective ϕ) : IsPGroup p (H.comap ϕ) := hH.comap_of_ker_isPGroup ϕ (ker_isPGroup_of_injective hϕ) #align is_p_group.comap_of_injective IsPGroup.comap_of_injective theorem comap_subtype {H : Subgroup G} (hH : IsPGroup p H) {K : Subgroup G} : IsPGroup p (H.comap K.subtype) := hH.comap_of_injective K.subtype Subtype.coe_injective #align is_p_group.comap_subtype IsPGroup.comap_subtype theorem to_sup_of_normal_right {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K) [K.Normal] : IsPGroup p (H ⊔ K : Subgroup G) := by rw [← QuotientGroup.ker_mk' K, ← Subgroup.comap_map_eq] apply (hH.map (QuotientGroup.mk' K)).comap_of_ker_isPGroup rwa [QuotientGroup.ker_mk'] #align is_p_group.to_sup_of_normal_right IsPGroup.to_sup_of_normal_right theorem to_sup_of_normal_left {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K) [H.Normal] : IsPGroup p (H ⊔ K : Subgroup G) := sup_comm H K ▸ to_sup_of_normal_right hK hH #align is_p_group.to_sup_of_normal_left IsPGroup.to_sup_of_normal_left theorem to_sup_of_normal_right' {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K) (hHK : H ≤ K.normalizer) : IsPGroup p (H ⊔ K : Subgroup G) := let hHK' := to_sup_of_normal_right (hH.of_equiv (Subgroup.subgroupOfEquivOfLe hHK).symm) (hK.of_equiv (Subgroup.subgroupOfEquivOfLe Subgroup.le_normalizer).symm) ((congr_arg (fun H : Subgroup K.normalizer => IsPGroup p H) (Subgroup.sup_subgroupOf_eq hHK Subgroup.le_normalizer)).mp hHK').of_equiv (Subgroup.subgroupOfEquivOfLe (sup_le hHK Subgroup.le_normalizer)) #align is_p_group.to_sup_of_normal_right' IsPGroup.to_sup_of_normal_right' theorem to_sup_of_normal_left' {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K) (hHK : K ≤ H.normalizer) : IsPGroup p (H ⊔ K : Subgroup G) := sup_comm H K ▸ to_sup_of_normal_right' hK hH hHK #align is_p_group.to_sup_of_normal_left' IsPGroup.to_sup_of_normal_left' /-- finite p-groups with different p have coprime orders -/ theorem coprime_card_of_ne {G₂ : Type*} [Group G₂] (p₁ p₂ : ℕ) [hp₁ : Fact p₁.Prime] [hp₂ : Fact p₂.Prime] (hne : p₁ ≠ p₂) (H₁ : Subgroup G) (H₂ : Subgroup G₂) [Fintype H₁] [Fintype H₂] (hH₁ : IsPGroup p₁ H₁) (hH₂ : IsPGroup p₂ H₂) : Nat.Coprime (Fintype.card H₁) (Fintype.card H₂) := by obtain ⟨n₁, heq₁⟩ := iff_card.mp hH₁; rw [heq₁]; clear heq₁ obtain ⟨n₂, heq₂⟩ := iff_card.mp hH₂; rw [heq₂]; clear heq₂ exact Nat.coprime_pow_primes _ _ hp₁.elim hp₂.elim hne #align is_p_group.coprime_card_of_ne IsPGroup.coprime_card_of_ne /-- p-groups with different p are disjoint -/
Mathlib/GroupTheory/PGroup.lean
348
358
theorem disjoint_of_ne (p₁ p₂ : ℕ) [hp₁ : Fact p₁.Prime] [hp₂ : Fact p₂.Prime] (hne : p₁ ≠ p₂) (H₁ H₂ : Subgroup G) (hH₁ : IsPGroup p₁ H₁) (hH₂ : IsPGroup p₂ H₂) : Disjoint H₁ H₂ := by
rw [Subgroup.disjoint_def] intro x hx₁ hx₂ obtain ⟨n₁, hn₁⟩ := iff_orderOf.mp hH₁ ⟨x, hx₁⟩ obtain ⟨n₂, hn₂⟩ := iff_orderOf.mp hH₂ ⟨x, hx₂⟩ rw [Subgroup.orderOf_mk] at hn₁ hn₂ have : p₁ ^ n₁ = p₂ ^ n₂ := by rw [← hn₁, ← hn₂] rcases n₁.eq_zero_or_pos with (rfl | hn₁) · simpa using hn₁ · exact absurd (eq_of_prime_pow_eq hp₁.out.prime hp₂.out.prime hn₁ this) hne
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Init.Order.Defs #align_import init.algebra.functions from "leanprover-community/lean"@"c2bcdbcbe741ed37c361a30d38e179182b989f76" /-! # Basic lemmas about linear orders. The contents of this file came from `init.algebra.functions` in Lean 3, and it would be good to find everything a better home. -/ universe u section open Decidable variable {α : Type u} [LinearOrder α] theorem min_def (a b : α) : min a b = if a ≤ b then a else b := by rw [LinearOrder.min_def a] #align min_def min_def theorem max_def (a b : α) : max a b = if a ≤ b then b else a := by rw [LinearOrder.max_def a] #align max_def max_def theorem min_le_left (a b : α) : min a b ≤ a := by -- Porting note: no `min_tac` tactic if h : a ≤ b then simp [min_def, if_pos h, le_refl] else simp [min_def, if_neg h]; exact le_of_not_le h #align min_le_left min_le_left theorem min_le_right (a b : α) : min a b ≤ b := by -- Porting note: no `min_tac` tactic if h : a ≤ b then simp [min_def, if_pos h]; exact h else simp [min_def, if_neg h, le_refl] #align min_le_right min_le_right
Mathlib/Init/Order/LinearOrder.lean
47
51
theorem le_min {a b c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) : c ≤ min a b := by
-- Porting note: no `min_tac` tactic if h : a ≤ b then simp [min_def, if_pos h]; exact h₁ else simp [min_def, if_neg h]; exact h₂
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Init.Core import Mathlib.LinearAlgebra.AffineSpace.Basis import Mathlib.LinearAlgebra.FiniteDimensional #align_import linear_algebra.affine_space.finite_dimensional from "leanprover-community/mathlib"@"67e606eaea14c7854bdc556bd53d98aefdf76ec0" /-! # Finite-dimensional subspaces of affine spaces. This file provides a few results relating to finite-dimensional subspaces of affine spaces. ## Main definitions * `Collinear` defines collinear sets of points as those that span a subspace of dimension at most 1. -/ noncomputable section open Affine section AffineSpace' variable (k : Type*) {V : Type*} {P : Type*} variable {ι : Type*} open AffineSubspace FiniteDimensional Module variable [DivisionRing k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The `vectorSpan` of a finite set is finite-dimensional. -/ theorem finiteDimensional_vectorSpan_of_finite {s : Set P} (h : Set.Finite s) : FiniteDimensional k (vectorSpan k s) := span_of_finite k <| h.vsub h #align finite_dimensional_vector_span_of_finite finiteDimensional_vectorSpan_of_finite /-- The `vectorSpan` of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_vectorSpan_range [Finite ι] (p : ι → P) : FiniteDimensional k (vectorSpan k (Set.range p)) := finiteDimensional_vectorSpan_of_finite k (Set.finite_range _) #align finite_dimensional_vector_span_range finiteDimensional_vectorSpan_range /-- The `vectorSpan` of a subset of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_vectorSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) : FiniteDimensional k (vectorSpan k (p '' s)) := finiteDimensional_vectorSpan_of_finite k (Set.toFinite _) #align finite_dimensional_vector_span_image_of_finite finiteDimensional_vectorSpan_image_of_finite /-- The direction of the affine span of a finite set is finite-dimensional. -/ theorem finiteDimensional_direction_affineSpan_of_finite {s : Set P} (h : Set.Finite s) : FiniteDimensional k (affineSpan k s).direction := (direction_affineSpan k s).symm ▸ finiteDimensional_vectorSpan_of_finite k h #align finite_dimensional_direction_affine_span_of_finite finiteDimensional_direction_affineSpan_of_finite /-- The direction of the affine span of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_range [Finite ι] (p : ι → P) : FiniteDimensional k (affineSpan k (Set.range p)).direction := finiteDimensional_direction_affineSpan_of_finite k (Set.finite_range _) #align finite_dimensional_direction_affine_span_range finiteDimensional_direction_affineSpan_range /-- The direction of the affine span of a subset of a family indexed by a `Fintype` is finite-dimensional. -/ instance finiteDimensional_direction_affineSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) : FiniteDimensional k (affineSpan k (p '' s)).direction := finiteDimensional_direction_affineSpan_of_finite k (Set.toFinite _) #align finite_dimensional_direction_affine_span_image_of_finite finiteDimensional_direction_affineSpan_image_of_finite /-- An affine-independent family of points in a finite-dimensional affine space is finite. -/ theorem finite_of_fin_dim_affineIndependent [FiniteDimensional k V] {p : ι → P} (hi : AffineIndependent k p) : Finite ι := by nontriviality ι; inhabit ι rw [affineIndependent_iff_linearIndependent_vsub k p default] at hi letI : IsNoetherian k V := IsNoetherian.iff_fg.2 inferInstance exact (Set.finite_singleton default).finite_of_compl (Set.finite_coe_iff.1 hi.finite_of_isNoetherian) #align finite_of_fin_dim_affine_independent finite_of_fin_dim_affineIndependent /-- An affine-independent subset of a finite-dimensional affine space is finite. -/ theorem finite_set_of_fin_dim_affineIndependent [FiniteDimensional k V] {s : Set ι} {f : s → P} (hi : AffineIndependent k f) : s.Finite := @Set.toFinite _ s (finite_of_fin_dim_affineIndependent k hi) #align finite_set_of_fin_dim_affine_independent finite_set_of_fin_dim_affineIndependent variable {k} /-- The `vectorSpan` of a finite subset of an affinely independent family has dimension one less than its cardinality. -/ theorem AffineIndependent.finrank_vectorSpan_image_finset [DecidableEq P] {p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {n : ℕ} (hc : Finset.card s = n + 1) : finrank k (vectorSpan k (s.image p : Set P)) = n := by classical have hi' := hi.range.mono (Set.image_subset_range p ↑s) have hc' : (s.image p).card = n + 1 := by rwa [s.card_image_of_injective hi.injective] have hn : (s.image p).Nonempty := by simp [hc', ← Finset.card_pos] rcases hn with ⟨p₁, hp₁⟩ have hp₁' : p₁ ∈ p '' s := by simpa using hp₁ rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁', ← Finset.coe_singleton, ← Finset.coe_image, ← Finset.coe_sdiff, Finset.sdiff_singleton_eq_erase, ← Finset.coe_image] at hi' have hc : (Finset.image (fun p : P => p -ᵥ p₁) ((Finset.image p s).erase p₁)).card = n := by rw [Finset.card_image_of_injective _ (vsub_left_injective _), Finset.card_erase_of_mem hp₁] exact Nat.pred_eq_of_eq_succ hc' rwa [vectorSpan_eq_span_vsub_finset_right_ne k hp₁, finrank_span_finset_eq_card, hc] #align affine_independent.finrank_vector_span_image_finset AffineIndependent.finrank_vectorSpan_image_finset /-- The `vectorSpan` of a finite affinely independent family has dimension one less than its cardinality. -/ theorem AffineIndependent.finrank_vectorSpan [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) {n : ℕ} (hc : Fintype.card ι = n + 1) : finrank k (vectorSpan k (Set.range p)) = n := by classical rw [← Finset.card_univ] at hc rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] exact hi.finrank_vectorSpan_image_finset hc #align affine_independent.finrank_vector_span AffineIndependent.finrank_vectorSpan /-- The `vectorSpan` of a finite affinely independent family has dimension one less than its cardinality. -/ lemma AffineIndependent.finrank_vectorSpan_add_one [Fintype ι] [Nonempty ι] {p : ι → P} (hi : AffineIndependent k p) : finrank k (vectorSpan k (Set.range p)) + 1 = Fintype.card ι := by rw [hi.finrank_vectorSpan (tsub_add_cancel_of_le _).symm, tsub_add_cancel_of_le] <;> exact Fintype.card_pos /-- The `vectorSpan` of a finite affinely independent family whose cardinality is one more than that of the finite-dimensional space is `⊤`. -/ theorem AffineIndependent.vectorSpan_eq_top_of_card_eq_finrank_add_one [FiniteDimensional k V] [Fintype ι] {p : ι → P} (hi : AffineIndependent k p) (hc : Fintype.card ι = finrank k V + 1) : vectorSpan k (Set.range p) = ⊤ := Submodule.eq_top_of_finrank_eq <| hi.finrank_vectorSpan hc #align affine_independent.vector_span_eq_top_of_card_eq_finrank_add_one AffineIndependent.vectorSpan_eq_top_of_card_eq_finrank_add_one variable (k) /-- The `vectorSpan` of `n + 1` points in an indexed family has dimension at most `n`. -/ theorem finrank_vectorSpan_image_finset_le [DecidableEq P] (p : ι → P) (s : Finset ι) {n : ℕ} (hc : Finset.card s = n + 1) : finrank k (vectorSpan k (s.image p : Set P)) ≤ n := by classical have hn : (s.image p).Nonempty := by rw [Finset.image_nonempty, ← Finset.card_pos, hc] apply Nat.succ_pos rcases hn with ⟨p₁, hp₁⟩ rw [vectorSpan_eq_span_vsub_finset_right_ne k hp₁] refine le_trans (finrank_span_finset_le_card (((s.image p).erase p₁).image fun p => p -ᵥ p₁)) ?_ rw [Finset.card_image_of_injective _ (vsub_left_injective p₁), Finset.card_erase_of_mem hp₁, tsub_le_iff_right, ← hc] apply Finset.card_image_le #align finrank_vector_span_image_finset_le finrank_vectorSpan_image_finset_le /-- The `vectorSpan` of an indexed family of `n + 1` points has dimension at most `n`. -/
Mathlib/LinearAlgebra/AffineSpace/FiniteDimensional.lean
164
169
theorem finrank_vectorSpan_range_le [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) : finrank k (vectorSpan k (Set.range p)) ≤ n := by
classical rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] rw [← Finset.card_univ] at hc exact finrank_vectorSpan_image_finset_le _ _ _ hc
/- 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 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 theorem X_eq_normalize : (X : Polynomial R) = normalize X := by simp only [normalize_apply, normUnit_X, Units.val_one, mul_one] end NormalizationMonoid end IsDomain section DivisionRing variable [DivisionRing R] {p q : R[X]} theorem degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬IsUnit p) : 0 < degree p := lt_of_not_ge fun h => by rw [eq_C_of_degree_le_zero h] at hp0 hp exact hp (IsUnit.map C (IsUnit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0)))) #align polynomial.degree_pos_of_ne_zero_of_nonunit Polynomial.degree_pos_of_ne_zero_of_nonunit @[simp] theorem map_eq_zero [Semiring S] [Nontrivial S] (f : R →+* S) : p.map f = 0 ↔ p = 0 := by simp only [Polynomial.ext_iff] congr! simp [map_eq_zero, coeff_map, coeff_zero] #align polynomial.map_eq_zero Polynomial.map_eq_zero theorem map_ne_zero [Semiring S] [Nontrivial S] {f : R →+* S} (hp : p ≠ 0) : p.map f ≠ 0 := mt (map_eq_zero f).1 hp #align polynomial.map_ne_zero Polynomial.map_ne_zero @[simp] theorem degree_map [Semiring S] [Nontrivial S] (p : R[X]) (f : R →+* S) : degree (p.map f) = degree p := p.degree_map_eq_of_injective f.injective #align polynomial.degree_map Polynomial.degree_map @[simp] theorem natDegree_map [Semiring S] [Nontrivial S] (f : R →+* S) : natDegree (p.map f) = natDegree p := natDegree_eq_of_degree_eq (degree_map _ f) #align polynomial.nat_degree_map Polynomial.natDegree_map @[simp] theorem leadingCoeff_map [Semiring S] [Nontrivial S] (f : R →+* S) : leadingCoeff (p.map f) = f (leadingCoeff p) := by simp only [← coeff_natDegree, coeff_map f, natDegree_map] #align polynomial.leading_coeff_map Polynomial.leadingCoeff_map theorem monic_map_iff [Semiring S] [Nontrivial S] {f : R →+* S} {p : R[X]} : (p.map f).Monic ↔ p.Monic := by rw [Monic, leadingCoeff_map, ← f.map_one, Function.Injective.eq_iff f.injective, Monic] #align polynomial.monic_map_iff Polynomial.monic_map_iff end DivisionRing section Field variable [Field R] {p q : R[X]} theorem isUnit_iff_degree_eq_zero : IsUnit p ↔ degree p = 0 := ⟨degree_eq_zero_of_isUnit, fun h => have : degree p ≤ 0 := by simp [*, le_refl] have hc : coeff p 0 ≠ 0 := fun hc => by rw [eq_C_of_degree_le_zero this, hc] at h; simp only [map_zero] at h; contradiction isUnit_iff_dvd_one.2 ⟨C (coeff p 0)⁻¹, by conv in p => rw [eq_C_of_degree_le_zero this] rw [← C_mul, _root_.mul_inv_cancel hc, C_1]⟩⟩ #align polynomial.is_unit_iff_degree_eq_zero Polynomial.isUnit_iff_degree_eq_zero /-- Division of polynomials. See `Polynomial.divByMonic` for more details. -/ def div (p q : R[X]) := C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) #align polynomial.div Polynomial.div /-- Remainder of polynomial division. See `Polynomial.modByMonic` for more details. -/ def mod (p q : R[X]) := p %ₘ (q * C (leadingCoeff q)⁻¹) #align polynomial.mod Polynomial.mod private theorem quotient_mul_add_remainder_eq_aux (p q : R[X]) : q * div p q + mod p q = p := by by_cases h : q = 0 · simp only [h, zero_mul, mod, modByMonic_zero, zero_add] · conv => rhs rw [← modByMonic_add_div p (monic_mul_leadingCoeff_inv h)] rw [div, mod, add_comm, mul_assoc] private theorem remainder_lt_aux (p : R[X]) (hq : q ≠ 0) : degree (mod p q) < degree q := by rw [← degree_mul_leadingCoeff_inv q hq] exact degree_modByMonic_lt p (monic_mul_leadingCoeff_inv hq) instance : Div R[X] := ⟨div⟩ instance : Mod R[X] := ⟨mod⟩ theorem div_def : p / q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) := rfl #align polynomial.div_def Polynomial.div_def theorem mod_def : p % q = p %ₘ (q * C (leadingCoeff q)⁻¹) := rfl #align polynomial.mod_def Polynomial.mod_def theorem modByMonic_eq_mod (p : R[X]) (hq : Monic q) : p %ₘ q = p % q := show p %ₘ q = p %ₘ (q * C (leadingCoeff q)⁻¹) by simp only [Monic.def.1 hq, inv_one, mul_one, C_1] #align polynomial.mod_by_monic_eq_mod Polynomial.modByMonic_eq_mod theorem divByMonic_eq_div (p : R[X]) (hq : Monic q) : p /ₘ q = p / q := show p /ₘ q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) by simp only [Monic.def.1 hq, inv_one, C_1, one_mul, mul_one] #align polynomial.div_by_monic_eq_div Polynomial.divByMonic_eq_div theorem mod_X_sub_C_eq_C_eval (p : R[X]) (a : R) : p % (X - C a) = C (p.eval a) := modByMonic_eq_mod p (monic_X_sub_C a) ▸ modByMonic_X_sub_C_eq_C_eval _ _ set_option linter.uppercaseLean3 false in #align polynomial.mod_X_sub_C_eq_C_eval Polynomial.mod_X_sub_C_eq_C_eval theorem mul_div_eq_iff_isRoot : (X - C a) * (p / (X - C a)) = p ↔ IsRoot p a := divByMonic_eq_div p (monic_X_sub_C a) ▸ mul_divByMonic_eq_iff_isRoot #align polynomial.mul_div_eq_iff_is_root Polynomial.mul_div_eq_iff_isRoot instance instEuclideanDomain : EuclideanDomain R[X] := { Polynomial.commRing, Polynomial.nontrivial with quotient := (· / ·) quotient_zero := by simp [div_def] remainder := (· % ·) r := _ r_wellFounded := degree_lt_wf quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux remainder_lt := fun p q hq => remainder_lt_aux _ hq mul_left_not_lt := fun p q hq => not_lt_of_ge (degree_le_mul_left _ hq) } theorem mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q := ⟨fun h => h ▸ EuclideanDomain.mod_lt _ hq0, fun h => by classical have : ¬degree (q * C (leadingCoeff q)⁻¹) ≤ degree p := not_le_of_gt <| by rwa [degree_mul_leadingCoeff_inv q hq0] rw [mod_def, modByMonic, dif_pos (monic_mul_leadingCoeff_inv hq0)] unfold divModByMonicAux dsimp simp only [this, false_and_iff, if_false]⟩ #align polynomial.mod_eq_self_iff Polynomial.mod_eq_self_iff theorem div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q := ⟨fun h => by have := EuclideanDomain.div_add_mod p q; rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this, fun h => by have hlt : degree p < degree (q * C (leadingCoeff q)⁻¹) := by rwa [degree_mul_leadingCoeff_inv q hq0] have hm : Monic (q * C (leadingCoeff q)⁻¹) := monic_mul_leadingCoeff_inv hq0 rw [div_def, (divByMonic_eq_zero_iff hm).2 hlt, mul_zero]⟩ #align polynomial.div_eq_zero_iff Polynomial.div_eq_zero_iff theorem degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) : degree q + degree (p / q) = degree p := by have : degree (p % q) < degree (q * (p / q)) := calc degree (p % q) < degree q := EuclideanDomain.mod_lt _ hq0 _ ≤ _ := degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq)) conv_rhs => rw [← EuclideanDomain.div_add_mod p q, degree_add_eq_left_of_degree_lt this, degree_mul] #align polynomial.degree_add_div Polynomial.degree_add_div theorem degree_div_le (p q : R[X]) : degree (p / q) ≤ degree p := by by_cases hq : q = 0 · simp [hq] · rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq]; exact degree_divByMonic_le _ _ #align polynomial.degree_div_le Polynomial.degree_div_le theorem degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p := by have hq0 : q ≠ 0 := fun hq0 => by simp [hq0] at hq rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq0]; exact degree_divByMonic_lt _ (monic_mul_leadingCoeff_inv hq0) hp (by rw [degree_mul_leadingCoeff_inv _ hq0]; exact hq) #align polynomial.degree_div_lt Polynomial.degree_div_lt theorem isUnit_map [Field k] (f : R →+* k) : IsUnit (p.map f) ↔ IsUnit p := by simp_rw [isUnit_iff_degree_eq_zero, degree_map] #align polynomial.is_unit_map Polynomial.isUnit_map theorem map_div [Field k] (f : R →+* k) : (p / q).map f = p.map f / q.map f := by if hq0 : q = 0 then simp [hq0] else rw [div_def, div_def, Polynomial.map_mul, map_divByMonic f (monic_mul_leadingCoeff_inv hq0), Polynomial.map_mul, map_C, leadingCoeff_map, map_inv₀] #align polynomial.map_div Polynomial.map_div theorem map_mod [Field k] (f : R →+* k) : (p % q).map f = p.map f % q.map f := by by_cases hq0 : q = 0 · simp [hq0] · rw [mod_def, mod_def, leadingCoeff_map f, ← map_inv₀ f, ← map_C f, ← Polynomial.map_mul f, map_modByMonic f (monic_mul_leadingCoeff_inv hq0)] #align polynomial.map_mod Polynomial.map_mod section open EuclideanDomain theorem gcd_map [Field k] [DecidableEq R] [DecidableEq k] (f : R →+* k) : gcd (p.map f) (q.map f) = (gcd p q).map f := GCD.induction p q (fun x => by simp_rw [Polynomial.map_zero, EuclideanDomain.gcd_zero_left]) fun x y _ ih => by rw [gcd_val, ← map_mod, ih, ← gcd_val] #align polynomial.gcd_map Polynomial.gcd_map end theorem eval₂_gcd_eq_zero [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} (hf : f.eval₂ ϕ α = 0) (hg : g.eval₂ ϕ α = 0) : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 := by rw [EuclideanDomain.gcd_eq_gcd_ab f g, Polynomial.eval₂_add, Polynomial.eval₂_mul, Polynomial.eval₂_mul, hf, hg, zero_mul, zero_mul, zero_add] #align polynomial.eval₂_gcd_eq_zero Polynomial.eval₂_gcd_eq_zero theorem eval_gcd_eq_zero [DecidableEq R] {f g : R[X]} {α : R} (hf : f.eval α = 0) (hg : g.eval α = 0) : (EuclideanDomain.gcd f g).eval α = 0 := eval₂_gcd_eq_zero hf hg #align polynomial.eval_gcd_eq_zero Polynomial.eval_gcd_eq_zero theorem root_left_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} (hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : f.eval₂ ϕ α = 0 := by cases' EuclideanDomain.gcd_dvd_left f g with p hp rw [hp, Polynomial.eval₂_mul, hα, zero_mul] #align polynomial.root_left_of_root_gcd Polynomial.root_left_of_root_gcd theorem root_right_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} (hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : g.eval₂ ϕ α = 0 := by cases' EuclideanDomain.gcd_dvd_right f g with p hp rw [hp, Polynomial.eval₂_mul, hα, zero_mul] #align polynomial.root_right_of_root_gcd Polynomial.root_right_of_root_gcd theorem root_gcd_iff_root_left_right [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k} : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 ↔ f.eval₂ ϕ α = 0 ∧ g.eval₂ ϕ α = 0 := ⟨fun h => ⟨root_left_of_root_gcd h, root_right_of_root_gcd h⟩, fun h => eval₂_gcd_eq_zero h.1 h.2⟩ #align polynomial.root_gcd_iff_root_left_right Polynomial.root_gcd_iff_root_left_right theorem isRoot_gcd_iff_isRoot_left_right [DecidableEq R] {f g : R[X]} {α : R} : (EuclideanDomain.gcd f g).IsRoot α ↔ f.IsRoot α ∧ g.IsRoot α := root_gcd_iff_root_left_right #align polynomial.is_root_gcd_iff_is_root_left_right Polynomial.isRoot_gcd_iff_isRoot_left_right theorem isCoprime_map [Field k] (f : R →+* k) : IsCoprime (p.map f) (q.map f) ↔ IsCoprime p q := by classical rw [← EuclideanDomain.gcd_isUnit_iff, ← EuclideanDomain.gcd_isUnit_iff, gcd_map, isUnit_map] #align polynomial.is_coprime_map Polynomial.isCoprime_map theorem mem_roots_map [CommRing k] [IsDomain k] {f : R →+* k} {x : k} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by rw [mem_roots (map_ne_zero hp), IsRoot, Polynomial.eval_map] #align polynomial.mem_roots_map Polynomial.mem_roots_map theorem rootSet_monomial [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R} (ha : a ≠ 0) : (monomial n a).rootSet S = {0} := by classical rw [rootSet, aroots_monomial ha, Multiset.toFinset_nsmul _ _ hn, Multiset.toFinset_singleton, Finset.coe_singleton] #align polynomial.root_set_monomial Polynomial.rootSet_monomial theorem rootSet_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R} (ha : a ≠ 0) : rootSet (C a * X ^ n) S = {0} := by rw [C_mul_X_pow_eq_monomial, rootSet_monomial hn ha] set_option linter.uppercaseLean3 false in #align polynomial.root_set_C_mul_X_pow Polynomial.rootSet_C_mul_X_pow theorem rootSet_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) : (X ^ n : R[X]).rootSet S = {0} := by rw [← one_mul (X ^ n : R[X]), ← C_1, rootSet_C_mul_X_pow hn] exact one_ne_zero set_option linter.uppercaseLean3 false in #align polynomial.root_set_X_pow Polynomial.rootSet_X_pow
Mathlib/Algebra/Polynomial/FieldDivision.lean
494
499
theorem rootSet_prod [CommRing S] [IsDomain S] [Algebra R S] {ι : Type*} (f : ι → R[X]) (s : Finset ι) (h : s.prod f ≠ 0) : (s.prod f).rootSet S = ⋃ i ∈ s, (f i).rootSet S := by
classical simp only [rootSet, aroots, ← Finset.mem_coe] rw [Polynomial.map_prod, roots_prod, Finset.bind_toFinset, s.val_toFinset, Finset.coe_biUnion] rwa [← Polynomial.map_prod, Ne, map_eq_zero]
/- 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 theorem lt_div_iff' (hc : 0 < c) : a < b / c ↔ c * a < b := by rw [mul_comm, lt_div_iff hc] #align lt_div_iff' lt_div_iff' theorem div_lt_iff (hc : 0 < c) : b / c < a ↔ b < a * c := lt_iff_lt_of_le_iff_le (le_div_iff hc) #align div_lt_iff div_lt_iff theorem div_lt_iff' (hc : 0 < c) : b / c < a ↔ b < c * a := by rw [mul_comm, div_lt_iff hc] #align div_lt_iff' div_lt_iff' lemma div_lt_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b < c ↔ a / c < b := by rw [div_lt_iff hb, div_lt_iff' hc] theorem inv_mul_le_iff (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_le_iff' h #align inv_mul_le_iff inv_mul_le_iff theorem inv_mul_le_iff' (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ c * b := by rw [inv_mul_le_iff h, mul_comm] #align inv_mul_le_iff' inv_mul_le_iff' theorem mul_inv_le_iff (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [mul_comm, inv_mul_le_iff h] #align mul_inv_le_iff mul_inv_le_iff theorem mul_inv_le_iff' (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ c * b := by rw [mul_comm, inv_mul_le_iff' h] #align mul_inv_le_iff' mul_inv_le_iff' theorem div_self_le_one (a : α) : a / a ≤ 1 := if h : a = 0 then by simp [h] else by simp [h] #align div_self_le_one div_self_le_one theorem inv_mul_lt_iff (h : 0 < b) : b⁻¹ * a < c ↔ a < b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_lt_iff' h #align inv_mul_lt_iff inv_mul_lt_iff theorem inv_mul_lt_iff' (h : 0 < b) : b⁻¹ * a < c ↔ a < c * b := by rw [inv_mul_lt_iff h, mul_comm] #align inv_mul_lt_iff' inv_mul_lt_iff' theorem mul_inv_lt_iff (h : 0 < b) : a * b⁻¹ < c ↔ a < b * c := by rw [mul_comm, inv_mul_lt_iff h] #align mul_inv_lt_iff mul_inv_lt_iff theorem mul_inv_lt_iff' (h : 0 < b) : a * b⁻¹ < c ↔ a < c * b := by rw [mul_comm, inv_mul_lt_iff' h] #align mul_inv_lt_iff' mul_inv_lt_iff' theorem inv_pos_le_iff_one_le_mul (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ b * a := by rw [inv_eq_one_div] exact div_le_iff ha #align inv_pos_le_iff_one_le_mul inv_pos_le_iff_one_le_mul
Mathlib/Algebra/Order/Field/Basic.lean
136
138
theorem inv_pos_le_iff_one_le_mul' (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by
rw [inv_eq_one_div] exact div_le_iff' ha
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SeparableClosure import Mathlib.Algebra.CharP.IntermediateField /-! # Purely inseparable extension and relative perfect closure This file contains basics about purely inseparable extensions and the relative perfect closure of fields. ## Main definitions - `IsPurelyInseparable`: typeclass for purely inseparable field extensions: an algebraic extension `E / F` is purely inseparable if and only if the minimal polynomial of every element of `E ∖ F` is not separable. - `perfectClosure`: the relative perfect closure of `F` in `E`, it consists of the elements `x` of `E` such that there exists a natural number `n` such that `x ^ (ringExpChar F) ^ n` is contained in `F`, where `ringExpChar F` is the exponential characteristic of `F`. It is also the maximal purely inseparable subextension of `E / F` (`le_perfectClosure_iff`). ## Main results - `IsPurelyInseparable.surjective_algebraMap_of_isSeparable`, `IsPurelyInseparable.bijective_algebraMap_of_isSeparable`, `IntermediateField.eq_bot_of_isPurelyInseparable_of_isSeparable`: if `E / F` is both purely inseparable and separable, then `algebraMap F E` is surjective (hence bijective). In particular, if an intermediate field of `E / F` is both purely inseparable and separable, then it is equal to `F`. - `isPurelyInseparable_iff_pow_mem`: a field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, there exists a natural number `n` such that `x ^ (q ^ n)` is contained in `F`. - `IsPurelyInseparable.trans`: if `E / F` and `K / E` are both purely inseparable extensions, then `K / F` is also purely inseparable. - `isPurelyInseparable_iff_natSepDegree_eq_one`: `E / F` is purely inseparable if and only if for every element `x` of `E`, its minimal polynomial has separable degree one. - `isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C`: a field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `X ^ (q ^ n) - y` for some natural number `n` and some element `y` of `F`. - `isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow`: a field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `(X - x) ^ (q ^ n)` for some natural number `n`. - `isPurelyInseparable_iff_finSepDegree_eq_one`: an algebraic extension is purely inseparable if and only if it has finite separable degree (`Field.finSepDegree`) one. **TODO:** remove the algebraic assumption. - `IsPurelyInseparable.normal`: a purely inseparable extension is normal. - `separableClosure.isPurelyInseparable`: if `E / F` is algebraic, then `E` is purely inseparable over the separable closure of `F` in `E`. - `separableClosure_le_iff`: if `E / F` is algebraic, then an intermediate field of `E / F` contains the separable closure of `F` in `E` if and only if `E` is purely inseparable over it. - `eq_separableClosure_iff`: if `E / F` is algebraic, then an intermediate field of `E / F` is equal to the separable closure of `F` in `E` if and only if it is separable over `F`, and `E` is purely inseparable over it. - `le_perfectClosure_iff`: an intermediate field of `E / F` is contained in the relative perfect closure of `F` in `E` if and only if it is purely inseparable over `F`. - `perfectClosure.perfectRing`, `perfectClosure.perfectField`: if `E` is a perfect field, then the (relative) perfect closure `perfectClosure F E` is perfect. - `IsPurelyInseparable.injective_comp_algebraMap`: if `E / F` is purely inseparable, then for any reduced ring `L`, the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective. In particular, a purely inseparable field extension is an epimorphism in the category of fields. - `IntermediateField.isPurelyInseparable_adjoin_iff_pow_mem`: if `F` is of exponential characteristic `q`, then `F(S) / F` is a purely inseparable extension if and only if for any `x ∈ S`, `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`. - `Field.finSepDegree_eq`: if `E / F` is algebraic, then the `Field.finSepDegree F E` is equal to `Field.sepDegree F E` as a natural number. This means that the cardinality of `Field.Emb F E` and the degree of `(separableClosure F E) / F` are both finite or infinite, and when they are finite, they coincide. - `Field.finSepDegree_mul_finInsepDegree`: the finite separable degree multiply by the finite inseparable degree is equal to the (finite) field extension degree. - `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`: the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$. - `IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable`, `IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable'`: if `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then for any subset `S` of `K` such that `F(S) / F` is algebraic, the `E(S) / E` and `F(S) / F` have the same separable degree. In particular, if `S` is an intermediate field of `K / F` such that `S / F` is algebraic, the `E(S) / E` and `S / F` have the same separable degree. - `minpoly.map_eq_of_separable_of_isPurelyInseparable`: if `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then for any element `x` of `K` separable over `F`, it has the same minimal polynomials over `F` and over `E`. - `Polynomial.Separable.map_irreducible_of_isPurelyInseparable`: if `E / F` is purely inseparable, `f` is a separable irreducible polynomial over `F`, then it is also irreducible over `E`. ## Tags separable degree, degree, separable closure, purely inseparable ## TODO - `IsPurelyInseparable.of_injective_comp_algebraMap`: if `L` is an algebraically closed field containing `E`, such that the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective, then `E / F` is purely inseparable. As a corollary, epimorphisms in the category of fields must be purely inseparable extensions. Need to use the fact that `Emb F E` is infinite (or just not a singleton) when `E / F` is (purely) transcendental. - Restate some intermediate result in terms of linearly disjointness. - Prove that the inseparable degrees satisfy the tower law: $[E:F]_i [K:E]_i = [K:F]_i$. Probably an argument using linearly disjointness is needed. -/ open FiniteDimensional Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] section IsPurelyInseparable /-- Typeclass for purely inseparable field extensions: an algebraic extension `E / F` is purely inseparable if and only if the minimal polynomial of every element of `E ∖ F` is not separable. -/ class IsPurelyInseparable : Prop where isIntegral : Algebra.IsIntegral F E inseparable' (x : E) : (minpoly F x).Separable → x ∈ (algebraMap F E).range attribute [instance] IsPurelyInseparable.isIntegral variable {E} in theorem IsPurelyInseparable.isIntegral' [IsPurelyInseparable F E] (x : E) : IsIntegral F x := Algebra.IsIntegral.isIntegral _ theorem IsPurelyInseparable.isAlgebraic [IsPurelyInseparable F E] : Algebra.IsAlgebraic F E := inferInstance variable {E} theorem IsPurelyInseparable.inseparable [IsPurelyInseparable F E] : ∀ x : E, (minpoly F x).Separable → x ∈ (algebraMap F E).range := IsPurelyInseparable.inseparable' variable {F K} theorem isPurelyInseparable_iff : IsPurelyInseparable F E ↔ ∀ x : E, IsIntegral F x ∧ ((minpoly F x).Separable → x ∈ (algebraMap F E).range) := ⟨fun h x ↦ ⟨h.isIntegral' x, h.inseparable' x⟩, fun h ↦ ⟨⟨fun x ↦ (h x).1⟩, fun x ↦ (h x).2⟩⟩ /-- Transfer `IsPurelyInseparable` across an `AlgEquiv`. -/ theorem AlgEquiv.isPurelyInseparable (e : K ≃ₐ[F] E) [IsPurelyInseparable F K] : IsPurelyInseparable F E := by refine ⟨⟨fun _ ↦ by rw [← isIntegral_algEquiv e.symm]; exact IsPurelyInseparable.isIntegral' F _⟩, fun x h ↦ ?_⟩ rw [← minpoly.algEquiv_eq e.symm] at h simpa only [RingHom.mem_range, algebraMap_eq_apply] using IsPurelyInseparable.inseparable F _ h theorem AlgEquiv.isPurelyInseparable_iff (e : K ≃ₐ[F] E) : IsPurelyInseparable F K ↔ IsPurelyInseparable F E := ⟨fun _ ↦ e.isPurelyInseparable, fun _ ↦ e.symm.isPurelyInseparable⟩ /-- If `E / F` is an algebraic extension, `F` is separably closed, then `E / F` is purely inseparable. -/ theorem Algebra.IsAlgebraic.isPurelyInseparable_of_isSepClosed [Algebra.IsAlgebraic F E] [IsSepClosed F] : IsPurelyInseparable F E := ⟨inferInstance, fun x h ↦ minpoly.mem_range_of_degree_eq_one F x <| IsSepClosed.degree_eq_one_of_irreducible F (minpoly.irreducible (Algebra.IsIntegral.isIntegral _)) h⟩ variable (F E K) /-- If `E / F` is both purely inseparable and separable, then `algebraMap F E` is surjective. -/ theorem IsPurelyInseparable.surjective_algebraMap_of_isSeparable [IsPurelyInseparable F E] [IsSeparable F E] : Function.Surjective (algebraMap F E) := fun x ↦ IsPurelyInseparable.inseparable F x (IsSeparable.separable F x) /-- If `E / F` is both purely inseparable and separable, then `algebraMap F E` is bijective. -/ theorem IsPurelyInseparable.bijective_algebraMap_of_isSeparable [IsPurelyInseparable F E] [IsSeparable F E] : Function.Bijective (algebraMap F E) := ⟨(algebraMap F E).injective, surjective_algebraMap_of_isSeparable F E⟩ variable {F E} in /-- If an intermediate field of `E / F` is both purely inseparable and separable, then it is equal to `F`. -/ theorem IntermediateField.eq_bot_of_isPurelyInseparable_of_isSeparable (L : IntermediateField F E) [IsPurelyInseparable F L] [IsSeparable F L] : L = ⊥ := bot_unique fun x hx ↦ by obtain ⟨y, hy⟩ := IsPurelyInseparable.surjective_algebraMap_of_isSeparable F L ⟨x, hx⟩ exact ⟨y, congr_arg (algebraMap L E) hy⟩ /-- If `E / F` is purely inseparable, then the separable closure of `F` in `E` is equal to `F`. -/ theorem separableClosure.eq_bot_of_isPurelyInseparable [IsPurelyInseparable F E] : separableClosure F E = ⊥ := bot_unique fun x h ↦ IsPurelyInseparable.inseparable F x (mem_separableClosure_iff.1 h) variable {F E} in /-- If `E / F` is an algebraic extension, then the separable closure of `F` in `E` is equal to `F` if and only if `E / F` is purely inseparable. -/ theorem separableClosure.eq_bot_iff [Algebra.IsAlgebraic F E] : separableClosure F E = ⊥ ↔ IsPurelyInseparable F E := ⟨fun h ↦ isPurelyInseparable_iff.2 fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, fun hs ↦ by simpa only [h] using mem_separableClosure_iff.2 hs⟩, fun _ ↦ eq_bot_of_isPurelyInseparable F E⟩ instance isPurelyInseparable_self : IsPurelyInseparable F F := ⟨inferInstance, fun x _ ↦ ⟨x, rfl⟩⟩ variable {E} /-- A field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, there exists a natural number `n` such that `x ^ (q ^ n)` is contained in `F`. -/ theorem isPurelyInseparable_iff_pow_mem (q : ℕ) [ExpChar F q] : IsPurelyInseparable F E ↔ ∀ x : E, ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by rw [isPurelyInseparable_iff] refine ⟨fun h x ↦ ?_, fun h x ↦ ?_⟩ · obtain ⟨g, h1, n, h2⟩ := (minpoly.irreducible (h x).1).hasSeparableContraction q exact ⟨n, (h _).2 <| h1.of_dvd <| minpoly.dvd F _ <| by simpa only [expand_aeval, minpoly.aeval] using congr_arg (aeval x) h2⟩ have hdeg := (minpoly.natSepDegree_eq_one_iff_pow_mem q).2 (h x) have halg : IsIntegral F x := by_contra fun h' ↦ by simp only [minpoly.eq_zero h', natSepDegree_zero, zero_ne_one] at hdeg refine ⟨halg, fun hsep ↦ ?_⟩ rw [hsep.natSepDegree_eq_natDegree, ← adjoin.finrank halg, IntermediateField.finrank_eq_one_iff] at hdeg simpa only [hdeg] using mem_adjoin_simple_self F x theorem IsPurelyInseparable.pow_mem (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E] (x : E) : ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := (isPurelyInseparable_iff_pow_mem F q).1 ‹_› x end IsPurelyInseparable section perfectClosure /-- The relative perfect closure of `F` in `E`, consists of the elements `x` of `E` such that there exists a natural number `n` such that `x ^ (ringExpChar F) ^ n` is contained in `F`, where `ringExpChar F` is the exponential characteristic of `F`. It is also the maximal purely inseparable subextension of `E / F` (`le_perfectClosure_iff`). -/ def perfectClosure : IntermediateField F E where carrier := {x : E | ∃ n : ℕ, x ^ (ringExpChar F) ^ n ∈ (algebraMap F E).range} add_mem' := by rintro x y ⟨n, hx⟩ ⟨m, hy⟩ use n + m have := expChar_of_injective_algebraMap (algebraMap F E).injective (ringExpChar F) rw [add_pow_expChar_pow, pow_add, pow_mul, mul_comm (_ ^ n), pow_mul] exact add_mem (pow_mem hx _) (pow_mem hy _) mul_mem' := by rintro x y ⟨n, hx⟩ ⟨m, hy⟩ use n + m rw [mul_pow, pow_add, pow_mul, mul_comm (_ ^ n), pow_mul] exact mul_mem (pow_mem hx _) (pow_mem hy _) inv_mem' := by rintro x ⟨n, hx⟩ use n; rw [inv_pow] apply inv_mem (id hx : _ ∈ (⊥ : IntermediateField F E)) algebraMap_mem' := fun x ↦ ⟨0, by rw [pow_zero, pow_one]; exact ⟨x, rfl⟩⟩ variable {F E} theorem mem_perfectClosure_iff {x : E} : x ∈ perfectClosure F E ↔ ∃ n : ℕ, x ^ (ringExpChar F) ^ n ∈ (algebraMap F E).range := Iff.rfl theorem mem_perfectClosure_iff_pow_mem (q : ℕ) [ExpChar F q] {x : E} : x ∈ perfectClosure F E ↔ ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by rw [mem_perfectClosure_iff, ringExpChar.eq F q] /-- An element is contained in the relative perfect closure if and only if its mininal polynomial has separable degree one. -/ theorem mem_perfectClosure_iff_natSepDegree_eq_one {x : E} : x ∈ perfectClosure F E ↔ (minpoly F x).natSepDegree = 1 := by rw [mem_perfectClosure_iff, minpoly.natSepDegree_eq_one_iff_pow_mem (ringExpChar F)] /-- A field extension `E / F` is purely inseparable if and only if the relative perfect closure of `F` in `E` is equal to `E`. -/ theorem isPurelyInseparable_iff_perfectClosure_eq_top : IsPurelyInseparable F E ↔ perfectClosure F E = ⊤ := by rw [isPurelyInseparable_iff_pow_mem F (ringExpChar F)] exact ⟨fun H ↦ top_unique fun x _ ↦ H x, fun H _ ↦ H.ge trivial⟩ variable (F E) /-- The relative perfect closure of `F` in `E` is purely inseparable over `F`. -/ instance perfectClosure.isPurelyInseparable : IsPurelyInseparable F (perfectClosure F E) := by rw [isPurelyInseparable_iff_pow_mem F (ringExpChar F)] exact fun ⟨_, n, y, h⟩ ↦ ⟨n, y, (algebraMap _ E).injective h⟩ /-- The relative perfect closure of `F` in `E` is algebraic over `F`. -/ instance perfectClosure.isAlgebraic : Algebra.IsAlgebraic F (perfectClosure F E) := IsPurelyInseparable.isAlgebraic F _ /-- If `E / F` is separable, then the perfect closure of `F` in `E` is equal to `F`. Note that the converse is not necessarily true (see https://math.stackexchange.com/a/3009197) even when `E / F` is algebraic. -/ theorem perfectClosure.eq_bot_of_isSeparable [IsSeparable F E] : perfectClosure F E = ⊥ := haveI := isSeparable_tower_bot_of_isSeparable F (perfectClosure F E) E eq_bot_of_isPurelyInseparable_of_isSeparable _ /-- An intermediate field of `E / F` is contained in the relative perfect closure of `F` in `E` if it is purely inseparable over `F`. -/ theorem le_perfectClosure (L : IntermediateField F E) [h : IsPurelyInseparable F L] : L ≤ perfectClosure F E := by rw [isPurelyInseparable_iff_pow_mem F (ringExpChar F)] at h intro x hx obtain ⟨n, y, hy⟩ := h ⟨x, hx⟩ exact ⟨n, y, congr_arg (algebraMap L E) hy⟩ /-- An intermediate field of `E / F` is contained in the relative perfect closure of `F` in `E` if and only if it is purely inseparable over `F`. -/ theorem le_perfectClosure_iff (L : IntermediateField F E) : L ≤ perfectClosure F E ↔ IsPurelyInseparable F L := by refine ⟨fun h ↦ (isPurelyInseparable_iff_pow_mem F (ringExpChar F)).2 fun x ↦ ?_, fun _ ↦ le_perfectClosure F E L⟩ obtain ⟨n, y, hy⟩ := h x.2 exact ⟨n, y, (algebraMap L E).injective hy⟩ theorem separableClosure_inf_perfectClosure : separableClosure F E ⊓ perfectClosure F E = ⊥ := haveI := (le_separableClosure_iff F E _).mp (inf_le_left (b := perfectClosure F E)) haveI := (le_perfectClosure_iff F E _).mp (inf_le_right (a := separableClosure F E)) eq_bot_of_isPurelyInseparable_of_isSeparable _ section map variable {F E K} /-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then `i x` is contained in `perfectClosure F K` if and only if `x` is contained in `perfectClosure F E`. -/ theorem map_mem_perfectClosure_iff (i : E →ₐ[F] K) {x : E} : i x ∈ perfectClosure F K ↔ x ∈ perfectClosure F E := by simp_rw [mem_perfectClosure_iff] refine ⟨fun ⟨n, y, h⟩ ↦ ⟨n, y, ?_⟩, fun ⟨n, y, h⟩ ↦ ⟨n, y, ?_⟩⟩ · apply_fun i using i.injective rwa [AlgHom.commutes, map_pow] simpa only [AlgHom.commutes, map_pow] using congr_arg i h /-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the preimage of `perfectClosure F K` under the map `i` is equal to `perfectClosure F E`. -/ theorem perfectClosure.comap_eq_of_algHom (i : E →ₐ[F] K) : (perfectClosure F K).comap i = perfectClosure F E := by ext x exact map_mem_perfectClosure_iff i /-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the image of `perfectClosure F E` under the map `i` is contained in `perfectClosure F K`. -/ theorem perfectClosure.map_le_of_algHom (i : E →ₐ[F] K) : (perfectClosure F E).map i ≤ perfectClosure F K := map_le_iff_le_comap.mpr (perfectClosure.comap_eq_of_algHom i).ge /-- If `i` is an `F`-algebra isomorphism of `E` and `K`, then the image of `perfectClosure F E` under the map `i` is equal to in `perfectClosure F K`. -/ theorem perfectClosure.map_eq_of_algEquiv (i : E ≃ₐ[F] K) : (perfectClosure F E).map i.toAlgHom = perfectClosure F K := (map_le_of_algHom i.toAlgHom).antisymm (fun x hx ↦ ⟨i.symm x, (map_mem_perfectClosure_iff i.symm.toAlgHom).2 hx, i.right_inv x⟩) /-- If `E` and `K` are isomorphic as `F`-algebras, then `perfectClosure F E` and `perfectClosure F K` are also isomorphic as `F`-algebras. -/ def perfectClosure.algEquivOfAlgEquiv (i : E ≃ₐ[F] K) : perfectClosure F E ≃ₐ[F] perfectClosure F K := (intermediateFieldMap i _).trans (equivOfEq (map_eq_of_algEquiv i)) alias AlgEquiv.perfectClosure := perfectClosure.algEquivOfAlgEquiv end map /-- If `E` is a perfect field of exponential characteristic `p`, then the (relative) perfect closure `perfectClosure F E` is perfect. -/ instance perfectClosure.perfectRing (p : ℕ) [ExpChar E p] [PerfectRing E p] : PerfectRing (perfectClosure F E) p := .ofSurjective _ p fun x ↦ by haveI := RingHom.expChar _ (algebraMap F E).injective p obtain ⟨x', hx⟩ := surjective_frobenius E p x.1 obtain ⟨n, y, hy⟩ := (mem_perfectClosure_iff_pow_mem p).1 x.2 rw [frobenius_def] at hx rw [← hx, ← pow_mul, ← pow_succ'] at hy exact ⟨⟨x', (mem_perfectClosure_iff_pow_mem p).2 ⟨n + 1, y, hy⟩⟩, by simp_rw [frobenius_def, SubmonoidClass.mk_pow, hx]⟩ /-- If `E` is a perfect field, then the (relative) perfect closure `perfectClosure F E` is perfect. -/ instance perfectClosure.perfectField [PerfectField E] : PerfectField (perfectClosure F E) := PerfectRing.toPerfectField _ (ringExpChar E) end perfectClosure section IsPurelyInseparable /-- If `K / E / F` is a field extension tower such that `K / F` is purely inseparable, then `E / F` is also purely inseparable. -/ theorem IsPurelyInseparable.tower_bot [Algebra E K] [IsScalarTower F E K] [IsPurelyInseparable F K] : IsPurelyInseparable F E := by refine ⟨⟨fun x ↦ (isIntegral' F (algebraMap E K x)).tower_bot_of_field⟩, fun x h ↦ ?_⟩ rw [← minpoly.algebraMap_eq (algebraMap E K).injective] at h obtain ⟨y, h⟩ := inseparable F _ h exact ⟨y, (algebraMap E K).injective (h.symm ▸ (IsScalarTower.algebraMap_apply F E K y).symm)⟩ /-- If `K / E / F` is a field extension tower such that `K / F` is purely inseparable, then `K / E` is also purely inseparable. -/ theorem IsPurelyInseparable.tower_top [Algebra E K] [IsScalarTower F E K] [h : IsPurelyInseparable F K] : IsPurelyInseparable E K := by obtain ⟨q, _⟩ := ExpChar.exists F haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q rw [isPurelyInseparable_iff_pow_mem _ q] at h ⊢ intro x obtain ⟨n, y, h⟩ := h x exact ⟨n, (algebraMap F E) y, h.symm ▸ (IsScalarTower.algebraMap_apply F E K y).symm⟩ /-- If `E / F` and `K / E` are both purely inseparable extensions, then `K / F` is also purely inseparable. -/ theorem IsPurelyInseparable.trans [Algebra E K] [IsScalarTower F E K] [h1 : IsPurelyInseparable F E] [h2 : IsPurelyInseparable E K] : IsPurelyInseparable F K := by obtain ⟨q, _⟩ := ExpChar.exists F haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q rw [isPurelyInseparable_iff_pow_mem _ q] at h1 h2 ⊢ intro x obtain ⟨n, y, h2⟩ := h2 x obtain ⟨m, z, h1⟩ := h1 y refine ⟨n + m, z, ?_⟩ rw [IsScalarTower.algebraMap_apply F E K, h1, map_pow, h2, ← pow_mul, ← pow_add] variable {E} /-- A field extension `E / F` is purely inseparable if and only if for every element `x` of `E`, its minimal polynomial has separable degree one. -/ theorem isPurelyInseparable_iff_natSepDegree_eq_one : IsPurelyInseparable F E ↔ ∀ x : E, (minpoly F x).natSepDegree = 1 := by obtain ⟨q, _⟩ := ExpChar.exists F simp_rw [isPurelyInseparable_iff_pow_mem F q, minpoly.natSepDegree_eq_one_iff_pow_mem q] theorem IsPurelyInseparable.natSepDegree_eq_one [IsPurelyInseparable F E] (x : E) : (minpoly F x).natSepDegree = 1 := (isPurelyInseparable_iff_natSepDegree_eq_one F).1 ‹_› x /-- A field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `X ^ (q ^ n) - y` for some natural number `n` and some element `y` of `F`. -/ theorem isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C (q : ℕ) [hF : ExpChar F q] : IsPurelyInseparable F E ↔ ∀ x : E, ∃ (n : ℕ) (y : F), minpoly F x = X ^ q ^ n - C y := by simp_rw [isPurelyInseparable_iff_natSepDegree_eq_one, minpoly.natSepDegree_eq_one_iff_eq_X_pow_sub_C q] theorem IsPurelyInseparable.minpoly_eq_X_pow_sub_C (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E] (x : E) : ∃ (n : ℕ) (y : F), minpoly F x = X ^ q ^ n - C y := (isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C F q).1 ‹_› x /-- A field extension `E / F` of exponential characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form `(X - x) ^ (q ^ n)` for some natural number `n`. -/ theorem isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow (q : ℕ) [hF : ExpChar F q] : IsPurelyInseparable F E ↔ ∀ x : E, ∃ n : ℕ, (minpoly F x).map (algebraMap F E) = (X - C x) ^ q ^ n := by simp_rw [isPurelyInseparable_iff_natSepDegree_eq_one, minpoly.natSepDegree_eq_one_iff_eq_X_sub_C_pow q] theorem IsPurelyInseparable.minpoly_eq_X_sub_C_pow (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E] (x : E) : ∃ n : ℕ, (minpoly F x).map (algebraMap F E) = (X - C x) ^ q ^ n := (isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow F q).1 ‹_› x variable (E) -- TODO: remove `halg` assumption variable {F E} in /-- If an algebraic extension has finite separable degree one, then it is purely inseparable. -/ theorem isPurelyInseparable_of_finSepDegree_eq_one [Algebra.IsAlgebraic F E] (hdeg : finSepDegree F E = 1) : IsPurelyInseparable F E := by rw [isPurelyInseparable_iff] refine fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, fun hsep ↦ ?_⟩ have : Algebra.IsAlgebraic F⟮x⟯ E := Algebra.IsAlgebraic.tower_top (K := F) F⟮x⟯ have := finSepDegree_mul_finSepDegree_of_isAlgebraic F F⟮x⟯ E rw [hdeg, mul_eq_one, (finSepDegree_adjoin_simple_eq_finrank_iff F E x (Algebra.IsAlgebraic.isAlgebraic x)).2 hsep, IntermediateField.finrank_eq_one_iff] at this simpa only [this.1] using mem_adjoin_simple_self F x /-- If `E / F` is purely inseparable, then for any reduced ring `L`, the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective. In particular, a purely inseparable field extension is an epimorphism in the category of fields. -/ theorem IsPurelyInseparable.injective_comp_algebraMap [IsPurelyInseparable F E] (L : Type w) [CommRing L] [IsReduced L] : Function.Injective fun f : E →+* L ↦ f.comp (algebraMap F E) := fun f g heq ↦ by ext x let q := ringExpChar F obtain ⟨n, y, h⟩ := IsPurelyInseparable.pow_mem F q x replace heq := congr($heq y) simp_rw [RingHom.comp_apply, h, map_pow] at heq nontriviality L haveI := expChar_of_injective_ringHom (f.comp (algebraMap F E)).injective q exact iterateFrobenius_inj L q n heq /-- If `E / F` is purely inseparable, then for any reduced `F`-algebra `L`, there exists at most one `F`-algebra homomorphism from `E` to `L`. -/ instance instSubsingletonAlgHomOfIsPurelyInseparable [IsPurelyInseparable F E] (L : Type w) [CommRing L] [IsReduced L] [Algebra F L] : Subsingleton (E →ₐ[F] L) where allEq f g := AlgHom.coe_ringHom_injective <| IsPurelyInseparable.injective_comp_algebraMap F E L (by simp_rw [AlgHom.comp_algebraMap]) instance instUniqueAlgHomOfIsPurelyInseparable [IsPurelyInseparable F E] (L : Type w) [CommRing L] [IsReduced L] [Algebra F L] [Algebra E L] [IsScalarTower F E L] : Unique (E →ₐ[F] L) := uniqueOfSubsingleton (IsScalarTower.toAlgHom F E L) /-- If `E / F` is purely inseparable, then `Field.Emb F E` has exactly one element. -/ instance instUniqueEmbOfIsPurelyInseparable [IsPurelyInseparable F E] : Unique (Emb F E) := instUniqueAlgHomOfIsPurelyInseparable F E _ /-- A purely inseparable extension has finite separable degree one. -/ theorem IsPurelyInseparable.finSepDegree_eq_one [IsPurelyInseparable F E] : finSepDegree F E = 1 := Nat.card_unique /-- A purely inseparable extension has separable degree one. -/ theorem IsPurelyInseparable.sepDegree_eq_one [IsPurelyInseparable F E] : sepDegree F E = 1 := by rw [sepDegree, separableClosure.eq_bot_of_isPurelyInseparable, IntermediateField.rank_bot] /-- A purely inseparable extension has inseparable degree equal to degree. -/ theorem IsPurelyInseparable.insepDegree_eq [IsPurelyInseparable F E] : insepDegree F E = Module.rank F E := by rw [insepDegree, separableClosure.eq_bot_of_isPurelyInseparable, rank_bot'] /-- A purely inseparable extension has finite inseparable degree equal to degree. -/ theorem IsPurelyInseparable.finInsepDegree_eq [IsPurelyInseparable F E] : finInsepDegree F E = finrank F E := congr(Cardinal.toNat $(insepDegree_eq F E)) -- TODO: remove `halg` assumption /-- An algebraic extension is purely inseparable if and only if it has finite separable degree one. -/ theorem isPurelyInseparable_iff_finSepDegree_eq_one [Algebra.IsAlgebraic F E] : IsPurelyInseparable F E ↔ finSepDegree F E = 1 := ⟨fun _ ↦ IsPurelyInseparable.finSepDegree_eq_one F E, fun h ↦ isPurelyInseparable_of_finSepDegree_eq_one h⟩ variable {F E} in /-- An algebraic extension is purely inseparable if and only if all of its finite dimensional subextensions are purely inseparable. -/ theorem isPurelyInseparable_iff_fd_isPurelyInseparable [Algebra.IsAlgebraic F E] : IsPurelyInseparable F E ↔ ∀ L : IntermediateField F E, FiniteDimensional F L → IsPurelyInseparable F L := by refine ⟨fun _ _ _ ↦ IsPurelyInseparable.tower_bot F _ E, fun h ↦ isPurelyInseparable_iff.2 fun x ↦ ?_⟩ have hx : IsIntegral F x := Algebra.IsIntegral.isIntegral x refine ⟨hx, fun _ ↦ ?_⟩ obtain ⟨y, h⟩ := (h _ (adjoin.finiteDimensional hx)).inseparable' _ <| show Separable (minpoly F (AdjoinSimple.gen F x)) by rwa [minpoly_eq] exact ⟨y, congr_arg (algebraMap _ E) h⟩ /-- A purely inseparable extension is normal. -/ instance IsPurelyInseparable.normal [IsPurelyInseparable F E] : Normal F E where toIsAlgebraic := isAlgebraic F E splits' x := by obtain ⟨n, h⟩ := IsPurelyInseparable.minpoly_eq_X_sub_C_pow F (ringExpChar F) x rw [← splits_id_iff_splits, h] exact splits_pow _ (splits_X_sub_C _) _ /-- If `E / F` is algebraic, then `E` is purely inseparable over the separable closure of `F` in `E`. -/ theorem separableClosure.isPurelyInseparable [Algebra.IsAlgebraic F E] : IsPurelyInseparable (separableClosure F E) E := isPurelyInseparable_iff.2 fun x ↦ by set L := separableClosure F E refine ⟨(IsAlgebraic.tower_top L (Algebra.IsAlgebraic.isAlgebraic (R := F) x)).isIntegral, fun h ↦ ?_⟩ haveI := (isSeparable_adjoin_simple_iff_separable L E).2 h haveI : IsSeparable F (restrictScalars F L⟮x⟯) := IsSeparable.trans F L L⟮x⟯ have hx : x ∈ restrictScalars F L⟮x⟯ := mem_adjoin_simple_self _ x exact ⟨⟨x, mem_separableClosure_iff.2 <| separable_of_mem_isSeparable F E hx⟩, rfl⟩ /-- An intermediate field of `E / F` contains the separable closure of `F` in `E` if `E` is purely inseparable over it. -/ theorem separableClosure_le (L : IntermediateField F E) [h : IsPurelyInseparable L E] : separableClosure F E ≤ L := fun x hx ↦ by obtain ⟨y, rfl⟩ := h.inseparable' _ <| (mem_separableClosure_iff.1 hx).map_minpoly L exact y.2 /-- If `E / F` is algebraic, then an intermediate field of `E / F` contains the separable closure of `F` in `E` if and only if `E` is purely inseparable over it. -/ theorem separableClosure_le_iff [Algebra.IsAlgebraic F E] (L : IntermediateField F E) : separableClosure F E ≤ L ↔ IsPurelyInseparable L E := by refine ⟨fun h ↦ ?_, fun _ ↦ separableClosure_le F E L⟩ have := separableClosure.isPurelyInseparable F E letI := (inclusion h).toAlgebra letI : SMul (separableClosure F E) L := Algebra.toSMul haveI : IsScalarTower (separableClosure F E) L E := IsScalarTower.of_algebraMap_eq (congrFun rfl) exact IsPurelyInseparable.tower_top (separableClosure F E) L E /-- If an intermediate field of `E / F` is separable over `F`, and `E` is purely inseparable over it, then it is equal to the separable closure of `F` in `E`. -/ theorem eq_separableClosure (L : IntermediateField F E) [IsSeparable F L] [IsPurelyInseparable L E] : L = separableClosure F E := le_antisymm (le_separableClosure F E L) (separableClosure_le F E L) open separableClosure in /-- If `E / F` is algebraic, then an intermediate field of `E / F` is equal to the separable closure of `F` in `E` if and only if it is separable over `F`, and `E` is purely inseparable over it. -/ theorem eq_separableClosure_iff [Algebra.IsAlgebraic F E] (L : IntermediateField F E) : L = separableClosure F E ↔ IsSeparable F L ∧ IsPurelyInseparable L E := ⟨by rintro rfl; exact ⟨isSeparable F E, isPurelyInseparable F E⟩, fun ⟨_, _⟩ ↦ eq_separableClosure F E L⟩ -- TODO: prove it set_option linter.unusedVariables false in /-- If `L` is an algebraically closed field containing `E`, such that the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective, then `E / F` is purely inseparable. As a corollary, epimorphisms in the category of fields must be purely inseparable extensions. -/ proof_wanted IsPurelyInseparable.of_injective_comp_algebraMap (L : Type w) [Field L] [IsAlgClosed L] (hn : Nonempty (E →+* L)) (h : Function.Injective fun f : E →+* L ↦ f.comp (algebraMap F E)) : IsPurelyInseparable F E end IsPurelyInseparable namespace IntermediateField instance isPurelyInseparable_bot : IsPurelyInseparable F (⊥ : IntermediateField F E) := (botEquiv F E).symm.isPurelyInseparable /-- `F⟮x⟯ / F` is a purely inseparable extension if and only if the mininal polynomial of `x` has separable degree one. -/ theorem isPurelyInseparable_adjoin_simple_iff_natSepDegree_eq_one {x : E} : IsPurelyInseparable F F⟮x⟯ ↔ (minpoly F x).natSepDegree = 1 := by rw [← le_perfectClosure_iff, adjoin_simple_le_iff, mem_perfectClosure_iff_natSepDegree_eq_one] /-- If `F` is of exponential characteristic `q`, then `F⟮x⟯ / F` is a purely inseparable extension if and only if `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`. -/ theorem isPurelyInseparable_adjoin_simple_iff_pow_mem (q : ℕ) [hF : ExpChar F q] {x : E} : IsPurelyInseparable F F⟮x⟯ ↔ ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by rw [← le_perfectClosure_iff, adjoin_simple_le_iff, mem_perfectClosure_iff_pow_mem q] /-- If `F` is of exponential characteristic `q`, then `F(S) / F` is a purely inseparable extension if and only if for any `x ∈ S`, `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`. -/ theorem isPurelyInseparable_adjoin_iff_pow_mem (q : ℕ) [hF : ExpChar F q] {S : Set E} : IsPurelyInseparable F (adjoin F S) ↔ ∀ x ∈ S, ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by simp_rw [← le_perfectClosure_iff, adjoin_le_iff, ← mem_perfectClosure_iff_pow_mem q, Set.le_iff_subset, Set.subset_def, SetLike.mem_coe] /-- A compositum of two purely inseparable extensions is purely inseparable. -/ instance isPurelyInseparable_sup (L1 L2 : IntermediateField F E) [h1 : IsPurelyInseparable F L1] [h2 : IsPurelyInseparable F L2] : IsPurelyInseparable F (L1 ⊔ L2 : IntermediateField F E) := by rw [← le_perfectClosure_iff] at h1 h2 ⊢ exact sup_le h1 h2 /-- A compositum of purely inseparable extensions is purely inseparable. -/ instance isPurelyInseparable_iSup {ι : Sort*} {t : ι → IntermediateField F E} [h : ∀ i, IsPurelyInseparable F (t i)] : IsPurelyInseparable F (⨆ i, t i : IntermediateField F E) := by simp_rw [← le_perfectClosure_iff] at h ⊢ exact iSup_le h /-- If `F` is a field of exponential characteristic `q`, `F(S) / F` is separable, then `F(S) = F(S ^ (q ^ n))` for any natural number `n`. -/ theorem adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable (S : Set E) [IsSeparable F (adjoin F S)] (q : ℕ) [ExpChar F q] (n : ℕ) : adjoin F S = adjoin F ((· ^ q ^ n) '' S) := by set L := adjoin F S set M := adjoin F ((· ^ q ^ n) '' S) have hi : M ≤ L := by rw [adjoin_le_iff] rintro _ ⟨y, hy, rfl⟩ exact pow_mem (subset_adjoin F S hy) _ letI := (inclusion hi).toAlgebra haveI : IsSeparable M (extendScalars hi) := isSeparable_tower_top_of_isSeparable F M L haveI : IsPurelyInseparable M (extendScalars hi) := by haveI := expChar_of_injective_algebraMap (algebraMap F M).injective q rw [extendScalars_adjoin hi, isPurelyInseparable_adjoin_iff_pow_mem M _ q] exact fun x hx ↦ ⟨n, ⟨x ^ q ^ n, subset_adjoin F _ ⟨x, hx, rfl⟩⟩, rfl⟩ simpa only [extendScalars_restrictScalars, restrictScalars_bot_eq_self] using congr_arg (restrictScalars F) (extendScalars hi).eq_bot_of_isPurelyInseparable_of_isSeparable /-- If `E / F` is a separable field extension of exponential characteristic `q`, then `F(S) = F(S ^ (q ^ n))` for any subset `S` of `E` and any natural number `n`. -/ theorem adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable' [IsSeparable F E] (S : Set E) (q : ℕ) [ExpChar F q] (n : ℕ) : adjoin F S = adjoin F ((· ^ q ^ n) '' S) := haveI := isSeparable_tower_bot_of_isSeparable F (adjoin F S) E adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable F E S q n -- TODO: prove the converse when `F(S) / F` is finite /-- If `F` is a field of exponential characteristic `q`, `F(S) / F` is separable, then `F(S) = F(S ^ q)`. -/ theorem adjoin_eq_adjoin_pow_expChar_of_isSeparable (S : Set E) [IsSeparable F (adjoin F S)] (q : ℕ) [ExpChar F q] : adjoin F S = adjoin F ((· ^ q) '' S) := pow_one q ▸ adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable F E S q 1 /-- If `E / F` is a separable field extension of exponential characteristic `q`, then `F(S) = F(S ^ q)` for any subset `S` of `E`. -/ theorem adjoin_eq_adjoin_pow_expChar_of_isSeparable' [IsSeparable F E] (S : Set E) (q : ℕ) [ExpChar F q] : adjoin F S = adjoin F ((· ^ q) '' S) := pow_one q ▸ adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable' F E S q 1 end IntermediateField section variable (q n : ℕ) [hF : ExpChar F q] {ι : Type*} {v : ι → E} {F E} /-- If `E / F` is a separable extension of exponential characteristic `q`, if `{ u_i }` is a family of elements of `E` which `F`-linearly spans `E`, then `{ u_i ^ (q ^ n) }` also `F`-linearly spans `E` for any natural number `n`. -/ theorem Field.span_map_pow_expChar_pow_eq_top_of_isSeparable [IsSeparable F E] (h : Submodule.span F (Set.range v) = ⊤) : Submodule.span F (Set.range (v · ^ q ^ n)) = ⊤ := by erw [← Algebra.top_toSubmodule, ← top_toSubalgebra, ← adjoin_univ, adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable' F E _ q n, adjoin_algebraic_toSubalgebra fun x _ ↦ Algebra.IsAlgebraic.isAlgebraic x, Set.image_univ, Algebra.adjoin_eq_span, (powMonoidHom _).mrange.closure_eq] refine (Submodule.span_mono <| Set.range_comp_subset_range _ _).antisymm (Submodule.span_le.2 ?_) rw [Set.range_comp, ← Set.image_univ] haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q apply h ▸ Submodule.image_span_subset_span (LinearMap.iterateFrobenius F E q n) _ /-- If `E / F` is a finite separable extension of exponential characteristic `q`, if `{ u_i }` is a family of elements of `E` which is `F`-linearly independent, then `{ u_i ^ (q ^ n) }` is also `F`-linearly independent for any natural number `n`. A special case of `LinearIndependent.map_pow_expChar_pow_of_isSeparable` and is an intermediate result used to prove it. -/ private theorem LinearIndependent.map_pow_expChar_pow_of_fd_isSeparable [FiniteDimensional F E] [IsSeparable F E] (h : LinearIndependent F v) : LinearIndependent F (v · ^ q ^ n) := by have h' := h.coe_range let ι' := h'.extend (Set.range v).subset_univ let b : Basis ι' F E := Basis.extend h' letI : Fintype ι' := fintypeBasisIndex b have H := linearIndependent_of_top_le_span_of_card_eq_finrank (span_map_pow_expChar_pow_eq_top_of_isSeparable q n b.span_eq).ge (finrank_eq_card_basis b).symm let f (i : ι) : ι' := ⟨v i, h'.subset_extend _ ⟨i, rfl⟩⟩ convert H.comp f fun _ _ heq ↦ h.injective (by simpa only [f, Subtype.mk.injEq] using heq) simp_rw [Function.comp_apply, b, Basis.extend_apply_self] /-- If `E / F` is a separable extension of exponential characteristic `q`, if `{ u_i }` is a family of elements of `E` which is `F`-linearly independent, then `{ u_i ^ (q ^ n) }` is also `F`-linearly independent for any natural number `n`. -/ theorem LinearIndependent.map_pow_expChar_pow_of_isSeparable [IsSeparable F E] (h : LinearIndependent F v) : LinearIndependent F (v · ^ q ^ n) := by classical have halg := IsSeparable.isAlgebraic F E rw [linearIndependent_iff_finset_linearIndependent] at h ⊢ intro s let E' := adjoin F (s.image v : Set E) haveI : FiniteDimensional F E' := finiteDimensional_adjoin fun x _ ↦ Algebra.IsIntegral.isIntegral x haveI : IsSeparable F E' := isSeparable_tower_bot_of_isSeparable F E' E let v' (i : s) : E' := ⟨v i.1, subset_adjoin F _ (Finset.mem_image.2 ⟨i.1, i.2, rfl⟩)⟩ have h' : LinearIndependent F v' := (h s).of_comp E'.val.toLinearMap exact (h'.map_pow_expChar_pow_of_fd_isSeparable q n).map' E'.val.toLinearMap (LinearMap.ker_eq_bot_of_injective E'.val.injective) /-- If `E / F` is a field extension of exponential characteristic `q`, if `{ u_i }` is a family of separable elements of `E` which is `F`-linearly independent, then `{ u_i ^ (q ^ n) }` is also `F`-linearly independent for any natural number `n`. -/ theorem LinearIndependent.map_pow_expChar_pow_of_separable (hsep : ∀ i : ι, (minpoly F (v i)).Separable) (h : LinearIndependent F v) : LinearIndependent F (v · ^ q ^ n) := by let E' := adjoin F (Set.range v) haveI : IsSeparable F E' := (isSeparable_adjoin_iff_separable F _).2 <| by rintro _ ⟨y, rfl⟩; exact hsep y let v' (i : ι) : E' := ⟨v i, subset_adjoin F _ ⟨i, rfl⟩⟩ have h' : LinearIndependent F v' := h.of_comp E'.val.toLinearMap exact (h'.map_pow_expChar_pow_of_isSeparable q n).map' E'.val.toLinearMap (LinearMap.ker_eq_bot_of_injective E'.val.injective) /-- If `E / F` is a separable extension of exponential characteristic `q`, if `{ u_i }` is an `F`-basis of `E`, then `{ u_i ^ (q ^ n) }` is also an `F`-basis of `E` for any natural number `n`. -/ def Basis.mapPowExpCharPowOfIsSeparable [IsSeparable F E] (b : Basis ι F E) : Basis ι F E := Basis.mk (b.linearIndependent.map_pow_expChar_pow_of_isSeparable q n) (span_map_pow_expChar_pow_eq_top_of_isSeparable q n b.span_eq).ge end /-- If `E` is an algebraic closure of `F`, then `F` is separably closed if and only if `E / F` is purely inseparable. -/ theorem isSepClosed_iff_isPurelyInseparable_algebraicClosure [IsAlgClosure F E] : IsSepClosed F ↔ IsPurelyInseparable F E := ⟨fun _ ↦ IsAlgClosure.algebraic.isPurelyInseparable_of_isSepClosed, fun H ↦ by haveI := IsAlgClosure.alg_closed F (K := E) rwa [← separableClosure.eq_bot_iff, IsSepClosed.separableClosure_eq_bot_iff] at H⟩ variable {F E} in /-- If `E / F` is an algebraic extension, `F` is separably closed, then `E` is also separably closed. -/ theorem Algebra.IsAlgebraic.isSepClosed [Algebra.IsAlgebraic F E] [IsSepClosed F] : IsSepClosed E := have : Algebra.IsAlgebraic F (AlgebraicClosure E) := Algebra.IsAlgebraic.trans (L := E) have : IsPurelyInseparable F (AlgebraicClosure E) := isPurelyInseparable_of_isSepClosed (isSepClosed_iff_isPurelyInseparable_algebraicClosure E _).mpr (IsPurelyInseparable.tower_top F E <| AlgebraicClosure E)
Mathlib/FieldTheory/PurelyInseparable.lean
803
812
theorem perfectField_of_perfectClosure_eq_bot [h : PerfectField E] (eq : perfectClosure F E = ⊥) : PerfectField F := by
let p := ringExpChar F haveI := expChar_of_injective_algebraMap (algebraMap F E).injective p haveI := PerfectRing.ofSurjective F p fun x ↦ by obtain ⟨y, h⟩ := surjective_frobenius E p (algebraMap F E x) have : y ∈ perfectClosure F E := ⟨1, x, by rw [← h, pow_one, frobenius_def, ringExpChar.eq F p]⟩ obtain ⟨z, rfl⟩ := eq ▸ this exact ⟨z, (algebraMap F E).injective (by erw [RingHom.map_frobenius, h])⟩ exact PerfectRing.toPerfectField F p
/- 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] theorem toReal_pi : (π : Angle).toReal = π := by rw [toReal_coe_eq_self_iff] exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩ #align real.angle.to_real_pi Real.Angle.toReal_pi @[simp] theorem toReal_eq_pi_iff {θ : Angle} : θ.toReal = π ↔ θ = π := by rw [← toReal_inj, toReal_pi] #align real.angle.to_real_eq_pi_iff Real.Angle.toReal_eq_pi_iff theorem pi_ne_zero : (π : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi, toReal_zero] exact Real.pi_ne_zero #align real.angle.pi_ne_zero Real.Angle.pi_ne_zero @[simp] theorem toReal_pi_div_two : ((π / 2 : ℝ) : Angle).toReal = π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] #align real.angle.to_real_pi_div_two Real.Angle.toReal_pi_div_two @[simp] theorem toReal_eq_pi_div_two_iff {θ : Angle} : θ.toReal = π / 2 ↔ θ = (π / 2 : ℝ) := by rw [← toReal_inj, toReal_pi_div_two] #align real.angle.to_real_eq_pi_div_two_iff Real.Angle.toReal_eq_pi_div_two_iff @[simp] theorem toReal_neg_pi_div_two : ((-π / 2 : ℝ) : Angle).toReal = -π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] #align real.angle.to_real_neg_pi_div_two Real.Angle.toReal_neg_pi_div_two @[simp] theorem toReal_eq_neg_pi_div_two_iff {θ : Angle} : θ.toReal = -π / 2 ↔ θ = (-π / 2 : ℝ) := by rw [← toReal_inj, toReal_neg_pi_div_two] #align real.angle.to_real_eq_neg_pi_div_two_iff Real.Angle.toReal_eq_neg_pi_div_two_iff theorem pi_div_two_ne_zero : ((π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi_div_two, toReal_zero] exact div_ne_zero Real.pi_ne_zero two_ne_zero #align real.angle.pi_div_two_ne_zero Real.Angle.pi_div_two_ne_zero theorem neg_pi_div_two_ne_zero : ((-π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_neg_pi_div_two, toReal_zero] exact div_ne_zero (neg_ne_zero.2 Real.pi_ne_zero) two_ne_zero #align real.angle.neg_pi_div_two_ne_zero Real.Angle.neg_pi_div_two_ne_zero theorem abs_toReal_coe_eq_self_iff {θ : ℝ} : |(θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => (toReal_coe_eq_self_iff.2 ⟨(Left.neg_neg_iff.2 Real.pi_pos).trans_le h.1, h.2⟩).symm ▸ abs_eq_self.2 h.1⟩ #align real.angle.abs_to_real_coe_eq_self_iff Real.Angle.abs_toReal_coe_eq_self_iff theorem abs_toReal_neg_coe_eq_self_iff {θ : ℝ} : |(-θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := by refine ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => ?_⟩ by_cases hnegpi : θ = π; · simp [hnegpi, Real.pi_pos.le] rw [← coe_neg, toReal_coe_eq_self_iff.2 ⟨neg_lt_neg (lt_of_le_of_ne h.2 hnegpi), (neg_nonpos.2 h.1).trans Real.pi_pos.le⟩, abs_neg, abs_eq_self.2 h.1] #align real.angle.abs_to_real_neg_coe_eq_self_iff Real.Angle.abs_toReal_neg_coe_eq_self_iff theorem abs_toReal_eq_pi_div_two_iff {θ : Angle} : |θ.toReal| = π / 2 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [abs_eq (div_nonneg Real.pi_pos.le two_pos.le), ← neg_div, toReal_eq_pi_div_two_iff, toReal_eq_neg_pi_div_two_iff] #align real.angle.abs_to_real_eq_pi_div_two_iff Real.Angle.abs_toReal_eq_pi_div_two_iff theorem nsmul_toReal_eq_mul {n : ℕ} (h : n ≠ 0) {θ : Angle} : (n • θ).toReal = n * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / n) (π / n) := by nth_rw 1 [← coe_toReal θ] have h' : 0 < (n : ℝ) := mod_cast Nat.pos_of_ne_zero h rw [← coe_nsmul, nsmul_eq_mul, toReal_coe_eq_self_iff, Set.mem_Ioc, div_lt_iff' h', le_div_iff' h'] #align real.angle.nsmul_to_real_eq_mul Real.Angle.nsmul_toReal_eq_mul theorem two_nsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := mod_cast nsmul_toReal_eq_mul two_ne_zero #align real.angle.two_nsmul_to_real_eq_two_mul Real.Angle.two_nsmul_toReal_eq_two_mul theorem two_zsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul] #align real.angle.two_zsmul_to_real_eq_two_mul Real.Angle.two_zsmul_toReal_eq_two_mul theorem toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff {θ : ℝ} {k : ℤ} : (θ : Angle).toReal = θ - 2 * k * π ↔ θ ∈ Set.Ioc ((2 * k - 1 : ℝ) * π) ((2 * k + 1) * π) := by rw [← sub_zero (θ : Angle), ← zsmul_zero k, ← coe_two_pi, ← coe_zsmul, ← coe_sub, zsmul_eq_mul, ← mul_assoc, mul_comm (k : ℝ), toReal_coe_eq_self_iff, Set.mem_Ioc] exact ⟨fun h => ⟨by linarith, by linarith⟩, fun h => ⟨by linarith, by linarith⟩⟩ #align real.angle.to_real_coe_eq_self_sub_two_mul_int_mul_pi_iff Real.Angle.toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff theorem toReal_coe_eq_self_sub_two_pi_iff {θ : ℝ} : (θ : Angle).toReal = θ - 2 * π ↔ θ ∈ Set.Ioc π (3 * π) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ 1 <;> norm_num #align real.angle.to_real_coe_eq_self_sub_two_pi_iff Real.Angle.toReal_coe_eq_self_sub_two_pi_iff theorem toReal_coe_eq_self_add_two_pi_iff {θ : ℝ} : (θ : Angle).toReal = θ + 2 * π ↔ θ ∈ Set.Ioc (-3 * π) (-π) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ (-1) using 2 <;> set_option tactic.skipAssignedInstances false in norm_num #align real.angle.to_real_coe_eq_self_add_two_pi_iff Real.Angle.toReal_coe_eq_self_add_two_pi_iff theorem two_nsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by nth_rw 1 [← coe_toReal θ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_sub_two_pi_iff, Set.mem_Ioc] exact ⟨fun h => by linarith, fun h => ⟨(div_lt_iff' (zero_lt_two' ℝ)).1 h, by linarith [pi_pos, toReal_le_pi θ]⟩⟩ #align real.angle.two_nsmul_to_real_eq_two_mul_sub_two_pi Real.Angle.two_nsmul_toReal_eq_two_mul_sub_two_pi theorem two_zsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_sub_two_pi] #align real.angle.two_zsmul_to_real_eq_two_mul_sub_two_pi Real.Angle.two_zsmul_toReal_eq_two_mul_sub_two_pi theorem two_nsmul_toReal_eq_two_mul_add_two_pi {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal + 2 * π ↔ θ.toReal ≤ -π / 2 := by nth_rw 1 [← coe_toReal θ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_add_two_pi_iff, Set.mem_Ioc] refine ⟨fun h => by linarith, fun h => ⟨by linarith [pi_pos, neg_pi_lt_toReal θ], (le_div_iff' (zero_lt_two' ℝ)).1 h⟩⟩ #align real.angle.two_nsmul_to_real_eq_two_mul_add_two_pi Real.Angle.two_nsmul_toReal_eq_two_mul_add_two_pi theorem two_zsmul_toReal_eq_two_mul_add_two_pi {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal + 2 * π ↔ θ.toReal ≤ -π / 2 := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_add_two_pi] #align real.angle.two_zsmul_to_real_eq_two_mul_add_two_pi Real.Angle.two_zsmul_toReal_eq_two_mul_add_two_pi @[simp] theorem sin_toReal (θ : Angle) : Real.sin θ.toReal = sin θ := by conv_rhs => rw [← coe_toReal θ, sin_coe] #align real.angle.sin_to_real Real.Angle.sin_toReal @[simp] theorem cos_toReal (θ : Angle) : Real.cos θ.toReal = cos θ := by conv_rhs => rw [← coe_toReal θ, cos_coe] #align real.angle.cos_to_real Real.Angle.cos_toReal theorem cos_nonneg_iff_abs_toReal_le_pi_div_two {θ : Angle} : 0 ≤ cos θ ↔ |θ.toReal| ≤ π / 2 := by nth_rw 1 [← coe_toReal θ] rw [abs_le, cos_coe] refine ⟨fun h => ?_, cos_nonneg_of_mem_Icc⟩ by_contra hn rw [not_and_or, not_le, not_le] at hn refine (not_lt.2 h) ?_ rcases hn with (hn | hn) · rw [← Real.cos_neg] refine cos_neg_of_pi_div_two_lt_of_lt (by linarith) ?_ linarith [neg_pi_lt_toReal θ] · refine cos_neg_of_pi_div_two_lt_of_lt hn ?_ linarith [toReal_le_pi θ] #align real.angle.cos_nonneg_iff_abs_to_real_le_pi_div_two Real.Angle.cos_nonneg_iff_abs_toReal_le_pi_div_two theorem cos_pos_iff_abs_toReal_lt_pi_div_two {θ : Angle} : 0 < cos θ ↔ |θ.toReal| < π / 2 := by rw [lt_iff_le_and_ne, lt_iff_le_and_ne, cos_nonneg_iff_abs_toReal_le_pi_div_two, ← and_congr_right] rintro - rw [Ne, Ne, not_iff_not, @eq_comm ℝ 0, abs_toReal_eq_pi_div_two_iff, cos_eq_zero_iff] #align real.angle.cos_pos_iff_abs_to_real_lt_pi_div_two Real.Angle.cos_pos_iff_abs_toReal_lt_pi_div_two theorem cos_neg_iff_pi_div_two_lt_abs_toReal {θ : Angle} : cos θ < 0 ↔ π / 2 < |θ.toReal| := by rw [← not_le, ← not_le, not_iff_not, cos_nonneg_iff_abs_toReal_le_pi_div_two] #align real.angle.cos_neg_iff_pi_div_two_lt_abs_to_real Real.Angle.cos_neg_iff_pi_div_two_lt_abs_toReal theorem abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi {θ ψ : Angle} (h : (2 : ℕ) • θ + (2 : ℕ) • ψ = π) : |cos θ| = |sin ψ| := by rw [← eq_sub_iff_add_eq, ← two_nsmul_coe_div_two, ← nsmul_sub, two_nsmul_eq_iff] at h rcases h with (rfl | rfl) <;> simp [cos_pi_div_two_sub] #align real.angle.abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi Real.Angle.abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi theorem abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi {θ ψ : Angle} (h : (2 : ℤ) • θ + (2 : ℤ) • ψ = π) : |cos θ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi h #align real.angle.abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi Real.Angle.abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi /-- The tangent of a `Real.Angle`. -/ def tan (θ : Angle) : ℝ := sin θ / cos θ #align real.angle.tan Real.Angle.tan theorem tan_eq_sin_div_cos (θ : Angle) : tan θ = sin θ / cos θ := rfl #align real.angle.tan_eq_sin_div_cos Real.Angle.tan_eq_sin_div_cos @[simp] theorem tan_coe (x : ℝ) : tan (x : Angle) = Real.tan x := by rw [tan, sin_coe, cos_coe, Real.tan_eq_sin_div_cos] #align real.angle.tan_coe Real.Angle.tan_coe @[simp] theorem tan_zero : tan (0 : Angle) = 0 := by rw [← coe_zero, tan_coe, Real.tan_zero] #align real.angle.tan_zero Real.Angle.tan_zero -- Porting note (#10618): @[simp] can now prove it theorem tan_coe_pi : tan (π : Angle) = 0 := by rw [tan_coe, Real.tan_pi] #align real.angle.tan_coe_pi Real.Angle.tan_coe_pi theorem tan_periodic : Function.Periodic tan (π : Angle) := by intro θ induction θ using Real.Angle.induction_on rw [← coe_add, tan_coe, tan_coe] exact Real.tan_periodic _ #align real.angle.tan_periodic Real.Angle.tan_periodic @[simp] theorem tan_add_pi (θ : Angle) : tan (θ + π) = tan θ := tan_periodic θ #align real.angle.tan_add_pi Real.Angle.tan_add_pi @[simp] theorem tan_sub_pi (θ : Angle) : tan (θ - π) = tan θ := tan_periodic.sub_eq θ #align real.angle.tan_sub_pi Real.Angle.tan_sub_pi @[simp] theorem tan_toReal (θ : Angle) : Real.tan θ.toReal = tan θ := by conv_rhs => rw [← coe_toReal θ, tan_coe] #align real.angle.tan_to_real Real.Angle.tan_toReal theorem tan_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : tan θ = tan ψ := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · exact tan_add_pi _ #align real.angle.tan_eq_of_two_nsmul_eq Real.Angle.tan_eq_of_two_nsmul_eq theorem tan_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : tan θ = tan ψ := by simp_rw [two_zsmul, ← two_nsmul] at h exact tan_eq_of_two_nsmul_eq h #align real.angle.tan_eq_of_two_zsmul_eq Real.Angle.tan_eq_of_two_zsmul_eq theorem tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi {θ ψ : Angle} (h : (2 : ℕ) • θ + (2 : ℕ) • ψ = π) : tan ψ = (tan θ)⁻¹ := by induction θ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on rw [← smul_add, ← coe_add, ← coe_nsmul, two_nsmul, ← two_mul, angle_eq_iff_two_pi_dvd_sub] at h rcases h with ⟨k, h⟩ rw [sub_eq_iff_eq_add, ← mul_inv_cancel_left₀ two_ne_zero π, mul_assoc, ← mul_add, mul_right_inj' (two_ne_zero' ℝ), ← eq_sub_iff_add_eq', mul_inv_cancel_left₀ two_ne_zero π, inv_mul_eq_div, mul_comm] at h rw [tan_coe, tan_coe, ← tan_pi_div_two_sub, h, add_sub_assoc, add_comm] exact Real.tan_periodic.int_mul _ _ #align real.angle.tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi Real.Angle.tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi theorem tan_eq_inv_of_two_zsmul_add_two_zsmul_eq_pi {θ ψ : Angle} (h : (2 : ℤ) • θ + (2 : ℤ) • ψ = π) : tan ψ = (tan θ)⁻¹ := by simp_rw [two_zsmul, ← two_nsmul] at h exact tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi h #align real.angle.tan_eq_inv_of_two_zsmul_add_two_zsmul_eq_pi Real.Angle.tan_eq_inv_of_two_zsmul_add_two_zsmul_eq_pi /-- The sign of a `Real.Angle` is `0` if the angle is `0` or `π`, `1` if the angle is strictly between `0` and `π` and `-1` is the angle is strictly between `-π` and `0`. It is defined as the sign of the sine of the angle. -/ def sign (θ : Angle) : SignType := SignType.sign (sin θ) #align real.angle.sign Real.Angle.sign @[simp] theorem sign_zero : (0 : Angle).sign = 0 := by rw [sign, sin_zero, _root_.sign_zero] #align real.angle.sign_zero Real.Angle.sign_zero @[simp] theorem sign_coe_pi : (π : Angle).sign = 0 := by rw [sign, sin_coe_pi, _root_.sign_zero] #align real.angle.sign_coe_pi Real.Angle.sign_coe_pi @[simp] theorem sign_neg (θ : Angle) : (-θ).sign = -θ.sign := by simp_rw [sign, sin_neg, Left.sign_neg] #align real.angle.sign_neg Real.Angle.sign_neg theorem sign_antiperiodic : Function.Antiperiodic sign (π : Angle) := fun θ => by rw [sign, sign, sin_add_pi, Left.sign_neg] #align real.angle.sign_antiperiodic Real.Angle.sign_antiperiodic @[simp] theorem sign_add_pi (θ : Angle) : (θ + π).sign = -θ.sign := sign_antiperiodic θ #align real.angle.sign_add_pi Real.Angle.sign_add_pi @[simp] theorem sign_pi_add (θ : Angle) : ((π : Angle) + θ).sign = -θ.sign := by rw [add_comm, sign_add_pi] #align real.angle.sign_pi_add Real.Angle.sign_pi_add @[simp] theorem sign_sub_pi (θ : Angle) : (θ - π).sign = -θ.sign := sign_antiperiodic.sub_eq θ #align real.angle.sign_sub_pi Real.Angle.sign_sub_pi @[simp] theorem sign_pi_sub (θ : Angle) : ((π : Angle) - θ).sign = θ.sign := by simp [sign_antiperiodic.sub_eq'] #align real.angle.sign_pi_sub Real.Angle.sign_pi_sub theorem sign_eq_zero_iff {θ : Angle} : θ.sign = 0 ↔ θ = 0 ∨ θ = π := by rw [sign, _root_.sign_eq_zero_iff, sin_eq_zero_iff] #align real.angle.sign_eq_zero_iff Real.Angle.sign_eq_zero_iff theorem sign_ne_zero_iff {θ : Angle} : θ.sign ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← sign_eq_zero_iff] #align real.angle.sign_ne_zero_iff Real.Angle.sign_ne_zero_iff
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
902
909
theorem toReal_neg_iff_sign_neg {θ : Angle} : θ.toReal < 0 ↔ θ.sign = -1 := by
rw [sign, ← sin_toReal, sign_eq_neg_one_iff] rcases lt_trichotomy θ.toReal 0 with (h | h | h) · exact ⟨fun _ => Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_toReal θ), fun _ => h⟩ · simp [h] · exact ⟨fun hn => False.elim (h.asymm hn), fun hn => False.elim (hn.not_le (sin_nonneg_of_nonneg_of_le_pi h.le (toReal_le_pi θ)))⟩
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.MeanInequalities import Mathlib.Analysis.MeanInequalitiesPow import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Data.Set.Image import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import analysis.normed_space.lp_space from "leanprover-community/mathlib"@"de83b43717abe353f425855fcf0cedf9ea0fe8a4" /-! # ℓp space This file describes properties of elements `f` of a pi-type `∀ i, E i` with finite "norm", defined for `p : ℝ≥0∞` as the size of the support of `f` if `p=0`, `(∑' a, ‖f a‖^p) ^ (1/p)` for `0 < p < ∞` and `⨆ a, ‖f a‖` for `p=∞`. The Prop-valued `Memℓp f p` states that a function `f : ∀ i, E i` has finite norm according to the above definition; that is, `f` has finite support if `p = 0`, `Summable (fun a ↦ ‖f a‖^p)` if `0 < p < ∞`, and `BddAbove (norm '' (Set.range f))` if `p = ∞`. The space `lp E p` is the subtype of elements of `∀ i : α, E i` which satisfy `Memℓp f p`. For `1 ≤ p`, the "norm" is genuinely a norm and `lp` is a complete metric space. ## Main definitions * `Memℓp f p` : property that the function `f` satisfies, as appropriate, `f` finitely supported if `p = 0`, `Summable (fun a ↦ ‖f a‖^p)` if `0 < p < ∞`, and `BddAbove (norm '' (Set.range f))` if `p = ∞`. * `lp E p` : elements of `∀ i : α, E i` such that `Memℓp f p`. Defined as an `AddSubgroup` of a type synonym `PreLp` for `∀ i : α, E i`, and equipped with a `NormedAddCommGroup` structure. Under appropriate conditions, this is also equipped with the instances `lp.normedSpace`, `lp.completeSpace`. For `p=∞`, there is also `lp.inftyNormedRing`, `lp.inftyNormedAlgebra`, `lp.inftyStarRing` and `lp.inftyCstarRing`. ## Main results * `Memℓp.of_exponent_ge`: For `q ≤ p`, a function which is `Memℓp` for `q` is also `Memℓp` for `p`. * `lp.memℓp_of_tendsto`, `lp.norm_le_of_tendsto`: A pointwise limit of functions in `lp`, all with `lp` norm `≤ C`, is itself in `lp` and has `lp` norm `≤ C`. * `lp.tsum_mul_le_mul_norm`: basic form of Hölder's inequality ## Implementation Since `lp` is defined as an `AddSubgroup`, dot notation does not work. Use `lp.norm_neg f` to say that `‖-f‖ = ‖f‖`, instead of the non-working `f.norm_neg`. ## TODO * More versions of Hölder's inequality (for example: the case `p = 1`, `q = ∞`; a version for normed rings which has `‖∑' i, f i * g i‖` rather than `∑' i, ‖f i‖ * g i‖` on the RHS; a version for three exponents satisfying `1 / r = 1 / p + 1 / q`) -/ noncomputable section open scoped NNReal ENNReal Function variable {α : Type*} {E : α → Type*} {p q : ℝ≥0∞} [∀ i, NormedAddCommGroup (E i)] /-! ### `Memℓp` predicate -/ /-- The property that `f : ∀ i : α, E i` * is finitely supported, if `p = 0`, or * admits an upper bound for `Set.range (fun i ↦ ‖f i‖)`, if `p = ∞`, or * has the series `∑' i, ‖f i‖ ^ p` be summable, if `0 < p < ∞`. -/ def Memℓp (f : ∀ i, E i) (p : ℝ≥0∞) : Prop := if p = 0 then Set.Finite { i | f i ≠ 0 } else if p = ∞ then BddAbove (Set.range fun i => ‖f i‖) else Summable fun i => ‖f i‖ ^ p.toReal #align mem_ℓp Memℓp theorem memℓp_zero_iff {f : ∀ i, E i} : Memℓp f 0 ↔ Set.Finite { i | f i ≠ 0 } := by dsimp [Memℓp] rw [if_pos rfl] #align mem_ℓp_zero_iff memℓp_zero_iff theorem memℓp_zero {f : ∀ i, E i} (hf : Set.Finite { i | f i ≠ 0 }) : Memℓp f 0 := memℓp_zero_iff.2 hf #align mem_ℓp_zero memℓp_zero theorem memℓp_infty_iff {f : ∀ i, E i} : Memℓp f ∞ ↔ BddAbove (Set.range fun i => ‖f i‖) := by dsimp [Memℓp] rw [if_neg ENNReal.top_ne_zero, if_pos rfl] #align mem_ℓp_infty_iff memℓp_infty_iff theorem memℓp_infty {f : ∀ i, E i} (hf : BddAbove (Set.range fun i => ‖f i‖)) : Memℓp f ∞ := memℓp_infty_iff.2 hf #align mem_ℓp_infty memℓp_infty theorem memℓp_gen_iff (hp : 0 < p.toReal) {f : ∀ i, E i} : Memℓp f p ↔ Summable fun i => ‖f i‖ ^ p.toReal := by rw [ENNReal.toReal_pos_iff] at hp dsimp [Memℓp] rw [if_neg hp.1.ne', if_neg hp.2.ne] #align mem_ℓp_gen_iff memℓp_gen_iff theorem memℓp_gen {f : ∀ i, E i} (hf : Summable fun i => ‖f i‖ ^ p.toReal) : Memℓp f p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero have H : Summable fun _ : α => (1 : ℝ) := by simpa using hf exact (Set.Finite.of_summable_const (by norm_num) H).subset (Set.subset_univ _) · apply memℓp_infty have H : Summable fun _ : α => (1 : ℝ) := by simpa using hf simpa using ((Set.Finite.of_summable_const (by norm_num) H).image fun i => ‖f i‖).bddAbove exact (memℓp_gen_iff hp).2 hf #align mem_ℓp_gen memℓp_gen theorem memℓp_gen' {C : ℝ} {f : ∀ i, E i} (hf : ∀ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ C) : Memℓp f p := by apply memℓp_gen use ⨆ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal apply hasSum_of_isLUB_of_nonneg · intro b exact Real.rpow_nonneg (norm_nonneg _) _ apply isLUB_ciSup use C rintro - ⟨s, rfl⟩ exact hf s #align mem_ℓp_gen' memℓp_gen'
Mathlib/Analysis/NormedSpace/lpSpace.lean
130
138
theorem zero_memℓp : Memℓp (0 : ∀ i, E i) p := by
rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero simp · apply memℓp_infty simp only [norm_zero, Pi.zero_apply] exact bddAbove_singleton.mono Set.range_const_subset · apply memℓp_gen simp [Real.zero_rpow hp.ne', summable_zero]
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.SetTheory.Cardinal.Finite #align_import data.set.ncard from "leanprover-community/mathlib"@"74c2af38a828107941029b03839882c5c6f87a04" /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `PartENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {α β : Type*} {s t : Set α} /-- The cardinality of a set as a term in `ℕ∞` -/ noncomputable def encard (s : Set α) : ℕ∞ := PartENat.withTopEquiv (PartENat.card s) @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by rw [encard, encard, PartENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (α : Type*) : encard (univ : Set α) = PartENat.withTopEquiv (PartENat.card α) := by rw [encard, PartENat.card_congr (Equiv.Set.univ α)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, PartENat.card_eq_coe_fintype_card, PartENat.withTopEquiv_natCast, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by have := h.to_subtype rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.withTopEquiv_symm_top, PartENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.withTopEquiv_symm_zero, PartENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]; rfl theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by classical have e := (Equiv.Set.union (by rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty])).symm simp [encard, ← PartENat.card_congr e, PartENat.card_sum, PartENat.withTopEquiv] theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by rw [← union_singleton, encard_union_eq (by simpa), encard_singleton] theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by refine h.induction_on (by simp) ?_ rintro a t hat _ ht' rw [encard_insert_of_not_mem hat] exact lt_tsub_iff_right.1 ht' theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard := (ENat.coe_toNat h.encard_lt_top.ne).symm theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n := ⟨_, h.encard_eq_coe⟩ @[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite := ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩ @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite] theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by simp theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _) theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite := finite_of_encard_le_coe h.le theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k := ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩, fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩ section Lattice theorem encard_le_card (h : s ⊆ t) : s.encard ≤ t.encard := by rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) := fun _ _ ↦ encard_le_card theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h] @[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero] theorem encard_diff_add_encard_inter (s t : Set α) : (s \ t).encard + (s ∩ t).encard = s.encard := by rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left), diff_union_inter] theorem encard_union_add_encard_inter (s t : Set α) : (s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm, encard_diff_add_encard_inter] theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) : s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_right_cancel_iff h.encard_lt_top.ne] theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) : s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_le_add_iff_right h.encard_lt_top.ne] theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) : s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_lt_add_iff_right h.encard_lt_top.ne] theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by rw [← encard_union_add_encard_inter]; exact le_self_add theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by rw [← encard_lt_top_iff, ← encard_lt_top_iff, h] theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) : s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff] theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite) (h : t.encard ≤ s.encard) : t.Finite := encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top) theorem Finite.eq_of_subset_of_encard_le (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := by rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff exact hst.antisymm hdiff theorem Finite.eq_of_subset_of_encard_le' (hs : s.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le hst hts theorem Finite.encard_lt_encard (ht : t.Finite) (h : s ⊂ t) : s.encard < t.encard := (encard_mono h.subset).lt_of_ne (fun he ↦ h.ne (ht.eq_of_subset_of_encard_le h.subset he.symm.le)) theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) := fun _ _ h ↦ (toFinite _).encard_lt_encard h theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self] theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard := (encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by rw [← encard_union_eq disjoint_compl_right, union_compl_self] end Lattice section InsertErase variable {a b : α} theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by rw [← union_singleton, ← encard_singleton x]; apply encard_union_le theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by rw [← encard_singleton x]; exact encard_le_card inter_subset_left theorem encard_diff_singleton_add_one (h : a ∈ s) : (s \ {a}).encard + 1 = s.encard := by rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h] theorem encard_diff_singleton_of_mem (h : a ∈ s) : (s \ {a}).encard = s.encard - 1 := by rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_cancel_iff WithTop.one_ne_top, tsub_add_cancel_of_le (self_le_add_left _ _)] theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) : s.encard - 1 ≤ (s \ {x}).encard := by rw [← encard_singleton x]; apply tsub_encard_le_encard_diff theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb] simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true] theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb] theorem encard_eq_add_one_iff {k : ℕ∞} : s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by refine ⟨fun h ↦ ?_, ?_⟩ · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h]) refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩ rw [← WithTop.add_right_cancel_iff WithTop.one_ne_top, ← h, encard_diff_singleton_add_one ha] rintro ⟨a, t, h, rfl, rfl⟩ rw [encard_insert_of_not_mem h] /-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended for well-founded induction on the value of `encard`. -/ theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) : s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦ (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq))) rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)] exact WithTop.add_lt_add_left (hfin.diff _).encard_lt_top.ne zero_lt_one end InsertErase section SmallSets theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two, WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_singleton] theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le' (by simpa) (by simp [h])).symm⟩ theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero, encard_eq_one] theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty] refine ⟨fun h a b has hbs ↦ ?_, fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩ obtain ⟨x, rfl⟩ := h ⟨_, has⟩ rw [(has : a = x), (hbs : b = x)] theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by by_contra! h' obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h apply hne rw [h' b hb, h' b' hb'] theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), ← one_add_one_eq_two, WithTop.add_right_cancel_iff (WithTop.one_ne_top), encard_eq_one] at h obtain ⟨y, h⟩ := h refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩ rw [← h, insert_diff_singleton, insert_eq_of_mem hx] theorem encard_eq_three {α : Type u_1} {s : Set α} : encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩ · obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1), WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_eq_two] at h obtain ⟨y, z, hne, hs⟩ := h refine ⟨x, y, z, ?_, ?_, hne, ?_⟩ · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl rw [← hs, insert_diff_singleton, insert_eq_of_mem hx] rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1 · rw [Finset.coe_range, Iio_def] rw [Finset.card_range] end SmallSets theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t) (hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_cancel_iff hs.encard_lt_top.ne, encard_eq_one] at hst obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union] theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by revert hk refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_ · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle) simp only [Nat.cast_succ] at * have hne : t₀ ≠ s := by rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne) exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩ simp only [top_le_iff, encard_eq_top_iff] exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩ theorem exists_superset_subset_encard_eq {k : ℕ∞} (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) : ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by obtain (hs | hs) := eq_or_ne s.encard ⊤ · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩ obtain ⟨k, rfl⟩ := exists_add_of_le hsk obtain ⟨k', hk'⟩ := exists_add_of_le hkt have hk : k ≤ encard (t \ s) := by rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt exact WithTop.le_of_add_le_add_right hs hkt obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩ rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)] section Function variable {s : Set α} {t : Set β} {f : α → β} theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by rw [encard, PartENat.card_image_of_injOn h, encard] theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, PartENat.card_congr e] theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) : (f '' s).encard = s.encard := hf.injOn.encard_image theorem _root_.Function.Embedding.enccard_le (e : s ↪ t) : s.encard ≤ t.encard := by rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image] exact encard_mono (by simp) theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by obtain (h | h) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] apply encard_le_card exact f.invFunOn_image_image_subset s theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) : InjOn f s := by obtain (h' | hne) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] at h rw [injOn_iff_invFunOn_image_image_eq_self] exact hs.eq_of_subset_of_encard_le (f.invFunOn_image_image_subset s) h.symm.le theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) : (f ⁻¹' t).encard = t.encard := by rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht] theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) : s.encard ≤ t.encard := by rw [← f_inj.encard_image]; apply encard_le_card; rintro _ ⟨x, hx, rfl⟩; exact hf hx theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite) (hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by classical obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · simp · exact (encard_ne_top_iff.mpr hs h).elim obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle) have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top, encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt] obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le (hs.diff {a}) hle' simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s use Function.update f₀ a b rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)] simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def, mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp, mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt] refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩ · rintro x hx; split_ifs with h · assumption · exact (hf₀s x hx h).1 exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_noteq]) termination_by encard s theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) : ∃ (f : α → β), BijOn f s t := by obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f convert hinj.bijOn_image rw [(hs.image f).eq_of_subset_of_encard_le' (image_subset_iff.mpr hf) (h.symm.trans hinj.encard_image.symm).le] end Function section ncard open Nat /-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite` term. -/ syntax "toFinite_tac" : tactic macro_rules | `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite) /-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/ syntax "to_encard_tac" : tactic macro_rules | `(tactic| to_encard_tac) => `(tactic| simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one]) /-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/ noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard #align set.ncard Set.ncard theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not] theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by obtain (h | h) := s.finite_or_infinite · have := h.fintype rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card, toFinite_toFinset, toFinset_card, ENat.toNat_coe] have := infinite_coe_iff.2 h rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top] #align set.nat.card_coe_set_eq Set.Nat.card_coe_set_eq theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) : s.ncard = hs.toFinset.card := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype, @Finite.card_toFinset _ _ hs.fintype hs] #align set.ncard_eq_to_finset_card Set.ncard_eq_toFinset_card theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] : s.ncard = s.toFinset.card := by simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card] theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by rw [encard_le_coe_iff, and_congr_right_iff] exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe], fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩ theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype] #align set.infinite.ncard Set.Infinite.ncard theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard := by rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq] exact encard_mono hst #align set.ncard_le_of_subset Set.ncard_le_ncard theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard #align set.ncard_mono Set.ncard_mono @[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) : s.ncard = 0 ↔ s = ∅ := by rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero] #align set.ncard_eq_zero Set.ncard_eq_zero @[simp] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset] #align set.ncard_coe_finset Set.ncard_coe_Finset theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by cases' finite_or_infinite α with h h · have hft := Fintype.ofFinite α rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card] rw [Nat.card_eq_zero_of_infinite, Infinite.ncard] exact infinite_univ #align set.ncard_univ Set.ncard_univ @[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by rw [ncard_eq_zero] #align set.ncard_empty Set.ncard_empty theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty] #align set.ncard_pos Set.ncard_pos theorem ncard_ne_zero_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 := ((ncard_pos hs).mpr ⟨a, h⟩).ne.symm #align set.ncard_ne_zero_of_mem Set.ncard_ne_zero_of_mem theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite := s.finite_or_infinite.elim id fun h ↦ (hs h.ncard).elim #align set.finite_of_ncard_ne_zero Set.finite_of_ncard_ne_zero theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite := finite_of_ncard_ne_zero hs.ne.symm #align set.finite_of_ncard_pos Set.finite_of_ncard_pos theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; simp at hs #align set.nonempty_of_ncard_ne_zero Set.nonempty_of_ncard_ne_zero @[simp] theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by simp [ncard, ncard_eq_toFinset_card] #align set.ncard_singleton Set.ncard_singleton theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one] apply encard_singleton_inter #align set.ncard_singleton_inter Set.ncard_singleton_inter section InsertErase @[simp] theorem ncard_insert_of_not_mem {a : α} (h : a ∉ s) (hs : s.Finite := by toFinite_tac) : (insert a s).ncard = s.ncard + 1 := by rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one, hs.cast_ncard_eq, encard_insert_of_not_mem h] #align set.ncard_insert_of_not_mem Set.ncard_insert_of_not_mem theorem ncard_insert_of_mem {a : α} (h : a ∈ s) : ncard (insert a s) = s.ncard := by rw [insert_eq_of_mem h] #align set.ncard_insert_of_mem Set.ncard_insert_of_mem theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by obtain hs | hs := s.finite_or_infinite · to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le rw [(hs.mono (subset_insert a s)).ncard] exact Nat.zero_le _ #align set.ncard_insert_le Set.ncard_insert_le theorem ncard_insert_eq_ite {a : α} [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) : ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by by_cases h : a ∈ s · rw [ncard_insert_of_mem h, if_pos h] · rw [ncard_insert_of_not_mem h hs, if_neg h] #align set.ncard_insert_eq_ite Set.ncard_insert_eq_ite theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by classical refine s.finite_or_infinite.elim (fun h ↦ ?_) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _)) rw [ncard_insert_eq_ite h]; split_ifs <;> simp #align set.ncard_le_ncard_insert Set.ncard_le_ncard_insert @[simp] theorem ncard_pair {a b : α} (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by rw [ncard_insert_of_not_mem, ncard_singleton]; simpa #align set.card_doubleton Set.ncard_pair @[simp] theorem ncard_diff_singleton_add_one {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard + 1 = s.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq, encard_diff_singleton_add_one h] #align set.ncard_diff_singleton_add_one Set.ncard_diff_singleton_add_one @[simp] theorem ncard_diff_singleton_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard = s.ncard - 1 := eq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs) #align set.ncard_diff_singleton_of_mem Set.ncard_diff_singleton_of_mem theorem ncard_diff_singleton_lt_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard < s.ncard := by rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one #align set.ncard_diff_singleton_lt_of_mem Set.ncard_diff_singleton_lt_of_mem theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by obtain hs | hs := s.finite_or_infinite · apply ncard_le_ncard diff_subset hs convert @zero_le ℕ _ _ exact (hs.diff (by simp : Set.Finite {a})).ncard #align set.ncard_diff_singleton_le Set.ncard_diff_singleton_le theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by cases' s.finite_or_infinite with hs hs · by_cases h : a ∈ s · rw [ncard_diff_singleton_of_mem h hs] rw [diff_singleton_eq_self h] apply Nat.pred_le convert Nat.zero_le _ rw [hs.ncard] #align set.pred_ncard_le_ncard_diff_singleton Set.pred_ncard_le_ncard_diff_singleton theorem ncard_exchange {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard := congr_arg ENat.toNat <| encard_exchange ha hb #align set.ncard_exchange Set.ncard_exchange theorem ncard_exchange' {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard = s.ncard := by rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib, @diff_singleton_eq_self _ b {a} fun h ↦ ha (by rwa [← mem_singleton_iff.mp h])] #align set.ncard_exchange' Set.ncard_exchange' end InsertErase variable {f : α → β} theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; apply encard_image_le #align set.ncard_image_le Set.ncard_image_le theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard := congr_arg ENat.toNat <| H.encard_image #align set.ncard_image_of_inj_on Set.ncard_image_of_injOn theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.Finite := by toFinite_tac) : Set.InjOn f s := by rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h exact hs.injOn_of_encard_image_eq h #align set.inj_on_of_ncard_image_eq Set.injOn_of_ncard_image_eq theorem ncard_image_iff (hs : s.Finite := by toFinite_tac) : (f '' s).ncard = s.ncard ↔ Set.InjOn f s := ⟨fun h ↦ injOn_of_ncard_image_eq h hs, ncard_image_of_injOn⟩ #align set.ncard_image_iff Set.ncard_image_iff theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard := ncard_image_of_injOn fun _ _ _ _ h ↦ H h #align set.ncard_image_of_injective Set.ncard_image_of_injective theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective) (hs : s ⊆ Set.range f) : (f ⁻¹' s).ncard = s.ncard := by rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs] #align set.ncard_preimage_of_injective_subset_range Set.ncard_preimage_of_injective_subset_range theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite_tac) : { x ∈ s | f x = y }.ncard ≠ 0 ↔ y ∈ f '' s := by refine ⟨nonempty_of_ncard_ne_zero, ?_⟩ rintro ⟨z, hz, rfl⟩ exact @ncard_ne_zero_of_mem _ ({ x ∈ s | f x = f z }) z (mem_sep hz rfl) (hs.subset (sep_subset _ _)) #align set.fiber_ncard_ne_zero_iff_mem_image Set.fiber_ncard_ne_zero_iff_mem_image @[simp] theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard := ncard_image_of_injective _ f.inj' #align set.ncard_map Set.ncard_map @[simp] theorem ncard_subtype (P : α → Prop) (s : Set α) : { x : Subtype P | (x : α) ∈ s }.ncard = (s ∩ setOf P).ncard := by convert (ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm ext x simp [← and_assoc, exists_eq_right] #align set.ncard_subtype Set.ncard_subtype theorem ncard_inter_le_ncard_left (s t : Set α) (hs : s.Finite := by toFinite_tac) : (s ∩ t).ncard ≤ s.ncard := ncard_le_ncard inter_subset_left hs #align set.ncard_inter_le_ncard_left Set.ncard_inter_le_ncard_left theorem ncard_inter_le_ncard_right (s t : Set α) (ht : t.Finite := by toFinite_tac) : (s ∩ t).ncard ≤ t.ncard := ncard_le_ncard inter_subset_right ht #align set.ncard_inter_le_ncard_right Set.ncard_inter_le_ncard_right theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) : s = t := ht.eq_of_subset_of_encard_le h (by rwa [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq] at h') #align set.eq_of_subset_of_ncard_le Set.eq_of_subset_of_ncard_le theorem subset_iff_eq_of_ncard_le (h : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) : s ⊆ t ↔ s = t := ⟨fun hst ↦ eq_of_subset_of_ncard_le hst h ht, Eq.subset'⟩ #align set.subset_iff_eq_of_ncard_le Set.subset_iff_eq_of_ncard_le theorem map_eq_of_subset {f : α ↪ α} (h : f '' s ⊆ s) (hs : s.Finite := by toFinite_tac) : f '' s = s := eq_of_subset_of_ncard_le h (ncard_map _).ge hs #align set.map_eq_of_subset Set.map_eq_of_subset theorem sep_of_ncard_eq {a : α} {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard) (ha : a ∈ s) (hs : s.Finite := by toFinite_tac) : P a := sep_eq_self_iff_mem_true.mp (eq_of_subset_of_ncard_le (by simp) h.symm.le hs) _ ha #align set.sep_of_ncard_eq Set.sep_of_ncard_eq theorem ncard_lt_ncard (h : s ⊂ t) (ht : t.Finite := by toFinite_tac) : s.ncard < t.ncard := by rw [← Nat.cast_lt (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h.subset).cast_ncard_eq] exact ht.encard_lt_encard h #align set.ncard_lt_ncard Set.ncard_lt_ncard theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard := fun _ _ h ↦ ncard_lt_ncard h #align set.ncard_strict_mono Set.ncard_strictMono theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α) (hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ (i) (h : i < n), f i h ∈ s) (f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) : s.ncard = n := by let f' : Fin n → α := fun i ↦ f i.val i.is_lt suffices himage : s = f' '' Set.univ by rw [← Fintype.card_fin n, ← Nat.card_eq_fintype_card, ← Set.ncard_univ, himage] exact ncard_image_of_injOn <| fun i _hi j _hj h ↦ Fin.ext <| f_inj i.val j.val i.is_lt j.is_lt h ext x simp only [image_univ, mem_range] refine ⟨fun hx ↦ ?_, fun ⟨⟨i, hi⟩, hx⟩ ↦ hx ▸ hf' i hi⟩ obtain ⟨i, hi, rfl⟩ := hf x hx use ⟨i, hi⟩ #align set.ncard_eq_of_bijective Set.ncard_eq_of_bijective theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t) (h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b) : s.ncard = t.ncard := by set f' : s → t := fun x ↦ ⟨f x.1 x.2, h₁ _ _⟩ have hbij : f'.Bijective := by constructor · rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy simp only [f', Subtype.mk.injEq] at hxy ⊢ exact h₂ _ _ hx hy hxy rintro ⟨y, hy⟩ obtain ⟨a, ha, rfl⟩ := h₃ y hy simp only [Subtype.mk.injEq, Subtype.exists] exact ⟨_, ha, rfl⟩ simp_rw [← Nat.card_coe_set_eq] exact Nat.card_congr (Equiv.ofBijective f' hbij) #align set.ncard_congr Set.ncard_congr theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : InjOn f s) (ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard := by have hle := encard_le_encard_of_injOn hf f_inj to_encard_tac; rwa [ht.cast_ncard_eq, (ht.finite_of_encard_le hle).cast_ncard_eq] #align set.ncard_le_ncard_of_inj_on Set.ncard_le_ncard_of_injOn theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.ncard) {f : α → β} (hf : ∀ a ∈ s, f a ∈ t) (ht : t.Finite := by toFinite_tac) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by by_contra h' simp only [Ne, exists_prop, not_exists, not_and, not_imp_not] at h' exact (ncard_le_ncard_of_injOn f hf h' ht).not_lt hc #align set.exists_ne_map_eq_of_ncard_lt_of_maps_to Set.exists_ne_map_eq_of_ncard_lt_of_maps_to theorem le_ncard_of_inj_on_range {n : ℕ} (f : ℕ → α) (hf : ∀ i < n, f i ∈ s) (f_inj : ∀ i < n, ∀ j < n, f i = f j → i = j) (hs : s.Finite := by toFinite_tac) : n ≤ s.ncard := by rw [ncard_eq_toFinset_card _ hs] apply Finset.le_card_of_inj_on_range <;> simpa #align set.le_ncard_of_inj_on_range Set.le_ncard_of_inj_on_range theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t) (hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) : ∀ b ∈ t, ∃ a ha, b = f a ha := by intro b hb set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩ have finj : f'.Injective := by rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy simp only [f', Subtype.mk.injEq] at hxy ⊢ apply hinj _ _ hx hy hxy have hft := ht.fintype have hft' := Fintype.ofInjective f' finj set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h) convert @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.toFinset f'' _ _ _ _ (by simpa) · simp · simp [hf] · intros a₁ a₂ ha₁ ha₂ h rw [mem_toFinset] at ha₁ ha₂ exact hinj _ _ ha₁ ha₂ h rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] #align set.surj_on_of_inj_on_of_ncard_le Set.surj_on_of_inj_on_of_ncard_le theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t) (hsurj : ∀ b ∈ t, ∃ a ha, f a ha = b) (hst : s.ncard ≤ t.ncard) ⦃a₁⦄ (ha₁ : a₁ ∈ s) ⦃a₂⦄ (ha₂ : a₂ ∈ s) (ha₁a₂ : f a₁ ha₁ = f a₂ ha₂) (hs : s.Finite := by toFinite_tac) : a₁ = a₂ := by classical set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩ have hsurj : f'.Surjective := by rintro ⟨y, hy⟩ obtain ⟨a, ha, rfl⟩ := hsurj y hy simp only [Subtype.mk.injEq, Subtype.exists] exact ⟨_, ha, rfl⟩ haveI := hs.fintype haveI := Fintype.ofSurjective _ hsurj set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h) exact @Finset.inj_on_of_surj_on_of_card_le _ _ _ t.toFinset f'' (fun a ha ↦ by { rw [mem_toFinset] at ha ⊢; exact hf a ha }) (by simpa) (by { rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] }) a₁ (by simpa) a₂ (by simpa) (by simpa) #align set.inj_on_of_surj_on_of_ncard_le Set.inj_on_of_surj_on_of_ncard_le section Lattice theorem ncard_union_add_ncard_inter (s t : Set α) (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq, (hs.subset inter_subset_left).cast_ncard_eq, encard_union_add_encard_inter] #align set.ncard_union_add_ncard_inter Set.ncard_union_add_ncard_inter theorem ncard_inter_add_ncard_union (s t : Set α) (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : (s ∩ t).ncard + (s ∪ t).ncard = s.ncard + t.ncard := by rw [add_comm, ncard_union_add_ncard_inter _ _ hs ht] #align set.ncard_inter_add_ncard_union Set.ncard_inter_add_ncard_union theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by obtain (h | h) := (s ∪ t).finite_or_infinite · to_encard_tac rw [h.cast_ncard_eq, (h.subset subset_union_left).cast_ncard_eq, (h.subset subset_union_right).cast_ncard_eq] apply encard_union_le rw [h.ncard] apply zero_le #align set.ncard_union_le Set.ncard_union_le theorem ncard_union_eq (h : Disjoint s t) (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard = s.ncard + t.ncard := by to_encard_tac rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq, encard_union_eq h] #align set.ncard_union_eq Set.ncard_union_eq theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t) (ht : t.Finite := by toFinite_tac) : (t \ s).ncard + s.ncard = t.ncard := by to_encard_tac rw [ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq, (ht.diff _).cast_ncard_eq, encard_diff_add_encard_of_subset h] #align set.ncard_diff_add_ncard_eq_ncard Set.ncard_diff_add_ncard_of_subset theorem ncard_diff (h : s ⊆ t) (ht : t.Finite := by toFinite_tac) : (t \ s).ncard = t.ncard - s.ncard := by rw [← ncard_diff_add_ncard_of_subset h ht, add_tsub_cancel_right] #align set.ncard_diff Set.ncard_diff theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) : s.ncard ≤ (s \ t).ncard + t.ncard := by cases' s.finite_or_infinite with hs hs · to_encard_tac rw [ht.cast_ncard_eq, hs.cast_ncard_eq, (hs.diff _).cast_ncard_eq] apply encard_le_encard_diff_add_encard convert Nat.zero_le _ rw [hs.ncard] #align set.ncard_le_ncard_diff_add_ncard Set.ncard_le_ncard_diff_add_ncard theorem le_ncard_diff (s t : Set α) (hs : s.Finite := by toFinite_tac) : t.ncard - s.ncard ≤ (t \ s).ncard := tsub_le_iff_left.mpr (by rw [add_comm]; apply ncard_le_ncard_diff_add_ncard _ _ hs) #align set.le_ncard_diff Set.le_ncard_diff theorem ncard_diff_add_ncard (s t : Set α) (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : (s \ t).ncard + t.ncard = (s ∪ t).ncard := by rw [← ncard_union_eq disjoint_sdiff_left (hs.diff _) ht, diff_union_self] #align set.ncard_diff_add_ncard Set.ncard_diff_add_ncard theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) : (t \ s).Nonempty := by rw [Set.nonempty_iff_ne_empty, Ne, diff_eq_empty] exact fun h' ↦ h.not_le (ncard_le_ncard h' hs) #align set.diff_nonempty_of_ncard_lt_ncard Set.diff_nonempty_of_ncard_lt_ncard theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) : ∃ e, e ∈ t ∧ e ∉ s := diff_nonempty_of_ncard_lt_ncard h hs #align set.exists_mem_not_mem_of_ncard_lt_ncard Set.exists_mem_not_mem_of_ncard_lt_ncard @[simp] theorem ncard_inter_add_ncard_diff_eq_ncard (s t : Set α) (hs : s.Finite := by toFinite_tac) : (s ∩ t).ncard + (s \ t).ncard = s.ncard := by rw [← ncard_union_eq (disjoint_of_subset_left inter_subset_right disjoint_sdiff_right) (hs.inter_of_left _) (hs.diff _), union_comm, diff_union_inter] #align set.ncard_inter_add_ncard_diff_eq_ncard Set.ncard_inter_add_ncard_diff_eq_ncard theorem ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : s.ncard = t.ncard ↔ (s \ t).ncard = (t \ s).ncard := by rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht, inter_comm, add_right_inj] #align set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff Set.ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff theorem ncard_le_ncard_iff_ncard_diff_le_ncard_diff (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard ↔ (s \ t).ncard ≤ (t \ s).ncard := by rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht, inter_comm, add_le_add_iff_left] #align set.ncard_le_ncard_iff_ncard_diff_le_ncard_diff Set.ncard_le_ncard_iff_ncard_diff_le_ncard_diff theorem ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff (hs : s.Finite := by toFinite_tac) (ht : t.Finite := by toFinite_tac) : s.ncard < t.ncard ↔ (s \ t).ncard < (t \ s).ncard := by rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht, inter_comm, add_lt_add_iff_left] #align set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff Set.ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff
Mathlib/Data/Set/Card.lean
934
936
theorem ncard_add_ncard_compl (s : Set α) (hs : s.Finite := by
toFinite_tac) (hsc : sᶜ.Finite := by toFinite_tac) : s.ncard + sᶜ.ncard = Nat.card α := by rw [← ncard_univ, ← ncard_union_eq (@disjoint_compl_right _ _ s) hs hsc, union_compl_self]
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Logic.Equiv.Option import Mathlib.Order.RelIso.Basic import Mathlib.Order.Disjoint import Mathlib.Order.WithBot import Mathlib.Tactic.Monotonicity.Attr import Mathlib.Util.AssertExists #align_import order.hom.basic from "leanprover-community/mathlib"@"62a5626868683c104774de8d85b9855234ac807c" /-! # Order homomorphisms This file defines order homomorphisms, which are bundled monotone functions. A preorder homomorphism `f : α →o β` is a function `α → β` along with a proof that `∀ x y, x ≤ y → f x ≤ f y`. ## Main definitions In this file we define the following bundled monotone maps: * `OrderHom α β` a.k.a. `α →o β`: Preorder homomorphism. An `OrderHom α β` is a function `f : α → β` such that `a₁ ≤ a₂ → f a₁ ≤ f a₂` * `OrderEmbedding α β` a.k.a. `α ↪o β`: Relation embedding. An `OrderEmbedding α β` is an embedding `f : α ↪ β` such that `a ≤ b ↔ f a ≤ f b`. Defined as an abbreviation of `@RelEmbedding α β (≤) (≤)`. * `OrderIso`: Relation isomorphism. An `OrderIso α β` is an equivalence `f : α ≃ β` such that `a ≤ b ↔ f a ≤ f b`. Defined as an abbreviation of `@RelIso α β (≤) (≤)`. We also define many `OrderHom`s. In some cases we define two versions, one with `ₘ` suffix and one without it (e.g., `OrderHom.compₘ` and `OrderHom.comp`). This means that the former function is a "more bundled" version of the latter. We can't just drop the "less bundled" version because the more bundled version usually does not work with dot notation. * `OrderHom.id`: identity map as `α →o α`; * `OrderHom.curry`: an order isomorphism between `α × β →o γ` and `α →o β →o γ`; * `OrderHom.comp`: composition of two bundled monotone maps; * `OrderHom.compₘ`: composition of bundled monotone maps as a bundled monotone map; * `OrderHom.const`: constant function as a bundled monotone map; * `OrderHom.prod`: combine `α →o β` and `α →o γ` into `α →o β × γ`; * `OrderHom.prodₘ`: a more bundled version of `OrderHom.prod`; * `OrderHom.prodIso`: order isomorphism between `α →o β × γ` and `(α →o β) × (α →o γ)`; * `OrderHom.diag`: diagonal embedding of `α` into `α × α` as a bundled monotone map; * `OrderHom.onDiag`: restrict a monotone map `α →o α →o β` to the diagonal; * `OrderHom.fst`: projection `Prod.fst : α × β → α` as a bundled monotone map; * `OrderHom.snd`: projection `Prod.snd : α × β → β` as a bundled monotone map; * `OrderHom.prodMap`: `prod.map f g` as a bundled monotone map; * `Pi.evalOrderHom`: evaluation of a function at a point `Function.eval i` as a bundled monotone map; * `OrderHom.coeFnHom`: coercion to function as a bundled monotone map; * `OrderHom.apply`: application of an `OrderHom` at a point as a bundled monotone map; * `OrderHom.pi`: combine a family of monotone maps `f i : α →o π i` into a monotone map `α →o Π i, π i`; * `OrderHom.piIso`: order isomorphism between `α →o Π i, π i` and `Π i, α →o π i`; * `OrderHom.subtype.val`: embedding `Subtype.val : Subtype p → α` as a bundled monotone map; * `OrderHom.dual`: reinterpret a monotone map `α →o β` as a monotone map `αᵒᵈ →o βᵒᵈ`; * `OrderHom.dualIso`: order isomorphism between `α →o β` and `(αᵒᵈ →o βᵒᵈ)ᵒᵈ`; * `OrderHom.compl`: order isomorphism `α ≃o αᵒᵈ` given by taking complements in a boolean algebra; We also define two functions to convert other bundled maps to `α →o β`: * `OrderEmbedding.toOrderHom`: convert `α ↪o β` to `α →o β`; * `RelHom.toOrderHom`: convert a `RelHom` between strict orders to an `OrderHom`. ## Tags monotone map, bundled morphism -/ open OrderDual variable {F α β γ δ : Type*} /-- Bundled monotone (aka, increasing) function -/ structure OrderHom (α β : Type*) [Preorder α] [Preorder β] where /-- The underlying function of an `OrderHom`. -/ toFun : α → β /-- The underlying function of an `OrderHom` is monotone. -/ monotone' : Monotone toFun #align order_hom OrderHom /-- Notation for an `OrderHom`. -/ infixr:25 " →o " => OrderHom /-- An order embedding is an embedding `f : α ↪ β` such that `a ≤ b ↔ (f a) ≤ (f b)`. This definition is an abbreviation of `RelEmbedding (≤) (≤)`. -/ abbrev OrderEmbedding (α β : Type*) [LE α] [LE β] := @RelEmbedding α β (· ≤ ·) (· ≤ ·) #align order_embedding OrderEmbedding /-- Notation for an `OrderEmbedding`. -/ infixl:25 " ↪o " => OrderEmbedding /-- An order isomorphism is an equivalence such that `a ≤ b ↔ (f a) ≤ (f b)`. This definition is an abbreviation of `RelIso (≤) (≤)`. -/ abbrev OrderIso (α β : Type*) [LE α] [LE β] := @RelIso α β (· ≤ ·) (· ≤ ·) #align order_iso OrderIso /-- Notation for an `OrderIso`. -/ infixl:25 " ≃o " => OrderIso section /-- `OrderHomClass F α b` asserts that `F` is a type of `≤`-preserving morphisms. -/ abbrev OrderHomClass (F : Type*) (α β : outParam Type*) [LE α] [LE β] [FunLike F α β] := RelHomClass F ((· ≤ ·) : α → α → Prop) ((· ≤ ·) : β → β → Prop) #align order_hom_class OrderHomClass /-- `OrderIsoClass F α β` states that `F` is a type of order isomorphisms. You should extend this class when you extend `OrderIso`. -/ class OrderIsoClass (F α β : Type*) [LE α] [LE β] [EquivLike F α β] : Prop where /-- An order isomorphism respects `≤`. -/ map_le_map_iff (f : F) {a b : α} : f a ≤ f b ↔ a ≤ b #align order_iso_class OrderIsoClass end export OrderIsoClass (map_le_map_iff) attribute [simp] map_le_map_iff /-- Turn an element of a type `F` satisfying `OrderIsoClass F α β` into an actual `OrderIso`. This is declared as the default coercion from `F` to `α ≃o β`. -/ @[coe] def OrderIsoClass.toOrderIso [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] (f : F) : α ≃o β := { EquivLike.toEquiv f with map_rel_iff' := map_le_map_iff f } /-- Any type satisfying `OrderIsoClass` can be cast into `OrderIso` via `OrderIsoClass.toOrderIso`. -/ instance [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : CoeTC F (α ≃o β) := ⟨OrderIsoClass.toOrderIso⟩ -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toOrderHomClass [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : OrderHomClass F α β := { EquivLike.toEmbeddingLike (E := F) with map_rel := fun f _ _ => (map_le_map_iff f).2 } #align order_iso_class.to_order_hom_class OrderIsoClass.toOrderHomClass namespace OrderHomClass variable [Preorder α] [Preorder β] [FunLike F α β] [OrderHomClass F α β] protected theorem monotone (f : F) : Monotone f := fun _ _ => map_rel f #align order_hom_class.monotone OrderHomClass.monotone protected theorem mono (f : F) : Monotone f := fun _ _ => map_rel f #align order_hom_class.mono OrderHomClass.mono /-- Turn an element of a type `F` satisfying `OrderHomClass F α β` into an actual `OrderHom`. This is declared as the default coercion from `F` to `α →o β`. -/ @[coe] def toOrderHom (f : F) : α →o β where toFun := f monotone' := OrderHomClass.monotone f /-- Any type satisfying `OrderHomClass` can be cast into `OrderHom` via `OrderHomClass.toOrderHom`. -/ instance : CoeTC F (α →o β) := ⟨toOrderHom⟩ end OrderHomClass section OrderIsoClass section LE variable [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] -- Porting note: needed to add explicit arguments to map_le_map_iff @[simp] theorem map_inv_le_iff (f : F) {a : α} {b : β} : EquivLike.inv f b ≤ a ↔ b ≤ f a := by convert (map_le_map_iff f (a := EquivLike.inv f b) (b := a)).symm exact (EquivLike.right_inv f _).symm #align map_inv_le_iff map_inv_le_iff -- Porting note: needed to add explicit arguments to map_le_map_iff @[simp] theorem le_map_inv_iff (f : F) {a : α} {b : β} : a ≤ EquivLike.inv f b ↔ f a ≤ b := by convert (map_le_map_iff f (a := a) (b := EquivLike.inv f b)).symm exact (EquivLike.right_inv _ _).symm #align le_map_inv_iff le_map_inv_iff end LE variable [Preorder α] [Preorder β] [EquivLike F α β] [OrderIsoClass F α β] theorem map_lt_map_iff (f : F) {a b : α} : f a < f b ↔ a < b := lt_iff_lt_of_le_iff_le' (map_le_map_iff f) (map_le_map_iff f) #align map_lt_map_iff map_lt_map_iff @[simp] theorem map_inv_lt_iff (f : F) {a : α} {b : β} : EquivLike.inv f b < a ↔ b < f a := by rw [← map_lt_map_iff f] simp only [EquivLike.apply_inv_apply] #align map_inv_lt_iff map_inv_lt_iff @[simp] theorem lt_map_inv_iff (f : F) {a : α} {b : β} : a < EquivLike.inv f b ↔ f a < b := by rw [← map_lt_map_iff f] simp only [EquivLike.apply_inv_apply] #align lt_map_inv_iff lt_map_inv_iff end OrderIsoClass namespace OrderHom variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] instance : FunLike (α →o β) α β where coe := toFun coe_injective' f g h := by cases f; cases g; congr instance : OrderHomClass (α →o β) α β where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f : α → β) (hf : Monotone f) : ⇑(mk f hf) = f := rfl #align order_hom.coe_fun_mk OrderHom.coe_mk protected theorem monotone (f : α →o β) : Monotone f := f.monotone' #align order_hom.monotone OrderHom.monotone protected theorem mono (f : α →o β) : Monotone f := f.monotone #align order_hom.mono OrderHom.mono /-- See Note [custom simps projection]. We give this manually so that we use `toFun` as the projection directly instead. -/ def Simps.coe (f : α →o β) : α → β := f /- Porting note (#11215): TODO: all other DFunLike classes use `apply` instead of `coe` for the projection names. Maybe we should change this. -/ initialize_simps_projections OrderHom (toFun → coe) @[simp] theorem toFun_eq_coe (f : α →o β) : f.toFun = f := rfl #align order_hom.to_fun_eq_coe OrderHom.toFun_eq_coe -- See library note [partially-applied ext lemmas] @[ext] theorem ext (f g : α →o β) (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h #align order_hom.ext OrderHom.ext @[simp] theorem coe_eq (f : α →o β) : OrderHomClass.toOrderHom f = f := rfl @[simp] theorem _root_.OrderHomClass.coe_coe {F} [FunLike F α β] [OrderHomClass F α β] (f : F) : ⇑(f : α →o β) = f := rfl /-- One can lift an unbundled monotone function to a bundled one. -/ protected instance canLift : CanLift (α → β) (α →o β) (↑) Monotone where prf f h := ⟨⟨f, h⟩, rfl⟩ #align order_hom.monotone.can_lift OrderHom.canLift /-- Copy of an `OrderHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : α →o β) (f' : α → β) (h : f' = f) : α →o β := ⟨f', h.symm.subst f.monotone'⟩ #align order_hom.copy OrderHom.copy @[simp] theorem coe_copy (f : α →o β) (f' : α → β) (h : f' = f) : (f.copy f' h) = f' := rfl #align order_hom.coe_copy OrderHom.coe_copy theorem copy_eq (f : α →o β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h #align order_hom.copy_eq OrderHom.copy_eq /-- The identity function as bundled monotone function. -/ @[simps (config := .asFn)] def id : α →o α := ⟨_root_.id, monotone_id⟩ #align order_hom.id OrderHom.id #align order_hom.id_coe OrderHom.id_coe instance : Inhabited (α →o α) := ⟨id⟩ /-- The preorder structure of `α →o β` is pointwise inequality: `f ≤ g ↔ ∀ a, f a ≤ g a`. -/ instance : Preorder (α →o β) := @Preorder.lift (α →o β) (α → β) _ toFun instance {β : Type*} [PartialOrder β] : PartialOrder (α →o β) := @PartialOrder.lift (α →o β) (α → β) _ toFun ext theorem le_def {f g : α →o β} : f ≤ g ↔ ∀ x, f x ≤ g x := Iff.rfl #align order_hom.le_def OrderHom.le_def @[simp, norm_cast] theorem coe_le_coe {f g : α →o β} : (f : α → β) ≤ g ↔ f ≤ g := Iff.rfl #align order_hom.coe_le_coe OrderHom.coe_le_coe @[simp] theorem mk_le_mk {f g : α → β} {hf hg} : mk f hf ≤ mk g hg ↔ f ≤ g := Iff.rfl #align order_hom.mk_le_mk OrderHom.mk_le_mk @[mono] theorem apply_mono {f g : α →o β} {x y : α} (h₁ : f ≤ g) (h₂ : x ≤ y) : f x ≤ g y := (h₁ x).trans <| g.mono h₂ #align order_hom.apply_mono OrderHom.apply_mono /-- Curry/uncurry as an order isomorphism between `α × β →o γ` and `α →o β →o γ`. -/ def curry : (α × β →o γ) ≃o (α →o β →o γ) where toFun f := ⟨fun x ↦ ⟨Function.curry f x, fun _ _ h ↦ f.mono ⟨le_rfl, h⟩⟩, fun _ _ h _ => f.mono ⟨h, le_rfl⟩⟩ invFun f := ⟨Function.uncurry fun x ↦ f x, fun x y h ↦ (f.mono h.1 x.2).trans ((f y.1).mono h.2)⟩ left_inv _ := rfl right_inv _ := rfl map_rel_iff' := by simp [le_def] #align order_hom.curry OrderHom.curry @[simp] theorem curry_apply (f : α × β →o γ) (x : α) (y : β) : curry f x y = f (x, y) := rfl #align order_hom.curry_apply OrderHom.curry_apply @[simp] theorem curry_symm_apply (f : α →o β →o γ) (x : α × β) : curry.symm f x = f x.1 x.2 := rfl #align order_hom.curry_symm_apply OrderHom.curry_symm_apply /-- The composition of two bundled monotone functions. -/ @[simps (config := .asFn)] def comp (g : β →o γ) (f : α →o β) : α →o γ := ⟨g ∘ f, g.mono.comp f.mono⟩ #align order_hom.comp OrderHom.comp #align order_hom.comp_coe OrderHom.comp_coe @[mono] theorem comp_mono ⦃g₁ g₂ : β →o γ⦄ (hg : g₁ ≤ g₂) ⦃f₁ f₂ : α →o β⦄ (hf : f₁ ≤ f₂) : g₁.comp f₁ ≤ g₂.comp f₂ := fun _ => (hg _).trans (g₂.mono <| hf _) #align order_hom.comp_mono OrderHom.comp_mono /-- The composition of two bundled monotone functions, a fully bundled version. -/ @[simps! (config := .asFn)] def compₘ : (β →o γ) →o (α →o β) →o α →o γ := curry ⟨fun f : (β →o γ) × (α →o β) => f.1.comp f.2, fun _ _ h => comp_mono h.1 h.2⟩ #align order_hom.compₘ OrderHom.compₘ #align order_hom.compₘ_coe_coe_coe OrderHom.compₘ_coe_coe_coe @[simp] theorem comp_id (f : α →o β) : comp f id = f := by ext rfl #align order_hom.comp_id OrderHom.comp_id @[simp] theorem id_comp (f : α →o β) : comp id f = f := by ext rfl #align order_hom.id_comp OrderHom.id_comp /-- Constant function bundled as an `OrderHom`. -/ @[simps (config := .asFn)] def const (α : Type*) [Preorder α] {β : Type*} [Preorder β] : β →o α →o β where toFun b := ⟨Function.const α b, fun _ _ _ => le_rfl⟩ monotone' _ _ h _ := h #align order_hom.const OrderHom.const #align order_hom.const_coe_coe OrderHom.const_coe_coe @[simp] theorem const_comp (f : α →o β) (c : γ) : (const β c).comp f = const α c := rfl #align order_hom.const_comp OrderHom.const_comp @[simp] theorem comp_const (γ : Type*) [Preorder γ] (f : α →o β) (c : α) : f.comp (const γ c) = const γ (f c) := rfl #align order_hom.comp_const OrderHom.comp_const /-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a `OrderHom`. -/ @[simps] protected def prod (f : α →o β) (g : α →o γ) : α →o β × γ := ⟨fun x => (f x, g x), fun _ _ h => ⟨f.mono h, g.mono h⟩⟩ #align order_hom.prod OrderHom.prod #align order_hom.prod_coe OrderHom.prod_coe @[mono] theorem prod_mono {f₁ f₂ : α →o β} (hf : f₁ ≤ f₂) {g₁ g₂ : α →o γ} (hg : g₁ ≤ g₂) : f₁.prod g₁ ≤ f₂.prod g₂ := fun _ => Prod.le_def.2 ⟨hf _, hg _⟩ #align order_hom.prod_mono OrderHom.prod_mono theorem comp_prod_comp_same (f₁ f₂ : β →o γ) (g : α →o β) : (f₁.comp g).prod (f₂.comp g) = (f₁.prod f₂).comp g := rfl #align order_hom.comp_prod_comp_same OrderHom.comp_prod_comp_same /-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a `OrderHom`. This is a fully bundled version. -/ @[simps!] def prodₘ : (α →o β) →o (α →o γ) →o α →o β × γ := curry ⟨fun f : (α →o β) × (α →o γ) => f.1.prod f.2, fun _ _ h => prod_mono h.1 h.2⟩ #align order_hom.prodₘ OrderHom.prodₘ #align order_hom.prodₘ_coe_coe_coe OrderHom.prodₘ_coe_coe_coe /-- Diagonal embedding of `α` into `α × α` as an `OrderHom`. -/ @[simps!] def diag : α →o α × α := id.prod id #align order_hom.diag OrderHom.diag #align order_hom.diag_coe OrderHom.diag_coe /-- Restriction of `f : α →o α →o β` to the diagonal. -/ @[simps! (config := { simpRhs := true })] def onDiag (f : α →o α →o β) : α →o β := (curry.symm f).comp diag #align order_hom.on_diag OrderHom.onDiag #align order_hom.on_diag_coe OrderHom.onDiag_coe /-- `Prod.fst` as an `OrderHom`. -/ @[simps] def fst : α × β →o α := ⟨Prod.fst, fun _ _ h => h.1⟩ #align order_hom.fst OrderHom.fst #align order_hom.fst_coe OrderHom.fst_coe /-- `Prod.snd` as an `OrderHom`. -/ @[simps] def snd : α × β →o β := ⟨Prod.snd, fun _ _ h => h.2⟩ #align order_hom.snd OrderHom.snd #align order_hom.snd_coe OrderHom.snd_coe @[simp] theorem fst_prod_snd : (fst : α × β →o α).prod snd = id := by ext ⟨x, y⟩ : 2 rfl #align order_hom.fst_prod_snd OrderHom.fst_prod_snd @[simp] theorem fst_comp_prod (f : α →o β) (g : α →o γ) : fst.comp (f.prod g) = f := ext _ _ rfl #align order_hom.fst_comp_prod OrderHom.fst_comp_prod @[simp] theorem snd_comp_prod (f : α →o β) (g : α →o γ) : snd.comp (f.prod g) = g := ext _ _ rfl #align order_hom.snd_comp_prod OrderHom.snd_comp_prod /-- Order isomorphism between the space of monotone maps to `β × γ` and the product of the spaces of monotone maps to `β` and `γ`. -/ @[simps] def prodIso : (α →o β × γ) ≃o (α →o β) × (α →o γ) where toFun f := (fst.comp f, snd.comp f) invFun f := f.1.prod f.2 left_inv _ := rfl right_inv _ := rfl map_rel_iff' := forall_and.symm #align order_hom.prod_iso OrderHom.prodIso #align order_hom.prod_iso_apply OrderHom.prodIso_apply #align order_hom.prod_iso_symm_apply OrderHom.prodIso_symm_apply /-- `Prod.map` of two `OrderHom`s as an `OrderHom`. -/ @[simps] def prodMap (f : α →o β) (g : γ →o δ) : α × γ →o β × δ := ⟨Prod.map f g, fun _ _ h => ⟨f.mono h.1, g.mono h.2⟩⟩ #align order_hom.prod_map OrderHom.prodMap #align order_hom.prod_map_coe OrderHom.prodMap_coe variable {ι : Type*} {π : ι → Type*} [∀ i, Preorder (π i)] /-- Evaluation of an unbundled function at a point (`Function.eval`) as an `OrderHom`. -/ @[simps (config := .asFn)] def _root_.Pi.evalOrderHom (i : ι) : (∀ j, π j) →o π i := ⟨Function.eval i, Function.monotone_eval i⟩ #align pi.eval_order_hom Pi.evalOrderHom #align pi.eval_order_hom_coe Pi.evalOrderHom_coe /-- The "forgetful functor" from `α →o β` to `α → β` that takes the underlying function, is monotone. -/ @[simps (config := .asFn)] def coeFnHom : (α →o β) →o α → β where toFun f := f monotone' _ _ h := h #align order_hom.coe_fn_hom OrderHom.coeFnHom #align order_hom.coe_fn_hom_coe OrderHom.coeFnHom_coe /-- Function application `fun f => f a` (for fixed `a`) is a monotone function from the monotone function space `α →o β` to `β`. See also `Pi.evalOrderHom`. -/ @[simps! (config := .asFn)] def apply (x : α) : (α →o β) →o β := (Pi.evalOrderHom x).comp coeFnHom #align order_hom.apply OrderHom.apply #align order_hom.apply_coe OrderHom.apply_coe /-- Construct a bundled monotone map `α →o Π i, π i` from a family of monotone maps `f i : α →o π i`. -/ @[simps] def pi (f : ∀ i, α →o π i) : α →o ∀ i, π i := ⟨fun x i => f i x, fun _ _ h i => (f i).mono h⟩ #align order_hom.pi OrderHom.pi #align order_hom.pi_coe OrderHom.pi_coe /-- Order isomorphism between bundled monotone maps `α →o Π i, π i` and families of bundled monotone maps `Π i, α →o π i`. -/ @[simps] def piIso : (α →o ∀ i, π i) ≃o ∀ i, α →o π i where toFun f i := (Pi.evalOrderHom i).comp f invFun := pi left_inv _ := rfl right_inv _ := rfl map_rel_iff' := forall_swap #align order_hom.pi_iso OrderHom.piIso #align order_hom.pi_iso_apply OrderHom.piIso_apply #align order_hom.pi_iso_symm_apply OrderHom.piIso_symm_apply /-- `Subtype.val` as a bundled monotone function. -/ @[simps (config := .asFn)] def Subtype.val (p : α → Prop) : Subtype p →o α := ⟨_root_.Subtype.val, fun _ _ h => h⟩ #align order_hom.subtype.val OrderHom.Subtype.val #align order_hom.subtype.val_coe OrderHom.Subtype.val_coe /-- `Subtype.impEmbedding` as an order embedding. -/ @[simps!] def _root_.Subtype.orderEmbedding {p q : α → Prop} (h : ∀ a, p a → q a) : {x // p x} ↪o {x // q x} := { Subtype.impEmbedding _ _ h with map_rel_iff' := by aesop } /-- There is a unique monotone map from a subsingleton to itself. -/ instance unique [Subsingleton α] : Unique (α →o α) where default := OrderHom.id uniq _ := ext _ _ (Subsingleton.elim _ _) #align order_hom.unique OrderHom.unique theorem orderHom_eq_id [Subsingleton α] (g : α →o α) : g = OrderHom.id := Subsingleton.elim _ _ #align order_hom.order_hom_eq_id OrderHom.orderHom_eq_id /-- Reinterpret a bundled monotone function as a monotone function between dual orders. -/ @[simps] protected def dual : (α →o β) ≃ (αᵒᵈ →o βᵒᵈ) where toFun f := ⟨(OrderDual.toDual : β → βᵒᵈ) ∘ (f : α → β) ∘ (OrderDual.ofDual : αᵒᵈ → α), f.mono.dual⟩ invFun f := ⟨OrderDual.ofDual ∘ f ∘ OrderDual.toDual, f.mono.dual⟩ left_inv _ := rfl right_inv _ := rfl #align order_hom.dual OrderHom.dual #align order_hom.dual_apply_coe OrderHom.dual_apply_coe #align order_hom.dual_symm_apply_coe OrderHom.dual_symm_apply_coe -- Porting note: We used to be able to write `(OrderHom.id : α →o α).dual` here rather than -- `OrderHom.dual (OrderHom.id : α →o α)`. -- See https://github.com/leanprover/lean4/issues/1910 @[simp] theorem dual_id : OrderHom.dual (OrderHom.id : α →o α) = OrderHom.id := rfl #align order_hom.dual_id OrderHom.dual_id @[simp] theorem dual_comp (g : β →o γ) (f : α →o β) : OrderHom.dual (g.comp f) = (OrderHom.dual g).comp (OrderHom.dual f) := rfl #align order_hom.dual_comp OrderHom.dual_comp @[simp] theorem symm_dual_id : OrderHom.dual.symm OrderHom.id = (OrderHom.id : α →o α) := rfl #align order_hom.symm_dual_id OrderHom.symm_dual_id @[simp] theorem symm_dual_comp (g : βᵒᵈ →o γᵒᵈ) (f : αᵒᵈ →o βᵒᵈ) : OrderHom.dual.symm (g.comp f) = (OrderHom.dual.symm g).comp (OrderHom.dual.symm f) := rfl #align order_hom.symm_dual_comp OrderHom.symm_dual_comp /-- `OrderHom.dual` as an order isomorphism. -/ def dualIso (α β : Type*) [Preorder α] [Preorder β] : (α →o β) ≃o (αᵒᵈ →o βᵒᵈ)ᵒᵈ where toEquiv := OrderHom.dual.trans OrderDual.toDual map_rel_iff' := Iff.rfl #align order_hom.dual_iso OrderHom.dualIso /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `WithBot α →o WithBot β`. -/ @[simps (config := .asFn)] protected def withBotMap (f : α →o β) : WithBot α →o WithBot β := ⟨WithBot.map f, f.mono.withBot_map⟩ #align order_hom.with_bot_map OrderHom.withBotMap #align order_hom.with_bot_map_coe OrderHom.withBotMap_coe /-- Lift an order homomorphism `f : α →o β` to an order homomorphism `WithTop α →o WithTop β`. -/ @[simps (config := .asFn)] protected def withTopMap (f : α →o β) : WithTop α →o WithTop β := ⟨WithTop.map f, f.mono.withTop_map⟩ #align order_hom.with_top_map OrderHom.withTopMap #align order_hom.with_top_map_coe OrderHom.withTopMap_coe end OrderHom /-- Embeddings of partial orders that preserve `<` also preserve `≤`. -/ def RelEmbedding.orderEmbeddingOfLTEmbedding [PartialOrder α] [PartialOrder β] (f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) : α ↪o β := { f with map_rel_iff' := by intros simp [le_iff_lt_or_eq, f.map_rel_iff, f.injective.eq_iff] } #align rel_embedding.order_embedding_of_lt_embedding RelEmbedding.orderEmbeddingOfLTEmbedding @[simp] theorem RelEmbedding.orderEmbeddingOfLTEmbedding_apply [PartialOrder α] [PartialOrder β] {f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)} {x : α} : RelEmbedding.orderEmbeddingOfLTEmbedding f x = f x := rfl #align rel_embedding.order_embedding_of_lt_embedding_apply RelEmbedding.orderEmbeddingOfLTEmbedding_apply namespace OrderEmbedding variable [Preorder α] [Preorder β] (f : α ↪o β) /-- `<` is preserved by order embeddings of preorders. -/ def ltEmbedding : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop) := { f with map_rel_iff' := by intros; simp [lt_iff_le_not_le, f.map_rel_iff] } #align order_embedding.lt_embedding OrderEmbedding.ltEmbedding @[simp] theorem ltEmbedding_apply (x : α) : f.ltEmbedding x = f x := rfl #align order_embedding.lt_embedding_apply OrderEmbedding.ltEmbedding_apply @[simp] theorem le_iff_le {a b} : f a ≤ f b ↔ a ≤ b := f.map_rel_iff #align order_embedding.le_iff_le OrderEmbedding.le_iff_le @[simp] theorem lt_iff_lt {a b} : f a < f b ↔ a < b := f.ltEmbedding.map_rel_iff #align order_embedding.lt_iff_lt OrderEmbedding.lt_iff_lt theorem eq_iff_eq {a b} : f a = f b ↔ a = b := f.injective.eq_iff #align order_embedding.eq_iff_eq OrderEmbedding.eq_iff_eq protected theorem monotone : Monotone f := OrderHomClass.monotone f #align order_embedding.monotone OrderEmbedding.monotone protected theorem strictMono : StrictMono f := fun _ _ => f.lt_iff_lt.2 #align order_embedding.strict_mono OrderEmbedding.strictMono protected theorem acc (a : α) : Acc (· < ·) (f a) → Acc (· < ·) a := f.ltEmbedding.acc a #align order_embedding.acc OrderEmbedding.acc protected theorem wellFounded : WellFounded ((· < ·) : β → β → Prop) → WellFounded ((· < ·) : α → α → Prop) := f.ltEmbedding.wellFounded #align order_embedding.well_founded OrderEmbedding.wellFounded protected theorem isWellOrder [IsWellOrder β (· < ·)] : IsWellOrder α (· < ·) := f.ltEmbedding.isWellOrder #align order_embedding.is_well_order OrderEmbedding.isWellOrder /-- An order embedding is also an order embedding between dual orders. -/ protected def dual : αᵒᵈ ↪o βᵒᵈ := ⟨f.toEmbedding, f.map_rel_iff⟩ #align order_embedding.dual OrderEmbedding.dual /-- A preorder which embeds into a well-founded preorder is itself well-founded. -/ protected theorem wellFoundedLT [WellFoundedLT β] : WellFoundedLT α where wf := f.wellFounded IsWellFounded.wf /-- A preorder which embeds into a preorder in which `(· > ·)` is well-founded also has `(· > ·)` well-founded. -/ protected theorem wellFoundedGT [WellFoundedGT β] : WellFoundedGT α := @OrderEmbedding.wellFoundedLT αᵒᵈ _ _ _ f.dual _ /-- A version of `WithBot.map` for order embeddings. -/ @[simps (config := .asFn)] protected def withBotMap (f : α ↪o β) : WithBot α ↪o WithBot β := { f.toEmbedding.optionMap with toFun := WithBot.map f, map_rel_iff' := @fun a b => WithBot.map_le_iff f f.map_rel_iff a b } #align order_embedding.with_bot_map OrderEmbedding.withBotMap #align order_embedding.with_bot_map_apply OrderEmbedding.withBotMap_apply /-- A version of `WithTop.map` for order embeddings. -/ @[simps (config := .asFn)] protected def withTopMap (f : α ↪o β) : WithTop α ↪o WithTop β := { f.dual.withBotMap.dual with toFun := WithTop.map f } #align order_embedding.with_top_map OrderEmbedding.withTopMap #align order_embedding.with_top_map_apply OrderEmbedding.withTopMap_apply /-- To define an order embedding from a partial order to a preorder it suffices to give a function together with a proof that it satisfies `f a ≤ f b ↔ a ≤ b`. -/ def ofMapLEIff {α β} [PartialOrder α] [Preorder β] (f : α → β) (hf : ∀ a b, f a ≤ f b ↔ a ≤ b) : α ↪o β := RelEmbedding.ofMapRelIff f hf #align order_embedding.of_map_le_iff OrderEmbedding.ofMapLEIff @[simp] theorem coe_ofMapLEIff {α β} [PartialOrder α] [Preorder β] {f : α → β} (h) : ⇑(ofMapLEIff f h) = f := rfl #align order_embedding.coe_of_map_le_iff OrderEmbedding.coe_ofMapLEIff /-- A strictly monotone map from a linear order is an order embedding. -/ def ofStrictMono {α β} [LinearOrder α] [Preorder β] (f : α → β) (h : StrictMono f) : α ↪o β := ofMapLEIff f fun _ _ => h.le_iff_le #align order_embedding.of_strict_mono OrderEmbedding.ofStrictMono @[simp] theorem coe_ofStrictMono {α β} [LinearOrder α] [Preorder β] {f : α → β} (h : StrictMono f) : ⇑(ofStrictMono f h) = f := rfl #align order_embedding.coe_of_strict_mono OrderEmbedding.coe_ofStrictMono /-- Embedding of a subtype into the ambient type as an `OrderEmbedding`. -/ @[simps! (config := .asFn)] def subtype (p : α → Prop) : Subtype p ↪o α := ⟨Function.Embedding.subtype p, Iff.rfl⟩ #align order_embedding.subtype OrderEmbedding.subtype #align order_embedding.subtype_apply OrderEmbedding.subtype_apply /-- Convert an `OrderEmbedding` to an `OrderHom`. -/ @[simps (config := .asFn)] def toOrderHom {X Y : Type*} [Preorder X] [Preorder Y] (f : X ↪o Y) : X →o Y where toFun := f monotone' := f.monotone #align order_embedding.to_order_hom OrderEmbedding.toOrderHom #align order_embedding.to_order_hom_coe OrderEmbedding.toOrderHom_coe /-- The trivial embedding from an empty preorder to another preorder -/ @[simps] def ofIsEmpty [IsEmpty α] : α ↪o β where toFun := isEmptyElim inj' := isEmptyElim map_rel_iff' {a} := isEmptyElim a @[simp, norm_cast] lemma coe_ofIsEmpty [IsEmpty α] : (ofIsEmpty : α ↪o β) = (isEmptyElim : α → β) := rfl end OrderEmbedding section Disjoint variable [PartialOrder α] [PartialOrder β] (f : OrderEmbedding α β) /-- If the images by an order embedding of two elements are disjoint, then they are themselves disjoint. -/ lemma Disjoint.of_orderEmbedding [OrderBot α] [OrderBot β] {a₁ a₂ : α} : Disjoint (f a₁) (f a₂) → Disjoint a₁ a₂ := by intro h x h₁ h₂ rw [← f.le_iff_le] at h₁ h₂ ⊢ calc f x ≤ ⊥ := h h₁ h₂ _ ≤ f ⊥ := bot_le /-- If the images by an order embedding of two elements are codisjoint, then they are themselves codisjoint. -/ lemma Codisjoint.of_orderEmbedding [OrderTop α] [OrderTop β] {a₁ a₂ : α} : Codisjoint (f a₁) (f a₂) → Codisjoint a₁ a₂ := Disjoint.of_orderEmbedding (α := αᵒᵈ) (β := βᵒᵈ) f.dual /-- If the images by an order embedding of two elements are complements, then they are themselves complements. -/ lemma IsCompl.of_orderEmbedding [BoundedOrder α] [BoundedOrder β] {a₁ a₂ : α} : IsCompl (f a₁) (f a₂) → IsCompl a₁ a₂ := fun ⟨hd, hcd⟩ ↦ ⟨Disjoint.of_orderEmbedding f hd, Codisjoint.of_orderEmbedding f hcd⟩ end Disjoint section RelHom variable [PartialOrder α] [Preorder β] namespace RelHom variable (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop)) /-- A bundled expression of the fact that a map between partial orders that is strictly monotone is weakly monotone. -/ @[simps (config := .asFn)] def toOrderHom : α →o β where toFun := f monotone' := StrictMono.monotone fun _ _ => f.map_rel #align rel_hom.to_order_hom RelHom.toOrderHom #align rel_hom.to_order_hom_coe RelHom.toOrderHom_coe end RelHom theorem RelEmbedding.toOrderHom_injective (f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) : Function.Injective (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop)).toOrderHom := fun _ _ h => f.injective h #align rel_embedding.to_order_hom_injective RelEmbedding.toOrderHom_injective end RelHom namespace OrderIso section LE variable [LE α] [LE β] [LE γ] instance : EquivLike (α ≃o β) α β where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by obtain ⟨⟨_, _⟩, _⟩ := f obtain ⟨⟨_, _⟩, _⟩ := g congr instance : OrderIsoClass (α ≃o β) α β where map_le_map_iff f _ _ := f.map_rel_iff' @[simp] theorem toFun_eq_coe {f : α ≃o β} : f.toFun = f := rfl #align order_iso.to_fun_eq_coe OrderIso.toFun_eq_coe -- See note [partially-applied ext lemmas] @[ext] theorem ext {f g : α ≃o β} (h : (f : α → β) = g) : f = g := DFunLike.coe_injective h #align order_iso.ext OrderIso.ext /-- Reinterpret an order isomorphism as an order embedding. -/ def toOrderEmbedding (e : α ≃o β) : α ↪o β := e.toRelEmbedding #align order_iso.to_order_embedding OrderIso.toOrderEmbedding @[simp] theorem coe_toOrderEmbedding (e : α ≃o β) : ⇑e.toOrderEmbedding = e := rfl #align order_iso.coe_to_order_embedding OrderIso.coe_toOrderEmbedding protected theorem bijective (e : α ≃o β) : Function.Bijective e := e.toEquiv.bijective #align order_iso.bijective OrderIso.bijective protected theorem injective (e : α ≃o β) : Function.Injective e := e.toEquiv.injective #align order_iso.injective OrderIso.injective protected theorem surjective (e : α ≃o β) : Function.Surjective e := e.toEquiv.surjective #align order_iso.surjective OrderIso.surjective -- Porting note (#10618): simp can prove this -- @[simp] theorem apply_eq_iff_eq (e : α ≃o β) {x y : α} : e x = e y ↔ x = y := e.toEquiv.apply_eq_iff_eq #align order_iso.apply_eq_iff_eq OrderIso.apply_eq_iff_eq /-- Identity order isomorphism. -/ def refl (α : Type*) [LE α] : α ≃o α := RelIso.refl (· ≤ ·) #align order_iso.refl OrderIso.refl @[simp] theorem coe_refl : ⇑(refl α) = id := rfl #align order_iso.coe_refl OrderIso.coe_refl @[simp] theorem refl_apply (x : α) : refl α x = x := rfl #align order_iso.refl_apply OrderIso.refl_apply @[simp] theorem refl_toEquiv : (refl α).toEquiv = Equiv.refl α := rfl #align order_iso.refl_to_equiv OrderIso.refl_toEquiv /-- Inverse of an order isomorphism. -/ def symm (e : α ≃o β) : β ≃o α := RelIso.symm e #align order_iso.symm OrderIso.symm @[simp] theorem apply_symm_apply (e : α ≃o β) (x : β) : e (e.symm x) = x := e.toEquiv.apply_symm_apply x #align order_iso.apply_symm_apply OrderIso.apply_symm_apply @[simp] theorem symm_apply_apply (e : α ≃o β) (x : α) : e.symm (e x) = x := e.toEquiv.symm_apply_apply x #align order_iso.symm_apply_apply OrderIso.symm_apply_apply @[simp] theorem symm_refl (α : Type*) [LE α] : (refl α).symm = refl α := rfl #align order_iso.symm_refl OrderIso.symm_refl theorem apply_eq_iff_eq_symm_apply (e : α ≃o β) (x : α) (y : β) : e x = y ↔ x = e.symm y := e.toEquiv.apply_eq_iff_eq_symm_apply #align order_iso.apply_eq_iff_eq_symm_apply OrderIso.apply_eq_iff_eq_symm_apply theorem symm_apply_eq (e : α ≃o β) {x : α} {y : β} : e.symm y = x ↔ y = e x := e.toEquiv.symm_apply_eq #align order_iso.symm_apply_eq OrderIso.symm_apply_eq @[simp] theorem symm_symm (e : α ≃o β) : e.symm.symm = e := by ext rfl #align order_iso.symm_symm OrderIso.symm_symm theorem symm_bijective : Function.Bijective (OrderIso.symm : (α ≃o β) → β ≃o α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem symm_injective : Function.Injective (symm : α ≃o β → β ≃o α) := symm_bijective.injective #align order_iso.symm_injective OrderIso.symm_injective @[simp] theorem toEquiv_symm (e : α ≃o β) : e.toEquiv.symm = e.symm.toEquiv := rfl #align order_iso.to_equiv_symm OrderIso.toEquiv_symm /-- Composition of two order isomorphisms is an order isomorphism. -/ @[trans] def trans (e : α ≃o β) (e' : β ≃o γ) : α ≃o γ := RelIso.trans e e' #align order_iso.trans OrderIso.trans @[simp] theorem coe_trans (e : α ≃o β) (e' : β ≃o γ) : ⇑(e.trans e') = e' ∘ e := rfl #align order_iso.coe_trans OrderIso.coe_trans @[simp] theorem trans_apply (e : α ≃o β) (e' : β ≃o γ) (x : α) : e.trans e' x = e' (e x) := rfl #align order_iso.trans_apply OrderIso.trans_apply @[simp] theorem refl_trans (e : α ≃o β) : (refl α).trans e = e := by ext x rfl #align order_iso.refl_trans OrderIso.refl_trans @[simp] theorem trans_refl (e : α ≃o β) : e.trans (refl β) = e := by ext x rfl #align order_iso.trans_refl OrderIso.trans_refl @[simp] theorem symm_trans_apply (e₁ : α ≃o β) (e₂ : β ≃o γ) (c : γ) : (e₁.trans e₂).symm c = e₁.symm (e₂.symm c) := rfl #align order_iso.symm_trans_apply OrderIso.symm_trans_apply theorem symm_trans (e₁ : α ≃o β) (e₂ : β ≃o γ) : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl #align order_iso.symm_trans OrderIso.symm_trans @[simp] theorem self_trans_symm (e : α ≃o β) : e.trans e.symm = OrderIso.refl α := RelIso.self_trans_symm e @[simp] theorem symm_trans_self (e : α ≃o β) : e.symm.trans e = OrderIso.refl β := RelIso.symm_trans_self e /-- An order isomorphism between the domains and codomains of two prosets of order homomorphisms gives an order isomorphism between the two function prosets. -/ @[simps apply symm_apply] def arrowCongr {α β γ δ} [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] (f : α ≃o γ) (g : β ≃o δ) : (α →o β) ≃o (γ →o δ) where toFun p := .comp g <| .comp p f.symm invFun p := .comp g.symm <| .comp p f left_inv p := DFunLike.coe_injective <| by change (g.symm ∘ g) ∘ p ∘ (f.symm ∘ f) = p simp only [← DFunLike.coe_eq_coe_fn, ← OrderIso.coe_trans, Function.id_comp, OrderIso.self_trans_symm, OrderIso.coe_refl, Function.comp_id] right_inv p := DFunLike.coe_injective <| by change (g ∘ g.symm) ∘ p ∘ (f ∘ f.symm) = p simp only [← DFunLike.coe_eq_coe_fn, ← OrderIso.coe_trans, Function.id_comp, OrderIso.symm_trans_self, OrderIso.coe_refl, Function.comp_id] map_rel_iff' {p q} := by simp only [Equiv.coe_fn_mk, OrderHom.le_def, OrderHom.comp_coe, OrderHomClass.coe_coe, Function.comp_apply, map_le_map_iff] exact Iff.symm f.forall_congr_left' /-- If `α` and `β` are order-isomorphic then the two orders of order-homomorphisms from `α` and `β` to themselves are order-isomorphic. -/ @[simps! apply symm_apply] def conj {α β} [Preorder α] [Preorder β] (f : α ≃o β) : (α →o α) ≃ (β →o β) := arrowCongr f f /-- `Prod.swap` as an `OrderIso`. -/ def prodComm : α × β ≃o β × α where toEquiv := Equiv.prodComm α β map_rel_iff' := Prod.swap_le_swap #align order_iso.prod_comm OrderIso.prodComm @[simp] theorem coe_prodComm : ⇑(prodComm : α × β ≃o β × α) = Prod.swap := rfl #align order_iso.coe_prod_comm OrderIso.coe_prodComm @[simp] theorem prodComm_symm : (prodComm : α × β ≃o β × α).symm = prodComm := rfl #align order_iso.prod_comm_symm OrderIso.prodComm_symm variable (α) /-- The order isomorphism between a type and its double dual. -/ def dualDual : α ≃o αᵒᵈᵒᵈ := refl α #align order_iso.dual_dual OrderIso.dualDual @[simp] theorem coe_dualDual : ⇑(dualDual α) = toDual ∘ toDual := rfl #align order_iso.coe_dual_dual OrderIso.coe_dualDual @[simp] theorem coe_dualDual_symm : ⇑(dualDual α).symm = ofDual ∘ ofDual := rfl #align order_iso.coe_dual_dual_symm OrderIso.coe_dualDual_symm variable {α} @[simp] theorem dualDual_apply (a : α) : dualDual α a = toDual (toDual a) := rfl #align order_iso.dual_dual_apply OrderIso.dualDual_apply @[simp] theorem dualDual_symm_apply (a : αᵒᵈᵒᵈ) : (dualDual α).symm a = ofDual (ofDual a) := rfl #align order_iso.dual_dual_symm_apply OrderIso.dualDual_symm_apply end LE open Set section LE variable [LE α] [LE β] [LE γ] --@[simp] Porting note (#10618): simp can prove it theorem le_iff_le (e : α ≃o β) {x y : α} : e x ≤ e y ↔ x ≤ y := e.map_rel_iff #align order_iso.le_iff_le OrderIso.le_iff_le theorem le_symm_apply (e : α ≃o β) {x : α} {y : β} : x ≤ e.symm y ↔ e x ≤ y := e.rel_symm_apply #align order_iso.le_symm_apply OrderIso.le_symm_apply theorem symm_apply_le (e : α ≃o β) {x : α} {y : β} : e.symm y ≤ x ↔ y ≤ e x := e.symm_apply_rel #align order_iso.symm_apply_le OrderIso.symm_apply_le end LE variable [Preorder α] [Preorder β] [Preorder γ] protected theorem monotone (e : α ≃o β) : Monotone e := e.toOrderEmbedding.monotone #align order_iso.monotone OrderIso.monotone protected theorem strictMono (e : α ≃o β) : StrictMono e := e.toOrderEmbedding.strictMono #align order_iso.strict_mono OrderIso.strictMono @[simp] theorem lt_iff_lt (e : α ≃o β) {x y : α} : e x < e y ↔ x < y := e.toOrderEmbedding.lt_iff_lt #align order_iso.lt_iff_lt OrderIso.lt_iff_lt /-- Converts an `OrderIso` into a `RelIso (<) (<)`. -/ def toRelIsoLT (e : α ≃o β) : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop) := ⟨e.toEquiv, lt_iff_lt e⟩ #align order_iso.to_rel_iso_lt OrderIso.toRelIsoLT @[simp] theorem toRelIsoLT_apply (e : α ≃o β) (x : α) : e.toRelIsoLT x = e x := rfl #align order_iso.to_rel_iso_lt_apply OrderIso.toRelIsoLT_apply @[simp] theorem toRelIsoLT_symm (e : α ≃o β) : e.toRelIsoLT.symm = e.symm.toRelIsoLT := rfl #align order_iso.to_rel_iso_lt_symm OrderIso.toRelIsoLT_symm /-- Converts a `RelIso (<) (<)` into an `OrderIso`. -/ def ofRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : α ≃o β := ⟨e.toEquiv, by simp [le_iff_eq_or_lt, e.map_rel_iff, e.injective.eq_iff]⟩ #align order_iso.of_rel_iso_lt OrderIso.ofRelIsoLT @[simp] theorem ofRelIsoLT_apply {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) (x : α) : ofRelIsoLT e x = e x := rfl #align order_iso.of_rel_iso_lt_apply OrderIso.ofRelIsoLT_apply @[simp] theorem ofRelIsoLT_symm {α β} [PartialOrder α] [PartialOrder β] (e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : (ofRelIsoLT e).symm = ofRelIsoLT e.symm := rfl #align order_iso.of_rel_iso_lt_symm OrderIso.ofRelIsoLT_symm @[simp]
Mathlib/Order/Hom/Basic.lean
1,118
1,121
theorem ofRelIsoLT_toRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : α ≃o β) : ofRelIsoLT (toRelIsoLT e) = e := by
ext simp
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Scott Morrison, Mario Carneiro, Andrew Yang -/ import Mathlib.Topology.Category.TopCat.EpiMono import Mathlib.Topology.Category.TopCat.Limits.Basic import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.ConcreteCategory import Mathlib.Data.Set.Subsingleton import Mathlib.Tactic.CategoryTheory.Elementwise #align_import topology.category.Top.limits.products from "leanprover-community/mathlib"@"178a32653e369dce2da68dc6b2694e385d484ef1" /-! # Products and coproducts in the category of topological spaces -/ -- Porting note: every ML3 decl has an uppercase letter set_option linter.uppercaseLean3 false open TopologicalSpace open CategoryTheory open CategoryTheory.Limits universe v u w noncomputable section namespace TopCat variable {J : Type v} [SmallCategory J] /-- The projection from the product as a bundled continuous map. -/ abbrev piπ {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : TopCat.of (∀ i, α i) ⟶ α i := ⟨fun f => f i, continuous_apply i⟩ #align Top.pi_π TopCat.piπ /-- The explicit fan of a family of topological spaces given by the pi type. -/ @[simps! pt π_app] def piFan {ι : Type v} (α : ι → TopCat.{max v u}) : Fan α := Fan.mk (TopCat.of (∀ i, α i)) (piπ.{v,u} α) #align Top.pi_fan TopCat.piFan /-- The constructed fan is indeed a limit -/ def piFanIsLimit {ι : Type v} (α : ι → TopCat.{max v u}) : IsLimit (piFan α) where lift S := { toFun := fun s i => S.π.app ⟨i⟩ s continuous_toFun := continuous_pi (fun i => (S.π.app ⟨i⟩).2) } uniq := by intro S m h apply ContinuousMap.ext; intro x funext i set_option tactic.skipAssignedInstances false in dsimp rw [ContinuousMap.coe_mk, ← h ⟨i⟩] rfl fac s j := rfl #align Top.pi_fan_is_limit TopCat.piFanIsLimit /-- The product is homeomorphic to the product of the underlying spaces, equipped with the product topology. -/ def piIsoPi {ι : Type v} (α : ι → TopCat.{max v u}) : ∏ᶜ α ≅ TopCat.of (∀ i, α i) := (limit.isLimit _).conePointUniqueUpToIso (piFanIsLimit.{v, u} α) -- Specifying the universes in `piFanIsLimit` wasn't necessary when we had `TopCatMax`  #align Top.pi_iso_pi TopCat.piIsoPi @[reassoc (attr := simp)] theorem piIsoPi_inv_π {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : (piIsoPi α).inv ≫ Pi.π α i = piπ α i := by simp [piIsoPi] #align Top.pi_iso_pi_inv_π TopCat.piIsoPi_inv_π theorem piIsoPi_inv_π_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) (x : ∀ i, α i) : (Pi.π α i : _) ((piIsoPi α).inv x) = x i := ConcreteCategory.congr_hom (piIsoPi_inv_π α i) x #align Top.pi_iso_pi_inv_π_apply TopCat.piIsoPi_inv_π_apply -- Porting note: needing the type ascription on `∏ᶜ α : TopCat.{max v u}` is unfortunate. theorem piIsoPi_hom_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) (x : (∏ᶜ α : TopCat.{max v u})) : (piIsoPi α).hom x i = (Pi.π α i : _) x := by have := piIsoPi_inv_π α i rw [Iso.inv_comp_eq] at this exact ConcreteCategory.congr_hom this x #align Top.pi_iso_pi_hom_apply TopCat.piIsoPi_hom_apply -- Porting note: Lean doesn't automatically reduce TopCat.of X|>.α to X now /-- The inclusion to the coproduct as a bundled continuous map. -/ abbrev sigmaι {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : α i ⟶ TopCat.of (Σi, α i) := by refine ContinuousMap.mk ?_ ?_ · dsimp apply Sigma.mk i · dsimp; continuity #align Top.sigma_ι TopCat.sigmaι /-- The explicit cofan of a family of topological spaces given by the sigma type. -/ @[simps! pt ι_app] def sigmaCofan {ι : Type v} (α : ι → TopCat.{max v u}) : Cofan α := Cofan.mk (TopCat.of (Σi, α i)) (sigmaι α) #align Top.sigma_cofan TopCat.sigmaCofan /-- The constructed cofan is indeed a colimit -/ def sigmaCofanIsColimit {ι : Type v} (β : ι → TopCat.{max v u}) : IsColimit (sigmaCofan β) where desc S := { toFun := fun (s : of (Σ i, β i)) => S.ι.app ⟨s.1⟩ s.2 continuous_toFun := continuous_sigma fun i => (S.ι.app ⟨i⟩).continuous_toFun } uniq := by intro S m h ext ⟨i, x⟩ simp only [hom_apply, ← h] congr fac s j := by cases j aesop_cat #align Top.sigma_cofan_is_colimit TopCat.sigmaCofanIsColimit /-- The coproduct is homeomorphic to the disjoint union of the topological spaces. -/ def sigmaIsoSigma {ι : Type v} (α : ι → TopCat.{max v u}) : ∐ α ≅ TopCat.of (Σi, α i) := (colimit.isColimit _).coconePointUniqueUpToIso (sigmaCofanIsColimit.{v, u} α) -- Specifying the universes in `sigmaCofanIsColimit` wasn't necessary when we had `TopCatMax`  #align Top.sigma_iso_sigma TopCat.sigmaIsoSigma @[reassoc (attr := simp)] theorem sigmaIsoSigma_hom_ι {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : Sigma.ι α i ≫ (sigmaIsoSigma α).hom = sigmaι α i := by simp [sigmaIsoSigma] #align Top.sigma_iso_sigma_hom_ι TopCat.sigmaIsoSigma_hom_ι theorem sigmaIsoSigma_hom_ι_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) (x : α i) : (sigmaIsoSigma α).hom ((Sigma.ι α i : _) x) = Sigma.mk i x := ConcreteCategory.congr_hom (sigmaIsoSigma_hom_ι α i) x #align Top.sigma_iso_sigma_hom_ι_apply TopCat.sigmaIsoSigma_hom_ι_apply theorem sigmaIsoSigma_inv_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) (x : α i) : (sigmaIsoSigma α).inv ⟨i, x⟩ = (Sigma.ι α i : _) x := by rw [← sigmaIsoSigma_hom_ι_apply, ← comp_app, ← comp_app, Iso.hom_inv_id, Category.comp_id] #align Top.sigma_iso_sigma_inv_apply TopCat.sigmaIsoSigma_inv_apply -- Porting note: cannot use .topologicalSpace in place .str theorem induced_of_isLimit {F : J ⥤ TopCat.{max v u}} (C : Cone F) (hC : IsLimit C) : C.pt.str = ⨅ j, (F.obj j).str.induced (C.π.app j) := by let homeo := homeoOfIso (hC.conePointUniqueUpToIso (limitConeInfiIsLimit F)) refine homeo.inducing.induced.trans ?_ change induced homeo (⨅ j : J, _) = _ simp [induced_iInf, induced_compose] rfl #align Top.induced_of_is_limit TopCat.induced_of_isLimit theorem limit_topology (F : J ⥤ TopCat.{max v u}) : (limit F).str = ⨅ j, (F.obj j).str.induced (limit.π F j) := induced_of_isLimit _ (limit.isLimit F) #align Top.limit_topology TopCat.limit_topology section Prod -- Porting note: why is autoParam not firing? /-- The first projection from the product. -/ abbrev prodFst {X Y : TopCat.{u}} : TopCat.of (X × Y) ⟶ X := ⟨Prod.fst, by continuity⟩ #align Top.prod_fst TopCat.prodFst /-- The second projection from the product. -/ abbrev prodSnd {X Y : TopCat.{u}} : TopCat.of (X × Y) ⟶ Y := ⟨Prod.snd, by continuity⟩ #align Top.prod_snd TopCat.prodSnd /-- The explicit binary cofan of `X, Y` given by `X × Y`. -/ def prodBinaryFan (X Y : TopCat.{u}) : BinaryFan X Y := BinaryFan.mk prodFst prodSnd #align Top.prod_binary_fan TopCat.prodBinaryFan /-- The constructed binary fan is indeed a limit -/ def prodBinaryFanIsLimit (X Y : TopCat.{u}) : IsLimit (prodBinaryFan X Y) where lift := fun S : BinaryFan X Y => { toFun := fun s => (S.fst s, S.snd s) -- Porting note: continuity failed again here. Lean cannot infer -- ContinuousMapClass (X ⟶ Y) X Y for X Y : TopCat which may be one of the problems continuous_toFun := Continuous.prod_mk (BinaryFan.fst S).continuous_toFun (BinaryFan.snd S).continuous_toFun } fac := by rintro S (_ | _) <;> {dsimp; ext; rfl} uniq := by intro S m h -- Porting note: used to be `ext x` refine ContinuousMap.ext (fun (x : ↥(S.pt)) => Prod.ext ?_ ?_) · specialize h ⟨WalkingPair.left⟩ apply_fun fun e => e x at h exact h · specialize h ⟨WalkingPair.right⟩ apply_fun fun e => e x at h exact h #align Top.prod_binary_fan_is_limit TopCat.prodBinaryFanIsLimit /-- The homeomorphism between `X ⨯ Y` and the set-theoretic product of `X` and `Y`, equipped with the product topology. -/ def prodIsoProd (X Y : TopCat.{u}) : X ⨯ Y ≅ TopCat.of (X × Y) := (limit.isLimit _).conePointUniqueUpToIso (prodBinaryFanIsLimit X Y) #align Top.prod_iso_prod TopCat.prodIsoProd @[reassoc (attr := simp)] theorem prodIsoProd_hom_fst (X Y : TopCat.{u}) : (prodIsoProd X Y).hom ≫ prodFst = Limits.prod.fst := by simp [← Iso.eq_inv_comp, prodIsoProd] rfl #align Top.prod_iso_prod_hom_fst TopCat.prodIsoProd_hom_fst @[reassoc (attr := simp)] theorem prodIsoProd_hom_snd (X Y : TopCat.{u}) : (prodIsoProd X Y).hom ≫ prodSnd = Limits.prod.snd := by simp [← Iso.eq_inv_comp, prodIsoProd] rfl #align Top.prod_iso_prod_hom_snd TopCat.prodIsoProd_hom_snd -- Porting note: need to force Lean to coerce X × Y to a type theorem prodIsoProd_hom_apply {X Y : TopCat.{u}} (x : ↑ (X ⨯ Y)) : (prodIsoProd X Y).hom x = ((Limits.prod.fst : X ⨯ Y ⟶ _) x, (Limits.prod.snd : X ⨯ Y ⟶ _) x) := by -- Porting note: ext didn't pick this up apply Prod.ext · exact ConcreteCategory.congr_hom (prodIsoProd_hom_fst X Y) x · exact ConcreteCategory.congr_hom (prodIsoProd_hom_snd X Y) x #align Top.prod_iso_prod_hom_apply TopCat.prodIsoProd_hom_apply @[reassoc (attr := simp), elementwise] theorem prodIsoProd_inv_fst (X Y : TopCat.{u}) : (prodIsoProd X Y).inv ≫ Limits.prod.fst = prodFst := by simp [Iso.inv_comp_eq] #align Top.prod_iso_prod_inv_fst TopCat.prodIsoProd_inv_fst @[reassoc (attr := simp), elementwise]
Mathlib/Topology/Category/TopCat/Limits/Products.lean
234
235
theorem prodIsoProd_inv_snd (X Y : TopCat.{u}) : (prodIsoProd X Y).inv ≫ Limits.prod.snd = prodSnd := by
simp [Iso.inv_comp_eq]
/- Copyright (c) 2022 Antoine Labelle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle -/ import Mathlib.Algebra.Group.Equiv.TypeTags import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.LinearAlgebra.Dual import Mathlib.LinearAlgebra.Contraction import Mathlib.RingTheory.TensorProduct.Basic #align_import representation_theory.basic from "leanprover-community/mathlib"@"c04bc6e93e23aa0182aba53661a2211e80b6feac" /-! # Monoid representations This file introduces monoid representations and their characters and defines a few ways to construct representations. ## Main definitions * Representation.Representation * Representation.character * Representation.tprod * Representation.linHom * Representation.dual ## Implementation notes Representations of a monoid `G` on a `k`-module `V` are implemented as homomorphisms `G →* (V →ₗ[k] V)`. We use the abbreviation `Representation` for this hom space. The theorem `asAlgebraHom_def` constructs a module over the group `k`-algebra of `G` (implemented as `MonoidAlgebra k G`) corresponding to a representation. If `ρ : Representation k G V`, this module can be accessed via `ρ.asModule`. Conversely, given a `MonoidAlgebra k G-module `M` `M.ofModule` is the associociated representation seen as a homomorphism. -/ open MonoidAlgebra (lift of) open LinearMap section variable (k G V : Type*) [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] /-- A representation of `G` on the `k`-module `V` is a homomorphism `G →* (V →ₗ[k] V)`. -/ abbrev Representation := G →* V →ₗ[k] V #align representation Representation end namespace Representation section trivial variable (k : Type*) {G V : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] /-- The trivial representation of `G` on a `k`-module V. -/ def trivial : Representation k G V := 1 #align representation.trivial Representation.trivial -- Porting note: why is `V` implicit theorem trivial_def (g : G) (v : V) : trivial k (V := V) g v = v := rfl #align representation.trivial_def Representation.trivial_def variable {k} /-- A predicate for representations that fix every element. -/ class IsTrivial (ρ : Representation k G V) : Prop where out : ∀ g x, ρ g x = x := by aesop instance : IsTrivial (trivial k (G := G) (V := V)) where @[simp] theorem apply_eq_self (ρ : Representation k G V) (g : G) (x : V) [h : IsTrivial ρ] : ρ g x = x := h.out g x end trivial section MonoidAlgebra variable {k G V : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] variable (ρ : Representation k G V) /-- A `k`-linear representation of `G` on `V` can be thought of as an algebra map from `MonoidAlgebra k G` into the `k`-linear endomorphisms of `V`. -/ noncomputable def asAlgebraHom : MonoidAlgebra k G →ₐ[k] Module.End k V := (lift k G _) ρ #align representation.as_algebra_hom Representation.asAlgebraHom theorem asAlgebraHom_def : asAlgebraHom ρ = (lift k G _) ρ := rfl #align representation.as_algebra_hom_def Representation.asAlgebraHom_def @[simp]
Mathlib/RepresentationTheory/Basic.lean
106
107
theorem asAlgebraHom_single (g : G) (r : k) : asAlgebraHom ρ (Finsupp.single g r) = r • ρ g := by
simp only [asAlgebraHom_def, MonoidAlgebra.lift_single]
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.LinearAlgebra.Finsupp import Mathlib.LinearAlgebra.Prod import Mathlib.SetTheory.Cardinal.Basic import Mathlib.Tactic.FinCases import Mathlib.Tactic.LinearCombination import Mathlib.Lean.Expr.ExtraRecognizers import Mathlib.Data.Set.Subsingleton #align_import linear_algebra.linear_independent from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Linear independence This file defines linear independence in a module or vector space. It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light. We define `LinearIndependent R v` as `ker (Finsupp.total ι M R v) = ⊥`. Here `Finsupp.total` is the linear map sending a function `f : ι →₀ R` with finite support to the linear combination of vectors from `v` with these coefficients. Then we prove that several other statements are equivalent to this one, including injectivity of `Finsupp.total ι M R v` and some versions with explicitly written linear combinations. ## Main definitions All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or vector space and `ι : Type*` is an arbitrary indexing type. * `LinearIndependent R v` states that the elements of the family `v` are linearly independent. * `LinearIndependent.repr hv x` returns the linear combination representing `x : span R (range v)` on the linearly independent vectors `v`, given `hv : LinearIndependent R v` (using classical choice). `LinearIndependent.repr hv` is provided as a linear map. ## Main statements We prove several specialized tests for linear independence of families of vectors and of sets of vectors. * `Fintype.linearIndependent_iff`: if `ι` is a finite type, then any function `f : ι → R` has finite support, so we can reformulate the statement using `∑ i : ι, f i • v i` instead of a sum over an auxiliary `s : Finset ι`; * `linearIndependent_empty_type`: a family indexed by an empty type is linearly independent; * `linearIndependent_unique_iff`: if `ι` is a singleton, then `LinearIndependent K v` is equivalent to `v default ≠ 0`; * `linearIndependent_option`, `linearIndependent_sum`, `linearIndependent_fin_cons`, `linearIndependent_fin_succ`: type-specific tests for linear independence of families of vector fields; * `linearIndependent_insert`, `linearIndependent_union`, `linearIndependent_pair`, `linearIndependent_singleton`: linear independence tests for set operations. In many cases we additionally provide dot-style operations (e.g., `LinearIndependent.union`) to make the linear independence tests usable as `hv.insert ha` etc. We also prove that, when working over a division ring, any family of vectors includes a linear independent subfamily spanning the same subspace. ## Implementation notes We use families instead of sets because it allows us to say that two identical vectors are linearly dependent. If you want to use sets, use the family `(fun x ↦ x : s → M)` given a set `s : Set M`. The lemmas `LinearIndependent.to_subtype_range` and `LinearIndependent.of_subtype_range` connect those two worlds. ## Tags linearly dependent, linear dependence, linearly independent, linear independence -/ noncomputable section open Function Set Submodule open Cardinal universe u' u variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*} variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*} section Module variable {v : ι → M} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M''] variable [Module R M] [Module R M'] [Module R M''] variable {a b : R} {x y : M} variable (R) (v) /-- `LinearIndependent R v` states the family of vectors `v` is linearly independent over `R`. -/ def LinearIndependent : Prop := LinearMap.ker (Finsupp.total ι M R v) = ⊥ #align linear_independent LinearIndependent open Lean PrettyPrinter.Delaborator SubExpr in /-- Delaborator for `LinearIndependent` that suggests pretty printing with type hints in case the family of vectors is over a `Set`. Type hints look like `LinearIndependent fun (v : ↑s) => ↑v` or `LinearIndependent (ι := ↑s) f`, depending on whether the family is a lambda expression or not. -/ @[delab app.LinearIndependent] def delabLinearIndependent : Delab := whenPPOption getPPNotation <| whenNotPPOption getPPAnalysisSkip <| withOptionAtCurrPos `pp.analysis.skip true do let e ← getExpr guard <| e.isAppOfArity ``LinearIndependent 7 let some _ := (e.getArg! 0).coeTypeSet? | failure let optionsPerPos ← if (e.getArg! 3).isLambda then withNaryArg 3 do return (← read).optionsPerPos.setBool (← getPos) pp.funBinderTypes.name true else withNaryArg 0 do return (← read).optionsPerPos.setBool (← getPos) `pp.analysis.namedArg true withTheReader Context ({· with optionsPerPos}) delab variable {R} {v} theorem linearIndependent_iff : LinearIndependent R v ↔ ∀ l, Finsupp.total ι M R v l = 0 → l = 0 := by simp [LinearIndependent, LinearMap.ker_eq_bot'] #align linear_independent_iff linearIndependent_iff theorem linearIndependent_iff' : LinearIndependent R v ↔ ∀ s : Finset ι, ∀ g : ι → R, ∑ i ∈ s, g i • v i = 0 → ∀ i ∈ s, g i = 0 := linearIndependent_iff.trans ⟨fun hf s g hg i his => have h := hf (∑ i ∈ s, Finsupp.single i (g i)) <| by simpa only [map_sum, Finsupp.total_single] using hg calc g i = (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single i (g i)) := by { rw [Finsupp.lapply_apply, Finsupp.single_eq_same] } _ = ∑ j ∈ s, (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single j (g j)) := Eq.symm <| Finset.sum_eq_single i (fun j _hjs hji => by rw [Finsupp.lapply_apply, Finsupp.single_eq_of_ne hji]) fun hnis => hnis.elim his _ = (∑ j ∈ s, Finsupp.single j (g j)) i := (map_sum ..).symm _ = 0 := DFunLike.ext_iff.1 h i, fun hf l hl => Finsupp.ext fun i => _root_.by_contradiction fun hni => hni <| hf _ _ hl _ <| Finsupp.mem_support_iff.2 hni⟩ #align linear_independent_iff' linearIndependent_iff' theorem linearIndependent_iff'' : LinearIndependent R v ↔ ∀ (s : Finset ι) (g : ι → R), (∀ i ∉ s, g i = 0) → ∑ i ∈ s, g i • v i = 0 → ∀ i, g i = 0 := by classical exact linearIndependent_iff'.trans ⟨fun H s g hg hv i => if his : i ∈ s then H s g hv i his else hg i his, fun H s g hg i hi => by convert H s (fun j => if j ∈ s then g j else 0) (fun j hj => if_neg hj) (by simp_rw [ite_smul, zero_smul, Finset.sum_extend_by_zero, hg]) i exact (if_pos hi).symm⟩ #align linear_independent_iff'' linearIndependent_iff'' theorem not_linearIndependent_iff : ¬LinearIndependent R v ↔ ∃ s : Finset ι, ∃ g : ι → R, ∑ i ∈ s, g i • v i = 0 ∧ ∃ i ∈ s, g i ≠ 0 := by rw [linearIndependent_iff'] simp only [exists_prop, not_forall] #align not_linear_independent_iff not_linearIndependent_iff theorem Fintype.linearIndependent_iff [Fintype ι] : LinearIndependent R v ↔ ∀ g : ι → R, ∑ i, g i • v i = 0 → ∀ i, g i = 0 := by refine ⟨fun H g => by simpa using linearIndependent_iff'.1 H Finset.univ g, fun H => linearIndependent_iff''.2 fun s g hg hs i => H _ ?_ _⟩ rw [← hs] refine (Finset.sum_subset (Finset.subset_univ _) fun i _ hi => ?_).symm rw [hg i hi, zero_smul] #align fintype.linear_independent_iff Fintype.linearIndependent_iff /-- A finite family of vectors `v i` is linear independent iff the linear map that sends `c : ι → R` to `∑ i, c i • v i` has the trivial kernel. -/ theorem Fintype.linearIndependent_iff' [Fintype ι] [DecidableEq ι] : LinearIndependent R v ↔ LinearMap.ker (LinearMap.lsum R (fun _ ↦ R) ℕ fun i ↦ LinearMap.id.smulRight (v i)) = ⊥ := by simp [Fintype.linearIndependent_iff, LinearMap.ker_eq_bot', funext_iff] #align fintype.linear_independent_iff' Fintype.linearIndependent_iff' theorem Fintype.not_linearIndependent_iff [Fintype ι] : ¬LinearIndependent R v ↔ ∃ g : ι → R, ∑ i, g i • v i = 0 ∧ ∃ i, g i ≠ 0 := by simpa using not_iff_not.2 Fintype.linearIndependent_iff #align fintype.not_linear_independent_iff Fintype.not_linearIndependent_iff theorem linearIndependent_empty_type [IsEmpty ι] : LinearIndependent R v := linearIndependent_iff.mpr fun v _hv => Subsingleton.elim v 0 #align linear_independent_empty_type linearIndependent_empty_type theorem LinearIndependent.ne_zero [Nontrivial R] (i : ι) (hv : LinearIndependent R v) : v i ≠ 0 := fun h => zero_ne_one' R <| Eq.symm (by suffices (Finsupp.single i 1 : ι →₀ R) i = 0 by simpa rw [linearIndependent_iff.1 hv (Finsupp.single i 1)] · simp · simp [h]) #align linear_independent.ne_zero LinearIndependent.ne_zero lemma LinearIndependent.eq_zero_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x + t • y = 0) : s = 0 ∧ t = 0 := by have := linearIndependent_iff'.1 h Finset.univ ![s, t] simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, h', Finset.mem_univ, forall_true_left] at this exact ⟨this 0, this 1⟩ /-- Also see `LinearIndependent.pair_iff'` for a simpler version over fields. -/ lemma LinearIndependent.pair_iff {x y : M} : LinearIndependent R ![x, y] ↔ ∀ (s t : R), s • x + t • y = 0 → s = 0 ∧ t = 0 := by refine ⟨fun h s t hst ↦ h.eq_zero_of_pair hst, fun h ↦ ?_⟩ apply Fintype.linearIndependent_iff.2 intro g hg simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons] at hg intro i fin_cases i exacts [(h _ _ hg).1, (h _ _ hg).2] /-- A subfamily of a linearly independent family (i.e., a composition with an injective map) is a linearly independent family. -/ theorem LinearIndependent.comp (h : LinearIndependent R v) (f : ι' → ι) (hf : Injective f) : LinearIndependent R (v ∘ f) := by rw [linearIndependent_iff, Finsupp.total_comp] intro l hl have h_map_domain : ∀ x, (Finsupp.mapDomain f l) (f x) = 0 := by rw [linearIndependent_iff.1 h (Finsupp.mapDomain f l) hl]; simp ext x convert h_map_domain x rw [Finsupp.mapDomain_apply hf] #align linear_independent.comp LinearIndependent.comp /-- A family is linearly independent if and only if all of its finite subfamily is linearly independent. -/ theorem linearIndependent_iff_finset_linearIndependent : LinearIndependent R v ↔ ∀ (s : Finset ι), LinearIndependent R (v ∘ (Subtype.val : s → ι)) := ⟨fun H _ ↦ H.comp _ Subtype.val_injective, fun H ↦ linearIndependent_iff'.2 fun s g hg i hi ↦ Fintype.linearIndependent_iff.1 (H s) (g ∘ Subtype.val) (hg ▸ Finset.sum_attach s fun j ↦ g j • v j) ⟨i, hi⟩⟩ theorem LinearIndependent.coe_range (i : LinearIndependent R v) : LinearIndependent R ((↑) : range v → M) := by simpa using i.comp _ (rangeSplitting_injective v) #align linear_independent.coe_range LinearIndependent.coe_range /-- If `v` is a linearly independent family of vectors and the kernel of a linear map `f` is disjoint with the submodule spanned by the vectors of `v`, then `f ∘ v` is a linearly independent family of vectors. See also `LinearIndependent.map'` for a special case assuming `ker f = ⊥`. -/ theorem LinearIndependent.map (hv : LinearIndependent R v) {f : M →ₗ[R] M'} (hf_inj : Disjoint (span R (range v)) (LinearMap.ker f)) : LinearIndependent R (f ∘ v) := by rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, map_le_iff_le_comap, comap_bot, Finsupp.supported_univ, top_inf_eq] at hf_inj unfold LinearIndependent at hv ⊢ rw [hv, le_bot_iff] at hf_inj haveI : Inhabited M := ⟨0⟩ rw [Finsupp.total_comp, Finsupp.lmapDomain_total _ _ f, LinearMap.ker_comp, hf_inj] exact fun _ => rfl #align linear_independent.map LinearIndependent.map /-- If `v` is an injective family of vectors such that `f ∘ v` is linearly independent, then `v` spans a submodule disjoint from the kernel of `f` -/ theorem Submodule.range_ker_disjoint {f : M →ₗ[R] M'} (hv : LinearIndependent R (f ∘ v)) : Disjoint (span R (range v)) (LinearMap.ker f) := by rw [LinearIndependent, Finsupp.total_comp, Finsupp.lmapDomain_total R _ f (fun _ ↦ rfl), LinearMap.ker_comp] at hv rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, hv, inf_bot_eq, map_bot] /-- An injective linear map sends linearly independent families of vectors to linearly independent families of vectors. See also `LinearIndependent.map` for a more general statement. -/ theorem LinearIndependent.map' (hv : LinearIndependent R v) (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) := hv.map <| by simp [hf_inj] #align linear_independent.map' LinearIndependent.map' /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map, `j : M →+ M'` is a monoid map, such that they send non-zero elements to non-zero elements, and compatible with the scalar multiplications on `M` and `M'`, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_injective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : R' → R) (j : M →+ M') (hi : ∀ r, i r = 0 → r = 0) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : LinearIndependent R' (j ∘ v) := by rw [linearIndependent_iff'] at hv ⊢ intro S r' H s hs simp_rw [comp_apply, ← hc, ← map_sum] at H exact hi _ <| hv _ _ (hj _ H) s hs /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map which maps zero to zero, `j : M →+ M'` is a monoid map which sends non-zero elements to non-zero elements, such that the scalar multiplications on `M` and `M'` are compatible, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_surjective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : ZeroHom R R') (j : M →+ M') (hi : Surjective i) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : LinearIndependent R' (j ∘ v) := by obtain ⟨i', hi'⟩ := hi.hasRightInverse refine hv.map_of_injective_injective i' j (fun _ h ↦ ?_) hj fun r m ↦ ?_ · apply_fun i at h rwa [hi', i.map_zero] at h rw [hc (i' r) m, hi'] /-- If the image of a family of vectors under a linear map is linearly independent, then so is the original family. -/ theorem LinearIndependent.of_comp (f : M →ₗ[R] M') (hfv : LinearIndependent R (f ∘ v)) : LinearIndependent R v := linearIndependent_iff'.2 fun s g hg i his => have : (∑ i ∈ s, g i • f (v i)) = 0 := by simp_rw [← map_smul, ← map_sum, hg, f.map_zero] linearIndependent_iff'.1 hfv s g this i his #align linear_independent.of_comp LinearIndependent.of_comp /-- If `f` is an injective linear map, then the family `f ∘ v` is linearly independent if and only if the family `v` is linearly independent. -/ protected theorem LinearMap.linearIndependent_iff (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) ↔ LinearIndependent R v := ⟨fun h => h.of_comp f, fun h => h.map <| by simp only [hf_inj, disjoint_bot_right]⟩ #align linear_map.linear_independent_iff LinearMap.linearIndependent_iff @[nontriviality] theorem linearIndependent_of_subsingleton [Subsingleton R] : LinearIndependent R v := linearIndependent_iff.2 fun _l _hl => Subsingleton.elim _ _ #align linear_independent_of_subsingleton linearIndependent_of_subsingleton theorem linearIndependent_equiv (e : ι ≃ ι') {f : ι' → M} : LinearIndependent R (f ∘ e) ↔ LinearIndependent R f := ⟨fun h => Function.comp_id f ▸ e.self_comp_symm ▸ h.comp _ e.symm.injective, fun h => h.comp _ e.injective⟩ #align linear_independent_equiv linearIndependent_equiv theorem linearIndependent_equiv' (e : ι ≃ ι') {f : ι' → M} {g : ι → M} (h : f ∘ e = g) : LinearIndependent R g ↔ LinearIndependent R f := h ▸ linearIndependent_equiv e #align linear_independent_equiv' linearIndependent_equiv' theorem linearIndependent_subtype_range {ι} {f : ι → M} (hf : Injective f) : LinearIndependent R ((↑) : range f → M) ↔ LinearIndependent R f := Iff.symm <| linearIndependent_equiv' (Equiv.ofInjective f hf) rfl #align linear_independent_subtype_range linearIndependent_subtype_range alias ⟨LinearIndependent.of_subtype_range, _⟩ := linearIndependent_subtype_range #align linear_independent.of_subtype_range LinearIndependent.of_subtype_range theorem linearIndependent_image {ι} {s : Set ι} {f : ι → M} (hf : Set.InjOn f s) : (LinearIndependent R fun x : s => f x) ↔ LinearIndependent R fun x : f '' s => (x : M) := linearIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl #align linear_independent_image linearIndependent_image theorem linearIndependent_span (hs : LinearIndependent R v) : LinearIndependent R (M := span R (range v)) (fun i : ι => ⟨v i, subset_span (mem_range_self i)⟩) := LinearIndependent.of_comp (span R (range v)).subtype hs #align linear_independent_span linearIndependent_span /-- See `LinearIndependent.fin_cons` for a family of elements in a vector space. -/ theorem LinearIndependent.fin_cons' {m : ℕ} (x : M) (v : Fin m → M) (hli : LinearIndependent R v) (x_ortho : ∀ (c : R) (y : Submodule.span R (Set.range v)), c • x + y = (0 : M) → c = 0) : LinearIndependent R (Fin.cons x v : Fin m.succ → M) := by rw [Fintype.linearIndependent_iff] at hli ⊢ rintro g total_eq j simp_rw [Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ] at total_eq have : g 0 = 0 := by refine x_ortho (g 0) ⟨∑ i : Fin m, g i.succ • v i, ?_⟩ total_eq exact sum_mem fun i _ => smul_mem _ _ (subset_span ⟨i, rfl⟩) rw [this, zero_smul, zero_add] at total_eq exact Fin.cases this (hli _ total_eq) j #align linear_independent.fin_cons' LinearIndependent.fin_cons' /-- A set of linearly independent vectors in a module `M` over a semiring `K` is also linearly independent over a subring `R` of `K`. The implementation uses minimal assumptions about the relationship between `R`, `K` and `M`. The version where `K` is an `R`-algebra is `LinearIndependent.restrict_scalars_algebras`. -/ theorem LinearIndependent.restrict_scalars [Semiring K] [SMulWithZero R K] [Module K M] [IsScalarTower R K M] (hinj : Function.Injective fun r : R => r • (1 : K)) (li : LinearIndependent K v) : LinearIndependent R v := by refine linearIndependent_iff'.mpr fun s g hg i hi => hinj ?_ dsimp only; rw [zero_smul] refine (linearIndependent_iff'.mp li : _) _ (g · • (1:K)) ?_ i hi simp_rw [smul_assoc, one_smul] exact hg #align linear_independent.restrict_scalars LinearIndependent.restrict_scalars /-- Every finite subset of a linearly independent set is linearly independent. -/ theorem linearIndependent_finset_map_embedding_subtype (s : Set M) (li : LinearIndependent R ((↑) : s → M)) (t : Finset s) : LinearIndependent R ((↑) : Finset.map (Embedding.subtype s) t → M) := 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, _ha, rfl⟩ := h simp only [Subtype.coe_prop, Embedding.coe_subtype]⟩ convert LinearIndependent.comp li f ?_ rintro ⟨x, hx⟩ ⟨y, hy⟩ rw [Finset.mem_map] at hx hy obtain ⟨a, _ha, rfl⟩ := hx obtain ⟨b, _hb, rfl⟩ := hy simp only [f, imp_self, Subtype.mk_eq_mk] #align linear_independent_finset_map_embedding_subtype linearIndependent_finset_map_embedding_subtype /-- If every finite set of linearly independent vectors has cardinality at most `n`, then the same is true for arbitrary sets of linearly independent vectors. -/ theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : ∀ s : Set M, LinearIndependent R ((↑) : s → M) → #s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply linearIndependent_finset_map_embedding_subtype _ li #align linear_independent_bounded_of_finset_linear_independent_bounded linearIndependent_bounded_of_finset_linearIndependent_bounded section Subtype /-! The following lemmas use the subtype defined by a set in `M` as the index set `ι`. -/ theorem linearIndependent_comp_subtype {s : Set ι} : LinearIndependent R (v ∘ (↑) : s → M) ↔ ∀ l ∈ Finsupp.supported R R s, (Finsupp.total ι M R v) l = 0 → l = 0 := by simp only [linearIndependent_iff, (· ∘ ·), Finsupp.mem_supported, Finsupp.total_apply, Set.subset_def, Finset.mem_coe] constructor · intro h l hl₁ hl₂ have := h (l.subtypeDomain s) ((Finsupp.sum_subtypeDomain_index hl₁).trans hl₂) exact (Finsupp.subtypeDomain_eq_zero_iff hl₁).1 this · intro h l hl refine Finsupp.embDomain_eq_zero.1 (h (l.embDomain <| Function.Embedding.subtype s) ?_ ?_) · suffices ∀ i hi, ¬l ⟨i, hi⟩ = 0 → i ∈ s by simpa intros assumption · rwa [Finsupp.embDomain_eq_mapDomain, Finsupp.sum_mapDomain_index] exacts [fun _ => zero_smul _ _, fun _ _ _ => add_smul _ _ _] #align linear_independent_comp_subtype linearIndependent_comp_subtype theorem linearDependent_comp_subtype' {s : Set ι} : ¬LinearIndependent R (v ∘ (↑) : s → M) ↔ ∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ Finsupp.total ι M R v f = 0 ∧ f ≠ 0 := by simp [linearIndependent_comp_subtype, and_left_comm] #align linear_dependent_comp_subtype' linearDependent_comp_subtype' /-- A version of `linearDependent_comp_subtype'` with `Finsupp.total` unfolded. -/ theorem linearDependent_comp_subtype {s : Set ι} : ¬LinearIndependent R (v ∘ (↑) : s → M) ↔ ∃ f : ι →₀ R, f ∈ Finsupp.supported R R s ∧ ∑ i ∈ f.support, f i • v i = 0 ∧ f ≠ 0 := linearDependent_comp_subtype' #align linear_dependent_comp_subtype linearDependent_comp_subtype theorem linearIndependent_subtype {s : Set M} : LinearIndependent R (fun x => x : s → M) ↔ ∀ l ∈ Finsupp.supported R R s, (Finsupp.total M M R id) l = 0 → l = 0 := by apply linearIndependent_comp_subtype (v := id) #align linear_independent_subtype linearIndependent_subtype theorem linearIndependent_comp_subtype_disjoint {s : Set ι} : LinearIndependent R (v ∘ (↑) : s → M) ↔ Disjoint (Finsupp.supported R R s) (LinearMap.ker <| Finsupp.total ι M R v) := by rw [linearIndependent_comp_subtype, LinearMap.disjoint_ker] #align linear_independent_comp_subtype_disjoint linearIndependent_comp_subtype_disjoint theorem linearIndependent_subtype_disjoint {s : Set M} : LinearIndependent R (fun x => x : s → M) ↔ Disjoint (Finsupp.supported R R s) (LinearMap.ker <| Finsupp.total M M R id) := by apply linearIndependent_comp_subtype_disjoint (v := id) #align linear_independent_subtype_disjoint linearIndependent_subtype_disjoint theorem linearIndependent_iff_totalOn {s : Set M} : LinearIndependent R (fun x => x : s → M) ↔ (LinearMap.ker <| Finsupp.totalOn M M R id s) = ⊥ := by rw [Finsupp.totalOn, LinearMap.ker, LinearMap.comap_codRestrict, Submodule.map_bot, comap_bot, LinearMap.ker_comp, linearIndependent_subtype_disjoint, disjoint_iff_inf_le, ← map_comap_subtype, map_le_iff_le_comap, comap_bot, ker_subtype, le_bot_iff] #align linear_independent_iff_total_on linearIndependent_iff_totalOn theorem LinearIndependent.restrict_of_comp_subtype {s : Set ι} (hs : LinearIndependent R (v ∘ (↑) : s → M)) : LinearIndependent R (s.restrict v) := hs #align linear_independent.restrict_of_comp_subtype LinearIndependent.restrict_of_comp_subtype variable (R M) theorem linearIndependent_empty : LinearIndependent R (fun x => x : (∅ : Set M) → M) := by simp [linearIndependent_subtype_disjoint] #align linear_independent_empty linearIndependent_empty variable {R M} theorem LinearIndependent.mono {t s : Set M} (h : t ⊆ s) : LinearIndependent R (fun x => x : s → M) → LinearIndependent R (fun x => x : t → M) := by simp only [linearIndependent_subtype_disjoint] exact Disjoint.mono_left (Finsupp.supported_mono h) #align linear_independent.mono LinearIndependent.mono theorem linearIndependent_of_finite (s : Set M) (H : ∀ t ⊆ s, Set.Finite t → LinearIndependent R (fun x => x : t → M)) : LinearIndependent R (fun x => x : s → M) := linearIndependent_subtype.2 fun l hl => linearIndependent_subtype.1 (H _ hl (Finset.finite_toSet _)) l (Subset.refl _) #align linear_independent_of_finite linearIndependent_of_finite theorem linearIndependent_iUnion_of_directed {η : Type*} {s : η → Set M} (hs : Directed (· ⊆ ·) s) (h : ∀ i, LinearIndependent R (fun x => x : s i → M)) : LinearIndependent R (fun x => x : (⋃ i, s i) → M) := by by_cases hη : Nonempty η · refine linearIndependent_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)) · refine (linearIndependent_empty R M).mono (t := iUnion (s ·)) ?_ rintro _ ⟨_, ⟨i, _⟩, _⟩ exact hη ⟨i⟩ #align linear_independent_Union_of_directed linearIndependent_iUnion_of_directed theorem linearIndependent_sUnion_of_directed {s : Set (Set M)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, LinearIndependent R ((↑) : ((a : Set M) : Type _) → M)) : LinearIndependent R (fun x => x : ⋃₀ s → M) := by rw [sUnion_eq_iUnion]; exact linearIndependent_iUnion_of_directed hs.directed_val (by simpa using h) #align linear_independent_sUnion_of_directed linearIndependent_sUnion_of_directed theorem linearIndependent_biUnion_of_directed {η} {s : Set η} {t : η → Set M} (hs : DirectedOn (t ⁻¹'o (· ⊆ ·)) s) (h : ∀ a ∈ s, LinearIndependent R (fun x => x : t a → M)) : LinearIndependent R (fun x => x : (⋃ a ∈ s, t a) → M) := by rw [biUnion_eq_iUnion] exact linearIndependent_iUnion_of_directed (directed_comp.2 <| hs.directed_val) (by simpa using h) #align linear_independent_bUnion_of_directed linearIndependent_biUnion_of_directed end Subtype end Module /-! ### Properties which require `Ring R` -/ section Module variable {v : ι → M} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M''] variable [Module R M] [Module R M'] [Module R M''] variable {a b : R} {x y : M} theorem linearIndependent_iff_injective_total : LinearIndependent R v ↔ Function.Injective (Finsupp.total ι M R v) := linearIndependent_iff.trans (injective_iff_map_eq_zero (Finsupp.total ι M R v).toAddMonoidHom).symm #align linear_independent_iff_injective_total linearIndependent_iff_injective_total alias ⟨LinearIndependent.injective_total, _⟩ := linearIndependent_iff_injective_total #align linear_independent.injective_total LinearIndependent.injective_total theorem LinearIndependent.injective [Nontrivial R] (hv : LinearIndependent R v) : Injective v := by intro i j hij let l : ι →₀ R := Finsupp.single i (1 : R) - Finsupp.single j 1 have h_total : Finsupp.total ι M R v l = 0 := by simp_rw [l, LinearMap.map_sub, Finsupp.total_apply] simp [hij] have h_single_eq : Finsupp.single i (1 : R) = Finsupp.single j 1 := by rw [linearIndependent_iff] at hv simp [eq_add_of_sub_eq' (hv l h_total)] simpa [Finsupp.single_eq_single_iff] using h_single_eq #align linear_independent.injective LinearIndependent.injective theorem LinearIndependent.to_subtype_range {ι} {f : ι → M} (hf : LinearIndependent R f) : LinearIndependent R ((↑) : range f → M) := by nontriviality R exact (linearIndependent_subtype_range hf.injective).2 hf #align linear_independent.to_subtype_range LinearIndependent.to_subtype_range theorem LinearIndependent.to_subtype_range' {ι} {f : ι → M} (hf : LinearIndependent R f) {t} (ht : range f = t) : LinearIndependent R ((↑) : t → M) := ht ▸ hf.to_subtype_range #align linear_independent.to_subtype_range' LinearIndependent.to_subtype_range'
Mathlib/LinearAlgebra/LinearIndependent.lean
592
597
theorem LinearIndependent.image_of_comp {ι ι'} (s : Set ι) (f : ι → ι') (g : ι' → M) (hs : LinearIndependent R fun x : s => g (f x)) : LinearIndependent R fun x : f '' s => g x := by
nontriviality R have : InjOn f s := injOn_iff_injective.2 hs.injective.of_comp exact (linearIndependent_equiv' (Equiv.Set.imageOfInjOn f s this) rfl).1 hs
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral #align_import analysis.special_functions.gamma.bohr_mollerup from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090" /-! # Convexity properties of the Gamma function In this file, we prove that `Gamma` and `log ∘ Gamma` are convex functions on the positive real line. We then prove the Bohr-Mollerup theorem, which characterises `Gamma` as the *unique* positive-real-valued, log-convex function on the positive reals satisfying `f (x + 1) = x f x` and `f 1 = 1`. The proof of the Bohr-Mollerup theorem is bound up with the proof of (a weak form of) the Euler limit formula, `Real.BohrMollerup.tendsto_logGammaSeq`, stating that for positive real `x` the sequence `x * log n + log n! - ∑ (m : ℕ) ∈ Finset.range (n + 1), log (x + m)` tends to `log Γ(x)` as `n → ∞`. We prove that any function satisfying the hypotheses of the Bohr-Mollerup theorem must agree with the limit in the Euler limit formula, so there is at most one such function; then we show that `Γ` satisfies these conditions. Since most of the auxiliary lemmas for the Bohr-Mollerup theorem are of no relevance outside the context of this proof, we place them in a separate namespace `Real.BohrMollerup` to avoid clutter. (This includes the logarithmic form of the Euler limit formula, since later we will prove a more general form of the Euler limit formula valid for any real or complex `x`; see `Real.Gamma_seq_tendsto_Gamma` and `Complex.Gamma_seq_tendsto_Gamma` in the file `Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean`.) As an application of the Bohr-Mollerup theorem we prove the Legendre doubling formula for the Gamma function for real positive `s` (which will be upgraded to a proof for all complex `s` in a later file). TODO: This argument can be extended to prove the general `k`-multiplication formula (at least up to a constant, and it should be possible to deduce the value of this constant using Stirling's formula). -/ set_option linter.uppercaseLean3 false noncomputable section open Filter Set MeasureTheory open scoped Nat ENNReal Topology Real section Convexity -- Porting note: move the following lemmas to `Analysis.Convex.Function` variable {𝕜 E β : Type*} {s : Set E} {f g : E → β} [OrderedSemiring 𝕜] [SMul 𝕜 E] [AddCommMonoid E] [OrderedAddCommMonoid β] theorem ConvexOn.congr [SMul 𝕜 β] (hf : ConvexOn 𝕜 s f) (hfg : EqOn f g s) : ConvexOn 𝕜 s g := ⟨hf.1, fun x hx y hy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩ #align convex_on.congr ConvexOn.congr theorem ConcaveOn.congr [SMul 𝕜 β] (hf : ConcaveOn 𝕜 s f) (hfg : EqOn f g s) : ConcaveOn 𝕜 s g := ⟨hf.1, fun x hx y hy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩ #align concave_on.congr ConcaveOn.congr theorem StrictConvexOn.congr [SMul 𝕜 β] (hf : StrictConvexOn 𝕜 s f) (hfg : EqOn f g s) : StrictConvexOn 𝕜 s g := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩ #align strict_convex_on.congr StrictConvexOn.congr theorem StrictConcaveOn.congr [SMul 𝕜 β] (hf : StrictConcaveOn 𝕜 s f) (hfg : EqOn f g s) : StrictConcaveOn 𝕜 s g := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩ #align strict_concave_on.congr StrictConcaveOn.congr theorem ConvexOn.add_const [Module 𝕜 β] (hf : ConvexOn 𝕜 s f) (b : β) : ConvexOn 𝕜 s (f + fun _ => b) := hf.add (convexOn_const _ hf.1) #align convex_on.add_const ConvexOn.add_const theorem ConcaveOn.add_const [Module 𝕜 β] (hf : ConcaveOn 𝕜 s f) (b : β) : ConcaveOn 𝕜 s (f + fun _ => b) := hf.add (concaveOn_const _ hf.1) #align concave_on.add_const ConcaveOn.add_const theorem StrictConvexOn.add_const {γ : Type*} {f : E → γ} [OrderedCancelAddCommMonoid γ] [Module 𝕜 γ] (hf : StrictConvexOn 𝕜 s f) (b : γ) : StrictConvexOn 𝕜 s (f + fun _ => b) := hf.add_convexOn (convexOn_const _ hf.1) #align strict_convex_on.add_const StrictConvexOn.add_const theorem StrictConcaveOn.add_const {γ : Type*} {f : E → γ} [OrderedCancelAddCommMonoid γ] [Module 𝕜 γ] (hf : StrictConcaveOn 𝕜 s f) (b : γ) : StrictConcaveOn 𝕜 s (f + fun _ => b) := hf.add_concaveOn (concaveOn_const _ hf.1) #align strict_concave_on.add_const StrictConcaveOn.add_const end Convexity namespace Real section Convexity /-- Log-convexity of the Gamma function on the positive reals (stated in multiplicative form), proved using the Hölder inequality applied to Euler's integral. -/ theorem Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma {s t a b : ℝ} (hs : 0 < s) (ht : 0 < t) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : Gamma (a * s + b * t) ≤ Gamma s ^ a * Gamma t ^ b := by -- We will apply Hölder's inequality, for the conjugate exponents `p = 1 / a` -- and `q = 1 / b`, to the functions `f a s` and `f b t`, where `f` is as follows: let f : ℝ → ℝ → ℝ → ℝ := fun c u x => exp (-c * x) * x ^ (c * (u - 1)) have e : IsConjExponent (1 / a) (1 / b) := Real.isConjExponent_one_div ha hb hab have hab' : b = 1 - a := by linarith have hst : 0 < a * s + b * t := add_pos (mul_pos ha hs) (mul_pos hb ht) -- some properties of f: have posf : ∀ c u x : ℝ, x ∈ Ioi (0 : ℝ) → 0 ≤ f c u x := fun c u x hx => mul_nonneg (exp_pos _).le (rpow_pos_of_pos hx _).le have posf' : ∀ c u : ℝ, ∀ᵐ x : ℝ ∂volume.restrict (Ioi 0), 0 ≤ f c u x := fun c u => (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ (posf c u)) have fpow : ∀ {c x : ℝ} (_ : 0 < c) (u : ℝ) (_ : 0 < x), exp (-x) * x ^ (u - 1) = f c u x ^ (1 / c) := by intro c x hc u hx dsimp only [f] rw [mul_rpow (exp_pos _).le ((rpow_nonneg hx.le) _), ← exp_mul, ← rpow_mul hx.le] congr 2 <;> field_simp [hc.ne']; ring -- show `f c u` is in `ℒp` for `p = 1/c`: have f_mem_Lp : ∀ {c u : ℝ} (hc : 0 < c) (hu : 0 < u), Memℒp (f c u) (ENNReal.ofReal (1 / c)) (volume.restrict (Ioi 0)) := by intro c u hc hu have A : ENNReal.ofReal (1 / c) ≠ 0 := by rwa [Ne, ENNReal.ofReal_eq_zero, not_le, one_div_pos] have B : ENNReal.ofReal (1 / c) ≠ ∞ := ENNReal.ofReal_ne_top rw [← memℒp_norm_rpow_iff _ A B, ENNReal.toReal_ofReal (one_div_nonneg.mpr hc.le), ENNReal.div_self A B, memℒp_one_iff_integrable] · apply Integrable.congr (GammaIntegral_convergent hu) refine eventuallyEq_of_mem (self_mem_ae_restrict measurableSet_Ioi) fun x hx => ?_ dsimp only rw [fpow hc u hx] congr 1 exact (norm_of_nonneg (posf _ _ x hx)).symm · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi refine (Continuous.continuousOn ?_).mul (ContinuousAt.continuousOn fun x hx => ?_) · exact continuous_exp.comp (continuous_const.mul continuous_id') · exact continuousAt_rpow_const _ _ (Or.inl (mem_Ioi.mp hx).ne') -- now apply Hölder: rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst] convert MeasureTheory.integral_mul_le_Lp_mul_Lq_of_nonneg e (posf' a s) (posf' b t) (f_mem_Lp ha hs) (f_mem_Lp hb ht) using 1 · refine setIntegral_congr measurableSet_Ioi fun x hx => ?_ dsimp only have A : exp (-x) = exp (-a * x) * exp (-b * x) := by rw [← exp_add, ← add_mul, ← neg_add, hab, neg_one_mul] have B : x ^ (a * s + b * t - 1) = x ^ (a * (s - 1)) * x ^ (b * (t - 1)) := by rw [← rpow_add hx, hab']; congr 1; ring rw [A, B] ring · rw [one_div_one_div, one_div_one_div] congr 2 <;> exact setIntegral_congr measurableSet_Ioi fun x hx => fpow (by assumption) _ hx #align real.Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma Real.Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma theorem convexOn_log_Gamma : ConvexOn ℝ (Ioi 0) (log ∘ Gamma) := by refine convexOn_iff_forall_pos.mpr ⟨convex_Ioi _, fun x hx y hy a b ha hb hab => ?_⟩ have : b = 1 - a := by linarith subst this simp_rw [Function.comp_apply, smul_eq_mul] simp only [mem_Ioi] at hx hy rw [← log_rpow, ← log_rpow, ← log_mul] · gcongr exact Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma hx hy ha hb hab all_goals positivity #align real.convex_on_log_Gamma Real.convexOn_log_Gamma theorem convexOn_Gamma : ConvexOn ℝ (Ioi 0) Gamma := by refine ((convexOn_exp.subset (subset_univ _) ?_).comp convexOn_log_Gamma (exp_monotone.monotoneOn _)).congr fun x hx => exp_log (Gamma_pos_of_pos hx) rw [convex_iff_isPreconnected] refine isPreconnected_Ioi.image _ fun x hx => ContinuousAt.continuousWithinAt ?_ refine (differentiableAt_Gamma fun m => ?_).continuousAt.log (Gamma_pos_of_pos hx).ne' exact (neg_lt_iff_pos_add.mpr (add_pos_of_pos_of_nonneg (mem_Ioi.mp hx) (Nat.cast_nonneg m))).ne' #align real.convex_on_Gamma Real.convexOn_Gamma end Convexity section BohrMollerup namespace BohrMollerup /-- The function `n ↦ x log n + log n! - (log x + ... + log (x + n))`, which we will show tends to `log (Gamma x)` as `n → ∞`. -/ def logGammaSeq (x : ℝ) (n : ℕ) : ℝ := x * log n + log n ! - ∑ m ∈ Finset.range (n + 1), log (x + m) #align real.bohr_mollerup.log_gamma_seq Real.BohrMollerup.logGammaSeq variable {f : ℝ → ℝ} {x : ℝ} {n : ℕ} theorem f_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) : f n = f 1 + log (n - 1)! := by refine Nat.le_induction (by simp) (fun m hm IH => ?_) n (Nat.one_le_iff_ne_zero.2 hn) have A : 0 < (m : ℝ) := Nat.cast_pos.2 hm simp only [hf_feq A, Nat.cast_add, Nat.cast_one, Nat.add_succ_sub_one, add_zero] rw [IH, add_assoc, ← log_mul (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)) A.ne', ← Nat.cast_mul] conv_rhs => rw [← Nat.succ_pred_eq_of_pos hm, Nat.factorial_succ, mul_comm] congr exact (Nat.succ_pred_eq_of_pos hm).symm #align real.bohr_mollerup.f_nat_eq Real.BohrMollerup.f_nat_eq theorem f_add_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (n : ℕ) : f (x + n) = f x + ∑ m ∈ Finset.range n, log (x + m) := by induction' n with n hn · simp · have : x + n.succ = x + n + 1 := by push_cast; ring rw [this, hf_feq, hn] · rw [Finset.range_succ, Finset.sum_insert Finset.not_mem_range_self] abel · linarith [(Nat.cast_nonneg n : 0 ≤ (n : ℝ))] #align real.bohr_mollerup.f_add_nat_eq Real.BohrMollerup.f_add_nat_eq /-- Linear upper bound for `f (x + n)` on unit interval -/ theorem f_add_nat_le (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) (hx : 0 < x) (hx' : x ≤ 1) : f (n + x) ≤ f n + x * log n := by have hn' : 0 < (n : ℝ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn) have : f n + x * log n = (1 - x) * f n + x * f (n + 1) := by rw [hf_feq hn']; ring rw [this, (by ring : (n : ℝ) + x = (1 - x) * n + x * (n + 1))] simpa only [smul_eq_mul] using hf_conv.2 hn' (by linarith : 0 < (n + 1 : ℝ)) (by linarith : 0 ≤ 1 - x) hx.le (by linarith) #align real.bohr_mollerup.f_add_nat_le Real.BohrMollerup.f_add_nat_le /-- Linear lower bound for `f (x + n)` on unit interval -/ theorem f_add_nat_ge (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : 2 ≤ n) (hx : 0 < x) : f n + x * log (n - 1) ≤ f (n + x) := by have npos : 0 < (n : ℝ) - 1 := by rw [← Nat.cast_one, sub_pos, Nat.cast_lt]; linarith have c := (convexOn_iff_slope_mono_adjacent.mp <| hf_conv).2 npos (by linarith : 0 < (n : ℝ) + x) (by linarith : (n : ℝ) - 1 < (n : ℝ)) (by linarith) rw [add_sub_cancel_left, sub_sub_cancel, div_one] at c have : f (↑n - 1) = f n - log (↑n - 1) := by -- Porting note: was -- nth_rw_rhs 1 [(by ring : (n : ℝ) = ↑n - 1 + 1)] -- rw [hf_feq npos, add_sub_cancel] rw [eq_sub_iff_add_eq, ← hf_feq npos, sub_add_cancel] rwa [this, le_div_iff hx, sub_sub_cancel, le_sub_iff_add_le, mul_comm _ x, add_comm] at c #align real.bohr_mollerup.f_add_nat_ge Real.BohrMollerup.f_add_nat_ge theorem logGammaSeq_add_one (x : ℝ) (n : ℕ) : logGammaSeq (x + 1) n = logGammaSeq x (n + 1) + log x - (x + 1) * (log (n + 1) - log n) := by dsimp only [Nat.factorial_succ, logGammaSeq] conv_rhs => rw [Finset.sum_range_succ', Nat.cast_zero, add_zero] rw [Nat.cast_mul, log_mul]; rotate_left · rw [Nat.cast_ne_zero]; exact Nat.succ_ne_zero n · rw [Nat.cast_ne_zero]; exact Nat.factorial_ne_zero n have : ∑ m ∈ Finset.range (n + 1), log (x + 1 + ↑m) = ∑ k ∈ Finset.range (n + 1), log (x + ↑(k + 1)) := by congr! 2 with m push_cast abel rw [← this, Nat.cast_add_one n] ring #align real.bohr_mollerup.log_gamma_seq_add_one Real.BohrMollerup.logGammaSeq_add_one theorem le_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≤ 1) (n : ℕ) : f x ≤ f 1 + x * log (n + 1) - x * log n + logGammaSeq x n := by rw [logGammaSeq, ← add_sub_assoc, le_sub_iff_add_le, ← f_add_nat_eq (@hf_feq) hx, add_comm x] refine (f_add_nat_le hf_conv (@hf_feq) (Nat.add_one_ne_zero n) hx hx').trans (le_of_eq ?_) rw [f_nat_eq @hf_feq (by linarith : n + 1 ≠ 0), Nat.add_sub_cancel, Nat.cast_add_one] ring #align real.bohr_mollerup.le_log_gamma_seq Real.BohrMollerup.le_logGammaSeq
Mathlib/Analysis/SpecialFunctions/Gamma/BohrMollerup.lean
278
287
theorem ge_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hn : n ≠ 0) : f 1 + logGammaSeq x n ≤ f x := by
dsimp [logGammaSeq] rw [← add_sub_assoc, sub_le_iff_le_add, ← f_add_nat_eq (@hf_feq) hx, add_comm x _] refine le_trans (le_of_eq ?_) (f_add_nat_ge hf_conv @hf_feq ?_ hx) · rw [f_nat_eq @hf_feq, Nat.add_sub_cancel, Nat.cast_add_one, add_sub_cancel_right] · ring · exact Nat.succ_ne_zero _ · omega
/- Copyright (c) 2021 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import Mathlib.Data.ZMod.Quotient import Mathlib.GroupTheory.NoncommPiCoprod import Mathlib.GroupTheory.OrderOfElement import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Tactic.ByContra import Mathlib.Tactic.Peel #align_import group_theory.exponent from "leanprover-community/mathlib"@"52fa514ec337dd970d71d8de8d0fd68b455a1e54" /-! # Exponent of a group This file defines the exponent of a group, or more generally a monoid. For a group `G` it is defined to be the minimal `n≥1` such that `g ^ n = 1` for all `g ∈ G`. For a finite group `G`, it is equal to the lowest common multiple of the order of all elements of the group `G`. ## Main definitions * `Monoid.ExponentExists` is a predicate on a monoid `G` saying that there is some positive `n` such that `g ^ n = 1` for all `g ∈ G`. * `Monoid.exponent` defines the exponent of a monoid `G` as the minimal positive `n` such that `g ^ n = 1` for all `g ∈ G`, by convention it is `0` if no such `n` exists. * `AddMonoid.ExponentExists` the additive version of `Monoid.ExponentExists`. * `AddMonoid.exponent` the additive version of `Monoid.exponent`. ## Main results * `Monoid.lcm_order_eq_exponent`: For a finite left cancel monoid `G`, the exponent is equal to the `Finset.lcm` of the order of its elements. * `Monoid.exponent_eq_iSup_orderOf(')`: For a commutative cancel monoid, the exponent is equal to `⨆ g : G, orderOf g` (or zero if it has any order-zero elements). * `Monoid.exponent_pi` and `Monoid.exponent_prod`: The exponent of a finite product of monoids is the least common multiple (`Finset.lcm` and `lcm`, respectively) of the exponents of the constituent monoids. * `MonoidHom.exponent_dvd`: If `f : M₁ →⋆ M₂` is surjective, then the exponent of `M₂` divides the exponent of `M₁`. ## TODO * Refactor the characteristic of a ring to be the exponent of its underlying additive group. -/ universe u variable {G : Type u} open scoped Classical namespace Monoid section Monoid variable (G) [Monoid G] /-- A predicate on a monoid saying that there is a positive integer `n` such that `g ^ n = 1` for all `g`. -/ @[to_additive "A predicate on an additive monoid saying that there is a positive integer `n` such\n that `n • g = 0` for all `g`."] def ExponentExists := ∃ n, 0 < n ∧ ∀ g : G, g ^ n = 1 #align monoid.exponent_exists Monoid.ExponentExists #align add_monoid.exponent_exists AddMonoid.ExponentExists /-- The exponent of a group is the smallest positive integer `n` such that `g ^ n = 1` for all `g ∈ G` if it exists, otherwise it is zero by convention. -/ @[to_additive "The exponent of an additive group is the smallest positive integer `n` such that\n `n • g = 0` for all `g ∈ G` if it exists, otherwise it is zero by convention."] noncomputable def exponent := if h : ExponentExists G then Nat.find h else 0 #align monoid.exponent Monoid.exponent #align add_monoid.exponent AddMonoid.exponent variable {G} @[simp] theorem _root_.AddMonoid.exponent_additive : AddMonoid.exponent (Additive G) = exponent G := rfl @[simp] theorem exponent_multiplicative {G : Type*} [AddMonoid G] : exponent (Multiplicative G) = AddMonoid.exponent G := rfl open MulOpposite in @[to_additive (attr := simp)] theorem _root_.MulOpposite.exponent : exponent (MulOpposite G) = exponent G := by simp only [Monoid.exponent, ExponentExists] congr! all_goals exact ⟨(op_injective <| · <| op ·), (unop_injective <| · <| unop ·)⟩ @[to_additive] theorem ExponentExists.isOfFinOrder (h : ExponentExists G) {g : G} : IsOfFinOrder g := isOfFinOrder_iff_pow_eq_one.mpr <| by peel 2 h; exact this g @[to_additive] theorem ExponentExists.orderOf_pos (h : ExponentExists G) (g : G) : 0 < orderOf g := h.isOfFinOrder.orderOf_pos @[to_additive] theorem exponent_ne_zero : exponent G ≠ 0 ↔ ExponentExists G := by rw [exponent] split_ifs with h · simp [h, @not_lt_zero' ℕ] --if this isn't done this way, `to_additive` freaks · tauto #align monoid.exponent_exists_iff_ne_zero Monoid.exponent_ne_zero #align add_monoid.exponent_exists_iff_ne_zero AddMonoid.exponent_ne_zero @[to_additive] protected alias ⟨_, ExponentExists.exponent_ne_zero⟩ := exponent_ne_zero @[to_additive (attr := deprecated (since := "2024-01-27"))] theorem exponentExists_iff_ne_zero : ExponentExists G ↔ exponent G ≠ 0 := exponent_ne_zero.symm @[to_additive] theorem exponent_pos : 0 < exponent G ↔ ExponentExists G := pos_iff_ne_zero.trans exponent_ne_zero @[to_additive] protected alias ⟨_, ExponentExists.exponent_pos⟩ := exponent_pos @[to_additive] theorem exponent_eq_zero_iff : exponent G = 0 ↔ ¬ExponentExists G := exponent_ne_zero.not_right #align monoid.exponent_eq_zero_iff Monoid.exponent_eq_zero_iff #align add_monoid.exponent_eq_zero_iff AddMonoid.exponent_eq_zero_iff @[to_additive exponent_eq_zero_addOrder_zero] theorem exponent_eq_zero_of_order_zero {g : G} (hg : orderOf g = 0) : exponent G = 0 := exponent_eq_zero_iff.mpr fun h ↦ h.orderOf_pos g |>.ne' hg #align monoid.exponent_eq_zero_of_order_zero Monoid.exponent_eq_zero_of_order_zero #align add_monoid.exponent_eq_zero_of_order_zero AddMonoid.exponent_eq_zero_addOrder_zero /-- The exponent is zero iff for all nonzero `n`, one can find a `g` such that `g ^ n ≠ 1`. -/ @[to_additive "The exponent is zero iff for all nonzero `n`, one can find a `g` such that `n • g ≠ 0`."] theorem exponent_eq_zero_iff_forall : exponent G = 0 ↔ ∀ n > 0, ∃ g : G, g ^ n ≠ 1 := by rw [exponent_eq_zero_iff, ExponentExists] push_neg rfl @[to_additive exponent_nsmul_eq_zero] theorem pow_exponent_eq_one (g : G) : g ^ exponent G = 1 := by by_cases h : ExponentExists G · simp_rw [exponent, dif_pos h] exact (Nat.find_spec h).2 g · simp_rw [exponent, dif_neg h, pow_zero] #align monoid.pow_exponent_eq_one Monoid.pow_exponent_eq_one #align add_monoid.exponent_nsmul_eq_zero AddMonoid.exponent_nsmul_eq_zero @[to_additive] theorem pow_eq_mod_exponent {n : ℕ} (g : G) : g ^ n = g ^ (n % exponent G) := calc g ^ n = g ^ (n % exponent G + exponent G * (n / exponent G)) := by rw [Nat.mod_add_div] _ = g ^ (n % exponent G) := by simp [pow_add, pow_mul, pow_exponent_eq_one] #align monoid.pow_eq_mod_exponent Monoid.pow_eq_mod_exponent #align add_monoid.nsmul_eq_mod_exponent AddMonoid.nsmul_eq_mod_exponent @[to_additive] theorem exponent_pos_of_exists (n : ℕ) (hpos : 0 < n) (hG : ∀ g : G, g ^ n = 1) : 0 < exponent G := ExponentExists.exponent_pos ⟨n, hpos, hG⟩ #align monoid.exponent_pos_of_exists Monoid.exponent_pos_of_exists #align add_monoid.exponent_pos_of_exists AddMonoid.exponent_pos_of_exists @[to_additive] theorem exponent_min' (n : ℕ) (hpos : 0 < n) (hG : ∀ g : G, g ^ n = 1) : exponent G ≤ n := by rw [exponent, dif_pos] · apply Nat.find_min' exact ⟨hpos, hG⟩ · exact ⟨n, hpos, hG⟩ #align monoid.exponent_min' Monoid.exponent_min' #align add_monoid.exponent_min' AddMonoid.exponent_min' @[to_additive] theorem exponent_min (m : ℕ) (hpos : 0 < m) (hm : m < exponent G) : ∃ g : G, g ^ m ≠ 1 := by by_contra! h have hcon : exponent G ≤ m := exponent_min' m hpos h omega #align monoid.exponent_min Monoid.exponent_min #align add_monoid.exponent_min AddMonoid.exponent_min @[to_additive AddMonoid.exp_eq_one_iff] theorem exp_eq_one_iff : exponent G = 1 ↔ Subsingleton G := by refine ⟨fun eq_one => ⟨fun a b => ?a_eq_b⟩, fun h => le_antisymm ?le ?ge⟩ · rw [← pow_one a, ← pow_one b, ← eq_one, Monoid.pow_exponent_eq_one, Monoid.pow_exponent_eq_one] · apply exponent_min' _ Nat.one_pos simp [eq_iff_true_of_subsingleton] · apply Nat.succ_le_of_lt apply exponent_pos_of_exists 1 Nat.one_pos simp [eq_iff_true_of_subsingleton] @[to_additive (attr := simp) AddMonoid.exp_eq_one_of_subsingleton] theorem exp_eq_one_of_subsingleton [hs : Subsingleton G] : exponent G = 1 := exp_eq_one_iff.mpr hs #align monoid.exp_eq_one_of_subsingleton Monoid.exp_eq_one_of_subsingleton #align add_monoid.exp_eq_zero_of_subsingleton AddMonoid.exp_eq_one_of_subsingleton @[to_additive addOrder_dvd_exponent] theorem order_dvd_exponent (g : G) : orderOf g ∣ exponent G := orderOf_dvd_of_pow_eq_one <| pow_exponent_eq_one g #align monoid.order_dvd_exponent Monoid.order_dvd_exponent #align add_monoid.add_order_dvd_exponent AddMonoid.addOrder_dvd_exponent @[to_additive] theorem orderOf_le_exponent (h : ExponentExists G) (g : G) : orderOf g ≤ exponent G := Nat.le_of_dvd h.exponent_pos (order_dvd_exponent g) @[to_additive] theorem exponent_dvd_iff_forall_pow_eq_one {n : ℕ} : exponent G ∣ n ↔ ∀ g : G, g ^ n = 1 := by rcases n.eq_zero_or_pos with (rfl | hpos) · simp constructor · intro h g rw [Nat.dvd_iff_mod_eq_zero] at h rw [pow_eq_mod_exponent, h, pow_zero] · intro hG by_contra h rw [Nat.dvd_iff_mod_eq_zero, ← Ne, ← pos_iff_ne_zero] at h have h₂ : n % exponent G < exponent G := Nat.mod_lt _ (exponent_pos_of_exists n hpos hG) have h₃ : exponent G ≤ n % exponent G := by apply exponent_min' _ h simp_rw [← pow_eq_mod_exponent] exact hG exact h₂.not_le h₃ @[to_additive] alias ⟨_, exponent_dvd_of_forall_pow_eq_one⟩ := exponent_dvd_iff_forall_pow_eq_one #align monoid.exponent_dvd_of_forall_pow_eq_one Monoid.exponent_dvd_of_forall_pow_eq_one #align add_monoid.exponent_dvd_of_forall_nsmul_eq_zero AddMonoid.exponent_dvd_of_forall_nsmul_eq_zero @[to_additive] theorem exponent_dvd {n : ℕ} : exponent G ∣ n ↔ ∀ g : G, orderOf g ∣ n := by simp_rw [exponent_dvd_iff_forall_pow_eq_one, orderOf_dvd_iff_pow_eq_one] variable (G) @[to_additive (attr := deprecated (since := "2024-01-27"))] theorem exponent_dvd_of_forall_orderOf_dvd (n : ℕ) (h : ∀ g : G, orderOf g ∣ n) : exponent G ∣ n := exponent_dvd.mpr h @[to_additive] theorem lcm_orderOf_dvd_exponent [Fintype G] : (Finset.univ : Finset G).lcm orderOf ∣ exponent G := by apply Finset.lcm_dvd intro g _ exact order_dvd_exponent g #align monoid.lcm_order_of_dvd_exponent Monoid.lcm_orderOf_dvd_exponent #align add_monoid.lcm_add_order_of_dvd_exponent AddMonoid.lcm_addOrderOf_dvd_exponent @[to_additive exists_addOrderOf_eq_pow_padic_val_nat_add_exponent] theorem _root_.Nat.Prime.exists_orderOf_eq_pow_factorization_exponent {p : ℕ} (hp : p.Prime) : ∃ g : G, orderOf g = p ^ (exponent G).factorization p := by haveI := Fact.mk hp rcases eq_or_ne ((exponent G).factorization p) 0 with (h | h) · refine ⟨1, by rw [h, pow_zero, orderOf_one]⟩ have he : 0 < exponent G := Ne.bot_lt fun ht => by rw [ht] at h apply h rw [bot_eq_zero, Nat.factorization_zero, Finsupp.zero_apply] rw [← Finsupp.mem_support_iff] at h obtain ⟨g, hg⟩ : ∃ g : G, g ^ (exponent G / p) ≠ 1 := by suffices key : ¬exponent G ∣ exponent G / p by rwa [exponent_dvd_iff_forall_pow_eq_one, not_forall] at key exact fun hd => hp.one_lt.not_le ((mul_le_iff_le_one_left he).mp <| Nat.le_of_dvd he <| Nat.mul_dvd_of_dvd_div (Nat.dvd_of_mem_primeFactors h) hd) obtain ⟨k, hk : exponent G = p ^ _ * k⟩ := Nat.ord_proj_dvd _ _ obtain ⟨t, ht⟩ := Nat.exists_eq_succ_of_ne_zero (Finsupp.mem_support_iff.mp h) refine ⟨g ^ k, ?_⟩ rw [ht] apply orderOf_eq_prime_pow · rwa [hk, mul_comm, ht, pow_succ, ← mul_assoc, Nat.mul_div_cancel _ hp.pos, pow_mul] at hg · rw [← Nat.succ_eq_add_one, ← ht, ← pow_mul, mul_comm, ← hk] exact pow_exponent_eq_one g #align nat.prime.exists_order_of_eq_pow_factorization_exponent Nat.Prime.exists_orderOf_eq_pow_factorization_exponent #align nat.prime.exists_order_of_eq_pow_padic_val_nat_add_exponent Nat.Prime.exists_addOrderOf_eq_pow_padic_val_nat_add_exponent variable {G} in open Nat in /-- If two commuting elements `x` and `y` of a monoid have order `n` and `m`, there is an element of order `lcm n m`. The result actually gives an explicit (computable) element, written as the product of a power of `x` and a power of `y`. See also the result below if you don't need the explicit formula. -/ @[to_additive "If two commuting elements `x` and `y` of an additive monoid have order `n` and `m`, there is an element of order `lcm n m`. The result actually gives an explicit (computable) element, written as the sum of a multiple of `x` and a multiple of `y`. See also the result below if you don't need the explicit formula."] lemma _root_.Commute.orderOf_mul_pow_eq_lcm {x y : G} (h : Commute x y) (hx : orderOf x ≠ 0) (hy : orderOf y ≠ 0) : orderOf (x ^ (orderOf x / (factorizationLCMLeft (orderOf x) (orderOf y))) * y ^ (orderOf y / factorizationLCMRight (orderOf x) (orderOf y))) = Nat.lcm (orderOf x) (orderOf y) := by rw [(h.pow_pow _ _).orderOf_mul_eq_mul_orderOf_of_coprime] all_goals iterate 2 rw [orderOf_pow_orderOf_div]; try rw [Coprime] all_goals simp [factorizationLCMLeft_mul_factorizationLCMRight, factorizationLCMLeft_dvd_left, factorizationLCMRight_dvd_right, coprime_factorizationLCMLeft_factorizationLCMRight, hx, hy] open Submonoid in /-- If two commuting elements `x` and `y` of a monoid have order `n` and `m`, then there is an element of order `lcm n m` that lies in the subgroup generated by `x` and `y`. -/ @[to_additive "If two commuting elements `x` and `y` of an additive monoid have order `n` and `m`, then there is an element of order `lcm n m` that lies in the additive subgroup generated by `x` and `y`."] theorem _root_.Commute.exists_orderOf_eq_lcm {x y : G} (h : Commute x y) : ∃ z ∈ closure {x, y}, orderOf z = Nat.lcm (orderOf x) (orderOf y) := by by_cases hx : orderOf x = 0 <;> by_cases hy : orderOf y = 0 · exact ⟨x, subset_closure (by simp), by simp [hx]⟩ · exact ⟨x, subset_closure (by simp), by simp [hx]⟩ · exact ⟨y, subset_closure (by simp), by simp [hy]⟩ · exact ⟨_, mul_mem (pow_mem (subset_closure (by simp)) _) (pow_mem (subset_closure (by simp)) _), h.orderOf_mul_pow_eq_lcm hx hy⟩ /-- A nontrivial monoid has prime exponent `p` if and only if every non-identity element has order `p`. -/ @[to_additive] lemma exponent_eq_prime_iff {G : Type*} [Monoid G] [Nontrivial G] {p : ℕ} (hp : p.Prime) : Monoid.exponent G = p ↔ ∀ g : G, g ≠ 1 → orderOf g = p := by refine ⟨fun hG g hg ↦ ?_, fun h ↦ dvd_antisymm ?_ ?_⟩ · rw [Ne, ← orderOf_eq_one_iff] at hg exact Eq.symm <| (hp.dvd_iff_eq hg).mp <| hG ▸ Monoid.order_dvd_exponent g · rw [exponent_dvd] intro g by_cases hg : g = 1 · simp [hg] · rw [h g hg] · obtain ⟨g, hg⟩ := exists_ne (1 : G) simpa [h g hg] using Monoid.order_dvd_exponent g variable {G} @[to_additive]
Mathlib/GroupTheory/Exponent.lean
344
364
theorem exponent_ne_zero_iff_range_orderOf_finite (h : ∀ g : G, 0 < orderOf g) : exponent G ≠ 0 ↔ (Set.range (orderOf : G → ℕ)).Finite := by
refine ⟨fun he => ?_, fun he => ?_⟩ · by_contra h obtain ⟨m, ⟨t, rfl⟩, het⟩ := Set.Infinite.exists_gt h (exponent G) exact pow_ne_one_of_lt_orderOf' he het (pow_exponent_eq_one t) · lift Set.range (orderOf (G := G)) to Finset ℕ using he with t ht have htpos : 0 < t.prod id := by refine Finset.prod_pos fun a ha => ?_ rw [← Finset.mem_coe, ht] at ha obtain ⟨k, rfl⟩ := ha exact h k suffices exponent G ∣ t.prod id by intro h rw [h, zero_dvd_iff] at this exact htpos.ne' this rw [exponent_dvd] intro g apply Finset.dvd_prod_of_mem id (?_ : orderOf g ∈ _) rw [← Finset.mem_coe, ht] exact Set.mem_range_self g
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.Restrict /-! # Classes of measures We introduce the following typeclasses for measures: * `IsProbabilityMeasure μ`: `μ univ = 1`; * `IsFiniteMeasure μ`: `μ univ < ∞`; * `SigmaFinite μ`: there exists a countable collection of sets that cover `univ` where `μ` is finite; * `SFinite μ`: the measure `μ` can be written as a countable sum of finite measures; * `IsLocallyFiniteMeasure μ` : `∀ x, ∃ s ∈ 𝓝 x, μ s < ∞`; * `NoAtoms μ` : `∀ x, μ {x} = 0`; possibly should be redefined as `∀ s, 0 < μ s → ∃ t ⊆ s, 0 < μ t ∧ μ t < μ s`. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter Function MeasurableSpace ENNReal variable {α β δ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] {μ ν ν₁ ν₂: Measure α} {s t : Set α} section IsFiniteMeasure /-- A measure `μ` is called finite if `μ univ < ∞`. -/ class IsFiniteMeasure (μ : Measure α) : Prop where measure_univ_lt_top : μ univ < ∞ #align measure_theory.is_finite_measure MeasureTheory.IsFiniteMeasure #align measure_theory.is_finite_measure.measure_univ_lt_top MeasureTheory.IsFiniteMeasure.measure_univ_lt_top theorem not_isFiniteMeasure_iff : ¬IsFiniteMeasure μ ↔ μ Set.univ = ∞ := by refine ⟨fun h => ?_, fun h => fun h' => h'.measure_univ_lt_top.ne h⟩ by_contra h' exact h ⟨lt_top_iff_ne_top.mpr h'⟩ #align measure_theory.not_is_finite_measure_iff MeasureTheory.not_isFiniteMeasure_iff instance Restrict.isFiniteMeasure (μ : Measure α) [hs : Fact (μ s < ∞)] : IsFiniteMeasure (μ.restrict s) := ⟨by simpa using hs.elim⟩ #align measure_theory.restrict.is_finite_measure MeasureTheory.Restrict.isFiniteMeasure theorem measure_lt_top (μ : Measure α) [IsFiniteMeasure μ] (s : Set α) : μ s < ∞ := (measure_mono (subset_univ s)).trans_lt IsFiniteMeasure.measure_univ_lt_top #align measure_theory.measure_lt_top MeasureTheory.measure_lt_top instance isFiniteMeasureRestrict (μ : Measure α) (s : Set α) [h : IsFiniteMeasure μ] : IsFiniteMeasure (μ.restrict s) := ⟨by simpa using measure_lt_top μ s⟩ #align measure_theory.is_finite_measure_restrict MeasureTheory.isFiniteMeasureRestrict theorem measure_ne_top (μ : Measure α) [IsFiniteMeasure μ] (s : Set α) : μ s ≠ ∞ := ne_of_lt (measure_lt_top μ s) #align measure_theory.measure_ne_top MeasureTheory.measure_ne_top theorem measure_compl_le_add_of_le_add [IsFiniteMeasure μ] (hs : MeasurableSet s) (ht : MeasurableSet t) {ε : ℝ≥0∞} (h : μ s ≤ μ t + ε) : μ tᶜ ≤ μ sᶜ + ε := by rw [measure_compl ht (measure_ne_top μ _), measure_compl hs (measure_ne_top μ _), tsub_le_iff_right] calc μ univ = μ univ - μ s + μ s := (tsub_add_cancel_of_le <| measure_mono s.subset_univ).symm _ ≤ μ univ - μ s + (μ t + ε) := add_le_add_left h _ _ = _ := by rw [add_right_comm, add_assoc] #align measure_theory.measure_compl_le_add_of_le_add MeasureTheory.measure_compl_le_add_of_le_add theorem measure_compl_le_add_iff [IsFiniteMeasure μ] (hs : MeasurableSet s) (ht : MeasurableSet t) {ε : ℝ≥0∞} : μ sᶜ ≤ μ tᶜ + ε ↔ μ t ≤ μ s + ε := ⟨fun h => compl_compl s ▸ compl_compl t ▸ measure_compl_le_add_of_le_add hs.compl ht.compl h, measure_compl_le_add_of_le_add ht hs⟩ #align measure_theory.measure_compl_le_add_iff MeasureTheory.measure_compl_le_add_iff /-- The measure of the whole space with respect to a finite measure, considered as `ℝ≥0`. -/ def measureUnivNNReal (μ : Measure α) : ℝ≥0 := (μ univ).toNNReal #align measure_theory.measure_univ_nnreal MeasureTheory.measureUnivNNReal @[simp] theorem coe_measureUnivNNReal (μ : Measure α) [IsFiniteMeasure μ] : ↑(measureUnivNNReal μ) = μ univ := ENNReal.coe_toNNReal (measure_ne_top μ univ) #align measure_theory.coe_measure_univ_nnreal MeasureTheory.coe_measureUnivNNReal instance isFiniteMeasureZero : IsFiniteMeasure (0 : Measure α) := ⟨by simp⟩ #align measure_theory.is_finite_measure_zero MeasureTheory.isFiniteMeasureZero instance (priority := 50) isFiniteMeasureOfIsEmpty [IsEmpty α] : IsFiniteMeasure μ := by rw [eq_zero_of_isEmpty μ] infer_instance #align measure_theory.is_finite_measure_of_is_empty MeasureTheory.isFiniteMeasureOfIsEmpty @[simp] theorem measureUnivNNReal_zero : measureUnivNNReal (0 : Measure α) = 0 := rfl #align measure_theory.measure_univ_nnreal_zero MeasureTheory.measureUnivNNReal_zero instance isFiniteMeasureAdd [IsFiniteMeasure μ] [IsFiniteMeasure ν] : IsFiniteMeasure (μ + ν) where measure_univ_lt_top := by rw [Measure.coe_add, Pi.add_apply, ENNReal.add_lt_top] exact ⟨measure_lt_top _ _, measure_lt_top _ _⟩ #align measure_theory.is_finite_measure_add MeasureTheory.isFiniteMeasureAdd instance isFiniteMeasureSMulNNReal [IsFiniteMeasure μ] {r : ℝ≥0} : IsFiniteMeasure (r • μ) where measure_univ_lt_top := ENNReal.mul_lt_top ENNReal.coe_ne_top (measure_ne_top _ _) #align measure_theory.is_finite_measure_smul_nnreal MeasureTheory.isFiniteMeasureSMulNNReal instance IsFiniteMeasure.average : IsFiniteMeasure ((μ univ)⁻¹ • μ) where measure_univ_lt_top := by rw [smul_apply, smul_eq_mul, ← ENNReal.div_eq_inv_mul] exact ENNReal.div_self_le_one.trans_lt ENNReal.one_lt_top instance isFiniteMeasureSMulOfNNRealTower {R} [SMul R ℝ≥0] [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0 ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [IsFiniteMeasure μ] {r : R} : IsFiniteMeasure (r • μ) := by rw [← smul_one_smul ℝ≥0 r μ] infer_instance #align measure_theory.is_finite_measure_smul_of_nnreal_tower MeasureTheory.isFiniteMeasureSMulOfNNRealTower theorem isFiniteMeasure_of_le (μ : Measure α) [IsFiniteMeasure μ] (h : ν ≤ μ) : IsFiniteMeasure ν := { measure_univ_lt_top := (h Set.univ).trans_lt (measure_lt_top _ _) } #align measure_theory.is_finite_measure_of_le MeasureTheory.isFiniteMeasure_of_le @[instance] theorem Measure.isFiniteMeasure_map {m : MeasurableSpace α} (μ : Measure α) [IsFiniteMeasure μ] (f : α → β) : IsFiniteMeasure (μ.map f) := by by_cases hf : AEMeasurable f μ · constructor rw [map_apply_of_aemeasurable hf MeasurableSet.univ] exact measure_lt_top μ _ · rw [map_of_not_aemeasurable hf] exact MeasureTheory.isFiniteMeasureZero #align measure_theory.measure.is_finite_measure_map MeasureTheory.Measure.isFiniteMeasure_map @[simp] theorem measureUnivNNReal_eq_zero [IsFiniteMeasure μ] : measureUnivNNReal μ = 0 ↔ μ = 0 := by rw [← MeasureTheory.Measure.measure_univ_eq_zero, ← coe_measureUnivNNReal] norm_cast #align measure_theory.measure_univ_nnreal_eq_zero MeasureTheory.measureUnivNNReal_eq_zero theorem measureUnivNNReal_pos [IsFiniteMeasure μ] (hμ : μ ≠ 0) : 0 < measureUnivNNReal μ := by contrapose! hμ simpa [measureUnivNNReal_eq_zero, Nat.le_zero] using hμ #align measure_theory.measure_univ_nnreal_pos MeasureTheory.measureUnivNNReal_pos /-- `le_of_add_le_add_left` is normally applicable to `OrderedCancelAddCommMonoid`, but it holds for measures with the additional assumption that μ is finite. -/ theorem Measure.le_of_add_le_add_left [IsFiniteMeasure μ] (A2 : μ + ν₁ ≤ μ + ν₂) : ν₁ ≤ ν₂ := fun S => ENNReal.le_of_add_le_add_left (MeasureTheory.measure_ne_top μ S) (A2 S) #align measure_theory.measure.le_of_add_le_add_left MeasureTheory.Measure.le_of_add_le_add_left theorem summable_measure_toReal [hμ : IsFiniteMeasure μ] {f : ℕ → Set α} (hf₁ : ∀ i : ℕ, MeasurableSet (f i)) (hf₂ : Pairwise (Disjoint on f)) : Summable fun x => (μ (f x)).toReal := by apply ENNReal.summable_toReal rw [← MeasureTheory.measure_iUnion hf₂ hf₁] exact ne_of_lt (measure_lt_top _ _) #align measure_theory.summable_measure_to_real MeasureTheory.summable_measure_toReal theorem ae_eq_univ_iff_measure_eq [IsFiniteMeasure μ] (hs : NullMeasurableSet s μ) : s =ᵐ[μ] univ ↔ μ s = μ univ := by refine ⟨measure_congr, fun h => ?_⟩ obtain ⟨t, -, ht₁, ht₂⟩ := hs.exists_measurable_subset_ae_eq exact ht₂.symm.trans (ae_eq_of_subset_of_measure_ge (subset_univ t) (Eq.le ((measure_congr ht₂).trans h).symm) ht₁ (measure_ne_top μ univ)) #align measure_theory.ae_eq_univ_iff_measure_eq MeasureTheory.ae_eq_univ_iff_measure_eq theorem ae_iff_measure_eq [IsFiniteMeasure μ] {p : α → Prop} (hp : NullMeasurableSet { a | p a } μ) : (∀ᵐ a ∂μ, p a) ↔ μ { a | p a } = μ univ := by rw [← ae_eq_univ_iff_measure_eq hp, eventuallyEq_univ, eventually_iff] #align measure_theory.ae_iff_measure_eq MeasureTheory.ae_iff_measure_eq theorem ae_mem_iff_measure_eq [IsFiniteMeasure μ] {s : Set α} (hs : NullMeasurableSet s μ) : (∀ᵐ a ∂μ, a ∈ s) ↔ μ s = μ univ := ae_iff_measure_eq hs #align measure_theory.ae_mem_iff_measure_eq MeasureTheory.ae_mem_iff_measure_eq lemma tendsto_measure_biUnion_Ici_zero_of_pairwise_disjoint {X : Type*} [MeasurableSpace X] {μ : Measure X} [IsFiniteMeasure μ] {Es : ℕ → Set X} (Es_mble : ∀ i, MeasurableSet (Es i)) (Es_disj : Pairwise fun n m ↦ Disjoint (Es n) (Es m)) : Tendsto (μ ∘ fun n ↦ ⋃ i ≥ n, Es i) atTop (𝓝 0) := by have decr : Antitone fun n ↦ ⋃ i ≥ n, Es i := fun n m hnm ↦ biUnion_mono (fun _ hi ↦ le_trans hnm hi) (fun _ _ ↦ subset_rfl) have nothing : ⋂ n, ⋃ i ≥ n, Es i = ∅ := by apply subset_antisymm _ (empty_subset _) intro x hx simp only [ge_iff_le, mem_iInter, mem_iUnion, exists_prop] at hx obtain ⟨j, _, x_in_Es_j⟩ := hx 0 obtain ⟨k, k_gt_j, x_in_Es_k⟩ := hx (j+1) have oops := (Es_disj (Nat.ne_of_lt k_gt_j)).ne_of_mem x_in_Es_j x_in_Es_k contradiction have key := tendsto_measure_iInter (μ := μ) (fun n ↦ by measurability) decr ⟨0, measure_ne_top _ _⟩ simp only [ge_iff_le, nothing, measure_empty] at key convert key open scoped symmDiff theorem abs_toReal_measure_sub_le_measure_symmDiff' (hs : MeasurableSet s) (ht : MeasurableSet t) (hs' : μ s ≠ ∞) (ht' : μ t ≠ ∞) : |(μ s).toReal - (μ t).toReal| ≤ (μ (s ∆ t)).toReal := by have hst : μ (s \ t) ≠ ∞ := (measure_lt_top_of_subset diff_subset hs').ne have hts : μ (t \ s) ≠ ∞ := (measure_lt_top_of_subset diff_subset ht').ne suffices (μ s).toReal - (μ t).toReal = (μ (s \ t)).toReal - (μ (t \ s)).toReal by rw [this, measure_symmDiff_eq hs ht, ENNReal.toReal_add hst hts] convert abs_sub (μ (s \ t)).toReal (μ (t \ s)).toReal <;> simp rw [measure_diff' s ht ht', measure_diff' t hs hs', ENNReal.toReal_sub_of_le measure_le_measure_union_right (measure_union_ne_top hs' ht'), ENNReal.toReal_sub_of_le measure_le_measure_union_right (measure_union_ne_top ht' hs'), union_comm t s] abel theorem abs_toReal_measure_sub_le_measure_symmDiff [IsFiniteMeasure μ] (hs : MeasurableSet s) (ht : MeasurableSet t) : |(μ s).toReal - (μ t).toReal| ≤ (μ (s ∆ t)).toReal := abs_toReal_measure_sub_le_measure_symmDiff' hs ht (measure_ne_top μ s) (measure_ne_top μ t) end IsFiniteMeasure section IsProbabilityMeasure /-- A measure `μ` is called a probability measure if `μ univ = 1`. -/ class IsProbabilityMeasure (μ : Measure α) : Prop where measure_univ : μ univ = 1 #align measure_theory.is_probability_measure MeasureTheory.IsProbabilityMeasure #align measure_theory.is_probability_measure.measure_univ MeasureTheory.IsProbabilityMeasure.measure_univ export MeasureTheory.IsProbabilityMeasure (measure_univ) attribute [simp] IsProbabilityMeasure.measure_univ lemma isProbabilityMeasure_iff : IsProbabilityMeasure μ ↔ μ univ = 1 := ⟨fun _ ↦ measure_univ, IsProbabilityMeasure.mk⟩ instance (priority := 100) IsProbabilityMeasure.toIsFiniteMeasure (μ : Measure α) [IsProbabilityMeasure μ] : IsFiniteMeasure μ := ⟨by simp only [measure_univ, ENNReal.one_lt_top]⟩ #align measure_theory.is_probability_measure.to_is_finite_measure MeasureTheory.IsProbabilityMeasure.toIsFiniteMeasure theorem IsProbabilityMeasure.ne_zero (μ : Measure α) [IsProbabilityMeasure μ] : μ ≠ 0 := mt measure_univ_eq_zero.2 <| by simp [measure_univ] #align measure_theory.is_probability_measure.ne_zero MeasureTheory.IsProbabilityMeasure.ne_zero instance (priority := 100) IsProbabilityMeasure.neZero (μ : Measure α) [IsProbabilityMeasure μ] : NeZero μ := ⟨IsProbabilityMeasure.ne_zero μ⟩ -- Porting note: no longer an `instance` because `inferInstance` can find it now theorem IsProbabilityMeasure.ae_neBot [IsProbabilityMeasure μ] : NeBot (ae μ) := inferInstance #align measure_theory.is_probability_measure.ae_ne_bot MeasureTheory.IsProbabilityMeasure.ae_neBot theorem prob_add_prob_compl [IsProbabilityMeasure μ] (h : MeasurableSet s) : μ s + μ sᶜ = 1 := (measure_add_measure_compl h).trans measure_univ #align measure_theory.prob_add_prob_compl MeasureTheory.prob_add_prob_compl theorem prob_le_one [IsProbabilityMeasure μ] : μ s ≤ 1 := (measure_mono <| Set.subset_univ _).trans_eq measure_univ #align measure_theory.prob_le_one MeasureTheory.prob_le_one -- Porting note: made an `instance`, using `NeZero` instance isProbabilityMeasureSMul [IsFiniteMeasure μ] [NeZero μ] : IsProbabilityMeasure ((μ univ)⁻¹ • μ) := ⟨ENNReal.inv_mul_cancel (NeZero.ne (μ univ)) (measure_ne_top _ _)⟩ #align measure_theory.is_probability_measure_smul MeasureTheory.isProbabilityMeasureSMulₓ variable [IsProbabilityMeasure μ] {p : α → Prop} {f : β → α} theorem isProbabilityMeasure_map {f : α → β} (hf : AEMeasurable f μ) : IsProbabilityMeasure (map f μ) := ⟨by simp [map_apply_of_aemeasurable, hf]⟩ #align measure_theory.is_probability_measure_map MeasureTheory.isProbabilityMeasure_map @[simp] theorem one_le_prob_iff : 1 ≤ μ s ↔ μ s = 1 := ⟨fun h => le_antisymm prob_le_one h, fun h => h ▸ le_refl _⟩ #align measure_theory.one_le_prob_iff MeasureTheory.one_le_prob_iff /-- Note that this is not quite as useful as it looks because the measure takes values in `ℝ≥0∞`. Thus the subtraction appearing is the truncated subtraction of `ℝ≥0∞`, rather than the better-behaved subtraction of `ℝ`. -/ lemma prob_compl_eq_one_sub₀ (h : NullMeasurableSet s μ) : μ sᶜ = 1 - μ s := by rw [measure_compl₀ h (measure_ne_top _ _), measure_univ] /-- Note that this is not quite as useful as it looks because the measure takes values in `ℝ≥0∞`. Thus the subtraction appearing is the truncated subtraction of `ℝ≥0∞`, rather than the better-behaved subtraction of `ℝ`. -/ theorem prob_compl_eq_one_sub (hs : MeasurableSet s) : μ sᶜ = 1 - μ s := prob_compl_eq_one_sub₀ hs.nullMeasurableSet #align measure_theory.prob_compl_eq_one_sub MeasureTheory.prob_compl_eq_one_sub lemma prob_compl_lt_one_sub_of_lt_prob {p : ℝ≥0∞} (hμs : p < μ s) (s_mble : MeasurableSet s) : μ sᶜ < 1 - p := by rw [prob_compl_eq_one_sub s_mble] apply ENNReal.sub_lt_of_sub_lt prob_le_one (Or.inl one_ne_top) convert hμs exact ENNReal.sub_sub_cancel one_ne_top (lt_of_lt_of_le hμs prob_le_one).le lemma prob_compl_le_one_sub_of_le_prob {p : ℝ≥0∞} (hμs : p ≤ μ s) (s_mble : MeasurableSet s) : μ sᶜ ≤ 1 - p := by simpa [prob_compl_eq_one_sub s_mble] using tsub_le_tsub_left hμs 1 @[simp] lemma prob_compl_eq_zero_iff₀ (hs : NullMeasurableSet s μ) : μ sᶜ = 0 ↔ μ s = 1 := by rw [prob_compl_eq_one_sub₀ hs, tsub_eq_zero_iff_le, one_le_prob_iff] @[simp] lemma prob_compl_eq_zero_iff (hs : MeasurableSet s) : μ sᶜ = 0 ↔ μ s = 1 := prob_compl_eq_zero_iff₀ hs.nullMeasurableSet #align measure_theory.prob_compl_eq_zero_iff MeasureTheory.prob_compl_eq_zero_iff @[simp] lemma prob_compl_eq_one_iff₀ (hs : NullMeasurableSet s μ) : μ sᶜ = 1 ↔ μ s = 0 := by rw [← prob_compl_eq_zero_iff₀ hs.compl, compl_compl] @[simp] lemma prob_compl_eq_one_iff (hs : MeasurableSet s) : μ sᶜ = 1 ↔ μ s = 0 := prob_compl_eq_one_iff₀ hs.nullMeasurableSet #align measure_theory.prob_compl_eq_one_iff MeasureTheory.prob_compl_eq_one_iff lemma mem_ae_iff_prob_eq_one₀ (hs : NullMeasurableSet s μ) : s ∈ ae μ ↔ μ s = 1 := mem_ae_iff.trans <| prob_compl_eq_zero_iff₀ hs lemma mem_ae_iff_prob_eq_one (hs : MeasurableSet s) : s ∈ ae μ ↔ μ s = 1 := mem_ae_iff.trans <| prob_compl_eq_zero_iff hs lemma ae_iff_prob_eq_one (hp : Measurable p) : (∀ᵐ a ∂μ, p a) ↔ μ {a | p a} = 1 := mem_ae_iff_prob_eq_one hp.setOf lemma isProbabilityMeasure_comap (hf : Injective f) (hf' : ∀ᵐ a ∂μ, a ∈ range f) (hf'' : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) : IsProbabilityMeasure (μ.comap f) where measure_univ := by rw [comap_apply _ hf hf'' _ MeasurableSet.univ, ← mem_ae_iff_prob_eq_one (hf'' _ MeasurableSet.univ)] simpa protected lemma _root_.MeasurableEmbedding.isProbabilityMeasure_comap (hf : MeasurableEmbedding f) (hf' : ∀ᵐ a ∂μ, a ∈ range f) : IsProbabilityMeasure (μ.comap f) := isProbabilityMeasure_comap hf.injective hf' hf.measurableSet_image' instance isProbabilityMeasure_map_up : IsProbabilityMeasure (μ.map ULift.up) := isProbabilityMeasure_map measurable_up.aemeasurable instance isProbabilityMeasure_comap_down : IsProbabilityMeasure (μ.comap ULift.down) := MeasurableEquiv.ulift.measurableEmbedding.isProbabilityMeasure_comap <| ae_of_all _ <| by simp [Function.Surjective.range_eq <| EquivLike.surjective _] end IsProbabilityMeasure section NoAtoms /-- Measure `μ` *has no atoms* if the measure of each singleton is zero. NB: Wikipedia assumes that for any measurable set `s` with positive `μ`-measure, there exists a measurable `t ⊆ s` such that `0 < μ t < μ s`. While this implies `μ {x} = 0`, the converse is not true. -/ class NoAtoms {m0 : MeasurableSpace α} (μ : Measure α) : Prop where measure_singleton : ∀ x, μ {x} = 0 #align measure_theory.has_no_atoms MeasureTheory.NoAtoms #align measure_theory.has_no_atoms.measure_singleton MeasureTheory.NoAtoms.measure_singleton export MeasureTheory.NoAtoms (measure_singleton) attribute [simp] measure_singleton variable [NoAtoms μ] theorem _root_.Set.Subsingleton.measure_zero (hs : s.Subsingleton) (μ : Measure α) [NoAtoms μ] : μ s = 0 := hs.induction_on (p := fun s => μ s = 0) measure_empty measure_singleton #align set.subsingleton.measure_zero Set.Subsingleton.measure_zero theorem Measure.restrict_singleton' {a : α} : μ.restrict {a} = 0 := by simp only [measure_singleton, Measure.restrict_eq_zero] #align measure_theory.measure.restrict_singleton' MeasureTheory.Measure.restrict_singleton' instance Measure.restrict.instNoAtoms (s : Set α) : NoAtoms (μ.restrict s) := by refine ⟨fun x => ?_⟩ obtain ⟨t, hxt, ht1, ht2⟩ := exists_measurable_superset_of_null (measure_singleton x : μ {x} = 0) apply measure_mono_null hxt rw [Measure.restrict_apply ht1] apply measure_mono_null inter_subset_left ht2 #align measure_theory.measure.restrict.has_no_atoms MeasureTheory.Measure.restrict.instNoAtoms theorem _root_.Set.Countable.measure_zero (h : s.Countable) (μ : Measure α) [NoAtoms μ] : μ s = 0 := by rw [← biUnion_of_singleton s, measure_biUnion_null_iff h] simp #align set.countable.measure_zero Set.Countable.measure_zero theorem _root_.Set.Countable.ae_not_mem (h : s.Countable) (μ : Measure α) [NoAtoms μ] : ∀ᵐ x ∂μ, x ∉ s := by simpa only [ae_iff, Classical.not_not] using h.measure_zero μ #align set.countable.ae_not_mem Set.Countable.ae_not_mem lemma _root_.Set.Countable.measure_restrict_compl (h : s.Countable) (μ : Measure α) [NoAtoms μ] : μ.restrict sᶜ = μ := restrict_eq_self_of_ae_mem <| h.ae_not_mem μ @[simp] lemma restrict_compl_singleton (a : α) : μ.restrict ({a}ᶜ) = μ := (countable_singleton _).measure_restrict_compl μ theorem _root_.Set.Finite.measure_zero (h : s.Finite) (μ : Measure α) [NoAtoms μ] : μ s = 0 := h.countable.measure_zero μ #align set.finite.measure_zero Set.Finite.measure_zero theorem _root_.Finset.measure_zero (s : Finset α) (μ : Measure α) [NoAtoms μ] : μ s = 0 := s.finite_toSet.measure_zero μ #align finset.measure_zero Finset.measure_zero theorem insert_ae_eq_self (a : α) (s : Set α) : (insert a s : Set α) =ᵐ[μ] s := union_ae_eq_right.2 <| measure_mono_null diff_subset (measure_singleton _) #align measure_theory.insert_ae_eq_self MeasureTheory.insert_ae_eq_self section variable [PartialOrder α] {a b : α} theorem Iio_ae_eq_Iic : Iio a =ᵐ[μ] Iic a := Iio_ae_eq_Iic' (measure_singleton a) #align measure_theory.Iio_ae_eq_Iic MeasureTheory.Iio_ae_eq_Iic theorem Ioi_ae_eq_Ici : Ioi a =ᵐ[μ] Ici a := Ioi_ae_eq_Ici' (measure_singleton a) #align measure_theory.Ioi_ae_eq_Ici MeasureTheory.Ioi_ae_eq_Ici theorem Ioo_ae_eq_Ioc : Ioo a b =ᵐ[μ] Ioc a b := Ioo_ae_eq_Ioc' (measure_singleton b) #align measure_theory.Ioo_ae_eq_Ioc MeasureTheory.Ioo_ae_eq_Ioc theorem Ioc_ae_eq_Icc : Ioc a b =ᵐ[μ] Icc a b := Ioc_ae_eq_Icc' (measure_singleton a) #align measure_theory.Ioc_ae_eq_Icc MeasureTheory.Ioc_ae_eq_Icc theorem Ioo_ae_eq_Ico : Ioo a b =ᵐ[μ] Ico a b := Ioo_ae_eq_Ico' (measure_singleton a) #align measure_theory.Ioo_ae_eq_Ico MeasureTheory.Ioo_ae_eq_Ico theorem Ioo_ae_eq_Icc : Ioo a b =ᵐ[μ] Icc a b := Ioo_ae_eq_Icc' (measure_singleton a) (measure_singleton b) #align measure_theory.Ioo_ae_eq_Icc MeasureTheory.Ioo_ae_eq_Icc theorem Ico_ae_eq_Icc : Ico a b =ᵐ[μ] Icc a b := Ico_ae_eq_Icc' (measure_singleton b) #align measure_theory.Ico_ae_eq_Icc MeasureTheory.Ico_ae_eq_Icc theorem Ico_ae_eq_Ioc : Ico a b =ᵐ[μ] Ioc a b := Ico_ae_eq_Ioc' (measure_singleton a) (measure_singleton b) #align measure_theory.Ico_ae_eq_Ioc MeasureTheory.Ico_ae_eq_Ioc theorem restrict_Iio_eq_restrict_Iic : μ.restrict (Iio a) = μ.restrict (Iic a) := restrict_congr_set Iio_ae_eq_Iic theorem restrict_Ioi_eq_restrict_Ici : μ.restrict (Ioi a) = μ.restrict (Ici a) := restrict_congr_set Ioi_ae_eq_Ici theorem restrict_Ioo_eq_restrict_Ioc : μ.restrict (Ioo a b) = μ.restrict (Ioc a b) := restrict_congr_set Ioo_ae_eq_Ioc theorem restrict_Ioc_eq_restrict_Icc : μ.restrict (Ioc a b) = μ.restrict (Icc a b) := restrict_congr_set Ioc_ae_eq_Icc theorem restrict_Ioo_eq_restrict_Ico : μ.restrict (Ioo a b) = μ.restrict (Ico a b) := restrict_congr_set Ioo_ae_eq_Ico theorem restrict_Ioo_eq_restrict_Icc : μ.restrict (Ioo a b) = μ.restrict (Icc a b) := restrict_congr_set Ioo_ae_eq_Icc theorem restrict_Ico_eq_restrict_Icc : μ.restrict (Ico a b) = μ.restrict (Icc a b) := restrict_congr_set Ico_ae_eq_Icc theorem restrict_Ico_eq_restrict_Ioc : μ.restrict (Ico a b) = μ.restrict (Ioc a b) := restrict_congr_set Ico_ae_eq_Ioc end open Interval theorem uIoc_ae_eq_interval [LinearOrder α] {a b : α} : Ι a b =ᵐ[μ] [[a, b]] := Ioc_ae_eq_Icc #align measure_theory.uIoc_ae_eq_interval MeasureTheory.uIoc_ae_eq_interval end NoAtoms theorem ite_ae_eq_of_measure_zero {γ} (f : α → γ) (g : α → γ) (s : Set α) [DecidablePred (· ∈ s)] (hs_zero : μ s = 0) : (fun x => ite (x ∈ s) (f x) (g x)) =ᵐ[μ] g := by have h_ss : sᶜ ⊆ { a : α | ite (a ∈ s) (f a) (g a) = g a } := fun x hx => by simp [(Set.mem_compl_iff _ _).mp hx] refine measure_mono_null ?_ hs_zero conv_rhs => rw [← compl_compl s] rwa [Set.compl_subset_compl] #align measure_theory.ite_ae_eq_of_measure_zero MeasureTheory.ite_ae_eq_of_measure_zero theorem ite_ae_eq_of_measure_compl_zero {γ} (f : α → γ) (g : α → γ) (s : Set α) [DecidablePred (· ∈ s)] (hs_zero : μ sᶜ = 0) : (fun x => ite (x ∈ s) (f x) (g x)) =ᵐ[μ] f := by rw [← mem_ae_iff] at hs_zero filter_upwards [hs_zero] intros split_ifs rfl #align measure_theory.ite_ae_eq_of_measure_compl_zero MeasureTheory.ite_ae_eq_of_measure_compl_zero namespace Measure /-- A measure is called finite at filter `f` if it is finite at some set `s ∈ f`. Equivalently, it is eventually finite at `s` in `f.small_sets`. -/ def FiniteAtFilter {_m0 : MeasurableSpace α} (μ : Measure α) (f : Filter α) : Prop := ∃ s ∈ f, μ s < ∞ #align measure_theory.measure.finite_at_filter MeasureTheory.Measure.FiniteAtFilter theorem finiteAtFilter_of_finite {_m0 : MeasurableSpace α} (μ : Measure α) [IsFiniteMeasure μ] (f : Filter α) : μ.FiniteAtFilter f := ⟨univ, univ_mem, measure_lt_top μ univ⟩ #align measure_theory.measure.finite_at_filter_of_finite MeasureTheory.Measure.finiteAtFilter_of_finite theorem FiniteAtFilter.exists_mem_basis {f : Filter α} (hμ : FiniteAtFilter μ f) {p : ι → Prop} {s : ι → Set α} (hf : f.HasBasis p s) : ∃ i, p i ∧ μ (s i) < ∞ := (hf.exists_iff fun {_s _t} hst ht => (measure_mono hst).trans_lt ht).1 hμ #align measure_theory.measure.finite_at_filter.exists_mem_basis MeasureTheory.Measure.FiniteAtFilter.exists_mem_basis theorem finiteAtBot {m0 : MeasurableSpace α} (μ : Measure α) : μ.FiniteAtFilter ⊥ := ⟨∅, mem_bot, by simp only [measure_empty, zero_lt_top]⟩ #align measure_theory.measure.finite_at_bot MeasureTheory.Measure.finiteAtBot /-- `μ` has finite spanning sets in `C` if there is a countable sequence of sets in `C` that have finite measures. This structure is a type, which is useful if we want to record extra properties about the sets, such as that they are monotone. `SigmaFinite` is defined in terms of this: `μ` is σ-finite if there exists a sequence of finite spanning sets in the collection of all measurable sets. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure FiniteSpanningSetsIn {m0 : MeasurableSpace α} (μ : Measure α) (C : Set (Set α)) where protected set : ℕ → Set α protected set_mem : ∀ i, set i ∈ C protected finite : ∀ i, μ (set i) < ∞ protected spanning : ⋃ i, set i = univ #align measure_theory.measure.finite_spanning_sets_in MeasureTheory.Measure.FiniteSpanningSetsIn #align measure_theory.measure.finite_spanning_sets_in.set MeasureTheory.Measure.FiniteSpanningSetsIn.set #align measure_theory.measure.finite_spanning_sets_in.set_mem MeasureTheory.Measure.FiniteSpanningSetsIn.set_mem #align measure_theory.measure.finite_spanning_sets_in.finite MeasureTheory.Measure.FiniteSpanningSetsIn.finite #align measure_theory.measure.finite_spanning_sets_in.spanning MeasureTheory.Measure.FiniteSpanningSetsIn.spanning end Measure open Measure section SFinite /-- A measure is called s-finite if it is a countable sum of finite measures. -/ class SFinite (μ : Measure α) : Prop where out' : ∃ m : ℕ → Measure α, (∀ n, IsFiniteMeasure (m n)) ∧ μ = Measure.sum m /-- A sequence of finite measures such that `μ = sum (sFiniteSeq μ)` (see `sum_sFiniteSeq`). -/ noncomputable def sFiniteSeq (μ : Measure α) [h : SFinite μ] : ℕ → Measure α := h.1.choose instance isFiniteMeasure_sFiniteSeq [h : SFinite μ] (n : ℕ) : IsFiniteMeasure (sFiniteSeq μ n) := h.1.choose_spec.1 n lemma sum_sFiniteSeq (μ : Measure α) [h : SFinite μ] : sum (sFiniteSeq μ) = μ := h.1.choose_spec.2.symm instance : SFinite (0 : Measure α) := ⟨fun _ ↦ 0, inferInstance, by rw [Measure.sum_zero]⟩ @[simp] lemma sFiniteSeq_zero (n : ℕ) : sFiniteSeq (0 : Measure α) n = 0 := by ext s hs have h : ∑' n, sFiniteSeq (0 : Measure α) n s = 0 := by simp [← Measure.sum_apply _ hs, sum_sFiniteSeq] simp only [ENNReal.tsum_eq_zero] at h exact h n /-- A countable sum of finite measures is s-finite. This lemma is superseeded by the instance below. -/ lemma sfinite_sum_of_countable [Countable ι] (m : ι → Measure α) [∀ n, IsFiniteMeasure (m n)] : SFinite (Measure.sum m) := by classical obtain ⟨f, hf⟩ : ∃ f : ι → ℕ, Function.Injective f := Countable.exists_injective_nat ι refine ⟨_, fun n ↦ ?_, (sum_extend_zero hf m).symm⟩ rcases em (n ∈ range f) with ⟨i, rfl⟩ | hn · rw [hf.extend_apply] infer_instance · rw [Function.extend_apply' _ _ _ hn, Pi.zero_apply] infer_instance instance [Countable ι] (m : ι → Measure α) [∀ n, SFinite (m n)] : SFinite (Measure.sum m) := by change SFinite (Measure.sum (fun i ↦ m i)) simp_rw [← sum_sFiniteSeq (m _), Measure.sum_sum] apply sfinite_sum_of_countable instance [SFinite μ] [SFinite ν] : SFinite (μ + ν) := by refine ⟨fun n ↦ sFiniteSeq μ n + sFiniteSeq ν n, inferInstance, ?_⟩ ext s hs simp only [Measure.add_apply, sum_apply _ hs] rw [tsum_add ENNReal.summable ENNReal.summable, ← sum_apply _ hs, ← sum_apply _ hs, sum_sFiniteSeq, sum_sFiniteSeq] instance [SFinite μ] (s : Set α) : SFinite (μ.restrict s) := ⟨fun n ↦ (sFiniteSeq μ n).restrict s, fun n ↦ inferInstance, by rw [← restrict_sum_of_countable, sum_sFiniteSeq]⟩ end SFinite /-- A measure `μ` is called σ-finite if there is a countable collection of sets `{ A i | i ∈ ℕ }` such that `μ (A i) < ∞` and `⋃ i, A i = s`. -/ class SigmaFinite {m0 : MeasurableSpace α} (μ : Measure α) : Prop where out' : Nonempty (μ.FiniteSpanningSetsIn univ) #align measure_theory.sigma_finite MeasureTheory.SigmaFinite #align measure_theory.sigma_finite.out' MeasureTheory.SigmaFinite.out' theorem sigmaFinite_iff : SigmaFinite μ ↔ Nonempty (μ.FiniteSpanningSetsIn univ) := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align measure_theory.sigma_finite_iff MeasureTheory.sigmaFinite_iff theorem SigmaFinite.out (h : SigmaFinite μ) : Nonempty (μ.FiniteSpanningSetsIn univ) := h.1 #align measure_theory.sigma_finite.out MeasureTheory.SigmaFinite.out /-- If `μ` is σ-finite it has finite spanning sets in the collection of all measurable sets. -/ def Measure.toFiniteSpanningSetsIn (μ : Measure α) [h : SigmaFinite μ] : μ.FiniteSpanningSetsIn { s | MeasurableSet s } where set n := toMeasurable μ (h.out.some.set n) set_mem n := measurableSet_toMeasurable _ _ finite n := by rw [measure_toMeasurable] exact h.out.some.finite n spanning := eq_univ_of_subset (iUnion_mono fun n => subset_toMeasurable _ _) h.out.some.spanning #align measure_theory.measure.to_finite_spanning_sets_in MeasureTheory.Measure.toFiniteSpanningSetsIn /-- A noncomputable way to get a monotone collection of sets that span `univ` and have finite measure using `Classical.choose`. This definition satisfies monotonicity in addition to all other properties in `SigmaFinite`. -/ def spanningSets (μ : Measure α) [SigmaFinite μ] (i : ℕ) : Set α := Accumulate μ.toFiniteSpanningSetsIn.set i #align measure_theory.spanning_sets MeasureTheory.spanningSets theorem monotone_spanningSets (μ : Measure α) [SigmaFinite μ] : Monotone (spanningSets μ) := monotone_accumulate #align measure_theory.monotone_spanning_sets MeasureTheory.monotone_spanningSets theorem measurable_spanningSets (μ : Measure α) [SigmaFinite μ] (i : ℕ) : MeasurableSet (spanningSets μ i) := MeasurableSet.iUnion fun j => MeasurableSet.iUnion fun _ => μ.toFiniteSpanningSetsIn.set_mem j #align measure_theory.measurable_spanning_sets MeasureTheory.measurable_spanningSets theorem measure_spanningSets_lt_top (μ : Measure α) [SigmaFinite μ] (i : ℕ) : μ (spanningSets μ i) < ∞ := measure_biUnion_lt_top (finite_le_nat i) fun j _ => (μ.toFiniteSpanningSetsIn.finite j).ne #align measure_theory.measure_spanning_sets_lt_top MeasureTheory.measure_spanningSets_lt_top theorem iUnion_spanningSets (μ : Measure α) [SigmaFinite μ] : ⋃ i : ℕ, spanningSets μ i = univ := by simp_rw [spanningSets, iUnion_accumulate, μ.toFiniteSpanningSetsIn.spanning] #align measure_theory.Union_spanning_sets MeasureTheory.iUnion_spanningSets theorem isCountablySpanning_spanningSets (μ : Measure α) [SigmaFinite μ] : IsCountablySpanning (range (spanningSets μ)) := ⟨spanningSets μ, mem_range_self, iUnion_spanningSets μ⟩ #align measure_theory.is_countably_spanning_spanning_sets MeasureTheory.isCountablySpanning_spanningSets open scoped Classical in /-- `spanningSetsIndex μ x` is the least `n : ℕ` such that `x ∈ spanningSets μ n`. -/ noncomputable def spanningSetsIndex (μ : Measure α) [SigmaFinite μ] (x : α) : ℕ := Nat.find <| iUnion_eq_univ_iff.1 (iUnion_spanningSets μ) x #align measure_theory.spanning_sets_index MeasureTheory.spanningSetsIndex open scoped Classical in theorem measurable_spanningSetsIndex (μ : Measure α) [SigmaFinite μ] : Measurable (spanningSetsIndex μ) := measurable_find _ <| measurable_spanningSets μ #align measure_theory.measurable_spanning_sets_index MeasureTheory.measurable_spanningSetsIndex open scoped Classical in theorem preimage_spanningSetsIndex_singleton (μ : Measure α) [SigmaFinite μ] (n : ℕ) : spanningSetsIndex μ ⁻¹' {n} = disjointed (spanningSets μ) n := preimage_find_eq_disjointed _ _ _ #align measure_theory.preimage_spanning_sets_index_singleton MeasureTheory.preimage_spanningSetsIndex_singleton theorem spanningSetsIndex_eq_iff (μ : Measure α) [SigmaFinite μ] {x : α} {n : ℕ} : spanningSetsIndex μ x = n ↔ x ∈ disjointed (spanningSets μ) n := by convert Set.ext_iff.1 (preimage_spanningSetsIndex_singleton μ n) x #align measure_theory.spanning_sets_index_eq_iff MeasureTheory.spanningSetsIndex_eq_iff theorem mem_disjointed_spanningSetsIndex (μ : Measure α) [SigmaFinite μ] (x : α) : x ∈ disjointed (spanningSets μ) (spanningSetsIndex μ x) := (spanningSetsIndex_eq_iff μ).1 rfl #align measure_theory.mem_disjointed_spanning_sets_index MeasureTheory.mem_disjointed_spanningSetsIndex theorem mem_spanningSetsIndex (μ : Measure α) [SigmaFinite μ] (x : α) : x ∈ spanningSets μ (spanningSetsIndex μ x) := disjointed_subset _ _ (mem_disjointed_spanningSetsIndex μ x) #align measure_theory.mem_spanning_sets_index MeasureTheory.mem_spanningSetsIndex theorem mem_spanningSets_of_index_le (μ : Measure α) [SigmaFinite μ] (x : α) {n : ℕ} (hn : spanningSetsIndex μ x ≤ n) : x ∈ spanningSets μ n := monotone_spanningSets μ hn (mem_spanningSetsIndex μ x) #align measure_theory.mem_spanning_sets_of_index_le MeasureTheory.mem_spanningSets_of_index_le theorem eventually_mem_spanningSets (μ : Measure α) [SigmaFinite μ] (x : α) : ∀ᶠ n in atTop, x ∈ spanningSets μ n := eventually_atTop.2 ⟨spanningSetsIndex μ x, fun _ => mem_spanningSets_of_index_le μ x⟩ #align measure_theory.eventually_mem_spanning_sets MeasureTheory.eventually_mem_spanningSets theorem sum_restrict_disjointed_spanningSets (μ : Measure α) [SigmaFinite μ] : sum (fun n ↦ μ.restrict (disjointed (spanningSets μ) n)) = μ := by rw [← restrict_iUnion (disjoint_disjointed _) (MeasurableSet.disjointed (measurable_spanningSets _)), iUnion_disjointed, iUnion_spanningSets, restrict_univ] instance (priority := 100) [SigmaFinite μ] : SFinite μ := by have : ∀ n, Fact (μ (disjointed (spanningSets μ) n) < ∞) := fun n ↦ ⟨(measure_mono (disjointed_subset _ _)).trans_lt (measure_spanningSets_lt_top μ n)⟩ exact ⟨⟨fun n ↦ μ.restrict (disjointed (spanningSets μ) n), fun n ↦ by infer_instance, (sum_restrict_disjointed_spanningSets μ).symm⟩⟩ namespace Measure /-- A set in a σ-finite space has zero measure if and only if its intersection with all members of the countable family of finite measure spanning sets has zero measure. -/ theorem forall_measure_inter_spanningSets_eq_zero [MeasurableSpace α] {μ : Measure α} [SigmaFinite μ] (s : Set α) : (∀ n, μ (s ∩ spanningSets μ n) = 0) ↔ μ s = 0 := by nth_rw 2 [show s = ⋃ n, s ∩ spanningSets μ n by rw [← inter_iUnion, iUnion_spanningSets, inter_univ] ] rw [measure_iUnion_null_iff] #align measure_theory.measure.forall_measure_inter_spanning_sets_eq_zero MeasureTheory.Measure.forall_measure_inter_spanningSets_eq_zero /-- A set in a σ-finite space has positive measure if and only if its intersection with some member of the countable family of finite measure spanning sets has positive measure. -/ theorem exists_measure_inter_spanningSets_pos [MeasurableSpace α] {μ : Measure α} [SigmaFinite μ] (s : Set α) : (∃ n, 0 < μ (s ∩ spanningSets μ n)) ↔ 0 < μ s := by rw [← not_iff_not] simp only [not_exists, not_lt, nonpos_iff_eq_zero] exact forall_measure_inter_spanningSets_eq_zero s #align measure_theory.measure.exists_measure_inter_spanning_sets_pos MeasureTheory.Measure.exists_measure_inter_spanningSets_pos /-- If the union of a.e.-disjoint null-measurable sets has finite measure, then there are only finitely many members of the union whose measure exceeds any given positive number. -/ theorem finite_const_le_meas_of_disjoint_iUnion₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α) {ε : ℝ≥0∞} (ε_pos : 0 < ε) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) : Set.Finite { i : ι | ε ≤ μ (As i) } := ENNReal.finite_const_le_of_tsum_ne_top (ne_top_of_le_ne_top Union_As_finite (tsum_meas_le_meas_iUnion_of_disjoint₀ μ As_mble As_disj)) ε_pos.ne' /-- If the union of disjoint measurable sets has finite measure, then there are only finitely many members of the union whose measure exceeds any given positive number. -/ theorem finite_const_le_meas_of_disjoint_iUnion {ι : Type*} [MeasurableSpace α] (μ : Measure α) {ε : ℝ≥0∞} (ε_pos : 0 < ε) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) : Set.Finite { i : ι | ε ≤ μ (As i) } := finite_const_le_meas_of_disjoint_iUnion₀ μ ε_pos (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) Union_As_finite #align measure_theory.measure.finite_const_le_meas_of_disjoint_Union MeasureTheory.Measure.finite_const_le_meas_of_disjoint_iUnion /-- If all elements of an infinite set have measure uniformly separated from zero, then the set has infinite measure. -/ theorem _root_.Set.Infinite.meas_eq_top [MeasurableSingletonClass α] {s : Set α} (hs : s.Infinite) (h' : ∃ ε, ε ≠ 0 ∧ ∀ x ∈ s, ε ≤ μ {x}) : μ s = ∞ := top_unique <| let ⟨ε, hne, hε⟩ := h'; have := hs.to_subtype calc ∞ = ∑' _ : s, ε := (ENNReal.tsum_const_eq_top_of_ne_zero hne).symm _ ≤ ∑' x : s, μ {x.1} := ENNReal.tsum_le_tsum fun x ↦ hε x x.2 _ ≤ μ (⋃ x : s, {x.1}) := tsum_meas_le_meas_iUnion_of_disjoint _ (fun _ ↦ MeasurableSet.singleton _) fun x y hne ↦ by simpa [Subtype.val_inj] _ = μ s := by simp /-- If the union of a.e.-disjoint null-measurable sets has finite measure, then there are only countably many members of the union whose measure is positive. -/ theorem countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top₀ {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) : Set.Countable { i : ι | 0 < μ (As i) } := by set posmeas := { i : ι | 0 < μ (As i) } with posmeas_def rcases exists_seq_strictAnti_tendsto' (zero_lt_one : (0 : ℝ≥0∞) < 1) with ⟨as, _, as_mem, as_lim⟩ set fairmeas := fun n : ℕ => { i : ι | as n ≤ μ (As i) } have countable_union : posmeas = ⋃ n, fairmeas n := by have fairmeas_eq : ∀ n, fairmeas n = (fun i => μ (As i)) ⁻¹' Ici (as n) := fun n => by simp only [fairmeas] rfl simpa only [fairmeas_eq, posmeas_def, ← preimage_iUnion, iUnion_Ici_eq_Ioi_of_lt_of_tendsto (0 : ℝ≥0∞) (fun n => (as_mem n).1) as_lim] rw [countable_union] refine countable_iUnion fun n => Finite.countable ?_ exact finite_const_le_meas_of_disjoint_iUnion₀ μ (as_mem n).1 As_mble As_disj Union_As_finite /-- If the union of disjoint measurable sets has finite measure, then there are only countably many members of the union whose measure is positive. -/ theorem countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) (Union_As_finite : μ (⋃ i, As i) ≠ ∞) : Set.Countable { i : ι | 0 < μ (As i) } := countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) ((fun _ _ h ↦ Disjoint.aedisjoint (As_disj h))) Union_As_finite #align measure_theory.measure.countable_meas_pos_of_disjoint_of_meas_Union_ne_top MeasureTheory.Measure.countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top /-- In an s-finite space, among disjoint null-measurable sets, only countably many can have positive measure. -/ theorem countable_meas_pos_of_disjoint_iUnion₀ {ι : Type*} { _ : MeasurableSpace α} {μ : Measure α} [SFinite μ] {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : Set.Countable { i : ι | 0 < μ (As i) } := by rw [← sum_sFiniteSeq μ] at As_disj As_mble ⊢ have obs : { i : ι | 0 < sum (sFiniteSeq μ) (As i) } ⊆ ⋃ n, { i : ι | 0 < sFiniteSeq μ n (As i) } := by intro i hi by_contra con simp only [mem_iUnion, mem_setOf_eq, not_exists, not_lt, nonpos_iff_eq_zero] at * rw [sum_apply₀] at hi · simp_rw [con] at hi simp at hi · exact As_mble i apply Countable.mono obs refine countable_iUnion fun n ↦ ?_ apply countable_meas_pos_of_disjoint_of_meas_iUnion_ne_top₀ · exact fun i ↦ (As_mble i).mono (le_sum _ _) · exact fun i j hij ↦ AEDisjoint.of_le (As_disj hij) (le_sum _ _) · exact measure_ne_top _ (⋃ i, As i) /-- In an s-finite space, among disjoint measurable sets, only countably many can have positive measure. -/ theorem countable_meas_pos_of_disjoint_iUnion {ι : Type*} {_ : MeasurableSpace α} {μ : Measure α} [SFinite μ] {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : Set.Countable { i : ι | 0 < μ (As i) } := countable_meas_pos_of_disjoint_iUnion₀ (fun i ↦ (As_mble i).nullMeasurableSet) ((fun _ _ h ↦ Disjoint.aedisjoint (As_disj h))) #align measure_theory.measure.countable_meas_pos_of_disjoint_Union MeasureTheory.Measure.countable_meas_pos_of_disjoint_iUnion theorem countable_meas_level_set_pos₀ {α β : Type*} {_ : MeasurableSpace α} {μ : Measure α} [SFinite μ] [MeasurableSpace β] [MeasurableSingletonClass β] {g : α → β} (g_mble : NullMeasurable g μ) : Set.Countable { t : β | 0 < μ { a : α | g a = t } } := by have level_sets_disjoint : Pairwise (Disjoint on fun t : β => { a : α | g a = t }) := fun s t hst => Disjoint.preimage g (disjoint_singleton.mpr hst) exact Measure.countable_meas_pos_of_disjoint_iUnion₀ (fun b => g_mble (‹MeasurableSingletonClass β›.measurableSet_singleton b)) ((fun _ _ h ↦ Disjoint.aedisjoint (level_sets_disjoint h))) theorem countable_meas_level_set_pos {α β : Type*} {_ : MeasurableSpace α} {μ : Measure α} [SFinite μ] [MeasurableSpace β] [MeasurableSingletonClass β] {g : α → β} (g_mble : Measurable g) : Set.Countable { t : β | 0 < μ { a : α | g a = t } } := countable_meas_level_set_pos₀ g_mble.nullMeasurable #align measure_theory.measure.countable_meas_level_set_pos MeasureTheory.Measure.countable_meas_level_set_pos /-- If a measure `μ` is the sum of a countable family `mₙ`, and a set `t` has finite measure for each `mₙ`, then its measurable superset `toMeasurable μ t` (which has the same measure as `t`) satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (t ∩ s)`. -/ theorem measure_toMeasurable_inter_of_sum {s : Set α} (hs : MeasurableSet s) {t : Set α} {m : ℕ → Measure α} (hv : ∀ n, m n t ≠ ∞) (hμ : μ = sum m) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := by -- we show that there is a measurable superset of `t` satisfying the conclusion for any -- measurable set `s`. It is built for each measure `mₙ` using `toMeasurable` -- (which is well behaved for finite measure sets thanks to `measure_toMeasurable_inter`), and -- then taking the intersection over `n`. have A : ∃ t', t' ⊇ t ∧ MeasurableSet t' ∧ ∀ u, MeasurableSet u → μ (t' ∩ u) = μ (t ∩ u) := by let w n := toMeasurable (m n) t have T : t ⊆ ⋂ n, w n := subset_iInter (fun i ↦ subset_toMeasurable (m i) t) have M : MeasurableSet (⋂ n, w n) := MeasurableSet.iInter (fun i ↦ measurableSet_toMeasurable (m i) t) refine ⟨⋂ n, w n, T, M, fun u hu ↦ ?_⟩ refine le_antisymm ?_ (by gcongr) rw [hμ, sum_apply _ (M.inter hu)] apply le_trans _ (le_sum_apply _ _) apply ENNReal.tsum_le_tsum (fun i ↦ ?_) calc m i ((⋂ n, w n) ∩ u) ≤ m i (w i ∩ u) := by gcongr; apply iInter_subset _ = m i (t ∩ u) := measure_toMeasurable_inter hu (hv i) -- thanks to the definition of `toMeasurable`, the previous property will also be shared -- by `toMeasurable μ t`, which is enough to conclude the proof. rw [toMeasurable] split_ifs with ht · apply measure_congr exact ae_eq_set_inter ht.choose_spec.2.2 (ae_eq_refl _) · exact A.choose_spec.2.2 s hs /-- If a set `t` is covered by a countable family of finite measure sets, then its measurable superset `toMeasurable μ t` (which has the same measure as `t`) satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (t ∩ s)`. -/ theorem measure_toMeasurable_inter_of_cover {s : Set α} (hs : MeasurableSet s) {t : Set α} {v : ℕ → Set α} (hv : t ⊆ ⋃ n, v n) (h'v : ∀ n, μ (t ∩ v n) ≠ ∞) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := by -- we show that there is a measurable superset of `t` satisfying the conclusion for any -- measurable set `s`. It is built on each member of a spanning family using `toMeasurable` -- (which is well behaved for finite measure sets thanks to `measure_toMeasurable_inter`), and -- the desired property passes to the union. have A : ∃ t', t' ⊇ t ∧ MeasurableSet t' ∧ ∀ u, MeasurableSet u → μ (t' ∩ u) = μ (t ∩ u) := by let w n := toMeasurable μ (t ∩ v n) have hw : ∀ n, μ (w n) < ∞ := by intro n simp_rw [w, measure_toMeasurable] exact (h'v n).lt_top set t' := ⋃ n, toMeasurable μ (t ∩ disjointed w n) with ht' have tt' : t ⊆ t' := calc t ⊆ ⋃ n, t ∩ disjointed w n := by rw [← inter_iUnion, iUnion_disjointed, inter_iUnion] intro x hx rcases mem_iUnion.1 (hv hx) with ⟨n, hn⟩ refine mem_iUnion.2 ⟨n, ?_⟩ have : x ∈ t ∩ v n := ⟨hx, hn⟩ exact ⟨hx, subset_toMeasurable μ _ this⟩ _ ⊆ ⋃ n, toMeasurable μ (t ∩ disjointed w n) := iUnion_mono fun n => subset_toMeasurable _ _ refine ⟨t', tt', MeasurableSet.iUnion fun n => measurableSet_toMeasurable μ _, fun u hu => ?_⟩ apply le_antisymm _ (by gcongr) calc μ (t' ∩ u) ≤ ∑' n, μ (toMeasurable μ (t ∩ disjointed w n) ∩ u) := by rw [ht', iUnion_inter] exact measure_iUnion_le _ _ = ∑' n, μ (t ∩ disjointed w n ∩ u) := by congr 1 ext1 n apply measure_toMeasurable_inter hu apply ne_of_lt calc μ (t ∩ disjointed w n) ≤ μ (t ∩ w n) := by gcongr exact disjointed_le w n _ ≤ μ (w n) := measure_mono inter_subset_right _ < ∞ := hw n _ = ∑' n, μ.restrict (t ∩ u) (disjointed w n) := by congr 1 ext1 n rw [restrict_apply, inter_comm t _, inter_assoc] refine MeasurableSet.disjointed (fun n => ?_) n exact measurableSet_toMeasurable _ _ _ = μ.restrict (t ∩ u) (⋃ n, disjointed w n) := by rw [measure_iUnion] · exact disjoint_disjointed _ · intro i refine MeasurableSet.disjointed (fun n => ?_) i exact measurableSet_toMeasurable _ _ _ ≤ μ.restrict (t ∩ u) univ := measure_mono (subset_univ _) _ = μ (t ∩ u) := by rw [restrict_apply MeasurableSet.univ, univ_inter] -- thanks to the definition of `toMeasurable`, the previous property will also be shared -- by `toMeasurable μ t`, which is enough to conclude the proof. rw [toMeasurable] split_ifs with ht · apply measure_congr exact ae_eq_set_inter ht.choose_spec.2.2 (ae_eq_refl _) · exact A.choose_spec.2.2 s hs #align measure_theory.measure.measure_to_measurable_inter_of_cover MeasureTheory.Measure.measure_toMeasurable_inter_of_cover theorem restrict_toMeasurable_of_cover {s : Set α} {v : ℕ → Set α} (hv : s ⊆ ⋃ n, v n) (h'v : ∀ n, μ (s ∩ v n) ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s := ext fun t ht => by simp only [restrict_apply ht, inter_comm t, measure_toMeasurable_inter_of_cover ht hv h'v] #align measure_theory.measure.restrict_to_measurable_of_cover MeasureTheory.Measure.restrict_toMeasurable_of_cover /-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`) satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (t ∩ s)`. This only holds when `μ` is s-finite -- for example for σ-finite measures. For a version without this assumption (but requiring that `t` has finite measure), see `measure_toMeasurable_inter`. -/ theorem measure_toMeasurable_inter_of_sFinite [SFinite μ] {s : Set α} (hs : MeasurableSet s) (t : Set α) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := measure_toMeasurable_inter_of_sum hs (fun _ ↦ measure_ne_top _ t) (sum_sFiniteSeq μ).symm #align measure_theory.measure.measure_to_measurable_inter_of_sigma_finite MeasureTheory.Measure.measure_toMeasurable_inter_of_sFinite @[simp] theorem restrict_toMeasurable_of_sFinite [SFinite μ] (s : Set α) : μ.restrict (toMeasurable μ s) = μ.restrict s := ext fun t ht => by rw [restrict_apply ht, inter_comm t, measure_toMeasurable_inter_of_sFinite ht, restrict_apply ht, inter_comm t] #align measure_theory.measure.restrict_to_measurable_of_sigma_finite MeasureTheory.Measure.restrict_toMeasurable_of_sFinite /-- Auxiliary lemma for `iSup_restrict_spanningSets`. -/ theorem iSup_restrict_spanningSets_of_measurableSet [SigmaFinite μ] (hs : MeasurableSet s) : ⨆ i, μ.restrict (spanningSets μ i) s = μ s := calc ⨆ i, μ.restrict (spanningSets μ i) s = μ.restrict (⋃ i, spanningSets μ i) s := (restrict_iUnion_apply_eq_iSup (monotone_spanningSets μ).directed_le hs).symm _ = μ s := by rw [iUnion_spanningSets, restrict_univ] #align measure_theory.measure.supr_restrict_spanning_sets MeasureTheory.Measure.iSup_restrict_spanningSets_of_measurableSet theorem iSup_restrict_spanningSets [SigmaFinite μ] (s : Set α) : ⨆ i, μ.restrict (spanningSets μ i) s = μ s := by rw [← measure_toMeasurable s, ← iSup_restrict_spanningSets_of_measurableSet (measurableSet_toMeasurable _ _)] simp_rw [restrict_apply' (measurable_spanningSets μ _), Set.inter_comm s, ← restrict_apply (measurable_spanningSets μ _), ← restrict_toMeasurable_of_sFinite s, restrict_apply (measurable_spanningSets μ _), Set.inter_comm _ (toMeasurable μ s)] /-- In a σ-finite space, any measurable set of measure `> r` contains a measurable subset of finite measure `> r`. -/ theorem exists_subset_measure_lt_top [SigmaFinite μ] {r : ℝ≥0∞} (hs : MeasurableSet s) (h's : r < μ s) : ∃ t, MeasurableSet t ∧ t ⊆ s ∧ r < μ t ∧ μ t < ∞ := by rw [← iSup_restrict_spanningSets, @lt_iSup_iff _ _ _ r fun i : ℕ => μ.restrict (spanningSets μ i) s] at h's rcases h's with ⟨n, hn⟩ simp only [restrict_apply hs] at hn refine ⟨s ∩ spanningSets μ n, hs.inter (measurable_spanningSets _ _), inter_subset_left, hn, ?_⟩ exact (measure_mono inter_subset_right).trans_lt (measure_spanningSets_lt_top _ _) #align measure_theory.measure.exists_subset_measure_lt_top MeasureTheory.Measure.exists_subset_measure_lt_top namespace FiniteSpanningSetsIn variable {C D : Set (Set α)} /-- If `μ` has finite spanning sets in `C` and `C ∩ {s | μ s < ∞} ⊆ D` then `μ` has finite spanning sets in `D`. -/ protected def mono' (h : μ.FiniteSpanningSetsIn C) (hC : C ∩ { s | μ s < ∞ } ⊆ D) : μ.FiniteSpanningSetsIn D := ⟨h.set, fun i => hC ⟨h.set_mem i, h.finite i⟩, h.finite, h.spanning⟩ #align measure_theory.measure.finite_spanning_sets_in.mono' MeasureTheory.Measure.FiniteSpanningSetsIn.mono' /-- If `μ` has finite spanning sets in `C` and `C ⊆ D` then `μ` has finite spanning sets in `D`. -/ protected def mono (h : μ.FiniteSpanningSetsIn C) (hC : C ⊆ D) : μ.FiniteSpanningSetsIn D := h.mono' fun _s hs => hC hs.1 #align measure_theory.measure.finite_spanning_sets_in.mono MeasureTheory.Measure.FiniteSpanningSetsIn.mono /-- If `μ` has finite spanning sets in the collection of measurable sets `C`, then `μ` is σ-finite. -/ protected theorem sigmaFinite (h : μ.FiniteSpanningSetsIn C) : SigmaFinite μ := ⟨⟨h.mono <| subset_univ C⟩⟩ #align measure_theory.measure.finite_spanning_sets_in.sigma_finite MeasureTheory.Measure.FiniteSpanningSetsIn.sigmaFinite /-- An extensionality for measures. It is `ext_of_generateFrom_of_iUnion` formulated in terms of `FiniteSpanningSetsIn`. -/ protected theorem ext {ν : Measure α} {C : Set (Set α)} (hA : ‹_› = generateFrom C) (hC : IsPiSystem C) (h : μ.FiniteSpanningSetsIn C) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν := ext_of_generateFrom_of_iUnion C _ hA hC h.spanning h.set_mem (fun i => (h.finite i).ne) h_eq #align measure_theory.measure.finite_spanning_sets_in.ext MeasureTheory.Measure.FiniteSpanningSetsIn.ext protected theorem isCountablySpanning (h : μ.FiniteSpanningSetsIn C) : IsCountablySpanning C := ⟨h.set, h.set_mem, h.spanning⟩ #align measure_theory.measure.finite_spanning_sets_in.is_countably_spanning MeasureTheory.Measure.FiniteSpanningSetsIn.isCountablySpanning end FiniteSpanningSetsIn theorem sigmaFinite_of_countable {S : Set (Set α)} (hc : S.Countable) (hμ : ∀ s ∈ S, μ s < ∞) (hU : ⋃₀ S = univ) : SigmaFinite μ := by obtain ⟨s, hμ, hs⟩ : ∃ s : ℕ → Set α, (∀ n, μ (s n) < ∞) ∧ ⋃ n, s n = univ := (@exists_seq_cover_iff_countable _ (fun x => μ x < ∞) ⟨∅, by simp⟩).2 ⟨S, hc, hμ, hU⟩ exact ⟨⟨⟨fun n => s n, fun _ => trivial, hμ, hs⟩⟩⟩ #align measure_theory.measure.sigma_finite_of_countable MeasureTheory.Measure.sigmaFinite_of_countable /-- Given measures `μ`, `ν` where `ν ≤ μ`, `FiniteSpanningSetsIn.ofLe` provides the induced `FiniteSpanningSet` with respect to `ν` from a `FiniteSpanningSet` with respect to `μ`. -/ def FiniteSpanningSetsIn.ofLE (h : ν ≤ μ) {C : Set (Set α)} (S : μ.FiniteSpanningSetsIn C) : ν.FiniteSpanningSetsIn C where set := S.set set_mem := S.set_mem finite n := lt_of_le_of_lt (le_iff'.1 h _) (S.finite n) spanning := S.spanning #align measure_theory.measure.finite_spanning_sets_in.of_le MeasureTheory.Measure.FiniteSpanningSetsIn.ofLE theorem sigmaFinite_of_le (μ : Measure α) [hs : SigmaFinite μ] (h : ν ≤ μ) : SigmaFinite ν := ⟨hs.out.map <| FiniteSpanningSetsIn.ofLE h⟩ #align measure_theory.measure.sigma_finite_of_le MeasureTheory.Measure.sigmaFinite_of_le @[simp] lemma add_right_inj (μ ν₁ ν₂ : Measure α) [SigmaFinite μ] : μ + ν₁ = μ + ν₂ ↔ ν₁ = ν₂ := by refine ⟨fun h ↦ ?_, fun h ↦ by rw [h]⟩ rw [ext_iff_of_iUnion_eq_univ (iUnion_spanningSets μ)] intro i ext s hs rw [← ENNReal.add_right_inj (measure_mono s.inter_subset_right |>.trans_lt <| measure_spanningSets_lt_top μ i).ne] simp only [ext_iff', coe_add, Pi.add_apply] at h simp [hs, h] @[simp] lemma add_left_inj (μ ν₁ ν₂ : Measure α) [SigmaFinite μ] : ν₁ + μ = ν₂ + μ ↔ ν₁ = ν₂ := by rw [add_comm _ μ, add_comm _ μ, μ.add_right_inj] end Measure /-- Every finite measure is σ-finite. -/ instance (priority := 100) IsFiniteMeasure.toSigmaFinite {_m0 : MeasurableSpace α} (μ : Measure α) [IsFiniteMeasure μ] : SigmaFinite μ := ⟨⟨⟨fun _ => univ, fun _ => trivial, fun _ => measure_lt_top μ _, iUnion_const _⟩⟩⟩ #align measure_theory.is_finite_measure.to_sigma_finite MeasureTheory.IsFiniteMeasure.toSigmaFinite theorem sigmaFinite_bot_iff (μ : @Measure α ⊥) : SigmaFinite μ ↔ IsFiniteMeasure μ := by refine ⟨fun h => ⟨?_⟩, fun h => by haveI := h infer_instance⟩ haveI : SigmaFinite μ := h let s := spanningSets μ have hs_univ : ⋃ i, s i = Set.univ := iUnion_spanningSets μ have hs_meas : ∀ i, MeasurableSet[⊥] (s i) := measurable_spanningSets μ simp_rw [MeasurableSpace.measurableSet_bot_iff] at hs_meas by_cases h_univ_empty : (Set.univ : Set α) = ∅ · rw [h_univ_empty, measure_empty] exact ENNReal.zero_ne_top.lt_top obtain ⟨i, hsi⟩ : ∃ i, s i = Set.univ := by by_contra! h_not_univ have h_empty : ∀ i, s i = ∅ := by simpa [h_not_univ] using hs_meas simp only [h_empty, iUnion_empty] at hs_univ exact h_univ_empty hs_univ.symm rw [← hsi] exact measure_spanningSets_lt_top μ i #align measure_theory.sigma_finite_bot_iff MeasureTheory.sigmaFinite_bot_iff instance Restrict.sigmaFinite (μ : Measure α) [SigmaFinite μ] (s : Set α) : SigmaFinite (μ.restrict s) := by refine ⟨⟨⟨spanningSets μ, fun _ => trivial, fun i => ?_, iUnion_spanningSets μ⟩⟩⟩ rw [Measure.restrict_apply (measurable_spanningSets μ i)] exact (measure_mono inter_subset_left).trans_lt (measure_spanningSets_lt_top μ i) #align measure_theory.restrict.sigma_finite MeasureTheory.Restrict.sigmaFinite instance sum.sigmaFinite {ι} [Finite ι] (μ : ι → Measure α) [∀ i, SigmaFinite (μ i)] : SigmaFinite (sum μ) := by cases nonempty_fintype ι have : ∀ n, MeasurableSet (⋂ i : ι, spanningSets (μ i) n) := fun n => MeasurableSet.iInter fun i => measurable_spanningSets (μ i) n refine ⟨⟨⟨fun n => ⋂ i, spanningSets (μ i) n, fun _ => trivial, fun n => ?_, ?_⟩⟩⟩ · rw [sum_apply _ (this n), tsum_fintype, ENNReal.sum_lt_top_iff] rintro i - exact (measure_mono <| iInter_subset _ i).trans_lt (measure_spanningSets_lt_top (μ i) n) · rw [iUnion_iInter_of_monotone] · simp_rw [iUnion_spanningSets, iInter_univ] exact fun i => monotone_spanningSets (μ i) #align measure_theory.sum.sigma_finite MeasureTheory.sum.sigmaFinite instance Add.sigmaFinite (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν] : SigmaFinite (μ + ν) := by rw [← sum_cond] refine @sum.sigmaFinite _ _ _ _ _ (Bool.rec ?_ ?_) <;> simpa #align measure_theory.add.sigma_finite MeasureTheory.Add.sigmaFinite instance SMul.sigmaFinite {μ : Measure α} [SigmaFinite μ] (c : ℝ≥0) : MeasureTheory.SigmaFinite (c • μ) where out' := ⟨{ set := spanningSets μ set_mem := fun _ ↦ trivial finite := by intro i simp only [Measure.coe_smul, Pi.smul_apply, nnreal_smul_coe_apply] exact ENNReal.mul_lt_top ENNReal.coe_ne_top (measure_spanningSets_lt_top μ i).ne spanning := iUnion_spanningSets μ }⟩ theorem SigmaFinite.of_map (μ : Measure α) {f : α → β} (hf : AEMeasurable f μ) (h : SigmaFinite (μ.map f)) : SigmaFinite μ := ⟨⟨⟨fun n => f ⁻¹' spanningSets (μ.map f) n, fun _ => trivial, fun n => by simp only [← map_apply_of_aemeasurable hf, measurable_spanningSets, measure_spanningSets_lt_top], by rw [← preimage_iUnion, iUnion_spanningSets, preimage_univ]⟩⟩⟩ #align measure_theory.sigma_finite.of_map MeasureTheory.SigmaFinite.of_map theorem _root_.MeasurableEquiv.sigmaFinite_map {μ : Measure α} (f : α ≃ᵐ β) (h : SigmaFinite μ) : SigmaFinite (μ.map f) := by refine SigmaFinite.of_map _ f.symm.measurable.aemeasurable ?_ rwa [map_map f.symm.measurable f.measurable, f.symm_comp_self, Measure.map_id] #align measurable_equiv.sigma_finite_map MeasurableEquiv.sigmaFinite_map /-- Similar to `ae_of_forall_measure_lt_top_ae_restrict`, but where you additionally get the hypothesis that another σ-finite measure has finite values on `s`. -/ theorem ae_of_forall_measure_lt_top_ae_restrict' {μ : Measure α} (ν : Measure α) [SigmaFinite μ] [SigmaFinite ν] (P : α → Prop) (h : ∀ s, MeasurableSet s → μ s < ∞ → ν s < ∞ → ∀ᵐ x ∂μ.restrict s, P x) : ∀ᵐ x ∂μ, P x := by have : ∀ n, ∀ᵐ x ∂μ, x ∈ spanningSets (μ + ν) n → P x := by intro n have := h (spanningSets (μ + ν) n) (measurable_spanningSets _ _) ((self_le_add_right _ _).trans_lt (measure_spanningSets_lt_top (μ + ν) _)) ((self_le_add_left _ _).trans_lt (measure_spanningSets_lt_top (μ + ν) _)) exact (ae_restrict_iff' (measurable_spanningSets _ _)).mp this filter_upwards [ae_all_iff.2 this] with _ hx using hx _ (mem_spanningSetsIndex _ _) #align measure_theory.ae_of_forall_measure_lt_top_ae_restrict' MeasureTheory.ae_of_forall_measure_lt_top_ae_restrict' /-- To prove something for almost all `x` w.r.t. a σ-finite measure, it is sufficient to show that this holds almost everywhere in sets where the measure has finite value. -/ theorem ae_of_forall_measure_lt_top_ae_restrict {μ : Measure α} [SigmaFinite μ] (P : α → Prop) (h : ∀ s, MeasurableSet s → μ s < ∞ → ∀ᵐ x ∂μ.restrict s, P x) : ∀ᵐ x ∂μ, P x := ae_of_forall_measure_lt_top_ae_restrict' μ P fun s hs h2s _ => h s hs h2s #align measure_theory.ae_of_forall_measure_lt_top_ae_restrict MeasureTheory.ae_of_forall_measure_lt_top_ae_restrict /-- A measure is called locally finite if it is finite in some neighborhood of each point. -/ class IsLocallyFiniteMeasure [TopologicalSpace α] (μ : Measure α) : Prop where finiteAtNhds : ∀ x, μ.FiniteAtFilter (𝓝 x) #align measure_theory.is_locally_finite_measure MeasureTheory.IsLocallyFiniteMeasure #align measure_theory.is_locally_finite_measure.finite_at_nhds MeasureTheory.IsLocallyFiniteMeasure.finiteAtNhds -- see Note [lower instance priority] instance (priority := 100) IsFiniteMeasure.toIsLocallyFiniteMeasure [TopologicalSpace α] (μ : Measure α) [IsFiniteMeasure μ] : IsLocallyFiniteMeasure μ := ⟨fun _ => finiteAtFilter_of_finite _ _⟩ #align measure_theory.is_finite_measure.to_is_locally_finite_measure MeasureTheory.IsFiniteMeasure.toIsLocallyFiniteMeasure theorem Measure.finiteAt_nhds [TopologicalSpace α] (μ : Measure α) [IsLocallyFiniteMeasure μ] (x : α) : μ.FiniteAtFilter (𝓝 x) := IsLocallyFiniteMeasure.finiteAtNhds x #align measure_theory.measure.finite_at_nhds MeasureTheory.Measure.finiteAt_nhds theorem Measure.smul_finite (μ : Measure α) [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : IsFiniteMeasure (c • μ) := by lift c to ℝ≥0 using hc exact MeasureTheory.isFiniteMeasureSMulNNReal #align measure_theory.measure.smul_finite MeasureTheory.Measure.smul_finite theorem Measure.exists_isOpen_measure_lt_top [TopologicalSpace α] (μ : Measure α) [IsLocallyFiniteMeasure μ] (x : α) : ∃ s : Set α, x ∈ s ∧ IsOpen s ∧ μ s < ∞ := by simpa only [and_assoc] using (μ.finiteAt_nhds x).exists_mem_basis (nhds_basis_opens x) #align measure_theory.measure.exists_is_open_measure_lt_top MeasureTheory.Measure.exists_isOpen_measure_lt_top instance isLocallyFiniteMeasureSMulNNReal [TopologicalSpace α] (μ : Measure α) [IsLocallyFiniteMeasure μ] (c : ℝ≥0) : IsLocallyFiniteMeasure (c • μ) := by refine ⟨fun x => ?_⟩ rcases μ.exists_isOpen_measure_lt_top x with ⟨o, xo, o_open, μo⟩ refine ⟨o, o_open.mem_nhds xo, ?_⟩ apply ENNReal.mul_lt_top _ μo.ne simp #align measure_theory.is_locally_finite_measure_smul_nnreal MeasureTheory.isLocallyFiniteMeasureSMulNNReal protected theorem Measure.isTopologicalBasis_isOpen_lt_top [TopologicalSpace α] (μ : Measure α) [IsLocallyFiniteMeasure μ] : TopologicalSpace.IsTopologicalBasis { s | IsOpen s ∧ μ s < ∞ } := by refine TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds (fun s hs => hs.1) ?_ intro x s xs hs rcases μ.exists_isOpen_measure_lt_top x with ⟨v, xv, hv, μv⟩ refine ⟨v ∩ s, ⟨hv.inter hs, lt_of_le_of_lt ?_ μv⟩, ⟨xv, xs⟩, inter_subset_right⟩ exact measure_mono inter_subset_left #align measure_theory.measure.is_topological_basis_is_open_lt_top MeasureTheory.Measure.isTopologicalBasis_isOpen_lt_top /-- A measure `μ` is finite on compacts if any compact set `K` satisfies `μ K < ∞`. -/ class IsFiniteMeasureOnCompacts [TopologicalSpace α] (μ : Measure α) : Prop where protected lt_top_of_isCompact : ∀ ⦃K : Set α⦄, IsCompact K → μ K < ∞ #align measure_theory.is_finite_measure_on_compacts MeasureTheory.IsFiniteMeasureOnCompacts #align measure_theory.is_finite_measure_on_compacts.lt_top_of_is_compact MeasureTheory.IsFiniteMeasureOnCompacts.lt_top_of_isCompact /-- A compact subset has finite measure for a measure which is finite on compacts. -/ theorem _root_.IsCompact.measure_lt_top [TopologicalSpace α] {μ : Measure α} [IsFiniteMeasureOnCompacts μ] ⦃K : Set α⦄ (hK : IsCompact K) : μ K < ∞ := IsFiniteMeasureOnCompacts.lt_top_of_isCompact hK #align is_compact.measure_lt_top IsCompact.measure_lt_top /-- A compact subset has finite measure for a measure which is finite on compacts. -/ theorem _root_.IsCompact.measure_ne_top [TopologicalSpace α] {μ : Measure α} [IsFiniteMeasureOnCompacts μ] ⦃K : Set α⦄ (hK : IsCompact K) : μ K ≠ ∞ := hK.measure_lt_top.ne /-- A bounded subset has finite measure for a measure which is finite on compact sets, in a proper space. -/ theorem _root_.Bornology.IsBounded.measure_lt_top [PseudoMetricSpace α] [ProperSpace α] {μ : Measure α} [IsFiniteMeasureOnCompacts μ] ⦃s : Set α⦄ (hs : Bornology.IsBounded s) : μ s < ∞ := calc μ s ≤ μ (closure s) := measure_mono subset_closure _ < ∞ := (Metric.isCompact_of_isClosed_isBounded isClosed_closure hs.closure).measure_lt_top #align metric.bounded.measure_lt_top Bornology.IsBounded.measure_lt_top theorem measure_closedBall_lt_top [PseudoMetricSpace α] [ProperSpace α] {μ : Measure α} [IsFiniteMeasureOnCompacts μ] {x : α} {r : ℝ} : μ (Metric.closedBall x r) < ∞ := Metric.isBounded_closedBall.measure_lt_top #align measure_theory.measure_closed_ball_lt_top MeasureTheory.measure_closedBall_lt_top theorem measure_ball_lt_top [PseudoMetricSpace α] [ProperSpace α] {μ : Measure α} [IsFiniteMeasureOnCompacts μ] {x : α} {r : ℝ} : μ (Metric.ball x r) < ∞ := Metric.isBounded_ball.measure_lt_top #align measure_theory.measure_ball_lt_top MeasureTheory.measure_ball_lt_top protected theorem IsFiniteMeasureOnCompacts.smul [TopologicalSpace α] (μ : Measure α) [IsFiniteMeasureOnCompacts μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : IsFiniteMeasureOnCompacts (c • μ) := ⟨fun _K hK => ENNReal.mul_lt_top hc hK.measure_lt_top.ne⟩ #align measure_theory.is_finite_measure_on_compacts.smul MeasureTheory.IsFiniteMeasureOnCompacts.smul instance IsFiniteMeasureOnCompacts.smul_nnreal [TopologicalSpace α] (μ : Measure α) [IsFiniteMeasureOnCompacts μ] (c : ℝ≥0) : IsFiniteMeasureOnCompacts (c • μ) := IsFiniteMeasureOnCompacts.smul μ coe_ne_top instance instIsFiniteMeasureOnCompactsRestrict [TopologicalSpace α] {μ : Measure α} [IsFiniteMeasureOnCompacts μ] {s : Set α} : IsFiniteMeasureOnCompacts (μ.restrict s) := ⟨fun _k hk ↦ (restrict_apply_le _ _).trans_lt hk.measure_lt_top⟩ instance (priority := 100) CompactSpace.isFiniteMeasure [TopologicalSpace α] [CompactSpace α] [IsFiniteMeasureOnCompacts μ] : IsFiniteMeasure μ := ⟨IsFiniteMeasureOnCompacts.lt_top_of_isCompact isCompact_univ⟩ #align measure_theory.compact_space.is_finite_measure MeasureTheory.CompactSpace.isFiniteMeasure instance (priority := 100) SigmaFinite.of_isFiniteMeasureOnCompacts [TopologicalSpace α] [SigmaCompactSpace α] (μ : Measure α) [IsFiniteMeasureOnCompacts μ] : SigmaFinite μ := ⟨⟨{ set := compactCovering α set_mem := fun _ => trivial finite := fun n => (isCompact_compactCovering α n).measure_lt_top spanning := iUnion_compactCovering α }⟩⟩ -- see Note [lower instance priority] instance (priority := 100) sigmaFinite_of_locallyFinite [TopologicalSpace α] [SecondCountableTopology α] [IsLocallyFiniteMeasure μ] : SigmaFinite μ := by choose s hsx hsμ using μ.finiteAt_nhds rcases TopologicalSpace.countable_cover_nhds hsx with ⟨t, htc, htU⟩ refine Measure.sigmaFinite_of_countable (htc.image s) (forall_mem_image.2 fun x _ => hsμ x) ?_ rwa [sUnion_image] #align measure_theory.sigma_finite_of_locally_finite MeasureTheory.sigmaFinite_of_locallyFinite /-- A measure which is finite on compact sets in a locally compact space is locally finite. -/ instance (priority := 100) isLocallyFiniteMeasure_of_isFiniteMeasureOnCompacts [TopologicalSpace α] [WeaklyLocallyCompactSpace α] [IsFiniteMeasureOnCompacts μ] : IsLocallyFiniteMeasure μ := ⟨fun x ↦ let ⟨K, K_compact, K_mem⟩ := exists_compact_mem_nhds x ⟨K, K_mem, K_compact.measure_lt_top⟩⟩ #align measure_theory.is_locally_finite_measure_of_is_finite_measure_on_compacts MeasureTheory.isLocallyFiniteMeasure_of_isFiniteMeasureOnCompacts theorem exists_pos_measure_of_cover [Countable ι] {U : ι → Set α} (hU : ⋃ i, U i = univ) (hμ : μ ≠ 0) : ∃ i, 0 < μ (U i) := by contrapose! hμ with H rw [← measure_univ_eq_zero, ← hU] exact measure_iUnion_null fun i => nonpos_iff_eq_zero.1 (H i) #align measure_theory.exists_pos_measure_of_cover MeasureTheory.exists_pos_measure_of_cover theorem exists_pos_preimage_ball [PseudoMetricSpace δ] (f : α → δ) (x : δ) (hμ : μ ≠ 0) : ∃ n : ℕ, 0 < μ (f ⁻¹' Metric.ball x n) := exists_pos_measure_of_cover (by rw [← preimage_iUnion, Metric.iUnion_ball_nat, preimage_univ]) hμ #align measure_theory.exists_pos_preimage_ball MeasureTheory.exists_pos_preimage_ball theorem exists_pos_ball [PseudoMetricSpace α] (x : α) (hμ : μ ≠ 0) : ∃ n : ℕ, 0 < μ (Metric.ball x n) := exists_pos_preimage_ball id x hμ #align measure_theory.exists_pos_ball MeasureTheory.exists_pos_ball /-- If a set has zero measure in a neighborhood of each of its points, then it has zero measure in a second-countable space. -/ @[deprecated (since := "2024-05-14")] alias null_of_locally_null := measure_null_of_locally_null theorem exists_ne_forall_mem_nhds_pos_measure_preimage {β} [TopologicalSpace β] [T1Space β] [SecondCountableTopology β] [Nonempty β] {f : α → β} (h : ∀ b, ∃ᵐ x ∂μ, f x ≠ b) : ∃ a b : β, a ≠ b ∧ (∀ s ∈ 𝓝 a, 0 < μ (f ⁻¹' s)) ∧ ∀ t ∈ 𝓝 b, 0 < μ (f ⁻¹' t) := by -- We use an `OuterMeasure` so that the proof works without `Measurable f` set m : OuterMeasure β := OuterMeasure.map f μ.toOuterMeasure replace h : ∀ b : β, m {b}ᶜ ≠ 0 := fun b => not_eventually.mpr (h b) inhabit β have : m univ ≠ 0 := ne_bot_of_le_ne_bot (h default) (measure_mono <| subset_univ _) rcases exists_mem_forall_mem_nhdsWithin_pos_measure this with ⟨b, -, hb⟩ simp only [nhdsWithin_univ] at hb rcases exists_mem_forall_mem_nhdsWithin_pos_measure (h b) with ⟨a, hab : a ≠ b, ha⟩ simp only [isOpen_compl_singleton.nhdsWithin_eq hab] at ha exact ⟨a, b, hab, ha, hb⟩ #align measure_theory.exists_ne_forall_mem_nhds_pos_measure_preimage MeasureTheory.exists_ne_forall_mem_nhds_pos_measure_preimage /-- If two finite measures give the same mass to the whole space and coincide on a π-system made of measurable sets, then they coincide on all sets in the σ-algebra generated by the π-system. -/ theorem ext_on_measurableSpace_of_generate_finite {α} (m₀ : MeasurableSpace α) {μ ν : Measure α} [IsFiniteMeasure μ] (C : Set (Set α)) (hμν : ∀ s ∈ C, μ s = ν s) {m : MeasurableSpace α} (h : m ≤ m₀) (hA : m = MeasurableSpace.generateFrom C) (hC : IsPiSystem C) (h_univ : μ Set.univ = ν Set.univ) {s : Set α} (hs : MeasurableSet[m] s) : μ s = ν s := by haveI : IsFiniteMeasure ν := by constructor rw [← h_univ] apply IsFiniteMeasure.measure_univ_lt_top refine induction_on_inter hA hC (by simp) hμν ?_ ?_ hs · intro t h1t h2t have h1t_ : @MeasurableSet α m₀ t := h _ h1t rw [@measure_compl α m₀ μ t h1t_ (@measure_ne_top α m₀ μ _ t), @measure_compl α m₀ ν t h1t_ (@measure_ne_top α m₀ ν _ t), h_univ, h2t] · intro f h1f h2f h3f have h2f_ : ∀ i : ℕ, @MeasurableSet α m₀ (f i) := fun i => h _ (h2f i) simp [measure_iUnion, h1f, h3f, h2f_] #align measure_theory.ext_on_measurable_space_of_generate_finite MeasureTheory.ext_on_measurableSpace_of_generate_finite /-- Two finite measures are equal if they are equal on the π-system generating the σ-algebra (and `univ`). -/ theorem ext_of_generate_finite (C : Set (Set α)) (hA : m0 = generateFrom C) (hC : IsPiSystem C) [IsFiniteMeasure μ] (hμν : ∀ s ∈ C, μ s = ν s) (h_univ : μ univ = ν univ) : μ = ν := Measure.ext fun _s hs => ext_on_measurableSpace_of_generate_finite m0 C hμν le_rfl hA hC h_univ hs #align measure_theory.ext_of_generate_finite MeasureTheory.ext_of_generate_finite namespace Measure section disjointed /-- Given `S : μ.FiniteSpanningSetsIn {s | MeasurableSet s}`, `FiniteSpanningSetsIn.disjointed` provides a `FiniteSpanningSetsIn {s | MeasurableSet s}` such that its underlying sets are pairwise disjoint. -/ protected def FiniteSpanningSetsIn.disjointed {μ : Measure α} (S : μ.FiniteSpanningSetsIn { s | MeasurableSet s }) : μ.FiniteSpanningSetsIn { s | MeasurableSet s } := ⟨disjointed S.set, MeasurableSet.disjointed S.set_mem, fun n => lt_of_le_of_lt (measure_mono (disjointed_subset S.set n)) (S.finite _), S.spanning ▸ iUnion_disjointed⟩ #align measure_theory.measure.finite_spanning_sets_in.disjointed MeasureTheory.Measure.FiniteSpanningSetsIn.disjointed theorem FiniteSpanningSetsIn.disjointed_set_eq {μ : Measure α} (S : μ.FiniteSpanningSetsIn { s | MeasurableSet s }) : S.disjointed.set = disjointed S.set := rfl #align measure_theory.measure.finite_spanning_sets_in.disjointed_set_eq MeasureTheory.Measure.FiniteSpanningSetsIn.disjointed_set_eq theorem exists_eq_disjoint_finiteSpanningSetsIn (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν] : ∃ (S : μ.FiniteSpanningSetsIn { s | MeasurableSet s }) (T : ν.FiniteSpanningSetsIn { s | MeasurableSet s }), S.set = T.set ∧ Pairwise (Disjoint on S.set) := let S := (μ + ν).toFiniteSpanningSetsIn.disjointed ⟨S.ofLE (Measure.le_add_right le_rfl), S.ofLE (Measure.le_add_left le_rfl), rfl, disjoint_disjointed _⟩ #align measure_theory.measure.exists_eq_disjoint_finite_spanning_sets_in MeasureTheory.Measure.exists_eq_disjoint_finiteSpanningSetsIn end disjointed namespace FiniteAtFilter variable {f g : Filter α} theorem filter_mono (h : f ≤ g) : μ.FiniteAtFilter g → μ.FiniteAtFilter f := fun ⟨s, hs, hμ⟩ => ⟨s, h hs, hμ⟩ #align measure_theory.measure.finite_at_filter.filter_mono MeasureTheory.Measure.FiniteAtFilter.filter_mono theorem inf_of_left (h : μ.FiniteAtFilter f) : μ.FiniteAtFilter (f ⊓ g) := h.filter_mono inf_le_left #align measure_theory.measure.finite_at_filter.inf_of_left MeasureTheory.Measure.FiniteAtFilter.inf_of_left theorem inf_of_right (h : μ.FiniteAtFilter g) : μ.FiniteAtFilter (f ⊓ g) := h.filter_mono inf_le_right #align measure_theory.measure.finite_at_filter.inf_of_right MeasureTheory.Measure.FiniteAtFilter.inf_of_right @[simp] theorem inf_ae_iff : μ.FiniteAtFilter (f ⊓ ae μ) ↔ μ.FiniteAtFilter f := by refine ⟨?_, fun h => h.filter_mono inf_le_left⟩ rintro ⟨s, ⟨t, ht, u, hu, rfl⟩, hμ⟩ suffices μ t ≤ μ (t ∩ u) from ⟨t, ht, this.trans_lt hμ⟩ exact measure_mono_ae (mem_of_superset hu fun x hu ht => ⟨ht, hu⟩) #align measure_theory.measure.finite_at_filter.inf_ae_iff MeasureTheory.Measure.FiniteAtFilter.inf_ae_iff alias ⟨of_inf_ae, _⟩ := inf_ae_iff #align measure_theory.measure.finite_at_filter.of_inf_ae MeasureTheory.Measure.FiniteAtFilter.of_inf_ae theorem filter_mono_ae (h : f ⊓ (ae μ) ≤ g) (hg : μ.FiniteAtFilter g) : μ.FiniteAtFilter f := inf_ae_iff.1 (hg.filter_mono h) #align measure_theory.measure.finite_at_filter.filter_mono_ae MeasureTheory.Measure.FiniteAtFilter.filter_mono_ae protected theorem measure_mono (h : μ ≤ ν) : ν.FiniteAtFilter f → μ.FiniteAtFilter f := fun ⟨s, hs, hν⟩ => ⟨s, hs, (Measure.le_iff'.1 h s).trans_lt hν⟩ #align measure_theory.measure.finite_at_filter.measure_mono MeasureTheory.Measure.FiniteAtFilter.measure_mono @[mono] protected theorem mono (hf : f ≤ g) (hμ : μ ≤ ν) : ν.FiniteAtFilter g → μ.FiniteAtFilter f := fun h => (h.filter_mono hf).measure_mono hμ #align measure_theory.measure.finite_at_filter.mono MeasureTheory.Measure.FiniteAtFilter.mono protected theorem eventually (h : μ.FiniteAtFilter f) : ∀ᶠ s in f.smallSets, μ s < ∞ := (eventually_smallSets' fun _s _t hst ht => (measure_mono hst).trans_lt ht).2 h #align measure_theory.measure.finite_at_filter.eventually MeasureTheory.Measure.FiniteAtFilter.eventually theorem filterSup : μ.FiniteAtFilter f → μ.FiniteAtFilter g → μ.FiniteAtFilter (f ⊔ g) := fun ⟨s, hsf, hsμ⟩ ⟨t, htg, htμ⟩ => ⟨s ∪ t, union_mem_sup hsf htg, (measure_union_le s t).trans_lt (ENNReal.add_lt_top.2 ⟨hsμ, htμ⟩)⟩ #align measure_theory.measure.finite_at_filter.filter_sup MeasureTheory.Measure.FiniteAtFilter.filterSup end FiniteAtFilter theorem finiteAt_nhdsWithin [TopologicalSpace α] {_m0 : MeasurableSpace α} (μ : Measure α) [IsLocallyFiniteMeasure μ] (x : α) (s : Set α) : μ.FiniteAtFilter (𝓝[s] x) := (finiteAt_nhds μ x).inf_of_left #align measure_theory.measure.finite_at_nhds_within MeasureTheory.Measure.finiteAt_nhdsWithin @[simp] theorem finiteAt_principal : μ.FiniteAtFilter (𝓟 s) ↔ μ s < ∞ := ⟨fun ⟨_t, ht, hμ⟩ => (measure_mono ht).trans_lt hμ, fun h => ⟨s, mem_principal_self s, h⟩⟩ #align measure_theory.measure.finite_at_principal MeasureTheory.Measure.finiteAt_principal theorem isLocallyFiniteMeasure_of_le [TopologicalSpace α] {_m : MeasurableSpace α} {μ ν : Measure α} [H : IsLocallyFiniteMeasure μ] (h : ν ≤ μ) : IsLocallyFiniteMeasure ν := let F := H.finiteAtNhds ⟨fun x => (F x).measure_mono h⟩ #align measure_theory.measure.is_locally_finite_measure_of_le MeasureTheory.Measure.isLocallyFiniteMeasure_of_le end Measure end MeasureTheory namespace IsCompact variable [TopologicalSpace α] [MeasurableSpace α] {μ : Measure α} {s : Set α} /-- If `s` is a compact set and `μ` is finite at `𝓝 x` for every `x ∈ s`, then `s` admits an open superset of finite measure. -/ theorem exists_open_superset_measure_lt_top' (h : IsCompact s) (hμ : ∀ x ∈ s, μ.FiniteAtFilter (𝓝 x)) : ∃ U ⊇ s, IsOpen U ∧ μ U < ∞ := by refine IsCompact.induction_on h ?_ ?_ ?_ ?_ · use ∅ simp [Superset] · rintro s t hst ⟨U, htU, hUo, hU⟩ exact ⟨U, hst.trans htU, hUo, hU⟩ · rintro s t ⟨U, hsU, hUo, hU⟩ ⟨V, htV, hVo, hV⟩ refine ⟨U ∪ V, union_subset_union hsU htV, hUo.union hVo, (measure_union_le _ _).trans_lt <| ENNReal.add_lt_top.2 ⟨hU, hV⟩⟩ · intro x hx rcases (hμ x hx).exists_mem_basis (nhds_basis_opens _) with ⟨U, ⟨hx, hUo⟩, hU⟩ exact ⟨U, nhdsWithin_le_nhds (hUo.mem_nhds hx), U, Subset.rfl, hUo, hU⟩ #align is_compact.exists_open_superset_measure_lt_top' IsCompact.exists_open_superset_measure_lt_top' /-- If `s` is a compact set and `μ` is a locally finite measure, then `s` admits an open superset of finite measure. -/ theorem exists_open_superset_measure_lt_top (h : IsCompact s) (μ : Measure α) [IsLocallyFiniteMeasure μ] : ∃ U ⊇ s, IsOpen U ∧ μ U < ∞ := h.exists_open_superset_measure_lt_top' fun x _ => μ.finiteAt_nhds x #align is_compact.exists_open_superset_measure_lt_top IsCompact.exists_open_superset_measure_lt_top theorem measure_lt_top_of_nhdsWithin (h : IsCompact s) (hμ : ∀ x ∈ s, μ.FiniteAtFilter (𝓝[s] x)) : μ s < ∞ := IsCompact.induction_on h (by simp) (fun s t hst ht => (measure_mono hst).trans_lt ht) (fun s t hs ht => (measure_union_le s t).trans_lt (ENNReal.add_lt_top.2 ⟨hs, ht⟩)) hμ #align is_compact.measure_lt_top_of_nhds_within IsCompact.measure_lt_top_of_nhdsWithin
Mathlib/MeasureTheory/Measure/Typeclasses.lean
1,506
1,508
theorem measure_zero_of_nhdsWithin (hs : IsCompact s) : (∀ a ∈ s, ∃ t ∈ 𝓝[s] a, μ t = 0) → μ s = 0 := by
simpa only [← compl_mem_ae_iff] using hs.compl_mem_sets_of_nhdsWithin
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta, Jakob von Raumer -/ import Mathlib.CategoryTheory.Functor.Trifunctor import Mathlib.CategoryTheory.Products.Basic #align_import category_theory.monoidal.category from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Monoidal categories A monoidal category is a category equipped with a tensor product, unitors, and an associator. In the definition, we provide the tensor product as a pair of functions * `tensorObj : C → C → C` * `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))` and allow use of the overloaded notation `⊗` for both. The unitors and associator are provided componentwise. The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`. The unitors and associator are gathered together as natural isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`. Some consequences of the definition are proved in other files after proving the coherence theorem, e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`. ## Implementation notes In the definition of monoidal categories, we also provide the whiskering operators: * `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`, * `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`. These are products of an object and a morphism (the terminology "whiskering" is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined in terms of the whiskerings. There are two possible such definitions, which are related by the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def` and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds definitionally. If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it, you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`. The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories. ### Simp-normal form for morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal form defined below. Rewriting into simp-normal form is especially useful in preprocessing performed by the `coherence` tactic. The simp-normal form of morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is either a structural morphisms (morphisms made up only of identities, associators, unitors) or non-structural morphisms, and 2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`, where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural morphisms that is not the identity or a composite. Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`. Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`, respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon. ## References * Tensor categories, Etingof, Gelaki, Nikshych, Ostrik, http://www-math.mit.edu/~etingof/egnobookfinal.pdf * <https://stacks.math.columbia.edu/tag/0FFK>. -/ universe v u open CategoryTheory.Category open CategoryTheory.Iso namespace CategoryTheory /-- Auxiliary structure to carry only the data fields of (and provide notation for) `MonoidalCategory`. -/ class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where /-- curried tensor product of objects -/ tensorObj : C → C → C /-- left whiskering for morphisms -/ whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂ /-- right whiskering for morphisms -/ whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ -- By default, it is defined in terms of whiskerings. tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g: X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) := whiskerRight f X₂ ≫ whiskerLeft Y₁ g /-- The tensor unity in the monoidal structure `𝟙_ C` -/ tensorUnit : C /-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z) /-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/ leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X /-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/ rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X namespace MonoidalCategory export MonoidalCategoryStruct (tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor) end MonoidalCategory namespace MonoidalCategory /-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj /-- Notation for the `whiskerLeft` operator of monoidal categories -/ scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft /-- Notation for the `whiskerRight` operator of monoidal categories -/ scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight /-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom /-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/ scoped notation "𝟙_ " C:max => (MonoidalCategoryStruct.tensorUnit : C) open Lean PrettyPrinter.Delaborator SubExpr in /-- Used to ensure that `𝟙_` notation is used, as the ascription makes this not automatic. -/ @[delab app.CategoryTheory.MonoidalCategoryStruct.tensorUnit] def delabTensorUnit : Delab := whenPPOption getPPNotation <| withOverApp 3 do let e ← getExpr guard <| e.isAppOfArity ``MonoidalCategoryStruct.tensorUnit 3 let C ← withNaryArg 0 delab `(𝟙_ $C) /-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ scoped notation "α_" => MonoidalCategoryStruct.associator /-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/ scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor /-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/ scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor end MonoidalCategory open MonoidalCategory /-- In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`. Tensor product does not need to be strictly associative on objects, but there is a specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`, with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`. These associators and unitors satisfy the pentagon and triangle equations. See <https://stacks.math.columbia.edu/tag/0FFK>. -/ -- Porting note: The Mathport did not translate the temporary notation class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g: X₂ ⟶ Y₂) : f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by aesop_cat /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat /-- Composition of tensor products is tensor product of compositions: `(f₁ ⊗ g₁) ∘ (f₂ ⊗ g₂) = (f₁ ∘ f₂) ⊗ (g₁ ⊗ g₂)` -/ tensor_comp : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), (f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by aesop_cat whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by aesop_cat id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by aesop_cat /-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/ associator_naturality : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃), ((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by aesop_cat /-- Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y` -/ leftUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by aesop_cat /-- Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y` -/ rightUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by aesop_cat /-- The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W` -/ pentagon : ∀ W X Y Z : C, (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom = (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by aesop_cat /-- The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y` -/ triangle : ∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by aesop_cat #align category_theory.monoidal_category CategoryTheory.MonoidalCategory attribute [reassoc] MonoidalCategory.tensorHom_def attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id attribute [reassoc, simp] MonoidalCategory.id_whiskerRight attribute [reassoc] MonoidalCategory.tensor_comp attribute [simp] MonoidalCategory.tensor_comp attribute [reassoc] MonoidalCategory.associator_naturality attribute [reassoc] MonoidalCategory.leftUnitor_naturality attribute [reassoc] MonoidalCategory.rightUnitor_naturality attribute [reassoc (attr := simp)] MonoidalCategory.pentagon attribute [reassoc (attr := simp)] MonoidalCategory.triangle namespace MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] @[simp] theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : 𝟙 X ⊗ f = X ◁ f := by simp [tensorHom_def] @[simp] theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : f ⊗ 𝟙 Y = f ▷ Y := by simp [tensorHom_def] @[reassoc, simp] theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by simp only [← id_tensorHom, ← tensor_comp, comp_id] @[reassoc, simp] theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) : 𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom] #align category_theory.monoidal_category.left_unitor_conjugation CategoryTheory.MonoidalCategory.id_whiskerLeft @[reassoc, simp] theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc, simp] theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) : (f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by simp only [← tensorHom_id, ← tensor_comp, id_comp] @[reassoc, simp] theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) : f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id] #align category_theory.monoidal_category.right_unitor_conjugation CategoryTheory.MonoidalCategory.whiskerRight_id @[reassoc, simp] theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by simp only [← id_tensorHom, ← tensorHom_id] rw [associator_naturality] simp [tensor_id] @[reassoc, simp] theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc] theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id] @[reassoc] theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ := whisker_exchange f g ▸ tensorHom_def f g end MonoidalCategory open scoped MonoidalCategory open MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] namespace MonoidalCategory @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.hom ≫ X ◁ f.inv = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.hom ▷ Z ≫ f.inv ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.inv ≫ X ◁ f.hom = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.inv ▷ Z ≫ f.hom ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ f ≫ X ◁ inv f = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : f ▷ Z ≫ inv f ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ inv f ≫ X ◁ f = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : inv f ▷ Z ≫ f ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight] /-- The left whiskering of an isomorphism is an isomorphism. -/ @[simps] def whiskerLeftIso (X : C) {Y Z : C} (f : Y ≅ Z) : X ⊗ Y ≅ X ⊗ Z where hom := X ◁ f.hom inv := X ◁ f.inv instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : IsIso (X ◁ f) := (whiskerLeftIso X (asIso f)).isIso_hom @[simp] theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : inv (X ◁ f) = X ◁ inv f := by aesop_cat @[simp] lemma whiskerLeftIso_refl (W X : C) : whiskerLeftIso W (Iso.refl X) = Iso.refl (W ⊗ X) := Iso.ext (whiskerLeft_id W X) @[simp] lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) : whiskerLeftIso W (f ≪≫ g) = whiskerLeftIso W f ≪≫ whiskerLeftIso W g := Iso.ext (whiskerLeft_comp W f.hom g.hom) @[simp] lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X ≅ Y) : (whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl /-- The right whiskering of an isomorphism is an isomorphism. -/ @[simps!] def whiskerRightIso {X Y : C} (f : X ≅ Y) (Z : C) : X ⊗ Z ≅ Y ⊗ Z where hom := f.hom ▷ Z inv := f.inv ▷ Z instance whiskerRight_isIso {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : IsIso (f ▷ Z) := (whiskerRightIso (asIso f) Z).isIso_hom @[simp] theorem inv_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : inv (f ▷ Z) = inv f ▷ Z := by aesop_cat @[simp] lemma whiskerRightIso_refl (X W : C) : whiskerRightIso (Iso.refl X) W = Iso.refl (X ⊗ W) := Iso.ext (id_whiskerRight X W) @[simp] lemma whiskerRightIso_trans {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) (W : C) : whiskerRightIso (f ≪≫ g) W = whiskerRightIso f W ≪≫ whiskerRightIso g W := Iso.ext (comp_whiskerRight f.hom g.hom W) @[simp] lemma whiskerRightIso_symm {X Y : C} (f : X ≅ Y) (W : C) : (whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl end MonoidalCategory /-- The tensor product of two isomorphisms is an isomorphism. -/ @[simps] def tensorIso {C : Type u} {X Y X' Y' : C} [Category.{v} C] [MonoidalCategory.{v} C] (f : X ≅ Y) (g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' where hom := f.hom ⊗ g.hom inv := f.inv ⊗ g.inv hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id] inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id] #align category_theory.tensor_iso CategoryTheory.tensorIso /-- Notation for `tensorIso`, the tensor product of isomorphisms -/ infixr:70 " ⊗ " => tensorIso namespace MonoidalCategory section variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] instance tensor_isIso {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : IsIso (f ⊗ g) := (asIso f ⊗ asIso g).isIso_hom #align category_theory.monoidal_category.tensor_is_iso CategoryTheory.MonoidalCategory.tensor_isIso @[simp] theorem inv_tensor {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : inv (f ⊗ g) = inv f ⊗ inv g := by simp [tensorHom_def ,whisker_exchange] #align category_theory.monoidal_category.inv_tensor CategoryTheory.MonoidalCategory.inv_tensor variable {U V W X Y Z : C} theorem whiskerLeft_dite {P : Prop} [Decidable P] (X : C) {Y Z : C} (f : P → (Y ⟶ Z)) (f' : ¬P → (Y ⟶ Z)) : X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by split_ifs <;> rfl theorem dite_whiskerRight {P : Prop} [Decidable P] {X Y : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (Z : C): (if h : P then f h else f' h) ▷ Z = if h : P then f h ▷ Z else f' h ▷ Z := by split_ifs <;> rfl theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (f ⊗ if h : P then g h else g' h) = if h : P then f ⊗ g h else f ⊗ g' h := by split_ifs <;> rfl #align category_theory.monoidal_category.tensor_dite CategoryTheory.MonoidalCategory.tensor_dite theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f = if h : P then g h ⊗ f else g' h ⊗ f := by split_ifs <;> rfl #align category_theory.monoidal_category.dite_tensor CategoryTheory.MonoidalCategory.dite_tensor @[simp] theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) : X ◁ eqToHom f = eqToHom (congr_arg₂ tensorObj rfl f) := by cases f simp only [whiskerLeft_id, eqToHom_refl] @[simp] theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) : eqToHom f ▷ Z = eqToHom (congr_arg₂ tensorObj f rfl) := by cases f simp only [id_whiskerRight, eqToHom_refl] @[reassoc] theorem associator_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) := by simp @[reassoc] theorem associator_inv_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z := by simp @[reassoc] theorem whiskerRight_tensor_symm {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv := by simp @[reassoc] theorem associator_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom = (α_ X Y Z).hom ≫ X ◁ f ▷ Z := by simp @[reassoc] theorem associator_inv_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z ≫ (α_ X Y' Z).inv = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z := by simp @[reassoc] theorem whisker_assoc_symm (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom := by simp @[reassoc] theorem associator_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ X ◁ Y ◁ f := by simp @[reassoc] theorem associator_inv_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f ≫ (α_ X Y Z').inv = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f := by simp @[reassoc] theorem tensor_whiskerLeft_symm (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom := by simp @[reassoc] theorem leftUnitor_inv_naturality {X Y : C} (f : X ⟶ Y) : f ≫ (λ_ Y).inv = (λ_ X).inv ≫ _ ◁ f := by simp #align category_theory.monoidal_category.left_unitor_inv_naturality CategoryTheory.MonoidalCategory.leftUnitor_inv_naturality @[reassoc] theorem id_whiskerLeft_symm {X X' : C} (f : X ⟶ X') : f = (λ_ X).inv ≫ 𝟙_ C ◁ f ≫ (λ_ X').hom := by simp only [id_whiskerLeft, assoc, inv_hom_id, comp_id, inv_hom_id_assoc] @[reassoc] theorem rightUnitor_inv_naturality {X X' : C} (f : X ⟶ X') : f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ f ▷ _ := by simp #align category_theory.monoidal_category.right_unitor_inv_naturality CategoryTheory.MonoidalCategory.rightUnitor_inv_naturality @[reassoc] theorem whiskerRight_id_symm {X Y : C} (f : X ⟶ Y) : f = (ρ_ X).inv ≫ f ▷ 𝟙_ C ≫ (ρ_ Y).hom := by simp theorem whiskerLeft_iff {X Y : C} (f g : X ⟶ Y) : 𝟙_ C ◁ f = 𝟙_ C ◁ g ↔ f = g := by simp theorem whiskerRight_iff {X Y : C} (f g : X ⟶ Y) : f ▷ 𝟙_ C = g ▷ 𝟙_ C ↔ f = g := by simp /-! The lemmas in the next section are true by coherence, but we prove them directly as they are used in proving the coherence theorem. -/ section @[reassoc (attr := simp)] theorem pentagon_inv : W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z = (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv := eq_of_inv_eq_inv (by simp) #align category_theory.monoidal_category.pentagon_inv CategoryTheory.MonoidalCategory.pentagon_inv @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv : (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom = W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv := by rw [← cancel_epi (W ◁ (α_ X Y Z).inv), ← cancel_mono (α_ (W ⊗ X) Y Z).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv : (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom = (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Monoidal/Category.lean
543
546
theorem pentagon_hom_inv_inv_inv_inv : W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv = (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z := by
simp [← cancel_epi (W ◁ (α_ X Y Z).inv)]
/- 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
Mathlib/Probability/Martingale/BorelCantelli.lean
295
300
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]
/- 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]
Mathlib/MeasureTheory/Measure/FiniteMeasure.lean
262
264
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]
/- Copyright (c) 2020 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Computation.CorrectnessTerminating import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Data.Nat.Fib.Basic import Mathlib.Tactic.Monotonicity #align_import algebra.continued_fractions.computation.approximations from "leanprover-community/mathlib"@"a7e36e48519ab281320c4d192da6a7b348ce40ad" /-! # Approximations for Continued Fraction Computations (`GeneralizedContinuedFraction.of`) ## Summary This file contains useful approximations for the values involved in the continued fractions computation `GeneralizedContinuedFraction.of`. In particular, we derive the so-called *determinant formula* for `GeneralizedContinuedFraction.of`: `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1)^(n + 1)`. Moreover, we derive some upper bounds for the error term when computing a continued fraction up a given position, i.e. bounds for the term `|v - (GeneralizedContinuedFraction.of v).convergents n|`. The derived bounds will show us that the error term indeed gets smaller. As a corollary, we will be able to show that `(GeneralizedContinuedFraction.of v).convergents` converges to `v` in `Algebra.ContinuedFractions.Computation.ApproximationCorollaries`. ## Main Theorems - `GeneralizedContinuedFraction.of_part_num_eq_one`: shows that all partial numerators `aᵢ` are equal to one. - `GeneralizedContinuedFraction.exists_int_eq_of_part_denom`: shows that all partial denominators `bᵢ` correspond to an integer. - `GeneralizedContinuedFraction.of_one_le_get?_part_denom`: shows that `1 ≤ bᵢ`. - `GeneralizedContinuedFraction.succ_nth_fib_le_of_nth_denom`: shows that the `n`th denominator `Bₙ` is greater than or equal to the `n + 1`th fibonacci number `Nat.fib (n + 1)`. - `GeneralizedContinuedFraction.le_of_succ_get?_denom`: shows that `bₙ * Bₙ ≤ Bₙ₊₁`, where `bₙ` is the `n`th partial denominator of the continued fraction. - `GeneralizedContinuedFraction.abs_sub_convergents_le`: shows that `|v - Aₙ / Bₙ| ≤ 1 / (Bₙ * Bₙ₊₁)`, where `Aₙ` is the `n`th partial numerator. ## References - [*Hardy, GH and Wright, EM and Heath-Brown, Roger and Silverman, Joseph*][hardy2008introduction] - https://en.wikipedia.org/wiki/Generalized_continued_fraction#The_determinant_formula -/ namespace GeneralizedContinuedFraction open GeneralizedContinuedFraction (of) open Int variable {K : Type*} {v : K} {n : ℕ} [LinearOrderedField K] [FloorRing K] namespace IntFractPair /-! We begin with some lemmas about the stream of `IntFractPair`s, which presumably are not of great interest for the end user. -/ /-- Shows that the fractional parts of the stream are in `[0,1)`. -/ theorem nth_stream_fr_nonneg_lt_one {ifp_n : IntFractPair K} (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1 := by cases n with | zero => have : IntFractPair.of v = ifp_n := by injection nth_stream_eq rw [← this, IntFractPair.of] exact ⟨fract_nonneg _, fract_lt_one _⟩ | succ => rcases succ_nth_stream_eq_some_iff.1 nth_stream_eq with ⟨_, _, _, ifp_of_eq_ifp_n⟩ rw [← ifp_of_eq_ifp_n, IntFractPair.of] exact ⟨fract_nonneg _, fract_lt_one _⟩ #align generalized_continued_fraction.int_fract_pair.nth_stream_fr_nonneg_lt_one GeneralizedContinuedFraction.IntFractPair.nth_stream_fr_nonneg_lt_one /-- Shows that the fractional parts of the stream are nonnegative. -/ theorem nth_stream_fr_nonneg {ifp_n : IntFractPair K} (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr := (nth_stream_fr_nonneg_lt_one nth_stream_eq).left #align generalized_continued_fraction.int_fract_pair.nth_stream_fr_nonneg GeneralizedContinuedFraction.IntFractPair.nth_stream_fr_nonneg /-- Shows that the fractional parts of the stream are smaller than one. -/ theorem nth_stream_fr_lt_one {ifp_n : IntFractPair K} (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : ifp_n.fr < 1 := (nth_stream_fr_nonneg_lt_one nth_stream_eq).right #align generalized_continued_fraction.int_fract_pair.nth_stream_fr_lt_one GeneralizedContinuedFraction.IntFractPair.nth_stream_fr_lt_one /-- Shows that the integer parts of the stream are at least one. -/ theorem one_le_succ_nth_stream_b {ifp_succ_n : IntFractPair K} (succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) : 1 ≤ ifp_succ_n.b := by obtain ⟨ifp_n, nth_stream_eq, stream_nth_fr_ne_zero, ⟨-⟩⟩ : ∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n := succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq suffices 1 ≤ ifp_n.fr⁻¹ by rwa [IntFractPair.of, le_floor, cast_one] suffices ifp_n.fr ≤ 1 by have h : 0 < ifp_n.fr := lt_of_le_of_ne (nth_stream_fr_nonneg nth_stream_eq) stream_nth_fr_ne_zero.symm apply one_le_inv h this simp only [le_of_lt (nth_stream_fr_lt_one nth_stream_eq)] #align generalized_continued_fraction.int_fract_pair.one_le_succ_nth_stream_b GeneralizedContinuedFraction.IntFractPair.one_le_succ_nth_stream_b /-- Shows that the `n + 1`th integer part `bₙ₊₁` of the stream is smaller or equal than the inverse of the `n`th fractional part `frₙ` of the stream. This result is straight-forward as `bₙ₊₁` is defined as the floor of `1 / frₙ`. -/ theorem succ_nth_stream_b_le_nth_stream_fr_inv {ifp_n ifp_succ_n : IntFractPair K} (nth_stream_eq : IntFractPair.stream v n = some ifp_n) (succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) : (ifp_succ_n.b : K) ≤ ifp_n.fr⁻¹ := by suffices (⌊ifp_n.fr⁻¹⌋ : K) ≤ ifp_n.fr⁻¹ by cases' ifp_n with _ ifp_n_fr have : ifp_n_fr ≠ 0 := by intro h simp [h, IntFractPair.stream, nth_stream_eq] at succ_nth_stream_eq have : IntFractPair.of ifp_n_fr⁻¹ = ifp_succ_n := by simpa [this, IntFractPair.stream, nth_stream_eq, Option.coe_def] using succ_nth_stream_eq rwa [← this] exact floor_le ifp_n.fr⁻¹ #align generalized_continued_fraction.int_fract_pair.succ_nth_stream_b_le_nth_stream_fr_inv GeneralizedContinuedFraction.IntFractPair.succ_nth_stream_b_le_nth_stream_fr_inv end IntFractPair /-! Next we translate above results about the stream of `IntFractPair`s to the computed continued fraction `GeneralizedContinuedFraction.of`. -/ /-- Shows that the integer parts of the continued fraction are at least one. -/ theorem of_one_le_get?_part_denom {b : K} (nth_part_denom_eq : (of v).partialDenominators.get? n = some b) : 1 ≤ b := by obtain ⟨gp_n, nth_s_eq, ⟨-⟩⟩ : ∃ gp_n, (of v).s.get? n = some gp_n ∧ gp_n.b = b := exists_s_b_of_part_denom nth_part_denom_eq obtain ⟨ifp_n, succ_nth_stream_eq, ifp_n_b_eq_gp_n_b⟩ : ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ (ifp.b : K) = gp_n.b := IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq rw [← ifp_n_b_eq_gp_n_b] exact mod_cast IntFractPair.one_le_succ_nth_stream_b succ_nth_stream_eq #align generalized_continued_fraction.of_one_le_nth_part_denom GeneralizedContinuedFraction.of_one_le_get?_part_denom /-- Shows that the partial numerators `aᵢ` of the continued fraction are equal to one and the partial denominators `bᵢ` correspond to integers. -/ theorem of_part_num_eq_one_and_exists_int_part_denom_eq {gp : GeneralizedContinuedFraction.Pair K} (nth_s_eq : (of v).s.get? n = some gp) : gp.a = 1 ∧ ∃ z : ℤ, gp.b = (z : K) := by obtain ⟨ifp, stream_succ_nth_eq, -⟩ : ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ _ := IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq have : gp = ⟨1, ifp.b⟩ := by have : (of v).s.get? n = some ⟨1, ifp.b⟩ := get?_of_eq_some_of_succ_get?_intFractPair_stream stream_succ_nth_eq have : some gp = some ⟨1, ifp.b⟩ := by rwa [nth_s_eq] at this injection this simp [this] #align generalized_continued_fraction.of_part_num_eq_one_and_exists_int_part_denom_eq GeneralizedContinuedFraction.of_part_num_eq_one_and_exists_int_part_denom_eq /-- Shows that the partial numerators `aᵢ` are equal to one. -/ theorem of_part_num_eq_one {a : K} (nth_part_num_eq : (of v).partialNumerators.get? n = some a) : a = 1 := by obtain ⟨gp, nth_s_eq, gp_a_eq_a_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.a = a := exists_s_a_of_part_num nth_part_num_eq have : gp.a = 1 := (of_part_num_eq_one_and_exists_int_part_denom_eq nth_s_eq).left rwa [gp_a_eq_a_n] at this #align generalized_continued_fraction.of_part_num_eq_one GeneralizedContinuedFraction.of_part_num_eq_one /-- Shows that the partial denominators `bᵢ` correspond to an integer. -/
Mathlib/Algebra/ContinuedFractions/Computation/Approximations.lean
176
181
theorem exists_int_eq_of_part_denom {b : K} (nth_part_denom_eq : (of v).partialDenominators.get? n = some b) : ∃ z : ℤ, b = (z : K) := by
obtain ⟨gp, nth_s_eq, gp_b_eq_b_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.b = b := exists_s_b_of_part_denom nth_part_denom_eq have : ∃ z : ℤ, gp.b = (z : K) := (of_part_num_eq_one_and_exists_int_part_denom_eq nth_s_eq).right rwa [gp_b_eq_b_n] at this
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca, Eric Rodriguez -/ import Mathlib.NumberTheory.NumberField.Basic import Mathlib.RingTheory.Localization.NormTrace #align_import number_theory.number_field.norm from "leanprover-community/mathlib"@"00f91228655eecdcd3ac97a7fd8dbcb139fe990a" /-! # Norm in number fields Given a finite extension of number fields, we define the norm morphism as a function between the rings of integers. ## Main definitions * `RingOfIntegers.norm K` : `Algebra.norm` as a morphism `(𝓞 L) →* (𝓞 K)`. ## Main results * `RingOfIntegers.dvd_norm` : if `L/K` is a finite Galois extension of fields, then, for all `(x : 𝓞 L)` we have that `x ∣ algebraMap (𝓞 K) (𝓞 L) (norm K x)`. -/ open scoped NumberField open Finset NumberField Algebra FiniteDimensional section Rat variable {K : Type*} [Field K] [NumberField K] (x : 𝓞 K) theorem Algebra.coe_norm_int : (Algebra.norm ℤ x : ℚ) = Algebra.norm ℚ (x : K) := (Algebra.norm_localization (R := ℤ) (Rₘ := ℚ) (S := 𝓞 K) (Sₘ := K) (nonZeroDivisors ℤ) x).symm theorem Algebra.coe_trace_int : (Algebra.trace ℤ _ x : ℚ) = Algebra.trace ℚ K (x : K) := (Algebra.trace_localization (R := ℤ) (Rₘ := ℚ) (S := 𝓞 K) (Sₘ := K) (nonZeroDivisors ℤ) x).symm end Rat namespace RingOfIntegers variable {L : Type*} (K : Type*) [Field K] [Field L] [Algebra K L] [FiniteDimensional K L] /-- `Algebra.norm` as a morphism betwen the rings of integers. -/ noncomputable def norm [IsSeparable K L] : 𝓞 L →* 𝓞 K := RingOfIntegers.restrict_monoidHom ((Algebra.norm K).comp (algebraMap (𝓞 L) L : (𝓞 L) →* L)) fun x => isIntegral_norm K x.2 #align ring_of_integers.norm RingOfIntegers.norm @[simp] lemma coe_norm [IsSeparable K L] (x : 𝓞 L) : norm K x = Algebra.norm K (x : L) := rfl theorem coe_algebraMap_norm [IsSeparable K L] (x : 𝓞 L) : (algebraMap (𝓞 K) (𝓞 L) (norm K x) : L) = algebraMap K L (Algebra.norm K (x : L)) := rfl #align ring_of_integers.coe_algebra_map_norm RingOfIntegers.coe_algebraMap_norm theorem algebraMap_norm_algebraMap [IsSeparable K L] (x : 𝓞 K) : algebraMap _ K (norm K (algebraMap (𝓞 K) (𝓞 L) x)) = Algebra.norm K (algebraMap K L (algebraMap _ _ x)) := rfl #align ring_of_integers.coe_norm_algebra_map RingOfIntegers.algebraMap_norm_algebraMap
Mathlib/NumberTheory/NumberField/Norm.lean
65
69
theorem norm_algebraMap [IsSeparable K L] (x : 𝓞 K) : norm K (algebraMap (𝓞 K) (𝓞 L) x) = x ^ finrank K L := by
rw [RingOfIntegers.ext_iff, RingOfIntegers.coe_eq_algebraMap, RingOfIntegers.algebraMap_norm_algebraMap, Algebra.norm_algebraMap, RingOfIntegers.coe_eq_algebraMap, map_pow]
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Topology.Bases import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Compactness.SigmaCompact /-! # Lindelöf sets and Lindelöf spaces ## Main definitions We define the following properties for sets in a topological space: * `IsLindelof s`: Two definitions are possible here. The more standard definition is that every open cover that contains `s` contains a countable subcover. We choose for the equivalent definition where we require that every nontrivial filter on `s` with the countable intersection property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`. * `LindelofSpace X`: `X` is Lindelöf if it is Lindelöf as a set. * `NonLindelofSpace`: a space that is not a Lindëlof space, e.g. the Long Line. ## Main results * `isLindelof_iff_countable_subcover`: A set is Lindelöf iff every open cover has a countable subcover. ## Implementation details * This API is mainly based on the API for IsCompact and follows notation and style as much as possible. -/ open Set Filter Topology TopologicalSpace universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Lindelof /-- A set `s` is Lindelöf if every nontrivial filter `f` with the countable intersection property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by `isLindelof_iff_countable_subcover`. -/ def IsLindelof (s : Set X) := ∀ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x f /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢ exact hs inf_le_right /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx ↦ ?_ rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left] exact hf x hx /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a Lindelöf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X → Prop} (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, p s) → p (⋃₀ S)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a Lindelöf set and a closed set is a Lindelöf set. -/
Mathlib/Topology/Compactness/Lindelof.lean
78
83
theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by
intro f hnf _ hstf rw [← inf_principal, le_inf_iff] at hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs hstf.1 have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2 exact ⟨x, ⟨hsx, hxt⟩, hx⟩
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Analysis.Normed.Group.Basic #align_import analysis.normed.group.hom from "leanprover-community/mathlib"@"3c4225288b55380a90df078ebae0991080b12393" /-! # Normed groups homomorphisms This file gathers definitions and elementary constructions about bounded group homomorphisms between normed (abelian) groups (abbreviated to "normed group homs"). The main lemmas relate the boundedness condition to continuity and Lipschitzness. The main construction is to endow the type of normed group homs between two given normed groups with a group structure and a norm, giving rise to a normed group structure. We provide several simple constructions for normed group homs, like kernel, range and equalizer. Some easy other constructions are related to subgroups of normed groups. Since a lot of elementary properties don't require `‖x‖ = 0 → x = 0` we start setting up the theory of `SeminormedAddGroupHom` and we specialize to `NormedAddGroupHom` when needed. -/ noncomputable section open NNReal -- TODO: migrate to the new morphism / morphism_class style /-- A morphism of seminormed abelian groups is a bounded group homomorphism. -/ structure NormedAddGroupHom (V W : Type*) [SeminormedAddCommGroup V] [SeminormedAddCommGroup W] where /-- The function underlying a `NormedAddGroupHom` -/ toFun : V → W /-- A `NormedAddGroupHom` is additive. -/ map_add' : ∀ v₁ v₂, toFun (v₁ + v₂) = toFun v₁ + toFun v₂ /-- A `NormedAddGroupHom` is bounded. -/ bound' : ∃ C, ∀ v, ‖toFun v‖ ≤ C * ‖v‖ #align normed_add_group_hom NormedAddGroupHom namespace AddMonoidHom variable {V W : Type*} [SeminormedAddCommGroup V] [SeminormedAddCommGroup W] {f g : NormedAddGroupHom V W} /-- Associate to a group homomorphism a bounded group homomorphism under a norm control condition. See `AddMonoidHom.mkNormedAddGroupHom'` for a version that uses `ℝ≥0` for the bound. -/ def mkNormedAddGroupHom (f : V →+ W) (C : ℝ) (h : ∀ v, ‖f v‖ ≤ C * ‖v‖) : NormedAddGroupHom V W := { f with bound' := ⟨C, h⟩ } #align add_monoid_hom.mk_normed_add_group_hom AddMonoidHom.mkNormedAddGroupHom /-- Associate to a group homomorphism a bounded group homomorphism under a norm control condition. See `AddMonoidHom.mkNormedAddGroupHom` for a version that uses `ℝ` for the bound. -/ def mkNormedAddGroupHom' (f : V →+ W) (C : ℝ≥0) (hC : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) : NormedAddGroupHom V W := { f with bound' := ⟨C, hC⟩ } #align add_monoid_hom.mk_normed_add_group_hom' AddMonoidHom.mkNormedAddGroupHom' end AddMonoidHom theorem exists_pos_bound_of_bound {V W : Type*} [SeminormedAddCommGroup V] [SeminormedAddCommGroup W] {f : V → W} (M : ℝ) (h : ∀ x, ‖f x‖ ≤ M * ‖x‖) : ∃ N, 0 < N ∧ ∀ x, ‖f x‖ ≤ N * ‖x‖ := ⟨max M 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), fun x => calc ‖f x‖ ≤ M * ‖x‖ := h x _ ≤ max M 1 * ‖x‖ := by gcongr; apply le_max_left ⟩ #align exists_pos_bound_of_bound exists_pos_bound_of_bound namespace NormedAddGroupHom variable {V V₁ V₂ V₃ : Type*} [SeminormedAddCommGroup V] [SeminormedAddCommGroup V₁] [SeminormedAddCommGroup V₂] [SeminormedAddCommGroup V₃] variable {f g : NormedAddGroupHom V₁ V₂} /-- A Lipschitz continuous additive homomorphism is a normed additive group homomorphism. -/ def ofLipschitz (f : V₁ →+ V₂) {K : ℝ≥0} (h : LipschitzWith K f) : NormedAddGroupHom V₁ V₂ := f.mkNormedAddGroupHom K fun x ↦ by simpa only [map_zero, dist_zero_right] using h.dist_le_mul x 0 instance funLike : FunLike (NormedAddGroupHom V₁ V₂) V₁ V₂ where coe := toFun coe_injective' := fun f g h => by cases f; cases g; congr -- Porting note: moved this declaration up so we could get a `FunLike` instance sooner. instance toAddMonoidHomClass : AddMonoidHomClass (NormedAddGroupHom V₁ V₂) V₁ V₂ where map_add f := f.map_add' map_zero f := (AddMonoidHom.mk' f.toFun f.map_add').map_zero initialize_simps_projections NormedAddGroupHom (toFun → apply) theorem coe_inj (H : (f : V₁ → V₂) = g) : f = g := by cases f; cases g; congr #align normed_add_group_hom.coe_inj NormedAddGroupHom.coe_inj theorem coe_injective : @Function.Injective (NormedAddGroupHom V₁ V₂) (V₁ → V₂) toFun := by apply coe_inj #align normed_add_group_hom.coe_injective NormedAddGroupHom.coe_injective theorem coe_inj_iff : f = g ↔ (f : V₁ → V₂) = g := ⟨congr_arg _, coe_inj⟩ #align normed_add_group_hom.coe_inj_iff NormedAddGroupHom.coe_inj_iff @[ext] theorem ext (H : ∀ x, f x = g x) : f = g := coe_inj <| funext H #align normed_add_group_hom.ext NormedAddGroupHom.ext theorem ext_iff : f = g ↔ ∀ x, f x = g x := ⟨by rintro rfl x; rfl, ext⟩ #align normed_add_group_hom.ext_iff NormedAddGroupHom.ext_iff variable (f g) @[simp] theorem toFun_eq_coe : f.toFun = f := rfl #align normed_add_group_hom.to_fun_eq_coe NormedAddGroupHom.toFun_eq_coe -- Porting note: removed `simp` because `simpNF` complains the LHS doesn't simplify. theorem coe_mk (f) (h₁) (h₂) (h₃) : ⇑(⟨f, h₁, h₂, h₃⟩ : NormedAddGroupHom V₁ V₂) = f := rfl #align normed_add_group_hom.coe_mk NormedAddGroupHom.coe_mk @[simp] theorem coe_mkNormedAddGroupHom (f : V₁ →+ V₂) (C) (hC) : ⇑(f.mkNormedAddGroupHom C hC) = f := rfl #align normed_add_group_hom.coe_mk_normed_add_group_hom NormedAddGroupHom.coe_mkNormedAddGroupHom @[simp] theorem coe_mkNormedAddGroupHom' (f : V₁ →+ V₂) (C) (hC) : ⇑(f.mkNormedAddGroupHom' C hC) = f := rfl #align normed_add_group_hom.coe_mk_normed_add_group_hom' NormedAddGroupHom.coe_mkNormedAddGroupHom' /-- The group homomorphism underlying a bounded group homomorphism. -/ def toAddMonoidHom (f : NormedAddGroupHom V₁ V₂) : V₁ →+ V₂ := AddMonoidHom.mk' f f.map_add' #align normed_add_group_hom.to_add_monoid_hom NormedAddGroupHom.toAddMonoidHom @[simp] theorem coe_toAddMonoidHom : ⇑f.toAddMonoidHom = f := rfl #align normed_add_group_hom.coe_to_add_monoid_hom NormedAddGroupHom.coe_toAddMonoidHom theorem toAddMonoidHom_injective : Function.Injective (@NormedAddGroupHom.toAddMonoidHom V₁ V₂ _ _) := fun f g h => coe_inj <| by rw [← coe_toAddMonoidHom f, ← coe_toAddMonoidHom g, h] #align normed_add_group_hom.to_add_monoid_hom_injective NormedAddGroupHom.toAddMonoidHom_injective @[simp] theorem mk_toAddMonoidHom (f) (h₁) (h₂) : (⟨f, h₁, h₂⟩ : NormedAddGroupHom V₁ V₂).toAddMonoidHom = AddMonoidHom.mk' f h₁ := rfl #align normed_add_group_hom.mk_to_add_monoid_hom NormedAddGroupHom.mk_toAddMonoidHom theorem bound : ∃ C, 0 < C ∧ ∀ x, ‖f x‖ ≤ C * ‖x‖ := let ⟨_C, hC⟩ := f.bound' exists_pos_bound_of_bound _ hC #align normed_add_group_hom.bound NormedAddGroupHom.bound theorem antilipschitz_of_norm_ge {K : ℝ≥0} (h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f := AntilipschitzWith.of_le_mul_dist fun x y => by simpa only [dist_eq_norm, map_sub] using h (x - y) #align normed_add_group_hom.antilipschitz_of_norm_ge NormedAddGroupHom.antilipschitz_of_norm_ge /-- A normed group hom is surjective on the subgroup `K` with constant `C` if every element `x` of `K` has a preimage whose norm is bounded above by `C*‖x‖`. This is a more abstract version of `f` having a right inverse defined on `K` with operator norm at most `C`. -/ def SurjectiveOnWith (f : NormedAddGroupHom V₁ V₂) (K : AddSubgroup V₂) (C : ℝ) : Prop := ∀ h ∈ K, ∃ g, f g = h ∧ ‖g‖ ≤ C * ‖h‖ #align normed_add_group_hom.surjective_on_with NormedAddGroupHom.SurjectiveOnWith theorem SurjectiveOnWith.mono {f : NormedAddGroupHom V₁ V₂} {K : AddSubgroup V₂} {C C' : ℝ} (h : f.SurjectiveOnWith K C) (H : C ≤ C') : f.SurjectiveOnWith K C' := by intro k k_in rcases h k k_in with ⟨g, rfl, hg⟩ use g, rfl by_cases Hg : ‖f g‖ = 0 · simpa [Hg] using hg · exact hg.trans (by gcongr) #align normed_add_group_hom.surjective_on_with.mono NormedAddGroupHom.SurjectiveOnWith.mono theorem SurjectiveOnWith.exists_pos {f : NormedAddGroupHom V₁ V₂} {K : AddSubgroup V₂} {C : ℝ} (h : f.SurjectiveOnWith K C) : ∃ C' > 0, f.SurjectiveOnWith K C' := by refine ⟨|C| + 1, ?_, ?_⟩ · linarith [abs_nonneg C] · apply h.mono linarith [le_abs_self C] #align normed_add_group_hom.surjective_on_with.exists_pos NormedAddGroupHom.SurjectiveOnWith.exists_pos theorem SurjectiveOnWith.surjOn {f : NormedAddGroupHom V₁ V₂} {K : AddSubgroup V₂} {C : ℝ} (h : f.SurjectiveOnWith K C) : Set.SurjOn f Set.univ K := fun x hx => (h x hx).imp fun _a ⟨ha, _⟩ => ⟨Set.mem_univ _, ha⟩ #align normed_add_group_hom.surjective_on_with.surj_on NormedAddGroupHom.SurjectiveOnWith.surjOn /-! ### The operator norm -/ /-- The operator norm of a seminormed group homomorphism is the inf of all its bounds. -/ def opNorm (f : NormedAddGroupHom V₁ V₂) := sInf { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } #align normed_add_group_hom.op_norm NormedAddGroupHom.opNorm instance hasOpNorm : Norm (NormedAddGroupHom V₁ V₂) := ⟨opNorm⟩ #align normed_add_group_hom.has_op_norm NormedAddGroupHom.hasOpNorm theorem norm_def : ‖f‖ = sInf { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } := rfl #align normed_add_group_hom.norm_def NormedAddGroupHom.norm_def -- So that invocations of `le_csInf` make sense: we show that the set of -- bounds is nonempty and bounded below. theorem bounds_nonempty {f : NormedAddGroupHom V₁ V₂} : ∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } := let ⟨M, hMp, hMb⟩ := f.bound ⟨M, le_of_lt hMp, hMb⟩ #align normed_add_group_hom.bounds_nonempty NormedAddGroupHom.bounds_nonempty theorem bounds_bddBelow {f : NormedAddGroupHom V₁ V₂} : BddBelow { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } := ⟨0, fun _ ⟨hn, _⟩ => hn⟩ #align normed_add_group_hom.bounds_bdd_below NormedAddGroupHom.bounds_bddBelow theorem opNorm_nonneg : 0 ≤ ‖f‖ := le_csInf bounds_nonempty fun _ ⟨hx, _⟩ => hx #align normed_add_group_hom.op_norm_nonneg NormedAddGroupHom.opNorm_nonneg /-- The fundamental property of the operator norm: `‖f x‖ ≤ ‖f‖ * ‖x‖`. -/ theorem le_opNorm (x : V₁) : ‖f x‖ ≤ ‖f‖ * ‖x‖ := by obtain ⟨C, _Cpos, hC⟩ := f.bound replace hC := hC x by_cases h : ‖x‖ = 0 · rwa [h, mul_zero] at hC ⊢ have hlt : 0 < ‖x‖ := lt_of_le_of_ne (norm_nonneg x) (Ne.symm h) exact (div_le_iff hlt).mp (le_csInf bounds_nonempty fun c ⟨_, hc⟩ => (div_le_iff hlt).mpr <| by apply hc) #align normed_add_group_hom.le_op_norm NormedAddGroupHom.le_opNorm theorem le_opNorm_of_le {c : ℝ} {x} (h : ‖x‖ ≤ c) : ‖f x‖ ≤ ‖f‖ * c := le_trans (f.le_opNorm x) (by gcongr; exact f.opNorm_nonneg) #align normed_add_group_hom.le_op_norm_of_le NormedAddGroupHom.le_opNorm_of_le theorem le_of_opNorm_le {c : ℝ} (h : ‖f‖ ≤ c) (x : V₁) : ‖f x‖ ≤ c * ‖x‖ := (f.le_opNorm x).trans (by gcongr) #align normed_add_group_hom.le_of_op_norm_le NormedAddGroupHom.le_of_opNorm_le /-- continuous linear maps are Lipschitz continuous. -/ theorem lipschitz : LipschitzWith ⟨‖f‖, opNorm_nonneg f⟩ f := LipschitzWith.of_dist_le_mul fun x y => by rw [dist_eq_norm, dist_eq_norm, ← map_sub] apply le_opNorm #align normed_add_group_hom.lipschitz NormedAddGroupHom.lipschitz protected theorem uniformContinuous (f : NormedAddGroupHom V₁ V₂) : UniformContinuous f := f.lipschitz.uniformContinuous #align normed_add_group_hom.uniform_continuous NormedAddGroupHom.uniformContinuous @[continuity] protected theorem continuous (f : NormedAddGroupHom V₁ V₂) : Continuous f := f.uniformContinuous.continuous #align normed_add_group_hom.continuous NormedAddGroupHom.continuous theorem ratio_le_opNorm (x : V₁) : ‖f x‖ / ‖x‖ ≤ ‖f‖ := div_le_of_nonneg_of_le_mul (norm_nonneg _) f.opNorm_nonneg (le_opNorm _ _) #align normed_add_group_hom.ratio_le_op_norm NormedAddGroupHom.ratio_le_opNorm /-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/ theorem opNorm_le_bound {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ x, ‖f x‖ ≤ M * ‖x‖) : ‖f‖ ≤ M := csInf_le bounds_bddBelow ⟨hMp, hM⟩ #align normed_add_group_hom.op_norm_le_bound NormedAddGroupHom.opNorm_le_bound theorem opNorm_eq_of_bounds {M : ℝ} (M_nonneg : 0 ≤ M) (h_above : ∀ x, ‖f x‖ ≤ M * ‖x‖) (h_below : ∀ N ≥ 0, (∀ x, ‖f x‖ ≤ N * ‖x‖) → M ≤ N) : ‖f‖ = M := le_antisymm (f.opNorm_le_bound M_nonneg h_above) ((le_csInf_iff NormedAddGroupHom.bounds_bddBelow ⟨M, M_nonneg, h_above⟩).mpr fun N ⟨N_nonneg, hN⟩ => h_below N N_nonneg hN) #align normed_add_group_hom.op_norm_eq_of_bounds NormedAddGroupHom.opNorm_eq_of_bounds theorem opNorm_le_of_lipschitz {f : NormedAddGroupHom V₁ V₂} {K : ℝ≥0} (hf : LipschitzWith K f) : ‖f‖ ≤ K := f.opNorm_le_bound K.2 fun x => by simpa only [dist_zero_right, map_zero] using hf.dist_le_mul x 0 #align normed_add_group_hom.op_norm_le_of_lipschitz NormedAddGroupHom.opNorm_le_of_lipschitz /-- If a bounded group homomorphism map is constructed from a group homomorphism via the constructor `AddMonoidHom.mkNormedAddGroupHom`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ theorem mkNormedAddGroupHom_norm_le (f : V₁ →+ V₂) {C : ℝ} (hC : 0 ≤ C) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : ‖f.mkNormedAddGroupHom C h‖ ≤ C := opNorm_le_bound _ hC h #align normed_add_group_hom.mk_normed_add_group_hom_norm_le NormedAddGroupHom.mkNormedAddGroupHom_norm_le /-- If a bounded group homomorphism map is constructed from a group homomorphism via the constructor `NormedAddGroupHom.ofLipschitz`, then its norm is bounded by the bound given to the constructor. -/ theorem ofLipschitz_norm_le (f : V₁ →+ V₂) {K : ℝ≥0} (h : LipschitzWith K f) : ‖ofLipschitz f h‖ ≤ K := mkNormedAddGroupHom_norm_le f K.coe_nonneg _ /-- If a bounded group homomorphism map is constructed from a group homomorphism via the constructor `AddMonoidHom.mkNormedAddGroupHom`, then its norm is bounded by the bound given to the constructor or zero if this bound is negative. -/ theorem mkNormedAddGroupHom_norm_le' (f : V₁ →+ V₂) {C : ℝ} (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : ‖f.mkNormedAddGroupHom C h‖ ≤ max C 0 := opNorm_le_bound _ (le_max_right _ _) fun x => (h x).trans <| by gcongr; apply le_max_left #align normed_add_group_hom.mk_normed_add_group_hom_norm_le' NormedAddGroupHom.mkNormedAddGroupHom_norm_le' alias _root_.AddMonoidHom.mkNormedAddGroupHom_norm_le := mkNormedAddGroupHom_norm_le #align add_monoid_hom.mk_normed_add_group_hom_norm_le AddMonoidHom.mkNormedAddGroupHom_norm_le alias _root_.AddMonoidHom.mkNormedAddGroupHom_norm_le' := mkNormedAddGroupHom_norm_le' #align add_monoid_hom.mk_normed_add_group_hom_norm_le' AddMonoidHom.mkNormedAddGroupHom_norm_le' /-! ### Addition of normed group homs -/ /-- Addition of normed group homs. -/ instance add : Add (NormedAddGroupHom V₁ V₂) := ⟨fun f g => (f.toAddMonoidHom + g.toAddMonoidHom).mkNormedAddGroupHom (‖f‖ + ‖g‖) fun v => calc ‖f v + g v‖ ≤ ‖f v‖ + ‖g v‖ := norm_add_le _ _ _ ≤ ‖f‖ * ‖v‖ + ‖g‖ * ‖v‖ := by gcongr <;> apply le_opNorm _ = (‖f‖ + ‖g‖) * ‖v‖ := by rw [add_mul] ⟩ /-- The operator norm satisfies the triangle inequality. -/ theorem opNorm_add_le : ‖f + g‖ ≤ ‖f‖ + ‖g‖ := mkNormedAddGroupHom_norm_le _ (add_nonneg (opNorm_nonneg _) (opNorm_nonneg _)) _ #align normed_add_group_hom.op_norm_add_le NormedAddGroupHom.opNorm_add_le -- Porting note: this library note doesn't seem to apply anymore /- library_note "addition on function coercions"/-- Terms containing `@has_add.add (has_coe_to_fun.F ...) pi.has_add` seem to cause leanchecker to [crash due to an out-of-memory condition](https://github.com/leanprover-community/lean/issues/543). As a workaround, we add a type annotation: `(f + g : V₁ → V₂)` -/ -/ @[simp] theorem coe_add (f g : NormedAddGroupHom V₁ V₂) : ⇑(f + g) = f + g := rfl #align normed_add_group_hom.coe_add NormedAddGroupHom.coe_add @[simp] theorem add_apply (f g : NormedAddGroupHom V₁ V₂) (v : V₁) : (f + g) v = f v + g v := rfl #align normed_add_group_hom.add_apply NormedAddGroupHom.add_apply /-! ### The zero normed group hom -/ instance zero : Zero (NormedAddGroupHom V₁ V₂) := ⟨(0 : V₁ →+ V₂).mkNormedAddGroupHom 0 (by simp)⟩ instance inhabited : Inhabited (NormedAddGroupHom V₁ V₂) := ⟨0⟩ /-- The norm of the `0` operator is `0`. -/ theorem opNorm_zero : ‖(0 : NormedAddGroupHom V₁ V₂)‖ = 0 := le_antisymm (csInf_le bounds_bddBelow ⟨ge_of_eq rfl, fun _ => le_of_eq (by rw [zero_mul] exact norm_zero)⟩) (opNorm_nonneg _) #align normed_add_group_hom.op_norm_zero NormedAddGroupHom.opNorm_zero /-- For normed groups, an operator is zero iff its norm vanishes. -/ theorem opNorm_zero_iff {V₁ V₂ : Type*} [NormedAddCommGroup V₁] [NormedAddCommGroup V₂] {f : NormedAddGroupHom V₁ V₂} : ‖f‖ = 0 ↔ f = 0 := Iff.intro (fun hn => ext fun x => norm_le_zero_iff.1 (calc _ ≤ ‖f‖ * ‖x‖ := le_opNorm _ _ _ = _ := by rw [hn, zero_mul] )) fun hf => by rw [hf, opNorm_zero] #align normed_add_group_hom.op_norm_zero_iff NormedAddGroupHom.opNorm_zero_iff @[simp] theorem coe_zero : ⇑(0 : NormedAddGroupHom V₁ V₂) = 0 := rfl #align normed_add_group_hom.coe_zero NormedAddGroupHom.coe_zero @[simp] theorem zero_apply (v : V₁) : (0 : NormedAddGroupHom V₁ V₂) v = 0 := rfl #align normed_add_group_hom.zero_apply NormedAddGroupHom.zero_apply variable {f g} /-! ### The identity normed group hom -/ variable (V) /-- The identity as a continuous normed group hom. -/ @[simps!] def id : NormedAddGroupHom V V := (AddMonoidHom.id V).mkNormedAddGroupHom 1 (by simp [le_refl]) #align normed_add_group_hom.id NormedAddGroupHom.id /-- The norm of the identity is at most `1`. It is in fact `1`, except when the norm of every element vanishes, where it is `0`. (Since we are working with seminorms this can happen even if the space is non-trivial.) It means that one can not do better than an inequality in general. -/ theorem norm_id_le : ‖(id V : NormedAddGroupHom V V)‖ ≤ 1 := opNorm_le_bound _ zero_le_one fun x => by simp #align normed_add_group_hom.norm_id_le NormedAddGroupHom.norm_id_le /-- If there is an element with norm different from `0`, then the norm of the identity equals `1`. (Since we are working with seminorms supposing that the space is non-trivial is not enough.) -/ theorem norm_id_of_nontrivial_seminorm (h : ∃ x : V, ‖x‖ ≠ 0) : ‖id V‖ = 1 := le_antisymm (norm_id_le V) <| by let ⟨x, hx⟩ := h have := (id V).ratio_le_opNorm x rwa [id_apply, div_self hx] at this #align normed_add_group_hom.norm_id_of_nontrivial_seminorm NormedAddGroupHom.norm_id_of_nontrivial_seminorm /-- If a normed space is non-trivial, then the norm of the identity equals `1`. -/ theorem norm_id {V : Type*} [NormedAddCommGroup V] [Nontrivial V] : ‖id V‖ = 1 := by refine norm_id_of_nontrivial_seminorm V ?_ obtain ⟨x, hx⟩ := exists_ne (0 : V) exact ⟨x, ne_of_gt (norm_pos_iff.2 hx)⟩ #align normed_add_group_hom.norm_id NormedAddGroupHom.norm_id theorem coe_id : (NormedAddGroupHom.id V : V → V) = _root_.id := rfl #align normed_add_group_hom.coe_id NormedAddGroupHom.coe_id /-! ### The negation of a normed group hom -/ /-- Opposite of a normed group hom. -/ instance neg : Neg (NormedAddGroupHom V₁ V₂) := ⟨fun f => (-f.toAddMonoidHom).mkNormedAddGroupHom ‖f‖ fun v => by simp [le_opNorm f v]⟩ @[simp] theorem coe_neg (f : NormedAddGroupHom V₁ V₂) : ⇑(-f) = -f := rfl #align normed_add_group_hom.coe_neg NormedAddGroupHom.coe_neg @[simp] theorem neg_apply (f : NormedAddGroupHom V₁ V₂) (v : V₁) : (-f : NormedAddGroupHom V₁ V₂) v = -f v := rfl #align normed_add_group_hom.neg_apply NormedAddGroupHom.neg_apply theorem opNorm_neg (f : NormedAddGroupHom V₁ V₂) : ‖-f‖ = ‖f‖ := by simp only [norm_def, coe_neg, norm_neg, Pi.neg_apply] #align normed_add_group_hom.op_norm_neg NormedAddGroupHom.opNorm_neg /-! ### Subtraction of normed group homs -/ /-- Subtraction of normed group homs. -/ instance sub : Sub (NormedAddGroupHom V₁ V₂) := ⟨fun f g => { f.toAddMonoidHom - g.toAddMonoidHom with bound' := by simp only [AddMonoidHom.sub_apply, AddMonoidHom.toFun_eq_coe, sub_eq_add_neg] exact (f + -g).bound' }⟩ @[simp] theorem coe_sub (f g : NormedAddGroupHom V₁ V₂) : ⇑(f - g) = f - g := rfl #align normed_add_group_hom.coe_sub NormedAddGroupHom.coe_sub @[simp] theorem sub_apply (f g : NormedAddGroupHom V₁ V₂) (v : V₁) : (f - g : NormedAddGroupHom V₁ V₂) v = f v - g v := rfl #align normed_add_group_hom.sub_apply NormedAddGroupHom.sub_apply /-! ### Scalar actions on normed group homs -/ section SMul variable {R R' : Type*} [MonoidWithZero R] [DistribMulAction R V₂] [PseudoMetricSpace R] [BoundedSMul R V₂] [MonoidWithZero R'] [DistribMulAction R' V₂] [PseudoMetricSpace R'] [BoundedSMul R' V₂] instance smul : SMul R (NormedAddGroupHom V₁ V₂) where smul r f := { toFun := r • ⇑f map_add' := (r • f.toAddMonoidHom).map_add' bound' := let ⟨b, hb⟩ := f.bound' ⟨dist r 0 * b, fun x => by have := dist_smul_pair r (f x) (f 0) rw [map_zero, smul_zero, dist_zero_right, dist_zero_right] at this rw [mul_assoc] refine this.trans ?_ gcongr exact hb x⟩ } @[simp] theorem coe_smul (r : R) (f : NormedAddGroupHom V₁ V₂) : ⇑(r • f) = r • ⇑f := rfl #align normed_add_group_hom.coe_smul NormedAddGroupHom.coe_smul @[simp] theorem smul_apply (r : R) (f : NormedAddGroupHom V₁ V₂) (v : V₁) : (r • f) v = r • f v := rfl #align normed_add_group_hom.smul_apply NormedAddGroupHom.smul_apply instance smulCommClass [SMulCommClass R R' V₂] : SMulCommClass R R' (NormedAddGroupHom V₁ V₂) where smul_comm _ _ _ := ext fun _ => smul_comm _ _ _ instance isScalarTower [SMul R R'] [IsScalarTower R R' V₂] : IsScalarTower R R' (NormedAddGroupHom V₁ V₂) where smul_assoc _ _ _ := ext fun _ => smul_assoc _ _ _ instance isCentralScalar [DistribMulAction Rᵐᵒᵖ V₂] [IsCentralScalar R V₂] : IsCentralScalar R (NormedAddGroupHom V₁ V₂) where op_smul_eq_smul _ _ := ext fun _ => op_smul_eq_smul _ _ end SMul instance nsmul : SMul ℕ (NormedAddGroupHom V₁ V₂) where smul n f := { toFun := n • ⇑f map_add' := (n • f.toAddMonoidHom).map_add' bound' := let ⟨b, hb⟩ := f.bound' ⟨n • b, fun v => by rw [Pi.smul_apply, nsmul_eq_mul, mul_assoc] exact (norm_nsmul_le _ _).trans (by gcongr; apply hb)⟩ } #align normed_add_group_hom.has_nat_scalar NormedAddGroupHom.nsmul @[simp] theorem coe_nsmul (r : ℕ) (f : NormedAddGroupHom V₁ V₂) : ⇑(r • f) = r • ⇑f := rfl #align normed_add_group_hom.coe_nsmul NormedAddGroupHom.coe_nsmul @[simp] theorem nsmul_apply (r : ℕ) (f : NormedAddGroupHom V₁ V₂) (v : V₁) : (r • f) v = r • f v := rfl #align normed_add_group_hom.nsmul_apply NormedAddGroupHom.nsmul_apply instance zsmul : SMul ℤ (NormedAddGroupHom V₁ V₂) where smul z f := { toFun := z • ⇑f map_add' := (z • f.toAddMonoidHom).map_add' bound' := let ⟨b, hb⟩ := f.bound' ⟨‖z‖ • b, fun v => by rw [Pi.smul_apply, smul_eq_mul, mul_assoc] exact (norm_zsmul_le _ _).trans (by gcongr; apply hb)⟩ } #align normed_add_group_hom.has_int_scalar NormedAddGroupHom.zsmul @[simp] theorem coe_zsmul (r : ℤ) (f : NormedAddGroupHom V₁ V₂) : ⇑(r • f) = r • ⇑f := rfl #align normed_add_group_hom.coe_zsmul NormedAddGroupHom.coe_zsmul @[simp] theorem zsmul_apply (r : ℤ) (f : NormedAddGroupHom V₁ V₂) (v : V₁) : (r • f) v = r • f v := rfl #align normed_add_group_hom.zsmul_apply NormedAddGroupHom.zsmul_apply /-! ### Normed group structure on normed group homs -/ /-- Homs between two given normed groups form a commutative additive group. -/ instance toAddCommGroup : AddCommGroup (NormedAddGroupHom V₁ V₂) := coe_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl /-- Normed group homomorphisms themselves form a seminormed group with respect to the operator norm. -/ instance toSeminormedAddCommGroup : SeminormedAddCommGroup (NormedAddGroupHom V₁ V₂) := AddGroupSeminorm.toSeminormedAddCommGroup { toFun := opNorm map_zero' := opNorm_zero neg' := opNorm_neg add_le' := opNorm_add_le } #align normed_add_group_hom.to_seminormed_add_comm_group NormedAddGroupHom.toSeminormedAddCommGroup /-- Normed group homomorphisms themselves form a normed group with respect to the operator norm. -/ instance toNormedAddCommGroup {V₁ V₂ : Type*} [NormedAddCommGroup V₁] [NormedAddCommGroup V₂] : NormedAddCommGroup (NormedAddGroupHom V₁ V₂) := AddGroupNorm.toNormedAddCommGroup { toFun := opNorm map_zero' := opNorm_zero neg' := opNorm_neg add_le' := opNorm_add_le eq_zero_of_map_eq_zero' := fun _f => opNorm_zero_iff.1 } #align normed_add_group_hom.to_normed_add_comm_group NormedAddGroupHom.toNormedAddCommGroup /-- Coercion of a `NormedAddGroupHom` is an `AddMonoidHom`. Similar to `AddMonoidHom.coeFn`. -/ @[simps] def coeAddHom : NormedAddGroupHom V₁ V₂ →+ V₁ → V₂ where toFun := DFunLike.coe map_zero' := coe_zero map_add' := coe_add #align normed_add_group_hom.coe_fn_add_hom NormedAddGroupHom.coeAddHom @[simp] theorem coe_sum {ι : Type*} (s : Finset ι) (f : ι → NormedAddGroupHom V₁ V₂) : ⇑(∑ i ∈ s, f i) = ∑ i ∈ s, (f i : V₁ → V₂) := map_sum coeAddHom f s #align normed_add_group_hom.coe_sum NormedAddGroupHom.coe_sum theorem sum_apply {ι : Type*} (s : Finset ι) (f : ι → NormedAddGroupHom V₁ V₂) (v : V₁) : (∑ i ∈ s, f i) v = ∑ i ∈ s, f i v := by simp only [coe_sum, Finset.sum_apply] #align normed_add_group_hom.sum_apply NormedAddGroupHom.sum_apply /-! ### Module structure on normed group homs -/ instance distribMulAction {R : Type*} [MonoidWithZero R] [DistribMulAction R V₂] [PseudoMetricSpace R] [BoundedSMul R V₂] : DistribMulAction R (NormedAddGroupHom V₁ V₂) := Function.Injective.distribMulAction coeAddHom coe_injective coe_smul instance module {R : Type*} [Semiring R] [Module R V₂] [PseudoMetricSpace R] [BoundedSMul R V₂] : Module R (NormedAddGroupHom V₁ V₂) := Function.Injective.module _ coeAddHom coe_injective coe_smul /-! ### Composition of normed group homs -/ /-- The composition of continuous normed group homs. -/ @[simps!] protected def comp (g : NormedAddGroupHom V₂ V₃) (f : NormedAddGroupHom V₁ V₂) : NormedAddGroupHom V₁ V₃ := (g.toAddMonoidHom.comp f.toAddMonoidHom).mkNormedAddGroupHom (‖g‖ * ‖f‖) fun v => calc ‖g (f v)‖ ≤ ‖g‖ * ‖f v‖ := le_opNorm _ _ _ ≤ ‖g‖ * (‖f‖ * ‖v‖) := by gcongr; apply le_opNorm _ = ‖g‖ * ‖f‖ * ‖v‖ := by rw [mul_assoc] #align normed_add_group_hom.comp NormedAddGroupHom.comp theorem norm_comp_le (g : NormedAddGroupHom V₂ V₃) (f : NormedAddGroupHom V₁ V₂) : ‖g.comp f‖ ≤ ‖g‖ * ‖f‖ := mkNormedAddGroupHom_norm_le _ (mul_nonneg (opNorm_nonneg _) (opNorm_nonneg _)) _ #align normed_add_group_hom.norm_comp_le NormedAddGroupHom.norm_comp_le theorem norm_comp_le_of_le {g : NormedAddGroupHom V₂ V₃} {C₁ C₂ : ℝ} (hg : ‖g‖ ≤ C₂) (hf : ‖f‖ ≤ C₁) : ‖g.comp f‖ ≤ C₂ * C₁ := le_trans (norm_comp_le g f) <| by gcongr; exact le_trans (norm_nonneg _) hg #align normed_add_group_hom.norm_comp_le_of_le NormedAddGroupHom.norm_comp_le_of_le theorem norm_comp_le_of_le' {g : NormedAddGroupHom V₂ V₃} (C₁ C₂ C₃ : ℝ) (h : C₃ = C₂ * C₁) (hg : ‖g‖ ≤ C₂) (hf : ‖f‖ ≤ C₁) : ‖g.comp f‖ ≤ C₃ := by rw [h] exact norm_comp_le_of_le hg hf #align normed_add_group_hom.norm_comp_le_of_le' NormedAddGroupHom.norm_comp_le_of_le' /-- Composition of normed groups hom as an additive group morphism. -/ def compHom : NormedAddGroupHom V₂ V₃ →+ NormedAddGroupHom V₁ V₂ →+ NormedAddGroupHom V₁ V₃ := AddMonoidHom.mk' (fun g => AddMonoidHom.mk' (fun f => g.comp f) (by intros ext exact map_add g _ _)) (by intros ext simp only [comp_apply, Pi.add_apply, Function.comp_apply, AddMonoidHom.add_apply, AddMonoidHom.mk'_apply, coe_add]) #align normed_add_group_hom.comp_hom NormedAddGroupHom.compHom @[simp] theorem comp_zero (f : NormedAddGroupHom V₂ V₃) : f.comp (0 : NormedAddGroupHom V₁ V₂) = 0 := by ext exact map_zero f #align normed_add_group_hom.comp_zero NormedAddGroupHom.comp_zero @[simp] theorem zero_comp (f : NormedAddGroupHom V₁ V₂) : (0 : NormedAddGroupHom V₂ V₃).comp f = 0 := by ext rfl #align normed_add_group_hom.zero_comp NormedAddGroupHom.zero_comp theorem comp_assoc {V₄ : Type*} [SeminormedAddCommGroup V₄] (h : NormedAddGroupHom V₃ V₄) (g : NormedAddGroupHom V₂ V₃) (f : NormedAddGroupHom V₁ V₂) : (h.comp g).comp f = h.comp (g.comp f) := by ext rfl #align normed_add_group_hom.comp_assoc NormedAddGroupHom.comp_assoc theorem coe_comp (f : NormedAddGroupHom V₁ V₂) (g : NormedAddGroupHom V₂ V₃) : (g.comp f : V₁ → V₃) = (g : V₂ → V₃) ∘ (f : V₁ → V₂) := rfl #align normed_add_group_hom.coe_comp NormedAddGroupHom.coe_comp end NormedAddGroupHom namespace NormedAddGroupHom variable {V W V₁ V₂ V₃ : Type*} [SeminormedAddCommGroup V] [SeminormedAddCommGroup W] [SeminormedAddCommGroup V₁] [SeminormedAddCommGroup V₂] [SeminormedAddCommGroup V₃] /-- The inclusion of an `AddSubgroup`, as bounded group homomorphism. -/ @[simps!] def incl (s : AddSubgroup V) : NormedAddGroupHom s V where toFun := (Subtype.val : s → V) map_add' v w := AddSubgroup.coe_add _ _ _ bound' := ⟨1, fun v => by rw [one_mul, AddSubgroup.coe_norm]⟩ #align normed_add_group_hom.incl NormedAddGroupHom.incl theorem norm_incl {V' : AddSubgroup V} (x : V') : ‖incl _ x‖ = ‖x‖ := rfl #align normed_add_group_hom.norm_incl NormedAddGroupHom.norm_incl /-!### Kernel -/ section Kernels variable (f : NormedAddGroupHom V₁ V₂) (g : NormedAddGroupHom V₂ V₃) /-- The kernel of a bounded group homomorphism. Naturally endowed with a `SeminormedAddCommGroup` instance. -/ def ker : AddSubgroup V₁ := f.toAddMonoidHom.ker #align normed_add_group_hom.ker NormedAddGroupHom.ker theorem mem_ker (v : V₁) : v ∈ f.ker ↔ f v = 0 := by erw [f.toAddMonoidHom.mem_ker, coe_toAddMonoidHom] #align normed_add_group_hom.mem_ker NormedAddGroupHom.mem_ker /-- Given a normed group hom `f : V₁ → V₂` satisfying `g.comp f = 0` for some `g : V₂ → V₃`, the corestriction of `f` to the kernel of `g`. -/ @[simps] def ker.lift (h : g.comp f = 0) : NormedAddGroupHom V₁ g.ker where toFun v := ⟨f v, by rw [g.mem_ker, ← comp_apply g f, h, zero_apply]⟩ map_add' v w := by simp only [map_add, AddSubmonoid.mk_add_mk] bound' := f.bound' #align normed_add_group_hom.ker.lift NormedAddGroupHom.ker.lift @[simp] theorem ker.incl_comp_lift (h : g.comp f = 0) : (incl g.ker).comp (ker.lift f g h) = f := by ext rfl #align normed_add_group_hom.ker.incl_comp_lift NormedAddGroupHom.ker.incl_comp_lift @[simp] theorem ker_zero : (0 : NormedAddGroupHom V₁ V₂).ker = ⊤ := by ext simp [mem_ker] #align normed_add_group_hom.ker_zero NormedAddGroupHom.ker_zero theorem coe_ker : (f.ker : Set V₁) = (f : V₁ → V₂) ⁻¹' {0} := rfl #align normed_add_group_hom.coe_ker NormedAddGroupHom.coe_ker theorem isClosed_ker {V₂ : Type*} [NormedAddCommGroup V₂] (f : NormedAddGroupHom V₁ V₂) : IsClosed (f.ker : Set V₁) := f.coe_ker ▸ IsClosed.preimage f.continuous (T1Space.t1 0) #align normed_add_group_hom.is_closed_ker NormedAddGroupHom.isClosed_ker end Kernels /-! ### Range -/ section Range variable (f : NormedAddGroupHom V₁ V₂) (g : NormedAddGroupHom V₂ V₃) /-- The image of a bounded group homomorphism. Naturally endowed with a `SeminormedAddCommGroup` instance. -/ def range : AddSubgroup V₂ := f.toAddMonoidHom.range #align normed_add_group_hom.range NormedAddGroupHom.range theorem mem_range (v : V₂) : v ∈ f.range ↔ ∃ w, f w = v := Iff.rfl #align normed_add_group_hom.mem_range NormedAddGroupHom.mem_range @[simp] theorem mem_range_self (v : V₁) : f v ∈ f.range := ⟨v, rfl⟩ #align normed_add_group_hom.mem_range_self NormedAddGroupHom.mem_range_self theorem comp_range : (g.comp f).range = AddSubgroup.map g.toAddMonoidHom f.range := by erw [AddMonoidHom.map_range] rfl #align normed_add_group_hom.comp_range NormedAddGroupHom.comp_range theorem incl_range (s : AddSubgroup V₁) : (incl s).range = s := by ext x exact ⟨fun ⟨y, hy⟩ => by rw [← hy]; simp, fun hx => ⟨⟨x, hx⟩, by simp⟩⟩ #align normed_add_group_hom.incl_range NormedAddGroupHom.incl_range @[simp] theorem range_comp_incl_top : (f.comp (incl (⊤ : AddSubgroup V₁))).range = f.range := by simp [comp_range, incl_range, ← AddMonoidHom.range_eq_map]; rfl #align normed_add_group_hom.range_comp_incl_top NormedAddGroupHom.range_comp_incl_top end Range variable {f : NormedAddGroupHom V W} /-- A `NormedAddGroupHom` is *norm-nonincreasing* if `‖f v‖ ≤ ‖v‖` for all `v`. -/ def NormNoninc (f : NormedAddGroupHom V W) : Prop := ∀ v, ‖f v‖ ≤ ‖v‖ #align normed_add_group_hom.norm_noninc NormedAddGroupHom.NormNoninc namespace NormNoninc theorem normNoninc_iff_norm_le_one : f.NormNoninc ↔ ‖f‖ ≤ 1 := by refine ⟨fun h => ?_, fun h => fun v => ?_⟩ · refine opNorm_le_bound _ zero_le_one fun v => ?_ simpa [one_mul] using h v · simpa using le_of_opNorm_le f h v #align normed_add_group_hom.norm_noninc.norm_noninc_iff_norm_le_one NormedAddGroupHom.NormNoninc.normNoninc_iff_norm_le_one theorem zero : (0 : NormedAddGroupHom V₁ V₂).NormNoninc := fun v => by simp #align normed_add_group_hom.norm_noninc.zero NormedAddGroupHom.NormNoninc.zero theorem id : (id V).NormNoninc := fun _v => le_rfl #align normed_add_group_hom.norm_noninc.id NormedAddGroupHom.NormNoninc.id theorem comp {g : NormedAddGroupHom V₂ V₃} {f : NormedAddGroupHom V₁ V₂} (hg : g.NormNoninc) (hf : f.NormNoninc) : (g.comp f).NormNoninc := fun v => (hg (f v)).trans (hf v) #align normed_add_group_hom.norm_noninc.comp NormedAddGroupHom.NormNoninc.comp @[simp] theorem neg_iff {f : NormedAddGroupHom V₁ V₂} : (-f).NormNoninc ↔ f.NormNoninc := ⟨fun h x => by simpa using h x, fun h x => (norm_neg (f x)).le.trans (h x)⟩ #align normed_add_group_hom.norm_noninc.neg_iff NormedAddGroupHom.NormNoninc.neg_iff end NormNoninc section Isometry theorem norm_eq_of_isometry {f : NormedAddGroupHom V W} (hf : Isometry f) (v : V) : ‖f v‖ = ‖v‖ := (AddMonoidHomClass.isometry_iff_norm f).mp hf v #align normed_add_group_hom.norm_eq_of_isometry NormedAddGroupHom.norm_eq_of_isometry theorem isometry_id : @Isometry V V _ _ (id V) := _root_.isometry_id #align normed_add_group_hom.isometry_id NormedAddGroupHom.isometry_id theorem isometry_comp {g : NormedAddGroupHom V₂ V₃} {f : NormedAddGroupHom V₁ V₂} (hg : Isometry g) (hf : Isometry f) : Isometry (g.comp f) := hg.comp hf #align normed_add_group_hom.isometry_comp NormedAddGroupHom.isometry_comp theorem normNoninc_of_isometry (hf : Isometry f) : f.NormNoninc := fun v => le_of_eq <| norm_eq_of_isometry hf v #align normed_add_group_hom.norm_noninc_of_isometry NormedAddGroupHom.normNoninc_of_isometry end Isometry variable {W₁ W₂ W₃ : Type*} [SeminormedAddCommGroup W₁] [SeminormedAddCommGroup W₂] [SeminormedAddCommGroup W₃] variable (f) (g : NormedAddGroupHom V W) variable {f₁ g₁ : NormedAddGroupHom V₁ W₁} variable {f₂ g₂ : NormedAddGroupHom V₂ W₂} variable {f₃ g₃ : NormedAddGroupHom V₃ W₃} /-- The equalizer of two morphisms `f g : NormedAddGroupHom V W`. -/ def equalizer := (f - g).ker #align normed_add_group_hom.equalizer NormedAddGroupHom.equalizer namespace Equalizer /-- The inclusion of `f.equalizer g` as a `NormedAddGroupHom`. -/ def ι : NormedAddGroupHom (f.equalizer g) V := incl _ #align normed_add_group_hom.equalizer.ι NormedAddGroupHom.Equalizer.ι theorem comp_ι_eq : f.comp (ι f g) = g.comp (ι f g) := by ext x rw [comp_apply, comp_apply, ← sub_eq_zero, ← NormedAddGroupHom.sub_apply] exact x.2 #align normed_add_group_hom.equalizer.comp_ι_eq NormedAddGroupHom.Equalizer.comp_ι_eq variable {f g} /-- If `φ : NormedAddGroupHom V₁ V` is such that `f.comp φ = g.comp φ`, the induced morphism `NormedAddGroupHom V₁ (f.equalizer g)`. -/ @[simps] def lift (φ : NormedAddGroupHom V₁ V) (h : f.comp φ = g.comp φ) : NormedAddGroupHom V₁ (f.equalizer g) where toFun v := ⟨φ v, show (f - g) (φ v) = 0 by rw [NormedAddGroupHom.sub_apply, sub_eq_zero, ← comp_apply, h, comp_apply]⟩ map_add' v₁ v₂ := by ext simp only [map_add, AddSubgroup.coe_add, Subtype.coe_mk] bound' := by obtain ⟨C, _C_pos, hC⟩ := φ.bound exact ⟨C, hC⟩ #align normed_add_group_hom.equalizer.lift NormedAddGroupHom.Equalizer.lift @[simp] theorem ι_comp_lift (φ : NormedAddGroupHom V₁ V) (h : f.comp φ = g.comp φ) : (ι _ _).comp (lift φ h) = φ := by ext rfl #align normed_add_group_hom.equalizer.ι_comp_lift NormedAddGroupHom.Equalizer.ι_comp_lift /-- The lifting property of the equalizer as an equivalence. -/ @[simps] def liftEquiv : { φ : NormedAddGroupHom V₁ V // f.comp φ = g.comp φ } ≃ NormedAddGroupHom V₁ (f.equalizer g) where toFun φ := lift φ φ.prop invFun ψ := ⟨(ι f g).comp ψ, by rw [← comp_assoc, ← comp_assoc, comp_ι_eq]⟩ left_inv φ := by simp right_inv ψ := by ext rfl #align normed_add_group_hom.equalizer.lift_equiv NormedAddGroupHom.Equalizer.liftEquiv /-- Given `φ : NormedAddGroupHom V₁ V₂` and `ψ : NormedAddGroupHom W₁ W₂` such that `ψ.comp f₁ = f₂.comp φ` and `ψ.comp g₁ = g₂.comp φ`, the induced morphism `NormedAddGroupHom (f₁.equalizer g₁) (f₂.equalizer g₂)`. -/ def map (φ : NormedAddGroupHom V₁ V₂) (ψ : NormedAddGroupHom W₁ W₂) (hf : ψ.comp f₁ = f₂.comp φ) (hg : ψ.comp g₁ = g₂.comp φ) : NormedAddGroupHom (f₁.equalizer g₁) (f₂.equalizer g₂) := lift (φ.comp <| ι _ _) <| by simp only [← comp_assoc, ← hf, ← hg] simp only [comp_assoc, comp_ι_eq f₁ g₁] #align normed_add_group_hom.equalizer.map NormedAddGroupHom.Equalizer.map variable {φ : NormedAddGroupHom V₁ V₂} {ψ : NormedAddGroupHom W₁ W₂} variable {φ' : NormedAddGroupHom V₂ V₃} {ψ' : NormedAddGroupHom W₂ W₃} @[simp] theorem ι_comp_map (hf : ψ.comp f₁ = f₂.comp φ) (hg : ψ.comp g₁ = g₂.comp φ) : (ι f₂ g₂).comp (map φ ψ hf hg) = φ.comp (ι f₁ g₁) := ι_comp_lift _ _ #align normed_add_group_hom.equalizer.ι_comp_map NormedAddGroupHom.Equalizer.ι_comp_map @[simp]
Mathlib/Analysis/Normed/Group/Hom.lean
953
955
theorem map_id : map (f₂ := f₁) (g₂ := g₁) (id V₁) (id W₁) rfl rfl = id (f₁.equalizer g₁) := by
ext rfl
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad -/ import Mathlib.Init.Function import Mathlib.Init.Order.Defs #align_import data.bool.basic from "leanprover-community/mathlib"@"c4658a649d216f57e99621708b09dcb3dcccbd23" /-! # Booleans This file proves various trivial lemmas about booleans and their relation to decidable propositions. ## Tags bool, boolean, Bool, De Morgan -/ namespace Bool @[deprecated (since := "2024-06-07")] alias decide_True := decide_true_eq_true #align bool.to_bool_true decide_true_eq_true @[deprecated (since := "2024-06-07")] alias decide_False := decide_false_eq_false #align bool.to_bool_false decide_false_eq_false #align bool.to_bool_coe Bool.decide_coe @[deprecated (since := "2024-06-07")] alias coe_decide := decide_eq_true_iff #align bool.coe_to_bool decide_eq_true_iff @[deprecated decide_eq_true_iff (since := "2024-06-07")] alias of_decide_iff := decide_eq_true_iff #align bool.of_to_bool_iff decide_eq_true_iff #align bool.tt_eq_to_bool_iff true_eq_decide_iff #align bool.ff_eq_to_bool_iff false_eq_decide_iff @[deprecated (since := "2024-06-07")] alias decide_not := decide_not #align bool.to_bool_not decide_not #align bool.to_bool_and Bool.decide_and #align bool.to_bool_or Bool.decide_or #align bool.to_bool_eq decide_eq_decide @[deprecated (since := "2024-06-07")] alias not_false' := false_ne_true #align bool.not_ff Bool.false_ne_true @[deprecated (since := "2024-06-07")] alias eq_iff_eq_true_iff := eq_iff_iff #align bool.default_bool Bool.default_bool theorem dichotomy (b : Bool) : b = false ∨ b = true := by cases b <;> simp #align bool.dichotomy Bool.dichotomy theorem forall_bool' {p : Bool → Prop} (b : Bool) : (∀ x, p x) ↔ p b ∧ p !b := ⟨fun h ↦ ⟨h _, h _⟩, fun ⟨h₁, h₂⟩ x ↦ by cases b <;> cases x <;> assumption⟩ @[simp] theorem forall_bool {p : Bool → Prop} : (∀ b, p b) ↔ p false ∧ p true := forall_bool' false #align bool.forall_bool Bool.forall_bool theorem exists_bool' {p : Bool → Prop} (b : Bool) : (∃ x, p x) ↔ p b ∨ p !b := ⟨fun ⟨x, hx⟩ ↦ by cases x <;> cases b <;> first | exact .inl ‹_› | exact .inr ‹_›, fun h ↦ by cases h <;> exact ⟨_, ‹_›⟩⟩ @[simp] theorem exists_bool {p : Bool → Prop} : (∃ b, p b) ↔ p false ∨ p true := exists_bool' false #align bool.exists_bool Bool.exists_bool #align bool.decidable_forall_bool Bool.instDecidableForallOfDecidablePred #align bool.decidable_exists_bool Bool.instDecidableExistsOfDecidablePred #align bool.cond_eq_ite Bool.cond_eq_ite #align bool.cond_to_bool Bool.cond_decide #align bool.cond_bnot Bool.cond_not theorem not_ne_id : not ≠ id := fun h ↦ false_ne_true <| congrFun h true #align bool.bnot_ne_id Bool.not_ne_id #align bool.coe_bool_iff Bool.coe_iff_coe @[deprecated (since := "2024-06-07")] alias eq_true_of_ne_false := eq_true_of_ne_false #align bool.eq_tt_of_ne_ff eq_true_of_ne_false @[deprecated (since := "2024-06-07")] alias eq_false_of_ne_true := eq_false_of_ne_true #align bool.eq_ff_of_ne_tt eq_true_of_ne_false #align bool.bor_comm Bool.or_comm #align bool.bor_assoc Bool.or_assoc #align bool.bor_left_comm Bool.or_left_comm theorem or_inl {a b : Bool} (H : a) : a || b := by simp [H] #align bool.bor_inl Bool.or_inl theorem or_inr {a b : Bool} (H : b) : a || b := by cases a <;> simp [H] #align bool.bor_inr Bool.or_inr #align bool.band_comm Bool.and_comm #align bool.band_assoc Bool.and_assoc #align bool.band_left_comm Bool.and_left_comm theorem and_elim_left : ∀ {a b : Bool}, a && b → a := by decide #align bool.band_elim_left Bool.and_elim_left theorem and_intro : ∀ {a b : Bool}, a → b → a && b := by decide #align bool.band_intro Bool.and_intro theorem and_elim_right : ∀ {a b : Bool}, a && b → b := by decide #align bool.band_elim_right Bool.and_elim_right #align bool.band_bor_distrib_left Bool.and_or_distrib_left #align bool.band_bor_distrib_right Bool.and_or_distrib_right #align bool.bor_band_distrib_left Bool.or_and_distrib_left #align bool.bor_band_distrib_right Bool.or_and_distrib_right #align bool.bnot_ff Bool.not_false #align bool.bnot_tt Bool.not_true lemma eq_not_iff : ∀ {a b : Bool}, a = !b ↔ a ≠ b := by decide #align bool.eq_bnot_iff Bool.eq_not_iff lemma not_eq_iff : ∀ {a b : Bool}, !a = b ↔ a ≠ b := by decide #align bool.bnot_eq_iff Bool.not_eq_iff #align bool.not_eq_bnot Bool.not_eq_not #align bool.bnot_not_eq Bool.not_not_eq theorem ne_not {a b : Bool} : a ≠ !b ↔ a = b := not_eq_not #align bool.ne_bnot Bool.ne_not @[deprecated (since := "2024-06-07")] alias not_ne := not_not_eq #align bool.bnot_ne Bool.not_not_eq lemma not_ne_self : ∀ b : Bool, (!b) ≠ b := by decide #align bool.bnot_ne_self Bool.not_ne_self lemma self_ne_not : ∀ b : Bool, b ≠ !b := by decide #align bool.self_ne_bnot Bool.self_ne_not lemma eq_or_eq_not : ∀ a b, a = b ∨ a = !b := by decide #align bool.eq_or_eq_bnot Bool.eq_or_eq_not -- Porting note: naming issue again: these two `not` are different. theorem not_iff_not : ∀ {b : Bool}, !b ↔ ¬b := by simp #align bool.bnot_iff_not Bool.not_iff_not theorem eq_true_of_not_eq_false' {a : Bool} : !a = false → a = true := by cases a <;> decide #align bool.eq_tt_of_bnot_eq_ff Bool.eq_true_of_not_eq_false' theorem eq_false_of_not_eq_true' {a : Bool} : !a = true → a = false := by cases a <;> decide #align bool.eq_ff_of_bnot_eq_tt Bool.eq_false_of_not_eq_true' #align bool.band_bnot_self Bool.and_not_self #align bool.bnot_band_self Bool.not_and_self #align bool.bor_bnot_self Bool.or_not_self #align bool.bnot_bor_self Bool.not_or_self theorem bne_eq_xor : bne = xor := by funext a b; revert a b; decide #align bool.bxor_comm Bool.xor_comm attribute [simp] xor_assoc #align bool.bxor_assoc Bool.xor_assoc #align bool.bxor_left_comm Bool.xor_left_comm #align bool.bxor_bnot_left Bool.not_xor #align bool.bxor_bnot_right Bool.xor_not #align bool.bxor_bnot_bnot Bool.not_xor_not #align bool.bxor_ff_left Bool.false_xor #align bool.bxor_ff_right Bool.xor_false #align bool.band_bxor_distrib_left Bool.and_xor_distrib_left #align bool.band_bxor_distrib_right Bool.and_xor_distrib_right theorem xor_iff_ne : ∀ {x y : Bool}, xor x y = true ↔ x ≠ y := by decide #align bool.bxor_iff_ne Bool.xor_iff_ne /-! ### De Morgan's laws for booleans-/ #align bool.bnot_band Bool.not_and #align bool.bnot_bor Bool.not_or #align bool.bnot_inj Bool.not_inj instance linearOrder : LinearOrder Bool where le_refl := by decide le_trans := by decide le_antisymm := by decide le_total := by decide decidableLE := inferInstance decidableEq := inferInstance decidableLT := inferInstance lt_iff_le_not_le := by decide max_def := by decide min_def := by decide #align bool.linear_order Bool.linearOrder #align bool.ff_le Bool.false_le #align bool.le_tt Bool.le_true theorem lt_iff : ∀ {x y : Bool}, x < y ↔ x = false ∧ y = true := by decide #align bool.lt_iff Bool.lt_iff @[simp] theorem false_lt_true : false < true := lt_iff.2 ⟨rfl, rfl⟩ #align bool.ff_lt_tt Bool.false_lt_true theorem le_iff_imp : ∀ {x y : Bool}, x ≤ y ↔ x → y := by decide #align bool.le_iff_imp Bool.le_iff_imp theorem and_le_left : ∀ x y : Bool, (x && y) ≤ x := by decide #align bool.band_le_left Bool.and_le_left theorem and_le_right : ∀ x y : Bool, (x && y) ≤ y := by decide #align bool.band_le_right Bool.and_le_right theorem le_and : ∀ {x y z : Bool}, x ≤ y → x ≤ z → x ≤ (y && z) := by decide #align bool.le_band Bool.le_and theorem left_le_or : ∀ x y : Bool, x ≤ (x || y) := by decide #align bool.left_le_bor Bool.left_le_or theorem right_le_or : ∀ x y : Bool, y ≤ (x || y) := by decide #align bool.right_le_bor Bool.right_le_or theorem or_le : ∀ {x y z}, x ≤ z → y ≤ z → (x || y) ≤ z := by decide #align bool.bor_le Bool.or_le #align bool.to_nat Bool.toNat /-- convert a `ℕ` to a `Bool`, `0 -> false`, everything else -> `true` -/ def ofNat (n : Nat) : Bool := decide (n ≠ 0) #align bool.of_nat Bool.ofNat @[simp] lemma toNat_beq_zero (b : Bool) : (b.toNat == 0) = !b := by cases b <;> rfl @[simp] lemma toNat_bne_zero (b : Bool) : (b.toNat != 0) = b := by simp [bne] @[simp] lemma toNat_beq_one (b : Bool) : (b.toNat == 1) = b := by cases b <;> rfl @[simp] lemma toNat_bne_one (b : Bool) : (b.toNat != 1) = !b := by simp [bne] theorem ofNat_le_ofNat {n m : Nat} (h : n ≤ m) : ofNat n ≤ ofNat m := by simp only [ofNat, ne_eq, _root_.decide_not] cases Nat.decEq n 0 with | isTrue hn => rw [_root_.decide_eq_true hn]; exact Bool.false_le _ | isFalse hn => cases Nat.decEq m 0 with | isFalse hm => rw [_root_.decide_eq_false hm]; exact Bool.le_true _ | isTrue hm => subst hm; have h := Nat.le_antisymm h (Nat.zero_le n); contradiction #align bool.of_nat_le_of_nat Bool.ofNat_le_ofNat theorem toNat_le_toNat {b₀ b₁ : Bool} (h : b₀ ≤ b₁) : toNat b₀ ≤ toNat b₁ := by cases b₀ <;> cases b₁ <;> simp_all (config := { decide := true }) #align bool.to_nat_le_to_nat Bool.toNat_le_toNat theorem ofNat_toNat (b : Bool) : ofNat (toNat b) = b := by cases b <;> rfl #align bool.of_nat_to_nat Bool.ofNat_toNat @[simp] theorem injective_iff {α : Sort*} {f : Bool → α} : Function.Injective f ↔ f false ≠ f true := ⟨fun Hinj Heq ↦ false_ne_true (Hinj Heq), fun H x y hxy ↦ by cases x <;> cases y exacts [rfl, (H hxy).elim, (H hxy.symm).elim, rfl]⟩ #align bool.injective_iff Bool.injective_iff /-- **Kaminski's Equation** -/
Mathlib/Data/Bool/Basic.lean
277
278
theorem apply_apply_apply (f : Bool → Bool) (x : Bool) : f (f (f x)) = f x := by
cases x <;> cases h₁ : f true <;> cases h₂ : f false <;> simp only [h₁, h₂]
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: María Inés de Frutos-Fernández -/ import Mathlib.RingTheory.DedekindDomain.Ideal #align_import ring_theory.dedekind_domain.factorization from "leanprover-community/mathlib"@"2f588be38bb5bec02f218ba14f82fc82eb663f87" /-! # Factorization of ideals and fractional ideals of Dedekind domains Every nonzero ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are natural numbers. Similarly, every nonzero fractional ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are integers. We define `FractionalIdeal.count K v I` (abbreviated as `val_v(I)` in the documentation) to be `n_v`, and we prove some of its properties. If `I = 0`, we define `val_v(I) = 0`. ## Main definitions - `FractionalIdeal.count` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. ## Main results - `Ideal.finite_factors` : Only finitely many maximal ideals of `R` divide a given nonzero ideal. - `Ideal.finprod_heightOneSpectrum_factorization` : The ideal `I` equals the finprod `∏_v v^(val_v(I))`, where `val_v(I)` denotes the multiplicity of `v` in the factorization of `I` and `v` runs over the maximal ideals of `R`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization'` : If `I` is a nonzero fractional ideal, then `I` is equal to the product `∏_v v^(val_v(I))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization_principal` : For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. - `FractionalIdeal.finite_factors` : If `I ≠ 0`, then `val_v(I) = 0` for all but finitely many maximal ideals of `R`. ## Implementation notes Since we are only interested in the factorization of nonzero fractional ideals, we define `val_v(0) = 0` so that every `val_v` is in `ℤ` and we can avoid having to use `WithTop ℤ`. ## Tags dedekind domain, fractional ideal, ideal, factorization -/ noncomputable section open scoped Classical nonZeroDivisors open Set Function UniqueFactorizationMonoid IsDedekindDomain IsDedekindDomain.HeightOneSpectrum Classical variable {R : Type*} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] /-! ### Factorization of ideals of Dedekind domains -/ variable [IsDedekindDomain R] (v : HeightOneSpectrum R) /-- Given a maximal ideal `v` and an ideal `I` of `R`, `maxPowDividing` returns the maximal power of `v` dividing `I`. -/ def IsDedekindDomain.HeightOneSpectrum.maxPowDividing (I : Ideal R) : Ideal R := v.asIdeal ^ (Associates.mk v.asIdeal).count (Associates.mk I).factors #align is_dedekind_domain.height_one_spectrum.max_pow_dividing IsDedekindDomain.HeightOneSpectrum.maxPowDividing /-- Only finitely many maximal ideals of `R` divide a given nonzero ideal. -/ theorem Ideal.finite_factors {I : Ideal R} (hI : I ≠ 0) : {v : HeightOneSpectrum R | v.asIdeal ∣ I}.Finite := by rw [← Set.finite_coe_iff, Set.coe_setOf] haveI h_fin := fintypeSubtypeDvd I hI refine Finite.of_injective (fun v => (⟨(v : HeightOneSpectrum R).asIdeal, v.2⟩ : { x // x ∣ I })) ?_ intro v w hvw simp? at hvw says simp only [Subtype.mk.injEq] at hvw exact Subtype.coe_injective ((HeightOneSpectrum.ext_iff (R := R) ↑v ↑w).mpr hvw) #align ideal.finite_factors Ideal.finite_factors /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that the multiplicity of `v` in the factorization of `I`, denoted `val_v(I)`, is nonzero. -/ theorem Associates.finite_factors {I : Ideal R} (hI : I ≠ 0) : ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0 := by have h_supp : {v : HeightOneSpectrum R | ¬((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0} = {v : HeightOneSpectrum R | v.asIdeal ∣ I} := by ext v simp_rw [Int.natCast_eq_zero] exact Associates.count_ne_zero_iff_dvd hI v.irreducible rw [Filter.eventually_cofinite, h_supp] exact Ideal.finite_factors hI #align associates.finite_factors Associates.finite_factors namespace Ideal /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))` is not the unit ideal. -/ theorem finite_mulSupport {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => v.maxPowDividing I).Finite := haveI h_subset : {v : HeightOneSpectrum R | v.maxPowDividing I ≠ 1} ⊆ {v : HeightOneSpectrum R | ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) ≠ 0} := by intro v hv h_zero have hv' : v.maxPowDividing I = 1 := by rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, Int.natCast_eq_zero.mp h_zero, pow_zero _] exact hv hv' Finite.subset (Filter.eventually_cofinite.mp (Associates.finite_factors hI)) h_subset #align ideal.finite_mul_support Ideal.finite_mulSupport /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))`, regarded as a fractional ideal, is not `(1)`. -/ theorem finite_mulSupport_coe {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)).Finite := by rw [mulSupport] simp_rw [Ne, zpow_natCast, ← FractionalIdeal.coeIdeal_pow, FractionalIdeal.coeIdeal_eq_one] exact finite_mulSupport hI #align ideal.finite_mul_support_coe Ideal.finite_mulSupport_coe /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^-(val_v(I))` is not the unit ideal. -/ theorem finite_mulSupport_inv {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ (-((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ))).Finite := by rw [mulSupport] simp_rw [zpow_neg, Ne, inv_eq_one] exact finite_mulSupport_coe hI #align ideal.finite_mul_support_inv Ideal.finite_mulSupport_inv /-- For every nonzero ideal `I` of `v`, `v^(val_v(I) + 1)` does not divide `∏_v v^(val_v(I))`. -/ theorem finprod_not_dvd (I : Ideal R) (hI : I ≠ 0) : ¬v.asIdeal ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors + 1) ∣ ∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I := by have hf := finite_mulSupport hI have h_ne_zero : v.maxPowDividing I ≠ 0 := pow_ne_zero _ v.ne_bot rw [← mul_finprod_cond_ne v hf, pow_add, pow_one, finprod_cond_ne _ _ hf] intro h_contr have hv_prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime obtain ⟨w, hw, hvw'⟩ := Prime.exists_mem_finset_dvd hv_prime ((mul_dvd_mul_iff_left h_ne_zero).mp h_contr) have hw_prime : Prime w.asIdeal := Ideal.prime_of_isPrime w.ne_bot w.isPrime have hvw := Prime.dvd_of_dvd_pow hv_prime hvw' rw [Prime.dvd_prime_iff_associated hv_prime hw_prime, associated_iff_eq] at hvw exact (Finset.mem_erase.mp hw).1 (HeightOneSpectrum.ext w v (Eq.symm hvw)) #align ideal.finprod_not_dvd Ideal.finprod_not_dvd end Ideal theorem Associates.finprod_ne_zero (I : Ideal R) : Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I) ≠ 0 := by rw [Associates.mk_ne_zero, finprod_def] split_ifs · rw [Finset.prod_ne_zero_iff] intro v _ apply pow_ne_zero _ v.ne_bot · exact one_ne_zero #align associates.finprod_ne_zero Associates.finprod_ne_zero namespace Ideal /-- The multiplicity of `v` in `∏_v v^(val_v(I))` equals `val_v(I)`. -/ theorem finprod_count (I : Ideal R) (hI : I ≠ 0) : (Associates.mk v.asIdeal).count (Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I)).factors = (Associates.mk v.asIdeal).count (Associates.mk I).factors := by have h_ne_zero := Associates.finprod_ne_zero I have hv : Irreducible (Associates.mk v.asIdeal) := v.associates_irreducible have h_dvd := finprod_mem_dvd v (Ideal.finite_mulSupport hI) have h_not_dvd := Ideal.finprod_not_dvd v I hI simp only [IsDedekindDomain.HeightOneSpectrum.maxPowDividing] at h_dvd h_ne_zero h_not_dvd rw [← Associates.mk_dvd_mk] at h_dvd h_not_dvd simp only [Associates.dvd_eq_le] at h_dvd h_not_dvd rw [Associates.mk_pow, Associates.prime_pow_dvd_iff_le h_ne_zero hv] at h_dvd h_not_dvd rw [not_le] at h_not_dvd apply Nat.eq_of_le_of_lt_succ h_dvd h_not_dvd #align ideal.finprod_count Ideal.finprod_count /-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`. -/ theorem finprod_heightOneSpectrum_factorization {I : Ideal R} (hI : I ≠ 0) : ∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I = I := by rw [← associated_iff_eq, ← Associates.mk_eq_mk_iff_associated] apply Associates.eq_of_eq_counts · apply Associates.finprod_ne_zero I · apply Associates.mk_ne_zero.mpr hI intro v hv obtain ⟨J, hJv⟩ := Associates.exists_rep v rw [← hJv, Associates.irreducible_mk] at hv rw [← hJv] apply Ideal.finprod_count ⟨J, Ideal.isPrime_of_prime (irreducible_iff_prime.mp hv), Irreducible.ne_zero hv⟩ I hI #align ideal.finprod_height_one_spectrum_factorization Ideal.finprod_heightOneSpectrum_factorization variable (K) /-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`, when both sides are regarded as fractional ideals of `R`. -/ theorem finprod_heightOneSpectrum_factorization_coe {I : Ideal R} (hI : I ≠ 0) : (∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)) = I := by conv_rhs => rw [← Ideal.finprod_heightOneSpectrum_factorization hI] rw [FractionalIdeal.coeIdeal_finprod R⁰ K (le_refl _)] simp_rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, FractionalIdeal.coeIdeal_pow, zpow_natCast] #align ideal.finprod_height_one_spectrum_factorization_coe Ideal.finprod_heightOneSpectrum_factorization_coe end Ideal /-! ### Factorization of fractional ideals of Dedekind domains -/ namespace FractionalIdeal open Int IsLocalization /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. -/ theorem finprod_heightOneSpectrum_factorization {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) = I := by have hJ_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI haJ have hJ := Ideal.finprod_heightOneSpectrum_factorization_coe K hJ_ne_zero have ha_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI haJ have ha := Ideal.finprod_heightOneSpectrum_factorization_coe K ha_ne_zero rw [haJ, ← div_spanSingleton, div_eq_mul_inv, ← coeIdeal_span_singleton, ← hJ, ← ha, ← finprod_inv_distrib] simp_rw [← zpow_neg] rw [← finprod_mul_distrib (Ideal.finite_mulSupport_coe hJ_ne_zero) (Ideal.finite_mulSupport_inv ha_ne_zero)] apply finprod_congr intro v rw [← zpow_add₀ ((@coeIdeal_ne_zero R _ K _ _ _ _).mpr v.ne_bot), sub_eq_add_neg] /-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. -/ theorem finprod_heightOneSpectrum_factorization_principal_fraction {n : R} (hn : n ≠ 0) (d : ↥R⁰) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {n} : Ideal R)).factors - (Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑d : R)}) : Ideal R)).factors : ℤ) = spanSingleton R⁰ (mk' K n d) := by have hd_ne_zero : (algebraMap R K) (d : R) ≠ 0 := map_ne_zero_of_mem_nonZeroDivisors _ (IsFractionRing.injective R K) d.property have h0 : spanSingleton R⁰ (mk' K n d) ≠ 0 := by rw [spanSingleton_ne_zero_iff, IsFractionRing.mk'_eq_div, ne_eq, div_eq_zero_iff, not_or] exact ⟨(map_ne_zero_iff (algebraMap R K) (IsFractionRing.injective R K)).mpr hn, hd_ne_zero⟩ have hI : spanSingleton R⁰ (mk' K n d) = spanSingleton R⁰ ((algebraMap R K) d)⁻¹ * ↑(Ideal.span {n} : Ideal R) := by rw [coeIdeal_span_singleton, spanSingleton_mul_spanSingleton] apply congr_arg rw [IsFractionRing.mk'_eq_div, div_eq_mul_inv, mul_comm] exact finprod_heightOneSpectrum_factorization h0 hI /-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. -/ theorem finprod_heightOneSpectrum_factorization_principal {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) (k : K) (hk : I = spanSingleton R⁰ k) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose (mk'_surjective R⁰ k)} : Ideal R)).factors - (Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑(choose (choose_spec (mk'_surjective R⁰ k)) : ↥R⁰) : R)}) : Ideal R)).factors : ℤ) = I := by set n : R := choose (mk'_surjective R⁰ k) set d : ↥R⁰ := choose (choose_spec (mk'_surjective R⁰ k)) have hnd : mk' K n d = k := choose_spec (choose_spec (mk'_surjective R⁰ k)) have hn0 : n ≠ 0 := by by_contra h rw [← hnd, h, IsFractionRing.mk'_eq_div, _root_.map_zero, zero_div, spanSingleton_zero] at hk exact hI hk rw [finprod_heightOneSpectrum_factorization_principal_fraction hn0 d, hk, hnd] variable (K) /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. -/ def count (I : FractionalIdeal R⁰ K) : ℤ := dite (I = 0) (fun _ : I = 0 => 0) fun _ : ¬I = 0 => let a := choose (exists_eq_spanSingleton_mul I) let J := choose (choose_spec (exists_eq_spanSingleton_mul I)) ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) /-- val_v(0) = 0. -/ lemma count_zero : count K v (0 : FractionalIdeal R⁰ K) = 0 := by simp only [count, dif_pos] lemma count_ne_zero {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) : count K v I = ((Associates.mk v.asIdeal).count (Associates.mk (choose (choose_spec (exists_eq_spanSingleton_mul I)))).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose (exists_eq_spanSingleton_mul I)})).factors : ℤ) := by simp only [count, dif_neg hI] /-- `val_v(I)` does not depend on the choice of `a` and `J` used to represent `I`. -/ theorem count_well_defined {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (h_aJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : count K v I = ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) := by set a₁ := choose (exists_eq_spanSingleton_mul I) set J₁ := choose (choose_spec (exists_eq_spanSingleton_mul I)) have h_a₁J₁ : I = spanSingleton R⁰ ((algebraMap R K) a₁)⁻¹ * ↑J₁ := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2 have h_a₁_ne_zero : a₁ ≠ 0 := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).1 have h_J₁_ne_zero : J₁ ≠ 0 := ideal_factor_ne_zero hI h_a₁J₁ have h_a_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI h_aJ have h_J_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI h_aJ have h_a₁' : spanSingleton R⁰ ((algebraMap R K) a₁) ≠ 0 := by rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero, Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))] exact h_a₁_ne_zero have h_a' : spanSingleton R⁰ ((algebraMap R K) a) ≠ 0 := by rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero, Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))] rw [ne_eq, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] at h_a_ne_zero exact h_a_ne_zero have hv : Irreducible (Associates.mk v.asIdeal) := by exact Associates.irreducible_mk.mpr v.irreducible rw [h_a₁J₁, ← div_spanSingleton, ← div_spanSingleton, div_eq_div_iff h_a₁' h_a', ← coeIdeal_span_singleton, ← coeIdeal_span_singleton, ← coeIdeal_mul, ← coeIdeal_mul] at h_aJ rw [count, dif_neg hI, sub_eq_sub_iff_add_eq_add, ← ofNat_add, ← ofNat_add, natCast_inj, ← Associates.count_mul _ _ hv, ← Associates.count_mul _ _ hv, Associates.mk_mul_mk, Associates.mk_mul_mk, coeIdeal_injective h_aJ] · rw [ne_eq, Associates.mk_eq_zero]; exact h_J_ne_zero · rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] exact h_a₁_ne_zero · rw [ne_eq, Associates.mk_eq_zero]; exact h_J₁_ne_zero · rw [ne_eq, Associates.mk_eq_zero]; exact h_a_ne_zero /-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. -/ theorem count_mul {I I' : FractionalIdeal R⁰ K} (hI : I ≠ 0) (hI' : I' ≠ 0) : count K v (I * I') = count K v I + count K v I' := by have hv : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible obtain ⟨a, J, ha, haJ⟩ := exists_eq_spanSingleton_mul I have ha_ne_zero : Associates.mk (Ideal.span {a} : Ideal R) ≠ 0 := by rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha have hJ_ne_zero : Associates.mk J ≠ 0 := Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI haJ) obtain ⟨a', J', ha', haJ'⟩ := exists_eq_spanSingleton_mul I' have ha'_ne_zero : Associates.mk (Ideal.span {a'} : Ideal R) ≠ 0 := by rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha' have hJ'_ne_zero : Associates.mk J' ≠ 0 := Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI' haJ') have h_prod : I * I' = spanSingleton R⁰ ((algebraMap R K) (a * a'))⁻¹ * ↑(J * J') := by rw [haJ, haJ', mul_assoc, mul_comm (J : FractionalIdeal R⁰ K), mul_assoc, ← mul_assoc, spanSingleton_mul_spanSingleton, coeIdeal_mul, RingHom.map_mul, mul_inv, mul_comm (J : FractionalIdeal R⁰ K)] rw [count_well_defined K v hI haJ, count_well_defined K v hI' haJ', count_well_defined K v (mul_ne_zero hI hI') h_prod, ← Associates.mk_mul_mk, Associates.count_mul hJ_ne_zero hJ'_ne_zero hv, ← Ideal.span_singleton_mul_span_singleton, ← Associates.mk_mul_mk, Associates.count_mul ha_ne_zero ha'_ne_zero hv] push_cast ring /-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. If `I` or `I'` is zero, then `val_v(I*I') = 0`. -/ theorem count_mul' (I I' : FractionalIdeal R⁰ K) : count K v (I * I') = if I ≠ 0 ∧ I' ≠ 0 then count K v I + count K v I' else 0 := by split_ifs with h · exact count_mul K v h.1 h.2 · push_neg at h by_cases hI : I = 0 · rw [hI, MulZeroClass.zero_mul, count, dif_pos (Eq.refl _)] · rw [h hI, MulZeroClass.mul_zero, count, dif_pos (Eq.refl _)] /-- val_v(1) = 0. -/ theorem count_one : count K v (1 : FractionalIdeal R⁰ K) = 0 := by have h1 : (1 : FractionalIdeal R⁰ K) = spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑(1 : Ideal R) := by rw [(algebraMap R K).map_one, Ideal.one_eq_top, coeIdeal_top, mul_one, inv_one, spanSingleton_one] rw [count_well_defined K v one_ne_zero h1, Ideal.span_singleton_one, Ideal.one_eq_top, sub_self] theorem count_prod {ι} (s : Finset ι) (I : ι → FractionalIdeal R⁰ K) (hS : ∀ i ∈ s, I i ≠ 0) : count K v (∏ i ∈ s, I i) = ∑ i ∈ s, count K v (I i) := by induction' s using Finset.induction with i s hi hrec · rw [Finset.prod_empty, Finset.sum_empty, count_one] · have hS' : ∀ i ∈ s, I i ≠ 0 := fun j hj => hS j (Finset.mem_insert_of_mem hj) have hS0 : ∏ i ∈ s, I i ≠ 0 := Finset.prod_ne_zero_iff.mpr hS' have hi0 : I i ≠ 0 := hS i (Finset.mem_insert_self i s) rw [Finset.prod_insert hi, Finset.sum_insert hi, count_mul K v hi0 hS0, hrec hS'] /-- For every `n ∈ ℕ` and every ideal `I`, `val_v(I^n) = n*val_v(I)`. -/ theorem count_pow (n : ℕ) (I : FractionalIdeal R⁰ K) : count K v (I ^ n) = n * count K v I := by induction' n with n h · rw [pow_zero, ofNat_zero, MulZeroClass.zero_mul, count_one] · rw [pow_succ, count_mul'] by_cases hI : I = 0 · have h_neg : ¬(I ^ n ≠ 0 ∧ I ≠ 0) := by rw [not_and', not_not, ne_eq] intro h exact absurd hI h rw [if_neg h_neg, hI, count_zero, MulZeroClass.mul_zero] · rw [if_pos (And.intro (pow_ne_zero n hI) hI), h, Nat.cast_add, Nat.cast_one] ring /-- `val_v(v) = 1`, when `v` is regarded as a fractional ideal. -/ theorem count_self : count K v (v.asIdeal : FractionalIdeal R⁰ K) = 1 := by have hv : (v.asIdeal : FractionalIdeal R⁰ K) ≠ 0 := coeIdeal_ne_zero.mpr v.ne_bot have h_self : (v.asIdeal : FractionalIdeal R⁰ K) = spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑v.asIdeal := by rw [(algebraMap R K).map_one, inv_one, spanSingleton_one, one_mul] have hv_irred : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible rw [count_well_defined K v hv h_self, Associates.count_self hv_irred, Ideal.span_singleton_one, ← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one, Associates.count_zero hv_irred, ofNat_zero, sub_zero, ofNat_one] /-- `val_v(v^n) = n` for every `n ∈ ℕ`. -/ theorem count_pow_self (n : ℕ) : count K v ((v.asIdeal : FractionalIdeal R⁰ K) ^ n) = n := by rw [count_pow, count_self, mul_one] /-- `val_v(I⁻ⁿ) = -val_v(Iⁿ)` for every `n ∈ ℤ`. -/
Mathlib/RingTheory/DedekindDomain/Factorization.lean
412
420
theorem count_neg_zpow (n : ℤ) (I : FractionalIdeal R⁰ K) : count K v (I ^ (-n)) = - count K v (I ^ n) := by
by_cases hI : I = 0 · by_cases hn : n = 0 · rw [hn, neg_zero, zpow_zero, count_one, neg_zero] · rw [hI, zero_zpow n hn, zero_zpow (-n) (neg_ne_zero.mpr hn), count_zero, neg_zero] · rw [eq_neg_iff_add_eq_zero, ← count_mul K v (zpow_ne_zero _ hI) (zpow_ne_zero _ hI), ← zpow_add₀ hI, neg_add_self, zpow_zero] exact count_one K v
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.MvPolynomial.Rename import Mathlib.Algebra.MvPolynomial.Degrees import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp [f, g] rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp [f, g] rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum @[simp] theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C @[simp] theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X @[simp] theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ @[simps!] def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft lemma optionEquivLeft_X_some (x : S₁) : optionEquivLeft R S₁ (X (some x)) = Polynomial.C (X x) := by simp only [optionEquivLeft_apply, aeval_X] lemma optionEquivLeft_X_none : optionEquivLeft R S₁ (X none) = Polynomial.X := by simp only [optionEquivLeft_apply, aeval_X] lemma optionEquivLeft_C (r : R) : optionEquivLeft R S₁ (C r) = Polynomial.C (C r) := by simp only [optionEquivLeft_apply, aeval_C, Polynomial.algebraMap_apply, algebraMap_eq] end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ @[simps!] def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight lemma optionEquivRight_X_some (x : S₁) : optionEquivRight R S₁ (X (some x)) = X x := by simp only [optionEquivRight_apply, aeval_X] lemma optionEquivRight_X_none : optionEquivRight R S₁ (X none) = C Polynomial.X := by simp only [optionEquivRight_apply, aeval_X] lemma optionEquivRight_C (r : R) : optionEquivRight R S₁ (C r) = C (Polynomial.C r) := by simp only [optionEquivRight_apply, aeval_C, algebraMap_apply, Polynomial.algebraMap_eq] variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine Fin.cases ?_ ?_ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine RingHom.ext fun x => ?_ rw [RingHom.comp_apply] refine (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) ?_) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true] have hmj : m ≠ j.tail := by rintro rfl rw [cons_tail] at hjmi contradiction simpa only [monomial_eq, C_1, one_mul, prod_pow, Finsupp.tail_apply, if_neg hmj.symm] using coeff_monomial m j.tail (1 : R) #align mv_polynomial.fin_succ_equiv_coeff_coeff MvPolynomial.finSuccEquiv_coeff_coeff
Mathlib/Algebra/MvPolynomial/Equiv.lean
408
429
theorem eval_eq_eval_mv_eval' (s : Fin n → R) (y : R) (f : MvPolynomial (Fin (n + 1)) R) : eval (Fin.cons y s : Fin (n + 1) → R) f = Polynomial.eval y (Polynomial.map (eval s) (finSuccEquiv R n f)) := by
-- turn this into a def `Polynomial.mapAlgHom` let φ : (MvPolynomial (Fin n) R)[X] →ₐ[R] R[X] := { Polynomial.mapRingHom (eval s) with commutes' := fun r => by convert Polynomial.map_C (eval s) exact (eval_C _).symm } show aeval (Fin.cons y s : Fin (n + 1) → R) f = (Polynomial.aeval y).comp (φ.comp (finSuccEquiv R n).toAlgHom) f congr 2 apply MvPolynomial.algHom_ext rw [Fin.forall_fin_succ] simp only [φ, aeval_X, Fin.cons_zero, AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_comp, Polynomial.coe_aeval_eq_eval, Polynomial.map_C, AlgHom.coe_mk, RingHom.toFun_eq_coe, Polynomial.coe_mapRingHom, comp_apply, finSuccEquiv_apply, eval₂Hom_X', Fin.cases_zero, Polynomial.map_X, Polynomial.eval_X, Fin.cons_succ, Fin.cases_succ, eval_X, Polynomial.eval_C, RingHom.coe_mk, MonoidHom.coe_coe, AlgHom.coe_coe, implies_true, and_self, RingHom.toMonoidHom_eq_coe]
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Anne Baanen, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Hom import Mathlib.Algebra.Module.LinearMap.End #align_import algebra.module.equiv from "leanprover-community/mathlib"@"ea94d7cd54ad9ca6b7710032868abb7c6a104c9c" /-! # (Semi)linear equivalences In this file we define * `LinearEquiv σ M M₂`, `M ≃ₛₗ[σ] M₂`: an invertible semilinear map. Here, `σ` is a `RingHom` from `R` to `R₂` and an `e : M ≃ₛₗ[σ] M₂` satisfies `e (c • x) = (σ c) • (e x)`. The plain linear version, with `σ` being `RingHom.id R`, is denoted by `M ≃ₗ[R] M₂`, and the star-linear version (with `σ` being `starRingEnd`) is denoted by `M ≃ₗ⋆[R] M₂`. ## Implementation notes To ensure that composition works smoothly for semilinear equivalences, we use the typeclasses `RingHomCompTriple`, `RingHomInvPair` and `RingHomSurjective` from `Algebra/Ring/CompTypeclasses`. The group structure on automorphisms, `LinearEquiv.automorphismGroup`, is provided elsewhere. ## TODO * Parts of this file have not yet been generalized to semilinear maps ## Tags linear equiv, linear equivalences, linear isomorphism, linear isomorphic -/ open Function universe u u' v w x y z variable {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} variable {k : Type*} {K : Type*} {S : Type*} {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*} variable {N₁ : Type*} {N₂ : Type*} {N₃ : Type*} {N₄ : Type*} {ι : Type*} section /-- A linear equivalence is an invertible linear map. -/ -- Porting note (#11215): TODO @[nolint has_nonempty_instance] structure LinearEquiv {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) (M₂ : Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] extends LinearMap σ M M₂, M ≃+ M₂ #align linear_equiv LinearEquiv attribute [coe] LinearEquiv.toLinearMap /-- The linear map underlying a linear equivalence. -/ add_decl_doc LinearEquiv.toLinearMap #align linear_equiv.to_linear_map LinearEquiv.toLinearMap /-- The additive equivalence of types underlying a linear equivalence. -/ add_decl_doc LinearEquiv.toAddEquiv #align linear_equiv.to_add_equiv LinearEquiv.toAddEquiv /-- The backwards directed function underlying a linear equivalence. -/ add_decl_doc LinearEquiv.invFun /-- `LinearEquiv.invFun` is a right inverse to the linear equivalence's underlying function. -/ add_decl_doc LinearEquiv.right_inv /-- `LinearEquiv.invFun` is a left inverse to the linear equivalence's underlying function. -/ add_decl_doc LinearEquiv.left_inv /-- The notation `M ≃ₛₗ[σ] M₂` denotes the type of linear equivalences between `M` and `M₂` over a ring homomorphism `σ`. -/ notation:50 M " ≃ₛₗ[" σ "] " M₂ => LinearEquiv σ M M₂ /-- The notation `M ≃ₗ [R] M₂` denotes the type of linear equivalences between `M` and `M₂` over a plain linear map `M →ₗ M₂`. -/ notation:50 M " ≃ₗ[" R "] " M₂ => LinearEquiv (RingHom.id R) M M₂ /-- The notation `M ≃ₗ⋆[R] M₂` denotes the type of star-linear equivalences between `M` and `M₂` over the `⋆` endomorphism of the underlying starred ring `R`. -/ notation:50 M " ≃ₗ⋆[" R "] " M₂ => LinearEquiv (starRingEnd R) M M₂ /-- `SemilinearEquivClass F σ M M₂` asserts `F` is a type of bundled `σ`-semilinear equivs `M → M₂`. See also `LinearEquivClass F R M M₂` for the case where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. -/ class SemilinearEquivClass (F : Type*) {R S : outParam Type*} [Semiring R] [Semiring S] (σ : outParam <| R →+* S) {σ' : outParam <| S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M M₂ : outParam Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] [EquivLike F M M₂] extends AddEquivClass F M M₂ : Prop where /-- Applying a semilinear equivalence `f` over `σ` to `r • x` equals `σ r • f x`. -/ map_smulₛₗ : ∀ (f : F) (r : R) (x : M), f (r • x) = σ r • f x #align semilinear_equiv_class SemilinearEquivClass -- `R, S, σ, σ'` become metavars, but it's OK since they are outparams. /-- `LinearEquivClass F R M M₂` asserts `F` is a type of bundled `R`-linear equivs `M → M₂`. This is an abbreviation for `SemilinearEquivClass F (RingHom.id R) M M₂`. -/ abbrev LinearEquivClass (F : Type*) (R M M₂ : outParam Type*) [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] [EquivLike F M M₂] := SemilinearEquivClass F (RingHom.id R) M M₂ #align linear_equiv_class LinearEquivClass end namespace SemilinearEquivClass variable (F : Type*) [Semiring R] [Semiring S] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] variable [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} instance (priority := 100) [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] [EquivLike F M M₂] [s : SemilinearEquivClass F σ M M₂] : SemilinearMapClass F σ M M₂ := { s with } variable {F} /-- Reinterpret an element of a type of semilinear equivalences as a semilinear equivalence. -/ @[coe] def semilinearEquiv [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] [EquivLike F M M₂] [SemilinearEquivClass F σ M M₂] (f : F) : M ≃ₛₗ[σ] M₂ := { (f : M ≃+ M₂), (f : M →ₛₗ[σ] M₂) with } /-- Reinterpret an element of a type of semilinear equivalences as a semilinear equivalence. -/ instance instCoeToSemilinearEquiv [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] [EquivLike F M M₂] [SemilinearEquivClass F σ M M₂] : CoeHead F (M ≃ₛₗ[σ] M₂) where coe f := semilinearEquiv f end SemilinearEquivClass namespace LinearEquiv section AddCommMonoid variable {M₄ : Type*} variable [Semiring R] [Semiring S] section variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] variable [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} variable [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] instance : Coe (M ≃ₛₗ[σ] M₂) (M →ₛₗ[σ] M₂) := ⟨toLinearMap⟩ -- This exists for compatibility, previously `≃ₗ[R]` extended `≃` instead of `≃+`. /-- The equivalence of types underlying a linear equivalence. -/ def toEquiv : (M ≃ₛₗ[σ] M₂) → M ≃ M₂ := fun f => f.toAddEquiv.toEquiv #align linear_equiv.to_equiv LinearEquiv.toEquiv theorem toEquiv_injective : Function.Injective (toEquiv : (M ≃ₛₗ[σ] M₂) → M ≃ M₂) := fun ⟨⟨⟨_, _⟩, _⟩, _, _, _⟩ ⟨⟨⟨_, _⟩, _⟩, _, _, _⟩ h => (LinearEquiv.mk.injEq _ _ _ _ _ _ _ _).mpr ⟨LinearMap.ext (congr_fun (Equiv.mk.inj h).1), (Equiv.mk.inj h).2⟩ #align linear_equiv.to_equiv_injective LinearEquiv.toEquiv_injective @[simp] theorem toEquiv_inj {e₁ e₂ : M ≃ₛₗ[σ] M₂} : e₁.toEquiv = e₂.toEquiv ↔ e₁ = e₂ := toEquiv_injective.eq_iff #align linear_equiv.to_equiv_inj LinearEquiv.toEquiv_inj theorem toLinearMap_injective : Injective (toLinearMap : (M ≃ₛₗ[σ] M₂) → M →ₛₗ[σ] M₂) := fun _ _ H => toEquiv_injective <| Equiv.ext <| LinearMap.congr_fun H #align linear_equiv.to_linear_map_injective LinearEquiv.toLinearMap_injective @[simp, norm_cast] theorem toLinearMap_inj {e₁ e₂ : M ≃ₛₗ[σ] M₂} : (↑e₁ : M →ₛₗ[σ] M₂) = e₂ ↔ e₁ = e₂ := toLinearMap_injective.eq_iff #align linear_equiv.to_linear_map_inj LinearEquiv.toLinearMap_inj instance : EquivLike (M ≃ₛₗ[σ] M₂) M M₂ where inv := LinearEquiv.invFun coe_injective' _ _ h _ := toLinearMap_injective (DFunLike.coe_injective h) left_inv := LinearEquiv.left_inv right_inv := LinearEquiv.right_inv /-- Helper instance for when inference gets stuck on following the normal chain `EquivLike → FunLike`. TODO: this instance doesn't appear to be necessary: remove it (after benchmarking?) -/ instance : FunLike (M ≃ₛₗ[σ] M₂) M M₂ where coe := DFunLike.coe coe_injective' := DFunLike.coe_injective instance : SemilinearEquivClass (M ≃ₛₗ[σ] M₂) σ M M₂ where map_add := (·.map_add') --map_add' Porting note (#11215): TODO why did I need to change this? map_smulₛₗ := (·.map_smul') --map_smul' Porting note (#11215): TODO why did I need to change this? -- Porting note: moved to a lower line since there is no shortcut `CoeFun` instance any more @[simp] theorem coe_mk {to_fun inv_fun map_add map_smul left_inv right_inv} : (⟨⟨⟨to_fun, map_add⟩, map_smul⟩, inv_fun, left_inv, right_inv⟩ : M ≃ₛₗ[σ] M₂) = to_fun := rfl #align linear_equiv.coe_mk LinearEquiv.coe_mk theorem coe_injective : @Injective (M ≃ₛₗ[σ] M₂) (M → M₂) CoeFun.coe := DFunLike.coe_injective #align linear_equiv.coe_injective LinearEquiv.coe_injective end section variable [Semiring R₁] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] variable [AddCommMonoid M₃] [AddCommMonoid M₄] variable [AddCommMonoid N₁] [AddCommMonoid N₂] variable {module_M : Module R M} {module_S_M₂ : Module S M₂} {σ : R →+* S} {σ' : S →+* R} variable {re₁ : RingHomInvPair σ σ'} {re₂ : RingHomInvPair σ' σ} variable (e e' : M ≃ₛₗ[σ] M₂) @[simp, norm_cast] theorem coe_coe : ⇑(e : M →ₛₗ[σ] M₂) = e := rfl #align linear_equiv.coe_coe LinearEquiv.coe_coe @[simp] theorem coe_toEquiv : ⇑(e.toEquiv) = e := rfl #align linear_equiv.coe_to_equiv LinearEquiv.coe_toEquiv @[simp] theorem coe_toLinearMap : ⇑e.toLinearMap = e := rfl #align linear_equiv.coe_to_linear_map LinearEquiv.coe_toLinearMap -- Porting note: no longer a `simp` theorem toFun_eq_coe : e.toFun = e := rfl #align linear_equiv.to_fun_eq_coe LinearEquiv.toFun_eq_coe section variable {e e'} @[ext] theorem ext (h : ∀ x, e x = e' x) : e = e' := DFunLike.ext _ _ h #align linear_equiv.ext LinearEquiv.ext theorem ext_iff : e = e' ↔ ∀ x, e x = e' x := DFunLike.ext_iff #align linear_equiv.ext_iff LinearEquiv.ext_iff protected theorem congr_arg {x x'} : x = x' → e x = e x' := DFunLike.congr_arg e #align linear_equiv.congr_arg LinearEquiv.congr_arg protected theorem congr_fun (h : e = e') (x : M) : e x = e' x := DFunLike.congr_fun h x #align linear_equiv.congr_fun LinearEquiv.congr_fun end section variable (M R) /-- The identity map is a linear equivalence. -/ @[refl] def refl [Module R M] : M ≃ₗ[R] M := { LinearMap.id, Equiv.refl M with } #align linear_equiv.refl LinearEquiv.refl end @[simp] theorem refl_apply [Module R M] (x : M) : refl R M x = x := rfl #align linear_equiv.refl_apply LinearEquiv.refl_apply /-- Linear equivalences are symmetric. -/ @[symm] def symm (e : M ≃ₛₗ[σ] M₂) : M₂ ≃ₛₗ[σ'] M := { e.toLinearMap.inverse e.invFun e.left_inv e.right_inv, e.toEquiv.symm with toFun := e.toLinearMap.inverse e.invFun e.left_inv e.right_inv invFun := e.toEquiv.symm.invFun map_smul' := fun r x => by dsimp only; rw [map_smulₛₗ] } #align linear_equiv.symm LinearEquiv.symm -- Porting note: this is new /-- See Note [custom simps projection] -/ def Simps.apply {R : Type*} {S : Type*} [Semiring R] [Semiring S] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] {M : Type*} {M₂ : Type*} [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] (e : M ≃ₛₗ[σ] M₂) : M → M₂ := e #align linear_equiv.simps.apply LinearEquiv.Simps.apply /-- See Note [custom simps projection] -/ def Simps.symm_apply {R : Type*} {S : Type*} [Semiring R] [Semiring S] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] {M : Type*} {M₂ : Type*} [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] (e : M ≃ₛₗ[σ] M₂) : M₂ → M := e.symm #align linear_equiv.simps.symm_apply LinearEquiv.Simps.symm_apply initialize_simps_projections LinearEquiv (toFun → apply, invFun → symm_apply) @[simp] theorem invFun_eq_symm : e.invFun = e.symm := rfl #align linear_equiv.inv_fun_eq_symm LinearEquiv.invFun_eq_symm @[simp] theorem coe_toEquiv_symm : e.toEquiv.symm = e.symm := rfl #align linear_equiv.coe_to_equiv_symm LinearEquiv.coe_toEquiv_symm variable {module_M₁ : Module R₁ M₁} {module_M₂ : Module R₂ M₂} {module_M₃ : Module R₃ M₃} variable {module_N₁ : Module R₁ N₁} {module_N₂ : Module R₁ N₂} variable {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} variable {σ₂₁ : R₂ →+* R₁} {σ₃₂ : R₃ →+* R₂} {σ₃₁ : R₃ →+* R₁} variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable [RingHomCompTriple σ₃₂ σ₂₁ σ₃₁] variable {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₃ : RingHomInvPair σ₂₃ σ₃₂} variable [RingHomInvPair σ₁₃ σ₃₁] {re₂₁ : RingHomInvPair σ₂₁ σ₁₂} variable {re₃₂ : RingHomInvPair σ₃₂ σ₂₃} [RingHomInvPair σ₃₁ σ₁₃] variable (e₁₂ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂₃ : M₂ ≃ₛₗ[σ₂₃] M₃) -- Porting note: Lean 4 aggressively removes unused variables declared using `variable`, so -- we have to list all the variables explicitly here in order to match the Lean 3 signature. set_option linter.unusedVariables false in /-- Linear equivalences are transitive. -/ -- Note: the `RingHomCompTriple σ₃₂ σ₂₁ σ₃₁` is unused, but is convenient to carry around -- implicitly for lemmas like `LinearEquiv.self_trans_symm`. @[trans, nolint unusedArguments] def trans [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₃₂ σ₂₁ σ₃₁] {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₃ : RingHomInvPair σ₂₃ σ₃₂} [RingHomInvPair σ₁₃ σ₃₁] {re₂₁ : RingHomInvPair σ₂₁ σ₁₂} {re₃₂ : RingHomInvPair σ₃₂ σ₂₃} [RingHomInvPair σ₃₁ σ₁₃] (e₁₂ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂₃ : M₂ ≃ₛₗ[σ₂₃] M₃) : M₁ ≃ₛₗ[σ₁₃] M₃ := { e₂₃.toLinearMap.comp e₁₂.toLinearMap, e₁₂.toEquiv.trans e₂₃.toEquiv with } #align linear_equiv.trans LinearEquiv.trans /-- The notation `e₁ ≪≫ₗ e₂` denotes the composition of the linear equivalences `e₁` and `e₂`. -/ notation3:80 (name := transNotation) e₁:80 " ≪≫ₗ " e₂:81 => @LinearEquiv.trans _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (RingHom.id _) (RingHom.id _) (RingHom.id _) (RingHom.id _) (RingHom.id _) (RingHom.id _) RingHomCompTriple.ids RingHomCompTriple.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids e₁ e₂ variable {e₁₂} {e₂₃} @[simp] theorem coe_toAddEquiv : e.toAddEquiv = e := rfl #align linear_equiv.coe_to_add_equiv LinearEquiv.coe_toAddEquiv /-- The two paths coercion can take to an `AddMonoidHom` are equivalent -/ theorem toAddMonoidHom_commutes : e.toLinearMap.toAddMonoidHom = e.toAddEquiv.toAddMonoidHom := rfl #align linear_equiv.to_add_monoid_hom_commutes LinearEquiv.toAddMonoidHom_commutes @[simp] theorem trans_apply (c : M₁) : (e₁₂.trans e₂₃ : M₁ ≃ₛₗ[σ₁₃] M₃) c = e₂₃ (e₁₂ c) := rfl #align linear_equiv.trans_apply LinearEquiv.trans_apply theorem coe_trans : (e₁₂.trans e₂₃ : M₁ →ₛₗ[σ₁₃] M₃) = (e₂₃ : M₂ →ₛₗ[σ₂₃] M₃).comp (e₁₂ : M₁ →ₛₗ[σ₁₂] M₂) := rfl #align linear_equiv.coe_trans LinearEquiv.coe_trans @[simp] theorem apply_symm_apply (c : M₂) : e (e.symm c) = c := e.right_inv c #align linear_equiv.apply_symm_apply LinearEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (b : M) : e.symm (e b) = b := e.left_inv b #align linear_equiv.symm_apply_apply LinearEquiv.symm_apply_apply @[simp] theorem trans_symm : (e₁₂.trans e₂₃ : M₁ ≃ₛₗ[σ₁₃] M₃).symm = e₂₃.symm.trans e₁₂.symm := rfl #align linear_equiv.trans_symm LinearEquiv.trans_symm theorem symm_trans_apply (c : M₃) : (e₁₂.trans e₂₃ : M₁ ≃ₛₗ[σ₁₃] M₃).symm c = e₁₂.symm (e₂₃.symm c) := rfl #align linear_equiv.symm_trans_apply LinearEquiv.symm_trans_apply @[simp] theorem trans_refl : e.trans (refl S M₂) = e := toEquiv_injective e.toEquiv.trans_refl #align linear_equiv.trans_refl LinearEquiv.trans_refl @[simp] theorem refl_trans : (refl R M).trans e = e := toEquiv_injective e.toEquiv.refl_trans #align linear_equiv.refl_trans LinearEquiv.refl_trans theorem symm_apply_eq {x y} : e.symm x = y ↔ x = e y := e.toEquiv.symm_apply_eq #align linear_equiv.symm_apply_eq LinearEquiv.symm_apply_eq theorem eq_symm_apply {x y} : y = e.symm x ↔ e y = x := e.toEquiv.eq_symm_apply #align linear_equiv.eq_symm_apply LinearEquiv.eq_symm_apply theorem eq_comp_symm {α : Type*} (f : M₂ → α) (g : M₁ → α) : f = g ∘ e₁₂.symm ↔ f ∘ e₁₂ = g := e₁₂.toEquiv.eq_comp_symm f g #align linear_equiv.eq_comp_symm LinearEquiv.eq_comp_symm theorem comp_symm_eq {α : Type*} (f : M₂ → α) (g : M₁ → α) : g ∘ e₁₂.symm = f ↔ g = f ∘ e₁₂ := e₁₂.toEquiv.comp_symm_eq f g #align linear_equiv.comp_symm_eq LinearEquiv.comp_symm_eq theorem eq_symm_comp {α : Type*} (f : α → M₁) (g : α → M₂) : f = e₁₂.symm ∘ g ↔ e₁₂ ∘ f = g := e₁₂.toEquiv.eq_symm_comp f g #align linear_equiv.eq_symm_comp LinearEquiv.eq_symm_comp theorem symm_comp_eq {α : Type*} (f : α → M₁) (g : α → M₂) : e₁₂.symm ∘ g = f ↔ g = e₁₂ ∘ f := e₁₂.toEquiv.symm_comp_eq f g #align linear_equiv.symm_comp_eq LinearEquiv.symm_comp_eq variable [RingHomCompTriple σ₂₁ σ₁₃ σ₂₃] [RingHomCompTriple σ₃₁ σ₁₂ σ₃₂] theorem eq_comp_toLinearMap_symm (f : M₂ →ₛₗ[σ₂₃] M₃) (g : M₁ →ₛₗ[σ₁₃] M₃) : f = g.comp e₁₂.symm.toLinearMap ↔ f.comp e₁₂.toLinearMap = g := by constructor <;> intro H <;> ext · simp [H, e₁₂.toEquiv.eq_comp_symm f g] · simp [← H, ← e₁₂.toEquiv.eq_comp_symm f g] #align linear_equiv.eq_comp_to_linear_map_symm LinearEquiv.eq_comp_toLinearMap_symm theorem comp_toLinearMap_symm_eq (f : M₂ →ₛₗ[σ₂₃] M₃) (g : M₁ →ₛₗ[σ₁₃] M₃) : g.comp e₁₂.symm.toLinearMap = f ↔ g = f.comp e₁₂.toLinearMap := by constructor <;> intro H <;> ext · simp [← H, ← e₁₂.toEquiv.comp_symm_eq f g] · simp [H, e₁₂.toEquiv.comp_symm_eq f g] #align linear_equiv.comp_to_linear_map_symm_eq LinearEquiv.comp_toLinearMap_symm_eq theorem eq_toLinearMap_symm_comp (f : M₃ →ₛₗ[σ₃₁] M₁) (g : M₃ →ₛₗ[σ₃₂] M₂) : f = e₁₂.symm.toLinearMap.comp g ↔ e₁₂.toLinearMap.comp f = g := by constructor <;> intro H <;> ext · simp [H, e₁₂.toEquiv.eq_symm_comp f g] · simp [← H, ← e₁₂.toEquiv.eq_symm_comp f g] #align linear_equiv.eq_to_linear_map_symm_comp LinearEquiv.eq_toLinearMap_symm_comp theorem toLinearMap_symm_comp_eq (f : M₃ →ₛₗ[σ₃₁] M₁) (g : M₃ →ₛₗ[σ₃₂] M₂) : e₁₂.symm.toLinearMap.comp g = f ↔ g = e₁₂.toLinearMap.comp f := by constructor <;> intro H <;> ext · simp [← H, ← e₁₂.toEquiv.symm_comp_eq f g] · simp [H, e₁₂.toEquiv.symm_comp_eq f g] #align linear_equiv.to_linear_map_symm_comp_eq LinearEquiv.toLinearMap_symm_comp_eq @[simp] theorem refl_symm [Module R M] : (refl R M).symm = LinearEquiv.refl R M := rfl #align linear_equiv.refl_symm LinearEquiv.refl_symm @[simp] theorem self_trans_symm (f : M₁ ≃ₛₗ[σ₁₂] M₂) : f.trans f.symm = LinearEquiv.refl R₁ M₁ := by ext x simp #align linear_equiv.self_trans_symm LinearEquiv.self_trans_symm @[simp] theorem symm_trans_self (f : M₁ ≃ₛₗ[σ₁₂] M₂) : f.symm.trans f = LinearEquiv.refl R₂ M₂ := by ext x simp #align linear_equiv.symm_trans_self LinearEquiv.symm_trans_self @[simp] -- Porting note: norm_cast theorem refl_toLinearMap [Module R M] : (LinearEquiv.refl R M : M →ₗ[R] M) = LinearMap.id := rfl #align linear_equiv.refl_to_linear_map LinearEquiv.refl_toLinearMap @[simp] -- Porting note: norm_cast theorem comp_coe [Module R M] [Module R M₂] [Module R M₃] (f : M ≃ₗ[R] M₂) (f' : M₂ ≃ₗ[R] M₃) : (f' : M₂ →ₗ[R] M₃).comp (f : M →ₗ[R] M₂) = (f.trans f' : M ≃ₗ[R] M₃) := rfl #align linear_equiv.comp_coe LinearEquiv.comp_coe @[simp] theorem mk_coe (f h₁ h₂) : (LinearEquiv.mk e f h₁ h₂ : M ≃ₛₗ[σ] M₂) = e := ext fun _ => rfl #align linear_equiv.mk_coe LinearEquiv.mk_coe protected theorem map_add (a b : M) : e (a + b) = e a + e b := map_add e a b #align linear_equiv.map_add LinearEquiv.map_add protected theorem map_zero : e 0 = 0 := map_zero e #align linear_equiv.map_zero LinearEquiv.map_zero protected theorem map_smulₛₗ (c : R) (x : M) : e (c • x) = (σ : R → S) c • e x := e.map_smul' c x #align linear_equiv.map_smulₛₗ LinearEquiv.map_smulₛₗ theorem map_smul (e : N₁ ≃ₗ[R₁] N₂) (c : R₁) (x : N₁) : e (c • x) = c • e x := map_smulₛₗ e c x #align linear_equiv.map_smul LinearEquiv.map_smul theorem map_eq_zero_iff {x : M} : e x = 0 ↔ x = 0 := e.toAddEquiv.map_eq_zero_iff #align linear_equiv.map_eq_zero_iff LinearEquiv.map_eq_zero_iff theorem map_ne_zero_iff {x : M} : e x ≠ 0 ↔ x ≠ 0 := e.toAddEquiv.map_ne_zero_iff #align linear_equiv.map_ne_zero_iff LinearEquiv.map_ne_zero_iff @[simp] theorem symm_symm (e : M ≃ₛₗ[σ] M₂) : e.symm.symm = e := by cases e rfl #align linear_equiv.symm_symm LinearEquiv.symm_symm theorem symm_bijective [Module R M] [Module S M₂] [RingHomInvPair σ' σ] [RingHomInvPair σ σ'] : Function.Bijective (symm : (M ≃ₛₗ[σ] M₂) → M₂ ≃ₛₗ[σ'] M) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ #align linear_equiv.symm_bijective LinearEquiv.symm_bijective @[simp] theorem mk_coe' (f h₁ h₂ h₃ h₄) : (LinearEquiv.mk ⟨⟨f, h₁⟩, h₂⟩ (⇑e) h₃ h₄ : M₂ ≃ₛₗ[σ'] M) = e.symm := symm_bijective.injective <| ext fun _ => rfl #align linear_equiv.mk_coe' LinearEquiv.mk_coe' @[simp] theorem symm_mk (f h₁ h₂ h₃ h₄) : (⟨⟨⟨e, h₁⟩, h₂⟩, f, h₃, h₄⟩ : M ≃ₛₗ[σ] M₂).symm = { (⟨⟨⟨e, h₁⟩, h₂⟩, f, h₃, h₄⟩ : M ≃ₛₗ[σ] M₂).symm with toFun := f invFun := e } := rfl #align linear_equiv.symm_mk LinearEquiv.symm_mk @[simp] theorem coe_symm_mk [Module R M] [Module R M₂] {to_fun inv_fun map_add map_smul left_inv right_inv} : ⇑(⟨⟨⟨to_fun, map_add⟩, map_smul⟩, inv_fun, left_inv, right_inv⟩ : M ≃ₗ[R] M₂).symm = inv_fun := rfl #align linear_equiv.coe_symm_mk LinearEquiv.coe_symm_mk protected theorem bijective : Function.Bijective e := e.toEquiv.bijective #align linear_equiv.bijective LinearEquiv.bijective protected theorem injective : Function.Injective e := e.toEquiv.injective #align linear_equiv.injective LinearEquiv.injective protected theorem surjective : Function.Surjective e := e.toEquiv.surjective #align linear_equiv.surjective LinearEquiv.surjective protected theorem image_eq_preimage (s : Set M) : e '' s = e.symm ⁻¹' s := e.toEquiv.image_eq_preimage s #align linear_equiv.image_eq_preimage LinearEquiv.image_eq_preimage protected theorem image_symm_eq_preimage (s : Set M₂) : e.symm '' s = e ⁻¹' s := e.toEquiv.symm.image_eq_preimage s #align linear_equiv.image_symm_eq_preimage LinearEquiv.image_symm_eq_preimage end /-- Interpret a `RingEquiv` `f` as an `f`-semilinear equiv. -/ @[simps] def _root_.RingEquiv.toSemilinearEquiv (f : R ≃+* S) : haveI := RingHomInvPair.of_ringEquiv f haveI := RingHomInvPair.symm (↑f : R →+* S) (f.symm : S →+* R) R ≃ₛₗ[(↑f : R →+* S)] S := haveI := RingHomInvPair.of_ringEquiv f haveI := RingHomInvPair.symm (↑f : R →+* S) (f.symm : S →+* R) { f with toFun := f map_smul' := f.map_mul } #align ring_equiv.to_semilinear_equiv RingEquiv.toSemilinearEquiv #align ring_equiv.to_semilinear_equiv_symm_apply RingEquiv.toSemilinearEquiv_symm_apply variable [Semiring R₁] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] /-- An involutive linear map is a linear equivalence. -/ def ofInvolutive {σ σ' : R →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] {_ : Module R M} (f : M →ₛₗ[σ] M) (hf : Involutive f) : M ≃ₛₗ[σ] M := { f, hf.toPerm f with } #align linear_equiv.of_involutive LinearEquiv.ofInvolutive @[simp] theorem coe_ofInvolutive {σ σ' : R →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] {_ : Module R M} (f : M →ₛₗ[σ] M) (hf : Involutive f) : ⇑(ofInvolutive f hf) = f := rfl #align linear_equiv.coe_of_involutive LinearEquiv.coe_ofInvolutive section RestrictScalars variable (R) variable [Module R M] [Module R M₂] [Module S M] [Module S M₂] [LinearMap.CompatibleSMul M M₂ R S] /-- If `M` and `M₂` are both `R`-semimodules and `S`-semimodules and `R`-semimodule structures are defined by an action of `R` on `S` (formally, we have two scalar towers), then any `S`-linear equivalence from `M` to `M₂` is also an `R`-linear equivalence. See also `LinearMap.restrictScalars`. -/ @[simps] def restrictScalars (f : M ≃ₗ[S] M₂) : M ≃ₗ[R] M₂ := { f.toLinearMap.restrictScalars R with toFun := f invFun := f.symm left_inv := f.left_inv right_inv := f.right_inv } #align linear_equiv.restrict_scalars LinearEquiv.restrictScalars #align linear_equiv.restrict_scalars_apply LinearEquiv.restrictScalars_apply #align linear_equiv.restrict_scalars_symm_apply LinearEquiv.restrictScalars_symm_apply theorem restrictScalars_injective : Function.Injective (restrictScalars R : (M ≃ₗ[S] M₂) → M ≃ₗ[R] M₂) := fun _ _ h => ext (LinearEquiv.congr_fun h : _) #align linear_equiv.restrict_scalars_injective LinearEquiv.restrictScalars_injective @[simp] theorem restrictScalars_inj (f g : M ≃ₗ[S] M₂) : f.restrictScalars R = g.restrictScalars R ↔ f = g := (restrictScalars_injective R).eq_iff #align linear_equiv.restrict_scalars_inj LinearEquiv.restrictScalars_inj end RestrictScalars theorem _root_.Module.End_isUnit_iff [Module R M] (f : Module.End R M) : IsUnit f ↔ Function.Bijective f := ⟨fun h => Function.bijective_iff_has_inverse.mpr <| ⟨h.unit.inv, ⟨Module.End_isUnit_inv_apply_apply_of_isUnit h, Module.End_isUnit_apply_inv_apply_of_isUnit h⟩⟩, fun H => let e : M ≃ₗ[R] M := { f, Equiv.ofBijective f H with } ⟨⟨_, e.symm, LinearMap.ext e.right_inv, LinearMap.ext e.left_inv⟩, rfl⟩⟩ #align module.End_is_unit_iff Module.End_isUnit_iff section Automorphisms variable [Module R M] instance automorphismGroup : Group (M ≃ₗ[R] M) where mul f g := g.trans f one := LinearEquiv.refl R M inv f := f.symm mul_assoc f g h := rfl mul_one f := ext fun x => rfl one_mul f := ext fun x => rfl mul_left_inv f := ext <| f.left_inv #align linear_equiv.automorphism_group LinearEquiv.automorphismGroup @[simp] lemma coe_one : ↑(1 : M ≃ₗ[R] M) = id := rfl @[simp] lemma coe_toLinearMap_one : (↑(1 : M ≃ₗ[R] M) : M →ₗ[R] M) = LinearMap.id := rfl @[simp] lemma coe_toLinearMap_mul {e₁ e₂ : M ≃ₗ[R] M} : (↑(e₁ * e₂) : M →ₗ[R] M) = (e₁ : M →ₗ[R] M) * (e₂ : M →ₗ[R] M) := by rfl theorem coe_pow (e : M ≃ₗ[R] M) (n : ℕ) : ⇑(e ^ n) = e^[n] := hom_coe_pow _ rfl (fun _ _ ↦ rfl) _ _ theorem pow_apply (e : M ≃ₗ[R] M) (n : ℕ) (m : M) : (e ^ n) m = e^[n] m := congr_fun (coe_pow e n) m /-- Restriction from `R`-linear automorphisms of `M` to `R`-linear endomorphisms of `M`, promoted to a monoid hom. -/ @[simps] def automorphismGroup.toLinearMapMonoidHom : (M ≃ₗ[R] M) →* M →ₗ[R] M where toFun e := e.toLinearMap map_one' := rfl map_mul' _ _ := rfl #align linear_equiv.automorphism_group.to_linear_map_monoid_hom LinearEquiv.automorphismGroup.toLinearMapMonoidHom #align linear_equiv.automorphism_group.to_linear_map_monoid_hom_apply LinearEquiv.automorphismGroup.toLinearMapMonoidHom_apply /-- The tautological action by `M ≃ₗ[R] M` on `M`. This generalizes `Function.End.applyMulAction`. -/ instance applyDistribMulAction : DistribMulAction (M ≃ₗ[R] M) M where smul := (· <| ·) smul_zero := LinearEquiv.map_zero smul_add := LinearEquiv.map_add one_smul _ := rfl mul_smul _ _ _ := rfl #align linear_equiv.apply_distrib_mul_action LinearEquiv.applyDistribMulAction @[simp] protected theorem smul_def (f : M ≃ₗ[R] M) (a : M) : f • a = f a := rfl #align linear_equiv.smul_def LinearEquiv.smul_def /-- `LinearEquiv.applyDistribMulAction` is faithful. -/ instance apply_faithfulSMul : FaithfulSMul (M ≃ₗ[R] M) M := ⟨@fun _ _ => LinearEquiv.ext⟩ #align linear_equiv.apply_has_faithful_smul LinearEquiv.apply_faithfulSMul instance apply_smulCommClass : SMulCommClass R (M ≃ₗ[R] M) M where smul_comm r e m := (e.map_smul r m).symm #align linear_equiv.apply_smul_comm_class LinearEquiv.apply_smulCommClass instance apply_smulCommClass' : SMulCommClass (M ≃ₗ[R] M) R M where smul_comm := LinearEquiv.map_smul #align linear_equiv.apply_smul_comm_class' LinearEquiv.apply_smulCommClass' end Automorphisms section OfSubsingleton variable (M M₂) variable [Module R M] [Module R M₂] [Subsingleton M] [Subsingleton M₂] /-- Any two modules that are subsingletons are isomorphic. -/ @[simps] def ofSubsingleton : M ≃ₗ[R] M₂ := { (0 : M →ₗ[R] M₂) with toFun := fun _ => 0 invFun := fun _ => 0 left_inv := fun _ => Subsingleton.elim _ _ right_inv := fun _ => Subsingleton.elim _ _ } #align linear_equiv.of_subsingleton LinearEquiv.ofSubsingleton #align linear_equiv.of_subsingleton_symm_apply LinearEquiv.ofSubsingleton_symm_apply @[simp] theorem ofSubsingleton_self : ofSubsingleton M M = refl R M := by ext simp [eq_iff_true_of_subsingleton] #align linear_equiv.of_subsingleton_self LinearEquiv.ofSubsingleton_self end OfSubsingleton end AddCommMonoid end LinearEquiv namespace Module /-- `g : R ≃+* S` is `R`-linear when the module structure on `S` is `Module.compHom S g` . -/ @[simps] def compHom.toLinearEquiv {R S : Type*} [Semiring R] [Semiring S] (g : R ≃+* S) : haveI := compHom S (↑g : R →+* S) R ≃ₗ[R] S := letI := compHom S (↑g : R →+* S) { g with toFun := (g : R → S) invFun := (g.symm : S → R) map_smul' := g.map_mul } #align module.comp_hom.to_linear_equiv Module.compHom.toLinearEquiv #align module.comp_hom.to_linear_equiv_symm_apply Module.compHom.toLinearEquiv_symm_apply end Module namespace DistribMulAction variable (R M) [Semiring R] [AddCommMonoid M] [Module R M] variable [Group S] [DistribMulAction S M] [SMulCommClass S R M] /-- Each element of the group defines a linear equivalence. This is a stronger version of `DistribMulAction.toAddEquiv`. -/ @[simps!] def toLinearEquiv (s : S) : M ≃ₗ[R] M := { toAddEquiv M s, toLinearMap R M s with } #align distrib_mul_action.to_linear_equiv DistribMulAction.toLinearEquiv #align distrib_mul_action.to_linear_equiv_apply DistribMulAction.toLinearEquiv_apply #align distrib_mul_action.to_linear_equiv_symm_apply DistribMulAction.toLinearEquiv_symm_apply /-- Each element of the group defines a module automorphism. This is a stronger version of `DistribMulAction.toAddAut`. -/ @[simps] def toModuleAut : S →* M ≃ₗ[R] M where toFun := toLinearEquiv R M map_one' := LinearEquiv.ext <| one_smul _ map_mul' _ _ := LinearEquiv.ext <| mul_smul _ _ #align distrib_mul_action.to_module_aut DistribMulAction.toModuleAut #align distrib_mul_action.to_module_aut_apply DistribMulAction.toModuleAut_apply end DistribMulAction namespace AddEquiv section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] variable (e : M ≃+ M₂) /-- An additive equivalence whose underlying function preserves `smul` is a linear equivalence. -/ def toLinearEquiv (h : ∀ (c : R) (x), e (c • x) = c • e x) : M ≃ₗ[R] M₂ := { e with map_smul' := h } #align add_equiv.to_linear_equiv AddEquiv.toLinearEquiv @[simp] theorem coe_toLinearEquiv (h : ∀ (c : R) (x), e (c • x) = c • e x) : ⇑(e.toLinearEquiv h) = e := rfl #align add_equiv.coe_to_linear_equiv AddEquiv.coe_toLinearEquiv @[simp] theorem coe_toLinearEquiv_symm (h : ∀ (c : R) (x), e (c • x) = c • e x) : ⇑(e.toLinearEquiv h).symm = e.symm := rfl #align add_equiv.coe_to_linear_equiv_symm AddEquiv.coe_toLinearEquiv_symm /-- An additive equivalence between commutative additive monoids is a linear equivalence between ℕ-modules -/ def toNatLinearEquiv : M ≃ₗ[ℕ] M₂ := e.toLinearEquiv fun c a => by rw [map_nsmul] #align add_equiv.to_nat_linear_equiv AddEquiv.toNatLinearEquiv @[simp] theorem coe_toNatLinearEquiv : ⇑e.toNatLinearEquiv = e := rfl #align add_equiv.coe_to_nat_linear_equiv AddEquiv.coe_toNatLinearEquiv @[simp] theorem toNatLinearEquiv_toAddEquiv : ↑e.toNatLinearEquiv = e := by ext rfl #align add_equiv.to_nat_linear_equiv_to_add_equiv AddEquiv.toNatLinearEquiv_toAddEquiv @[simp] theorem _root_.LinearEquiv.toAddEquiv_toNatLinearEquiv (e : M ≃ₗ[ℕ] M₂) : AddEquiv.toNatLinearEquiv ↑e = e := DFunLike.coe_injective rfl #align linear_equiv.to_add_equiv_to_nat_linear_equiv LinearEquiv.toAddEquiv_toNatLinearEquiv @[simp] theorem toNatLinearEquiv_symm : e.toNatLinearEquiv.symm = e.symm.toNatLinearEquiv := rfl #align add_equiv.to_nat_linear_equiv_symm AddEquiv.toNatLinearEquiv_symm @[simp] theorem toNatLinearEquiv_refl : (AddEquiv.refl M).toNatLinearEquiv = LinearEquiv.refl ℕ M := rfl #align add_equiv.to_nat_linear_equiv_refl AddEquiv.toNatLinearEquiv_refl @[simp] theorem toNatLinearEquiv_trans (e₂ : M₂ ≃+ M₃) : e.toNatLinearEquiv.trans e₂.toNatLinearEquiv = (e.trans e₂).toNatLinearEquiv := rfl #align add_equiv.to_nat_linear_equiv_trans AddEquiv.toNatLinearEquiv_trans end AddCommMonoid section AddCommGroup variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] variable (e : M ≃+ M₂) /-- An additive equivalence between commutative additive groups is a linear equivalence between ℤ-modules -/ def toIntLinearEquiv : M ≃ₗ[ℤ] M₂ := e.toLinearEquiv fun c a => e.toAddMonoidHom.map_zsmul a c #align add_equiv.to_int_linear_equiv AddEquiv.toIntLinearEquiv @[simp] theorem coe_toIntLinearEquiv : ⇑e.toIntLinearEquiv = e := rfl #align add_equiv.coe_to_int_linear_equiv AddEquiv.coe_toIntLinearEquiv @[simp] theorem toIntLinearEquiv_toAddEquiv : ↑e.toIntLinearEquiv = e := by ext rfl #align add_equiv.to_int_linear_equiv_to_add_equiv AddEquiv.toIntLinearEquiv_toAddEquiv @[simp] theorem _root_.LinearEquiv.toAddEquiv_toIntLinearEquiv (e : M ≃ₗ[ℤ] M₂) : AddEquiv.toIntLinearEquiv (e : M ≃+ M₂) = e := DFunLike.coe_injective rfl #align linear_equiv.to_add_equiv_to_int_linear_equiv LinearEquiv.toAddEquiv_toIntLinearEquiv @[simp] theorem toIntLinearEquiv_symm : e.toIntLinearEquiv.symm = e.symm.toIntLinearEquiv := rfl #align add_equiv.to_int_linear_equiv_symm AddEquiv.toIntLinearEquiv_symm @[simp] theorem toIntLinearEquiv_refl : (AddEquiv.refl M).toIntLinearEquiv = LinearEquiv.refl ℤ M := rfl #align add_equiv.to_int_linear_equiv_refl AddEquiv.toIntLinearEquiv_refl @[simp] theorem toIntLinearEquiv_trans (e₂ : M₂ ≃+ M₃) : e.toIntLinearEquiv.trans e₂.toIntLinearEquiv = (e.trans e₂).toIntLinearEquiv := rfl #align add_equiv.to_int_linear_equiv_trans AddEquiv.toIntLinearEquiv_trans end AddCommGroup end AddEquiv namespace LinearMap variable (R S M) variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] /-- The equivalence between R-linear maps from `R` to `M`, and points of `M` itself. This says that the forgetful functor from `R`-modules to types is representable, by `R`. This is an `S`-linear equivalence, under the assumption that `S` acts on `M` commuting with `R`. When `R` is commutative, we can take this to be the usual action with `S = R`. Otherwise, `S = ℕ` shows that the equivalence is additive. See note [bundled maps over different rings]. -/ @[simps] def ringLmapEquivSelf [Module S M] [SMulCommClass R S M] : (R →ₗ[R] M) ≃ₗ[S] M := { applyₗ' S (1 : R) with toFun := fun f => f 1 invFun := smulRight (1 : R →ₗ[R] R) left_inv := fun f => by ext simp only [coe_smulRight, one_apply, smul_eq_mul, ← map_smul f, mul_one] right_inv := fun x => by simp } #align linear_map.ring_lmap_equiv_self LinearMap.ringLmapEquivSelf end LinearMap /-- The `R`-linear equivalence between additive morphisms `A →+ B` and `ℕ`-linear morphisms `A →ₗ[ℕ] B`. -/ @[simps] def addMonoidHomLequivNat {A B : Type*} (R : Type*) [Semiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R B] : (A →+ B) ≃ₗ[R] A →ₗ[ℕ] B where toFun := AddMonoidHom.toNatLinearMap invFun := LinearMap.toAddMonoidHom map_add' := by intros; ext; rfl map_smul' := by intros; ext; rfl left_inv := by intro f; ext; rfl right_inv := by intro f; ext; rfl #align add_monoid_hom_lequiv_nat addMonoidHomLequivNat /-- The `R`-linear equivalence between additive morphisms `A →+ B` and `ℤ`-linear morphisms `A →ₗ[ℤ] B`. -/ @[simps] def addMonoidHomLequivInt {A B : Type*} (R : Type*) [Semiring R] [AddCommGroup A] [AddCommGroup B] [Module R B] : (A →+ B) ≃ₗ[R] A →ₗ[ℤ] B where toFun := AddMonoidHom.toIntLinearMap invFun := LinearMap.toAddMonoidHom map_add' := by intros; ext; rfl map_smul' := by intros; ext; rfl left_inv := by intro f; ext; rfl right_inv := by intro f; ext; rfl #align add_monoid_hom_lequiv_int addMonoidHomLequivInt /-- Ring equivalence between additive group endomorphisms of an `AddCommGroup` `A` and `ℤ`-module endomorphisms of `A.` -/ @[simps] def addMonoidEndRingEquivInt (A : Type*) [AddCommGroup A] : AddMonoid.End A ≃+* Module.End ℤ A := { addMonoidHomLequivInt (B := A) ℤ with map_mul' := fun _ _ => rfl } namespace LinearEquiv section AddCommMonoid section Subsingleton variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} variable [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] section Module variable [Subsingleton M] [Subsingleton M₂] /-- Between two zero modules, the zero map is an equivalence. -/ instance : Zero (M ≃ₛₗ[σ₁₂] M₂) := ⟨{ (0 : M →ₛₗ[σ₁₂] M₂) with toFun := 0 invFun := 0 right_inv := Subsingleton.elim _ left_inv := Subsingleton.elim _ }⟩ -- Even though these are implied by `Subsingleton.elim` via the `Unique` instance below, they're -- nice to have as `rfl`-lemmas for `dsimp`. @[simp] theorem zero_symm : (0 : M ≃ₛₗ[σ₁₂] M₂).symm = 0 := rfl #align linear_equiv.zero_symm LinearEquiv.zero_symm @[simp] theorem coe_zero : ⇑(0 : M ≃ₛₗ[σ₁₂] M₂) = 0 := rfl #align linear_equiv.coe_zero LinearEquiv.coe_zero theorem zero_apply (x : M) : (0 : M ≃ₛₗ[σ₁₂] M₂) x = 0 := rfl #align linear_equiv.zero_apply LinearEquiv.zero_apply /-- Between two zero modules, the zero map is the only equivalence. -/ instance : Unique (M ≃ₛₗ[σ₁₂] M₂) where uniq _ := toLinearMap_injective (Subsingleton.elim _ _) default := 0 end Module instance uniqueOfSubsingleton [Subsingleton R] [Subsingleton R₂] : Unique (M ≃ₛₗ[σ₁₂] M₂) := by haveI := Module.subsingleton R M haveI := Module.subsingleton R₂ M₂ infer_instance #align linear_equiv.unique_of_subsingleton LinearEquiv.uniqueOfSubsingleton end Subsingleton section Uncurry variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable (V V₂ R) /-- Linear equivalence between a curried and uncurried function. Differs from `TensorProduct.curry`. -/ protected def curry : (V × V₂ → R) ≃ₗ[R] V → V₂ → R := { Equiv.curry _ _ _ with map_add' := fun _ _ => by ext rfl map_smul' := fun _ _ => by ext rfl } #align linear_equiv.curry LinearEquiv.curry @[simp] theorem coe_curry : ⇑(LinearEquiv.curry R V V₂) = curry := rfl #align linear_equiv.coe_curry LinearEquiv.coe_curry @[simp] theorem coe_curry_symm : ⇑(LinearEquiv.curry R V V₂).symm = uncurry := rfl #align linear_equiv.coe_curry_symm LinearEquiv.coe_curry_symm end Uncurry section variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable {module_M : Module R M} {module_M₂ : Module R₂ M₂} variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} variable {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₁ : RingHomInvPair σ₂₁ σ₁₂} variable (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₁] M) /-- If a linear map has an inverse, it is a linear equivalence. -/ def ofLinear (h₁ : f.comp g = LinearMap.id) (h₂ : g.comp f = LinearMap.id) : M ≃ₛₗ[σ₁₂] M₂ := { f with invFun := g left_inv := LinearMap.ext_iff.1 h₂ right_inv := LinearMap.ext_iff.1 h₁ } #align linear_equiv.of_linear LinearEquiv.ofLinear @[simp] theorem ofLinear_apply {h₁ h₂} (x : M) : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂) x = f x := rfl #align linear_equiv.of_linear_apply LinearEquiv.ofLinear_apply @[simp] theorem ofLinear_symm_apply {h₁ h₂} (x : M₂) : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂).symm x = g x := rfl #align linear_equiv.of_linear_symm_apply LinearEquiv.ofLinear_symm_apply @[simp] theorem ofLinear_toLinearMap {h₁ h₂} : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂) = f := rfl @[simp] theorem ofLinear_symm_toLinearMap {h₁ h₂} : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂).symm = g := rfl end end AddCommMonoid section Neg variable (R) [Semiring R] [AddCommGroup M] [Module R M] /-- `x ↦ -x` as a `LinearEquiv` -/ def neg : M ≃ₗ[R] M := { Equiv.neg M, (-LinearMap.id : M →ₗ[R] M) with } #align linear_equiv.neg LinearEquiv.neg variable {R} @[simp] theorem coe_neg : ⇑(neg R : M ≃ₗ[R] M) = -id := rfl #align linear_equiv.coe_neg LinearEquiv.coe_neg theorem neg_apply (x : M) : neg R x = -x := by simp #align linear_equiv.neg_apply LinearEquiv.neg_apply @[simp] theorem symm_neg : (neg R : M ≃ₗ[R] M).symm = neg R := rfl #align linear_equiv.symm_neg LinearEquiv.symm_neg end Neg section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module R M₃] open LinearMap /-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/ def smulOfUnit (a : Rˣ) : M ≃ₗ[R] M := DistribMulAction.toLinearEquiv R M a #align linear_equiv.smul_of_unit LinearEquiv.smulOfUnit /-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives a linear isomorphism between the two function spaces. -/ def arrowCongr {R M₁ M₂ M₂₁ M₂₂ : Sort _} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₂₁] [AddCommMonoid M₂₂] [Module R M₁] [Module R M₂] [Module R M₂₁] [Module R M₂₂] (e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) : (M₁ →ₗ[R] M₂₁) ≃ₗ[R] M₂ →ₗ[R] M₂₂ where toFun := fun f : M₁ →ₗ[R] M₂₁ => (e₂ : M₂₁ →ₗ[R] M₂₂).comp <| f.comp (e₁.symm : M₂ →ₗ[R] M₁) invFun f := (e₂.symm : M₂₂ →ₗ[R] M₂₁).comp <| f.comp (e₁ : M₁ →ₗ[R] M₂) left_inv f := by ext x simp only [symm_apply_apply, Function.comp_apply, coe_comp, coe_coe] right_inv f := by ext x simp only [Function.comp_apply, apply_symm_apply, coe_comp, coe_coe] map_add' f g := by ext x simp only [map_add, add_apply, Function.comp_apply, coe_comp, coe_coe] map_smul' c f := by ext x simp only [smul_apply, Function.comp_apply, coe_comp, map_smulₛₗ e₂, coe_coe] #align linear_equiv.arrow_congr LinearEquiv.arrowCongr @[simp] theorem arrowCongr_apply {R M₁ M₂ M₂₁ M₂₂ : Sort _} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₂₁] [AddCommMonoid M₂₂] [Module R M₁] [Module R M₂] [Module R M₂₁] [Module R M₂₂] (e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₁ →ₗ[R] M₂₁) (x : M₂) : arrowCongr e₁ e₂ f x = e₂ (f (e₁.symm x)) := rfl #align linear_equiv.arrow_congr_apply LinearEquiv.arrowCongr_apply @[simp] theorem arrowCongr_symm_apply {R M₁ M₂ M₂₁ M₂₂ : Sort _} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₂₁] [AddCommMonoid M₂₂] [Module R M₁] [Module R M₂] [Module R M₂₁] [Module R M₂₂] (e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₂ →ₗ[R] M₂₂) (x : M₁) : (arrowCongr e₁ e₂).symm f x = e₂.symm (f (e₁ x)) := rfl #align linear_equiv.arrow_congr_symm_apply LinearEquiv.arrowCongr_symm_apply theorem arrowCongr_comp {N N₂ N₃ : Sort _} [AddCommMonoid N] [AddCommMonoid N₂] [AddCommMonoid N₃] [Module R N] [Module R N₂] [Module R N₃] (e₁ : M ≃ₗ[R] N) (e₂ : M₂ ≃ₗ[R] N₂) (e₃ : M₃ ≃ₗ[R] N₃) (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : arrowCongr e₁ e₃ (g.comp f) = (arrowCongr e₂ e₃ g).comp (arrowCongr e₁ e₂ f) := by ext simp only [symm_apply_apply, arrowCongr_apply, LinearMap.comp_apply] #align linear_equiv.arrow_congr_comp LinearEquiv.arrowCongr_comp theorem arrowCongr_trans {M₁ M₂ M₃ N₁ N₂ N₃ : Sort _} [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] [AddCommMonoid M₃] [Module R M₃] [AddCommMonoid N₁] [Module R N₁] [AddCommMonoid N₂] [Module R N₂] [AddCommMonoid N₃] [Module R N₃] (e₁ : M₁ ≃ₗ[R] M₂) (e₂ : N₁ ≃ₗ[R] N₂) (e₃ : M₂ ≃ₗ[R] M₃) (e₄ : N₂ ≃ₗ[R] N₃) : (arrowCongr e₁ e₂).trans (arrowCongr e₃ e₄) = arrowCongr (e₁.trans e₃) (e₂.trans e₄) := rfl #align linear_equiv.arrow_congr_trans LinearEquiv.arrowCongr_trans /-- If `M₂` and `M₃` are linearly isomorphic then the two spaces of linear maps from `M` into `M₂` and `M` into `M₃` are linearly isomorphic. -/ def congrRight (f : M₂ ≃ₗ[R] M₃) : (M →ₗ[R] M₂) ≃ₗ[R] M →ₗ[R] M₃ := arrowCongr (LinearEquiv.refl R M) f #align linear_equiv.congr_right LinearEquiv.congrRight /-- If `M` and `M₂` are linearly isomorphic then the two spaces of linear maps from `M` and `M₂` to themselves are linearly isomorphic. -/ def conj (e : M ≃ₗ[R] M₂) : Module.End R M ≃ₗ[R] Module.End R M₂ := arrowCongr e e #align linear_equiv.conj LinearEquiv.conj theorem conj_apply (e : M ≃ₗ[R] M₂) (f : Module.End R M) : e.conj f = ((↑e : M →ₗ[R] M₂).comp f).comp (e.symm : M₂ →ₗ[R] M) := rfl #align linear_equiv.conj_apply LinearEquiv.conj_apply theorem conj_apply_apply (e : M ≃ₗ[R] M₂) (f : Module.End R M) (x : M₂) : e.conj f x = e (f (e.symm x)) := rfl #align linear_equiv.conj_apply_apply LinearEquiv.conj_apply_apply theorem symm_conj_apply (e : M ≃ₗ[R] M₂) (f : Module.End R M₂) : e.symm.conj f = ((↑e.symm : M₂ →ₗ[R] M).comp f).comp (e : M →ₗ[R] M₂) := rfl #align linear_equiv.symm_conj_apply LinearEquiv.symm_conj_apply theorem conj_comp (e : M ≃ₗ[R] M₂) (f g : Module.End R M) : e.conj (g.comp f) = (e.conj g).comp (e.conj f) := arrowCongr_comp e e e f g #align linear_equiv.conj_comp LinearEquiv.conj_comp theorem conj_trans (e₁ : M ≃ₗ[R] M₂) (e₂ : M₂ ≃ₗ[R] M₃) : e₁.conj.trans e₂.conj = (e₁.trans e₂).conj := by ext f x rfl #align linear_equiv.conj_trans LinearEquiv.conj_trans @[simp] theorem conj_id (e : M ≃ₗ[R] M₂) : e.conj LinearMap.id = LinearMap.id := by ext simp [conj_apply] #align linear_equiv.conj_id LinearEquiv.conj_id variable (M) in /-- An `R`-linear isomorphism between two `R`-modules `M₂` and `M₃` induces an `S`-linear isomorphism between `M₂ →ₗ[R] M` and `M₃ →ₗ[R] M`, if `M` is both an `R`-module and an `S`-module and their actions commute. -/ def congrLeft {R} (S) [Semiring R] [Semiring S] [Module R M₂] [Module R M₃] [Module R M] [Module S M] [SMulCommClass R S M] (e : M₂ ≃ₗ[R] M₃) : (M₂ →ₗ[R] M) ≃ₗ[S] (M₃ →ₗ[R] M) where toFun f := f.comp e.symm.toLinearMap invFun f := f.comp e.toLinearMap map_add' _ _ := rfl map_smul' _ _ := rfl left_inv f := by dsimp only; apply DFunLike.ext; exact (congr_arg f <| e.left_inv ·) right_inv f := by dsimp only; apply DFunLike.ext; exact (congr_arg f <| e.right_inv ·) end CommSemiring section Field variable [Field K] [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] variable [Module K M] [Module K M₂] [Module K M₃] variable (K) (M) open LinearMap /-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/ @[simps!] def smulOfNeZero (a : K) (ha : a ≠ 0) : M ≃ₗ[K] M := smulOfUnit <| Units.mk0 a ha #align linear_equiv.smul_of_ne_zero LinearEquiv.smulOfNeZero end Field end LinearEquiv namespace Equiv variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R M₂] /-- An equivalence whose underlying function is linear is a linear equivalence. -/ def toLinearEquiv (e : M ≃ M₂) (h : IsLinearMap R (e : M → M₂)) : M ≃ₗ[R] M₂ := { e, h.mk' e with } #align equiv.to_linear_equiv Equiv.toLinearEquiv end Equiv section FunLeft variable (R M) [Semiring R] [AddCommMonoid M] [Module R M] variable {m n p : Type*} namespace LinearMap /-- Given an `R`-module `M` and a function `m → n` between arbitrary types, construct a linear map `(n → M) →ₗ[R] (m → M)` -/ def funLeft (f : m → n) : (n → M) →ₗ[R] m → M where toFun := (· ∘ f) map_add' _ _ := rfl map_smul' _ _ := rfl #align linear_map.fun_left LinearMap.funLeft @[simp] theorem funLeft_apply (f : m → n) (g : n → M) (i : m) : funLeft R M f g i = g (f i) := rfl #align linear_map.fun_left_apply LinearMap.funLeft_apply @[simp] theorem funLeft_id (g : n → M) : funLeft R M _root_.id g = g := rfl #align linear_map.fun_left_id LinearMap.funLeft_id theorem funLeft_comp (f₁ : n → p) (f₂ : m → n) : funLeft R M (f₁ ∘ f₂) = (funLeft R M f₂).comp (funLeft R M f₁) := rfl #align linear_map.fun_left_comp LinearMap.funLeft_comp theorem funLeft_surjective_of_injective (f : m → n) (hf : Injective f) : Surjective (funLeft R M f) := by classical intro g refine ⟨fun x => if h : ∃ y, f y = x then g h.choose else 0, ?_⟩ ext dsimp only [funLeft_apply] split_ifs with w · congr exact hf w.choose_spec · simp only [not_true, exists_apply_eq_apply] at w #align linear_map.fun_left_surjective_of_injective LinearMap.funLeft_surjective_of_injective
Mathlib/Algebra/Module/Equiv.lean
1,316
1,321
theorem funLeft_injective_of_surjective (f : m → n) (hf : Surjective f) : Injective (funLeft R M f) := by
obtain ⟨g, hg⟩ := hf.hasRightInverse suffices LeftInverse (funLeft R M g) (funLeft R M f) by exact this.injective intro x rw [← LinearMap.comp_apply, ← funLeft_comp, hg.id, funLeft_id]
/- Copyright (c) 2023 Ziyu Wang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ziyu Wang, Chenyi Li, Sébastien Gouëzel, Penghao Yu, Zhipeng Cao -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.Calculus.FDeriv.Basic import Mathlib.Analysis.Calculus.Deriv.Basic /-! # Gradient ## Main Definitions Let `f` be a function from a Hilbert Space `F` to `𝕜` (`𝕜` is `ℝ` or `ℂ`) , `x` be a point in `F` and `f'` be a vector in F. Then `HasGradientWithinAt f f' s x` says that `f` has a gradient `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasGradientAt f f' x := HasGradientWithinAt f f' x univ` ## Main results This file contains the following parts of gradient. * the definition of gradient. * the theorems translating between `HasGradientAtFilter` and `HasFDerivAtFilter`, `HasGradientWithinAt` and `HasFDerivWithinAt`, `HasGradientAt` and `HasFDerivAt`, `Gradient` and `fderiv`. * theorems the Uniqueness of Gradient. * the theorems translating between `HasGradientAtFilter` and `HasDerivAtFilter`, `HasGradientAt` and `HasDerivAt`, `Gradient` and `deriv` when `F = 𝕜`. * the theorems about the congruence of the gradient. * the theorems about the gradient of constant function. * the theorems about the continuity of a function admitting a gradient. -/ open Topology InnerProductSpace Set noncomputable section variable {𝕜 F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [CompleteSpace F] variable {f : F → 𝕜} {f' x : F} /-- A function `f` has the gradient `f'` as derivative along the filter `L` if `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` when `x'` converges along the filter `L`. -/ def HasGradientAtFilter (f : F → 𝕜) (f' x : F) (L : Filter F) := HasFDerivAtFilter f (toDual 𝕜 F f') x L /-- `f` has the gradient `f'` at the point `x` within the subset `s` if `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x` inside `s`. -/ def HasGradientWithinAt (f : F → 𝕜) (f' : F) (s : Set F) (x : F) := HasGradientAtFilter f f' x (𝓝[s] x) /-- `f` has the gradient `f'` at the point `x` if `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x`. -/ def HasGradientAt (f : F → 𝕜) (f' x : F) := HasGradientAtFilter f f' x (𝓝 x) /-- Gradient of `f` at the point `x` within the set `s`, if it exists. Zero otherwise. If the derivative exists (i.e., `∃ f', HasGradientWithinAt f f' s x`), then `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x` inside `s`. -/ def gradientWithin (f : F → 𝕜) (s : Set F) (x : F) : F := (toDual 𝕜 F).symm (fderivWithin 𝕜 f s x) /-- Gradient of `f` at the point `x`, if it exists. Zero otherwise. If the derivative exists (i.e., `∃ f', HasGradientAt f f' x`), then `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x`. -/ def gradient (f : F → 𝕜) (x : F) : F := (toDual 𝕜 F).symm (fderiv 𝕜 f x) @[inherit_doc] scoped[Gradient] notation "∇" => gradient local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y open scoped Gradient variable {s : Set F} {L : Filter F} theorem hasGradientWithinAt_iff_hasFDerivWithinAt {s : Set F} : HasGradientWithinAt f f' s x ↔ HasFDerivWithinAt f (toDual 𝕜 F f') s x := Iff.rfl theorem hasFDerivWithinAt_iff_hasGradientWithinAt {frechet : F →L[𝕜] 𝕜} {s : Set F} : HasFDerivWithinAt f frechet s x ↔ HasGradientWithinAt f ((toDual 𝕜 F).symm frechet) s x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, (toDual 𝕜 F).apply_symm_apply frechet] theorem hasGradientAt_iff_hasFDerivAt : HasGradientAt f f' x ↔ HasFDerivAt f (toDual 𝕜 F f') x := Iff.rfl theorem hasFDerivAt_iff_hasGradientAt {frechet : F →L[𝕜] 𝕜} : HasFDerivAt f frechet x ↔ HasGradientAt f ((toDual 𝕜 F).symm frechet) x := by rw [hasGradientAt_iff_hasFDerivAt, (toDual 𝕜 F).apply_symm_apply frechet] alias ⟨HasGradientWithinAt.hasFDerivWithinAt, _⟩ := hasGradientWithinAt_iff_hasFDerivWithinAt alias ⟨HasFDerivWithinAt.hasGradientWithinAt, _⟩ := hasFDerivWithinAt_iff_hasGradientWithinAt alias ⟨HasGradientAt.hasFDerivAt, _⟩ := hasGradientAt_iff_hasFDerivAt alias ⟨HasFDerivAt.hasGradientAt, _⟩ := hasFDerivAt_iff_hasGradientAt theorem gradient_eq_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : ∇ f x = 0 := by rw [gradient, fderiv_zero_of_not_differentiableAt h, map_zero] theorem HasGradientAt.unique {gradf gradg : F} (hf : HasGradientAt f gradf x) (hg : HasGradientAt f gradg x) : gradf = gradg := (toDual 𝕜 F).injective (hf.hasFDerivAt.unique hg.hasFDerivAt)
Mathlib/Analysis/Calculus/Gradient/Basic.lean
118
121
theorem DifferentiableAt.hasGradientAt (h : DifferentiableAt 𝕜 f x) : HasGradientAt f (∇ f x) x := by
rw [hasGradientAt_iff_hasFDerivAt, gradient, (toDual 𝕜 F).apply_symm_apply (fderiv 𝕜 f x)] exact h.hasFDerivAt
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import Mathlib.Algebra.BigOperators.Ring import Mathlib.Data.Fintype.Basic import Mathlib.Data.Int.GCD import Mathlib.RingTheory.Coprime.Basic #align_import ring_theory.coprime.lemmas from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226" /-! # Additional lemmas about elements of a ring satisfying `IsCoprime` and elements of a monoid satisfying `IsRelPrime` These lemmas are in a separate file to the definition of `IsCoprime` or `IsRelPrime` as they require more imports. Notably, this includes lemmas about `Finset.prod` as this requires importing BigOperators, and lemmas about `Pow` since these are easiest to prove via `Finset.prod`. -/ universe u v section IsCoprime variable {R : Type u} {I : Type v} [CommSemiring R] {x y z : R} {s : I → R} {t : Finset I} section theorem Int.isCoprime_iff_gcd_eq_one {m n : ℤ} : IsCoprime m n ↔ Int.gcd m n = 1 := by constructor · rintro ⟨a, b, h⟩ have : 1 = m * a + n * b := by rwa [mul_comm m, mul_comm n, eq_comm] exact Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, this⟩) · rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one] intro h exact ⟨_, _, h⟩ theorem Nat.isCoprime_iff_coprime {m n : ℕ} : IsCoprime (m : ℤ) n ↔ Nat.Coprime m n := by rw [Int.isCoprime_iff_gcd_eq_one, Int.gcd_natCast_natCast] #align nat.is_coprime_iff_coprime Nat.isCoprime_iff_coprime alias ⟨IsCoprime.nat_coprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime #align is_coprime.nat_coprime IsCoprime.nat_coprime #align nat.coprime.is_coprime Nat.Coprime.isCoprime theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) : IsCoprime (a : R) (b : R) := by rw [← isCoprime_iff_coprime] at h rw [← Int.cast_natCast a, ← Int.cast_natCast b] exact IsCoprime.intCast h theorem ne_zero_or_ne_zero_of_nat_coprime {A : Type u} [CommRing A] [Nontrivial A] {a b : ℕ} (h : Nat.Coprime a b) : (a : A) ≠ 0 ∨ (b : A) ≠ 0 := IsCoprime.ne_zero_or_ne_zero (R := A) <| by simpa only [map_natCast] using IsCoprime.map (Nat.Coprime.isCoprime h) (Int.castRingHom A) theorem IsCoprime.prod_left : (∀ i ∈ t, IsCoprime (s i) x) → IsCoprime (∏ i ∈ t, s i) x := by classical refine Finset.induction_on t (fun _ ↦ isCoprime_one_left) fun b t hbt ih H ↦ ?_ rw [Finset.prod_insert hbt] rw [Finset.forall_mem_insert] at H exact H.1.mul_left (ih H.2) #align is_coprime.prod_left IsCoprime.prod_left theorem IsCoprime.prod_right : (∀ i ∈ t, IsCoprime x (s i)) → IsCoprime x (∏ i ∈ t, s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left (R := R) #align is_coprime.prod_right IsCoprime.prod_right theorem IsCoprime.prod_left_iff : IsCoprime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsCoprime (s i) x := by classical refine Finset.induction_on t (iff_of_true isCoprime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_ rw [Finset.prod_insert hbt, IsCoprime.mul_left_iff, ih, Finset.forall_mem_insert] #align is_coprime.prod_left_iff IsCoprime.prod_left_iff theorem IsCoprime.prod_right_iff : IsCoprime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsCoprime x (s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left_iff (R := R) #align is_coprime.prod_right_iff IsCoprime.prod_right_iff theorem IsCoprime.of_prod_left (H1 : IsCoprime (∏ i ∈ t, s i) x) (i : I) (hit : i ∈ t) : IsCoprime (s i) x := IsCoprime.prod_left_iff.1 H1 i hit #align is_coprime.of_prod_left IsCoprime.of_prod_left theorem IsCoprime.of_prod_right (H1 : IsCoprime x (∏ i ∈ t, s i)) (i : I) (hit : i ∈ t) : IsCoprime x (s i) := IsCoprime.prod_right_iff.1 H1 i hit #align is_coprime.of_prod_right IsCoprime.of_prod_right -- Porting note: removed names of things due to linter, but they seem helpful theorem Finset.prod_dvd_of_coprime : (t : Set I).Pairwise (IsCoprime on s) → (∀ i ∈ t, s i ∣ z) → (∏ x ∈ t, s x) ∣ z := by classical exact Finset.induction_on t (fun _ _ ↦ one_dvd z) (by intro a r har ih Hs Hs1 rw [Finset.prod_insert har] have aux1 : a ∈ (↑(insert a r) : Set I) := Finset.mem_insert_self a r refine (IsCoprime.prod_right fun i hir ↦ Hs aux1 (Finset.mem_insert_of_mem hir) <| by rintro rfl exact har hir).mul_dvd (Hs1 a aux1) (ih (Hs.mono ?_) fun i hi ↦ Hs1 i <| Finset.mem_insert_of_mem hi) simp only [Finset.coe_insert, Set.subset_insert]) #align finset.prod_dvd_of_coprime Finset.prod_dvd_of_coprime theorem Fintype.prod_dvd_of_coprime [Fintype I] (Hs : Pairwise (IsCoprime on s)) (Hs1 : ∀ i, s i ∣ z) : (∏ x, s x) ∣ z := Finset.prod_dvd_of_coprime (Hs.set_pairwise _) fun i _ ↦ Hs1 i #align fintype.prod_dvd_of_coprime Fintype.prod_dvd_of_coprime end open Finset theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) : (∃ μ : I → R, (∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j) = 1) ↔ Pairwise (IsCoprime on fun i : t ↦ s i) := by induction h using Finset.Nonempty.cons_induction with | singleton => simp [exists_apply_eq, Pairwise, Function.onFun] | cons a t hat h ih => rw [pairwise_cons'] have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by rw [mem_sdiff, mem_singleton] exact ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩ constructor · rintro ⟨μ, hμ⟩ rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ refine ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩ · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ← @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ rw [← hμ, sum_congr rfl] intro x hx dsimp -- Porting note: terms were showing as sort of `HAdd.hadd` instead of `+` -- this whole proof pretty much breaks and has to be rewritten from scratch rw [add_mul] congr 1 · by_cases hx : x = h.choose · rw [hx, Pi.single_eq_same, Pi.single_eq_same] · rw [Pi.single_eq_of_ne hx, Pi.single_eq_of_ne hx, zero_mul] · rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _, mul_comm] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · have : IsCoprime (s b) (s a) := ⟨μ a * ∏ i ∈ t \ {b}, s i, ∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j, ?_⟩ · exact ⟨this.symm, this⟩ rw [mul_assoc, ← prod_eq_prod_diff_singleton_mul hb, sum_mul, ← hμ, sum_congr rfl] intro x hx rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · rintro ⟨hs, Hb⟩ obtain ⟨μ, hμ⟩ := ih.mpr hs obtain ⟨u, v, huv⟩ := IsCoprime.prod_left fun b hb ↦ (Hb b hb).right use fun i ↦ if i = a then u else v * μ i have hμ' : (∑ i ∈ t, v * ((μ i * ∏ j ∈ t \ {i}, s j) * s a)) = v * s a := by rw [← mul_sum, ← sum_mul, hμ, one_mul] rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat, if_pos rfl, ← huv, ← hμ', sum_congr rfl] intro x hx rw [mul_assoc, if_neg fun ha : x = a ↦ hat (ha.casesOn hx)] rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] #align exists_sum_eq_one_iff_pairwise_coprime exists_sum_eq_one_iff_pairwise_coprime theorem exists_sum_eq_one_iff_pairwise_coprime' [Fintype I] [Nonempty I] [DecidableEq I] : (∃ μ : I → R, (∑ i : I, μ i * ∏ j ∈ {i}ᶜ, s j) = 1) ↔ Pairwise (IsCoprime on s) := by convert exists_sum_eq_one_iff_pairwise_coprime Finset.univ_nonempty (s := s) using 1 simp only [Function.onFun, pairwise_subtype_iff_pairwise_finset', coe_univ, Set.pairwise_univ] #align exists_sum_eq_one_iff_pairwise_coprime' exists_sum_eq_one_iff_pairwise_coprime' -- Porting note: a lot of the capitalization wasn't working theorem pairwise_coprime_iff_coprime_prod [DecidableEq I] : Pairwise (IsCoprime on fun i : t ↦ s i) ↔ ∀ i ∈ t, IsCoprime (s i) (∏ j ∈ t \ {i}, s j) := by refine ⟨fun hp i hi ↦ IsCoprime.prod_right_iff.mpr fun j hj ↦ ?_, fun hp ↦ ?_⟩ · rw [Finset.mem_sdiff, Finset.mem_singleton] at hj obtain ⟨hj, ji⟩ := hj refine @hp ⟨i, hi⟩ ⟨j, hj⟩ fun h ↦ ji (congrArg Subtype.val h).symm -- Porting note: is there a better way compared to the old `congr_arg coe h`? · rintro ⟨i, hi⟩ ⟨j, hj⟩ h apply IsCoprime.prod_right_iff.mp (hp i hi) exact Finset.mem_sdiff.mpr ⟨hj, fun f ↦ h <| Subtype.ext (Finset.mem_singleton.mp f).symm⟩ #align pairwise_coprime_iff_coprime_prod pairwise_coprime_iff_coprime_prod variable {m n : ℕ} theorem IsCoprime.pow_left (H : IsCoprime x y) : IsCoprime (x ^ m) y := by rw [← Finset.card_range m, ← Finset.prod_const] exact IsCoprime.prod_left fun _ _ ↦ H #align is_coprime.pow_left IsCoprime.pow_left theorem IsCoprime.pow_right (H : IsCoprime x y) : IsCoprime x (y ^ n) := by rw [← Finset.card_range n, ← Finset.prod_const] exact IsCoprime.prod_right fun _ _ ↦ H #align is_coprime.pow_right IsCoprime.pow_right theorem IsCoprime.pow (H : IsCoprime x y) : IsCoprime (x ^ m) (y ^ n) := H.pow_left.pow_right #align is_coprime.pow IsCoprime.pow theorem IsCoprime.pow_left_iff (hm : 0 < m) : IsCoprime (x ^ m) y ↔ IsCoprime x y := by refine ⟨fun h ↦ ?_, IsCoprime.pow_left⟩ rw [← Finset.card_range m, ← Finset.prod_const] at h exact h.of_prod_left 0 (Finset.mem_range.mpr hm) -- Porting note: I'm not sure why `finset` didn't get corrected automatically to `Finset` -- by Mathport, nor whether this is an issue #align is_coprime.pow_left_iff IsCoprime.pow_left_iff theorem IsCoprime.pow_right_iff (hm : 0 < m) : IsCoprime x (y ^ m) ↔ IsCoprime x y := isCoprime_comm.trans <| (IsCoprime.pow_left_iff hm).trans <| isCoprime_comm #align is_coprime.pow_right_iff IsCoprime.pow_right_iff theorem IsCoprime.pow_iff (hm : 0 < m) (hn : 0 < n) : IsCoprime (x ^ m) (y ^ n) ↔ IsCoprime x y := (IsCoprime.pow_left_iff hm).trans <| IsCoprime.pow_right_iff hn #align is_coprime.pow_iff IsCoprime.pow_iff end IsCoprime section RelPrime variable {α I} [CommMonoid α] [DecompositionMonoid α] {x y z : α} {s : I → α} {t : Finset I} theorem IsRelPrime.prod_left : (∀ i ∈ t, IsRelPrime (s i) x) → IsRelPrime (∏ i ∈ t, s i) x := by classical refine Finset.induction_on t (fun _ ↦ isRelPrime_one_left) fun b t hbt ih H ↦ ?_ rw [Finset.prod_insert hbt] rw [Finset.forall_mem_insert] at H exact H.1.mul_left (ih H.2) theorem IsRelPrime.prod_right : (∀ i ∈ t, IsRelPrime x (s i)) → IsRelPrime x (∏ i ∈ t, s i) := by simpa only [isRelPrime_comm] using IsRelPrime.prod_left (α := α) theorem IsRelPrime.prod_left_iff : IsRelPrime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsRelPrime (s i) x := by classical refine Finset.induction_on t (iff_of_true isRelPrime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_ rw [Finset.prod_insert hbt, IsRelPrime.mul_left_iff, ih, Finset.forall_mem_insert] theorem IsRelPrime.prod_right_iff : IsRelPrime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsRelPrime x (s i) := by simpa only [isRelPrime_comm] using IsRelPrime.prod_left_iff (α := α) theorem IsRelPrime.of_prod_left (H1 : IsRelPrime (∏ i ∈ t, s i) x) (i : I) (hit : i ∈ t) : IsRelPrime (s i) x := IsRelPrime.prod_left_iff.1 H1 i hit theorem IsRelPrime.of_prod_right (H1 : IsRelPrime x (∏ i ∈ t, s i)) (i : I) (hit : i ∈ t) : IsRelPrime x (s i) := IsRelPrime.prod_right_iff.1 H1 i hit theorem Finset.prod_dvd_of_isRelPrime : (t : Set I).Pairwise (IsRelPrime on s) → (∀ i ∈ t, s i ∣ z) → (∏ x ∈ t, s x) ∣ z := by classical exact Finset.induction_on t (fun _ _ ↦ one_dvd z) (by intro a r har ih Hs Hs1 rw [Finset.prod_insert har] have aux1 : a ∈ (↑(insert a r) : Set I) := Finset.mem_insert_self a r refine (IsRelPrime.prod_right fun i hir ↦ Hs aux1 (Finset.mem_insert_of_mem hir) <| by rintro rfl exact har hir).mul_dvd (Hs1 a aux1) (ih (Hs.mono ?_) fun i hi ↦ Hs1 i <| Finset.mem_insert_of_mem hi) simp only [Finset.coe_insert, Set.subset_insert]) theorem Fintype.prod_dvd_of_isRelPrime [Fintype I] (Hs : Pairwise (IsRelPrime on s)) (Hs1 : ∀ i, s i ∣ z) : (∏ x, s x) ∣ z := Finset.prod_dvd_of_isRelPrime (Hs.set_pairwise _) fun i _ ↦ Hs1 i
Mathlib/RingTheory/Coprime/Lemmas.lean
281
289
theorem pairwise_isRelPrime_iff_isRelPrime_prod [DecidableEq I] : Pairwise (IsRelPrime on fun i : t ↦ s i) ↔ ∀ i ∈ t, IsRelPrime (s i) (∏ j ∈ t \ {i}, s j) := by
refine ⟨fun hp i hi ↦ IsRelPrime.prod_right_iff.mpr fun j hj ↦ ?_, fun hp ↦ ?_⟩ · rw [Finset.mem_sdiff, Finset.mem_singleton] at hj obtain ⟨hj, ji⟩ := hj exact @hp ⟨i, hi⟩ ⟨j, hj⟩ fun h ↦ ji (congrArg Subtype.val h).symm · rintro ⟨i, hi⟩ ⟨j, hj⟩ h apply IsRelPrime.prod_right_iff.mp (hp i hi) exact Finset.mem_sdiff.mpr ⟨hj, fun f ↦ h <| Subtype.ext (Finset.mem_singleton.mp f).symm⟩
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.Ideal.Operations #align_import ring_theory.ideal.operations from "leanprover-community/mathlib"@"e7f0ddbf65bd7181a85edb74b64bdc35ba4bdc74" /-! # Maps on modules and ideals -/ assert_not_exists Basis -- See `RingTheory.Ideal.Basis` assert_not_exists Submodule.hasQuotient -- See `RingTheory.Ideal.QuotientOperations` universe u v w x open Pointwise namespace Ideal section MapAndComap variable {R : Type u} {S : Type v} section Semiring variable {F : Type*} [Semiring R] [Semiring S] variable [FunLike F R S] [rc : RingHomClass F R S] variable (f : F) variable {I J : Ideal R} {K L : Ideal S} /-- `I.map f` is the span of the image of the ideal `I` under `f`, which may be bigger than the image itself. -/ def map (I : Ideal R) : Ideal S := span (f '' I) #align ideal.map Ideal.map /-- `I.comap f` is the preimage of `I` under `f`. -/ def comap (I : Ideal S) : Ideal R where carrier := f ⁻¹' I add_mem' {x y} hx hy := by simp only [Set.mem_preimage, SetLike.mem_coe, map_add f] at hx hy ⊢ exact add_mem hx hy zero_mem' := by simp only [Set.mem_preimage, map_zero, SetLike.mem_coe, Submodule.zero_mem] smul_mem' c x hx := by simp only [smul_eq_mul, Set.mem_preimage, map_mul, SetLike.mem_coe] at * exact mul_mem_left I _ hx #align ideal.comap Ideal.comap @[simp] theorem coe_comap (I : Ideal S) : (comap f I : Set R) = f ⁻¹' I := rfl variable {f} theorem map_mono (h : I ≤ J) : map f I ≤ map f J := span_mono <| Set.image_subset _ h #align ideal.map_mono Ideal.map_mono theorem mem_map_of_mem (f : F) {I : Ideal R} {x : R} (h : x ∈ I) : f x ∈ map f I := subset_span ⟨x, h, rfl⟩ #align ideal.mem_map_of_mem Ideal.mem_map_of_mem theorem apply_coe_mem_map (f : F) (I : Ideal R) (x : I) : f x ∈ I.map f := mem_map_of_mem f x.2 #align ideal.apply_coe_mem_map Ideal.apply_coe_mem_map theorem map_le_iff_le_comap : map f I ≤ K ↔ I ≤ comap f K := span_le.trans Set.image_subset_iff #align ideal.map_le_iff_le_comap Ideal.map_le_iff_le_comap @[simp] theorem mem_comap {x} : x ∈ comap f K ↔ f x ∈ K := Iff.rfl #align ideal.mem_comap Ideal.mem_comap theorem comap_mono (h : K ≤ L) : comap f K ≤ comap f L := Set.preimage_mono fun _ hx => h hx #align ideal.comap_mono Ideal.comap_mono variable (f) theorem comap_ne_top (hK : K ≠ ⊤) : comap f K ≠ ⊤ := (ne_top_iff_one _).2 <| by rw [mem_comap, map_one]; exact (ne_top_iff_one _).1 hK #align ideal.comap_ne_top Ideal.comap_ne_top variable {G : Type*} [FunLike G S R] [rcg : RingHomClass G S R] theorem map_le_comap_of_inv_on (g : G) (I : Ideal R) (hf : Set.LeftInvOn g f I) : I.map f ≤ I.comap g := by refine Ideal.span_le.2 ?_ rintro x ⟨x, hx, rfl⟩ rw [SetLike.mem_coe, mem_comap, hf hx] exact hx #align ideal.map_le_comap_of_inv_on Ideal.map_le_comap_of_inv_on theorem comap_le_map_of_inv_on (g : G) (I : Ideal S) (hf : Set.LeftInvOn g f (f ⁻¹' I)) : I.comap f ≤ I.map g := fun x (hx : f x ∈ I) => hf hx ▸ Ideal.mem_map_of_mem g hx #align ideal.comap_le_map_of_inv_on Ideal.comap_le_map_of_inv_on /-- The `Ideal` version of `Set.image_subset_preimage_of_inverse`. -/ theorem map_le_comap_of_inverse (g : G) (I : Ideal R) (h : Function.LeftInverse g f) : I.map f ≤ I.comap g := map_le_comap_of_inv_on _ _ _ <| h.leftInvOn _ #align ideal.map_le_comap_of_inverse Ideal.map_le_comap_of_inverse /-- The `Ideal` version of `Set.preimage_subset_image_of_inverse`. -/ theorem comap_le_map_of_inverse (g : G) (I : Ideal S) (h : Function.LeftInverse g f) : I.comap f ≤ I.map g := comap_le_map_of_inv_on _ _ _ <| h.leftInvOn _ #align ideal.comap_le_map_of_inverse Ideal.comap_le_map_of_inverse instance IsPrime.comap [hK : K.IsPrime] : (comap f K).IsPrime := ⟨comap_ne_top _ hK.1, fun {x y} => by simp only [mem_comap, map_mul]; apply hK.2⟩ #align ideal.is_prime.comap Ideal.IsPrime.comap variable (I J K L) theorem map_top : map f ⊤ = ⊤ := (eq_top_iff_one _).2 <| subset_span ⟨1, trivial, map_one f⟩ #align ideal.map_top Ideal.map_top theorem gc_map_comap : GaloisConnection (Ideal.map f) (Ideal.comap f) := fun _ _ => Ideal.map_le_iff_le_comap #align ideal.gc_map_comap Ideal.gc_map_comap @[simp] theorem comap_id : I.comap (RingHom.id R) = I := Ideal.ext fun _ => Iff.rfl #align ideal.comap_id Ideal.comap_id @[simp] theorem map_id : I.map (RingHom.id R) = I := (gc_map_comap (RingHom.id R)).l_unique GaloisConnection.id comap_id #align ideal.map_id Ideal.map_id theorem comap_comap {T : Type*} [Semiring T] {I : Ideal T} (f : R →+* S) (g : S →+* T) : (I.comap g).comap f = I.comap (g.comp f) := rfl #align ideal.comap_comap Ideal.comap_comap theorem map_map {T : Type*} [Semiring T] {I : Ideal R} (f : R →+* S) (g : S →+* T) : (I.map f).map g = I.map (g.comp f) := ((gc_map_comap f).compose (gc_map_comap g)).l_unique (gc_map_comap (g.comp f)) fun _ => comap_comap _ _ #align ideal.map_map Ideal.map_map theorem map_span (f : F) (s : Set R) : map f (span s) = span (f '' s) := by refine (Submodule.span_eq_of_le _ ?_ ?_).symm · rintro _ ⟨x, hx, rfl⟩; exact mem_map_of_mem f (subset_span hx) · rw [map_le_iff_le_comap, span_le, coe_comap, ← Set.image_subset_iff] exact subset_span #align ideal.map_span Ideal.map_span variable {f I J K L} theorem map_le_of_le_comap : I ≤ K.comap f → I.map f ≤ K := (gc_map_comap f).l_le #align ideal.map_le_of_le_comap Ideal.map_le_of_le_comap theorem le_comap_of_map_le : I.map f ≤ K → I ≤ K.comap f := (gc_map_comap f).le_u #align ideal.le_comap_of_map_le Ideal.le_comap_of_map_le theorem le_comap_map : I ≤ (I.map f).comap f := (gc_map_comap f).le_u_l _ #align ideal.le_comap_map Ideal.le_comap_map theorem map_comap_le : (K.comap f).map f ≤ K := (gc_map_comap f).l_u_le _ #align ideal.map_comap_le Ideal.map_comap_le @[simp] theorem comap_top : (⊤ : Ideal S).comap f = ⊤ := (gc_map_comap f).u_top #align ideal.comap_top Ideal.comap_top @[simp] theorem comap_eq_top_iff {I : Ideal S} : I.comap f = ⊤ ↔ I = ⊤ := ⟨fun h => I.eq_top_iff_one.mpr (map_one f ▸ mem_comap.mp ((I.comap f).eq_top_iff_one.mp h)), fun h => by rw [h, comap_top]⟩ #align ideal.comap_eq_top_iff Ideal.comap_eq_top_iff @[simp] theorem map_bot : (⊥ : Ideal R).map f = ⊥ := (gc_map_comap f).l_bot #align ideal.map_bot Ideal.map_bot variable (f I J K L) @[simp] theorem map_comap_map : ((I.map f).comap f).map f = I.map f := (gc_map_comap f).l_u_l_eq_l I #align ideal.map_comap_map Ideal.map_comap_map @[simp] theorem comap_map_comap : ((K.comap f).map f).comap f = K.comap f := (gc_map_comap f).u_l_u_eq_u K #align ideal.comap_map_comap Ideal.comap_map_comap theorem map_sup : (I ⊔ J).map f = I.map f ⊔ J.map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup #align ideal.map_sup Ideal.map_sup theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L := rfl #align ideal.comap_inf Ideal.comap_inf variable {ι : Sort*} theorem map_iSup (K : ι → Ideal R) : (iSup K).map f = ⨆ i, (K i).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup #align ideal.map_supr Ideal.map_iSup theorem comap_iInf (K : ι → Ideal S) : (iInf K).comap f = ⨅ i, (K i).comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf #align ideal.comap_infi Ideal.comap_iInf theorem map_sSup (s : Set (Ideal R)) : (sSup s).map f = ⨆ I ∈ s, (I : Ideal R).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_sSup #align ideal.map_Sup Ideal.map_sSup theorem comap_sInf (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ s, (I : Ideal S).comap f := (gc_map_comap f : GaloisConnection (map f) (comap f)).u_sInf #align ideal.comap_Inf Ideal.comap_sInf theorem comap_sInf' (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ comap f '' s, I := _root_.trans (comap_sInf f s) (by rw [iInf_image]) #align ideal.comap_Inf' Ideal.comap_sInf' theorem comap_isPrime [H : IsPrime K] : IsPrime (comap f K) := ⟨comap_ne_top f H.ne_top, fun {x y} h => H.mem_or_mem <| by rwa [mem_comap, map_mul] at h⟩ #align ideal.comap_is_prime Ideal.comap_isPrime variable {I J K L} theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J := (gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_l.map_inf_le _ _ #align ideal.map_inf_le Ideal.map_inf_le theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) := (gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_u.le_map_sup _ _ #align ideal.le_comap_sup Ideal.le_comap_sup -- TODO: Should these be simp lemmas? theorem _root_.element_smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] (r : R) (N : Submodule S M) : (algebraMap R S r • N).restrictScalars R = r • N.restrictScalars R := SetLike.coe_injective (congrArg (· '' _) (funext (algebraMap_smul S r))) theorem smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] (I : Ideal R) (N : Submodule S M) : (I.map (algebraMap R S) • N).restrictScalars R = I • N.restrictScalars R := by simp_rw [map, Submodule.span_smul_eq, ← Submodule.coe_set_smul, Submodule.set_smul_eq_iSup, ← element_smul_restrictScalars, iSup_image] exact (_root_.map_iSup₂ (Submodule.restrictScalarsLatticeHom R S M) _) @[simp] theorem smul_top_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] (I : Ideal R) : I • (⊤ : Submodule R S) = (I.map (algebraMap R S)).restrictScalars R := Eq.trans (smul_restrictScalars I (⊤ : Ideal S)).symm <| congrArg _ <| Eq.trans (Ideal.smul_eq_mul _ _) (Ideal.mul_top _) #align ideal.smul_top_eq_map Ideal.smul_top_eq_map @[simp] theorem coe_restrictScalars {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) : (I.restrictScalars R : Set S) = ↑I := rfl #align ideal.coe_restrict_scalars Ideal.coe_restrictScalars /-- The smallest `S`-submodule that contains all `x ∈ I * y ∈ J` is also the smallest `R`-submodule that does so. -/ @[simp] theorem restrictScalars_mul {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] (I J : Ideal S) : (I * J).restrictScalars R = I.restrictScalars R * J.restrictScalars R := le_antisymm (fun _ hx => Submodule.mul_induction_on hx (fun _ hx _ hy => Submodule.mul_mem_mul hx hy) fun _ _ => Submodule.add_mem _) (Submodule.mul_le.mpr fun _ hx _ hy => Ideal.mul_mem_mul hx hy) #align ideal.restrict_scalars_mul Ideal.restrictScalars_mul section Surjective variable (hf : Function.Surjective f) open Function theorem map_comap_of_surjective (I : Ideal S) : map f (comap f I) = I := le_antisymm (map_le_iff_le_comap.2 le_rfl) fun s hsi => let ⟨r, hfrs⟩ := hf s hfrs ▸ (mem_map_of_mem f <| show f r ∈ I from hfrs.symm ▸ hsi) #align ideal.map_comap_of_surjective Ideal.map_comap_of_surjective /-- `map` and `comap` are adjoint, and the composition `map f ∘ comap f` is the identity -/ def giMapComap : GaloisInsertion (map f) (comap f) := GaloisInsertion.monotoneIntro (gc_map_comap f).monotone_u (gc_map_comap f).monotone_l (fun _ => le_comap_map) (map_comap_of_surjective _ hf) #align ideal.gi_map_comap Ideal.giMapComap theorem map_surjective_of_surjective : Surjective (map f) := (giMapComap f hf).l_surjective #align ideal.map_surjective_of_surjective Ideal.map_surjective_of_surjective theorem comap_injective_of_surjective : Injective (comap f) := (giMapComap f hf).u_injective #align ideal.comap_injective_of_surjective Ideal.comap_injective_of_surjective theorem map_sup_comap_of_surjective (I J : Ideal S) : (I.comap f ⊔ J.comap f).map f = I ⊔ J := (giMapComap f hf).l_sup_u _ _ #align ideal.map_sup_comap_of_surjective Ideal.map_sup_comap_of_surjective theorem map_iSup_comap_of_surjective (K : ι → Ideal S) : (⨆ i, (K i).comap f).map f = iSup K := (giMapComap f hf).l_iSup_u _ #align ideal.map_supr_comap_of_surjective Ideal.map_iSup_comap_of_surjective theorem map_inf_comap_of_surjective (I J : Ideal S) : (I.comap f ⊓ J.comap f).map f = I ⊓ J := (giMapComap f hf).l_inf_u _ _ #align ideal.map_inf_comap_of_surjective Ideal.map_inf_comap_of_surjective theorem map_iInf_comap_of_surjective (K : ι → Ideal S) : (⨅ i, (K i).comap f).map f = iInf K := (giMapComap f hf).l_iInf_u _ #align ideal.map_infi_comap_of_surjective Ideal.map_iInf_comap_of_surjective theorem mem_image_of_mem_map_of_surjective {I : Ideal R} {y} (H : y ∈ map f I) : y ∈ f '' I := Submodule.span_induction H (fun _ => id) ⟨0, I.zero_mem, map_zero f⟩ (fun _ _ ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩ => ⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ map_add f _ _⟩) fun c _ ⟨x, hxi, hxy⟩ => let ⟨d, hdc⟩ := hf c ⟨d * x, I.mul_mem_left _ hxi, hdc ▸ hxy ▸ map_mul f _ _⟩ #align ideal.mem_image_of_mem_map_of_surjective Ideal.mem_image_of_mem_map_of_surjective theorem mem_map_iff_of_surjective {I : Ideal R} {y} : y ∈ map f I ↔ ∃ x, x ∈ I ∧ f x = y := ⟨fun h => (Set.mem_image _ _ _).2 (mem_image_of_mem_map_of_surjective f hf h), fun ⟨_, hx⟩ => hx.right ▸ mem_map_of_mem f hx.left⟩ #align ideal.mem_map_iff_of_surjective Ideal.mem_map_iff_of_surjective theorem le_map_of_comap_le_of_surjective : comap f K ≤ I → K ≤ map f I := fun h => map_comap_of_surjective f hf K ▸ map_mono h #align ideal.le_map_of_comap_le_of_surjective Ideal.le_map_of_comap_le_of_surjective theorem map_eq_submodule_map (f : R →+* S) [h : RingHomSurjective f] (I : Ideal R) : I.map f = Submodule.map f.toSemilinearMap I := Submodule.ext fun _ => mem_map_iff_of_surjective f h.1 #align ideal.map_eq_submodule_map Ideal.map_eq_submodule_map end Surjective section Injective variable (hf : Function.Injective f) theorem comap_bot_le_of_injective : comap f ⊥ ≤ I := by refine le_trans (fun x hx => ?_) bot_le rw [mem_comap, Submodule.mem_bot, ← map_zero f] at hx exact Eq.symm (hf hx) ▸ Submodule.zero_mem ⊥ #align ideal.comap_bot_le_of_injective Ideal.comap_bot_le_of_injective theorem comap_bot_of_injective : Ideal.comap f ⊥ = ⊥ := le_bot_iff.mp (Ideal.comap_bot_le_of_injective f hf) #align ideal.comap_bot_of_injective Ideal.comap_bot_of_injective end Injective /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm (map f I) = I`. -/ @[simp] theorem map_of_equiv (I : Ideal R) (f : R ≃+* S) : (I.map (f : R →+* S)).map (f.symm : S →+* R) = I := by rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, map_map, RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, map_id] #align ideal.map_of_equiv Ideal.map_of_equiv /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f (comap f.symm I) = I`. -/ @[simp] theorem comap_of_equiv (I : Ideal R) (f : R ≃+* S) : (I.comap (f.symm : S →+* R)).comap (f : R →+* S) = I := by rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, comap_comap, RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, comap_id] #align ideal.comap_of_equiv Ideal.comap_of_equiv /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f I = comap f.symm I`. -/ theorem map_comap_of_equiv (I : Ideal R) (f : R ≃+* S) : I.map (f : R →+* S) = I.comap f.symm := le_antisymm (Ideal.map_le_comap_of_inverse _ _ _ (Equiv.left_inv' _)) (Ideal.comap_le_map_of_inverse _ _ _ (Equiv.right_inv' _)) #align ideal.map_comap_of_equiv Ideal.map_comap_of_equiv /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f.symm I = map f I`. -/ @[simp] theorem comap_symm (I : Ideal R) (f : R ≃+* S) : I.comap f.symm = I.map f := (map_comap_of_equiv I f).symm /-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm I = comap f I`. -/ @[simp] theorem map_symm (I : Ideal S) (f : R ≃+* S) : I.map f.symm = I.comap f := map_comap_of_equiv I (RingEquiv.symm f) end Semiring section Ring variable {F : Type*} [Ring R] [Ring S] variable [FunLike F R S] [RingHomClass F R S] (f : F) {I : Ideal R} section Surjective variable (hf : Function.Surjective f) theorem comap_map_of_surjective (I : Ideal R) : comap f (map f I) = I ⊔ comap f ⊥ := le_antisymm (fun r h => let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h Submodule.mem_sup.2 ⟨s, hsi, r - s, (Submodule.mem_bot S).2 <| by rw [map_sub, hfsr, sub_self], add_sub_cancel s r⟩) (sup_le (map_le_iff_le_comap.1 le_rfl) (comap_mono bot_le)) #align ideal.comap_map_of_surjective Ideal.comap_map_of_surjective /-- Correspondence theorem -/ def relIsoOfSurjective : Ideal S ≃o { p : Ideal R // comap f ⊥ ≤ p } where toFun J := ⟨comap f J, comap_mono bot_le⟩ invFun I := map f I.1 left_inv J := map_comap_of_surjective f hf J right_inv I := Subtype.eq <| show comap f (map f I.1) = I.1 from (comap_map_of_surjective f hf I).symm ▸ le_antisymm (sup_le le_rfl I.2) le_sup_left map_rel_iff' {I1 I2} := ⟨fun H => map_comap_of_surjective f hf I1 ▸ map_comap_of_surjective f hf I2 ▸ map_mono H, comap_mono⟩ #align ideal.rel_iso_of_surjective Ideal.relIsoOfSurjective /-- The map on ideals induced by a surjective map preserves inclusion. -/ def orderEmbeddingOfSurjective : Ideal S ↪o Ideal R := (relIsoOfSurjective f hf).toRelEmbedding.trans (Subtype.relEmbedding (fun x y => x ≤ y) _) #align ideal.order_embedding_of_surjective Ideal.orderEmbeddingOfSurjective theorem map_eq_top_or_isMaximal_of_surjective {I : Ideal R} (H : IsMaximal I) : map f I = ⊤ ∨ IsMaximal (map f I) := by refine or_iff_not_imp_left.2 fun ne_top => ⟨⟨fun h => ne_top h, fun J hJ => ?_⟩⟩ · refine (relIsoOfSurjective f hf).injective (Subtype.ext_iff.2 (Eq.trans (H.1.2 (comap f J) (lt_of_le_of_ne ?_ ?_)) comap_top.symm)) · exact map_le_iff_le_comap.1 (le_of_lt hJ) · exact fun h => hJ.right (le_map_of_comap_le_of_surjective f hf (le_of_eq h.symm)) #align ideal.map_eq_top_or_is_maximal_of_surjective Ideal.map_eq_top_or_isMaximal_of_surjective theorem comap_isMaximal_of_surjective {K : Ideal S} [H : IsMaximal K] : IsMaximal (comap f K) := by refine ⟨⟨comap_ne_top _ H.1.1, fun J hJ => ?_⟩⟩ suffices map f J = ⊤ by have := congr_arg (comap f) this rw [comap_top, comap_map_of_surjective _ hf, eq_top_iff] at this rw [eq_top_iff] exact le_trans this (sup_le (le_of_eq rfl) (le_trans (comap_mono bot_le) (le_of_lt hJ))) refine H.1.2 (map f J) (lt_of_le_of_ne (le_map_of_comap_le_of_surjective _ hf (le_of_lt hJ)) fun h => ne_of_lt hJ (_root_.trans (congr_arg (comap f) h) ?_)) rw [comap_map_of_surjective _ hf, sup_eq_left] exact le_trans (comap_mono bot_le) (le_of_lt hJ) #align ideal.comap_is_maximal_of_surjective Ideal.comap_isMaximal_of_surjective theorem comap_le_comap_iff_of_surjective (I J : Ideal S) : comap f I ≤ comap f J ↔ I ≤ J := ⟨fun h => (map_comap_of_surjective f hf I).symm.le.trans (map_le_of_le_comap h), fun h => le_comap_of_map_le ((map_comap_of_surjective f hf I).le.trans h)⟩ #align ideal.comap_le_comap_iff_of_surjective Ideal.comap_le_comap_iff_of_surjective end Surjective section Bijective variable (hf : Function.Bijective f) /-- Special case of the correspondence theorem for isomorphic rings -/ def relIsoOfBijective : Ideal S ≃o Ideal R where toFun := comap f invFun := map f left_inv := (relIsoOfSurjective f hf.right).left_inv right_inv J := Subtype.ext_iff.1 ((relIsoOfSurjective f hf.right).right_inv ⟨J, comap_bot_le_of_injective f hf.left⟩) map_rel_iff' {_ _} := (relIsoOfSurjective f hf.right).map_rel_iff' #align ideal.rel_iso_of_bijective Ideal.relIsoOfBijective theorem comap_le_iff_le_map {I : Ideal R} {K : Ideal S} : comap f K ≤ I ↔ K ≤ map f I := ⟨fun h => le_map_of_comap_le_of_surjective f hf.right h, fun h => (relIsoOfBijective f hf).right_inv I ▸ comap_mono h⟩ #align ideal.comap_le_iff_le_map Ideal.comap_le_iff_le_map theorem map.isMaximal {I : Ideal R} (H : IsMaximal I) : IsMaximal (map f I) := by refine or_iff_not_imp_left.1 (map_eq_top_or_isMaximal_of_surjective f hf.right H) fun h => H.1.1 ?_ calc I = comap f (map f I) := ((relIsoOfBijective f hf).right_inv I).symm _ = comap f ⊤ := by rw [h] _ = ⊤ := by rw [comap_top] #align ideal.map.is_maximal Ideal.map.isMaximal end Bijective theorem RingEquiv.bot_maximal_iff (e : R ≃+* S) : (⊥ : Ideal R).IsMaximal ↔ (⊥ : Ideal S).IsMaximal := ⟨fun h => map_bot (f := e.toRingHom) ▸ map.isMaximal e.toRingHom e.bijective h, fun h => map_bot (f := e.symm.toRingHom) ▸ map.isMaximal e.symm.toRingHom e.symm.bijective h⟩ #align ideal.ring_equiv.bot_maximal_iff Ideal.RingEquiv.bot_maximal_iff end Ring section CommRing variable {F : Type*} [CommRing R] [CommRing S] variable [FunLike F R S] [rc : RingHomClass F R S] variable (f : F) variable {I J : Ideal R} {K L : Ideal S} variable (I J K L) theorem map_mul : map f (I * J) = map f I * map f J := le_antisymm (map_le_iff_le_comap.2 <| mul_le.2 fun r hri s hsj => show (f (r * s)) ∈ map f I * map f J by rw [_root_.map_mul]; exact mul_mem_mul (mem_map_of_mem f hri) (mem_map_of_mem f hsj)) (span_mul_span (↑f '' ↑I) (↑f '' ↑J) ▸ (span_le.2 <| Set.iUnion₂_subset fun i ⟨r, hri, hfri⟩ => Set.iUnion₂_subset fun j ⟨s, hsj, hfsj⟩ => Set.singleton_subset_iff.2 <| hfri ▸ hfsj ▸ by rw [← _root_.map_mul]; exact mem_map_of_mem f (mul_mem_mul hri hsj))) #align ideal.map_mul Ideal.map_mul /-- The pushforward `Ideal.map` as a monoid-with-zero homomorphism. -/ @[simps] def mapHom : Ideal R →*₀ Ideal S where toFun := map f map_mul' I J := Ideal.map_mul f I J map_one' := by simp only [one_eq_top]; exact Ideal.map_top f map_zero' := Ideal.map_bot #align ideal.map_hom Ideal.mapHom protected theorem map_pow (n : ℕ) : map f (I ^ n) = map f I ^ n := map_pow (mapHom f) I n #align ideal.map_pow Ideal.map_pow theorem comap_radical : comap f (radical K) = radical (comap f K) := by ext simp [radical] #align ideal.comap_radical Ideal.comap_radical variable {K} theorem IsRadical.comap (hK : K.IsRadical) : (comap f K).IsRadical := by rw [← hK.radical, comap_radical] apply radical_isRadical #align ideal.is_radical.comap Ideal.IsRadical.comap variable {I J L} theorem map_radical_le : map f (radical I) ≤ radical (map f I) := map_le_iff_le_comap.2 fun r ⟨n, hrni⟩ => ⟨n, map_pow f r n ▸ mem_map_of_mem f hrni⟩ #align ideal.map_radical_le Ideal.map_radical_le theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) := map_le_iff_le_comap.1 <| (map_mul f (comap f K) (comap f L)).symm ▸ mul_mono (map_le_iff_le_comap.2 <| le_rfl) (map_le_iff_le_comap.2 <| le_rfl) #align ideal.le_comap_mul Ideal.le_comap_mul theorem le_comap_pow (n : ℕ) : K.comap f ^ n ≤ (K ^ n).comap f := by induction' n with n n_ih · rw [pow_zero, pow_zero, Ideal.one_eq_top, Ideal.one_eq_top] exact rfl.le · rw [pow_succ, pow_succ] exact (Ideal.mul_mono_left n_ih).trans (Ideal.le_comap_mul f) #align ideal.le_comap_pow Ideal.le_comap_pow end CommRing end MapAndComap end Ideal namespace RingHom variable {R : Type u} {S : Type v} {T : Type w} section Semiring variable {F : Type*} {G : Type*} [Semiring R] [Semiring S] [Semiring T] variable [FunLike F R S] [rcf : RingHomClass F R S] [FunLike G T S] [rcg : RingHomClass G T S] variable (f : F) (g : G) /-- Kernel of a ring homomorphism as an ideal of the domain. -/ def ker : Ideal R := Ideal.comap f ⊥ #align ring_hom.ker RingHom.ker /-- An element is in the kernel if and only if it maps to zero. -/ theorem mem_ker {r} : r ∈ ker f ↔ f r = 0 := by rw [ker, Ideal.mem_comap, Submodule.mem_bot] #align ring_hom.mem_ker RingHom.mem_ker theorem ker_eq : (ker f : Set R) = Set.preimage f {0} := rfl #align ring_hom.ker_eq RingHom.ker_eq theorem ker_eq_comap_bot (f : F) : ker f = Ideal.comap f ⊥ := rfl #align ring_hom.ker_eq_comap_bot RingHom.ker_eq_comap_bot theorem comap_ker (f : S →+* R) (g : T →+* S) : f.ker.comap g = ker (f.comp g) := by rw [RingHom.ker_eq_comap_bot, Ideal.comap_comap, RingHom.ker_eq_comap_bot] #align ring_hom.comap_ker RingHom.comap_ker /-- If the target is not the zero ring, then one is not in the kernel. -/ theorem not_one_mem_ker [Nontrivial S] (f : F) : (1 : R) ∉ ker f := by rw [mem_ker, map_one] exact one_ne_zero #align ring_hom.not_one_mem_ker RingHom.not_one_mem_ker theorem ker_ne_top [Nontrivial S] (f : F) : ker f ≠ ⊤ := (Ideal.ne_top_iff_one _).mpr <| not_one_mem_ker f #align ring_hom.ker_ne_top RingHom.ker_ne_top lemma _root_.Pi.ker_ringHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)] (φ : ∀ i, S →+* R i) : ker (Pi.ringHom φ) = ⨅ i, ker (φ i) := by ext x simp [mem_ker, Ideal.mem_iInf, Function.funext_iff] @[simp] theorem ker_rangeSRestrict (f : R →+* S) : ker f.rangeSRestrict = ker f := Ideal.ext fun _ ↦ Subtype.ext_iff end Semiring section Ring variable {F : Type*} [Ring R] [Semiring S] [FunLike F R S] [rc : RingHomClass F R S] (f : F) theorem injective_iff_ker_eq_bot : Function.Injective f ↔ ker f = ⊥ := by rw [SetLike.ext'_iff, ker_eq, Set.ext_iff] exact injective_iff_map_eq_zero' f #align ring_hom.injective_iff_ker_eq_bot RingHom.injective_iff_ker_eq_bot theorem ker_eq_bot_iff_eq_zero : ker f = ⊥ ↔ ∀ x, f x = 0 → x = 0 := by rw [← injective_iff_map_eq_zero f, injective_iff_ker_eq_bot] #align ring_hom.ker_eq_bot_iff_eq_zero RingHom.ker_eq_bot_iff_eq_zero @[simp] theorem ker_coe_equiv (f : R ≃+* S) : ker (f : R →+* S) = ⊥ := by simpa only [← injective_iff_ker_eq_bot] using EquivLike.injective f #align ring_hom.ker_coe_equiv RingHom.ker_coe_equiv @[simp] theorem ker_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S] (f : F') : ker f = ⊥ := by simpa only [← injective_iff_ker_eq_bot] using EquivLike.injective f #align ring_hom.ker_equiv RingHom.ker_equiv end Ring section RingRing variable {F : Type*} [Ring R] [Ring S] [FunLike F R S] [rc : RingHomClass F R S] (f : F) theorem sub_mem_ker_iff {x y} : x - y ∈ ker f ↔ f x = f y := by rw [mem_ker, map_sub, sub_eq_zero] #align ring_hom.sub_mem_ker_iff RingHom.sub_mem_ker_iff @[simp] theorem ker_rangeRestrict (f : R →+* S) : ker f.rangeRestrict = ker f := Ideal.ext fun _ ↦ Subtype.ext_iff end RingRing /-- The kernel of a homomorphism to a domain is a prime ideal. -/ theorem ker_isPrime {F : Type*} [Ring R] [Ring S] [IsDomain S] [FunLike F R S] [RingHomClass F R S] (f : F) : (ker f).IsPrime := ⟨by rw [Ne, Ideal.eq_top_iff_one] exact not_one_mem_ker f, fun {x y} => by simpa only [mem_ker, map_mul] using @eq_zero_or_eq_zero_of_mul_eq_zero S _ _ _ _ _⟩ #align ring_hom.ker_is_prime RingHom.ker_isPrime /-- The kernel of a homomorphism to a field is a maximal ideal. -/ theorem ker_isMaximal_of_surjective {R K F : Type*} [Ring R] [Field K] [FunLike F R K] [RingHomClass F R K] (f : F) (hf : Function.Surjective f) : (ker f).IsMaximal := by refine Ideal.isMaximal_iff.mpr ⟨fun h1 => one_ne_zero' K <| map_one f ▸ (mem_ker f).mp h1, fun J x hJ hxf hxJ => ?_⟩ obtain ⟨y, hy⟩ := hf (f x)⁻¹ have H : 1 = y * x - (y * x - 1) := (sub_sub_cancel _ _).symm rw [H] refine J.sub_mem (J.mul_mem_left _ hxJ) (hJ ?_) rw [mem_ker] simp only [hy, map_sub, map_one, map_mul, inv_mul_cancel (mt (mem_ker f).mpr hxf), sub_self] #align ring_hom.ker_is_maximal_of_surjective RingHom.ker_isMaximal_of_surjective end RingHom namespace Ideal variable {R : Type*} {S : Type*} {F : Type*} section Semiring variable [Semiring R] [Semiring S] [FunLike F R S] [rc : RingHomClass F R S] theorem map_eq_bot_iff_le_ker {I : Ideal R} (f : F) : I.map f = ⊥ ↔ I ≤ RingHom.ker f := by rw [RingHom.ker, eq_bot_iff, map_le_iff_le_comap] #align ideal.map_eq_bot_iff_le_ker Ideal.map_eq_bot_iff_le_ker theorem ker_le_comap {K : Ideal S} (f : F) : RingHom.ker f ≤ comap f K := fun _ hx => mem_comap.2 (((RingHom.mem_ker f).1 hx).symm ▸ K.zero_mem) #align ideal.ker_le_comap Ideal.ker_le_comap theorem map_isPrime_of_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S] (f : F') {I : Ideal R} [IsPrime I] : IsPrime (map f I) := by have h : I.map f = I.map ((f : R ≃+* S) : R →+* S) := rfl rw [h, map_comap_of_equiv I (f : R ≃+* S)] exact Ideal.IsPrime.comap (RingEquiv.symm (f : R ≃+* S)) #align ideal.map_is_prime_of_equiv Ideal.map_isPrime_of_equiv end Semiring section Ring variable [Ring R] [Ring S] [FunLike F R S] [rc : RingHomClass F R S]
Mathlib/RingTheory/Ideal/Maps.lean
736
754
theorem map_sInf {A : Set (Ideal R)} {f : F} (hf : Function.Surjective f) : (∀ J ∈ A, RingHom.ker f ≤ J) → map f (sInf A) = sInf (map f '' A) := by
refine fun h => le_antisymm (le_sInf ?_) ?_ · intro j hj y hy cases' (mem_map_iff_of_surjective f hf).1 hy with x hx cases' (Set.mem_image _ _ _).mp hj with J hJ rw [← hJ.right, ← hx.right] exact mem_map_of_mem f (sInf_le_of_le hJ.left (le_of_eq rfl) hx.left) · intro y hy cases' hf y with x hx refine hx ▸ mem_map_of_mem f ?_ have : ∀ I ∈ A, y ∈ map f I := by simpa using hy rw [Submodule.mem_sInf] intro J hJ rcases (mem_map_iff_of_surjective f hf).1 (this J hJ) with ⟨x', hx', rfl⟩ have : x - x' ∈ J := by apply h J hJ rw [RingHom.mem_ker, map_sub, hx, sub_self] simpa only [sub_add_cancel] using J.add_mem this hx'
/- 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, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Logic.Pairwise import Mathlib.Order.CompleteBooleanAlgebra import Mathlib.Order.Directed import Mathlib.Order.GaloisConnection #align_import data.set.lattice from "leanprover-community/mathlib"@"b86832321b586c6ac23ef8cdef6a7a27e42b13bd" /-! # The set lattice This file provides usual set notation for unions and intersections, a `CompleteLattice` instance for `Set α`, and some more set constructions. ## Main declarations * `Set.iUnion`: **i**ndexed **union**. Union of an indexed family of sets. * `Set.iInter`: **i**ndexed **inter**section. Intersection of an indexed family of sets. * `Set.sInter`: **s**et **inter**section. Intersection of sets belonging to a set of sets. * `Set.sUnion`: **s**et **union**. Union of sets belonging to a set of sets. * `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and `⋃₀ s = ⋃ x ∈ s, x`. * `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`, `< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference. See `Set.BooleanAlgebra`. * `Set.kernImage`: For a function `f : α → β`, `s.kernImage f` is the set of `y` such that `f ⁻¹ y ⊆ s`. * `Set.seq`: Union of the image of a set under a **seq**uence of functions. `seq s t` is the union of `f '' t` over all `f ∈ s`, where `t : Set α` and `s : Set (α → β)`. * `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an indexed family of disjoint sets. ## Naming convention In lemma names, * `⋃ i, s i` is called `iUnion` * `⋂ i, s i` is called `iInter` * `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`. * `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`. * `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂` where `j : i ∈ s`. * `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂` where `j : i ∈ s`. ## Notation * `⋃`: `Set.iUnion` * `⋂`: `Set.iInter` * `⋃₀`: `Set.sUnion` * `⋂₀`: `Set.sInter` -/ open Function Set universe u variable {α β γ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*} namespace Set /-! ### Complete lattice and complete Boolean algebra instances -/ theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by simp_rw [mem_iUnion] #align set.mem_Union₂ Set.mem_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by simp_rw [mem_iInter] #align set.mem_Inter₂ Set.mem_iInter₂ theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i := mem_iUnion.2 ⟨i, ha⟩ #align set.mem_Union_of_mem Set.mem_iUnion_of_mem /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) : a ∈ ⋃ (i) (j), s i j := mem_iUnion₂.2 ⟨i, j, ha⟩ #align set.mem_Union₂_of_mem Set.mem_iUnion₂_of_mem theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i := mem_iInter.2 h #align set.mem_Inter_of_mem Set.mem_iInter_of_mem /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) : a ∈ ⋂ (i) (j), s i j := mem_iInter₂.2 h #align set.mem_Inter₂_of_mem Set.mem_iInter₂_of_mem instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (Set α) := { instBooleanAlgebraSet with le_sSup := fun s t t_in a a_in => ⟨t, t_in, a_in⟩ sSup_le := fun s t h a ⟨t', ⟨t'_in, a_in⟩⟩ => h t' t'_in a_in le_sInf := fun s t h a a_in t' t'_in => h t' t'_in a_in sInf_le := fun s t t_in a h => h _ t_in iInf_iSup_eq := by intros; ext; simp [Classical.skolem] } section GaloisConnection variable {f : α → β} protected theorem image_preimage : GaloisConnection (image f) (preimage f) := fun _ _ => image_subset_iff #align set.image_preimage Set.image_preimage protected theorem preimage_kernImage : GaloisConnection (preimage f) (kernImage f) := fun _ _ => subset_kernImage_iff.symm #align set.preimage_kern_image Set.preimage_kernImage end GaloisConnection section kernImage variable {f : α → β} lemma kernImage_mono : Monotone (kernImage f) := Set.preimage_kernImage.monotone_u lemma kernImage_eq_compl {s : Set α} : kernImage f s = (f '' sᶜ)ᶜ := Set.preimage_kernImage.u_unique (Set.image_preimage.compl) (fun t ↦ compl_compl (f ⁻¹' t) ▸ Set.preimage_compl) lemma kernImage_compl {s : Set α} : kernImage f (sᶜ) = (f '' s)ᶜ := by rw [kernImage_eq_compl, compl_compl] lemma kernImage_empty : kernImage f ∅ = (range f)ᶜ := by rw [kernImage_eq_compl, compl_empty, image_univ] lemma kernImage_preimage_eq_iff {s : Set β} : kernImage f (f ⁻¹' s) = s ↔ (range f)ᶜ ⊆ s := by rw [kernImage_eq_compl, ← preimage_compl, compl_eq_comm, eq_comm, image_preimage_eq_iff, compl_subset_comm] lemma compl_range_subset_kernImage {s : Set α} : (range f)ᶜ ⊆ kernImage f s := by rw [← kernImage_empty] exact kernImage_mono (empty_subset _) lemma kernImage_union_preimage {s : Set α} {t : Set β} : kernImage f (s ∪ f ⁻¹' t) = kernImage f s ∪ t := by rw [kernImage_eq_compl, kernImage_eq_compl, compl_union, ← preimage_compl, image_inter_preimage, compl_inter, compl_compl] lemma kernImage_preimage_union {s : Set α} {t : Set β} : kernImage f (f ⁻¹' t ∪ s) = t ∪ kernImage f s := by rw [union_comm, kernImage_union_preimage, union_comm] end kernImage /-! ### Union and intersection over an indexed family of sets -/ instance : OrderTop (Set α) where top := univ le_top := by simp @[congr] theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ := iSup_congr_Prop pq f #align set.Union_congr_Prop Set.iUnion_congr_Prop @[congr] theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ := iInf_congr_Prop pq f #align set.Inter_congr_Prop Set.iInter_congr_Prop theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i := iSup_plift_up _ #align set.Union_plift_up Set.iUnion_plift_up theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i := iSup_plift_down _ #align set.Union_plift_down Set.iUnion_plift_down theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i := iInf_plift_up _ #align set.Inter_plift_up Set.iInter_plift_up theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i := iInf_plift_down _ #align set.Inter_plift_down Set.iInter_plift_down theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ := iSup_eq_if _ #align set.Union_eq_if Set.iUnion_eq_if theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋃ h : p, s h = if h : p then s h else ∅ := iSup_eq_dif _ #align set.Union_eq_dif Set.iUnion_eq_dif theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ := iInf_eq_if _ #align set.Inter_eq_if Set.iInter_eq_if theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋂ h : p, s h = if h : p then s h else univ := _root_.iInf_eq_dif _ #align set.Infi_eq_dif Set.iInf_eq_dif theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β) (w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by have p : x ∈ ⊤ := Set.mem_univ x rw [← w, Set.mem_iUnion] at p simpa using p #align set.exists_set_mem_of_union_eq_top Set.exists_set_mem_of_union_eq_top theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α) (H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some exact ⟨x, m⟩ #align set.nonempty_of_union_eq_top_of_nonempty Set.nonempty_of_union_eq_top_of_nonempty theorem nonempty_of_nonempty_iUnion {s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by obtain ⟨x, hx⟩ := h_Union exact ⟨Classical.choose <| mem_iUnion.mp hx⟩ theorem nonempty_of_nonempty_iUnion_eq_univ {s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι := nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty) theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } := ext fun _ => mem_iUnion.symm #align set.set_of_exists Set.setOf_exists theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } := ext fun _ => mem_iInter.symm #align set.set_of_forall Set.setOf_forall theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t := iSup_le h #align set.Union_subset Set.iUnion_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) : ⋃ (i) (j), s i j ⊆ t := iUnion_subset fun x => iUnion_subset (h x) #align set.Union₂_subset Set.iUnion₂_subset theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i := le_iInf h #align set.subset_Inter Set.subset_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) : s ⊆ ⋂ (i) (j), t i j := subset_iInter fun x => subset_iInter <| h x #align set.subset_Inter₂ Set.subset_iInter₂ @[simp] theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t := ⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩ #align set.Union_subset_iff Set.iUnion_subset_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} : ⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff] #align set.Union₂_subset_iff Set.iUnion₂_subset_iff @[simp] theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i := le_iInf_iff #align set.subset_Inter_iff Set.subset_iInter_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- Porting note (#10618): removing `simp`. `simp` can prove it theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} : (s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff] #align set.subset_Inter₂_iff Set.subset_iInter₂_iff theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i := le_iSup #align set.subset_Union Set.subset_iUnion theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i := iInf_le #align set.Inter_subset Set.iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' := le_iSup₂ i j #align set.subset_Union₂ Set.subset_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j := iInf₂_le i j #align set.Inter₂_subset Set.iInter₂_subset /-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i := le_iSup_of_le i h #align set.subset_Union_of_subset Set.subset_iUnion_of_subset /-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) : ⋂ i, s i ⊆ t := iInf_le_of_le i h #align set.Inter_subset_of_subset Set.iInter_subset_of_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i) (h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j := le_iSup₂_of_le i j h #align set.subset_Union₂_of_subset Set.subset_iUnion₂_of_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i) (h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t := iInf₂_le_of_le i j h #align set.Inter₂_subset_of_subset Set.iInter₂_subset_of_subset theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono h #align set.Union_mono Set.iUnion_mono @[gcongr] theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t := iSup_mono h /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j := iSup₂_mono h #align set.Union₂_mono Set.iUnion₂_mono theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i := iInf_mono h #align set.Inter_mono Set.iInter_mono @[gcongr] theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t := iInf_mono h /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j := iInf₂_mono h #align set.Inter₂_mono Set.iInter₂_mono theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono' h #align set.Union_mono' Set.iUnion_mono' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/ theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' := iSup₂_mono' h #align set.Union₂_mono' Set.iUnion₂_mono' theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) : ⋂ i, s i ⊆ ⋂ j, t j := Set.subset_iInter fun j => let ⟨i, hi⟩ := h j iInter_subset_of_subset i hi #align set.Inter_mono' Set.iInter_mono' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/ theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' := subset_iInter₂_iff.2 fun i' j' => let ⟨_, _, hst⟩ := h i' j' (iInter₂_subset _ _).trans hst #align set.Inter₂_mono' Set.iInter₂_mono' theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) : ⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i := iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl #align set.Union₂_subset_Union Set.iUnion₂_subset_iUnion theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) : ⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i := iInter_mono fun _ => subset_iInter fun _ => Subset.rfl #align set.Inter_subset_Inter₂ Set.iInter_subset_iInter₂ theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by ext exact mem_iUnion #align set.Union_set_of Set.iUnion_setOf theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by ext exact mem_iInter #align set.Inter_set_of Set.iInter_setOf theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y := h1.iSup_congr h h2 #align set.Union_congr_of_surjective Set.iUnion_congr_of_surjective theorem iInter_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⋂ x, f x = ⋂ y, g y := h1.iInf_congr h h2 #align set.Inter_congr_of_surjective Set.iInter_congr_of_surjective lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h #align set.Union_congr Set.iUnion_congr lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h #align set.Inter_congr Set.iInter_congr /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ lemma iUnion₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) : ⋃ (i) (j), s i j = ⋃ (i) (j), t i j := iUnion_congr fun i => iUnion_congr <| h i #align set.Union₂_congr Set.iUnion₂_congr /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ lemma iInter₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) : ⋂ (i) (j), s i j = ⋂ (i) (j), t i j := iInter_congr fun i => iInter_congr <| h i #align set.Inter₂_congr Set.iInter₂_congr section Nonempty variable [Nonempty ι] {f : ι → Set α} {s : Set α} lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const #align set.Union_const Set.iUnion_const lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const #align set.Inter_const Set.iInter_const lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s := (iUnion_congr hf).trans <| iUnion_const _ #align set.Union_eq_const Set.iUnion_eq_const lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s := (iInter_congr hf).trans <| iInter_const _ #align set.Inter_eq_const Set.iInter_eq_const end Nonempty @[simp] theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ := compl_iSup #align set.compl_Union Set.compl_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by simp_rw [compl_iUnion] #align set.compl_Union₂ Set.compl_iUnion₂ @[simp] theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ := compl_iInf #align set.compl_Inter Set.compl_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by simp_rw [compl_iInter] #align set.compl_Inter₂ Set.compl_iInter₂ -- classical -- complete_boolean_algebra theorem iUnion_eq_compl_iInter_compl (s : ι → Set β) : ⋃ i, s i = (⋂ i, (s i)ᶜ)ᶜ := by simp only [compl_iInter, compl_compl] #align set.Union_eq_compl_Inter_compl Set.iUnion_eq_compl_iInter_compl -- classical -- complete_boolean_algebra theorem iInter_eq_compl_iUnion_compl (s : ι → Set β) : ⋂ i, s i = (⋃ i, (s i)ᶜ)ᶜ := by simp only [compl_iUnion, compl_compl] #align set.Inter_eq_compl_Union_compl Set.iInter_eq_compl_iUnion_compl theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i := inf_iSup_eq _ _ #align set.inter_Union Set.inter_iUnion theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s := iSup_inf_eq _ _ #align set.Union_inter Set.iUnion_inter theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) : ⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i := iSup_sup_eq #align set.Union_union_distrib Set.iUnion_union_distrib theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) : ⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i := iInf_inf_eq #align set.Inter_inter_distrib Set.iInter_inter_distrib theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i := sup_iSup #align set.union_Union Set.union_iUnion theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s := iSup_sup #align set.Union_union Set.iUnion_union theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i := inf_iInf #align set.inter_Inter Set.inter_iInter theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s := iInf_inf #align set.Inter_inter Set.iInter_inter -- classical theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i := sup_iInf_eq _ _ #align set.union_Inter Set.union_iInter theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t := iInf_sup_eq _ _ #align set.Inter_union Set.iInter_union theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s := iUnion_inter _ _ #align set.Union_diff Set.iUnion_diff theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i, t i) = ⋂ i, s \ t i := by rw [diff_eq, compl_iUnion, inter_iInter]; rfl #align set.diff_Union Set.diff_iUnion theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by rw [diff_eq, compl_iInter, inter_iUnion]; rfl #align set.diff_Inter Set.diff_iInter theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i := le_iSup_inf_iSup s t #align set.Union_inter_subset Set.iUnion_inter_subset theorem iUnion_inter_of_monotone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α} (hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_monotone hs ht #align set.Union_inter_of_monotone Set.iUnion_inter_of_monotone theorem iUnion_inter_of_antitone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α} (hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_antitone hs ht #align set.Union_inter_of_antitone Set.iUnion_inter_of_antitone theorem iInter_union_of_monotone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α} (hs : Monotone s) (ht : Monotone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i := iInf_sup_of_monotone hs ht #align set.Inter_union_of_monotone Set.iInter_union_of_monotone theorem iInter_union_of_antitone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α} (hs : Antitone s) (ht : Antitone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i := iInf_sup_of_antitone hs ht #align set.Inter_union_of_antitone Set.iInter_union_of_antitone /-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/ theorem iUnion_iInter_subset {s : ι → ι' → Set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j := iSup_iInf_le_iInf_iSup (flip s) #align set.Union_Inter_subset Set.iUnion_iInter_subset theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) := iSup_option s #align set.Union_option Set.iUnion_option theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) := iInf_option s #align set.Inter_option Set.iInter_option section variable (p : ι → Prop) [DecidablePred p] theorem iUnion_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) : ⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) ∪ ⋃ (i) (h : ¬p i), g i h := iSup_dite _ _ _ #align set.Union_dite Set.iUnion_dite theorem iUnion_ite (f g : ι → Set α) : ⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) ∪ ⋃ (i) (_ : ¬p i), g i := iUnion_dite _ _ _ #align set.Union_ite Set.iUnion_ite theorem iInter_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) : ⋂ i, (if h : p i then f i h else g i h) = (⋂ (i) (h : p i), f i h) ∩ ⋂ (i) (h : ¬p i), g i h := iInf_dite _ _ _ #align set.Inter_dite Set.iInter_dite theorem iInter_ite (f g : ι → Set α) : ⋂ i, (if p i then f i else g i) = (⋂ (i) (_ : p i), f i) ∩ ⋂ (i) (_ : ¬p i), g i := iInter_dite _ _ _ #align set.Inter_ite Set.iInter_ite end theorem image_projection_prod {ι : Type*} {α : ι → Type*} {v : ∀ i : ι, Set (α i)} (hv : (pi univ v).Nonempty) (i : ι) : ((fun x : ∀ i : ι, α i => x i) '' ⋂ k, (fun x : ∀ j : ι, α j => x k) ⁻¹' v k) = v i := by classical apply Subset.antisymm · simp [iInter_subset] · intro y y_in simp only [mem_image, mem_iInter, mem_preimage] rcases hv with ⟨z, hz⟩ refine ⟨Function.update z i y, ?_, update_same i y z⟩ rw [@forall_update_iff ι α _ z i y fun i t => t ∈ v i] exact ⟨y_in, fun j _ => by simpa using hz j⟩ #align set.image_projection_prod Set.image_projection_prod /-! ### Unions and intersections indexed by `Prop` -/ theorem iInter_false {s : False → Set α} : iInter s = univ := iInf_false #align set.Inter_false Set.iInter_false theorem iUnion_false {s : False → Set α} : iUnion s = ∅ := iSup_false #align set.Union_false Set.iUnion_false @[simp] theorem iInter_true {s : True → Set α} : iInter s = s trivial := iInf_true #align set.Inter_true Set.iInter_true @[simp] theorem iUnion_true {s : True → Set α} : iUnion s = s trivial := iSup_true #align set.Union_true Set.iUnion_true @[simp] theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} : ⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ := iInf_exists #align set.Inter_exists Set.iInter_exists @[simp] theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} : ⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ := iSup_exists #align set.Union_exists Set.iUnion_exists @[simp] theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ := iSup_bot #align set.Union_empty Set.iUnion_empty @[simp] theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ := iInf_top #align set.Inter_univ Set.iInter_univ section variable {s : ι → Set α} @[simp] theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ := iSup_eq_bot #align set.Union_eq_empty Set.iUnion_eq_empty @[simp] theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ := iInf_eq_top #align set.Inter_eq_univ Set.iInter_eq_univ @[simp] theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by simp [nonempty_iff_ne_empty] #align set.nonempty_Union Set.nonempty_iUnion -- Porting note (#10618): removing `simp`. `simp` can prove it theorem nonempty_biUnion {t : Set α} {s : α → Set β} : (⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp #align set.nonempty_bUnion Set.nonempty_biUnion theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) : ⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ := iSup_exists #align set.Union_nonempty_index Set.iUnion_nonempty_index end @[simp] theorem iInter_iInter_eq_left {b : β} {s : ∀ x : β, x = b → Set α} : ⋂ (x) (h : x = b), s x h = s b rfl := iInf_iInf_eq_left #align set.Inter_Inter_eq_left Set.iInter_iInter_eq_left @[simp] theorem iInter_iInter_eq_right {b : β} {s : ∀ x : β, b = x → Set α} : ⋂ (x) (h : b = x), s x h = s b rfl := iInf_iInf_eq_right #align set.Inter_Inter_eq_right Set.iInter_iInter_eq_right @[simp] theorem iUnion_iUnion_eq_left {b : β} {s : ∀ x : β, x = b → Set α} : ⋃ (x) (h : x = b), s x h = s b rfl := iSup_iSup_eq_left #align set.Union_Union_eq_left Set.iUnion_iUnion_eq_left @[simp] theorem iUnion_iUnion_eq_right {b : β} {s : ∀ x : β, b = x → Set α} : ⋃ (x) (h : b = x), s x h = s b rfl := iSup_iSup_eq_right #align set.Union_Union_eq_right Set.iUnion_iUnion_eq_right theorem iInter_or {p q : Prop} (s : p ∨ q → Set α) : ⋂ h, s h = (⋂ h : p, s (Or.inl h)) ∩ ⋂ h : q, s (Or.inr h) := iInf_or #align set.Inter_or Set.iInter_or theorem iUnion_or {p q : Prop} (s : p ∨ q → Set α) : ⋃ h, s h = (⋃ i, s (Or.inl i)) ∪ ⋃ j, s (Or.inr j) := iSup_or #align set.Union_or Set.iUnion_or /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/ theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ := iSup_and #align set.Union_and Set.iUnion_and /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/ theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ := iInf_and #align set.Inter_and Set.iInter_and /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/ theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' := iSup_comm #align set.Union_comm Set.iUnion_comm /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/ theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' := iInf_comm #align set.Inter_comm Set.iInter_comm theorem iUnion_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ := iSup_sigma theorem iUnion_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋃ i, ⋃ a, s i a = ⋃ ia : Sigma γ, s ia.1 ia.2 := iSup_sigma' _ theorem iInter_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ := iInf_sigma theorem iInter_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋂ i, ⋂ a, s i a = ⋂ ia : Sigma γ, s ia.1 ia.2 := iInf_sigma' _ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/ theorem iUnion₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) : ⋃ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋃ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ := iSup₂_comm _ #align set.Union₂_comm Set.iUnion₂_comm /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/ theorem iInter₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) : ⋂ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋂ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ := iInf₂_comm _ #align set.Inter₂_comm Set.iInter₂_comm @[simp] theorem biUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) : ⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h = ⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iUnion_and, @iUnion_comm _ ι'] #align set.bUnion_and Set.biUnion_and @[simp] theorem biUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) : ⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h = ⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iUnion_and, @iUnion_comm _ ι] #align set.bUnion_and' Set.biUnion_and' @[simp] theorem biInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) : ⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h = ⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iInter_and, @iInter_comm _ ι'] #align set.bInter_and Set.biInter_and @[simp] theorem biInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) : ⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h = ⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iInter_and, @iInter_comm _ ι] #align set.bInter_and' Set.biInter_and' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/ @[simp] theorem iUnion_iUnion_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} : ⋃ (x) (h), s x h = s b (Or.inl rfl) ∪ ⋃ (x) (h : p x), s x (Or.inr h) := by simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left] #align set.Union_Union_eq_or_left Set.iUnion_iUnion_eq_or_left /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/ @[simp] theorem iInter_iInter_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} : ⋂ (x) (h), s x h = s b (Or.inl rfl) ∩ ⋂ (x) (h : p x), s x (Or.inr h) := by simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left] #align set.Inter_Inter_eq_or_left Set.iInter_iInter_eq_or_left /-! ### Bounded unions and intersections -/ /-- A specialization of `mem_iUnion₂`. -/ theorem mem_biUnion {s : Set α} {t : α → Set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) : y ∈ ⋃ x ∈ s, t x := mem_iUnion₂_of_mem xs ytx #align set.mem_bUnion Set.mem_biUnion /-- A specialization of `mem_iInter₂`. -/ theorem mem_biInter {s : Set α} {t : α → Set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) : y ∈ ⋂ x ∈ s, t x := mem_iInter₂_of_mem h #align set.mem_bInter Set.mem_biInter /-- A specialization of `subset_iUnion₂`. -/ theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) : u x ⊆ ⋃ x ∈ s, u x := -- Porting note: Why is this not just `subset_iUnion₂ x xs`? @subset_iUnion₂ β α (· ∈ s) (fun i _ => u i) x xs #align set.subset_bUnion_of_mem Set.subset_biUnion_of_mem /-- A specialization of `iInter₂_subset`. -/ theorem biInter_subset_of_mem {s : Set α} {t : α → Set β} {x : α} (xs : x ∈ s) : ⋂ x ∈ s, t x ⊆ t x := iInter₂_subset x xs #align set.bInter_subset_of_mem Set.biInter_subset_of_mem theorem biUnion_subset_biUnion_left {s s' : Set α} {t : α → Set β} (h : s ⊆ s') : ⋃ x ∈ s, t x ⊆ ⋃ x ∈ s', t x := iUnion₂_subset fun _ hx => subset_biUnion_of_mem <| h hx #align set.bUnion_subset_bUnion_left Set.biUnion_subset_biUnion_left theorem biInter_subset_biInter_left {s s' : Set α} {t : α → Set β} (h : s' ⊆ s) : ⋂ x ∈ s, t x ⊆ ⋂ x ∈ s', t x := subset_iInter₂ fun _ hx => biInter_subset_of_mem <| h hx #align set.bInter_subset_bInter_left Set.biInter_subset_biInter_left theorem biUnion_mono {s s' : Set α} {t t' : α → Set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) : ⋃ x ∈ s', t x ⊆ ⋃ x ∈ s, t' x := (biUnion_subset_biUnion_left hs).trans <| iUnion₂_mono h #align set.bUnion_mono Set.biUnion_mono theorem biInter_mono {s s' : Set α} {t t' : α → Set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) : ⋂ x ∈ s', t x ⊆ ⋂ x ∈ s, t' x := (biInter_subset_biInter_left hs).trans <| iInter₂_mono h #align set.bInter_mono Set.biInter_mono theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) : ⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 := iSup_subtype' #align set.bUnion_eq_Union Set.biUnion_eq_iUnion theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) : ⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 := iInf_subtype' #align set.bInter_eq_Inter Set.biInter_eq_iInter theorem iUnion_subtype (p : α → Prop) (s : { x // p x } → Set β) : ⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ := iSup_subtype #align set.Union_subtype Set.iUnion_subtype theorem iInter_subtype (p : α → Prop) (s : { x // p x } → Set β) : ⋂ x : { x // p x }, s x = ⋂ (x) (hx : p x), s ⟨x, hx⟩ := iInf_subtype #align set.Inter_subtype Set.iInter_subtype theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ := iInf_emptyset #align set.bInter_empty Set.biInter_empty theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x := iInf_univ #align set.bInter_univ Set.biInter_univ @[simp] theorem biUnion_self (s : Set α) : ⋃ x ∈ s, s = s := Subset.antisymm (iUnion₂_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx #align set.bUnion_self Set.biUnion_self @[simp] theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by rw [iUnion_nonempty_index, biUnion_self] #align set.Union_nonempty_self Set.iUnion_nonempty_self theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a := iInf_singleton #align set.bInter_singleton Set.biInter_singleton theorem biInter_union (s t : Set α) (u : α → Set β) : ⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x := iInf_union #align set.bInter_union Set.biInter_union theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) : ⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp #align set.bInter_insert Set.biInter_insert theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by rw [biInter_insert, biInter_singleton] #align set.bInter_pair Set.biInter_pair theorem biInter_inter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) : ⋂ i ∈ s, f i ∩ t = (⋂ i ∈ s, f i) ∩ t := by haveI : Nonempty s := hs.to_subtype simp [biInter_eq_iInter, ← iInter_inter] #align set.bInter_inter Set.biInter_inter theorem inter_biInter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) : ⋂ i ∈ s, t ∩ f i = t ∩ ⋂ i ∈ s, f i := by rw [inter_comm, ← biInter_inter hs] simp [inter_comm] #align set.inter_bInter Set.inter_biInter theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ := iSup_emptyset #align set.bUnion_empty Set.biUnion_empty theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x := iSup_univ #align set.bUnion_univ Set.biUnion_univ theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a := iSup_singleton #align set.bUnion_singleton Set.biUnion_singleton @[simp] theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s := ext <| by simp #align set.bUnion_of_singleton Set.biUnion_of_singleton theorem biUnion_union (s t : Set α) (u : α → Set β) : ⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x := iSup_union #align set.bUnion_union Set.biUnion_union @[simp] theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iUnion_subtype _ _ #align set.Union_coe_set Set.iUnion_coe_set @[simp] theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iInter_subtype _ _ #align set.Inter_coe_set Set.iInter_coe_set theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) : ⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp #align set.bUnion_insert Set.biUnion_insert theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by simp #align set.bUnion_pair Set.biUnion_pair /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem inter_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion] #align set.inter_Union₂ Set.inter_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_inter (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter] #align set.Union₂_inter Set.iUnion₂_inter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem union_iInter₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_iInter] #align set.union_Inter₂ Set.union_iInter₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_union (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [iInter_union] #align set.Inter₂_union Set.iInter₂_union theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) : x ∈ ⋃₀S := ⟨t, ht, hx⟩ #align set.mem_sUnion_of_mem Set.mem_sUnion_of_mem -- is this theorem really necessary? theorem not_mem_of_not_mem_sUnion {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∉ ⋃₀S) (ht : t ∈ S) : x ∉ t := fun h => hx ⟨t, ht, h⟩ #align set.not_mem_of_not_mem_sUnion Set.not_mem_of_not_mem_sUnion theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t := sInf_le tS #align set.sInter_subset_of_mem Set.sInter_subset_of_mem theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀S := le_sSup tS #align set.subset_sUnion_of_mem Set.subset_sUnion_of_mem theorem subset_sUnion_of_subset {s : Set α} (t : Set (Set α)) (u : Set α) (h₁ : s ⊆ u) (h₂ : u ∈ t) : s ⊆ ⋃₀t := Subset.trans h₁ (subset_sUnion_of_mem h₂) #align set.subset_sUnion_of_subset Set.subset_sUnion_of_subset theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀S ⊆ t := sSup_le h #align set.sUnion_subset Set.sUnion_subset @[simp] theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t := sSup_le_iff #align set.sUnion_subset_iff Set.sUnion_subset_iff /-- `sUnion` is monotone under taking a subset of each set. -/ lemma sUnion_mono_subsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, t ⊆ f t) : ⋃₀ s ⊆ ⋃₀ (f '' s) := fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩ /-- `sUnion` is monotone under taking a superset of each set. -/ lemma sUnion_mono_supsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, f t ⊆ t) : ⋃₀ (f '' s) ⊆ ⋃₀ s := -- If t ∈ f '' s is arbitrary; t = f u for some u : Set α. fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut ▸ hf u) hxt⟩ theorem subset_sInter {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ ⋂₀ S := le_sInf h #align set.subset_sInter Set.subset_sInter @[simp] theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' := le_sInf_iff #align set.subset_sInter_iff Set.subset_sInter_iff @[gcongr] theorem sUnion_subset_sUnion {S T : Set (Set α)} (h : S ⊆ T) : ⋃₀S ⊆ ⋃₀T := sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs) #align set.sUnion_subset_sUnion Set.sUnion_subset_sUnion @[gcongr] theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S := subset_sInter fun _ hs => sInter_subset_of_mem (h hs) #align set.sInter_subset_sInter Set.sInter_subset_sInter @[simp] theorem sUnion_empty : ⋃₀∅ = (∅ : Set α) := sSup_empty #align set.sUnion_empty Set.sUnion_empty @[simp] theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) := sInf_empty #align set.sInter_empty Set.sInter_empty @[simp] theorem sUnion_singleton (s : Set α) : ⋃₀{s} = s := sSup_singleton #align set.sUnion_singleton Set.sUnion_singleton @[simp] theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s := sInf_singleton #align set.sInter_singleton Set.sInter_singleton @[simp] theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀S = ∅ ↔ ∀ s ∈ S, s = ∅ := sSup_eq_bot #align set.sUnion_eq_empty Set.sUnion_eq_empty @[simp] theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ := sInf_eq_top #align set.sInter_eq_univ Set.sInter_eq_univ theorem subset_powerset_iff {s : Set (Set α)} {t : Set α} : s ⊆ 𝒫 t ↔ ⋃₀ s ⊆ t := sUnion_subset_iff.symm /-- `⋃₀` and `𝒫` form a Galois connection. -/ theorem sUnion_powerset_gc : GaloisConnection (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) := gc_sSup_Iic /-- `⋃₀` and `𝒫` form a Galois insertion. -/ def sUnion_powerset_gi : GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) := gi_sSup_Iic /-- If all sets in a collection are either `∅` or `Set.univ`, then so is their union. -/ theorem sUnion_mem_empty_univ {S : Set (Set α)} (h : S ⊆ {∅, univ}) : ⋃₀ S ∈ ({∅, univ} : Set (Set α)) := by simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall] rintro ⟨s, hs, hne⟩ obtain rfl : s = univ := (h hs).resolve_left hne exact univ_subset_iff.1 <| subset_sUnion_of_mem hs @[simp] theorem nonempty_sUnion {S : Set (Set α)} : (⋃₀S).Nonempty ↔ ∃ s ∈ S, Set.Nonempty s := by simp [nonempty_iff_ne_empty] #align set.nonempty_sUnion Set.nonempty_sUnion theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀s).Nonempty) : s.Nonempty := let ⟨s, hs, _⟩ := nonempty_sUnion.1 h ⟨s, hs⟩ #align set.nonempty.of_sUnion Set.Nonempty.of_sUnion theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀s = univ) : s.Nonempty := Nonempty.of_sUnion <| h.symm ▸ univ_nonempty #align set.nonempty.of_sUnion_eq_univ Set.Nonempty.of_sUnion_eq_univ theorem sUnion_union (S T : Set (Set α)) : ⋃₀(S ∪ T) = ⋃₀S ∪ ⋃₀T := sSup_union #align set.sUnion_union Set.sUnion_union theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := sInf_union #align set.sInter_union Set.sInter_union @[simp] theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀insert s T = s ∪ ⋃₀T := sSup_insert #align set.sUnion_insert Set.sUnion_insert @[simp] theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T := sInf_insert #align set.sInter_insert Set.sInter_insert @[simp] theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀(s \ {∅}) = ⋃₀s := sSup_diff_singleton_bot s #align set.sUnion_diff_singleton_empty Set.sUnion_diff_singleton_empty @[simp] theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s := sInf_diff_singleton_top s #align set.sInter_diff_singleton_univ Set.sInter_diff_singleton_univ theorem sUnion_pair (s t : Set α) : ⋃₀{s, t} = s ∪ t := sSup_pair #align set.sUnion_pair Set.sUnion_pair theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t := sInf_pair #align set.sInter_pair Set.sInter_pair @[simp] theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀(f '' s) = ⋃ x ∈ s, f x := sSup_image #align set.sUnion_image Set.sUnion_image @[simp] theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x := sInf_image #align set.sInter_image Set.sInter_image @[simp] theorem sUnion_range (f : ι → Set β) : ⋃₀range f = ⋃ x, f x := rfl #align set.sUnion_range Set.sUnion_range @[simp] theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x := rfl #align set.sInter_range Set.sInter_range theorem iUnion_eq_univ_iff {f : ι → Set α} : ⋃ i, f i = univ ↔ ∀ x, ∃ i, x ∈ f i := by simp only [eq_univ_iff_forall, mem_iUnion] #align set.Union_eq_univ_iff Set.iUnion_eq_univ_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iUnion₂_eq_univ_iff {s : ∀ i, κ i → Set α} : ⋃ (i) (j), s i j = univ ↔ ∀ a, ∃ i j, a ∈ s i j := by simp only [iUnion_eq_univ_iff, mem_iUnion] #align set.Union₂_eq_univ_iff Set.iUnion₂_eq_univ_iff
Mathlib/Data/Set/Lattice.lean
1,188
1,189
theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by
simp only [eq_univ_iff_forall, mem_sUnion]
/- Copyright (c) 2020 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.BigOperators.NatAntidiagonal import Mathlib.Algebra.Polynomial.RingDivision #align_import data.polynomial.mirror from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # "Mirror" of a univariate polynomial In this file we define `Polynomial.mirror`, a variant of `Polynomial.reverse`. The difference between `reverse` and `mirror` is that `reverse` will decrease the degree if the polynomial is divisible by `X`. ## Main definitions - `Polynomial.mirror` ## Main results - `Polynomial.mirror_mul_of_domain`: `mirror` preserves multiplication. - `Polynomial.irreducible_of_mirror`: an irreducibility criterion involving `mirror` -/ namespace Polynomial open Polynomial section Semiring variable {R : Type*} [Semiring R] (p q : R[X]) /-- mirror of a polynomial: reverses the coefficients while preserving `Polynomial.natDegree` -/ noncomputable def mirror := p.reverse * X ^ p.natTrailingDegree #align polynomial.mirror Polynomial.mirror @[simp] theorem mirror_zero : (0 : R[X]).mirror = 0 := by simp [mirror] #align polynomial.mirror_zero Polynomial.mirror_zero theorem mirror_monomial (n : ℕ) (a : R) : (monomial n a).mirror = monomial n a := by classical by_cases ha : a = 0 · rw [ha, monomial_zero_right, mirror_zero] · rw [mirror, reverse, natDegree_monomial n a, if_neg ha, natTrailingDegree_monomial ha, ← C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, revAt_le (le_refl n), tsub_self, pow_zero, mul_one] #align polynomial.mirror_monomial Polynomial.mirror_monomial theorem mirror_C (a : R) : (C a).mirror = C a := mirror_monomial 0 a set_option linter.uppercaseLean3 false in #align polynomial.mirror_C Polynomial.mirror_C theorem mirror_X : X.mirror = (X : R[X]) := mirror_monomial 1 (1 : R) set_option linter.uppercaseLean3 false in #align polynomial.mirror_X Polynomial.mirror_X
Mathlib/Algebra/Polynomial/Mirror.lean
66
72
theorem mirror_natDegree : p.mirror.natDegree = p.natDegree := by
by_cases hp : p = 0 · rw [hp, mirror_zero] nontriviality R rw [mirror, natDegree_mul', reverse_natDegree, natDegree_X_pow, tsub_add_cancel_of_le p.natTrailingDegree_le_natDegree] rwa [leadingCoeff_X_pow, mul_one, reverse_leadingCoeff, Ne, trailingCoeff_eq_zero]
/- 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 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 variable (M) in lemma isLocalizedModule_id (R') [CommSemiring R'] [Algebra R R'] [IsLocalization S R'] [Module R' M] [IsScalarTower R R' M] : IsLocalizedModule S (.id : M →ₗ[R] M) where map_units s := by rw [← (Algebra.lsmul R (A := R') R M).commutes]; exact (IsLocalization.map_units R' s).map _ surj' m := ⟨(m, 1), one_smul _ _⟩ exists_of_eq h := ⟨1, congr_arg _ h⟩ variable {S} in theorem isLocalizedModule_iff_isLocalization {A Aₛ} [CommSemiring A] [Algebra R A] [CommSemiring Aₛ] [Algebra A Aₛ] [Algebra R Aₛ] [IsScalarTower R A Aₛ] : IsLocalizedModule S (IsScalarTower.toAlgHom R A Aₛ).toLinearMap ↔ IsLocalization (Algebra.algebraMapSubmonoid A S) Aₛ := by rw [isLocalizedModule_iff, isLocalization_iff] refine and_congr ?_ (and_congr (forall_congr' fun _ ↦ ?_) (forall₂_congr fun _ _ ↦ ?_)) · simp_rw [← (Algebra.lmul R Aₛ).commutes, Algebra.lmul_isUnit_iff, Subtype.forall, Algebra.algebraMapSubmonoid, ← SetLike.mem_coe, Submonoid.coe_map, Set.forall_mem_image, ← IsScalarTower.algebraMap_apply] · simp_rw [Prod.exists, Subtype.exists, Algebra.algebraMapSubmonoid] simp [← IsScalarTower.algebraMap_apply, Submonoid.mk_smul, Algebra.smul_def, mul_comm] · congr!; simp_rw [Subtype.exists, Algebra.algebraMapSubmonoid]; simp [Algebra.smul_def] instance {A Aₛ} [CommSemiring A] [Algebra R A][CommSemiring Aₛ] [Algebra A Aₛ] [Algebra R Aₛ] [IsScalarTower R A Aₛ] [h : IsLocalization (Algebra.algebraMapSubmonoid A S) Aₛ] : IsLocalizedModule S (IsScalarTower.toAlgHom R A Aₛ).toLinearMap := isLocalizedModule_iff_isLocalization.mpr h lemma isLocalizedModule_iff_isLocalization' (R') [CommSemiring R'] [Algebra R R'] : IsLocalizedModule S (Algebra.ofId R R').toLinearMap ↔ IsLocalization S R' := by convert isLocalizedModule_iff_isLocalization (S := S) (A := R) (Aₛ := R') exact (Submonoid.map_id S).symm namespace LocalizedModule /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `LocalizedModule S M → M''`. -/ noncomputable def lift' (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit (algebraMap R (Module.End R M'') x)) : LocalizedModule S M → M'' := fun m => m.liftOn (fun p => (h p.2).unit⁻¹.val <| g p.1) fun ⟨m, s⟩ ⟨m', s'⟩ ⟨c, eq1⟩ => by -- Porting note: We remove `generalize_proofs h1 h2`. This does nothing here. dsimp only simp only [Submonoid.smul_def] at eq1 rw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← map_smul, eq_comm, Module.End_algebraMap_isUnit_inv_apply_eq_iff] have : c • s • g m' = c • s' • g m := by simp only [Submonoid.smul_def, ← g.map_smul, eq1] have : Function.Injective (h c).unit.inv := by rw [Function.injective_iff_hasLeftInverse] refine ⟨(h c).unit, ?_⟩ intro x change ((h c).unit.1 * (h c).unit.inv) x = x simp only [Units.inv_eq_val_inv, IsUnit.mul_val_inv, LinearMap.one_apply] apply_fun (h c).unit.inv erw [Units.inv_eq_val_inv, Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← (h c).unit⁻¹.val.map_smul] symm rw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← g.map_smul, ← g.map_smul, ← g.map_smul, ← g.map_smul, eq1] #align localized_module.lift' LocalizedModule.lift' theorem lift'_mk (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (m : M) (s : S) : LocalizedModule.lift' S g h (LocalizedModule.mk m s) = (h s).unit⁻¹.val (g m) := rfl #align localized_module.lift'_mk LocalizedModule.lift'_mk theorem lift'_add (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (x y) : LocalizedModule.lift' S g h (x + y) = LocalizedModule.lift' S g h x + LocalizedModule.lift' S g h y := LocalizedModule.induction_on₂ (by intro a a' b b' erw [LocalizedModule.lift'_mk, LocalizedModule.lift'_mk, LocalizedModule.lift'_mk] -- Porting note: We remove `generalize_proofs h1 h2 h3`. This only generalize `h1`. erw [map_add, Module.End_algebraMap_isUnit_inv_apply_eq_iff, smul_add, ← map_smul, ← map_smul, ← map_smul] congr 1 <;> symm · erw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, mul_smul, ← map_smul] rfl · dsimp erw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, mul_comm, mul_smul, ← map_smul] rfl) x y #align localized_module.lift'_add LocalizedModule.lift'_add theorem lift'_smul (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (r : R) (m) : r • LocalizedModule.lift' S g h m = LocalizedModule.lift' S g h (r • m) := m.induction_on fun a b => by rw [LocalizedModule.lift'_mk, LocalizedModule.smul'_mk, LocalizedModule.lift'_mk] -- Porting note: We remove `generalize_proofs h1 h2`. This does nothing here. rw [← map_smul, ← g.map_smul] #align localized_module.lift'_smul LocalizedModule.lift'_smul /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `LocalizedModule S M → M''`. -/ noncomputable def lift (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : LocalizedModule S M →ₗ[R] M'' where toFun := LocalizedModule.lift' S g h map_add' := LocalizedModule.lift'_add S g h map_smul' r x := by rw [LocalizedModule.lift'_smul, RingHom.id_apply] #align localized_module.lift LocalizedModule.lift /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then `lift g m s = s⁻¹ • g m`. -/ theorem lift_mk (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit (algebraMap R (Module.End R M'') x)) (m : M) (s : S) : LocalizedModule.lift S g h (LocalizedModule.mk m s) = (h s).unit⁻¹.val (g m) := rfl #align localized_module.lift_mk LocalizedModule.lift_mk /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `lift g ∘ mkLinearMap = g`. -/ theorem lift_comp (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : (lift S g h).comp (mkLinearMap S M) = g := by ext x; dsimp; rw [LocalizedModule.lift_mk] erw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, one_smul] #align localized_module.lift_comp LocalizedModule.lift_comp /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible and `l` is another linear map `LocalizedModule S M ⟶ M''` such that `l ∘ mkLinearMap = g` then `l = lift g` -/ theorem lift_unique (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (l : LocalizedModule S M →ₗ[R] M'') (hl : l.comp (LocalizedModule.mkLinearMap S M) = g) : LocalizedModule.lift S g h = l := by ext x; induction' x using LocalizedModule.induction_on with m s rw [LocalizedModule.lift_mk] rw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← hl, LinearMap.coe_comp, Function.comp_apply, LocalizedModule.mkLinearMap_apply, ← l.map_smul, LocalizedModule.smul'_mk] congr 1; rw [LocalizedModule.mk_eq] refine ⟨1, ?_⟩; simp only [one_smul, Submonoid.smul_def] #align localized_module.lift_unique LocalizedModule.lift_unique end LocalizedModule instance localizedModuleIsLocalizedModule : IsLocalizedModule S (LocalizedModule.mkLinearMap S M) where map_units s := ⟨⟨algebraMap R (Module.End R (LocalizedModule S M)) s, LocalizedModule.divBy s, DFunLike.ext _ _ <| LocalizedModule.mul_by_divBy s, DFunLike.ext _ _ <| LocalizedModule.divBy_mul_by s⟩, DFunLike.ext _ _ fun p => p.induction_on <| by intros rfl⟩ surj' p := p.induction_on fun m t => by refine ⟨⟨m, t⟩, ?_⟩ erw [LocalizedModule.smul'_mk, LocalizedModule.mkLinearMap_apply, Submonoid.coe_subtype, LocalizedModule.mk_cancel t] exists_of_eq eq1 := by simpa only [eq_comm, one_smul] using LocalizedModule.mk_eq.mp eq1 #align localized_module_is_localized_module localizedModuleIsLocalizedModule namespace IsLocalizedModule variable [IsLocalizedModule S f] /-- If `(M', f : M ⟶ M')` satisfies universal property of localized module, there is a canonical map `LocalizedModule S M ⟶ M'`. -/ noncomputable def fromLocalizedModule' : LocalizedModule S M → M' := fun p => p.liftOn (fun x => (IsLocalizedModule.map_units f x.2).unit⁻¹.val (f x.1)) (by rintro ⟨a, b⟩ ⟨a', b'⟩ ⟨c, eq1⟩ dsimp -- Porting note: We remove `generalize_proofs h1 h2`. rw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← map_smul, ← map_smul, Module.End_algebraMap_isUnit_inv_apply_eq_iff', ← map_smul] exact (IsLocalizedModule.eq_iff_exists S f).mpr ⟨c, eq1.symm⟩) #align is_localized_module.from_localized_module' IsLocalizedModule.fromLocalizedModule' @[simp] theorem fromLocalizedModule'_mk (m : M) (s : S) : fromLocalizedModule' S f (LocalizedModule.mk m s) = (IsLocalizedModule.map_units f s).unit⁻¹.val (f m) := rfl #align is_localized_module.from_localized_module'_mk IsLocalizedModule.fromLocalizedModule'_mk theorem fromLocalizedModule'_add (x y : LocalizedModule S M) : fromLocalizedModule' S f (x + y) = fromLocalizedModule' S f x + fromLocalizedModule' S f y := LocalizedModule.induction_on₂ (by intro a a' b b' simp only [LocalizedModule.mk_add_mk, fromLocalizedModule'_mk] -- Porting note: We remove `generalize_proofs h1 h2 h3`. rw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, smul_add, ← map_smul, ← map_smul, ← map_smul, map_add] congr 1 all_goals rw [Module.End_algebraMap_isUnit_inv_apply_eq_iff'] · simp [mul_smul, Submonoid.smul_def] · rw [Submonoid.coe_mul, LinearMap.map_smul_of_tower, mul_comm, mul_smul, Submonoid.smul_def]) x y #align is_localized_module.from_localized_module'_add IsLocalizedModule.fromLocalizedModule'_add theorem fromLocalizedModule'_smul (r : R) (x : LocalizedModule S M) : r • fromLocalizedModule' S f x = fromLocalizedModule' S f (r • x) := LocalizedModule.induction_on (by intro a b rw [fromLocalizedModule'_mk, LocalizedModule.smul'_mk, fromLocalizedModule'_mk] -- Porting note: We remove `generalize_proofs h1`. rw [f.map_smul, map_smul]) x #align is_localized_module.from_localized_module'_smul IsLocalizedModule.fromLocalizedModule'_smul /-- If `(M', f : M ⟶ M')` satisfies universal property of localized module, there is a canonical map `LocalizedModule S M ⟶ M'`. -/ noncomputable def fromLocalizedModule : LocalizedModule S M →ₗ[R] M' where toFun := fromLocalizedModule' S f map_add' := fromLocalizedModule'_add S f map_smul' r x := by rw [fromLocalizedModule'_smul, RingHom.id_apply] #align is_localized_module.from_localized_module IsLocalizedModule.fromLocalizedModule theorem fromLocalizedModule_mk (m : M) (s : S) : fromLocalizedModule S f (LocalizedModule.mk m s) = (IsLocalizedModule.map_units f s).unit⁻¹.val (f m) := rfl #align is_localized_module.from_localized_module_mk IsLocalizedModule.fromLocalizedModule_mk theorem fromLocalizedModule.inj : Function.Injective <| fromLocalizedModule S f := fun x y eq1 => by induction' x using LocalizedModule.induction_on with a b induction' y using LocalizedModule.induction_on with a' b' simp only [fromLocalizedModule_mk] at eq1 -- Porting note: We remove `generalize_proofs h1 h2`. rw [Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← LinearMap.map_smul, Module.End_algebraMap_isUnit_inv_apply_eq_iff'] at eq1 rw [LocalizedModule.mk_eq, ← IsLocalizedModule.eq_iff_exists S f, Submonoid.smul_def, Submonoid.smul_def, f.map_smul, f.map_smul, eq1] #align is_localized_module.from_localized_module.inj IsLocalizedModule.fromLocalizedModule.inj theorem fromLocalizedModule.surj : Function.Surjective <| fromLocalizedModule S f := fun x => let ⟨⟨m, s⟩, eq1⟩ := IsLocalizedModule.surj S f x ⟨LocalizedModule.mk m s, by rw [fromLocalizedModule_mk, Module.End_algebraMap_isUnit_inv_apply_eq_iff, ← eq1, Submonoid.smul_def]⟩ #align is_localized_module.from_localized_module.surj IsLocalizedModule.fromLocalizedModule.surj theorem fromLocalizedModule.bij : Function.Bijective <| fromLocalizedModule S f := ⟨fromLocalizedModule.inj _ _, fromLocalizedModule.surj _ _⟩ #align is_localized_module.from_localized_module.bij IsLocalizedModule.fromLocalizedModule.bij /-- If `(M', f : M ⟶ M')` satisfies universal property of localized module, then `M'` is isomorphic to `LocalizedModule S M` as an `R`-module. -/ @[simps!] noncomputable def iso : LocalizedModule S M ≃ₗ[R] M' := { fromLocalizedModule S f, Equiv.ofBijective (fromLocalizedModule S f) <| fromLocalizedModule.bij _ _ with } #align is_localized_module.iso IsLocalizedModule.iso theorem iso_apply_mk (m : M) (s : S) : iso S f (LocalizedModule.mk m s) = (IsLocalizedModule.map_units f s).unit⁻¹.val (f m) := rfl #align is_localized_module.iso_apply_mk IsLocalizedModule.iso_apply_mk theorem iso_symm_apply_aux (m : M') : (iso S f).symm m = LocalizedModule.mk (IsLocalizedModule.surj S f m).choose.1 (IsLocalizedModule.surj S f m).choose.2 := by -- Porting note: We remove `generalize_proofs _ h2`. apply_fun iso S f using LinearEquiv.injective (iso S f) rw [LinearEquiv.apply_symm_apply] simp only [iso_apply, LinearMap.toFun_eq_coe, fromLocalizedModule_mk] erw [Module.End_algebraMap_isUnit_inv_apply_eq_iff', (surj' _).choose_spec] #align is_localized_module.iso_symm_apply_aux IsLocalizedModule.iso_symm_apply_aux theorem iso_symm_apply' (m : M') (a : M) (b : S) (eq1 : b • m = f a) : (iso S f).symm m = LocalizedModule.mk a b := (iso_symm_apply_aux S f m).trans <| LocalizedModule.mk_eq.mpr <| by -- Porting note: We remove `generalize_proofs h1`. rw [← IsLocalizedModule.eq_iff_exists S f, Submonoid.smul_def, Submonoid.smul_def, f.map_smul, f.map_smul, ← (surj' _).choose_spec, ← Submonoid.smul_def, ← Submonoid.smul_def, ← mul_smul, mul_comm, mul_smul, eq1] #align is_localized_module.iso_symm_apply' IsLocalizedModule.iso_symm_apply' theorem iso_symm_comp : (iso S f).symm.toLinearMap.comp f = LocalizedModule.mkLinearMap S M := by ext m rw [LinearMap.comp_apply, LocalizedModule.mkLinearMap_apply, LinearEquiv.coe_coe, iso_symm_apply'] exact one_smul _ _ #align is_localized_module.iso_symm_comp IsLocalizedModule.iso_symm_comp /-- If `M'` is a localized module and `g` is a linear map `M' → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `M' → M''`. -/ noncomputable def lift (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : M' →ₗ[R] M'' := (LocalizedModule.lift S g h).comp (iso S f).symm.toLinearMap #align is_localized_module.lift IsLocalizedModule.lift theorem lift_comp (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : (lift S f g h).comp f = g := by dsimp only [IsLocalizedModule.lift] rw [LinearMap.comp_assoc, iso_symm_comp, LocalizedModule.lift_comp S g h] #align is_localized_module.lift_comp IsLocalizedModule.lift_comp @[simp] theorem lift_apply (g : M →ₗ[R] M'') (h) (x) : lift S f g h (f x) = g x := LinearMap.congr_fun (lift_comp S f g h) x theorem lift_unique (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (l : M' →ₗ[R] M'') (hl : l.comp f = g) : lift S f g h = l := by dsimp only [IsLocalizedModule.lift] rw [LocalizedModule.lift_unique S g h (l.comp (iso S f).toLinearMap), LinearMap.comp_assoc, LinearEquiv.comp_coe, LinearEquiv.symm_trans_self, LinearEquiv.refl_toLinearMap, LinearMap.comp_id] rw [LinearMap.comp_assoc, ← hl] congr 1 ext x rw [LinearMap.comp_apply, LocalizedModule.mkLinearMap_apply, LinearEquiv.coe_coe, iso_apply, fromLocalizedModule'_mk, Module.End_algebraMap_isUnit_inv_apply_eq_iff, OneMemClass.coe_one, one_smul] #align is_localized_module.lift_unique IsLocalizedModule.lift_unique /-- Universal property from localized module: If `(M', f : M ⟶ M')` is a localized module then it satisfies the following universal property: For every `R`-module `M''` which every `s : S`-scalar multiplication is invertible and for every `R`-linear map `g : M ⟶ M''`, there is a unique `R`-linear map `l : M' ⟶ M''` such that `l ∘ f = g`. ``` M -----f----> M' | / |g / | / l v / M'' ``` -/ theorem is_universal : ∀ (g : M →ₗ[R] M'') (_ : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)), ∃! l : M' →ₗ[R] M'', l.comp f = g := fun g h => ⟨lift S f g h, lift_comp S f g h, fun l hl => (lift_unique S f g h l hl).symm⟩ #align is_localized_module.is_universal IsLocalizedModule.is_universal theorem ringHom_ext (map_unit : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) ⦃j k : M' →ₗ[R] M''⦄ (h : j.comp f = k.comp f) : j = k := by rw [← lift_unique S f (k.comp f) map_unit j h, lift_unique] rfl #align is_localized_module.ring_hom_ext IsLocalizedModule.ringHom_ext /-- If `(M', f)` and `(M'', g)` both satisfy universal property of localized module, then `M', M''` are isomorphic as `R`-module -/ noncomputable def linearEquiv [IsLocalizedModule S g] : M' ≃ₗ[R] M'' := (iso S f).symm.trans (iso S g) #align is_localized_module.linear_equiv IsLocalizedModule.linearEquiv variable {S} theorem smul_injective (s : S) : Function.Injective fun m : M' => s • m := ((Module.End_isUnit_iff _).mp (IsLocalizedModule.map_units f s)).injective #align is_localized_module.smul_injective IsLocalizedModule.smul_injective theorem smul_inj (s : S) (m₁ m₂ : M') : s • m₁ = s • m₂ ↔ m₁ = m₂ := (smul_injective f s).eq_iff #align is_localized_module.smul_inj IsLocalizedModule.smul_inj /-- `mk' f m s` is the fraction `m/s` with respect to the localization map `f`. -/ noncomputable def mk' (m : M) (s : S) : M' := fromLocalizedModule S f (LocalizedModule.mk m s) #align is_localized_module.mk' IsLocalizedModule.mk'
Mathlib/Algebra/Module/LocalizedModule.lean
968
970
theorem mk'_smul (r : R) (m : M) (s : S) : mk' f (r • m) s = r • mk' f m s := by
delta mk' rw [← LocalizedModule.smul'_mk, LinearMap.map_smul]
/- Copyright (c) 2020 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Data.Stream.Init import Mathlib.Tactic.ApplyFun import Mathlib.Control.Fix import Mathlib.Order.OmegaCompletePartialOrder #align_import control.lawful_fix from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Lawful fixed point operators This module defines the laws required of a `Fix` instance, using the theory of omega complete partial orders (ωCPO). Proofs of the lawfulness of all `Fix` instances in `Control.Fix` are provided. ## Main definition * class `LawfulFix` -/ universe u v open scoped Classical variable {α : Type*} {β : α → Type*} open OmegaCompletePartialOrder /- Porting note: in `#align`s, mathport is putting some `fix`es where `Fix`es should be. -/ /-- Intuitively, a fixed point operator `fix` is lawful if it satisfies `fix f = f (fix f)` for all `f`, but this is inconsistent / uninteresting in most cases due to the existence of "exotic" functions `f`, such as the function that is defined iff its argument is not, familiar from the halting problem. Instead, this requirement is limited to only functions that are `Continuous` in the sense of `ω`-complete partial orders, which excludes the example because it is not monotone (making the input argument less defined can make `f` more defined). -/ class LawfulFix (α : Type*) [OmegaCompletePartialOrder α] extends Fix α where fix_eq : ∀ {f : α →o α}, Continuous f → Fix.fix f = f (Fix.fix f) #align lawful_fix LawfulFix theorem LawfulFix.fix_eq' {α} [OmegaCompletePartialOrder α] [LawfulFix α] {f : α → α} (hf : Continuous' f) : Fix.fix f = f (Fix.fix f) := LawfulFix.fix_eq (hf.to_bundled _) #align lawful_fix.fix_eq' LawfulFix.fix_eq' namespace Part open Part Nat Nat.Upto namespace Fix variable (f : ((a : _) → Part <| β a) →o (a : _) → Part <| β a) theorem approx_mono' {i : ℕ} : Fix.approx f i ≤ Fix.approx f (succ i) := by induction i with | zero => dsimp [approx]; apply @bot_le _ _ _ (f ⊥) | succ _ i_ih => intro; apply f.monotone; apply i_ih #align part.fix.approx_mono' Part.Fix.approx_mono' theorem approx_mono ⦃i j : ℕ⦄ (hij : i ≤ j) : approx f i ≤ approx f j := by induction' j with j ih · cases hij exact le_rfl cases hij; · exact le_rfl exact le_trans (ih ‹_›) (approx_mono' f) #align part.fix.approx_mono Part.Fix.approx_mono
Mathlib/Control/LawfulFix.lean
71
91
theorem mem_iff (a : α) (b : β a) : b ∈ Part.fix f a ↔ ∃ i, b ∈ approx f i a := by
by_cases h₀ : ∃ i : ℕ, (approx f i a).Dom · simp only [Part.fix_def f h₀] constructor <;> intro hh · exact ⟨_, hh⟩ have h₁ := Nat.find_spec h₀ rw [dom_iff_mem] at h₁ cases' h₁ with y h₁ replace h₁ := approx_mono' f _ _ h₁ suffices y = b by subst this exact h₁ cases' hh with i hh revert h₁; generalize succ (Nat.find h₀) = j; intro h₁ wlog case : i ≤ j · rcases le_total i j with H | H <;> [skip; symm] <;> apply_assumption <;> assumption replace hh := approx_mono f case _ _ hh apply Part.mem_unique h₁ hh · simp only [fix_def' (⇑f) h₀, not_exists, false_iff_iff, not_mem_none] simp only [dom_iff_mem, not_exists] at h₀ intro; apply h₀
/- 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]
Mathlib/Algebra/Polynomial/Eval.lean
685
686
theorem bit1_comp : comp (bit1 p : R[X]) q = bit1 (p.comp q) := by
simp only [bit1, add_comp, bit0_comp, one_comp]
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.DivergenceTheorem import Mathlib.Analysis.BoxIntegral.Integrability import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.MeasureTheory.Constructions.Prod.Integral import Mathlib.MeasureTheory.Integral.IntervalIntegral import Mathlib.Analysis.Calculus.FDeriv.Equiv #align_import measure_theory.integral.divergence_theorem from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Divergence theorem for Bochner integral In this file we prove the Divergence theorem for Bochner integral on a box in `ℝⁿ⁺¹ = Fin (n + 1) → ℝ`. More precisely, we prove the following theorem. Let `E` be a complete normed space. If `f : ℝⁿ⁺¹ → Eⁿ⁺¹` is continuous on a rectangular box `[a, b] : Set ℝⁿ⁺¹`, `a ≤ b`, differentiable on its interior with derivative `f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹`, and the divergence `fun x ↦ ∑ i, f' x eᵢ i` is integrable on `[a, b]`, where `eᵢ = Pi.single i 1` is the `i`-th basis vector, then its integral is equal to the sum of integrals of `f` over the faces of `[a, b]`, taken with appropriate signs. Moreover, the same is true if the function is not differentiable at countably many points of the interior of `[a, b]`. Once we prove the general theorem, we deduce corollaries for functions `ℝ → E` and pairs of functions `(ℝ × ℝ) → E`. ## Notations We use the following local notation to make the statement more readable. Note that the documentation website shows the actual terms, not those abbreviated using local notations. Porting note (Yury Kudryashov): I disabled some of these notations because I failed to make them work with Lean 4. * `ℝⁿ`, `ℝⁿ⁺¹`, `Eⁿ⁺¹`: `Fin n → ℝ`, `Fin (n + 1) → ℝ`, `Fin (n + 1) → E`; * `face i`: the `i`-th face of the box `[a, b]` as a closed segment in `ℝⁿ`, namely `[a ∘ Fin.succAbove i, b ∘ Fin.succAbove i]`; * `e i` : `i`-th basis vector `Pi.single i 1`; * `frontFace i`, `backFace i`: embeddings `ℝⁿ → ℝⁿ⁺¹` corresponding to the front face `{x | x i = b i}` and back face `{x | x i = a i}` of the box `[a, b]`, respectively. They are given by `Fin.insertNth i (b i)` and `Fin.insertNth i (a i)`. ## TODO * Add a version that assumes existence and integrability of partial derivatives. * Restore local notations for find another way to make the statements more readable. ## Tags divergence theorem, Bochner integral -/ open Set Finset TopologicalSpace Function BoxIntegral MeasureTheory Filter open scoped Classical Topology Interval universe u namespace MeasureTheory variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] section variable {n : ℕ} local macro:arg t:term:max noWs "ⁿ" : term => `(Fin n → $t) local macro:arg t:term:max noWs "ⁿ⁺¹" : term => `(Fin (n + 1) → $t) local notation "e " i => Pi.single i 1 section /-! ### Divergence theorem for functions on `ℝⁿ⁺¹ = Fin (n + 1) → ℝ`. In this section we use the divergence theorem for a Henstock-Kurzweil-like integral `BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt` to prove the divergence theorem for Bochner integral. The divergence theorem for Bochner integral `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable` assumes that the function itself is continuous on a closed box, differentiable at all but countably many points of its interior, and the divergence is integrable on the box. This statement differs from `BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt` in several aspects. * We use Bochner integral instead of a Henstock-Kurzweil integral. This modification is done in `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁`. As a side effect of this change, we need to assume that the divergence is integrable. * We don't assume differentiability on the boundary of the box. This modification is done in `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂`. To prove it, we choose an increasing sequence of smaller boxes that cover the interior of the original box, then apply the previous lemma to these smaller boxes and take the limit of both sides of the equation. * We assume `a ≤ b` instead of `∀ i, a i < b i`. This is the last step of the proof, and it is done in the main theorem `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`. -/ /-- An auxiliary lemma for `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`. This is exactly `BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt` reformulated for the Bochner integral. -/ theorem integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁ (I : Box (Fin (n + 1))) (f : ℝⁿ⁺¹ → Eⁿ⁺¹) (f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹) (s : Set ℝⁿ⁺¹) (hs : s.Countable) (Hc : ContinuousOn f (Box.Icc I)) (Hd : ∀ x ∈ (Box.Icc I) \ s, HasFDerivWithinAt f (f' x) (Box.Icc I) x) (Hi : IntegrableOn (fun x => ∑ i, f' x (e i) i) (Box.Icc I)) : (∫ x in Box.Icc I, ∑ i, f' x (e i) i) = ∑ i : Fin (n + 1), ((∫ x in Box.Icc (I.face i), f (i.insertNth (I.upper i) x) i) - ∫ x in Box.Icc (I.face i), f (i.insertNth (I.lower i) x) i) := by simp only [← setIntegral_congr_set_ae (Box.coe_ae_eq_Icc _)] have A := (Hi.mono_set Box.coe_subset_Icc).hasBoxIntegral ⊥ rfl have B := hasIntegral_GP_divergence_of_forall_hasDerivWithinAt I f f' (s ∩ Box.Icc I) (hs.mono inter_subset_left) (fun x hx => Hc _ hx.2) fun x hx => Hd _ ⟨hx.1, fun h => hx.2 ⟨h, hx.1⟩⟩ rw [continuousOn_pi] at Hc refine (A.unique B).trans (sum_congr rfl fun i _ => ?_) refine congr_arg₂ Sub.sub ?_ ?_ · have := Box.continuousOn_face_Icc (Hc i) (Set.right_mem_Icc.2 (I.lower_le_upper i)) have := (this.integrableOn_compact (μ := volume) (Box.isCompact_Icc _)).mono_set Box.coe_subset_Icc exact (this.hasBoxIntegral ⊥ rfl).integral_eq · have := Box.continuousOn_face_Icc (Hc i) (Set.left_mem_Icc.2 (I.lower_le_upper i)) have := (this.integrableOn_compact (μ := volume) (Box.isCompact_Icc _)).mono_set Box.coe_subset_Icc exact (this.hasBoxIntegral ⊥ rfl).integral_eq #align measure_theory.integral_divergence_of_has_fderiv_within_at_off_countable_aux₁ MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁ /-- An auxiliary lemma for `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`. Compared to the previous lemma, here we drop the assumption of differentiability on the boundary of the box. -/ theorem integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂ (I : Box (Fin (n + 1))) (f : ℝⁿ⁺¹ → Eⁿ⁺¹) (f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹) (s : Set ℝⁿ⁺¹) (hs : s.Countable) (Hc : ContinuousOn f (Box.Icc I)) (Hd : ∀ x ∈ Box.Ioo I \ s, HasFDerivAt f (f' x) x) (Hi : IntegrableOn (∑ i, f' · (e i) i) (Box.Icc I)) : (∫ x in Box.Icc I, ∑ i, f' x (e i) i) = ∑ i : Fin (n + 1), ((∫ x in Box.Icc (I.face i), f (i.insertNth (I.upper i) x) i) - ∫ x in Box.Icc (I.face i), f (i.insertNth (I.lower i) x) i) := by /- Choose a monotone sequence `J k` of subboxes that cover the interior of `I` and prove that these boxes satisfy the assumptions of the previous lemma. -/ rcases I.exists_seq_mono_tendsto with ⟨J, hJ_sub, hJl, hJu⟩ have hJ_sub' : ∀ k, Box.Icc (J k) ⊆ Box.Icc I := fun k => (hJ_sub k).trans I.Ioo_subset_Icc have hJ_le : ∀ k, J k ≤ I := fun k => Box.le_iff_Icc.2 (hJ_sub' k) have HcJ : ∀ k, ContinuousOn f (Box.Icc (J k)) := fun k => Hc.mono (hJ_sub' k) have HdJ : ∀ (k), ∀ x ∈ (Box.Icc (J k)) \ s, HasFDerivWithinAt f (f' x) (Box.Icc (J k)) x := fun k x hx => (Hd x ⟨hJ_sub k hx.1, hx.2⟩).hasFDerivWithinAt have HiJ : ∀ k, IntegrableOn (∑ i, f' · (e i) i) (Box.Icc (J k)) volume := fun k => Hi.mono_set (hJ_sub' k) -- Apply the previous lemma to `J k`. have HJ_eq := fun k => integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁ (J k) f f' s hs (HcJ k) (HdJ k) (HiJ k) -- Note that the LHS of `HJ_eq k` tends to the LHS of the goal as `k → ∞`. have hI_tendsto : Tendsto (fun k => ∫ x in Box.Icc (J k), ∑ i, f' x (e i) i) atTop (𝓝 (∫ x in Box.Icc I, ∑ i, f' x (e i) i)) := by simp only [IntegrableOn, ← Measure.restrict_congr_set (Box.Ioo_ae_eq_Icc _)] at Hi ⊢ rw [← Box.iUnion_Ioo_of_tendsto J.monotone hJl hJu] at Hi ⊢ exact tendsto_setIntegral_of_monotone (fun k => (J k).measurableSet_Ioo) (Box.Ioo.comp J).monotone Hi -- Thus it suffices to prove the same about the RHS. refine tendsto_nhds_unique_of_eventuallyEq hI_tendsto ?_ (eventually_of_forall HJ_eq) clear hI_tendsto rw [tendsto_pi_nhds] at hJl hJu /- We'll need to prove a similar statement about the integrals over the front sides and the integrals over the back sides. In order to avoid repeating ourselves, we formulate a lemma. -/ suffices ∀ (i : Fin (n + 1)) (c : ℕ → ℝ) (d), (∀ k, c k ∈ Icc (I.lower i) (I.upper i)) → Tendsto c atTop (𝓝 d) → Tendsto (fun k => ∫ x in Box.Icc ((J k).face i), f (i.insertNth (c k) x) i) atTop (𝓝 <| ∫ x in Box.Icc (I.face i), f (i.insertNth d x) i) by rw [Box.Icc_eq_pi] at hJ_sub' refine tendsto_finset_sum _ fun i _ => (this _ _ _ ?_ (hJu _)).sub (this _ _ _ ?_ (hJl _)) exacts [fun k => hJ_sub' k (J k).upper_mem_Icc _ trivial, fun k => hJ_sub' k (J k).lower_mem_Icc _ trivial] intro i c d hc hcd /- First we prove that the integrals of the restriction of `f` to `{x | x i = d}` over increasing boxes `((J k).face i).Icc` tend to the desired limit. The proof mostly repeats the one above. -/ have hd : d ∈ Icc (I.lower i) (I.upper i) := isClosed_Icc.mem_of_tendsto hcd (eventually_of_forall hc) have Hic : ∀ k, IntegrableOn (fun x => f (i.insertNth (c k) x) i) (Box.Icc (I.face i)) := fun k => (Box.continuousOn_face_Icc ((continuous_apply i).comp_continuousOn Hc) (hc k)).integrableOn_Icc have Hid : IntegrableOn (fun x => f (i.insertNth d x) i) (Box.Icc (I.face i)) := (Box.continuousOn_face_Icc ((continuous_apply i).comp_continuousOn Hc) hd).integrableOn_Icc have H : Tendsto (fun k => ∫ x in Box.Icc ((J k).face i), f (i.insertNth d x) i) atTop (𝓝 <| ∫ x in Box.Icc (I.face i), f (i.insertNth d x) i) := by have hIoo : (⋃ k, Box.Ioo ((J k).face i)) = Box.Ioo (I.face i) := Box.iUnion_Ioo_of_tendsto ((Box.monotone_face i).comp J.monotone) (tendsto_pi_nhds.2 fun _ => hJl _) (tendsto_pi_nhds.2 fun _ => hJu _) simp only [IntegrableOn, ← Measure.restrict_congr_set (Box.Ioo_ae_eq_Icc _), ← hIoo] at Hid ⊢ exact tendsto_setIntegral_of_monotone (fun k => ((J k).face i).measurableSet_Ioo) (Box.Ioo.monotone.comp ((Box.monotone_face i).comp J.monotone)) Hid /- Thus it suffices to show that the distance between the integrals of the restrictions of `f` to `{x | x i = c k}` and `{x | x i = d}` over `((J k).face i).Icc` tends to zero as `k → ∞`. Choose `ε > 0`. -/ refine H.congr_dist (Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε εpos => ?_) have hvol_pos : ∀ J : Box (Fin n), 0 < ∏ j, (J.upper j - J.lower j) := fun J => prod_pos fun j hj => sub_pos.2 <| J.lower_lt_upper _ /- Choose `δ > 0` such that for any `x y ∈ I.Icc` at distance at most `δ`, the distance between `f x` and `f y` is at most `ε / volume (I.face i).Icc`, then the distance between the integrals is at most `(ε / volume (I.face i).Icc) * volume ((J k).face i).Icc ≤ ε`. -/ rcases Metric.uniformContinuousOn_iff_le.1 (I.isCompact_Icc.uniformContinuousOn_of_continuous Hc) (ε / ∏ j, ((I.face i).upper j - (I.face i).lower j)) (div_pos εpos (hvol_pos (I.face i))) with ⟨δ, δpos, hδ⟩ refine (hcd.eventually (Metric.ball_mem_nhds _ δpos)).mono fun k hk => ?_ have Hsub : Box.Icc ((J k).face i) ⊆ Box.Icc (I.face i) := Box.le_iff_Icc.1 (Box.face_mono (hJ_le _) i) rw [mem_closedBall_zero_iff, Real.norm_eq_abs, abs_of_nonneg dist_nonneg, dist_eq_norm, ← integral_sub (Hid.mono_set Hsub) ((Hic _).mono_set Hsub)] calc ‖∫ x in Box.Icc ((J k).face i), f (i.insertNth d x) i - f (i.insertNth (c k) x) i‖ ≤ (ε / ∏ j, ((I.face i).upper j - (I.face i).lower j)) * (volume (Box.Icc ((J k).face i))).toReal := by refine norm_setIntegral_le_of_norm_le_const' (((J k).face i).measure_Icc_lt_top _) ((J k).face i).measurableSet_Icc fun x hx => ?_ rw [← dist_eq_norm] calc dist (f (i.insertNth d x) i) (f (i.insertNth (c k) x) i) ≤ dist (f (i.insertNth d x)) (f (i.insertNth (c k) x)) := dist_le_pi_dist (f (i.insertNth d x)) (f (i.insertNth (c k) x)) i _ ≤ ε / ∏ j, ((I.face i).upper j - (I.face i).lower j) := hδ _ (I.mapsTo_insertNth_face_Icc hd <| Hsub hx) _ (I.mapsTo_insertNth_face_Icc (hc _) <| Hsub hx) ?_ rw [Fin.dist_insertNth_insertNth, dist_self, dist_comm] exact max_le hk.le δpos.lt.le _ ≤ ε := by rw [Box.Icc_def, Real.volume_Icc_pi_toReal ((J k).face i).lower_le_upper, ← le_div_iff (hvol_pos _)] gcongr exacts [hvol_pos _, fun _ _ ↦ sub_nonneg.2 (Box.lower_le_upper _ _), (hJ_sub' _ (J _).upper_mem_Icc).2 _, (hJ_sub' _ (J _).lower_mem_Icc).1 _] #align measure_theory.integral_divergence_of_has_fderiv_within_at_off_countable_aux₂ MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂ variable (a b : Fin (n + 1) → ℝ) local notation "face " i => Set.Icc (a ∘ Fin.succAbove i) (b ∘ Fin.succAbove i) local notation:max "frontFace " i:arg => Fin.insertNth i (b i) local notation:max "backFace " i:arg => Fin.insertNth i (a i) /-- **Divergence theorem** for Bochner integral. If `f : ℝⁿ⁺¹ → Eⁿ⁺¹` is continuous on a rectangular box `[a, b] : Set ℝⁿ⁺¹`, `a ≤ b`, is differentiable on its interior with derivative `f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹` and the divergence `fun x ↦ ∑ i, f' x eᵢ i` is integrable on `[a, b]`, where `eᵢ = Pi.single i 1` is the `i`-th basis vector, then its integral is equal to the sum of integrals of `f` over the faces of `[a, b]`, taken with appropriate signs. Moreover, the same is true if the function is not differentiable at countably many points of the interior of `[a, b]`. We represent both faces `x i = a i` and `x i = b i` as the box `face i = [a ∘ Fin.succAbove i, b ∘ Fin.succAbove i]` in `ℝⁿ`, where `Fin.succAbove : Fin n ↪o Fin (n + 1)` is the order embedding with range `{i}ᶜ`. The restrictions of `f : ℝⁿ⁺¹ → Eⁿ⁺¹` to these faces are given by `f ∘ backFace i` and `f ∘ frontFace i`, where `backFace i = Fin.insertNth i (a i)` and `frontFace i = Fin.insertNth i (b i)` are embeddings `ℝⁿ → ℝⁿ⁺¹` that take `y : ℝⁿ` and insert `a i` (resp., `b i`) as `i`-th coordinate. -/ theorem integral_divergence_of_hasFDerivWithinAt_off_countable (hle : a ≤ b) (f : ℝⁿ⁺¹ → Eⁿ⁺¹) (f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹) (s : Set ℝⁿ⁺¹) (hs : s.Countable) (Hc : ContinuousOn f (Icc a b)) (Hd : ∀ x ∈ (Set.pi univ fun i => Ioo (a i) (b i)) \ s, HasFDerivAt f (f' x) x) (Hi : IntegrableOn (fun x => ∑ i, f' x (e i) i) (Icc a b)) : (∫ x in Icc a b, ∑ i, f' x (e i) i) = ∑ i : Fin (n + 1), ((∫ x in face i, f (frontFace i x) i) - ∫ x in face i, f (backFace i x) i) := by rcases em (∃ i, a i = b i) with (⟨i, hi⟩ | hne) · -- First we sort out the trivial case `∃ i, a i = b i`. rw [volume_pi, ← setIntegral_congr_set_ae Measure.univ_pi_Ioc_ae_eq_Icc] have hi' : Ioc (a i) (b i) = ∅ := Ioc_eq_empty hi.not_lt have : (pi Set.univ fun j => Ioc (a j) (b j)) = ∅ := univ_pi_eq_empty hi' rw [this, integral_empty, sum_eq_zero] rintro j - rcases eq_or_ne i j with (rfl | hne) · simp [hi] · rcases Fin.exists_succAbove_eq hne with ⟨i, rfl⟩ have : Icc (a ∘ j.succAbove) (b ∘ j.succAbove) =ᵐ[volume] (∅ : Set ℝⁿ) := by rw [ae_eq_empty, Real.volume_Icc_pi, prod_eq_zero (Finset.mem_univ i)] simp [hi] rw [setIntegral_congr_set_ae this, setIntegral_congr_set_ae this, integral_empty, integral_empty, sub_self] · -- In the non-trivial case `∀ i, a i < b i`, we apply a lemma we proved above. have hlt : ∀ i, a i < b i := fun i => (hle i).lt_of_ne fun hi => hne ⟨i, hi⟩ exact integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂ ⟨a, b, hlt⟩ f f' s hs Hc Hd Hi #align measure_theory.integral_divergence_of_has_fderiv_within_at_off_countable MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable /-- **Divergence theorem** for a family of functions `f : Fin (n + 1) → ℝⁿ⁺¹ → E`. See also `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable'` for a version formulated in terms of a vector-valued function `f : ℝⁿ⁺¹ → Eⁿ⁺¹`. -/ theorem integral_divergence_of_hasFDerivWithinAt_off_countable' (hle : a ≤ b) (f : Fin (n + 1) → ℝⁿ⁺¹ → E) (f' : Fin (n + 1) → ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] E) (s : Set ℝⁿ⁺¹) (hs : s.Countable) (Hc : ∀ i, ContinuousOn (f i) (Icc a b)) (Hd : ∀ x ∈ (pi Set.univ fun i => Ioo (a i) (b i)) \ s, ∀ (i), HasFDerivAt (f i) (f' i x) x) (Hi : IntegrableOn (fun x => ∑ i, f' i x (e i)) (Icc a b)) : (∫ x in Icc a b, ∑ i, f' i x (e i)) = ∑ i : Fin (n + 1), ((∫ x in face i, f i (frontFace i x)) - ∫ x in face i, f i (backFace i x)) := integral_divergence_of_hasFDerivWithinAt_off_countable a b hle (fun x i => f i x) (fun x => ContinuousLinearMap.pi fun i => f' i x) s hs (continuousOn_pi.2 Hc) (fun x hx => hasFDerivAt_pi.2 (Hd x hx)) Hi #align measure_theory.integral_divergence_of_has_fderiv_within_at_off_countable' MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable' end /-- An auxiliary lemma that is used to specialize the general divergence theorem to spaces that do not have the form `Fin n → ℝ`. -/
Mathlib/MeasureTheory/Integral/DivergenceTheorem.lean
320
359
theorem integral_divergence_of_hasFDerivWithinAt_off_countable_of_equiv {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [PartialOrder F] [MeasureSpace F] [BorelSpace F] (eL : F ≃L[ℝ] ℝⁿ⁺¹) (he_ord : ∀ x y, eL x ≤ eL y ↔ x ≤ y) (he_vol : MeasurePreserving eL volume volume) (f : Fin (n + 1) → F → E) (f' : Fin (n + 1) → F → F →L[ℝ] E) (s : Set F) (hs : s.Countable) (a b : F) (hle : a ≤ b) (Hc : ∀ i, ContinuousOn (f i) (Icc a b)) (Hd : ∀ x ∈ interior (Icc a b) \ s, ∀ (i), HasFDerivAt (f i) (f' i x) x) (DF : F → E) (hDF : ∀ x, DF x = ∑ i, f' i x (eL.symm <| e i)) (Hi : IntegrableOn DF (Icc a b)) : ∫ x in Icc a b, DF x = ∑ i : Fin (n + 1), ((∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove), f i (eL.symm <| i.insertNth (eL b i) x)) - ∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove), f i (eL.symm <| i.insertNth (eL a i) x)) := have he_emb : MeasurableEmbedding eL := eL.toHomeomorph.measurableEmbedding have hIcc : eL ⁻¹' Icc (eL a) (eL b) = Icc a b := by
ext1 x; simp only [Set.mem_preimage, Set.mem_Icc, he_ord] have hIcc' : Icc (eL a) (eL b) = eL.symm ⁻¹' Icc a b := by rw [← hIcc, eL.symm_preimage_preimage] calc ∫ x in Icc a b, DF x = ∫ x in Icc a b, ∑ i, f' i x (eL.symm <| e i) := by simp only [hDF] _ = ∫ x in Icc (eL a) (eL b), ∑ i, f' i (eL.symm x) (eL.symm <| e i) := by rw [← he_vol.setIntegral_preimage_emb he_emb] simp only [hIcc, eL.symm_apply_apply] _ = ∑ i : Fin (n + 1), ((∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove), f i (eL.symm <| i.insertNth (eL b i) x)) - ∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove), f i (eL.symm <| i.insertNth (eL a i) x)) := by refine integral_divergence_of_hasFDerivWithinAt_off_countable' (eL a) (eL b) ((he_ord _ _).2 hle) (fun i x => f i (eL.symm x)) (fun i x => f' i (eL.symm x) ∘L (eL.symm : ℝⁿ⁺¹ →L[ℝ] F)) (eL.symm ⁻¹' s) (hs.preimage eL.symm.injective) ?_ ?_ ?_ · exact fun i => (Hc i).comp eL.symm.continuousOn hIcc'.subset · refine fun x hx i => (Hd (eL.symm x) ⟨?_, hx.2⟩ i).comp x eL.symm.hasFDerivAt rw [← hIcc] refine preimage_interior_subset_interior_preimage eL.continuous ?_ simpa only [Set.mem_preimage, eL.apply_symm_apply, ← pi_univ_Icc, interior_pi_set (@finite_univ (Fin _) _), interior_Icc] using hx.1 · rw [← he_vol.integrableOn_comp_preimage he_emb, hIcc] simp [← hDF, (· ∘ ·), Hi]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Data.Complex.Abs import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Nat.Choose.Sum #align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Exponential, trigonometric and hyperbolic trigonometric functions This file contains the definitions of the real and complex exponential, sine, cosine, tangent, hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions. -/ open CauSeq Finset IsAbsoluteValue open scoped Classical ComplexConjugate namespace Complex theorem isCauSeq_abs_exp (z : ℂ) : IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) := let ⟨n, hn⟩ := exists_nat_gt (abs z) have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff hn0, one_mul]) fun m hm => by rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast] gcongr exact le_trans hm (Nat.le_succ _) #align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_abs_exp z).of_abv #align complex.is_cau_exp Complex.isCauSeq_exp /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ -- Porting note (#11180): removed `@[pp_nodot]` def exp' (z : ℂ) : CauSeq ℂ Complex.abs := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ #align complex.exp' Complex.exp' /-- The complex exponential function, defined via its Taylor series -/ -- Porting note (#11180): removed `@[pp_nodot]` -- Porting note: removed `irreducible` attribute, so I can prove things def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) #align complex.exp Complex.exp /-- The complex sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / 2 #align complex.sin Complex.sin /-- The complex cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 #align complex.cos Complex.cos /-- The complex tangent function, defined as `sin z / cos z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tan (z : ℂ) : ℂ := sin z / cos z #align complex.tan Complex.tan /-- The complex cotangent function, defined as `cos z / sin z` -/ def cot (z : ℂ) : ℂ := cos z / sin z /-- The complex hyperbolic sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 #align complex.sinh Complex.sinh /-- The complex hyperbolic cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 #align complex.cosh Complex.cosh /-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tanh (z : ℂ) : ℂ := sinh z / cosh z #align complex.tanh Complex.tanh /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def exp (x : ℝ) : ℝ := (exp x).re #align real.exp Real.exp /-- The real sine function, defined as the real part of the complex sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sin (x : ℝ) : ℝ := (sin x).re #align real.sin Real.sin /-- The real cosine function, defined as the real part of the complex cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cos (x : ℝ) : ℝ := (cos x).re #align real.cos Real.cos /-- The real tangent function, defined as the real part of the complex tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tan (x : ℝ) : ℝ := (tan x).re #align real.tan Real.tan /-- The real cotangent function, defined as the real part of the complex cotangent -/ nonrec def cot (x : ℝ) : ℝ := (cot x).re /-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sinh (x : ℝ) : ℝ := (sinh x).re #align real.sinh Real.sinh /-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cosh (x : ℝ) : ℝ := (cosh x).re #align real.cosh Real.cosh /-- The real hypebolic tangent function, defined as the real part of the complex hyperbolic tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tanh (x : ℝ) : ℝ := (tanh x).re #align real.tanh Real.tanh /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε cases' j with j j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp #align complex.exp_zero Complex.exp_zero theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y) #align complex.exp_add Complex.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp (Multiplicative.toAdd z), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l #align complex.exp_list_sum Complex.exp_list_sum theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s #align complex.exp_multiset_sum Complex.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s #align complex.exp_sum Complex.exp_sum lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] #align complex.exp_nat_mul Complex.exp_nat_mul theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp #align complex.exp_ne_zero Complex.exp_ne_zero theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)] #align complex.exp_neg Complex.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align complex.exp_sub Complex.exp_sub theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] #align complex.exp_int_mul Complex.exp_int_mul @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] #align complex.exp_conj Complex.exp_conj @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] #align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ #align complex.of_real_exp Complex.ofReal_exp @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] #align complex.exp_of_real_im Complex.exp_ofReal_im theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl #align complex.exp_of_real_re Complex.exp_ofReal_re theorem two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_sinh Complex.two_sinh theorem two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cosh Complex.two_cosh @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align complex.sinh_zero Complex.sinh_zero @[simp]
Mathlib/Data/Complex/Exponential.lean
294
294
theorem sinh_neg : sinh (-x) = -sinh x := by
simp [sinh, exp_neg, (neg_div _ _).symm, add_mul]
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Splits #align_import algebra.cubic_discriminant from "leanprover-community/mathlib"@"930133160e24036d5242039fe4972407cd4f1222" /-! # Cubics and discriminants This file defines cubic polynomials over a semiring and their discriminants over a splitting field. ## Main definitions * `Cubic`: the structure representing a cubic polynomial. * `Cubic.disc`: the discriminant of a cubic polynomial. ## Main statements * `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if the cubic has no duplicate roots. ## References * https://en.wikipedia.org/wiki/Cubic_equation * https://en.wikipedia.org/wiki/Discriminant ## Tags cubic, discriminant, polynomial, root -/ noncomputable section /-- The structure representing a cubic polynomial. -/ @[ext] structure Cubic (R : Type*) where (a b c d : R) #align cubic Cubic namespace Cubic open Cubic Polynomial open Polynomial variable {R S F K : Type*} instance [Inhabited R] : Inhabited (Cubic R) := ⟨⟨default, default, default, default⟩⟩ instance [Zero R] : Zero (Cubic R) := ⟨⟨0, 0, 0, 0⟩⟩ section Basic variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R] /-- Convert a cubic polynomial to a polynomial. -/ def toPoly (P : Cubic R) : R[X] := C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d #align cubic.to_poly Cubic.toPoly theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} : C w * (X - C x) * (X - C y) * (X - C z) = toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by simp only [toPoly, C_neg, C_add, C_mul] ring1 set_option linter.uppercaseLean3 false in #align cubic.C_mul_prod_X_sub_C_eq Cubic.C_mul_prod_X_sub_C_eq theorem prod_X_sub_C_eq [CommRing S] {x y z : S} : (X - C x) * (X - C y) * (X - C z) = toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul] set_option linter.uppercaseLean3 false in #align cubic.prod_X_sub_C_eq Cubic.prod_X_sub_C_eq /-! ### Coefficients -/ section Coeff private theorem coeffs : (∀ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧ P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow] set_option tactic.skipAssignedInstances false in norm_num intro n hn repeat' rw [if_neg] any_goals linarith only [hn] repeat' rw [zero_add] @[simp] theorem coeff_eq_zero {n : ℕ} (hn : 3 < n) : P.toPoly.coeff n = 0 := coeffs.1 n hn #align cubic.coeff_eq_zero Cubic.coeff_eq_zero @[simp] theorem coeff_eq_a : P.toPoly.coeff 3 = P.a := coeffs.2.1 #align cubic.coeff_eq_a Cubic.coeff_eq_a @[simp] theorem coeff_eq_b : P.toPoly.coeff 2 = P.b := coeffs.2.2.1 #align cubic.coeff_eq_b Cubic.coeff_eq_b @[simp] theorem coeff_eq_c : P.toPoly.coeff 1 = P.c := coeffs.2.2.2.1 #align cubic.coeff_eq_c Cubic.coeff_eq_c @[simp] theorem coeff_eq_d : P.toPoly.coeff 0 = P.d := coeffs.2.2.2.2 #align cubic.coeff_eq_d Cubic.coeff_eq_d theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a] #align cubic.a_of_eq Cubic.a_of_eq theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b] #align cubic.b_of_eq Cubic.b_of_eq theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c] #align cubic.c_of_eq Cubic.c_of_eq theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d] #align cubic.d_of_eq Cubic.d_of_eq theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q := ⟨fun h ↦ Cubic.ext P Q (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩ #align cubic.to_poly_injective Cubic.toPoly_injective theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by rw [toPoly, ha, C_0, zero_mul, zero_add] #align cubic.of_a_eq_zero Cubic.of_a_eq_zero theorem of_a_eq_zero' : toPoly ⟨0, b, c, d⟩ = C b * X ^ 2 + C c * X + C d := of_a_eq_zero rfl #align cubic.of_a_eq_zero' Cubic.of_a_eq_zero' theorem of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly = C P.c * X + C P.d := by rw [of_a_eq_zero ha, hb, C_0, zero_mul, zero_add] #align cubic.of_b_eq_zero Cubic.of_b_eq_zero theorem of_b_eq_zero' : toPoly ⟨0, 0, c, d⟩ = C c * X + C d := of_b_eq_zero rfl rfl #align cubic.of_b_eq_zero' Cubic.of_b_eq_zero' theorem of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly = C P.d := by rw [of_b_eq_zero ha hb, hc, C_0, zero_mul, zero_add] #align cubic.of_c_eq_zero Cubic.of_c_eq_zero theorem of_c_eq_zero' : toPoly ⟨0, 0, 0, d⟩ = C d := of_c_eq_zero rfl rfl rfl #align cubic.of_c_eq_zero' Cubic.of_c_eq_zero' theorem of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) : P.toPoly = 0 := by rw [of_c_eq_zero ha hb hc, hd, C_0] #align cubic.of_d_eq_zero Cubic.of_d_eq_zero theorem of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly = 0 := of_d_eq_zero rfl rfl rfl rfl #align cubic.of_d_eq_zero' Cubic.of_d_eq_zero' theorem zero : (0 : Cubic R).toPoly = 0 := of_d_eq_zero' #align cubic.zero Cubic.zero theorem toPoly_eq_zero_iff (P : Cubic R) : P.toPoly = 0 ↔ P = 0 := by rw [← zero, toPoly_injective] #align cubic.to_poly_eq_zero_iff Cubic.toPoly_eq_zero_iff private theorem ne_zero (h0 : P.a ≠ 0 ∨ P.b ≠ 0 ∨ P.c ≠ 0 ∨ P.d ≠ 0) : P.toPoly ≠ 0 := by contrapose! h0 rw [(toPoly_eq_zero_iff P).mp h0] exact ⟨rfl, rfl, rfl, rfl⟩ theorem ne_zero_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly ≠ 0 := (or_imp.mp ne_zero).1 ha #align cubic.ne_zero_of_a_ne_zero Cubic.ne_zero_of_a_ne_zero theorem ne_zero_of_b_ne_zero (hb : P.b ≠ 0) : P.toPoly ≠ 0 := (or_imp.mp (or_imp.mp ne_zero).2).1 hb #align cubic.ne_zero_of_b_ne_zero Cubic.ne_zero_of_b_ne_zero theorem ne_zero_of_c_ne_zero (hc : P.c ≠ 0) : P.toPoly ≠ 0 := (or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).1 hc #align cubic.ne_zero_of_c_ne_zero Cubic.ne_zero_of_c_ne_zero theorem ne_zero_of_d_ne_zero (hd : P.d ≠ 0) : P.toPoly ≠ 0 := (or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).2 hd #align cubic.ne_zero_of_d_ne_zero Cubic.ne_zero_of_d_ne_zero @[simp] theorem leadingCoeff_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.leadingCoeff = P.a := leadingCoeff_cubic ha #align cubic.leading_coeff_of_a_ne_zero Cubic.leadingCoeff_of_a_ne_zero @[simp] theorem leadingCoeff_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).leadingCoeff = a := leadingCoeff_of_a_ne_zero ha #align cubic.leading_coeff_of_a_ne_zero' Cubic.leadingCoeff_of_a_ne_zero' @[simp] theorem leadingCoeff_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.leadingCoeff = P.b := by rw [of_a_eq_zero ha, leadingCoeff_quadratic hb] #align cubic.leading_coeff_of_b_ne_zero Cubic.leadingCoeff_of_b_ne_zero @[simp] theorem leadingCoeff_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).leadingCoeff = b := leadingCoeff_of_b_ne_zero rfl hb #align cubic.leading_coeff_of_b_ne_zero' Cubic.leadingCoeff_of_b_ne_zero' @[simp] theorem leadingCoeff_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) : P.toPoly.leadingCoeff = P.c := by rw [of_b_eq_zero ha hb, leadingCoeff_linear hc] #align cubic.leading_coeff_of_c_ne_zero Cubic.leadingCoeff_of_c_ne_zero @[simp] theorem leadingCoeff_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).leadingCoeff = c := leadingCoeff_of_c_ne_zero rfl rfl hc #align cubic.leading_coeff_of_c_ne_zero' Cubic.leadingCoeff_of_c_ne_zero' @[simp] theorem leadingCoeff_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.leadingCoeff = P.d := by rw [of_c_eq_zero ha hb hc, leadingCoeff_C] #align cubic.leading_coeff_of_c_eq_zero Cubic.leadingCoeff_of_c_eq_zero -- @[simp] -- porting note (#10618): simp can prove this theorem leadingCoeff_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).leadingCoeff = d := leadingCoeff_of_c_eq_zero rfl rfl rfl #align cubic.leading_coeff_of_c_eq_zero' Cubic.leadingCoeff_of_c_eq_zero' theorem monic_of_a_eq_one (ha : P.a = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_a_ne_zero (ha ▸ one_ne_zero), ha] #align cubic.monic_of_a_eq_one Cubic.monic_of_a_eq_one theorem monic_of_a_eq_one' : (toPoly ⟨1, b, c, d⟩).Monic := monic_of_a_eq_one rfl #align cubic.monic_of_a_eq_one' Cubic.monic_of_a_eq_one' theorem monic_of_b_eq_one (ha : P.a = 0) (hb : P.b = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_b_ne_zero ha (hb ▸ one_ne_zero), hb] #align cubic.monic_of_b_eq_one Cubic.monic_of_b_eq_one theorem monic_of_b_eq_one' : (toPoly ⟨0, 1, c, d⟩).Monic := monic_of_b_eq_one rfl rfl #align cubic.monic_of_b_eq_one' Cubic.monic_of_b_eq_one' theorem monic_of_c_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_c_ne_zero ha hb (hc ▸ one_ne_zero), hc] #align cubic.monic_of_c_eq_one Cubic.monic_of_c_eq_one theorem monic_of_c_eq_one' : (toPoly ⟨0, 0, 1, d⟩).Monic := monic_of_c_eq_one rfl rfl rfl #align cubic.monic_of_c_eq_one' Cubic.monic_of_c_eq_one' theorem monic_of_d_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 1) : P.toPoly.Monic := by rw [Monic, leadingCoeff_of_c_eq_zero ha hb hc, hd] #align cubic.monic_of_d_eq_one Cubic.monic_of_d_eq_one theorem monic_of_d_eq_one' : (toPoly ⟨0, 0, 0, 1⟩).Monic := monic_of_d_eq_one rfl rfl rfl rfl #align cubic.monic_of_d_eq_one' Cubic.monic_of_d_eq_one' end Coeff /-! ### Degrees -/ section Degree /-- The equivalence between cubic polynomials and polynomials of degree at most three. -/ @[simps] def equiv : Cubic R ≃ { p : R[X] // p.degree ≤ 3 } where toFun P := ⟨P.toPoly, degree_cubic_le⟩ invFun f := ⟨coeff f 3, coeff f 2, coeff f 1, coeff f 0⟩ left_inv P := by ext <;> simp only [Subtype.coe_mk, coeffs] right_inv f := by -- Porting note: Added `simp only [Nat.zero_eq, Nat.succ_eq_add_one] <;> ring_nf` -- There's probably a better way to do this. ext (_ | _ | _ | _ | n) <;> simp only [Nat.zero_eq, Nat.succ_eq_add_one] <;> ring_nf <;> try simp only [coeffs] have h3 : 3 < 4 + n := by linarith only rw [coeff_eq_zero h3, (degree_le_iff_coeff_zero (f : R[X]) 3).mp f.2 _ <| WithBot.coe_lt_coe.mpr (by exact h3)] #align cubic.equiv Cubic.equiv @[simp] theorem degree_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.degree = 3 := degree_cubic ha #align cubic.degree_of_a_ne_zero Cubic.degree_of_a_ne_zero @[simp] theorem degree_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).degree = 3 := degree_of_a_ne_zero ha #align cubic.degree_of_a_ne_zero' Cubic.degree_of_a_ne_zero' theorem degree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.degree ≤ 2 := by simpa only [of_a_eq_zero ha] using degree_quadratic_le #align cubic.degree_of_a_eq_zero Cubic.degree_of_a_eq_zero theorem degree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).degree ≤ 2 := degree_of_a_eq_zero rfl #align cubic.degree_of_a_eq_zero' Cubic.degree_of_a_eq_zero' @[simp] theorem degree_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.degree = 2 := by rw [of_a_eq_zero ha, degree_quadratic hb] #align cubic.degree_of_b_ne_zero Cubic.degree_of_b_ne_zero @[simp] theorem degree_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).degree = 2 := degree_of_b_ne_zero rfl hb #align cubic.degree_of_b_ne_zero' Cubic.degree_of_b_ne_zero' theorem degree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.degree ≤ 1 := by simpa only [of_b_eq_zero ha hb] using degree_linear_le #align cubic.degree_of_b_eq_zero Cubic.degree_of_b_eq_zero theorem degree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).degree ≤ 1 := degree_of_b_eq_zero rfl rfl #align cubic.degree_of_b_eq_zero' Cubic.degree_of_b_eq_zero' @[simp] theorem degree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) : P.toPoly.degree = 1 := by rw [of_b_eq_zero ha hb, degree_linear hc] #align cubic.degree_of_c_ne_zero Cubic.degree_of_c_ne_zero @[simp] theorem degree_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).degree = 1 := degree_of_c_ne_zero rfl rfl hc #align cubic.degree_of_c_ne_zero' Cubic.degree_of_c_ne_zero' theorem degree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.degree ≤ 0 := by simpa only [of_c_eq_zero ha hb hc] using degree_C_le #align cubic.degree_of_c_eq_zero Cubic.degree_of_c_eq_zero theorem degree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).degree ≤ 0 := degree_of_c_eq_zero rfl rfl rfl #align cubic.degree_of_c_eq_zero' Cubic.degree_of_c_eq_zero' @[simp] theorem degree_of_d_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d ≠ 0) : P.toPoly.degree = 0 := by rw [of_c_eq_zero ha hb hc, degree_C hd] #align cubic.degree_of_d_ne_zero Cubic.degree_of_d_ne_zero @[simp] theorem degree_of_d_ne_zero' (hd : d ≠ 0) : (toPoly ⟨0, 0, 0, d⟩).degree = 0 := degree_of_d_ne_zero rfl rfl rfl hd #align cubic.degree_of_d_ne_zero' Cubic.degree_of_d_ne_zero' @[simp] theorem degree_of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) : P.toPoly.degree = ⊥ := by rw [of_d_eq_zero ha hb hc hd, degree_zero] #align cubic.degree_of_d_eq_zero Cubic.degree_of_d_eq_zero -- @[simp] -- porting note (#10618): simp can prove this theorem degree_of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly.degree = ⊥ := degree_of_d_eq_zero rfl rfl rfl rfl #align cubic.degree_of_d_eq_zero' Cubic.degree_of_d_eq_zero' @[simp] theorem degree_of_zero : (0 : Cubic R).toPoly.degree = ⊥ := degree_of_d_eq_zero' #align cubic.degree_of_zero Cubic.degree_of_zero @[simp] theorem natDegree_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.natDegree = 3 := natDegree_cubic ha #align cubic.nat_degree_of_a_ne_zero Cubic.natDegree_of_a_ne_zero @[simp] theorem natDegree_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).natDegree = 3 := natDegree_of_a_ne_zero ha #align cubic.nat_degree_of_a_ne_zero' Cubic.natDegree_of_a_ne_zero' theorem natDegree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.natDegree ≤ 2 := by simpa only [of_a_eq_zero ha] using natDegree_quadratic_le #align cubic.nat_degree_of_a_eq_zero Cubic.natDegree_of_a_eq_zero theorem natDegree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).natDegree ≤ 2 := natDegree_of_a_eq_zero rfl #align cubic.nat_degree_of_a_eq_zero' Cubic.natDegree_of_a_eq_zero' @[simp] theorem natDegree_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.natDegree = 2 := by rw [of_a_eq_zero ha, natDegree_quadratic hb] #align cubic.nat_degree_of_b_ne_zero Cubic.natDegree_of_b_ne_zero @[simp] theorem natDegree_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).natDegree = 2 := natDegree_of_b_ne_zero rfl hb #align cubic.nat_degree_of_b_ne_zero' Cubic.natDegree_of_b_ne_zero' theorem natDegree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.natDegree ≤ 1 := by simpa only [of_b_eq_zero ha hb] using natDegree_linear_le #align cubic.nat_degree_of_b_eq_zero Cubic.natDegree_of_b_eq_zero theorem natDegree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).natDegree ≤ 1 := natDegree_of_b_eq_zero rfl rfl #align cubic.nat_degree_of_b_eq_zero' Cubic.natDegree_of_b_eq_zero' @[simp] theorem natDegree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) : P.toPoly.natDegree = 1 := by rw [of_b_eq_zero ha hb, natDegree_linear hc] #align cubic.nat_degree_of_c_ne_zero Cubic.natDegree_of_c_ne_zero @[simp] theorem natDegree_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).natDegree = 1 := natDegree_of_c_ne_zero rfl rfl hc #align cubic.nat_degree_of_c_ne_zero' Cubic.natDegree_of_c_ne_zero' @[simp] theorem natDegree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.natDegree = 0 := by rw [of_c_eq_zero ha hb hc, natDegree_C] #align cubic.nat_degree_of_c_eq_zero Cubic.natDegree_of_c_eq_zero -- @[simp] -- porting note (#10618): simp can prove this theorem natDegree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).natDegree = 0 := natDegree_of_c_eq_zero rfl rfl rfl #align cubic.nat_degree_of_c_eq_zero' Cubic.natDegree_of_c_eq_zero' @[simp] theorem natDegree_of_zero : (0 : Cubic R).toPoly.natDegree = 0 := natDegree_of_c_eq_zero' #align cubic.nat_degree_of_zero Cubic.natDegree_of_zero end Degree /-! ### Map across a homomorphism -/ section Map variable [Semiring S] {φ : R →+* S} /-- Map a cubic polynomial across a semiring homomorphism. -/ def map (φ : R →+* S) (P : Cubic R) : Cubic S := ⟨φ P.a, φ P.b, φ P.c, φ P.d⟩ #align cubic.map Cubic.map theorem map_toPoly : (map φ P).toPoly = Polynomial.map φ P.toPoly := by simp only [map, toPoly, map_C, map_X, Polynomial.map_add, Polynomial.map_mul, Polynomial.map_pow] #align cubic.map_to_poly Cubic.map_toPoly end Map end Basic section Roots open Multiset /-! ### Roots over an extension -/ section Extension variable {P : Cubic R} [CommRing R] [CommRing S] {φ : R →+* S} /-- The roots of a cubic polynomial. -/ def roots [IsDomain R] (P : Cubic R) : Multiset R := P.toPoly.roots #align cubic.roots Cubic.roots theorem map_roots [IsDomain S] : (map φ P).roots = (Polynomial.map φ P.toPoly).roots := by rw [roots, map_toPoly] #align cubic.map_roots Cubic.map_roots theorem mem_roots_iff [IsDomain R] (h0 : P.toPoly ≠ 0) (x : R) : x ∈ P.roots ↔ P.a * x ^ 3 + P.b * x ^ 2 + P.c * x + P.d = 0 := by rw [roots, mem_roots h0, IsRoot, toPoly] simp only [eval_C, eval_X, eval_add, eval_mul, eval_pow] #align cubic.mem_roots_iff Cubic.mem_roots_iff theorem card_roots_le [IsDomain R] [DecidableEq R] : P.roots.toFinset.card ≤ 3 := by apply (toFinset_card_le P.toPoly.roots).trans by_cases hP : P.toPoly = 0 · exact (card_roots' P.toPoly).trans (by rw [hP, natDegree_zero]; exact zero_le 3) · exact WithBot.coe_le_coe.1 ((card_roots hP).trans degree_cubic_le) #align cubic.card_roots_le Cubic.card_roots_le end Extension variable {P : Cubic F} [Field F] [Field K] {φ : F →+* K} {x y z : K} /-! ### Roots over a splitting field -/ section Split theorem splits_iff_card_roots (ha : P.a ≠ 0) : Splits φ P.toPoly ↔ Multiset.card (map φ P).roots = 3 := by replace ha : (map φ P).a ≠ 0 := (_root_.map_ne_zero φ).mpr ha nth_rw 1 [← RingHom.id_comp φ] rw [roots, ← splits_map_iff, ← map_toPoly, Polynomial.splits_iff_card_roots, ← ((degree_eq_iff_natDegree_eq <| ne_zero_of_a_ne_zero ha).1 <| degree_of_a_ne_zero ha : _ = 3)] #align cubic.splits_iff_card_roots Cubic.splits_iff_card_roots theorem splits_iff_roots_eq_three (ha : P.a ≠ 0) : Splits φ P.toPoly ↔ ∃ x y z : K, (map φ P).roots = {x, y, z} := by rw [splits_iff_card_roots ha, card_eq_three] #align cubic.splits_iff_roots_eq_three Cubic.splits_iff_roots_eq_three theorem eq_prod_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) : (map φ P).toPoly = C (φ P.a) * (X - C x) * (X - C y) * (X - C z) := by rw [map_toPoly, eq_prod_roots_of_splits <| (splits_iff_roots_eq_three ha).mpr <| Exists.intro x <| Exists.intro y <| Exists.intro z h3, leadingCoeff_of_a_ne_zero ha, ← map_roots, h3] change C (φ P.a) * ((X - C x) ::ₘ (X - C y) ::ₘ {X - C z}).prod = _ rw [prod_cons, prod_cons, prod_singleton, mul_assoc, mul_assoc] #align cubic.eq_prod_three_roots Cubic.eq_prod_three_roots theorem eq_sum_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) : map φ P = ⟨φ P.a, φ P.a * -(x + y + z), φ P.a * (x * y + x * z + y * z), φ P.a * -(x * y * z)⟩ := by apply_fun @toPoly _ _ · rw [eq_prod_three_roots ha h3, C_mul_prod_X_sub_C_eq] · exact fun P Q ↦ (toPoly_injective P Q).mp #align cubic.eq_sum_three_roots Cubic.eq_sum_three_roots theorem b_eq_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) : φ P.b = φ P.a * -(x + y + z) := by injection eq_sum_three_roots ha h3 #align cubic.b_eq_three_roots Cubic.b_eq_three_roots theorem c_eq_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) : φ P.c = φ P.a * (x * y + x * z + y * z) := by injection eq_sum_three_roots ha h3 #align cubic.c_eq_three_roots Cubic.c_eq_three_roots theorem d_eq_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) : φ P.d = φ P.a * -(x * y * z) := by injection eq_sum_three_roots ha h3 #align cubic.d_eq_three_roots Cubic.d_eq_three_roots end Split /-! ### Discriminant over a splitting field -/ section Discriminant /-- The discriminant of a cubic polynomial. -/ def disc {R : Type*} [Ring R] (P : Cubic R) : R := P.b ^ 2 * P.c ^ 2 - 4 * P.a * P.c ^ 3 - 4 * P.b ^ 3 * P.d - 27 * P.a ^ 2 * P.d ^ 2 + 18 * P.a * P.b * P.c * P.d #align cubic.disc Cubic.disc theorem disc_eq_prod_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) : φ P.disc = (φ P.a * φ P.a * (x - y) * (x - z) * (y - z)) ^ 2 := by simp only [disc, RingHom.map_add, RingHom.map_sub, RingHom.map_mul, map_pow] -- Porting note: Replaced `simp only [RingHom.map_one, map_bit0, map_bit1]` with f4, f18, f27 have f4 : φ 4 = 4 := map_natCast φ 4 have f18 : φ 18 = 18 := map_natCast φ 18 have f27 : φ 27 = 27 := map_natCast φ 27 rw [f4, f18, f27, b_eq_three_roots ha h3, c_eq_three_roots ha h3, d_eq_three_roots ha h3] ring1 #align cubic.disc_eq_prod_three_roots Cubic.disc_eq_prod_three_roots theorem disc_ne_zero_iff_roots_ne (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) : P.disc ≠ 0 ↔ x ≠ y ∧ x ≠ z ∧ y ≠ z := by rw [← _root_.map_ne_zero φ, disc_eq_prod_three_roots ha h3, pow_two] simp_rw [mul_ne_zero_iff, sub_ne_zero, _root_.map_ne_zero, and_self_iff, and_iff_right ha, and_assoc] #align cubic.disc_ne_zero_iff_roots_ne Cubic.disc_ne_zero_iff_roots_ne theorem disc_ne_zero_iff_roots_nodup (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) : P.disc ≠ 0 ↔ (map φ P).roots.Nodup := by rw [disc_ne_zero_iff_roots_ne ha h3, h3] change _ ↔ (x ::ₘ y ::ₘ {z}).Nodup rw [nodup_cons, nodup_cons, mem_cons, mem_singleton, mem_singleton] simp only [nodup_singleton] tauto #align cubic.disc_ne_zero_iff_roots_nodup Cubic.disc_ne_zero_iff_roots_nodup
Mathlib/Algebra/CubicDiscriminant.lean
594
598
theorem card_roots_of_disc_ne_zero [DecidableEq K] (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) (hd : P.disc ≠ 0) : (map φ P).roots.toFinset.card = 3 := by
rw [toFinset_card_of_nodup <| (disc_ne_zero_iff_roots_nodup ha h3).mp hd, ← splits_iff_card_roots ha, splits_iff_roots_eq_three ha] exact ⟨x, ⟨y, ⟨z, h3⟩⟩⟩
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.ModEq import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Order.Archimedean import Mathlib.Algebra.Periodic import Mathlib.Data.Int.SuccPred import Mathlib.GroupTheory.QuotientGroup import Mathlib.Order.Circular import Mathlib.Data.List.TFAE import Mathlib.Data.Set.Lattice #align_import algebra.order.to_interval_mod from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # Reducing to an interval modulo its length This file defines operations that reduce a number (in an `Archimedean` `LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that interval. ## Main definitions * `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. * `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`. * `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. * `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`. -/ noncomputable section section LinearOrderedAddCommGroup variable {α : Type*} [LinearOrderedAddCommGroup α] [hα : Archimedean α] {p : α} (hp : 0 < p) {a b c : α} {n : ℤ} /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/ def toIcoDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ico hp b a).choose #align to_Ico_div toIcoDiv theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) := (existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1 #align sub_to_Ico_div_zsmul_mem_Ico sub_toIcoDiv_zsmul_mem_Ico theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) : toIcoDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm #align to_Ico_div_eq_of_sub_zsmul_mem_Ico toIcoDiv_eq_of_sub_zsmul_mem_Ico /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/ def toIocDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose #align to_Ioc_div toIocDiv theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1 #align sub_to_Ioc_div_zsmul_mem_Ioc sub_toIocDiv_zsmul_mem_Ioc theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) : toIocDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm #align to_Ioc_div_eq_of_sub_zsmul_mem_Ioc toIocDiv_eq_of_sub_zsmul_mem_Ioc /-- Reduce `b` to the interval `Ico a (a + p)`. -/ def toIcoMod (a b : α) : α := b - toIcoDiv hp a b • p #align to_Ico_mod toIcoMod /-- Reduce `b` to the interval `Ioc a (a + p)`. -/ def toIocMod (a b : α) : α := b - toIocDiv hp a b • p #align to_Ioc_mod toIocMod theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) := sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_mod_mem_Ico toIcoMod_mem_Ico theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by convert toIcoMod_mem_Ico hp 0 b exact (zero_add p).symm #align to_Ico_mod_mem_Ico' toIcoMod_mem_Ico' theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) := sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_mod_mem_Ioc toIocMod_mem_Ioc theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1 #align left_le_to_Ico_mod left_le_toIcoMod theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1 #align left_lt_to_Ioc_mod left_lt_toIocMod theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2 #align to_Ico_mod_lt_right toIcoMod_lt_right theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2 #align to_Ioc_mod_le_right toIocMod_le_right @[simp] theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b := rfl #align self_sub_to_Ico_div_zsmul self_sub_toIcoDiv_zsmul @[simp] theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b := rfl #align self_sub_to_Ioc_div_zsmul self_sub_toIocDiv_zsmul @[simp] theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by rw [toIcoMod, neg_sub] #align to_Ico_div_zsmul_sub_self toIcoDiv_zsmul_sub_self @[simp] theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by rw [toIocMod, neg_sub] #align to_Ioc_div_zsmul_sub_self toIocDiv_zsmul_sub_self @[simp] theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel_left, neg_smul] #align to_Ico_mod_sub_self toIcoMod_sub_self @[simp] theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel_left, neg_smul] #align to_Ioc_mod_sub_self toIocMod_sub_self @[simp] theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel] #align self_sub_to_Ico_mod self_sub_toIcoMod @[simp] theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel] #align self_sub_to_Ioc_mod self_sub_toIocMod @[simp] theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by rw [toIcoMod, sub_add_cancel] #align to_Ico_mod_add_to_Ico_div_zsmul toIcoMod_add_toIcoDiv_zsmul @[simp] theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by rw [toIocMod, sub_add_cancel] #align to_Ioc_mod_add_to_Ioc_div_zsmul toIocMod_add_toIocDiv_zsmul @[simp] theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by rw [add_comm, toIcoMod_add_toIcoDiv_zsmul] #align to_Ico_div_zsmul_sub_to_Ico_mod toIcoDiv_zsmul_sub_toIcoMod @[simp] theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by rw [add_comm, toIocMod_add_toIocDiv_zsmul] #align to_Ioc_div_zsmul_sub_to_Ioc_mod toIocDiv_zsmul_sub_toIocMod theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod] #align to_Ico_mod_eq_iff toIcoMod_eq_iff theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod] #align to_Ioc_mod_eq_iff toIocMod_eq_iff @[simp] theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] #align to_Ico_div_apply_left toIcoDiv_apply_left @[simp] theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] #align to_Ioc_div_apply_left toIocDiv_apply_left @[simp] theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ #align to_Ico_mod_apply_left toIcoMod_apply_left @[simp] theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩ #align to_Ioc_mod_apply_left toIocMod_apply_left theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] #align to_Ico_div_apply_right toIcoDiv_apply_right theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] #align to_Ioc_div_apply_right toIocDiv_apply_right theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩ #align to_Ico_mod_apply_right toIcoMod_apply_right theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ #align to_Ioc_mod_apply_right toIocMod_apply_right @[simp] theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_div_add_zsmul toIcoDiv_add_zsmul @[simp] theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_div_add_zsmul' toIcoDiv_add_zsmul' @[simp] theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_div_add_zsmul toIocDiv_add_zsmul @[simp] theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_div_add_zsmul' toIocDiv_add_zsmul' @[simp] theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by rw [add_comm, toIcoDiv_add_zsmul, add_comm] #align to_Ico_div_zsmul_add toIcoDiv_zsmul_add /-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/ @[simp] theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by rw [add_comm, toIocDiv_add_zsmul, add_comm] #align to_Ioc_div_zsmul_add toIocDiv_zsmul_add /-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/ @[simp] theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg] #align to_Ico_div_sub_zsmul toIcoDiv_sub_zsmul @[simp] theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add] #align to_Ico_div_sub_zsmul' toIcoDiv_sub_zsmul' @[simp] theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg] #align to_Ioc_div_sub_zsmul toIocDiv_sub_zsmul @[simp] theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add] #align to_Ioc_div_sub_zsmul' toIocDiv_sub_zsmul' @[simp] theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1 #align to_Ico_div_add_right toIcoDiv_add_right @[simp] theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1 #align to_Ico_div_add_right' toIcoDiv_add_right' @[simp] theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1 #align to_Ioc_div_add_right toIocDiv_add_right @[simp] theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1 #align to_Ioc_div_add_right' toIocDiv_add_right' @[simp] theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by rw [add_comm, toIcoDiv_add_right] #align to_Ico_div_add_left toIcoDiv_add_left @[simp] theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by rw [add_comm, toIcoDiv_add_right'] #align to_Ico_div_add_left' toIcoDiv_add_left' @[simp] theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by rw [add_comm, toIocDiv_add_right] #align to_Ioc_div_add_left toIocDiv_add_left @[simp] theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by rw [add_comm, toIocDiv_add_right'] #align to_Ioc_div_add_left' toIocDiv_add_left' @[simp] theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1 #align to_Ico_div_sub toIcoDiv_sub @[simp] theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1 #align to_Ico_div_sub' toIcoDiv_sub' @[simp] theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1 #align to_Ioc_div_sub toIocDiv_sub @[simp] theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1 #align to_Ioc_div_sub' toIocDiv_sub' theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) : toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by apply toIcoDiv_eq_of_sub_zsmul_mem_Ico rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm] exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b #align to_Ico_div_sub_eq_to_Ico_div_add toIcoDiv_sub_eq_toIcoDiv_add theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) : toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by apply toIocDiv_eq_of_sub_zsmul_mem_Ioc rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm] exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b #align to_Ioc_div_sub_eq_to_Ioc_div_add toIocDiv_sub_eq_toIocDiv_add theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) : toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg] #align to_Ico_div_sub_eq_to_Ico_div_add' toIcoDiv_sub_eq_toIcoDiv_add' theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) : toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg] #align to_Ioc_div_sub_eq_to_Ioc_div_add' toIocDiv_sub_eq_toIocDiv_add' theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this rw [← neg_eq_iff_eq_neg, eq_comm] apply toIocDiv_eq_of_sub_zsmul_mem_Ioc obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b) rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc refine ⟨ho, hc.trans_eq ?_⟩ rw [neg_add, neg_add_cancel_right] #align to_Ico_div_neg toIcoDiv_neg theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b) #align to_Ico_div_neg' toIcoDiv_neg' theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right] #align to_Ioc_div_neg toIocDiv_neg theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b) #align to_Ioc_div_neg' toIocDiv_neg' @[simp] theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul] abel #align to_Ico_mod_add_zsmul toIcoMod_add_zsmul @[simp] theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add] #align to_Ico_mod_add_zsmul' toIcoMod_add_zsmul' @[simp] theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul] abel #align to_Ioc_mod_add_zsmul toIocMod_add_zsmul @[simp] theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add] #align to_Ioc_mod_add_zsmul' toIocMod_add_zsmul' @[simp] theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul] #align to_Ico_mod_zsmul_add toIcoMod_zsmul_add @[simp] theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) : toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul', add_comm] #align to_Ico_mod_zsmul_add' toIcoMod_zsmul_add' @[simp] theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul] #align to_Ioc_mod_zsmul_add toIocMod_zsmul_add @[simp] theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) : toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul', add_comm] #align to_Ioc_mod_zsmul_add' toIocMod_zsmul_add' @[simp] theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul] #align to_Ico_mod_sub_zsmul toIcoMod_sub_zsmul @[simp] theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul'] #align to_Ico_mod_sub_zsmul' toIcoMod_sub_zsmul' @[simp] theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul] #align to_Ioc_mod_sub_zsmul toIocMod_sub_zsmul @[simp] theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul'] #align to_Ioc_mod_sub_zsmul' toIocMod_sub_zsmul' @[simp] theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1 #align to_Ico_mod_add_right toIcoMod_add_right @[simp] theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1 #align to_Ico_mod_add_right' toIcoMod_add_right' @[simp] theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1 #align to_Ioc_mod_add_right toIocMod_add_right @[simp] theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1 #align to_Ioc_mod_add_right' toIocMod_add_right' @[simp] theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right] #align to_Ico_mod_add_left toIcoMod_add_left @[simp] theorem toIcoMod_add_left' (a b : α) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right', add_comm] #align to_Ico_mod_add_left' toIcoMod_add_left' @[simp] theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_right] #align to_Ioc_mod_add_left toIocMod_add_left @[simp] theorem toIocMod_add_left' (a b : α) : toIocMod hp (p + a) b = p + toIocMod hp a b := by rw [add_comm, toIocMod_add_right', add_comm] #align to_Ioc_mod_add_left' toIocMod_add_left' @[simp] theorem toIcoMod_sub (a b : α) : toIcoMod hp a (b - p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1 #align to_Ico_mod_sub toIcoMod_sub @[simp] theorem toIcoMod_sub' (a b : α) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1 #align to_Ico_mod_sub' toIcoMod_sub' @[simp] theorem toIocMod_sub (a b : α) : toIocMod hp a (b - p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1 #align to_Ioc_mod_sub toIocMod_sub @[simp] theorem toIocMod_sub' (a b : α) : toIocMod hp (a - p) b = toIocMod hp a b - p := by simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1 #align to_Ioc_mod_sub' toIocMod_sub' theorem toIcoMod_sub_eq_sub (a b c : α) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm] #align to_Ico_mod_sub_eq_sub toIcoMod_sub_eq_sub theorem toIocMod_sub_eq_sub (a b c : α) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm] #align to_Ioc_mod_sub_eq_sub toIocMod_sub_eq_sub theorem toIcoMod_add_right_eq_add (a b c : α) : toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub] #align to_Ico_mod_add_right_eq_add toIcoMod_add_right_eq_add theorem toIocMod_add_right_eq_add (a b c : α) : toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub] #align to_Ioc_mod_add_right_eq_add toIocMod_add_right_eq_add theorem toIcoMod_neg (a b : α) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul] abel #align to_Ico_mod_neg toIcoMod_neg theorem toIcoMod_neg' (a b : α) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b) #align to_Ico_mod_neg' toIcoMod_neg' theorem toIocMod_neg (a b : α) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul] abel #align to_Ioc_mod_neg toIocMod_neg theorem toIocMod_neg' (a b : α) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by simpa only [neg_neg] using toIocMod_neg hp (-a) (-b) #align to_Ioc_mod_neg' toIocMod_neg' theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIcoMod_zsmul_add] #align to_Ico_mod_eq_to_Ico_mod toIcoMod_eq_toIcoMod theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIocMod_zsmul_add] #align to_Ioc_mod_eq_to_Ioc_mod toIocMod_eq_toIocMod /-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/ section IcoIoc namespace AddCommGroup theorem modEq_iff_toIcoMod_eq_left : a ≡ b [PMOD p] ↔ toIcoMod hp a b = a := modEq_iff_eq_add_zsmul.trans ⟨by rintro ⟨n, rfl⟩ rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩ #align add_comm_group.modeq_iff_to_Ico_mod_eq_left AddCommGroup.modEq_iff_toIcoMod_eq_left theorem modEq_iff_toIocMod_eq_right : a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p := by refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩ · rintro ⟨z, rfl⟩ rw [toIocMod_add_zsmul, toIocMod_apply_left] · rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add'] #align add_comm_group.modeq_iff_to_Ioc_mod_eq_right AddCommGroup.modEq_iff_toIocMod_eq_right alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left #align add_comm_group.modeq.to_Ico_mod_eq_left AddCommGroup.ModEq.toIcoMod_eq_left alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right #align add_comm_group.modeq.to_Ico_mod_eq_right AddCommGroup.ModEq.toIcoMod_eq_right variable (a b) open List in theorem tfae_modEq : TFAE [a ≡ b [PMOD p], ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] := by rw [modEq_iff_toIcoMod_eq_left hp] tfae_have 3 → 2 · rw [← not_exists, not_imp_not] exact fun ⟨i, hi⟩ => ((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans ((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm tfae_have 4 → 3 · intro h rw [← h, Ne, eq_comm, add_right_eq_self] exact hp.ne' tfae_have 1 → 4 · intro h rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc] refine ⟨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, ?_⟩ rw [sub_one_zsmul, add_add_add_comm, add_right_neg, add_zero] conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] tfae_have 2 → 1 · rw [← not_exists, not_imp_comm] have h' := toIcoMod_mem_Ico hp a b exact fun h => ⟨_, h'.1.lt_of_ne' h, h'.2⟩ tfae_finish #align add_comm_group.tfae_modeq AddCommGroup.tfae_modEq variable {a b} theorem modEq_iff_not_forall_mem_Ioo_mod : a ≡ b [PMOD p] ↔ ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p) := (tfae_modEq hp a b).out 0 1 #align add_comm_group.modeq_iff_not_forall_mem_Ioo_mod AddCommGroup.modEq_iff_not_forall_mem_Ioo_mod theorem modEq_iff_toIcoMod_ne_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b ≠ toIocMod hp a b := (tfae_modEq hp a b).out 0 2 #align add_comm_group.modeq_iff_to_Ico_mod_ne_to_Ioc_mod AddCommGroup.modEq_iff_toIcoMod_ne_toIocMod theorem modEq_iff_toIcoMod_add_period_eq_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b + p = toIocMod hp a b := (tfae_modEq hp a b).out 0 3 #align add_comm_group.modeq_iff_to_Ico_mod_add_period_eq_to_Ioc_mod AddCommGroup.modEq_iff_toIcoMod_add_period_eq_toIocMod theorem not_modEq_iff_toIcoMod_eq_toIocMod : ¬a ≡ b [PMOD p] ↔ toIcoMod hp a b = toIocMod hp a b := (modEq_iff_toIcoMod_ne_toIocMod _).not_left #align add_comm_group.not_modeq_iff_to_Ico_mod_eq_to_Ioc_mod AddCommGroup.not_modEq_iff_toIcoMod_eq_toIocMod theorem not_modEq_iff_toIcoDiv_eq_toIocDiv : ¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj, (zsmul_strictMono_left hp).injective.eq_iff] #align add_comm_group.not_modeq_iff_to_Ico_div_eq_to_Ioc_div AddCommGroup.not_modEq_iff_toIcoDiv_eq_toIocDiv theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one : a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 := by rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq, sub_sub, sub_right_inj, ← add_one_zsmul, (zsmul_strictMono_left hp).injective.eq_iff] #align add_comm_group.modeq_iff_to_Ico_div_eq_to_Ioc_div_add_one AddCommGroup.modEq_iff_toIcoDiv_eq_toIocDiv_add_one end AddCommGroup open AddCommGroup /-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/ @[simp] theorem toIcoMod_inj {c : α} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] := by simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add'] #align to_Ico_mod_inj toIcoMod_inj alias ⟨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoMod⟩ := toIcoMod_inj #align add_comm_group.modeq.to_Ico_mod_eq_to_Ico_mod AddCommGroup.ModEq.toIcoMod_eq_toIcoMod theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo : { b | toIcoMod hp a b = toIocMod hp a b } = ⋃ z : ℤ, Set.Ioo (a + z • p) (a + p + z • p) := by ext1; simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ← not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall, Classical.not_not] #align Ico_eq_locus_Ioc_eq_Union_Ioo Ico_eq_locus_Ioc_eq_iUnion_Ioo theorem toIocDiv_wcovBy_toIcoDiv (a b : α) : toIocDiv hp a b ⩿ toIcoDiv hp a b := by suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy] rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ← modEq_iff_toIcoDiv_eq_toIocDiv_add_one] exact em' _ #align to_Ioc_div_wcovby_to_Ico_div toIocDiv_wcovBy_toIcoDiv theorem toIcoMod_le_toIocMod (a b : α) : toIcoMod hp a b ≤ toIocMod hp a b := by rw [toIcoMod, toIocMod, sub_le_sub_iff_left] exact zsmul_mono_left hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le #align to_Ico_mod_le_to_Ioc_mod toIcoMod_le_toIocMod theorem toIocMod_le_toIcoMod_add (a b : α) : toIocMod hp a b ≤ toIcoMod hp a b + p := by rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul, (zsmul_strictMono_left hp).le_iff_le] apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ #align to_Ioc_mod_le_to_Ico_mod_add toIocMod_le_toIcoMod_add end IcoIoc open AddCommGroup
Mathlib/Algebra/Order/ToIntervalMod.lean
723
725
theorem toIcoMod_eq_self : toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) := by
rw [toIcoMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩
/- Copyright (c) 2022 Michael Blyth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Blyth -/ import Mathlib.LinearAlgebra.Projectivization.Basic #align_import linear_algebra.projective_space.subspace from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Subspaces of Projective Space In this file we define subspaces of a projective space, and show that the subspaces of a projective space form a complete lattice under inclusion. ## Implementation Details A subspace of a projective space ℙ K V is defined to be a structure consisting of a subset of ℙ K V such that if two nonzero vectors in V determine points in ℙ K V which are in the subset, and the sum of the two vectors is nonzero, then the point determined by the sum of the two vectors is also in the subset. ## Results - There is a Galois insertion between the subsets of points of a projective space and the subspaces of the projective space, which is given by taking the span of the set of points. - The subspaces of a projective space form a complete lattice under inclusion. # Future Work - Show that there is a one-to-one order-preserving correspondence between subspaces of a projective space and the submodules of the underlying vector space. -/ variable (K V : Type*) [Field K] [AddCommGroup V] [Module K V] namespace Projectivization open scoped LinearAlgebra.Projectivization /-- A subspace of a projective space is a structure consisting of a set of points such that: If two nonzero vectors determine points which are in the set, and the sum of the two vectors is nonzero, then the point determined by the sum is also in the set. -/ @[ext] structure Subspace where /-- The set of points. -/ carrier : Set (ℙ K V) /-- The addition rule. -/ mem_add' (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : mk K v hv ∈ carrier → mk K w hw ∈ carrier → mk K (v + w) hvw ∈ carrier #align projectivization.subspace Projectivization.Subspace namespace Subspace variable {K V} instance : SetLike (Subspace K V) (ℙ K V) where coe := carrier coe_injective' A B := by cases A cases B simp @[simp] theorem mem_carrier_iff (A : Subspace K V) (x : ℙ K V) : x ∈ A.carrier ↔ x ∈ A := Iff.refl _ #align projectivization.subspace.mem_carrier_iff Projectivization.Subspace.mem_carrier_iff theorem mem_add (T : Subspace K V) (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : Projectivization.mk K v hv ∈ T → Projectivization.mk K w hw ∈ T → Projectivization.mk K (v + w) hvw ∈ T := T.mem_add' v w hv hw hvw #align projectivization.subspace.mem_add Projectivization.Subspace.mem_add /-- The span of a set of points in a projective space is defined inductively to be the set of points which contains the original set, and contains all points determined by the (nonzero) sum of two nonzero vectors, each of which determine points in the span. -/ inductive spanCarrier (S : Set (ℙ K V)) : Set (ℙ K V) | of (x : ℙ K V) (hx : x ∈ S) : spanCarrier S x | mem_add (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : spanCarrier S (Projectivization.mk K v hv) → spanCarrier S (Projectivization.mk K w hw) → spanCarrier S (Projectivization.mk K (v + w) hvw) #align projectivization.subspace.span_carrier Projectivization.Subspace.spanCarrier /-- The span of a set of points in projective space is a subspace. -/ def span (S : Set (ℙ K V)) : Subspace K V where carrier := spanCarrier S mem_add' v w hv hw hvw := spanCarrier.mem_add v w hv hw hvw #align projectivization.subspace.span Projectivization.Subspace.span /-- The span of a set of points contains the set of points. -/ theorem subset_span (S : Set (ℙ K V)) : S ⊆ span S := fun _x hx => spanCarrier.of _ hx #align projectivization.subspace.subset_span Projectivization.Subspace.subset_span /-- The span of a set of points is a Galois insertion between sets of points of a projective space and subspaces of the projective space. -/ def gi : GaloisInsertion (span : Set (ℙ K V) → Subspace K V) SetLike.coe where choice S _hS := span S gc A B := ⟨fun h => le_trans (subset_span _) h, by intro h x hx induction' hx with y hy · apply h assumption · apply B.mem_add assumption'⟩ le_l_u S := subset_span _ choice_eq _ _ := rfl #align projectivization.subspace.gi Projectivization.Subspace.gi /-- The span of a subspace is the subspace. -/ @[simp] theorem span_coe (W : Subspace K V) : span ↑W = W := GaloisInsertion.l_u_eq gi W #align projectivization.subspace.span_coe Projectivization.Subspace.span_coe /-- The infimum of two subspaces exists. -/ instance instInf : Inf (Subspace K V) := ⟨fun A B => ⟨A ⊓ B, fun _v _w hv hw _hvw h1 h2 => ⟨A.mem_add _ _ hv hw _ h1.1 h2.1, B.mem_add _ _ hv hw _ h1.2 h2.2⟩⟩⟩ #align projectivization.subspace.has_inf Projectivization.Subspace.instInf -- Porting note: delete the name of this instance since it causes problem since hasInf is already -- defined above /-- Infimums of arbitrary collections of subspaces exist. -/ instance instInfSet : InfSet (Subspace K V) := ⟨fun A => ⟨sInf (SetLike.coe '' A), fun v w hv hw hvw h1 h2 t => by rintro ⟨s, hs, rfl⟩ exact s.mem_add v w hv hw _ (h1 s ⟨s, hs, rfl⟩) (h2 s ⟨s, hs, rfl⟩)⟩⟩ #align projectivization.subspace.has_Inf Projectivization.Subspace.instInfSet /-- The subspaces of a projective space form a complete lattice. -/ instance : CompleteLattice (Subspace K V) := { __ := completeLatticeOfInf (Subspace K V) (by refine fun s => ⟨fun a ha x hx => hx _ ⟨a, ha, rfl⟩, fun a ha x hx E => ?_⟩ rintro ⟨E, hE, rfl⟩ exact ha hE hx) inf_le_left := fun A B _ hx => (@inf_le_left _ _ A B) hx inf_le_right := fun A B _ hx => (@inf_le_right _ _ A B) hx le_inf := fun A B _ h1 h2 _ hx => (le_inf h1 h2) hx } instance subspaceInhabited : Inhabited (Subspace K V) where default := ⊤ #align projectivization.subspace.subspace_inhabited Projectivization.Subspace.subspaceInhabited /-- The span of the empty set is the bottom of the lattice of subspaces. -/ @[simp] theorem span_empty : span (∅ : Set (ℙ K V)) = ⊥ := gi.gc.l_bot #align projectivization.subspace.span_empty Projectivization.Subspace.span_empty /-- The span of the entire projective space is the top of the lattice of subspaces. -/ @[simp] theorem span_univ : span (Set.univ : Set (ℙ K V)) = ⊤ := by rw [eq_top_iff, SetLike.le_def] intro x _hx exact subset_span _ (Set.mem_univ x) #align projectivization.subspace.span_univ Projectivization.Subspace.span_univ /-- The span of a set of points is contained in a subspace if and only if the set of points is contained in the subspace. -/ theorem span_le_subspace_iff {S : Set (ℙ K V)} {W : Subspace K V} : span S ≤ W ↔ S ⊆ W := gi.gc S W #align projectivization.subspace.span_le_subspace_iff Projectivization.Subspace.span_le_subspace_iff /-- If a set of points is a subset of another set of points, then its span will be contained in the span of that set. -/ @[mono] theorem monotone_span : Monotone (span : Set (ℙ K V) → Subspace K V) := gi.gc.monotone_l #align projectivization.subspace.monotone_span Projectivization.Subspace.monotone_span theorem subset_span_trans {S T U : Set (ℙ K V)} (hST : S ⊆ span T) (hTU : T ⊆ span U) : S ⊆ span U := gi.gc.le_u_l_trans hST hTU #align projectivization.subspace.subset_span_trans Projectivization.Subspace.subset_span_trans /-- The supremum of two subspaces is equal to the span of their union. -/ theorem span_union (S T : Set (ℙ K V)) : span (S ∪ T) = span S ⊔ span T := (@gi K V _ _ _).gc.l_sup #align projectivization.subspace.span_union Projectivization.Subspace.span_union /-- The supremum of a collection of subspaces is equal to the span of the union of the collection. -/ theorem span_iUnion {ι} (s : ι → Set (ℙ K V)) : span (⋃ i, s i) = ⨆ i, span (s i) := (@gi K V _ _ _).gc.l_iSup #align projectivization.subspace.span_Union Projectivization.Subspace.span_iUnion /-- The supremum of a subspace and the span of a set of points is equal to the span of the union of the subspace and the set of points. -/
Mathlib/LinearAlgebra/Projectivization/Subspace.lean
192
193
theorem sup_span {S : Set (ℙ K V)} {W : Subspace K V} : W ⊔ span S = span (W ∪ S) := by
rw [span_union, span_coe]
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yakov Pechersky -/ import Mathlib.Data.List.Nodup import Mathlib.Data.List.Zip import Mathlib.Data.Nat.Defs import Mathlib.Data.List.Infix #align_import data.list.rotate from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # List rotation This file proves basic results about `List.rotate`, the list rotation. ## Main declarations * `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`. * `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`. ## Tags rotated, rotation, permutation, cycle -/ universe u variable {α : Type u} open Nat Function namespace List theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] #align list.rotate_mod List.rotate_mod @[simp] theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate] #align list.rotate_nil List.rotate_nil @[simp] theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate] #align list.rotate_zero List.rotate_zero -- Porting note: removing simp, simp can prove it theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by cases n <;> rfl #align list.rotate'_nil List.rotate'_nil @[simp] theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl #align list.rotate'_zero List.rotate'_zero theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate'] #align list.rotate'_cons_succ List.rotate'_cons_succ @[simp] theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length | [], _ => by simp | a :: l, 0 => rfl | a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp #align list.length_rotate' List.length_rotate' theorem rotate'_eq_drop_append_take : ∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n | [], n, h => by simp [drop_append_of_le_length h] | l, 0, h => by simp [take_append_of_le_length h] | a :: l, n + 1, h => by have hnl : n ≤ l.length := le_of_succ_le_succ h have hnl' : n ≤ (l ++ [a]).length := by rw [length_append, length_cons, List.length]; exact le_of_succ_le h rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take, drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp #align list.rotate'_eq_drop_append_take List.rotate'_eq_drop_append_take theorem rotate'_rotate' : ∀ (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m) | a :: l, 0, m => by simp | [], n, m => by simp | a :: l, n + 1, m => by rw [rotate'_cons_succ, rotate'_rotate' _ n, Nat.add_right_comm, ← rotate'_cons_succ, Nat.succ_eq_add_one] #align list.rotate'_rotate' List.rotate'_rotate' @[simp] theorem rotate'_length (l : List α) : rotate' l l.length = l := by rw [rotate'_eq_drop_append_take le_rfl]; simp #align list.rotate'_length List.rotate'_length @[simp] theorem rotate'_length_mul (l : List α) : ∀ n : ℕ, l.rotate' (l.length * n) = l | 0 => by simp | n + 1 => calc l.rotate' (l.length * (n + 1)) = (l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length := by simp [-rotate'_length, Nat.mul_succ, rotate'_rotate'] _ = l := by rw [rotate'_length, rotate'_length_mul l n] #align list.rotate'_length_mul List.rotate'_length_mul theorem rotate'_mod (l : List α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n := calc l.rotate' (n % l.length) = (l.rotate' (n % l.length)).rotate' ((l.rotate' (n % l.length)).length * (n / l.length)) := by rw [rotate'_length_mul] _ = l.rotate' n := by rw [rotate'_rotate', length_rotate', Nat.mod_add_div] #align list.rotate'_mod List.rotate'_mod theorem rotate_eq_rotate' (l : List α) (n : ℕ) : l.rotate n = l.rotate' n := if h : l.length = 0 then by simp_all [length_eq_zero] else by rw [← rotate'_mod, rotate'_eq_drop_append_take (le_of_lt (Nat.mod_lt _ (Nat.pos_of_ne_zero h)))]; simp [rotate] #align list.rotate_eq_rotate' List.rotate_eq_rotate' theorem rotate_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate (n + 1) = (l ++ [a]).rotate n := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate'_cons_succ] #align list.rotate_cons_succ List.rotate_cons_succ @[simp] theorem mem_rotate : ∀ {l : List α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l | [], _, n => by simp | a :: l, _, 0 => by simp | a :: l, _, n + 1 => by simp [rotate_cons_succ, mem_rotate, or_comm] #align list.mem_rotate List.mem_rotate @[simp] theorem length_rotate (l : List α) (n : ℕ) : (l.rotate n).length = l.length := by rw [rotate_eq_rotate', length_rotate'] #align list.length_rotate List.length_rotate @[simp] theorem rotate_replicate (a : α) (n : ℕ) (k : ℕ) : (replicate n a).rotate k = replicate n a := eq_replicate.2 ⟨by rw [length_rotate, length_replicate], fun b hb => eq_of_mem_replicate <| mem_rotate.1 hb⟩ #align list.rotate_replicate List.rotate_replicate theorem rotate_eq_drop_append_take {l : List α} {n : ℕ} : n ≤ l.length → l.rotate n = l.drop n ++ l.take n := by rw [rotate_eq_rotate']; exact rotate'_eq_drop_append_take #align list.rotate_eq_drop_append_take List.rotate_eq_drop_append_take theorem rotate_eq_drop_append_take_mod {l : List α} {n : ℕ} : l.rotate n = l.drop (n % l.length) ++ l.take (n % l.length) := by rcases l.length.zero_le.eq_or_lt with hl | hl · simp [eq_nil_of_length_eq_zero hl.symm] rw [← rotate_eq_drop_append_take (n.mod_lt hl).le, rotate_mod] #align list.rotate_eq_drop_append_take_mod List.rotate_eq_drop_append_take_mod @[simp] theorem rotate_append_length_eq (l l' : List α) : (l ++ l').rotate l.length = l' ++ l := by rw [rotate_eq_rotate'] induction l generalizing l' · simp · simp_all [rotate'] #align list.rotate_append_length_eq List.rotate_append_length_eq theorem rotate_rotate (l : List α) (n m : ℕ) : (l.rotate n).rotate m = l.rotate (n + m) := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate_eq_rotate', rotate'_rotate'] #align list.rotate_rotate List.rotate_rotate @[simp] theorem rotate_length (l : List α) : rotate l l.length = l := by rw [rotate_eq_rotate', rotate'_length] #align list.rotate_length List.rotate_length @[simp] theorem rotate_length_mul (l : List α) (n : ℕ) : l.rotate (l.length * n) = l := by rw [rotate_eq_rotate', rotate'_length_mul] #align list.rotate_length_mul List.rotate_length_mul
Mathlib/Data/List/Rotate.lean
176
183
theorem rotate_perm (l : List α) (n : ℕ) : l.rotate n ~ l := by
rw [rotate_eq_rotate'] induction' n with n hn generalizing l · simp · cases' l with hd tl · simp · rw [rotate'_cons_succ] exact (hn _).trans (perm_append_singleton _ _)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad -/ import Mathlib.Order.Filter.Lift import Mathlib.Topology.Defs.Filter #align_import topology.basic from "leanprover-community/mathlib"@"e354e865255654389cc46e6032160238df2e0f40" /-! # Basic theory of topological spaces. The main definition is the type class `TopologicalSpace X` which endows a type `X` with a topology. Then `Set X` gets predicates `IsOpen`, `IsClosed` and functions `interior`, `closure` and `frontier`. Each point `x` of `X` gets a neighborhood filter `𝓝 x`. A filter `F` on `X` has `x` as a cluster point if `ClusterPt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : α → X` clusters at `x` along `F : Filter α` if `MapClusterPt x F f : ClusterPt x (map f F)`. In particular the notion of cluster point of a sequence `u` is `MapClusterPt x atTop u`. For topological spaces `X` and `Y`, a function `f : X → Y` and a point `x : X`, `ContinuousAt f x` means `f` is continuous at `x`, and global continuity is `Continuous f`. There is also a version of continuity `PContinuous` for partially defined functions. ## Notation The following notation is introduced elsewhere and it heavily used in this file. * `𝓝 x`: the filter `nhds x` of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`; * `𝓝[≠] x`: the filter `nhdsWithin x {x}ᶜ` of punctured neighborhoods of `x`. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space, interior, closure, frontier, neighborhood, continuity, continuous function -/ noncomputable section open Set Filter universe u v w x /-! ### Topological spaces -/ /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T) (union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where IsOpen X := Xᶜ ∈ T isOpen_univ := by simp [empty_mem] isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht isOpen_sUnion s hs := by simp only [Set.compl_sUnion] exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy #align topological_space.of_closed TopologicalSpace.ofClosed section TopologicalSpace variable {X : Type u} {Y : Type v} {ι : Sort w} {α β : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} open Topology lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl #align is_open_mk isOpen_mk @[ext] protected theorem TopologicalSpace.ext : ∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align topological_space_eq TopologicalSpace.ext section variable [TopologicalSpace X] end protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} : t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s := ⟨fun h s => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ #align topological_space_eq_iff TopologicalSpace.ext_iff theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s := rfl #align is_open_fold isOpen_fold variable [TopologicalSpace X] theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) := isOpen_sUnion (forall_mem_range.2 h) #align is_open_Union isOpen_iUnion theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋃ i ∈ s, f i) := isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi #align is_open_bUnion isOpen_biUnion theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) #align is_open.union IsOpen.union lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) : IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩ rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter] exact isOpen_iUnion fun i ↦ h i @[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim #align is_open_empty isOpen_empty theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) : (∀ t ∈ s, IsOpen t) → IsOpen (⋂₀ s) := Finite.induction_on hs (fun _ => by rw [sInter_empty]; exact isOpen_univ) fun _ _ ih h => by simp only [sInter_insert, forall_mem_insert] at h ⊢ exact h.1.inter (ih h.2) #align is_open_sInter Set.Finite.isOpen_sInter theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h) #align is_open_bInter Set.Finite.isOpen_biInter theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) : IsOpen (⋂ i, s i) := (finite_range _).isOpen_sInter (forall_mem_range.2 h) #align is_open_Inter isOpen_iInter_of_finite theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := s.finite_toSet.isOpen_biInter h #align is_open_bInter_finset isOpen_biInter_finset @[simp] -- Porting note: added `simp` theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*] #align is_open_const isOpen_const theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } := IsOpen.inter #align is_open.and IsOpen.and @[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s := ⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩ #align is_open_compl_iff isOpen_compl_iff theorem TopologicalSpace.ext_iff_isClosed {t₁ t₂ : TopologicalSpace X} : t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by rw [TopologicalSpace.ext_iff, compl_surjective.forall] simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂] alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed -- Porting note (#10756): new lemma theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩ @[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const #align is_closed_empty isClosed_empty @[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const #align is_closed_univ isClosed_univ theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter #align is_closed.union IsClosed.union theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion #align is_closed_sInter isClosed_sInter theorem isClosed_iInter {f : ι → Set X} (h : ∀ i, IsClosed (f i)) : IsClosed (⋂ i, f i) := isClosed_sInter <| forall_mem_range.2 h #align is_closed_Inter isClosed_iInter theorem isClosed_biInter {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋂ i ∈ s, f i) := isClosed_iInter fun i => isClosed_iInter <| h i #align is_closed_bInter isClosed_biInter @[simp] theorem isClosed_compl_iff {s : Set X} : IsClosed sᶜ ↔ IsOpen s := by rw [← isOpen_compl_iff, compl_compl] #align is_closed_compl_iff isClosed_compl_iff alias ⟨_, IsOpen.isClosed_compl⟩ := isClosed_compl_iff #align is_open.is_closed_compl IsOpen.isClosed_compl theorem IsOpen.sdiff (h₁ : IsOpen s) (h₂ : IsClosed t) : IsOpen (s \ t) := IsOpen.inter h₁ h₂.isOpen_compl #align is_open.sdiff IsOpen.sdiff theorem IsClosed.inter (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ∩ s₂) := by rw [← isOpen_compl_iff] at * rw [compl_inter] exact IsOpen.union h₁ h₂ #align is_closed.inter IsClosed.inter theorem IsClosed.sdiff (h₁ : IsClosed s) (h₂ : IsOpen t) : IsClosed (s \ t) := IsClosed.inter h₁ (isClosed_compl_iff.mpr h₂) #align is_closed.sdiff IsClosed.sdiff theorem Set.Finite.isClosed_biUnion {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact hs.isOpen_biInter h #align is_closed_bUnion Set.Finite.isClosed_biUnion lemma isClosed_biUnion_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := s.finite_toSet.isClosed_biUnion h theorem isClosed_iUnion_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsClosed (s i)) : IsClosed (⋃ i, s i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact isOpen_iInter_of_finite h #align is_closed_Union isClosed_iUnion_of_finite theorem isClosed_imp {p q : X → Prop} (hp : IsOpen { x | p x }) (hq : IsClosed { x | q x }) : IsClosed { x | p x → q x } := by simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq #align is_closed_imp isClosed_imp theorem IsClosed.not : IsClosed { a | p a } → IsOpen { a | ¬p a } := isOpen_compl_iff.mpr #align is_closed.not IsClosed.not /-! ### Interior of a set -/ theorem mem_interior : x ∈ interior s ↔ ∃ t ⊆ s, IsOpen t ∧ x ∈ t := by simp only [interior, mem_sUnion, mem_setOf_eq, and_assoc, and_left_comm] #align mem_interior mem_interiorₓ @[simp] theorem isOpen_interior : IsOpen (interior s) := isOpen_sUnion fun _ => And.left #align is_open_interior isOpen_interior theorem interior_subset : interior s ⊆ s := sUnion_subset fun _ => And.right #align interior_subset interior_subset theorem interior_maximal (h₁ : t ⊆ s) (h₂ : IsOpen t) : t ⊆ interior s := subset_sUnion_of_mem ⟨h₂, h₁⟩ #align interior_maximal interior_maximal theorem IsOpen.interior_eq (h : IsOpen s) : interior s = s := interior_subset.antisymm (interior_maximal (Subset.refl s) h) #align is_open.interior_eq IsOpen.interior_eq theorem interior_eq_iff_isOpen : interior s = s ↔ IsOpen s := ⟨fun h => h ▸ isOpen_interior, IsOpen.interior_eq⟩ #align interior_eq_iff_is_open interior_eq_iff_isOpen theorem subset_interior_iff_isOpen : s ⊆ interior s ↔ IsOpen s := by simp only [interior_eq_iff_isOpen.symm, Subset.antisymm_iff, interior_subset, true_and] #align subset_interior_iff_is_open subset_interior_iff_isOpen theorem IsOpen.subset_interior_iff (h₁ : IsOpen s) : s ⊆ interior t ↔ s ⊆ t := ⟨fun h => Subset.trans h interior_subset, fun h₂ => interior_maximal h₂ h₁⟩ #align is_open.subset_interior_iff IsOpen.subset_interior_iff theorem subset_interior_iff : t ⊆ interior s ↔ ∃ U, IsOpen U ∧ t ⊆ U ∧ U ⊆ s := ⟨fun h => ⟨interior s, isOpen_interior, h, interior_subset⟩, fun ⟨_U, hU, htU, hUs⟩ => htU.trans (interior_maximal hUs hU)⟩ #align subset_interior_iff subset_interior_iff lemma interior_subset_iff : interior s ⊆ t ↔ ∀ U, IsOpen U → U ⊆ s → U ⊆ t := by simp [interior] @[mono, gcongr] theorem interior_mono (h : s ⊆ t) : interior s ⊆ interior t := interior_maximal (Subset.trans interior_subset h) isOpen_interior #align interior_mono interior_mono @[simp] theorem interior_empty : interior (∅ : Set X) = ∅ := isOpen_empty.interior_eq #align interior_empty interior_empty @[simp] theorem interior_univ : interior (univ : Set X) = univ := isOpen_univ.interior_eq #align interior_univ interior_univ @[simp] theorem interior_eq_univ : interior s = univ ↔ s = univ := ⟨fun h => univ_subset_iff.mp <| h.symm.trans_le interior_subset, fun h => h.symm ▸ interior_univ⟩ #align interior_eq_univ interior_eq_univ @[simp] theorem interior_interior : interior (interior s) = interior s := isOpen_interior.interior_eq #align interior_interior interior_interior @[simp] theorem interior_inter : interior (s ∩ t) = interior s ∩ interior t := (Monotone.map_inf_le (fun _ _ ↦ interior_mono) s t).antisymm <| interior_maximal (inter_subset_inter interior_subset interior_subset) <| isOpen_interior.inter isOpen_interior #align interior_inter interior_inter theorem Set.Finite.interior_biInter {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := hs.induction_on (by simp) <| by intros; simp [*] theorem Set.Finite.interior_sInter {S : Set (Set X)} (hS : S.Finite) : interior (⋂₀ S) = ⋂ s ∈ S, interior s := by rw [sInter_eq_biInter, hS.interior_biInter] @[simp] theorem Finset.interior_iInter {ι : Type*} (s : Finset ι) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := s.finite_toSet.interior_biInter f #align finset.interior_Inter Finset.interior_iInter @[simp] theorem interior_iInter_of_finite [Finite ι] (f : ι → Set X) : interior (⋂ i, f i) = ⋂ i, interior (f i) := by rw [← sInter_range, (finite_range f).interior_sInter, biInter_range] #align interior_Inter interior_iInter_of_finite theorem interior_union_isClosed_of_interior_empty (h₁ : IsClosed s) (h₂ : interior t = ∅) : interior (s ∪ t) = interior s := have : interior (s ∪ t) ⊆ s := fun x ⟨u, ⟨(hu₁ : IsOpen u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩ => by_contradiction fun hx₂ : x ∉ s => have : u \ s ⊆ t := fun x ⟨h₁, h₂⟩ => Or.resolve_left (hu₂ h₁) h₂ have : u \ s ⊆ interior t := by rwa [(IsOpen.sdiff hu₁ h₁).subset_interior_iff] have : u \ s ⊆ ∅ := by rwa [h₂] at this this ⟨hx₁, hx₂⟩ Subset.antisymm (interior_maximal this isOpen_interior) (interior_mono subset_union_left) #align interior_union_is_closed_of_interior_empty interior_union_isClosed_of_interior_empty theorem isOpen_iff_forall_mem_open : IsOpen s ↔ ∀ x ∈ s, ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t := by rw [← subset_interior_iff_isOpen] simp only [subset_def, mem_interior] #align is_open_iff_forall_mem_open isOpen_iff_forall_mem_open theorem interior_iInter_subset (s : ι → Set X) : interior (⋂ i, s i) ⊆ ⋂ i, interior (s i) := subset_iInter fun _ => interior_mono <| iInter_subset _ _ #align interior_Inter_subset interior_iInter_subset theorem interior_iInter₂_subset (p : ι → Sort*) (s : ∀ i, p i → Set X) : interior (⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), interior (s i j) := (interior_iInter_subset _).trans <| iInter_mono fun _ => interior_iInter_subset _ #align interior_Inter₂_subset interior_iInter₂_subset theorem interior_sInter_subset (S : Set (Set X)) : interior (⋂₀ S) ⊆ ⋂ s ∈ S, interior s := calc interior (⋂₀ S) = interior (⋂ s ∈ S, s) := by rw [sInter_eq_biInter] _ ⊆ ⋂ s ∈ S, interior s := interior_iInter₂_subset _ _ #align interior_sInter_subset interior_sInter_subset theorem Filter.HasBasis.lift'_interior {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) : (l.lift' interior).HasBasis p fun i => interior (s i) := h.lift' fun _ _ ↦ interior_mono theorem Filter.lift'_interior_le (l : Filter X) : l.lift' interior ≤ l := fun _s hs ↦ mem_of_superset (mem_lift' hs) interior_subset theorem Filter.HasBasis.lift'_interior_eq_self {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) (ho : ∀ i, p i → IsOpen (s i)) : l.lift' interior = l := le_antisymm l.lift'_interior_le <| h.lift'_interior.ge_iff.2 fun i hi ↦ by simpa only [(ho i hi).interior_eq] using h.mem_of_mem hi /-! ### Closure of a set -/ @[simp] theorem isClosed_closure : IsClosed (closure s) := isClosed_sInter fun _ => And.left #align is_closed_closure isClosed_closure theorem subset_closure : s ⊆ closure s := subset_sInter fun _ => And.right #align subset_closure subset_closure theorem not_mem_of_not_mem_closure {P : X} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) #align not_mem_of_not_mem_closure not_mem_of_not_mem_closure theorem closure_minimal (h₁ : s ⊆ t) (h₂ : IsClosed t) : closure s ⊆ t := sInter_subset_of_mem ⟨h₂, h₁⟩ #align closure_minimal closure_minimal theorem Disjoint.closure_left (hd : Disjoint s t) (ht : IsOpen t) : Disjoint (closure s) t := disjoint_compl_left.mono_left <| closure_minimal hd.subset_compl_right ht.isClosed_compl #align disjoint.closure_left Disjoint.closure_left theorem Disjoint.closure_right (hd : Disjoint s t) (hs : IsOpen s) : Disjoint s (closure t) := (hd.symm.closure_left hs).symm #align disjoint.closure_right Disjoint.closure_right theorem IsClosed.closure_eq (h : IsClosed s) : closure s = s := Subset.antisymm (closure_minimal (Subset.refl s) h) subset_closure #align is_closed.closure_eq IsClosed.closure_eq theorem IsClosed.closure_subset (hs : IsClosed s) : closure s ⊆ s := closure_minimal (Subset.refl _) hs #align is_closed.closure_subset IsClosed.closure_subset theorem IsClosed.closure_subset_iff (h₁ : IsClosed t) : closure s ⊆ t ↔ s ⊆ t := ⟨Subset.trans subset_closure, fun h => closure_minimal h h₁⟩ #align is_closed.closure_subset_iff IsClosed.closure_subset_iff theorem IsClosed.mem_iff_closure_subset (hs : IsClosed s) : x ∈ s ↔ closure ({x} : Set X) ⊆ s := (hs.closure_subset_iff.trans Set.singleton_subset_iff).symm #align is_closed.mem_iff_closure_subset IsClosed.mem_iff_closure_subset @[mono, gcongr] theorem closure_mono (h : s ⊆ t) : closure s ⊆ closure t := closure_minimal (Subset.trans h subset_closure) isClosed_closure #align closure_mono closure_mono theorem monotone_closure (X : Type*) [TopologicalSpace X] : Monotone (@closure X _) := fun _ _ => closure_mono #align monotone_closure monotone_closure theorem diff_subset_closure_iff : s \ t ⊆ closure t ↔ s ⊆ closure t := by rw [diff_subset_iff, union_eq_self_of_subset_left subset_closure] #align diff_subset_closure_iff diff_subset_closure_iff theorem closure_inter_subset_inter_closure (s t : Set X) : closure (s ∩ t) ⊆ closure s ∩ closure t := (monotone_closure X).map_inf_le s t #align closure_inter_subset_inter_closure closure_inter_subset_inter_closure theorem isClosed_of_closure_subset (h : closure s ⊆ s) : IsClosed s := by rw [subset_closure.antisymm h]; exact isClosed_closure #align is_closed_of_closure_subset isClosed_of_closure_subset theorem closure_eq_iff_isClosed : closure s = s ↔ IsClosed s := ⟨fun h => h ▸ isClosed_closure, IsClosed.closure_eq⟩ #align closure_eq_iff_is_closed closure_eq_iff_isClosed theorem closure_subset_iff_isClosed : closure s ⊆ s ↔ IsClosed s := ⟨isClosed_of_closure_subset, IsClosed.closure_subset⟩ #align closure_subset_iff_is_closed closure_subset_iff_isClosed @[simp] theorem closure_empty : closure (∅ : Set X) = ∅ := isClosed_empty.closure_eq #align closure_empty closure_empty @[simp] theorem closure_empty_iff (s : Set X) : closure s = ∅ ↔ s = ∅ := ⟨subset_eq_empty subset_closure, fun h => h.symm ▸ closure_empty⟩ #align closure_empty_iff closure_empty_iff @[simp] theorem closure_nonempty_iff : (closure s).Nonempty ↔ s.Nonempty := by simp only [nonempty_iff_ne_empty, Ne, closure_empty_iff] #align closure_nonempty_iff closure_nonempty_iff alias ⟨Set.Nonempty.of_closure, Set.Nonempty.closure⟩ := closure_nonempty_iff #align set.nonempty.of_closure Set.Nonempty.of_closure #align set.nonempty.closure Set.Nonempty.closure @[simp] theorem closure_univ : closure (univ : Set X) = univ := isClosed_univ.closure_eq #align closure_univ closure_univ @[simp] theorem closure_closure : closure (closure s) = closure s := isClosed_closure.closure_eq #align closure_closure closure_closure theorem closure_eq_compl_interior_compl : closure s = (interior sᶜ)ᶜ := by rw [interior, closure, compl_sUnion, compl_image_set_of] simp only [compl_subset_compl, isOpen_compl_iff] #align closure_eq_compl_interior_compl closure_eq_compl_interior_compl @[simp] theorem closure_union : closure (s ∪ t) = closure s ∪ closure t := by simp [closure_eq_compl_interior_compl, compl_inter] #align closure_union closure_union theorem Set.Finite.closure_biUnion {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) : closure (⋃ i ∈ s, f i) = ⋃ i ∈ s, closure (f i) := by simp [closure_eq_compl_interior_compl, hs.interior_biInter] theorem Set.Finite.closure_sUnion {S : Set (Set X)} (hS : S.Finite) : closure (⋃₀ S) = ⋃ s ∈ S, closure s := by rw [sUnion_eq_biUnion, hS.closure_biUnion] @[simp] theorem Finset.closure_biUnion {ι : Type*} (s : Finset ι) (f : ι → Set X) : closure (⋃ i ∈ s, f i) = ⋃ i ∈ s, closure (f i) := s.finite_toSet.closure_biUnion f #align finset.closure_bUnion Finset.closure_biUnion @[simp] theorem closure_iUnion_of_finite [Finite ι] (f : ι → Set X) : closure (⋃ i, f i) = ⋃ i, closure (f i) := by rw [← sUnion_range, (finite_range _).closure_sUnion, biUnion_range] #align closure_Union closure_iUnion_of_finite theorem interior_subset_closure : interior s ⊆ closure s := Subset.trans interior_subset subset_closure #align interior_subset_closure interior_subset_closure @[simp] theorem interior_compl : interior sᶜ = (closure s)ᶜ := by simp [closure_eq_compl_interior_compl] #align interior_compl interior_compl @[simp] theorem closure_compl : closure sᶜ = (interior s)ᶜ := by simp [closure_eq_compl_interior_compl] #align closure_compl closure_compl theorem mem_closure_iff : x ∈ closure s ↔ ∀ o, IsOpen o → x ∈ o → (o ∩ s).Nonempty := ⟨fun h o oo ao => by_contradiction fun os => have : s ⊆ oᶜ := fun x xs xo => os ⟨x, xo, xs⟩ closure_minimal this (isClosed_compl_iff.2 oo) h ao, fun H _ ⟨h₁, h₂⟩ => by_contradiction fun nc => let ⟨_, hc, hs⟩ := H _ h₁.isOpen_compl nc hc (h₂ hs)⟩ #align mem_closure_iff mem_closure_iff theorem closure_inter_open_nonempty_iff (h : IsOpen t) : (closure s ∩ t).Nonempty ↔ (s ∩ t).Nonempty := ⟨fun ⟨_x, hxcs, hxt⟩ => inter_comm t s ▸ mem_closure_iff.1 hxcs t h hxt, fun h => h.mono <| inf_le_inf_right t subset_closure⟩ #align closure_inter_open_nonempty_iff closure_inter_open_nonempty_iff theorem Filter.le_lift'_closure (l : Filter X) : l ≤ l.lift' closure := le_lift'.2 fun _ h => mem_of_superset h subset_closure #align filter.le_lift'_closure Filter.le_lift'_closure theorem Filter.HasBasis.lift'_closure {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) : (l.lift' closure).HasBasis p fun i => closure (s i) := h.lift' (monotone_closure X) #align filter.has_basis.lift'_closure Filter.HasBasis.lift'_closure theorem Filter.HasBasis.lift'_closure_eq_self {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) (hc : ∀ i, p i → IsClosed (s i)) : l.lift' closure = l := le_antisymm (h.ge_iff.2 fun i hi => (hc i hi).closure_eq ▸ mem_lift' (h.mem_of_mem hi)) l.le_lift'_closure #align filter.has_basis.lift'_closure_eq_self Filter.HasBasis.lift'_closure_eq_self @[simp] theorem Filter.lift'_closure_eq_bot {l : Filter X} : l.lift' closure = ⊥ ↔ l = ⊥ := ⟨fun h => bot_unique <| h ▸ l.le_lift'_closure, fun h => h.symm ▸ by rw [lift'_bot (monotone_closure _), closure_empty, principal_empty]⟩ #align filter.lift'_closure_eq_bot Filter.lift'_closure_eq_bot theorem dense_iff_closure_eq : Dense s ↔ closure s = univ := eq_univ_iff_forall.symm #align dense_iff_closure_eq dense_iff_closure_eq alias ⟨Dense.closure_eq, _⟩ := dense_iff_closure_eq #align dense.closure_eq Dense.closure_eq theorem interior_eq_empty_iff_dense_compl : interior s = ∅ ↔ Dense sᶜ := by rw [dense_iff_closure_eq, closure_compl, compl_univ_iff] #align interior_eq_empty_iff_dense_compl interior_eq_empty_iff_dense_compl theorem Dense.interior_compl (h : Dense s) : interior sᶜ = ∅ := interior_eq_empty_iff_dense_compl.2 <| by rwa [compl_compl] #align dense.interior_compl Dense.interior_compl /-- The closure of a set `s` is dense if and only if `s` is dense. -/ @[simp] theorem dense_closure : Dense (closure s) ↔ Dense s := by rw [Dense, Dense, closure_closure] #align dense_closure dense_closure protected alias ⟨_, Dense.closure⟩ := dense_closure alias ⟨Dense.of_closure, _⟩ := dense_closure #align dense.of_closure Dense.of_closure #align dense.closure Dense.closure @[simp] theorem dense_univ : Dense (univ : Set X) := fun _ => subset_closure trivial #align dense_univ dense_univ /-- A set is dense if and only if it has a nonempty intersection with each nonempty open set. -/
Mathlib/Topology/Basic.lean
606
614
theorem dense_iff_inter_open : Dense s ↔ ∀ U, IsOpen U → U.Nonempty → (U ∩ s).Nonempty := by
constructor <;> intro h · rintro U U_op ⟨x, x_in⟩ exact mem_closure_iff.1 (h _) U U_op x_in · intro x rw [mem_closure_iff] intro U U_op x_in exact h U U_op ⟨_, x_in⟩
/- Copyright (c) 2021 Justus Springer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Justus Springer -/ import Mathlib.CategoryTheory.Sites.Spaces import Mathlib.Topology.Sheaves.Sheaf import Mathlib.CategoryTheory.Sites.DenseSubsite #align_import topology.sheaves.sheaf_condition.sites from "leanprover-community/mathlib"@"d39590fc8728fbf6743249802486f8c91ffe07bc" /-! # Coverings and sieves; from sheaves on sites and sheaves on spaces In this file, we connect coverings in a topological space to sieves in the associated Grothendieck topology, in preparation of connecting the sheaf condition on sites to the various sheaf conditions on spaces. We also specialize results about sheaves on sites to sheaves on spaces; we show that the inclusion functor from a topological basis to `TopologicalSpace.Opens` is cover dense, that open maps induce cover preserving functors, and that open embeddings induce continuous functors. -/ noncomputable section set_option linter.uppercaseLean3 false -- Porting note: Added because of too many false positives universe w v u open CategoryTheory TopologicalSpace namespace TopCat.Presheaf variable {X : TopCat.{w}} /-- Given a presieve `R` on `U`, we obtain a covering family of open sets in `X`, by taking as index type the type of dependent pairs `(V, f)`, where `f : V ⟶ U` is in `R`. -/ def coveringOfPresieve (U : Opens X) (R : Presieve U) : (ΣV, { f : V ⟶ U // R f }) → Opens X := fun f => f.1 #align Top.presheaf.covering_of_presieve TopCat.Presheaf.coveringOfPresieve @[simp] theorem coveringOfPresieve_apply (U : Opens X) (R : Presieve U) (f : ΣV, { f : V ⟶ U // R f }) : coveringOfPresieve U R f = f.1 := rfl #align Top.presheaf.covering_of_presieve_apply TopCat.Presheaf.coveringOfPresieve_apply namespace coveringOfPresieve variable (U : Opens X) (R : Presieve U) /-- If `R` is a presieve in the grothendieck topology on `Opens X`, the covering family associated to `R` really is _covering_, i.e. the union of all open sets equals `U`. -/ theorem iSup_eq_of_mem_grothendieck (hR : Sieve.generate R ∈ Opens.grothendieckTopology X U) : iSup (coveringOfPresieve U R) = U := by apply le_antisymm · refine iSup_le ?_ intro f exact f.2.1.le intro x hxU rw [Opens.coe_iSup, Set.mem_iUnion] obtain ⟨V, iVU, ⟨W, iVW, iWU, hiWU, -⟩, hxV⟩ := hR x hxU exact ⟨⟨W, ⟨iWU, hiWU⟩⟩, iVW.le hxV⟩ #align Top.presheaf.covering_of_presieve.supr_eq_of_mem_grothendieck TopCat.Presheaf.coveringOfPresieve.iSup_eq_of_mem_grothendieck end coveringOfPresieve /-- Given a family of opens `U : ι → Opens X` and any open `Y : Opens X`, we obtain a presieve on `Y` by declaring that a morphism `f : V ⟶ Y` is a member of the presieve if and only if there exists an index `i : ι` such that `V = U i`. -/ def presieveOfCoveringAux {ι : Type v} (U : ι → Opens X) (Y : Opens X) : Presieve Y := fun V _ => ∃ i, V = U i #align Top.presheaf.presieve_of_covering_aux TopCat.Presheaf.presieveOfCoveringAux /-- Take `Y` to be `iSup U` and obtain a presieve over `iSup U`. -/ def presieveOfCovering {ι : Type v} (U : ι → Opens X) : Presieve (iSup U) := presieveOfCoveringAux U (iSup U) #align Top.presheaf.presieve_of_covering TopCat.Presheaf.presieveOfCovering /-- Given a presieve `R` on `Y`, if we take its associated family of opens via `coveringOfPresieve` (which may not cover `Y` if `R` is not covering), and take the presieve on `Y` associated to the family of opens via `presieveOfCoveringAux`, then we get back the original presieve `R`. -/ @[simp] theorem covering_presieve_eq_self {Y : Opens X} (R : Presieve Y) : presieveOfCoveringAux (coveringOfPresieve Y R) Y = R := by funext Z ext f exact ⟨fun ⟨⟨_, f', h⟩, rfl⟩ => by rwa [Subsingleton.elim f f'], fun h => ⟨⟨Z, f, h⟩, rfl⟩⟩ #align Top.presheaf.covering_presieve_eq_self TopCat.Presheaf.covering_presieve_eq_self namespace presieveOfCovering variable {ι : Type v} (U : ι → Opens X) /-- The sieve generated by `presieveOfCovering U` is a member of the grothendieck topology. -/ theorem mem_grothendieckTopology : Sieve.generate (presieveOfCovering U) ∈ Opens.grothendieckTopology X (iSup U) := by intro x hx obtain ⟨i, hxi⟩ := Opens.mem_iSup.mp hx exact ⟨U i, Opens.leSupr U i, ⟨U i, 𝟙 _, Opens.leSupr U i, ⟨i, rfl⟩, Category.id_comp _⟩, hxi⟩ #align Top.presheaf.presieve_of_covering.mem_grothendieck_topology TopCat.Presheaf.presieveOfCovering.mem_grothendieckTopology /-- An index `i : ι` can be turned into a dependent pair `(V, f)`, where `V` is an open set and `f : V ⟶ iSup U` is a member of `presieveOfCovering U f`. -/ def homOfIndex (i : ι) : ΣV, { f : V ⟶ iSup U // presieveOfCovering U f } := ⟨U i, Opens.leSupr U i, i, rfl⟩ #align Top.presheaf.presieve_of_covering.hom_of_index TopCat.Presheaf.presieveOfCovering.homOfIndex /-- By using the axiom of choice, a dependent pair `(V, f)` where `f : V ⟶ iSup U` is a member of `presieveOfCovering U f` can be turned into an index `i : ι`, such that `V = U i`. -/ def indexOfHom (f : ΣV, { f : V ⟶ iSup U // presieveOfCovering U f }) : ι := f.2.2.choose #align Top.presheaf.presieve_of_covering.index_of_hom TopCat.Presheaf.presieveOfCovering.indexOfHom theorem indexOfHom_spec (f : ΣV, { f : V ⟶ iSup U // presieveOfCovering U f }) : f.1 = U (indexOfHom U f) := f.2.2.choose_spec #align Top.presheaf.presieve_of_covering.index_of_hom_spec TopCat.Presheaf.presieveOfCovering.indexOfHom_spec end presieveOfCovering end TopCat.Presheaf namespace TopCat.Opens variable {X : TopCat} {ι : Type*} theorem coverDense_iff_isBasis [Category ι] (B : ι ⥤ Opens X) : B.IsCoverDense (Opens.grothendieckTopology X) ↔ Opens.IsBasis (Set.range B.obj) := by rw [Opens.isBasis_iff_nbhd] constructor · intro hd U x hx; rcases hd.1 U x hx with ⟨V, f, ⟨i, f₁, f₂, _⟩, hV⟩ exact ⟨B.obj i, ⟨i, rfl⟩, f₁.le hV, f₂.le⟩ intro hb; constructor; intro U x hx; rcases hb hx with ⟨_, ⟨i, rfl⟩, hx, hi⟩ exact ⟨B.obj i, ⟨⟨hi⟩⟩, ⟨⟨i, 𝟙 _, ⟨⟨hi⟩⟩, rfl⟩⟩, hx⟩ #align Top.opens.cover_dense_iff_is_basis TopCat.Opens.coverDense_iff_isBasis theorem coverDense_inducedFunctor {B : ι → Opens X} (h : Opens.IsBasis (Set.range B)) : (inducedFunctor B).IsCoverDense (Opens.grothendieckTopology X) := (coverDense_iff_isBasis _).2 h #align Top.opens.cover_dense_induced_functor TopCat.Opens.coverDense_inducedFunctor end TopCat.Opens section OpenEmbedding open TopCat.Presheaf Opposite variable {C : Type u} [Category.{v} C] variable {X Y : TopCat.{w}} {f : X ⟶ Y} {F : Y.Presheaf C} theorem OpenEmbedding.compatiblePreserving (hf : OpenEmbedding f) : CompatiblePreserving (Opens.grothendieckTopology Y) hf.isOpenMap.functor := by haveI : Mono f := (TopCat.mono_iff_injective f).mpr hf.inj apply compatiblePreservingOfDownwardsClosed intro U V i refine ⟨(Opens.map f).obj V, eqToIso <| Opens.ext <| Set.image_preimage_eq_of_subset fun x h ↦ ?_⟩ obtain ⟨_, _, rfl⟩ := i.le h exact ⟨_, rfl⟩ #align open_embedding.compatible_preserving OpenEmbedding.compatiblePreserving theorem IsOpenMap.coverPreserving (hf : IsOpenMap f) : CoverPreserving (Opens.grothendieckTopology X) (Opens.grothendieckTopology Y) hf.functor := by constructor rintro U S hU _ ⟨x, hx, rfl⟩ obtain ⟨V, i, hV, hxV⟩ := hU x hx exact ⟨_, hf.functor.map i, ⟨_, i, 𝟙 _, hV, rfl⟩, Set.mem_image_of_mem f hxV⟩ #align is_open_map.cover_preserving IsOpenMap.coverPreserving lemma OpenEmbedding.functor_isContinuous (h : OpenEmbedding f) : h.isOpenMap.functor.IsContinuous (Opens.grothendieckTopology X) (Opens.grothendieckTopology Y) := by apply Functor.isContinuous_of_coverPreserving · exact h.compatiblePreserving · exact h.isOpenMap.coverPreserving theorem TopCat.Presheaf.isSheaf_of_openEmbedding (h : OpenEmbedding f) (hF : F.IsSheaf) : IsSheaf (h.isOpenMap.functor.op ⋙ F) := by have := h.functor_isContinuous exact Functor.op_comp_isSheaf _ _ _ ⟨_, hF⟩ #align Top.presheaf.is_sheaf_of_open_embedding TopCat.Presheaf.isSheaf_of_openEmbedding variable (f) instance : RepresentablyFlat (Opens.map f) := by constructor intro U refine @IsCofiltered.mk _ _ ?_ ?_ · constructor · intro V W exact ⟨⟨⟨PUnit.unit⟩, V.right ⊓ W.right, homOfLE <| le_inf V.hom.le W.hom.le⟩, StructuredArrow.homMk (homOfLE inf_le_left), StructuredArrow.homMk (homOfLE inf_le_right), trivial⟩ · exact fun _ _ _ _ ↦ ⟨_, 𝟙 _, by simp [eq_iff_true_of_subsingleton]⟩ · exact ⟨StructuredArrow.mk <| show U ⟶ (Opens.map f).obj ⊤ from homOfLE le_top⟩ theorem compatiblePreserving_opens_map : CompatiblePreserving (Opens.grothendieckTopology X) (Opens.map f) := compatiblePreservingOfFlat _ _ theorem coverPreserving_opens_map : CoverPreserving (Opens.grothendieckTopology Y) (Opens.grothendieckTopology X) (Opens.map f) := by constructor intro U S hS x hx obtain ⟨V, i, hi, hxV⟩ := hS (f x) hx exact ⟨_, (Opens.map f).map i, ⟨_, _, 𝟙 _, hi, Subsingleton.elim _ _⟩, hxV⟩ instance : (Opens.map f).IsContinuous (Opens.grothendieckTopology Y) (Opens.grothendieckTopology X) := by apply Functor.isContinuous_of_coverPreserving · exact compatiblePreserving_opens_map f · exact coverPreserving_opens_map f end OpenEmbedding namespace TopCat.Sheaf open TopCat Opposite variable {C : Type u} [Category.{v} C] variable {X : TopCat.{w}} {ι : Type*} {B : ι → Opens X} variable (F : X.Presheaf C) (F' : Sheaf C X) (h : Opens.IsBasis (Set.range B)) /-- The empty component of a sheaf is terminal. -/ def isTerminalOfEmpty (F : Sheaf C X) : Limits.IsTerminal (F.val.obj (op ⊥)) := F.isTerminalOfBotCover ⊥ (fun _ h => h.elim) #align Top.sheaf.is_terminal_of_empty TopCat.Sheaf.isTerminalOfEmpty /-- A variant of `isTerminalOfEmpty` that is easier to `apply`. -/ def isTerminalOfEqEmpty (F : X.Sheaf C) {U : Opens X} (h : U = ⊥) : Limits.IsTerminal (F.val.obj (op U)) := by convert F.isTerminalOfEmpty #align Top.sheaf.is_terminal_of_eq_empty TopCat.Sheaf.isTerminalOfEqEmpty /-- If a family `B` of open sets forms a basis of the topology on `X`, and if `F'` is a sheaf on `X`, then a homomorphism between a presheaf `F` on `X` and `F'` is equivalent to a homomorphism between their restrictions to the indexing type `ι` of `B`, with the induced category structure on `ι`. -/ def restrictHomEquivHom : ((inducedFunctor B).op ⋙ F ⟶ (inducedFunctor B).op ⋙ F'.1) ≃ (F ⟶ F'.1) := @Functor.IsCoverDense.restrictHomEquivHom _ _ _ _ _ _ _ _ (Opens.coverDense_inducedFunctor h) _ F F' #align Top.sheaf.restrict_hom_equiv_hom TopCat.Sheaf.restrictHomEquivHom @[simp] theorem extend_hom_app (α : (inducedFunctor B).op ⋙ F ⟶ (inducedFunctor B).op ⋙ F'.1) (i : ι) : (restrictHomEquivHom F F' h α).app (op (B i)) = α.app (op i) := by nth_rw 2 [← (restrictHomEquivHom F F' h).left_inv α] rfl #align Top.sheaf.extend_hom_app TopCat.Sheaf.extend_hom_app
Mathlib/Topology/Sheaves/SheafCondition/Sites.lean
262
265
theorem hom_ext {α β : F ⟶ F'.1} (he : ∀ i, α.app (op (B i)) = β.app (op (B i))) : α = β := by
apply (restrictHomEquivHom F F' h).symm.injective ext i exact he i.unop
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Comma.StructuredArrow import Mathlib.CategoryTheory.IsConnected import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal import Mathlib.CategoryTheory.Limits.Shapes.Types import Mathlib.CategoryTheory.Filtered.Basic import Mathlib.CategoryTheory.Limits.Yoneda import Mathlib.CategoryTheory.PUnit #align_import category_theory.limits.final from "leanprover-community/mathlib"@"8a318021995877a44630c898d0b2bc376fceef3b" /-! # Final and initial functors A functor `F : C ⥤ D` is final if for every `d : D`, the comma category of morphisms `d ⟶ F.obj c` is connected. Dually, a functor `F : C ⥤ D` is initial if for every `d : D`, the comma category of morphisms `F.obj c ⟶ d` is connected. We show that right adjoints are examples of final functors, while left adjoints are examples of initial functors. For final functors, we prove that the following three statements are equivalent: 1. `F : C ⥤ D` is final. 2. Every functor `G : D ⥤ E` has a colimit if and only if `F ⋙ G` does, and these colimits are isomorphic via `colimit.pre G F`. 3. `colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit`. Starting at 1. we show (in `coconesEquiv`) that the categories of cocones over `G : D ⥤ E` and over `F ⋙ G` are equivalent. (In fact, via an equivalence which does not change the cocone point.) This readily implies 2., as `comp_hasColimit`, `hasColimit_of_comp`, and `colimitIso`. From 2. we can specialize to `G = coyoneda.obj (op d)` to obtain 3., as `colimitCompCoyonedaIso`. From 3., we prove 1. directly in `cofinal_of_colimit_comp_coyoneda_iso_pUnit`. Dually, we prove that if a functor `F : C ⥤ D` is initial, then any functor `G : D ⥤ E` has a limit if and only if `F ⋙ G` does, and these limits are isomorphic via `limit.pre G F`. ## Naming There is some discrepancy in the literature about naming; some say 'cofinal' instead of 'final'. The explanation for this is that the 'co' prefix here is *not* the usual category-theoretic one indicating duality, but rather indicating the sense of "along with". ## See also In `CategoryTheory.Filtered.Final` we give additional equivalent conditions in the case that `C` is filtered. ## Future work Dualise condition 3 above and the implications 2 ⇒ 3 and 3 ⇒ 1 to initial functors. ## References * https://stacks.math.columbia.edu/tag/09WN * https://ncatlab.org/nlab/show/final+functor * Borceux, Handbook of Categorical Algebra I, Section 2.11. (Note he reverses the roles of definition and main result relative to here!) -/ noncomputable section universe v v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory namespace Functor open Opposite open CategoryTheory.Limits section ArbitraryUniverse variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] /-- A functor `F : C ⥤ D` is final if for every `d : D`, the comma category of morphisms `d ⟶ F.obj c` is connected. See <https://stacks.math.columbia.edu/tag/04E6> -/ class Final (F : C ⥤ D) : Prop where out (d : D) : IsConnected (StructuredArrow d F) #align category_theory.functor.final CategoryTheory.Functor.Final attribute [instance] Final.out /-- A functor `F : C ⥤ D` is initial if for every `d : D`, the comma category of morphisms `F.obj c ⟶ d` is connected. -/ class Initial (F : C ⥤ D) : Prop where out (d : D) : IsConnected (CostructuredArrow F d) #align category_theory.functor.initial CategoryTheory.Functor.Initial attribute [instance] Initial.out instance final_op_of_initial (F : C ⥤ D) [Initial F] : Final F.op where out d := isConnected_of_equivalent (costructuredArrowOpEquivalence F (unop d)) #align category_theory.functor.final_op_of_initial CategoryTheory.Functor.final_op_of_initial instance initial_op_of_final (F : C ⥤ D) [Final F] : Initial F.op where out d := isConnected_of_equivalent (structuredArrowOpEquivalence F (unop d)) #align category_theory.functor.initial_op_of_final CategoryTheory.Functor.initial_op_of_final theorem final_of_initial_op (F : C ⥤ D) [Initial F.op] : Final F := { out := fun d => @isConnected_of_isConnected_op _ _ (isConnected_of_equivalent (structuredArrowOpEquivalence F d).symm) } #align category_theory.functor.final_of_initial_op CategoryTheory.Functor.final_of_initial_op theorem initial_of_final_op (F : C ⥤ D) [Final F.op] : Initial F := { out := fun d => @isConnected_of_isConnected_op _ _ (isConnected_of_equivalent (costructuredArrowOpEquivalence F d).symm) } #align category_theory.functor.initial_of_final_op CategoryTheory.Functor.initial_of_final_op /-- If a functor `R : D ⥤ C` is a right adjoint, it is final. -/ theorem final_of_adjunction {L : C ⥤ D} {R : D ⥤ C} (adj : L ⊣ R) : Final R := { out := fun c => let u : StructuredArrow c R := StructuredArrow.mk (adj.unit.app c) @zigzag_isConnected _ _ ⟨u⟩ fun f g => Relation.ReflTransGen.trans (Relation.ReflTransGen.single (show Zag f u from Or.inr ⟨StructuredArrow.homMk ((adj.homEquiv c f.right).symm f.hom) (by simp [u])⟩)) (Relation.ReflTransGen.single (show Zag u g from Or.inl ⟨StructuredArrow.homMk ((adj.homEquiv c g.right).symm g.hom) (by simp [u])⟩)) } #align category_theory.functor.final_of_adjunction CategoryTheory.Functor.final_of_adjunction /-- If a functor `L : C ⥤ D` is a left adjoint, it is initial. -/ theorem initial_of_adjunction {L : C ⥤ D} {R : D ⥤ C} (adj : L ⊣ R) : Initial L := { out := fun d => let u : CostructuredArrow L d := CostructuredArrow.mk (adj.counit.app d) @zigzag_isConnected _ _ ⟨u⟩ fun f g => Relation.ReflTransGen.trans (Relation.ReflTransGen.single (show Zag f u from Or.inl ⟨CostructuredArrow.homMk (adj.homEquiv f.left d f.hom) (by simp [u])⟩)) (Relation.ReflTransGen.single (show Zag u g from Or.inr ⟨CostructuredArrow.homMk (adj.homEquiv g.left d g.hom) (by simp [u])⟩)) } #align category_theory.functor.initial_of_adjunction CategoryTheory.Functor.initial_of_adjunction instance (priority := 100) final_of_isRightAdjoint (F : C ⥤ D) [IsRightAdjoint F] : Final F := final_of_adjunction (Adjunction.ofIsRightAdjoint F) #align category_theory.functor.final_of_is_right_adjoint CategoryTheory.Functor.final_of_isRightAdjoint instance (priority := 100) initial_of_isLeftAdjoint (F : C ⥤ D) [IsLeftAdjoint F] : Initial F := initial_of_adjunction (Adjunction.ofIsLeftAdjoint F) #align category_theory.functor.initial_of_is_left_adjoint CategoryTheory.Functor.initial_of_isLeftAdjoint theorem final_of_natIso {F F' : C ⥤ D} [Final F] (i : F ≅ F') : Final F' where out _ := isConnected_of_equivalent (StructuredArrow.mapNatIso i) theorem final_natIso_iff {F F' : C ⥤ D} (i : F ≅ F') : Final F ↔ Final F' := ⟨fun _ => final_of_natIso i, fun _ => final_of_natIso i.symm⟩ theorem initial_of_natIso {F F' : C ⥤ D} [Initial F] (i : F ≅ F') : Initial F' where out _ := isConnected_of_equivalent (CostructuredArrow.mapNatIso i) theorem initial_natIso_iff {F F' : C ⥤ D} (i : F ≅ F') : Initial F ↔ Initial F' := ⟨fun _ => initial_of_natIso i, fun _ => initial_of_natIso i.symm⟩ namespace Final variable (F : C ⥤ D) [Final F] instance (d : D) : Nonempty (StructuredArrow d F) := IsConnected.is_nonempty variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- When `F : C ⥤ D` is cofinal, we denote by `lift F d` an arbitrary choice of object in `C` such that there exists a morphism `d ⟶ F.obj (lift F d)`. -/ def lift (d : D) : C := (Classical.arbitrary (StructuredArrow d F)).right #align category_theory.functor.final.lift CategoryTheory.Functor.Final.lift /-- When `F : C ⥤ D` is cofinal, we denote by `homToLift` an arbitrary choice of morphism `d ⟶ F.obj (lift F d)`. -/ def homToLift (d : D) : d ⟶ F.obj (lift F d) := (Classical.arbitrary (StructuredArrow d F)).hom #align category_theory.functor.final.hom_to_lift CategoryTheory.Functor.Final.homToLift /-- We provide an induction principle for reasoning about `lift` and `homToLift`. We want to perform some construction (usually just a proof) about the particular choices `lift F d` and `homToLift F d`, it suffices to perform that construction for some other pair of choices (denoted `X₀ : C` and `k₀ : d ⟶ F.obj X₀` below), and to show how to transport such a construction *both* directions along a morphism between such choices. -/ def induction {d : D} (Z : ∀ (X : C) (_ : d ⟶ F.obj X), Sort*) (h₁ : ∀ (X₁ X₂) (k₁ : d ⟶ F.obj X₁) (k₂ : d ⟶ F.obj X₂) (f : X₁ ⟶ X₂), k₁ ≫ F.map f = k₂ → Z X₁ k₁ → Z X₂ k₂) (h₂ : ∀ (X₁ X₂) (k₁ : d ⟶ F.obj X₁) (k₂ : d ⟶ F.obj X₂) (f : X₁ ⟶ X₂), k₁ ≫ F.map f = k₂ → Z X₂ k₂ → Z X₁ k₁) {X₀ : C} {k₀ : d ⟶ F.obj X₀} (z : Z X₀ k₀) : Z (lift F d) (homToLift F d) := by apply Nonempty.some apply @isPreconnected_induction _ _ _ (fun Y : StructuredArrow d F => Z Y.right Y.hom) _ _ (StructuredArrow.mk k₀) z · intro j₁ j₂ f a fapply h₁ _ _ _ _ f.right _ a convert f.w.symm dsimp simp · intro j₁ j₂ f a fapply h₂ _ _ _ _ f.right _ a convert f.w.symm dsimp simp #align category_theory.functor.final.induction CategoryTheory.Functor.Final.induction variable {F G} /-- Given a cocone over `F ⋙ G`, we can construct a `Cocone G` with the same cocone point. -/ @[simps] def extendCocone : Cocone (F ⋙ G) ⥤ Cocone G where obj c := { pt := c.pt ι := { app := fun X => G.map (homToLift F X) ≫ c.ι.app (lift F X) naturality := fun X Y f => by dsimp; simp -- This would be true if we'd chosen `lift F X` to be `lift F Y` -- and `homToLift F X` to be `f ≫ homToLift F Y`. apply induction F fun Z k => G.map f ≫ G.map (homToLift F Y) ≫ c.ι.app (lift F Y) = G.map k ≫ c.ι.app Z · intro Z₁ Z₂ k₁ k₂ g a z rw [← a, Functor.map_comp, Category.assoc, ← Functor.comp_map, c.w, z] · intro Z₁ Z₂ k₁ k₂ g a z rw [← a, Functor.map_comp, Category.assoc, ← Functor.comp_map, c.w] at z rw [z] · rw [← Functor.map_comp_assoc] } } map f := { hom := f.hom } #align category_theory.functor.final.extend_cocone CategoryTheory.Functor.Final.extendCocone @[simp] theorem colimit_cocone_comp_aux (s : Cocone (F ⋙ G)) (j : C) : G.map (homToLift F (F.obj j)) ≫ s.ι.app (lift F (F.obj j)) = s.ι.app j := by -- This point is that this would be true if we took `lift (F.obj j)` to just be `j` -- and `homToLift (F.obj j)` to be `𝟙 (F.obj j)`. apply induction F fun X k => G.map k ≫ s.ι.app X = (s.ι.app j : _) · intro j₁ j₂ k₁ k₂ f w h rw [← w] rw [← s.w f] at h simpa using h · intro j₁ j₂ k₁ k₂ f w h rw [← w] at h rw [← s.w f] simpa using h · exact s.w (𝟙 _) #align category_theory.functor.final.colimit_cocone_comp_aux CategoryTheory.Functor.Final.colimit_cocone_comp_aux variable (F G) /-- If `F` is cofinal, the category of cocones on `F ⋙ G` is equivalent to the category of cocones on `G`, for any `G : D ⥤ E`. -/ @[simps] def coconesEquiv : Cocone (F ⋙ G) ≌ Cocone G where functor := extendCocone inverse := Cocones.whiskering F unitIso := NatIso.ofComponents fun c => Cocones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun c => Cocones.ext (Iso.refl _) #align category_theory.functor.final.cocones_equiv CategoryTheory.Functor.Final.coconesEquiv variable {G} /-- When `F : C ⥤ D` is cofinal, and `t : Cocone G` for some `G : D ⥤ E`, `t.whisker F` is a colimit cocone exactly when `t` is. -/ def isColimitWhiskerEquiv (t : Cocone G) : IsColimit (t.whisker F) ≃ IsColimit t := IsColimit.ofCoconeEquiv (coconesEquiv F G).symm #align category_theory.functor.final.is_colimit_whisker_equiv CategoryTheory.Functor.Final.isColimitWhiskerEquiv /-- When `F` is cofinal, and `t : Cocone (F ⋙ G)`, `extendCocone.obj t` is a colimit cocone exactly when `t` is. -/ def isColimitExtendCoconeEquiv (t : Cocone (F ⋙ G)) : IsColimit (extendCocone.obj t) ≃ IsColimit t := IsColimit.ofCoconeEquiv (coconesEquiv F G) #align category_theory.functor.final.is_colimit_extend_cocone_equiv CategoryTheory.Functor.Final.isColimitExtendCoconeEquiv /-- Given a colimit cocone over `G : D ⥤ E` we can construct a colimit cocone over `F ⋙ G`. -/ @[simps] def colimitCoconeComp (t : ColimitCocone G) : ColimitCocone (F ⋙ G) where cocone := _ isColimit := (isColimitWhiskerEquiv F _).symm t.isColimit #align category_theory.functor.final.colimit_cocone_comp CategoryTheory.Functor.Final.colimitCoconeComp instance (priority := 100) comp_hasColimit [HasColimit G] : HasColimit (F ⋙ G) := HasColimit.mk (colimitCoconeComp F (getColimitCocone G)) #align category_theory.functor.final.comp_has_colimit CategoryTheory.Functor.Final.comp_hasColimit instance colimit_pre_isIso [HasColimit G] : IsIso (colimit.pre G F) := by rw [colimit.pre_eq (colimitCoconeComp F (getColimitCocone G)) (getColimitCocone G)] erw [IsColimit.desc_self] dsimp infer_instance #align category_theory.functor.final.colimit_pre_is_iso CategoryTheory.Functor.Final.colimit_pre_isIso section variable (G) /-- When `F : C ⥤ D` is cofinal, and `G : D ⥤ E` has a colimit, then `F ⋙ G` has a colimit also and `colimit (F ⋙ G) ≅ colimit G` https://stacks.math.columbia.edu/tag/04E7 -/ def colimitIso [HasColimit G] : colimit (F ⋙ G) ≅ colimit G := asIso (colimit.pre G F) #align category_theory.functor.final.colimit_iso CategoryTheory.Functor.Final.colimitIso end /-- Given a colimit cocone over `F ⋙ G` we can construct a colimit cocone over `G`. -/ @[simps] def colimitCoconeOfComp (t : ColimitCocone (F ⋙ G)) : ColimitCocone G where cocone := extendCocone.obj t.cocone isColimit := (isColimitExtendCoconeEquiv F _).symm t.isColimit #align category_theory.functor.final.colimit_cocone_of_comp CategoryTheory.Functor.Final.colimitCoconeOfComp /-- When `F` is cofinal, and `F ⋙ G` has a colimit, then `G` has a colimit also. We can't make this an instance, because `F` is not determined by the goal. (Even if this weren't a problem, it would cause a loop with `comp_hasColimit`.) -/ theorem hasColimit_of_comp [HasColimit (F ⋙ G)] : HasColimit G := HasColimit.mk (colimitCoconeOfComp F (getColimitCocone (F ⋙ G))) #align category_theory.functor.final.has_colimit_of_comp CategoryTheory.Functor.Final.hasColimit_of_comp theorem hasColimitsOfShape_of_final [HasColimitsOfShape C E] : HasColimitsOfShape D E where has_colimit := fun _ => hasColimit_of_comp F section -- Porting note: this instance does not seem to be found automatically --attribute [local instance] hasColimit_of_comp /-- When `F` is cofinal, and `F ⋙ G` has a colimit, then `G` has a colimit also and `colimit (F ⋙ G) ≅ colimit G` https://stacks.math.columbia.edu/tag/04E7 -/ def colimitIso' [HasColimit (F ⋙ G)] : haveI : HasColimit G := hasColimit_of_comp F; colimit (F ⋙ G) ≅ colimit G := haveI : HasColimit G := hasColimit_of_comp F; asIso (colimit.pre G F) #align category_theory.functor.final.colimit_iso' CategoryTheory.Functor.Final.colimitIso' end end Final end ArbitraryUniverse section LocallySmall variable {C : Type v} [Category.{v} C] {D : Type u₁} [Category.{v} D] (F : C ⥤ D) namespace Final theorem zigzag_of_eqvGen_quot_rel {F : C ⥤ D} {d : D} {f₁ f₂ : ΣX, d ⟶ F.obj X} (t : EqvGen (Types.Quot.Rel.{v, v} (F ⋙ coyoneda.obj (op d))) f₁ f₂) : Zigzag (StructuredArrow.mk f₁.2) (StructuredArrow.mk f₂.2) := by induction t with | rel x y r => obtain ⟨f, w⟩ := r fconstructor swap · fconstructor left; fconstructor exact StructuredArrow.homMk f | refl => fconstructor | symm x y _ ih => apply zigzag_symmetric exact ih | trans x y z _ _ ih₁ ih₂ => apply Relation.ReflTransGen.trans · exact ih₁ · exact ih₂ #align category_theory.functor.final.zigzag_of_eqv_gen_quot_rel CategoryTheory.Functor.Final.zigzag_of_eqvGen_quot_rel end Final /-- If `colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit` for all `d : D`, then `F` is cofinal. -/ theorem cofinal_of_colimit_comp_coyoneda_iso_pUnit (I : ∀ d, colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit) : Final F := ⟨fun d => by have : Nonempty (StructuredArrow d F) := by have := (I d).inv PUnit.unit obtain ⟨j, y, rfl⟩ := Limits.Types.jointly_surjective'.{v, v} this exact ⟨StructuredArrow.mk y⟩ apply zigzag_isConnected rintro ⟨⟨⟨⟩⟩, X₁, f₁⟩ ⟨⟨⟨⟩⟩, X₂, f₂⟩ let y₁ := colimit.ι (F ⋙ coyoneda.obj (op d)) X₁ f₁ let y₂ := colimit.ι (F ⋙ coyoneda.obj (op d)) X₂ f₂ have e : y₁ = y₂ := by apply (I d).toEquiv.injective ext have t := Types.colimit_eq.{v, v} e clear e y₁ y₂ exact Final.zigzag_of_eqvGen_quot_rel t⟩ #align category_theory.functor.final.cofinal_of_colimit_comp_coyoneda_iso_punit CategoryTheory.Functor.cofinal_of_colimit_comp_coyoneda_iso_pUnit /-- A variant of `cofinal_of_colimit_comp_coyoneda_iso_pUnit` where we bind the various claims about `colimit (F ⋙ coyoneda.obj (Opposite.op d))` for each `d : D` into a single claim about the presheaf `colimit (F ⋙ yoneda)`. -/ theorem cofinal_of_isTerminal_colimit_comp_yoneda (h : IsTerminal (colimit (F ⋙ yoneda))) : Final F := by refine cofinal_of_colimit_comp_coyoneda_iso_pUnit _ (fun d => ?_) refine Types.isTerminalEquivIsoPUnit _ ?_ let b := IsTerminal.isTerminalObj ((evaluation _ _).obj (Opposite.op d)) _ h exact b.ofIso <| preservesColimitIso ((evaluation _ _).obj (Opposite.op d)) (F ⋙ yoneda) /-- If the universal morphism `colimit (F ⋙ coyoneda.obj (op d)) ⟶ colimit (coyoneda.obj (op d))` is an isomorphism (as it always is when `F` is cofinal), then `colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit` (simply because `colimit (coyoneda.obj (op d)) ≅ PUnit`). -/ def Final.colimitCompCoyonedaIso (d : D) [IsIso (colimit.pre (coyoneda.obj (op d)) F)] : colimit (F ⋙ coyoneda.obj (op d)) ≅ PUnit := asIso (colimit.pre (coyoneda.obj (op d)) F) ≪≫ Coyoneda.colimitCoyonedaIso (op d) #align category_theory.functor.final.colimit_comp_coyoneda_iso CategoryTheory.Functor.Final.colimitCompCoyonedaIso end LocallySmall section SmallCategory variable {C : Type v} [Category.{v} C] {D : Type v} [Category.{v} D] (F : C ⥤ D) theorem final_iff_isIso_colimit_pre : Final F ↔ ∀ G : D ⥤ Type v, IsIso (colimit.pre G F) := ⟨fun _ => inferInstance, fun _ => cofinal_of_colimit_comp_coyoneda_iso_pUnit _ fun _ => Final.colimitCompCoyonedaIso _ _⟩ end SmallCategory namespace Initial variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) [Initial F] instance (d : D) : Nonempty (CostructuredArrow F d) := IsConnected.is_nonempty variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- When `F : C ⥤ D` is initial, we denote by `lift F d` an arbitrary choice of object in `C` such that there exists a morphism `F.obj (lift F d) ⟶ d`. -/ def lift (d : D) : C := (Classical.arbitrary (CostructuredArrow F d)).left #align category_theory.functor.initial.lift CategoryTheory.Functor.Initial.lift /-- When `F : C ⥤ D` is initial, we denote by `homToLift` an arbitrary choice of morphism `F.obj (lift F d) ⟶ d`. -/ def homToLift (d : D) : F.obj (lift F d) ⟶ d := (Classical.arbitrary (CostructuredArrow F d)).hom #align category_theory.functor.initial.hom_to_lift CategoryTheory.Functor.Initial.homToLift /-- We provide an induction principle for reasoning about `lift` and `homToLift`. We want to perform some construction (usually just a proof) about the particular choices `lift F d` and `homToLift F d`, it suffices to perform that construction for some other pair of choices (denoted `X₀ : C` and `k₀ : F.obj X₀ ⟶ d` below), and to show how to transport such a construction *both* directions along a morphism between such choices. -/ def induction {d : D} (Z : ∀ (X : C) (_ : F.obj X ⟶ d), Sort*) (h₁ : ∀ (X₁ X₂) (k₁ : F.obj X₁ ⟶ d) (k₂ : F.obj X₂ ⟶ d) (f : X₁ ⟶ X₂), F.map f ≫ k₂ = k₁ → Z X₁ k₁ → Z X₂ k₂) (h₂ : ∀ (X₁ X₂) (k₁ : F.obj X₁ ⟶ d) (k₂ : F.obj X₂ ⟶ d) (f : X₁ ⟶ X₂), F.map f ≫ k₂ = k₁ → Z X₂ k₂ → Z X₁ k₁) {X₀ : C} {k₀ : F.obj X₀ ⟶ d} (z : Z X₀ k₀) : Z (lift F d) (homToLift F d) := by apply Nonempty.some apply @isPreconnected_induction _ _ _ (fun Y : CostructuredArrow F d => Z Y.left Y.hom) _ _ (CostructuredArrow.mk k₀) z · intro j₁ j₂ f a fapply h₁ _ _ _ _ f.left _ a convert f.w dsimp simp · intro j₁ j₂ f a fapply h₂ _ _ _ _ f.left _ a convert f.w dsimp simp #align category_theory.functor.initial.induction CategoryTheory.Functor.Initial.induction variable {F G} /-- Given a cone over `F ⋙ G`, we can construct a `Cone G` with the same cocone point. -/ @[simps] def extendCone : Cone (F ⋙ G) ⥤ Cone G where obj c := { pt := c.pt π := { app := fun d => c.π.app (lift F d) ≫ G.map (homToLift F d) naturality := fun X Y f => by dsimp; simp -- This would be true if we'd chosen `lift F Y` to be `lift F X` -- and `homToLift F Y` to be `homToLift F X ≫ f`. apply induction F fun Z k => (c.π.app Z ≫ G.map k : c.pt ⟶ _) = c.π.app (lift F X) ≫ G.map (homToLift F X) ≫ G.map f · intro Z₁ Z₂ k₁ k₂ g a z rw [← a, Functor.map_comp, ← Functor.comp_map, ← Category.assoc, ← Category.assoc, c.w] at z rw [z, Category.assoc] · intro Z₁ Z₂ k₁ k₂ g a z rw [← a, Functor.map_comp, ← Functor.comp_map, ← Category.assoc, ← Category.assoc, c.w, z, Category.assoc] · rw [← Functor.map_comp] } } map f := { hom := f.hom } #align category_theory.functor.initial.extend_cone CategoryTheory.Functor.Initial.extendCone @[simp] theorem limit_cone_comp_aux (s : Cone (F ⋙ G)) (j : C) : s.π.app (lift F (F.obj j)) ≫ G.map (homToLift F (F.obj j)) = s.π.app j := by -- This point is that this would be true if we took `lift (F.obj j)` to just be `j` -- and `homToLift (F.obj j)` to be `𝟙 (F.obj j)`. apply induction F fun X k => s.π.app X ≫ G.map k = (s.π.app j : _) · intro j₁ j₂ k₁ k₂ f w h rw [← s.w f] rw [← w] at h simpa using h · intro j₁ j₂ k₁ k₂ f w h rw [← s.w f] at h rw [← w] simpa using h · exact s.w (𝟙 _) #align category_theory.functor.initial.limit_cone_comp_aux CategoryTheory.Functor.Initial.limit_cone_comp_aux variable (F G) /-- If `F` is initial, the category of cones on `F ⋙ G` is equivalent to the category of cones on `G`, for any `G : D ⥤ E`. -/ @[simps] def conesEquiv : Cone (F ⋙ G) ≌ Cone G where functor := extendCone inverse := Cones.whiskering F unitIso := NatIso.ofComponents fun c => Cones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun c => Cones.ext (Iso.refl _) #align category_theory.functor.initial.cones_equiv CategoryTheory.Functor.Initial.conesEquiv variable {G} /-- When `F : C ⥤ D` is initial, and `t : Cone G` for some `G : D ⥤ E`, `t.whisker F` is a limit cone exactly when `t` is. -/ def isLimitWhiskerEquiv (t : Cone G) : IsLimit (t.whisker F) ≃ IsLimit t := IsLimit.ofConeEquiv (conesEquiv F G).symm #align category_theory.functor.initial.is_limit_whisker_equiv CategoryTheory.Functor.Initial.isLimitWhiskerEquiv /-- When `F` is initial, and `t : Cone (F ⋙ G)`, `extendCone.obj t` is a limit cone exactly when `t` is. -/ def isLimitExtendConeEquiv (t : Cone (F ⋙ G)) : IsLimit (extendCone.obj t) ≃ IsLimit t := IsLimit.ofConeEquiv (conesEquiv F G) #align category_theory.functor.initial.is_limit_extend_cone_equiv CategoryTheory.Functor.Initial.isLimitExtendConeEquiv /-- Given a limit cone over `G : D ⥤ E` we can construct a limit cone over `F ⋙ G`. -/ @[simps] def limitConeComp (t : LimitCone G) : LimitCone (F ⋙ G) where cone := _ isLimit := (isLimitWhiskerEquiv F _).symm t.isLimit #align category_theory.functor.initial.limit_cone_comp CategoryTheory.Functor.Initial.limitConeComp instance (priority := 100) comp_hasLimit [HasLimit G] : HasLimit (F ⋙ G) := HasLimit.mk (limitConeComp F (getLimitCone G)) #align category_theory.functor.initial.comp_has_limit CategoryTheory.Functor.Initial.comp_hasLimit instance limit_pre_isIso [HasLimit G] : IsIso (limit.pre G F) := by rw [limit.pre_eq (limitConeComp F (getLimitCone G)) (getLimitCone G)] erw [IsLimit.lift_self] dsimp infer_instance #align category_theory.functor.initial.limit_pre_is_iso CategoryTheory.Functor.Initial.limit_pre_isIso section variable (G) /-- When `F : C ⥤ D` is initial, and `G : D ⥤ E` has a limit, then `F ⋙ G` has a limit also and `limit (F ⋙ G) ≅ limit G` https://stacks.math.columbia.edu/tag/04E7 -/ def limitIso [HasLimit G] : limit (F ⋙ G) ≅ limit G := (asIso (limit.pre G F)).symm #align category_theory.functor.initial.limit_iso CategoryTheory.Functor.Initial.limitIso end /-- Given a limit cone over `F ⋙ G` we can construct a limit cone over `G`. -/ @[simps] def limitConeOfComp (t : LimitCone (F ⋙ G)) : LimitCone G where cone := extendCone.obj t.cone isLimit := (isLimitExtendConeEquiv F _).symm t.isLimit #align category_theory.functor.initial.limit_cone_of_comp CategoryTheory.Functor.Initial.limitConeOfComp /-- When `F` is initial, and `F ⋙ G` has a limit, then `G` has a limit also. We can't make this an instance, because `F` is not determined by the goal. (Even if this weren't a problem, it would cause a loop with `comp_hasLimit`.) -/ theorem hasLimit_of_comp [HasLimit (F ⋙ G)] : HasLimit G := HasLimit.mk (limitConeOfComp F (getLimitCone (F ⋙ G))) #align category_theory.functor.initial.has_limit_of_comp CategoryTheory.Functor.Initial.hasLimit_of_comp theorem hasLimitsOfShape_of_initial [HasLimitsOfShape C E] : HasLimitsOfShape D E where has_limit := fun _ => hasLimit_of_comp F section -- Porting note: this instance does not seem to be found automatically -- attribute [local instance] hasLimit_of_comp /-- When `F` is initial, and `F ⋙ G` has a limit, then `G` has a limit also and `limit (F ⋙ G) ≅ limit G` https://stacks.math.columbia.edu/tag/04E7 -/ def limitIso' [HasLimit (F ⋙ G)] : haveI : HasLimit G := hasLimit_of_comp F; limit (F ⋙ G) ≅ limit G := haveI : HasLimit G := hasLimit_of_comp F; (asIso (limit.pre G F)).symm #align category_theory.functor.initial.limit_iso' CategoryTheory.Functor.Initial.limitIso' end end Initial section variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] (F : C ⥤ D) (G : D ⥤ E) /-- The hypotheses also imply that `G` is final, see `final_of_comp_full_faithful'`. -/ theorem final_of_comp_full_faithful [Full G] [Faithful G] [Final (F ⋙ G)] : Final F where out d := isConnected_of_equivalent (StructuredArrow.post d F G).asEquivalence.symm /-- The hypotheses also imply that `G` is initial, see `initial_of_comp_full_faithful'`. -/ theorem initial_of_comp_full_faithful [Full G] [Faithful G] [Initial (F ⋙ G)] : Initial F where out d := isConnected_of_equivalent (CostructuredArrow.post F G d).asEquivalence.symm /-- See also the strictly more general `final_comp` below. -/ theorem final_comp_equivalence [Final F] [IsEquivalence G] : Final (F ⋙ G) := let i : F ≅ (F ⋙ G) ⋙ G.inv := isoWhiskerLeft F G.asEquivalence.unitIso have : Final ((F ⋙ G) ⋙ G.inv) := final_of_natIso i final_of_comp_full_faithful (F ⋙ G) G.inv /-- See also the strictly more general `initial_comp` below. -/ theorem initial_comp_equivalence [Initial F] [IsEquivalence G] : Initial (F ⋙ G) := let i : F ≅ (F ⋙ G) ⋙ G.inv := isoWhiskerLeft F G.asEquivalence.unitIso have : Initial ((F ⋙ G) ⋙ G.inv) := initial_of_natIso i initial_of_comp_full_faithful (F ⋙ G) G.inv /-- See also the strictly more general `final_comp` below. -/ theorem final_equivalence_comp [IsEquivalence F] [Final G] : Final (F ⋙ G) where out d := isConnected_of_equivalent (StructuredArrow.pre d F G).asEquivalence.symm /-- See also the strictly more general `inital_comp` below. -/ theorem initial_equivalence_comp [IsEquivalence F] [Initial G] : Initial (F ⋙ G) where out d := isConnected_of_equivalent (CostructuredArrow.pre F G d).asEquivalence.symm /-- See also the strictly more general `final_of_final_comp` below. -/ theorem final_of_equivalence_comp [IsEquivalence F] [Final (F ⋙ G)] : Final G where out d := isConnected_of_equivalent (StructuredArrow.pre d F G).asEquivalence /-- See also the strictly more general `initial_of_initial_comp` below. -/ theorem initial_of_equivalence_comp [IsEquivalence F] [Initial (F ⋙ G)] : Initial G where out d := isConnected_of_equivalent (CostructuredArrow.pre F G d).asEquivalence /-- See also the strictly more general `final_iff_comp_final_full_faithful` below. -/ theorem final_iff_comp_equivalence [IsEquivalence G] : Final F ↔ Final (F ⋙ G) := ⟨fun _ => final_comp_equivalence _ _, fun _ => final_of_comp_full_faithful _ G⟩ /-- See also the strictly more general `final_iff_final_comp` below. -/ theorem final_iff_equivalence_comp [IsEquivalence F] : Final G ↔ Final (F ⋙ G) := ⟨fun _ => final_equivalence_comp _ _, fun _ => final_of_equivalence_comp F _⟩ /-- See also the strictly more general `initial_iff_comp_initial_full_faithful` below. -/ theorem initial_iff_comp_equivalence [IsEquivalence G] : Initial F ↔ Initial (F ⋙ G) := ⟨fun _ => initial_comp_equivalence _ _, fun _ => initial_of_comp_full_faithful _ G⟩ /-- See also the strictly more general `initial_iff_initial_comp` below. -/ theorem initial_iff_equivalence_comp [IsEquivalence F] : Initial G ↔ Initial (F ⋙ G) := ⟨fun _ => initial_equivalence_comp _ _, fun _ => initial_of_equivalence_comp F _⟩ instance final_comp [hF : Final F] [hG : Final G] : Final (F ⋙ G) := by let s₁ : C ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} C := AsSmall.equiv let s₂ : D ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} D := AsSmall.equiv let s₃ : E ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} E := AsSmall.equiv let i : s₁.inverse ⋙ (F ⋙ G) ⋙ s₃.functor ≅ (s₁.inverse ⋙ F ⋙ s₂.functor) ⋙ (s₂.inverse ⋙ G ⋙ s₃.functor) := isoWhiskerLeft (s₁.inverse ⋙ F) (isoWhiskerRight s₂.unitIso (G ⋙ s₃.functor)) rw [final_iff_comp_equivalence (F ⋙ G) s₃.functor, final_iff_equivalence_comp s₁.inverse, final_natIso_iff i, final_iff_isIso_colimit_pre] rw [final_iff_comp_equivalence F s₂.functor, final_iff_equivalence_comp s₁.inverse, final_iff_isIso_colimit_pre] at hF rw [final_iff_comp_equivalence G s₃.functor, final_iff_equivalence_comp s₂.inverse, final_iff_isIso_colimit_pre] at hG intro H rw [← colimit.pre_pre] infer_instance instance initial_comp [Initial F] [Initial G] : Initial (F ⋙ G) := by suffices Final (F ⋙ G).op from initial_of_final_op _ exact final_comp F.op G.op theorem final_of_final_comp [hF : Final F] [hFG : Final (F ⋙ G)] : Final G := by let s₁ : C ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} C := AsSmall.equiv let s₂ : D ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} D := AsSmall.equiv let s₃ : E ≌ AsSmall.{max u₁ v₁ u₂ v₂ u₃ v₃} E := AsSmall.equiv let _i : s₁.inverse ⋙ (F ⋙ G) ⋙ s₃.functor ≅ (s₁.inverse ⋙ F ⋙ s₂.functor) ⋙ (s₂.inverse ⋙ G ⋙ s₃.functor) := isoWhiskerLeft (s₁.inverse ⋙ F) (isoWhiskerRight s₂.unitIso (G ⋙ s₃.functor)) rw [final_iff_comp_equivalence G s₃.functor, final_iff_equivalence_comp s₂.inverse, final_iff_isIso_colimit_pre] rw [final_iff_comp_equivalence F s₂.functor, final_iff_equivalence_comp s₁.inverse, final_iff_isIso_colimit_pre] at hF rw [final_iff_comp_equivalence (F ⋙ G) s₃.functor, final_iff_equivalence_comp s₁.inverse, final_natIso_iff _i, final_iff_isIso_colimit_pre] at hFG intro H replace hFG := hFG H rw [← colimit.pre_pre] at hFG exact IsIso.of_isIso_comp_left (colimit.pre _ (s₁.inverse ⋙ F ⋙ s₂.functor)) _
Mathlib/CategoryTheory/Limits/Final.lean
763
766
theorem initial_of_initial_comp [Initial F] [Initial (F ⋙ G)] : Initial G := by
suffices Final G.op from initial_of_final_op _ have : Final (F.op ⋙ G.op) := show Final (F ⋙ G).op from inferInstance exact final_of_final_comp F.op G.op
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Finset.NAry import Mathlib.Data.Finset.Slice import Mathlib.Data.Set.Sups #align_import data.finset.sups from "leanprover-community/mathlib"@"8818fdefc78642a7e6afcd20be5c184f3c7d9699" /-! # Set family operations This file defines a few binary operations on `Finset α` for use in set family combinatorics. ## Main declarations * `Finset.sups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. * `Finset.infs s t`: Finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. * `Finset.disjSups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. * `Finset.diffs`: Finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`. * `Finset.compls`: Finset of elements of the form `aᶜ` where `a ∈ s`. ## Notation We define the following notation in locale `FinsetFamily`: * `s ⊻ t` for `Finset.sups` * `s ⊼ t` for `Finset.infs` * `s ○ t` for `Finset.disjSups s t` * `s \\ t` for `Finset.diffs` * `sᶜˢ` for `Finset.compls` ## References [B. Bollobás, *Combinatorics*][bollobas1986] -/ #align finset.decidable_pred_mem_upper_closure instDecidablePredMemUpperClosure #align finset.decidable_pred_mem_lower_closure instDecidablePredMemLowerClosure open Function open SetFamily variable {F α β : Type*} [DecidableEq α] [DecidableEq β] namespace Finset section Sups variable [SemilatticeSup α] [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β] variable (s s₁ s₂ t t₁ t₂ u v : Finset α) /-- `s ⊻ t` is the finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. -/ protected def hasSups : HasSups (Finset α) := ⟨image₂ (· ⊔ ·)⟩ #align finset.has_sups Finset.hasSups scoped[FinsetFamily] attribute [instance] Finset.hasSups open FinsetFamily variable {s t} {a b c : α} @[simp] theorem mem_sups : c ∈ s ⊻ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊔ b = c := by simp [(· ⊻ ·)] #align finset.mem_sups Finset.mem_sups variable (s t) @[simp, norm_cast] theorem coe_sups : (↑(s ⊻ t) : Set α) = ↑s ⊻ ↑t := coe_image₂ _ _ _ #align finset.coe_sups Finset.coe_sups theorem card_sups_le : (s ⊻ t).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.card_sups_le Finset.card_sups_le theorem card_sups_iff : (s ⊻ t).card = s.card * t.card ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊔ x.2 := card_image₂_iff #align finset.card_sups_iff Finset.card_sups_iff variable {s s₁ s₂ t t₁ t₂ u} theorem sup_mem_sups : a ∈ s → b ∈ t → a ⊔ b ∈ s ⊻ t := mem_image₂_of_mem #align finset.sup_mem_sups Finset.sup_mem_sups theorem sups_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊻ t₁ ⊆ s₂ ⊻ t₂ := image₂_subset #align finset.sups_subset Finset.sups_subset theorem sups_subset_left : t₁ ⊆ t₂ → s ⊻ t₁ ⊆ s ⊻ t₂ := image₂_subset_left #align finset.sups_subset_left Finset.sups_subset_left theorem sups_subset_right : s₁ ⊆ s₂ → s₁ ⊻ t ⊆ s₂ ⊻ t := image₂_subset_right #align finset.sups_subset_right Finset.sups_subset_right lemma image_subset_sups_left : b ∈ t → s.image (· ⊔ b) ⊆ s ⊻ t := image_subset_image₂_left #align finset.image_subset_sups_left Finset.image_subset_sups_left lemma image_subset_sups_right : a ∈ s → t.image (a ⊔ ·) ⊆ s ⊻ t := image_subset_image₂_right #align finset.image_subset_sups_right Finset.image_subset_sups_right theorem forall_sups_iff {p : α → Prop} : (∀ c ∈ s ⊻ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊔ b) := forall_image₂_iff #align finset.forall_sups_iff Finset.forall_sups_iff @[simp] theorem sups_subset_iff : s ⊻ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊔ b ∈ u := image₂_subset_iff #align finset.sups_subset_iff Finset.sups_subset_iff @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem sups_nonempty : (s ⊻ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.sups_nonempty Finset.sups_nonempty protected theorem Nonempty.sups : s.Nonempty → t.Nonempty → (s ⊻ t).Nonempty := Nonempty.image₂ #align finset.nonempty.sups Finset.Nonempty.sups theorem Nonempty.of_sups_left : (s ⊻ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_sups_left Finset.Nonempty.of_sups_left theorem Nonempty.of_sups_right : (s ⊻ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_sups_right Finset.Nonempty.of_sups_right @[simp] theorem empty_sups : ∅ ⊻ t = ∅ := image₂_empty_left #align finset.empty_sups Finset.empty_sups @[simp] theorem sups_empty : s ⊻ ∅ = ∅ := image₂_empty_right #align finset.sups_empty Finset.sups_empty @[simp] theorem sups_eq_empty : s ⊻ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.sups_eq_empty Finset.sups_eq_empty @[simp] lemma singleton_sups : {a} ⊻ t = t.image (a ⊔ ·) := image₂_singleton_left #align finset.singleton_sups Finset.singleton_sups @[simp] lemma sups_singleton : s ⊻ {b} = s.image (· ⊔ b) := image₂_singleton_right #align finset.sups_singleton Finset.sups_singleton theorem singleton_sups_singleton : ({a} ⊻ {b} : Finset α) = {a ⊔ b} := image₂_singleton #align finset.singleton_sups_singleton Finset.singleton_sups_singleton theorem sups_union_left : (s₁ ∪ s₂) ⊻ t = s₁ ⊻ t ∪ s₂ ⊻ t := image₂_union_left #align finset.sups_union_left Finset.sups_union_left theorem sups_union_right : s ⊻ (t₁ ∪ t₂) = s ⊻ t₁ ∪ s ⊻ t₂ := image₂_union_right #align finset.sups_union_right Finset.sups_union_right theorem sups_inter_subset_left : (s₁ ∩ s₂) ⊻ t ⊆ s₁ ⊻ t ∩ s₂ ⊻ t := image₂_inter_subset_left #align finset.sups_inter_subset_left Finset.sups_inter_subset_left theorem sups_inter_subset_right : s ⊻ (t₁ ∩ t₂) ⊆ s ⊻ t₁ ∩ s ⊻ t₂ := image₂_inter_subset_right #align finset.sups_inter_subset_right Finset.sups_inter_subset_right theorem subset_sups {s t : Set α} : ↑u ⊆ s ⊻ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊻ t' := subset_image₂ #align finset.subset_sups Finset.subset_sups lemma image_sups (f : F) (s t : Finset α) : image f (s ⊻ t) = image f s ⊻ image f t := image_image₂_distrib <| map_sup f lemma map_sups (f : F) (hf) (s t : Finset α) : map ⟨f, hf⟩ (s ⊻ t) = map ⟨f, hf⟩ s ⊻ map ⟨f, hf⟩ t := by simpa [map_eq_image] using image_sups f s t lemma subset_sups_self : s ⊆ s ⊻ s := fun _a ha ↦ mem_sups.2 ⟨_, ha, _, ha, sup_idem _⟩ lemma sups_subset_self : s ⊻ s ⊆ s ↔ SupClosed (s : Set α) := sups_subset_iff @[simp] lemma sups_eq_self : s ⊻ s = s ↔ SupClosed (s : Set α) := by simp [← coe_inj] @[simp] lemma univ_sups_univ [Fintype α] : (univ : Finset α) ⊻ univ = univ := by simp lemma filter_sups_le [@DecidableRel α (· ≤ ·)] (s t : Finset α) (a : α) : (s ⊻ t).filter (· ≤ a) = s.filter (· ≤ a) ⊻ t.filter (· ≤ a) := by simp only [← coe_inj, coe_filter, coe_sups, ← mem_coe, Set.sep_sups_le] variable (s t u) lemma biUnion_image_sup_left : s.biUnion (fun a ↦ t.image (a ⊔ ·)) = s ⊻ t := biUnion_image_left #align finset.bUnion_image_sup_left Finset.biUnion_image_sup_left lemma biUnion_image_sup_right : t.biUnion (fun b ↦ s.image (· ⊔ b)) = s ⊻ t := biUnion_image_right #align finset.bUnion_image_sup_right Finset.biUnion_image_sup_right -- Porting note: simpNF linter doesn't like @[simp] theorem image_sup_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊔ ·)) = s ⊻ t := image_uncurry_product _ _ _ #align finset.image_sup_product Finset.image_sup_product theorem sups_assoc : s ⊻ t ⊻ u = s ⊻ (t ⊻ u) := image₂_assoc sup_assoc #align finset.sups_assoc Finset.sups_assoc theorem sups_comm : s ⊻ t = t ⊻ s := image₂_comm sup_comm #align finset.sups_comm Finset.sups_comm theorem sups_left_comm : s ⊻ (t ⊻ u) = t ⊻ (s ⊻ u) := image₂_left_comm sup_left_comm #align finset.sups_left_comm Finset.sups_left_comm theorem sups_right_comm : s ⊻ t ⊻ u = s ⊻ u ⊻ t := image₂_right_comm sup_right_comm #align finset.sups_right_comm Finset.sups_right_comm theorem sups_sups_sups_comm : s ⊻ t ⊻ (u ⊻ v) = s ⊻ u ⊻ (t ⊻ v) := image₂_image₂_image₂_comm sup_sup_sup_comm #align finset.sups_sups_sups_comm Finset.sups_sups_sups_comm #align finset.filter_sups_le Finset.filter_sups_le end Sups section Infs variable [SemilatticeInf α] [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β] variable (s s₁ s₂ t t₁ t₂ u v : Finset α) /-- `s ⊼ t` is the finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. -/ protected def hasInfs : HasInfs (Finset α) := ⟨image₂ (· ⊓ ·)⟩ #align finset.has_infs Finset.hasInfs scoped[FinsetFamily] attribute [instance] Finset.hasInfs open FinsetFamily variable {s t} {a b c : α} @[simp] theorem mem_infs : c ∈ s ⊼ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊓ b = c := by simp [(· ⊼ ·)] #align finset.mem_infs Finset.mem_infs variable (s t) @[simp, norm_cast] theorem coe_infs : (↑(s ⊼ t) : Set α) = ↑s ⊼ ↑t := coe_image₂ _ _ _ #align finset.coe_infs Finset.coe_infs theorem card_infs_le : (s ⊼ t).card ≤ s.card * t.card := card_image₂_le _ _ _ #align finset.card_infs_le Finset.card_infs_le theorem card_infs_iff : (s ⊼ t).card = s.card * t.card ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊓ x.2 := card_image₂_iff #align finset.card_infs_iff Finset.card_infs_iff variable {s s₁ s₂ t t₁ t₂ u} theorem inf_mem_infs : a ∈ s → b ∈ t → a ⊓ b ∈ s ⊼ t := mem_image₂_of_mem #align finset.inf_mem_infs Finset.inf_mem_infs theorem infs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊼ t₁ ⊆ s₂ ⊼ t₂ := image₂_subset #align finset.infs_subset Finset.infs_subset theorem infs_subset_left : t₁ ⊆ t₂ → s ⊼ t₁ ⊆ s ⊼ t₂ := image₂_subset_left #align finset.infs_subset_left Finset.infs_subset_left theorem infs_subset_right : s₁ ⊆ s₂ → s₁ ⊼ t ⊆ s₂ ⊼ t := image₂_subset_right #align finset.infs_subset_right Finset.infs_subset_right lemma image_subset_infs_left : b ∈ t → s.image (· ⊓ b) ⊆ s ⊼ t := image_subset_image₂_left #align finset.image_subset_infs_left Finset.image_subset_infs_left lemma image_subset_infs_right : a ∈ s → t.image (a ⊓ ·) ⊆ s ⊼ t := image_subset_image₂_right #align finset.image_subset_infs_right Finset.image_subset_infs_right theorem forall_infs_iff {p : α → Prop} : (∀ c ∈ s ⊼ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊓ b) := forall_image₂_iff #align finset.forall_infs_iff Finset.forall_infs_iff @[simp] theorem infs_subset_iff : s ⊼ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊓ b ∈ u := image₂_subset_iff #align finset.infs_subset_iff Finset.infs_subset_iff @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem infs_nonempty : (s ⊼ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff #align finset.infs_nonempty Finset.infs_nonempty protected theorem Nonempty.infs : s.Nonempty → t.Nonempty → (s ⊼ t).Nonempty := Nonempty.image₂ #align finset.nonempty.infs Finset.Nonempty.infs theorem Nonempty.of_infs_left : (s ⊼ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left #align finset.nonempty.of_infs_left Finset.Nonempty.of_infs_left theorem Nonempty.of_infs_right : (s ⊼ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right #align finset.nonempty.of_infs_right Finset.Nonempty.of_infs_right @[simp] theorem empty_infs : ∅ ⊼ t = ∅ := image₂_empty_left #align finset.empty_infs Finset.empty_infs @[simp] theorem infs_empty : s ⊼ ∅ = ∅ := image₂_empty_right #align finset.infs_empty Finset.infs_empty @[simp] theorem infs_eq_empty : s ⊼ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff #align finset.infs_eq_empty Finset.infs_eq_empty @[simp] lemma singleton_infs : {a} ⊼ t = t.image (a ⊓ ·) := image₂_singleton_left #align finset.singleton_infs Finset.singleton_infs @[simp] lemma infs_singleton : s ⊼ {b} = s.image (· ⊓ b) := image₂_singleton_right #align finset.infs_singleton Finset.infs_singleton theorem singleton_infs_singleton : ({a} ⊼ {b} : Finset α) = {a ⊓ b} := image₂_singleton #align finset.singleton_infs_singleton Finset.singleton_infs_singleton theorem infs_union_left : (s₁ ∪ s₂) ⊼ t = s₁ ⊼ t ∪ s₂ ⊼ t := image₂_union_left #align finset.infs_union_left Finset.infs_union_left theorem infs_union_right : s ⊼ (t₁ ∪ t₂) = s ⊼ t₁ ∪ s ⊼ t₂ := image₂_union_right #align finset.infs_union_right Finset.infs_union_right theorem infs_inter_subset_left : (s₁ ∩ s₂) ⊼ t ⊆ s₁ ⊼ t ∩ s₂ ⊼ t := image₂_inter_subset_left #align finset.infs_inter_subset_left Finset.infs_inter_subset_left theorem infs_inter_subset_right : s ⊼ (t₁ ∩ t₂) ⊆ s ⊼ t₁ ∩ s ⊼ t₂ := image₂_inter_subset_right #align finset.infs_inter_subset_right Finset.infs_inter_subset_right theorem subset_infs {s t : Set α} : ↑u ⊆ s ⊼ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊼ t' := subset_image₂ #align finset.subset_infs Finset.subset_infs lemma image_infs (f : F) (s t : Finset α) : image f (s ⊼ t) = image f s ⊼ image f t := image_image₂_distrib <| map_inf f lemma map_infs (f : F) (hf) (s t : Finset α) : map ⟨f, hf⟩ (s ⊼ t) = map ⟨f, hf⟩ s ⊼ map ⟨f, hf⟩ t := by simpa [map_eq_image] using image_infs f s t lemma subset_infs_self : s ⊆ s ⊼ s := fun _a ha ↦ mem_infs.2 ⟨_, ha, _, ha, inf_idem _⟩ lemma infs_self_subset : s ⊼ s ⊆ s ↔ InfClosed (s : Set α) := infs_subset_iff @[simp] lemma infs_self : s ⊼ s = s ↔ InfClosed (s : Set α) := by simp [← coe_inj] @[simp] lemma univ_infs_univ [Fintype α] : (univ : Finset α) ⊼ univ = univ := by simp lemma filter_infs_le [@DecidableRel α (· ≤ ·)] (s t : Finset α) (a : α) : (s ⊼ t).filter (a ≤ ·) = s.filter (a ≤ ·) ⊼ t.filter (a ≤ ·) := by simp only [← coe_inj, coe_filter, coe_infs, ← mem_coe, Set.sep_infs_le] variable (s t u) lemma biUnion_image_inf_left : s.biUnion (fun a ↦ t.image (a ⊓ ·)) = s ⊼ t := biUnion_image_left #align finset.bUnion_image_inf_left Finset.biUnion_image_inf_left lemma biUnion_image_inf_right : t.biUnion (fun b ↦ s.image (· ⊓ b)) = s ⊼ t := biUnion_image_right #align finset.bUnion_image_inf_right Finset.biUnion_image_inf_right -- Porting note: simpNF linter doesn't like @[simp] theorem image_inf_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊓ ·)) = s ⊼ t := image_uncurry_product _ _ _ #align finset.image_inf_product Finset.image_inf_product theorem infs_assoc : s ⊼ t ⊼ u = s ⊼ (t ⊼ u) := image₂_assoc inf_assoc #align finset.infs_assoc Finset.infs_assoc theorem infs_comm : s ⊼ t = t ⊼ s := image₂_comm inf_comm #align finset.infs_comm Finset.infs_comm theorem infs_left_comm : s ⊼ (t ⊼ u) = t ⊼ (s ⊼ u) := image₂_left_comm inf_left_comm #align finset.infs_left_comm Finset.infs_left_comm theorem infs_right_comm : s ⊼ t ⊼ u = s ⊼ u ⊼ t := image₂_right_comm inf_right_comm #align finset.infs_right_comm Finset.infs_right_comm theorem infs_infs_infs_comm : s ⊼ t ⊼ (u ⊼ v) = s ⊼ u ⊼ (t ⊼ v) := image₂_image₂_image₂_comm inf_inf_inf_comm #align finset.infs_infs_infs_comm Finset.infs_infs_infs_comm #align finset.filter_infs_ge Finset.filter_infs_le end Infs open FinsetFamily section DistribLattice variable [DistribLattice α] (s t u : Finset α) theorem sups_infs_subset_left : s ⊻ t ⊼ u ⊆ (s ⊻ t) ⊼ (s ⊻ u) := image₂_distrib_subset_left sup_inf_left #align finset.sups_infs_subset_left Finset.sups_infs_subset_left theorem sups_infs_subset_right : t ⊼ u ⊻ s ⊆ (t ⊻ s) ⊼ (u ⊻ s) := image₂_distrib_subset_right sup_inf_right #align finset.sups_infs_subset_right Finset.sups_infs_subset_right theorem infs_sups_subset_left : s ⊼ (t ⊻ u) ⊆ s ⊼ t ⊻ s ⊼ u := image₂_distrib_subset_left inf_sup_left #align finset.infs_sups_subset_left Finset.infs_sups_subset_left theorem infs_sups_subset_right : (t ⊻ u) ⊼ s ⊆ t ⊼ s ⊻ u ⊼ s := image₂_distrib_subset_right inf_sup_right #align finset.infs_sups_subset_right Finset.infs_sups_subset_right end DistribLattice section Finset variable {𝒜 ℬ : Finset (Finset α)} {s t : Finset α} {a : α} @[simp] lemma powerset_union (s t : Finset α) : (s ∪ t).powerset = s.powerset ⊻ t.powerset := by ext u simp only [mem_sups, mem_powerset, le_eq_subset, sup_eq_union] refine ⟨fun h ↦ ⟨_, inter_subset_left (s₂:=u), _, inter_subset_left (s₂:=u), ?_⟩, ?_⟩ · rwa [← union_inter_distrib_right, inter_eq_right] · rintro ⟨v, hv, w, hw, rfl⟩ exact union_subset_union hv hw @[simp] lemma powerset_inter (s t : Finset α) : (s ∩ t).powerset = s.powerset ⊼ t.powerset := by ext u simp only [mem_infs, mem_powerset, le_eq_subset, inf_eq_inter] refine ⟨fun h ↦ ⟨_, inter_subset_left (s₂:=u), _, inter_subset_left (s₂:=u), ?_⟩, ?_⟩ · rwa [← inter_inter_distrib_right, inter_eq_right] · rintro ⟨v, hv, w, hw, rfl⟩ exact inter_subset_inter hv hw @[simp] lemma powerset_sups_powerset_self (s : Finset α) : s.powerset ⊻ s.powerset = s.powerset := by simp [← powerset_union] @[simp] lemma powerset_infs_powerset_self (s : Finset α) : s.powerset ⊼ s.powerset = s.powerset := by simp [← powerset_inter] lemma union_mem_sups : s ∈ 𝒜 → t ∈ ℬ → s ∪ t ∈ 𝒜 ⊻ ℬ := sup_mem_sups lemma inter_mem_infs : s ∈ 𝒜 → t ∈ ℬ → s ∩ t ∈ 𝒜 ⊼ ℬ := inf_mem_infs end Finset section DisjSups variable [SemilatticeSup α] [OrderBot α] [@DecidableRel α Disjoint] (s s₁ s₂ t t₁ t₂ u : Finset α) /-- The finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. -/ def disjSups : Finset α := ((s ×ˢ t).filter fun ab : α × α => Disjoint ab.1 ab.2).image fun ab => ab.1 ⊔ ab.2 #align finset.disj_sups Finset.disjSups @[inherit_doc] scoped[FinsetFamily] infixl:74 " ○ " => Finset.disjSups open FinsetFamily variable {s t u} {a b c : α} @[simp] theorem mem_disjSups : c ∈ s ○ t ↔ ∃ a ∈ s, ∃ b ∈ t, Disjoint a b ∧ a ⊔ b = c := by simp [disjSups, and_assoc] #align finset.mem_disj_sups Finset.mem_disjSups theorem disjSups_subset_sups : s ○ t ⊆ s ⊻ t := by simp_rw [subset_iff, mem_sups, mem_disjSups] exact fun c ⟨a, b, ha, hb, _, hc⟩ => ⟨a, b, ha, hb, hc⟩ #align finset.disj_sups_subset_sups Finset.disjSups_subset_sups variable (s t) theorem card_disjSups_le : (s ○ t).card ≤ s.card * t.card := (card_le_card disjSups_subset_sups).trans <| card_sups_le _ _ #align finset.card_disj_sups_le Finset.card_disjSups_le variable {s s₁ s₂ t t₁ t₂} theorem disjSups_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ○ t₁ ⊆ s₂ ○ t₂ := image_subset_image <| filter_subset_filter _ <| product_subset_product hs ht #align finset.disj_sups_subset Finset.disjSups_subset theorem disjSups_subset_left (ht : t₁ ⊆ t₂) : s ○ t₁ ⊆ s ○ t₂ := disjSups_subset Subset.rfl ht #align finset.disj_sups_subset_left Finset.disjSups_subset_left theorem disjSups_subset_right (hs : s₁ ⊆ s₂) : s₁ ○ t ⊆ s₂ ○ t := disjSups_subset hs Subset.rfl #align finset.disj_sups_subset_right Finset.disjSups_subset_right theorem forall_disjSups_iff {p : α → Prop} : (∀ c ∈ s ○ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → p (a ⊔ b) := by simp_rw [mem_disjSups] refine ⟨fun h a ha b hb hab => h _ ⟨_, ha, _, hb, hab, rfl⟩, ?_⟩ rintro h _ ⟨a, ha, b, hb, hab, rfl⟩ exact h _ ha _ hb hab #align finset.forall_disj_sups_iff Finset.forall_disjSups_iff @[simp] theorem disjSups_subset_iff : s ○ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → a ⊔ b ∈ u := forall_disjSups_iff #align finset.disj_sups_subset_iff Finset.disjSups_subset_iff theorem Nonempty.of_disjSups_left : (s ○ t).Nonempty → s.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟨_, a, ha, _⟩ => ⟨a, ha⟩ #align finset.nonempty.of_disj_sups_left Finset.Nonempty.of_disjSups_left theorem Nonempty.of_disjSups_right : (s ○ t).Nonempty → t.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟨_, _, _, b, hb, _⟩ => ⟨b, hb⟩ #align finset.nonempty.of_disj_sups_right Finset.Nonempty.of_disjSups_right @[simp] theorem disjSups_empty_left : ∅ ○ t = ∅ := by simp [disjSups] #align finset.disj_sups_empty_left Finset.disjSups_empty_left @[simp] theorem disjSups_empty_right : s ○ ∅ = ∅ := by simp [disjSups] #align finset.disj_sups_empty_right Finset.disjSups_empty_right theorem disjSups_singleton : ({a} ○ {b} : Finset α) = if Disjoint a b then {a ⊔ b} else ∅ := by split_ifs with h <;> simp [disjSups, filter_singleton, h] #align finset.disj_sups_singleton Finset.disjSups_singleton theorem disjSups_union_left : (s₁ ∪ s₂) ○ t = s₁ ○ t ∪ s₂ ○ t := by simp [disjSups, filter_union, image_union] #align finset.disj_sups_union_left Finset.disjSups_union_left theorem disjSups_union_right : s ○ (t₁ ∪ t₂) = s ○ t₁ ∪ s ○ t₂ := by simp [disjSups, filter_union, image_union] #align finset.disj_sups_union_right Finset.disjSups_union_right
Mathlib/Data/Finset/Sups.lean
561
562
theorem disjSups_inter_subset_left : (s₁ ∩ s₂) ○ t ⊆ s₁ ○ t ∩ s₂ ○ t := by
simpa only [disjSups, inter_product, filter_inter_distrib] using image_inter_subset _ _ _
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro -/ import Mathlib.Algebra.Module.Submodule.Bilinear import Mathlib.GroupTheory.Congruence.Basic import Mathlib.LinearAlgebra.Basic import Mathlib.Tactic.SuppressCompilation #align_import linear_algebra.tensor_product from "leanprover-community/mathlib"@"88fcdc3da43943f5b01925deddaa5bf0c0e85e4e" /-! # Tensor product of modules over commutative semirings. This file constructs the tensor product of modules over commutative semirings. Given a semiring `R` and modules over it `M` and `N`, the standard construction of the tensor product is `TensorProduct R M N`. It is also a module over `R`. It comes with a canonical bilinear map `M → N → TensorProduct R M N`. Given any bilinear map `M → N → P`, there is a unique linear map `TensorProduct R M N → P` whose composition with the canonical bilinear map `M → N → TensorProduct R M N` is the given bilinear map `M → N → P`. We start by proving basic lemmas about bilinear maps. ## Notations This file uses the localized notation `M ⊗ N` and `M ⊗[R] N` for `TensorProduct R M N`, as well as `m ⊗ₜ n` and `m ⊗ₜ[R] n` for `TensorProduct.tmul R m n`. ## Tags bilinear, tensor, tensor product -/ suppress_compilation section Semiring variable {R : Type*} [CommSemiring R] variable {R' : Type*} [Monoid R'] variable {R'' : Type*} [Semiring R''] variable {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {S : Type*} {T : Type*} variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable [AddCommMonoid Q] [AddCommMonoid S] [AddCommMonoid T] variable [Module R M] [Module R N] [Module R P] [Module R Q] [Module R S] [Module R T] variable [DistribMulAction R' M] variable [Module R'' M] variable (M N) namespace TensorProduct section variable (R) /-- The relation on `FreeAddMonoid (M × N)` that generates a congruence whose quotient is the tensor product. -/ inductive Eqv : FreeAddMonoid (M × N) → FreeAddMonoid (M × N) → Prop | of_zero_left : ∀ n : N, Eqv (.of (0, n)) 0 | of_zero_right : ∀ m : M, Eqv (.of (m, 0)) 0 | of_add_left : ∀ (m₁ m₂ : M) (n : N), Eqv (.of (m₁, n) + .of (m₂, n)) (.of (m₁ + m₂, n)) | of_add_right : ∀ (m : M) (n₁ n₂ : N), Eqv (.of (m, n₁) + .of (m, n₂)) (.of (m, n₁ + n₂)) | of_smul : ∀ (r : R) (m : M) (n : N), Eqv (.of (r • m, n)) (.of (m, r • n)) | add_comm : ∀ x y, Eqv (x + y) (y + x) #align tensor_product.eqv TensorProduct.Eqv end end TensorProduct variable (R) /-- The tensor product of two modules `M` and `N` over the same commutative semiring `R`. The localized notations are `M ⊗ N` and `M ⊗[R] N`, accessed by `open scoped TensorProduct`. -/ def TensorProduct : Type _ := (addConGen (TensorProduct.Eqv R M N)).Quotient #align tensor_product TensorProduct variable {R} set_option quotPrecheck false in @[inherit_doc TensorProduct] scoped[TensorProduct] infixl:100 " ⊗ " => TensorProduct _ @[inherit_doc] scoped[TensorProduct] notation:100 M " ⊗[" R "] " N:100 => TensorProduct R M N namespace TensorProduct section Module protected instance add : Add (M ⊗[R] N) := (addConGen (TensorProduct.Eqv R M N)).hasAdd instance addZeroClass : AddZeroClass (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with /- The `toAdd` field is given explicitly as `TensorProduct.add` for performance reasons. This avoids any need to unfold `Con.addMonoid` when the type checker is checking that instance diagrams commute -/ toAdd := TensorProduct.add _ _ } instance addSemigroup : AddSemigroup (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with toAdd := TensorProduct.add _ _ } instance addCommSemigroup : AddCommSemigroup (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with toAddSemigroup := TensorProduct.addSemigroup _ _ add_comm := fun x y => AddCon.induction_on₂ x y fun _ _ => Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.add_comm _ _ } instance : Inhabited (M ⊗[R] N) := ⟨0⟩ variable (R) {M N} /-- The canonical function `M → N → M ⊗ N`. The localized notations are `m ⊗ₜ n` and `m ⊗ₜ[R] n`, accessed by `open scoped TensorProduct`. -/ def tmul (m : M) (n : N) : M ⊗[R] N := AddCon.mk' _ <| FreeAddMonoid.of (m, n) #align tensor_product.tmul TensorProduct.tmul variable {R} /-- The canonical function `M → N → M ⊗ N`. -/ infixl:100 " ⊗ₜ " => tmul _ /-- The canonical function `M → N → M ⊗ N`. -/ notation:100 x " ⊗ₜ[" R "] " y:100 => tmul R x y -- Porting note: make the arguments of induction_on explicit @[elab_as_elim] protected theorem induction_on {motive : M ⊗[R] N → Prop} (z : M ⊗[R] N) (zero : motive 0) (tmul : ∀ x y, motive <| x ⊗ₜ[R] y) (add : ∀ x y, motive x → motive y → motive (x + y)) : motive z := AddCon.induction_on z fun x => FreeAddMonoid.recOn x zero fun ⟨m, n⟩ y ih => by rw [AddCon.coe_add] exact add _ _ (tmul ..) ih #align tensor_product.induction_on TensorProduct.induction_on /-- Lift an `R`-balanced map to the tensor product. A map `f : M →+ N →+ P` additive in both components is `R`-balanced, or middle linear with respect to `R`, if scalar multiplication in either argument is equivalent, `f (r • m) n = f m (r • n)`. Note that strictly the first action should be a right-action by `R`, but for now `R` is commutative so it doesn't matter. -/ -- TODO: use this to implement `lift` and `SMul.aux`. For now we do not do this as it causes -- performance issues elsewhere. def liftAddHom (f : M →+ N →+ P) (hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) : M ⊗[R] N →+ P := (addConGen (TensorProduct.Eqv R M N)).lift (FreeAddMonoid.lift (fun mn : M × N => f mn.1 mn.2)) <| AddCon.addConGen_le fun x y hxy => match x, y, hxy with | _, _, .of_zero_left n => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero, AddMonoidHom.zero_apply] | _, _, .of_zero_right m => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero] | _, _, .of_add_left m₁ m₂ n => (AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add, AddMonoidHom.add_apply] | _, _, .of_add_right m n₁ n₂ => (AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add] | _, _, .of_smul s m n => (AddCon.ker_rel _).2 <| by rw [FreeAddMonoid.lift_eval_of, FreeAddMonoid.lift_eval_of, hf] | _, _, .add_comm x y => (AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm] @[simp] theorem liftAddHom_tmul (f : M →+ N →+ P) (hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) (m : M) (n : N) : liftAddHom f hf (m ⊗ₜ n) = f m n := rfl variable (M) @[simp] theorem zero_tmul (n : N) : (0 : M) ⊗ₜ[R] n = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_left _ #align tensor_product.zero_tmul TensorProduct.zero_tmul variable {M} theorem add_tmul (m₁ m₂ : M) (n : N) : (m₁ + m₂) ⊗ₜ n = m₁ ⊗ₜ n + m₂ ⊗ₜ[R] n := Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_left _ _ _ #align tensor_product.add_tmul TensorProduct.add_tmul variable (N) @[simp] theorem tmul_zero (m : M) : m ⊗ₜ[R] (0 : N) = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_right _ #align tensor_product.tmul_zero TensorProduct.tmul_zero variable {N} theorem tmul_add (m : M) (n₁ n₂ : N) : m ⊗ₜ (n₁ + n₂) = m ⊗ₜ n₁ + m ⊗ₜ[R] n₂ := Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_right _ _ _ #align tensor_product.tmul_add TensorProduct.tmul_add instance uniqueLeft [Subsingleton M] : Unique (M ⊗[R] N) where default := 0 uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim x 0, zero_tmul]; rfl) <| by rintro _ _ rfl rfl; apply add_zero instance uniqueRight [Subsingleton N] : Unique (M ⊗[R] N) where default := 0 uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim y 0, tmul_zero]; rfl) <| by rintro _ _ rfl rfl; apply add_zero section variable (R R' M N) /-- A typeclass for `SMul` structures which can be moved across a tensor product. This typeclass is generated automatically from an `IsScalarTower` instance, but exists so that we can also add an instance for `AddCommGroup.intModule`, allowing `z •` to be moved even if `R` does not support negation. Note that `Module R' (M ⊗[R] N)` is available even without this typeclass on `R'`; it's only needed if `TensorProduct.smul_tmul`, `TensorProduct.smul_tmul'`, or `TensorProduct.tmul_smul` is used. -/ class CompatibleSMul [DistribMulAction R' N] : Prop where smul_tmul : ∀ (r : R') (m : M) (n : N), (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) #align tensor_product.compatible_smul TensorProduct.CompatibleSMul end /-- Note that this provides the default `compatible_smul R R M N` instance through `IsScalarTower.left`. -/ instance (priority := 100) CompatibleSMul.isScalarTower [SMul R' R] [IsScalarTower R' R M] [DistribMulAction R' N] [IsScalarTower R' R N] : CompatibleSMul R R' M N := ⟨fun r m n => by conv_lhs => rw [← one_smul R m] conv_rhs => rw [← one_smul R n] rw [← smul_assoc, ← smul_assoc] exact Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_smul _ _ _⟩ #align tensor_product.compatible_smul.is_scalar_tower TensorProduct.CompatibleSMul.isScalarTower /-- `smul` can be moved from one side of the product to the other . -/ theorem smul_tmul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (m : M) (n : N) : (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) := CompatibleSMul.smul_tmul _ _ _ #align tensor_product.smul_tmul TensorProduct.smul_tmul -- Porting note: This is added as a local instance for `SMul.aux`. -- For some reason type-class inference in Lean 3 unfolded this definition. private def addMonoidWithWrongNSMul : AddMonoid (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with } attribute [local instance] addMonoidWithWrongNSMul in /-- Auxiliary function to defining scalar multiplication on tensor product. -/ def SMul.aux {R' : Type*} [SMul R' M] (r : R') : FreeAddMonoid (M × N) →+ M ⊗[R] N := FreeAddMonoid.lift fun p : M × N => (r • p.1) ⊗ₜ p.2 #align tensor_product.smul.aux TensorProduct.SMul.aux theorem SMul.aux_of {R' : Type*} [SMul R' M] (r : R') (m : M) (n : N) : SMul.aux r (.of (m, n)) = (r • m) ⊗ₜ[R] n := rfl #align tensor_product.smul.aux_of TensorProduct.SMul.aux_of variable [SMulCommClass R R' M] [SMulCommClass R R'' M] /-- Given two modules over a commutative semiring `R`, if one of the factors carries a (distributive) action of a second type of scalars `R'`, which commutes with the action of `R`, then the tensor product (over `R`) carries an action of `R'`. This instance defines this `R'` action in the case that it is the left module which has the `R'` action. Two natural ways in which this situation arises are: * Extension of scalars * A tensor product of a group representation with a module not carrying an action Note that in the special case that `R = R'`, since `R` is commutative, we just get the usual scalar action on a tensor product of two modules. This special case is important enough that, for performance reasons, we define it explicitly below. -/ instance leftHasSMul : SMul R' (M ⊗[R] N) := ⟨fun r => (addConGen (TensorProduct.Eqv R M N)).lift (SMul.aux r : _ →+ M ⊗[R] N) <| AddCon.addConGen_le fun x y hxy => match x, y, hxy with | _, _, .of_zero_left n => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, smul_zero, zero_tmul] | _, _, .of_zero_right m => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, tmul_zero] | _, _, .of_add_left m₁ m₂ n => (AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, smul_add, add_tmul] | _, _, .of_add_right m n₁ n₂ => (AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, tmul_add] | _, _, .of_smul s m n => (AddCon.ker_rel _).2 <| by rw [SMul.aux_of, SMul.aux_of, ← smul_comm, smul_tmul] | _, _, .add_comm x y => (AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm]⟩ #align tensor_product.left_has_smul TensorProduct.leftHasSMul instance : SMul R (M ⊗[R] N) := TensorProduct.leftHasSMul protected theorem smul_zero (r : R') : r • (0 : M ⊗[R] N) = 0 := AddMonoidHom.map_zero _ #align tensor_product.smul_zero TensorProduct.smul_zero protected theorem smul_add (r : R') (x y : M ⊗[R] N) : r • (x + y) = r • x + r • y := AddMonoidHom.map_add _ _ _ #align tensor_product.smul_add TensorProduct.smul_add protected theorem zero_smul (x : M ⊗[R] N) : (0 : R'') • x = 0 := have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by rw [TensorProduct.smul_zero]) (fun m n => by rw [this, zero_smul, zero_tmul]) fun x y ihx ihy => by rw [TensorProduct.smul_add, ihx, ihy, add_zero] #align tensor_product.zero_smul TensorProduct.zero_smul protected theorem one_smul (x : M ⊗[R] N) : (1 : R') • x = x := have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by rw [TensorProduct.smul_zero]) (fun m n => by rw [this, one_smul]) fun x y ihx ihy => by rw [TensorProduct.smul_add, ihx, ihy] #align tensor_product.one_smul TensorProduct.one_smul protected theorem add_smul (r s : R'') (x : M ⊗[R] N) : (r + s) • x = r • x + s • x := have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by simp_rw [TensorProduct.smul_zero, add_zero]) (fun m n => by simp_rw [this, add_smul, add_tmul]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add] rw [ihx, ihy, add_add_add_comm] #align tensor_product.add_smul TensorProduct.add_smul instance addMonoid : AddMonoid (M ⊗[R] N) := { TensorProduct.addZeroClass _ _ with toAddSemigroup := TensorProduct.addSemigroup _ _ toZero := (TensorProduct.addZeroClass _ _).toZero nsmul := fun n v => n • v nsmul_zero := by simp [TensorProduct.zero_smul] nsmul_succ := by simp only [TensorProduct.one_smul, TensorProduct.add_smul, add_comm, forall_const] } instance addCommMonoid : AddCommMonoid (M ⊗[R] N) := { TensorProduct.addCommSemigroup _ _ with toAddMonoid := TensorProduct.addMonoid } instance leftDistribMulAction : DistribMulAction R' (M ⊗[R] N) := have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl { smul_add := fun r x y => TensorProduct.smul_add r x y mul_smul := fun r s x => x.induction_on (by simp_rw [TensorProduct.smul_zero]) (fun m n => by simp_rw [this, mul_smul]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add] rw [ihx, ihy] one_smul := TensorProduct.one_smul smul_zero := TensorProduct.smul_zero } #align tensor_product.left_distrib_mul_action TensorProduct.leftDistribMulAction instance : DistribMulAction R (M ⊗[R] N) := TensorProduct.leftDistribMulAction theorem smul_tmul' (r : R') (m : M) (n : N) : r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := rfl #align tensor_product.smul_tmul' TensorProduct.smul_tmul' @[simp] theorem tmul_smul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (x : M) (y : N) : x ⊗ₜ (r • y) = r • x ⊗ₜ[R] y := (smul_tmul _ _ _).symm #align tensor_product.tmul_smul TensorProduct.tmul_smul theorem smul_tmul_smul (r s : R) (m : M) (n : N) : (r • m) ⊗ₜ[R] (s • n) = (r * s) • m ⊗ₜ[R] n := by simp_rw [smul_tmul, tmul_smul, mul_smul] #align tensor_product.smul_tmul_smul TensorProduct.smul_tmul_smul instance leftModule : Module R'' (M ⊗[R] N) := { add_smul := TensorProduct.add_smul zero_smul := TensorProduct.zero_smul } #align tensor_product.left_module TensorProduct.leftModule instance : Module R (M ⊗[R] N) := TensorProduct.leftModule instance [Module R''ᵐᵒᵖ M] [IsCentralScalar R'' M] : IsCentralScalar R'' (M ⊗[R] N) where op_smul_eq_smul r x := x.induction_on (by rw [smul_zero, smul_zero]) (fun x y => by rw [smul_tmul', smul_tmul', op_smul_eq_smul]) fun x y hx hy => by rw [smul_add, smul_add, hx, hy] section -- Like `R'`, `R'₂` provides a `DistribMulAction R'₂ (M ⊗[R] N)` variable {R'₂ : Type*} [Monoid R'₂] [DistribMulAction R'₂ M] variable [SMulCommClass R R'₂ M] /-- `SMulCommClass R' R'₂ M` implies `SMulCommClass R' R'₂ (M ⊗[R] N)` -/ instance smulCommClass_left [SMulCommClass R' R'₂ M] : SMulCommClass R' R'₂ (M ⊗[R] N) where smul_comm r' r'₂ x := TensorProduct.induction_on x (by simp_rw [TensorProduct.smul_zero]) (fun m n => by simp_rw [smul_tmul', smul_comm]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add]; rw [ihx, ihy] #align tensor_product.smul_comm_class_left TensorProduct.smulCommClass_left variable [SMul R'₂ R'] /-- `IsScalarTower R'₂ R' M` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/ instance isScalarTower_left [IsScalarTower R'₂ R' M] : IsScalarTower R'₂ R' (M ⊗[R] N) := ⟨fun s r x => x.induction_on (by simp) (fun m n => by rw [smul_tmul', smul_tmul', smul_tmul', smul_assoc]) fun x y ihx ihy => by rw [smul_add, smul_add, smul_add, ihx, ihy]⟩ #align tensor_product.is_scalar_tower_left TensorProduct.isScalarTower_left variable [DistribMulAction R'₂ N] [DistribMulAction R' N] variable [CompatibleSMul R R'₂ M N] [CompatibleSMul R R' M N] /-- `IsScalarTower R'₂ R' N` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/ instance isScalarTower_right [IsScalarTower R'₂ R' N] : IsScalarTower R'₂ R' (M ⊗[R] N) := ⟨fun s r x => x.induction_on (by simp) (fun m n => by rw [← tmul_smul, ← tmul_smul, ← tmul_smul, smul_assoc]) fun x y ihx ihy => by rw [smul_add, smul_add, smul_add, ihx, ihy]⟩ #align tensor_product.is_scalar_tower_right TensorProduct.isScalarTower_right end /-- A short-cut instance for the common case, where the requirements for the `compatible_smul` instances are sufficient. -/ instance isScalarTower [SMul R' R] [IsScalarTower R' R M] : IsScalarTower R' R (M ⊗[R] N) := TensorProduct.isScalarTower_left #align tensor_product.is_scalar_tower TensorProduct.isScalarTower -- or right variable (R M N) /-- The canonical bilinear map `M → N → M ⊗[R] N`. -/ def mk : M →ₗ[R] N →ₗ[R] M ⊗[R] N := LinearMap.mk₂ R (· ⊗ₜ ·) add_tmul (fun c m n => by simp_rw [smul_tmul, tmul_smul]) tmul_add tmul_smul #align tensor_product.mk TensorProduct.mk variable {R M N} @[simp] theorem mk_apply (m : M) (n : N) : mk R M N m n = m ⊗ₜ n := rfl #align tensor_product.mk_apply TensorProduct.mk_apply theorem ite_tmul (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] : (if P then x₁ else 0) ⊗ₜ[R] x₂ = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp #align tensor_product.ite_tmul TensorProduct.ite_tmul theorem tmul_ite (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] : (x₁ ⊗ₜ[R] if P then x₂ else 0) = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp #align tensor_product.tmul_ite TensorProduct.tmul_ite section theorem sum_tmul {α : Type*} (s : Finset α) (m : α → M) (n : N) : (∑ a ∈ s, m a) ⊗ₜ[R] n = ∑ a ∈ s, m a ⊗ₜ[R] n := by classical induction' s using Finset.induction with a s has ih h · simp · simp [Finset.sum_insert has, add_tmul, ih] #align tensor_product.sum_tmul TensorProduct.sum_tmul theorem tmul_sum (m : M) {α : Type*} (s : Finset α) (n : α → N) : (m ⊗ₜ[R] ∑ a ∈ s, n a) = ∑ a ∈ s, m ⊗ₜ[R] n a := by classical induction' s using Finset.induction with a s has ih h · simp · simp [Finset.sum_insert has, tmul_add, ih] #align tensor_product.tmul_sum TensorProduct.tmul_sum end variable (R M N) /-- The simple (aka pure) elements span the tensor product. -/ theorem span_tmul_eq_top : Submodule.span R { t : M ⊗[R] N | ∃ m n, m ⊗ₜ n = t } = ⊤ := by ext t; simp only [Submodule.mem_top, iff_true_iff] refine t.induction_on ?_ ?_ ?_ · exact Submodule.zero_mem _ · intro m n apply Submodule.subset_span use m, n · intro t₁ t₂ ht₁ ht₂ exact Submodule.add_mem _ ht₁ ht₂ #align tensor_product.span_tmul_eq_top TensorProduct.span_tmul_eq_top @[simp] theorem map₂_mk_top_top_eq_top : Submodule.map₂ (mk R M N) ⊤ ⊤ = ⊤ := by rw [← top_le_iff, ← span_tmul_eq_top, Submodule.map₂_eq_span_image2] exact Submodule.span_mono fun _ ⟨m, n, h⟩ => ⟨m, trivial, n, trivial, h⟩ #align tensor_product.map₂_mk_top_top_eq_top TensorProduct.map₂_mk_top_top_eq_top theorem exists_eq_tmul_of_forall (x : TensorProduct R M N) (h : ∀ (m₁ m₂ : M) (n₁ n₂ : N), ∃ m n, m₁ ⊗ₜ n₁ + m₂ ⊗ₜ n₂ = m ⊗ₜ[R] n) : ∃ m n, x = m ⊗ₜ n := by induction x using TensorProduct.induction_on with | zero => use 0, 0 rw [TensorProduct.zero_tmul] | tmul m n => use m, n | add x y h₁ h₂ => obtain ⟨m₁, n₁, rfl⟩ := h₁ obtain ⟨m₂, n₂, rfl⟩ := h₂ apply h end Module section UMP variable {M N} variable (f : M →ₗ[R] N →ₗ[R] P) /-- Auxiliary function to constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def liftAux : M ⊗[R] N →+ P := liftAddHom (LinearMap.toAddMonoidHom'.comp <| f.toAddMonoidHom) fun r m n => by dsimp; rw [LinearMap.map_smul₂, map_smul] #align tensor_product.lift_aux TensorProduct.liftAux theorem liftAux_tmul (m n) : liftAux f (m ⊗ₜ n) = f m n := rfl #align tensor_product.lift_aux_tmul TensorProduct.liftAux_tmul variable {f} @[simp] theorem liftAux.smul (r : R) (x) : liftAux f (r • x) = r • liftAux f x := TensorProduct.induction_on x (smul_zero _).symm (fun p q => by simp_rw [← tmul_smul, liftAux_tmul, (f p).map_smul]) fun p q ih1 ih2 => by simp_rw [smul_add, (liftAux f).map_add, ih1, ih2, smul_add] #align tensor_product.lift_aux.smul TensorProduct.liftAux.smul variable (f) /-- Constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def lift : M ⊗[R] N →ₗ[R] P := { liftAux f with map_smul' := liftAux.smul } #align tensor_product.lift TensorProduct.lift variable {f} @[simp] theorem lift.tmul (x y) : lift f (x ⊗ₜ y) = f x y := rfl #align tensor_product.lift.tmul TensorProduct.lift.tmul @[simp] theorem lift.tmul' (x y) : (lift f).1 (x ⊗ₜ y) = f x y := rfl #align tensor_product.lift.tmul' TensorProduct.lift.tmul' theorem ext' {g h : M ⊗[R] N →ₗ[R] P} (H : ∀ x y, g (x ⊗ₜ y) = h (x ⊗ₜ y)) : g = h := LinearMap.ext fun z => TensorProduct.induction_on z (by simp_rw [LinearMap.map_zero]) H fun x y ihx ihy => by rw [g.map_add, h.map_add, ihx, ihy] #align tensor_product.ext' TensorProduct.ext' theorem lift.unique {g : M ⊗[R] N →ₗ[R] P} (H : ∀ x y, g (x ⊗ₜ y) = f x y) : g = lift f := ext' fun m n => by rw [H, lift.tmul] #align tensor_product.lift.unique TensorProduct.lift.unique theorem lift_mk : lift (mk R M N) = LinearMap.id := Eq.symm <| lift.unique fun _ _ => rfl #align tensor_product.lift_mk TensorProduct.lift_mk theorem lift_compr₂ (g : P →ₗ[R] Q) : lift (f.compr₂ g) = g.comp (lift f) := Eq.symm <| lift.unique fun _ _ => by simp #align tensor_product.lift_compr₂ TensorProduct.lift_compr₂ theorem lift_mk_compr₂ (f : M ⊗ N →ₗ[R] P) : lift ((mk R M N).compr₂ f) = f := by rw [lift_compr₂ f, lift_mk, LinearMap.comp_id] #align tensor_product.lift_mk_compr₂ TensorProduct.lift_mk_compr₂ /-- This used to be an `@[ext]` lemma, but it fails very slowly when the `ext` tactic tries to apply it in some cases, notably when one wants to show equality of two linear maps. The `@[ext]` attribute is now added locally where it is needed. Using this as the `@[ext]` lemma instead of `TensorProduct.ext'` allows `ext` to apply lemmas specific to `M →ₗ _` and `N →ₗ _`. See note [partially-applied ext lemmas]. -/ theorem ext {g h : M ⊗ N →ₗ[R] P} (H : (mk R M N).compr₂ g = (mk R M N).compr₂ h) : g = h := by rw [← lift_mk_compr₂ g, H, lift_mk_compr₂] #align tensor_product.ext TensorProduct.ext attribute [local ext high] ext example : M → N → (M → N → P) → P := fun m => flip fun f => f m variable (R M N P) /-- Linearly constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def uncurry : (M →ₗ[R] N →ₗ[R] P) →ₗ[R] M ⊗[R] N →ₗ[R] P := LinearMap.flip <| lift <| LinearMap.lflip.comp (LinearMap.flip LinearMap.id) #align tensor_product.uncurry TensorProduct.uncurry variable {R M N P} @[simp] theorem uncurry_apply (f : M →ₗ[R] N →ₗ[R] P) (m : M) (n : N) : uncurry R M N P f (m ⊗ₜ n) = f m n := by rw [uncurry, LinearMap.flip_apply, lift.tmul]; rfl #align tensor_product.uncurry_apply TensorProduct.uncurry_apply variable (R M N P) /-- A linear equivalence constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def lift.equiv : (M →ₗ[R] N →ₗ[R] P) ≃ₗ[R] M ⊗[R] N →ₗ[R] P := { uncurry R M N P with invFun := fun f => (mk R M N).compr₂ f left_inv := fun _ => LinearMap.ext₂ fun _ _ => lift.tmul _ _ right_inv := fun _ => ext' fun _ _ => lift.tmul _ _ } #align tensor_product.lift.equiv TensorProduct.lift.equiv @[simp] theorem lift.equiv_apply (f : M →ₗ[R] N →ₗ[R] P) (m : M) (n : N) : lift.equiv R M N P f (m ⊗ₜ n) = f m n := uncurry_apply f m n #align tensor_product.lift.equiv_apply TensorProduct.lift.equiv_apply @[simp] theorem lift.equiv_symm_apply (f : M ⊗[R] N →ₗ[R] P) (m : M) (n : N) : (lift.equiv R M N P).symm f m n = f (m ⊗ₜ n) := rfl #align tensor_product.lift.equiv_symm_apply TensorProduct.lift.equiv_symm_apply /-- Given a linear map `M ⊗ N → P`, compose it with the canonical bilinear map `M → N → M ⊗ N` to form a bilinear map `M → N → P`. -/ def lcurry : (M ⊗[R] N →ₗ[R] P) →ₗ[R] M →ₗ[R] N →ₗ[R] P := (lift.equiv R M N P).symm #align tensor_product.lcurry TensorProduct.lcurry variable {R M N P} @[simp] theorem lcurry_apply (f : M ⊗[R] N →ₗ[R] P) (m : M) (n : N) : lcurry R M N P f m n = f (m ⊗ₜ n) := rfl #align tensor_product.lcurry_apply TensorProduct.lcurry_apply /-- Given a linear map `M ⊗ N → P`, compose it with the canonical bilinear map `M → N → M ⊗ N` to form a bilinear map `M → N → P`. -/ def curry (f : M ⊗[R] N →ₗ[R] P) : M →ₗ[R] N →ₗ[R] P := lcurry R M N P f #align tensor_product.curry TensorProduct.curry @[simp] theorem curry_apply (f : M ⊗ N →ₗ[R] P) (m : M) (n : N) : curry f m n = f (m ⊗ₜ n) := rfl #align tensor_product.curry_apply TensorProduct.curry_apply theorem curry_injective : Function.Injective (curry : (M ⊗[R] N →ₗ[R] P) → M →ₗ[R] N →ₗ[R] P) := fun _ _ H => ext H #align tensor_product.curry_injective TensorProduct.curry_injective theorem ext_threefold {g h : (M ⊗[R] N) ⊗[R] P →ₗ[R] Q} (H : ∀ x y z, g (x ⊗ₜ y ⊗ₜ z) = h (x ⊗ₜ y ⊗ₜ z)) : g = h := by ext x y z exact H x y z #align tensor_product.ext_threefold TensorProduct.ext_threefold -- We'll need this one for checking the pentagon identity! theorem ext_fourfold {g h : ((M ⊗[R] N) ⊗[R] P) ⊗[R] Q →ₗ[R] S} (H : ∀ w x y z, g (w ⊗ₜ x ⊗ₜ y ⊗ₜ z) = h (w ⊗ₜ x ⊗ₜ y ⊗ₜ z)) : g = h := by ext w x y z exact H w x y z #align tensor_product.ext_fourfold TensorProduct.ext_fourfold /-- Two linear maps (M ⊗ N) ⊗ (P ⊗ Q) → S which agree on all elements of the form (m ⊗ₜ n) ⊗ₜ (p ⊗ₜ q) are equal. -/ theorem ext_fourfold' {φ ψ : (M ⊗[R] N) ⊗[R] P ⊗[R] Q →ₗ[R] S} (H : ∀ w x y z, φ (w ⊗ₜ x ⊗ₜ (y ⊗ₜ z)) = ψ (w ⊗ₜ x ⊗ₜ (y ⊗ₜ z))) : φ = ψ := by ext m n p q exact H m n p q #align tensor_product.ext_fourfold' TensorProduct.ext_fourfold' end UMP variable {M N} section variable (R M) /-- The base ring is a left identity for the tensor product of modules, up to linear equivalence. -/ protected def lid : R ⊗[R] M ≃ₗ[R] M := LinearEquiv.ofLinear (lift <| LinearMap.lsmul R M) (mk R R M 1) (LinearMap.ext fun _ => by simp) (ext' fun r m => by simp; rw [← tmul_smul, ← smul_tmul, smul_eq_mul, mul_one]) #align tensor_product.lid TensorProduct.lid end @[simp] theorem lid_tmul (m : M) (r : R) : (TensorProduct.lid R M : R ⊗ M → M) (r ⊗ₜ m) = r • m := rfl #align tensor_product.lid_tmul TensorProduct.lid_tmul @[simp] theorem lid_symm_apply (m : M) : (TensorProduct.lid R M).symm m = 1 ⊗ₜ m := rfl #align tensor_product.lid_symm_apply TensorProduct.lid_symm_apply section variable (R M N) /-- The tensor product of modules is commutative, up to linear equivalence. -/ protected def comm : M ⊗[R] N ≃ₗ[R] N ⊗[R] M := LinearEquiv.ofLinear (lift (mk R N M).flip) (lift (mk R M N).flip) (ext' fun _ _ => rfl) (ext' fun _ _ => rfl) #align tensor_product.comm TensorProduct.comm @[simp] theorem comm_tmul (m : M) (n : N) : (TensorProduct.comm R M N) (m ⊗ₜ n) = n ⊗ₜ m := rfl #align tensor_product.comm_tmul TensorProduct.comm_tmul @[simp] theorem comm_symm_tmul (m : M) (n : N) : (TensorProduct.comm R M N).symm (n ⊗ₜ m) = m ⊗ₜ n := rfl #align tensor_product.comm_symm_tmul TensorProduct.comm_symm_tmul lemma lift_comp_comm_eq (f : M →ₗ[R] N →ₗ[R] P) : lift f ∘ₗ TensorProduct.comm R N M = lift f.flip := ext rfl end section variable (R M) /-- The base ring is a right identity for the tensor product of modules, up to linear equivalence. -/ protected def rid : M ⊗[R] R ≃ₗ[R] M := LinearEquiv.trans (TensorProduct.comm R M R) (TensorProduct.lid R M) #align tensor_product.rid TensorProduct.rid end @[simp] theorem rid_tmul (m : M) (r : R) : (TensorProduct.rid R M) (m ⊗ₜ r) = r • m := rfl #align tensor_product.rid_tmul TensorProduct.rid_tmul @[simp] theorem rid_symm_apply (m : M) : (TensorProduct.rid R M).symm m = m ⊗ₜ 1 := rfl #align tensor_product.rid_symm_apply TensorProduct.rid_symm_apply variable (R) in theorem lid_eq_rid : TensorProduct.lid R R = TensorProduct.rid R R := LinearEquiv.toLinearMap_injective <| ext' mul_comm open LinearMap section variable (R M N P) /-- The associator for tensor product of R-modules, as a linear equivalence. -/ protected def assoc : (M ⊗[R] N) ⊗[R] P ≃ₗ[R] M ⊗[R] N ⊗[R] P := by refine LinearEquiv.ofLinear (lift <| lift <| comp (lcurry R _ _ _) <| mk _ _ _) (lift <| comp (uncurry R _ _ _) <| curry <| mk _ _ _) (ext <| LinearMap.ext fun m => ext' fun n p => ?_) (ext <| flip_inj <| LinearMap.ext fun p => ext' fun m n => ?_) <;> repeat' first |rw [lift.tmul]|rw [compr₂_apply]|rw [comp_apply]|rw [mk_apply]|rw [flip_apply] |rw [lcurry_apply]|rw [uncurry_apply]|rw [curry_apply]|rw [id_apply] #align tensor_product.assoc TensorProduct.assoc end @[simp] theorem assoc_tmul (m : M) (n : N) (p : P) : (TensorProduct.assoc R M N P) (m ⊗ₜ n ⊗ₜ p) = m ⊗ₜ (n ⊗ₜ p) := rfl #align tensor_product.assoc_tmul TensorProduct.assoc_tmul @[simp] theorem assoc_symm_tmul (m : M) (n : N) (p : P) : (TensorProduct.assoc R M N P).symm (m ⊗ₜ (n ⊗ₜ p)) = m ⊗ₜ n ⊗ₜ p := rfl #align tensor_product.assoc_symm_tmul TensorProduct.assoc_symm_tmul /-- The tensor product of a pair of linear maps between modules. -/ def map (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : M ⊗[R] N →ₗ[R] P ⊗[R] Q := lift <| comp (compl₂ (mk _ _ _) g) f #align tensor_product.map TensorProduct.map @[simp] theorem map_tmul (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (m : M) (n : N) : map f g (m ⊗ₜ n) = f m ⊗ₜ g n := rfl #align tensor_product.map_tmul TensorProduct.map_tmul /-- Given linear maps `f : M → P`, `g : N → Q`, if we identify `M ⊗ N` with `N ⊗ M` and `P ⊗ Q` with `Q ⊗ P`, then this lemma states that `f ⊗ g = g ⊗ f`. -/ lemma map_comp_comm_eq (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : map f g ∘ₗ TensorProduct.comm R N M = TensorProduct.comm R Q P ∘ₗ map g f := ext rfl lemma map_comm (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (x : N ⊗[R] M): map f g (TensorProduct.comm R N M x) = TensorProduct.comm R Q P (map g f x) := DFunLike.congr_fun (map_comp_comm_eq _ _) _ /-- Given linear maps `f : M → Q`, `g : N → S`, and `h : P → T`, if we identify `(M ⊗ N) ⊗ P` with `M ⊗ (N ⊗ P)` and `(Q ⊗ S) ⊗ T` with `Q ⊗ (S ⊗ T)`, then this lemma states that `f ⊗ (g ⊗ h) = (f ⊗ g) ⊗ h`. -/ lemma map_map_comp_assoc_eq (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) : map f (map g h) ∘ₗ TensorProduct.assoc R M N P = TensorProduct.assoc R Q S T ∘ₗ map (map f g) h := ext <| ext <| LinearMap.ext fun _ => LinearMap.ext fun _ => LinearMap.ext fun _ => rfl lemma map_map_assoc (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) (x : (M ⊗[R] N) ⊗[R] P) : map f (map g h) (TensorProduct.assoc R M N P x) = TensorProduct.assoc R Q S T (map (map f g) h x) := DFunLike.congr_fun (map_map_comp_assoc_eq _ _ _) _ /-- Given linear maps `f : M → Q`, `g : N → S`, and `h : P → T`, if we identify `M ⊗ (N ⊗ P)` with `(M ⊗ N) ⊗ P` and `Q ⊗ (S ⊗ T)` with `(Q ⊗ S) ⊗ T`, then this lemma states that `(f ⊗ g) ⊗ h = f ⊗ (g ⊗ h)`. -/ lemma map_map_comp_assoc_symm_eq (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) : map (map f g) h ∘ₗ (TensorProduct.assoc R M N P).symm = (TensorProduct.assoc R Q S T).symm ∘ₗ map f (map g h) := ext <| LinearMap.ext fun _ => ext <| LinearMap.ext fun _ => LinearMap.ext fun _ => rfl lemma map_map_assoc_symm (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) (x : M ⊗[R] (N ⊗[R] P)) : map (map f g) h ((TensorProduct.assoc R M N P).symm x) = (TensorProduct.assoc R Q S T).symm (map f (map g h) x) := DFunLike.congr_fun (map_map_comp_assoc_symm_eq _ _ _) _ theorem map_range_eq_span_tmul (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : range (map f g) = Submodule.span R { t | ∃ m n, f m ⊗ₜ g n = t } := by simp only [← Submodule.map_top, ← span_tmul_eq_top, Submodule.map_span, Set.mem_image, Set.mem_setOf_eq] congr; ext t constructor · rintro ⟨_, ⟨⟨m, n, rfl⟩, rfl⟩⟩ use m, n simp only [map_tmul] · rintro ⟨m, n, rfl⟩ refine ⟨_, ⟨⟨m, n, rfl⟩, ?_⟩⟩ simp only [map_tmul] #align tensor_product.map_range_eq_span_tmul TensorProduct.map_range_eq_span_tmul /-- Given submodules `p ⊆ P` and `q ⊆ Q`, this is the natural map: `p ⊗ q → P ⊗ Q`. -/ @[simp] def mapIncl (p : Submodule R P) (q : Submodule R Q) : p ⊗[R] q →ₗ[R] P ⊗[R] Q := map p.subtype q.subtype #align tensor_product.map_incl TensorProduct.mapIncl lemma range_mapIncl (p : Submodule R P) (q : Submodule R Q) : LinearMap.range (mapIncl p q) = Submodule.span R (Set.image2 (· ⊗ₜ ·) p q) := by rw [mapIncl, map_range_eq_span_tmul] congr; ext; simp theorem map₂_eq_range_lift_comp_mapIncl (f : P →ₗ[R] Q →ₗ[R] M) (p : Submodule R P) (q : Submodule R Q) : Submodule.map₂ f p q = LinearMap.range (lift f ∘ₗ mapIncl p q) := by simp_rw [LinearMap.range_comp, range_mapIncl, Submodule.map_span, Set.image_image2, Submodule.map₂_eq_span_image2, lift.tmul] section variable {P' Q' : Type*} variable [AddCommMonoid P'] [Module R P'] variable [AddCommMonoid Q'] [Module R Q'] theorem map_comp (f₂ : P →ₗ[R] P') (f₁ : M →ₗ[R] P) (g₂ : Q →ₗ[R] Q') (g₁ : N →ₗ[R] Q) : map (f₂.comp f₁) (g₂.comp g₁) = (map f₂ g₂).comp (map f₁ g₁) := ext' fun _ _ => rfl #align tensor_product.map_comp TensorProduct.map_comp lemma range_mapIncl_mono {p p' : Submodule R P} {q q' : Submodule R Q} (hp : p ≤ p') (hq : q ≤ q') : LinearMap.range (mapIncl p q) ≤ LinearMap.range (mapIncl p' q') := by simp_rw [range_mapIncl] exact Submodule.span_mono (Set.image2_subset hp hq) theorem lift_comp_map (i : P →ₗ[R] Q →ₗ[R] Q') (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : (lift i).comp (map f g) = lift ((i.comp f).compl₂ g) := ext' fun _ _ => rfl #align tensor_product.lift_comp_map TensorProduct.lift_comp_map attribute [local ext high] ext @[simp] theorem map_id : map (id : M →ₗ[R] M) (id : N →ₗ[R] N) = .id := by ext simp only [mk_apply, id_coe, compr₂_apply, _root_.id, map_tmul] #align tensor_product.map_id TensorProduct.map_id @[simp] theorem map_one : map (1 : M →ₗ[R] M) (1 : N →ₗ[R] N) = 1 := map_id #align tensor_product.map_one TensorProduct.map_one theorem map_mul (f₁ f₂ : M →ₗ[R] M) (g₁ g₂ : N →ₗ[R] N) : map (f₁ * f₂) (g₁ * g₂) = map f₁ g₁ * map f₂ g₂ := map_comp f₁ f₂ g₁ g₂ #align tensor_product.map_mul TensorProduct.map_mul @[simp] protected theorem map_pow (f : M →ₗ[R] M) (g : N →ₗ[R] N) (n : ℕ) : map f g ^ n = map (f ^ n) (g ^ n) := by induction' n with n ih · simp only [Nat.zero_eq, pow_zero, map_one] · simp only [pow_succ', ih, map_mul] #align tensor_product.map_pow TensorProduct.map_pow theorem map_add_left (f₁ f₂ : M →ₗ[R] P) (g : N →ₗ[R] Q) : map (f₁ + f₂) g = map f₁ g + map f₂ g := by ext simp only [add_tmul, compr₂_apply, mk_apply, map_tmul, add_apply] #align tensor_product.map_add_left TensorProduct.map_add_left theorem map_add_right (f : M →ₗ[R] P) (g₁ g₂ : N →ₗ[R] Q) : map f (g₁ + g₂) = map f g₁ + map f g₂ := by ext simp only [tmul_add, compr₂_apply, mk_apply, map_tmul, add_apply] #align tensor_product.map_add_right TensorProduct.map_add_right theorem map_smul_left (r : R) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : map (r • f) g = r • map f g := by ext simp only [smul_tmul, compr₂_apply, mk_apply, map_tmul, smul_apply, tmul_smul] #align tensor_product.map_smul_left TensorProduct.map_smul_left theorem map_smul_right (r : R) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : map f (r • g) = r • map f g := by ext simp only [smul_tmul, compr₂_apply, mk_apply, map_tmul, smul_apply, tmul_smul] #align tensor_product.map_smul_right TensorProduct.map_smul_right variable (R M N P Q) /-- The tensor product of a pair of linear maps between modules, bilinear in both maps. -/ def mapBilinear : (M →ₗ[R] P) →ₗ[R] (N →ₗ[R] Q) →ₗ[R] M ⊗[R] N →ₗ[R] P ⊗[R] Q := LinearMap.mk₂ R map map_add_left map_smul_left map_add_right map_smul_right #align tensor_product.map_bilinear TensorProduct.mapBilinear /-- The canonical linear map from `P ⊗[R] (M →ₗ[R] Q)` to `(M →ₗ[R] P ⊗[R] Q)` -/ def lTensorHomToHomLTensor : P ⊗[R] (M →ₗ[R] Q) →ₗ[R] M →ₗ[R] P ⊗[R] Q := TensorProduct.lift (llcomp R M Q _ ∘ₗ mk R P Q) #align tensor_product.ltensor_hom_to_hom_ltensor TensorProduct.lTensorHomToHomLTensor /-- The canonical linear map from `(M →ₗ[R] P) ⊗[R] Q` to `(M →ₗ[R] P ⊗[R] Q)` -/ def rTensorHomToHomRTensor : (M →ₗ[R] P) ⊗[R] Q →ₗ[R] M →ₗ[R] P ⊗[R] Q := TensorProduct.lift (llcomp R M P _ ∘ₗ (mk R P Q).flip).flip #align tensor_product.rtensor_hom_to_hom_rtensor TensorProduct.rTensorHomToHomRTensor /-- The linear map from `(M →ₗ P) ⊗ (N →ₗ Q)` to `(M ⊗ N →ₗ P ⊗ Q)` sending `f ⊗ₜ g` to the `TensorProduct.map f g`, the tensor product of the two maps. -/ def homTensorHomMap : (M →ₗ[R] P) ⊗[R] (N →ₗ[R] Q) →ₗ[R] M ⊗[R] N →ₗ[R] P ⊗[R] Q := lift (mapBilinear R M N P Q) #align tensor_product.hom_tensor_hom_map TensorProduct.homTensorHomMap variable {R M N P Q} /-- This is a binary version of `TensorProduct.map`: Given a bilinear map `f : M ⟶ P ⟶ Q` and a bilinear map `g : N ⟶ S ⟶ T`, if we think `f` and `g` as linear maps with two inputs, then `map₂ f g` is a bilinear map taking two inputs `M ⊗ N → P ⊗ S → Q ⊗ S` defined by `map₂ f g (m ⊗ n) (p ⊗ s) = f m p ⊗ g n s`. Mathematically, `TensorProduct.map₂` is defined as the composition `M ⊗ N -map→ Hom(P, Q) ⊗ Hom(S, T) -homTensorHomMap→ Hom(P ⊗ S, Q ⊗ T)`. -/ def map₂ (f : M →ₗ[R] P →ₗ[R] Q) (g : N →ₗ[R] S →ₗ[R] T) : M ⊗[R] N →ₗ[R] P ⊗[R] S →ₗ[R] Q ⊗[R] T := homTensorHomMap R _ _ _ _ ∘ₗ map f g @[simp] theorem mapBilinear_apply (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : mapBilinear R M N P Q f g = map f g := rfl #align tensor_product.map_bilinear_apply TensorProduct.mapBilinear_apply @[simp] theorem lTensorHomToHomLTensor_apply (p : P) (f : M →ₗ[R] Q) (m : M) : lTensorHomToHomLTensor R M P Q (p ⊗ₜ f) m = p ⊗ₜ f m := rfl #align tensor_product.ltensor_hom_to_hom_ltensor_apply TensorProduct.lTensorHomToHomLTensor_apply @[simp] theorem rTensorHomToHomRTensor_apply (f : M →ₗ[R] P) (q : Q) (m : M) : rTensorHomToHomRTensor R M P Q (f ⊗ₜ q) m = f m ⊗ₜ q := rfl #align tensor_product.rtensor_hom_to_hom_rtensor_apply TensorProduct.rTensorHomToHomRTensor_apply @[simp] theorem homTensorHomMap_apply (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : homTensorHomMap R M N P Q (f ⊗ₜ g) = map f g := rfl #align tensor_product.hom_tensor_hom_map_apply TensorProduct.homTensorHomMap_apply @[simp] theorem map₂_apply_tmul (f : M →ₗ[R] P →ₗ[R] Q) (g : N →ₗ[R] S →ₗ[R] T) (m : M) (n : N) : map₂ f g (m ⊗ₜ n) = map (f m) (g n) := rfl @[simp] theorem map_zero_left (g : N →ₗ[R] Q) : map (0 : M →ₗ[R] P) g = 0 := (mapBilinear R M N P Q).map_zero₂ _ @[simp] theorem map_zero_right (f : M →ₗ[R] P) : map f (0 : N →ₗ[R] Q) = 0 := (mapBilinear R M N P Q _).map_zero end /-- If `M` and `P` are linearly equivalent and `N` and `Q` are linearly equivalent then `M ⊗ N` and `P ⊗ Q` are linearly equivalent. -/ def congr (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : M ⊗[R] N ≃ₗ[R] P ⊗[R] Q := LinearEquiv.ofLinear (map f g) (map f.symm g.symm) (ext' fun m n => by simp) (ext' fun m n => by simp) #align tensor_product.congr TensorProduct.congr @[simp] theorem congr_tmul (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (m : M) (n : N) : congr f g (m ⊗ₜ n) = f m ⊗ₜ g n := rfl #align tensor_product.congr_tmul TensorProduct.congr_tmul @[simp] theorem congr_symm_tmul (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (p : P) (q : Q) : (congr f g).symm (p ⊗ₜ q) = f.symm p ⊗ₜ g.symm q := rfl #align tensor_product.congr_symm_tmul TensorProduct.congr_symm_tmul theorem congr_symm (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : (congr f g).symm = congr f.symm g.symm := rfl @[simp] theorem congr_refl_refl : congr (.refl R M) (.refl R N) = .refl R _ := LinearEquiv.toLinearMap_injective <| ext' fun _ _ ↦ rfl theorem congr_trans (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (f' : P ≃ₗ[R] S) (g' : Q ≃ₗ[R] T) : congr (f ≪≫ₗ f') (g ≪≫ₗ g') = congr f g ≪≫ₗ congr f' g' := LinearEquiv.toLinearMap_injective <| map_comp _ _ _ _ theorem congr_mul (f : M ≃ₗ[R] M) (g : N ≃ₗ[R] N) (f' : M ≃ₗ[R] M) (g' : N ≃ₗ[R] N) : congr (f * f') (g * g') = congr f g * congr f' g' := congr_trans _ _ _ _ @[simp] theorem congr_pow (f : M ≃ₗ[R] M) (g : N ≃ₗ[R] N) (n : ℕ) : congr f g ^ n = congr (f ^ n) (g ^ n) := by induction n with | zero => exact congr_refl_refl.symm | succ n ih => simp_rw [pow_succ, ih, congr_mul] @[simp] theorem congr_zpow (f : M ≃ₗ[R] M) (g : N ≃ₗ[R] N) (n : ℤ) : congr f g ^ n = congr (f ^ n) (g ^ n) := by induction n with | ofNat n => exact congr_pow _ _ _ | negSucc n => simp_rw [zpow_negSucc, congr_pow]; exact congr_symm _ _ variable (R M N P Q) /-- A tensor product analogue of `mul_left_comm`. -/ def leftComm : M ⊗[R] N ⊗[R] P ≃ₗ[R] N ⊗[R] M ⊗[R] P := let e₁ := (TensorProduct.assoc R M N P).symm let e₂ := congr (TensorProduct.comm R M N) (1 : P ≃ₗ[R] P) let e₃ := TensorProduct.assoc R N M P e₁ ≪≫ₗ (e₂ ≪≫ₗ e₃) #align tensor_product.left_comm TensorProduct.leftComm variable {M N P Q} @[simp] theorem leftComm_tmul (m : M) (n : N) (p : P) : leftComm R M N P (m ⊗ₜ (n ⊗ₜ p)) = n ⊗ₜ (m ⊗ₜ p) := rfl #align tensor_product.left_comm_tmul TensorProduct.leftComm_tmul @[simp] theorem leftComm_symm_tmul (m : M) (n : N) (p : P) : (leftComm R M N P).symm (n ⊗ₜ (m ⊗ₜ p)) = m ⊗ₜ (n ⊗ₜ p) := rfl #align tensor_product.left_comm_symm_tmul TensorProduct.leftComm_symm_tmul variable (M N P Q) /-- This special case is worth defining explicitly since it is useful for defining multiplication on tensor products of modules carrying multiplications (e.g., associative rings, Lie rings, ...). E.g., suppose `M = P` and `N = Q` and that `M` and `N` carry bilinear multiplications: `M ⊗ M → M` and `N ⊗ N → N`. Using `map`, we can define `(M ⊗ M) ⊗ (N ⊗ N) → M ⊗ N` which, when combined with this definition, yields a bilinear multiplication on `M ⊗ N`: `(M ⊗ N) ⊗ (M ⊗ N) → M ⊗ N`. In particular we could use this to define the multiplication in the `TensorProduct.semiring` instance (currently defined "by hand" using `TensorProduct.mul`). See also `mul_mul_mul_comm`. -/ def tensorTensorTensorComm : (M ⊗[R] N) ⊗[R] P ⊗[R] Q ≃ₗ[R] (M ⊗[R] P) ⊗[R] N ⊗[R] Q := let e₁ := TensorProduct.assoc R M N (P ⊗[R] Q) let e₂ := congr (1 : M ≃ₗ[R] M) (leftComm R N P Q) let e₃ := (TensorProduct.assoc R M P (N ⊗[R] Q)).symm e₁ ≪≫ₗ (e₂ ≪≫ₗ e₃) #align tensor_product.tensor_tensor_tensor_comm TensorProduct.tensorTensorTensorComm variable {M N P Q} @[simp] theorem tensorTensorTensorComm_tmul (m : M) (n : N) (p : P) (q : Q) : tensorTensorTensorComm R M N P Q (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ p ⊗ₜ (n ⊗ₜ q) := rfl #align tensor_product.tensor_tensor_tensor_comm_tmul TensorProduct.tensorTensorTensorComm_tmul -- Porting note: the proof here was `rfl` but that caused a timeout. @[simp] theorem tensorTensorTensorComm_symm : (tensorTensorTensorComm R M N P Q).symm = tensorTensorTensorComm R M P N Q := by ext; rfl #align tensor_product.tensor_tensor_tensor_comm_symm TensorProduct.tensorTensorTensorComm_symm variable (M N P Q) /-- This special case is useful for describing the interplay between `dualTensorHomEquiv` and composition of linear maps. E.g., composition of linear maps gives a map `(M → N) ⊗ (N → P) → (M → P)`, and applying `dual_tensor_hom_equiv.symm` to the three hom-modules gives a map `(M.dual ⊗ N) ⊗ (N.dual ⊗ P) → (M.dual ⊗ P)`, which agrees with the application of `contractRight` on `N ⊗ N.dual` after the suitable rebracketting. -/ def tensorTensorTensorAssoc : (M ⊗[R] N) ⊗[R] P ⊗[R] Q ≃ₗ[R] (M ⊗[R] N ⊗[R] P) ⊗[R] Q := (TensorProduct.assoc R (M ⊗[R] N) P Q).symm ≪≫ₗ congr (TensorProduct.assoc R M N P) (1 : Q ≃ₗ[R] Q) #align tensor_product.tensor_tensor_tensor_assoc TensorProduct.tensorTensorTensorAssoc variable {M N P Q} @[simp] theorem tensorTensorTensorAssoc_tmul (m : M) (n : N) (p : P) (q : Q) : tensorTensorTensorAssoc R M N P Q (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ (n ⊗ₜ p) ⊗ₜ q := rfl #align tensor_product.tensor_tensor_tensor_assoc_tmul TensorProduct.tensorTensorTensorAssoc_tmul @[simp] theorem tensorTensorTensorAssoc_symm_tmul (m : M) (n : N) (p : P) (q : Q) : (tensorTensorTensorAssoc R M N P Q).symm (m ⊗ₜ (n ⊗ₜ p) ⊗ₜ q) = m ⊗ₜ n ⊗ₜ (p ⊗ₜ q) := rfl #align tensor_product.tensor_tensor_tensor_assoc_symm_tmul TensorProduct.tensorTensorTensorAssoc_symm_tmul end TensorProduct open scoped TensorProduct namespace LinearMap variable {N} /-- `LinearMap.lTensor M f : M ⊗ N →ₗ M ⊗ P` is the natural linear map induced by `f : N →ₗ P`. -/ def lTensor (f : N →ₗ[R] P) : M ⊗[R] N →ₗ[R] M ⊗[R] P := TensorProduct.map id f #align linear_map.ltensor LinearMap.lTensor /-- `LinearMap.rTensor M f : N₁ ⊗ M →ₗ N₂ ⊗ M` is the natural linear map induced by `f : N₁ →ₗ N₂`. -/ def rTensor (f : N →ₗ[R] P) : N ⊗[R] M →ₗ[R] P ⊗[R] M := TensorProduct.map f id #align linear_map.rtensor LinearMap.rTensor variable (g : P →ₗ[R] Q) (f : N →ₗ[R] P) @[simp] theorem lTensor_tmul (m : M) (n : N) : f.lTensor M (m ⊗ₜ n) = m ⊗ₜ f n := rfl #align linear_map.ltensor_tmul LinearMap.lTensor_tmul @[simp] theorem rTensor_tmul (m : M) (n : N) : f.rTensor M (n ⊗ₜ m) = f n ⊗ₜ m := rfl #align linear_map.rtensor_tmul LinearMap.rTensor_tmul @[simp] theorem lTensor_comp_mk (m : M) : f.lTensor M ∘ₗ TensorProduct.mk R M N m = TensorProduct.mk R M P m ∘ₗ f := rfl @[simp] theorem rTensor_comp_flip_mk (m : M) : f.rTensor M ∘ₗ (TensorProduct.mk R N M).flip m = (TensorProduct.mk R P M).flip m ∘ₗ f := rfl lemma comm_comp_rTensor_comp_comm_eq (g : N →ₗ[R] P) : TensorProduct.comm R P Q ∘ₗ rTensor Q g ∘ₗ TensorProduct.comm R Q N = lTensor Q g := TensorProduct.ext rfl lemma comm_comp_lTensor_comp_comm_eq (g : N →ₗ[R] P) : TensorProduct.comm R Q P ∘ₗ lTensor Q g ∘ₗ TensorProduct.comm R N Q = rTensor Q g := TensorProduct.ext rfl /-- Given a linear map `f : N → P`, `f ⊗ M` is injective if and only if `M ⊗ f` is injective. -/ theorem lTensor_inj_iff_rTensor_inj : Function.Injective (lTensor M f) ↔ Function.Injective (rTensor M f) := by simp [← comm_comp_rTensor_comp_comm_eq] /-- Given a linear map `f : N → P`, `f ⊗ M` is surjective if and only if `M ⊗ f` is surjective. -/ theorem lTensor_surj_iff_rTensor_surj : Function.Surjective (lTensor M f) ↔ Function.Surjective (rTensor M f) := by simp [← comm_comp_rTensor_comp_comm_eq] /-- Given a linear map `f : N → P`, `f ⊗ M` is bijective if and only if `M ⊗ f` is bijective. -/ theorem lTensor_bij_iff_rTensor_bij : Function.Bijective (lTensor M f) ↔ Function.Bijective (rTensor M f) := by simp [← comm_comp_rTensor_comp_comm_eq] open TensorProduct attribute [local ext high] TensorProduct.ext /-- `lTensorHom M` is the natural linear map that sends a linear map `f : N →ₗ P` to `M ⊗ f`. -/ def lTensorHom : (N →ₗ[R] P) →ₗ[R] M ⊗[R] N →ₗ[R] M ⊗[R] P where toFun := lTensor M map_add' f g := by ext x y simp only [compr₂_apply, mk_apply, add_apply, lTensor_tmul, tmul_add] map_smul' r f := by dsimp ext x y simp only [compr₂_apply, mk_apply, tmul_smul, smul_apply, lTensor_tmul] #align linear_map.ltensor_hom LinearMap.lTensorHom /-- `rTensorHom M` is the natural linear map that sends a linear map `f : N →ₗ P` to `f ⊗ M`. -/ def rTensorHom : (N →ₗ[R] P) →ₗ[R] N ⊗[R] M →ₗ[R] P ⊗[R] M where toFun f := f.rTensor M map_add' f g := by ext x y simp only [compr₂_apply, mk_apply, add_apply, rTensor_tmul, add_tmul] map_smul' r f := by dsimp ext x y simp only [compr₂_apply, mk_apply, smul_tmul, tmul_smul, smul_apply, rTensor_tmul] #align linear_map.rtensor_hom LinearMap.rTensorHom @[simp] theorem coe_lTensorHom : (lTensorHom M : (N →ₗ[R] P) → M ⊗[R] N →ₗ[R] M ⊗[R] P) = lTensor M := rfl #align linear_map.coe_ltensor_hom LinearMap.coe_lTensorHom @[simp] theorem coe_rTensorHom : (rTensorHom M : (N →ₗ[R] P) → N ⊗[R] M →ₗ[R] P ⊗[R] M) = rTensor M := rfl #align linear_map.coe_rtensor_hom LinearMap.coe_rTensorHom @[simp] theorem lTensor_add (f g : N →ₗ[R] P) : (f + g).lTensor M = f.lTensor M + g.lTensor M := (lTensorHom M).map_add f g #align linear_map.ltensor_add LinearMap.lTensor_add @[simp] theorem rTensor_add (f g : N →ₗ[R] P) : (f + g).rTensor M = f.rTensor M + g.rTensor M := (rTensorHom M).map_add f g #align linear_map.rtensor_add LinearMap.rTensor_add @[simp] theorem lTensor_zero : lTensor M (0 : N →ₗ[R] P) = 0 := (lTensorHom M).map_zero #align linear_map.ltensor_zero LinearMap.lTensor_zero @[simp] theorem rTensor_zero : rTensor M (0 : N →ₗ[R] P) = 0 := (rTensorHom M).map_zero #align linear_map.rtensor_zero LinearMap.rTensor_zero @[simp] theorem lTensor_smul (r : R) (f : N →ₗ[R] P) : (r • f).lTensor M = r • f.lTensor M := (lTensorHom M).map_smul r f #align linear_map.ltensor_smul LinearMap.lTensor_smul @[simp] theorem rTensor_smul (r : R) (f : N →ₗ[R] P) : (r • f).rTensor M = r • f.rTensor M := (rTensorHom M).map_smul r f #align linear_map.rtensor_smul LinearMap.rTensor_smul theorem lTensor_comp : (g.comp f).lTensor M = (g.lTensor M).comp (f.lTensor M) := by ext m n simp only [compr₂_apply, mk_apply, comp_apply, lTensor_tmul] #align linear_map.ltensor_comp LinearMap.lTensor_comp theorem lTensor_comp_apply (x : M ⊗[R] N) : (g.comp f).lTensor M x = (g.lTensor M) ((f.lTensor M) x) := by rw [lTensor_comp, coe_comp]; rfl #align linear_map.ltensor_comp_apply LinearMap.lTensor_comp_apply theorem rTensor_comp : (g.comp f).rTensor M = (g.rTensor M).comp (f.rTensor M) := by ext m n simp only [compr₂_apply, mk_apply, comp_apply, rTensor_tmul] #align linear_map.rtensor_comp LinearMap.rTensor_comp
Mathlib/LinearAlgebra/TensorProduct/Basic.lean
1,298
1,299
theorem rTensor_comp_apply (x : N ⊗[R] M) : (g.comp f).rTensor M x = (g.rTensor M) ((f.rTensor M) x) := by
rw [rTensor_comp, coe_comp]; rfl
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Analysis.InnerProductSpace.Adjoint import Mathlib.Topology.Algebra.Module.Basic #align_import analysis.inner_product_space.linear_pmap from "leanprover-community/mathlib"@"8b981918a93bc45a8600de608cde7944a80d92b9" /-! # Partially defined linear operators on Hilbert spaces We will develop the basics of the theory of unbounded operators on Hilbert spaces. ## Main definitions * `LinearPMap.IsFormalAdjoint`: An operator `T` is a formal adjoint of `S` if for all `x` in the domain of `T` and `y` in the domain of `S`, we have that `⟪T x, y⟫ = ⟪x, S y⟫`. * `LinearPMap.adjoint`: The adjoint of a map `E →ₗ.[𝕜] F` as a map `F →ₗ.[𝕜] E`. ## Main statements * `LinearPMap.adjoint_isFormalAdjoint`: The adjoint is a formal adjoint * `LinearPMap.IsFormalAdjoint.le_adjoint`: Every formal adjoint is contained in the adjoint * `ContinuousLinearMap.toPMap_adjoint_eq_adjoint_toPMap_of_dense`: The adjoint on `ContinuousLinearMap` and `LinearPMap` coincide. ## Notation * For `T : E →ₗ.[𝕜] F` the adjoint can be written as `T†`. This notation is localized in `LinearPMap`. ## Implementation notes We use the junk value pattern to define the adjoint for all `LinearPMap`s. In the case that `T : E →ₗ.[𝕜] F` is not densely defined the adjoint `T†` is the zero map from `T.adjoint.domain` to `E`. ## References * [J. Weidmann, *Linear Operators in Hilbert Spaces*][weidmann_linear] ## Tags Unbounded operators, closed operators -/ noncomputable section open RCLike open scoped ComplexConjugate Classical variable {𝕜 E F G : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y namespace LinearPMap /-- An operator `T` is a formal adjoint of `S` if for all `x` in the domain of `T` and `y` in the domain of `S`, we have that `⟪T x, y⟫ = ⟪x, S y⟫`. -/ def IsFormalAdjoint (T : E →ₗ.[𝕜] F) (S : F →ₗ.[𝕜] E) : Prop := ∀ (x : T.domain) (y : S.domain), ⟪T x, y⟫ = ⟪(x : E), S y⟫ #align linear_pmap.is_formal_adjoint LinearPMap.IsFormalAdjoint variable {T : E →ₗ.[𝕜] F} {S : F →ₗ.[𝕜] E} @[symm] protected theorem IsFormalAdjoint.symm (h : T.IsFormalAdjoint S) : S.IsFormalAdjoint T := fun y _ => by rw [← inner_conj_symm, ← inner_conj_symm (y : F), h] #align linear_pmap.is_formal_adjoint.symm LinearPMap.IsFormalAdjoint.symm variable (T) /-- The domain of the adjoint operator. This definition is needed to construct the adjoint operator and the preferred version to use is `T.adjoint.domain` instead of `T.adjointDomain`. -/ def adjointDomain : Submodule 𝕜 F where carrier := {y | Continuous ((innerₛₗ 𝕜 y).comp T.toFun)} zero_mem' := by rw [Set.mem_setOf_eq, LinearMap.map_zero, LinearMap.zero_comp] exact continuous_zero add_mem' hx hy := by rw [Set.mem_setOf_eq, LinearMap.map_add] at *; exact hx.add hy smul_mem' a x hx := by rw [Set.mem_setOf_eq, LinearMap.map_smulₛₗ] at * exact hx.const_smul (conj a) #align linear_pmap.adjoint_domain LinearPMap.adjointDomain /-- The operator `fun x ↦ ⟪y, T x⟫` considered as a continuous linear operator from `T.adjointDomain` to `𝕜`. -/ def adjointDomainMkCLM (y : T.adjointDomain) : T.domain →L[𝕜] 𝕜 := ⟨(innerₛₗ 𝕜 (y : F)).comp T.toFun, y.prop⟩ #align linear_pmap.adjoint_domain_mk_clm LinearPMap.adjointDomainMkCLM theorem adjointDomainMkCLM_apply (y : T.adjointDomain) (x : T.domain) : adjointDomainMkCLM T y x = ⟪(y : F), T x⟫ := rfl #align linear_pmap.adjoint_domain_mk_clm_apply LinearPMap.adjointDomainMkCLM_apply variable {T} variable (hT : Dense (T.domain : Set E)) /-- The unique continuous extension of the operator `adjointDomainMkCLM` to `E`. -/ def adjointDomainMkCLMExtend (y : T.adjointDomain) : E →L[𝕜] 𝕜 := (T.adjointDomainMkCLM y).extend (Submodule.subtypeL T.domain) hT.denseRange_val uniformEmbedding_subtype_val.toUniformInducing #align linear_pmap.adjoint_domain_mk_clm_extend LinearPMap.adjointDomainMkCLMExtend @[simp] theorem adjointDomainMkCLMExtend_apply (y : T.adjointDomain) (x : T.domain) : adjointDomainMkCLMExtend hT y (x : E) = ⟪(y : F), T x⟫ := ContinuousLinearMap.extend_eq _ _ _ _ _ #align linear_pmap.adjoint_domain_mk_clm_extend_apply LinearPMap.adjointDomainMkCLMExtend_apply variable [CompleteSpace E] /-- The adjoint as a linear map from its domain to `E`. This is an auxiliary definition needed to define the adjoint operator as a `LinearPMap` without the assumption that `T.domain` is dense. -/ def adjointAux : T.adjointDomain →ₗ[𝕜] E where toFun y := (InnerProductSpace.toDual 𝕜 E).symm (adjointDomainMkCLMExtend hT y) map_add' x y := hT.eq_of_inner_left fun _ => by simp only [inner_add_left, Submodule.coe_add, InnerProductSpace.toDual_symm_apply, adjointDomainMkCLMExtend_apply] map_smul' _ _ := hT.eq_of_inner_left fun _ => by simp only [inner_smul_left, Submodule.coe_smul_of_tower, RingHom.id_apply, InnerProductSpace.toDual_symm_apply, adjointDomainMkCLMExtend_apply] #align linear_pmap.adjoint_aux LinearPMap.adjointAux theorem adjointAux_inner (y : T.adjointDomain) (x : T.domain) : ⟪adjointAux hT y, x⟫ = ⟪(y : F), T x⟫ := by simp only [adjointAux, LinearMap.coe_mk, InnerProductSpace.toDual_symm_apply, adjointDomainMkCLMExtend_apply] -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5026): -- mathlib3 was finished here simp only [AddHom.coe_mk, InnerProductSpace.toDual_symm_apply] rw [adjointDomainMkCLMExtend_apply] #align linear_pmap.adjoint_aux_inner LinearPMap.adjointAux_inner theorem adjointAux_unique (y : T.adjointDomain) {x₀ : E} (hx₀ : ∀ x : T.domain, ⟪x₀, x⟫ = ⟪(y : F), T x⟫) : adjointAux hT y = x₀ := hT.eq_of_inner_left fun v => (adjointAux_inner hT _ _).trans (hx₀ v).symm #align linear_pmap.adjoint_aux_unique LinearPMap.adjointAux_unique variable (T) /-- The adjoint operator as a partially defined linear operator. -/ def adjoint : F →ₗ.[𝕜] E where domain := T.adjointDomain toFun := if hT : Dense (T.domain : Set E) then adjointAux hT else 0 #align linear_pmap.adjoint LinearPMap.adjoint scoped postfix:1024 "†" => LinearPMap.adjoint theorem mem_adjoint_domain_iff (y : F) : y ∈ T†.domain ↔ Continuous ((innerₛₗ 𝕜 y).comp T.toFun) := Iff.rfl #align linear_pmap.mem_adjoint_domain_iff LinearPMap.mem_adjoint_domain_iff variable {T} theorem mem_adjoint_domain_of_exists (y : F) (h : ∃ w : E, ∀ x : T.domain, ⟪w, x⟫ = ⟪y, T x⟫) : y ∈ T†.domain := by cases' h with w hw rw [T.mem_adjoint_domain_iff] -- Porting note: was `by continuity` have : Continuous ((innerSL 𝕜 w).comp T.domain.subtypeL) := ContinuousLinearMap.continuous _ convert this using 1 exact funext fun x => (hw x).symm #align linear_pmap.mem_adjoint_domain_of_exists LinearPMap.mem_adjoint_domain_of_exists theorem adjoint_apply_of_not_dense (hT : ¬Dense (T.domain : Set E)) (y : T†.domain) : T† y = 0 := by change (if hT : Dense (T.domain : Set E) then adjointAux hT else 0) y = _ simp only [hT, not_false_iff, dif_neg, LinearMap.zero_apply] #align linear_pmap.adjoint_apply_of_not_dense LinearPMap.adjoint_apply_of_not_dense
Mathlib/Analysis/InnerProductSpace/LinearPMap.lean
186
188
theorem adjoint_apply_of_dense (y : T†.domain) : T† y = adjointAux hT y := by
change (if hT : Dense (T.domain : Set E) then adjointAux hT else 0) y = _ simp only [hT, dif_pos, LinearMap.coe_mk]
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Chris Hughes -/ import Mathlib.Algebra.GeomSum import Mathlib.Algebra.Polynomial.Roots import Mathlib.GroupTheory.SpecificGroups.Cyclic #align_import ring_theory.integral_domain from "leanprover-community/mathlib"@"6e70e0d419bf686784937d64ed4bfde866ff229e" /-! # Integral domains Assorted theorems about integral domains. ## Main theorems * `isCyclic_of_subgroup_isDomain`: A finite subgroup of the units of an integral domain is cyclic. * `Fintype.fieldOfDomain`: A finite integral domain is a field. ## Notes Wedderburn's little theorem, which shows that all finite division rings are actually fields, is in `Mathlib.RingTheory.LittleWedderburn`. ## Tags integral domain, finite integral domain, finite field -/ section open Finset Polynomial Function Nat section CancelMonoidWithZero -- There doesn't seem to be a better home for these right now variable {M : Type*} [CancelMonoidWithZero M] [Finite M] theorem mul_right_bijective_of_finite₀ {a : M} (ha : a ≠ 0) : Bijective fun b => a * b := Finite.injective_iff_bijective.1 <| mul_right_injective₀ ha #align mul_right_bijective_of_finite₀ mul_right_bijective_of_finite₀ theorem mul_left_bijective_of_finite₀ {a : M} (ha : a ≠ 0) : Bijective fun b => b * a := Finite.injective_iff_bijective.1 <| mul_left_injective₀ ha #align mul_left_bijective_of_finite₀ mul_left_bijective_of_finite₀ /-- Every finite nontrivial cancel_monoid_with_zero is a group_with_zero. -/ def Fintype.groupWithZeroOfCancel (M : Type*) [CancelMonoidWithZero M] [DecidableEq M] [Fintype M] [Nontrivial M] : GroupWithZero M := { ‹Nontrivial M›, ‹CancelMonoidWithZero M› with inv := fun a => if h : a = 0 then 0 else Fintype.bijInv (mul_right_bijective_of_finite₀ h) 1 mul_inv_cancel := fun a ha => by simp only [Inv.inv, dif_neg ha] exact Fintype.rightInverse_bijInv _ _ inv_zero := by simp [Inv.inv, dif_pos rfl] } #align fintype.group_with_zero_of_cancel Fintype.groupWithZeroOfCancel theorem exists_eq_pow_of_mul_eq_pow_of_coprime {R : Type*} [CommSemiring R] [IsDomain R] [GCDMonoid R] [Unique Rˣ] {a b c : R} {n : ℕ} (cp : IsCoprime a b) (h : a * b = c ^ n) : ∃ d : R, a = d ^ n := by refine exists_eq_pow_of_mul_eq_pow (isUnit_of_dvd_one ?_) h obtain ⟨x, y, hxy⟩ := cp rw [← hxy] exact -- Porting note: added `GCDMonoid.` twice dvd_add (dvd_mul_of_dvd_right (GCDMonoid.gcd_dvd_left _ _) _) (dvd_mul_of_dvd_right (GCDMonoid.gcd_dvd_right _ _) _) #align exists_eq_pow_of_mul_eq_pow_of_coprime exists_eq_pow_of_mul_eq_pow_of_coprime nonrec
Mathlib/RingTheory/IntegralDomain.lean
73
84
theorem Finset.exists_eq_pow_of_mul_eq_pow_of_coprime {ι R : Type*} [CommSemiring R] [IsDomain R] [GCDMonoid R] [Unique Rˣ] {n : ℕ} {c : R} {s : Finset ι} {f : ι → R} (h : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → IsCoprime (f i) (f j)) (hprod : ∏ i ∈ s, f i = c ^ n) : ∀ i ∈ s, ∃ d : R, f i = d ^ n := by
classical intro i hi rw [← insert_erase hi, prod_insert (not_mem_erase i s)] at hprod refine exists_eq_pow_of_mul_eq_pow_of_coprime (IsCoprime.prod_right fun j hj => h i hi j (erase_subset i s hj) fun hij => ?_) hprod rw [hij] at hj exact (s.not_mem_erase _) hj
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Set.Function import Mathlib.Logic.Equiv.Defs import Mathlib.Tactic.Core import Mathlib.Tactic.Attr.Core #align_import logic.equiv.local_equiv from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Partial equivalences This files defines equivalences between subsets of given types. An element `e` of `PartialEquiv α β` is made of two maps `e.toFun` and `e.invFun` respectively from α to β and from β to α (just like equivs), which are inverse to each other on the subsets `e.source` and `e.target` of respectively α and β. They are designed in particular to define charts on manifolds. The main functionality is `e.trans f`, which composes the two partial equivalences by restricting the source and target to the maximal set where the composition makes sense. As for equivs, we register a coercion to functions and use it in our simp normal form: we write `e x` and `e.symm y` instead of `e.toFun x` and `e.invFun y`. ## Main definitions * `Equiv.toPartialEquiv`: associating a partial equiv to an equiv, with source = target = univ * `PartialEquiv.symm`: the inverse of a partial equivalence * `PartialEquiv.trans`: the composition of two partial equivalences * `PartialEquiv.refl`: the identity partial equivalence * `PartialEquiv.ofSet`: the identity on a set `s` * `EqOnSource`: equivalence relation describing the "right" notion of equality for partial equivalences (see below in implementation notes) ## Implementation notes There are at least three possible implementations of partial equivalences: * equivs on subtypes * pairs of functions taking values in `Option α` and `Option β`, equal to none where the partial equivalence is not defined * pairs of functions defined everywhere, keeping the source and target as additional data Each of these implementations has pros and cons. * When dealing with subtypes, one still need to define additional API for composition and restriction of domains. Checking that one always belongs to the right subtype makes things very tedious, and leads quickly to DTT hell (as the subtype `u ∩ v` is not the "same" as `v ∩ u`, for instance). * With option-valued functions, the composition is very neat (it is just the usual composition, and the domain is restricted automatically). These are implemented in `PEquiv.lean`. For manifolds, where one wants to discuss thoroughly the smoothness of the maps, this creates however a lot of overhead as one would need to extend all classes of smoothness to option-valued maps. * The `PartialEquiv` version as explained above is easier to use for manifolds. The drawback is that there is extra useless data (the values of `toFun` and `invFun` outside of `source` and `target`). In particular, the equality notion between partial equivs is not "the right one", i.e., coinciding source and target and equality there. Moreover, there are no partial equivs in this sense between an empty type and a nonempty type. Since empty types are not that useful, and since one almost never needs to talk about equal partial equivs, this is not an issue in practice. Still, we introduce an equivalence relation `EqOnSource` that captures this right notion of equality, and show that many properties are invariant under this equivalence relation. ### Local coding conventions If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`, then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`. -/ open Lean Meta Elab Tactic /-! Implementation of the `mfld_set_tac` tactic for working with the domains of partially-defined functions (`PartialEquiv`, `PartialHomeomorph`, etc). This is in a separate file from `Mathlib.Logic.Equiv.MfldSimpsAttr` because attributes need a new file to become functional. -/ /-- Common `@[simps]` configuration options used for manifold-related declarations. -/ def mfld_cfg : Simps.Config where attrs := [`mfld_simps] fullyApplied := false #align mfld_cfg mfld_cfg namespace Tactic.MfldSetTac /-- A very basic tactic to show that sets showing up in manifolds coincide or are included in one another. -/ elab (name := mfldSetTac) "mfld_set_tac" : tactic => withMainContext do let g ← getMainGoal let goalTy := (← instantiateMVars (← g.getDecl).type).getAppFnArgs match goalTy with | (``Eq, #[_ty, _e₁, _e₂]) => evalTactic (← `(tactic| ( apply Set.ext; intro my_y constructor <;> · intro h_my_y try simp only [*, mfld_simps] at h_my_y try simp only [*, mfld_simps]))) | (``Subset, #[_ty, _inst, _e₁, _e₂]) => evalTactic (← `(tactic| ( intro my_y h_my_y try simp only [*, mfld_simps] at h_my_y try simp only [*, mfld_simps]))) | _ => throwError "goal should be an equality or an inclusion" attribute [mfld_simps] and_true eq_self_iff_true Function.comp_apply end Tactic.MfldSetTac open Function Set variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} /-- Local equivalence between subsets `source` and `target` of `α` and `β` respectively. The (global) maps `toFun : α → β` and `invFun : β → α` map `source` to `target` and conversely, and are inverse to each other there. The values of `toFun` outside of `source` and of `invFun` outside of `target` are irrelevant. -/ structure PartialEquiv (α : Type*) (β : Type*) where /-- The global function which has a partial inverse. Its value outside of the `source` subset is irrelevant. -/ toFun : α → β /-- The partial inverse to `toFun`. Its value outside of the `target` subset is irrelevant. -/ invFun : β → α /-- The domain of the partial equivalence. -/ source : Set α /-- The codomain of the partial equivalence. -/ target : Set β /-- The proposition that elements of `source` are mapped to elements of `target`. -/ map_source' : ∀ ⦃x⦄, x ∈ source → toFun x ∈ target /-- The proposition that elements of `target` are mapped to elements of `source`. -/ map_target' : ∀ ⦃x⦄, x ∈ target → invFun x ∈ source /-- The proposition that `invFun` is a left-inverse of `toFun` on `source`. -/ left_inv' : ∀ ⦃x⦄, x ∈ source → invFun (toFun x) = x /-- The proposition that `invFun` is a right-inverse of `toFun` on `target`. -/ right_inv' : ∀ ⦃x⦄, x ∈ target → toFun (invFun x) = x #align local_equiv PartialEquiv attribute [coe] PartialEquiv.toFun namespace PartialEquiv variable (e : PartialEquiv α β) (e' : PartialEquiv β γ) instance [Inhabited α] [Inhabited β] : Inhabited (PartialEquiv α β) := ⟨⟨const α default, const β default, ∅, ∅, mapsTo_empty _ _, mapsTo_empty _ _, eqOn_empty _ _, eqOn_empty _ _⟩⟩ /-- The inverse of a partial equivalence -/ @[symm] protected def symm : PartialEquiv β α where toFun := e.invFun invFun := e.toFun source := e.target target := e.source map_source' := e.map_target' map_target' := e.map_source' left_inv' := e.right_inv' right_inv' := e.left_inv' #align local_equiv.symm PartialEquiv.symm instance : CoeFun (PartialEquiv α β) fun _ => α → β := ⟨PartialEquiv.toFun⟩ /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : PartialEquiv α β) : β → α := e.symm #align local_equiv.simps.symm_apply PartialEquiv.Simps.symm_apply initialize_simps_projections PartialEquiv (toFun → apply, invFun → symm_apply) -- Porting note: this can be proven with `dsimp only` -- @[simp, mfld_simps] -- theorem coe_mk (f : α → β) (g s t ml mr il ir) : -- (PartialEquiv.mk f g s t ml mr il ir : α → β) = f := by dsimp only -- #align local_equiv.coe_mk PartialEquiv.coe_mk #noalign local_equiv.coe_mk @[simp, mfld_simps] theorem coe_symm_mk (f : α → β) (g s t ml mr il ir) : ((PartialEquiv.mk f g s t ml mr il ir).symm : β → α) = g := rfl #align local_equiv.coe_symm_mk PartialEquiv.coe_symm_mk -- Porting note: this is now a syntactic tautology -- @[simp, mfld_simps] -- theorem toFun_as_coe : e.toFun = e := rfl -- #align local_equiv.to_fun_as_coe PartialEquiv.toFun_as_coe #noalign local_equiv.to_fun_as_coe @[simp, mfld_simps] theorem invFun_as_coe : e.invFun = e.symm := rfl #align local_equiv.inv_fun_as_coe PartialEquiv.invFun_as_coe @[simp, mfld_simps] theorem map_source {x : α} (h : x ∈ e.source) : e x ∈ e.target := e.map_source' h #align local_equiv.map_source PartialEquiv.map_source /-- Variant of `e.map_source` and `map_source'`, stated for images of subsets of `source`. -/ lemma map_source'' : e '' e.source ⊆ e.target := fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx) @[simp, mfld_simps] theorem map_target {x : β} (h : x ∈ e.target) : e.symm x ∈ e.source := e.map_target' h #align local_equiv.map_target PartialEquiv.map_target @[simp, mfld_simps] theorem left_inv {x : α} (h : x ∈ e.source) : e.symm (e x) = x := e.left_inv' h #align local_equiv.left_inv PartialEquiv.left_inv @[simp, mfld_simps] theorem right_inv {x : β} (h : x ∈ e.target) : e (e.symm x) = x := e.right_inv' h #align local_equiv.right_inv PartialEquiv.right_inv theorem eq_symm_apply {x : α} {y : β} (hx : x ∈ e.source) (hy : y ∈ e.target) : x = e.symm y ↔ e x = y := ⟨fun h => by rw [← e.right_inv hy, h], fun h => by rw [← e.left_inv hx, h]⟩ #align local_equiv.eq_symm_apply PartialEquiv.eq_symm_apply protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source #align local_equiv.maps_to PartialEquiv.mapsTo theorem symm_mapsTo : MapsTo e.symm e.target e.source := e.symm.mapsTo #align local_equiv.symm_maps_to PartialEquiv.symm_mapsTo protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv #align local_equiv.left_inv_on PartialEquiv.leftInvOn protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv #align local_equiv.right_inv_on PartialEquiv.rightInvOn protected theorem invOn : InvOn e.symm e e.source e.target := ⟨e.leftInvOn, e.rightInvOn⟩ #align local_equiv.inv_on PartialEquiv.invOn protected theorem injOn : InjOn e e.source := e.leftInvOn.injOn #align local_equiv.inj_on PartialEquiv.injOn protected theorem bijOn : BijOn e e.source e.target := e.invOn.bijOn e.mapsTo e.symm_mapsTo #align local_equiv.bij_on PartialEquiv.bijOn protected theorem surjOn : SurjOn e e.source e.target := e.bijOn.surjOn #align local_equiv.surj_on PartialEquiv.surjOn /-- Interpret an `Equiv` as a `PartialEquiv` by restricting it to `s` in the domain and to `t` in the codomain. -/ @[simps (config := .asFn)] def _root_.Equiv.toPartialEquivOfImageEq (e : α ≃ β) (s : Set α) (t : Set β) (h : e '' s = t) : PartialEquiv α β where toFun := e invFun := e.symm source := s target := t map_source' x hx := h ▸ mem_image_of_mem _ hx map_target' x hx := by subst t rcases hx with ⟨x, hx, rfl⟩ rwa [e.symm_apply_apply] left_inv' x _ := e.symm_apply_apply x right_inv' x _ := e.apply_symm_apply x /-- Associate a `PartialEquiv` to an `Equiv`. -/ @[simps! (config := mfld_cfg)] def _root_.Equiv.toPartialEquiv (e : α ≃ β) : PartialEquiv α β := e.toPartialEquivOfImageEq univ univ <| by rw [image_univ, e.surjective.range_eq] #align equiv.to_local_equiv Equiv.toPartialEquiv #align equiv.to_local_equiv_symm_apply Equiv.toPartialEquiv_symm_apply #align equiv.to_local_equiv_target Equiv.toPartialEquiv_target #align equiv.to_local_equiv_apply Equiv.toPartialEquiv_apply #align equiv.to_local_equiv_source Equiv.toPartialEquiv_source instance inhabitedOfEmpty [IsEmpty α] [IsEmpty β] : Inhabited (PartialEquiv α β) := ⟨((Equiv.equivEmpty α).trans (Equiv.equivEmpty β).symm).toPartialEquiv⟩ #align local_equiv.inhabited_of_empty PartialEquiv.inhabitedOfEmpty /-- Create a copy of a `PartialEquiv` providing better definitional equalities. -/ @[simps (config := .asFn)] def copy (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) : PartialEquiv α β where toFun := f invFun := g source := s target := t map_source' _ := ht ▸ hs ▸ hf ▸ e.map_source map_target' _ := hs ▸ ht ▸ hg ▸ e.map_target left_inv' _ := hs ▸ hf ▸ hg ▸ e.left_inv right_inv' _ := ht ▸ hf ▸ hg ▸ e.right_inv #align local_equiv.copy PartialEquiv.copy #align local_equiv.copy_source PartialEquiv.copy_source #align local_equiv.copy_apply PartialEquiv.copy_apply #align local_equiv.copy_symm_apply PartialEquiv.copy_symm_apply #align local_equiv.copy_target PartialEquiv.copy_target theorem copy_eq (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) : e.copy f hf g hg s hs t ht = e := by substs f g s t cases e rfl #align local_equiv.copy_eq PartialEquiv.copy_eq /-- Associate to a `PartialEquiv` an `Equiv` between the source and the target. -/ protected def toEquiv : e.source ≃ e.target where toFun x := ⟨e x, e.map_source x.mem⟩ invFun y := ⟨e.symm y, e.map_target y.mem⟩ left_inv := fun ⟨_, hx⟩ => Subtype.eq <| e.left_inv hx right_inv := fun ⟨_, hy⟩ => Subtype.eq <| e.right_inv hy #align local_equiv.to_equiv PartialEquiv.toEquiv @[simp, mfld_simps] theorem symm_source : e.symm.source = e.target := rfl #align local_equiv.symm_source PartialEquiv.symm_source @[simp, mfld_simps] theorem symm_target : e.symm.target = e.source := rfl #align local_equiv.symm_target PartialEquiv.symm_target @[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := by cases e rfl #align local_equiv.symm_symm PartialEquiv.symm_symm theorem symm_bijective : Function.Bijective (PartialEquiv.symm : PartialEquiv α β → PartialEquiv β α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem image_source_eq_target : e '' e.source = e.target := e.bijOn.image_eq #align local_equiv.image_source_eq_target PartialEquiv.image_source_eq_target theorem forall_mem_target {p : β → Prop} : (∀ y ∈ e.target, p y) ↔ ∀ x ∈ e.source, p (e x) := by rw [← image_source_eq_target, forall_mem_image] #align local_equiv.forall_mem_target PartialEquiv.forall_mem_target theorem exists_mem_target {p : β → Prop} : (∃ y ∈ e.target, p y) ↔ ∃ x ∈ e.source, p (e x) := by rw [← image_source_eq_target, exists_mem_image] #align local_equiv.exists_mem_target PartialEquiv.exists_mem_target /-- We say that `t : Set β` is an image of `s : Set α` under a partial equivalence if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). -/ def IsImage (s : Set α) (t : Set β) : Prop := ∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s) #align local_equiv.is_image PartialEquiv.IsImage namespace IsImage variable {e} {s : Set α} {t : Set β} {x : α} {y : β} theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s := h hx #align local_equiv.is_image.apply_mem_iff PartialEquiv.IsImage.apply_mem_iff theorem symm_apply_mem_iff (h : e.IsImage s t) : ∀ ⦃y⦄, y ∈ e.target → (e.symm y ∈ s ↔ y ∈ t) := e.forall_mem_target.mpr fun x hx => by rw [e.left_inv hx, h hx] #align local_equiv.is_image.symm_apply_mem_iff PartialEquiv.IsImage.symm_apply_mem_iff protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s := h.symm_apply_mem_iff #align local_equiv.is_image.symm PartialEquiv.IsImage.symm @[simp] theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t := ⟨fun h => h.symm, fun h => h.symm⟩ #align local_equiv.is_image.symm_iff PartialEquiv.IsImage.symm_iff protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) := fun _ hx => ⟨e.mapsTo hx.1, (h hx.1).2 hx.2⟩ #align local_equiv.is_image.maps_to PartialEquiv.IsImage.mapsTo theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) := h.symm.mapsTo #align local_equiv.is_image.symm_maps_to PartialEquiv.IsImage.symm_mapsTo /-- Restrict a `PartialEquiv` to a pair of corresponding sets. -/ @[simps (config := .asFn)] def restr (h : e.IsImage s t) : PartialEquiv α β where toFun := e invFun := e.symm source := e.source ∩ s target := e.target ∩ t map_source' := h.mapsTo map_target' := h.symm_mapsTo left_inv' := e.leftInvOn.mono inter_subset_left right_inv' := e.rightInvOn.mono inter_subset_left #align local_equiv.is_image.restr PartialEquiv.IsImage.restr #align local_equiv.is_image.restr_apply PartialEquiv.IsImage.restr_apply #align local_equiv.is_image.restr_source PartialEquiv.IsImage.restr_source #align local_equiv.is_image.restr_target PartialEquiv.IsImage.restr_target #align local_equiv.is_image.restr_symm_apply PartialEquiv.IsImage.restr_symm_apply theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t := h.restr.image_source_eq_target #align local_equiv.is_image.image_eq PartialEquiv.IsImage.image_eq theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s := h.symm.image_eq #align local_equiv.is_image.symm_image_eq PartialEquiv.IsImage.symm_image_eq theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s := by simp only [IsImage, ext_iff, mem_inter_iff, mem_preimage, and_congr_right_iff] #align local_equiv.is_image.iff_preimage_eq PartialEquiv.IsImage.iff_preimage_eq alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq #align local_equiv.is_image.of_preimage_eq PartialEquiv.IsImage.of_preimage_eq #align local_equiv.is_image.preimage_eq PartialEquiv.IsImage.preimage_eq theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t := symm_iff.symm.trans iff_preimage_eq #align local_equiv.is_image.iff_symm_preimage_eq PartialEquiv.IsImage.iff_symm_preimage_eq alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq #align local_equiv.is_image.of_symm_preimage_eq PartialEquiv.IsImage.of_symm_preimage_eq #align local_equiv.is_image.symm_preimage_eq PartialEquiv.IsImage.symm_preimage_eq theorem of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.IsImage s t := of_symm_preimage_eq <| Eq.trans (of_symm_preimage_eq rfl).image_eq.symm h #align local_equiv.is_image.of_image_eq PartialEquiv.IsImage.of_image_eq theorem of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.IsImage s t := of_preimage_eq <| Eq.trans (iff_preimage_eq.2 rfl).symm_image_eq.symm h #align local_equiv.is_image.of_symm_image_eq PartialEquiv.IsImage.of_symm_image_eq protected theorem compl (h : e.IsImage s t) : e.IsImage sᶜ tᶜ := fun _ hx => not_congr (h hx) #align local_equiv.is_image.compl PartialEquiv.IsImage.compl protected theorem inter {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∩ s') (t ∩ t') := fun _ hx => and_congr (h hx) (h' hx) #align local_equiv.is_image.inter PartialEquiv.IsImage.inter protected theorem union {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∪ s') (t ∪ t') := fun _ hx => or_congr (h hx) (h' hx) #align local_equiv.is_image.union PartialEquiv.IsImage.union protected theorem diff {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s \ s') (t \ t') := h.inter h'.compl #align local_equiv.is_image.diff PartialEquiv.IsImage.diff theorem leftInvOn_piecewise {e' : PartialEquiv α β} [∀ i, Decidable (i ∈ s)] [∀ i, Decidable (i ∈ t)] (h : e.IsImage s t) (h' : e'.IsImage s t) : LeftInvOn (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) := by rintro x (⟨he, hs⟩ | ⟨he, hs : x ∉ s⟩) · rw [piecewise_eq_of_mem _ _ _ hs, piecewise_eq_of_mem _ _ _ ((h he).2 hs), e.left_inv he] · rw [piecewise_eq_of_not_mem _ _ _ hs, piecewise_eq_of_not_mem _ _ _ ((h'.compl he).2 hs), e'.left_inv he] #align local_equiv.is_image.left_inv_on_piecewise PartialEquiv.IsImage.leftInvOn_piecewise theorem inter_eq_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t) (h' : e'.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) : e.target ∩ t = e'.target ∩ t := by rw [← h.image_eq, ← h'.image_eq, ← hs, heq.image_eq] #align local_equiv.is_image.inter_eq_of_inter_eq_of_eq_on PartialEquiv.IsImage.inter_eq_of_inter_eq_of_eqOn theorem symm_eq_on_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) : EqOn e.symm e'.symm (e.target ∩ t) := by rw [← h.image_eq] rintro y ⟨x, hx, rfl⟩ have hx' := hx; rw [hs] at hx' rw [e.left_inv hx.1, heq hx, e'.left_inv hx'.1] #align local_equiv.is_image.symm_eq_on_of_inter_eq_of_eq_on PartialEquiv.IsImage.symm_eq_on_of_inter_eq_of_eqOn end IsImage theorem isImage_source_target : e.IsImage e.source e.target := fun x hx => by simp [hx] #align local_equiv.is_image_source_target PartialEquiv.isImage_source_target theorem isImage_source_target_of_disjoint (e' : PartialEquiv α β) (hs : Disjoint e.source e'.source) (ht : Disjoint e.target e'.target) : e.IsImage e'.source e'.target := IsImage.of_image_eq <| by rw [hs.inter_eq, ht.inter_eq, image_empty] #align local_equiv.is_image_source_target_of_disjoint PartialEquiv.isImage_source_target_of_disjoint theorem image_source_inter_eq' (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := by rw [inter_comm, e.leftInvOn.image_inter', image_source_eq_target, inter_comm] #align local_equiv.image_source_inter_eq' PartialEquiv.image_source_inter_eq' theorem image_source_inter_eq (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := by rw [inter_comm, e.leftInvOn.image_inter, image_source_eq_target, inter_comm] #align local_equiv.image_source_inter_eq PartialEquiv.image_source_inter_eq theorem image_eq_target_inter_inv_preimage {s : Set α} (h : s ⊆ e.source) : e '' s = e.target ∩ e.symm ⁻¹' s := by rw [← e.image_source_inter_eq', inter_eq_self_of_subset_right h] #align local_equiv.image_eq_target_inter_inv_preimage PartialEquiv.image_eq_target_inter_inv_preimage theorem symm_image_eq_source_inter_preimage {s : Set β} (h : s ⊆ e.target) : e.symm '' s = e.source ∩ e ⁻¹' s := e.symm.image_eq_target_inter_inv_preimage h #align local_equiv.symm_image_eq_source_inter_preimage PartialEquiv.symm_image_eq_source_inter_preimage theorem symm_image_target_inter_eq (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) := e.symm.image_source_inter_eq _ #align local_equiv.symm_image_target_inter_eq PartialEquiv.symm_image_target_inter_eq theorem symm_image_target_inter_eq' (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' s := e.symm.image_source_inter_eq' _ #align local_equiv.symm_image_target_inter_eq' PartialEquiv.symm_image_target_inter_eq' theorem source_inter_preimage_inv_preimage (s : Set α) : e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s := Set.ext fun x => and_congr_right_iff.2 fun hx => by simp only [mem_preimage, e.left_inv hx] #align local_equiv.source_inter_preimage_inv_preimage PartialEquiv.source_inter_preimage_inv_preimage theorem source_inter_preimage_target_inter (s : Set β) : e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s := ext fun _ => ⟨fun hx => ⟨hx.1, hx.2.2⟩, fun hx => ⟨hx.1, e.map_source hx.1, hx.2⟩⟩ #align local_equiv.source_inter_preimage_target_inter PartialEquiv.source_inter_preimage_target_inter theorem target_inter_inv_preimage_preimage (s : Set β) : e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s := e.symm.source_inter_preimage_inv_preimage _ #align local_equiv.target_inter_inv_preimage_preimage PartialEquiv.target_inter_inv_preimage_preimage theorem symm_image_image_of_subset_source {s : Set α} (h : s ⊆ e.source) : e.symm '' (e '' s) = s := (e.leftInvOn.mono h).image_image #align local_equiv.symm_image_image_of_subset_source PartialEquiv.symm_image_image_of_subset_source theorem image_symm_image_of_subset_target {s : Set β} (h : s ⊆ e.target) : e '' (e.symm '' s) = s := e.symm.symm_image_image_of_subset_source h #align local_equiv.image_symm_image_of_subset_target PartialEquiv.image_symm_image_of_subset_target theorem source_subset_preimage_target : e.source ⊆ e ⁻¹' e.target := e.mapsTo #align local_equiv.source_subset_preimage_target PartialEquiv.source_subset_preimage_target theorem symm_image_target_eq_source : e.symm '' e.target = e.source := e.symm.image_source_eq_target #align local_equiv.symm_image_target_eq_source PartialEquiv.symm_image_target_eq_source theorem target_subset_preimage_source : e.target ⊆ e.symm ⁻¹' e.source := e.symm_mapsTo #align local_equiv.target_subset_preimage_source PartialEquiv.target_subset_preimage_source /-- Two partial equivs that have the same `source`, same `toFun` and same `invFun`, coincide. -/ @[ext] protected theorem ext {e e' : PartialEquiv α β} (h : ∀ x, e x = e' x) (hsymm : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := by have A : (e : α → β) = e' := by ext x exact h x have B : (e.symm : β → α) = e'.symm := by ext x exact hsymm x have I : e '' e.source = e.target := e.image_source_eq_target have I' : e' '' e'.source = e'.target := e'.image_source_eq_target rw [A, hs, I'] at I cases e; cases e' simp_all #align local_equiv.ext PartialEquiv.ext /-- Restricting a partial equivalence to `e.source ∩ s` -/ protected def restr (s : Set α) : PartialEquiv α β := (@IsImage.of_symm_preimage_eq α β e s (e.symm ⁻¹' s) rfl).restr #align local_equiv.restr PartialEquiv.restr @[simp, mfld_simps] theorem restr_coe (s : Set α) : (e.restr s : α → β) = e := rfl #align local_equiv.restr_coe PartialEquiv.restr_coe @[simp, mfld_simps] theorem restr_coe_symm (s : Set α) : ((e.restr s).symm : β → α) = e.symm := rfl #align local_equiv.restr_coe_symm PartialEquiv.restr_coe_symm @[simp, mfld_simps] theorem restr_source (s : Set α) : (e.restr s).source = e.source ∩ s := rfl #align local_equiv.restr_source PartialEquiv.restr_source @[simp, mfld_simps] theorem restr_target (s : Set α) : (e.restr s).target = e.target ∩ e.symm ⁻¹' s := rfl #align local_equiv.restr_target PartialEquiv.restr_target theorem restr_eq_of_source_subset {e : PartialEquiv α β} {s : Set α} (h : e.source ⊆ s) : e.restr s = e := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [inter_eq_self_of_subset_left h]) #align local_equiv.restr_eq_of_source_subset PartialEquiv.restr_eq_of_source_subset @[simp, mfld_simps] theorem restr_univ {e : PartialEquiv α β} : e.restr univ = e := restr_eq_of_source_subset (subset_univ _) #align local_equiv.restr_univ PartialEquiv.restr_univ /-- The identity partial equiv -/ protected def refl (α : Type*) : PartialEquiv α α := (Equiv.refl α).toPartialEquiv #align local_equiv.refl PartialEquiv.refl @[simp, mfld_simps] theorem refl_source : (PartialEquiv.refl α).source = univ := rfl #align local_equiv.refl_source PartialEquiv.refl_source @[simp, mfld_simps] theorem refl_target : (PartialEquiv.refl α).target = univ := rfl #align local_equiv.refl_target PartialEquiv.refl_target @[simp, mfld_simps] theorem refl_coe : (PartialEquiv.refl α : α → α) = id := rfl #align local_equiv.refl_coe PartialEquiv.refl_coe @[simp, mfld_simps] theorem refl_symm : (PartialEquiv.refl α).symm = PartialEquiv.refl α := rfl #align local_equiv.refl_symm PartialEquiv.refl_symm -- Porting note: removed `simp` because `simp` can prove this @[mfld_simps] theorem refl_restr_source (s : Set α) : ((PartialEquiv.refl α).restr s).source = s := by simp #align local_equiv.refl_restr_source PartialEquiv.refl_restr_source -- Porting note: removed `simp` because `simp` can prove this @[mfld_simps] theorem refl_restr_target (s : Set α) : ((PartialEquiv.refl α).restr s).target = s := by change univ ∩ id ⁻¹' s = s simp #align local_equiv.refl_restr_target PartialEquiv.refl_restr_target /-- The identity partial equivalence on a set `s` -/ def ofSet (s : Set α) : PartialEquiv α α where toFun := id invFun := id source := s target := s map_source' _ hx := hx map_target' _ hx := hx left_inv' _ _ := rfl right_inv' _ _ := rfl #align local_equiv.of_set PartialEquiv.ofSet @[simp, mfld_simps] theorem ofSet_source (s : Set α) : (PartialEquiv.ofSet s).source = s := rfl #align local_equiv.of_set_source PartialEquiv.ofSet_source @[simp, mfld_simps] theorem ofSet_target (s : Set α) : (PartialEquiv.ofSet s).target = s := rfl #align local_equiv.of_set_target PartialEquiv.ofSet_target @[simp, mfld_simps] theorem ofSet_coe (s : Set α) : (PartialEquiv.ofSet s : α → α) = id := rfl #align local_equiv.of_set_coe PartialEquiv.ofSet_coe @[simp, mfld_simps] theorem ofSet_symm (s : Set α) : (PartialEquiv.ofSet s).symm = PartialEquiv.ofSet s := rfl #align local_equiv.of_set_symm PartialEquiv.ofSet_symm /-- Composing two partial equivs if the target of the first coincides with the source of the second. -/ @[simps] protected def trans' (e' : PartialEquiv β γ) (h : e.target = e'.source) : PartialEquiv α γ where toFun := e' ∘ e invFun := e.symm ∘ e'.symm source := e.source target := e'.target map_source' x hx := by simp [← h, hx] map_target' y hy := by simp [h, hy] left_inv' x hx := by simp [hx, ← h] right_inv' y hy := by simp [hy, h] #align local_equiv.trans' PartialEquiv.trans' /-- Composing two partial equivs, by restricting to the maximal domain where their composition is well defined. -/ @[trans] protected def trans : PartialEquiv α γ := PartialEquiv.trans' (e.symm.restr e'.source).symm (e'.restr e.target) (inter_comm _ _) #align local_equiv.trans PartialEquiv.trans @[simp, mfld_simps] theorem coe_trans : (e.trans e' : α → γ) = e' ∘ e := rfl #align local_equiv.coe_trans PartialEquiv.coe_trans @[simp, mfld_simps] theorem coe_trans_symm : ((e.trans e').symm : γ → α) = e.symm ∘ e'.symm := rfl #align local_equiv.coe_trans_symm PartialEquiv.coe_trans_symm theorem trans_apply {x : α} : (e.trans e') x = e' (e x) := rfl #align local_equiv.trans_apply PartialEquiv.trans_apply theorem trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm := by cases e; cases e'; rfl #align local_equiv.trans_symm_eq_symm_trans_symm PartialEquiv.trans_symm_eq_symm_trans_symm @[simp, mfld_simps] theorem trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source := rfl #align local_equiv.trans_source PartialEquiv.trans_source theorem trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) := by mfld_set_tac #align local_equiv.trans_source' PartialEquiv.trans_source' theorem trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) := by rw [e.trans_source', e.symm_image_target_inter_eq] #align local_equiv.trans_source'' PartialEquiv.trans_source'' theorem image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source := (e.symm.restr e'.source).symm.image_source_eq_target #align local_equiv.image_trans_source PartialEquiv.image_trans_source @[simp, mfld_simps] theorem trans_target : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target := rfl #align local_equiv.trans_target PartialEquiv.trans_target theorem trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) := trans_source' e'.symm e.symm #align local_equiv.trans_target' PartialEquiv.trans_target' theorem trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) := trans_source'' e'.symm e.symm #align local_equiv.trans_target'' PartialEquiv.trans_target'' theorem inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target := image_trans_source e'.symm e.symm #align local_equiv.inv_image_trans_target PartialEquiv.inv_image_trans_target theorem trans_assoc (e'' : PartialEquiv γ δ) : (e.trans e').trans e'' = e.trans (e'.trans e'') := PartialEquiv.ext (fun x => rfl) (fun x => rfl) (by simp [trans_source, @preimage_comp α β γ, inter_assoc]) #align local_equiv.trans_assoc PartialEquiv.trans_assoc @[simp, mfld_simps] theorem trans_refl : e.trans (PartialEquiv.refl β) = e := PartialEquiv.ext (fun x => rfl) (fun x => rfl) (by simp [trans_source]) #align local_equiv.trans_refl PartialEquiv.trans_refl @[simp, mfld_simps] theorem refl_trans : (PartialEquiv.refl α).trans e = e := PartialEquiv.ext (fun x => rfl) (fun x => rfl) (by simp [trans_source, preimage_id]) #align local_equiv.refl_trans PartialEquiv.refl_trans theorem trans_ofSet (s : Set β) : e.trans (ofSet s) = e.restr (e ⁻¹' s) := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) rfl theorem trans_refl_restr (s : Set β) : e.trans ((PartialEquiv.refl β).restr s) = e.restr (e ⁻¹' s) := PartialEquiv.ext (fun x => rfl) (fun x => rfl) (by simp [trans_source]) #align local_equiv.trans_refl_restr PartialEquiv.trans_refl_restr theorem trans_refl_restr' (s : Set β) : e.trans ((PartialEquiv.refl β).restr s) = e.restr (e.source ∩ e ⁻¹' s) := PartialEquiv.ext (fun x => rfl) (fun x => rfl) <| by simp only [trans_source, restr_source, refl_source, univ_inter] rw [← inter_assoc, inter_self] #align local_equiv.trans_refl_restr' PartialEquiv.trans_refl_restr' theorem restr_trans (s : Set α) : (e.restr s).trans e' = (e.trans e').restr s := PartialEquiv.ext (fun x => rfl) (fun x => rfl) <| by simp [trans_source, inter_comm, inter_assoc] #align local_equiv.restr_trans PartialEquiv.restr_trans /-- A lemma commonly useful when `e` and `e'` are charts of a manifold. -/ theorem mem_symm_trans_source {e' : PartialEquiv α γ} {x : α} (he : x ∈ e.source) (he' : x ∈ e'.source) : e x ∈ (e.symm.trans e').source := ⟨e.mapsTo he, by rwa [mem_preimage, PartialEquiv.symm_symm, e.left_inv he]⟩ #align local_equiv.mem_symm_trans_source PartialEquiv.mem_symm_trans_source /-- `EqOnSource e e'` means that `e` and `e'` have the same source, and coincide there. Then `e` and `e'` should really be considered the same partial equiv. -/ def EqOnSource (e e' : PartialEquiv α β) : Prop := e.source = e'.source ∧ e.source.EqOn e e' #align local_equiv.eq_on_source PartialEquiv.EqOnSource /-- `EqOnSource` is an equivalence relation. This instance provides the `≈` notation between two `PartialEquiv`s. -/ instance eqOnSourceSetoid : Setoid (PartialEquiv α β) where r := EqOnSource iseqv := by constructor <;> simp only [Equivalence, EqOnSource, EqOn] <;> aesop #align local_equiv.eq_on_source_setoid PartialEquiv.eqOnSourceSetoid theorem eqOnSource_refl : e ≈ e := Setoid.refl _ #align local_equiv.eq_on_source_refl PartialEquiv.eqOnSource_refl /-- Two equivalent partial equivs have the same source. -/ theorem EqOnSource.source_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.source = e'.source := h.1 #align local_equiv.eq_on_source.source_eq PartialEquiv.EqOnSource.source_eq /-- Two equivalent partial equivs coincide on the source. -/ theorem EqOnSource.eqOn {e e' : PartialEquiv α β} (h : e ≈ e') : e.source.EqOn e e' := h.2 #align local_equiv.eq_on_source.eq_on PartialEquiv.EqOnSource.eqOn -- Porting note: A lot of dot notation failures here. Maybe we should not use `≈` /-- Two equivalent partial equivs have the same target. -/ theorem EqOnSource.target_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.target = e'.target := by simp only [← image_source_eq_target, ← source_eq h, h.2.image_eq] #align local_equiv.eq_on_source.target_eq PartialEquiv.EqOnSource.target_eq /-- If two partial equivs are equivalent, so are their inverses. -/ theorem EqOnSource.symm' {e e' : PartialEquiv α β} (h : e ≈ e') : e.symm ≈ e'.symm := by refine ⟨target_eq h, eqOn_of_leftInvOn_of_rightInvOn e.leftInvOn ?_ ?_⟩ <;> simp only [symm_source, target_eq h, source_eq h, e'.symm_mapsTo] exact e'.rightInvOn.congr_right e'.symm_mapsTo (source_eq h ▸ h.eqOn.symm) #align local_equiv.eq_on_source.symm' PartialEquiv.EqOnSource.symm' /-- Two equivalent partial equivs have coinciding inverses on the target. -/ theorem EqOnSource.symm_eqOn {e e' : PartialEquiv α β} (h : e ≈ e') : EqOn e.symm e'.symm e.target := -- Porting note: `h.symm'` dot notation doesn't work anymore because `h` is not recognised as -- `PartialEquiv.EqOnSource` for some reason. eqOn (symm' h) #align local_equiv.eq_on_source.symm_eq_on PartialEquiv.EqOnSource.symm_eqOn /-- Composition of partial equivs respects equivalence. -/ theorem EqOnSource.trans' {e e' : PartialEquiv α β} {f f' : PartialEquiv β γ} (he : e ≈ e') (hf : f ≈ f') : e.trans f ≈ e'.trans f' := by constructor · rw [trans_source'', trans_source'', ← target_eq he, ← hf.1] exact (he.symm'.eqOn.mono inter_subset_left).image_eq · intro x hx rw [trans_source] at hx simp [Function.comp_apply, PartialEquiv.coe_trans, (he.2 hx.1).symm, hf.2 hx.2] #align local_equiv.eq_on_source.trans' PartialEquiv.EqOnSource.trans' /-- Restriction of partial equivs respects equivalence. -/ theorem EqOnSource.restr {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set α) : e.restr s ≈ e'.restr s := by constructor · simp [he.1] · intro x hx simp only [mem_inter_iff, restr_source] at hx exact he.2 hx.1 #align local_equiv.eq_on_source.restr PartialEquiv.EqOnSource.restr /-- Preimages are respected by equivalence. -/ theorem EqOnSource.source_inter_preimage_eq {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set β) : e.source ∩ e ⁻¹' s = e'.source ∩ e' ⁻¹' s := by rw [he.eqOn.inter_preimage_eq, source_eq he] #align local_equiv.eq_on_source.source_inter_preimage_eq PartialEquiv.EqOnSource.source_inter_preimage_eq /-- Composition of a partial equivlance and its inverse is equivalent to the restriction of the identity to the source. -/ theorem self_trans_symm : e.trans e.symm ≈ ofSet e.source := by have A : (e.trans e.symm).source = e.source := by mfld_set_tac refine ⟨by rw [A, ofSet_source], fun x hx => ?_⟩ rw [A] at hx simp only [hx, mfld_simps] #align local_equiv.self_trans_symm PartialEquiv.self_trans_symm /-- Composition of the inverse of a partial equivalence and this partial equivalence is equivalent to the restriction of the identity to the target. -/ theorem symm_trans_self : e.symm.trans e ≈ ofSet e.target := self_trans_symm e.symm #align local_equiv.symm_trans_self PartialEquiv.symm_trans_self /-- Two equivalent partial equivs are equal when the source and target are `univ`. -/ theorem eq_of_eqOnSource_univ (e e' : PartialEquiv α β) (h : e ≈ e') (s : e.source = univ) (t : e.target = univ) : e = e' := by refine PartialEquiv.ext (fun x => ?_) (fun x => ?_) h.1 · apply h.2 rw [s] exact mem_univ _ · apply h.symm'.2 rw [symm_source, t] exact mem_univ _ #align local_equiv.eq_of_eq_on_source_univ PartialEquiv.eq_of_eqOnSource_univ section Prod /-- The product of two partial equivalences, as a partial equivalence on the product. -/ def prod (e : PartialEquiv α β) (e' : PartialEquiv γ δ) : PartialEquiv (α × γ) (β × δ) where source := e.source ×ˢ e'.source target := e.target ×ˢ e'.target toFun p := (e p.1, e' p.2) invFun p := (e.symm p.1, e'.symm p.2) map_source' p hp := by simp_all map_target' p hp := by simp_all left_inv' p hp := by simp_all right_inv' p hp := by simp_all #align local_equiv.prod PartialEquiv.prod @[simp, mfld_simps] theorem prod_source (e : PartialEquiv α β) (e' : PartialEquiv γ δ) : (e.prod e').source = e.source ×ˢ e'.source := rfl #align local_equiv.prod_source PartialEquiv.prod_source @[simp, mfld_simps] theorem prod_target (e : PartialEquiv α β) (e' : PartialEquiv γ δ) : (e.prod e').target = e.target ×ˢ e'.target := rfl #align local_equiv.prod_target PartialEquiv.prod_target @[simp, mfld_simps] theorem prod_coe (e : PartialEquiv α β) (e' : PartialEquiv γ δ) : (e.prod e' : α × γ → β × δ) = fun p => (e p.1, e' p.2) := rfl #align local_equiv.prod_coe PartialEquiv.prod_coe theorem prod_coe_symm (e : PartialEquiv α β) (e' : PartialEquiv γ δ) : ((e.prod e').symm : β × δ → α × γ) = fun p => (e.symm p.1, e'.symm p.2) := rfl #align local_equiv.prod_coe_symm PartialEquiv.prod_coe_symm @[simp, mfld_simps] theorem prod_symm (e : PartialEquiv α β) (e' : PartialEquiv γ δ) : (e.prod e').symm = e.symm.prod e'.symm := by ext x <;> simp [prod_coe_symm] #align local_equiv.prod_symm PartialEquiv.prod_symm @[simp, mfld_simps] theorem refl_prod_refl : (PartialEquiv.refl α).prod (PartialEquiv.refl β) = PartialEquiv.refl (α × β) := by -- Porting note: `ext1 ⟨x, y⟩` insufficient number of binders ext ⟨x, y⟩ <;> simp #align local_equiv.refl_prod_refl PartialEquiv.refl_prod_refl @[simp, mfld_simps] theorem prod_trans {η : Type*} {ε : Type*} (e : PartialEquiv α β) (f : PartialEquiv β γ) (e' : PartialEquiv δ η) (f' : PartialEquiv η ε) : (e.prod e').trans (f.prod f') = (e.trans f).prod (e'.trans f') := by ext ⟨x, y⟩ <;> simp [ext_iff]; tauto #align local_equiv.prod_trans PartialEquiv.prod_trans end Prod /-- Combine two `PartialEquiv`s using `Set.piecewise`. The source of the new `PartialEquiv` is `s.ite e.source e'.source = e.source ∩ s ∪ e'.source \ s`, and similarly for target. The function sends `e.source ∩ s` to `e.target ∩ t` using `e` and `e'.source \ s` to `e'.target \ t` using `e'`, and similarly for the inverse function. The definition assumes `e.isImage s t` and `e'.isImage s t`. -/ @[simps (config := .asFn)] def piecewise (e e' : PartialEquiv α β) (s : Set α) (t : Set β) [∀ x, Decidable (x ∈ s)] [∀ y, Decidable (y ∈ t)] (H : e.IsImage s t) (H' : e'.IsImage s t) : PartialEquiv α β where toFun := s.piecewise e e' invFun := t.piecewise e.symm e'.symm source := s.ite e.source e'.source target := t.ite e.target e'.target map_source' := H.mapsTo.piecewise_ite H'.compl.mapsTo map_target' := H.symm.mapsTo.piecewise_ite H'.symm.compl.mapsTo left_inv' := H.leftInvOn_piecewise H' right_inv' := H.symm.leftInvOn_piecewise H'.symm #align local_equiv.piecewise PartialEquiv.piecewise #align local_equiv.piecewise_source PartialEquiv.piecewise_source #align local_equiv.piecewise_target PartialEquiv.piecewise_target #align local_equiv.piecewise_symm_apply PartialEquiv.piecewise_symm_apply #align local_equiv.piecewise_apply PartialEquiv.piecewise_apply theorem symm_piecewise (e e' : PartialEquiv α β) {s : Set α} {t : Set β} [∀ x, Decidable (x ∈ s)] [∀ y, Decidable (y ∈ t)] (H : e.IsImage s t) (H' : e'.IsImage s t) : (e.piecewise e' s t H H').symm = e.symm.piecewise e'.symm t s H.symm H'.symm := rfl #align local_equiv.symm_piecewise PartialEquiv.symm_piecewise /-- Combine two `PartialEquiv`s with disjoint sources and disjoint targets. We reuse `PartialEquiv.piecewise`, then override `source` and `target` to ensure better definitional equalities. -/ @[simps! (config := .asFn)] def disjointUnion (e e' : PartialEquiv α β) (hs : Disjoint e.source e'.source) (ht : Disjoint e.target e'.target) [∀ x, Decidable (x ∈ e.source)] [∀ y, Decidable (y ∈ e.target)] : PartialEquiv α β := (e.piecewise e' e.source e.target e.isImage_source_target <| e'.isImage_source_target_of_disjoint _ hs.symm ht.symm).copy _ rfl _ rfl (e.source ∪ e'.source) (ite_left _ _) (e.target ∪ e'.target) (ite_left _ _) #align local_equiv.disjoint_union PartialEquiv.disjointUnion #align local_equiv.disjoint_union_source PartialEquiv.disjointUnion_source #align local_equiv.disjoint_union_target PartialEquiv.disjointUnion_target #align local_equiv.disjoint_union_symm_apply PartialEquiv.disjointUnion_symm_apply #align local_equiv.disjoint_union_apply PartialEquiv.disjointUnion_apply theorem disjointUnion_eq_piecewise (e e' : PartialEquiv α β) (hs : Disjoint e.source e'.source) (ht : Disjoint e.target e'.target) [∀ x, Decidable (x ∈ e.source)] [∀ y, Decidable (y ∈ e.target)] : e.disjointUnion e' hs ht = e.piecewise e' e.source e.target e.isImage_source_target (e'.isImage_source_target_of_disjoint _ hs.symm ht.symm) := copy_eq .. #align local_equiv.disjoint_union_eq_piecewise PartialEquiv.disjointUnion_eq_piecewise section Pi variable {ι : Type*} {αi βi γi : ι → Type*} /-- The product of a family of partial equivalences, as a partial equivalence on the pi type. -/ @[simps (config := mfld_cfg) apply source target] protected def pi (ei : ∀ i, PartialEquiv (αi i) (βi i)) : PartialEquiv (∀ i, αi i) (∀ i, βi i) where toFun f i := ei i (f i) invFun f i := (ei i).symm (f i) source := pi univ fun i => (ei i).source target := pi univ fun i => (ei i).target map_source' _ hf i hi := (ei i).map_source (hf i hi) map_target' _ hf i hi := (ei i).map_target (hf i hi) left_inv' _ hf := funext fun i => (ei i).left_inv (hf i trivial) right_inv' _ hf := funext fun i => (ei i).right_inv (hf i trivial) #align local_equiv.pi PartialEquiv.pi #align local_equiv.pi_source PartialEquiv.pi_source #align local_equiv.pi_apply PartialEquiv.pi_apply #align local_equiv.pi_target PartialEquiv.pi_target @[simp, mfld_simps] theorem pi_symm (ei : ∀ i, PartialEquiv (αi i) (βi i)) : (PartialEquiv.pi ei).symm = .pi fun i ↦ (ei i).symm := rfl theorem pi_symm_apply (ei : ∀ i, PartialEquiv (αi i) (βi i)) : ⇑(PartialEquiv.pi ei).symm = fun f i ↦ (ei i).symm (f i) := rfl #align local_equiv.pi_symm_apply PartialEquiv.pi_symm_apply @[simp, mfld_simps] theorem pi_refl : (PartialEquiv.pi fun i ↦ PartialEquiv.refl (αi i)) = .refl (∀ i, αi i) := by ext <;> simp @[simp, mfld_simps]
Mathlib/Logic/Equiv/PartialEquiv.lean
1,040
1,042
theorem pi_trans (ei : ∀ i, PartialEquiv (αi i) (βi i)) (ei' : ∀ i, PartialEquiv (βi i) (γi i)) : (PartialEquiv.pi ei).trans (PartialEquiv.pi ei') = .pi fun i ↦ (ei i).trans (ei' i) := by
ext <;> simp [forall_and]
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Complex.Circle import Mathlib.Analysis.SpecialFunctions.Complex.Log #align_import analysis.special_functions.complex.circle from "leanprover-community/mathlib"@"f333194f5ecd1482191452c5ea60b37d4d6afa08" /-! # Maps on the unit circle In this file we prove some basic lemmas about `expMapCircle` and the restriction of `Complex.arg` to the unit circle. These two maps define a partial equivalence between `circle` and `ℝ`, see `circle.argPartialEquiv` and `circle.argEquiv`, that sends the whole circle to `(-π, π]`. -/ open Complex Function Set open Real namespace circle theorem injective_arg : Injective fun z : circle => arg z := fun z w h => Subtype.ext <| ext_abs_arg ((abs_coe_circle z).trans (abs_coe_circle w).symm) h #align circle.injective_arg circle.injective_arg @[simp] theorem arg_eq_arg {z w : circle} : arg z = arg w ↔ z = w := injective_arg.eq_iff #align circle.arg_eq_arg circle.arg_eq_arg end circle theorem arg_expMapCircle {x : ℝ} (h₁ : -π < x) (h₂ : x ≤ π) : arg (expMapCircle x) = x := by rw [expMapCircle_apply, exp_mul_I, arg_cos_add_sin_mul_I ⟨h₁, h₂⟩] #align arg_exp_map_circle arg_expMapCircle @[simp] theorem expMapCircle_arg (z : circle) : expMapCircle (arg z) = z := circle.injective_arg <| arg_expMapCircle (neg_pi_lt_arg _) (arg_le_pi _) #align exp_map_circle_arg expMapCircle_arg namespace circle /-- `Complex.arg ∘ (↑)` and `expMapCircle` define a partial equivalence between `circle` and `ℝ` with `source = Set.univ` and `target = Set.Ioc (-π) π`. -/ @[simps (config := .asFn)] noncomputable def argPartialEquiv : PartialEquiv circle ℝ where toFun := arg ∘ (↑) invFun := expMapCircle source := univ target := Ioc (-π) π map_source' _ _ := ⟨neg_pi_lt_arg _, arg_le_pi _⟩ map_target' := mapsTo_univ _ _ left_inv' z _ := expMapCircle_arg z right_inv' _ hx := arg_expMapCircle hx.1 hx.2 #align circle.arg_local_equiv circle.argPartialEquiv /-- `Complex.arg` and `expMapCircle` define an equivalence between `circle` and `(-π, π]`. -/ @[simps (config := .asFn)] noncomputable def argEquiv : circle ≃ Ioc (-π) π where toFun z := ⟨arg z, neg_pi_lt_arg _, arg_le_pi _⟩ invFun := expMapCircle ∘ (↑) left_inv _ := argPartialEquiv.left_inv trivial right_inv x := Subtype.ext <| argPartialEquiv.right_inv x.2 #align circle.arg_equiv circle.argEquiv end circle theorem leftInverse_expMapCircle_arg : LeftInverse expMapCircle (arg ∘ (↑)) := expMapCircle_arg #align left_inverse_exp_map_circle_arg leftInverse_expMapCircle_arg theorem invOn_arg_expMapCircle : InvOn (arg ∘ (↑)) expMapCircle (Ioc (-π) π) univ := circle.argPartialEquiv.symm.invOn #align inv_on_arg_exp_map_circle invOn_arg_expMapCircle theorem surjOn_expMapCircle_neg_pi_pi : SurjOn expMapCircle (Ioc (-π) π) univ := circle.argPartialEquiv.symm.surjOn #align surj_on_exp_map_circle_neg_pi_pi surjOn_expMapCircle_neg_pi_pi theorem expMapCircle_eq_expMapCircle {x y : ℝ} : expMapCircle x = expMapCircle y ↔ ∃ m : ℤ, x = y + m * (2 * π) := by rw [Subtype.ext_iff, expMapCircle_apply, expMapCircle_apply, exp_eq_exp_iff_exists_int] refine exists_congr fun n => ?_ rw [← mul_assoc, ← add_mul, mul_left_inj' I_ne_zero] norm_cast #align exp_map_circle_eq_exp_map_circle expMapCircle_eq_expMapCircle theorem periodic_expMapCircle : Periodic expMapCircle (2 * π) := fun z => expMapCircle_eq_expMapCircle.2 ⟨1, by rw [Int.cast_one, one_mul]⟩ #align periodic_exp_map_circle periodic_expMapCircle #adaptation_note /-- nightly-2024-04-14 The simpNF linter now times out on this lemma. See https://github.com/leanprover-community/mathlib4/issues/12229 -/ @[simp, nolint simpNF] theorem expMapCircle_two_pi : expMapCircle (2 * π) = 1 := periodic_expMapCircle.eq.trans expMapCircle_zero #align exp_map_circle_two_pi expMapCircle_two_pi theorem expMapCircle_sub_two_pi (x : ℝ) : expMapCircle (x - 2 * π) = expMapCircle x := periodic_expMapCircle.sub_eq x #align exp_map_circle_sub_two_pi expMapCircle_sub_two_pi theorem expMapCircle_add_two_pi (x : ℝ) : expMapCircle (x + 2 * π) = expMapCircle x := periodic_expMapCircle x #align exp_map_circle_add_two_pi expMapCircle_add_two_pi /-- `expMapCircle`, applied to a `Real.Angle`. -/ noncomputable def Real.Angle.expMapCircle (θ : Real.Angle) : circle := periodic_expMapCircle.lift θ #align real.angle.exp_map_circle Real.Angle.expMapCircle @[simp] theorem Real.Angle.expMapCircle_coe (x : ℝ) : Real.Angle.expMapCircle x = _root_.expMapCircle x := rfl #align real.angle.exp_map_circle_coe Real.Angle.expMapCircle_coe theorem Real.Angle.coe_expMapCircle (θ : Real.Angle) : (θ.expMapCircle : ℂ) = θ.cos + θ.sin * I := by induction θ using Real.Angle.induction_on simp [Complex.exp_mul_I] #align real.angle.coe_exp_map_circle Real.Angle.coe_expMapCircle @[simp] theorem Real.Angle.expMapCircle_zero : Real.Angle.expMapCircle 0 = 1 := by rw [← Real.Angle.coe_zero, Real.Angle.expMapCircle_coe, _root_.expMapCircle_zero] #align real.angle.exp_map_circle_zero Real.Angle.expMapCircle_zero @[simp] theorem Real.Angle.expMapCircle_neg (θ : Real.Angle) : Real.Angle.expMapCircle (-θ) = (Real.Angle.expMapCircle θ)⁻¹ := by induction θ using Real.Angle.induction_on simp_rw [← Real.Angle.coe_neg, Real.Angle.expMapCircle_coe, _root_.expMapCircle_neg] #align real.angle.exp_map_circle_neg Real.Angle.expMapCircle_neg @[simp] theorem Real.Angle.expMapCircle_add (θ₁ θ₂ : Real.Angle) : Real.Angle.expMapCircle (θ₁ + θ₂) = Real.Angle.expMapCircle θ₁ * Real.Angle.expMapCircle θ₂ := by induction θ₁ using Real.Angle.induction_on induction θ₂ using Real.Angle.induction_on exact _root_.expMapCircle_add _ _ #align real.angle.exp_map_circle_add Real.Angle.expMapCircle_add @[simp] theorem Real.Angle.arg_expMapCircle (θ : Real.Angle) : (arg (Real.Angle.expMapCircle θ) : Real.Angle) = θ := by induction θ using Real.Angle.induction_on rw [Real.Angle.expMapCircle_coe, expMapCircle_apply, exp_mul_I, ← ofReal_cos, ← ofReal_sin, ← Real.Angle.cos_coe, ← Real.Angle.sin_coe, arg_cos_add_sin_mul_I_coe_angle] #align real.angle.arg_exp_map_circle Real.Angle.arg_expMapCircle namespace AddCircle variable {T : ℝ} /-! ### Map from `AddCircle` to `Circle` -/ theorem scaled_exp_map_periodic : Function.Periodic (fun x => expMapCircle (2 * π / T * x)) T := by -- The case T = 0 is not interesting, but it is true, so we prove it to save hypotheses rcases eq_or_ne T 0 with (rfl | hT) · intro x; simp · intro x; simp_rw [mul_add]; rw [div_mul_cancel₀ _ hT, periodic_expMapCircle] #align add_circle.scaled_exp_map_periodic AddCircle.scaled_exp_map_periodic /-- The canonical map `fun x => exp (2 π i x / T)` from `ℝ / ℤ • T` to the unit circle in `ℂ`. If `T = 0` we understand this as the constant function 1. -/ noncomputable def toCircle : AddCircle T → circle := (@scaled_exp_map_periodic T).lift #align add_circle.to_circle AddCircle.toCircle theorem toCircle_apply_mk (x : ℝ) : @toCircle T x = expMapCircle (2 * π / T * x) := rfl theorem toCircle_add (x : AddCircle T) (y : AddCircle T) : @toCircle T (x + y) = toCircle x * toCircle y := by induction x using QuotientAddGroup.induction_on' induction y using QuotientAddGroup.induction_on' simp_rw [← coe_add, toCircle_apply_mk, mul_add, expMapCircle_add] #align add_circle.to_circle_add AddCircle.toCircle_add theorem continuous_toCircle : Continuous (@toCircle T) := continuous_coinduced_dom.mpr (expMapCircle.continuous.comp <| continuous_const.mul continuous_id') #align add_circle.continuous_to_circle AddCircle.continuous_toCircle theorem injective_toCircle (hT : T ≠ 0) : Function.Injective (@toCircle T) := by intro a b h induction a using QuotientAddGroup.induction_on' induction b using QuotientAddGroup.induction_on' simp_rw [toCircle_apply_mk] at h obtain ⟨m, hm⟩ := expMapCircle_eq_expMapCircle.mp h.symm rw [QuotientAddGroup.eq]; simp_rw [AddSubgroup.mem_zmultiples_iff, zsmul_eq_mul] use m field_simp at hm rw [← mul_right_inj' Real.two_pi_pos.ne'] linarith #align add_circle.injective_to_circle AddCircle.injective_toCircle /-- The homeomorphism between `AddCircle (2 * π)` and `circle`. -/ @[simps] noncomputable def homeomorphCircle' : AddCircle (2 * π) ≃ₜ circle where toFun := Angle.expMapCircle invFun := fun x ↦ arg x left_inv := Angle.arg_expMapCircle right_inv := expMapCircle_arg continuous_toFun := continuous_coinduced_dom.mpr expMapCircle.continuous continuous_invFun := by rw [continuous_iff_continuousAt] intro x apply (continuousAt_arg_coe_angle (ne_zero_of_mem_circle x)).comp continuousAt_subtype_val theorem homeomorphCircle'_apply_mk (x : ℝ) : homeomorphCircle' x = expMapCircle x := rfl /-- The homeomorphism between `AddCircle` and `circle`. -/ noncomputable def homeomorphCircle (hT : T ≠ 0) : AddCircle T ≃ₜ circle := (homeomorphAddCircle T (2 * π) hT (by positivity)).trans homeomorphCircle'
Mathlib/Analysis/SpecialFunctions/Complex/Circle.lean
223
228
theorem homeomorphCircle_apply (hT : T ≠ 0) (x : AddCircle T) : homeomorphCircle hT x = toCircle x := by
induction' x using QuotientAddGroup.induction_on' with x rw [homeomorphCircle, Homeomorph.trans_apply, homeomorphAddCircle_apply_mk, homeomorphCircle'_apply_mk, toCircle_apply_mk] ring_nf
/- 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
Mathlib/MeasureTheory/Measure/WithDensity.lean
83
87
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)
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Julian Kuelshammer, Heather Macbeth, Mitchell Lee -/ import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Tactic.LinearCombination #align_import ring_theory.polynomial.chebyshev from "leanprover-community/mathlib"@"d774451114d6045faeb6751c396bea1eb9058946" /-! # Chebyshev polynomials The Chebyshev polynomials are families of polynomials indexed by `ℤ`, with integral coefficients. ## Main definitions * `Polynomial.Chebyshev.T`: the Chebyshev polynomials of the first kind. * `Polynomial.Chebyshev.U`: the Chebyshev polynomials of the second kind. ## Main statements * The formal derivative of the Chebyshev polynomials of the first kind is a scalar multiple of the Chebyshev polynomials of the second kind. * `Polynomial.Chebyshev.mul_T`, twice the product of the `m`-th and `k`-th Chebyshev polynomials of the first kind is the sum of the `m + k`-th and `m - k`-th Chebyshev polynomials of the first kind. * `Polynomial.Chebyshev.T_mul`, the `(m * n)`-th Chebyshev polynomial of the first kind is the composition of the `m`-th and `n`-th Chebyshev polynomials of the first kind. ## Implementation details Since Chebyshev polynomials have interesting behaviour over the complex numbers and modulo `p`, we define them to have coefficients in an arbitrary commutative ring, even though technically `ℤ` would suffice. The benefit of allowing arbitrary coefficient rings, is that the statements afterwards are clean, and do not have `map (Int.castRingHom R)` interfering all the time. ## References [Lionel Ponton, _Roots of the Chebyshev polynomials: A purely algebraic approach_] [ponton2020chebyshev] ## TODO * Redefine and/or relate the definition of Chebyshev polynomials to `LinearRecurrence`. * Add explicit formula involving square roots for Chebyshev polynomials * Compute zeroes and extrema of Chebyshev polynomials. * Prove that the roots of the Chebyshev polynomials (except 0) are irrational. * Prove minimax properties of Chebyshev polynomials. -/ namespace Polynomial.Chebyshev set_option linter.uppercaseLean3 false -- `T` `U` `X` open Polynomial variable (R S : Type*) [CommRing R] [CommRing S] /-- `T n` is the `n`-th Chebyshev polynomial of the first kind. -/ -- Well-founded definitions are now irreducible by default; -- as this was implemented before this change, -- we just set it back to semireducible to avoid needing to change any proofs. @[semireducible] noncomputable def T : ℤ → R[X] | 0 => 1 | 1 => X | (n : ℕ) + 2 => 2 * X * T (n + 1) - T n | -((n : ℕ) + 1) => 2 * X * T (-n) - T (-n + 1) termination_by n => Int.natAbs n + Int.natAbs (n - 1) #align polynomial.chebyshev.T Polynomial.Chebyshev.T /-- Induction principle used for proving facts about Chebyshev polynomials. -/ @[elab_as_elim] protected theorem induct (motive : ℤ → Prop) (zero : motive 0) (one : motive 1) (add_two : ∀ (n : ℕ), motive (↑n + 1) → motive ↑n → motive (↑n + 2)) (neg_add_one : ∀ (n : ℕ), motive (-↑n) → motive (-↑n + 1) → motive (-↑n - 1)) : ∀ (a : ℤ), motive a := T.induct Unit motive zero one add_two fun n hn hnm => by simpa only [Int.negSucc_eq, neg_add] using neg_add_one n hn hnm @[simp] theorem T_add_two : ∀ n, T R (n + 2) = 2 * X * T R (n + 1) - T R n | (k : ℕ) => T.eq_3 R k | -(k + 1 : ℕ) => by linear_combination (norm := (simp [Int.negSucc_eq]; ring_nf)) T.eq_4 R k #align polynomial.chebyshev.T_add_two Polynomial.Chebyshev.T_add_two theorem T_add_one (n : ℤ) : T R (n + 1) = 2 * X * T R n - T R (n - 1) := by linear_combination (norm := ring_nf) T_add_two R (n - 1) theorem T_sub_two (n : ℤ) : T R (n - 2) = 2 * X * T R (n - 1) - T R n := by linear_combination (norm := ring_nf) T_add_two R (n - 2) theorem T_sub_one (n : ℤ) : T R (n - 1) = 2 * X * T R n - T R (n + 1) := by linear_combination (norm := ring_nf) T_add_two R (n - 1) theorem T_eq (n : ℤ) : T R n = 2 * X * T R (n - 1) - T R (n - 2) := by linear_combination (norm := ring_nf) T_add_two R (n - 2) #align polynomial.chebyshev.T_of_two_le Polynomial.Chebyshev.T_eq @[simp] theorem T_zero : T R 0 = 1 := rfl #align polynomial.chebyshev.T_zero Polynomial.Chebyshev.T_zero @[simp] theorem T_one : T R 1 = X := rfl #align polynomial.chebyshev.T_one Polynomial.Chebyshev.T_one theorem T_neg_one : T R (-1) = X := (by ring : 2 * X * 1 - X = X) theorem T_two : T R 2 = 2 * X ^ 2 - 1 := by simpa [pow_two, mul_assoc] using T_add_two R 0 #align polynomial.chebyshev.T_two Polynomial.Chebyshev.T_two @[simp] theorem T_neg (n : ℤ) : T R (-n) = T R n := by induction n using Polynomial.Chebyshev.induct with | zero => rfl | one => show 2 * X * 1 - X = X; ring | add_two n ih1 ih2 => have h₁ := T_add_two R n have h₂ := T_sub_two R (-n) linear_combination (norm := ring_nf) (2 * (X:R[X])) * ih1 - ih2 - h₁ + h₂ | neg_add_one n ih1 ih2 => have h₁ := T_add_one R n have h₂ := T_sub_one R (-n) linear_combination (norm := ring_nf) (2 * (X:R[X])) * ih1 - ih2 + h₁ - h₂ theorem T_natAbs (n : ℤ) : T R n.natAbs = T R n := by obtain h | h := Int.natAbs_eq n <;> nth_rw 2 [h]; simp
Mathlib/RingTheory/Polynomial/Chebyshev.lean
134
134
theorem T_neg_two : T R (-2) = 2 * X ^ 2 - 1 := by
simp [T_two]