state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b C x : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) hx : x ∈ Icc a b hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C h : a < b hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) h' : ∀ y ∈ Ico a x, ‖((↑n !)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C t : ℝ ht : t ∈ Icc a x ⊢ HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht
have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht
Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n !
Mathlib_Analysis_Calculus_Taylor
𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b C x : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) hx : x ∈ Icc a b hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C h : a < b hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) h' : ∀ y ∈ Ico a x, ‖((↑n !)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C t : ℝ ht : t ∈ Icc a x I : Icc a x ⊆ Icc a b ⊢ HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2
exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2
Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n !
Mathlib_Analysis_Calculus_Taylor
case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b C x : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) hx : x ∈ Icc a b hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C h : a < b hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) h' : ∀ y ∈ Ico a x, ‖((↑n !)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t ⊢ ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / ↑n !
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I
have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1)
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I
Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n !
Mathlib_Analysis_Calculus_Taylor
case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b C x : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) hx : x ∈ Icc a b hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C h : a < b hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) h' : ∀ y ∈ Ico a x, ‖((↑n !)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t this : ‖taylorWithinEval f n (Icc a b) x x - taylorWithinEval f n (Icc a b) a x‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C * (x - a) ⊢ ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / ↑n !
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1)
simp only [taylorWithinEval_self] at this
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1)
Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n !
Mathlib_Analysis_Calculus_Taylor
case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b C x : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) hx : x ∈ Icc a b hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C h : a < b hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) h' : ∀ y ∈ Ico a x, ‖((↑n !)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t this : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C * (x - a) ⊢ ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / ↑n !
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this
refine' this.trans_eq _
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this
Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n !
Mathlib_Analysis_Calculus_Taylor
case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b C x : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) hx : x ∈ Icc a b hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C h : a < b hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) h' : ∀ y ∈ Ico a x, ‖((↑n !)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t this : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C * (x - a) ⊢ (↑n !)⁻¹ * |x - a| ^ n * C * (x - a) = C * (x - a) ^ (n + 1) / ↑n !
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation
rw [abs_of_nonneg (sub_nonneg.mpr hx.1)]
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation
Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n !
Mathlib_Analysis_Calculus_Taylor
case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b C x : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) hx : x ∈ Icc a b hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C h : a < b hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) h' : ∀ y ∈ Ico a x, ‖((↑n !)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t this : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ (↑n !)⁻¹ * |x - a| ^ n * C * (x - a) ⊢ (↑n !)⁻¹ * (x - a) ^ n * C * (x - a) = C * (x - a) ^ (n + 1) / ↑n !
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)]
ring
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)]
Mathlib.Analysis.Calculus.Taylor.313_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n !
Mathlib_Analysis_Calculus_Taylor
𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) ⊢ ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by
rcases eq_or_lt_of_le hab with (rfl | h)
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
case inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a : ℝ n : ℕ hab : a ≀ a hf : ContDiffOn ℝ (↑n + 1) f (Icc a a) ⊢ ∃ C, ∀ x ∈ Icc a a, ‖f x - taylorWithinEval f n (Icc a a) a x‖ ≀ C * (x - a) ^ (n + 1)
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) ·
refine' ⟹0, fun x hx => _⟩
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) ·
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
case inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a : ℝ n : ℕ hab : a ≀ a hf : ContDiffOn ℝ (↑n + 1) f (Icc a a) x : ℝ hx : x ∈ Icc a a ⊢ ‖f x - taylorWithinEval f n (Icc a a) a x‖ ≀ 0 * (x - a) ^ (n + 1)
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩
have : x = a := by simpa [← le_antisymm_iff] using hx
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a : ℝ n : ℕ hab : a ≀ a hf : ContDiffOn ℝ (↑n + 1) f (Icc a a) x : ℝ hx : x ∈ Icc a a ⊢ x = a
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by
simpa [← le_antisymm_iff] using hx
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
case inl 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a : ℝ n : ℕ hab : a ≀ a hf : ContDiffOn ℝ (↑n + 1) f (Icc a a) x : ℝ hx : x ∈ Icc a a this : x = a ⊢ ‖f x - taylorWithinEval f n (Icc a a) a x‖ ≀ 0 * (x - a) ^ (n + 1)
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx
simp [← this]
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) h : a < b ⊢ ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative
let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
case inr 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) h : a < b g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ⊢ ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖
use SupSet.sSup (g '' Icc a b) / (n !)
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) h : a < b g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ⊢ ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ sSup (g '' Icc a b) / ↑n ! * (x - a) ^ (n + 1)
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ use SupSet.sSup (g '' Icc a b) / (n !)
intro x hx
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ use SupSet.sSup (g '' Icc a b) / (n !)
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) h : a < b g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ x : ℝ hx : x ∈ Icc a b ⊢ ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ sSup (g '' Icc a b) / ↑n ! * (x - a) ^ (n + 1)
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ use SupSet.sSup (g '' Icc a b) / (n !) intro x hx
rw [div_mul_eq_mul_div₀]
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ use SupSet.sSup (g '' Icc a b) / (n !) intro x hx
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) h : a < b g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ x : ℝ hx : x ∈ Icc a b ⊢ ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ sSup (g '' Icc a b) * (x - a) ^ (n + 1) / ↑n !
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ use SupSet.sSup (g '' Icc a b) / (n !) intro x hx rw [div_mul_eq_mul_div₀]
refine' taylor_mean_remainder_bound hab hf hx fun y => _
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ use SupSet.sSup (g '' Icc a b) / (n !) intro x hx rw [div_mul_eq_mul_div₀]
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
case h 𝕜 : Type u_1 E : Type u_2 F : Type u_3 inst✝¹ : NormedAddCommGroup E inst✝ : NormedSpace ℝ E f : ℝ → E a b : ℝ n : ℕ hab : a ≀ b hf : ContDiffOn ℝ (↑n + 1) f (Icc a b) h : a < b g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ x : ℝ hx : x ∈ Icc a b y : ℝ ⊢ y ∈ Icc a b → ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ sSup (g '' Icc a b)
/- 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.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Data.Polynomial.Module #align_import analysis.calculus.taylor from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped BigOperators Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ #align taylor_coeff_within taylorCoeffWithin /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) #align taylor_within taylorWithin /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) #align taylor_within_eval taylorWithinEval theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] #align taylor_within_succ taylorWithin_succ @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] #align taylor_within_eval_succ taylorWithinEval_succ /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp #align taylor_within_zero_eval taylor_within_zero_eval /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] #align taylor_within_eval_self taylorWithinEval_self theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k in Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] #align taylor_within_apply taylor_within_apply /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine' continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => _ refine' (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul _ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine' hf_left _ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] #align continuous_on_taylor_within_eval continuousOn_taylorWithinEval /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions.-/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] #align monomial_has_deriv_aux monomial_has_deriv_aux theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] #align has_deriv_within_at_taylor_coeff_within hasDerivWithinAt_taylor_coeff_within /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] norm_num exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel'_right _ _).symm #align has_deriv_within_at_taylor_within_eval hasDerivWithinAt_taylorWithinEval /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds #align taylor_within_eval_has_deriv_at_Ioo taylorWithinEval_hasDerivAt_Ioo /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem has_deriv_within_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) #align has_deriv_within_taylor_within_eval_at_Icc has_deriv_within_taylorWithinEval_at_Icc /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring #align taylor_mean_remainder taylor_mean_remainder /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by refine' Continuous.continuousOn _ exact (continuous_const.sub continuous_id').pow _ -- Porting note: was `continuity` have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine' pow_ne_zero _ _ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring #align taylor_mean_remainder_lagrange taylor_mean_remainder_lagrange /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := Continuous.continuousOn (by continuity) have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring #align taylor_mean_remainder_cauchy taylor_mean_remainder_cauchy /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr rw [abs_of_nonneg, abs_of_nonneg] <;> linarith -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (has_deriv_within_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine' this.trans_eq _ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring #align taylor_mean_remainder_bound taylor_mean_remainder_bound /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ use SupSet.sSup (g '' Icc a b) / (n !) intro x hx rw [div_mul_eq_mul_div₀] refine' taylor_mean_remainder_bound hab hf hx fun y => _
exact (hf.continuousOn_iteratedDerivWithin rfl.le <| uniqueDiffOn_Icc h).norm.le_sSup_image_Icc
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine' ⟹0, fun x hx => _⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ use SupSet.sSup (g '' Icc a b) / (n !) intro x hx rw [div_mul_eq_mul_div₀] refine' taylor_mean_remainder_bound hab hf hx fun y => _
Mathlib.Analysis.Calculus.Taylor.355_0.INXnr4jrmq9RIjK
/-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1)
Mathlib_Analysis_Calculus_Taylor
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Equiv.Perm α f : α ↪ β x✝ : α ⊢ invOfMemRange f ((fun a => { val := f a, property := (_ : f a ∈ Set.range ⇑f) }) x✝) = x✝
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by
simp
/-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by
Mathlib.Logic.Equiv.Fintype.33_0.fUeUwBtkCE24P9E
/-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Equiv.Perm α f : α ↪ β x✝ : ↑(Set.range ⇑f) ⊢ (fun a => { val := f a, property := (_ : f a ∈ Set.range ⇑f) }) (invOfMemRange f x✝) = x✝
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by
simp
/-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by
Mathlib.Logic.Equiv.Fintype.33_0.fUeUwBtkCE24P9E
/-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Equiv.Perm α f : α ↪ β a : α ⊢ (toEquivRange f).symm { val := f a, property := (_ : f a ∈ Set.range ⇑f) } = a
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by
simp [Equiv.symm_apply_eq]
@[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by
Mathlib.Logic.Equiv.Fintype.48_0.fUeUwBtkCE24P9E
@[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Equiv.Perm α f : α ↪ β ⊢ toEquivRange f = Equiv.ofInjective ⇑f (_ : Injective ⇑f)
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by
ext
theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by
Mathlib.Logic.Equiv.Fintype.53_0.fUeUwBtkCE24P9E
theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective
Mathlib_Logic_Equiv_Fintype
case H.a α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Equiv.Perm α f : α ↪ β x✝ : α ⊢ ↑((toEquivRange f) x✝) = ↑((Equiv.ofInjective ⇑f (_ : Injective ⇑f)) x✝)
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext
simp
theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext
Mathlib.Logic.Equiv.Fintype.53_0.fUeUwBtkCE24P9E
theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Perm α f : α ↪ β a : α ⊢ (viaFintypeEmbedding e f) (f a) = f (e a)
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by
rw [Equiv.Perm.viaFintypeEmbedding]
@[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by
Mathlib.Logic.Equiv.Fintype.70_0.fUeUwBtkCE24P9E
@[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a)
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Perm α f : α ↪ β a : α ⊢ (extendDomain e (Function.Embedding.toEquivRange f)) (f a) = f (e a)
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding]
convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a
@[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding]
Mathlib.Logic.Equiv.Fintype.70_0.fUeUwBtkCE24P9E
@[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a)
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Perm α f : α ↪ β b : β h : b ∈ Set.range ⇑f ⊢ (viaFintypeEmbedding e f) b = f (e (Function.Embedding.invOfMemRange f { val := b, property := h }))
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by
simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange]
theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by
Mathlib.Logic.Equiv.Fintype.77_0.fUeUwBtkCE24P9E
theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩))
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Perm α f : α ↪ β b : β h : b ∈ Set.range ⇑f ⊢ (extendDomain e (Function.Embedding.toEquivRange f)) b = f (e (Function.Injective.invOfMemRange (_ : Function.Injective ⇑f) { val := b, property := h }))
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange]
rw [Equiv.Perm.extendDomain_apply_subtype]
theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange]
Mathlib.Logic.Equiv.Fintype.77_0.fUeUwBtkCE24P9E
theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩))
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Perm α f : α ↪ β b : β h : b ∈ Set.range ⇑f ⊢ ↑((Function.Embedding.toEquivRange f) (e ((Function.Embedding.toEquivRange f).symm { val := b, property := ?h }))) = f (e (Function.Injective.invOfMemRange (_ : Function.Injective ⇑f) { val := b, property := h })) case h α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Perm α f : α ↪ β b : β h : b ∈ Set.range ⇑f ⊢ b ∈ Set.range ⇑f
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype]
congr
theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype]
Mathlib.Logic.Equiv.Fintype.77_0.fUeUwBtkCE24P9E
theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩))
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝¹ : Fintype α inst✝ : DecidableEq β e : Perm α f : α ↪ β b : β h : b ∉ Set.range ⇑f ⊢ (viaFintypeEmbedding e f) b = b
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by
rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype]
theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by
Mathlib.Logic.Equiv.Fintype.84_0.fUeUwBtkCE24P9E
theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e : Perm α f : α ↪ β inst✝¹ : DecidableEq α inst✝ : Fintype β ⊢ sign (viaFintypeEmbedding e f) = sign e
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by
simp [Equiv.Perm.viaFintypeEmbedding]
@[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by
Mathlib.Logic.Equiv.Fintype.89_0.fUeUwBtkCE24P9E
@[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : p x ⊢ (extendSubtype e) x = ↑(e { val := x, property := hx })
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by
dsimp only [extendSubtype]
theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by
Mathlib.Logic.Equiv.Fintype.117_0.fUeUwBtkCE24P9E
theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : p x ⊢ (subtypeCongr e (toCompl e)) x = ↑(e { val := x, property := hx })
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype]
simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply]
theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype]
Mathlib.Logic.Equiv.Fintype.117_0.fUeUwBtkCE24P9E
theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : p x ⊢ (sumCompl fun x => q x) (Sum.map (⇑e) (⇑(toCompl e)) ((sumCompl fun x => p x).symm x)) = ↑(e { val := x, property := hx })
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply]
rw [sumCompl_apply_symm_of_pos _ _ hx, Sum.map_inl, sumCompl_apply_inl]
theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply]
Mathlib.Logic.Equiv.Fintype.117_0.fUeUwBtkCE24P9E
theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : p x ⊢ q ((extendSubtype e) x)
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_pos _ _ hx, Sum.map_inl, sumCompl_apply_inl] #align equiv.extend_subtype_apply_of_mem Equiv.extendSubtype_apply_of_mem theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by
convert (e ⟹x, hx⟩).2
theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by
Mathlib.Logic.Equiv.Fintype.124_0.fUeUwBtkCE24P9E
theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x)
Mathlib_Logic_Equiv_Fintype
case h.e'_1 α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : p x ⊢ (extendSubtype e) x = ↑(e { val := x, property := hx })
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_pos _ _ hx, Sum.map_inl, sumCompl_apply_inl] #align equiv.extend_subtype_apply_of_mem Equiv.extendSubtype_apply_of_mem theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by convert (e ⟹x, hx⟩).2
rw [e.extendSubtype_apply_of_mem _ hx]
theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by convert (e ⟹x, hx⟩).2
Mathlib.Logic.Equiv.Fintype.124_0.fUeUwBtkCE24P9E
theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x)
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : ¬p x ⊢ (extendSubtype e) x = ↑((toCompl e) { val := x, property := hx })
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_pos _ _ hx, Sum.map_inl, sumCompl_apply_inl] #align equiv.extend_subtype_apply_of_mem Equiv.extendSubtype_apply_of_mem theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by convert (e ⟹x, hx⟩).2 rw [e.extendSubtype_apply_of_mem _ hx] #align equiv.extend_subtype_mem Equiv.extendSubtype_mem theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩ := by
dsimp only [extendSubtype]
theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩ := by
Mathlib.Logic.Equiv.Fintype.130_0.fUeUwBtkCE24P9E
theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : ¬p x ⊢ (subtypeCongr e (toCompl e)) x = ↑((toCompl e) { val := x, property := hx })
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_pos _ _ hx, Sum.map_inl, sumCompl_apply_inl] #align equiv.extend_subtype_apply_of_mem Equiv.extendSubtype_apply_of_mem theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by convert (e ⟹x, hx⟩).2 rw [e.extendSubtype_apply_of_mem _ hx] #align equiv.extend_subtype_mem Equiv.extendSubtype_mem theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩ := by dsimp only [extendSubtype]
simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply]
theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩ := by dsimp only [extendSubtype]
Mathlib.Logic.Equiv.Fintype.130_0.fUeUwBtkCE24P9E
theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : ¬p x ⊢ (sumCompl fun x => q x) (Sum.map (⇑e) (⇑(toCompl e)) ((sumCompl fun x => p x).symm x)) = ↑((toCompl e) { val := x, property := hx })
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_pos _ _ hx, Sum.map_inl, sumCompl_apply_inl] #align equiv.extend_subtype_apply_of_mem Equiv.extendSubtype_apply_of_mem theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by convert (e ⟹x, hx⟩).2 rw [e.extendSubtype_apply_of_mem _ hx] #align equiv.extend_subtype_mem Equiv.extendSubtype_mem theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply]
rw [sumCompl_apply_symm_of_neg _ _ hx, Sum.map_inr, sumCompl_apply_inr]
theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply]
Mathlib.Logic.Equiv.Fintype.130_0.fUeUwBtkCE24P9E
theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩
Mathlib_Logic_Equiv_Fintype
α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : ¬p x ⊢ ¬q ((extendSubtype e) x)
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_pos _ _ hx, Sum.map_inl, sumCompl_apply_inl] #align equiv.extend_subtype_apply_of_mem Equiv.extendSubtype_apply_of_mem theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by convert (e ⟹x, hx⟩).2 rw [e.extendSubtype_apply_of_mem _ hx] #align equiv.extend_subtype_mem Equiv.extendSubtype_mem theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_neg _ _ hx, Sum.map_inr, sumCompl_apply_inr] #align equiv.extend_subtype_apply_of_not_mem Equiv.extendSubtype_apply_of_not_mem theorem extendSubtype_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : ¬q (e.extendSubtype x) := by
convert (e.toCompl ⟹x, hx⟩).2
theorem extendSubtype_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : ¬q (e.extendSubtype x) := by
Mathlib.Logic.Equiv.Fintype.137_0.fUeUwBtkCE24P9E
theorem extendSubtype_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : ¬q (e.extendSubtype x)
Mathlib_Logic_Equiv_Fintype
case h.e'_1.h.e'_1 α : Type u_1 β : Type u_2 inst✝³ : Fintype α inst✝² : DecidableEq β e✝ : Perm α f : α ↪ β p q : α → Prop inst✝¹ : DecidablePred p inst✝ : DecidablePred q e : { x // p x } ≃ { x // q x } x : α hx : ¬p x ⊢ (extendSubtype e) x = ↑((toCompl e) { val := x, property := hx })
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Fintype.Basic import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Defs #align_import logic.equiv.fintype from "leanprover-community/mathlib"@"9407b03373c8cd201df99d6bc5514fc2db44054f" /-! # Equivalence between fintypes This file contains some basic results on equivalences where one or both sides of the equivalence are `Fintype`s. # Main definitions - `Function.Embedding.toEquivRange`: computably turn an embedding of a fintype into an `Equiv` of the domain to its range - `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of a permutation, fixing everything outside the range of the embedding # Implementation details - `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor computational performance, since it operates by exhaustive search over the input `Fintype`s. -/ variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β) /-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`, if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or `Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`. -/ def Function.Embedding.toEquivRange : α ≃ Set.range f := ⟹fun a => ⟹f a, Set.mem_range_self a⟩, f.invOfMemRange, fun _ => by simp, fun _ => by simp⟩ #align function.embedding.to_equiv_range Function.Embedding.toEquivRange @[simp] theorem Function.Embedding.toEquivRange_apply (a : α) : f.toEquivRange a = ⟹f a, Set.mem_range_self a⟩ := rfl #align function.embedding.to_equiv_range_apply Function.Embedding.toEquivRange_apply @[simp] theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) : f.toEquivRange.symm ⟹f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq] #align function.embedding.to_equiv_range_symm_apply_self Function.Embedding.toEquivRange_symm_apply_self theorem Function.Embedding.toEquivRange_eq_ofInjective : f.toEquivRange = Equiv.ofInjective f f.injective := by ext simp #align function.embedding.to_equiv_range_eq_of_injective Function.Embedding.toEquivRange_eq_ofInjective /-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`. Everything outside of `Set.range f` is kept fixed. Has poor computational performance, due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`. When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`. When `[Fintype α]` is not available, a noncomputable version is available as `Equiv.Perm.viaEmbedding`. -/ def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β := e.extendDomain f.toEquivRange #align equiv.perm.via_fintype_embedding Equiv.Perm.viaFintypeEmbedding @[simp] theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) : e.viaFintypeEmbedding f (f a) = f (e a) := by rw [Equiv.Perm.viaFintypeEmbedding] convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a #align equiv.perm.via_fintype_embedding_apply_image Equiv.Perm.viaFintypeEmbedding_apply_image theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) : e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟹b, h⟩)) := by simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange] rw [Equiv.Perm.extendDomain_apply_subtype] congr #align equiv.perm.via_fintype_embedding_apply_mem_range Equiv.Perm.viaFintypeEmbedding_apply_mem_range theorem Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range {b : β} (h : b ∉ Set.range f) : e.viaFintypeEmbedding f b = b := by rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype] #align equiv.perm.via_fintype_embedding_apply_not_mem_range Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range @[simp] theorem Equiv.Perm.viaFintypeEmbedding_sign [DecidableEq α] [Fintype β] : Equiv.Perm.sign (e.viaFintypeEmbedding f) = Equiv.Perm.sign e := by simp [Equiv.Perm.viaFintypeEmbedding] #align equiv.perm.via_fintype_embedding_sign Equiv.Perm.viaFintypeEmbedding_sign namespace Equiv variable {p q : α → Prop} [DecidablePred p] [DecidablePred q] /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.toCompl` is an equivalence between the complement of those subtypes. See also `Equiv.compl`, for a computable version when a term of type `{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/ noncomputable def toCompl (e : { x // p x } ≃ { x // q x }) : { x // ¬p x } ≃ { x // ¬q x } := Classical.choice (Fintype.card_eq.mp (Fintype.card_compl_eq_card_compl _ _ (Fintype.card_congr e))) #align equiv.to_compl Equiv.toCompl /-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype` is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside. Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/ noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α := subtypeCongr e e.toCompl #align equiv.extend_subtype Equiv.extendSubtype theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : e.extendSubtype x = e ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_pos _ _ hx, Sum.map_inl, sumCompl_apply_inl] #align equiv.extend_subtype_apply_of_mem Equiv.extendSubtype_apply_of_mem theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) : q (e.extendSubtype x) := by convert (e ⟹x, hx⟩).2 rw [e.extendSubtype_apply_of_mem _ hx] #align equiv.extend_subtype_mem Equiv.extendSubtype_mem theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : e.extendSubtype x = e.toCompl ⟹x, hx⟩ := by dsimp only [extendSubtype] simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply] rw [sumCompl_apply_symm_of_neg _ _ hx, Sum.map_inr, sumCompl_apply_inr] #align equiv.extend_subtype_apply_of_not_mem Equiv.extendSubtype_apply_of_not_mem theorem extendSubtype_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : ¬q (e.extendSubtype x) := by convert (e.toCompl ⟹x, hx⟩).2
rw [e.extendSubtype_apply_of_not_mem _ hx]
theorem extendSubtype_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : ¬q (e.extendSubtype x) := by convert (e.toCompl ⟹x, hx⟩).2
Mathlib.Logic.Equiv.Fintype.137_0.fUeUwBtkCE24P9E
theorem extendSubtype_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) : ¬q (e.extendSubtype x)
Mathlib_Logic_Equiv_Fintype
𝕜 : Type u_1 inst✝ : IsROrC 𝕜 ⊢ Tendsto (fun n => (↑n)⁻¹) atTop (nhds 0)
/- Copyright (c) 2023 Xavier Généreux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Généreux, Patrick Massot -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Analysis.Complex.ReImTopology /-! # A collection of specific limit computations for `IsROrC` -/ open Set Algebra Filter variable (𝕜 : Type*) [IsROrC 𝕜] theorem IsROrC.tendsto_inverse_atTop_nhds_0_nat : Tendsto (fun n : ℕ => (n : 𝕜)⁻¹) atTop (nhds 0) := by
convert tendsto_algebraMap_inverse_atTop_nhds_0_nat 𝕜
theorem IsROrC.tendsto_inverse_atTop_nhds_0_nat : Tendsto (fun n : ℕ => (n : 𝕜)⁻¹) atTop (nhds 0) := by
Mathlib.Analysis.SpecificLimits.IsROrC.18_0.GxvrNOjFh6rYkey
theorem IsROrC.tendsto_inverse_atTop_nhds_0_nat : Tendsto (fun n : ℕ => (n : 𝕜)⁻¹) atTop (nhds 0)
Mathlib_Analysis_SpecificLimits_IsROrC
case h.e'_3.h 𝕜 : Type u_1 inst✝ : IsROrC 𝕜 x✝ : ℕ ⊢ (↑x✝)⁻¹ = (⇑(algebraMap ℝ 𝕜) ∘ fun n => (↑n)⁻¹) x✝
/- Copyright (c) 2023 Xavier Généreux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Généreux, Patrick Massot -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Analysis.Complex.ReImTopology /-! # A collection of specific limit computations for `IsROrC` -/ open Set Algebra Filter variable (𝕜 : Type*) [IsROrC 𝕜] theorem IsROrC.tendsto_inverse_atTop_nhds_0_nat : Tendsto (fun n : ℕ => (n : 𝕜)⁻¹) atTop (nhds 0) := by convert tendsto_algebraMap_inverse_atTop_nhds_0_nat 𝕜
simp
theorem IsROrC.tendsto_inverse_atTop_nhds_0_nat : Tendsto (fun n : ℕ => (n : 𝕜)⁻¹) atTop (nhds 0) := by convert tendsto_algebraMap_inverse_atTop_nhds_0_nat 𝕜
Mathlib.Analysis.SpecificLimits.IsROrC.18_0.GxvrNOjFh6rYkey
theorem IsROrC.tendsto_inverse_atTop_nhds_0_nat : Tendsto (fun n : ℕ => (n : 𝕜)⁻¹) atTop (nhds 0)
Mathlib_Analysis_SpecificLimits_IsROrC
C : Type u_2 inst✝ : Category.{u_1, u_2} C r : HomRel C a b : C m₁ m₂ : a ⟶ b h : r m₁ m₂ ⊢ CompClosure r m₁ m₂
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by
simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h
theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by
Mathlib.CategoryTheory.Quotient.65_0.34bZdkqpf1A9Wub
theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂
Mathlib_CategoryTheory_Quotient
C : Type u_2 inst✝ : Category.{u_1, u_2} C r : HomRel C a b c : C f : a ⟶ b a✝ b✝ : C x : b ⟶ a✝ m₁ m₂ : a✝ ⟶ b✝ y : b✝ ⟶ c h : r m₁ m₂ ⊢ CompClosure r (f ≫ x ≫ m₁ ≫ y) (f ≫ x ≫ m₂ ≫ y)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by
simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h
theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by
Mathlib.CategoryTheory.Quotient.69_0.34bZdkqpf1A9Wub
theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h
Mathlib_CategoryTheory_Quotient
C : Type u_2 inst✝ : Category.{u_1, u_2} C r : HomRel C a b c : C g : b ⟶ c a✝ b✝ : C x : a ⟶ a✝ m₁ m₂ : a✝ ⟶ b✝ y : b✝ ⟶ b h : r m₁ m₂ ⊢ CompClosure r ((x ≫ m₁ ≫ y) ≫ g) ((x ≫ m₂ ≫ y) ≫ g)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by
simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h
theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by
Mathlib.CategoryTheory.Quotient.74_0.34bZdkqpf1A9Wub
theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h
Mathlib_CategoryTheory_Quotient
C : Type ?u.6549 inst✝ : Category.{?u.6553, ?u.6549} C r : HomRel C X✝ Y✝ : Quotient r f : X✝ ⟶ Y✝ ⊢ ∀ (a : X✝.as ⟶ Y✝.as), 𝟙 X✝ ≫ Quot.mk (CompClosure r) a = Quot.mk (CompClosure r) a
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by
simp
instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by
Mathlib.CategoryTheory.Quotient.103_0.34bZdkqpf1A9Wub
instance category : Category (Quotient r) where Hom
Mathlib_CategoryTheory_Quotient
C : Type ?u.6549 inst✝ : Category.{?u.6553, ?u.6549} C r : HomRel C X✝ Y✝ : Quotient r f : X✝ ⟶ Y✝ ⊢ ∀ (a : X✝.as ⟶ Y✝.as), Quot.mk (CompClosure r) a ≫ 𝟙 Y✝ = Quot.mk (CompClosure r) a
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by
simp
instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by
Mathlib.CategoryTheory.Quotient.103_0.34bZdkqpf1A9Wub
instance category : Category (Quotient r) where Hom
Mathlib_CategoryTheory_Quotient
C : Type ?u.6549 inst✝ : Category.{?u.6553, ?u.6549} C r : HomRel C W✝ X✝ Y✝ Z✝ : Quotient r f : W✝ ⟶ X✝ g : X✝ ⟶ Y✝ h : Y✝ ⟶ Z✝ ⊢ ∀ (a : Y✝.as ⟶ Z✝.as) (a_1 : X✝.as ⟶ Y✝.as) (a_2 : W✝.as ⟶ X✝.as), (Quot.mk (CompClosure r) a_2 ≫ Quot.mk (CompClosure r) a_1) ≫ Quot.mk (CompClosure r) a = Quot.mk (CompClosure r) a_2 ≫ Quot.mk (CompClosure r) a_1 ≫ Quot.mk (CompClosure r) a
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by
simp
instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by
Mathlib.CategoryTheory.Quotient.103_0.34bZdkqpf1A9Wub
instance category : Category (Quotient r) where Hom
Mathlib_CategoryTheory_Quotient
C : Type ?u.9520 inst✝ : Category.{?u.9524, ?u.9520} C r : HomRel C X✝ Y✝ : C f : (functor r).obj X✝ ⟶ (functor r).obj Y✝ ⊢ (functor r).map ((fun X Y f => Quot.out f) X✝ Y✝ f) = f
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by
dsimp [functor]
noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by
Mathlib.CategoryTheory.Quotient.118_0.34bZdkqpf1A9Wub
noncomputable instance fullFunctor : Full (functor r) where preimage
Mathlib_CategoryTheory_Quotient
C : Type ?u.9520 inst✝ : Category.{?u.9524, ?u.9520} C r : HomRel C X✝ Y✝ : C f : (functor r).obj X✝ ⟶ (functor r).obj Y✝ ⊢ Quot.mk (CompClosure r) (Quot.out f) = f
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor]
simp
noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor]
Mathlib.CategoryTheory.Quotient.118_0.34bZdkqpf1A9Wub
noncomputable instance fullFunctor : Full (functor r) where preimage
Mathlib_CategoryTheory_Quotient
C : Type ?u.9843 inst✝ : Category.{?u.9847, ?u.9843} C r : HomRel C Y : Quotient r ⊢ (functor r).obj Y.as = Y
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by
ext
instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by
Mathlib.CategoryTheory.Quotient.124_0.34bZdkqpf1A9Wub
instance essSurj_functor : EssSurj (functor r) where mem_essImage Y
Mathlib_CategoryTheory_Quotient
case as C : Type ?u.9843 inst✝ : Category.{?u.9847, ?u.9843} C r : HomRel C Y : Quotient r ⊢ ((functor r).obj Y.as).as = Y.as
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext
rfl
instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext
Mathlib.CategoryTheory.Quotient.124_0.34bZdkqpf1A9Wub
instance essSurj_functor : EssSurj (functor r) where mem_essImage Y
Mathlib_CategoryTheory_Quotient
C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C P : {a b : Quotient r} → (a ⟶ b) → Prop h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f) ⊢ ∀ {a b : Quotient r} (f : a ⟶ b), P f
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by
rintro ⟹x⟩ ⟹y⟩ ⟹f⟩
protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by
Mathlib.CategoryTheory.Quotient.130_0.34bZdkqpf1A9Wub
protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f
Mathlib_CategoryTheory_Quotient
case mk.mk.mk C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C P : {a b : Quotient r} → (a ⟶ b) → Prop h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f) x y : C f✝ : { as := x } ⟶ { as := y } f : { as := x }.as ⟶ { as := y }.as ⊢ P (Quot.mk (CompClosure r) f)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩
exact h f
protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩
Mathlib.CategoryTheory.Quotient.130_0.34bZdkqpf1A9Wub
protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f
Mathlib_CategoryTheory_Quotient
C : Type u_2 inst✝ : Category.{u_1, u_2} C r : HomRel C a b : C f₁ f₂ : a ⟶ b h : r f₁ f₂ ⊢ (functor r).map f₁ = (functor r).map f₂
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by
simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h)
protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by
Mathlib.CategoryTheory.Quotient.137_0.34bZdkqpf1A9Wub
protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂
Mathlib_CategoryTheory_Quotient
C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r X Y : C f g : X ⟶ Y ⊢ CompClosure r f g ↔ r f g
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by
constructor
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by
Mathlib.CategoryTheory.Quotient.142_0.34bZdkqpf1A9Wub
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g
Mathlib_CategoryTheory_Quotient
case mp C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r X Y : C f g : X ⟶ Y ⊢ CompClosure r f g → r f g
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor ·
intro hfg
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor ·
Mathlib.CategoryTheory.Quotient.142_0.34bZdkqpf1A9Wub
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g
Mathlib_CategoryTheory_Quotient
case mp C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r X Y : C f g : X ⟶ Y hfg : CompClosure r f g ⊢ r f g
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg
induction' hfg with m m' hm
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg
Mathlib.CategoryTheory.Quotient.142_0.34bZdkqpf1A9Wub
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g
Mathlib_CategoryTheory_Quotient
case mp.intro C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r X Y : C f g : X ⟶ Y m m' : C hm : X ⟶ m m₁✝ m₂✝ : m ⟶ m' g✝ : m' ⟶ Y h✝ : r m₁✝ m₂✝ ⊢ r (hm ≫ m₁✝ ≫ g✝) (hm ≫ m₂✝ ≫ g✝)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm
exact Congruence.compLeft _ (Congruence.compRight _ (by assumption))
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm
Mathlib.CategoryTheory.Quotient.142_0.34bZdkqpf1A9Wub
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g
Mathlib_CategoryTheory_Quotient
C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r X Y : C f g : X ⟶ Y m m' : C hm : X ⟶ m m₁✝ m₂✝ : m ⟶ m' g✝ : m' ⟶ Y h✝ : r m₁✝ m₂✝ ⊢ r m₁✝ m₂✝
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by
assumption
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by
Mathlib.CategoryTheory.Quotient.142_0.34bZdkqpf1A9Wub
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g
Mathlib_CategoryTheory_Quotient
case mpr C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r X Y : C f g : X ⟶ Y ⊢ r f g → CompClosure r f g
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) ·
exact CompClosure.of _ _ _
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) ·
Mathlib.CategoryTheory.Quotient.142_0.34bZdkqpf1A9Wub
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g
Mathlib_CategoryTheory_Quotient
C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r ⊢ CompClosure r = r
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by
ext
@[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by
Mathlib.CategoryTheory.Quotient.150_0.34bZdkqpf1A9Wub
@[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r
Mathlib_CategoryTheory_Quotient
case h.h.h.h.a C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r x✝³ x✝² : C x✝¹ x✝ : x✝³ ⟶ x✝² ⊢ CompClosure r x✝¹ x✝ ↔ r x✝¹ x✝
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext
simp only [compClosure_iff_self]
@[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext
Mathlib.CategoryTheory.Quotient.150_0.34bZdkqpf1A9Wub
@[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r
Mathlib_CategoryTheory_Quotient
C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r X Y : C f f' : X ⟶ Y ⊢ (functor r).map f = (functor r).map f' ↔ r f f'
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by
dsimp [functor]
theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by
Mathlib.CategoryTheory.Quotient.156_0.34bZdkqpf1A9Wub
theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f'
Mathlib_CategoryTheory_Quotient
C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r X Y : C f f' : X ⟶ Y ⊢ Quot.mk (CompClosure r) f = Quot.mk (CompClosure r) f' ↔ r f f'
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor]
rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r]
theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor]
Mathlib.CategoryTheory.Quotient.156_0.34bZdkqpf1A9Wub
theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f'
Mathlib_CategoryTheory_Quotient
case h C : Type u_1 inst✝ : Category.{u_2, u_1} C r : HomRel C h : Congruence r X Y : C f f' : X ⟶ Y ⊢ _root_.Equivalence (CompClosure r)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r]
simpa only [compClosure_eq_self r] using h.equivalence
theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r]
Mathlib.CategoryTheory.Quotient.156_0.34bZdkqpf1A9Wub
theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f'
Mathlib_CategoryTheory_Quotient
C : Type ?u.12785 inst✝¹ : Category.{?u.12789, ?u.12785} C r : HomRel C D : Type ?u.12817 inst✝ : Category.{?u.12821, ?u.12817} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ a b : Quotient r hf : a ⟶ b ⊢ ∀ (a_1 b_1 : a.as ⟶ b.as), CompClosure r a_1 b_1 → (fun f => F.map f) a_1 = (fun f => F.map f) b_1
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by
rintro _ _ ⟹_, _, _, _, h⟩
/-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by
Mathlib.CategoryTheory.Quotient.166_0.34bZdkqpf1A9Wub
/-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a
Mathlib_CategoryTheory_Quotient
case intro C : Type ?u.12785 inst✝¹ : Category.{?u.12789, ?u.12785} C r : HomRel C D : Type ?u.12817 inst✝ : Category.{?u.12821, ?u.12817} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ a b : Quotient r hf : a ⟶ b a✝ b✝ : C f✝ : a.as ⟶ a✝ m₁✝ m₂✝ : a✝ ⟶ b✝ g✝ : b✝ ⟶ b.as h : r m₁✝ m₂✝ ⊢ (fun f => F.map f) (f✝ ≫ m₁✝ ≫ g✝) = (fun f => F.map f) (f✝ ≫ m₂✝ ≫ g✝)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩
simp [H _ _ _ _ h]
/-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩
Mathlib.CategoryTheory.Quotient.166_0.34bZdkqpf1A9Wub
/-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a
Mathlib_CategoryTheory_Quotient
C : Type ?u.12785 inst✝¹ : Category.{?u.12789, ?u.12785} C r : HomRel C D : Type ?u.12817 inst✝ : Category.{?u.12821, ?u.12817} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ ⊢ ∀ {X Y Z : Quotient r} (f : X ⟶ Y) (g : Y ⟶ Z), { obj := fun a => F.obj a.as, map := fun a b hf => Quot.liftOn hf (fun f => F.map f) (_ : ∀ (a_1 b_1 : a.as ⟶ b.as), CompClosure r a_1 b_1 → (fun f => F.map f) a_1 = (fun f => F.map f) b_1) }.map (f ≫ g) = { obj := fun a => F.obj a.as, map := fun a b hf => Quot.liftOn hf (fun f => F.map f) (_ : ∀ (a_1 b_1 : a.as ⟶ b.as), CompClosure r a_1 b_1 → (fun f => F.map f) a_1 = (fun f => F.map f) b_1) }.map f ≫ { obj := fun a => F.obj a.as, map := fun a b hf => Quot.liftOn hf (fun f => F.map f) (_ : ∀ (a_1 b_1 : a.as ⟶ b.as), CompClosure r a_1 b_1 → (fun f => F.map f) a_1 = (fun f => F.map f) b_1) }.map g
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by
rintro a b c ⟹f⟩ ⟹g⟩
/-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by
Mathlib.CategoryTheory.Quotient.166_0.34bZdkqpf1A9Wub
/-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a
Mathlib_CategoryTheory_Quotient
case mk.mk C : Type ?u.12785 inst✝¹ : Category.{?u.12789, ?u.12785} C r : HomRel C D : Type ?u.12817 inst✝ : Category.{?u.12821, ?u.12817} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ a b c : Quotient r f✝ : a ⟶ b f : a.as ⟶ b.as g✝ : b ⟶ c g : b.as ⟶ c.as ⊢ { obj := fun a => F.obj a.as, map := fun a b hf => Quot.liftOn hf (fun f => F.map f) (_ : ∀ (a_1 b_1 : a.as ⟶ b.as), CompClosure r a_1 b_1 → (fun f => F.map f) a_1 = (fun f => F.map f) b_1) }.map (Quot.mk (CompClosure r) f ≫ Quot.mk (CompClosure r) g) = { obj := fun a => F.obj a.as, map := fun a b hf => Quot.liftOn hf (fun f => F.map f) (_ : ∀ (a_1 b_1 : a.as ⟶ b.as), CompClosure r a_1 b_1 → (fun f => F.map f) a_1 = (fun f => F.map f) b_1) }.map (Quot.mk (CompClosure r) f) ≫ { obj := fun a => F.obj a.as, map := fun a b hf => Quot.liftOn hf (fun f => F.map f) (_ : ∀ (a_1 b_1 : a.as ⟶ b.as), CompClosure r a_1 b_1 → (fun f => F.map f) a_1 = (fun f => F.map f) b_1) }.map (Quot.mk (CompClosure r) g)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩
exact F.map_comp f g
/-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩
Mathlib.CategoryTheory.Quotient.166_0.34bZdkqpf1A9Wub
/-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a
Mathlib_CategoryTheory_Quotient
C : Type u_1 inst✝¹ : Category.{u_2, u_1} C r : HomRel C D : Type u_3 inst✝ : Category.{u_4, u_3} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ ⊢ functor r ⋙ lift r F H = F
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by
apply Functor.ext
theorem lift_spec : functor r ⋙ lift r F H = F := by
Mathlib.CategoryTheory.Quotient.180_0.34bZdkqpf1A9Wub
theorem lift_spec : functor r ⋙ lift r F H = F
Mathlib_CategoryTheory_Quotient
case h_map C : Type u_1 inst✝¹ : Category.{u_2, u_1} C r : HomRel C D : Type u_3 inst✝ : Category.{u_4, u_3} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ ⊢ autoParam (∀ (X Y : C) (f : X ⟶ Y), (functor r ⋙ lift r F H).map f = eqToHom (_ : ?F.obj X = ?G.obj X) ≫ F.map f ≫ eqToHom (_ : F.obj Y = (functor r ⋙ lift r F H).obj Y)) _auto✝ case h_obj C : Type u_1 inst✝¹ : Category.{u_2, u_1} C r : HomRel C D : Type u_3 inst✝ : Category.{u_4, u_3} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ ⊢ ∀ (X : C), (functor r ⋙ lift r F H).obj X = F.obj X
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext;
rotate_left
theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext;
Mathlib.CategoryTheory.Quotient.180_0.34bZdkqpf1A9Wub
theorem lift_spec : functor r ⋙ lift r F H = F
Mathlib_CategoryTheory_Quotient
case h_obj C : Type u_1 inst✝¹ : Category.{u_2, u_1} C r : HomRel C D : Type u_3 inst✝ : Category.{u_4, u_3} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ ⊢ ∀ (X : C), (functor r ⋙ lift r F H).obj X = F.obj X
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left ·
rintro X
theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left ·
Mathlib.CategoryTheory.Quotient.180_0.34bZdkqpf1A9Wub
theorem lift_spec : functor r ⋙ lift r F H = F
Mathlib_CategoryTheory_Quotient
case h_obj C : Type u_1 inst✝¹ : Category.{u_2, u_1} C r : HomRel C D : Type u_3 inst✝ : Category.{u_4, u_3} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ X : C ⊢ (functor r ⋙ lift r F H).obj X = F.obj X
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X
rfl
theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X
Mathlib.CategoryTheory.Quotient.180_0.34bZdkqpf1A9Wub
theorem lift_spec : functor r ⋙ lift r F H = F
Mathlib_CategoryTheory_Quotient
case h_map C : Type u_1 inst✝¹ : Category.{u_2, u_1} C r : HomRel C D : Type u_3 inst✝ : Category.{u_4, u_3} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ ⊢ autoParam (∀ (X Y : C) (f : X ⟶ Y), (functor r ⋙ lift r F H).map f = eqToHom (_ : (functor r ⋙ lift r F H).obj X = (functor r ⋙ lift r F H).obj X) ≫ F.map f ≫ eqToHom (_ : F.obj Y = (functor r ⋙ lift r F H).obj Y)) _auto✝
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl ·
rintro X Y f
theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl ·
Mathlib.CategoryTheory.Quotient.180_0.34bZdkqpf1A9Wub
theorem lift_spec : functor r ⋙ lift r F H = F
Mathlib_CategoryTheory_Quotient
case h_map C : Type u_1 inst✝¹ : Category.{u_2, u_1} C r : HomRel C D : Type u_3 inst✝ : Category.{u_4, u_3} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ X Y : C f : X ⟶ Y ⊢ (functor r ⋙ lift r F H).map f = eqToHom (_ : (functor r ⋙ lift r F H).obj X = (functor r ⋙ lift r F H).obj X) ≫ F.map f ≫ eqToHom (_ : F.obj Y = (functor r ⋙ lift r F H).obj Y)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f
dsimp [lift, functor]
theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f
Mathlib.CategoryTheory.Quotient.180_0.34bZdkqpf1A9Wub
theorem lift_spec : functor r ⋙ lift r F H = F
Mathlib_CategoryTheory_Quotient
case h_map C : Type u_1 inst✝¹ : Category.{u_2, u_1} C r : HomRel C D : Type u_3 inst✝ : Category.{u_4, u_3} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ X Y : C f : X ⟶ Y ⊢ Quot.liftOn (Quot.mk (CompClosure r) f) (fun f => F.map f) (_ : ∀ (a b : { as := X }.as ⟶ { as := Y }.as), CompClosure r a b → (fun f => F.map f) a = (fun f => F.map f) b) = 𝟙 (F.obj X) ≫ F.map f ≫ 𝟙 (F.obj Y)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor]
simp
theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor]
Mathlib.CategoryTheory.Quotient.180_0.34bZdkqpf1A9Wub
theorem lift_spec : functor r ⋙ lift r F H = F
Mathlib_CategoryTheory_Quotient
C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ Ί : Quotient r ⥀ D hΊ : functor r ⋙ Ί = F ⊢ Ί = lift r F H
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by
subst_vars
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D Ί : Quotient r ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → (functor r ⋙ Ί).map f₁ = (functor r ⋙ Ί).map f₂ ⊢ Ί = lift r (functor r ⋙ Ί) H
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars
fapply Functor.hext
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
case h_obj C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D Ί : Quotient r ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → (functor r ⋙ Ί).map f₁ = (functor r ⋙ Ί).map f₂ ⊢ ∀ (X : Quotient r), Ί.obj X = (lift r (functor r ⋙ Ί) H).obj X
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext ·
rintro X
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext ·
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
case h_obj C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D Ί : Quotient r ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → (functor r ⋙ Ί).map f₁ = (functor r ⋙ Ί).map f₂ X : Quotient r ⊢ Ί.obj X = (lift r (functor r ⋙ Ί) H).obj X
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X
dsimp [lift, Functor]
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
case h_obj C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D Ί : Quotient r ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → (functor r ⋙ Ί).map f₁ = (functor r ⋙ Ί).map f₂ X : Quotient r ⊢ Ί.obj X = Ί.obj ((functor r).obj X.as)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor]
congr
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor]
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
case h_map C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D Ί : Quotient r ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → (functor r ⋙ Ί).map f₁ = (functor r ⋙ Ί).map f₂ ⊢ ∀ (X Y : Quotient r) (f : X ⟶ Y), HEq (Ί.map f) ((lift r (functor r ⋙ Ί) H).map f)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr ·
rintro _ _ f
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr ·
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
case h_map C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D Ί : Quotient r ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → (functor r ⋙ Ί).map f₁ = (functor r ⋙ Ί).map f₂ X✝ Y✝ : Quotient r f : X✝ ⟶ Y✝ ⊢ HEq (Ί.map f) ((lift r (functor r ⋙ Ί) H).map f)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f
dsimp [lift, Functor]
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
case h_map C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D Ί : Quotient r ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → (functor r ⋙ Ί).map f₁ = (functor r ⋙ Ί).map f₂ X✝ Y✝ : Quotient r f : X✝ ⟶ Y✝ ⊢ HEq (Ί.map f) (Quot.liftOn f (fun f => Ί.map ((functor r).map f)) (_ : ∀ (a b : X✝.as ⟶ Y✝.as), CompClosure r a b → (fun f => (functor r ⋙ Ί).map f) a = (fun f => (functor r ⋙ Ί).map f) b))
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor]
refine Quot.inductionOn f (fun _ ↩ ?_)
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor]
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
case h_map C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D Ί : Quotient r ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → (functor r ⋙ Ί).map f₁ = (functor r ⋙ Ί).map f₂ X✝ Y✝ : Quotient r f : X✝ ⟶ Y✝ x✝ : X✝.as ⟶ Y✝.as ⊢ HEq (Ί.map (Quot.mk (CompClosure r) x✝)) (Quot.liftOn (Quot.mk (CompClosure r) x✝) (fun f => Ί.map ((functor r).map f)) (_ : ∀ (a b : X✝.as ⟶ Y✝.as), CompClosure r a b → (fun f => (functor r ⋙ Ί).map f) a = (fun f => (functor r ⋙ Ί).map f) b))
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply`
simp only [Quot.liftOn_mk, Functor.comp_map]
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply`
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
case h_map C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D Ί : Quotient r ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → (functor r ⋙ Ί).map f₁ = (functor r ⋙ Ί).map f₂ X✝ Y✝ : Quotient r f : X✝ ⟶ Y✝ x✝ : X✝.as ⟶ Y✝.as ⊢ HEq (Ί.map (Quot.mk (CompClosure r) x✝)) (Ί.map ((functor r).map x✝))
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map]
congr
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map]
Mathlib.CategoryTheory.Quotient.189_0.34bZdkqpf1A9Wub
theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H
Mathlib_CategoryTheory_Quotient
C : Type u_2 inst✝¹ : Category.{u_1, u_2} C r : HomRel C D : Type u_4 inst✝ : Category.{u_3, u_4} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ X Y : C f : X ⟶ Y ⊢ (lift r F H).map ((functor r).map f) = F.map f
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by
rw [← NatIso.naturality_1 (lift.isLift r F H)]
theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by
Mathlib.CategoryTheory.Quotient.217_0.34bZdkqpf1A9Wub
theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f
Mathlib_CategoryTheory_Quotient
C : Type u_2 inst✝¹ : Category.{u_1, u_2} C r : HomRel C D : Type u_4 inst✝ : Category.{u_3, u_4} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ X Y : C f : X ⟶ Y ⊢ (lift r F H).map ((functor r).map f) = (lift.isLift r F H).inv.app X ≫ (functor r ⋙ lift r F H).map f ≫ (lift.isLift r F H).hom.app Y
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)]
dsimp [lift, functor]
theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)]
Mathlib.CategoryTheory.Quotient.217_0.34bZdkqpf1A9Wub
theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f
Mathlib_CategoryTheory_Quotient
C : Type u_2 inst✝¹ : Category.{u_1, u_2} C r : HomRel C D : Type u_4 inst✝ : Category.{u_3, u_4} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ X Y : C f : X ⟶ Y ⊢ Quot.liftOn (Quot.mk (CompClosure r) f) (fun f => F.map f) (_ : ∀ (a b : { as := X }.as ⟶ { as := Y }.as), CompClosure r a b → (fun f => F.map f) a = (fun f => F.map f) b) = 𝟙 (F.obj X) ≫ Quot.liftOn (Quot.mk (CompClosure r) f) (fun f => F.map f) (_ : ∀ (a b : { as := X }.as ⟶ { as := Y }.as), CompClosure r a b → (fun f => F.map f) a = (fun f => F.map f) b) ≫ 𝟙 (F.obj Y)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor]
simp
theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor]
Mathlib.CategoryTheory.Quotient.217_0.34bZdkqpf1A9Wub
theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f
Mathlib_CategoryTheory_Quotient
C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D F✝ : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F✝.map f₁ = F✝.map f₂ F G : Quotient r ⥀ D τ₁ τ₂ : F ⟶ G h : whiskerLeft (functor r) τ₁ = whiskerLeft (functor r) τ₂ ⊢ τ₁.app = τ₂.app
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor] simp #align category_theory.quotient.lift_map_functor_map CategoryTheory.Quotient.lift_map_functor_map variable {r} lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by
ext1 ⟹X⟩
lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by
Mathlib.CategoryTheory.Quotient.226_0.34bZdkqpf1A9Wub
lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂
Mathlib_CategoryTheory_Quotient
case h.mk C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D F✝ : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F✝.map f₁ = F✝.map f₂ F G : Quotient r ⥀ D τ₁ τ₂ : F ⟶ G h : whiskerLeft (functor r) τ₁ = whiskerLeft (functor r) τ₂ X : C ⊢ τ₁.app { as := X } = τ₂.app { as := X }
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor] simp #align category_theory.quotient.lift_map_functor_map CategoryTheory.Quotient.lift_map_functor_map variable {r} lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by ext1 ⟹X⟩;
exact NatTrans.congr_app h X
lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by ext1 ⟹X⟩;
Mathlib.CategoryTheory.Quotient.226_0.34bZdkqpf1A9Wub
lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂
Mathlib_CategoryTheory_Quotient
C : Type ?u.21219 inst✝¹ : Category.{?u.21223, ?u.21219} C r : HomRel C D : Type ?u.21251 inst✝ : Category.{?u.21255, ?u.21251} D F✝ : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F✝.map f₁ = F✝.map f₂ F G : Quotient r ⥀ D τ : functor r ⋙ F ⟶ functor r ⋙ G x✝¹ x✝ : Quotient r X Y : C ⊢ ∀ (f : { as := X } ⟶ { as := Y }), F.map f ≫ (fun x => match x with | { as := X } => τ.app X) { as := Y } = (fun x => match x with | { as := X } => τ.app X) { as := X } ≫ G.map f
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor] simp #align category_theory.quotient.lift_map_functor_map CategoryTheory.Quotient.lift_map_functor_map variable {r} lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by ext1 ⟹X⟩; exact NatTrans.congr_app h X) variable (r) /-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app := fun ⟹X⟩ => τ.app X naturality := fun ⟹X⟩ ⟹Y⟩ => by
rintro ⟹f⟩
/-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app := fun ⟹X⟩ => τ.app X naturality := fun ⟹X⟩ ⟹Y⟩ => by
Mathlib.CategoryTheory.Quotient.232_0.34bZdkqpf1A9Wub
/-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app
Mathlib_CategoryTheory_Quotient
case mk C : Type ?u.21219 inst✝¹ : Category.{?u.21223, ?u.21219} C r : HomRel C D : Type ?u.21251 inst✝ : Category.{?u.21255, ?u.21251} D F✝ : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F✝.map f₁ = F✝.map f₂ F G : Quotient r ⥀ D τ : functor r ⋙ F ⟶ functor r ⋙ G x✝¹ x✝ : Quotient r X Y : C f✝ : { as := X } ⟶ { as := Y } f : { as := X }.as ⟶ { as := Y }.as ⊢ F.map (Quot.mk (CompClosure r) f) ≫ (fun x => match x with | { as := X } => τ.app X) { as := Y } = (fun x => match x with | { as := X } => τ.app X) { as := X } ≫ G.map (Quot.mk (CompClosure r) f)
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor] simp #align category_theory.quotient.lift_map_functor_map CategoryTheory.Quotient.lift_map_functor_map variable {r} lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by ext1 ⟹X⟩; exact NatTrans.congr_app h X) variable (r) /-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app := fun ⟹X⟩ => τ.app X naturality := fun ⟹X⟩ ⟹Y⟩ => by rintro ⟹f⟩
exact τ.naturality f
/-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app := fun ⟹X⟩ => τ.app X naturality := fun ⟹X⟩ ⟹Y⟩ => by rintro ⟹f⟩
Mathlib.CategoryTheory.Quotient.232_0.34bZdkqpf1A9Wub
/-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app
Mathlib_CategoryTheory_Quotient
C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D F✝ : C ⥀ D H✝ : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F✝.map f₁ = F✝.map f₂ F G H : Quotient r ⥀ D τ : functor r ⋙ F ⟶ functor r ⋙ G τ' : functor r ⋙ G ⟶ functor r ⋙ H ⊢ natTransLift r τ ≫ natTransLift r τ' = natTransLift r (τ ≫ τ')
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor] simp #align category_theory.quotient.lift_map_functor_map CategoryTheory.Quotient.lift_map_functor_map variable {r} lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by ext1 ⟹X⟩; exact NatTrans.congr_app h X) variable (r) /-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app := fun ⟹X⟩ => τ.app X naturality := fun ⟹X⟩ ⟹Y⟩ => by rintro ⟹f⟩ exact τ.naturality f @[simp] lemma natTransLift_app (F G : Quotient r ⥀ D) (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (X : C) : (natTransLift r τ).app ((Quotient.functor r).obj X) = τ.app X := rfl @[reassoc] lemma comp_natTransLift {F G H : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (τ' : Quotient.functor r ⋙ G ⟶ Quotient.functor r ⋙ H) : natTransLift r τ ≫ natTransLift r τ' = natTransLift r (τ ≫ τ') := by
aesop_cat
@[reassoc] lemma comp_natTransLift {F G H : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (τ' : Quotient.functor r ⋙ G ⟶ Quotient.functor r ⋙ H) : natTransLift r τ ≫ natTransLift r τ' = natTransLift r (τ ≫ τ') := by
Mathlib.CategoryTheory.Quotient.246_0.34bZdkqpf1A9Wub
@[reassoc] lemma comp_natTransLift {F G H : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (τ' : Quotient.functor r ⋙ G ⟶ Quotient.functor r ⋙ H) : natTransLift r τ ≫ natTransLift r τ' = natTransLift r (τ ≫ τ')
Mathlib_CategoryTheory_Quotient
C : Type u_3 inst✝¹ : Category.{u_1, u_3} C r : HomRel C D : Type u_4 inst✝ : Category.{u_2, u_4} D F✝ : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F✝.map f₁ = F✝.map f₂ F : Quotient r ⥀ D ⊢ natTransLift r (𝟙 (functor r ⋙ F)) = 𝟙 F
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor] simp #align category_theory.quotient.lift_map_functor_map CategoryTheory.Quotient.lift_map_functor_map variable {r} lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by ext1 ⟹X⟩; exact NatTrans.congr_app h X) variable (r) /-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app := fun ⟹X⟩ => τ.app X naturality := fun ⟹X⟩ ⟹Y⟩ => by rintro ⟹f⟩ exact τ.naturality f @[simp] lemma natTransLift_app (F G : Quotient r ⥀ D) (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (X : C) : (natTransLift r τ).app ((Quotient.functor r).obj X) = τ.app X := rfl @[reassoc] lemma comp_natTransLift {F G H : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (τ' : Quotient.functor r ⋙ G ⟶ Quotient.functor r ⋙ H) : natTransLift r τ ≫ natTransLift r τ' = natTransLift r (τ ≫ τ') := by aesop_cat @[simp] lemma natTransLift_id (F : Quotient r ⥀ D) : natTransLift r (𝟙 (Quotient.functor r ⋙ F)) = 𝟙 _ := by
aesop_cat
@[simp] lemma natTransLift_id (F : Quotient r ⥀ D) : natTransLift r (𝟙 (Quotient.functor r ⋙ F)) = 𝟙 _ := by
Mathlib.CategoryTheory.Quotient.252_0.34bZdkqpf1A9Wub
@[simp] lemma natTransLift_id (F : Quotient r ⥀ D) : natTransLift r (𝟙 (Quotient.functor r ⋙ F)) = 𝟙 _
Mathlib_CategoryTheory_Quotient
C : Type ?u.27722 inst✝¹ : Category.{?u.27726, ?u.27722} C r : HomRel C D : Type ?u.27754 inst✝ : Category.{?u.27758, ?u.27754} D F✝ : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F✝.map f₁ = F✝.map f₂ F G : Quotient r ⥀ D τ : functor r ⋙ F ≅ functor r ⋙ G ⊢ natTransLift r τ.hom ≫ natTransLift r τ.inv = 𝟙 F
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor] simp #align category_theory.quotient.lift_map_functor_map CategoryTheory.Quotient.lift_map_functor_map variable {r} lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by ext1 ⟹X⟩; exact NatTrans.congr_app h X) variable (r) /-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app := fun ⟹X⟩ => τ.app X naturality := fun ⟹X⟩ ⟹Y⟩ => by rintro ⟹f⟩ exact τ.naturality f @[simp] lemma natTransLift_app (F G : Quotient r ⥀ D) (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (X : C) : (natTransLift r τ).app ((Quotient.functor r).obj X) = τ.app X := rfl @[reassoc] lemma comp_natTransLift {F G H : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (τ' : Quotient.functor r ⋙ G ⟶ Quotient.functor r ⋙ H) : natTransLift r τ ≫ natTransLift r τ' = natTransLift r (τ ≫ τ') := by aesop_cat @[simp] lemma natTransLift_id (F : Quotient r ⥀ D) : natTransLift r (𝟙 (Quotient.functor r ⋙ F)) = 𝟙 _ := by aesop_cat /-- In order to define a natural isomorphism `F ≅ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ @[simps] def natIsoLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ≅ Quotient.functor r ⋙ G) : F ≅ G where hom := natTransLift _ τ.hom inv := natTransLift _ τ.inv hom_inv_id := by
rw [comp_natTransLift, τ.hom_inv_id, natTransLift_id]
/-- In order to define a natural isomorphism `F ≅ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ @[simps] def natIsoLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ≅ Quotient.functor r ⋙ G) : F ≅ G where hom := natTransLift _ τ.hom inv := natTransLift _ τ.inv hom_inv_id := by
Mathlib.CategoryTheory.Quotient.256_0.34bZdkqpf1A9Wub
/-- In order to define a natural isomorphism `F ≅ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ @[simps] def natIsoLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ≅ Quotient.functor r ⋙ G) : F ≅ G where hom
Mathlib_CategoryTheory_Quotient
C : Type ?u.27722 inst✝¹ : Category.{?u.27726, ?u.27722} C r : HomRel C D : Type ?u.27754 inst✝ : Category.{?u.27758, ?u.27754} D F✝ : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F✝.map f₁ = F✝.map f₂ F G : Quotient r ⥀ D τ : functor r ⋙ F ≅ functor r ⋙ G ⊢ natTransLift r τ.inv ≫ natTransLift r τ.hom = 𝟙 G
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor] simp #align category_theory.quotient.lift_map_functor_map CategoryTheory.Quotient.lift_map_functor_map variable {r} lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by ext1 ⟹X⟩; exact NatTrans.congr_app h X) variable (r) /-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app := fun ⟹X⟩ => τ.app X naturality := fun ⟹X⟩ ⟹Y⟩ => by rintro ⟹f⟩ exact τ.naturality f @[simp] lemma natTransLift_app (F G : Quotient r ⥀ D) (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (X : C) : (natTransLift r τ).app ((Quotient.functor r).obj X) = τ.app X := rfl @[reassoc] lemma comp_natTransLift {F G H : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (τ' : Quotient.functor r ⋙ G ⟶ Quotient.functor r ⋙ H) : natTransLift r τ ≫ natTransLift r τ' = natTransLift r (τ ≫ τ') := by aesop_cat @[simp] lemma natTransLift_id (F : Quotient r ⥀ D) : natTransLift r (𝟙 (Quotient.functor r ⋙ F)) = 𝟙 _ := by aesop_cat /-- In order to define a natural isomorphism `F ≅ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ @[simps] def natIsoLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ≅ Quotient.functor r ⋙ G) : F ≅ G where hom := natTransLift _ τ.hom inv := natTransLift _ τ.inv hom_inv_id := by rw [comp_natTransLift, τ.hom_inv_id, natTransLift_id] inv_hom_id := by
rw [comp_natTransLift, τ.inv_hom_id, natTransLift_id]
/-- In order to define a natural isomorphism `F ≅ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ @[simps] def natIsoLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ≅ Quotient.functor r ⋙ G) : F ≅ G where hom := natTransLift _ τ.hom inv := natTransLift _ τ.inv hom_inv_id := by rw [comp_natTransLift, τ.hom_inv_id, natTransLift_id] inv_hom_id := by
Mathlib.CategoryTheory.Quotient.256_0.34bZdkqpf1A9Wub
/-- In order to define a natural isomorphism `F ≅ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ @[simps] def natIsoLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ≅ Quotient.functor r ⋙ G) : F ≅ G where hom
Mathlib_CategoryTheory_Quotient
C : Type ?u.32590 inst✝¹ : Category.{?u.32594, ?u.32590} C r : HomRel C D : Type ?u.32622 inst✝ : Category.{?u.32626, ?u.32622} D F : C ⥀ D H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂ ⊢ ∀ {X Y : Quotient r ⥀ D}, Function.Injective ((whiskeringLeft C (Quotient r) D).obj (functor r)).map
/- Copyright (c) 2020 David WÀrn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David WÀrn -/ import Mathlib.CategoryTheory.NatIso import Mathlib.CategoryTheory.EqToHom #align_import category_theory.quotient from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence relation, `functor_map_eq_iff` says that no unnecessary identifications have been made. -/ /-- A `HomRel` on `C` consists of a relation on every hom-set. -/ def HomRel (C) [Quiver C] := ∀ ⊃X Y : C⩄, (X ⟶ Y) → (X ⟶ Y) → Prop #align hom_rel HomRel -- Porting Note: `deriving Inhabited` was not able to deduce this typeclass instance (C) [Quiver C] : Inhabited (HomRel C) where default := fun _ _ _ _ ↩ PUnit namespace CategoryTheory variable {C : Type _} [Category C] (r : HomRel C) /-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed from left and right. -/ class Congruence : Prop where /-- `r` is an equivalence on every hom-set. -/ equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y) /-- Precomposition with an arrow respects `r`. -/ compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g') /-- Postcomposition with an arrow respects `r`. -/ compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g) #align category_theory.congruence CategoryTheory.Congruence /-- A type synonym for `C`, thought of as the objects of the quotient category. -/ @[ext] structure Quotient (r : HomRel C) where /-- The object of `C`. -/ as : C #align category_theory.quotient CategoryTheory.Quotient instance [Inhabited C] : Inhabited (Quotient r) := ⟹{ as := default }⟩ namespace Quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive CompClosure (r : HomRel C) ⊃s t : C⩄ : (s ⟶ t) → (s ⟶ t) → Prop | intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) : CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) #align category_theory.quotient.comp_closure CategoryTheory.Quotient.CompClosure theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h #align category_theory.quotient.comp_closure.of CategoryTheory.Quotient.CompClosure.of theorem comp_left {a b c : C} (f : a ⟶ b) : ∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h #align category_theory.quotient.comp_left CategoryTheory.Quotient.comp_left theorem comp_right {a b c : C} (g : b ⟶ c) : ∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g) | _, _, ⟹x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h #align category_theory.quotient.comp_right CategoryTheory.Quotient.comp_right /-- Hom-sets of the quotient category. -/ def Hom (s t : Quotient r) := Quot <| @CompClosure C _ r s.as t.as #align category_theory.quotient.hom CategoryTheory.Quotient.Hom instance (a : Quotient r) : Inhabited (Hom r a a) := ⟹Quot.mk _ (𝟙 a.as)⟩ /-- Composition in the quotient category. -/ def comp ⊃a b c : Quotient r⩄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↩ Quot.liftOn hf (fun f ↩ Quot.liftOn hg (fun g ↩ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↩ Quot.sound <| comp_left r f g₁ g₂ h) fun f₁ f₂ h ↩ Quot.inductionOn hg fun g ↩ Quot.sound <| comp_right r g f₁ f₂ h #align category_theory.quotient.comp CategoryTheory.Quotient.comp @[simp] theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) : comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) := rfl #align category_theory.quotient.comp_mk CategoryTheory.Quotient.comp_mk -- porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc` instance category : Category (Quotient r) where Hom := Hom r id a := Quot.mk _ (𝟙 a.as) comp := @comp _ _ r comp_id f := Quot.inductionOn f $ by simp id_comp f := Quot.inductionOn f $ by simp assoc f g h := Quot.inductionOn f $ Quot.inductionOn g $ Quot.inductionOn h $ by simp #align category_theory.quotient.category CategoryTheory.Quotient.category /-- The functor from a category to its quotient. -/ def functor : C ⥀ Quotient r where obj a := { as := a } map := @fun _ _ f ↩ Quot.mk _ f #align category_theory.quotient.functor CategoryTheory.Quotient.functor noncomputable instance fullFunctor : Full (functor r) where preimage := @fun X Y f ↩ Quot.out f witness f := by dsimp [functor] simp instance essSurj_functor : EssSurj (functor r) where mem_essImage Y := ⟹Y.as, ⟹eqToIso (by ext rfl)⟩⟩ protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) : ∀ {a b : Quotient r} (f : a ⟶ b), P f := by rintro ⟹x⟩ ⟹y⟩ ⟹f⟩ exact h f #align category_theory.quotient.induction CategoryTheory.Quotient.induction protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) : (functor r).map f₁ = (functor r).map f₂ := by simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h) #align category_theory.quotient.sound CategoryTheory.Quotient.sound lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) : CompClosure r f g ↔ r f g := by constructor · intro hfg induction' hfg with m m' hm exact Congruence.compLeft _ (Congruence.compRight _ (by assumption)) · exact CompClosure.of _ _ _ @[simp] theorem compClosure_eq_self [h : Congruence r] : CompClosure r = r := by ext simp only [compClosure_iff_self] theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) : (functor r).map f = (functor r).map f' ↔ r f f' := by dsimp [functor] rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r] simpa only [compClosure_eq_self r] using h.equivalence #align category_theory.quotient.functor_map_eq_iff CategoryTheory.Quotient.functor_map_eq_iff variable {D : Type _} [Category D] (F : C ⥀ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) /-- The induced functor on the quotient category. -/ def lift : Quotient r ⥀ D where obj a := F.obj a.as map := @fun a b hf ↩ Quot.liftOn hf (fun f ↩ F.map f) (by rintro _ _ ⟹_, _, _, _, h⟩ simp [H _ _ _ _ h]) map_id a := F.map_id a.as map_comp := by rintro a b c ⟹f⟩ ⟹g⟩ exact F.map_comp f g #align category_theory.quotient.lift CategoryTheory.Quotient.lift theorem lift_spec : functor r ⋙ lift r F H = F := by apply Functor.ext; rotate_left · rintro X rfl · rintro X Y f dsimp [lift, functor] simp #align category_theory.quotient.lift_spec CategoryTheory.Quotient.lift_spec theorem lift_unique (Ί : Quotient r ⥀ D) (hΊ : functor r ⋙ Ί = F) : Ί = lift r F H := by subst_vars fapply Functor.hext · rintro X dsimp [lift, Functor] congr · rintro _ _ f dsimp [lift, Functor] refine Quot.inductionOn f (fun _ ↩ ?_) -- porting note: this line was originally an `apply` simp only [Quot.liftOn_mk, Functor.comp_map] congr #align category_theory.quotient.lift_unique CategoryTheory.Quotient.lift_unique /-- The original functor factors through the induced functor. -/ def lift.isLift : functor r ⋙ lift r F H ≅ F := NatIso.ofComponents fun X ↩ Iso.refl _ #align category_theory.quotient.lift.is_lift CategoryTheory.Quotient.lift.isLift @[simp] theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_hom CategoryTheory.Quotient.lift.isLift_hom @[simp] theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) := rfl #align category_theory.quotient.lift.is_lift_inv CategoryTheory.Quotient.lift.isLift_inv theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) : (lift r F H).map ((functor r).map f) = F.map f := by rw [← NatIso.naturality_1 (lift.isLift r F H)] dsimp [lift, functor] simp #align category_theory.quotient.lift_map_functor_map CategoryTheory.Quotient.lift_map_functor_map variable {r} lemma natTrans_ext {F G : Quotient r ⥀ D} (τ₁ τ₂ : F ⟶ G) (h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ := NatTrans.ext _ _ (by ext1 ⟹X⟩; exact NatTrans.congr_app h X) variable (r) /-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ def natTransLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) : F ⟶ G where app := fun ⟹X⟩ => τ.app X naturality := fun ⟹X⟩ ⟹Y⟩ => by rintro ⟹f⟩ exact τ.naturality f @[simp] lemma natTransLift_app (F G : Quotient r ⥀ D) (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (X : C) : (natTransLift r τ).app ((Quotient.functor r).obj X) = τ.app X := rfl @[reassoc] lemma comp_natTransLift {F G H : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (τ' : Quotient.functor r ⋙ G ⟶ Quotient.functor r ⋙ H) : natTransLift r τ ≫ natTransLift r τ' = natTransLift r (τ ≫ τ') := by aesop_cat @[simp] lemma natTransLift_id (F : Quotient r ⥀ D) : natTransLift r (𝟙 (Quotient.functor r ⋙ F)) = 𝟙 _ := by aesop_cat /-- In order to define a natural isomorphism `F ≅ G` with `F G : Quotient r ⥀ D`, it suffices to do so after precomposing with `Quotient.functor r`. -/ @[simps] def natIsoLift {F G : Quotient r ⥀ D} (τ : Quotient.functor r ⋙ F ≅ Quotient.functor r ⋙ G) : F ≅ G where hom := natTransLift _ τ.hom inv := natTransLift _ τ.inv hom_inv_id := by rw [comp_natTransLift, τ.hom_inv_id, natTransLift_id] inv_hom_id := by rw [comp_natTransLift, τ.inv_hom_id, natTransLift_id] variable (D) instance full_whiskeringLeft_functor : Full ((whiskeringLeft C _ D).obj (functor r)) where preimage := natTransLift r instance faithful_whiskeringLeft_functor : Faithful ((whiskeringLeft C _ D).obj (functor r)) := ⟹by
apply natTrans_ext
instance faithful_whiskeringLeft_functor : Faithful ((whiskeringLeft C _ D).obj (functor r)) := ⟹by
Mathlib.CategoryTheory.Quotient.272_0.34bZdkqpf1A9Wub
instance faithful_whiskeringLeft_functor : Faithful ((whiskeringLeft C _ D).obj (functor r))
Mathlib_CategoryTheory_Quotient
a b : ℝ n : ℕ f : ℝ → ℝ ÎŒ Îœ : Measure ℝ inst✝ : IsLocallyFiniteMeasure ÎŒ c d r : ℝ h : -1 < r ⊢ IntervalIntegrable (fun x => x ^ r) volume a b
/- Copyright (c) 2021 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson -/ import Mathlib.MeasureTheory.Integral.FundThmCalculus import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv import Mathlib.Analysis.SpecialFunctions.NonIntegrable #align_import analysis.special_functions.integrals from "leanprover-community/mathlib"@"011cafb4a5bc695875d186e245d6b3df03bf6c40" /-! # Integration of specific interval integrals This file contains proofs of the integrals of various specific functions. This includes: * Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log` * Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)` * The integral of `cos x ^ 2 - sin x ^ 2` * Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n ≥ 2` * The computation of `∫ x in 0..π, sin x ^ n` as a product for even and odd `n` (used in proving the Wallis product for pi) * Integrals of the form `sin x ^ m * cos x ^ n` With these lemmas, many simple integrals can be computed by `simp` or `norm_num`. See `test/integration.lean` for specific examples. This file also contains some facts about the interval integrability of specific functions. This file is still being developed. ## Tags integrate, integration, integrable, integrability -/ open Real Nat Set Finset open scoped Real BigOperators Interval variable {a b : ℝ} (n : ℕ) namespace intervalIntegral open MeasureTheory variable {f : ℝ → ℝ} {ÎŒ Îœ : Measure ℝ} [IsLocallyFiniteMeasure ÎŒ] (c d : ℝ) /-! ### Interval integrability -/ @[simp] theorem intervalIntegrable_pow : IntervalIntegrable (fun x => x ^ n) ÎŒ a b := (continuous_pow n).intervalIntegrable a b #align interval_integral.interval_integrable_pow intervalIntegral.intervalIntegrable_pow theorem intervalIntegrable_zpow {n : â„€} (h : 0 ≀ n √ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x => x ^ n) ÎŒ a b := (continuousOn_id.zpow₀ n fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable #align interval_integral.interval_integrable_zpow intervalIntegral.intervalIntegrable_zpow /-- See `intervalIntegrable_rpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_rpow {r : ℝ} (h : 0 ≀ r √ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x => x ^ r) ÎŒ a b := (continuousOn_id.rpow_const fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable #align interval_integral.interval_integrable_rpow intervalIntegral.intervalIntegrable_rpow /-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_rpow' {r : ℝ} (h : -1 < r) : IntervalIntegrable (fun x => x ^ r) volume a b := by
suffices ∀ c : ℝ, IntervalIntegrable (fun x => x ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b)
/-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_rpow' {r : ℝ} (h : -1 < r) : IntervalIntegrable (fun x => x ^ r) volume a b := by
Mathlib.Analysis.SpecialFunctions.Integrals.70_0.61KIRGZyZnxsI7s
/-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_rpow' {r : ℝ} (h : -1 < r) : IntervalIntegrable (fun x => x ^ r) volume a b
Mathlib_Analysis_SpecialFunctions_Integrals