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 |