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