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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.